Skip to content

Commit

Permalink
Update exec query metrics response format
Browse files Browse the repository at this point in the history
  • Loading branch information
gschueler committed Jan 18, 2019
1 parent 412507f commit 85312c8
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
*/
public class RundeckClient {
public static final String USER_AGENT = Version.NAME + "/" + Version.VERSION;
public static final int API_VERS = 28;
public static final int API_VERS = 29;
public static final Pattern API_VERS_PATTERN = Pattern.compile("^(.*)(/api/(\\d+)/?)$");
public static final String ENV_BYPASS_URL = "RD_BYPASS_URL";
public static final String ENV_INSECURE_SSL = "RD_INSECURE_SSL";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,45 +4,71 @@
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import org.rundeck.client.util.DataOutput;
import org.simpleframework.xml.Element;
import org.simpleframework.xml.Root;

import java.util.HashMap;
import java.util.Map;

@JsonIgnoreProperties(ignoreUnknown = true)

@Root(strict = false, name = "result")
@Data
public class MetricsResponse
implements DataOutput
{
private Long total;
private Long failed;
@JsonProperty(value = "failed-with-retry")
@Element(name = "failed-with-retry")
private Long failedWithRetry;
private Long succeeded;
@JsonProperty(value = "duration-avg")
@Element(name = "duration-avg")
private String durationAvg;
@JsonProperty(value = "duration-min")
@Element(name = "duration-min")
private String durationMin;
@JsonProperty(value = "duration-max")
@Element(name = "duration-max")
private String durationMax;
private Status status;
private Map<String, String> duration;

@Override
public Map<?, ?> asMap() {
HashMap<String, Object> data = new HashMap<>();
data.put("total", total);
data.put("failed-with-retry", failedWithRetry);
data.put("succeeded", succeeded);
data.put("failed", failed);
data.put("duration-avg", durationAvg);
data.put("duration-min", durationMin);
data.put("duration-max", durationMax);
data.put("status", status);
data.put("duration", duration);
return data;
}

@JsonIgnoreProperties(ignoreUnknown = true)
@Data
public static class Status
implements DataOutput
{
private Long succeeded;
private Long failed;
@JsonProperty("failed-with-retry")
private Long failedWithRetry;
private Long aborted;
private Long running;
private Long other;
private Long timedout;
private Long scheduled;

@Override
public Map<?, ?> asMap() {
HashMap<String, Object> data = new HashMap<>();
if (null != succeeded) {
data.put("succeeded", succeeded);
}
if (null != failed) {
data.put("failed", failed);
}
if (null != failedWithRetry) {
data.put("failed-with-retry", failedWithRetry);
}
if (null != aborted) {
data.put("aborted", aborted);
}
if (null != running) {
data.put("running", running);
}
if (null != other) {
data.put("other", other);
}
if (null != timedout) {
data.put("timedout", timedout);
}
if (null != scheduled) {
data.put("scheduled", scheduled);
}
return data;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -668,9 +668,10 @@ interface MetricsCmd

@Command(description = "Obtain metrics over the result set of an execution query.")
public void metrics(MetricsCmd options, CommandOutput out) throws IOException, InputError {
requireApiVersion("metrics", 29);

// Check parameters.
if (!"xml".equalsIgnoreCase(getAppConfig().getString("RD_FORMAT", null)) && options.isRawXML()) {
if (!"xml".equalsIgnoreCase(getAppConfig().getString("RD_FORMAT", "xml")) && options.isRawXML()) {
throw new InputError("You cannot use RD_FORMAT env var with --xml");
}

Expand Down Expand Up @@ -739,7 +740,7 @@ public void metrics(MetricsCmd options, CommandOutput out) throws IOException, I
out.info("No results.");
return;
}
out.info(String.format("Showing stats for a resultset of %d executions.", result.getTotal()));
out.info(String.format("Showing stats for %d matching executions.", result.getTotal()));
out.output(result);
return;
}
Expand Down

0 comments on commit 85312c8

Please sign in to comment.