Search in sources :

Example 1 with CreateCloudLoadBalancersSuccess

use of com.sequenceiq.cloudbreak.reactor.api.event.stack.loadbalancer.CreateCloudLoadBalancersSuccess in project cloudbreak by hortonworks.

the class CreateCloudLoadBalancersHandler method doAccept.

@Override
protected Selectable doAccept(HandlerEvent<CreateCloudLoadBalancersRequest> event) {
    CreateCloudLoadBalancersRequest request = event.getData();
    CloudContext cloudContext = request.getCloudContext();
    try {
        LOGGER.info("Updating cloud stack with load balancer network information");
        CloudStack origCloudStack = request.getCloudStack();
        Stack stack = request.getStack();
        CloudStack updatedCloudStack = new CloudStack(origCloudStack.getGroups(), cloudStackConverter.buildNetwork(stack), origCloudStack.getImage(), origCloudStack.getParameters(), origCloudStack.getTags(), origCloudStack.getTemplate(), origCloudStack.getInstanceAuthentication(), origCloudStack.getLoginUserName(), origCloudStack.getPublicKey(), origCloudStack.getFileSystem().orElse(null), origCloudStack.getLoadBalancers());
        CloudConnector<Object> connector = cloudPlatformConnectors.get(cloudContext.getPlatformVariant());
        AuthenticatedContext ac = connector.authentication().authenticate(cloudContext, request.getCloudCredential());
        LOGGER.debug("Initiating cloud load balancer creation");
        List<CloudResourceStatus> resourceStatus = connector.resources().launchLoadBalancers(ac, updatedCloudStack, persistenceNotifier);
        LOGGER.debug("Waiting for cloud load balancers to be fully created");
        List<CloudResource> resources = ResourceLists.transform(resourceStatus);
        PollTask<ResourcesStatePollerResult> task = statusCheckFactory.newPollResourcesStateTask(ac, resources, true);
        ResourcesStatePollerResult statePollerResult = ResourcesStatePollerResults.build(cloudContext, resourceStatus);
        if (!task.completed(statePollerResult)) {
            syncPollingScheduler.schedule(task);
        }
        if (resourceStatus.stream().anyMatch(CloudResourceStatus::isFailed)) {
            Set<String> names = resourceStatus.stream().filter(CloudResourceStatus::isFailed).map(r -> r.getCloudResource().getName()).collect(Collectors.toSet());
            throw new CloudbreakException("Creation failed for load balancers: " + names);
        }
        Set<String> types = updatedCloudStack.getLoadBalancers().stream().map(CloudLoadBalancer::getType).map(LoadBalancerType::toString).collect(Collectors.toSet());
        LOGGER.info("Cloud load balancer creation for load balancer types {} successful", types);
        return new CreateCloudLoadBalancersSuccess(stack);
    } catch (Exception e) {
        LOGGER.warn("Failed to created cloud load balance resources.", e);
        return new CreateCloudLoadBalancersFailure(request.getResourceId(), e);
    }
}
Also used : Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) ResourcesStatePollerResult(com.sequenceiq.cloudbreak.cloud.task.ResourcesStatePollerResult) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) ResourceLists(com.sequenceiq.cloudbreak.cloud.transform.ResourceLists) LoggerFactory(org.slf4j.LoggerFactory) StackToCloudStackConverter(com.sequenceiq.cloudbreak.converter.spi.StackToCloudStackConverter) EventSelectorUtil(com.sequenceiq.flow.event.EventSelectorUtil) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) LoadBalancerType(com.sequenceiq.common.api.type.LoadBalancerType) Inject(javax.inject.Inject) ExceptionCatcherEventHandler(com.sequenceiq.flow.reactor.api.handler.ExceptionCatcherEventHandler) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) Event(reactor.bus.Event) CloudLoadBalancer(com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancer) PollTask(com.sequenceiq.cloudbreak.cloud.task.PollTask) CreateCloudLoadBalancersSuccess(com.sequenceiq.cloudbreak.reactor.api.event.stack.loadbalancer.CreateCloudLoadBalancersSuccess) Logger(org.slf4j.Logger) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) PollTaskFactory(com.sequenceiq.cloudbreak.cloud.task.PollTaskFactory) CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) ResourcesStatePollerResults(com.sequenceiq.cloudbreak.cloud.transform.ResourcesStatePollerResults) Set(java.util.Set) HandlerEvent(com.sequenceiq.flow.reactor.api.handler.HandlerEvent) PersistenceNotifier(com.sequenceiq.cloudbreak.cloud.notification.PersistenceNotifier) CreateCloudLoadBalancersFailure(com.sequenceiq.cloudbreak.reactor.api.event.stack.loadbalancer.CreateCloudLoadBalancersFailure) Collectors(java.util.stream.Collectors) CloudConnector(com.sequenceiq.cloudbreak.cloud.CloudConnector) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) List(java.util.List) Component(org.springframework.stereotype.Component) CloudPlatformConnectors(com.sequenceiq.cloudbreak.cloud.init.CloudPlatformConnectors) SyncPollingScheduler(com.sequenceiq.cloudbreak.cloud.scheduler.SyncPollingScheduler) CreateCloudLoadBalancersRequest(com.sequenceiq.cloudbreak.reactor.api.event.stack.loadbalancer.CreateCloudLoadBalancersRequest) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) CreateCloudLoadBalancersRequest(com.sequenceiq.cloudbreak.reactor.api.event.stack.loadbalancer.CreateCloudLoadBalancersRequest) CreateCloudLoadBalancersFailure(com.sequenceiq.cloudbreak.reactor.api.event.stack.loadbalancer.CreateCloudLoadBalancersFailure) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) CloudLoadBalancer(com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancer) CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) CreateCloudLoadBalancersSuccess(com.sequenceiq.cloudbreak.reactor.api.event.stack.loadbalancer.CreateCloudLoadBalancersSuccess) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) ResourcesStatePollerResult(com.sequenceiq.cloudbreak.cloud.task.ResourcesStatePollerResult)

