From d0bc76abb823aa2c256f86d82fef830fed666af6 Mon Sep 17 00:00:00 2001 From: Vincent Behar Date: Wed, 6 Jul 2011 14:58:37 +0200 Subject: [PATCH] support all options for the /job/ID/executions endpoint --- .../java/org/rundeck/api/RundeckClient.java | 45 ++++++++++++++++++- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/rundeck/api/RundeckClient.java b/src/main/java/org/rundeck/api/RundeckClient.java index 09943ad..1bf83fe 100644 --- a/src/main/java/org/rundeck/api/RundeckClient.java +++ b/src/main/java/org/rundeck/api/RundeckClient.java @@ -617,9 +617,50 @@ public class RundeckClient implements Serializable { */ public List getJobExecutions(String jobId) throws RundeckApiException, RundeckApiLoginException, IllegalArgumentException { + return getJobExecutions(jobId, null); + } + + /** + * Get the executions of the given job + * + * @param jobId identifier of the job - mandatory + * @param status of the executions - optional (null for all) + * @return a {@link List} of {@link RundeckExecution} : might be empty, but 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) + */ + public List getJobExecutions(String jobId, ExecutionStatus status) throws RundeckApiException, + RundeckApiLoginException, IllegalArgumentException { + return getJobExecutions(jobId, status, null, null); + } + + /** + * Get the executions of the given job + * + * @param jobId identifier of the job - mandatory + * @param status of the executions - optional (null for all) + * @param max number of results to return - optional (null for all) + * @param offset the 0-indexed offset for the first result to return - optional + * @return a {@link List} of {@link RundeckExecution} : might be empty, but 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) + */ + public List getJobExecutions(String jobId, ExecutionStatus status, Long max, Long offset) + throws RundeckApiException, RundeckApiLoginException, IllegalArgumentException { AssertUtil.notBlank(jobId, "jobId is mandatory to get the executions of a job !"); - return new ApiCall(this).get("/job/" + jobId + "/executions", - new ExecutionsParser("result/executions/execution")); + StringBuilder apiPath = new StringBuilder("/job/").append(jobId).append("/executions?"); + if (status != null) { + apiPath.append("status=").append(StringUtils.lowerCase(status.toString())).append("&"); + } + if (max != null && max >= 0) { + apiPath.append("max=").append(max).append("&"); + } + if (offset != null && offset >= 0) { + apiPath.append("offset=").append(offset); + } + return new ApiCall(this).get(apiPath.toString(), new ExecutionsParser("result/executions/execution")); } /**