Search in sources :

Example 1 with StackStartStopContext

use of com.sequenceiq.cloudbreak.core.flow2.stack.start.StackStartStopContext in project cloudbreak by hortonworks.

the class StackStartActions method stackStartAction.

@Bean(name = "START_STATE")
public Action<?, ?> stackStartAction() {
    return new AbstractStackStartAction<>(StackEvent.class) {

        @Override
        protected void doExecute(StackStartStopContext context, StackEvent payload, Map<Object, Object> variables) {
            stackStartStopService.startStackStart(context);
            sendEvent(context);
        }

        @Override
        protected Selectable createRequest(StackStartStopContext context) {
            Stack stack = context.getStack();
            LOGGER.debug("Assembling start request for stack: {}", stack);
            List<CloudInstance> cloudInstances = instanceMetaDataToCloudInstanceConverter.convert(stack.getNotDeletedAndNotZombieInstanceMetaDataList(), stack.getEnvironmentCrn(), stack.getStackAuthentication());
            List<CloudResource> resources = stack.getResources().stream().map(s -> resourceToCloudResourceConverter.convert(s)).collect(Collectors.toList());
            cloudInstances.forEach(instance -> context.getStack().getParameters().forEach(instance::putParameter));
            return new StartInstancesRequest(context.getCloudContext(), context.getCloudCredential(), resources, cloudInstances);
        }
    };
}
Also used : Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Action(org.springframework.statemachine.action.Action) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) Payload(com.sequenceiq.cloudbreak.common.event.Payload) AvailabilityZone.availabilityZone(com.sequenceiq.cloudbreak.cloud.model.AvailabilityZone.availabilityZone) LoggerFactory(org.slf4j.LoggerFactory) StackToCloudStackConverter(com.sequenceiq.cloudbreak.converter.spi.StackToCloudStackConverter) Location.location(com.sequenceiq.cloudbreak.cloud.model.Location.location) MDCBuilder(com.sequenceiq.cloudbreak.logger.MDCBuilder) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) StackFailureEvent(com.sequenceiq.cloudbreak.reactor.api.event.StackFailureEvent) StackEvent(com.sequenceiq.cloudbreak.reactor.api.event.StackEvent) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Inject(javax.inject.Inject) ResourceToCloudResourceConverter(com.sequenceiq.cloudbreak.converter.spi.ResourceToCloudResourceConverter) ResourceService(com.sequenceiq.cloudbreak.service.resource.ResourceService) InstanceMetaDataToCloudInstanceConverter(com.sequenceiq.cloudbreak.converter.spi.InstanceMetaDataToCloudInstanceConverter) StateContext(org.springframework.statemachine.StateContext) Map(java.util.Map) Location(com.sequenceiq.cloudbreak.cloud.model.Location) StartInstancesRequest(com.sequenceiq.cloudbreak.cloud.event.instance.StartInstancesRequest) InstanceMetaDataService(com.sequenceiq.cloudbreak.service.stack.InstanceMetaDataService) StartInstancesResult(com.sequenceiq.cloudbreak.cloud.event.instance.StartInstancesResult) AbstractStackAction(com.sequenceiq.cloudbreak.core.flow2.AbstractStackAction) AbstractStackFailureAction(com.sequenceiq.cloudbreak.core.flow2.stack.AbstractStackFailureAction) Logger(org.slf4j.Logger) CollectMetadataResult(com.sequenceiq.cloudbreak.cloud.event.instance.CollectMetadataResult) CollectMetadataRequest(com.sequenceiq.cloudbreak.cloud.event.instance.CollectMetadataRequest) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) StackFailureContext(com.sequenceiq.cloudbreak.core.flow2.stack.StackFailureContext) Region.region(com.sequenceiq.cloudbreak.cloud.model.Region.region) FlowParameters(com.sequenceiq.flow.core.FlowParameters) Crn(com.sequenceiq.cloudbreak.auth.crn.Crn) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) Collectors(java.util.stream.Collectors) Configuration(org.springframework.context.annotation.Configuration) List(java.util.List) StackUtil(com.sequenceiq.cloudbreak.util.StackUtil) MetricType(com.sequenceiq.cloudbreak.service.metrics.MetricType) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) Optional(java.util.Optional) Bean(org.springframework.context.annotation.Bean) StackService(com.sequenceiq.cloudbreak.service.stack.StackService) StackEvent(com.sequenceiq.cloudbreak.reactor.api.event.StackEvent) StartInstancesRequest(com.sequenceiq.cloudbreak.cloud.event.instance.StartInstancesRequest) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) Map(java.util.Map) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Bean(org.springframework.context.annotation.Bean)

Example 2 with StackStartStopContext

use of com.sequenceiq.cloudbreak.core.flow2.stack.start.StackStartStopContext in project cloudbreak by hortonworks.

the class StackStopActions method stackStopAction.

