Skip to content

Commit

Permalink
Add scheduler job list
Browse files Browse the repository at this point in the history
  • Loading branch information
gschueler committed Jul 8, 2016
1 parent 6015c1a commit 8e5e5b5
Show file tree
Hide file tree
Showing 4 changed files with 155 additions and 1 deletion.
20 changes: 20 additions & 0 deletions src/main/java/org/rundeck/client/api/RundeckApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -298,4 +298,24 @@ Call<Void> deleteAclPolicy(
@Headers("Accept: application/json")
@GET("system/info")
Call<SystemInfo> systemInfo();

//scheduler

/**
* List scheduler owned jobs for the target server
* @return list of jobs
*/
@Headers("Accept: application/json")
@GET("scheduler/jobs")
Call<List<ScheduledJobItem>> 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<List<ScheduledJobItem>> listSchedulerJobs(@Path("uuid") String uuid);

}
82 changes: 82 additions & 0 deletions src/main/java/org/rundeck/client/api/model/ScheduledJobItem.java
Original file line number Diff line number Diff line change
@@ -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<String, Object> toMap() {
HashMap<String, Object> 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;

}
}
3 changes: 2 additions & 1 deletion src/main/java/org/rundeck/client/tool/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
51 changes: 51 additions & 0 deletions src/main/java/org/rundeck/client/tool/commands/Scheduler.java
Original file line number Diff line number Diff line change
@@ -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<RundeckApi> 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<List<ScheduledJobItem>> call;
if (options.isUuid()) {
call = client.getService().listSchedulerJobs(options.getUuid());
} else {
call = client.getService().listSchedulerJobs();
}
List<ScheduledJobItem> jobInfo = client.checkError(call);
output.output(jobInfo.stream().map(ScheduledJobItem::toMap).collect(Collectors.toList()));
}
}

0 comments on commit 8e5e5b5

Please sign in to comment.