use of com.sequenceiq.cloudbreak.core.flow2.cluster.stopstartds.StopStartDownscaleEvent.STOPSTART_DOWNSCALE_FINALIZED_EVENT in project cloudbreak by hortonworks.
the class StopStartDownscaleActionsTest method testDownscaleFinishedActionNotAllStopped.
@Test
void testDownscaleFinishedActionNotAllStopped() throws Exception {
AbstractStopStartDownscaleActions<StopStartDownscaleStopInstancesResult> action = (AbstractStopStartDownscaleActions<StopStartDownscaleStopInstancesResult>) underTest.downscaleFinishedAction();
initActionPrivateFields(action);
List<InstanceMetaData> instancesActionableStarted = generateInstances(10, 100, InstanceStatus.SERVICES_HEALTHY, INSTANCE_GROUP_NAME_ACTIONABLE);
List<InstanceMetaData> instancesActionableNotStarted = generateInstances(5, 200, InstanceStatus.STOPPED, INSTANCE_GROUP_NAME_ACTIONABLE);
List<InstanceMetaData> instancesRandomStarted = generateInstances(8, 300, InstanceStatus.SERVICES_HEALTHY, INSTANCE_GROUP_NAME_RANDOM);
List<InstanceMetaData> instancesRandomNotStarted = generateInstances(3, 400, InstanceStatus.STOPPED, INSTANCE_GROUP_NAME_RANDOM);
List<InstanceMetaData> expectedToBeStopped = instancesActionableStarted.stream().limit(5).collect(Collectors.toList());
Set<Long> instanceIdsToRemove = expectedToBeStopped.stream().map(InstanceMetaData::getId).collect(Collectors.toUnmodifiableSet());
StopStartDownscaleContext stopStartDownscaleContext = createContext(instanceIdsToRemove);
mockStackEtc(instancesActionableStarted, instancesActionableNotStarted, instancesRandomStarted, instancesRandomNotStarted);
List<CloudInstance> expectedCloudInstances = mockInstanceMetadataToCloudInstanceConverter(expectedToBeStopped);
List<CloudVmInstanceStatus> cloudVmInstanceStatusList = constructMixedCloudVmInstanceStatus(expectedCloudInstances);
when(reactorEventFactory.createEvent(anyMap(), isNotNull())).thenReturn(event);
StopStartDownscaleStopInstancesResult payload = new StopStartDownscaleStopInstancesResult(STACK_ID, mock(StopStartDownscaleStopInstancesRequest.class), cloudVmInstanceStatusList);
new AbstractActionTestSupport<>(action).doExecute(stopStartDownscaleContext, payload, Collections.emptyMap());
ArgumentCaptor<List> listCap = ArgumentCaptor.forClass(List.class);
verify(stopStartDownscaleFlowService).instancesStopped(eq(STACK_ID), listCap.capture());
assertThat(new HashSet<>(listCap.getValue())).isEqualTo(new HashSet<>(expectedToBeStopped.subList(1, 5)));
verify(stopStartDownscaleFlowService).clusterDownscaleFinished(eq(STACK_ID), eq(INSTANCE_GROUP_NAME_ACTIONABLE), listCap.capture());
assertThat(new HashSet<>(listCap.getValue())).isEqualTo(new HashSet<>(expectedToBeStopped.subList(1, 5)));
verify(stopStartDownscaleFlowService).logInstancesFailedToStop(eq(STACK_ID), eq(cloudVmInstanceStatusList.subList(0, 1)));
verifyNoMoreInteractions(stopStartDownscaleFlowService);
ArgumentCaptor<Object> argumentCaptor = ArgumentCaptor.forClass(Object.class);
verify(reactorEventFactory).createEvent(anyMap(), argumentCaptor.capture());
verify(eventBus).notify("STOPSTART_DOWNSCALE_FINALIZED_EVENT", event);
assertThat(argumentCaptor.getValue()).isInstanceOf(StopStartDownscaleStopInstancesResult.class);
}
use of com.sequenceiq.cloudbreak.core.flow2.cluster.stopstartds.StopStartDownscaleEvent.STOPSTART_DOWNSCALE_FINALIZED_EVENT in project cloudbreak by hortonworks.
the class StopStartDownscaleActionsTest method testDownscaleFinishedActionAllStopped.
@Test
void testDownscaleFinishedActionAllStopped() throws Exception {
AbstractStopStartDownscaleActions<StopStartDownscaleStopInstancesResult> action = (AbstractStopStartDownscaleActions<StopStartDownscaleStopInstancesResult>) underTest.downscaleFinishedAction();
initActionPrivateFields(action);
List<InstanceMetaData> instancesActionableStarted = generateInstances(10, 100, InstanceStatus.SERVICES_HEALTHY, INSTANCE_GROUP_NAME_ACTIONABLE);
List<InstanceMetaData> instancesActionableNotStarted = generateInstances(5, 200, InstanceStatus.STOPPED, INSTANCE_GROUP_NAME_ACTIONABLE);
List<InstanceMetaData> instancesRandomStarted = generateInstances(8, 300, InstanceStatus.SERVICES_HEALTHY, INSTANCE_GROUP_NAME_RANDOM);
List<InstanceMetaData> instancesRandomNotStarted = generateInstances(3, 400, InstanceStatus.STOPPED, INSTANCE_GROUP_NAME_RANDOM);
List<InstanceMetaData> expectedToBeStopped = instancesActionableStarted.stream().limit(5).collect(Collectors.toList());
Set<Long> instanceIdsToRemove = expectedToBeStopped.stream().map(InstanceMetaData::getId).collect(Collectors.toUnmodifiableSet());
StopStartDownscaleContext stopStartDownscaleContext = createContext(instanceIdsToRemove);
mockStackEtc(instancesActionableStarted, instancesActionableNotStarted, instancesRandomStarted, instancesRandomNotStarted);
List<CloudInstance> expectedCloudInstances = mockInstanceMetadataToCloudInstanceConverter(expectedToBeStopped);
List<CloudVmInstanceStatus> cloudVmInstanceStatusList = constructStoppedCloudVmInstanceStatus(expectedCloudInstances);
when(reactorEventFactory.createEvent(anyMap(), isNotNull())).thenReturn(event);
StopStartDownscaleStopInstancesResult payload = new StopStartDownscaleStopInstancesResult(STACK_ID, mock(StopStartDownscaleStopInstancesRequest.class), cloudVmInstanceStatusList);
new AbstractActionTestSupport<>(action).doExecute(stopStartDownscaleContext, payload, Collections.emptyMap());
ArgumentCaptor<List> listCap = ArgumentCaptor.forClass(List.class);
verify(stopStartDownscaleFlowService).instancesStopped(eq(STACK_ID), listCap.capture());
assertThat(new HashSet<>(listCap.getValue())).isEqualTo(new HashSet<>(expectedToBeStopped));
verify(stopStartDownscaleFlowService).clusterDownscaleFinished(eq(STACK_ID), eq(INSTANCE_GROUP_NAME_ACTIONABLE), listCap.capture());
assertThat(new HashSet<>(listCap.getValue())).isEqualTo(new HashSet<>(expectedToBeStopped));
verifyNoMoreInteractions(stopStartDownscaleFlowService);
ArgumentCaptor<Object> argumentCaptor = ArgumentCaptor.forClass(Object.class);
verify(reactorEventFactory).createEvent(anyMap(), argumentCaptor.capture());
verify(eventBus).notify("STOPSTART_DOWNSCALE_FINALIZED_EVENT", event);
assertThat(argumentCaptor.getValue()).isInstanceOf(StopStartDownscaleStopInstancesResult.class);
}
Aggregations