Search in sources :

Example 1 with PrimaryGatewayFirstThenSortByFqdnComparator

use of com.sequenceiq.freeipa.service.freeipa.PrimaryGatewayFirstThenSortByFqdnComparator 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

EntitlementService (com.sequenceiq.cloudbreak.auth.altus.EntitlementService)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 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)1 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)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 Resource (com.sequenceiq.freeipa.entity.Resource)1 Stack (com.sequenceiq.freeipa.entity.Stack)1 AbstractStackFailureAction (com.sequenceiq.freeipa.flow.stack.AbstractStackFailureAction)1 HealthCheckRequest (com.sequenceiq.freeipa.flow.stack.HealthCheckRequest)1 HealthCheckSuccess (com.sequenceiq.freeipa.flow.stack.HealthCheckSuccess)1 StackEvent (com.sequenceiq.freeipa.flow.stack.StackEvent)1 StackFailureContext (com.sequenceiq.freeipa.flow.stack.StackFailureContext)1 StackFailureEvent (com.sequenceiq.freeipa.flow.stack.StackFailureEvent)1