Package org.jenkinsci.plugins.nomad
Class NomadApi
- java.lang.Object
-
- org.jenkinsci.plugins.nomad.NomadApi
-
public final class NomadApi extends Object
Provides access to Nomad by using the Nomad REST API.
-
-
Field Summary
Fields Modifier and Type Field Description static okhttp3.MediaType
JSON
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description FormValidation
checkConnection()
Checks whether Nomad is reachable.org.json.JSONObject
getRunningWorker(String jobID, String namespace)
Get all job specifications and statusJobInfo[]
getRunningWorkers(String prefix)
Provides a lists all existing jobs in Nomad with the same prefix.String
startWorker(String workerName, String jnlpSecret, NomadWorkerTemplate template)
Creates a new job in Nomad.void
stopWorker(String workerName, String namespace, String region)
Deletes an existing job in Nomad.FormValidation
validateTemplate(NomadWorkerTemplate template)
Validates a givenNomadWorkerTemplate
.
-
-
-
Method Detail
-
checkConnection
public FormValidation checkConnection()
Checks whether Nomad is reachable.- Returns:
- FormValidation object with kind = OK or ERROR and a message.
-
validateTemplate
public FormValidation validateTemplate(NomadWorkerTemplate template)
Validates a givenNomadWorkerTemplate
.- Returns:
- FormValidation object with kind = OK or ERROR and a message.
-
startWorker
public String startWorker(String workerName, String jnlpSecret, NomadWorkerTemplate template)
Creates a new job in Nomad. It logs when it was not successful but there is no further indication whether this was successful or not.- Parameters:
workerName
- Name of the correspondingNomadWorker
(e.g. jenkins-1234)jnlpSecret
- Secret used by the jenkins agent to connect to Jenkinstemplate
- Template used to create a new Job in Nomad
-
stopWorker
public void stopWorker(String workerName, String namespace, String region)
Deletes an existing job in Nomad. It logs when it was not successful but there is no further indication whether this was successful or not.- Parameters:
workerName
- Name of the correspondingNomadWorker
(e.g. jenkins-1234)namespace
- Name of the nomad namespace where job is runningregion
- Name of the region where job is running
-
getRunningWorkers
public JobInfo[] getRunningWorkers(String prefix)
Provides a lists all existing jobs in Nomad with the same prefix. It logs when it was not successful but there is no further indication whether this was successful or not.- Parameters:
prefix
- Prefix of the job (e.g.jenkins when you want all jobs where the name starts with jenkins)- Returns:
- Array of
JobInfo
objects or an empty list if there are no Jobs at all or when something was wrong
-
-