Search in sources :

Example 6 with StopStartUpscaleStartInstancesResult

use of com.sequenceiq.cloudbreak.cloud.event.instance.StopStartUpscaleStartInstancesResult 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)

Example 7 with StopStartUpscaleStartInstancesResult

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

the class StopStartUpscaleStartInstancesHandlerTest method testFailureFromCloudProviderWhenStartingInstances.

@Test
void testFailureFromCloudProviderWhenStartingInstances() {
    List<CloudInstance> stoppedInstancesInHg = generateCloudInstances(5);
    List<CloudInstance> allInstancesInHg = generateCloudInstances(10);
    List<CloudInstance> startedInstancesWithServicesNotRunning = null;
    int numInstancesToStart = 5;
    List<CloudVmInstanceStatus> stoppedInstanceStatusList = generateStoppedCloudVmInstanceStatuses(stoppedInstancesInHg);
    List<CloudVmInstanceStatus> startedInstanceStatusList = generateStartedCloudVmInstanceStatuses(stoppedInstancesInHg);
    when(instanceConnector.checkWithoutRetry(any(AuthenticatedContext.class), eq(stoppedInstancesInHg))).thenReturn(stoppedInstanceStatusList).thenReturn(startedInstanceStatusList);
    when(instanceConnector.startWithLimitedRetry(any(AuthenticatedContext.class), eq(null), any(List.class), any(Long.class))).thenThrow(new RuntimeException("CloudProviderStartError"));
    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());
    assertEquals(1, resultCaptor.getAllValues().size());
    Event resultEvent = resultCaptor.getValue();
    assertEquals(StopStartUpscaleStartInstancesResult.class, resultEvent.getData().getClass());
    StopStartUpscaleStartInstancesResult result = (StopStartUpscaleStartInstancesResult) resultEvent.getData();
    assertNull(result.getErrorDetails());
    assertEquals(numInstancesToStart, result.getAffectedInstanceStatuses().size());
    assertEquals(startedInstanceStatusList, result.getAffectedInstanceStatuses());
    assertEquals(EventStatus.OK, result.getStatus());
    assertEquals("STOPSTARTUPSCALESTARTINSTANCESRESULT", result.selector());
}
Also used : CloudVmInstanceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) StopStartUpscaleStartInstancesResult(com.sequenceiq.cloudbreak.cloud.event.instance.StopStartUpscaleStartInstancesResult) StopStartUpscaleStartInstancesRequest(com.sequenceiq.cloudbreak.cloud.event.instance.StopStartUpscaleStartInstancesRequest) Event(reactor.bus.Event) LinkedList(java.util.LinkedList) List(java.util.List) Test(org.junit.jupiter.api.Test)

Example 8 with StopStartUpscaleStartInstancesResult

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

the class StopStartUpscaleStartInstancesHandlerTest method testCloudProviderInstancesInTerminatedEtcStateInternal.

