Add output/state sequence result for api v10

This commit is contained in:
Greg Schueler 2014-01-16 17:34:42 -08:00
parent ad49b635b7
commit 6b2b7954d3
4 changed files with 143 additions and 0 deletions

View file

@ -3435,6 +3435,36 @@ public class RundeckClient implements Serializable {
}
return new ApiCall(this).get(param, new OutputParser("result/output", createOutputEntryParser()));
}
/**
* Get the execution state output sequence of the given job
*
* @param executionId identifier of the execution - mandatory
* @param stateOnly if true, include only state change output entries, otherwise include state and log entries
* @param offset byte offset to read from in the file. 0 indicates the beginning.
* @param lastmod epoch datestamp in milliseconds, return results only if modification changed since the specified date OR if more data is available at the given offset
* @param maxlines maximum number of lines to retrieve forward from the specified offset.
* @return {@link RundeckOutput}
* @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 RundeckOutput getJobExecutionOutputState(Long executionId, boolean stateOnly, int offset, long lastmod, int maxlines)
throws RundeckApiException, RundeckApiLoginException, RundeckApiTokenException, IllegalArgumentException {
AssertUtil.notNull(executionId, "executionId is mandatory to get the output of a job execution!");
ApiPathBuilder param = new ApiPathBuilder("/execution/", executionId.toString(), "/output/state")
.param("offset", offset);
if (lastmod >= 0) {
param.param("lastmod", lastmod);
}
if (maxlines > 0) {
param.param("maxlines", maxlines);
}
if(stateOnly) {
param.param("stateOnly", true);
}
return new ApiCall(this).get(param, new OutputParser("result/output", createOutputEntryParser()));
}
private OutputEntryParser createOutputEntryParser() {
if (getApiVersion() <= Version.V5.versionNumber) {

View file

@ -1136,6 +1136,57 @@ public class RundeckClientTest {
Assert.assertEquals(1, output.getLogEntries().size());
}
/**
* Execution output state sequence
*/
@Test
@Betamax(tape = "execution_output_state", mode = TapeMode.READ_ONLY)
public void executionOutputState() throws Exception {
final RundeckClient client = createClient(TEST_TOKEN_6, 10);
RundeckOutput output = client.getJobExecutionOutputState(146L,false,0,0L,-1);
Assert.assertEquals(new Long(1602), output.getExecDuration());
Assert.assertEquals(new Long(146), output.getExecutionId());
Assert.assertEquals(new Long(1389894504000L), output.getLastModified());
Assert.assertEquals(null, output.getFilterNode());
Assert.assertEquals(null, output.getFilterStep());
Assert.assertEquals(1409, output.getOffset());
Assert.assertEquals(RundeckExecution.ExecutionStatus.SUCCEEDED, output.getStatus());
Assert.assertEquals(new Float(99.57597), output.getPercentLoaded());
Assert.assertEquals(1415, output.getTotalSize());
Assert.assertEquals(true, output.isCompleted());
Assert.assertEquals(true, output.isExecCompleted());
Assert.assertEquals(false, output.isEmpty());
Assert.assertEquals(false, output.isHasFailedNodes());
Assert.assertEquals(false, output.isUnmodified());
Assert.assertEquals(15, output.getLogEntries().size());
}
/**
* Execution output state sequence
*/
@Test
@Betamax(tape = "execution_output_state_only", mode = TapeMode.READ_ONLY)
public void executionOutputStateOnly() throws Exception {
final RundeckClient client = createClient(TEST_TOKEN_6, 10);
RundeckOutput output = client.getJobExecutionOutputState(146L,true,0,0L,-1);
Assert.assertEquals(new Long(1602), output.getExecDuration());
Assert.assertEquals(new Long(146), output.getExecutionId());
Assert.assertEquals(new Long(1389894504000L), output.getLastModified());
Assert.assertEquals(null, output.getFilterNode());
Assert.assertEquals(null, output.getFilterStep());
Assert.assertEquals(1409, output.getOffset());
Assert.assertEquals(RundeckExecution.ExecutionStatus.SUCCEEDED, output.getStatus());
Assert.assertEquals(new Float(99.57597), output.getPercentLoaded());
Assert.assertEquals(1415, output.getTotalSize());
Assert.assertEquals(true, output.isCompleted());
Assert.assertEquals(true, output.isExecCompleted());
Assert.assertEquals(false, output.isEmpty());
Assert.assertEquals(false, output.isHasFailedNodes());
Assert.assertEquals(false, output.isUnmodified());
Assert.assertEquals(12, output.getLogEntries().size());
}
@Before
public void setUp() throws Exception {
// not that you can put whatever here, because we don't actually connect to the RunDeck instance

View file

@ -0,0 +1,32 @@
!tape
name: execution_output_state
interactions:
- recorded: 2014-01-17T01:32:08.245Z
request:
method: GET
uri: http://rundeck.local:4440/api/10/execution/146/output/state?offset=0&lastmod=0
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=wanbmac3kkhgo3jghy3twd7g;Path=/
body: "<result success='true' apiversion='10'>\n <output>\n <id>146</id>\n <offset>1409</offset>\n <completed>true</completed>\n <execCompleted>true</execCompleted>\n <hasFailedNodes>false</hasFailedNodes>\n <execState>succeeded</execState>\n\
\ <lastModified>1389894504000</lastModified>\n <execDuration>1602</execDuration>\n <percentLoaded>99.57597173144876</percentLoaded>\n <totalSize>1415</totalSize>\n <entries>\n <entry node='dignan' step='1' stepctx='1' user='admin' time='09:48:23'\
\ level='NORMAL' type='stepbegin' absolute_time='2014-01-16T17:48:23Z' log='' />\n <entry node='node-111.qa.subgroup.mycompany.com' step='1' stepctx='1' user='Raif' time='09:48:23' level='NORMAL' type='nodebegin' absolute_time='2014-01-16T17:48:23Z'\
\ log='' />\n <entry node='node-111.qa.subgroup.mycompany.com' step='1' stepctx='1' user='Raif' time='09:48:23' level='NORMAL' type='log' absolute_time='2014-01-16T17:48:23Z' log='hi there' />\n <entry node='node-111.qa.subgroup.mycompany.com'\
\ step='1' stepctx='1' user='Raif' time='09:48:23' level='NORMAL' type='nodeend' absolute_time='2014-01-16T17:48:23Z' log='' />\n <entry node='dignan' step='1' stepctx='1' user='admin' time='09:48:23' level='NORMAL' type='stepend' absolute_time='2014-01-16T17:48:23Z'\
\ log='' />\n <entry node='dignan' step='1' stepctx='1' user='admin' time='09:48:23' level='NORMAL' type='stepbegin' absolute_time='2014-01-16T17:48:23Z' log='' />\n <entry node='node-14.qa.subgroup.mycompany.com' step='1' stepctx='1' user='Dale'\
\ time='09:48:23' level='NORMAL' type='nodebegin' absolute_time='2014-01-16T17:48:23Z' log='' />\n <entry node='node-14.qa.subgroup.mycompany.com' step='1' stepctx='1' user='Dale' time='09:48:23' level='NORMAL' type='log' absolute_time='2014-01-16T17:48:23Z'\
\ log='hi there' />\n <entry node='node-14.qa.subgroup.mycompany.com' step='1' stepctx='1' user='Dale' time='09:48:24' level='NORMAL' type='nodeend' absolute_time='2014-01-16T17:48:24Z' log='' />\n <entry node='dignan' step='1' stepctx='1' user='admin'\
\ time='09:48:24' level='NORMAL' type='stepend' absolute_time='2014-01-16T17:48:24Z' log='' />\n <entry node='dignan' step='1' stepctx='1' user='admin' time='09:48:24' level='NORMAL' type='stepbegin' absolute_time='2014-01-16T17:48:24Z' log='' />\n\
\ <entry node='node-6.qa.subgroup.mycompany.com' step='1' stepctx='1' user='Carolyn' time='09:48:24' level='NORMAL' type='nodebegin' absolute_time='2014-01-16T17:48:24Z' log='' />\n <entry node='node-6.qa.subgroup.mycompany.com' step='1' stepctx='1'\
\ user='Carolyn' time='09:48:24' level='NORMAL' type='log' absolute_time='2014-01-16T17:48:24Z' log='hi there' />\n <entry node='node-6.qa.subgroup.mycompany.com' step='1' stepctx='1' user='Carolyn' time='09:48:24' level='NORMAL' type='nodeend' absolute_time='2014-01-16T17:48:24Z'\
\ log='' />\n <entry node='dignan' step='1' stepctx='1' user='admin' time='09:48:24' level='NORMAL' type='stepend' absolute_time='2014-01-16T17:48:24Z' log='' />\n </entries>\n </output>\n</result>"

View file

@ -0,0 +1,30 @@
!tape
name: execution_output_state_only
interactions:
- recorded: 2014-01-17T01:34:08.528Z
request:
method: GET
uri: http://rundeck.local:4440/api/10/execution/146/output/state?offset=0&lastmod=0&stateOnly=true
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=19nlvjuo85wqz1lwl7biksu77h;Path=/
body: "<result success='true' apiversion='10'>\n <output>\n <id>146</id>\n <offset>1409</offset>\n <completed>true</completed>\n <execCompleted>true</execCompleted>\n <hasFailedNodes>false</hasFailedNodes>\n <execState>succeeded</execState>\n\
\ <lastModified>1389894504000</lastModified>\n <execDuration>1602</execDuration>\n <percentLoaded>99.57597173144876</percentLoaded>\n <totalSize>1415</totalSize>\n <entries>\n <entry node='dignan' step='1' stepctx='1' user='admin' time='09:48:23'\
\ level='NORMAL' type='stepbegin' absolute_time='2014-01-16T17:48:23Z' log='' />\n <entry node='node-111.qa.subgroup.mycompany.com' step='1' stepctx='1' user='Raif' time='09:48:23' level='NORMAL' type='nodebegin' absolute_time='2014-01-16T17:48:23Z'\
\ log='' />\n <entry node='node-111.qa.subgroup.mycompany.com' step='1' stepctx='1' user='Raif' time='09:48:23' level='NORMAL' type='nodeend' absolute_time='2014-01-16T17:48:23Z' log='' />\n <entry node='dignan' step='1' stepctx='1' user='admin'\
\ time='09:48:23' level='NORMAL' type='stepend' absolute_time='2014-01-16T17:48:23Z' log='' />\n <entry node='dignan' step='1' stepctx='1' user='admin' time='09:48:23' level='NORMAL' type='stepbegin' absolute_time='2014-01-16T17:48:23Z' log='' />\n\
\ <entry node='node-14.qa.subgroup.mycompany.com' step='1' stepctx='1' user='Dale' time='09:48:23' level='NORMAL' type='nodebegin' absolute_time='2014-01-16T17:48:23Z' log='' />\n <entry node='node-14.qa.subgroup.mycompany.com' step='1' stepctx='1'\
\ user='Dale' time='09:48:24' level='NORMAL' type='nodeend' absolute_time='2014-01-16T17:48:24Z' log='' />\n <entry node='dignan' step='1' stepctx='1' user='admin' time='09:48:24' level='NORMAL' type='stepend' absolute_time='2014-01-16T17:48:24Z'\
\ log='' />\n <entry node='dignan' step='1' stepctx='1' user='admin' time='09:48:24' level='NORMAL' type='stepbegin' absolute_time='2014-01-16T17:48:24Z' log='' />\n <entry node='node-6.qa.subgroup.mycompany.com' step='1' stepctx='1' user='Carolyn'\
\ time='09:48:24' level='NORMAL' type='nodebegin' absolute_time='2014-01-16T17:48:24Z' log='' />\n <entry node='node-6.qa.subgroup.mycompany.com' step='1' stepctx='1' user='Carolyn' time='09:48:24' level='NORMAL' type='nodeend' absolute_time='2014-01-16T17:48:24Z'\
\ log='' />\n <entry node='dignan' step='1' stepctx='1' user='admin' time='09:48:24' level='NORMAL' type='stepend' absolute_time='2014-01-16T17:48:24Z' log='' />\n </entries>\n </output>\n</result>"