Add project export for apiv11

This commit is contained in:
Greg Schueler 2014-03-07 13:22:59 -08:00
parent 2ffe87d428
commit bea99b1c97
3 changed files with 77 additions and 5 deletions

View file

@ -34,11 +34,7 @@ import org.rundeck.api.util.AssertUtil;
import org.rundeck.api.util.PagedResults;
import org.rundeck.api.util.ParametersUtil;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.Serializable;
import java.io.*;
import java.util.*;
import java.util.concurrent.TimeUnit;
@ -378,6 +374,49 @@ public class RundeckClient implements Serializable {
AssertUtil.notBlank(projectName, "projectName is mandatory to create a project !");
new ApiCall(this).delete(new ApiPathBuilder("/project/", projectName));
}
/**
* Convenience method to export the archive of a project to the specified file.
*
* @param projectName name of the project - mandatory
* @param out file to write to
* @return number of bytes written to the stream
*
* @throws RundeckApiException in case of error when calling the API (non-existent project with this name)
* @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 projectName is blank (null, empty or whitespace)
*/
public int exportProject(final String projectName, final File out) throws
RundeckApiException, RundeckApiLoginException,
RundeckApiTokenException, IllegalArgumentException, IOException {
final FileOutputStream fileOutputStream = new FileOutputStream(out);
try {
return exportProject(projectName, fileOutputStream);
}finally {
fileOutputStream.close();
}
}
/**
* Export the archive of a project to the specified outputstream
*
* @param projectName name of the project - mandatory
* @return number of bytes written to the stream
*
* @throws RundeckApiException in case of error when calling the API (non-existent project with this name)
* @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 projectName is blank (null, empty or whitespace)
*/
public int exportProject(String projectName, OutputStream out) throws
RundeckApiException, RundeckApiLoginException,
RundeckApiTokenException, IllegalArgumentException, IOException {
AssertUtil.notBlank(projectName, "projectName is mandatory to export a project archive!");
return new ApiCall(this).get(
new ApiPathBuilder("/project/", projectName, "/export")
.accept("application/zip"),
out);
}
/**
* Return the configuration of a project
*

View file

@ -28,6 +28,7 @@ import org.rundeck.api.query.ExecutionQuery;
import org.rundeck.api.util.PagedResults;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.InputStream;
import java.util.*;
@ -160,6 +161,15 @@ public class RundeckClientTest {
Assert.assertNull(value);
}
@Test
@Betamax(tape = "export_projectv11")
public void exportProject() throws Exception {
RundeckClient client1 = createClient(TEST_TOKEN_6, 11);
File temp = File.createTempFile("test-archive", ".zip");
temp.deleteOnExit();
int i = client1.exportProject("DEF1", temp);
Assert.assertEquals(8705,i);
}
@Test
@Betamax(tape = "get_history")
public void getHistory() throws Exception {
final RundeckHistory test = client.getHistory("test");

File diff suppressed because one or more lines are too long