private void testCloudProviderInstancesInTerminatedEtcStateInternal(int cbStoppedInstanceCount, int cloudProviderStoppedInstanceCount, int numInstancesToStart) {
    List<CloudInstance> stoppedInstancesInHg = generateCloudInstances(cbStoppedInstanceCount);
    List<CloudInstance> allInstancesInHg = generateCloudInstances(10);
    List<CloudInstance> startedInstancesWithServicesNotRunning = null;
    int expectedInstances = Math.min(cloudProviderStoppedInstanceCount, numInstancesToStart);
    StopStartUpscaleStartInstancesRequest request = new StopStartUpscaleStartInstancesRequest(cloudContext, cloudCredential, cloudStack, "compute", stoppedInstancesInHg, allInstancesInHg, startedInstancesWithServicesNotRunning, numInstancesToStart);
    List<CloudVmInstanceStatus> cloudVmInstanceStatusList = generateCloudVmInstanceStatusesIncludingOtherStates(allInstancesInHg, cloudProviderStoppedInstanceCount);
    when(instanceConnector.checkWithoutRetry(any(AuthenticatedContext.class), eq(allInstancesInHg))).thenReturn(cloudVmInstanceStatusList);
    List<CloudVmInstanceStatus> startedInstanceStatusList = generateStartedCloudVmInstanceStatuses(cloudVmInstanceStatusList, expectedInstances);
    List<CloudInstance> expInvocationList = startedInstanceStatusList.stream().map(CloudVmInstanceStatus::getCloudInstance).collect(Collectors.toList());
    when(instanceConnector.startWithLimitedRetry(any(AuthenticatedContext.class), eq(null), eq(expInvocationList), 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(allInstancesInHg));
    verify(instanceConnector).startWithLimitedRetry(any(AuthenticatedContext.class), eq(null), eq(expInvocationList), any(Long.class));
    assertEquals(1, resultCaptor.getAllValues().size());
    Event resultEvent = resultCaptor.getValue();
    assertEquals(StopStartUpscaleStartInstancesResult.class, resultEvent.getData().getClass());
    StopStartUpscaleStartInstancesResult result = (StopStartUpscaleStartInstancesResult) resultEvent.getData();
    verifyAffectedInstancesInResult(startedInstanceStatusList, 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 9 with StopStartUpscaleStartInstancesResult

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

the class StopStartUpscaleStartInstancesHandlerTest method testCbHasAdequateInstancesToStartInternal.

private void testCbHasAdequateInstancesToStartInternal(int cbStoppedInstanceCount, int numInstancesToStart) {
    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> startedInstanceStatusList = generateStartedCloudVmInstanceStatuses(stoppedInstancesArg);
    List<CloudVmInstanceStatus> stoppedInstanceStatusList = generateStoppedCloudVmInstanceStatuses(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, never()).checkWithoutRetry(any(AuthenticatedContext.class), eq(allInstancesInHg));
    verify(instanceConnector).startWithLimitedRetry(any(AuthenticatedContext.class), eq(null), eq(stoppedInstancesArg), any(Long.class));
    assertEquals(1, resultCaptor.getAllValues().size());
    Event resultEvent = resultCaptor.getValue();
    assertEquals(StopStartUpscaleStartInstancesResult.class, resultEvent.getData().getClass());
    StopStartUpscaleStartInstancesResult result = (StopStartUpscaleStartInstancesResult) resultEvent.getData();
    verifyAffectedInstancesInResult(startedInstanceStatusList, 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 10 with StopStartUpscaleStartInstancesResult

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

the class StopStartUpscaleStartInstancesHandlerTest method testNotEnoughInstancesAvailableToStartTestInternal.

private void testNotEnoughInstancesAvailableToStartTestInternal(int cbStoppedInstanceCount, int cloudProviderStoppedInstanceCount, int numInstancesToStart) {
    List<CloudInstance> stoppedInstancesInHg = generateCloudInstances(cbStoppedInstanceCount);
    List<CloudInstance> allInstancesInHg = generateCloudInstances(10);
    List<CloudInstance> startedInstancesWithServicesNotRunning = null;
    int expectedInstances = Math.min(cloudProviderStoppedInstanceCount, numInstancesToStart);
    StopStartUpscaleStartInstancesRequest request = new StopStartUpscaleStartInstancesRequest(cloudContext, cloudCredential, cloudStack, "compute", stoppedInstancesInHg, allInstancesInHg, startedInstancesWithServicesNotRunning, numInstancesToStart);
    List<CloudVmInstanceStatus> cloudVmInstanceStatusList = generateCloudVmInstanceStatuses(allInstancesInHg, cloudProviderStoppedInstanceCount);
    when(instanceConnector.checkWithoutRetry(any(AuthenticatedContext.class), eq(allInstancesInHg))).thenReturn(cloudVmInstanceStatusList);
    List<CloudVmInstanceStatus> startedInstanceStatusList = generateStartedCloudVmInstanceStatuses(allInstancesInHg.subList(0, expectedInstances));
    when(instanceConnector.startWithLimitedRetry(any(AuthenticatedContext.class), eq(null), eq(allInstancesInHg.subList(0, expectedInstances)), 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(allInstancesInHg));
    verify(instanceConnector).startWithLimitedRetry(any(AuthenticatedContext.class), eq(null), eq(allInstancesInHg.subList(0, expectedInstances)), any(Long.class));
    assertEquals(1, resultCaptor.getAllValues().size());
    Event resultEvent = resultCaptor.getValue();
    assertEquals(StopStartUpscaleStartInstancesResult.class, resultEvent.getData().getClass());
    StopStartUpscaleStartInstancesResult result = (StopStartUpscaleStartInstancesResult) resultEvent.getData();
    verifyAffectedInstancesInResult(cloudVmInstanceStatusList.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)

Aggregations

StopStartUpscaleStartInstancesResult (com.sequenceiq.cloudbreak.cloud.event.instance.StopStartUpscaleStartInstancesResult)13 StopStartUpscaleStartInstancesRequest (com.sequenceiq.cloudbreak.cloud.event.instance.StopStartUpscaleStartInstancesRequest)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 List (java.util.List)6 Test (org.junit.jupiter.api.Test)6 LinkedList (java.util.LinkedList)4 InstanceMetaData (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData)3 StopStartUpscaleCommissionViaCMRequest (com.sequenceiq.cloudbreak.reactor.api.event.cluster.StopStartUpscaleCommissionViaCMRequest)3 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)2 InstanceStatus (com.sequenceiq.cloudbreak.cloud.model.InstanceStatus)2 AbstractStopStartUpscaleActions (com.sequenceiq.cloudbreak.core.flow2.cluster.stopstartus.StopStartUpscaleActions.AbstractStopStartUpscaleActions)2 StackFailureEvent (com.sequenceiq.cloudbreak.reactor.api.event.StackFailureEvent)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 Bean (org.springframework.context.annotation.Bean)2 PollerStoppedException (com.dyngr.exception.PollerStoppedException)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1