Search in sources :

Example 1 with JobListStub

use of com.hashicorp.nomad.apimodel.JobListStub 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;
}
Also used : NomadException(com.hashicorp.nomad.javasdk.NomadException) IOException(java.io.IOException) JobListStub(com.hashicorp.nomad.apimodel.JobListStub) Job(com.hashicorp.nomad.apimodel.Job) LinkedList(java.util.LinkedList)

Example 2 with JobListStub

use of com.hashicorp.nomad.apimodel.JobListStub 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;
}
Also used : NomadException(com.hashicorp.nomad.javasdk.NomadException) IOException(java.io.IOException) JobListStub(com.hashicorp.nomad.apimodel.JobListStub) Job(com.hashicorp.nomad.apimodel.Job) LinkedList(java.util.LinkedList)

Aggregations

Job (com.hashicorp.nomad.apimodel.Job)2 JobListStub (com.hashicorp.nomad.apimodel.JobListStub)2 NomadException (com.hashicorp.nomad.javasdk.NomadException)2 IOException (java.io.IOException)2 LinkedList (java.util.LinkedList)2