upload client now works

This commit is contained in:
Adrian Cole 2012-03-11 12:56:25 -07:00
parent d820e4fab8
commit b309dd60df
4 changed files with 37 additions and 41 deletions

View File

@ -384,6 +384,7 @@ public class Task extends EntityType<Task> {
* <li>aborted - The task was aborted by an administrative action.
* </ul>
*/
// TODO: enum!!!
public String getStatus() {
return status;
}

View File

@ -18,38 +18,27 @@
*/
package org.jclouds.vcloud.director.v1_5.features;
import java.io.File;
import java.net.URI;
import javax.ws.rs.PUT;
import org.jclouds.rest.annotations.ExceptionParser;
import org.jclouds.io.Payload;
import org.jclouds.rest.annotations.EndpointParam;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.vcloud.director.v1_5.filters.AddVCloudAuthorizationToRequest;
import org.jclouds.vcloud.director.v1_5.functions.ThrowVCloudErrorOn4xx;
import com.google.common.util.concurrent.ListenableFuture;
/**
*
* @see UploadClient
* @author danikov
*/
@RequestFilters(AddVCloudAuthorizationToRequest.class)
public interface UploadAsyncClient { // TODO: implement these operations correctly
public interface UploadAsyncClient {
/**
* @see UploadClient#uploadFile(URI, File)
* @see UploadClient#put
*/
@PUT
@ExceptionParser(ThrowVCloudErrorOn4xx.class)
ListenableFuture<Object> uploadFile(URI uri, File file);
/**
* @see UploadClient#uploadBigFile(URI, File)
*/
@PUT
@ExceptionParser(ThrowVCloudErrorOn4xx.class)
ListenableFuture<Object> uploadBigFile(URI target, File file);
ListenableFuture<Void> upload(@EndpointParam URI location, Payload payload);
}

View File

@ -18,31 +18,25 @@
*/
package org.jclouds.vcloud.director.v1_5.features;
import java.io.File;
import java.net.URI;
import java.util.concurrent.TimeUnit;
import org.jclouds.concurrent.Timeout;
import org.jclouds.io.Payload;
/**
* Provides synchronous access to Upload.
* <p/>
*
* @see UploadAsyncClient
* @see <a href= "http://support.theenterprisecloud.com/kb/default.asp?id=984&Lang=1&SID=" />
* @author danikov
*/
@Timeout(duration = 180, timeUnit = TimeUnit.SECONDS)
public interface UploadClient {
/**
* Uploads a file.
* @return eTag
*/
void uploadFile(URI uri, File file);
/**
* Uploads a file using ranged PUTs.
*/
void uploadBigFile(URI uri, File file);
void upload(URI location, Payload payload);
}

View File

@ -47,6 +47,7 @@ import static org.testng.Assert.fail;
import java.net.URISyntaxException;
import java.util.Set;
import org.jclouds.io.Payloads;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorException;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType;
import org.jclouds.vcloud.director.v1_5.domain.Checks;
@ -102,19 +103,20 @@ public class MediaClientLiveTest extends BaseVCloudDirectorClientLiveTest {
private MetadataValue metadataValue;
private String metadataEntryValue = "value";
@Test(testName = "POST /vdc/{id}/media", enabled = false)
@Test(testName = "POST /vdc/{id}/media")
public void testCreateMedia() throws URISyntaxException {
assertNotNull(vdcURI, String.format(REF_REQ_LIVE, VDC));
Vdc vdc = vdcClient.getVdc(vdcURI);
assertNotNull(vdc, String.format(OBJ_REQ_LIVE, VDC));
Link addMedia = find(vdc.getLinks(), and(relEquals("add"), typeEquals(VCloudDirectorMediaType.MEDIA)));
java.io.File sourceFile = new java.io.File(getClass().getResource("/media/test.iso").toURI());
// TODO: generate an iso
byte[] iso = new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
Media sourceMedia = Media.builder()
.type(VCloudDirectorMediaType.MEDIA)
.name("Test media 1")
.size(sourceFile.length())
.size(iso.length)
.imageType(Media.ImageType.ISO)
.description("Test media generated by testCreateMedia()")
.build();
@ -137,11 +139,21 @@ public class MediaClientLiveTest extends BaseVCloudDirectorClientLiveTest {
Link uploadLink = getFirst(links, null);
assertTrue(equal(uploadLink.getRel(), Link.Rel.UPLOAD_DEFAULT), String.format(OBJ_FIELD_REQ, MEDIA, "uploadFile.links.first"));
fail(); //TODO upload file and assert it succeeds
context.getApi().getUploadClient().uploadFile(uploadLink.getHref(), sourceFile);
context.getApi().getUploadClient().upload(uploadLink.getHref(), Payloads.newByteArrayPayload(iso));
media = mediaClient.getMedia(media.getHref());
Task task = Iterables.getOnlyElement(media.getTasksInProgress().getTasks());
assertEquals(task.getStatus(), "running");
File file = Iterables.getOnlyElement(media.getFiles().getFiles());
assertEquals(file.getSize(), new Long(iso.length));
assertEquals(file.getBytesTransferred(), new Long(iso.length));
}
@Test(testName = "GET /media/{id}", dependsOnMethods = { "testCreateMedia" }, enabled = false)
@Test(testName = "GET /media/{id}", dependsOnMethods = { "testCreateMedia" })
public void testGetMedia() {
media = mediaClient.getMedia(media.getHref());
assertNotNull(media, String.format(OBJ_REQ_LIVE, MEDIA));
@ -154,7 +166,7 @@ public class MediaClientLiveTest extends BaseVCloudDirectorClientLiveTest {
}
@Test(testName = "GET /media/{id}/owner",
dependsOnMethods = { "testGetMedia" }, enabled = false)
dependsOnMethods = { "testGetMedia" })
public void testGetMediaOwner() {
Owner directOwner = mediaClient.getOwner(media.getHref());
assertEquals(owner, directOwner, String.format(GETTER_RETURNS_SAME_OBJ,
@ -169,7 +181,7 @@ public class MediaClientLiveTest extends BaseVCloudDirectorClientLiveTest {
}
@Test(testName = "POST /vdc/{id}/action/cloneMedia",
dependsOnMethods = { "testGetMediaOwner" }, enabled = false)
dependsOnMethods = { "testGetMediaOwner" })
public void testCloneMedia() {
oldMedia = media;
media = vdcClient.cloneMedia(vdcURI, CloneMediaParams.builder()
@ -219,7 +231,7 @@ public class MediaClientLiveTest extends BaseVCloudDirectorClientLiveTest {
}
@Test(testName = "PUT /media/{id}",
dependsOnMethods = { "testCloneMedia" }, enabled = false)
dependsOnMethods = { "testCloneMedia" })
public void testSetMedia() {
String oldName = media.getName();
String newName = "new "+oldName;
@ -249,7 +261,7 @@ public class MediaClientLiveTest extends BaseVCloudDirectorClientLiveTest {
}
@Test(testName = "GET /media/{id}/metadata",
dependsOnMethods = { "testGetMedia" }, enabled = false)
dependsOnMethods = { "testGetMedia" })
public void testGetMetadata() {
metadata = mediaClient.getMetadataClient().getMetadata(media.getHref());
// required for testing
@ -260,7 +272,7 @@ public class MediaClientLiveTest extends BaseVCloudDirectorClientLiveTest {
}
@Test(testName = "POST /media/{id}/metadata",
dependsOnMethods = { "testGetMetadata" }, enabled = false)
dependsOnMethods = { "testGetMetadata" })
public void testMergeMetadata() {
// test new
Set<MetadataEntry> inputEntries = ImmutableSet.of(MetadataEntry.builder().entry("testKey", "testValue").build());
@ -313,14 +325,14 @@ public class MediaClientLiveTest extends BaseVCloudDirectorClientLiveTest {
}
@Test(testName = "GET /media/{id}/metadata/{key}",
dependsOnMethods = { "testMergeMetadata" }, enabled = false)
dependsOnMethods = { "testMergeMetadata" })
public void testGetMetadataValue() {
metadataValue = mediaClient.getMetadataClient().getMetadataValue(media.getHref(), "key");
Checks.checkMetadataValueFor(MEDIA, metadataValue);
}
@Test(testName = "PUT /media/{id}/metadata/{key}",
dependsOnMethods = { "testGetMetadataValue" }, enabled = false)
dependsOnMethods = { "testGetMetadataValue" })
public void testSetMetadataValue() {
metadataEntryValue = "newValue";
MetadataValue newValue = MetadataValue.builder().value(metadataEntryValue).build();
@ -334,7 +346,7 @@ public class MediaClientLiveTest extends BaseVCloudDirectorClientLiveTest {
}
@Test(testName = "DELETE /media/{id}/metadata/{key}",
dependsOnMethods = { "testSetMetadataValue" }, enabled = false )
dependsOnMethods = { "testSetMetadataValue" } )
public void testDeleteMetadata() {
Task deleteMetadataEntry = mediaClient.getMetadataClient().deleteMetadataEntry(media.getHref(), "testKey");
Checks.checkTask(deleteMetadataEntry);
@ -371,7 +383,7 @@ public class MediaClientLiveTest extends BaseVCloudDirectorClientLiveTest {
}
@Test(testName = "DELETE /media/{id}",
dependsOnMethods = { "testDeleteMetadata" }, enabled = false )
dependsOnMethods = { "testDeleteMetadata" } )
public void testDeleteMedia() {
Task deleteMedia = mediaClient.deleteMedia(media.getHref());
Checks.checkTask(deleteMedia);