Search in sources :

Example 1 with CollectLoadBalancerMetadataResult

use of com.sequenceiq.cloudbreak.cloud.event.loadbalancer.CollectLoadBalancerMetadataResult 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);
    }
}
Also used : Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) AmazonElasticLoadBalancingClient(com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonElasticLoadBalancingClient) CollectLoadBalancerMetadataRequest(com.sequenceiq.cloudbreak.cloud.event.loadbalancer.CollectLoadBalancerMetadataRequest) LoadBalancerType(com.sequenceiq.common.api.type.LoadBalancerType) Inject(javax.inject.Inject) ResourceToCloudResourceConverter(com.sequenceiq.cloudbreak.converter.spi.ResourceToCloudResourceConverter) ResourceService(com.sequenceiq.cloudbreak.service.resource.ResourceService) AwsCredentialView(com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsCredentialView) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) CreateResourcesRequest(com.sequenceiq.cloudbreak.cloud.event.resource.migration.aws.CreateResourcesRequest) Event(reactor.bus.Event) AwsNativeLoadBalancerLaunchService(com.sequenceiq.cloudbreak.cloud.aws.resource.loadbalancer.AwsNativeLoadBalancerLaunchService) LoadBalancer(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.LoadBalancer) AwsContext(com.sequenceiq.cloudbreak.cloud.aws.common.context.AwsContext) MetadataSetupService(com.sequenceiq.cloudbreak.service.stack.flow.MetadataSetupService) ResourceType(com.sequenceiq.common.api.type.ResourceType) LoadBalancerPersistenceService(com.sequenceiq.cloudbreak.service.stack.LoadBalancerPersistenceService) Logger(org.slf4j.Logger) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) EventBus(reactor.bus.EventBus) EventStatus(com.sequenceiq.cloudbreak.cloud.event.model.EventStatus) PersistenceNotifier(com.sequenceiq.cloudbreak.cloud.notification.PersistenceNotifier) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) Collectors(java.util.stream.Collectors) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) List(java.util.List) Component(org.springframework.stereotype.Component) OperationException(com.sequenceiq.cloudbreak.service.OperationException) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) CloudLoadBalancerMetadata(com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancerMetadata) CommonAwsClient(com.sequenceiq.cloudbreak.cloud.aws.common.CommonAwsClient) CollectLoadBalancerMetadataResult(com.sequenceiq.cloudbreak.cloud.event.loadbalancer.CollectLoadBalancerMetadataResult) StackService(com.sequenceiq.cloudbreak.service.stack.StackService) CollectLoadBalancerMetadataRequest(com.sequenceiq.cloudbreak.cloud.event.loadbalancer.CollectLoadBalancerMetadataRequest) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) CollectLoadBalancerMetadataResult(com.sequenceiq.cloudbreak.cloud.event.loadbalancer.CollectLoadBalancerMetadataResult) OperationException(com.sequenceiq.cloudbreak.service.OperationException) LoadBalancerType(com.sequenceiq.common.api.type.LoadBalancerType)

Example 2 with CollectLoadBalancerMetadataResult

use of com.sequenceiq.cloudbreak.cloud.event.loadbalancer.CollectLoadBalancerMetadataResult 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));
    }
}
Also used : CollectLoadBalancerMetadataRequest(com.sequenceiq.cloudbreak.cloud.event.loadbalancer.CollectLoadBalancerMetadataRequest) Event(reactor.bus.Event) CollectLoadBalancerMetadataResult(com.sequenceiq.cloudbreak.cloud.event.loadbalancer.CollectLoadBalancerMetadataResult) CloudLoadBalancerMetadata(com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancerMetadata)

Example 3 with CollectLoadBalancerMetadataResult

use of com.sequenceiq.cloudbreak.cloud.event.loadbalancer.CollectLoadBalancerMetadataResult in project cloudbreak by hortonworks.

the class StackCreationActions method collectLoadBalancerMetadataAction.

@Bean(name = "COLLECTMETADATA_LOADBALANCER_STATE")
public Action<?, ?> collectLoadBalancerMetadataAction() {
    return new AbstractStackCreationAction<>(CollectLoadBalancerMetadataResult.class) {

        @Override
        protected void doExecute(StackCreationContext context, CollectLoadBalancerMetadataResult payload, Map<Object, Object> variables) {
            Stack stack = stackCreationService.setupLoadBalancerMetadata(context, payload);
            StackCreationContext newContext = new StackCreationContext(context.getFlowParameters(), stack, context.getCloudContext(), context.getCloudCredential(), context.getCloudStack());
            if (newContext.getStack().getTunnel().useCcm()) {
                GetTlsInfoResult getTlsInfoResult = new GetTlsInfoResult(context.getCloudContext().getId(), new TlsInfo(true));
                sendEvent(newContext, getTlsInfoResult.selector(), getTlsInfoResult);
            } else {
                sendEvent(newContext);
            }
        }

        @Override
        protected Selectable createRequest(StackCreationContext context) {
            CloudStack cloudStack = cloudStackConverter.convert(context.getStack());
            return new GetTlsInfoRequest<GetTlsInfoResult>(context.getCloudContext(), context.getCloudCredential(), cloudStack);
        }
    };
}
Also used : StackCreationContext(com.sequenceiq.cloudbreak.core.flow2.stack.start.StackCreationContext) TlsInfo(com.sequenceiq.cloudbreak.cloud.model.TlsInfo) GetTlsInfoResult(com.sequenceiq.cloudbreak.cloud.event.instance.GetTlsInfoResult) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) Map(java.util.Map) CollectLoadBalancerMetadataResult(com.sequenceiq.cloudbreak.cloud.event.loadbalancer.CollectLoadBalancerMetadataResult) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) GetTlsInfoRequest(com.sequenceiq.cloudbreak.cloud.event.instance.GetTlsInfoRequest) Bean(org.springframework.context.annotation.Bean)

Aggregations

CollectLoadBalancerMetadataResult (com.sequenceiq.cloudbreak.cloud.event.loadbalancer.CollectLoadBalancerMetadataResult)3 CollectLoadBalancerMetadataRequest (com.sequenceiq.cloudbreak.cloud.event.loadbalancer.CollectLoadBalancerMetadataRequest)2 CloudLoadBalancerMetadata (com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancerMetadata)2 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)2 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)2 Event (reactor.bus.Event)2 CommonAwsClient (com.sequenceiq.cloudbreak.cloud.aws.common.CommonAwsClient)1 AmazonElasticLoadBalancingClient (com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonElasticLoadBalancingClient)1 AwsContext (com.sequenceiq.cloudbreak.cloud.aws.common.context.AwsContext)1 AwsCredentialView (com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsCredentialView)1 AwsNativeLoadBalancerLaunchService (com.sequenceiq.cloudbreak.cloud.aws.resource.loadbalancer.AwsNativeLoadBalancerLaunchService)1 AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)1 GetTlsInfoRequest (com.sequenceiq.cloudbreak.cloud.event.instance.GetTlsInfoRequest)1 GetTlsInfoResult (com.sequenceiq.cloudbreak.cloud.event.instance.GetTlsInfoResult)1 EventStatus (com.sequenceiq.cloudbreak.cloud.event.model.EventStatus)1 CreateResourcesRequest (com.sequenceiq.cloudbreak.cloud.event.resource.migration.aws.CreateResourcesRequest)1 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)1 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)1 TlsInfo (com.sequenceiq.cloudbreak.cloud.model.TlsInfo)1 PersistenceNotifier (com.sequenceiq.cloudbreak.cloud.notification.PersistenceNotifier)1