Search in sources :

Example 1 with UpstreamInfo

use of com.hubspot.baragon.models.UpstreamInfo in project Singularity by HubSpot.

the class LoadBalancerClientImpl method enqueue.

@Override
public SingularityLoadBalancerUpdate enqueue(LoadBalancerRequestId loadBalancerRequestId, SingularityRequest request, SingularityDeploy deploy, List<SingularityTask> add, List<SingularityTask> remove) {
    final List<String> serviceOwners = request.getOwners().or(Collections.<String>emptyList());
    final Set<String> loadBalancerGroups = deploy.getLoadBalancerGroups().or(Collections.<String>emptySet());
    final BaragonService lbService = new BaragonService(deploy.getLoadBalancerServiceIdOverride().or(request.getId()), serviceOwners, deploy.getServiceBasePath().get(), deploy.getLoadBalancerAdditionalRoutes().or(Collections.<String>emptyList()), loadBalancerGroups, deploy.getLoadBalancerOptions().orNull(), deploy.getLoadBalancerTemplate(), deploy.getLoadBalancerDomains().or(Collections.<String>emptySet()));
    final List<UpstreamInfo> addUpstreams = tasksToUpstreams(add, loadBalancerRequestId.toString(), deploy.getLoadBalancerUpstreamGroup());
    final List<UpstreamInfo> removeUpstreams = tasksToUpstreams(remove, loadBalancerRequestId.toString(), deploy.getLoadBalancerUpstreamGroup());
    final BaragonRequest loadBalancerRequest = new BaragonRequest(loadBalancerRequestId.toString(), lbService, addUpstreams, removeUpstreams);
    return sendBaragonRequest(loadBalancerRequestId, loadBalancerRequest, LoadBalancerMethod.ENQUEUE);
}
Also used : BaragonService(com.hubspot.baragon.models.BaragonService) UpstreamInfo(com.hubspot.baragon.models.UpstreamInfo) BaragonRequest(com.hubspot.baragon.models.BaragonRequest)

Example 2 with UpstreamInfo

use of com.hubspot.baragon.models.UpstreamInfo in project Singularity by HubSpot.

the class LoadBalancerClientImpl method tasksToUpstreams.

private List<UpstreamInfo> tasksToUpstreams(List<SingularityTask> tasks, String requestId, Optional<String> loadBalancerUpstreamGroup) {
    final List<UpstreamInfo> upstreams = Lists.newArrayListWithCapacity(tasks.size());
    for (SingularityTask task : tasks) {
        final Optional<Long> maybeLoadBalancerPort = MesosUtils.getPortByIndex(mesosProtosUtils.toResourceList(task.getMesosTask().getResources()), task.getTaskRequest().getDeploy().getLoadBalancerPortIndex().or(0));
        if (maybeLoadBalancerPort.isPresent()) {
            String upstream = String.format("%s:%d", task.getHostname(), maybeLoadBalancerPort.get());
            Optional<String> group = loadBalancerUpstreamGroup;
            if (taskLabelForLoadBalancerUpstreamGroup.isPresent()) {
                for (MesosParameter label : task.getMesosTask().getLabels().getLabels()) {
                    if (label.hasKey() && label.getKey().equals(taskLabelForLoadBalancerUpstreamGroup.get()) && label.hasValue()) {
                        group = Optional.of(label.getValue());
                        break;
                    }
                }
            }
            upstreams.add(new UpstreamInfo(upstream, Optional.of(requestId), task.getRackId(), Optional.<String>absent(), group));
        } else {
            LOG.warn("Task {} is missing port but is being passed to LB  ({})", task.getTaskId(), task);
        }
    }
    return upstreams;
}
Also used : SingularityTask(com.hubspot.singularity.SingularityTask) MesosParameter(com.hubspot.mesos.protos.MesosParameter) UpstreamInfo(com.hubspot.baragon.models.UpstreamInfo)

Aggregations

UpstreamInfo (com.hubspot.baragon.models.UpstreamInfo)2 BaragonRequest (com.hubspot.baragon.models.BaragonRequest)1 BaragonService (com.hubspot.baragon.models.BaragonService)1 MesosParameter (com.hubspot.mesos.protos.MesosParameter)1 SingularityTask (com.hubspot.singularity.SingularityTask)1