Search in sources :

Example 1 with ServicePortParameters

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()));
}
Also used : ServicePorts(com.spotify.helios.common.descriptors.ServicePorts) ServicePortParameters(com.spotify.helios.common.descriptors.ServicePortParameters) Matchers.containsString(org.hamcrest.Matchers.containsString) PortMapping(com.spotify.helios.common.descriptors.PortMapping) Job(com.spotify.helios.common.descriptors.Job) ImmutableMap(com.google.common.collect.ImmutableMap) ServiceEndpoint(com.spotify.helios.common.descriptors.ServiceEndpoint) Test(org.junit.Test)

Example 2 with ServicePortParameters

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();
}
Also used : ServicePorts(com.spotify.helios.common.descriptors.ServicePorts) ServicePortParameters(com.spotify.helios.common.descriptors.ServicePortParameters) PortMapping(com.spotify.helios.common.descriptors.PortMapping) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) ServiceEndpoint(com.spotify.helios.common.descriptors.ServiceEndpoint) ServiceRegistration(com.spotify.helios.serviceregistration.ServiceRegistration)

Aggregations

ImmutableMap (com.google.common.collect.ImmutableMap)2 PortMapping (com.spotify.helios.common.descriptors.PortMapping)2 ServiceEndpoint (com.spotify.helios.common.descriptors.ServiceEndpoint)2 ServicePortParameters (com.spotify.helios.common.descriptors.ServicePortParameters)2 ServicePorts (com.spotify.helios.common.descriptors.ServicePorts)2 Job (com.spotify.helios.common.descriptors.Job)1 ServiceRegistration (com.spotify.helios.serviceregistration.ServiceRegistration)1 Map (java.util.Map)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1 Test (org.junit.Test)1