Search in sources :

Example 11 with StopStartDownscaleDecommissionViaCMRequest

use of com.sequenceiq.cloudbreak.reactor.api.event.cluster.StopStartDownscaleDecommissionViaCMRequest in project cloudbreak by hortonworks.

the class StopStartDownscaleActionsTest method testStopInstancesActionNoneDecommissioned.

@Test
void testStopInstancesActionNoneDecommissioned() throws Exception {
    // This behaviour is not ideal. Letting 0 stopped flow through the actual state machine instead of short-circuiting it.
    AbstractStopStartDownscaleActions<StopStartDownscaleDecommissionViaCMResult> action = (AbstractStopStartDownscaleActions<StopStartDownscaleDecommissionViaCMResult>) underTest.stopInstancesAction();
    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);
    Set<Long> instanceIdsToRemove = instancesActionableStarted.stream().limit(6).map(InstanceMetaData::getId).collect(Collectors.toUnmodifiableSet());
    List<InstanceMetaData> expectedToBeStopped = Collections.emptyList();
    Set<String> decommissionedHostsFqdns = Collections.emptySet();
    List<InstanceMetaData> notDecommissioned = instancesActionableStarted.subList(0, 6);
    List<String> notDecommissionedFqdns = notDecommissioned.stream().map(InstanceMetaData::getDiscoveryFQDN).collect(Collectors.toUnmodifiableList());
    StopStartDownscaleContext stopStartDownscaleContext = createContext(instanceIdsToRemove);
    StopStartDownscaleDecommissionViaCMRequest r = new StopStartDownscaleDecommissionViaCMRequest(1L, INSTANCE_GROUP_NAME_ACTIONABLE, instanceIdsToRemove);
    StopStartDownscaleDecommissionViaCMResult payload = new StopStartDownscaleDecommissionViaCMResult(r, decommissionedHostsFqdns, notDecommissionedFqdns);
    mockStackEtc(instancesActionableStarted, instancesActionableNotStarted, instancesRandomStarted, instancesRandomNotStarted);
    List<CloudInstance> expectedCloudInstances = mockInstanceMetadataToCloudInstanceConverter(expectedToBeStopped);
    when(reactorEventFactory.createEvent(anyMap(), isNotNull())).thenReturn(event);
    new AbstractActionTestSupport<>(action).doExecute(stopStartDownscaleContext, payload, Collections.emptyMap());
    verify(instanceMetaDataToCloudInstanceConverter).convert(eq(expectedToBeStopped), anyString(), any(StackAuthentication.class));
    verify(stopStartDownscaleFlowService).logCouldNotDecommission(eq(STACK_ID), eq(notDecommissionedFqdns));
    verify(stopStartDownscaleFlowService).clusterDownscalingStoppingInstances(eq(STACK_ID), eq(INSTANCE_GROUP_NAME_ACTIONABLE), eq(decommissionedHostsFqdns));
    verifyNoMoreInteractions(stopStartDownscaleFlowService);
    ArgumentCaptor<Object> argumentCaptor = ArgumentCaptor.forClass(Object.class);
    verify(reactorEventFactory).createEvent(anyMap(), argumentCaptor.capture());
    verify(eventBus).notify("STOPSTARTDOWNSCALESTOPINSTANCESREQUEST", event);
    assertThat(argumentCaptor.getValue()).isInstanceOf(StopStartDownscaleStopInstancesRequest.class);
    StopStartDownscaleStopInstancesRequest req = (StopStartDownscaleStopInstancesRequest) argumentCaptor.getValue();
    Assert.assertEquals(expectedCloudInstances, req.getCloudInstancesToStop());
}
Also used : StopStartDownscaleDecommissionViaCMResult(com.sequenceiq.cloudbreak.reactor.api.event.orchestration.StopStartDownscaleDecommissionViaCMResult) StackAuthentication(com.sequenceiq.cloudbreak.domain.StackAuthentication) StopStartDownscaleStopInstancesRequest(com.sequenceiq.cloudbreak.cloud.event.instance.StopStartDownscaleStopInstancesRequest) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) StopStartDownscaleDecommissionViaCMRequest(com.sequenceiq.cloudbreak.reactor.api.event.cluster.StopStartDownscaleDecommissionViaCMRequest) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) AbstractStopStartDownscaleActions(com.sequenceiq.cloudbreak.core.flow2.cluster.stopstartds.StopStartDownscaleActions.AbstractStopStartDownscaleActions) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) Test(org.junit.jupiter.api.Test)

Aggregations

InstanceMetaData (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData)11 StopStartDownscaleDecommissionViaCMRequest (com.sequenceiq.cloudbreak.reactor.api.event.cluster.StopStartDownscaleDecommissionViaCMRequest)11 StopStartDownscaleDecommissionViaCMResult (com.sequenceiq.cloudbreak.reactor.api.event.orchestration.StopStartDownscaleDecommissionViaCMResult)10 Test (org.junit.jupiter.api.Test)10 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)9 UPDATE_IN_PROGRESS (com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status.UPDATE_IN_PROGRESS)7 InstanceStatus (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus)7 ClusterDecomissionService (com.sequenceiq.cloudbreak.cluster.api.ClusterDecomissionService)7 Selectable (com.sequenceiq.cloudbreak.common.event.Selectable)7 CloudbreakFlowMessageService (com.sequenceiq.cloudbreak.core.flow2.stack.CloudbreakFlowMessageService)7 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)7 Cluster (com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster)7 HostGroup (com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup)7 CLUSTER_SCALING_STOPSTART_DOWNSCALE_ENTEREDCMMAINTMODE (com.sequenceiq.cloudbreak.event.ResourceEvent.CLUSTER_SCALING_STOPSTART_DOWNSCALE_ENTEREDCMMAINTMODE)7 CLUSTER_SCALING_STOPSTART_DOWNSCALE_ENTERINGCMMAINTMODE (com.sequenceiq.cloudbreak.event.ResourceEvent.CLUSTER_SCALING_STOPSTART_DOWNSCALE_ENTERINGCMMAINTMODE)7 ClusterApiConnectors (com.sequenceiq.cloudbreak.service.cluster.ClusterApiConnectors)7 HostGroupService (com.sequenceiq.cloudbreak.service.hostgroup.HostGroupService)7 InstanceMetaDataService (com.sequenceiq.cloudbreak.service.stack.InstanceMetaDataService)7 StackService (com.sequenceiq.cloudbreak.service.stack.StackService)7 HandlerEvent (com.sequenceiq.flow.reactor.api.handler.HandlerEvent)7