Skip to content

Commit

Permalink
Add API implementation of RundeckCentralDispatcher. Support loglevel …
Browse files Browse the repository at this point in the history
…in job run api
  • Loading branch information
gschueler committed Apr 29, 2011
1 parent 2fae883 commit 764f85a
Show file tree
Hide file tree
Showing 15 changed files with 1,578 additions and 85 deletions.
1,147 changes: 1,147 additions & 0 deletions core/src/java/com/dtolabs/client/services/RundeckAPICentralDispatcher.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -491,10 +491,7 @@ public Collection<IStoredJob> listStoredJobs(final IStoredJobsQuery iStoredJobsQ
final String nameMatch = iStoredJobsQuery.getNameMatch();
String groupMatch = iStoredJobsQuery.getGroupMatch();
final String projectFilter = iStoredJobsQuery.getProjectFilter();
final String commandFilter = iStoredJobsQuery.getCommand();
final String idlistFilter = iStoredJobsQuery.getIdlist();
final String typeFilter = iStoredJobsQuery.getType();
final String resourceFilter = iStoredJobsQuery.getResource();

if (null != output && null != fformat) {
params.put("format", fformat.getName());
Expand All @@ -515,15 +512,6 @@ public Collection<IStoredJob> listStoredJobs(final IStoredJobsQuery iStoredJobsQ
if (null != projectFilter) {
params.put("projFilter", projectFilter);
}
if (null != resourceFilter) {
params.put("objFilter", resourceFilter);
}
if (null != typeFilter) {
params.put("typeFilter", typeFilter);
}
if (null != commandFilter) {
params.put("cmdFilter", commandFilter);
}
if (null != idlistFilter) {
params.put("idlist", idlistFilter);
}
Expand Down Expand Up @@ -562,7 +550,7 @@ public Collection<IStoredJob> listStoredJobs(final IStoredJobsQuery iStoredJobsQ
final Node gnode = node1.selectSingleNode("group");
final String group = null != gnode ? gnode.getStringValue() : null;
final String description = node1.selectSingleNode("description").getStringValue();
list.add(StoredJobImpl.create(id, name, url, group, description));
list.add(StoredJobImpl.create(id, name, url, group, description, projectFilter));
}
}

Expand Down Expand Up @@ -592,7 +580,7 @@ public Collection<IStoredJob> listStoredJobs(final IStoredJobsQuery iStoredJobsQ
final String group = map.containsKey("group") ? (String) map.get("group") : null;
final String desc = map.containsKey("description") ? (String) map.get("description") : "";
final String url = createJobURL(id);
list.add(StoredJobImpl.create(id, name, url, group, desc));
list.add(StoredJobImpl.create(id, name, url, group, desc, projectFilter));
}

if (null != output) {
Expand Down Expand Up @@ -901,7 +889,7 @@ private IStoredJobLoadResult parseStoredJobResult(final Node node1, final boolea
}
return StoredJobLoadResultImpl.createLoadResult(id, name, url,
group, description, successful, skippedJob,
message, ndx);
message);
}

/**
Expand Down
23 changes: 23 additions & 0 deletions core/src/java/com/dtolabs/client/services/StoredJobImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public class StoredJobImpl implements IStoredJob {
private String url;
private String group;
private String description;
private String project;

StoredJobImpl(final String jobId, final String name, final String url, final String group, final String description) {
this.jobId = jobId;
Expand All @@ -46,10 +47,24 @@ public class StoredJobImpl implements IStoredJob {
this.description = description;
}

StoredJobImpl(final String jobId, final String name, final String url, final String group, final String description,
final String project) {
this.jobId = jobId;
this.name = name;
this.url = url;
this.group = group;
this.description = description;
this.project= project;
}

public static IStoredJob create(final String jobId, final String name, final String url, final String group,
final String description) {
return new StoredJobImpl(jobId, name, url, group, description);
}
public static IStoredJob create(final String jobId, final String name, final String url, final String group,
final String description, final String project) {
return new StoredJobImpl(jobId, name, url, group, description, project);
}

public String getJobId() {
return jobId;
Expand Down Expand Up @@ -90,4 +105,12 @@ public String getDescription() {
public void setDescription(String description) {
this.description = description;
}

public String getProject() {
return project;
}

public void setProject(String project) {
this.project = project;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,14 @@ public class StoredJobLoadResultImpl extends StoredJobImpl implements IStoredJob
private boolean successful;
private boolean skippedJob;
private String message;
private int index;

StoredJobLoadResultImpl(final String jobId, final String name, final String url, final String group,
final String description, final boolean successful, final boolean skippedJob,
final String message, final int index) {
final String message) {
super(jobId, name, url, group, description);
this.successful = successful;
this.skippedJob = skippedJob;
this.message = message;
this.index= index;
}

/**
Expand All @@ -58,15 +56,14 @@ public class StoredJobLoadResultImpl extends StoredJobImpl implements IStoredJob
* @param successful true if creation succeeded
* @param skippedJob true if creation was skippped
* @param message message for error
* @param index index of job in original input
* @return IStoredJobLoadResult instance
*/
public static IStoredJobLoadResult createLoadResult(final String jobId, final String name, final String url,
final String group,
final String description, final boolean successful,
final boolean skippedJob,
final String message, final int index) {
return new StoredJobLoadResultImpl(jobId, name, url, group, description, successful, skippedJob, message, index);
final String message) {
return new StoredJobLoadResultImpl(jobId, name, url, group, description, successful, skippedJob, message);

}

Expand All @@ -81,8 +78,4 @@ public boolean isSkippedJob() {
public String getMessage() {
return message;
}

public int getIndex() {
return index;
}
}
24 changes: 12 additions & 12 deletions core/src/java/com/dtolabs/rundeck/core/cli/jobs/JobsTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.dtolabs.rundeck.core.Constants;
import com.dtolabs.rundeck.core.cli.*;
import com.dtolabs.rundeck.core.common.Framework;
import com.dtolabs.rundeck.core.common.FrameworkProject;
import com.dtolabs.rundeck.core.dispatcher.*;
import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;
Expand Down Expand Up @@ -134,22 +135,10 @@ public String getIdlist() {
return getArgIdlist();
}

public String getCommand() {
return null;
}

public String getType() {
return null;
}

public String getProjectFilter() {
return getArgProject();
}

public String getResource() {
return null;
}

/**
* Return file argument
*
Expand Down Expand Up @@ -544,6 +533,17 @@ public void parseArgs(final CommandLine cli, final String[] original) throws CLI
}

public void validate(final CommandLine cli, final String[] original) throws CLIToolOptionsException {
if(null==argProject){
if(framework.getFrameworkProjectMgr().listFrameworkProjects().size() == 1) {
final FrameworkProject project =
(FrameworkProject) framework.getFrameworkProjectMgr().listFrameworkProjects().iterator().next();
argProject = project.getName();
debug("No project specified, defaulting to: " + argProject);
}else{
throw new CLIToolOptionsException(
"list action: -" + PROJECT_OPTION + "/--" + PROJECT_OPTION_LONG + " option is required");
}
}
}
}

Expand Down
28 changes: 28 additions & 0 deletions core/src/java/com/dtolabs/rundeck/core/cli/run/RunTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -221,16 +221,29 @@ private class Options implements CLIToolOptions {
* long option string for run option: job
*/
public static final String JOB_OPTION_LONG = "job";

/**
* short option string for run option: job
*/
public static final String PROJECT_OPTION = "p";

/**
* long option string for run option: job
*/
public static final String PROJECT_OPTION_LONG = "project";
String argIdlist;
String argJob;
boolean argVerbose;
String argProject;

public void addOptions(final org.apache.commons.cli.Options options) {

options.addOption(ID_OPTION, ID_OPTION_LONG, true,
"Job ID. Run the Job with this ID. ");
options.addOption(JOB_OPTION, JOB_OPTION_LONG, true,
"Job identifier (group and name). Run a Job specified by Job name and optional group, e.g: 'Group Name/Job Name'. ");
options.addOption(PROJECT_OPTION, PROJECT_OPTION_LONG, true,
"Project name. Required if not specifying Job ID.");
options.addOption(VERBOSE_OPTION, VERBOSE_OPTION_LONG, false,
"Enable verbose output");
}
Expand All @@ -246,6 +259,9 @@ public void parseArgs(final CommandLine cli, final String[] original) throws CLI
if (cli.hasOption(JOB_OPTION)) {
argJob = cli.getOptionValue(JOB_OPTION);
}
if (cli.hasOption(PROJECT_OPTION)) {
argProject = cli.getOptionValue(PROJECT_OPTION);
}
}

