@Override public Object call() throws Exception { final JobStatus jobStatus = getOrNull(client.jobStatus(jobId)); final TaskStatus taskStatus = jobStatus.getTaskStatuses().get(host); if (taskStatus.getThrottled() == FLAPPING) { return true; } final PortMapping port = taskStatus.getPorts().get("poke"); assert port.getExternalPort() != null; poke(port.getExternalPort()); return null; } });
@Override public Object call() throws Exception { final JobStatus jobStatus = getOrNull(client.jobStatus(jobId)); final TaskStatus taskStatus = jobStatus.getTaskStatuses().get(testHost()); final PortMapping port = taskStatus.getPorts().get("poke"); assert port.getExternalPort() != null; if (poke(port.getExternalPort())) { return true; } else { return null; } } });
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); } }
assertTrue(portRange.contains(firstTaskStatus1.getPorts().get("foo").getExternalPort())); assertTrue(portRange.contains(firstTaskStatus2.getPorts().get("foo").getExternalPort())); assertEquals(staticMapping1, firstTaskStatus1.getPorts().get("bar")); assertEquals(staticMapping2, firstTaskStatus2.getPorts().get("bar")); assertNotEquals(firstTaskStatus1.getPorts().get("foo"), firstTaskStatus2.getPorts().get("foo")); assertEquals(firstTaskStatus1.getPorts(), restartedTaskStatus1.getPorts()); assertEquals(firstTaskStatus2.getPorts(), restartedTaskStatus2.getPorts());
public void assertVolumes(final JobId jobId) throws Exception { // Wait for agent to come up awaitHostRegistered(client, testHost(), LONG_WAIT_SECONDS, SECONDS); awaitHostStatus(client, testHost(), UP, LONG_WAIT_SECONDS, SECONDS); // Deploy the job on the agent final Deployment deployment = Deployment.of(jobId, START); final JobDeployResponse deployed = client.deploy(deployment, testHost()).get(); assertEquals(JobDeployResponse.Status.OK, deployed.getStatus()); // Wait for the job to run final TaskStatus taskStatus = awaitJobState( client, testHost(), jobId, RUNNING, LONG_WAIT_SECONDS, SECONDS); assertJobEquals(job, taskStatus.getJob()); final Integer randomVolPort = taskStatus.getPorts().get("random").getExternalPort(); final Integer namedVolPort = taskStatus.getPorts().get("named").getExternalPort(); final Integer hostnamePort = taskStatus.getPorts().get("hostname").getExternalPort(); assert randomVolPort != null; assert namedVolPort != null; assert hostnamePort != null; // Read "foo" from /volume/bar and /mnt/my-volume/bar assertEquals("foo", recvUtf8(randomVolPort, 3)); assertEquals("foo", recvUtf8(namedVolPort, 3)); // Read hostname from /hostname final String hostname = getNewDockerClient().info().name(); final String mountedHostname = recvUtf8(hostnamePort, hostname.length()); assertEquals(hostname, mountedHostname); }
public void assertRamdisk(final JobId jobId) throws Exception { // Wait for agent to come up awaitHostRegistered(client, testHost(), LONG_WAIT_SECONDS, SECONDS); awaitHostStatus(client, testHost(), UP, LONG_WAIT_SECONDS, SECONDS); // Deploy the job on the agent final Deployment deployment = Deployment.of(jobId, START); final JobDeployResponse deployed = client.deploy(deployment, testHost()).get(); assertEquals(JobDeployResponse.Status.OK, deployed.getStatus()); // Wait for the job to run final TaskStatus taskStatus = awaitJobState( client, testHost(), jobId, RUNNING, LONG_WAIT_SECONDS, SECONDS); assertJobEquals(job, taskStatus.getJob()); final Integer dfPort = taskStatus.getPorts().get("df").getExternalPort(); assert dfPort != null; // If "/much-volatile" mount is present a line starting with tmpfs should be returned final String dfOutput = recvUtf8(dfPort, 5); assertEquals("tmpfs", dfOutput); }
/** * Returns the port that a job can be reached at given the host and name of registered port. * This is useful to discover the value of a dynamically allocated port. * @param host the host where the job is deployed * @param port the name of the registered port * @return the port where the job can be reached, or null if the host or port name is not found */ public Integer port(final String host, final String port) { checkArgument(hosts.contains(host), "host %s not found", host); checkArgument(job.getPorts().containsKey(port), "port %s not found", port); final TaskStatus status = statuses.get(host); if (status == null) { return null; } final PortMapping portMapping = status.getPorts().get(port); if (portMapping == null) { return null; } return portMapping.getExternalPort(); }
/** * Returns a {@link com.google.common.net.HostAndPort} object for a registered port, for each * host the job has been deployed to. This is useful for discovering the value of dynamically * allocated ports. * @param port the name of the registered port * @return a HostAndPort describing where the registered port can be reached. Null if * no ports have been registered. */ public List<HostAndPort> addresses(final String port) { checkArgument(job.getPorts().containsKey(port), "port %s not found", port); final List<HostAndPort> addresses = Lists.newArrayList(); for (Map.Entry<String, TaskStatus> entry : statuses.entrySet()) { final Integer externalPort = entry.getValue().getPorts().get(port).getExternalPort(); assert externalPort != null; final String host = endpointFromHost(entry.getKey()); addresses.add(HostAndPort.fromParts(host, externalPort)); } return addresses; }
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 Integer externalPort = taskStatus.getPorts().get(port).getExternalPort(); assert externalPort != null; Polling.awaitUnchecked(TIMEOUT_MILLIS, MILLISECONDS, new Callable<Boolean>() { @Override public Boolean call() throws Exception { log.info("Probing: {} @ {}:{}", port, endpoint, externalPort); final boolean up = prober.probe(endpoint, externalPort); if (up) { log.info("Up: {} @ {}:{}", port, endpoint, externalPort); return true; } else { return null; } } }); }
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 (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); } }