diff --git a/src/main/java/org/rundeck/client/api/RundeckApi.java b/src/main/java/org/rundeck/client/api/RundeckApi.java index 361c0059..4512d11f 100644 --- a/src/main/java/org/rundeck/client/api/RundeckApi.java +++ b/src/main/java/org/rundeck/client/api/RundeckApi.java @@ -298,4 +298,24 @@ Call deleteAclPolicy( @Headers("Accept: application/json") @GET("system/info") Call systemInfo(); + + //scheduler + + /** + * List scheduler owned jobs for the target server + * @return list of jobs + */ + @Headers("Accept: application/json") + @GET("scheduler/jobs") + Call> listSchedulerJobs(); + + /** + * List scheduler owned jobs for the specified server + * @param uuid server uuid + * @return list of jobs + */ + @Headers("Accept: application/json") + @GET("scheduler/server/{uuid}/jobs") + Call> listSchedulerJobs(@Path("uuid") String uuid); + } diff --git a/src/main/java/org/rundeck/client/api/model/ScheduledJobItem.java b/src/main/java/org/rundeck/client/api/model/ScheduledJobItem.java new file mode 100644 index 00000000..e7578b89 --- /dev/null +++ b/src/main/java/org/rundeck/client/api/model/ScheduledJobItem.java @@ -0,0 +1,82 @@ +package org.rundeck.client.api.model; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; + +import java.util.HashMap; +import java.util.Map; + +/** + * Created by greg on 7/8/16. + */ + +@JsonIgnoreProperties(ignoreUnknown = true) +public class ScheduledJobItem extends JobItem { + private String serverNodeUUID; + private boolean scheduled; + private boolean scheduleEnabled; + private boolean enabled; + private boolean serverOwner; + + + public String getServerNodeUUID() { + return serverNodeUUID; + } + + public void setServerNodeUUID(String serverNodeUUID) { + this.serverNodeUUID = serverNodeUUID; + } + + public boolean isScheduled() { + return scheduled; + } + + public void setScheduled(boolean scheduled) { + this.scheduled = scheduled; + } + + public boolean isScheduleEnabled() { + return scheduleEnabled; + } + + public void setScheduleEnabled(boolean scheduleEnabled) { + this.scheduleEnabled = scheduleEnabled; + } + + public boolean isEnabled() { + return enabled; + } + + public void setEnabled(boolean enabled) { + this.enabled = enabled; + } + + public boolean isServerOwner() { + return serverOwner; + } + + public void setServerOwner(boolean serverOwner) { + this.serverOwner = serverOwner; + } + + public Map toMap() { + HashMap map = new HashMap<>(); + map.put("job", toBasicString()); + map.put("serverNodeUUID", getServerNodeUUID()); + map.put("scheduled", scheduled); + map.put("scheduleEnabled", scheduleEnabled); + map.put("enabled", enabled); + map.put("serverOwner", serverOwner); + return map; + } + + @Override + public String toString() { + return super.toBasicString() + + "\n serverNodeUUID='" + serverNodeUUID + '\'' + + ", scheduled=" + scheduled + + ", scheduleEnabled=" + scheduleEnabled + + ", enabled=" + enabled + + ", serverOwner=" + serverOwner; + + } +} diff --git a/src/main/java/org/rundeck/client/tool/App.java b/src/main/java/org/rundeck/client/tool/App.java index ebcbc190..e6c2017d 100644 --- a/src/main/java/org/rundeck/client/tool/App.java +++ b/src/main/java/org/rundeck/client/tool/App.java @@ -32,7 +32,8 @@ public static Tool tool(final String name) { new Executions(client), new Run(client), new Keys(client), - new RDSystem(client) + new RDSystem(client), + new Scheduler(client) ) .commandInput(new JewelInput()) .buckle(); diff --git a/src/main/java/org/rundeck/client/tool/commands/Scheduler.java b/src/main/java/org/rundeck/client/tool/commands/Scheduler.java new file mode 100644 index 00000000..29b75a46 --- /dev/null +++ b/src/main/java/org/rundeck/client/tool/commands/Scheduler.java @@ -0,0 +1,51 @@ +package org.rundeck.client.tool.commands; + +import com.lexicalscope.jewel.cli.CommandLineInterface; +import com.lexicalscope.jewel.cli.Option; +import org.rundeck.client.api.RundeckApi; +import org.rundeck.client.api.model.JobItem; +import org.rundeck.client.api.model.ScheduledJobItem; +import org.rundeck.client.api.model.SystemInfo; +import org.rundeck.client.tool.options.ProjectCreateOptions; +import org.rundeck.client.util.Client; +import org.rundeck.util.toolbelt.Command; +import org.rundeck.util.toolbelt.CommandOutput; +import retrofit2.Call; + +import java.io.IOException; +import java.util.List; +import java.util.stream.Collectors; + +/** + * Created by greg on 7/8/16. + */ +@Command(description = "View scheduler information") +public class Scheduler extends ApiCommand { + public Scheduler(final Client client) { + super(client); + } + + + @CommandLineInterface(application = "jobs") interface SchedulerJobs { + + + @Option(shortName = "u", + longName = "uuid", + description = "Server UUID to query, or blank to select the target server") + String getUuid(); + + boolean isUuid(); + } + + @Command(description = "List jobs for the current target server, or a specified server.") + public void jobs(SchedulerJobs options, CommandOutput output) throws IOException { + Call> call; + if (options.isUuid()) { + call = client.getService().listSchedulerJobs(options.getUuid()); + } else { + call = client.getService().listSchedulerJobs(); + } + List jobInfo = client.checkError(call); + output.output(jobInfo.stream().map(ScheduledJobItem::toMap).collect(Collectors.toList())); + } +}