Search in sources :

Example 1 with StopStartUpscaleTriggerEvent

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

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());
        }
    };
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) Action(org.springframework.statemachine.action.Action) DetailedStackStatus(com.sequenceiq.cloudbreak.api.endpoint.v4.common.DetailedStackStatus) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) AvailabilityZone.availabilityZone(com.sequenceiq.cloudbreak.cloud.model.AvailabilityZone.availabilityZone) StopStartUpscaleStartInstancesRequest(com.sequenceiq.cloudbreak.cloud.event.instance.StopStartUpscaleStartInstancesRequest) LoggerFactory(org.slf4j.LoggerFactory) StackToCloudStackConverter(com.sequenceiq.cloudbreak.converter.spi.StackToCloudStackConverter) Location.location(com.sequenceiq.cloudbreak.cloud.model.Location.location) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) STOPSTART_UPSCALE_FAILURE_EVENT(com.sequenceiq.cloudbreak.core.flow2.cluster.stopstartus.StopStartUpscaleEvent.STOPSTART_UPSCALE_FAILURE_EVENT) InstanceMetaDataToCloudInstanceConverter(com.sequenceiq.cloudbreak.converter.spi.InstanceMetaDataToCloudInstanceConverter) Map(java.util.Map) Location(com.sequenceiq.cloudbreak.cloud.model.Location) CloudVmInstanceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus) AbstractStackAction(com.sequenceiq.cloudbreak.core.flow2.AbstractStackAction) AbstractStackFailureAction(com.sequenceiq.cloudbreak.core.flow2.stack.AbstractStackFailureAction) STOPPED(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus.STOPPED) StackFailureContext(com.sequenceiq.cloudbreak.core.flow2.stack.StackFailureContext) Set(java.util.Set) FlowParameters(com.sequenceiq.flow.core.FlowParameters) StopStartUpscaleStartInstancesResult(com.sequenceiq.cloudbreak.cloud.event.instance.StopStartUpscaleStartInstancesResult) Crn(com.sequenceiq.cloudbreak.auth.crn.Crn) StopStartUpscaleCommissionViaCMRequest(com.sequenceiq.cloudbreak.reactor.api.event.cluster.StopStartUpscaleCommissionViaCMRequest) Collectors(java.util.stream.Collectors) Configuration(org.springframework.context.annotation.Configuration) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) List(java.util.List) StackUtil(com.sequenceiq.cloudbreak.util.StackUtil) Optional(java.util.Optional) StackService(com.sequenceiq.cloudbreak.service.stack.StackService) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Payload(com.sequenceiq.cloudbreak.common.event.Payload) MDCBuilder(com.sequenceiq.cloudbreak.logger.MDCBuilder) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) StackFailureEvent(com.sequenceiq.cloudbreak.reactor.api.event.StackFailureEvent) StackEvent(com.sequenceiq.cloudbreak.reactor.api.event.StackEvent) StopStartUpscaleCommissionViaCMResult(com.sequenceiq.cloudbreak.reactor.api.event.orchestration.StopStartUpscaleCommissionViaCMResult) HashSet(java.util.HashSet) Inject(javax.inject.Inject) ResourceService(com.sequenceiq.cloudbreak.service.resource.ResourceService) CloudInstanceIdToInstanceMetaDataConverter(com.sequenceiq.cloudbreak.converter.CloudInstanceIdToInstanceMetaDataConverter) ClusterManagerType(com.sequenceiq.cloudbreak.common.type.ClusterManagerType) StateContext(org.springframework.statemachine.StateContext) Logger(org.slf4j.Logger) Region.region(com.sequenceiq.cloudbreak.cloud.model.Region.region) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) STOPSTART_UPSCALE_FINALIZED_EVENT(com.sequenceiq.cloudbreak.core.flow2.cluster.stopstartus.StopStartUpscaleEvent.STOPSTART_UPSCALE_FINALIZED_EVENT) InstanceStatus(com.sequenceiq.cloudbreak.cloud.model.InstanceStatus) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) Bean(org.springframework.context.annotation.Bean) VisibleForTesting(com.google.common.annotations.VisibleForTesting) StopStartUpscaleTriggerEvent(com.sequenceiq.cloudbreak.core.flow2.event.StopStartUpscaleTriggerEvent) Collections(java.util.Collections) StopStartUpscaleStartInstancesRequest(com.sequenceiq.cloudbreak.cloud.event.instance.StopStartUpscaleStartInstancesRequest) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) StopStartUpscaleTriggerEvent(com.sequenceiq.cloudbreak.core.flow2.event.StopStartUpscaleTriggerEvent) Map(java.util.Map) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Bean(org.springframework.context.annotation.Bean)

Aggregations

StopStartUpscaleStartInstancesRequest (com.sequenceiq.cloudbreak.cloud.event.instance.StopStartUpscaleStartInstancesRequest)2 StopStartUpscaleTriggerEvent (com.sequenceiq.cloudbreak.core.flow2.event.StopStartUpscaleTriggerEvent)2 InstanceMetaData (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 DetailedStackStatus (com.sequenceiq.cloudbreak.api.endpoint.v4.common.DetailedStackStatus)1 STOPPED (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus.STOPPED)1 Crn (com.sequenceiq.cloudbreak.auth.crn.Crn)1 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)1 StopStartUpscaleStartInstancesResult (com.sequenceiq.cloudbreak.cloud.event.instance.StopStartUpscaleStartInstancesResult)1 AvailabilityZone.availabilityZone (com.sequenceiq.cloudbreak.cloud.model.AvailabilityZone.availabilityZone)1 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)1 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)1 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)1 CloudVmInstanceStatus (com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus)1 InstanceStatus (com.sequenceiq.cloudbreak.cloud.model.InstanceStatus)1 Location (com.sequenceiq.cloudbreak.cloud.model.Location)1 Location.location (com.sequenceiq.cloudbreak.cloud.model.Location.location)1 Region.region (com.sequenceiq.cloudbreak.cloud.model.Region.region)1 Payload (com.sequenceiq.cloudbreak.common.event.Payload)1 Selectable (com.sequenceiq.cloudbreak.common.event.Selectable)1