/** * Generate a random container name. * * @return The random container name. */ public String containerName() { final String shortId = job.getId().toShortString(); final String escaped = CONTAINER_NAME_FORBIDDEN.matcher(shortId).replaceAll("_"); final String random = Integer.toHexString(new SecureRandom().nextInt()); return namespace + "-" + escaped + "_" + random; }
private void fireStateChanged() { log.debug("Supervisor {}: state changed", job.getId()); try { listener.stateChanged(this); } catch (Exception e) { log.error("Listener threw exception", e); } }
@Override public void matchedStatus(JobStatus jobStatus, Iterable<String> matchingHosts, Map<String, TaskStatus> taskStatuses) { displayTask(full, table, jobStatus.getJob().getId(), jobStatus, taskStatuses, matchingHosts); } });
@Override public int compareTo(@NotNull final Job job) { return id.compareTo(job.getId()); }
@Override public void run(final boolean timeout) throws InterruptedException { final Command command = currentCommand; final boolean done = performedCommand == command; log.debug("Supervisor {}: update: performedCommand={}, command={}, done={}", job.getId(), performedCommand, command, done); command.perform(done); if (!done) { performedCommand = command; fireStateChanged(); } } }
public String name() { return job.getId().toShortString(); }
private static void verifyToken(final String token, final Job job) throws TokenVerificationException { checkNotNull(token, "token"); if (!token.equals(job.getToken())) { throw new TokenVerificationException(job.getId()); } }
@Override public void matchedStatus(JobStatus jobStatus, Iterable<String> matchingHosts, Map<String, TaskStatus> taskStatuses) { for (final String host : matchingHosts) { final Map<String, Deployment> deployments = jobStatus.getDeployments(); final Deployment deployment = (deployments == null) ? null : deployments.get(host); if (deployment != null) { returnStatuses.put(jobStatus.getJob().getId(), filterJobStatus(jobStatus, matchingHosts)); } } }
/** * Create a job supervisor. * * @param job The job . */ private Supervisor createSupervisor(final Job job, final Map<String, Integer> portAllocation) { log.debug("creating job supervisor: {}", job); final TaskStatus taskStatus = model.getTaskStatus(job.getId()); final String containerId = (taskStatus == null) ? null : taskStatus.getContainerId(); final Supervisor supervisor = supervisorFactory.create(job, containerId, portAllocation, supervisorListener); supervisors.put(job.getId(), supervisor); return supervisor; }
private void deploy(final Job job, final String host) throws Exception { Futures.addCallback(client.deploy(Deployment.of(job.getId(), START), host), new FutureCallback<JobDeployResponse>() { @Override public void onSuccess(final JobDeployResponse result) { assertEquals(JobDeployResponse.Status.OK, result.getStatus()); } @Override public void onFailure(@NotNull final Throwable th) { fail("deploy failed"); } }, MoreExecutors.directExecutor()); }
private void putBack(TaskStatusEvent event) { final JobId key = event.getStatus().getJob().getId(); final Deque<TaskStatusEvent> queue = getDeque(key); synchronized (queue) { if (queue.size() >= MAX_QUEUE_SIZE) { // already full, just toss the event return; } queue.push(event); count.incrementAndGet(); } }
protected String createJobRawOutput(final Job job) throws Exception { final String name = job.getId().getName(); checkArgument(name.contains(testTag), "Job name must contain testTag to enable cleanup"); final String serializedConfig = Json.asNormalizedString(job); final File configFile = temporaryFolder.newFile(); Files.write(serializedConfig, configFile, Charsets.UTF_8); final List<String> args = ImmutableList.of("-q", "-f", configFile.getAbsolutePath()); return cli("create", args); }
public Supervisor(final Builder builder) { this.job = checkNotNull(builder.job, "job"); this.docker = checkNotNull(builder.dockerClient, "docker"); this.restartPolicy = checkNotNull(builder.restartPolicy, "restartPolicy"); this.metrics = checkNotNull(builder.metrics, "metrics"); this.listener = checkNotNull(builder.listener, "listener"); this.currentCommand = new Nop(); this.containerId = builder.existingContainerId; this.runnerFactory = checkNotNull(builder.runnerFactory, "runnerFactory"); this.statusUpdater = checkNotNull(builder.statusUpdater, "statusUpdater"); this.monitor = checkNotNull(builder.monitor, "monitor"); this.reactor = new DefaultReactor("supervisor-" + job.getId(), new Update(), SECONDS.toMillis(30)); this.reactor.startAsync(); statusUpdater.setContainerId(containerId); this.sleeper = builder.sleeper; }
@Test public void testClient() throws Exception { final CreateJobResponse created = client.createJob(job).get(); assertEquals(CreateJobResponse.Status.OK, created.getStatus()); assertRamdisk(job.getId()); }
@Test public void testClient() throws Exception { final CreateJobResponse created = client.createJob(job).get(); assertEquals(CreateJobResponse.Status.OK, created.getStatus()); assertVolumes(job.getId()); }
private JobId createAndAwaitJobRunning() throws Exception { final CreateJobResponse jobby = client.createJob(job).get(); assertEquals(CreateJobResponse.Status.OK, jobby.getStatus()); final JobId jobId = job.getId(); final JobDeployResponse deployResponse = client.deploy( Deployment.of(jobId, START), TEST_HOST).get(); assertEquals(JobDeployResponse.Status.OK, deployResponse.getStatus()); awaitJobState(client, TEST_HOST, jobId, State.RUNNING, 30, TimeUnit.SECONDS); return jobId; }
@Test public void verifyCanDeployWithOnePeerDead() throws Exception { deploy(fooJob); zkc.stopPeer(0); undeploy(fooJob.getId()); deploy(barJob); }
private void deploy(final Job job) throws Exception { final JobId jobId = job.getId(); final CreateJobResponse created = client.createJob(job).get(); assertEquals(CreateJobResponse.Status.OK, created.getStatus()); 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 awaitJobState(client, testHost(), jobId, RUNNING, LONG_WAIT_SECONDS, SECONDS); }
@Override protected int runWithJob(final Namespace options, final HeliosClient client, final PrintStream out, final boolean json, final Job job, final BufferedReader stdin) throws ExecutionException, InterruptedException, IOException { final JobId jobId = job.getId(); final List<String> hosts = options.getList(hostsArg.getDest()); final Deployment deployment = new Deployment.Builder() .setGoal(Goal.START) .setJobId(jobId) .build(); if (!json) { out.printf("Starting %s on %s%n", jobId, hosts); } return Utils.setGoalOnHosts(client, out, json, hosts, deployment, options.getString(tokenArg.getDest())); } }
@Override public void update() throws InterruptedException { final TaskStatus status = builder .setGoal(goal) .setState(state) .setContainerId(containerId) .setThrottled(throttleState) .setContainerError(containerError) .build(); model.setTaskStatus(status.getJob().getId(), status); }