From 7b06c9278d02dc868d12777d3048d2943a68bee9 Mon Sep 17 00:00:00 2001 From: Vincent Behar Date: Sun, 3 Jul 2011 12:54:35 +0200 Subject: [PATCH] cleanup --- .../java/org/rundeck/api/RundeckClient.java | 100 ++++++++++-------- 1 file changed, 56 insertions(+), 44 deletions(-) diff --git a/src/main/java/org/rundeck/api/RundeckClient.java b/src/main/java/org/rundeck/api/RundeckClient.java index 9285c5a..a7d8a45 100644 --- a/src/main/java/org/rundeck/api/RundeckClient.java +++ b/src/main/java/org/rundeck/api/RundeckClient.java @@ -68,6 +68,40 @@ public class RundeckClient implements Serializable { new ApiCall(this).testCredentials(); } + /* + * Projects + */ + + /** + * List all projects + * + * @return a {@link List} of {@link RundeckProject} : might be empty, but won't be null + * @throws RundeckApiException in case of error when calling the API + * @throws RundeckApiLoginException if the login failed + */ + public List getProjects() throws RundeckApiException, RundeckApiLoginException { + return new ApiCall(this).get("/projects", new ProjectsParser("result/projects/project")); + } + + /** + * Get the definition of a single project, identified by the given name + * + * @param projectName name of the project - mandatory + * @return a {@link RundeckProject} instance + * @throws RundeckApiException in case of error when calling the API + * @throws RundeckApiLoginException if the login failed + * @throws IllegalArgumentException if the projectName is blank (null, empty or whitespace) + */ + public RundeckProject getProject(String projectName) throws RundeckApiException, RundeckApiLoginException, + IllegalArgumentException { + AssertUtil.notBlank(projectName, "projectName is mandatory to get the details of a project !"); + return new ApiCall(this).get("/project/" + projectName, new ProjectParser("result/projects/project")); + } + + /* + * Jobs + */ + /** * List all jobs that belongs to the given project * @@ -128,6 +162,28 @@ public class RundeckClient implements Serializable { return new ApiCall(this).get("/job/" + jobId, new JobParser("joblist/job")); } + /** + * Trigger the execution of a RunDeck job (identified by the given ID), and return immediately (without waiting the + * end of the job execution) + * + * @param jobId identifier of the job - mandatory + * @param options of the job - optional + * @return a {@link RundeckExecution} instance representing the newly created (and running) execution + * @throws RundeckApiException in case of error when calling the API + * @throws RundeckApiLoginException if the login failed + * @throws IllegalArgumentException if the jobId is blank (null, empty or whitespace) + */ + public RundeckExecution triggerJob(String jobId, Properties options) throws RundeckApiException, + RundeckApiLoginException, IllegalArgumentException { + AssertUtil.notBlank(jobId, "jobId is mandatory to trigger a job !"); + String apiPath = "/job/" + jobId + "/run?argString=" + ArgsUtil.generateUrlEncodedArgString(options); + return new ApiCall(this).get(apiPath, new ExecutionParser("result/executions/execution")); + } + + /* + * Executions + */ + /** * Get the executions of the given job * @@ -159,50 +215,6 @@ public class RundeckClient implements Serializable { return new ApiCall(this).get("/execution/" + executionId, new ExecutionParser("result/executions/execution")); } - /** - * Trigger the execution of a RunDeck job (identified by the given ID), and return immediately (without waiting the - * end of the job execution) - * - * @param jobId identifier of the job - mandatory - * @param options of the job - optional - * @return a {@link RundeckExecution} instance representing the newly created (and running) execution - * @throws RundeckApiException in case of error when calling the API - * @throws RundeckApiLoginException if the login failed - * @throws IllegalArgumentException if the jobId is blank (null, empty or whitespace) - */ - public RundeckExecution triggerJob(String jobId, Properties options) throws RundeckApiException, - RundeckApiLoginException, IllegalArgumentException { - AssertUtil.notBlank(jobId, "jobId is mandatory to trigger a job !"); - String apiPath = "/job/" + jobId + "/run?argString=" + ArgsUtil.generateUrlEncodedArgString(options); - return new ApiCall(this).get(apiPath, new ExecutionParser("result/executions/execution")); - } - - /** - * List all projects - * - * @return a {@link List} of {@link RundeckProject} : might be empty, but won't be null - * @throws RundeckApiException in case of error when calling the API - * @throws RundeckApiLoginException if the login failed - */ - public List getProjects() throws RundeckApiException, RundeckApiLoginException { - return new ApiCall(this).get("/projects", new ProjectsParser("result/projects/project")); - } - - /** - * Get the definition of a single project, identified by the given name - * - * @param projectName name of the project - mandatory - * @return a {@link RundeckProject} instance - * @throws RundeckApiException in case of error when calling the API - * @throws RundeckApiLoginException if the login failed - * @throws IllegalArgumentException if the projectName is blank (null, empty or whitespace) - */ - public RundeckProject getProject(String projectName) throws RundeckApiException, RundeckApiLoginException, - IllegalArgumentException { - AssertUtil.notBlank(projectName, "projectName is mandatory to get the details of a project !"); - return new ApiCall(this).get("/project/" + projectName, new ProjectParser("result/projects/project")); - } - public String getUrl() { return url; }