Search in sources :

Example 1 with LaunchLoadBalancerResult

use of com.sequenceiq.cloudbreak.cloud.event.resource.LaunchLoadBalancerResult in project cloudbreak by hortonworks.

the class StackCreationActions method provisioningFinishedAction.

@Bean(name = "PROVISIONING_FINISHED_STATE")
public Action<?, ?> provisioningFinishedAction() {
    return new AbstractStackCreationAction<>(LaunchLoadBalancerResult.class) {

        @Override
        protected void doExecute(StackCreationContext context, LaunchLoadBalancerResult payload, Map<Object, Object> variables) {
            Stack stack = stackCreationService.loadBalancerProvisioningFinished(context, payload, variables);
            StackCreationContext newContext = new StackCreationContext(context.getFlowParameters(), stack, context.getCloudContext(), context.getCloudCredential(), context.getCloudStack());
            sendEvent(newContext);
        }

        @Override
        protected Selectable createRequest(StackCreationContext context) {
            List<CloudInstance> cloudInstances = cloudStackConverter.buildInstances(context.getStack());
            List<CloudResource> cloudResources = context.getStack().getResources().stream().map(r -> cloudResourceConverter.convert(r)).collect(Collectors.toList());
            return new CollectMetadataRequest(context.getCloudContext(), context.getCloudCredential(), cloudResources, cloudInstances, cloudInstances);
        }
    };
}
Also used : START_DATE(com.sequenceiq.cloudbreak.core.flow2.stack.provision.StackProvisionConstants.START_DATE) CreateCredentialRequest(com.sequenceiq.cloudbreak.cloud.event.resource.CreateCredentialRequest) ProvisionEvent(com.sequenceiq.cloudbreak.reactor.api.event.stack.ProvisionEvent) CreateUserDataSuccess(com.sequenceiq.cloudbreak.reactor.api.event.stack.userdata.CreateUserDataSuccess) Action(org.springframework.statemachine.action.Action) PrepareImageRequest(com.sequenceiq.cloudbreak.cloud.event.setup.PrepareImageRequest) Date(java.util.Date) CollectLoadBalancerMetadataRequest(com.sequenceiq.cloudbreak.cloud.event.loadbalancer.CollectLoadBalancerMetadataRequest) StackToCloudStackConverter(com.sequenceiq.cloudbreak.converter.spi.StackToCloudStackConverter) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) LaunchLoadBalancerRequest(com.sequenceiq.cloudbreak.cloud.event.resource.LaunchLoadBalancerRequest) TlsInfo(com.sequenceiq.cloudbreak.cloud.model.TlsInfo) StackWithFingerprintsEvent(com.sequenceiq.cloudbreak.reactor.api.event.stack.StackWithFingerprintsEvent) ImageService(com.sequenceiq.cloudbreak.service.image.ImageService) InstanceMetaDataToCloudInstanceConverter(com.sequenceiq.cloudbreak.converter.spi.InstanceMetaDataToCloudInstanceConverter) CreateUserDataRequest(com.sequenceiq.cloudbreak.reactor.api.event.stack.userdata.CreateUserDataRequest) LoadBalancer(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.LoadBalancer) Map(java.util.Map) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) ValidationRequest(com.sequenceiq.cloudbreak.cloud.event.setup.ValidationRequest) AbstractStackFailureAction(com.sequenceiq.cloudbreak.core.flow2.stack.AbstractStackFailureAction) LoadBalancerPersistenceService(com.sequenceiq.cloudbreak.service.stack.LoadBalancerPersistenceService) StackCreationService(com.sequenceiq.cloudbreak.core.flow2.stack.provision.service.StackCreationService) StackFailureContext(com.sequenceiq.cloudbreak.core.flow2.stack.StackFailureContext) CreateCredentialResult(com.sequenceiq.cloudbreak.cloud.event.resource.CreateCredentialResult) Collectors(java.util.stream.Collectors) GetTlsInfoResult(com.sequenceiq.cloudbreak.cloud.event.instance.GetTlsInfoResult) Configuration(org.springframework.context.annotation.Configuration) SetupResult(com.sequenceiq.cloudbreak.cloud.event.setup.SetupResult) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) List(java.util.List) ValidationResult(com.sequenceiq.cloudbreak.cloud.event.setup.ValidationResult) Optional(java.util.Optional) StackCreationEvent(com.sequenceiq.cloudbreak.core.flow2.stack.provision.StackCreationEvent) SetupRequest(com.sequenceiq.cloudbreak.cloud.event.setup.SetupRequest) CollectLoadBalancerMetadataResult(com.sequenceiq.cloudbreak.cloud.event.loadbalancer.CollectLoadBalancerMetadataResult) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) FailurePolicy(com.sequenceiq.cloudbreak.domain.FailurePolicy) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) StackFailureEvent(com.sequenceiq.cloudbreak.reactor.api.event.StackFailureEvent) Image(com.sequenceiq.cloudbreak.cloud.model.Image) StackEvent(com.sequenceiq.cloudbreak.reactor.api.event.StackEvent) LoadBalancerType(com.sequenceiq.common.api.type.LoadBalancerType) Inject(javax.inject.Inject) ResourceToCloudResourceConverter(com.sequenceiq.cloudbreak.converter.spi.ResourceToCloudResourceConverter) LaunchLoadBalancerResult(com.sequenceiq.cloudbreak.cloud.event.resource.LaunchLoadBalancerResult) GetSSHFingerprintsResult(com.sequenceiq.cloudbreak.cloud.event.instance.GetSSHFingerprintsResult) GetSSHFingerprintsRequest(com.sequenceiq.cloudbreak.cloud.event.instance.GetSSHFingerprintsRequest) CollectMetadataResult(com.sequenceiq.cloudbreak.cloud.event.instance.CollectMetadataResult) CollectMetadataRequest(com.sequenceiq.cloudbreak.cloud.event.instance.CollectMetadataRequest) LaunchStackResult(com.sequenceiq.cloudbreak.cloud.event.resource.LaunchStackResult) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) EnvironmentClientService(com.sequenceiq.cloudbreak.service.environment.EnvironmentClientService) CloudbreakImageNotFoundException(com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException) MetricType(com.sequenceiq.cloudbreak.service.metrics.MetricType) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) GetTlsInfoRequest(com.sequenceiq.cloudbreak.cloud.event.instance.GetTlsInfoRequest) StackCreationContext(com.sequenceiq.cloudbreak.core.flow2.stack.start.StackCreationContext) LaunchStackRequest(com.sequenceiq.cloudbreak.cloud.event.resource.LaunchStackRequest) Bean(org.springframework.context.annotation.Bean) StackCreationState(com.sequenceiq.cloudbreak.core.flow2.stack.provision.StackCreationState) StackCreationContext(com.sequenceiq.cloudbreak.core.flow2.stack.start.StackCreationContext) CollectMetadataRequest(com.sequenceiq.cloudbreak.cloud.event.instance.CollectMetadataRequest) LaunchLoadBalancerResult(com.sequenceiq.cloudbreak.cloud.event.resource.LaunchLoadBalancerResult) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) Map(java.util.Map) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Bean(org.springframework.context.annotation.Bean)

