Search in sources :

Example 1 with LoadBalancerMetadataFailure

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

the class LoadBalancerMetadataHandler method doAccept.

@Override
protected Selectable doAccept(HandlerEvent<LoadBalancerMetadataRequest> event) {
    LoadBalancerMetadataRequest request = event.getData();
    CloudContext cloudContext = request.getCloudContext();
    try {
        LOGGER.info("Fetch cloud load balancer metadata");
        List<CloudLoadBalancerMetadata> loadBalancerStatuses = loadBalancerMetadataService.collectMetadata(cloudContext, request.getCloudCredential(), request.getTypesPresentInStack(), request.getCloudResources());
        Set<CloudLoadBalancerMetadata> failedStatues = loadBalancerStatuses.stream().filter(this::isMissingMetadata).collect(Collectors.toSet());
        if (!failedStatues.isEmpty()) {
            Set<String> names = failedStatues.stream().map(CloudLoadBalancerMetadata::getName).collect(Collectors.toSet());
            throw new CloudbreakException("Creation failed for load balancers: " + names);
        }
        LOGGER.info("Persisting load balancer metadata to the database: {}", loadBalancerStatuses);
        metadataSetupService.saveLoadBalancerMetadata(request.getStack(), loadBalancerStatuses);
        LOGGER.info("Load balancer metadata collection was successful");
        return new LoadBalancerMetadataSuccess(request.getStack());
    } catch (Exception e) {
        LOGGER.warn("Failed to fetch cloud load balancer metadata.", e);
        return new LoadBalancerMetadataFailure(request.getResourceId(), e);
    }
}
Also used : LoadBalancerMetadataFailure(com.sequenceiq.cloudbreak.reactor.api.event.stack.loadbalancer.LoadBalancerMetadataFailure) LoadBalancerMetadataRequest(com.sequenceiq.cloudbreak.reactor.api.event.stack.loadbalancer.LoadBalancerMetadataRequest) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) CloudLoadBalancerMetadata(com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancerMetadata) LoadBalancerMetadataSuccess(com.sequenceiq.cloudbreak.reactor.api.event.stack.loadbalancer.LoadBalancerMetadataSuccess)

Aggregations

CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)1 CloudLoadBalancerMetadata (com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancerMetadata)1 LoadBalancerMetadataFailure (com.sequenceiq.cloudbreak.reactor.api.event.stack.loadbalancer.LoadBalancerMetadataFailure)1 LoadBalancerMetadataRequest (com.sequenceiq.cloudbreak.reactor.api.event.stack.loadbalancer.LoadBalancerMetadataRequest)1 LoadBalancerMetadataSuccess (com.sequenceiq.cloudbreak.reactor.api.event.stack.loadbalancer.LoadBalancerMetadataSuccess)1 CloudbreakException (com.sequenceiq.cloudbreak.service.CloudbreakException)1