public void validate(CommandLine cli, String[] original) throws CLIToolOptionsException {
Expand Down Expand Up @@ -273,6 +289,12 @@ public void validateRunAction() throws CLIToolOptionsException {
+ Options.ID_OPTION + "/--"
+ Options.ID_OPTION_LONG + " cannot be combined, please specify only one.");
}
if (null != argJob && null == argProject) {
throw new CLIToolOptionsException(
"run action: -" + Options.JOB_OPTION + "/--" + Options.JOB_OPTION_LONG + " option requires -"
+ Options.PROJECT_OPTION + "/--"
+ Options.PROJECT_OPTION_LONG + " option");
}
if (null != argIdlist ) {
try {
Long.parseLong(argIdlist);
Expand Down Expand Up @@ -329,6 +351,7 @@ private void jobrunAction() throws RunToolException {
final QueuedItemResult result;
final String jobname;
final String jobgroup;
final String project;

if (null != runOptions.argJob && runOptions.argJob.indexOf("/") >= 0) {
//separate group and job name
Expand All @@ -347,6 +370,7 @@ private void jobrunAction() throws RunToolException {
jobname = null;
jobgroup = null;
}
project=runOptions.argProject;

final NodeSet nodeset = nodefilterOptions.getNodeSet();
final Boolean argKeepgoing = nodefilterOptions.isKeepgoingSet() ? nodeset.isKeepgoing() : null;
Expand Down Expand Up @@ -384,6 +408,10 @@ public String getName() {
public String getGroup() {
return jobgroup;
}

public String getProject() {
return project;
}
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,6 @@
* @version $Revision$
*/
public interface IStoredJobLoadResult extends IStoredJob {
/**
* Return the original job index from the input
*
* @return index of this job in the original input
*/
public int getIndex();

/**
* Return true if the load was successful.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,9 @@ public interface IStoredJobRef {
* @return the name
*/
String getGroup();

/**
* Get the project
*/
String getProject();
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,31 +52,11 @@ public interface IStoredJobsQuery {
*/
public String getIdlist();

/**
* Return match string for command name
*
* @return match string
*/
public String getCommand();

/**
* Return match string for type name
*
* @return match string
*/
public String getType();

/**
* Return match string for project name
*
* @return match string
*/
public String getProjectFilter();

/**
* Return match string for resource name
*
* @return match string
*/
public String getResource();
}

0 comments on commit 764f85a

Please sign in to comment.