use of com.spotify.helios.common.protocol.JobDeployResponse in project helios by spotify.
the class CliDeploymentTest method testUndeployingNonexistantJobJson.
@Test
public void testUndeployingNonexistantJobJson() throws Exception {
startDefaultMaster();
// Wait for master to come up
Polling.await(LONG_WAIT_SECONDS, SECONDS, new Callable<String>() {
@Override
public String call() throws Exception {
final String output = cli("masters");
return output.contains(masterName()) ? output : null;
}
});
// Verify that undeploying a nonexistent job from a host fails
final String output = cli("undeploy", "--json", BOGUS_JOB.toString(), testHost());
final JobDeployResponse jobDeployResponse = Json.read(output, JobDeployResponse.class);
assertEquals(JobDeployResponse.Status.JOB_NOT_FOUND, jobDeployResponse.getStatus());
}
use of com.spotify.helios.common.protocol.JobDeployResponse in project helios by spotify.
the class JobDeployCommand method runWithJobId.
@Override
protected int runWithJobId(final Namespace options, final HeliosClient client, final PrintStream out, final boolean json, final JobId jobId, final BufferedReader stdin) throws ExecutionException, InterruptedException {
final List<String> hosts = options.getList(hostsArg.getDest());
final Deployment job = Deployment.of(jobId, options.getBoolean(noStartArg.getDest()) ? STOP : START);
if (!json) {
out.printf("Deploying %s on %s%n", job, hosts);
}
int code = 0;
final HostResolver resolver = HostResolver.create(client);
final List<String> resolvedHosts = Lists.newArrayList();
for (final String candidateHost : hosts) {
final String host = resolver.resolveName(candidateHost);
resolvedHosts.add(host);
if (!json) {
out.printf("%s: ", host);
}
final String token = options.getString(tokenArg.getDest());
final JobDeployResponse result = client.deploy(job, host, token).get();
if (result.getStatus() == JobDeployResponse.Status.OK) {
if (!json) {
out.printf("done%n");
} else {
out.print(result.toJsonString());
}
} else {
if (!json) {
out.printf("failed: %s%n", result);
} else {
out.print(result.toJsonString());
}
code = 1;
}
}
if (code == 0 && options.getBoolean(watchArg.getDest())) {
JobWatchCommand.watchJobsOnHosts(out, true, resolvedHosts, ImmutableList.of(jobId), options.getInt(intervalArg.getDest()), client);
}
return code;
}
use of com.spotify.helios.common.protocol.JobDeployResponse in project helios by spotify.
the class TemporaryJob method deploy.
void deploy() {
final TemporaryJobReports.Step createJob = reportWriter.step("create job").tag("jobId", job.getId());
try {
// Create job
log.info("Creating job {}", job.getId().toShortString());
final CreateJobResponse createResponse = get(client.createJob(job));
if (createResponse.getStatus() != CreateJobResponse.Status.OK) {
fail(format("Failed to create job %s - %s", job.getId(), createResponse.toString()));
}
createJob.markSuccess();
} catch (InterruptedException | ExecutionException | TimeoutException e) {
fail(format("Failed to create job %s %s - %s", job.getId(), job.toString(), e));
} finally {
createJob.finish();
}
final TemporaryJobReports.Step deployJob = reportWriter.step("deploy job").tag("jobId", job.getId());
try {
// Deploy job
final Deployment deployment = Deployment.of(job.getId(), Goal.START);
for (final String host : hosts) {
// HELIOS_HOST_ADDRESS is the IP address we should use to reach the host, instead of
// the hostname. This is used when running a helios cluster inside a VM, and the containers
// can be reached by IP address only, since DNS won't be able to resolve the host name of
// the helios agent running in the VM.
final HostStatus hostStatus = client.hostStatus(host).get();
final String hostAddress = hostStatus.getEnvironment().get("HELIOS_HOST_ADDRESS");
if (hostAddress != null) {
hostToIp.put(host, hostAddress);
}
log.info("Deploying {} to {}", getJobDescription(job), host);
final JobDeployResponse deployResponse = get(client.deploy(deployment, host));
if (deployResponse.getStatus() != JobDeployResponse.Status.OK) {
fail(format("Failed to deploy job %s %s - %s", job.getId(), job.toString(), deployResponse));
}
}
deployJob.markSuccess();
} catch (InterruptedException | ExecutionException | TimeoutException e) {
fail(format("Failed to deploy job %s %s - %s", job.getId(), job.toString(), e));
} finally {
deployJob.finish();
}
try {
// Wait for job to come up
for (final String host : hosts) {
awaitUp(host);
}
} catch (TimeoutException e) {
fail(format("Failed while probing job %s %s - %s", job.getId(), job.toString(), e));
}
}
use of com.spotify.helios.common.protocol.JobDeployResponse in project helios by spotify.
the class ZooKeeperRestoreTest method verifyAgentPushesTaskStateAfterRestore.
@Test
public void verifyAgentPushesTaskStateAfterRestore() throws Exception {
// Start agent once to have it register
final AgentMain agent1 = startDefaultAgent(testHost());
awaitHostStatus(client, testHost(), UP, LONG_WAIT_SECONDS, SECONDS);
agent1.stopAsync().awaitTerminated();
// Deploy job
final Deployment deployment = Deployment.of(fooJob.getId(), START);
final JobDeployResponse deployed = client.deploy(deployment, testHost()).get();
assertEquals(JobDeployResponse.Status.OK, deployed.getStatus());
// Back up zk
zkc.backup(backupDir);
// Start agent
startDefaultAgent(testHost());
awaitHostStatus(client, testHost(), UP, LONG_WAIT_SECONDS, SECONDS);
// Wait for agent to indicate that job is running
awaitJobState(client, testHost(), fooJob.getId(), RUNNING, LONG_WAIT_SECONDS, SECONDS);
// Restore zk, erasing task state
zkc.stop();
zkc.restore(backupDir);
zkc.start();
// Wait for agent to again indicate that job is running
awaitJobState(client, testHost(), fooJob.getId(), RUNNING, LONG_WAIT_SECONDS, SECONDS);
// Remove task status
zkc.curatorWithSuperAuth().delete().forPath(Paths.statusHostJob(testHost(), fooJob.getId()));
}
use of com.spotify.helios.common.protocol.JobDeployResponse in project helios by spotify.
the class WildcardJobCommand method run.
@Override
int run(final Namespace options, final HeliosClient client, final PrintStream out, final boolean json, final BufferedReader stdin) throws ExecutionException, InterruptedException, IOException {
final String jobIdString = options.getString(jobArg.getDest());
final Map<JobId, Job> jobs = client.jobs(jobIdString).get();
if (jobs.size() == 0) {
if (!json) {
out.printf("Unknown job: %s%n", jobIdString);
} else {
final JobDeployResponse jobDeployResponse = new JobDeployResponse(JobDeployResponse.Status.JOB_NOT_FOUND, null, null);
out.print(jobDeployResponse.toJsonString());
}
return 1;
} else if (jobs.size() > 1) {
if (!json) {
out.printf("Ambiguous job reference: %s%n", jobIdString);
} else {
final JobDeployResponse jobDeployResponse = new JobDeployResponse(JobDeployResponse.Status.AMBIGUOUS_JOB_REFERENCE, null, null);
out.print(jobDeployResponse.toJsonString());
}
return 1;
}
final JobId jobId = Iterables.getOnlyElement(jobs.keySet());
return runWithJobId(options, client, out, json, jobId, stdin);
}
Aggregations