use of com.sequenceiq.cloudbreak.reactor.api.event.cluster.StopStartUpscaleCommissionViaCMRequest in project cloudbreak by hortonworks.
the class StopStartUpscaleActionsTest method testCmCommissionAction2.
@Test
void testCmCommissionAction2() throws Exception {
// All instances didn't start from the previous step.
AbstractStopStartUpscaleActions<StopStartUpscaleStartInstancesResult> action = (AbstractStopStartUpscaleActions<StopStartUpscaleStartInstancesResult>) underTest.cmCommissionAction();
initActionPrivateFields(action);
int adjustment = 5;
StopStartUpscaleContext stopStartUpscaleContext = createContext(adjustment);
List<InstanceMetaData> instancesActionableNotStopped = generateInstances(5, 100, InstanceStatus.SERVICES_HEALTHY, INSTANCE_GROUP_NAME_ACTIONABLE);
List<InstanceMetaData> instancesActionableStopped = generateInstances(10, 200, InstanceStatus.STOPPED, INSTANCE_GROUP_NAME_ACTIONABLE);
List<InstanceMetaData> instancesRandomNotStopped = generateInstances(3, 300, InstanceStatus.SERVICES_HEALTHY, INSTANCE_GROUP_NAME_RANDOM);
List<InstanceMetaData> instancesRandomStopped = generateInstances(8, 400, InstanceStatus.STOPPED, INSTANCE_GROUP_NAME_RANDOM);
List<InstanceMetaData> allInstancesInHgMdList = new LinkedList<>();
allInstancesInHgMdList.addAll(instancesActionableStopped);
allInstancesInHgMdList.addAll(instancesActionableNotStopped);
List<CloudInstance> stoppedInstancesInHgList = convertToCloudInstance(instancesActionableStopped);
List<CloudInstance> allInstancesInHgList = convertToCloudInstance(allInstancesInHgMdList);
StopStartUpscaleStartInstancesRequest startInstancesRequest = new StopStartUpscaleStartInstancesRequest(cloudContext, cloudCredential, cloudStack, INSTANCE_GROUP_NAME_ACTIONABLE, stoppedInstancesInHgList, allInstancesInHgList, Collections.emptyList(), stopStartUpscaleContext.getAdjustment());
List<CloudVmInstanceStatus> affectedInstances = constructVmInstanceStatusWithTerminated(stoppedInstancesInHgList, adjustment, 2);
int expectedCount = adjustment - 2;
StopStartUpscaleStartInstancesResult payload = new StopStartUpscaleStartInstancesResult(STACK_ID, startInstancesRequest, affectedInstances);
// Mocks
mockStackEtc(instancesActionableNotStopped, instancesActionableStopped, instancesRandomNotStopped, instancesRandomStopped);
when(reactorEventFactory.createEvent(anyMap(), isNotNull())).thenReturn(event);
new AbstractActionTestSupport<>(action).doExecute(stopStartUpscaleContext, payload, Collections.emptyMap());
ArgumentCaptor<List> instancesCaptor = ArgumentCaptor.forClass(List.class);
verify(stopStartUpscaleFlowService).instancesStarted(eq(STACK_ID), instancesCaptor.capture());
Assert.assertEquals(expectedCount, instancesCaptor.getValue().size());
verify(stopStartUpscaleFlowService).logInstancesFailedToStart(eq(STACK_ID), instancesCaptor.capture());
Assert.assertEquals(2, instancesCaptor.getValue().size());
verify(stopStartUpscaleFlowService).warnNotEnoughInstances(eq(STACK_ID), eq(INSTANCE_GROUP_NAME_ACTIONABLE), eq(adjustment), eq(expectedCount));
verify(stopStartUpscaleFlowService).upscaleCommissioningNodes(eq(STACK_ID), eq(INSTANCE_GROUP_NAME_ACTIONABLE), instancesCaptor.capture(), eq(Collections.emptyList()));
Assert.assertEquals(expectedCount, instancesCaptor.getValue().size());
verifyNoMoreInteractions(stopStartUpscaleFlowService);
ArgumentCaptor<Object> argumentCaptor = ArgumentCaptor.forClass(Object.class);
verify(reactorEventFactory).createEvent(anyMap(), argumentCaptor.capture());
verify(eventBus).notify("STOPSTARTUPSCALECOMMISSIONVIACMREQUEST", event);
assertThat(argumentCaptor.getValue()).isInstanceOf(StopStartUpscaleCommissionViaCMRequest.class);
StopStartUpscaleCommissionViaCMRequest req = (StopStartUpscaleCommissionViaCMRequest) argumentCaptor.getValue();
Assert.assertEquals(expectedCount, req.getStartedInstancesToCommission().size());
}
use of com.sequenceiq.cloudbreak.reactor.api.event.cluster.StopStartUpscaleCommissionViaCMRequest in project cloudbreak by hortonworks.
the class StopStartUpscaleActionsTest method testCmCommissionAction.
@Test
void testCmCommissionAction() throws Exception {
// Simple scenario. Adequate instances. Everything started etc.
AbstractStopStartUpscaleActions<StopStartUpscaleStartInstancesResult> action = (AbstractStopStartUpscaleActions<StopStartUpscaleStartInstancesResult>) underTest.cmCommissionAction();
initActionPrivateFields(action);
int adjustment = 5;
StopStartUpscaleContext stopStartUpscaleContext = createContext(adjustment);
List<InstanceMetaData> instancesActionableNotStopped = generateInstances(5, 100, InstanceStatus.SERVICES_HEALTHY, INSTANCE_GROUP_NAME_ACTIONABLE);
List<InstanceMetaData> instancesActionableStopped = generateInstances(10, 200, InstanceStatus.STOPPED, INSTANCE_GROUP_NAME_ACTIONABLE);
List<InstanceMetaData> instancesRandomNotStopped = generateInstances(3, 300, InstanceStatus.SERVICES_HEALTHY, INSTANCE_GROUP_NAME_RANDOM);
List<InstanceMetaData> instancesRandomStopped = generateInstances(8, 400, InstanceStatus.STOPPED, INSTANCE_GROUP_NAME_RANDOM);
List<InstanceMetaData> allInstancesInHgMdList = new LinkedList<>();
allInstancesInHgMdList.addAll(instancesActionableStopped);
allInstancesInHgMdList.addAll(instancesActionableNotStopped);
List<CloudInstance> stoppedInstancesInHgList = convertToCloudInstance(instancesActionableStopped);
List<CloudInstance> allInstancesInHgList = convertToCloudInstance(allInstancesInHgMdList);
StopStartUpscaleStartInstancesRequest startInstancesRequest = new StopStartUpscaleStartInstancesRequest(cloudContext, cloudCredential, cloudStack, INSTANCE_GROUP_NAME_ACTIONABLE, stoppedInstancesInHgList, allInstancesInHgList, Collections.emptyList(), stopStartUpscaleContext.getAdjustment());
List<CloudVmInstanceStatus> affectedInstances = constructStartedCloudVmInstanceStatus(stoppedInstancesInHgList, adjustment);
StopStartUpscaleStartInstancesResult payload = new StopStartUpscaleStartInstancesResult(STACK_ID, startInstancesRequest, affectedInstances);
// Mocks
mockStackEtc(instancesActionableNotStopped, instancesActionableStopped, instancesRandomNotStopped, instancesRandomStopped);
when(reactorEventFactory.createEvent(anyMap(), isNotNull())).thenReturn(event);
new AbstractActionTestSupport<>(action).doExecute(stopStartUpscaleContext, payload, Collections.emptyMap());
ArgumentCaptor<List> instancesCaptor = ArgumentCaptor.forClass(List.class);
verify(stopStartUpscaleFlowService).instancesStarted(eq(STACK_ID), instancesCaptor.capture());
Assert.assertEquals(adjustment, instancesCaptor.getValue().size());
verify(stopStartUpscaleFlowService).upscaleCommissioningNodes(eq(STACK_ID), eq(INSTANCE_GROUP_NAME_ACTIONABLE), instancesCaptor.capture(), eq(Collections.emptyList()));
Assert.assertEquals(adjustment, instancesCaptor.getValue().size());
verifyNoMoreInteractions(stopStartUpscaleFlowService);
ArgumentCaptor<Object> argumentCaptor = ArgumentCaptor.forClass(Object.class);
verify(reactorEventFactory).createEvent(anyMap(), argumentCaptor.capture());
verify(eventBus).notify("STOPSTARTUPSCALECOMMISSIONVIACMREQUEST", event);
assertThat(argumentCaptor.getValue()).isInstanceOf(StopStartUpscaleCommissionViaCMRequest.class);
StopStartUpscaleCommissionViaCMRequest req = (StopStartUpscaleCommissionViaCMRequest) argumentCaptor.getValue();
Assert.assertEquals(adjustment, req.getStartedInstancesToCommission().size());
}
use of com.sequenceiq.cloudbreak.reactor.api.event.cluster.StopStartUpscaleCommissionViaCMRequest in project cloudbreak by hortonworks.
the class StopStartUpscaleCommissionViaCMHandlerTest method testCmHasMissingNodes.
@Test
void testCmHasMissingNodes() throws ClusterClientInitException {
int commissionInstanceCount = 5;
List<InstanceMetaData> instancesToCommission = createInstancesToCommission(commissionInstanceCount);
HostGroup hostGroup = createHostGroup(instancesToCommission);
Set<String> hostNames = instancesToCommission.stream().map(i -> i.getDiscoveryFQDN()).collect(Collectors.toSet());
Map<String, InstanceMetaData> cmAvailableHosts = instancesToCommission.stream().limit(commissionInstanceCount - 1).collect(Collectors.toMap(i -> i.getDiscoveryFQDN(), i -> i));
Set<String> recommissionedFqdns = cmAvailableHosts.keySet().stream().collect(Collectors.toUnmodifiableSet());
setupPerTestMocks(hostGroup, hostNames, cmAvailableHosts, recommissionedFqdns);
StopStartUpscaleCommissionViaCMRequest request = new StopStartUpscaleCommissionViaCMRequest(1L, INSTANCE_GROUP_NAME, instancesToCommission, Collections.emptyList());
HandlerEvent handlerEvent = new HandlerEvent(Event.wrap(request));
Selectable selectable = underTest.doAccept(handlerEvent);
assertThat(selectable).isInstanceOf(StopStartUpscaleCommissionViaCMResult.class);
StopStartUpscaleCommissionViaCMResult result = (StopStartUpscaleCommissionViaCMResult) selectable;
assertThat(result.getNotRecommissionedFqdns()).hasSize(1);
assertThat(result.getSuccessfullyCommissionedFqdns()).hasSize(commissionInstanceCount - 1);
}
use of com.sequenceiq.cloudbreak.reactor.api.event.cluster.StopStartUpscaleCommissionViaCMRequest in project cloudbreak by hortonworks.
the class StopStartUpscaleCommissionViaCMHandlerTest method testErrorFromWaitForHostsHealthy.
@Test
void testErrorFromWaitForHostsHealthy() throws ClusterClientInitException {
int commissionInstanceCount = 5;
List<InstanceMetaData> instancesToCommission = createInstancesToCommission(commissionInstanceCount);
HostGroup hostGroup = createHostGroup(instancesToCommission);
Set<String> hostNames = instancesToCommission.stream().map(i -> i.getDiscoveryFQDN()).collect(Collectors.toSet());
Map<String, InstanceMetaData> cmAvailableHosts = instancesToCommission.stream().collect(Collectors.toMap(i -> i.getDiscoveryFQDN(), i -> i));
Set<String> recommissionedFqdns = cmAvailableHosts.keySet().stream().collect(Collectors.toUnmodifiableSet());
setupPerTestMocks(hostGroup, hostNames, cmAvailableHosts, recommissionedFqdns);
doThrow(new RuntimeException("waitForHostsHealthyException")).when(clusterSetupService).waitForHostsHealthy(anySet());
StopStartUpscaleCommissionViaCMRequest request = new StopStartUpscaleCommissionViaCMRequest(1L, INSTANCE_GROUP_NAME, instancesToCommission, Collections.emptyList());
HandlerEvent handlerEvent = new HandlerEvent(Event.wrap(request));
Selectable selectable = underTest.doAccept(handlerEvent);
assertThat(selectable).isInstanceOf(StopStartUpscaleCommissionViaCMResult.class);
StopStartUpscaleCommissionViaCMResult result = (StopStartUpscaleCommissionViaCMResult) selectable;
assertThat(result.getSuccessfullyCommissionedFqdns()).hasSize(0);
assertThat(result.getNotRecommissionedFqdns()).hasSize(0);
assertThat(result.getErrorDetails().getMessage()).isEqualTo("waitForHostsHealthyException");
assertThat(result.getStatus()).isEqualTo(EventStatus.FAILED);
assertThat(result.selector()).isEqualTo("STOPSTARTUPSCALECOMMISSIONVIACMRESULT_ERROR");
}
use of com.sequenceiq.cloudbreak.reactor.api.event.cluster.StopStartUpscaleCommissionViaCMRequest in project cloudbreak by hortonworks.
the class StopStartUpscaleCommissionViaCMHandlerTest method testCmCommissionReturnsFewerNodes.
@Test
void testCmCommissionReturnsFewerNodes() throws ClusterClientInitException {
int commissionInstanceCount = 5;
List<InstanceMetaData> instancesToCommission = createInstancesToCommission(commissionInstanceCount);
HostGroup hostGroup = createHostGroup(instancesToCommission);
Set<String> hostNames = instancesToCommission.stream().map(i -> i.getDiscoveryFQDN()).collect(Collectors.toSet());
Map<String, InstanceMetaData> cmAvailableHosts = instancesToCommission.stream().collect(Collectors.toMap(i -> i.getDiscoveryFQDN(), i -> i));
Set<String> recommissionedFqdns = cmAvailableHosts.keySet().stream().limit(commissionInstanceCount - 1).collect(Collectors.toUnmodifiableSet());
setupPerTestMocks(hostGroup, hostNames, cmAvailableHosts, recommissionedFqdns);
StopStartUpscaleCommissionViaCMRequest request = new StopStartUpscaleCommissionViaCMRequest(1L, INSTANCE_GROUP_NAME, instancesToCommission, Collections.emptyList());
HandlerEvent handlerEvent = new HandlerEvent(Event.wrap(request));
Selectable selectable = underTest.doAccept(handlerEvent);
assertThat(selectable).isInstanceOf(StopStartUpscaleCommissionViaCMResult.class);
StopStartUpscaleCommissionViaCMResult result = (StopStartUpscaleCommissionViaCMResult) selectable;
assertThat(result.getNotRecommissionedFqdns()).hasSize(1);
assertThat(result.getSuccessfullyCommissionedFqdns()).hasSize(commissionInstanceCount - 1);
}
Aggregations