ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From magyari_san...@apache.org
Subject ambari git commit: AMBARI-17313. Handle desired state for services/components on restart (Laszlo Puskas via magyari_sandor)
Date Wed, 29 Jun 2016 13:19:22 GMT
Repository: ambari
Updated Branches:
  refs/heads/branch-2.4 32326775f -> 74a262c48


 AMBARI-17313. Handle desired state for services/components on restart (Laszlo Puskas via
magyari_sandor)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/74a262c4
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/74a262c4
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/74a262c4

Branch: refs/heads/branch-2.4
Commit: 74a262c48da8a5faf6996b250ec0c5bf660e5ab8
Parents: 3232677
Author: Laszlo Puskas <lpuskas@hortonworks.com>
Authored: Wed Jun 29 15:04:38 2016 +0200
Committer: Sandor Magyari <smagyari@hortonworks.com>
Committed: Wed Jun 29 15:17:05 2016 +0200

----------------------------------------------------------------------
 .../AmbariCustomCommandExecutionHelper.java     |  72 +++---
 .../AmbariCustomCommandExecutionHelperTest.java | 221 +++++++++----------
 .../AmbariManagementControllerTest.java         |  39 ++--
 3 files changed, 168 insertions(+), 164 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/74a262c4/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelper.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelper.java
b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelper.java
index b60592d..9526077 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelper.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelper.java
@@ -18,33 +18,6 @@
 
 package org.apache.ambari.server.controller;
 
-import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.AGENT_STACK_RETRY_COUNT;
-import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.AGENT_STACK_RETRY_ON_UNAVAILABILITY;
-import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.CLIENTS_TO_UPDATE_CONFIGS;
-import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.COMMAND_TIMEOUT;
-import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.COMPONENT_CATEGORY;
-import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.CUSTOM_COMMAND;
-import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.DB_DRIVER_FILENAME;
-import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.DB_NAME;
-import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.GROUP_LIST;
-import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.HOOKS_FOLDER;
-import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.HOST_SYS_PREPPED;
-import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.JAVA_HOME;
-import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.JAVA_VERSION;
-import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.JCE_NAME;
-import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.JDK_LOCATION;
-import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.JDK_NAME;
-import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.MYSQL_JDBC_URL;
-import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.NOT_MANAGED_HDFS_PATH_LIST;
-import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.ORACLE_JDBC_URL;
-import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.REPO_INFO;
-import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.SCRIPT;
-import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.SCRIPT_TYPE;
-import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.SERVICE_PACKAGE_FOLDER;
-import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.STACK_NAME;
-import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.STACK_VERSION;
-import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.USER_LIST;
-
 import java.text.MessageFormat;
 import java.util.ArrayList;
 import java.util.Collections;
@@ -109,6 +82,33 @@ import com.google.gson.JsonObject;
 import com.google.inject.Inject;
 import com.google.inject.Singleton;
 
