use of com.sequenceiq.cloudbreak.core.flow2.event.StopStartUpscaleTriggerEvent 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());
}
use of com.sequenceiq.cloudbreak.core.flow2.event.StopStartUpscaleTriggerEvent in project cloudbreak by hortonworks.
the class StopStartUpscaleActions method startInstancesAction.
@Bean(name = "STOPSTART_UPSCALE_START_INSTANCE_STATE")
public Action<?, ?> startInstancesAction() {
return new AbstractStopStartUpscaleActions<>(StopStartUpscaleTriggerEvent.class) {
@Override
protected void prepareExecution(StopStartUpscaleTriggerEvent payload, Map<Object, Object> variables) {
variables.put(HOSTGROUPNAME, payload.getHostGroupName());
variables.put(ADJUSTMENT, payload.getAdjustment());
}
@Override
protected void doExecute(StopStartUpscaleContext context, StopStartUpscaleTriggerEvent payload, Map<Object, Object> variables) throws Exception {
clusterUpscaleFlowService.startingInstances(context.getStack().getId(), payload.getHostGroupName(), payload.getAdjustment());
sendEvent(context);
}
@Override
protected Selectable createRequest(StopStartUpscaleContext context) {
Stack stack = context.getStack();
List<InstanceMetaData> instanceMetaDataList = stack.getNotDeletedAndNotZombieInstanceMetaDataList();
List<InstanceMetaData> instanceMetaDataForHg = instanceMetaDataList.stream().filter(x -> x.getInstanceGroupName().equals(context.getHostGroupName())).collect(Collectors.toList());
List<InstanceMetaData> stoppedInstancesInHg = instanceMetaDataForHg.stream().filter(s -> s.getInstanceStatus() == STOPPED).collect(Collectors.toList());
LOGGER.info("NotDeletedInstanceMetadata totalCount={}. count for hostGroup: {}={}, stoppedInstancesInHgCount={}", instanceMetaDataList.size(), context.getHostGroupName(), instanceMetaDataForHg.size(), stoppedInstancesInHg.size());
List<CloudInstance> stoppedCloudInstancesForHg = instanceMetaDataToCloudInstanceConverter.convert(stoppedInstancesInHg, stack.getEnvironmentCrn(), stack.getStackAuthentication());
List<CloudInstance> allCloudInstancesForHg = instanceMetaDataToCloudInstanceConverter.convert(instanceMetaDataForHg, stack.getEnvironmentCrn(), stack.getStackAuthentication());
return new StopStartUpscaleStartInstancesRequest(context.getCloudContext(), context.getCloudCredential(), context.getCloudStack(), context.getHostGroupName(), stoppedCloudInstancesForHg, allCloudInstancesForHg, Collections.emptyList(), context.getAdjustment());
}
};
}
Aggregations