Search in sources :

Example 1 with ForwardingRuleList

use of com.google.api.services.compute.model.ForwardingRuleList 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

Compute (com.google.api.services.compute.Compute)1 ForwardingRule (com.google.api.services.compute.model.ForwardingRule)1 ForwardingRuleList (com.google.api.services.compute.model.ForwardingRuleList)1 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)1 CloudLoadBalancerMetadata (com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancerMetadata)1 LoadBalancerType (com.sequenceiq.common.api.type.LoadBalancerType)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1