+import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.AGENT_STACK_RETRY_COUNT;
+import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.AGENT_STACK_RETRY_ON_UNAVAILABILITY;
+import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.CLIENTS_TO_UPDATE_CONFIGS;
+import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.COMMAND_TIMEOUT;
+import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.COMPONENT_CATEGORY;
+import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.CUSTOM_COMMAND;
+import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.DB_DRIVER_FILENAME;
+import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.DB_NAME;
+import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.GROUP_LIST;
+import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.HOOKS_FOLDER;
+import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.HOST_SYS_PREPPED;
+import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.JAVA_HOME;
+import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.JAVA_VERSION;
+import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.JCE_NAME;
+import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.JDK_LOCATION;
+import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.JDK_NAME;
+import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.MYSQL_JDBC_URL;
+import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.NOT_MANAGED_HDFS_PATH_LIST;
+import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.ORACLE_JDBC_URL;
+import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.REPO_INFO;
+import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.SCRIPT;
+import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.SCRIPT_TYPE;
+import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.SERVICE_PACKAGE_FOLDER;
+import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.STACK_NAME;
+import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.STACK_VERSION;
+import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.USER_LIST;
+
 /**
  * Helper class containing logic to process custom command execution requests .
  * This class has special support needed for SERVICE_CHECK and DECOMMISSION.
@@ -446,6 +446,21 @@ public class AmbariCustomCommandExecutionHelper {
 
       roleParams.put(COMPONENT_CATEGORY, componentInfo.getCategory());
       execCmd.setRoleParams(roleParams);
+
+      // perform any server side command related logic - eg - set desired states on restart
+      applyCustomCommandBackendLogic(cluster, serviceName, componentName, commandName, hostName);
+    }
+  }
+
+  private void applyCustomCommandBackendLogic(Cluster cluster, String serviceName, String
componentName, String commandName, String hostname) throws AmbariException {
+    switch (commandName) {
+      case "RESTART":
+        LOG.info("Updating desired state on RESTART for the service [{}], service component
[{}]", serviceName, componentName);
+        cluster.getService(serviceName).getServiceComponent(componentName).getServiceComponentHost(hostname).setDesiredState(State.STARTED);
+        break;
+      default:
+        LOG.debug("No backend operations needed for the custom command: {}", commandName);
+        break;
     }
   }
 
@@ -989,8 +1004,7 @@ public class AmbariCustomCommandExecutionHelper {
           }
         }
 
-        addCustomCommandAction(actionExecutionContext, resourceFilter, stage, extraParams,
-            commandDetail);
+        addCustomCommandAction(actionExecutionContext, resourceFilter, stage, extraParams,
commandDetail);
       } else {
         throw new AmbariException("Unsupported action " + actionName);
       }

http://git-wip-us.apache.org/repos/asf/ambari/blob/74a262c4/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelperTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelperTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelperTest.java
index 68b31c0..251f00a 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelperTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelperTest.java
@@ -17,8 +17,6 @@
  */
 package org.apache.ambari.server.controller;
 
-import static org.mockito.Matchers.any;
-
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.HashMap;
@@ -28,8 +26,12 @@ import java.util.Map;
 import java.util.Set;
 
 import org.apache.ambari.server.AmbariException;
+import org.apache.ambari.server.Role;
+import org.apache.ambari.server.RoleCommand;
 import org.apache.ambari.server.actionmanager.ActionManager;
 import org.apache.ambari.server.actionmanager.ExecutionCommandWrapper;
+import org.apache.ambari.server.actionmanager.HostRoleCommand;
+import org.apache.ambari.server.actionmanager.HostRoleStatus;
 import org.apache.ambari.server.actionmanager.Request;
 import org.apache.ambari.server.actionmanager.Stage;
 import org.apache.ambari.server.agent.ExecutionCommand;
@@ -52,15 +54,15 @@ import org.apache.ambari.server.state.SecurityType;
 import org.apache.ambari.server.state.State;
 import org.apache.ambari.server.topology.TopologyManager;
 import org.apache.ambari.server.utils.StageUtils;
+import org.easymock.Capture;
+import org.easymock.EasyMock;
+import org.easymock.EasyMockRule;
+import org.easymock.Mock;
+import org.easymock.MockType;
 import org.junit.After;
 import org.junit.Before;
+import org.junit.Rule;
 import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.ArgumentCaptor;
-import org.mockito.Captor;
-import org.mockito.Mock;
-import org.mockito.Mockito;
-import org.mockito.runners.MockitoJUnitRunner;
 import org.springframework.security.core.context.SecurityContextHolder;
 
 import com.google.inject.Guice;
@@ -69,54 +71,70 @@ import com.google.inject.persist.PersistService;
 
 import junit.framework.Assert;
 
