Search in sources :

Example 1 with LaunchLoadBalancerRequest

use of com.sequenceiq.cloudbreak.cloud.event.resource.LaunchLoadBalancerRequest 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

AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)1 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)1 LaunchLoadBalancerRequest (com.sequenceiq.cloudbreak.cloud.event.resource.LaunchLoadBalancerRequest)1 LaunchLoadBalancerResult (com.sequenceiq.cloudbreak.cloud.event.resource.LaunchLoadBalancerResult)1 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)1 ResourcesStatePollerResult (com.sequenceiq.cloudbreak.cloud.task.ResourcesStatePollerResult)1 Event (reactor.bus.Event)1