@Bean(name = "STOP_STATE")
public Action<?, ?> stackStopAction() {
    return new AbstractStackStopAction<>(StackEvent.class) {

        @Override
        protected void doExecute(StackStartStopContext context, StackEvent payload, Map<Object, Object> variables) {
            stackStartStopService.startStackStop(context);
            sendEvent(context);
        }

        @Override
        protected Selectable createRequest(StackStartStopContext context) {
            Stack stack = context.getStack();
            List<CloudInstance> cloudInstances = instanceMetaDataToCloudInstanceConverter.convert(context.getInstanceMetaData(), stack.getEnvironmentCrn(), stack.getStackAuthentication());
            List<CloudResource> cloudResources = stack.getResources().stream().map(s -> resourceToCloudResourceConverter.convert(s)).collect(Collectors.toList());
            cloudInstances.forEach(instance -> stack.getParameters().forEach(instance::putParameter));
            return new StopInstancesRequest(context.getCloudContext(), context.getCloudCredential(), cloudResources, cloudInstances);
        }
    };
}
Also used : Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Action(org.springframework.statemachine.action.Action) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) Payload(com.sequenceiq.cloudbreak.common.event.Payload) AvailabilityZone.availabilityZone(com.sequenceiq.cloudbreak.cloud.model.AvailabilityZone.availabilityZone) LoggerFactory(org.slf4j.LoggerFactory) Location.location(com.sequenceiq.cloudbreak.cloud.model.Location.location) MDCBuilder(com.sequenceiq.cloudbreak.logger.MDCBuilder) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) StackFailureEvent(com.sequenceiq.cloudbreak.reactor.api.event.StackFailureEvent) StopInstancesRequest(com.sequenceiq.cloudbreak.cloud.event.instance.StopInstancesRequest) StackEvent(com.sequenceiq.cloudbreak.reactor.api.event.StackEvent) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Inject(javax.inject.Inject) ResourceToCloudResourceConverter(com.sequenceiq.cloudbreak.converter.spi.ResourceToCloudResourceConverter) ResourceService(com.sequenceiq.cloudbreak.service.resource.ResourceService) InstanceMetaDataToCloudInstanceConverter(com.sequenceiq.cloudbreak.converter.spi.InstanceMetaDataToCloudInstanceConverter) StateContext(org.springframework.statemachine.StateContext) Map(java.util.Map) Location(com.sequenceiq.cloudbreak.cloud.model.Location) InstanceMetaDataService(com.sequenceiq.cloudbreak.service.stack.InstanceMetaDataService) AbstractStackAction(com.sequenceiq.cloudbreak.core.flow2.AbstractStackAction) AbstractStackFailureAction(com.sequenceiq.cloudbreak.core.flow2.stack.AbstractStackFailureAction) Logger(org.slf4j.Logger) StackStartStopContext(com.sequenceiq.cloudbreak.core.flow2.stack.start.StackStartStopContext) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) StackStartStopService(com.sequenceiq.cloudbreak.core.flow2.stack.start.StackStartStopService) StackFailureContext(com.sequenceiq.cloudbreak.core.flow2.stack.StackFailureContext) Region.region(com.sequenceiq.cloudbreak.cloud.model.Region.region) FlowParameters(com.sequenceiq.flow.core.FlowParameters) Crn(com.sequenceiq.cloudbreak.auth.crn.Crn) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) Collectors(java.util.stream.Collectors) Configuration(org.springframework.context.annotation.Configuration) List(java.util.List) StackUtil(com.sequenceiq.cloudbreak.util.StackUtil) MetricType(com.sequenceiq.cloudbreak.service.metrics.MetricType) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) StopInstancesResult(com.sequenceiq.cloudbreak.cloud.event.instance.StopInstancesResult) Optional(java.util.Optional) Bean(org.springframework.context.annotation.Bean) StackService(com.sequenceiq.cloudbreak.service.stack.StackService) StackEvent(com.sequenceiq.cloudbreak.reactor.api.event.StackEvent) StackStartStopContext(com.sequenceiq.cloudbreak.core.flow2.stack.start.StackStartStopContext) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) StopInstancesRequest(com.sequenceiq.cloudbreak.cloud.event.instance.StopInstancesRequest) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) Map(java.util.Map) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Bean(org.springframework.context.annotation.Bean)

Aggregations

Crn (com.sequenceiq.cloudbreak.auth.crn.Crn)2 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)2 AvailabilityZone.availabilityZone (com.sequenceiq.cloudbreak.cloud.model.AvailabilityZone.availabilityZone)2 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)2 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)2 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)2 Location (com.sequenceiq.cloudbreak.cloud.model.Location)2 Location.location (com.sequenceiq.cloudbreak.cloud.model.Location.location)2 Region.region (com.sequenceiq.cloudbreak.cloud.model.Region.region)2 Payload (com.sequenceiq.cloudbreak.common.event.Payload)2 Selectable (com.sequenceiq.cloudbreak.common.event.Selectable)2 InstanceMetaDataToCloudInstanceConverter (com.sequenceiq.cloudbreak.converter.spi.InstanceMetaDataToCloudInstanceConverter)2 ResourceToCloudResourceConverter (com.sequenceiq.cloudbreak.converter.spi.ResourceToCloudResourceConverter)2 AbstractStackAction (com.sequenceiq.cloudbreak.core.flow2.AbstractStackAction)2 AbstractStackFailureAction (com.sequenceiq.cloudbreak.core.flow2.stack.AbstractStackFailureAction)2 StackFailureContext (com.sequenceiq.cloudbreak.core.flow2.stack.StackFailureContext)2 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)2 InstanceMetaData (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData)2 MDCBuilder (com.sequenceiq.cloudbreak.logger.MDCBuilder)2 StackEvent (com.sequenceiq.cloudbreak.reactor.api.event.StackEvent)2