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;
}
Aggregations