Search in sources :

Example 1 with LoadBalancerType

use of com.sequenceiq.common.api.type.LoadBalancerType 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 LoadBalancerType

use of com.sequenceiq.common.api.type.LoadBalancerType 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)

Example 3 with LoadBalancerType

use of com.sequenceiq.common.api.type.LoadBalancerType in project cloudbreak by hortonworks.

the class AwsLoadBalancerCommonService method convertLoadBalancer.

@VisibleForTesting
AwsLoadBalancer convertLoadBalancer(CloudLoadBalancer cloudLoadBalancer, Map<String, List<String>> instanceIdsByGroupName, AwsNetworkView awsNetworkView, List<AwsLoadBalancer> awsLoadBalancers) {
    // Check and see if we already have a load balancer whose scheme matches this one.
    AwsLoadBalancer currentLoadBalancer = null;
    LoadBalancerType cloudLbType = cloudLoadBalancer.getType();
    Set<String> subnetIds = selectLoadBalancerSubnetIds(cloudLbType, awsNetworkView, cloudLoadBalancer);
    AwsLoadBalancerScheme scheme = loadBalancerTypeConverter.convert(cloudLbType);
    currentLoadBalancer = awsLoadBalancers.stream().filter(lb -> lb.getScheme() == scheme).findFirst().orElse(new AwsLoadBalancer(scheme));
    currentLoadBalancer.addSubnets(subnetIds);
    setupLoadBalancer(cloudLoadBalancer, instanceIdsByGroupName, currentLoadBalancer);
    return currentLoadBalancer;
}
Also used : Logger(org.slf4j.Logger) TargetGroupPortPair(com.sequenceiq.cloudbreak.cloud.model.TargetGroupPortPair) LoggerFactory(org.slf4j.LoggerFactory) Set(java.util.Set) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) AwsListener(com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsListener) LoadBalancerType(com.sequenceiq.common.api.type.LoadBalancerType) HashSet(java.util.HashSet) Inject(javax.inject.Inject) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) AwsNetworkView(com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsNetworkView) List(java.util.List) GroupSubnet(com.sequenceiq.cloudbreak.cloud.model.GroupSubnet) Service(org.springframework.stereotype.Service) Group(com.sequenceiq.cloudbreak.cloud.model.Group) Map(java.util.Map) CloudLoadBalancer(com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancer) AwsLoadBalancer(com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsLoadBalancer) VisibleForTesting(com.google.common.annotations.VisibleForTesting) AwsLoadBalancerScheme(com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsLoadBalancerScheme) LoadBalancerTypeConverter(com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.LoadBalancerTypeConverter) AwsLoadBalancer(com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsLoadBalancer) LoadBalancerType(com.sequenceiq.common.api.type.LoadBalancerType) AwsLoadBalancerScheme(com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsLoadBalancerScheme) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 4 with LoadBalancerType

use of com.sequenceiq.common.api.type.LoadBalancerType in project cloudbreak by hortonworks.

the class AzureMetadataCollector method collectLoadBalancer.

@Override
public List<CloudLoadBalancerMetadata> collectLoadBalancer(AuthenticatedContext ac, List<LoadBalancerType> loadBalancerTypes, List<CloudResource> resources) {
    LOGGER.debug("Collecting Azure load balancer metadata, for cluster {}", ac.getCloudContext().getName());
    List<CloudLoadBalancerMetadata> cloudLoadBalancerMetadata = new ArrayList<>();
    String resourceGroup = azureUtils.getTemplateResource(resources).getName();
    final String stackName = azureUtils.getStackName(ac.getCloudContext());
    AzureClient azureClient = ac.getParameter(AzureClient.class);
    for (LoadBalancerType type : loadBalancerTypes) {
        String loadBalancerName = AzureLoadBalancer.getLoadBalancerName(type, stackName);
        LOGGER.debug("Attempting to collect metadata for load balancer {}, type {}", loadBalancerName, type);
        try {
            Optional<String> ip;
            if (LoadBalancerType.PUBLIC.equals(type)) {
                ip = lookupPublicIp(resourceGroup, azureClient, loadBalancerName);
            } else if (LoadBalancerType.PRIVATE.equals(type)) {
                ip = lookupPrivateIp(resourceGroup, azureClient, loadBalancerName);
            } else {
                ip = Optional.empty();
            }
            if (ip.isPresent()) {
                Map<String, Object> parameters = azureLbMetadataCollector.getParameters(ac, resourceGroup, loadBalancerName);
                CloudLoadBalancerMetadata loadBalancerMetadata = new CloudLoadBalancerMetadata.Builder().withType(type).withIp(ip.get()).withName(loadBalancerName).withParameters(parameters).build();
                cloudLoadBalancerMetadata.add(loadBalancerMetadata);
                LOGGER.debug("Saved metadata for load balancer: {}", loadBalancerMetadata);
            } else {
                LOGGER.warn("Unable to find metadata for load balancer {}.", loadBalancerName);
            }
        } catch (RuntimeException e) {
            LOGGER.warn("Unable to find metadata for load balancer " + loadBalancerName, e);
        }
    }
    return cloudLoadBalancerMetadata;
}
Also used : AzureClient(com.sequenceiq.cloudbreak.cloud.azure.client.AzureClient) ArrayList(java.util.ArrayList) CloudLoadBalancerMetadata(com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancerMetadata) LoadBalancerType(com.sequenceiq.common.api.type.LoadBalancerType)

