New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support API v19 job file input #79

Merged
merged 4 commits into from Apr 11, 2017
Jump to file or symbol
Failed to load files and symbols.
+540 −35
Diff settings

Always

Just for now

Next

log: APIv19: new `rd jobs files` command

  • Loading branch information...
gschueler committed Mar 2, 2017
commit e634e68dd9850f461f05aa53ff5f4eddb4e1dca1
@@ -26,7 +26,7 @@
*/
public class Rundeck {
public static final String USER_AGENT = Version.NAME + "/" + Version.VERSION;
public static final int API_VERS = 18;
public static final int API_VERS = 19;
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";
@@ -46,6 +46,75 @@
@Path("jobid") String jobid
);
/**
* Get uploaded file info
*
* @param fileid
*
* @return
*/
@Headers("Accept: application/json")
@GET("jobs/file/{fileid}")
Call<JobFileItem> getJobFileInfo(
@Path("fileid") String fileid
);
/**
* List uploaded files for a job
*
* @param jobid job id
* @param fileState file state
*
* @return
*/
@Headers("Accept: application/json")
@GET("job/{jobid}/input/files")
Call<JobFileItemList> listJobFiles(
@Path("jobid") String jobid,
@Query("fileState") String fileState,
@Query("offset") int offset,
@Query("max") int max
);
/**
* List uploaded files for a job in state 'temp'
*
* @param jobid job id
*
* @return
*/
@Headers("Accept: application/json")
@GET("job/{jobid}/input/files")
Call<JobFileItemList> listJobFiles(
@Path("jobid") String jobid,
@Query("offset") int offset,
@Query("max") int max
);
/**
* List uploaded files for an execution
*
* @param execid execution id
*
* @return
*/
@Headers("Accept: application/json")
@GET("execution/{execid}/input/files")
Call<JobFileItemList> listExecutionFiles(
@Path("execid") String execid,
@Query("offset") int offset,
@Query("max") int max
);
@Headers("Accept: application/json")
@POST("job/{jobid}/input/file")
Call<JobFileUploadResult> uploadJobOptionFile(
@Path("jobid") String jobid,
@Query("optionName") String optionName,
@Query("fileName") String fileName,
@Body RequestBody body
);
@GET("project/{project}/jobs/export")
Call<ResponseBody> exportJobs(
@@ -0,0 +1,157 @@
package org.rundeck.client.api.model;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.simplifyops.toolbelt.Formatable;
import org.simpleframework.xml.Root;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author greg
* @since 3/1/17
*/
@JsonIgnoreProperties(ignoreUnknown = true)
@Root(strict = false)
public class JobFileItem implements Formatable {
private String id;
private String user;
private String optionName;
private String fileState;
private String sha;
private String jobId;
private String dateCreated;
private String serverNodeUUID;
private String fileName;
private Long size;
private String expirationDate;
private Long execId;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getUser() {
return user;
}
public void setUser(String user) {
this.user = user;
}
public String getOptionName() {
return optionName;
}
public void setOptionName(String optionName) {
this.optionName = optionName;
}
public String getFileState() {
return fileState;
}
public void setFileState(String fileState) {
this.fileState = fileState;
}
public String getSha() {
return sha;
}
public void setSha(String sha) {
this.sha = sha;
}
public String getJobId() {
return jobId;
}
public void setJobId(String jobId) {
this.jobId = jobId;
}
public String getDateCreated() {
return dateCreated;
}
public DateInfo dateInfoDateCreated() {
return new DateInfo(dateCreated);
}
public void setDateCreated(String dateCreated) {
this.dateCreated = dateCreated;
}
public String getServerNodeUUID() {
return serverNodeUUID;
}
public void setServerNodeUUID(String serverNodeUUID) {
this.serverNodeUUID = serverNodeUUID;
}
public String getFileName() {
return fileName;
}
public void setFileName(String fileName) {
this.fileName = fileName;
}
public Long getSize() {
return size;
}
public void setSize(Long size) {
this.size = size;
}
public String getExpirationDate() {
return expirationDate;
}
public DateInfo dateInfoExpirationDate() {
return new DateInfo(expirationDate);
}
public void setExpirationDate(String expirationDate) {
this.expirationDate = expirationDate;
}
public Long getExecId() {
return execId;
}
public void setExecId(Long execId) {
this.execId = execId;
}
@Override
public List<?> asList() {
return null;
}
@Override
public Map<?, ?> asMap() {
HashMap<String, Object> map = new HashMap<>();
map.put("id", id);
map.put("user", user);
map.put("optionName", optionName);
map.put("fileState", fileState);
map.put("sha", sha);
map.put("jobId", jobId);
map.put("dateCreated", dateCreated);
map.put("serverNodeUUID", serverNodeUUID);
map.put("fileName", fileName);
map.put("size", size);
map.put("expirationDate", expirationDate);
map.put("execId", execId);
return map;
}
}
@@ -0,0 +1,31 @@
package org.rundeck.client.api.model;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import java.util.List;
/**
* @author greg
* @since 3/2/17
*/
@JsonIgnoreProperties(ignoreUnknown = true)
public class JobFileItemList {
private Paging paging;
private List<JobFileItem> files;
public Paging getPaging() {
return paging;
}
public void setPaging(Paging paging) {
this.paging = paging;
}
public List<JobFileItem> getFiles() {
return files;
}
public void setFiles(List<JobFileItem> files) {
this.files = files;
}
}
@@ -0,0 +1,48 @@
package org.rundeck.client.api.model;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.simplifyops.toolbelt.Formatable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author greg
* @since 3/1/17
*/
@JsonIgnoreProperties(ignoreUnknown = true)
public class JobFileUploadResult implements Formatable {
private Integer total;
private Map<String, String> options;
public Integer getTotal() {
return total;
}
public void setTotal(Integer total) {
this.total = total;
}
public Map<String, String> getOptions() {
return options;
}
public void setOptions(Map<String, String> options) {
this.options = options;
}
@Override
public List<?> asList() {
return null;
}
@Override
public Map<?, ?> asMap() {
HashMap<String, Object> map = new HashMap<>();
map.put("total", total);
map.put("options", options);
return map;
}
}
@@ -44,4 +44,22 @@ public int getOffset() {
public void setOffset(int offset) {
this.offset = offset;
}
@Override
public String toString() {
return String.format("Paged results %d - %d (of %d by %d).", offset, count + offset, total, max);
}
public String moreResults(final String offsetArg) {
if (hasMoreResults()) {
int nextOffset = getOffset() + getMax();
return String.format("(more results available, append: %s %d)", offsetArg, nextOffset);
} else {
return "End of results.";
}
}
public boolean hasMoreResults() {
return getTotal() > (getOffset() + getCount());
}
}
@@ -6,10 +6,7 @@
import com.simplifyops.toolbelt.input.jewelcli.JewelInput;
import org.rundeck.client.Rundeck;
import org.rundeck.client.api.RundeckApi;
import org.rundeck.client.api.model.DateInfo;
import org.rundeck.client.api.model.Execution;
import org.rundeck.client.api.model.JobItem;
import org.rundeck.client.api.model.ScheduledJobItem;
import org.rundeck.client.api.model.*;
import org.rundeck.client.tool.commands.*;
import org.rundeck.client.util.Client;
import org.rundeck.client.util.ConfigSource;
@@ -20,9 +17,7 @@
import org.yaml.snakeyaml.representer.Representer;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collection;
import java.util.Random;
import java.util.*;
import java.util.function.Function;
import static org.rundeck.client.Rundeck.ENV_INSECURE_SSL;
@@ -71,7 +66,23 @@ private static void setupFormat(final ToolBelt belt, AppConfig config) {
belt.channels().warningEnabled(false);
belt.channels().errorEnabled(false);
} else {
NiceFormatter formatter = new NiceFormatter(null);
NiceFormatter formatter = new NiceFormatter(null) {
@Override
public String format(final Object o) {
if (o instanceof Formatable) {
Formatable o1 = (Formatable) o;
Map<?, ?> map = o1.asMap();
if (null != map) {
return super.format(map);
}
List<?> objects = o1.asList();
if (null != objects) {
return super.format(objects);
}
}
return super.format(o);
}
};
formatter.setCollectionIndicator("");
belt.formatter(formatter);
belt.channels().info(new FormattedOutput(
Oops, something went wrong.
ProTip! Use n and p to navigate between commits in a pull request.