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());
}
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());
}
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());
}
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());
}
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());
}
Aggregations