From aed16bfe6997455646faebc892ac42bf345c8631 Mon Sep 17 00:00:00 2001 From: Vincent Behar Date: Fri, 8 Jul 2011 16:06:46 +0200 Subject: [PATCH] add new methods to export a single job definition --- .../java/org/rundeck/api/RundeckClient.java | 38 +++++++++++++++++++ src/site/confluence/groovy.confluence | 1 + src/site/confluence/jruby.confluence | 1 + src/site/confluence/jython.confluence | 1 + 4 files changed, 41 insertions(+) diff --git a/src/main/java/org/rundeck/api/RundeckClient.java b/src/main/java/org/rundeck/api/RundeckClient.java index 6f7c8c5..2549109 100644 --- a/src/main/java/org/rundeck/api/RundeckClient.java +++ b/src/main/java/org/rundeck/api/RundeckClient.java @@ -281,6 +281,41 @@ public class RundeckClient implements Serializable { .param("idlist", StringUtils.join(jobIds, ","))); } + /** + * Export the definition of a single job (identified by the given ID), as an XML file + * + * @param filename path of the file where the content should be saved + * @param jobId identifier of the job - mandatory + * @throws RundeckApiException in case of error when calling the API (non-existent job with this ID) + * @throws RundeckApiLoginException if the login failed + * @throws IllegalArgumentException if the jobId is blank (null, empty or whitespace) + * @throws IOException if we failed to write to the file + * @see #exportJob(String) + * @see #getJob(String) + */ + public void exportJobToFile(String filename, String jobId) throws RundeckApiException, RundeckApiLoginException, + IllegalArgumentException, IOException { + InputStream inputStream = exportJob(jobId); + FileUtils.writeByteArrayToFile(new File(filename), IOUtils.toByteArray(inputStream)); + } + + /** + * Export the definition of a single job, identified by the given ID + * + * @param jobId identifier of the job - mandatory + * @return an {@link InputStream} instance, not linked to any network resources - won't be null + * @throws RundeckApiException in case of error when calling the API (non-existent job with this ID) + * @throws RundeckApiLoginException if the login failed + * @throws IllegalArgumentException if the jobId is blank (null, empty or whitespace) + * @see #exportJobToFile(String, String) + * @see #getJob(String) + */ + public InputStream exportJob(String jobId) throws RundeckApiException, RundeckApiLoginException, + IllegalArgumentException { + AssertUtil.notBlank(jobId, "jobId is mandatory to get the details of a job !"); + return new ApiCall(this).get(new ApiPathBuilder("/job/", jobId)); + } + /** * Find a job, identified by its project, group and name. Note that the groupPath is optional, as a job does not * need to belong to a group (either pass null, or an empty string). @@ -292,6 +327,7 @@ public class RundeckClient implements Serializable { * @throws RundeckApiException in case of error when calling the API (non-existent project with this name) * @throws RundeckApiLoginException if the login failed * @throws IllegalArgumentException if the project or the name is blank (null, empty or whitespace) + * @see #getJob(String) */ public RundeckJob findJob(String project, String groupPath, String name) throws RundeckApiException, RundeckApiLoginException, IllegalArgumentException { @@ -309,6 +345,8 @@ public class RundeckClient implements Serializable { * @throws RundeckApiException in case of error when calling the API (non-existent job with this ID) * @throws RundeckApiLoginException if the login failed * @throws IllegalArgumentException if the jobId is blank (null, empty or whitespace) + * @see #findJob(String, String, String) + * @see #exportJob(String) */ public RundeckJob getJob(String jobId) throws RundeckApiException, RundeckApiLoginException, IllegalArgumentException { diff --git a/src/site/confluence/groovy.confluence b/src/site/confluence/groovy.confluence index 2768cca..8cbeb61 100644 --- a/src/site/confluence/groovy.confluence +++ b/src/site/confluence/groovy.confluence @@ -86,6 +86,7 @@ import org.rundeck.api.RundeckClient rundeck = new RundeckClient("http://localhost:4440", "admin", "admin") rundeck.exportJobsToFile("/tmp/jobs.xml", "my-project") +rundeck.exportJobToFile("/tmp/job.xml", "job-id") {code} h2. And more... diff --git a/src/site/confluence/jruby.confluence b/src/site/confluence/jruby.confluence index 7fe128c..afcc9f6 100644 --- a/src/site/confluence/jruby.confluence +++ b/src/site/confluence/jruby.confluence @@ -87,6 +87,7 @@ import org.rundeck.api.RundeckClient rundeck = RundeckClient.new("http://localhost:4440", "admin", "admin") rundeck.exportJobsToFile("/tmp/jobs.xml", "my-project") +rundeck.exportJobToFile("/tmp/job.xml", "job-id") {code} h2. And more... diff --git a/src/site/confluence/jython.confluence b/src/site/confluence/jython.confluence index 0175837..0d25926 100644 --- a/src/site/confluence/jython.confluence +++ b/src/site/confluence/jython.confluence @@ -71,6 +71,7 @@ from org.rundeck.api import RundeckClient rundeck = RundeckClient("http://localhost:4440", "admin", "admin") rundeck.exportJobsToFile("/tmp/jobs.xml", "my-project") +rundeck.exportJobToFile("/tmp/job.xml", "job-id") {code} h2. And more...