Skip to content

Commit

Permalink
Support v5 bulk delete
Browse files Browse the repository at this point in the history
  • Loading branch information
gschueler committed Oct 2, 2012
1 parent 76a150c commit adfcc63
Show file tree
Hide file tree
Showing 13 changed files with 696 additions and 10 deletions.
29 changes: 19 additions & 10 deletions src/main/java/org/rundeck/api/RundeckClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,8 @@
import org.apache.commons.lang.StringUtils;
import org.rundeck.api.RundeckApiException.RundeckApiLoginException;
import org.rundeck.api.RundeckApiException.RundeckApiTokenException;
import org.rundeck.api.domain.RundeckAbort;
import org.rundeck.api.domain.RundeckExecution;
import org.rundeck.api.domain.RundeckHistory;
import org.rundeck.api.domain.RundeckJob;
import org.rundeck.api.domain.RundeckJobsImportMethod;
import org.rundeck.api.domain.RundeckJobsImportResult;
import org.rundeck.api.domain.RundeckNode;
import org.rundeck.api.domain.RundeckProject;
import org.rundeck.api.domain.RundeckSystemInfo;
import org.rundeck.api.domain.*;
import org.rundeck.api.domain.RundeckExecution.ExecutionStatus;
import org.rundeck.api.domain.RundeckOutput;
import org.rundeck.api.parser.*;
import org.rundeck.api.query.ExecutionQuery;
import org.rundeck.api.util.AssertUtil;
Expand Down Expand Up @@ -786,6 +777,24 @@ public String deleteJob(String jobId) throws RundeckApiException, RundeckApiLogi
AssertUtil.notBlank(jobId, "jobId is mandatory to delete a job !");
return new ApiCall(this).delete(new ApiPathBuilder("/job/", jobId), new StringParser("result/success/message"));
}
/**
* Delete multiple jobs, identified by the given IDs
*
* @param jobIds List of job IDS
* @return the bulk delete result
* @throws RundeckApiException in case of error when calling the API (non-existent job with this ID)
* @throws RundeckApiLoginException if the login fails (in case of login-based authentication)
* @throws RundeckApiTokenException if the token is invalid (in case of token-based authentication)
* @throws IllegalArgumentException if the jobId is blank (null, empty or whitespace)
*/
public RundeckJobDeleteBulk deleteJobs(final List<String> jobIds) throws RundeckApiException, RundeckApiLoginException,
RundeckApiTokenException, IllegalArgumentException {
if (null == jobIds || 0 == jobIds.size()) {
throw new IllegalArgumentException("jobIds are mandatory to delete a job");
}
return new ApiCall(this).post(new ApiPathBuilder("/jobs/delete").field("ids",jobIds),
new BulkDeleteParser("result/deleteJobs"));
}

/**
* Trigger the execution of a RunDeck job (identified by the given ID), and return immediately (without waiting the
Expand Down
133 changes: 133 additions & 0 deletions src/main/java/org/rundeck/api/domain/RundeckJobDelete.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
/*
* Copyright 2012 DTO Labs, Inc. (http://dtolabs.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

/*
* RundeckJobDelete.java
*
* User: Greg Schueler <a href="mailto:[email protected]">[email protected]</a>
* Created: 10/1/12 3:53 PM
*
*/
package org.rundeck.api.domain;

import java.util.*;


