Class NomadApi


  • public final class NomadApi
    extends Object
    Provides access to Nomad by using the Nomad REST API.
    • Field Detail

      • JSON

        public static final okhttp3.MediaType JSON
    • Method Detail

      • checkConnection

        public FormValidation checkConnection()
        Checks whether Nomad is reachable.
        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 corresponding NomadWorker (e.g. jenkins-1234)
        jnlpSecret - Secret used by the jenkins agent to connect to Jenkins
        template - 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 corresponding NomadWorker (e.g. jenkins-1234)
        namespace - Name of the nomad namespace where job is running
        region - 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
      • getRunningWorker

        public org.json.JSONObject getRunningWorker​(String jobID,
                                                    String namespace)
        Get all job specifications and status
        Parameters:
        jobID - Id of the job
        namespace - Name of the nomad namespace where job is running
        Returns:
        JSONObject object