Search in sources :

Example 1 with StopStartDownscaleStopInstancesResult

use of com.sequenceiq.cloudbreak.cloud.event.instance.StopStartDownscaleStopInstancesResult in project cloudbreak by hortonworks.

the class StopStartDownscaleActions method stopInstancesFailedAction.

@Bean(name = "STOPSTART_DOWNSCALE_STOP_INSTANCES_FAILED_STATE")
public Action<?, ?> stopInstancesFailedAction() {
    return new AbstractStopStartDownscaleActions<>(StopStartDownscaleStopInstancesResult.class) {

        @Override
        protected void doExecute(StopStartDownscaleContext context, StopStartDownscaleStopInstancesResult payload, Map<Object, Object> variables) throws Exception {
            LOGGER.warn("Failure during the stopInstancesOnCloudProvider step");
            // TODO CB-14929. Should the nodes be put into an ORCHESTRATOR_FAILED state? What are the manual recovery steps from this state.
            stopStartDownscaleFlowService.stopInstancesFailed(payload.getResourceId(), payload.getStopInstancesRequest().getCloudInstancesToStop());
            sendEvent(context, STOPSTART_DOWNSCALE_FAILURE_EVENT.event(), new StackFailureEvent(payload.getResourceId(), payload.getErrorDetails()));
        }
    };
}
Also used : StackFailureEvent(com.sequenceiq.cloudbreak.reactor.api.event.StackFailureEvent) StopStartDownscaleStopInstancesResult(com.sequenceiq.cloudbreak.cloud.event.instance.StopStartDownscaleStopInstancesResult) Map(java.util.Map) Bean(org.springframework.context.annotation.Bean)

Example 2 with StopStartDownscaleStopInstancesResult

use of com.sequenceiq.cloudbreak.cloud.event.instance.StopStartDownscaleStopInstancesResult 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);
}
Also used : StopStartDownscaleStopInstancesRequest(com.sequenceiq.cloudbreak.cloud.event.instance.StopStartDownscaleStopInstancesRequest) CloudVmInstanceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus) StopStartDownscaleStopInstancesResult(com.sequenceiq.cloudbreak.cloud.event.instance.StopStartDownscaleStopInstancesResult) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) AbstractStopStartDownscaleActions(com.sequenceiq.cloudbreak.core.flow2.cluster.stopstartds.StopStartDownscaleActions.AbstractStopStartDownscaleActions) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 3 with StopStartDownscaleStopInstancesResult

use of com.sequenceiq.cloudbreak.cloud.event.instance.StopStartDownscaleStopInstancesResult 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);
}
Also used : StopStartDownscaleStopInstancesRequest(com.sequenceiq.cloudbreak.cloud.event.instance.StopStartDownscaleStopInstancesRequest) CloudVmInstanceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus) StopStartDownscaleStopInstancesResult(com.sequenceiq.cloudbreak.cloud.event.instance.StopStartDownscaleStopInstancesResult) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) AbstractStopStartDownscaleActions(com.sequenceiq.cloudbreak.core.flow2.cluster.stopstartds.StopStartDownscaleActions.AbstractStopStartDownscaleActions) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 4 with StopStartDownscaleStopInstancesResult

use of com.sequenceiq.cloudbreak.cloud.event.instance.StopStartDownscaleStopInstancesResult in project cloudbreak by hortonworks.

the class StopStartDownscaleStopInstancesHandlerTest method testExpectedResultInernal.

