use of com.sequenceiq.cloudbreak.cloud.event.loadbalancer.CollectLoadBalancerMetadataRequest in project cloudbreak by hortonworks.
the class LoadBalancerRecreatorService method collectLoadBalancerMetadata.
private List<CloudLoadBalancerMetadata> collectLoadBalancerMetadata(AuthenticatedContext authenticatedContext, Long stackId) {
List<LoadBalancerType> loadBalancerTypes = loadBalancerPersistenceService.findByStackId(stackId).stream().map(LoadBalancer::getType).collect(Collectors.toList());
List<CloudResource> cloudResources = resourceService.findByStackIdAndType(stackId, ResourceType.ELASTIC_LOAD_BALANCER).stream().map(r -> cloudResourceConverter.convert(r)).collect(Collectors.toList());
CollectLoadBalancerMetadataRequest request = new CollectLoadBalancerMetadataRequest(authenticatedContext.getCloudContext(), authenticatedContext.getCloudCredential(), loadBalancerTypes, cloudResources);
eventBus.notify(request.selector(), Event.wrap(request));
try {
CollectLoadBalancerMetadataResult res = request.await();
LOGGER.debug("Collect load balancer metadata result: {}", res);
if (res.getStatus().equals(EventStatus.FAILED)) {
String msg = "Failed to collect the load balancer metadata. " + res.getErrorDetails().getMessage();
LOGGER.debug(msg);
throw new CloudbreakServiceException(msg, res.getErrorDetails());
}
return res.getResults();
} catch (InterruptedException e) {
LOGGER.error("Error while collect load balancer metadata", e);
throw new OperationException(e);
}
}
use of com.sequenceiq.cloudbreak.cloud.event.loadbalancer.CollectLoadBalancerMetadataRequest in project cloudbreak by hortonworks.
the class CollectLoadBalancerMetadataHandler method accept.
@Override
public void accept(Event<CollectLoadBalancerMetadataRequest> collectLBMetadataRequestEvent) {
LOGGER.debug("Received event: {}", collectLBMetadataRequestEvent);
CollectLoadBalancerMetadataRequest request = collectLBMetadataRequestEvent.getData();
try {
List<CloudLoadBalancerMetadata> loadBalancerStatuses = loadBalancerMetadataService.collectMetadata(request.getCloudContext(), request.getCloudCredential(), request.getTypesPresentInStack(), request.getCloudResources());
CollectLoadBalancerMetadataResult collectLBMetadataResult = new CollectLoadBalancerMetadataResult(request.getResourceId(), loadBalancerStatuses);
request.getResult().onNext(collectLBMetadataResult);
eventBus.notify(collectLBMetadataResult.selector(), new Event<>(collectLBMetadataRequestEvent.getHeaders(), collectLBMetadataResult));
LOGGER.debug("Load balancer metadata collection successfully finished");
} catch (RuntimeException e) {
LOGGER.error("Collecting load balancer metadata failed", e);
CollectLoadBalancerMetadataResult failure = new CollectLoadBalancerMetadataResult(e, request.getResourceId());
request.getResult().onNext(failure);
eventBus.notify(failure.selector(), new Event<>(collectLBMetadataRequestEvent.getHeaders(), failure));
}
}
use of com.sequenceiq.cloudbreak.cloud.event.loadbalancer.CollectLoadBalancerMetadataRequest in project cloudbreak by hortonworks.
the class StackCreationActions method collectMetadataAction.
@Bean(name = "COLLECTMETADATA_STATE")
public Action<?, ?> collectMetadataAction() {
return new AbstractStackCreationAction<>(CollectMetadataResult.class) {
@Override
protected void doExecute(StackCreationContext context, CollectMetadataResult payload, Map<Object, Object> variables) {
Stack stack = stackCreationService.setupMetadata(context, payload);
StackCreationContext newContext = new StackCreationContext(context.getFlowParameters(), stack, context.getCloudContext(), context.getCloudCredential(), context.getCloudStack());
sendEvent(newContext);
}
@Override
protected Selectable createRequest(StackCreationContext context) {
List<LoadBalancerType> loadBalancerTypes = loadBalancerPersistenceService.findByStackId(context.getStack().getId()).stream().map(LoadBalancer::getType).collect(Collectors.toList());
List<CloudResource> cloudResources = context.getStack().getResources().stream().map(r -> cloudResourceConverter.convert(r)).collect(Collectors.toList());
return new CollectLoadBalancerMetadataRequest(context.getCloudContext(), context.getCloudCredential(), loadBalancerTypes, cloudResources);
}
};
}
Aggregations