Search in sources :

Example 11 with PortMapping

use of com.spotify.helios.common.descriptors.PortMapping in project helios by spotify.

the class TemporaryJob method awaitPort.

private void awaitPort(final String port, final String host) throws TimeoutException {
    final String endpoint = endpointFromHost(host);
    final TaskStatus taskStatus = statuses.get(host);
    assert taskStatus != null;
    final PortMapping portMapping = taskStatus.getPorts().get(port);
    final Integer externalPort = portMapping.getExternalPort();
    assert externalPort != null;
    Polling.awaitUnchecked(TIMEOUT_MILLIS, MILLISECONDS, "Unable to connect to port " + port + " on host " + host + " within %d %s", new Callable<Boolean>() {

        @Override
        public Boolean call() throws Exception {
            log.info("Probing: {} @ {}:{}", port, endpoint, portMapping);
            final boolean up = prober.probe(endpoint, portMapping);
            if (up) {
                log.info("Up: {} @ {}:{}", port, endpoint, externalPort);
                return true;
            } else {
                return null;
            }
        }
    });
}
Also used : PortMapping(com.spotify.helios.common.descriptors.PortMapping) TaskStatus(com.spotify.helios.common.descriptors.TaskStatus) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TimeoutException(java.util.concurrent.TimeoutException) ExecutionException(java.util.concurrent.ExecutionException)

Example 12 with PortMapping

use of com.spotify.helios.common.descriptors.PortMapping in project helios by spotify.

the class JobStatusTable method task.

public void task(final JobId jobId, final String host, final TaskStatus ts, final Deployment deployment) {
    final String goal = (deployment == null) ? "" : deployment.getGoal().toString();
    final int maxContainerId = full ? Integer.MAX_VALUE : 7;
    final String jobIdString = full ? jobId.toString() : jobId.toShortString();
    if (ts == null) {
        table.row(jobIdString, host, goal, "", "", "");
    } else {
        final List<String> portMappings = new ArrayList<>();
        for (final Map.Entry<String, PortMapping> entry : ts.getPorts().entrySet()) {
            final PortMapping portMapping = entry.getValue();
            portMappings.add(String.format("%s=%d:%d", entry.getKey(), portMapping.getInternalPort(), portMapping.getExternalPort()));
        }
        String state = ts.getState().toString();
        if (ts.getThrottled() != ThrottleState.NO) {
            state += " (" + ts.getThrottled() + ")";
        }
        final String ports = Joiner.on(" ").join(portMappings);
        final String cid = truncate(fromNullable(ts.getContainerId()).or(""), maxContainerId, "");
        table.row(jobIdString, host, goal, state, cid, ports);
    }
}
Also used : ArrayList(java.util.ArrayList) PortMapping(com.spotify.helios.common.descriptors.PortMapping) Map(java.util.Map)

Example 13 with PortMapping

use of com.spotify.helios.common.descriptors.PortMapping 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 14 with PortMapping

use of com.spotify.helios.common.descriptors.PortMapping in project helios by spotify.

the class PortAllocator method allocate0.

private Map<String, Integer> allocate0(final Map<String, PortMapping> mappings, final Set<Integer> used) {
    final ImmutableMap.Builder<String, Integer> allocation = ImmutableMap.builder();
    for (final Map.Entry<String, PortMapping> entry : mappings.entrySet()) {
        final String name = entry.getKey();
        final PortMapping portMapping = entry.getValue();
        final Integer externalPort = portMapping.getExternalPort();
        if (externalPort == null) {
            if (!allocateDynamic(allocation, used, name)) {
                return null;
            }
        } else {
            if (!allocateStatic(allocation, used, name, externalPort)) {
                return null;
            }
        }
    }
    return allocation.build();
}
Also used : PortMapping(com.spotify.helios.common.descriptors.PortMapping) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 15 with PortMapping

use of com.spotify.helios.common.descriptors.PortMapping in project helios by spotify.

the class TaskConfig method ports.

/**
   * Get final port mappings using allocated ports.
   * @return The port mapping.
   */
public Map<String, PortMapping> ports() {
    final ImmutableMap.Builder<String, PortMapping> builder = ImmutableMap.builder();
    for (final Map.Entry<String, PortMapping> e : job.getPorts().entrySet()) {
        final PortMapping mapping = e.getValue();
        builder.put(e.getKey(), mapping.hasExternalPort() ? mapping : mapping.withExternalPort(checkNotNull(ports.get(e.getKey()))));
    }
    return builder.build();
}
Also used : PortMapping(com.spotify.helios.common.descriptors.PortMapping) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) ImmutableMap(com.google.common.collect.ImmutableMap)

Aggregations

PortMapping (com.spotify.helios.common.descriptors.PortMapping)21 Test (org.junit.Test)11 ServiceEndpoint (com.spotify.helios.common.descriptors.ServiceEndpoint)9 ServicePorts (com.spotify.helios.common.descriptors.ServicePorts)9 Job (com.spotify.helios.common.descriptors.Job)8 Map (java.util.Map)8 ImmutableMap (com.google.common.collect.ImmutableMap)7 JobId (com.spotify.helios.common.descriptors.JobId)7 TaskStatus (com.spotify.helios.common.descriptors.TaskStatus)6 HeliosClient (com.spotify.helios.client.HeliosClient)5 File (java.io.File)3 DockerClient (com.spotify.docker.client.DockerClient)2 HostStatus (com.spotify.helios.common.descriptors.HostStatus)2 JobStatus (com.spotify.helios.common.descriptors.JobStatus)2 ServicePortParameters (com.spotify.helios.common.descriptors.ServicePortParameters)2 CreateJobResponse (com.spotify.helios.common.protocol.CreateJobResponse)2 ServiceRegistration (com.spotify.helios.serviceregistration.ServiceRegistration)2 FileOutputStream (java.io.FileOutputStream)2 Matchers.containsString (org.hamcrest.Matchers.containsString)2 ImmutableList (com.google.common.collect.ImmutableList)1