Skip to content

Commit

Permalink
Merge pull request #210 from ahormazabal/dev/execution_query_metrics
Browse files Browse the repository at this point in the history
support for execution metrics API
  • Loading branch information
gschueler authored Jan 18, 2019
2 parents fc3f05f + 85312c8 commit 1b0466f
Show file tree
Hide file tree
Showing 8 changed files with 432 additions and 132 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 = 25;
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
83 changes: 83 additions & 0 deletions rd-api-client/src/main/java/org/rundeck/client/api/RundeckApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import okhttp3.RequestBody;
import okhttp3.ResponseBody;
import org.rundeck.client.api.model.*;
import org.rundeck.client.api.model.executions.MetricsResponse;
import org.rundeck.client.api.model.metrics.EndpointListResult;
import org.rundeck.client.api.model.metrics.HealthCheckStatus;
import org.rundeck.client.api.model.metrics.MetricsData;
Expand Down Expand Up @@ -1194,4 +1195,86 @@ Call<BulkToggleJobScheduleResponse> bulkDisableJobSchedule(
@GET("metrics/metrics")
Call<MetricsData> getMetricsData();

/* Execution Query Metrics */

/**
* Get stats on a project-wide query of executions, with all query parameters available, in JSON format.
* @param project
* @param options
* @param jobIdListFilter
* @param xjobIdListFilter
* @param jobListFilter
* @param excludeJobListFilters
* @return
*/
@Headers("Accept: application/json")
@GET("project/{project}/executions/metrics")
Call<MetricsResponse> executionMetrics(
@Path("project") String project,
@QueryMap Map<String, String> options,
@Query("jobIdListFilter") List<String> jobIdListFilter,
@Query("excludeJobIdListFilter") List<String> xjobIdListFilter,
@Query("jobListFilter") List<String> jobListFilter,
@Query("excludeJobListFilter") List<String> excludeJobListFilters
);

/**
* Get stats on a system-wide query of executions, with all query parameters available, in JSON format.
* @param options
* @param jobIdListFilter
* @param xjobIdListFilter
* @param jobListFilter
* @param excludeJobListFilters
* @return
*/
@Headers("Accept: application/json")
@GET("executions/metrics")
Call<MetricsResponse> executionMetrics(
@QueryMap Map<String, String> options,
@Query("jobIdListFilter") List<String> jobIdListFilter,
@Query("excludeJobIdListFilter") List<String> xjobIdListFilter,
@Query("jobListFilter") List<String> jobListFilter,
@Query("excludeJobListFilter") List<String> excludeJobListFilters
);

/**
* Get stats on a project-wide query of executions, with all query parameters available, in XML format.
* @param project
* @param options
* @param jobIdListFilter
* @param xjobIdListFilter
* @param jobListFilter
* @param excludeJobListFilters
* @return
*/
@Headers("Accept: application/xml")
@GET("project/{project}/executions/metrics")
Call<ResponseBody> executionMetricsXML(
@Path("project") String project,
@QueryMap Map<String, String> options,
@Query("jobIdListFilter") List<String> jobIdListFilter,
@Query("excludeJobIdListFilter") List<String> xjobIdListFilter,
@Query("jobListFilter") List<String> jobListFilter,
@Query("excludeJobListFilter") List<String> excludeJobListFilters
);

/**
* Get stats on a system-wide query of executions, with all query parameters available, in XML format.
* @param options
* @param jobIdListFilter
* @param xjobIdListFilter
* @param jobListFilter
* @param excludeJobListFilters
* @return
*/
@Headers("Accept: application/xml")
@GET("executions/metrics")
Call<ResponseBody> executionMetricsXML(
@QueryMap Map<String, String> options,
@Query("jobIdListFilter") List<String> jobIdListFilter,
@Query("excludeJobIdListFilter") List<String> xjobIdListFilter,
@Query("jobListFilter") List<String> jobListFilter,
@Query("excludeJobListFilter") List<String> excludeJobListFilters
);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package org.rundeck.client.api.model.executions;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import org.rundeck.client.util.DataOutput;

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

@JsonIgnoreProperties(ignoreUnknown = true)
@Data
public class MetricsResponse
implements DataOutput
{
private Long total;
private Status status;
private Map<String, String> duration;

@Override
public Map<?, ?> asMap() {
HashMap<String, Object> data = new HashMap<>();
data.put("total", total);
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;
}
}
}
13 changes: 13 additions & 0 deletions rd-api-client/src/main/java/org/rundeck/client/util/Format.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ public class Format {
private Format() {
}

public static String format(String format, DataOutput data, final String start, final String end) {
return format(format, data.asMap(), start, end);
}

public static String format(String format, Map<?, ?> data, final String start, final String end) {
Pattern pat = Pattern.compile(Pattern.quote(start) + "([\\w.]+)" + Pattern.quote(end));
Matcher matcher = pat.matcher(format);
Expand Down Expand Up @@ -79,6 +83,15 @@ private static Object descend(final Map<?, ?> data, final String... found) {
return (Map<?, ?> map) -> format(format, map, start, end);
}

public static <X extends DataOutput> Function<X, String> dataFormatter(
String format,
final String start,
final String end
)
{
return formatter(format, DataOutput::asMap, start, end);
}

@SuppressWarnings("SameParameterValue")
public static <X> Function<X, String> formatter(
String format,
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/org/rundeck/client/tool/commands/Adhoc.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,19 @@
package org.rundeck.client.tool.commands;

import com.lexicalscope.jewel.cli.CommandLineInterface;
import org.rundeck.toolbelt.Command;
import org.rundeck.toolbelt.CommandOutput;
import org.rundeck.toolbelt.InputError;
import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.RequestBody;
import org.rundeck.client.api.model.AdhocResponse;
import org.rundeck.client.api.model.Execution;
import org.rundeck.client.tool.RdApp;
import org.rundeck.client.tool.options.AdhocBaseOptions;
import org.rundeck.client.tool.options.ExecutionResultOptions;
import org.rundeck.client.util.Quoting;
import org.rundeck.client.util.Util;
import org.rundeck.toolbelt.Command;
import org.rundeck.toolbelt.CommandOutput;
import org.rundeck.toolbelt.InputError;

import java.io.ByteArrayOutputStream;
import java.io.File;
Expand All @@ -50,7 +51,7 @@ public Adhoc(final RdApp client) {
}

@CommandLineInterface(application = COMMAND) interface AdhocOptions extends AdhocBaseOptions,
Executions.ExecutionResultOptions
ExecutionResultOptions
{

}
Expand Down
Loading

0 comments on commit 1b0466f

Please sign in to comment.