added last drive commands to elastichosts

This commit is contained in:
Adrian Cole 2010-11-21 22:53:16 +01:00
parent a2a84535d0
commit 0caab0226b
4 changed files with 98 additions and 7 deletions

View File

@ -80,6 +80,22 @@ public interface ElasticHostsAsyncClient {
@ResponseParser(SplitNewlines.class)
ListenableFuture<Set<String>> listStandardDrives();
/**
* @see ElasticHostsClient#listStandardCds()
*/
@GET
@Path("/drives/standard/cd/list")
@ResponseParser(SplitNewlines.class)
ListenableFuture<Set<String>> listStandardCds();
/**
* @see ElasticHostsClient#listStandardImages()
*/
@GET
@Path("/drives/standard/img/list")
@ResponseParser(SplitNewlines.class)
ListenableFuture<Set<String>> listStandardImages();
/**
* @see ElasticHostsClient#listDriveInfo()
*/

View File

@ -54,6 +54,20 @@ public interface ElasticHostsClient {
*/
Set<String> listStandardDrives();
/**
* list of cd uuids that are in the library
*
* @return or empty set if no cds are found
*/
Set<String> listStandardCds();
/**
* list of image uuids that are in the library
*
* @return or empty set if no images are found
*/
Set<String> listStandardImages();
/**
* Get all drives info
*

View File

@ -102,6 +102,36 @@ public class ElasticHostsAsyncClientTest extends RestClientTest<ElasticHostsAsyn
checkFilters(httpRequest);
}
public void testListStandardCds() throws SecurityException, NoSuchMethodException, IOException {
Method method = ElasticHostsAsyncClient.class.getMethod("listStandardCds");
GeneratedHttpRequest<ElasticHostsAsyncClient> httpRequest = processor.createRequest(method);
assertRequestLineEquals(httpRequest, "GET https://api.elastichosts.com/drives/standard/cd/list HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: text/plain\n");
assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, SplitNewlines.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null);
checkFilters(httpRequest);
}
public void testListStandardImages() throws SecurityException, NoSuchMethodException, IOException {
Method method = ElasticHostsAsyncClient.class.getMethod("listStandardImages");
GeneratedHttpRequest<ElasticHostsAsyncClient> httpRequest = processor.createRequest(method);
assertRequestLineEquals(httpRequest, "GET https://api.elastichosts.com/drives/standard/img/list HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: text/plain\n");
assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, SplitNewlines.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null);
checkFilters(httpRequest);
}
public void testListDriveInfo() throws SecurityException, NoSuchMethodException, IOException {
Method method = ElasticHostsAsyncClient.class.getMethod("listDriveInfo");
GeneratedHttpRequest<ElasticHostsAsyncClient> httpRequest = processor.createRequest(method);
@ -279,6 +309,7 @@ public class ElasticHostsAsyncClientTest extends RestClientTest<ElasticHostsAsyn
checkFilters(httpRequest);
}
@Override
protected void checkFilters(HttpRequest request) {
assertEquals(request.getFilters().size(), 1);

View File

@ -25,6 +25,7 @@ import static org.jclouds.rest.RestContextFactory.createContext;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import java.io.IOException;
import java.util.Properties;
import java.util.Set;
@ -33,8 +34,10 @@ import org.jclouds.elastichosts.domain.ClaimType;
import org.jclouds.elastichosts.domain.CreateDriveRequest;
import org.jclouds.elastichosts.domain.DriveData;
import org.jclouds.elastichosts.domain.DriveInfo;
import org.jclouds.io.Payloads;
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
import org.jclouds.rest.RestContext;
import org.jclouds.util.Utils;
import org.testng.annotations.AfterGroups;
import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test;
@ -120,6 +123,18 @@ public class ElasticHostsClientLiveTest {
assertNotNull(drives);
}
@Test
public void testListStandardCds() throws Exception {
Set<String> drives = client.listStandardCds();
assertNotNull(drives);
}
@Test
public void testListStandardImages() throws Exception {
Set<String> drives = client.listStandardImages();
assertNotNull(drives);
}
@Test
public void testGetDrive() throws Exception {
for (String driveUUID : client.listDrives()) {
@ -132,11 +147,12 @@ public class ElasticHostsClientLiveTest {
private String prefix = System.getProperty("user.name") + ".test";
private DriveInfo info;
private DriveInfo info2;
@Test
public void testCreate() throws Exception {
try {
findAndDestroyDrive();
findAndDestroyDrive(prefix);
} catch (Exception e) {
}
@ -149,12 +165,25 @@ public class ElasticHostsClientLiveTest {
}
public void testWeCanReadAndWriteToDrive() {
// TODO put a bunch of bytes and then read them back.
@Test(dependsOnMethods = "testCreate")
public void testWeCanReadAndWriteToDrive() throws IOException {
client.writeDrive(info.getUuid(), Payloads.newStringPayload("foo"));
assertEquals(Utils.toStringAndClose(client.readDrive(info.getUuid()).getInput()), "foo");
}
public void testWeCopyADriveContentsViaGzip() {
// TODO gzip source to destination, then gunzip back to source and assert equiv
@Test(dependsOnMethods = "testWeCanReadAndWriteToDrive")
public void testWeCopyADriveContentsViaGzip() throws IOException {
try {
findAndDestroyDrive(prefix + "2");
} catch (Exception e) {
}
info2 = client.createDrive(new CreateDriveRequest.Builder().name(prefix + "2").size(1024 * 1024l).build());
client.imageDrive(info.getUuid(), info2.getUuid());
// TODO block until complete
System.err.println("state " + client.getDriveInfo(info2.getUuid()));
assertEquals(Utils.toStringAndClose(client.readDrive(info2.getUuid()).getInput()), "foo");
}
@ -166,6 +195,7 @@ public class ElasticHostsClientLiveTest {
new DriveData.Builder().claimType(ClaimType.SHARED).name("rediculous")
.readers(ImmutableSet.of("ffffffff-ffff-ffff-ffff-ffffffffffff"))
.tags(ImmutableSet.of("tag1", "tag2")).userMetadata(ImmutableMap.of("foo", "bar")).build());
assertNotNull(info2.getUuid(), info.getUuid());
assertEquals(info.getName(), "rediculous");
assertEquals(info.getClaimType(), ClaimType.SHARED);
@ -177,12 +207,12 @@ public class ElasticHostsClientLiveTest {
@Test(dependsOnMethods = "testSetDriveData")
public void testDestroyDrive() throws Exception {
findAndDestroyDrive();
findAndDestroyDrive(prefix);
assertEquals(client.getDriveInfo(info.getUuid()), null);
}
protected void findAndDestroyDrive() {
protected void findAndDestroyDrive(final String prefix) {
DriveInfo drive = Iterables.find(client.listDriveInfo(), new Predicate<DriveInfo>() {
@Override