private void testExpectedResultInernal(List<CloudInstance> cloudInstancesToStop, List<CloudVmInstanceStatus> cloudConnectoReturnList, boolean expectedCloudInteractions) {
    StopStartDownscaleStopInstancesRequest request = new StopStartDownscaleStopInstancesRequest(cloudContext, cloudCredential, cloudStack, cloudInstancesToStop);
    lenient().when(instanceConnector.stopWithLimitedRetry(any(AuthenticatedContext.class), eq(null), eq(cloudInstancesToStop), any(Long.class))).thenReturn(cloudConnectoReturnList);
    Event event = new Event(request);
    underTest.accept(event);
    ArgumentCaptor<Event> resultCaptor = ArgumentCaptor.forClass(Event.class);
    verify(eventBus).notify(any(Object.class), resultCaptor.capture());
    if (expectedCloudInteractions) {
        verify(instanceConnector).stopWithLimitedRetry(any(AuthenticatedContext.class), eq(null), eq(cloudInstancesToStop), eq(EXPECTED_STOP_POLL_TIMEBOUND_MS));
    }
    verifyNoMoreInteractions(instanceConnector);
    assertEquals(1, resultCaptor.getAllValues().size());
    Event resultEvent = resultCaptor.getValue();
    assertEquals(StopStartDownscaleStopInstancesResult.class, resultEvent.getData().getClass());
    StopStartDownscaleStopInstancesResult result = (StopStartDownscaleStopInstancesResult) resultEvent.getData();
    assertEquals(cloudConnectoReturnList, result.getAffectedInstanceStatuses());
}
Also used : StopStartDownscaleStopInstancesRequest(com.sequenceiq.cloudbreak.cloud.event.instance.StopStartDownscaleStopInstancesRequest) Event(reactor.bus.Event) StopStartDownscaleStopInstancesResult(com.sequenceiq.cloudbreak.cloud.event.instance.StopStartDownscaleStopInstancesResult) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)

Example 5 with StopStartDownscaleStopInstancesResult

use of com.sequenceiq.cloudbreak.cloud.event.instance.StopStartDownscaleStopInstancesResult in project cloudbreak by hortonworks.

the class StopStartDownscaleStopInstancesHandlerTest method testFailureFromCloudProviderWhenStoppingInstances.

@Test
void testFailureFromCloudProviderWhenStoppingInstances() {
    List<CloudInstance> cloudInstancesToStop = generateCloudInstances(5);
    when(instanceConnector.stopWithLimitedRetry(any(AuthenticatedContext.class), eq(null), eq(cloudInstancesToStop), any(Long.class))).thenThrow(new RuntimeException("CloudProviderStopError"));
    StopStartDownscaleStopInstancesRequest request = new StopStartDownscaleStopInstancesRequest(cloudContext, cloudCredential, cloudStack, cloudInstancesToStop);
    Event event = new Event(request);
    underTest.accept(event);
    ArgumentCaptor<Event> resultCaptor = ArgumentCaptor.forClass(Event.class);
    verify(eventBus).notify(any(Object.class), resultCaptor.capture());
    assertEquals(1, resultCaptor.getAllValues().size());
    Event resultEvent = resultCaptor.getValue();
    assertEquals(StopStartDownscaleStopInstancesResult.class, resultEvent.getData().getClass());
    StopStartDownscaleStopInstancesResult result = (StopStartDownscaleStopInstancesResult) resultEvent.getData();
    assertEquals(0, result.getAffectedInstanceStatuses().size());
    assertEquals("CloudProviderStopError", result.getErrorDetails().getMessage());
    assertEquals("STOPSTARTDOWNSCALESTOPINSTANCESRESULT_ERROR", result.selector());
    assertEquals(EventStatus.FAILED, result.getStatus());
}
Also used : StopStartDownscaleStopInstancesRequest(com.sequenceiq.cloudbreak.cloud.event.instance.StopStartDownscaleStopInstancesRequest) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) Event(reactor.bus.Event) StopStartDownscaleStopInstancesResult(com.sequenceiq.cloudbreak.cloud.event.instance.StopStartDownscaleStopInstancesResult) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) Test(org.junit.jupiter.api.Test)

Aggregations

StopStartDownscaleStopInstancesResult (com.sequenceiq.cloudbreak.cloud.event.instance.StopStartDownscaleStopInstancesResult)6 StopStartDownscaleStopInstancesRequest (com.sequenceiq.cloudbreak.cloud.event.instance.StopStartDownscaleStopInstancesRequest)5 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)4 AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)3 CloudVmInstanceStatus (com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus)3 Test (org.junit.jupiter.api.Test)3 Event (reactor.bus.Event)3 AbstractStopStartDownscaleActions (com.sequenceiq.cloudbreak.core.flow2.cluster.stopstartds.StopStartDownscaleActions.AbstractStopStartDownscaleActions)2 InstanceMetaData (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)1 StackFailureEvent (com.sequenceiq.cloudbreak.reactor.api.event.StackFailureEvent)1 Map (java.util.Map)1 Bean (org.springframework.context.annotation.Bean)1