Example 2 with LaunchLoadBalancerResult

use of com.sequenceiq.cloudbreak.cloud.event.resource.LaunchLoadBalancerResult in project cloudbreak by hortonworks.

the class LaunchLoadBalancerHandler method accept.

@Override
public void accept(Event<LaunchLoadBalancerRequest> launchLoadBalancerRequestEvent) {
    LOGGER.debug("Received event: {}", launchLoadBalancerRequestEvent);
    LaunchLoadBalancerRequest request = launchLoadBalancerRequestEvent.getData();
    CloudContext cloudContext = request.getCloudContext();
    CloudStack cloudStack = request.getCloudStack();
    CloudConnector<Object> connector = cloudPlatformConnectors.get(cloudContext.getPlatformVariant());
    AuthenticatedContext ac = connector.authentication().authenticate(cloudContext, request.getCloudCredential());
    try {
        LaunchLoadBalancerResult result;
        if (!cloudStack.getLoadBalancers().isEmpty()) {
            ResourcesStatePollerResult statePollerResult = launchLoadBalancers(cloudStack, connector, ac, persistenceNotifier, cloudContext);
            result = ResourcesStatePollerResults.transformToLaunchLoadBalancerResult(request, statePollerResult);
            request.getResult().onNext(result);
            LOGGER.debug("Launching the load balancers successfully finished for {}", cloudContext);
        } else {
            LOGGER.debug("No load balancers configured for stack.");
            result = new LaunchLoadBalancerResult(request.getResourceId(), List.of());
        }
        eventBus.notify(result.selector(), new Event<>(launchLoadBalancerRequestEvent.getHeaders(), result));
    } catch (Exception e) {
        if (ExceptionUtils.getRootCause(e) instanceof InterruptedException) {
            LOGGER.info("Interrupted exception is ignored as it has been thrown because of graceful shutdown of the java process.");
        }
        LaunchLoadBalancerResult failure = new LaunchLoadBalancerResult(e, request.getResourceId());
        LOGGER.warn("Error during launching the load balancerse:", e);
        request.getResult().onNext(failure);
        eventBus.notify(failure.selector(), new Event<>(launchLoadBalancerRequestEvent.getHeaders(), failure));
    }
}
Also used : LaunchLoadBalancerResult(com.sequenceiq.cloudbreak.cloud.event.resource.LaunchLoadBalancerResult) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) Event(reactor.bus.Event) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) ResourcesStatePollerResult(com.sequenceiq.cloudbreak.cloud.task.ResourcesStatePollerResult) LaunchLoadBalancerRequest(com.sequenceiq.cloudbreak.cloud.event.resource.LaunchLoadBalancerRequest)

