diff --git a/src/main/java/org/rundeck/api/RundeckClient.java b/src/main/java/org/rundeck/api/RundeckClient.java index 221f735..aa54b7b 100644 --- a/src/main/java/org/rundeck/api/RundeckClient.java +++ b/src/main/java/org/rundeck/api/RundeckClient.java @@ -3281,6 +3281,25 @@ public class RundeckClient implements Serializable { return new ApiCall(this).get(param, new OutputParser("result/output", createOutputEntryParser())); } + /** + * Get the execution state of the given execution + * + * @param executionId identifier of the execution - mandatory + * @return {@link RundeckExecutionState} the execution state + * @throws RundeckApiException in case of error when calling the API (non-existent job with this ID) + * @throws RundeckApiLoginException if the login fails (in case of login-based authentication) + * @throws RundeckApiTokenException if the token is invalid (in case of token-based authentication) + * @throws IllegalArgumentException if the jobId is blank (null, empty or whitespace) + */ + public RundeckExecutionState getExecutionState(Long executionId) + throws RundeckApiException, RundeckApiLoginException, RundeckApiTokenException, IllegalArgumentException { + AssertUtil.notNull(executionId, "executionId is mandatory to get the state of an execution!"); + ApiPathBuilder param = new ApiPathBuilder( + "/execution/", executionId.toString(), + "/state"); + + return new ApiCall(this).get(param, new ExecutionStateParser("result/executionState")); + } /** * Get the execution output of the given execution on the specified node diff --git a/src/test/java/org/rundeck/api/RundeckClientTest.java b/src/test/java/org/rundeck/api/RundeckClientTest.java index 5e925a5..afc90d4 100644 --- a/src/test/java/org/rundeck/api/RundeckClientTest.java +++ b/src/test/java/org/rundeck/api/RundeckClientTest.java @@ -1186,6 +1186,22 @@ public class RundeckClientTest { Assert.assertEquals(false, output.isUnmodified()); Assert.assertEquals(12, output.getLogEntries().size()); } + /** + * Execution state structure + */ + @Test + @Betamax(tape = "execution_state", mode = TapeMode.READ_ONLY) + public void executionState() throws Exception { + final RundeckClient client = createClient(TEST_TOKEN_6, 10); + RundeckExecutionState output = client.getExecutionState(149L); + + Assert.assertEquals(149,output.getExecutionId()); + Assert.assertEquals(3,output.getTargetNodes().size()); + Assert.assertEquals(3,output.getAllNodes().size()); + Assert.assertEquals(1,output.getStepCount()); + Assert.assertEquals(1,output.getSteps().size()); + Assert.assertEquals(RundeckWFExecState.SUCCEEDED,output.getExecutionState()); + } @Before public void setUp() throws Exception { diff --git a/src/test/resources/betamax/tapes/execution_state.yaml b/src/test/resources/betamax/tapes/execution_state.yaml new file mode 100644 index 0000000..35c721f --- /dev/null +++ b/src/test/resources/betamax/tapes/execution_state.yaml @@ -0,0 +1,21 @@ +!tape +name: execution_state +interactions: +- recorded: 2014-01-18T18:24:49.806Z + request: + method: GET + uri: http://rundeck.local:4440/api/10/execution/149/state + headers: + Accept: text/xml + Host: rundeck.local:4440 + Proxy-Connection: Keep-Alive + User-Agent: RunDeck API Java Client 10 + X-RunDeck-Auth-Token: Do4d3NUD5DKk21DR4sNK755RcPk618vn + response: + status: 200 + headers: + Content-Type: text/xml;charset=UTF-8 + Expires: Thu, 01 Jan 1970 00:00:00 GMT + Server: Jetty(7.6.0.v20120127) + Set-Cookie: JSESSIONID=x0rnzzfb3xi410pethl5ttvjb;Path=/ + body: 2014-01-18T17:29:19Z12014-01-18T17:29:20Z149dignan2014-01-18T17:29:20ZSUCCEEDEDtrue2014-01-18T17:29:19Ztrue2014-01-18T17:29:20Z2014-01-18T17:29:20ZSUCCEEDED2014-01-18T17:29:19Z2014-01-18T17:29:20Z2014-01-18T17:29:20ZSUCCEEDED2014-01-18T17:29:20Z2014-01-18T17:29:20Z2014-01-18T17:29:20ZSUCCEEDED2014-01-18T17:29:20Z2014-01-18T17:29:20Z2014-01-18T17:29:20ZSUCCEEDED1SUCCEEDED1SUCCEEDED1SUCCEEDED