Skip to content

Commit

Permalink
Merge pull request #1 from gschueler/uuid-support
Browse files Browse the repository at this point in the history
Change Job ID support to use Strings instead of Long, allowing UUIDs
  • Loading branch information
vbehar committed Jun 28, 2011
2 parents 02f02e2 + e0fee35 commit 5c9922f
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 33 deletions.
Expand Up @@ -28,7 +28,7 @@ public class RundeckJobProjectLinkerAction implements Action {
* @param rundeckJobId ID of the RunDeck job
* @throws RundeckApiException in case of error while load the job details from RunDeck API
*/
public RundeckJobProjectLinkerAction(RundeckInstance rundeck, Long rundeckJobId) throws RundeckApiException {
public RundeckJobProjectLinkerAction(RundeckInstance rundeck, String rundeckJobId) throws RundeckApiException {
this.rundeck = rundeck;
this.rundeckJob = rundeck.getJob(rundeckJobId);
this.rundeckJobUrl = buildRundeckJobUrl();
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/org/jenkinsci/plugins/rundeck/RundeckNotifier.java
Expand Up @@ -42,7 +42,7 @@
*/
public class RundeckNotifier extends Notifier {

private final Long jobId;
private final String jobId;

private final String options;

Expand All @@ -53,7 +53,7 @@ public class RundeckNotifier extends Notifier {
private final Boolean shouldFailTheBuild;

@DataBoundConstructor
public RundeckNotifier(Long jobId, String options, String tag, Boolean shouldWaitForRundeckJob,
public RundeckNotifier(String jobId, String options, String tag, Boolean shouldWaitForRundeckJob,
Boolean shouldFailTheBuild) {
this.jobId = jobId;
this.options = options;
Expand Down Expand Up @@ -240,7 +240,7 @@ public BuildStepMonitor getRequiredMonitorService() {
return BuildStepMonitor.NONE;
}

public Long getJobId() {
public String getJobId() {
return jobId;
}

Expand Down Expand Up @@ -287,7 +287,7 @@ public boolean configure(StaplerRequest req, JSONObject json) throws FormExcepti

@Override
public Publisher newInstance(StaplerRequest req, JSONObject formData) throws FormException {
return new RundeckNotifier(formData.getLong("jobId"),
return new RundeckNotifier(formData.getString("jobId"),
formData.getString("options"),
formData.getString("tag"),
formData.getBoolean("shouldWaitForRundeckJob"),
Expand All @@ -310,7 +310,7 @@ public FormValidation doTestConnection(@QueryParameter("rundeck.url") final Stri
return FormValidation.ok("Your RunDeck instance is alive, and your credentials are valid !");
}

public FormValidation doCheckJob(@QueryParameter("jobId") final Long jobId) {
public FormValidation doCheckJob(@QueryParameter("jobId") final String jobId) {
try {
RundeckJob job = rundeckInstance.getJob(jobId);
return FormValidation.ok("Your RunDeck job is : %s (project: %s)", job.getFullName(), job.getProject());
Expand Down
Expand Up @@ -99,13 +99,13 @@ public boolean isLoginValid() {

/**
* Get the details of a job, identified by the given id.
*
*
* @param jobId - mandatory
* @return a {@link RundeckJob} instance (won't be null), with details on the job
* @throws RundeckApiException in case of error calling the API
* @throws RundeckApiLoginException if the login failed
*/
public RundeckJob getJob(Long jobId) throws RundeckApiException, RundeckApiLoginException {
public RundeckJob getJob(String jobId) throws RundeckApiException, RundeckApiLoginException {
if (jobId == null) {
throw new IllegalArgumentException("jobId is mandatory to get the details of a job !");
}
Expand Down Expand Up @@ -193,15 +193,15 @@ public RundeckExecution getExecution(Long executionId) throws RundeckApiExceptio

/**
* Run a job, identified by the given id.
*
*
* @param jobId - mandatory
* @param options for the job, optional
* @return a {@link RundeckExecution} instance (won't be null), with details on the execution
* @throws RundeckApiLoginException if the login failed
* @throws RundeckApiJobRunException if the run failed
* @throws RundeckApiException in case of error calling the API
*/
public RundeckExecution runJob(Long jobId, Properties options) throws RundeckApiException,
public RundeckExecution runJob(String jobId, Properties options) throws RundeckApiException,
RundeckApiLoginException, RundeckApiJobRunException {
if (jobId == null) {
throw new IllegalArgumentException("jobId is mandatory to run a job !");
Expand Down
Expand Up @@ -12,7 +12,7 @@ public class RundeckJob implements Serializable {

private static final long serialVersionUID = 1L;

private Long id;
private String id;

private String name;

Expand All @@ -34,11 +34,11 @@ public String getFullName() {
return fullName.toString();
}

public Long getId() {
public String getId() {
return id;
}

public void setId(Long id) {
public void setId(String id) {
this.id = id;
}

Expand Down
Expand Up @@ -79,7 +79,7 @@ public static RundeckJob parseJobDefinition(InputStream response) throws Rundeck
Node jobNode = document.selectSingleNode("joblist/job");

RundeckJob job = new RundeckJob();
job.setId(Long.valueOf(jobNode.valueOf("id")));
job.setId(jobNode.valueOf("id"));
job.setName(jobNode.valueOf("name"));
job.setDescription(jobNode.valueOf("description"));
job.setGroup(jobNode.valueOf("group"));
Expand Down Expand Up @@ -130,7 +130,7 @@ public static RundeckExecution parseExecution(InputStream response) throws Runde
Node jobNode = execNode.selectSingleNode("job");
if (jobNode != null) {
RundeckJob job = new RundeckJob();
job.setId(Long.valueOf(jobNode.valueOf("@id")));
job.setId(jobNode.valueOf("@id"));
job.setName(jobNode.valueOf("name"));
job.setGroup(StringUtils.trimToNull(jobNode.valueOf("group")));
job.setProject(jobNode.valueOf("project"));
Expand Down
Expand Up @@ -37,7 +37,7 @@
public class RundeckNotifierTest extends HudsonTestCase {

public void testCommitWithoutTag() throws Exception {
RundeckNotifier notifier = new RundeckNotifier(1L, createOptions(), "", false, false);
RundeckNotifier notifier = new RundeckNotifier("1", createOptions(), "", false, false);
notifier.getDescriptor().setRundeckInstance(new MockRundeckInstance());

FreeStyleProject project = createFreeStyleProject();
Expand All @@ -63,7 +63,7 @@ public void testCommitWithoutTag() throws Exception {
}

public void testStandardCommitWithTag() throws Exception {
RundeckNotifier notifier = new RundeckNotifier(1L, null, "#deploy", false, false);
RundeckNotifier notifier = new RundeckNotifier("1", null, "#deploy", false, false);
notifier.getDescriptor().setRundeckInstance(new MockRundeckInstance());

FreeStyleProject project = createFreeStyleProject();
Expand All @@ -87,7 +87,7 @@ public void testStandardCommitWithTag() throws Exception {
}

public void testDeployCommitWithTagWontBreakTheBuild() throws Exception {
RundeckNotifier notifier = new RundeckNotifier(1L, null, "#deploy", false, false);
RundeckNotifier notifier = new RundeckNotifier("1", null, "#deploy", false, false);
notifier.getDescriptor().setRundeckInstance(new MockRundeckInstance());

FreeStyleProject project = createFreeStyleProject();
Expand All @@ -113,13 +113,13 @@ public void testDeployCommitWithTagWontBreakTheBuild() throws Exception {
}

public void testDeployCommitWithTagWillBreakTheBuild() throws Exception {
RundeckNotifier notifier = new RundeckNotifier(1L, null, "#deploy", false, true);
RundeckNotifier notifier = new RundeckNotifier("1", null, "#deploy", false, true);
notifier.getDescriptor().setRundeckInstance(new MockRundeckInstance() {

private static final long serialVersionUID = 1L;

@Override
public RundeckExecution runJob(Long jobId, Properties options) throws RundeckApiException,
public RundeckExecution runJob(String jobId, Properties options) throws RundeckApiException,
RundeckApiLoginException, RundeckApiJobRunException {
throw new RundeckApiJobRunException("Fake error for testing");
}
Expand Down Expand Up @@ -150,13 +150,13 @@ public RundeckExecution runJob(Long jobId, Properties options) throws RundeckApi
}

public void testExpandEnvVarsInOptions() throws Exception {
RundeckNotifier notifier = new RundeckNotifier(1L, createOptions(), null, false, true);
RundeckNotifier notifier = new RundeckNotifier("1", createOptions(), null, false, true);
notifier.getDescriptor().setRundeckInstance(new MockRundeckInstance() {

private static final long serialVersionUID = 1L;

@Override
public RundeckExecution runJob(Long jobId, Properties options) throws RundeckApiException,
public RundeckExecution runJob(String jobId, Properties options) throws RundeckApiException,
RundeckApiLoginException, RundeckApiJobRunException {
Assert.assertEquals(4, options.size());
Assert.assertEquals("value 1", options.getProperty("option1"));
Expand All @@ -181,7 +181,7 @@ public RundeckExecution runJob(Long jobId, Properties options) throws RundeckApi
}

public void testUpstreamBuildWithTag() throws Exception {
RundeckNotifier notifier = new RundeckNotifier(1L, null, "#deploy", false, false);
RundeckNotifier notifier = new RundeckNotifier("1", null, "#deploy", false, false);
notifier.getDescriptor().setRundeckInstance(new MockRundeckInstance());

FreeStyleProject upstream = createFreeStyleProject("upstream");
Expand Down Expand Up @@ -216,7 +216,7 @@ public void testUpstreamBuildWithTag() throws Exception {
}

public void testFailedBuild() throws Exception {
RundeckNotifier notifier = new RundeckNotifier(1L, createOptions(), "", false, false);
RundeckNotifier notifier = new RundeckNotifier("1", createOptions(), "", false, false);
notifier.getDescriptor().setRundeckInstance(new MockRundeckInstance());

FreeStyleProject project = createFreeStyleProject();
Expand All @@ -240,13 +240,13 @@ public void testFailedBuild() throws Exception {
}

public void testWaitForRundeckJob() throws Exception {
RundeckNotifier notifier = new RundeckNotifier(1L, createOptions(), "", true, false);
RundeckNotifier notifier = new RundeckNotifier("1", createOptions(), "", true, false);
notifier.getDescriptor().setRundeckInstance(new MockRundeckInstance() {

private static final long serialVersionUID = 1L;

@Override
public RundeckExecution runJob(Long jobId, Properties options) throws RundeckApiException,
public RundeckExecution runJob(String jobId, Properties options) throws RundeckApiException,
RundeckApiLoginException, RundeckApiJobRunException {
RundeckExecution execution = new RundeckExecution();
execution.setStatus(ExecutionStatus.SUCCEEDED);
Expand Down Expand Up @@ -349,7 +349,7 @@ public boolean isLoginValid() {
}

@Override
public RundeckExecution runJob(Long jobId, Properties options) throws RundeckApiException,
public RundeckExecution runJob(String jobId, Properties options) throws RundeckApiException,
RundeckApiLoginException, RundeckApiJobRunException {
RundeckExecution execution = new RundeckExecution();
execution.setStatus(ExecutionStatus.RUNNING);
Expand All @@ -364,7 +364,7 @@ public RundeckExecution getExecution(Long executionId) throws RundeckApiExceptio
}

@Override
public RundeckJob getJob(Long jobId) throws RundeckApiException, RundeckApiLoginException {
public RundeckJob getJob(String jobId) throws RundeckApiException, RundeckApiLoginException {
RundeckJob job = new RundeckJob();
return job;
}
Expand Down
Expand Up @@ -25,7 +25,7 @@ public void testInvalidLogin() throws Exception {
rundeck = new RundeckInstance(rundeck.getUrl(), "invalid", "invalidToo");
if (rundeck.isAlive()) {
try {
rundeck.runJob(1L, null);
rundeck.runJob("1", null);
fail("login for an invalid user should have failed !");
} catch (RundeckApiLoginException e) {
assertNull("Login failure for invalid user should not have a cause ! cause : " + e.getCause(),
Expand All @@ -39,7 +39,7 @@ public void testInvalidLogin() throws Exception {
public void testInvalidJob() throws Exception {
if (rundeck.isAlive()) {
try {
rundeck.runJob(4242424242L, null);
rundeck.runJob("4242424242", null);
fail("running an invalid job should have failed !");
} catch (RundeckApiJobRunException e) {
assertNull("failure when running an invalid job should not have a cause ! cause : " + e.getCause(),
Expand All @@ -55,7 +55,7 @@ public void testValidJob() throws Exception {
Properties options = new Properties();
options.setProperty("command", "ls");
options.setProperty("dir", "/tmp");
RundeckExecution execution = rundeck.runJob(1l, options);
RundeckExecution execution = rundeck.runJob("1", options);
assertEquals(rundeck.getLogin(), execution.getStartedBy());
} else {
System.out.println("No live RunDeck instance at " + rundeck.getUrl() + " - doing nothing...");
Expand Down
Expand Up @@ -32,7 +32,7 @@ public void testParseJobDefinition() throws Exception {
InputStream input = getClass().getResourceAsStream("job-definition.xml");
RundeckJob job = RundeckUtils.parseJobDefinition(input);

assertEquals(new Long(1), job.getId());
assertEquals("1", job.getId());
assertEquals("job-name", job.getName());
assertEquals("job description", job.getDescription());
assertEquals("group-name", job.getGroup());
Expand Down Expand Up @@ -64,7 +64,7 @@ public void testParseExecutionSuccess() throws Exception {
assertEquals(null, execution.getEndedAt());
assertEquals("ls ${option.dir}", execution.getDescription());

assertEquals(new Long(1), job.getId());
assertEquals("1", job.getId());
assertEquals("ls", job.getName());
assertEquals("test", job.getGroup());
assertEquals("test", job.getProject());
Expand Down

0 comments on commit 5c9922f

Please sign in to comment.