Example 5 with LoadBalancerType

use of com.sequenceiq.common.api.type.LoadBalancerType in project cloudbreak by hortonworks.

the class GcpMetadataCollector method collectLoadBalancer.

@Override
public List<CloudLoadBalancerMetadata> collectLoadBalancer(AuthenticatedContext ac, List<LoadBalancerType> loadBalancerTypes, List<CloudResource> resources) {
    CloudCredential credential = ac.getCloudCredential();
    Compute compute = gcpComputeFactory.buildCompute(credential);
    String projectId = gcpStackUtil.getProjectId(credential);
    String region = ac.getCloudContext().getLocation().getRegion().getRegionName();
    List<CloudLoadBalancerMetadata> results = new ArrayList<>();
    Set<String> names = resources.stream().filter(resource -> resource.getType().equals(ResourceType.GCP_FORWARDING_RULE)).map(CloudResource::getName).collect(Collectors.toSet());
    try {
        ForwardingRuleList forwardingRuleList = compute.forwardingRules().list(projectId, region).execute();
        if (forwardingRuleList.getWarning() != null) {
            LOGGER.warn("Warning fetching GCP loadbalancer metadata, {}", forwardingRuleList.getWarning().getMessage());
        }
        for (ForwardingRule item : forwardingRuleList.getItems()) {
            LoadBalancerType itemType = gcpLoadBalancerTypeConverter.getScheme(item.getLoadBalancingScheme()).getCbType();
            if (names.contains(item.getName()) && loadBalancerTypes.contains(itemType)) {
                Map<String, Object> params = getParams(compute, projectId, item);
                CloudLoadBalancerMetadata loadBalancerMetadata = new CloudLoadBalancerMetadata.Builder().withType(itemType).withIp(item.getIPAddress()).withName(item.getName()).withParameters(params).build();
                results.add(loadBalancerMetadata);
            }
        }
    } catch (RuntimeException | IOException e) {
        LOGGER.error("Couldn't collect GCP LB metadata for {} ", projectId, e);
    }
    // no-op
    return results;
}
Also used : ForwardingRule(com.google.api.services.compute.model.ForwardingRule) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) ArrayList(java.util.ArrayList) IOException(java.io.IOException) CloudLoadBalancerMetadata(com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancerMetadata) LoadBalancerType(com.sequenceiq.common.api.type.LoadBalancerType) ForwardingRuleList(com.google.api.services.compute.model.ForwardingRuleList) Compute(com.google.api.services.compute.Compute)

Aggregations

LoadBalancerType (com.sequenceiq.common.api.type.LoadBalancerType)36 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)21 AwsNetworkView (com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsNetworkView)18 StackResourceSummary (com.amazonaws.services.cloudformation.model.StackResourceSummary)12 Test (org.junit.jupiter.api.Test)12 CloudLoadBalancerMetadata (com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancerMetadata)11 GroupNetwork (com.sequenceiq.cloudbreak.cloud.model.GroupNetwork)11 Network (com.sequenceiq.cloudbreak.cloud.model.Network)11 Test (org.junit.Test)11 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)11 CloudLoadBalancer (com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancer)9 CloudConnectorException (com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException)8 ArrayList (java.util.ArrayList)7 List (java.util.List)6 Collectors (java.util.stream.Collectors)6 Inject (javax.inject.Inject)6 CloudResourceStatus (com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus)5 Logger (org.slf4j.Logger)5 DescribeLoadBalancersResult (com.amazonaws.services.elasticloadbalancingv2.model.DescribeLoadBalancersResult)4 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)4