-@RunWith(MockitoJUnitRunner.class)
+
 public class AmbariCustomCommandExecutionHelperTest {
-  private Injector injector;
-  private AmbariManagementController controller;
-  private Clusters clusters;
+  private static final String REQUEST_CONTEXT_PROPERTY = "context";
 
+  @Rule
+  public EasyMockRule mocks = new EasyMockRule(this);
 
-  private static final String REQUEST_CONTEXT_PROPERTY = "context";
+  @Mock(type = MockType.NICE)
+  private ActionManager actionManager;
+
+  @Mock(type = MockType.NICE)
+  private HostRoleCommand hostRoleCommand;
+
+  private Injector injector;
+  private Clusters clusters;
+  private AmbariManagementController ambariManagementController;
+  private Capture<Request> requestCapture = EasyMock.newCapture();
 
-  @Captor ArgumentCaptor<Request> requestCapture;
-  @Mock ActionManager am;
 
   @Before
   public void setup() throws Exception {
+    EasyMock.reset(actionManager, hostRoleCommand);
+
     InMemoryDefaultTestModule module = new InMemoryDefaultTestModule(){
       @Override
       protected void configure() {
         super.configure();
-        bind(ActionManager.class).toInstance(am);
+        bind(ActionManager.class).toInstance(actionManager);
       }
     };
-    injector = Guice.createInjector(module);
-
 
+    injector = Guice.createInjector(module);
     injector.getInstance(GuiceJpaInitializer.class);
-    controller = injector.getInstance(AmbariManagementController.class);
+    ambariManagementController = injector.getInstance(AmbariManagementController.class);
     clusters = injector.getInstance(Clusters.class);
+
     StageUtils.setTopologyManager(injector.getInstance(TopologyManager.class));
     StageUtils.setConfiguration(injector.getInstance(Configuration.class));
-  }
 
-  @After
-  public void clearAuthentication() {
-    SecurityContextHolder.getContext().setAuthentication(null);
+    SecurityContextHolder.getContext().setAuthentication(TestAuthenticationFactory.createAdministrator());
+    createClusterFixture("c1", "HDP-2.0.6", "c1");
+
+    EasyMock.expect(hostRoleCommand.getTaskId()).andReturn(1L);
+    EasyMock.expect(hostRoleCommand.getStageId()).andReturn(1L);
+    EasyMock.expect(hostRoleCommand.getRoleCommand()).andReturn(RoleCommand.CUSTOM_COMMAND);
+    EasyMock.expect(hostRoleCommand.getRole()).andReturn(Role.AMBARI_SERVER_ACTION);
+    EasyMock.expect(hostRoleCommand.getStatus()).andReturn(HostRoleStatus.PENDING);
+
+    EasyMock.expect(actionManager.getNextRequestId()).andReturn(1L).anyTimes();
+    EasyMock.expect(actionManager.getRequestTasks(1L)).andReturn(Collections.singletonList(hostRoleCommand));
+
+    actionManager.sendActions(EasyMock.capture(requestCapture), EasyMock.anyObject(ExecuteActionRequest.class));
+    EasyMock.expectLastCall();
+
   }
 
   @After
   public void teardown() {
+    SecurityContextHolder.getContext().setAuthentication(null);
     injector.getInstance(PersistService.class).stop();
   }
 
-  @SuppressWarnings("serial")
   @Test
   public void testRefreshQueueCustomCommand() throws Exception {
-    SecurityContextHolder.getContext().setAuthentication(TestAuthenticationFactory.createAdministrator());
-
-    createClusterFixture("HDP-2.0.6");
-
     Map<String, String> requestProperties = new HashMap<String, String>() {
       {
         put(REQUEST_CONTEXT_PROPERTY, "Refresh YARN Capacity Scheduler");
@@ -130,13 +148,11 @@ public class AmbariCustomCommandExecutionHelperTest {
             put("forceRefreshConfigTags", "capacity-scheduler");
           }
         }, false);
-    actionRequest.getResourceFilters().add(
-        new RequestResourceFilter("YARN", "RESOURCEMANAGER", Collections.singletonList("c6401")));
+    actionRequest.getResourceFilters().add(new RequestResourceFilter("YARN", "RESOURCEMANAGER",
Collections.singletonList("c1-c6401")));
 
-    controller.createAction(actionRequest, requestProperties);
+    EasyMock.replay(hostRoleCommand, actionManager);
 
-    Mockito.verify(am, Mockito.times(1)).sendActions(requestCapture.capture(),
-        any(ExecuteActionRequest.class));
+    ambariManagementController.createAction(actionRequest, requestProperties);
 
     Request request = requestCapture.getValue();
     Assert.assertNotNull(request);
@@ -146,7 +162,7 @@ public class AmbariCustomCommandExecutionHelperTest {
 
     Assert.assertEquals(1, stage.getHosts().size());
 
-    List<ExecutionCommandWrapper> commands = stage.getExecutionCommands("c6401");
+    List<ExecutionCommandWrapper> commands = stage.getExecutionCommands("c1-c6401");
     Assert.assertEquals(1, commands.size());
 
     ExecutionCommand command = commands.get(0).getExecutionCommand();
@@ -159,9 +175,6 @@ public class AmbariCustomCommandExecutionHelperTest {
 
   @Test
   public void testHostsFilterHealthy() throws Exception {
-    SecurityContextHolder.getContext().setAuthentication(TestAuthenticationFactory.createAdministrator());
-
-    createClusterFixture("HDP-2.0.6");
 
     Map<String, String> requestProperties = new HashMap<String, String>() {
       {
@@ -175,9 +188,9 @@ public class AmbariCustomCommandExecutionHelperTest {
     ExecuteActionRequest actionRequest = new ExecuteActionRequest(
        "c1", "RESTART", null,
        Arrays.asList(
-          new RequestResourceFilter("GANGLIA", "GANGLIA_SERVER", Collections.singletonList("c6401")),
-          new RequestResourceFilter("GANGLIA", "GANGLIA_MONITOR", Collections.singletonList("c6401")),
-          new RequestResourceFilter("GANGLIA", "GANGLIA_MONITOR", Collections.singletonList("c6402"))
+           new RequestResourceFilter("GANGLIA", "GANGLIA_SERVER", Collections.singletonList("c1-c6401")),
+           new RequestResourceFilter("GANGLIA", "GANGLIA_MONITOR", Collections.singletonList("c1-c6401")),
+           new RequestResourceFilter("GANGLIA", "GANGLIA_MONITOR", Collections.singletonList("c1-c6402"))
        ),
        new RequestOperationLevel(Resource.Type.Service, "c1", "GANGLIA", null, null),
         new HashMap<String, String>() {
@@ -186,11 +199,9 @@ public class AmbariCustomCommandExecutionHelperTest {
         },
        false);
 
-    controller.createAction(actionRequest, requestProperties);
-
-    //clusters.getHost("c6402").setState(HostState.HEARTBEAT_LOST);
+    EasyMock.replay(hostRoleCommand, actionManager);
 
-    Mockito.verify(am, Mockito.times(1)).sendActions(requestCapture.capture(), any(ExecuteActionRequest.class));
+    ambariManagementController.createAction(actionRequest, requestProperties);
 
     Request request = requestCapture.getValue();
     Assert.assertNotNull(request);
@@ -204,12 +215,8 @@ public class AmbariCustomCommandExecutionHelperTest {
 
   @Test
   public void testHostsFilterUnhealthyHost() throws Exception {
-    SecurityContextHolder.getContext().setAuthentication(TestAuthenticationFactory.createAdministrator());
-
-    createClusterFixture("HDP-2.0.6");
-
     // Set custom status to host
-    clusters.getHost("c6402").setState(HostState.HEARTBEAT_LOST);
+    clusters.getHost("c1-c6402").setState(HostState.HEARTBEAT_LOST);
     Map<String, String> requestProperties = new HashMap<String, String>() {
       {
         put("context", "Restart all components for GANGLIA");
@@ -221,22 +228,18 @@ public class AmbariCustomCommandExecutionHelperTest {
 
     ExecuteActionRequest actionRequest = new ExecuteActionRequest("c1", "RESTART", null,
         Arrays.asList(
-            new RequestResourceFilter("GANGLIA", "GANGLIA_SERVER",
-                Collections.singletonList("c6401")),
-            new RequestResourceFilter("GANGLIA", "GANGLIA_MONITOR",
-                Collections.singletonList("c6401")),
-            new RequestResourceFilter("GANGLIA", "GANGLIA_MONITOR",
-                Collections.singletonList("c6402"))),
+            new RequestResourceFilter("GANGLIA", "GANGLIA_SERVER", Collections.singletonList("c1-c6401")),
+            new RequestResourceFilter("GANGLIA", "GANGLIA_MONITOR", Collections.singletonList("c1-c6401")),
+            new RequestResourceFilter("GANGLIA", "GANGLIA_MONITOR", Collections.singletonList("c1-c6402"))),
         new RequestOperationLevel(Resource.Type.Service, "c1", "GANGLIA", null, null),
         new HashMap<String, String>() {
           {
           }
         }, false);
 
-    controller.createAction(actionRequest, requestProperties);
+    EasyMock.replay(hostRoleCommand, actionManager);
 
-    Mockito.verify(am, Mockito.times(1)).sendActions(requestCapture.capture(),
-        any(ExecuteActionRequest.class));
+    ambariManagementController.createAction(actionRequest, requestProperties);
 
     Request request = requestCapture.getValue();
     Assert.assertNotNull(request);
@@ -250,13 +253,9 @@ public class AmbariCustomCommandExecutionHelperTest {
 
   @Test
   public void testHostsFilterUnhealthyComponent() throws Exception {
-    SecurityContextHolder.getContext().setAuthentication(TestAuthenticationFactory.createAdministrator());
-
-    createClusterFixture("HDP-2.0.6");
-
     // Set custom status to host
     clusters.getCluster("c1").getService("GANGLIA").getServiceComponent(
-        "GANGLIA_MONITOR").getServiceComponentHost("c6402").setState(State.UNKNOWN);
+        "GANGLIA_MONITOR").getServiceComponentHost("c1-c6402").setState(State.UNKNOWN);
 
     Map<String, String> requestProperties = new HashMap<String, String>() {
       {
@@ -269,22 +268,18 @@ public class AmbariCustomCommandExecutionHelperTest {
 
     ExecuteActionRequest actionRequest = new ExecuteActionRequest("c1", "RESTART", null,
         Arrays.asList(
-            new RequestResourceFilter("GANGLIA", "GANGLIA_SERVER",
-                Collections.singletonList("c6401")),
-            new RequestResourceFilter("GANGLIA", "GANGLIA_MONITOR",
-                Collections.singletonList("c6401")),
-            new RequestResourceFilter("GANGLIA", "GANGLIA_MONITOR",
-                Collections.singletonList("c6402"))),
+            new RequestResourceFilter("GANGLIA", "GANGLIA_SERVER", Collections.singletonList("c1-c6401")),
+            new RequestResourceFilter("GANGLIA", "GANGLIA_MONITOR", Collections.singletonList("c1-c6401")),
+            new RequestResourceFilter("GANGLIA", "GANGLIA_MONITOR", Collections.singletonList("c1-c6402"))),
         new RequestOperationLevel(Resource.Type.Host, "c1", "GANGLIA", null, null),
         new HashMap<String, String>() {
           {
           }
         }, false);
 
-    controller.createAction(actionRequest, requestProperties);
+    EasyMock.replay(hostRoleCommand, actionManager);
 
-    Mockito.verify(am, Mockito.times(1)).sendActions(requestCapture.capture(),
-        any(ExecuteActionRequest.class));
+    ambariManagementController.createAction(actionRequest, requestProperties);
 
     Request request = requestCapture.getValue();
     Assert.assertNotNull(request);
@@ -302,9 +297,6 @@ public class AmbariCustomCommandExecutionHelperTest {
    */
   @Test(expected = AmbariException.class)
   public void testNoCandidateHostThrowsException() throws Exception {
-    SecurityContextHolder.getContext().setAuthentication(TestAuthenticationFactory.createAdministrator());
-
-    createClusterFixture("HDP-2.0.6");
     long clusterId = clusters.getCluster("c1").getClusterId();
 
     // put host into MM
@@ -325,8 +317,8 @@ public class AmbariCustomCommandExecutionHelperTest {
     // create the service check on the host in MM
     ExecuteActionRequest actionRequest = new ExecuteActionRequest("c1",
         "ZOOKEEPER_QUORUM_SERVICE_CHECK",
-        null, Arrays.asList(new RequestResourceFilter("ZOOKEEPER", "ZOOKEEPER_CLIENT",
-            Collections.singletonList("c6402"))),
+        null, Collections.singletonList(new RequestResourceFilter("ZOOKEEPER", "ZOOKEEPER_CLIENT",
+        Collections.singletonList("c6402"))),
 
         new RequestOperationLevel(Resource.Type.Service, "c1", "ZOOKEEPER", null, null),
         new HashMap<String, String>() {
@@ -334,7 +326,8 @@ public class AmbariCustomCommandExecutionHelperTest {
           }
         }, false);
 
-    controller.createAction(actionRequest, requestProperties);
+    EasyMock.replay(hostRoleCommand, actionManager);
+    ambariManagementController.createAction(actionRequest, requestProperties);
     Assert.fail(
         "Expected an exception since there are no hosts which can run the ZK service check");
   }
@@ -346,10 +339,6 @@ public class AmbariCustomCommandExecutionHelperTest {
    */
   @Test(expected = AmbariException.class)
   public void testServiceCheckMaintenanceModeWithMissingComponentName() throws Exception
{
-    SecurityContextHolder.getContext().setAuthentication(
-        TestAuthenticationFactory.createAdministrator());
-
-    createClusterFixture("HDP-2.0.6");
     long clusterId = clusters.getCluster("c1").getClusterId();
 
     // put host into MM
@@ -371,8 +360,8 @@ public class AmbariCustomCommandExecutionHelperTest {
     // create the service check on the host in MM, passing in null for the
     // component name
     ExecuteActionRequest actionRequest = new ExecuteActionRequest("c1",
-        "ZOOKEEPER_QUORUM_SERVICE_CHECK", null, Arrays.asList(
-            new RequestResourceFilter("ZOOKEEPER", null, Collections.singletonList("c6402"))),
+        "ZOOKEEPER_QUORUM_SERVICE_CHECK", null, Collections.singletonList(new RequestResourceFilter("ZOOKEEPER",
null,
+        Collections.singletonList("c6402"))),
 
         new RequestOperationLevel(Resource.Type.Service, "c1", "ZOOKEEPER", null, null),
         new HashMap<String, String>() {
@@ -380,48 +369,46 @@ public class AmbariCustomCommandExecutionHelperTest {
           }
         }, false);
 
-    controller.createAction(actionRequest, requestProperties);
-    Assert.fail(
-        "Expected an exception since there are no hosts which can run the ZK service check");
+    EasyMock.replay(hostRoleCommand, actionManager);
+    ambariManagementController.createAction(actionRequest, requestProperties);
+    Assert.fail("Expected an exception since there are no hosts which can run the ZK service
check");
   }
 
   @Test
   public void testIsTopologyRefreshRequired() throws Exception {
-    SecurityContextHolder.getContext().setAuthentication(TestAuthenticationFactory.createAdministrator());
-
     AmbariCustomCommandExecutionHelper helper = injector.getInstance(AmbariCustomCommandExecutionHelper.class);
 
-    createClusterFixture("HDP-2.1.1");
+    createClusterFixture("c2", "HDP-2.1.1", "c2");
 
-    Assert.assertTrue(helper.isTopologyRefreshRequired("START", "c1", "HDFS"));
-    Assert.assertTrue(helper.isTopologyRefreshRequired("RESTART", "c1", "HDFS"));
-    Assert.assertFalse(helper.isTopologyRefreshRequired("STOP", "c1", "HDFS"));
+    Assert.assertTrue(helper.isTopologyRefreshRequired("START", "c2", "HDFS"));
+    Assert.assertTrue(helper.isTopologyRefreshRequired("RESTART", "c2", "HDFS"));
+    Assert.assertFalse(helper.isTopologyRefreshRequired("STOP", "c2", "HDFS"));
   }
 
-  private void createClusterFixture(String stackVersion) throws AmbariException, AuthorizationException
{
-    createCluster("c1", stackVersion);
-    addHost("c6401","c1");
-    addHost("c6402","c1");
+  private void createClusterFixture(String clusterName, String stackVersion, String hostPrefix)
throws AmbariException, AuthorizationException {
+    createCluster(clusterName, stackVersion);
+    addHost(hostPrefix + "-c6401", clusterName);
+    addHost(hostPrefix + "-c6402", clusterName);
 
-    clusters.getCluster("c1");
-    createService("c1", "YARN", null);
-    createService("c1", "GANGLIA", null);
-    createService("c1", "ZOOKEEPER", null);
+    clusters.getCluster(clusterName);
+    createService(clusterName, "YARN", null);
+    createService(clusterName, "GANGLIA", null);
+    createService(clusterName, "ZOOKEEPER", null);
 
-    createServiceComponent("c1", "YARN","RESOURCEMANAGER", State.INIT);
-    createServiceComponent("c1", "YARN", "NODEMANAGER", State.INIT);
-    createServiceComponent("c1", "GANGLIA", "GANGLIA_SERVER", State.INIT);
-    createServiceComponent("c1", "GANGLIA", "GANGLIA_MONITOR", State.INIT);
-    createServiceComponent("c1", "ZOOKEEPER", "ZOOKEEPER_CLIENT", State.INIT);
+    createServiceComponent(clusterName, "YARN", "RESOURCEMANAGER", State.INIT);
+    createServiceComponent(clusterName, "YARN", "NODEMANAGER", State.INIT);
+    createServiceComponent(clusterName, "GANGLIA", "GANGLIA_SERVER", State.INIT);
+    createServiceComponent(clusterName, "GANGLIA", "GANGLIA_MONITOR", State.INIT);
+    createServiceComponent(clusterName, "ZOOKEEPER", "ZOOKEEPER_CLIENT", State.INIT);
 
-    createServiceComponentHost("c1","YARN","RESOURCEMANAGER","c6401", null);
-    createServiceComponentHost("c1","YARN","NODEMANAGER","c6401", null);
-    createServiceComponentHost("c1","GANGLIA","GANGLIA_SERVER","c6401", State.INIT);
-    createServiceComponentHost("c1","GANGLIA","GANGLIA_MONITOR","c6401", State.INIT);
+    createServiceComponentHost(clusterName, "YARN", "RESOURCEMANAGER", hostPrefix + "-c6401",
null);
+    createServiceComponentHost(clusterName, "YARN", "NODEMANAGER", hostPrefix + "-c6401",
null);
+    createServiceComponentHost(clusterName, "GANGLIA", "GANGLIA_SERVER", hostPrefix + "-c6401",
State.INIT);
+    createServiceComponentHost(clusterName, "GANGLIA", "GANGLIA_MONITOR", hostPrefix + "-c6401",
State.INIT);
 
-    createServiceComponentHost("c1","YARN","NODEMANAGER","c6402", null);
-    createServiceComponentHost("c1","GANGLIA","GANGLIA_MONITOR","c6402", State.INIT);
-    createServiceComponentHost("c1", "ZOOKEEPER", "ZOOKEEPER_CLIENT", "c6402", State.INIT);
+    createServiceComponentHost(clusterName, "YARN", "NODEMANAGER", hostPrefix + "-c6402",
null);
+    createServiceComponentHost(clusterName, "GANGLIA", "GANGLIA_MONITOR", hostPrefix + "-c6402",
State.INIT);
+    createServiceComponentHost(clusterName, "ZOOKEEPER", "ZOOKEEPER_CLIENT", hostPrefix +
"-c6402", State.INIT);
 
   }
   private void addHost(String hostname, String clusterName) throws AmbariException {
@@ -444,7 +431,7 @@ public class AmbariCustomCommandExecutionHelperTest {
   private void createCluster(String clusterName, String stackVersion) throws AmbariException,
AuthorizationException {
     ClusterRequest r = new ClusterRequest(null, clusterName, State.INSTALLED.name(),
         SecurityType.NONE, stackVersion, null);
-    controller.createCluster(r);
+    ambariManagementController.createCluster(r);
   }
 
   private void createService(String clusterName,
@@ -457,7 +444,7 @@ public class AmbariCustomCommandExecutionHelperTest {
     Set<ServiceRequest> requests = new HashSet<ServiceRequest>();
     requests.add(r1);
 
-    ServiceResourceProviderTest.createServices(controller, requests);
+    ServiceResourceProviderTest.createServices(ambariManagementController, requests);
   }
 
   private void createServiceComponent(String clusterName,
@@ -472,7 +459,7 @@ public class AmbariCustomCommandExecutionHelperTest {
     Set<ServiceComponentRequest> requests =
         new HashSet<ServiceComponentRequest>();
     requests.add(r);
-    ComponentResourceProviderTest.createComponents(controller, requests);
+    ComponentResourceProviderTest.createComponents(ambariManagementController, requests);
   }
 
   private void createServiceComponentHost(String clusterName, String serviceName, String
componentName, String hostname, State desiredState)
@@ -486,7 +473,7 @@ public class AmbariCustomCommandExecutionHelperTest {
     Set<ServiceComponentHostRequest> requests =
         new HashSet<ServiceComponentHostRequest>();
     requests.add(r);
-    controller.createHostComponents(requests);
+    ambariManagementController.createHostComponents(requests);
   }
 
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/74a262c4/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java
index fd70df5..29cdbdf 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java
@@ -18,22 +18,6 @@
 
 package org.apache.ambari.server.controller;
 
-import static org.easymock.EasyMock.capture;
-import static org.easymock.EasyMock.createNiceMock;
-import static org.easymock.EasyMock.createStrictMock;
-import static org.easymock.EasyMock.expect;
-import static org.easymock.EasyMock.replay;
-import static org.easymock.EasyMock.verify;
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
 import java.io.StringReader;
 import java.lang.reflect.Type;
 import java.net.UnknownHostException;
@@ -176,6 +160,22 @@ import com.google.inject.persist.PersistService;
 
 import junit.framework.Assert;
 
+import static org.easymock.EasyMock.capture;
+import static org.easymock.EasyMock.createNiceMock;
+import static org.easymock.EasyMock.createStrictMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.verify;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
 public class AmbariManagementControllerTest {
 
   private static final Logger LOG =
@@ -6685,8 +6685,7 @@ public class AmbariManagementControllerTest {
       Role.RESOURCEMANAGER.name(), new ArrayList<String>() {{ add(host2); }});
     resourceFilters.add(resourceFilter);
 
-    ExecuteActionRequest request = new ExecuteActionRequest(cluster1,
-      "RESTART", null, resourceFilters, null, params, false);
+    ExecuteActionRequest request = new ExecuteActionRequest(cluster1, "RESTART", null, resourceFilters,
null, params, false);
 
     RequestStatusResponse response = controller.createAction(request, requestProperties);
     Assert.assertEquals(3, response.getTasks().size());
@@ -6728,6 +6727,10 @@ public class AmbariManagementControllerTest {
         storedTasks.get(0).getRole().name());
     Assert.assertEquals(host1, storedTasks.get(0).getHostName());
     Assert.assertEquals(requestProperties.get(REQUEST_CONTEXT_PROPERTY), response.getRequestContext());
+
+    Assert.assertEquals(State.STARTED, cluster.getService("HDFS").getServiceComponent(Role.DATANODE.name()).getServiceComponentHost(host1).getDesiredState());
+    Assert.assertEquals(State.STARTED, cluster.getService("HDFS").getServiceComponent(Role.DATANODE.name()).getServiceComponentHost(host2).getDesiredState());
+    Assert.assertEquals(State.STARTED, cluster.getService("YARN").getServiceComponent(Role.RESOURCEMANAGER.name()).getServiceComponentHost(host2).getDesiredState());
   }
 
 


Mime
View raw message