Search in sources :

Example 1 with StopStartUpscaleStartInstancesRequest

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());
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) StackAuthentication(com.sequenceiq.cloudbreak.domain.StackAuthentication) AbstractStopStartUpscaleActions(com.sequenceiq.cloudbreak.core.flow2.cluster.stopstartus.StopStartUpscaleActions.AbstractStopStartUpscaleActions) StopStartUpscaleStartInstancesRequest(com.sequenceiq.cloudbreak.cloud.event.instance.StopStartUpscaleStartInstancesRequest) StopStartUpscaleTriggerEvent(com.sequenceiq.cloudbreak.core.flow2.event.StopStartUpscaleTriggerEvent) Test(org.junit.jupiter.api.Test)

Example 2 with StopStartUpscaleStartInstancesRequest

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());
}
Also used : CloudVmInstanceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) LinkedList(java.util.LinkedList) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) AbstractStopStartUpscaleActions(com.sequenceiq.cloudbreak.core.flow2.cluster.stopstartus.StopStartUpscaleActions.AbstractStopStartUpscaleActions) StopStartUpscaleStartInstancesResult(com.sequenceiq.cloudbreak.cloud.event.instance.StopStartUpscaleStartInstancesResult) StopStartUpscaleStartInstancesRequest(com.sequenceiq.cloudbreak.cloud.event.instance.StopStartUpscaleStartInstancesRequest) StopStartUpscaleCommissionViaCMRequest(com.sequenceiq.cloudbreak.reactor.api.event.cluster.StopStartUpscaleCommissionViaCMRequest) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) Test(org.junit.jupiter.api.Test)

Example 3 with StopStartUpscaleStartInstancesRequest

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());
}
Also used : CloudVmInstanceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) LinkedList(java.util.LinkedList) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) AbstractStopStartUpscaleActions(com.sequenceiq.cloudbreak.core.flow2.cluster.stopstartus.StopStartUpscaleActions.AbstractStopStartUpscaleActions) StopStartUpscaleStartInstancesResult(com.sequenceiq.cloudbreak.cloud.event.instance.StopStartUpscaleStartInstancesResult) StopStartUpscaleStartInstancesRequest(com.sequenceiq.cloudbreak.cloud.event.instance.StopStartUpscaleStartInstancesRequest) StopStartUpscaleCommissionViaCMRequest(com.sequenceiq.cloudbreak.reactor.api.event.cluster.StopStartUpscaleCommissionViaCMRequest) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) Test(org.junit.jupiter.api.Test)

Example 4 with StopStartUpscaleStartInstancesRequest

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());
}
Also used : StopStartUpscaleStartInstancesResult(com.sequenceiq.cloudbreak.cloud.event.instance.StopStartUpscaleStartInstancesResult) StopStartUpscaleStartInstancesRequest(com.sequenceiq.cloudbreak.cloud.event.instance.StopStartUpscaleStartInstancesRequest) CloudVmInstanceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) Event(reactor.bus.Event) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)

Example 5 with StopStartUpscaleStartInstancesRequest

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());
}
Also used : StopStartUpscaleStartInstancesResult(com.sequenceiq.cloudbreak.cloud.event.instance.StopStartUpscaleStartInstancesResult) StopStartUpscaleStartInstancesRequest(com.sequenceiq.cloudbreak.cloud.event.instance.StopStartUpscaleStartInstancesRequest) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) Event(reactor.bus.Event) Test(org.junit.jupiter.api.Test)

Aggregations

StopStartUpscaleStartInstancesRequest (com.sequenceiq.cloudbreak.cloud.event.instance.StopStartUpscaleStartInstancesRequest)13 StopStartUpscaleStartInstancesResult (com.sequenceiq.cloudbreak.cloud.event.instance.StopStartUpscaleStartInstancesResult)12 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)12 CloudVmInstanceStatus (com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus)9 Event (reactor.bus.Event)9 AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)7 Test (org.junit.jupiter.api.Test)7 List (java.util.List)6 LinkedList (java.util.LinkedList)4 AbstractStopStartUpscaleActions (com.sequenceiq.cloudbreak.core.flow2.cluster.stopstartus.StopStartUpscaleActions.AbstractStopStartUpscaleActions)3 InstanceMetaData (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData)3 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)2 InstanceStatus (com.sequenceiq.cloudbreak.cloud.model.InstanceStatus)2 StopStartUpscaleTriggerEvent (com.sequenceiq.cloudbreak.core.flow2.event.StopStartUpscaleTriggerEvent)2 StopStartUpscaleCommissionViaCMRequest (com.sequenceiq.cloudbreak.reactor.api.event.cluster.StopStartUpscaleCommissionViaCMRequest)2 ArrayList (java.util.ArrayList)2 Collections (java.util.Collections)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 Inject (javax.inject.Inject)2