Search in sources :

Example 1 with NomadException

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

Example 2 with NomadException

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;
}
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 3 with NomadException

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

Example 4 with NomadException

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;
}
Also used : NomadException(com.hashicorp.nomad.javasdk.NomadException) IOException(java.io.IOException) Job(com.hashicorp.nomad.apimodel.Job) NomadApiClient(com.hashicorp.nomad.javasdk.NomadApiClient) NomadApiConfiguration(com.hashicorp.nomad.javasdk.NomadApiConfiguration)

Example 5 with NomadException

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;
}
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)6 NomadException (com.hashicorp.nomad.javasdk.NomadException)6 IOException (java.io.IOException)6 EvaluationResponse (com.hashicorp.nomad.javasdk.EvaluationResponse)3 JobListStub (com.hashicorp.nomad.apimodel.JobListStub)2 NomadApiClient (com.hashicorp.nomad.javasdk.NomadApiClient)2 NomadApiConfiguration (com.hashicorp.nomad.javasdk.NomadApiConfiguration)2 LinkedList (java.util.LinkedList)2