Search in sources :

Example 1 with StackStartContext

use of com.sequenceiq.freeipa.flow.stack.start.StackStartContext in project cloudbreak by hortonworks.

the class AbstractStackStartAction method createFlowContext.

@Override
protected StackStartContext createFlowContext(FlowParameters flowParameters, StateContext<StackStartState, StackStartEvent> stateContext, P payload) {
    Long stackId = payload.getResourceId();
    Stack stack = stackService.getByIdWithListsInTransaction(stackId);
    MDCBuilder.buildMdcContext(stack);
    List<InstanceMetaData> instances = stack.getNotDeletedInstanceMetaDataList();
    Location location = location(region(stack.getRegion()), availabilityZone(stack.getAvailabilityZone()));
    CloudContext cloudContext = CloudContext.Builder.builder().withId(stack.getId()).withName(stack.getName()).withCrn(stack.getResourceCrn()).withPlatform(stack.getCloudPlatform()).withVariant(stack.getPlatformvariant()).withLocation(location).withUserName(stack.getOwner()).withAccountId(stack.getAccountId()).build();
    Credential credential = credentialService.getCredentialByEnvCrn(stack.getEnvironmentCrn());
    CloudCredential cloudCredential = credentialConverter.convert(credential);
    return new StackStartContext(flowParameters, stack, instances, cloudContext, cloudCredential);
}
Also used : InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) Credential(com.sequenceiq.freeipa.dto.Credential) StackStartContext(com.sequenceiq.freeipa.flow.stack.start.StackStartContext) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) Stack(com.sequenceiq.freeipa.entity.Stack) Location(com.sequenceiq.cloudbreak.cloud.model.Location)

Example 2 with StackStartContext

use of com.sequenceiq.freeipa.flow.stack.start.StackStartContext in project cloudbreak by hortonworks.

