use of com.spotify.helios.common.descriptors.ServicePortParameters in project helios by spotify.
the class JobValidatorTest method testValidPortTagsPass.
@Test
public void testValidPortTagsPass() {
final Job j = Job.newBuilder().setName("foo").setVersion("1").setImage("foobar").build();
final Job.Builder builder = j.toBuilder();
final Map<String, PortMapping> ports = ImmutableMap.of("add_ports1", PortMapping.of(1234), "add_ports2", PortMapping.of(2345));
final ImmutableMap.Builder<String, ServicePortParameters> servicePortsBuilder = ImmutableMap.builder();
servicePortsBuilder.put("add_ports1", new ServicePortParameters(ImmutableList.of("tag1", "tag2")));
servicePortsBuilder.put("add_ports2", new ServicePortParameters(ImmutableList.of("tag3", "tag4")));
final ServicePorts servicePorts = new ServicePorts(servicePortsBuilder.build());
final Map<ServiceEndpoint, ServicePorts> addRegistration = ImmutableMap.of(ServiceEndpoint.of("add_service", "add_proto"), servicePorts);
builder.setPorts(ports).setRegistration(addRegistration);
assertThat(validator.validate(builder.build()), is(empty()));
}
use of com.spotify.helios.common.descriptors.ServicePortParameters in project helios by spotify.
the class TaskConfig method registration.
public ServiceRegistration registration() throws InterruptedException {
final ServiceRegistration.Builder builder = ServiceRegistration.newBuilder();
for (final Map.Entry<ServiceEndpoint, ServicePorts> entry : job.getRegistration().entrySet()) {
final ServiceEndpoint registration = entry.getKey();
final ServicePorts servicePorts = entry.getValue();
for (final Entry<String, ServicePortParameters> portEntry : servicePorts.getPorts().entrySet()) {
final String portName = portEntry.getKey();
final ServicePortParameters portParameters = portEntry.getValue();
final PortMapping mapping = job.getPorts().get(portName);
if (mapping == null) {
log.error("no '{}' port mapped for registration: '{}'", portName, registration);
continue;
}
final Integer externalPort;
if (mapping.getExternalPort() != null) {
// Use the statically assigned port if one is specified
externalPort = mapping.getExternalPort();
} else {
// Otherwise use the dynamically allocated port
externalPort = ports.get(portName);
}
if (externalPort == null) {
log.error("no external '{}' port for registration: '{}'", portName, registration);
continue;
}
builder.endpoint(registration.getName(), registration.getProtocol(), externalPort, fullyQualifiedRegistrationDomain(), host, portParameters.getTags(), endpointHealthCheck(portName));
}
}
return builder.build();
}
Aggregations