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;
}
}
});
}
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);
}
}
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()));
}
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();
}
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();
}
Aggregations