|
@@ -17,8 +17,6 @@
|
|
*/
|
|
*/
|
|
package org.apache.ambari.server.controller;
|
|
package org.apache.ambari.server.controller;
|
|
|
|
|
|
-import static org.mockito.Matchers.any;
|
|
|
|
-
|
|
|
|
import java.util.Arrays;
|
|
import java.util.Arrays;
|
|
import java.util.Collections;
|
|
import java.util.Collections;
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
@@ -28,8 +26,12 @@ import java.util.Map;
|
|
import java.util.Set;
|
|
import java.util.Set;
|
|
|
|
|
|
import org.apache.ambari.server.AmbariException;
|
|
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.ActionManager;
|
|
import org.apache.ambari.server.actionmanager.ExecutionCommandWrapper;
|
|
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.Request;
|
|
import org.apache.ambari.server.actionmanager.Stage;
|
|
import org.apache.ambari.server.actionmanager.Stage;
|
|
import org.apache.ambari.server.agent.ExecutionCommand;
|
|
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.state.State;
|
|
import org.apache.ambari.server.topology.TopologyManager;
|
|
import org.apache.ambari.server.topology.TopologyManager;
|
|
import org.apache.ambari.server.utils.StageUtils;
|
|
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.After;
|
|
import org.junit.Before;
|
|
import org.junit.Before;
|
|
|
|
+import org.junit.Rule;
|
|
import org.junit.Test;
|
|
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 org.springframework.security.core.context.SecurityContextHolder;
|
|
|
|
|
|
import com.google.inject.Guice;
|
|
import com.google.inject.Guice;
|
|
@@ -69,54 +71,70 @@ import com.google.inject.persist.PersistService;
|
|
|
|
|
|
import junit.framework.Assert;
|
|
import junit.framework.Assert;
|
|
|
|
|
|
-@RunWith(MockitoJUnitRunner.class)
|
|
|
|
|
|
+
|
|
public class AmbariCustomCommandExecutionHelperTest {
|
|
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
|
|
@Before
|
|
public void setup() throws Exception {
|
|
public void setup() throws Exception {
|
|
|
|
+ EasyMock.reset(actionManager, hostRoleCommand);
|
|
|
|
+
|
|
InMemoryDefaultTestModule module = new InMemoryDefaultTestModule(){
|
|
InMemoryDefaultTestModule module = new InMemoryDefaultTestModule(){
|
|
@Override
|
|
@Override
|
|
protected void configure() {
|
|
protected void configure() {
|
|
super.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);
|
|
injector.getInstance(GuiceJpaInitializer.class);
|
|
- controller = injector.getInstance(AmbariManagementController.class);
|
|
|
|
|
|
+ ambariManagementController = injector.getInstance(AmbariManagementController.class);
|
|
clusters = injector.getInstance(Clusters.class);
|
|
clusters = injector.getInstance(Clusters.class);
|
|
|
|
+
|
|
StageUtils.setTopologyManager(injector.getInstance(TopologyManager.class));
|
|
StageUtils.setTopologyManager(injector.getInstance(TopologyManager.class));
|
|
StageUtils.setConfiguration(injector.getInstance(Configuration.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
|
|
@After
|
|
public void teardown() {
|
|
public void teardown() {
|
|
|
|
+ SecurityContextHolder.getContext().setAuthentication(null);
|
|
injector.getInstance(PersistService.class).stop();
|
|
injector.getInstance(PersistService.class).stop();
|
|
}
|
|
}
|
|
|
|
|
|
- @SuppressWarnings("serial")
|
|
|
|
@Test
|
|
@Test
|
|
public void testRefreshQueueCustomCommand() throws Exception {
|
|
public void testRefreshQueueCustomCommand() throws Exception {
|
|
- SecurityContextHolder.getContext().setAuthentication(TestAuthenticationFactory.createAdministrator());
|
|
|
|
-
|
|
|
|
- createClusterFixture("HDP-2.0.6");
|
|
|
|
-
|
|
|
|
Map<String, String> requestProperties = new HashMap<String, String>() {
|
|
Map<String, String> requestProperties = new HashMap<String, String>() {
|
|
{
|
|
{
|
|
put(REQUEST_CONTEXT_PROPERTY, "Refresh YARN Capacity Scheduler");
|
|
put(REQUEST_CONTEXT_PROPERTY, "Refresh YARN Capacity Scheduler");
|
|
@@ -130,13 +148,11 @@ public class AmbariCustomCommandExecutionHelperTest {
|
|
put("forceRefreshConfigTags", "capacity-scheduler");
|
|
put("forceRefreshConfigTags", "capacity-scheduler");
|
|
}
|
|
}
|
|
}, false);
|
|
}, 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();
|
|
Request request = requestCapture.getValue();
|
|
Assert.assertNotNull(request);
|
|
Assert.assertNotNull(request);
|
|
@@ -146,7 +162,7 @@ public class AmbariCustomCommandExecutionHelperTest {
|
|
|
|
|
|
Assert.assertEquals(1, stage.getHosts().size());
|
|
Assert.assertEquals(1, stage.getHosts().size());
|
|
|
|
|
|
- List<ExecutionCommandWrapper> commands = stage.getExecutionCommands("c6401");
|
|
|
|
|
|
+ List<ExecutionCommandWrapper> commands = stage.getExecutionCommands("c1-c6401");
|
|
Assert.assertEquals(1, commands.size());
|
|
Assert.assertEquals(1, commands.size());
|
|
|
|
|
|
ExecutionCommand command = commands.get(0).getExecutionCommand();
|
|
ExecutionCommand command = commands.get(0).getExecutionCommand();
|
|
@@ -159,9 +175,6 @@ public class AmbariCustomCommandExecutionHelperTest {
|
|
|
|
|
|
@Test
|
|
@Test
|
|
public void testHostsFilterHealthy() throws Exception {
|
|
public void testHostsFilterHealthy() throws Exception {
|
|
- SecurityContextHolder.getContext().setAuthentication(TestAuthenticationFactory.createAdministrator());
|
|
|
|
-
|
|
|
|
- createClusterFixture("HDP-2.0.6");
|
|
|
|
|
|
|
|
Map<String, String> requestProperties = new HashMap<String, String>() {
|
|
Map<String, String> requestProperties = new HashMap<String, String>() {
|
|
{
|
|
{
|
|
@@ -175,9 +188,9 @@ public class AmbariCustomCommandExecutionHelperTest {
|
|
ExecuteActionRequest actionRequest = new ExecuteActionRequest(
|
|
ExecuteActionRequest actionRequest = new ExecuteActionRequest(
|
|
"c1", "RESTART", null,
|
|
"c1", "RESTART", null,
|
|
Arrays.asList(
|
|
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 RequestOperationLevel(Resource.Type.Service, "c1", "GANGLIA", null, null),
|
|
new HashMap<String, String>() {
|
|
new HashMap<String, String>() {
|
|
@@ -186,11 +199,9 @@ public class AmbariCustomCommandExecutionHelperTest {
|
|
},
|
|
},
|
|
false);
|
|
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();
|
|
Request request = requestCapture.getValue();
|
|
Assert.assertNotNull(request);
|
|
Assert.assertNotNull(request);
|
|
@@ -204,12 +215,8 @@ public class AmbariCustomCommandExecutionHelperTest {
|
|
|
|
|
|
@Test
|
|
@Test
|
|
public void testHostsFilterUnhealthyHost() throws Exception {
|
|
public void testHostsFilterUnhealthyHost() throws Exception {
|
|
- SecurityContextHolder.getContext().setAuthentication(TestAuthenticationFactory.createAdministrator());
|
|
|
|
-
|
|
|
|
- createClusterFixture("HDP-2.0.6");
|
|
|
|
-
|
|
|
|
// Set custom status to host
|
|
// 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>() {
|
|
Map<String, String> requestProperties = new HashMap<String, String>() {
|
|
{
|
|
{
|
|
put("context", "Restart all components for GANGLIA");
|
|
put("context", "Restart all components for GANGLIA");
|
|
@@ -221,22 +228,18 @@ public class AmbariCustomCommandExecutionHelperTest {
|
|
|
|
|
|
ExecuteActionRequest actionRequest = new ExecuteActionRequest("c1", "RESTART", null,
|
|
ExecuteActionRequest actionRequest = new ExecuteActionRequest("c1", "RESTART", null,
|
|
Arrays.asList(
|
|
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 RequestOperationLevel(Resource.Type.Service, "c1", "GANGLIA", null, null),
|
|
new HashMap<String, String>() {
|
|
new HashMap<String, String>() {
|
|
{
|
|
{
|
|
}
|
|
}
|
|
}, false);
|
|
}, 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();
|
|
Request request = requestCapture.getValue();
|
|
Assert.assertNotNull(request);
|
|
Assert.assertNotNull(request);
|
|
@@ -250,13 +253,9 @@ public class AmbariCustomCommandExecutionHelperTest {
|
|
|
|
|
|
@Test
|
|
@Test
|
|
public void testHostsFilterUnhealthyComponent() throws Exception {
|
|
public void testHostsFilterUnhealthyComponent() throws Exception {
|
|
- SecurityContextHolder.getContext().setAuthentication(TestAuthenticationFactory.createAdministrator());
|
|
|
|
-
|
|
|
|
- createClusterFixture("HDP-2.0.6");
|
|
|
|
-
|
|
|
|
// Set custom status to host
|
|
// Set custom status to host
|
|
clusters.getCluster("c1").getService("GANGLIA").getServiceComponent(
|
|
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>() {
|
|
Map<String, String> requestProperties = new HashMap<String, String>() {
|
|
{
|
|
{
|
|
@@ -269,22 +268,18 @@ public class AmbariCustomCommandExecutionHelperTest {
|
|
|
|
|
|
ExecuteActionRequest actionRequest = new ExecuteActionRequest("c1", "RESTART", null,
|
|
ExecuteActionRequest actionRequest = new ExecuteActionRequest("c1", "RESTART", null,
|
|
Arrays.asList(
|
|
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 RequestOperationLevel(Resource.Type.Host, "c1", "GANGLIA", null, null),
|
|
new HashMap<String, String>() {
|
|
new HashMap<String, String>() {
|
|
{
|
|
{
|
|
}
|
|
}
|
|
}, false);
|
|
}, 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();
|
|
Request request = requestCapture.getValue();
|
|
Assert.assertNotNull(request);
|
|
Assert.assertNotNull(request);
|
|
@@ -302,9 +297,6 @@ public class AmbariCustomCommandExecutionHelperTest {
|
|
*/
|
|
*/
|
|
@Test(expected = AmbariException.class)
|
|
@Test(expected = AmbariException.class)
|
|
public void testNoCandidateHostThrowsException() throws Exception {
|
|
public void testNoCandidateHostThrowsException() throws Exception {
|
|
- SecurityContextHolder.getContext().setAuthentication(TestAuthenticationFactory.createAdministrator());
|
|
|
|
-
|
|
|
|
- createClusterFixture("HDP-2.0.6");
|
|
|
|
long clusterId = clusters.getCluster("c1").getClusterId();
|
|
long clusterId = clusters.getCluster("c1").getClusterId();
|
|
|
|
|
|
// put host into MM
|
|
// put host into MM
|
|
@@ -325,8 +317,8 @@ public class AmbariCustomCommandExecutionHelperTest {
|
|
// create the service check on the host in MM
|
|
// create the service check on the host in MM
|
|
ExecuteActionRequest actionRequest = new ExecuteActionRequest("c1",
|
|
ExecuteActionRequest actionRequest = new ExecuteActionRequest("c1",
|
|
"ZOOKEEPER_QUORUM_SERVICE_CHECK",
|
|
"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 RequestOperationLevel(Resource.Type.Service, "c1", "ZOOKEEPER", null, null),
|
|
new HashMap<String, String>() {
|
|
new HashMap<String, String>() {
|
|
@@ -334,7 +326,8 @@ public class AmbariCustomCommandExecutionHelperTest {
|
|
}
|
|
}
|
|
}, false);
|
|
}, false);
|
|
|
|
|
|
- controller.createAction(actionRequest, requestProperties);
|
|
|
|
|
|
+ EasyMock.replay(hostRoleCommand, actionManager);
|
|
|
|
+ ambariManagementController.createAction(actionRequest, requestProperties);
|
|
Assert.fail(
|
|
Assert.fail(
|
|
"Expected an exception since there are no hosts which can run the ZK service check");
|
|
"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)
|
|
@Test(expected = AmbariException.class)
|
|
public void testServiceCheckMaintenanceModeWithMissingComponentName() throws Exception {
|
|
public void testServiceCheckMaintenanceModeWithMissingComponentName() throws Exception {
|
|
- SecurityContextHolder.getContext().setAuthentication(
|
|
|
|
- TestAuthenticationFactory.createAdministrator());
|
|
|
|
-
|
|
|
|
- createClusterFixture("HDP-2.0.6");
|
|
|
|
long clusterId = clusters.getCluster("c1").getClusterId();
|
|
long clusterId = clusters.getCluster("c1").getClusterId();
|
|
|
|
|
|
// put host into MM
|
|
// 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
|
|
// create the service check on the host in MM, passing in null for the
|
|
// component name
|
|
// component name
|
|
ExecuteActionRequest actionRequest = new ExecuteActionRequest("c1",
|
|
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 RequestOperationLevel(Resource.Type.Service, "c1", "ZOOKEEPER", null, null),
|
|
new HashMap<String, String>() {
|
|
new HashMap<String, String>() {
|
|
@@ -380,48 +369,46 @@ public class AmbariCustomCommandExecutionHelperTest {
|
|
}
|
|
}
|
|
}, false);
|
|
}, 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
|
|
@Test
|
|
public void testIsTopologyRefreshRequired() throws Exception {
|
|
public void testIsTopologyRefreshRequired() throws Exception {
|
|
- SecurityContextHolder.getContext().setAuthentication(TestAuthenticationFactory.createAdministrator());
|
|
|
|
-
|
|
|
|
AmbariCustomCommandExecutionHelper helper = injector.getInstance(AmbariCustomCommandExecutionHelper.class);
|
|
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 {
|
|
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 {
|
|
private void createCluster(String clusterName, String stackVersion) throws AmbariException, AuthorizationException {
|
|
ClusterRequest r = new ClusterRequest(null, clusterName, State.INSTALLED.name(),
|
|
ClusterRequest r = new ClusterRequest(null, clusterName, State.INSTALLED.name(),
|
|
SecurityType.NONE, stackVersion, null);
|
|
SecurityType.NONE, stackVersion, null);
|
|
- controller.createCluster(r);
|
|
|
|
|
|
+ ambariManagementController.createCluster(r);
|
|
}
|
|
}
|
|
|
|
|
|
private void createService(String clusterName,
|
|
private void createService(String clusterName,
|
|
@@ -457,7 +444,7 @@ public class AmbariCustomCommandExecutionHelperTest {
|
|
Set<ServiceRequest> requests = new HashSet<ServiceRequest>();
|
|
Set<ServiceRequest> requests = new HashSet<ServiceRequest>();
|
|
requests.add(r1);
|
|
requests.add(r1);
|
|
|
|
|
|
- ServiceResourceProviderTest.createServices(controller, requests);
|
|
|
|
|
|
+ ServiceResourceProviderTest.createServices(ambariManagementController, requests);
|
|
}
|
|
}
|
|
|
|
|
|
private void createServiceComponent(String clusterName,
|
|
private void createServiceComponent(String clusterName,
|
|
@@ -472,7 +459,7 @@ public class AmbariCustomCommandExecutionHelperTest {
|
|
Set<ServiceComponentRequest> requests =
|
|
Set<ServiceComponentRequest> requests =
|
|
new HashSet<ServiceComponentRequest>();
|
|
new HashSet<ServiceComponentRequest>();
|
|
requests.add(r);
|
|
requests.add(r);
|
|
- ComponentResourceProviderTest.createComponents(controller, requests);
|
|
|
|
|
|
+ ComponentResourceProviderTest.createComponents(ambariManagementController, requests);
|
|
}
|
|
}
|
|
|
|
|
|
private void createServiceComponentHost(String clusterName, String serviceName, String componentName, String hostname, State desiredState)
|
|
private void createServiceComponentHost(String clusterName, String serviceName, String componentName, String hostname, State desiredState)
|
|
@@ -486,7 +473,7 @@ public class AmbariCustomCommandExecutionHelperTest {
|
|
Set<ServiceComponentHostRequest> requests =
|
|
Set<ServiceComponentHostRequest> requests =
|
|
new HashSet<ServiceComponentHostRequest>();
|
|
new HashSet<ServiceComponentHostRequest>();
|
|
requests.add(r);
|
|
requests.add(r);
|
|
- controller.createHostComponents(requests);
|
|
|
|
|
|
+ ambariManagementController.createHostComponents(requests);
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|