use of com.hashicorp.nomad.javasdk.NomadException in project incubator-heron by apache.
the class NomadScheduler method startJobs.
static void startJobs(NomadApiClient apiClient, Job... jobs) {
for (Job job : jobs) {
LOG.fine("Starting job " + job.getId());
LOG.fine("Job spec: " + job.toString());
try {
EvaluationResponse response = apiClient.getJobsApi().register(job);
LOG.fine("response: " + response);
} catch (IOException | NomadException e) {
String msg = "Failed to submit job " + job.getId() + " with error: " + e.getMessage();
LOG.log(Level.FINE, msg + " with job spec: " + job.toString());
throw new RuntimeException(msg, e);
}
}
}
use of com.hashicorp.nomad.javasdk.NomadException in project heron by twitter.
the class NomadScheduler method getTopologyJobs.
static List<Job> getTopologyJobs(NomadApiClient apiClient, String topologyName) {
List<JobListStub> jobs = getJobList(apiClient);
List<Job> ret = new LinkedList<>();
for (JobListStub job : jobs) {
Job jobActual;
try {
jobActual = apiClient.getJobsApi().info(job.getId()).getValue();
} catch (IOException | NomadException e) {
String msg = "Failed to retrieve job info for job " + job.getId() + " part of topology " + topologyName;
LOG.log(Level.SEVERE, msg, e);
throw new RuntimeException(msg, e);
}
Map<String, String> metaData = jobActual.getMeta();
if (metaData != null && metaData.containsKey(NomadConstants.NOMAD_TOPOLOGY_NAME)) {
if (metaData.get(NomadConstants.NOMAD_TOPOLOGY_NAME).equals(topologyName)) {
ret.add(jobActual);
}
}
}
return ret;
}
use of com.hashicorp.nomad.javasdk.NomadException in project heron by twitter.
the class NomadScheduler method startJobs.
static void startJobs(NomadApiClient apiClient, Job... jobs) {
for (Job job : jobs) {
LOG.fine("Starting job " + job.getId());
LOG.fine("Job spec: " + job.toString());
try {
EvaluationResponse response = apiClient.getJobsApi().register(job);
LOG.fine("response: " + response);
} catch (IOException | NomadException e) {
String msg = "Failed to submit job " + job.getId() + " with error: " + e.getMessage();
LOG.log(Level.FINE, msg + " with job spec: " + job.toString());
throw new RuntimeException(msg, e);
}
}
}
use of com.hashicorp.nomad.javasdk.NomadException in project twister2 by DSC-SPIDAL.
the class NomadController method kill.
@Override
public boolean kill(JobAPI.Job job) {
String jobID = job.getJobId();
String uri = NomadContext.nomadSchedulerUri(config);
LOG.log(Level.INFO, "Killing Job " + jobID);
NomadApiClient nomadApiClient = new NomadApiClient(new NomadApiConfiguration.Builder().setAddress(uri).build());
try {
Job nomadJob = getRunningJob(nomadApiClient, job.getJobId());
if (nomadJob == null) {
LOG.log(Level.INFO, "Cannot find the running job: " + job.getJobId());
return false;
}
nomadApiClient.getJobsApi().deregister(nomadJob.getId());
} catch (RuntimeException | IOException | NomadException e) {
LOG.log(Level.SEVERE, "Failed to terminate job " + jobID + " with error: " + e.getMessage(), e);
return false;
} finally {
closeClient(nomadApiClient);
}
return true;
}
use of com.hashicorp.nomad.javasdk.NomadException in project incubator-heron by apache.
the class NomadScheduler method getTopologyJobs.
static List<Job> getTopologyJobs(NomadApiClient apiClient, String topologyName) {
List<JobListStub> jobs = getJobList(apiClient);
List<Job> ret = new LinkedList<>();
for (JobListStub job : jobs) {
Job jobActual;
try {
jobActual = apiClient.getJobsApi().info(job.getId()).getValue();
} catch (IOException | NomadException e) {
String msg = "Failed to retrieve job info for job " + job.getId() + " part of topology " + topologyName;
LOG.log(Level.SEVERE, msg, e);
throw new RuntimeException(msg, e);
}
Map<String, String> metaData = jobActual.getMeta();
if (metaData != null && metaData.containsKey(NomadConstants.NOMAD_TOPOLOGY_NAME)) {
if (metaData.get(NomadConstants.NOMAD_TOPOLOGY_NAME).equals(topologyName)) {
ret.add(jobActual);
}
}
}
return ret;
}
Aggregations