Search in sources :

Example 1 with CloudLoadBalancerMetadata

use of com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancerMetadata 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 CloudLoadBalancerMetadata

use of com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancerMetadata in project cloudbreak by hortonworks.

the class LoadBalancerRecreatorService method recreate.

@Override
public void recreate(CreateResourcesRequest request, AwsContext awsContext, AuthenticatedContext ac) throws Exception {
    LOGGER.info("Launching elastic load balancers");
    CloudCredential cloudCredential = ac.getCloudCredential();
    String region = ac.getCloudContext().getLocation().getRegion().value();
    AwsCredentialView awsCredentialView = new AwsCredentialView(cloudCredential);
    AmazonElasticLoadBalancingClient elasticLoadBalancingClient = commonAwsClient.createElasticLoadBalancingClient(awsCredentialView, region);
    CloudStack cloudStack = request.getCloudStack();
    loadBalancerLaunchService.launchLoadBalancerResources(ac, cloudStack, persistenceNotifier, elasticLoadBalancingClient, false);
    List<CloudLoadBalancerMetadata> cloudLoadBalancerMetadata = collectLoadBalancerMetadata(ac, ac.getCloudContext().getId());
    Stack stack = stackService.getByIdWithLists(ac.getCloudContext().getId());
    metadataSetupService.saveLoadBalancerMetadata(stack, cloudLoadBalancerMetadata);
}
Also used : AwsCredentialView(com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsCredentialView) AmazonElasticLoadBalancingClient(com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonElasticLoadBalancingClient) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) CloudLoadBalancerMetadata(com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancerMetadata) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack)

Example 3 with CloudLoadBalancerMetadata

use of com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancerMetadata 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 4 with CloudLoadBalancerMetadata

use of com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancerMetadata 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)

Example 5 with CloudLoadBalancerMetadata

use of com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancerMetadata in project cloudbreak by hortonworks.

the class GCPLoadBalancerMetadataCollectorTest method testNullPortInformation.

@Test
public void testNullPortInformation() {
    List<CloudResource> resources = new ArrayList<>();
    resources.add(createCloudResource(FORWARDING_RULE_NAME_1, ResourceType.GCP_FORWARDING_RULE));
    ForwardingRule publicFowardingRule = createPublicFowardingRule();
    publicFowardingRule.setPorts(null);
    when(forwardingRuleListResponse.getItems()).thenReturn(List.of(publicFowardingRule));
    List<CloudLoadBalancerMetadata> result = underTest.collectLoadBalancer(authenticatedContext, List.of(LoadBalancerType.PUBLIC), resources);
    assertEquals(1, result.size());
    assertEquals(PUBLIC_IP, result.get(0).getIp());
    assertEquals(LoadBalancerType.PUBLIC, result.get(0).getType());
    assertEquals(FORWARDING_RULE_NAME_1, result.get(0).getName());
    assertEquals(FORWARDING_RULE_NAME_1, result.get(0).getStringParameter(GcpLoadBalancerMetadataView.LOADBALANCER_NAME));
    assertNull(result.get(0).getStringParameter(GcpLoadBalancerMetadataView.getBackendServiceParam(8080)));
    assertNull(result.get(0).getStringParameter(GcpLoadBalancerMetadataView.getInstanceGroupParam(8080)));
}
Also used : ForwardingRule(com.google.api.services.compute.model.ForwardingRule) ArrayList(java.util.ArrayList) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) CloudLoadBalancerMetadata(com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancerMetadata) Test(org.junit.jupiter.api.Test)

Aggregations

CloudLoadBalancerMetadata (com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancerMetadata)45 ArrayList (java.util.ArrayList)22 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)20 LoadBalancerType (com.sequenceiq.common.api.type.LoadBalancerType)18 Test (org.junit.jupiter.api.Test)17 Test (org.junit.Test)16 AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)9 List (java.util.List)9 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)8 Optional (java.util.Optional)8 LoadBalancer (com.amazonaws.services.elasticloadbalancingv2.model.LoadBalancer)7 AwsCredentialView (com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsCredentialView)7 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)7 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)7 CloudVmMetaDataStatus (com.sequenceiq.cloudbreak.cloud.model.CloudVmMetaDataStatus)7 TargetGroup (com.sequenceiq.cloudbreak.domain.stack.loadbalancer.TargetGroup)7 Map (java.util.Map)7 Collectors (java.util.stream.Collectors)7 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)7 ForwardingRule (com.google.api.services.compute.model.ForwardingRule)6