add an OptionsBuilder (easier to use in scripts)

This commit is contained in:
Vincent Behar 2011-07-04 17:36:16 +02:00
parent 3720fe9d31
commit 48948d4c52
2 changed files with 47 additions and 3 deletions

View file

@ -19,6 +19,7 @@ import org.rundeck.api.parser.ProjectParser;
import org.rundeck.api.parser.ProjectsParser;
import org.rundeck.api.util.ArgsUtil;
import org.rundeck.api.util.AssertUtil;
import org.rundeck.api.util.OptionsBuilder;
/**
* Main entry point to talk to a RunDeck instance
@ -226,7 +227,7 @@ public class RundeckClient implements Serializable {
* end of the job execution)
*
* @param jobId identifier of the job - mandatory
* @param options of the job - optional
* @param options of the job - optional. See {@link OptionsBuilder}.
* @return a {@link RundeckExecution} instance for the newly created (and running) execution - won't be null
* @throws RundeckApiException in case of error when calling the API (non-existent job with this ID)
* @throws RundeckApiLoginException if the login failed
@ -268,7 +269,7 @@ public class RundeckClient implements Serializable {
* aborted) or is still running.
*
* @param jobId identifier of the job - mandatory
* @param options of the job - optional
* @param options of the job - optional. See {@link OptionsBuilder}.
* @return a {@link RundeckExecution} instance for the (finished/aborted) execution - won't be null
* @throws RundeckApiException in case of error when calling the API (non-existent job with this ID)
* @throws RundeckApiLoginException if the login failed
@ -287,7 +288,7 @@ public class RundeckClient implements Serializable {
* know if the execution is finished (or aborted) or is still running.
*
* @param jobId identifier of the job - mandatory
* @param options of the job - optional
* @param options of the job - optional. See {@link OptionsBuilder}.
* @param poolingInterval for checking the status of the execution. Must be > 0.
* @param poolingUnit unit (seconds, milli-seconds, ...) of the interval. Default to seconds.
* @return a {@link RundeckExecution} instance for the (finished/aborted) execution - won't be null

View file

@ -0,0 +1,43 @@
package org.rundeck.api.util;
import java.util.Properties;
/**
* Builder for job options
*
* @author Vincent Behar
*/
public class OptionsBuilder {
private final Properties options;
/**
* Build a new instance. Use {@link #addOption(Object, Object)} to add some options, and then
* {@link #toProperties()} when you're done !
*/
public OptionsBuilder() {
options = new Properties();
}
/**
* Add an option
*
* @param key of the option
* @param value of the option
* @return this, for method chaining
*/
public OptionsBuilder addOption(Object key, Object value) {
options.put(key, value);
return this;
}
/**
* @return a new {@link Properties} instance
*/
public Properties toProperties() {
Properties options = new Properties();
options.putAll(this.options);
return options;
}
}