mirror of
https://github.com/Fishwaldo/rundeck-api-java-client.git
synced 2025-07-07 13:38:23 +00:00
Support update for output entry format, API v6 #1
This commit is contained in:
parent
00268997c1
commit
234cf6db2a
4 changed files with 111 additions and 49 deletions
|
@ -2526,7 +2526,7 @@ public class RundeckClient implements Serializable {
|
|||
.param("lastlines", lastlines)
|
||||
.param("lastmod", lastmod)
|
||||
.param("maxlines", maxlines),
|
||||
new OutputParser("result/output"));
|
||||
new OutputParser("result/output", createOutputEntryParser()));
|
||||
}
|
||||
|
||||
|
||||
|
@ -2549,7 +2549,15 @@ public class RundeckClient implements Serializable {
|
|||
return new ApiCall(this).get(new ApiPathBuilder("/execution/", executionId.toString(), "/output.xml").param("offset", offset)
|
||||
.param("lastmod", lastmod)
|
||||
.param("maxlines", maxlines),
|
||||
new OutputParser("result/output"));
|
||||
new OutputParser("result/output", createOutputEntryParser()));
|
||||
}
|
||||
|
||||
private OutputEntryParser createOutputEntryParser() {
|
||||
if (getApiVersion() <= Version.V5.versionNumber) {
|
||||
return new OutputEntryParserV5();
|
||||
}else{
|
||||
return new OutputEntryParser();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -6,6 +6,9 @@ import org.dom4j.Node;
|
|||
import org.rundeck.api.domain.RundeckOutputEntry;
|
||||
import org.rundeck.api.domain.RundeckOutputEntry.RundeckLogLevel;
|
||||
|
||||
/**
|
||||
* Parses output message content for API v6
|
||||
*/
|
||||
public class OutputEntryParser implements XmlNodeParser<RundeckOutputEntry> {
|
||||
|
||||
|
||||
|
@ -39,9 +42,16 @@ public class OutputEntryParser implements XmlNodeParser<RundeckOutputEntry> {
|
|||
outputEntry.setUser(StringUtils.trimToNull(entryNode.valueOf("@user")));
|
||||
outputEntry.setCommand(StringUtils.trimToNull(entryNode.valueOf("@command")));
|
||||
outputEntry.setNode(StringUtils.trimToNull(entryNode.valueOf("@node")));
|
||||
outputEntry.setMessage(StringUtils.trimToNull(entryNode.getStringValue()));
|
||||
outputEntry.setMessage(parseMessage(entryNode));
|
||||
|
||||
return outputEntry;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the message content
|
||||
*/
|
||||
protected String parseMessage(Node entryNode) {
|
||||
return StringUtils.trimToNull(entryNode.valueOf("@log"));
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
* Copyright 2013 DTO Labs, Inc. (http://dtolabs.com)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* OutputEntryParserV5.java
|
||||
*
|
||||
* User: Greg Schueler <a href="mailto:greg@dtosolutions.com">greg@dtosolutions.com</a>
|
||||
* Created: 1/2/13 5:33 PM
|
||||
*
|
||||
*/
|
||||
package org.rundeck.api.parser;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.dom4j.Node;
|
||||
import org.rundeck.api.domain.RundeckOutputEntry;
|
||||
|
||||
|
||||
/**
|
||||
* OutputEntryParserV5 parses message entry for API v5
|
||||
*
|
||||
* @author Greg Schueler <a href="mailto:greg@dtosolutions.com">greg@dtosolutions.com</a>
|
||||
*/
|
||||
public class OutputEntryParserV5 extends OutputEntryParser implements XmlNodeParser<RundeckOutputEntry>{
|
||||
public OutputEntryParserV5() {
|
||||
}
|
||||
|
||||
public OutputEntryParserV5(String xpath) {
|
||||
super(xpath);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String parseMessage(Node entryNode) {
|
||||
return StringUtils.trimToNull(entryNode.getStringValue());
|
||||
}
|
||||
}
|
|
@ -1,30 +1,25 @@
|
|||
package org.rundeck.api.parser;
|
||||
|
||||
import java.util.List;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.dom4j.Node;
|
||||
|
||||
import org.rundeck.api.domain.RundeckExecution;
|
||||
import org.rundeck.api.domain.RundeckOutput;
|
||||
import org.rundeck.api.domain.RundeckOutputEntry;
|
||||
import org.rundeck.api.domain.RundeckExecution;
|
||||
import org.rundeck.api.domain.RundeckExecution.ExecutionStatus;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class OutputParser implements XmlNodeParser<RundeckOutput> {
|
||||
|
||||
|
||||
private String xpath;
|
||||
XmlNodeParser<RundeckOutputEntry> parser;
|
||||
|
||||
public OutputParser() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param xpath of the event element if it is not the root node
|
||||
*/
|
||||
public OutputParser(String xpath) {
|
||||
super();
|
||||
public OutputParser(String xpath, XmlNodeParser<RundeckOutputEntry> parser) {
|
||||
this.xpath = xpath;
|
||||
if (null != parser) {
|
||||
this.parser = parser;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -37,13 +32,13 @@ public class OutputParser implements XmlNodeParser<RundeckOutput> {
|
|||
//output.setError(StringUtils.trimToNull(entryNode.valueOf("error")));
|
||||
|
||||
|
||||
try{
|
||||
try {
|
||||
output.setExecutionId(Long.valueOf(entryNode.valueOf("id")));
|
||||
} catch (NumberFormatException e) {
|
||||
output.setExecutionId(null);
|
||||
}
|
||||
|
||||
try{
|
||||
try {
|
||||
output.setOffset(Integer.valueOf(entryNode.valueOf("offset")));
|
||||
} catch (NumberFormatException e) {
|
||||
output.setOffset(-1);
|
||||
|
@ -54,30 +49,31 @@ public class OutputParser implements XmlNodeParser<RundeckOutput> {
|
|||
output.setHasFailedNodes(Boolean.valueOf(entryNode.valueOf("hasFailedNodes")));
|
||||
|
||||
try {
|
||||
output.setStatus(RundeckExecution.ExecutionStatus.valueOf(StringUtils.upperCase(entryNode.valueOf("execState"))));
|
||||
output.setStatus(RundeckExecution.ExecutionStatus
|
||||
.valueOf(StringUtils.upperCase(entryNode.valueOf("execState"))));
|
||||
} catch (IllegalArgumentException e) {
|
||||
output.setStatus(null);
|
||||
}
|
||||
|
||||
try{
|
||||
try {
|
||||
output.setLastModified(Long.valueOf(entryNode.valueOf("lastModified")));
|
||||
} catch (NumberFormatException e) {
|
||||
output.setLastModified(null);
|
||||
}
|
||||
|
||||
try{
|
||||
try {
|
||||
output.setExecDuration(Long.valueOf(entryNode.valueOf("execDuration")));
|
||||
} catch (NumberFormatException e) {
|
||||
output.setExecDuration(null);
|
||||
}
|
||||
|
||||
try{
|
||||
try {
|
||||
output.setPercentLoaded(Float.valueOf(entryNode.valueOf("percentLoaded")));
|
||||
} catch (NumberFormatException e) {
|
||||
output.setPercentLoaded(null);
|
||||
}
|
||||
|
||||
try{
|
||||
try {
|
||||
output.setTotalSize(Integer.valueOf(entryNode.valueOf("totalSize")));
|
||||
} catch (NumberFormatException e) {
|
||||
output.setTotalSize(-1);
|
||||
|
@ -85,13 +81,12 @@ public class OutputParser implements XmlNodeParser<RundeckOutput> {
|
|||
|
||||
Node entriesListNode = entryNode.selectSingleNode("entries");
|
||||
|
||||
if(entriesListNode != null){
|
||||
if (entriesListNode != null) {
|
||||
@SuppressWarnings("unchecked")
|
||||
List<Node> entries = entriesListNode.selectNodes("entry");
|
||||
OutputEntryParser entryParser = new OutputEntryParser();
|
||||
|
||||
for (Node logEntryNode : entries) {
|
||||
RundeckOutputEntry outputEntry = entryParser.parseXmlNode(logEntryNode);
|
||||
RundeckOutputEntry outputEntry = parser.parseXmlNode(logEntryNode);
|
||||
output.addLogEntry(outputEntry);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue