Search in sources :

Example 1 with NomadApiClient

use of com.hashicorp.nomad.javasdk.NomadApiClient in project incubator-heron by apache.

the class NomadScheduler method onSchedule.

@Override
public boolean onSchedule(PackingPlan packing) {
    if (packing == null || packing.getContainers().isEmpty()) {
        LOG.severe("No container requested. Can't schedule");
        return false;
    }
    NomadApiClient apiClient = getApiClient(NomadContext.getSchedulerURI(this.localConfig));
    try {
        List<Job> jobs = getJobs(packing);
        startJobs(apiClient, jobs.toArray(new Job[jobs.size()]));
    } catch (RuntimeException e) {
        LOG.log(Level.SEVERE, "Failed to deploy topology " + Runtime.topologyName(this.runtimeConfig) + " with error: " + e.getMessage(), e);
        return false;
    } finally {
        closeClient(apiClient);
    }
    return true;
}
Also used : Job(com.hashicorp.nomad.apimodel.Job) NomadApiClient(com.hashicorp.nomad.javasdk.NomadApiClient)

Example 2 with NomadApiClient

use of com.hashicorp.nomad.javasdk.NomadApiClient in project heron by twitter.

the class NomadScheduler method onSchedule.

@Override
public boolean onSchedule(PackingPlan packing) {
    if (packing == null || packing.getContainers().isEmpty()) {
        LOG.severe("No container requested. Can't schedule");
        return false;
    }
    NomadApiClient apiClient = getApiClient(NomadContext.getSchedulerURI(this.localConfig));
    try {
        List<Job> jobs = getJobs(packing);
        startJobs(apiClient, jobs.toArray(new Job[jobs.size()]));
    } catch (RuntimeException e) {
        LOG.log(Level.SEVERE, "Failed to deploy topology " + Runtime.topologyName(this.runtimeConfig) + " with error: " + e.getMessage(), e);
        return false;
    } finally {
        closeClient(apiClient);
    }
    return true;
}
Also used : Job(com.hashicorp.nomad.apimodel.Job) NomadApiClient(com.hashicorp.nomad.javasdk.NomadApiClient)

Example 3 with NomadApiClient

use of com.hashicorp.nomad.javasdk.NomadApiClient 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 4 with NomadApiClient

use of com.hashicorp.nomad.javasdk.NomadApiClient in project incubator-heron by apache.

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

Example 5 with NomadApiClient

use of com.hashicorp.nomad.javasdk.NomadApiClient in project incubator-heron by apache.

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

Aggregations

Job (com.hashicorp.nomad.apimodel.Job)8 NomadApiClient (com.hashicorp.nomad.javasdk.NomadApiClient)8 NomadApiConfiguration (com.hashicorp.nomad.javasdk.NomadApiConfiguration)2 NomadException (com.hashicorp.nomad.javasdk.NomadException)2 IOException (java.io.IOException)2 EvaluationResponse (com.hashicorp.nomad.javasdk.EvaluationResponse)1