Add delete all job executions endpoint

This commit is contained in:
Greg Schueler 2014-11-06 10:05:35 -08:00
parent e092ccdb13
commit a598c76d8e
4 changed files with 108 additions and 3 deletions

View file

@ -1642,7 +1642,32 @@ public class RundeckClient implements Serializable {
if(null!=asUser) {
apiPath.param("asUser", asUser);
}
return new ApiCall(this).get(apiPath, new AbortParser(rootXpath()+"/abort"));
return new ApiCall(this).get(apiPath, new AbortParser(rootXpath() + "/abort"));
}
/**
* Delete all executions for a job specified by a job ID
*
* @param jobId Identifier for the job
*
* @return a {@link DeleteExecutionsResponse} instance - won't be null
*
* @throws RundeckApiException in case of error when calling the API (non-existent
* execution 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 executionIds is null
*/
public DeleteExecutionsResponse deleteAllJobExecutions(final String jobId)
throws RundeckApiException, RundeckApiLoginException,
RundeckApiTokenException, IllegalArgumentException
{
AssertUtil.notNull(jobId, "jobId is mandatory to delete executions!");
return new ApiCall(this).delete(
new ApiPathBuilder("/job/",jobId,"/executions"),
new DeleteExecutionsResponseParser(rootXpath() + "/deleteExecutions")
);
}
/**
@ -1659,7 +1684,7 @@ public class RundeckClient implements Serializable {
throws RundeckApiException, RundeckApiLoginException,
RundeckApiTokenException, IllegalArgumentException
{
AssertUtil.notNull(executionIds, "executionIds is mandatory to abort an execution !");
AssertUtil.notNull(executionIds, "executionIds is mandatory to delete executions!");
if (executionIds.size() < 1) {
throw new IllegalArgumentException("executionIds cannot be empty");
}
@ -1685,7 +1710,7 @@ public class RundeckClient implements Serializable {
throws RundeckApiException, RundeckApiLoginException,
RundeckApiTokenException, IllegalArgumentException
{
AssertUtil.notNull(executionId, "executionId is mandatory to abort an execution !");
AssertUtil.notNull(executionId, "executionId is mandatory to delete an execution!");
new ApiCall(this).delete(new ApiPathBuilder("/execution/", executionId.toString()));
}

View file

@ -1572,6 +1572,42 @@ public class RundeckClientTest {
response.getFailures().get(1).getMessage()
);
}
/**
* delete executions with failure
*/
@Test
@Betamax(tape = "delete_all_job_executions_unauthorized", mode = TapeMode.READ_ONLY)
public void deleteAllJobExecutionsUnauthorized() throws Exception {
final RundeckClient client = createClient(TEST_TOKEN_8, 12);
try {
final DeleteExecutionsResponse response = client.deleteAllJobExecutions(
"764c1209-68ed-4185-8d43-a739364bf156"
);
Assert.fail();
} catch (RundeckApiException.RundeckApiTokenException e) {
e.printStackTrace();
}
}
/**
*
* @throws Exception
*/
@Test
@Betamax(tape = "delete_all_job_executions_success", mode = TapeMode.READ_ONLY)
public void deleteAllJobExecutionsSuccess() throws Exception {
final RundeckClient client = createClient(TEST_TOKEN_8, 12);
final DeleteExecutionsResponse response = client.deleteAllJobExecutions(
"764c1209-68ed-4185-8d43-a739364bf156"
);
Assert.assertEquals(2, response.getRequestCount());
Assert.assertEquals(2, response.getSuccessCount());
Assert.assertEquals(0, response.getFailedCount());
Assert.assertTrue(response.isAllsuccessful());
Assert.assertNotNull(response.getFailures());
Assert.assertEquals(0, response.getFailures().size());
}
/**
* delete single execution success
*/

View file

@ -0,0 +1,23 @@
!tape
name: delete_all_job_executions_success
interactions:
- recorded: 2014-11-06T18:03:44.789Z
request:
method: DELETE
uri: http://rundeck.local:4440/api/12/job/764c1209-68ed-4185-8d43-a739364bf156/executions
headers:
Host: rundeck.local:4440
Proxy-Connection: Keep-Alive
User-Agent: RunDeck API Java Client 12
X-RunDeck-Auth-Token: GG7uj1y6UGahOs7QlmeN2sIwz1Y2j7zI
response:
status: 200
headers:
Content-Type: application/xml;charset=UTF-8
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Server: Jetty(7.6.0.v20120127)
Set-Cookie: JSESSIONID=cqqoff205qus10sz1v3t54rk7;Path=/
X-Rundeck-API-Version: '12'
X-Rundeck-API-XML-Response-Wrapper: 'false'
body: !!binary |-
PGRlbGV0ZUV4ZWN1dGlvbnMgcmVxdWVzdENvdW50PScyJyBhbGxzdWNjZXNzZnVsPSd0cnVlJz4KICA8c3VjY2Vzc2Z1bCBjb3VudD0nMicgLz4KPC9kZWxldGVFeGVjdXRpb25zPg==

View file

@ -0,0 +1,21 @@
!tape
name: delete_all_job_executions_unauthorized
interactions:
- recorded: 2014-11-06T17:57:02.905Z
request:
method: DELETE
uri: http://rundeck.local:4440/api/12/job/764c1209-68ed-4185-8d43-a739364bf156/executions
headers:
Host: rundeck.local:4440
Proxy-Connection: Keep-Alive
User-Agent: RunDeck API Java Client 12
X-RunDeck-Auth-Token: GG7uj1y6UGahOs7QlmeN2sIwz1Y2j7zI
response:
status: 403
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=splzhkd5xunl1noidus2o7im3;Path=/
X-Rundeck-API-Version: '12'
body: "<result error='true' apiversion='12'>\n <error code='api.error.item.unauthorized'>\n <message>Not authorized for action \"Delete Execution\" for Project test</message>\n </error>\n</result>"