use of com.hubspot.mesos.protos.MesosParameter 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;
}
Aggregations