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);
}
}
Aggregations