/**
* RundeckJobDelete represents a result of a job delete request.
*
* @author Greg Schueler <a href="mailto:[email protected]">[email protected]</a>
*/
public class RundeckJobDelete {
private String id;
private String error;
private boolean successful;
private String errorCode;
private String message;

/**
* Job ID
*/
public String getId() {
return id;
}

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

/**
* Error message if the job could not be deleted
*/
public String getError() {
return error;
}

public void setError(String error) {
this.error = error;
}

/**
* True if the job was successfully deleted
*/
public boolean isSuccessful() {
return successful;
}

public void setSuccessful(boolean successful) {
this.successful = successful;
}

/**
* Error code string if there was a failure
*/
public String getErrorCode() {
return errorCode;
}

public void setErrorCode(String errorCode) {
this.errorCode = errorCode;
}

/**
* Success message if it was successful
*/
public String getMessage() {
return message;
}

public void setMessage(String message) {
this.message = message;
}

@Override
public boolean equals(Object o) {
if (this == o) { return true; }
if (o == null || getClass() != o.getClass()) { return false; }

RundeckJobDelete delete = (RundeckJobDelete) o;

if (successful != delete.successful) { return false; }
if (error != null ? !error.equals(delete.error) : delete.error != null) { return false; }
if (errorCode != null ? !errorCode.equals(delete.errorCode) : delete.errorCode != null) { return false; }
if (id != null ? !id.equals(delete.id) : delete.id != null) { return false; }
if (message != null ? !message.equals(delete.message) : delete.message != null) { return false; }

return true;
}

@Override
public int hashCode() {
int result = id != null ? id.hashCode() : 0;
result = 31 * result + (error != null ? error.hashCode() : 0);
result = 31 * result + (successful ? 1 : 0);
result = 31 * result + (errorCode != null ? errorCode.hashCode() : 0);
result = 31 * result + (message != null ? message.hashCode() : 0);
return result;
}

@Override
public String toString() {
return "RundeckJobDelete{" +
"id='" + id + '\'' +
", error='" + error + '\'' +
", successful=" + successful +
", errorCode='" + errorCode + '\'' +
", message='" + message + '\'' +
'}';
}
}
82 changes: 82 additions & 0 deletions src/main/java/org/rundeck/api/domain/RundeckJobDeleteBulk.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
* Copyright 2012 DTO Labs, Inc. (http://dtolabs.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

/*
* RundeckJobDeleteBulk.java
*
* User: Greg Schueler <a href="mailto:[email protected]">[email protected]</a>
* Created: 10/1/12 4:12 PM
*
*/
package org.rundeck.api.domain;

import java.util.*;


/**
* RundeckJobDeleteBulk represents the result of a bulk job delete request and contains
* a list of {@link RundeckJobDelete} objects.
*
* @author Greg Schueler <a href="mailto:[email protected]">[email protected]</a>
*/
public class RundeckJobDeleteBulk implements Iterable<RundeckJobDelete> {
private List<RundeckJobDelete> results;
private int requestCount;
private boolean allsuccessful;

public RundeckJobDeleteBulk(List<RundeckJobDelete> results, int requestCount, boolean allsuccessful) {
this.results = results;
this.requestCount = requestCount;
this.allsuccessful = allsuccessful;
}

public List<RundeckJobDelete> getResults() {
return results;
}

/**
* The number of job delete requests processed.
*/
public int getRequestCount() {
return requestCount;
}

/**
* True if all job delete requests were successful
*/
public boolean isAllsuccessful() {
return allsuccessful;
}

@Override
public Iterator<RundeckJobDelete> iterator() {
if(null!=results){
return results.iterator();
}else{
return null;
}
}

@Override
public String toString() {
return "RundeckJobDeleteBulk{" +
"results=" + results +
", requestCount=" + requestCount +
", allsuccessful=" + allsuccessful +
'}';
}
}
80 changes: 80 additions & 0 deletions src/main/java/org/rundeck/api/parser/BulkDeleteParser.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* Copyright 2012 DTO Labs, Inc. (http://dtolabs.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

/*
* BulkDeleteParser.java
*
* User: Greg Schueler <a href="mailto:[email protected]">[email protected]</a>
* Created: 10/1/12 3:55 PM
*
*/
package org.rundeck.api.parser;

import org.apache.commons.lang.StringUtils;
import org.dom4j.Element;
import org.dom4j.Node;
import org.rundeck.api.domain.RundeckJobDelete;
import org.rundeck.api.domain.RundeckJobDeleteBulk;

import java.util.*;


/**
* BulkDeleteParser is ...
*
* @author Greg Schueler <a href="mailto:[email protected]">[email protected]</a>
*/
public class BulkDeleteParser implements XmlNodeParser<RundeckJobDeleteBulk> {
private String xpath;

public BulkDeleteParser(String xpath) {
this.xpath = xpath;
}

public BulkDeleteParser() {
}

@Override
public RundeckJobDeleteBulk parseXmlNode(Node node) {
Node subnode = xpath != null ? node.selectSingleNode(xpath) : node;
final ArrayList<RundeckJobDelete> deletes = new ArrayList<RundeckJobDelete>();
final List results = subnode.selectNodes("(succeeded|failed)/deleteJobResult");
final DeleteParser parser = new DeleteParser();
if (null != results && results.size() > 0) {
for (final Object o : results) {
deletes.add(parser.parseXmlNode((Node) o));
}
}

final String requestcount = StringUtils.trimToNull(subnode.valueOf("@requestCount"));
final String allsuccessString = StringUtils.trimToNull(subnode.valueOf("@allsuccessful"));
int count = 0;
boolean allsuccess = false;
if (null != requestcount) {
try {
count = Integer.parseInt(requestcount);
} catch (NumberFormatException e) {

}
}
if (null != allsuccessString) {
allsuccess = Boolean.parseBoolean(allsuccessString);
}

return new RundeckJobDeleteBulk(deletes, count, allsuccess);
}
}
Loading

0 comments on commit adfcc63

Please sign in to comment.