Aggregations

CloudConnector (com.sequenceiq.cloudbreak.cloud.CloudConnector)1 AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)1 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)1 CloudPlatformConnectors (com.sequenceiq.cloudbreak.cloud.init.CloudPlatformConnectors)1 CloudLoadBalancer (com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancer)1 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)1 CloudResourceStatus (com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus)1 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)1 PersistenceNotifier (com.sequenceiq.cloudbreak.cloud.notification.PersistenceNotifier)1 SyncPollingScheduler (com.sequenceiq.cloudbreak.cloud.scheduler.SyncPollingScheduler)1 PollTask (com.sequenceiq.cloudbreak.cloud.task.PollTask)1 PollTaskFactory (com.sequenceiq.cloudbreak.cloud.task.PollTaskFactory)1 ResourcesStatePollerResult (com.sequenceiq.cloudbreak.cloud.task.ResourcesStatePollerResult)1 ResourceLists (com.sequenceiq.cloudbreak.cloud.transform.ResourceLists)1 ResourcesStatePollerResults (com.sequenceiq.cloudbreak.cloud.transform.ResourcesStatePollerResults)1 Selectable (com.sequenceiq.cloudbreak.common.event.Selectable)1 StackToCloudStackConverter (com.sequenceiq.cloudbreak.converter.spi.StackToCloudStackConverter)1 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)1 CreateCloudLoadBalancersFailure (com.sequenceiq.cloudbreak.reactor.api.event.stack.loadbalancer.CreateCloudLoadBalancersFailure)1 CreateCloudLoadBalancersRequest (com.sequenceiq.cloudbreak.reactor.api.event.stack.loadbalancer.CreateCloudLoadBalancersRequest)1