Aggregations

LaunchLoadBalancerRequest (com.sequenceiq.cloudbreak.cloud.event.resource.LaunchLoadBalancerRequest)2 LaunchLoadBalancerResult (com.sequenceiq.cloudbreak.cloud.event.resource.LaunchLoadBalancerResult)2 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)2 AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)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 GetSSHFingerprintsRequest (com.sequenceiq.cloudbreak.cloud.event.instance.GetSSHFingerprintsRequest)1 GetSSHFingerprintsResult (com.sequenceiq.cloudbreak.cloud.event.instance.GetSSHFingerprintsResult)1 GetTlsInfoRequest (com.sequenceiq.cloudbreak.cloud.event.instance.GetTlsInfoRequest)1 GetTlsInfoResult (com.sequenceiq.cloudbreak.cloud.event.instance.GetTlsInfoResult)1 CollectLoadBalancerMetadataRequest (com.sequenceiq.cloudbreak.cloud.event.loadbalancer.CollectLoadBalancerMetadataRequest)1 CollectLoadBalancerMetadataResult (com.sequenceiq.cloudbreak.cloud.event.loadbalancer.CollectLoadBalancerMetadataResult)1 CreateCredentialRequest (com.sequenceiq.cloudbreak.cloud.event.resource.CreateCredentialRequest)1 CreateCredentialResult (com.sequenceiq.cloudbreak.cloud.event.resource.CreateCredentialResult)1 LaunchStackRequest (com.sequenceiq.cloudbreak.cloud.event.resource.LaunchStackRequest)1 LaunchStackResult (com.sequenceiq.cloudbreak.cloud.event.resource.LaunchStackResult)1 PrepareImageRequest (com.sequenceiq.cloudbreak.cloud.event.setup.PrepareImageRequest)1 SetupRequest (com.sequenceiq.cloudbreak.cloud.event.setup.SetupRequest)1 SetupResult (com.sequenceiq.cloudbreak.cloud.event.setup.SetupResult)1