the class StackStartActions method stackStartAction.

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

        @Value("${freeipa.delayed.stop-start-sec}")
        private long delayInSec;

        @Inject
        private EntitlementService entitlementService;

        @Override
        protected void doExecute(StackStartContext context, StackEvent payload, Map<Object, Object> variables) {
            stackStartService.startStack(context.getStack());
            sendEvent(context);
        }

        @Override
        protected Selectable createRequest(StackStartContext context) {
            Stack stack = context.getStack();
            LOGGER.debug("Assembling start request for stack: {}", stack);
            List<CloudInstance> cloudInstances = stack.getNotDeletedInstanceMetaDataSet().stream().sorted(new PrimaryGatewayFirstThenSortByFqdnComparator()).map(i -> metadataConverter.convert(i)).collect(Collectors.toList());
            List<CloudResource> cloudResources = getCloudResources(stack.getId());
            if (entitlementService.isFmsDelayedStopStartEnabled(context.getStack().getAccountId())) {
                return new DelayedStartInstancesRequest(context.getCloudContext(), context.getCloudCredential(), cloudResources, cloudInstances, delayInSec);
            } else {
                return new StartInstancesRequest(context.getCloudContext(), context.getCloudCredential(), cloudResources, cloudInstances);
            }
        }
    };
}
Also used : EntitlementService(com.sequenceiq.cloudbreak.auth.altus.EntitlementService) Action(org.springframework.statemachine.action.Action) InstanceMetaDataToCloudInstanceConverter(com.sequenceiq.freeipa.converter.cloud.InstanceMetaDataToCloudInstanceConverter) EntitlementService(com.sequenceiq.cloudbreak.auth.altus.EntitlementService) LoggerFactory(org.slf4j.LoggerFactory) DelayedStartInstancesRequest(com.sequenceiq.cloudbreak.cloud.event.instance.DelayedStartInstancesRequest) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) ResourceToCloudResourceConverter(com.sequenceiq.freeipa.converter.cloud.ResourceToCloudResourceConverter) AbstractStackFailureAction(com.sequenceiq.freeipa.flow.stack.AbstractStackFailureAction) Inject(javax.inject.Inject) Value(org.springframework.beans.factory.annotation.Value) HealthCheckRequest(com.sequenceiq.freeipa.flow.stack.HealthCheckRequest) ResourceService(com.sequenceiq.freeipa.service.resource.ResourceService) Map(java.util.Map) Resource(com.sequenceiq.freeipa.entity.Resource) StartInstancesRequest(com.sequenceiq.cloudbreak.cloud.event.instance.StartInstancesRequest) StartInstancesResult(com.sequenceiq.cloudbreak.cloud.event.instance.StartInstancesResult) StackStartEvent(com.sequenceiq.freeipa.flow.stack.start.StackStartEvent) Stack(com.sequenceiq.freeipa.entity.Stack) StackEvent(com.sequenceiq.freeipa.flow.stack.StackEvent) StackFailureEvent(com.sequenceiq.freeipa.flow.stack.StackFailureEvent) StackStartState(com.sequenceiq.freeipa.flow.stack.start.StackStartState) Logger(org.slf4j.Logger) CollectMetadataResult(com.sequenceiq.cloudbreak.cloud.event.instance.CollectMetadataResult) StackStartService(com.sequenceiq.freeipa.flow.stack.start.StackStartService) CollectMetadataRequest(com.sequenceiq.cloudbreak.cloud.event.instance.CollectMetadataRequest) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) StackStartContext(com.sequenceiq.freeipa.flow.stack.start.StackStartContext) Collectors(java.util.stream.Collectors) HealthCheckSuccess(com.sequenceiq.freeipa.flow.stack.HealthCheckSuccess) PrimaryGatewayFirstThenSortByFqdnComparator(com.sequenceiq.freeipa.service.freeipa.PrimaryGatewayFirstThenSortByFqdnComparator) Configuration(org.springframework.context.annotation.Configuration) List(java.util.List) StackToCloudStackConverter(com.sequenceiq.freeipa.converter.cloud.StackToCloudStackConverter) StackFailureContext(com.sequenceiq.freeipa.flow.stack.StackFailureContext) Bean(org.springframework.context.annotation.Bean) StackStartContext(com.sequenceiq.freeipa.flow.stack.start.StackStartContext) DelayedStartInstancesRequest(com.sequenceiq.cloudbreak.cloud.event.instance.DelayedStartInstancesRequest) StartInstancesRequest(com.sequenceiq.cloudbreak.cloud.event.instance.StartInstancesRequest) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) DelayedStartInstancesRequest(com.sequenceiq.cloudbreak.cloud.event.instance.DelayedStartInstancesRequest) PrimaryGatewayFirstThenSortByFqdnComparator(com.sequenceiq.freeipa.service.freeipa.PrimaryGatewayFirstThenSortByFqdnComparator) Stack(com.sequenceiq.freeipa.entity.Stack) StackEvent(com.sequenceiq.freeipa.flow.stack.StackEvent) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) Map(java.util.Map) Bean(org.springframework.context.annotation.Bean)

Aggregations

Stack (com.sequenceiq.freeipa.entity.Stack)2 StackStartContext (com.sequenceiq.freeipa.flow.stack.start.StackStartContext)2 EntitlementService (com.sequenceiq.cloudbreak.auth.altus.EntitlementService)1 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)1 CollectMetadataRequest (com.sequenceiq.cloudbreak.cloud.event.instance.CollectMetadataRequest)1 CollectMetadataResult (com.sequenceiq.cloudbreak.cloud.event.instance.CollectMetadataResult)1 DelayedStartInstancesRequest (com.sequenceiq.cloudbreak.cloud.event.instance.DelayedStartInstancesRequest)1 StartInstancesRequest (com.sequenceiq.cloudbreak.cloud.event.instance.StartInstancesRequest)1 StartInstancesResult (com.sequenceiq.cloudbreak.cloud.event.instance.StartInstancesResult)1 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)1 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)1 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)1 Location (com.sequenceiq.cloudbreak.cloud.model.Location)1 Selectable (com.sequenceiq.cloudbreak.common.event.Selectable)1 InstanceMetaDataToCloudInstanceConverter (com.sequenceiq.freeipa.converter.cloud.InstanceMetaDataToCloudInstanceConverter)1 ResourceToCloudResourceConverter (com.sequenceiq.freeipa.converter.cloud.ResourceToCloudResourceConverter)1 StackToCloudStackConverter (com.sequenceiq.freeipa.converter.cloud.StackToCloudStackConverter)1 Credential (com.sequenceiq.freeipa.dto.Credential)1 InstanceMetaData (com.sequenceiq.freeipa.entity.InstanceMetaData)1 Resource (com.sequenceiq.freeipa.entity.Resource)1