use of com.sequenceiq.cloudbreak.cloud.event.instance.StopStartUpscaleStartInstancesRequest in project cloudbreak by hortonworks.
the class StopStartUpscaleActionsTest method testStartInstancesAction.
@Test
void testStartInstancesAction() throws Exception {
AbstractStopStartUpscaleActions<StopStartUpscaleTriggerEvent> action = (AbstractStopStartUpscaleActions<StopStartUpscaleTriggerEvent>) underTest.startInstancesAction();
initActionPrivateFields(action);
StopStartUpscaleContext stopStartUpscaleContext = createContext(5);
StopStartUpscaleTriggerEvent payload = new StopStartUpscaleTriggerEvent(SELECTOR, STACK_ID, INSTANCE_GROUP_NAME_ACTIONABLE, 5, ClusterManagerType.CLOUDERA_MANAGER);
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);
// Mocks
mockStackEtc(instancesActionableNotStopped, instancesActionableStopped, instancesRandomNotStopped, instancesRandomStopped);
when(reactorEventFactory.createEvent(anyMap(), isNotNull())).thenReturn(event);
new AbstractActionTestSupport<>(action).doExecute(stopStartUpscaleContext, payload, Collections.emptyMap());
verify(stopStartUpscaleFlowService).startingInstances(eq(STACK_ID), eq(INSTANCE_GROUP_NAME_ACTIONABLE), eq(5));
ArgumentCaptor<Object> argumentCaptor = ArgumentCaptor.forClass(Object.class);
verify(reactorEventFactory).createEvent(anyMap(), argumentCaptor.capture());
verify(eventBus).notify("STOPSTARTUPSCALESTARTINSTANCESREQUEST", event);
assertThat(argumentCaptor.getValue()).isInstanceOf(StopStartUpscaleStartInstancesRequest.class);
verify(instanceMetaDataToCloudInstanceConverter, times(2)).convert(anyCollection(), anyString(), any(StackAuthentication.class));
StopStartUpscaleStartInstancesRequest req = (StopStartUpscaleStartInstancesRequest) argumentCaptor.getValue();
Assert.assertEquals(15, req.getAllInstancesInHg().size());
Assert.assertEquals(10, req.getStoppedCloudInstancesInHg().size());
}
use of com.sequenceiq.cloudbreak.cloud.event.instance.StopStartUpscaleStartInstancesRequest 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.cloud.event.instance.StopStartUpscaleStartInstancesRequest 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.cloud.event.instance.StopStartUpscaleStartInstancesRequest in project cloudbreak by hortonworks.
the class StopStartUpscaleStartInstancesHandlerTest method testCloudProviderInstancesInTerminatedEtcStateDuringStartInternal.
private void testCloudProviderInstancesInTerminatedEtcStateDuringStartInternal(int cbStoppedInstanceCount, int numInstancesToStart) {
// This assumes behaviour on the CloudConnector API to ignore certain TERMINAL states, and provide information back on the
// instances with the state set. If that is not the behaviour (to be verified manually) - this test is pointless.
List<CloudInstance> stoppedInstancesInHg = generateCloudInstances(cbStoppedInstanceCount);
List<CloudInstance> allInstancesInHg = generateCloudInstances(10);
List<CloudInstance> startedInstancesWithServicesNotRunning = null;
int expectedInstances = Math.min(cbStoppedInstanceCount, numInstancesToStart);
StopStartUpscaleStartInstancesRequest request = new StopStartUpscaleStartInstancesRequest(cloudContext, cloudCredential, cloudStack, "compute", stoppedInstancesInHg, allInstancesInHg, startedInstancesWithServicesNotRunning, numInstancesToStart);
List<CloudInstance> stoppedInstancesArg = stoppedInstancesInHg.subList(0, expectedInstances);
List<CloudVmInstanceStatus> stoppedInstanceStatusList = generateStoppedCloudVmInstanceStatuses(stoppedInstancesInHg);
List<CloudVmInstanceStatus> startedInstanceStatusList = generateStartedCloudVmInstanceStatusesIncludingOtherStates(stoppedInstancesArg);
when(instanceConnector.checkWithoutRetry(any(AuthenticatedContext.class), eq(stoppedInstancesArg))).thenReturn(stoppedInstanceStatusList);
when(instanceConnector.startWithLimitedRetry(any(AuthenticatedContext.class), eq(null), eq(stoppedInstancesArg), any(Long.class))).thenReturn(startedInstanceStatusList);
Event event = new Event(request);
underTest.accept(event);
ArgumentCaptor<Event> resultCaptor = ArgumentCaptor.forClass(Event.class);
verify(eventBus).notify(any(Object.class), resultCaptor.capture());
verify(instanceConnector).checkWithoutRetry(any(AuthenticatedContext.class), eq(stoppedInstancesArg));
verify(instanceConnector).startWithLimitedRetry(any(AuthenticatedContext.class), eq(null), eq(stoppedInstancesInHg.subList(0, expectedInstances)), any(Long.class));
verifyNoMoreInteractions(instanceConnector);
assertEquals(1, resultCaptor.getAllValues().size());
Event resultEvent = resultCaptor.getValue();
assertEquals(StopStartUpscaleStartInstancesResult.class, resultEvent.getData().getClass());
StopStartUpscaleStartInstancesResult result = (StopStartUpscaleStartInstancesResult) resultEvent.getData();
verifyAffectedInstancesInResult3(stoppedInstancesInHg.subList(0, expectedInstances), result.getAffectedInstanceStatuses());
}
use of com.sequenceiq.cloudbreak.cloud.event.instance.StopStartUpscaleStartInstancesRequest in project cloudbreak by hortonworks.
the class StopStartUpscaleStartInstancesHandlerTest method testZeroInstancesToStart.
@Test
void testZeroInstancesToStart() {
List<CloudInstance> stoppedInstancesInHg = generateCloudInstances(5);
List<CloudInstance> allInstancesInHg = generateCloudInstances(10);
List<CloudInstance> startedInstancesWithServicesNotRunning = null;
int numInstancesToStart = 0;
StopStartUpscaleStartInstancesRequest request = new StopStartUpscaleStartInstancesRequest(cloudContext, cloudCredential, cloudStack, "compute", stoppedInstancesInHg, allInstancesInHg, startedInstancesWithServicesNotRunning, numInstancesToStart);
Event event = new Event(request);
underTest.accept(event);
ArgumentCaptor<Event> resultCaptor = ArgumentCaptor.forClass(Event.class);
verify(eventBus).notify(any(Object.class), resultCaptor.capture());
verifyNoMoreInteractions(instanceConnector);
assertEquals(1, resultCaptor.getAllValues().size());
Event resultEvent = resultCaptor.getValue();
assertEquals(StopStartUpscaleStartInstancesResult.class, resultEvent.getData().getClass());
StopStartUpscaleStartInstancesResult result = (StopStartUpscaleStartInstancesResult) resultEvent.getData();
assertEquals(0, result.getAffectedInstanceStatuses().size());
}
Aggregations