Search in sources :

Example 1 with BackendService

use of com.google.api.services.compute.model.BackendService in project cloudbreak by hortonworks.

the class GCPLoadBalancerMetadataCollectorTest method createBackendService.

private BackendService createBackendService() {
    BackendService backendService = new BackendService();
    backendService.setName(BACKEND_SERVICE_NAME);
    Backend backend = new Backend();
    backend.setGroup(INSTANCE_GROUP_NAME);
    backendService.setBackends(List.of(backend));
    return backendService;
}
Also used : BackendService(com.google.api.services.compute.model.BackendService) Backend(com.google.api.services.compute.model.Backend)

Example 2 with BackendService

use of com.google.api.services.compute.model.BackendService in project cloudbreak by hortonworks.

the class GcpBackendServiceResourceBuilder method build.

@Override
public List<CloudResource> build(GcpContext context, AuthenticatedContext auth, List<CloudResource> buildableResources, CloudLoadBalancer loadBalancer, CloudStack cloudStack) throws Exception {
    List<CloudResource> results = new ArrayList<>();
    String projectId = context.getProjectId();
    String zone = context.getLocation().getAvailabilityZone().value();
    List<CloudResource> healthResources = filterResourcesByType(context.getLoadBalancerResources(loadBalancer.getType()), ResourceType.GCP_HEALTH_CHECK);
    for (CloudResource buildableResource : buildableResources) {
        LOGGER.info("Building backend service {} for {}", buildableResource.getName(), projectId);
        Optional<String> name = healthResources.stream().filter(healthResource -> buildableResource.getParameter(HCPORT, Integer.class).equals(healthResource.getParameter(HCPORT, Integer.class))).findFirst().map(CloudResource::getName);
        if (!name.isPresent()) {
            LOGGER.info("Health check resource not found for port {}", buildableResource.getParameter(HCPORT, Integer.class));
        }
        BackendService backendService = new BackendService();
        backendService.setHealthChecks(Collections.singletonList(String.format(GCP_HEALTH_CHECK_FORMAT, projectId, context.getLocation().getRegion().getRegionName(), name.get())));
        List<Backend> backends = new ArrayList<>();
        Map<String, Object> portMap = buildableResource.getParameters();
        Integer hcPort = buildableResource.getParameter(HCPORT, Integer.class);
        Set<Group> groups = new HashSet<>();
        if (portMap.containsKey(TRAFFICPORTS)) {
            for (Integer trafficPort : (List<Integer>) portMap.get(TRAFFICPORTS)) {
                TargetGroupPortPair targetGroupPortPair = new TargetGroupPortPair(trafficPort, hcPort);
                groups.addAll(loadBalancer.getPortToTargetGroupMapping().get(targetGroupPortPair));
            }
        } else {
            Integer trafficPort = buildableResource.getParameter(TRAFFICPORT, Integer.class);
            TargetGroupPortPair targetGroupPortPair = new TargetGroupPortPair(trafficPort, hcPort);
            groups.addAll(loadBalancer.getPortToTargetGroupMapping().get(targetGroupPortPair));
        }
        makeBackendForTargetGroup(context, loadBalancer, projectId, zone, groups, backends);
        backendService.setBackends(backends);
        backendService.setName(buildableResource.getName());
        backendService.setLoadBalancingScheme(gcpLoadBalancerTypeConverter.getScheme(loadBalancer).getGcpType());
        backendService.setProtocol("TCP");
        String regionName = context.getLocation().getRegion().getRegionName();
        Insert insert = context.getCompute().regionBackendServices().insert(projectId, regionName, backendService);
        results.add(doOperationalRequest(buildableResource, insert));
    }
    return results;
}
Also used : Group(com.sequenceiq.cloudbreak.cloud.model.Group) ArrayList(java.util.ArrayList) Insert(com.google.api.services.compute.Compute.RegionBackendServices.Insert) BackendService(com.google.api.services.compute.model.BackendService) Backend(com.google.api.services.compute.model.Backend) ArrayList(java.util.ArrayList) List(java.util.List) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) TargetGroupPortPair(com.sequenceiq.cloudbreak.cloud.model.TargetGroupPortPair) HashSet(java.util.HashSet)

Example 3 with BackendService

use of com.google.api.services.compute.model.BackendService in project cloudbreak by hortonworks.

the class GcpMetadataCollector method getParams.

private Map<String, Object> getParams(Compute compute, String projectId, ForwardingRule item) {
    Map<String, Object> params = new HashMap<>();
    List<String> ports = item.getPorts();
    params.put(GcpLoadBalancerMetadataView.LOADBALANCER_NAME, item.getName());
    if (ports == null || ports.size() != 1) {
        LOGGER.warn("Unexpected port count on {}, {}", item.getName(), ports);
    }
    if (ports != null && !ports.isEmpty()) {
        try {
            String backendService = item.getBackendService();
            params.put(GcpLoadBalancerMetadataView.getBackendServiceParam(ports.get(0)), backendService);
            BackendService service = compute.backendServices().get(projectId, backendService).execute();
            params.put(GcpLoadBalancerMetadataView.getInstanceGroupParam(ports.get(0)), service.getBackends().get(0).getGroup());
        } catch (RuntimeException | IOException e) {
            LOGGER.error("Couldn't deterimine instancegroups for {}", item.getName(), e);
        }
    }
    return params;
}
Also used : BackendService(com.google.api.services.compute.model.BackendService) HashMap(java.util.HashMap) IOException(java.io.IOException)

Aggregations

BackendService (com.google.api.services.compute.model.BackendService)3 Backend (com.google.api.services.compute.model.Backend)2 Insert (com.google.api.services.compute.Compute.RegionBackendServices.Insert)1 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)1 Group (com.sequenceiq.cloudbreak.cloud.model.Group)1 TargetGroupPortPair (com.sequenceiq.cloudbreak.cloud.model.TargetGroupPortPair)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1