use of com.hashicorp.nomad.apimodel.Job in project heron by twitter.
the class NomadScheduler method onKill.
@Override
public boolean onKill(Scheduler.KillTopologyRequest request) {
String topologyName = request.getTopologyName();
LOG.fine("Killing Topology " + topologyName);
NomadApiClient apiClient = getApiClient(NomadContext.getSchedulerURI(this.localConfig));
try {
List<Job> jobs = getTopologyJobs(apiClient, topologyName);
killJobs(apiClient, jobs.toArray(new Job[jobs.size()]));
} catch (RuntimeException e) {
LOG.log(Level.SEVERE, "Failed to kill topology " + topologyName + " with error: " + e.getMessage(), e);
return false;
} finally {
closeClient(apiClient);
}
return true;
}
use of com.hashicorp.nomad.apimodel.Job in project heron by twitter.
the class NomadScheduler method getJob.
Job getJob(int containerIndex, Optional<PackingPlan.ContainerPlan> containerPlan, Resource containerResource) {
String topologyName = Runtime.topologyName(this.runtimeConfig);
String topologyId = Runtime.topologyId(this.runtimeConfig);
Job job = new Job();
job.setId(getJobId(topologyId, containerIndex));
job.setName(getJobId(topologyName, containerIndex));
job.addTaskGroups(getTaskGroup(getJobId(topologyName, containerIndex), containerIndex, containerResource));
job.setDatacenters(Arrays.asList(NomadConstants.NOMAD_DEFAULT_DATACENTER));
job.setMeta(getMetaData(this.runtimeConfig, containerPlan));
return job;
}
use of com.hashicorp.nomad.apimodel.Job in project heron by twitter.
the class NomadScheduler method getJobs.
List<Job> getJobs(PackingPlan packing) {
List<Job> ret = new LinkedList<>();
PackingPlan homogeneousPackingPlan = getHomogeneousPackingPlan(packing);
Resource resource = getHomogeneousContainerResource(homogeneousPackingPlan);
for (int i = 0; i < Runtime.numContainers(this.runtimeConfig); i++) {
Optional<PackingPlan.ContainerPlan> containerPlan = homogeneousPackingPlan.getContainer(i);
ret.add(getJob(i, containerPlan, resource));
}
return ret;
}
use of com.hashicorp.nomad.apimodel.Job in project heron by twitter.
the class NomadScheduler method onRestart.
@Override
public boolean onRestart(Scheduler.RestartTopologyRequest request) {
LOG.fine("Restarting Topology " + request.getTopologyName() + " container " + request.getContainerIndex());
NomadApiClient apiClient = getApiClient(NomadContext.getSchedulerURI(this.localConfig));
String topologyName = request.getTopologyName();
int containerIndex = request.getContainerIndex();
try {
if (containerIndex == -1) {
// restarting whole topology
List<Job> jobs = getTopologyJobs(apiClient, topologyName);
restartJobs(apiClient, jobs.toArray(new Job[jobs.size()]));
} else {
// restarting single container
Job job = getTopologyContainerJob(apiClient, topologyName, containerIndex);
restartJobs(apiClient, job);
}
} catch (RuntimeException e) {
LOG.log(Level.SEVERE, "Failed to restart topology " + topologyName + " with error: " + e.getMessage(), e);
return false;
} finally {
closeClient(apiClient);
}
return true;
}
use of com.hashicorp.nomad.apimodel.Job in project twister2 by DSC-SPIDAL.
the class NomadController method start.
@Override
public boolean start(JobAPI.Job job) {
String uri = NomadContext.nomadSchedulerUri(config);
NomadApiClient nomadApiClient = new NomadApiClient(new NomadApiConfiguration.Builder().setAddress(uri).build());
Job nomadJob = getJob(job);
try {
EvaluationResponse response = nomadApiClient.getJobsApi().register(nomadJob);
LOG.log(Level.INFO, "Submitted job to nomad: " + response);
} catch (IOException | NomadException e) {
LOG.log(Level.SEVERE, "Failed to submit the job: ", e);
} finally {
closeClient(nomadApiClient);
}
return false;
}
Aggregations