mirror of https://github.com/apache/jclouds.git
Merge branch 'master' of github.com:jclouds/jclouds into 1.5.x
* 'master' of github.com:jclouds/jclouds: (33 commits)
optimize imports
reset loginpassword/privatekey when explicitly set
revised tests that AdminAccess change recently broke
Issue 1028:vCloud Director 1.5: require x-vcloud-authorization header on vcloud api
Add SYSTEM scope from DMTF CIMI. FGCP provider needs it.
Issue-1020 Add full name option for AdminUser and UserAdd
Add missing @Override in TransientStorageStrategy
format and imports
Ensure that EventBus is a singleton
Introduce LocalAsyncBlobStore
Miscellaneous local blobstore cleanups
Prefer valueOf over explicit object creation
Move helper method to TransientStorageStrategy
Move copy(MutableBlobMetadata) to BlobStoreUtils
Cloudstack VirtualMachines can have negative cpuUsed values for some reason
removed dead code
corrected destroyNodes bug
Fixed compilation failures caused by 70fa74df1a
Remove encodeString() and encodeString(String)
Shuffle blobstore parameters to match superclass
...
This commit is contained in:
commit
954b5f914b
|
@ -1,7 +1,11 @@
|
||||||
jclouds
|
jclouds
|
||||||
======
|
======
|
||||||
jclouds is an open source library that helps you get started in the cloud and reuse your java and clojure development skills. Our api allows you freedom to use portable abstractions or cloud-specific features. We test support of 30 cloud providers and cloud software stacks, including Amazon, GoGrid, Ninefold, vCloud, OpenStack, and Azure.
|
jclouds allows provisioning and control of cloud resources, including blobstore
|
||||||
We offer several API abstractions as java and clojure libraries. The following are the most mature:
|
and compute, from Java and Clojure. Our API gives allows developers to use
|
||||||
|
both portable abstractions and cloud-specific features. We test support of 30
|
||||||
|
cloud providers and cloud software stacks, including Amazon, Azure, GoGrid,
|
||||||
|
Ninefold, OpenStack, and vCloud. jclouds is licensed under the Apache License,
|
||||||
|
Version 2.0
|
||||||
|
|
||||||
Features
|
Features
|
||||||
--------
|
--------
|
||||||
|
|
12
README.txt
12
README.txt
|
@ -1,11 +1,11 @@
|
||||||
Overview:
|
Overview:
|
||||||
|
|
||||||
jclouds is an open source library that helps you get started in the cloud
|
jclouds allows provisioning and control of cloud resources, including blobstore
|
||||||
and reuse your java and clojure development skills. Our api allows you to
|
and compute, from Java and Clojure. Our API gives allows developers to use
|
||||||
freedom to use portable abstractions or cloud-specific features. We have
|
both portable abstractions and cloud-specific features. We test support of 30
|
||||||
two abstractions at the moment: compute and blobstore. compute helps you
|
cloud providers and cloud software stacks, including Amazon, Azure, GoGrid,
|
||||||
bootstrap machines in the cloud. blobstore helps you manage key-value
|
Ninefold, OpenStack, and vCloud. jclouds is licensed under the Apache License,
|
||||||
data.
|
Version 2.0
|
||||||
|
|
||||||
our current version is 1.4.2
|
our current version is 1.4.2
|
||||||
our next maintenance version is 1.4.2-SNAPSHOT
|
our next maintenance version is 1.4.2-SNAPSHOT
|
||||||
|
|
|
@ -71,7 +71,7 @@ public class ParseAtmosErrorFromXmlContent implements HttpErrorHandler {
|
||||||
AtmosError error = null;
|
AtmosError error = null;
|
||||||
if (response.getPayload() != null) {
|
if (response.getPayload() != null) {
|
||||||
try {
|
try {
|
||||||
String content = Strings2.toStringAndClose(response.getPayload().getInput());
|
String content = Strings2.toString(response.getPayload());
|
||||||
if (content != null && content.indexOf('<') >= 0) {
|
if (content != null && content.indexOf('<') >= 0) {
|
||||||
error = utils.parseAtmosErrorFromContent(command, response, Strings2.toInputStream(content));
|
error = utils.parseAtmosErrorFromContent(command, response, Strings2.toInputStream(content));
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -72,7 +72,7 @@ public class ListOptions extends BaseHttpRequestOptions {
|
||||||
|
|
||||||
public Integer getLimit() {
|
public Integer getLimit() {
|
||||||
String maxresults = getFirstHeaderOrNull("x-emc-limit");
|
String maxresults = getFirstHeaderOrNull("x-emc-limit");
|
||||||
return (maxresults != null) ? new Integer(maxresults) : null;
|
return (maxresults != null) ? Integer.valueOf(maxresults) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Builder {
|
public static class Builder {
|
||||||
|
|
|
@ -239,19 +239,19 @@ public class AtmosClientLiveTest extends BaseBlobStoreIntegrationTest {
|
||||||
private static void verifyHeadObject(AtmosClient connection, String path, String metadataValue)
|
private static void verifyHeadObject(AtmosClient connection, String path, String metadataValue)
|
||||||
throws InterruptedException, ExecutionException, TimeoutException, IOException {
|
throws InterruptedException, ExecutionException, TimeoutException, IOException {
|
||||||
AtmosObject getBlob = connection.headFile(path);
|
AtmosObject getBlob = connection.headFile(path);
|
||||||
assertEquals(Strings2.toStringAndClose(getBlob.getPayload().getInput()), "");
|
assertEquals(Strings2.toString(getBlob.getPayload()), "");
|
||||||
verifyMetadata(metadataValue, getBlob);
|
verifyMetadata(metadataValue, getBlob);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void verifyObject(AtmosClient connection, String path, String compare, String metadataValue)
|
private static void verifyObject(AtmosClient connection, String path, String compare, String metadataValue)
|
||||||
throws InterruptedException, ExecutionException, TimeoutException, IOException {
|
throws InterruptedException, ExecutionException, TimeoutException, IOException {
|
||||||
AtmosObject getBlob = connection.readFile(path);
|
AtmosObject getBlob = connection.readFile(path);
|
||||||
assertEquals(Strings2.toStringAndClose(getBlob.getPayload().getInput()), compare);
|
assertEquals(Strings2.toString(getBlob.getPayload()), compare);
|
||||||
verifyMetadata(metadataValue, getBlob);
|
verifyMetadata(metadataValue, getBlob);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void verifyMetadata(String metadataValue, AtmosObject getBlob) {
|
private static void verifyMetadata(String metadataValue, AtmosObject getBlob) {
|
||||||
assertEquals(getBlob.getContentMetadata().getContentLength(), new Long(16));
|
assertEquals(getBlob.getContentMetadata().getContentLength(), Long.valueOf(16));
|
||||||
assert getBlob.getContentMetadata().getContentType().startsWith("text/plain");
|
assert getBlob.getContentMetadata().getContentType().startsWith("text/plain");
|
||||||
assertEquals(getBlob.getUserMetadata().getMetadata().get("Metadata"), metadataValue);
|
assertEquals(getBlob.getUserMetadata().getMetadata().get("Metadata"), metadataValue);
|
||||||
SystemMetadata md = getBlob.getSystemMetadata();
|
SystemMetadata md = getBlob.getSystemMetadata();
|
||||||
|
|
|
@ -43,7 +43,7 @@ import org.jclouds.atmos.domain.SystemMetadata;
|
||||||
import org.jclouds.atmos.domain.UserMetadata;
|
import org.jclouds.atmos.domain.UserMetadata;
|
||||||
import org.jclouds.atmos.options.ListOptions;
|
import org.jclouds.atmos.options.ListOptions;
|
||||||
import org.jclouds.atmos.options.PutOptions;
|
import org.jclouds.atmos.options.PutOptions;
|
||||||
import org.jclouds.blobstore.TransientAsyncBlobStore;
|
import org.jclouds.blobstore.LocalAsyncBlobStore;
|
||||||
import org.jclouds.blobstore.domain.Blob;
|
import org.jclouds.blobstore.domain.Blob;
|
||||||
import org.jclouds.blobstore.domain.BlobMetadata;
|
import org.jclouds.blobstore.domain.BlobMetadata;
|
||||||
import org.jclouds.blobstore.functions.HttpGetOptionsListToGetOptions;
|
import org.jclouds.blobstore.functions.HttpGetOptionsListToGetOptions;
|
||||||
|
@ -61,7 +61,7 @@ import com.google.common.util.concurrent.ListenableFuture;
|
||||||
*/
|
*/
|
||||||
public class StubAtmosAsyncClient implements AtmosAsyncClient {
|
public class StubAtmosAsyncClient implements AtmosAsyncClient {
|
||||||
private final HttpGetOptionsListToGetOptions httpGetOptionsConverter;
|
private final HttpGetOptionsListToGetOptions httpGetOptionsConverter;
|
||||||
private final TransientAsyncBlobStore blobStore;
|
private final LocalAsyncBlobStore blobStore;
|
||||||
private final AtmosObject.Factory objectProvider;
|
private final AtmosObject.Factory objectProvider;
|
||||||
private final ObjectToBlob object2Blob;
|
private final ObjectToBlob object2Blob;
|
||||||
private final BlobToObject blob2Object;
|
private final BlobToObject blob2Object;
|
||||||
|
@ -71,7 +71,7 @@ public class StubAtmosAsyncClient implements AtmosAsyncClient {
|
||||||
private final ExecutorService service;
|
private final ExecutorService service;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private StubAtmosAsyncClient(TransientAsyncBlobStore blobStore, AtmosObject.Factory objectProvider,
|
private StubAtmosAsyncClient(LocalAsyncBlobStore blobStore, AtmosObject.Factory objectProvider,
|
||||||
HttpGetOptionsListToGetOptions httpGetOptionsConverter, ObjectToBlob object2Blob, BlobToObject blob2Object,
|
HttpGetOptionsListToGetOptions httpGetOptionsConverter, ObjectToBlob object2Blob, BlobToObject blob2Object,
|
||||||
BlobMetadataToObject blob2ObjectInfo, ListOptionsToBlobStoreListOptions container2ContainerListOptions,
|
BlobMetadataToObject blob2ObjectInfo, ListOptionsToBlobStoreListOptions container2ContainerListOptions,
|
||||||
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService service,
|
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService service,
|
||||||
|
|
|
@ -85,7 +85,7 @@ public class ParseCloudLoadBalancersErrorFromHttpResponse implements HttpErrorHa
|
||||||
String parseErrorFromContentOrNull(HttpCommand command, HttpResponse response) {
|
String parseErrorFromContentOrNull(HttpCommand command, HttpResponse response) {
|
||||||
if (response.getPayload() != null) {
|
if (response.getPayload() != null) {
|
||||||
try {
|
try {
|
||||||
return Strings2.toStringAndClose(response.getPayload().getInput());
|
return Strings2.toString(response.getPayload());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
logger.warn(e, "exception reading error from response", response);
|
logger.warn(e, "exception reading error from response", response);
|
||||||
}
|
}
|
||||||
|
|
|
@ -136,7 +136,7 @@ public class LoadBalancerClientLiveTest extends BaseCloudLoadBalancersClientLive
|
||||||
assertEquals(lb.getRegion(), region);
|
assertEquals(lb.getRegion(), region);
|
||||||
assertEquals(lb.getName(), name);
|
assertEquals(lb.getName(), name);
|
||||||
assertEquals(lb.getProtocol(), "HTTP");
|
assertEquals(lb.getProtocol(), "HTTP");
|
||||||
assertEquals(lb.getPort(), new Integer(80));
|
assertEquals(lb.getPort(), Integer.valueOf(80));
|
||||||
assertEquals(Iterables.get(lb.getVirtualIPs(), 0).getType(), Type.PUBLIC);
|
assertEquals(Iterables.get(lb.getVirtualIPs(), 0).getType(), Type.PUBLIC);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -85,7 +85,7 @@ public class ParseCloudServersErrorFromHttpResponse implements HttpErrorHandler
|
||||||
String parseErrorFromContentOrNull(HttpCommand command, HttpResponse response) {
|
String parseErrorFromContentOrNull(HttpCommand command, HttpResponse response) {
|
||||||
if (response.getPayload() != null) {
|
if (response.getPayload() != null) {
|
||||||
try {
|
try {
|
||||||
return Strings2.toStringAndClose(response.getPayload().getInput());
|
return Strings2.toString(response.getPayload());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
logger.warn(e, "exception reading error from response", response);
|
logger.warn(e, "exception reading error from response", response);
|
||||||
}
|
}
|
||||||
|
|
|
@ -344,8 +344,8 @@ public class CloudServersClientLiveTest extends BaseComputeServiceContextLiveTes
|
||||||
assertNotNull(server.getHostId());
|
assertNotNull(server.getHostId());
|
||||||
assertEquals(server.getStatus(), ServerStatus.ACTIVE);
|
assertEquals(server.getStatus(), ServerStatus.ACTIVE);
|
||||||
assert server.getProgress() >= 0 : "newDetails.getProgress()" + server.getProgress();
|
assert server.getProgress() >= 0 : "newDetails.getProgress()" + server.getProgress();
|
||||||
assertEquals(new Integer(14362), server.getImageId());
|
assertEquals(Integer.valueOf(14362), server.getImageId());
|
||||||
assertEquals(new Integer(1), server.getFlavorId());
|
assertEquals(Integer.valueOf(1), server.getFlavorId());
|
||||||
assertNotNull(server.getAddresses());
|
assertNotNull(server.getAddresses());
|
||||||
// listAddresses tests..
|
// listAddresses tests..
|
||||||
assertEquals(client.getAddresses(serverId), server.getAddresses());
|
assertEquals(client.getAddresses(serverId), server.getAddresses());
|
||||||
|
@ -383,7 +383,7 @@ public class CloudServersClientLiveTest extends BaseComputeServiceContextLiveTes
|
||||||
try {
|
try {
|
||||||
client.connect();
|
client.connect();
|
||||||
Payload etcPasswd = client.get("/etc/jclouds.txt");
|
Payload etcPasswd = client.get("/etc/jclouds.txt");
|
||||||
String etcPasswdContents = Strings2.toStringAndClose(etcPasswd.getInput());
|
String etcPasswdContents = Strings2.toString(etcPasswd);
|
||||||
assertEquals("rackspace", etcPasswdContents.trim());
|
assertEquals("rackspace", etcPasswdContents.trim());
|
||||||
} finally {
|
} finally {
|
||||||
if (client != null)
|
if (client != null)
|
||||||
|
@ -445,7 +445,7 @@ public class CloudServersClientLiveTest extends BaseComputeServiceContextLiveTes
|
||||||
blockUntilServerActive(serverId2);
|
blockUntilServerActive(serverId2);
|
||||||
assertIpConfigured(server, adminPass2);
|
assertIpConfigured(server, adminPass2);
|
||||||
assert server.getAddresses().getPublicAddresses().contains(ip) : server.getAddresses() + " doesn't contain " + ip;
|
assert server.getAddresses().getPublicAddresses().contains(ip) : server.getAddresses() + " doesn't contain " + ip;
|
||||||
assertEquals(server.getSharedIpGroupId(), new Integer(sharedIpGroupId));
|
assertEquals(server.getSharedIpGroupId(), Integer.valueOf(sharedIpGroupId));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void assertIpConfigured(Server server, String password) {
|
private void assertIpConfigured(Server server, String password) {
|
||||||
|
@ -518,7 +518,7 @@ public class CloudServersClientLiveTest extends BaseComputeServiceContextLiveTes
|
||||||
public void testCreateImage() throws Exception {
|
public void testCreateImage() throws Exception {
|
||||||
Image image = client.createImageFromServer("hoofie", serverId);
|
Image image = client.createImageFromServer("hoofie", serverId);
|
||||||
assertEquals("hoofie", image.getName());
|
assertEquals("hoofie", image.getName());
|
||||||
assertEquals(new Integer(serverId), image.getServerId());
|
assertEquals(Integer.valueOf(serverId), image.getServerId());
|
||||||
imageId = image.getId();
|
imageId = image.getId();
|
||||||
blockUntilImageActive(imageId);
|
blockUntilImageActive(imageId);
|
||||||
}
|
}
|
||||||
|
@ -528,7 +528,7 @@ public class CloudServersClientLiveTest extends BaseComputeServiceContextLiveTes
|
||||||
client.rebuildServer(serverId, new RebuildServerOptions().withImage(imageId));
|
client.rebuildServer(serverId, new RebuildServerOptions().withImage(imageId));
|
||||||
blockUntilServerActive(serverId);
|
blockUntilServerActive(serverId);
|
||||||
// issue Web Hosting #119580 imageId comes back incorrect after rebuild
|
// issue Web Hosting #119580 imageId comes back incorrect after rebuild
|
||||||
assert !new Integer(imageId).equals(client.getServer(serverId).getImageId());
|
assert !Integer.valueOf(imageId).equals(client.getServer(serverId).getImageId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(timeOut = 10 * 60 * 1000, dependsOnMethods = "testRebuildServer")
|
@Test(timeOut = 10 * 60 * 1000, dependsOnMethods = "testRebuildServer")
|
||||||
|
@ -549,7 +549,7 @@ public class CloudServersClientLiveTest extends BaseComputeServiceContextLiveTes
|
||||||
blockUntilServerVerifyResize(serverId);
|
blockUntilServerVerifyResize(serverId);
|
||||||
client.revertResizeServer(serverId);
|
client.revertResizeServer(serverId);
|
||||||
blockUntilServerActive(serverId);
|
blockUntilServerActive(serverId);
|
||||||
assertEquals(new Integer(1), client.getServer(serverId).getFlavorId());
|
assertEquals(Integer.valueOf(1), client.getServer(serverId).getFlavorId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(timeOut = 10 * 60 * 1000, dependsOnMethods = "testRebootSoft")
|
@Test(timeOut = 10 * 60 * 1000, dependsOnMethods = "testRebootSoft")
|
||||||
|
@ -558,7 +558,7 @@ public class CloudServersClientLiveTest extends BaseComputeServiceContextLiveTes
|
||||||
blockUntilServerVerifyResize(serverId2);
|
blockUntilServerVerifyResize(serverId2);
|
||||||
client.confirmResizeServer(serverId2);
|
client.confirmResizeServer(serverId2);
|
||||||
blockUntilServerActive(serverId2);
|
blockUntilServerActive(serverId2);
|
||||||
assertEquals(new Integer(2), client.getServer(serverId2).getFlavorId());
|
assertEquals(Integer.valueOf(2), client.getServer(serverId2).getFlavorId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(timeOut = 10 * 60 * 1000, dependsOnMethods = { "testRebootSoft", "testRevertResize", "testConfirmResize" })
|
@Test(timeOut = 10 * 60 * 1000, dependsOnMethods = { "testRebootSoft", "testRevertResize", "testConfirmResize" })
|
||||||
|
|
|
@ -67,13 +67,13 @@ public class ParseFlavorListFromJsonResponseTest {
|
||||||
List<Flavor> response = parser.apply(HttpResponse.builder().statusCode(200).message("ok").payload(is).build());
|
List<Flavor> response = parser.apply(HttpResponse.builder().statusCode(200).message("ok").payload(is).build());
|
||||||
assertEquals(response.get(0).getId(), 1);
|
assertEquals(response.get(0).getId(), 1);
|
||||||
assertEquals(response.get(0).getName(), "256 MB Server");
|
assertEquals(response.get(0).getName(), "256 MB Server");
|
||||||
assertEquals(response.get(0).getDisk(), new Integer(10));
|
assertEquals(response.get(0).getDisk(), Integer.valueOf(10));
|
||||||
assertEquals(response.get(0).getRam(), new Integer(256));
|
assertEquals(response.get(0).getRam(), Integer.valueOf(256));
|
||||||
|
|
||||||
assertEquals(response.get(1).getId(), 2);
|
assertEquals(response.get(1).getId(), 2);
|
||||||
assertEquals(response.get(1).getName(), "512 MB Server");
|
assertEquals(response.get(1).getName(), "512 MB Server");
|
||||||
assertEquals(response.get(1).getDisk(), new Integer(20));
|
assertEquals(response.get(1).getDisk(), Integer.valueOf(20));
|
||||||
assertEquals(response.get(1).getRam(), new Integer(512));
|
assertEquals(response.get(1).getRam(), Integer.valueOf(512));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -63,8 +63,8 @@ public class ParseImageFromJsonResponseTest {
|
||||||
assertEquals(response.getId(), 2);
|
assertEquals(response.getId(), 2);
|
||||||
assertEquals(response.getName(), "CentOS 5.2");
|
assertEquals(response.getName(), "CentOS 5.2");
|
||||||
assertEquals(response.getCreated(), dateService.iso8601SecondsDateParse("2010-08-10T12:00:00Z"));
|
assertEquals(response.getCreated(), dateService.iso8601SecondsDateParse("2010-08-10T12:00:00Z"));
|
||||||
assertEquals(response.getProgress(), new Integer(80));
|
assertEquals(response.getProgress(), Integer.valueOf(80));
|
||||||
assertEquals(response.getServerId(), new Integer(12));
|
assertEquals(response.getServerId(), Integer.valueOf(12));
|
||||||
assertEquals(response.getStatus(), ImageStatus.SAVING);
|
assertEquals(response.getStatus(), ImageStatus.SAVING);
|
||||||
assertEquals(response.getUpdated(), dateService.iso8601SecondsDateParse(("2010-10-10T12:00:00Z")));
|
assertEquals(response.getUpdated(), dateService.iso8601SecondsDateParse(("2010-10-10T12:00:00Z")));
|
||||||
|
|
||||||
|
|
|
@ -91,8 +91,8 @@ public class ParseImageListFromJsonResponseTest {
|
||||||
assertEquals(response.get(1).getName(), "My Server Backup");
|
assertEquals(response.get(1).getName(), "My Server Backup");
|
||||||
assertEquals(response.get(1).getCreated(), dateService.iso8601SecondsDateParse("2009-07-07T09:56:16-05:00"));
|
assertEquals(response.get(1).getCreated(), dateService.iso8601SecondsDateParse("2009-07-07T09:56:16-05:00"));
|
||||||
;
|
;
|
||||||
assertEquals(response.get(1).getProgress(), new Integer(80));
|
assertEquals(response.get(1).getProgress(), Integer.valueOf(80));
|
||||||
assertEquals(response.get(1).getServerId(), new Integer(12));
|
assertEquals(response.get(1).getServerId(), Integer.valueOf(12));
|
||||||
assertEquals(response.get(1).getStatus(), ImageStatus.SAVING);
|
assertEquals(response.get(1).getStatus(), ImageStatus.SAVING);
|
||||||
assertEquals(response.get(1).getUpdated(), dateService.iso8601SecondsDateParse("2010-10-10T12:00:00Z"));
|
assertEquals(response.get(1).getUpdated(), dateService.iso8601SecondsDateParse("2010-10-10T12:00:00Z"));
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,11 +52,11 @@ public class ParseServerFromJsonResponseTest {
|
||||||
|
|
||||||
assertEquals(response.getId(), 1234);
|
assertEquals(response.getId(), 1234);
|
||||||
assertEquals(response.getName(), "sample-server");
|
assertEquals(response.getName(), "sample-server");
|
||||||
assertEquals(response.getImageId(), new Integer(2));
|
assertEquals(response.getImageId(), Integer.valueOf(2));
|
||||||
assertEquals(response.getFlavorId(), new Integer(1));
|
assertEquals(response.getFlavorId(), Integer.valueOf(1));
|
||||||
assertEquals(response.getHostId(), "e4d909c290d0fb1ca068ffaddf22cbd0");
|
assertEquals(response.getHostId(), "e4d909c290d0fb1ca068ffaddf22cbd0");
|
||||||
assertEquals(response.getStatus(), ServerStatus.BUILD);
|
assertEquals(response.getStatus(), ServerStatus.BUILD);
|
||||||
assertEquals(response.getProgress(), new Integer(60));
|
assertEquals(response.getProgress(), Integer.valueOf(60));
|
||||||
List<String> publicAddresses = Lists.newArrayList("67.23.10.132", "67.23.10.131");
|
List<String> publicAddresses = Lists.newArrayList("67.23.10.132", "67.23.10.131");
|
||||||
List<String> privateAddresses = Lists.newArrayList("10.176.42.16");
|
List<String> privateAddresses = Lists.newArrayList("10.176.42.16");
|
||||||
Addresses addresses1 = new Addresses();
|
Addresses addresses1 = new Addresses();
|
||||||
|
|
|
@ -73,11 +73,11 @@ public class ParseServerListFromJsonResponseTest {
|
||||||
|
|
||||||
assertEquals(response.get(0).getId(), 1234);
|
assertEquals(response.get(0).getId(), 1234);
|
||||||
assertEquals(response.get(0).getName(), "sample-server");
|
assertEquals(response.get(0).getName(), "sample-server");
|
||||||
assertEquals(response.get(0).getImageId(), new Integer(2));
|
assertEquals(response.get(0).getImageId(), Integer.valueOf(2));
|
||||||
assertEquals(response.get(0).getFlavorId(), new Integer(1));
|
assertEquals(response.get(0).getFlavorId(), Integer.valueOf(1));
|
||||||
assertEquals(response.get(0).getHostId(), "e4d909c290d0fb1ca068ffaddf22cbd0");
|
assertEquals(response.get(0).getHostId(), "e4d909c290d0fb1ca068ffaddf22cbd0");
|
||||||
assertEquals(response.get(0).getStatus(), ServerStatus.BUILD);
|
assertEquals(response.get(0).getStatus(), ServerStatus.BUILD);
|
||||||
assertEquals(response.get(0).getProgress(), new Integer(60));
|
assertEquals(response.get(0).getProgress(), Integer.valueOf(60));
|
||||||
List<String> publicAddresses = Lists.newArrayList("67.23.10.132", "67.23.10.131");
|
List<String> publicAddresses = Lists.newArrayList("67.23.10.132", "67.23.10.131");
|
||||||
List<String> privateAddresses = Lists.newArrayList("10.176.42.16");
|
List<String> privateAddresses = Lists.newArrayList("10.176.42.16");
|
||||||
Addresses addresses1 = new Addresses();
|
Addresses addresses1 = new Addresses();
|
||||||
|
@ -87,8 +87,8 @@ public class ParseServerListFromJsonResponseTest {
|
||||||
assertEquals(response.get(0).getMetadata(), ImmutableMap.of("Server Label", "Web Head 1", "Image Version", "2.1"));
|
assertEquals(response.get(0).getMetadata(), ImmutableMap.of("Server Label", "Web Head 1", "Image Version", "2.1"));
|
||||||
assertEquals(response.get(1).getId(), 5678);
|
assertEquals(response.get(1).getId(), 5678);
|
||||||
assertEquals(response.get(1).getName(), "sample-server2");
|
assertEquals(response.get(1).getName(), "sample-server2");
|
||||||
assertEquals(response.get(1).getImageId(), new Integer(2));
|
assertEquals(response.get(1).getImageId(), Integer.valueOf(2));
|
||||||
assertEquals(response.get(1).getFlavorId(), new Integer(1));
|
assertEquals(response.get(1).getFlavorId(), Integer.valueOf(1));
|
||||||
assertEquals(response.get(1).getHostId(), "9e107d9d372bb6826bd81d3542a419d6");
|
assertEquals(response.get(1).getHostId(), "9e107d9d372bb6826bd81d3542a419d6");
|
||||||
assertEquals(response.get(1).getStatus(), ServerStatus.ACTIVE);
|
assertEquals(response.get(1).getStatus(), ServerStatus.ACTIVE);
|
||||||
assertEquals(response.get(1).getProgress(), null);
|
assertEquals(response.get(1).getProgress(), null);
|
||||||
|
|
|
@ -69,7 +69,7 @@ public class MapToDriveInfo implements Function<Map<String, String>, DriveInfo>
|
||||||
if (from.containsKey("readers"))
|
if (from.containsKey("readers"))
|
||||||
builder.readers(Splitter.on(' ').split(from.get("readers")));
|
builder.readers(Splitter.on(' ').split(from.get("readers")));
|
||||||
if (from.containsKey("size"))
|
if (from.containsKey("size"))
|
||||||
builder.size(new Long(from.get("size")));
|
builder.size(Long.valueOf(from.get("size")));
|
||||||
Map<String, String> metadata = Maps.newLinkedHashMap();
|
Map<String, String> metadata = Maps.newLinkedHashMap();
|
||||||
for (Entry<String, String> entry : from.entrySet()) {
|
for (Entry<String, String> entry : from.entrySet()) {
|
||||||
if (entry.getKey().startsWith("user:"))
|
if (entry.getKey().startsWith("user:"))
|
||||||
|
@ -78,7 +78,7 @@ public class MapToDriveInfo implements Function<Map<String, String>, DriveInfo>
|
||||||
if (from.containsKey("use"))
|
if (from.containsKey("use"))
|
||||||
builder.use(Splitter.on(' ').split(from.get("use")));
|
builder.use(Splitter.on(' ').split(from.get("use")));
|
||||||
if (from.containsKey("bits"))
|
if (from.containsKey("bits"))
|
||||||
builder.bits(new Integer(from.get("bits")));
|
builder.bits(Integer.valueOf(from.get("bits")));
|
||||||
if (from.containsKey("url"))
|
if (from.containsKey("url"))
|
||||||
builder.url(URI.create(from.get("url")));
|
builder.url(URI.create(from.get("url")));
|
||||||
builder.encryptionKey(from.get("encryption:key"));
|
builder.encryptionKey(from.get("encryption:key"));
|
||||||
|
@ -88,9 +88,9 @@ public class MapToDriveInfo implements Function<Map<String, String>, DriveInfo>
|
||||||
if (from.containsKey("drive_type"))
|
if (from.containsKey("drive_type"))
|
||||||
builder.driveType(Splitter.on(',').split(from.get("drive_type")));
|
builder.driveType(Splitter.on(',').split(from.get("drive_type")));
|
||||||
if (from.containsKey("autoexpanding"))
|
if (from.containsKey("autoexpanding"))
|
||||||
builder.autoexpanding(new Boolean(from.get("autoexpanding")));
|
builder.autoexpanding(Boolean.valueOf(from.get("autoexpanding")));
|
||||||
if (from.containsKey("free"))
|
if (from.containsKey("free"))
|
||||||
builder.free(new Boolean(from.get("free")));
|
builder.free(Boolean.valueOf(from.get("free")));
|
||||||
if (from.containsKey("type"))
|
if (from.containsKey("type"))
|
||||||
builder.type(DriveType.fromValue(from.get("type")));
|
builder.type(DriveType.fromValue(from.get("type")));
|
||||||
try {
|
try {
|
||||||
|
@ -104,13 +104,13 @@ public class MapToDriveInfo implements Function<Map<String, String>, DriveInfo>
|
||||||
protected DriveMetrics buildMetrics(Map<String, String> from) {
|
protected DriveMetrics buildMetrics(Map<String, String> from) {
|
||||||
DriveMetrics.Builder metricsBuilder = new DriveMetrics.Builder();
|
DriveMetrics.Builder metricsBuilder = new DriveMetrics.Builder();
|
||||||
if (from.containsKey("read:bytes"))
|
if (from.containsKey("read:bytes"))
|
||||||
metricsBuilder.readBytes(new Long(from.get("read:bytes")));
|
metricsBuilder.readBytes(Long.valueOf(from.get("read:bytes")));
|
||||||
if (from.containsKey("read:requests"))
|
if (from.containsKey("read:requests"))
|
||||||
metricsBuilder.readRequests(new Long(from.get("read:requests")));
|
metricsBuilder.readRequests(Long.valueOf(from.get("read:requests")));
|
||||||
if (from.containsKey("write:bytes"))
|
if (from.containsKey("write:bytes"))
|
||||||
metricsBuilder.writeBytes(new Long(from.get("write:bytes")));
|
metricsBuilder.writeBytes(Long.valueOf(from.get("write:bytes")));
|
||||||
if (from.containsKey("write:requests"))
|
if (from.containsKey("write:requests"))
|
||||||
metricsBuilder.writeRequests(new Long(from.get("write:requests")));
|
metricsBuilder.writeRequests(Long.valueOf(from.get("write:requests")));
|
||||||
return metricsBuilder.build();
|
return metricsBuilder.build();
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -74,13 +74,13 @@ public class MapToDriveMetrics implements Function<Map<String, String>, Map<Stri
|
||||||
protected DriveMetrics buildMetrics(String key, Map<String, String> from) {
|
protected DriveMetrics buildMetrics(String key, Map<String, String> from) {
|
||||||
DriveMetrics.Builder builder = new DriveMetrics.Builder();
|
DriveMetrics.Builder builder = new DriveMetrics.Builder();
|
||||||
if (from.containsKey(key + ":read:bytes"))
|
if (from.containsKey(key + ":read:bytes"))
|
||||||
builder.readBytes(new Long(from.get(key + ":read:bytes")));
|
builder.readBytes(Long.valueOf(from.get(key + ":read:bytes")));
|
||||||
if (from.containsKey(key + ":read:requests"))
|
if (from.containsKey(key + ":read:requests"))
|
||||||
builder.readRequests(new Long(from.get(key + ":read:requests")));
|
builder.readRequests(Long.valueOf(from.get(key + ":read:requests")));
|
||||||
if (from.containsKey(key + ":write:bytes"))
|
if (from.containsKey(key + ":write:bytes"))
|
||||||
builder.writeBytes(new Long(from.get(key + ":write:bytes")));
|
builder.writeBytes(Long.valueOf(from.get(key + ":write:bytes")));
|
||||||
if (from.containsKey(key + ":write:requests"))
|
if (from.containsKey(key + ":write:requests"))
|
||||||
builder.writeRequests(new Long(from.get(key + ":write:requests")));
|
builder.writeRequests(Long.valueOf(from.get(key + ":write:requests")));
|
||||||
return builder.build();
|
return builder.build();
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -68,12 +68,12 @@ public class MapToServerInfo implements Function<Map<String, String>, ServerInfo
|
||||||
if (from.containsKey("status"))
|
if (from.containsKey("status"))
|
||||||
builder.status(ServerStatus.fromValue(from.get("status")));
|
builder.status(ServerStatus.fromValue(from.get("status")));
|
||||||
if (from.containsKey("smp") && !"auto".equals(from.get("smp")))
|
if (from.containsKey("smp") && !"auto".equals(from.get("smp")))
|
||||||
builder.smp(new Integer(from.get("smp")));
|
builder.smp(Integer.valueOf(from.get("smp")));
|
||||||
builder.cpu(Integer.parseInt(from.get("cpu")));
|
builder.cpu(Integer.parseInt(from.get("cpu")));
|
||||||
builder.mem(Integer.parseInt(from.get("mem")));
|
builder.mem(Integer.parseInt(from.get("mem")));
|
||||||
builder.user(from.get("user"));
|
builder.user(from.get("user"));
|
||||||
if (from.containsKey("started"))
|
if (from.containsKey("started"))
|
||||||
builder.started(new Date(new Long(from.get("started"))));
|
builder.started(new Date(Long.valueOf(from.get("started"))));
|
||||||
builder.uuid(from.get("server"));
|
builder.uuid(from.get("server"));
|
||||||
builder.vnc(new VNC(from.get("vnc:ip"), from.get("vnc:password"), from.containsKey("vnc:tls")
|
builder.vnc(new VNC(from.get("vnc:ip"), from.get("vnc:password"), from.containsKey("vnc:tls")
|
||||||
&& Boolean.valueOf(from.get("vnc:tls"))));
|
&& Boolean.valueOf(from.get("vnc:tls"))));
|
||||||
|
|
|
@ -44,13 +44,13 @@ public class MapToServerMetrics implements Function<Map<String, String>, ServerM
|
||||||
public ServerMetrics apply(Map<String, String> from) {
|
public ServerMetrics apply(Map<String, String> from) {
|
||||||
ServerMetrics.Builder metricsBuilder = new ServerMetrics.Builder();
|
ServerMetrics.Builder metricsBuilder = new ServerMetrics.Builder();
|
||||||
if (from.containsKey("tx:packets"))
|
if (from.containsKey("tx:packets"))
|
||||||
metricsBuilder.txPackets(new Long(from.get("tx:packets")));
|
metricsBuilder.txPackets(Long.valueOf(from.get("tx:packets")));
|
||||||
if (from.containsKey("tx"))
|
if (from.containsKey("tx"))
|
||||||
metricsBuilder.tx(new Long(from.get("tx")));
|
metricsBuilder.tx(Long.valueOf(from.get("tx")));
|
||||||
if (from.containsKey("rx:packets"))
|
if (from.containsKey("rx:packets"))
|
||||||
metricsBuilder.rxPackets(new Long(from.get("rx:packets")));
|
metricsBuilder.rxPackets(Long.valueOf(from.get("rx:packets")));
|
||||||
if (from.containsKey("rx"))
|
if (from.containsKey("rx"))
|
||||||
metricsBuilder.rx(new Long(from.get("rx")));
|
metricsBuilder.rx(Long.valueOf(from.get("rx")));
|
||||||
metricsBuilder.driveMetrics(mapToDriveMetrics.apply(from));
|
metricsBuilder.driveMetrics(mapToDriveMetrics.apply(from));
|
||||||
|
|
||||||
ServerMetrics metrics = metricsBuilder.build();
|
ServerMetrics metrics = metricsBuilder.build();
|
||||||
|
|
|
@ -94,7 +94,7 @@ public class CloudSigmaErrorHandler implements HttpErrorHandler {
|
||||||
if (response.getPayload() == null)
|
if (response.getPayload() == null)
|
||||||
return null;
|
return null;
|
||||||
try {
|
try {
|
||||||
return Strings2.toStringAndClose(response.getPayload().getInput());
|
return Strings2.toString(response.getPayload());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
} finally {
|
} finally {
|
||||||
|
|
|
@ -103,7 +103,7 @@ public class Account extends ForwardingSet<User> {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Type fromValue(String type) {
|
public static Type fromValue(String type) {
|
||||||
Integer code = new Integer(checkNotNull(type, "type"));
|
Integer code = Integer.valueOf(checkNotNull(type, "type"));
|
||||||
return INDEX.containsKey(code) ? INDEX.get(code) : UNRECOGNIZED;
|
return INDEX.containsKey(code) ? INDEX.get(code) : UNRECOGNIZED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -473,7 +473,7 @@ public class Account extends ForwardingSet<User> {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Long toLongNullIfUnlimited(String in) {
|
private static Long toLongNullIfUnlimited(String in) {
|
||||||
return in == null || "Unlimited".equals(in) ? null : new Long(in);
|
return in == null || "Unlimited".equals(in) ? null : Long.valueOf(in);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Account(String id, @Nullable Account.Type type, @Nullable String networkDomain, @Nullable String domain,
|
protected Account(String id, @Nullable Account.Type type, @Nullable String networkDomain, @Nullable String domain,
|
||||||
|
|
|
@ -75,7 +75,7 @@ public class Capacity implements Comparable<Capacity> {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Type fromValue(String type) {
|
public static Type fromValue(String type) {
|
||||||
Integer code = new Integer(checkNotNull(type, "type"));
|
Integer code = Integer.valueOf(checkNotNull(type, "type"));
|
||||||
return INDEX.containsKey(code) ? INDEX.get(code) : UNRECOGNIZED;
|
return INDEX.containsKey(code) ? INDEX.get(code) : UNRECOGNIZED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -91,7 +91,7 @@ public class ResourceLimit {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ResourceType fromValue(String resourceType) {
|
public static ResourceType fromValue(String resourceType) {
|
||||||
Integer code = new Integer(checkNotNull(resourceType, "resourcetype"));
|
Integer code = Integer.valueOf(checkNotNull(resourceType, "resourcetype"));
|
||||||
return INDEX.containsKey(code) ? INDEX.get(code) : UNRECOGNIZED;
|
return INDEX.containsKey(code) ? INDEX.get(code) : UNRECOGNIZED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -80,7 +80,7 @@ public class UsageRecord {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static UsageType fromValue(String usageType) {
|
public static UsageType fromValue(String usageType) {
|
||||||
Integer code = new Integer(checkNotNull(usageType, "usageType"));
|
Integer code = Integer.valueOf(checkNotNull(usageType, "usageType"));
|
||||||
return INDEX.containsKey(code) ? INDEX.get(code) : UNRECOGNIZED;
|
return INDEX.containsKey(code) ? INDEX.get(code) : UNRECOGNIZED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -588,7 +588,7 @@ public class VirtualMachine {
|
||||||
@Nullable VirtualMachine.State state, @Nullable String templateDisplayText, @Nullable String templateId,
|
@Nullable VirtualMachine.State state, @Nullable String templateDisplayText, @Nullable String templateId,
|
||||||
@Nullable String templateName, @Nullable String zoneId, @Nullable String zoneName, @Nullable Set<NIC> nics,
|
@Nullable String templateName, @Nullable String zoneId, @Nullable String zoneName, @Nullable Set<NIC> nics,
|
||||||
@Nullable String hypervisor, @Nullable Set<SecurityGroup> securityGroups) {
|
@Nullable String hypervisor, @Nullable Set<SecurityGroup> securityGroups) {
|
||||||
Preconditions.checkArgument(Strings.isNullOrEmpty(cpuUsed) || cpuUsed.matches("^[0-9\\.]+%$"), "cpuUsed value should be a decimal number followed by %");
|
Preconditions.checkArgument(Strings.isNullOrEmpty(cpuUsed) || cpuUsed.matches("^[0-9\\.\\-]+%$"), "cpuUsed value should be a decimal number followed by %");
|
||||||
this.id = checkNotNull(id, "id");
|
this.id = checkNotNull(id, "id");
|
||||||
this.account = account;
|
this.account = account;
|
||||||
this.cpuCount = cpuCount;
|
this.cpuCount = cpuCount;
|
||||||
|
|
|
@ -108,7 +108,7 @@ public class Volume {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Type fromValue(String resourceType) {
|
public static Type fromValue(String resourceType) {
|
||||||
Integer code = new Integer(checkNotNull(resourceType, "resourcetype"));
|
Integer code = Integer.valueOf(checkNotNull(resourceType, "resourcetype"));
|
||||||
return INDEX.containsKey(code) ? INDEX.get(code) : UNRECOGNIZED;
|
return INDEX.containsKey(code) ? INDEX.get(code) : UNRECOGNIZED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -92,7 +92,7 @@ public class CloudStackErrorHandler implements HttpErrorHandler {
|
||||||
if (response.getPayload() == null)
|
if (response.getPayload() == null)
|
||||||
return null;
|
return null;
|
||||||
try {
|
try {
|
||||||
return Strings2.toStringAndClose(response.getPayload().getInput());
|
return Strings2.toString(response.getPayload());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
} finally {
|
} finally {
|
||||||
|
|
|
@ -87,7 +87,7 @@ public class DeltacloudErrorHandler implements HttpErrorHandler {
|
||||||
if (response.getPayload() == null)
|
if (response.getPayload() == null)
|
||||||
return null;
|
return null;
|
||||||
try {
|
try {
|
||||||
return Strings2.toStringAndClose(response.getPayload().getInput());
|
return Strings2.toString(response.getPayload());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
} finally {
|
} finally {
|
||||||
|
|
|
@ -87,7 +87,7 @@ public class HardwarePropertyHandler extends ParseSax.HandlerWithResult<Hardware
|
||||||
if (DOUBLE.matcher(in).matches())
|
if (DOUBLE.matcher(in).matches())
|
||||||
return new Double(in);
|
return new Double(in);
|
||||||
else if (LONG.matcher(in).matches())
|
else if (LONG.matcher(in).matches())
|
||||||
return new Long(in);
|
return Long.valueOf(in);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -65,13 +65,13 @@ public class HardwareProfileHandlerTest {
|
||||||
HardwareProfile expects = new HardwareProfile(
|
HardwareProfile expects = new HardwareProfile(
|
||||||
URI.create("http://localhost:3001/api/hardware_profiles/m1-xlarge"), "m1-xlarge", "m1-xlarge",
|
URI.create("http://localhost:3001/api/hardware_profiles/m1-xlarge"), "m1-xlarge", "m1-xlarge",
|
||||||
ImmutableSet.<HardwareProperty> of(
|
ImmutableSet.<HardwareProperty> of(
|
||||||
new FixedHardwareProperty("cpu", "count", new Long(4)),
|
new FixedHardwareProperty("cpu", "count", Long.valueOf(4)),
|
||||||
new RangeHardwareProperty("memory", "MB", new Long(12288), new HardwareParameter(URI
|
new RangeHardwareProperty("memory", "MB", Long.valueOf(12288), new HardwareParameter(URI
|
||||||
.create("http://localhost:3001/api/instances"), "post", "hwp_memory", "create"),
|
.create("http://localhost:3001/api/instances"), "post", "hwp_memory", "create"),
|
||||||
new Long(12288), new Long(32768)),
|
Long.valueOf(12288), Long.valueOf(32768)),
|
||||||
new EnumHardwareProperty("storage", "GB", new Long(1024), new HardwareParameter(URI
|
new EnumHardwareProperty("storage", "GB", Long.valueOf(1024), new HardwareParameter(URI
|
||||||
.create("http://localhost:3001/api/instances"), "post", "hwp_storage", "create"),
|
.create("http://localhost:3001/api/instances"), "post", "hwp_storage", "create"),
|
||||||
ImmutableSet.<Object> of(new Long(1024), new Long(2048), new Long(4096))),
|
ImmutableSet.<Object> of(Long.valueOf(1024), Long.valueOf(2048), Long.valueOf(4096))),
|
||||||
new FixedHardwareProperty("architecture", "label", "x86_64"))
|
new FixedHardwareProperty("architecture", "label", "x86_64"))
|
||||||
);
|
);
|
||||||
assertEquals(parseHardwareProfile(), expects);
|
assertEquals(parseHardwareProfile(), expects);
|
||||||
|
|
|
@ -50,27 +50,27 @@ public class HardwareProfilesHandlerTest extends BaseHandlerTest {
|
||||||
Set<? extends HardwareProfile> expects = ImmutableSet.of(
|
Set<? extends HardwareProfile> expects = ImmutableSet.of(
|
||||||
new HardwareProfile(URI.create("http://localhost:3001/api/hardware_profiles/m1-small"), "m1-small",
|
new HardwareProfile(URI.create("http://localhost:3001/api/hardware_profiles/m1-small"), "m1-small",
|
||||||
"m1-small", ImmutableSet.<HardwareProperty> of(
|
"m1-small", ImmutableSet.<HardwareProperty> of(
|
||||||
new FixedHardwareProperty("cpu", "count", new Long(1)), new FixedHardwareProperty("memory",
|
new FixedHardwareProperty("cpu", "count", Long.valueOf(1)), new FixedHardwareProperty("memory",
|
||||||
"MB", new Double(1740.8)), new FixedHardwareProperty("storage", "GB", new Long(160)),
|
"MB", new Double(1740.8)), new FixedHardwareProperty("storage", "GB", Long.valueOf(160)),
|
||||||
new FixedHardwareProperty("architecture", "label", "i386"))),
|
new FixedHardwareProperty("architecture", "label", "i386"))),
|
||||||
new HardwareProfile(URI.create("http://localhost:3001/api/hardware_profiles/m1-large"), "m1-large",
|
new HardwareProfile(URI.create("http://localhost:3001/api/hardware_profiles/m1-large"), "m1-large",
|
||||||
"m1-large", ImmutableSet.<HardwareProperty> of(
|
"m1-large", ImmutableSet.<HardwareProperty> of(
|
||||||
new FixedHardwareProperty("cpu", "count", new Long(2)),
|
new FixedHardwareProperty("cpu", "count", Long.valueOf(2)),
|
||||||
new RangeHardwareProperty("memory", "MB", new Long(10240), new HardwareParameter(URI
|
new RangeHardwareProperty("memory", "MB", Long.valueOf(10240), new HardwareParameter(URI
|
||||||
.create("http://localhost:3001/api/instances"), "post", "hwp_memory", "create"),
|
.create("http://localhost:3001/api/instances"), "post", "hwp_memory", "create"),
|
||||||
new Double(7680.0), new Long(15360)), new EnumHardwareProperty("storage", "GB", new Long(
|
new Double(7680.0), Long.valueOf(15360)), new EnumHardwareProperty("storage", "GB", Long.valueOf(
|
||||||
850), new HardwareParameter(URI.create("http://localhost:3001/api/instances"), "post",
|
850), new HardwareParameter(URI.create("http://localhost:3001/api/instances"), "post",
|
||||||
"hwp_storage", "create"), ImmutableSet.<Object> of(new Long(850), new Long(1024))),
|
"hwp_storage", "create"), ImmutableSet.<Object> of(Long.valueOf(850), Long.valueOf(1024))),
|
||||||
new FixedHardwareProperty("architecture", "label", "x86_64"))),
|
new FixedHardwareProperty("architecture", "label", "x86_64"))),
|
||||||
new HardwareProfile(URI.create("http://localhost:3001/api/hardware_profiles/m1-xlarge"), "m1-xlarge",
|
new HardwareProfile(URI.create("http://localhost:3001/api/hardware_profiles/m1-xlarge"), "m1-xlarge",
|
||||||
"m1-xlarge", ImmutableSet.<HardwareProperty> of(
|
"m1-xlarge", ImmutableSet.<HardwareProperty> of(
|
||||||
new FixedHardwareProperty("cpu", "count", new Long(4)),
|
new FixedHardwareProperty("cpu", "count", Long.valueOf(4)),
|
||||||
new RangeHardwareProperty("memory", "MB", new Long(12288), new HardwareParameter(URI
|
new RangeHardwareProperty("memory", "MB", Long.valueOf(12288), new HardwareParameter(URI
|
||||||
.create("http://localhost:3001/api/instances"), "post", "hwp_memory", "create"),
|
.create("http://localhost:3001/api/instances"), "post", "hwp_memory", "create"),
|
||||||
new Long(12288), new Long(32768)),
|
Long.valueOf(12288), Long.valueOf(32768)),
|
||||||
new EnumHardwareProperty("storage", "GB", new Long(1024), new HardwareParameter(URI
|
new EnumHardwareProperty("storage", "GB", Long.valueOf(1024), new HardwareParameter(URI
|
||||||
.create("http://localhost:3001/api/instances"), "post", "hwp_storage", "create"),
|
.create("http://localhost:3001/api/instances"), "post", "hwp_storage", "create"),
|
||||||
ImmutableSet.<Object> of(new Long(1024), new Long(2048), new Long(4096))),
|
ImmutableSet.<Object> of(Long.valueOf(1024), Long.valueOf(2048), Long.valueOf(4096))),
|
||||||
new FixedHardwareProperty("architecture", "label", "x86_64"))),
|
new FixedHardwareProperty("architecture", "label", "x86_64"))),
|
||||||
new HardwareProfile(URI.create("http://localhost:3001/api/hardware_profiles/opaque"), "opaque", "opaque",
|
new HardwareProfile(URI.create("http://localhost:3001/api/hardware_profiles/opaque"), "opaque", "opaque",
|
||||||
ImmutableSet.<HardwareProperty> of()));
|
ImmutableSet.<HardwareProperty> of()));
|
||||||
|
|
|
@ -65,7 +65,7 @@ public class MapToDriveInfo implements Function<Map<String, String>, DriveInfo>
|
||||||
if (from.containsKey("readers"))
|
if (from.containsKey("readers"))
|
||||||
builder.readers(Splitter.on(' ').split(from.get("readers")));
|
builder.readers(Splitter.on(' ').split(from.get("readers")));
|
||||||
if (from.containsKey("size"))
|
if (from.containsKey("size"))
|
||||||
builder.size(new Long(from.get("size")));
|
builder.size(Long.valueOf(from.get("size")));
|
||||||
Map<String, String> metadata = Maps.newLinkedHashMap();
|
Map<String, String> metadata = Maps.newLinkedHashMap();
|
||||||
for (Entry<String, String> entry : from.entrySet()) {
|
for (Entry<String, String> entry : from.entrySet()) {
|
||||||
if (entry.getKey().startsWith("user:"))
|
if (entry.getKey().startsWith("user:"))
|
||||||
|
@ -83,13 +83,13 @@ public class MapToDriveInfo implements Function<Map<String, String>, DriveInfo>
|
||||||
protected DriveMetrics buildMetrics(Map<String, String> from) {
|
protected DriveMetrics buildMetrics(Map<String, String> from) {
|
||||||
DriveMetrics.Builder metricsBuilder = new DriveMetrics.Builder();
|
DriveMetrics.Builder metricsBuilder = new DriveMetrics.Builder();
|
||||||
if (from.containsKey("read:bytes"))
|
if (from.containsKey("read:bytes"))
|
||||||
metricsBuilder.readBytes(new Long(from.get("read:bytes")));
|
metricsBuilder.readBytes(Long.valueOf(from.get("read:bytes")));
|
||||||
if (from.containsKey("read:requests"))
|
if (from.containsKey("read:requests"))
|
||||||
metricsBuilder.readRequests(new Long(from.get("read:requests")));
|
metricsBuilder.readRequests(Long.valueOf(from.get("read:requests")));
|
||||||
if (from.containsKey("write:bytes"))
|
if (from.containsKey("write:bytes"))
|
||||||
metricsBuilder.writeBytes(new Long(from.get("write:bytes")));
|
metricsBuilder.writeBytes(Long.valueOf(from.get("write:bytes")));
|
||||||
if (from.containsKey("write:requests"))
|
if (from.containsKey("write:requests"))
|
||||||
metricsBuilder.writeRequests(new Long(from.get("write:requests")));
|
metricsBuilder.writeRequests(Long.valueOf(from.get("write:requests")));
|
||||||
return metricsBuilder.build();
|
return metricsBuilder.build();
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -74,13 +74,13 @@ public class MapToDriveMetrics implements Function<Map<String, String>, Map<Stri
|
||||||
protected DriveMetrics buildMetrics(String key, Map<String, String> from) {
|
protected DriveMetrics buildMetrics(String key, Map<String, String> from) {
|
||||||
DriveMetrics.Builder builder = new DriveMetrics.Builder();
|
DriveMetrics.Builder builder = new DriveMetrics.Builder();
|
||||||
if (from.containsKey(key + ":read:bytes"))
|
if (from.containsKey(key + ":read:bytes"))
|
||||||
builder.readBytes(new Long(from.get(key + ":read:bytes")));
|
builder.readBytes(Long.valueOf(from.get(key + ":read:bytes")));
|
||||||
if (from.containsKey(key + ":read:requests"))
|
if (from.containsKey(key + ":read:requests"))
|
||||||
builder.readRequests(new Long(from.get(key + ":read:requests")));
|
builder.readRequests(Long.valueOf(from.get(key + ":read:requests")));
|
||||||
if (from.containsKey(key + ":write:bytes"))
|
if (from.containsKey(key + ":write:bytes"))
|
||||||
builder.writeBytes(new Long(from.get(key + ":write:bytes")));
|
builder.writeBytes(Long.valueOf(from.get(key + ":write:bytes")));
|
||||||
if (from.containsKey(key + ":write:requests"))
|
if (from.containsKey(key + ":write:requests"))
|
||||||
builder.writeRequests(new Long(from.get(key + ":write:requests")));
|
builder.writeRequests(Long.valueOf(from.get(key + ":write:requests")));
|
||||||
return builder.build();
|
return builder.build();
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -68,16 +68,16 @@ public class MapToServerInfo implements Function<Map<String, String>, ServerInfo
|
||||||
|
|
||||||
|
|
||||||
if (from.containsKey("smp:cores")) {
|
if (from.containsKey("smp:cores")) {
|
||||||
builder.smp(new Integer(from.get("smp:cores")));
|
builder.smp(Integer.valueOf(from.get("smp:cores")));
|
||||||
} else if (from.containsKey("smp") && !"auto".equals(from.get("smp"))) {
|
} else if (from.containsKey("smp") && !"auto".equals(from.get("smp"))) {
|
||||||
builder.smp(new Integer(from.get("smp")));
|
builder.smp(Integer.valueOf(from.get("smp")));
|
||||||
}
|
}
|
||||||
|
|
||||||
builder.cpu(Integer.parseInt(from.get("cpu")));
|
builder.cpu(Integer.parseInt(from.get("cpu")));
|
||||||
builder.mem(Integer.parseInt(from.get("mem")));
|
builder.mem(Integer.parseInt(from.get("mem")));
|
||||||
builder.user(from.get("user"));
|
builder.user(from.get("user"));
|
||||||
if (from.containsKey("started"))
|
if (from.containsKey("started"))
|
||||||
builder.started(new Date(new Long(from.get("started"))));
|
builder.started(new Date(Long.valueOf(from.get("started"))));
|
||||||
builder.uuid(from.get("server"));
|
builder.uuid(from.get("server"));
|
||||||
if (from.containsKey("boot"))
|
if (from.containsKey("boot"))
|
||||||
builder.bootDeviceIds(Splitter.on(' ').split(from.get("boot")));
|
builder.bootDeviceIds(Splitter.on(' ').split(from.get("boot")));
|
||||||
|
|
|
@ -44,13 +44,13 @@ public class MapToServerMetrics implements Function<Map<String, String>, ServerM
|
||||||
public ServerMetrics apply(Map<String, String> from) {
|
public ServerMetrics apply(Map<String, String> from) {
|
||||||
ServerMetrics.Builder metricsBuilder = new ServerMetrics.Builder();
|
ServerMetrics.Builder metricsBuilder = new ServerMetrics.Builder();
|
||||||
if (from.containsKey("tx:packets"))
|
if (from.containsKey("tx:packets"))
|
||||||
metricsBuilder.txPackets(new Long(from.get("tx:packets")));
|
metricsBuilder.txPackets(Long.valueOf(from.get("tx:packets")));
|
||||||
if (from.containsKey("tx"))
|
if (from.containsKey("tx"))
|
||||||
metricsBuilder.tx(new Long(from.get("tx")));
|
metricsBuilder.tx(Long.valueOf(from.get("tx")));
|
||||||
if (from.containsKey("rx:packets"))
|
if (from.containsKey("rx:packets"))
|
||||||
metricsBuilder.rxPackets(new Long(from.get("rx:packets")));
|
metricsBuilder.rxPackets(Long.valueOf(from.get("rx:packets")));
|
||||||
if (from.containsKey("rx"))
|
if (from.containsKey("rx"))
|
||||||
metricsBuilder.rx(new Long(from.get("rx")));
|
metricsBuilder.rx(Long.valueOf(from.get("rx")));
|
||||||
metricsBuilder.driveMetrics(mapToDriveMetrics.apply(from));
|
metricsBuilder.driveMetrics(mapToDriveMetrics.apply(from));
|
||||||
|
|
||||||
ServerMetrics metrics = metricsBuilder.build();
|
ServerMetrics metrics = metricsBuilder.build();
|
||||||
|
|
|
@ -92,7 +92,7 @@ public class ElasticStackErrorHandler implements HttpErrorHandler {
|
||||||
if (response.getPayload() == null)
|
if (response.getPayload() == null)
|
||||||
return null;
|
return null;
|
||||||
try {
|
try {
|
||||||
return Strings2.toStringAndClose(response.getPayload().getInput());
|
return Strings2.toString(response.getPayload());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
} finally {
|
} finally {
|
||||||
|
|
|
@ -326,7 +326,7 @@ public class ElasticStackClientLiveTest
|
||||||
public void testWeCanReadAndWriteToDrive() throws IOException {
|
public void testWeCanReadAndWriteToDrive() throws IOException {
|
||||||
drive2 = client.createDrive(new CreateDriveRequest.Builder().name(prefix + "2").size(1 * 1024 * 1024l).build());
|
drive2 = client.createDrive(new CreateDriveRequest.Builder().name(prefix + "2").size(1 * 1024 * 1024l).build());
|
||||||
client.writeDrive(drive2.getUuid(), Payloads.newStringPayload("foo"));
|
client.writeDrive(drive2.getUuid(), Payloads.newStringPayload("foo"));
|
||||||
assertEquals(Strings2.toStringAndClose(client.readDrive(drive2.getUuid(), 0, 3).getInput()), "foo");
|
assertEquals(Strings2.toString(client.readDrive(drive2.getUuid(), 0, 3)), "foo");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(dependsOnMethods = "testWeCanReadAndWriteToDrive")
|
@Test(dependsOnMethods = "testWeCanReadAndWriteToDrive")
|
||||||
|
@ -341,7 +341,7 @@ public class ElasticStackClientLiveTest
|
||||||
assert driveNotClaimed.apply(drive2) : client.getDriveInfo(drive2.getUuid());
|
assert driveNotClaimed.apply(drive2) : client.getDriveInfo(drive2.getUuid());
|
||||||
System.err.println("after image; drive 2" + client.getDriveInfo(drive2.getUuid()));
|
System.err.println("after image; drive 2" + client.getDriveInfo(drive2.getUuid()));
|
||||||
System.err.println("after image; drive 3" + client.getDriveInfo(drive3.getUuid()));
|
System.err.println("after image; drive 3" + client.getDriveInfo(drive3.getUuid()));
|
||||||
assertEquals(Strings2.toStringAndClose(client.readDrive(drive3.getUuid(), 0, 3).getInput()), "foo");
|
assertEquals(Strings2.toString(client.readDrive(drive3.getUuid(), 0, 3)), "foo");
|
||||||
} finally {
|
} finally {
|
||||||
client.destroyDrive(drive2.getUuid());
|
client.destroyDrive(drive2.getUuid());
|
||||||
client.destroyDrive(drive3.getUuid());
|
client.destroyDrive(drive3.getUuid());
|
||||||
|
|
|
@ -1,31 +0,0 @@
|
||||||
/**
|
|
||||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
|
||||||
* contributor license agreements. See the NOTICE file
|
|
||||||
* distributed with this work for additional information
|
|
||||||
* regarding copyright ownership. jclouds licenses this file
|
|
||||||
* to you 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.
|
|
||||||
*/
|
|
||||||
package org.jclouds.filesystem;
|
|
||||||
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
import org.jclouds.blobstore.BlobStore;
|
|
||||||
import org.jclouds.concurrent.Timeout;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Alfredo "Rainbowbreeze" Morresi
|
|
||||||
*/
|
|
||||||
@Timeout(duration = 2, timeUnit = TimeUnit.MINUTES) public interface FilesystemBlobStore extends BlobStore {
|
|
||||||
}
|
|
|
@ -21,18 +21,18 @@ package org.jclouds.filesystem.config;
|
||||||
import org.jclouds.blobstore.AsyncBlobStore;
|
import org.jclouds.blobstore.AsyncBlobStore;
|
||||||
import org.jclouds.blobstore.BlobRequestSigner;
|
import org.jclouds.blobstore.BlobRequestSigner;
|
||||||
import org.jclouds.blobstore.BlobStore;
|
import org.jclouds.blobstore.BlobStore;
|
||||||
|
import org.jclouds.blobstore.LocalAsyncBlobStore;
|
||||||
|
import org.jclouds.blobstore.LocalStorageStrategy;
|
||||||
import org.jclouds.blobstore.TransientBlobRequestSigner;
|
import org.jclouds.blobstore.TransientBlobRequestSigner;
|
||||||
import org.jclouds.blobstore.attr.ConsistencyModel;
|
import org.jclouds.blobstore.attr.ConsistencyModel;
|
||||||
import org.jclouds.blobstore.config.BlobStoreMapModule;
|
import org.jclouds.blobstore.config.BlobStoreMapModule;
|
||||||
import org.jclouds.blobstore.config.BlobStoreObjectModule;
|
import org.jclouds.blobstore.config.BlobStoreObjectModule;
|
||||||
|
import org.jclouds.blobstore.config.LocalBlobStore;
|
||||||
import org.jclouds.blobstore.util.BlobUtils;
|
import org.jclouds.blobstore.util.BlobUtils;
|
||||||
import org.jclouds.filesystem.FilesystemAsyncBlobStore;
|
|
||||||
import org.jclouds.filesystem.FilesystemBlobStore;
|
|
||||||
import org.jclouds.filesystem.predicates.validators.FilesystemBlobKeyValidator;
|
import org.jclouds.filesystem.predicates.validators.FilesystemBlobKeyValidator;
|
||||||
import org.jclouds.filesystem.predicates.validators.FilesystemContainerNameValidator;
|
import org.jclouds.filesystem.predicates.validators.FilesystemContainerNameValidator;
|
||||||
import org.jclouds.filesystem.predicates.validators.internal.FilesystemBlobKeyValidatorImpl;
|
import org.jclouds.filesystem.predicates.validators.internal.FilesystemBlobKeyValidatorImpl;
|
||||||
import org.jclouds.filesystem.predicates.validators.internal.FilesystemContainerNameValidatorImpl;
|
import org.jclouds.filesystem.predicates.validators.internal.FilesystemContainerNameValidatorImpl;
|
||||||
import org.jclouds.filesystem.strategy.FilesystemStorageStrategy;
|
|
||||||
import org.jclouds.filesystem.strategy.internal.FilesystemStorageStrategyImpl;
|
import org.jclouds.filesystem.strategy.internal.FilesystemStorageStrategyImpl;
|
||||||
import org.jclouds.filesystem.util.internal.FileSystemBlobUtilsImpl;
|
import org.jclouds.filesystem.util.internal.FileSystemBlobUtilsImpl;
|
||||||
import org.jclouds.rest.config.BinderUtils;
|
import org.jclouds.rest.config.BinderUtils;
|
||||||
|
@ -48,15 +48,15 @@ public class FilesystemBlobStoreContextModule extends AbstractModule {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void configure() {
|
protected void configure() {
|
||||||
bind(AsyncBlobStore.class).to(FilesystemAsyncBlobStore.class).asEagerSingleton();
|
bind(AsyncBlobStore.class).to(LocalAsyncBlobStore.class).asEagerSingleton();
|
||||||
// forward all requests from TransientBlobStore to TransientAsyncBlobStore. needs above binding as cannot proxy a class
|
// forward all requests from TransientBlobStore to TransientAsyncBlobStore. needs above binding as cannot proxy a class
|
||||||
BinderUtils.bindClient(binder(), FilesystemBlobStore.class, AsyncBlobStore.class, ImmutableMap.<Class<?>, Class<?>>of());
|
BinderUtils.bindClient(binder(), LocalBlobStore.class, AsyncBlobStore.class, ImmutableMap.<Class<?>, Class<?>>of());
|
||||||
bind(BlobStore.class).to(FilesystemBlobStore.class);
|
bind(BlobStore.class).to(LocalBlobStore.class);
|
||||||
|
|
||||||
install(new BlobStoreObjectModule());
|
install(new BlobStoreObjectModule());
|
||||||
install(new BlobStoreMapModule());
|
install(new BlobStoreMapModule());
|
||||||
bind(ConsistencyModel.class).toInstance(ConsistencyModel.STRICT);
|
bind(ConsistencyModel.class).toInstance(ConsistencyModel.STRICT);
|
||||||
bind(FilesystemStorageStrategy.class).to(FilesystemStorageStrategyImpl.class);
|
bind(LocalStorageStrategy.class).to(FilesystemStorageStrategyImpl.class);
|
||||||
bind(BlobUtils.class).to(FileSystemBlobUtilsImpl.class);
|
bind(BlobUtils.class).to(FileSystemBlobUtilsImpl.class);
|
||||||
bind(FilesystemBlobKeyValidator.class).to(FilesystemBlobKeyValidatorImpl.class);
|
bind(FilesystemBlobKeyValidator.class).to(FilesystemBlobKeyValidatorImpl.class);
|
||||||
bind(FilesystemContainerNameValidator.class).to(FilesystemContainerNameValidatorImpl.class);
|
bind(FilesystemContainerNameValidator.class).to(FilesystemContainerNameValidatorImpl.class);
|
||||||
|
|
|
@ -35,15 +35,18 @@ import javax.inject.Provider;
|
||||||
|
|
||||||
import org.apache.commons.io.FileUtils;
|
import org.apache.commons.io.FileUtils;
|
||||||
import org.apache.commons.io.filefilter.DirectoryFileFilter;
|
import org.apache.commons.io.filefilter.DirectoryFileFilter;
|
||||||
|
import org.jclouds.blobstore.LocalStorageStrategy;
|
||||||
import org.jclouds.blobstore.domain.Blob;
|
import org.jclouds.blobstore.domain.Blob;
|
||||||
import org.jclouds.blobstore.domain.BlobBuilder;
|
import org.jclouds.blobstore.domain.BlobBuilder;
|
||||||
import org.jclouds.blobstore.options.ListContainerOptions;
|
import org.jclouds.blobstore.options.ListContainerOptions;
|
||||||
|
import org.jclouds.crypto.Crypto;
|
||||||
import org.jclouds.crypto.CryptoStreams;
|
import org.jclouds.crypto.CryptoStreams;
|
||||||
|
import org.jclouds.domain.Location;
|
||||||
import org.jclouds.filesystem.predicates.validators.FilesystemBlobKeyValidator;
|
import org.jclouds.filesystem.predicates.validators.FilesystemBlobKeyValidator;
|
||||||
import org.jclouds.filesystem.predicates.validators.FilesystemContainerNameValidator;
|
import org.jclouds.filesystem.predicates.validators.FilesystemContainerNameValidator;
|
||||||
import org.jclouds.filesystem.reference.FilesystemConstants;
|
import org.jclouds.filesystem.reference.FilesystemConstants;
|
||||||
import org.jclouds.filesystem.strategy.FilesystemStorageStrategy;
|
|
||||||
import org.jclouds.io.Payload;
|
import org.jclouds.io.Payload;
|
||||||
|
import org.jclouds.io.Payloads;
|
||||||
import org.jclouds.logging.Logger;
|
import org.jclouds.logging.Logger;
|
||||||
import org.jclouds.rest.annotations.ParamValidators;
|
import org.jclouds.rest.annotations.ParamValidators;
|
||||||
|
|
||||||
|
@ -55,7 +58,7 @@ import com.google.common.io.Files;
|
||||||
*
|
*
|
||||||
* @author Alfredo "Rainbowbreeze" Morresi
|
* @author Alfredo "Rainbowbreeze" Morresi
|
||||||
*/
|
*/
|
||||||
public class FilesystemStorageStrategyImpl implements FilesystemStorageStrategy {
|
public class FilesystemStorageStrategyImpl implements LocalStorageStrategy {
|
||||||
|
|
||||||
private static final String BACK_SLASH = "\\";
|
private static final String BACK_SLASH = "\\";
|
||||||
|
|
||||||
|
@ -66,17 +69,20 @@ public class FilesystemStorageStrategyImpl implements FilesystemStorageStrategy
|
||||||
protected final String baseDirectory;
|
protected final String baseDirectory;
|
||||||
protected final FilesystemContainerNameValidator filesystemContainerNameValidator;
|
protected final FilesystemContainerNameValidator filesystemContainerNameValidator;
|
||||||
protected final FilesystemBlobKeyValidator filesystemBlobKeyValidator;
|
protected final FilesystemBlobKeyValidator filesystemBlobKeyValidator;
|
||||||
|
private final Crypto crypto;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
protected FilesystemStorageStrategyImpl(Provider<BlobBuilder> blobBuilders,
|
protected FilesystemStorageStrategyImpl(Provider<BlobBuilder> blobBuilders,
|
||||||
@Named(FilesystemConstants.PROPERTY_BASEDIR) String baseDir,
|
@Named(FilesystemConstants.PROPERTY_BASEDIR) String baseDir,
|
||||||
FilesystemContainerNameValidator filesystemContainerNameValidator,
|
FilesystemContainerNameValidator filesystemContainerNameValidator,
|
||||||
FilesystemBlobKeyValidator filesystemBlobKeyValidator) {
|
FilesystemBlobKeyValidator filesystemBlobKeyValidator,
|
||||||
|
Crypto crypto) {
|
||||||
this.blobBuilders = checkNotNull(blobBuilders, "filesystem storage strategy blobBuilders");
|
this.blobBuilders = checkNotNull(blobBuilders, "filesystem storage strategy blobBuilders");
|
||||||
this.baseDirectory = checkNotNull(baseDir, "filesystem storage strategy base directory");
|
this.baseDirectory = checkNotNull(baseDir, "filesystem storage strategy base directory");
|
||||||
this.filesystemContainerNameValidator = checkNotNull(filesystemContainerNameValidator,
|
this.filesystemContainerNameValidator = checkNotNull(filesystemContainerNameValidator,
|
||||||
"filesystem container name validator");
|
"filesystem container name validator");
|
||||||
this.filesystemBlobKeyValidator = checkNotNull(filesystemBlobKeyValidator, "filesystem blob key validator");
|
this.filesystemBlobKeyValidator = checkNotNull(filesystemBlobKeyValidator, "filesystem blob key validator");
|
||||||
|
this.crypto = crypto;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -109,8 +115,14 @@ public class FilesystemStorageStrategyImpl implements FilesystemStorageStrategy
|
||||||
return blob;
|
return blob;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean createContainer(String container) {
|
public boolean createContainer(String container) {
|
||||||
|
filesystemContainerNameValidator.validate(container);
|
||||||
|
return createContainerInLocation(container, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean createContainerInLocation(String container, Location location) {
|
||||||
|
// TODO: implement location
|
||||||
logger.debug("Creating container %s", container);
|
logger.debug("Creating container %s", container);
|
||||||
filesystemContainerNameValidator.validate(container);
|
filesystemContainerNameValidator.validate(container);
|
||||||
return createDirectoryWithResult(container, null);
|
return createDirectoryWithResult(container, null);
|
||||||
|
@ -151,7 +163,6 @@ public class FilesystemStorageStrategyImpl implements FilesystemStorageStrategy
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Blob newBlob(@ParamValidators({ FilesystemBlobKeyValidator.class }) String name) {
|
public Blob newBlob(@ParamValidators({ FilesystemBlobKeyValidator.class }) String name) {
|
||||||
filesystemBlobKeyValidator.validate(name);
|
filesystemBlobKeyValidator.validate(name);
|
||||||
return blobBuilders.get().name(name).build();
|
return blobBuilders.get().name(name).build();
|
||||||
|
@ -195,7 +206,6 @@ public class FilesystemStorageStrategyImpl implements FilesystemStorageStrategy
|
||||||
* @param blobKey
|
* @param blobKey
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@Override
|
|
||||||
public File getFileForBlobKey(String container, String blobKey) {
|
public File getFileForBlobKey(String container, String blobKey) {
|
||||||
filesystemContainerNameValidator.validate(container);
|
filesystemContainerNameValidator.validate(container);
|
||||||
filesystemBlobKeyValidator.validate(blobKey);
|
filesystemBlobKeyValidator.validate(blobKey);
|
||||||
|
@ -205,7 +215,7 @@ public class FilesystemStorageStrategyImpl implements FilesystemStorageStrategy
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void putBlob(final String containerName, final Blob blob) throws IOException {
|
public String putBlob(final String containerName, final Blob blob) throws IOException {
|
||||||
String blobKey = blob.getMetadata().getName();
|
String blobKey = blob.getMetadata().getName();
|
||||||
Payload payload = blob.getPayload();
|
Payload payload = blob.getPayload();
|
||||||
filesystemContainerNameValidator.validate(containerName);
|
filesystemContainerNameValidator.validate(containerName);
|
||||||
|
@ -220,6 +230,9 @@ public class FilesystemStorageStrategyImpl implements FilesystemStorageStrategy
|
||||||
output = new FileOutputStream(outputFile);
|
output = new FileOutputStream(outputFile);
|
||||||
payload.writeTo(output);
|
payload.writeTo(output);
|
||||||
}
|
}
|
||||||
|
Payloads.calculateMD5(payload, crypto.md5());
|
||||||
|
String eTag = CryptoStreams.hex(payload.getContentMetadata().getContentMD5());
|
||||||
|
return eTag;
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
if (outputFile != null) {
|
if (outputFile != null) {
|
||||||
outputFile.delete();
|
outputFile.delete();
|
||||||
|
@ -263,16 +276,23 @@ public class FilesystemStorageStrategyImpl implements FilesystemStorageStrategy
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
public Location getLocation(final String containerName) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getSeparator() {
|
||||||
|
return File.separator;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean directoryExists(String container, String directory) {
|
public boolean directoryExists(String container, String directory) {
|
||||||
return buildPathAndChecksIfDirectoryExists(container, directory);
|
return buildPathAndChecksIfDirectoryExists(container, directory);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void createDirectory(String container, String directory) {
|
public void createDirectory(String container, String directory) {
|
||||||
createDirectoryWithResult(container, directory);
|
createDirectoryWithResult(container, directory);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void deleteDirectory(String container, String directory) {
|
public void deleteDirectory(String container, String directory) {
|
||||||
// create complete dir path
|
// create complete dir path
|
||||||
String fullDirPath = buildPathStartingFromBaseDir(container, directory);
|
String fullDirPath = buildPathStartingFromBaseDir(container, directory);
|
||||||
|
@ -284,7 +304,6 @@ public class FilesystemStorageStrategyImpl implements FilesystemStorageStrategy
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public long countBlobs(String container, ListContainerOptions options) {
|
public long countBlobs(String container, ListContainerOptions options) {
|
||||||
// TODO
|
// TODO
|
||||||
throw new UnsupportedOperationException("Not supported yet.");
|
throw new UnsupportedOperationException("Not supported yet.");
|
||||||
|
|
|
@ -23,27 +23,28 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
import javax.inject.Provider;
|
import javax.inject.Provider;
|
||||||
|
|
||||||
import org.jclouds.blobstore.AsyncBlobStore;
|
import org.jclouds.blobstore.AsyncBlobStore;
|
||||||
|
import org.jclouds.blobstore.LocalStorageStrategy;
|
||||||
import org.jclouds.blobstore.domain.BlobBuilder;
|
import org.jclouds.blobstore.domain.BlobBuilder;
|
||||||
import org.jclouds.blobstore.options.ListContainerOptions;
|
import org.jclouds.blobstore.options.ListContainerOptions;
|
||||||
import org.jclouds.blobstore.util.BlobUtils;
|
import org.jclouds.blobstore.util.BlobUtils;
|
||||||
import org.jclouds.filesystem.strategy.FilesystemStorageStrategy;
|
import org.jclouds.filesystem.strategy.internal.FilesystemStorageStrategyImpl;
|
||||||
|
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implements the {@link BlobUtils} interfaced and act as a bridge to
|
* Implements the {@link BlobUtils} interfaced and act as a bridge to
|
||||||
* {@link FilesystemStorageStrategy} when used inside {@link AsyncBlobStore}
|
* {@link LocalStorageStrategy} when used inside {@link AsyncBlobStore}
|
||||||
*
|
*
|
||||||
* @author Alfredo "Rainbowbreeze" Morresi
|
* @author Alfredo "Rainbowbreeze" Morresi
|
||||||
*/
|
*/
|
||||||
public class FileSystemBlobUtilsImpl implements BlobUtils {
|
public class FileSystemBlobUtilsImpl implements BlobUtils {
|
||||||
|
|
||||||
protected final FilesystemStorageStrategy storageStrategy;
|
protected final FilesystemStorageStrategyImpl storageStrategy;
|
||||||
protected final Provider<BlobBuilder> blobBuilders;
|
protected final Provider<BlobBuilder> blobBuilders;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public FileSystemBlobUtilsImpl(FilesystemStorageStrategy storageStrategy, Provider<BlobBuilder> blobBuilders) {
|
public FileSystemBlobUtilsImpl(LocalStorageStrategy storageStrategy, Provider<BlobBuilder> blobBuilders) {
|
||||||
this.storageStrategy = checkNotNull(storageStrategy, "Filesystem Storage Strategy");
|
this.storageStrategy = (FilesystemStorageStrategyImpl) checkNotNull(storageStrategy, "Filesystem Storage Strategy");
|
||||||
this.blobBuilders = checkNotNull(blobBuilders, "Filesystem blobBuilders");
|
this.blobBuilders = checkNotNull(blobBuilders, "Filesystem blobBuilders");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -656,7 +656,7 @@ public class FilesystemAsyncBlobStoreTest {
|
||||||
assertEquals(metadata.getUserMetadata().size(), 0, "Wrong blob UserMetadata");
|
assertEquals(metadata.getUserMetadata().size(), 0, "Wrong blob UserMetadata");
|
||||||
// metadata.getLastModified()
|
// metadata.getLastModified()
|
||||||
File file = new File(TARGET_CONTAINER_NAME + File.separator + BLOB_KEY);
|
File file = new File(TARGET_CONTAINER_NAME + File.separator + BLOB_KEY);
|
||||||
assertEquals(metadata.getContentMetadata().getContentLength(), new Long(file.length()), "Wrong blob size");
|
assertEquals(metadata.getContentMetadata().getContentLength(), Long.valueOf(file.length()), "Wrong blob size");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testDeleteContainer_NotExistingContainer() {
|
public void testDeleteContainer_NotExistingContainer() {
|
||||||
|
|
|
@ -42,7 +42,6 @@ import org.jclouds.blobstore.options.ListContainerOptions;
|
||||||
import org.jclouds.encryption.internal.JCECrypto;
|
import org.jclouds.encryption.internal.JCECrypto;
|
||||||
import org.jclouds.filesystem.predicates.validators.internal.FilesystemBlobKeyValidatorImpl;
|
import org.jclouds.filesystem.predicates.validators.internal.FilesystemBlobKeyValidatorImpl;
|
||||||
import org.jclouds.filesystem.predicates.validators.internal.FilesystemContainerNameValidatorImpl;
|
import org.jclouds.filesystem.predicates.validators.internal.FilesystemContainerNameValidatorImpl;
|
||||||
import org.jclouds.filesystem.strategy.FilesystemStorageStrategy;
|
|
||||||
import org.jclouds.filesystem.utils.TestUtils;
|
import org.jclouds.filesystem.utils.TestUtils;
|
||||||
import org.jclouds.io.payloads.FilePayload;
|
import org.jclouds.io.payloads.FilePayload;
|
||||||
import org.testng.annotations.AfterMethod;
|
import org.testng.annotations.AfterMethod;
|
||||||
|
@ -73,7 +72,7 @@ public class FilesystemStorageStrategyImplTest {
|
||||||
System.setProperty(LOGGING_CONFIG_KEY, LOGGING_CONFIG_VALUE);
|
System.setProperty(LOGGING_CONFIG_KEY, LOGGING_CONFIG_VALUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
private FilesystemStorageStrategy storageStrategy;
|
private FilesystemStorageStrategyImpl storageStrategy;
|
||||||
|
|
||||||
@BeforeMethod
|
@BeforeMethod
|
||||||
protected void setUp() throws Exception {
|
protected void setUp() throws Exception {
|
||||||
|
@ -87,7 +86,7 @@ public class FilesystemStorageStrategyImplTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}, TestUtils.TARGET_BASE_DIR, new FilesystemContainerNameValidatorImpl(), new FilesystemBlobKeyValidatorImpl());
|
}, TestUtils.TARGET_BASE_DIR, new FilesystemContainerNameValidatorImpl(), new FilesystemBlobKeyValidatorImpl(), new JCECrypto());
|
||||||
TestUtils.cleanDirectoryContent(TestUtils.TARGET_BASE_DIR);
|
TestUtils.cleanDirectoryContent(TestUtils.TARGET_BASE_DIR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -409,12 +408,12 @@ public class FilesystemStorageStrategyImplTest {
|
||||||
assertEquals(fileForPayload.getAbsolutePath(), fullPath + blobKey, "Wrong file path");
|
assertEquals(fileForPayload.getAbsolutePath(), fullPath + blobKey, "Wrong file path");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGetFileForBlobKey_AbsolutePath() throws IOException {
|
public void testGetFileForBlobKey_AbsolutePath() throws Exception {
|
||||||
String absoluteBasePath = (new File(getAbsoluteDirectory(), "basedir")).getAbsolutePath() + FS;
|
String absoluteBasePath = (new File(getAbsoluteDirectory(), "basedir")).getAbsolutePath() + FS;
|
||||||
String absoluteContainerPath = absoluteBasePath + CONTAINER_NAME + FS;
|
String absoluteContainerPath = absoluteBasePath + CONTAINER_NAME + FS;
|
||||||
|
|
||||||
// create storageStrategy with an absolute path
|
// create storageStrategy with an absolute path
|
||||||
FilesystemStorageStrategy storageStrategyAbsolute = new FilesystemStorageStrategyImpl(
|
FilesystemStorageStrategyImpl storageStrategyAbsolute = new FilesystemStorageStrategyImpl(
|
||||||
new Provider<BlobBuilder>() {
|
new Provider<BlobBuilder>() {
|
||||||
@Override
|
@Override
|
||||||
public BlobBuilder get() {
|
public BlobBuilder get() {
|
||||||
|
@ -424,7 +423,7 @@ public class FilesystemStorageStrategyImplTest {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, absoluteBasePath, new FilesystemContainerNameValidatorImpl(), new FilesystemBlobKeyValidatorImpl());
|
}, absoluteBasePath, new FilesystemContainerNameValidatorImpl(), new FilesystemBlobKeyValidatorImpl(), new JCECrypto());
|
||||||
TestUtils.cleanDirectoryContent(absoluteContainerPath);
|
TestUtils.cleanDirectoryContent(absoluteContainerPath);
|
||||||
|
|
||||||
String blobKey;
|
String blobKey;
|
||||||
|
|
|
@ -85,7 +85,7 @@ public class ParseNovaErrorFromHttpResponse implements HttpErrorHandler {
|
||||||
String parseErrorFromContentOrNull(HttpCommand command, HttpResponse response) {
|
String parseErrorFromContentOrNull(HttpCommand command, HttpResponse response) {
|
||||||
if (response.getPayload() != null) {
|
if (response.getPayload() != null) {
|
||||||
try {
|
try {
|
||||||
return Strings2.toStringAndClose(response.getPayload().getInput());
|
return Strings2.toString(response.getPayload());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
logger.warn(e, "exception reading error from response", response);
|
logger.warn(e, "exception reading error from response", response);
|
||||||
}
|
}
|
||||||
|
|
|
@ -264,8 +264,8 @@ public class NovaClientLiveTest extends BaseComputeServiceContextLiveTest {
|
||||||
assertNotNull(server.getHostId());
|
assertNotNull(server.getHostId());
|
||||||
assertEquals(server.getStatus(), ServerStatus.ACTIVE);
|
assertEquals(server.getStatus(), ServerStatus.ACTIVE);
|
||||||
assert server.getProgress() >= 0 : "newDetails.getProgress()" + server.getProgress();
|
assert server.getProgress() >= 0 : "newDetails.getProgress()" + server.getProgress();
|
||||||
assertEquals(new Integer(14362), server.getImage());
|
assertEquals(Integer.valueOf(14362), server.getImage());
|
||||||
assertEquals(new Integer(1), server.getFlavor());
|
assertEquals(Integer.valueOf(1), server.getFlavor());
|
||||||
assertNotNull(server.getAddresses());
|
assertNotNull(server.getAddresses());
|
||||||
// listAddresses tests..
|
// listAddresses tests..
|
||||||
assertEquals(client.getAddresses(serverId), server.getAddresses());
|
assertEquals(client.getAddresses(serverId), server.getAddresses());
|
||||||
|
@ -303,7 +303,7 @@ public class NovaClientLiveTest extends BaseComputeServiceContextLiveTest {
|
||||||
try {
|
try {
|
||||||
client.connect();
|
client.connect();
|
||||||
Payload etcPasswd = client.get("/etc/jclouds.txt");
|
Payload etcPasswd = client.get("/etc/jclouds.txt");
|
||||||
String etcPasswdContents = Strings2.toStringAndClose(etcPasswd.getInput());
|
String etcPasswdContents = Strings2.toString(etcPasswd);
|
||||||
assertEquals("nova", etcPasswdContents.trim());
|
assertEquals("nova", etcPasswdContents.trim());
|
||||||
} finally {
|
} finally {
|
||||||
if (client != null)
|
if (client != null)
|
||||||
|
@ -332,7 +332,7 @@ public class NovaClientLiveTest extends BaseComputeServiceContextLiveTest {
|
||||||
public void testCreateImage() throws Exception {
|
public void testCreateImage() throws Exception {
|
||||||
Image image = client.createImageFromServer("hoofie", serverId);
|
Image image = client.createImageFromServer("hoofie", serverId);
|
||||||
assertEquals("hoofie", image.getName());
|
assertEquals("hoofie", image.getName());
|
||||||
assertEquals(new Integer(serverId), image.getServerRef());
|
assertEquals(Integer.valueOf(serverId), image.getServerRef());
|
||||||
createdImageRef = image.getId()+"";
|
createdImageRef = image.getId()+"";
|
||||||
blockUntilImageActive(createdImageRef);
|
blockUntilImageActive(createdImageRef);
|
||||||
}
|
}
|
||||||
|
@ -341,7 +341,7 @@ public class NovaClientLiveTest extends BaseComputeServiceContextLiveTest {
|
||||||
public void testRebuildServer() throws Exception {
|
public void testRebuildServer() throws Exception {
|
||||||
client.rebuildServer(serverId, new RebuildServerOptions().withImage(createdImageRef));
|
client.rebuildServer(serverId, new RebuildServerOptions().withImage(createdImageRef));
|
||||||
blockUntilServerActive(serverId);
|
blockUntilServerActive(serverId);
|
||||||
assertEquals(new Integer(createdImageRef).intValue(),client.getServer(serverId).getImage().getId());
|
assertEquals(Integer.valueOf(createdImageRef).intValue(),client.getServer(serverId).getImage().getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(timeOut = 10 * 60 * 1000, dependsOnMethods = "testRebuildServer")
|
@Test(timeOut = 10 * 60 * 1000, dependsOnMethods = "testRebuildServer")
|
||||||
|
@ -362,7 +362,7 @@ public class NovaClientLiveTest extends BaseComputeServiceContextLiveTest {
|
||||||
blockUntilServerVerifyResize(serverId);
|
blockUntilServerVerifyResize(serverId);
|
||||||
client.revertResizeServer(serverId);
|
client.revertResizeServer(serverId);
|
||||||
blockUntilServerActive(serverId);
|
blockUntilServerActive(serverId);
|
||||||
assertEquals(new Integer(1), client.getServer(serverId).getFlavorRef());
|
assertEquals(Integer.valueOf(1), client.getServer(serverId).getFlavorRef());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(timeOut = 10 * 60 * 1000, dependsOnMethods = "testRebootSoft")
|
@Test(timeOut = 10 * 60 * 1000, dependsOnMethods = "testRebootSoft")
|
||||||
|
@ -371,7 +371,7 @@ public class NovaClientLiveTest extends BaseComputeServiceContextLiveTest {
|
||||||
blockUntilServerVerifyResize(serverId2);
|
blockUntilServerVerifyResize(serverId2);
|
||||||
client.confirmResizeServer(serverId2);
|
client.confirmResizeServer(serverId2);
|
||||||
blockUntilServerActive(serverId2);
|
blockUntilServerActive(serverId2);
|
||||||
assertEquals(new Integer(2), client.getServer(serverId2).getFlavorRef());
|
assertEquals(Integer.valueOf(2), client.getServer(serverId2).getFlavorRef());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(timeOut = 10 * 60 * 1000, dependsOnMethods = { "testRebootSoft", "testRevertResize", "testConfirmResize" })
|
@Test(timeOut = 10 * 60 * 1000, dependsOnMethods = { "testRebootSoft", "testRevertResize", "testConfirmResize" })
|
||||||
|
|
|
@ -64,7 +64,7 @@ public class ParseImageFromJsonResponseTest {
|
||||||
assertEquals(response.getId(), 2);
|
assertEquals(response.getId(), 2);
|
||||||
assertEquals(response.getName(), "CentOS 5.2");
|
assertEquals(response.getName(), "CentOS 5.2");
|
||||||
assertEquals(response.getCreated(), dateService.iso8601SecondsDateParse("2010-08-10T12:00:00Z"));
|
assertEquals(response.getCreated(), dateService.iso8601SecondsDateParse("2010-08-10T12:00:00Z"));
|
||||||
assertEquals(response.getProgress(), new Integer(80));
|
assertEquals(response.getProgress(), Integer.valueOf(80));
|
||||||
assertEquals(response.getStatus(), ImageStatus.SAVING);
|
assertEquals(response.getStatus(), ImageStatus.SAVING);
|
||||||
assertEquals(response.getUpdated(), dateService.iso8601SecondsDateParse(("2010-10-10T12:00:00Z")));
|
assertEquals(response.getUpdated(), dateService.iso8601SecondsDateParse(("2010-10-10T12:00:00Z")));
|
||||||
assertEquals(response.getServerRef(), "http://servers.api.openstack.org/v1.1/1234/servers/12");
|
assertEquals(response.getServerRef(), "http://servers.api.openstack.org/v1.1/1234/servers/12");
|
||||||
|
|
|
@ -96,7 +96,7 @@ public class ParseImageListFromJsonResponseTest {
|
||||||
assertEquals(response.get(1).getName(), "My Server Backup");
|
assertEquals(response.get(1).getName(), "My Server Backup");
|
||||||
assertEquals(response.get(1).getCreated(), dateService.iso8601SecondsDateParse("2009-07-07T09:56:16Z"));
|
assertEquals(response.get(1).getCreated(), dateService.iso8601SecondsDateParse("2009-07-07T09:56:16Z"));
|
||||||
|
|
||||||
assertEquals(response.get(1).getProgress(), new Integer(80));
|
assertEquals(response.get(1).getProgress(), Integer.valueOf(80));
|
||||||
assertEquals(response.get(1).getStatus(), ImageStatus.SAVING);
|
assertEquals(response.get(1).getStatus(), ImageStatus.SAVING);
|
||||||
assertEquals(response.get(1).getUpdated(), dateService.iso8601SecondsDateParse("2010-10-10T12:00:00Z"));
|
assertEquals(response.get(1).getUpdated(), dateService.iso8601SecondsDateParse("2010-10-10T12:00:00Z"));
|
||||||
assertEquals(response.get(1).getServerRef(), "http://servers.api.openstack.org/v1.1/1234/servers/12");
|
assertEquals(response.get(1).getServerRef(), "http://servers.api.openstack.org/v1.1/1234/servers/12");
|
||||||
|
|
|
@ -64,7 +64,7 @@ public class ParseServerFromJsonResponseDiabloTest {
|
||||||
assertEquals(response.getFlavor().getURI(), new URI("http://servers.api.openstack.org/1234/flavors/1"));
|
assertEquals(response.getFlavor().getURI(), new URI("http://servers.api.openstack.org/1234/flavors/1"));
|
||||||
assertEquals(response.getHostId(), "e4d909c290d0fb1ca068ffaddf22cbd0");
|
assertEquals(response.getHostId(), "e4d909c290d0fb1ca068ffaddf22cbd0");
|
||||||
assertEquals(response.getStatus(), ServerStatus.BUILD);
|
assertEquals(response.getStatus(), ServerStatus.BUILD);
|
||||||
assertEquals(response.getProgress(), new Integer(60));
|
assertEquals(response.getProgress(), Integer.valueOf(60));
|
||||||
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.US);
|
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.US);
|
||||||
dateFormat.setTimeZone(new SimpleTimeZone(0, "GMT"));
|
dateFormat.setTimeZone(new SimpleTimeZone(0, "GMT"));
|
||||||
assertEquals(response.getCreated(), dateFormat.parse("2010-08-10T12:00:00Z"));
|
assertEquals(response.getCreated(), dateFormat.parse("2010-08-10T12:00:00Z"));
|
||||||
|
|
|
@ -65,7 +65,7 @@ public class ParseServerFromJsonResponseTest {
|
||||||
assertEquals(response.getFlavorRef(), "http://servers.api.openstack.org/1234/flavors/1");
|
assertEquals(response.getFlavorRef(), "http://servers.api.openstack.org/1234/flavors/1");
|
||||||
assertEquals(response.getHostId(), "e4d909c290d0fb1ca068ffaddf22cbd0");
|
assertEquals(response.getHostId(), "e4d909c290d0fb1ca068ffaddf22cbd0");
|
||||||
assertEquals(response.getStatus(), ServerStatus.BUILD);
|
assertEquals(response.getStatus(), ServerStatus.BUILD);
|
||||||
assertEquals(response.getProgress(), new Integer(60));
|
assertEquals(response.getProgress(), Integer.valueOf(60));
|
||||||
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.US);
|
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.US);
|
||||||
dateFormat.setTimeZone(new SimpleTimeZone(0, "GMT"));
|
dateFormat.setTimeZone(new SimpleTimeZone(0, "GMT"));
|
||||||
assertEquals(response.getCreated(), dateFormat.parse("2010-08-10T12:00:00Z"));
|
assertEquals(response.getCreated(), dateFormat.parse("2010-08-10T12:00:00Z"));
|
||||||
|
|
|
@ -88,7 +88,7 @@ public class ParseServerListFromJsonResponseTest {
|
||||||
assertEquals(response.get(0).getHostId(), "e4d909c290d0fb1ca068ffaddf22cbd0");
|
assertEquals(response.get(0).getHostId(), "e4d909c290d0fb1ca068ffaddf22cbd0");
|
||||||
assertEquals(response.get(0).getUuid(), "d84e2086-fc0d-11e0-8e08-2837371c69ae");
|
assertEquals(response.get(0).getUuid(), "d84e2086-fc0d-11e0-8e08-2837371c69ae");
|
||||||
assertEquals(response.get(0).getStatus(), ServerStatus.BUILD);
|
assertEquals(response.get(0).getStatus(), ServerStatus.BUILD);
|
||||||
assertEquals(response.get(0).getProgress(), new Integer(60));
|
assertEquals(response.get(0).getProgress(), Integer.valueOf(60));
|
||||||
|
|
||||||
List<Address> publicAddresses = ImmutableList.copyOf(Iterables.transform(
|
List<Address> publicAddresses = ImmutableList.copyOf(Iterables.transform(
|
||||||
ImmutableList.of("67.23.10.132", "::babe:67.23.10.132", "67.23.10.131", "::babe:4317:0A83"),
|
ImmutableList.of("67.23.10.132", "::babe:67.23.10.132", "67.23.10.131", "::babe:4317:0A83"),
|
||||||
|
|
|
@ -85,7 +85,7 @@ public class ListBucketOptions extends BaseHttpRequestOptions {
|
||||||
|
|
||||||
public Integer getMaxResults() {
|
public Integer getMaxResults() {
|
||||||
String returnVal = getFirstQueryOrNull("max-keys");
|
String returnVal = getFirstQueryOrNull("max-keys");
|
||||||
return (returnVal != null) ? new Integer(returnVal) : null;
|
return (returnVal != null) ? Integer.valueOf(returnVal) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -104,7 +104,7 @@ public class ListBucketHandler extends ParseSax.HandlerWithResult<ListBucketResp
|
||||||
builder.eTag(currentETag);
|
builder.eTag(currentETag);
|
||||||
builder.contentMD5(CryptoStreams.hex(Strings2.replaceAll(currentETag, '"', "")));
|
builder.contentMD5(CryptoStreams.hex(Strings2.replaceAll(currentETag, '"', "")));
|
||||||
} else if (qName.equals("Size")) {
|
} else if (qName.equals("Size")) {
|
||||||
builder.contentLength(new Long(currentOrNull(currentText)));
|
builder.contentLength(Long.valueOf(currentOrNull(currentText)));
|
||||||
} else if (qName.equals("Owner")) {
|
} else if (qName.equals("Owner")) {
|
||||||
builder.owner(currentOwner);
|
builder.owner(currentOwner);
|
||||||
currentOwner = null;
|
currentOwner = null;
|
||||||
|
|
|
@ -284,7 +284,7 @@ public class S3ClientLiveTest extends BaseBlobStoreIntegrationTest {
|
||||||
assertConsistencyAwareContainerSize(sourceContainer, 1);
|
assertConsistencyAwareContainerSize(sourceContainer, 1);
|
||||||
S3Object newObject = getApi().getObject(sourceContainer, key);
|
S3Object newObject = getApi().getObject(sourceContainer, key);
|
||||||
assert newObject != null;
|
assert newObject != null;
|
||||||
assertEquals(Strings2.toStringAndClose(newObject.getPayload().getInput()), TEST_STRING);
|
assertEquals(Strings2.toString(newObject.getPayload()), TEST_STRING);
|
||||||
return newObject;
|
return newObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -37,12 +37,13 @@ import org.jclouds.Constants;
|
||||||
import org.jclouds.aws.domain.Region;
|
import org.jclouds.aws.domain.Region;
|
||||||
import org.jclouds.blobstore.AsyncBlobStore;
|
import org.jclouds.blobstore.AsyncBlobStore;
|
||||||
import org.jclouds.blobstore.KeyNotFoundException;
|
import org.jclouds.blobstore.KeyNotFoundException;
|
||||||
import org.jclouds.blobstore.TransientAsyncBlobStore;
|
import org.jclouds.blobstore.LocalAsyncBlobStore;
|
||||||
import org.jclouds.blobstore.domain.Blob;
|
import org.jclouds.blobstore.domain.Blob;
|
||||||
import org.jclouds.blobstore.domain.BlobMetadata;
|
import org.jclouds.blobstore.domain.BlobMetadata;
|
||||||
import org.jclouds.blobstore.domain.MutableBlobMetadata;
|
import org.jclouds.blobstore.domain.MutableBlobMetadata;
|
||||||
import org.jclouds.blobstore.functions.HttpGetOptionsListToGetOptions;
|
import org.jclouds.blobstore.functions.HttpGetOptionsListToGetOptions;
|
||||||
import org.jclouds.blobstore.options.ListContainerOptions;
|
import org.jclouds.blobstore.options.ListContainerOptions;
|
||||||
|
import org.jclouds.blobstore.util.BlobStoreUtils;
|
||||||
import org.jclouds.concurrent.Futures;
|
import org.jclouds.concurrent.Futures;
|
||||||
import org.jclouds.date.DateService;
|
import org.jclouds.date.DateService;
|
||||||
import org.jclouds.domain.Location;
|
import org.jclouds.domain.Location;
|
||||||
|
@ -102,7 +103,7 @@ public class StubS3AsyncClient implements S3AsyncClient {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private StubS3AsyncClient(@Named(Constants.PROPERTY_USER_THREADS) ExecutorService service,
|
private StubS3AsyncClient(@Named(Constants.PROPERTY_USER_THREADS) ExecutorService service,
|
||||||
TransientAsyncBlobStore blobStore, ConcurrentMap<String, ConcurrentMap<String, Blob>> containerToBlobs,
|
LocalAsyncBlobStore blobStore, ConcurrentMap<String, ConcurrentMap<String, Blob>> containerToBlobs,
|
||||||
ConcurrentMap<String, Location> containerToLocation, DateService dateService,
|
ConcurrentMap<String, Location> containerToLocation, DateService dateService,
|
||||||
S3Object.Factory objectProvider, Blob.Factory blobProvider,
|
S3Object.Factory objectProvider, Blob.Factory blobProvider,
|
||||||
HttpGetOptionsListToGetOptions httpGetOptionsConverter, ObjectToBlob object2Blob, BlobToObject blob2Object,
|
HttpGetOptionsListToGetOptions httpGetOptionsConverter, ObjectToBlob object2Blob, BlobToObject blob2Object,
|
||||||
|
@ -157,25 +158,25 @@ public class StubS3AsyncClient implements S3AsyncClient {
|
||||||
Blob object = source.get(sourceObject);
|
Blob object = source.get(sourceObject);
|
||||||
if (options.getIfMatch() != null) {
|
if (options.getIfMatch() != null) {
|
||||||
if (!object.getMetadata().getETag().equals(options.getIfMatch()))
|
if (!object.getMetadata().getETag().equals(options.getIfMatch()))
|
||||||
return immediateFailedFuture(TransientAsyncBlobStore.returnResponseException(412));
|
return immediateFailedFuture(LocalAsyncBlobStore.returnResponseException(412));
|
||||||
}
|
}
|
||||||
if (options.getIfNoneMatch() != null) {
|
if (options.getIfNoneMatch() != null) {
|
||||||
if (object.getMetadata().getETag().equals(options.getIfNoneMatch()))
|
if (object.getMetadata().getETag().equals(options.getIfNoneMatch()))
|
||||||
return immediateFailedFuture(TransientAsyncBlobStore.returnResponseException(412));
|
return immediateFailedFuture(LocalAsyncBlobStore.returnResponseException(412));
|
||||||
}
|
}
|
||||||
if (options.getIfModifiedSince() != null) {
|
if (options.getIfModifiedSince() != null) {
|
||||||
Date modifiedSince = dateService.rfc822DateParse(options.getIfModifiedSince());
|
Date modifiedSince = dateService.rfc822DateParse(options.getIfModifiedSince());
|
||||||
if (modifiedSince.after(object.getMetadata().getLastModified()))
|
if (modifiedSince.after(object.getMetadata().getLastModified()))
|
||||||
return immediateFailedFuture(TransientAsyncBlobStore.returnResponseException(412));
|
return immediateFailedFuture(LocalAsyncBlobStore.returnResponseException(412));
|
||||||
|
|
||||||
}
|
}
|
||||||
if (options.getIfUnmodifiedSince() != null) {
|
if (options.getIfUnmodifiedSince() != null) {
|
||||||
Date unmodifiedSince = dateService.rfc822DateParse(options.getIfUnmodifiedSince());
|
Date unmodifiedSince = dateService.rfc822DateParse(options.getIfUnmodifiedSince());
|
||||||
if (unmodifiedSince.before(object.getMetadata().getLastModified()))
|
if (unmodifiedSince.before(object.getMetadata().getLastModified()))
|
||||||
return immediateFailedFuture(TransientAsyncBlobStore.returnResponseException(412));
|
return immediateFailedFuture(LocalAsyncBlobStore.returnResponseException(412));
|
||||||
}
|
}
|
||||||
Blob sourceS3 = source.get(sourceObject);
|
Blob sourceS3 = source.get(sourceObject);
|
||||||
MutableBlobMetadata newMd = TransientAsyncBlobStore.copy(sourceS3.getMetadata(), destinationObject);
|
MutableBlobMetadata newMd = BlobStoreUtils.copy(sourceS3.getMetadata(), destinationObject);
|
||||||
if (options.getAcl() != null)
|
if (options.getAcl() != null)
|
||||||
keyToAcl.put(destinationBucket + "/" + destinationObject, options.getAcl());
|
keyToAcl.put(destinationBucket + "/" + destinationObject, options.getAcl());
|
||||||
|
|
||||||
|
@ -183,7 +184,7 @@ public class StubS3AsyncClient implements S3AsyncClient {
|
||||||
Blob newBlob = blobProvider.create(newMd);
|
Blob newBlob = blobProvider.create(newMd);
|
||||||
newBlob.setPayload(sourceS3.getPayload());
|
newBlob.setPayload(sourceS3.getPayload());
|
||||||
dest.put(destinationObject, newBlob);
|
dest.put(destinationObject, newBlob);
|
||||||
return immediateFuture((ObjectMetadata) blob2ObjectMetadata.apply(TransientAsyncBlobStore.copy(newMd)));
|
return immediateFuture((ObjectMetadata) blob2ObjectMetadata.apply(BlobStoreUtils.copy(newMd)));
|
||||||
}
|
}
|
||||||
return immediateFailedFuture(new KeyNotFoundException(sourceBucket, sourceObject, sourceBucket + "/"
|
return immediateFailedFuture(new KeyNotFoundException(sourceBucket, sourceObject, sourceBucket + "/"
|
||||||
+ sourceObject));
|
+ sourceObject));
|
||||||
|
|
|
@ -164,7 +164,7 @@ public class ParallelMultipartUploadStrategy implements AsyncMultipartUploadStra
|
||||||
CountDownLatch latch = new CountDownLatch(effectiveParts);
|
CountDownLatch latch = new CountDownLatch(effectiveParts);
|
||||||
int part;
|
int part;
|
||||||
while ((part = algorithm.getNextPart()) <= parts) {
|
while ((part = algorithm.getNextPart()) <= parts) {
|
||||||
Integer partKey = new Integer(part);
|
Integer partKey = Integer.valueOf(part);
|
||||||
activeParts.put(partKey);
|
activeParts.put(partKey);
|
||||||
|
|
||||||
prepareUploadPart(container, blob, key, partKey, payload,
|
prepareUploadPart(container, blob, key, partKey, payload,
|
||||||
|
@ -173,7 +173,7 @@ public class ParallelMultipartUploadStrategy implements AsyncMultipartUploadStra
|
||||||
blob2Object);
|
blob2Object);
|
||||||
}
|
}
|
||||||
if (remaining > 0) {
|
if (remaining > 0) {
|
||||||
Integer partKey = new Integer(part);
|
Integer partKey = Integer.valueOf(part);
|
||||||
activeParts.put(partKey);
|
activeParts.put(partKey);
|
||||||
prepareUploadPart(container, blob, key, partKey, payload,
|
prepareUploadPart(container, blob, key, partKey, payload,
|
||||||
algorithm.getNextChunkOffset(), remaining, etags,
|
algorithm.getNextChunkOffset(), remaining, etags,
|
||||||
|
@ -187,7 +187,7 @@ public class ParallelMultipartUploadStrategy implements AsyncMultipartUploadStra
|
||||||
CountDownLatch retryLatch = new CountDownLatch(atOnce);
|
CountDownLatch retryLatch = new CountDownLatch(atOnce);
|
||||||
for (int i = 0; i < atOnce; i++) {
|
for (int i = 0; i < atOnce; i++) {
|
||||||
Part failedPart = toRetry.poll();
|
Part failedPart = toRetry.poll();
|
||||||
Integer partKey = new Integer(failedPart.getPart());
|
Integer partKey = Integer.valueOf(failedPart.getPart());
|
||||||
activeParts.put(partKey);
|
activeParts.put(partKey);
|
||||||
prepareUploadPart(container, blob, key, partKey, payload,
|
prepareUploadPart(container, blob, key, partKey, payload,
|
||||||
failedPart.getOffset(), failedPart.getSize(), etags,
|
failedPart.getOffset(), failedPart.getSize(), etags,
|
||||||
|
|
|
@ -57,7 +57,7 @@ public class ListContainerOptions extends BaseHttpRequestOptions {
|
||||||
|
|
||||||
public int getMaxResults() {
|
public int getMaxResults() {
|
||||||
String val = getFirstQueryOrNull("limit");
|
String val = getFirstQueryOrNull("limit");
|
||||||
return val != null ? new Integer(val) : 10000;
|
return val != null ? Integer.valueOf(val) : 10000;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -204,7 +204,7 @@ public abstract class CommonSwiftClientLiveTest<C extends CommonSwiftClient> ext
|
||||||
MutableObjectInfoWithMetadata metadata = getApi().getObjectInfo(containerName, object.getInfo().getName());
|
MutableObjectInfoWithMetadata metadata = getApi().getObjectInfo(containerName, object.getInfo().getName());
|
||||||
assertEquals(metadata.getName(), object.getInfo().getName());
|
assertEquals(metadata.getName(), object.getInfo().getName());
|
||||||
|
|
||||||
assertEquals(metadata.getBytes(), new Long(data.length()));
|
assertEquals(metadata.getBytes(), Long.valueOf(data.length()));
|
||||||
assert metadata.getContentType().startsWith("text/plain") : metadata.getContentType();
|
assert metadata.getContentType().startsWith("text/plain") : metadata.getContentType();
|
||||||
|
|
||||||
assertEquals(CryptoStreams.hex(md5), CryptoStreams.hex(metadata.getHash()));
|
assertEquals(CryptoStreams.hex(md5), CryptoStreams.hex(metadata.getHash()));
|
||||||
|
@ -222,10 +222,10 @@ public abstract class CommonSwiftClientLiveTest<C extends CommonSwiftClient> ext
|
||||||
assert getApi().getObject(containerName, "non-existent-object") == null;
|
assert getApi().getObject(containerName, "non-existent-object") == null;
|
||||||
// Test GET of object (including updated metadata)
|
// Test GET of object (including updated metadata)
|
||||||
SwiftObject getBlob = getApi().getObject(containerName, object.getInfo().getName());
|
SwiftObject getBlob = getApi().getObject(containerName, object.getInfo().getName());
|
||||||
assertEquals(Strings2.toStringAndClose(getBlob.getPayload().getInput()), data);
|
assertEquals(Strings2.toString(getBlob.getPayload()), data);
|
||||||
// TODO assertEquals(getBlob.getName(),
|
// TODO assertEquals(getBlob.getName(),
|
||||||
// object.getMetadata().getName());
|
// object.getMetadata().getName());
|
||||||
assertEquals(getBlob.getInfo().getBytes(), new Long(data.length()));
|
assertEquals(getBlob.getInfo().getBytes(), Long.valueOf(data.length()));
|
||||||
testGetObjectContentType(getBlob);
|
testGetObjectContentType(getBlob);
|
||||||
assertEquals(CryptoStreams.hex(md5), CryptoStreams.hex(getBlob.getInfo().getHash()));
|
assertEquals(CryptoStreams.hex(md5), CryptoStreams.hex(getBlob.getInfo().getHash()));
|
||||||
assertEquals(CryptoStreams.hex(newEtag), getBlob.getInfo().getHash());
|
assertEquals(CryptoStreams.hex(newEtag), getBlob.getInfo().getHash());
|
||||||
|
@ -267,7 +267,7 @@ public abstract class CommonSwiftClientLiveTest<C extends CommonSwiftClient> ext
|
||||||
GetOptions.Builder.ifETagMatches(newEtag));
|
GetOptions.Builder.ifETagMatches(newEtag));
|
||||||
assertEquals(getBlob.getInfo().getHash(), CryptoStreams.hex(newEtag));
|
assertEquals(getBlob.getInfo().getHash(), CryptoStreams.hex(newEtag));
|
||||||
getBlob = getApi().getObject(containerName, object.getInfo().getName(), GetOptions.Builder.startAt(8));
|
getBlob = getApi().getObject(containerName, object.getInfo().getName(), GetOptions.Builder.startAt(8));
|
||||||
assertEquals(Strings2.toStringAndClose(getBlob.getPayload().getInput()), data.substring(8));
|
assertEquals(Strings2.toString(getBlob.getPayload()), data.substring(8));
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
returnContainer(containerName);
|
returnContainer(containerName);
|
||||||
|
|
|
@ -33,7 +33,7 @@ import javax.inject.Named;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
import org.jclouds.Constants;
|
import org.jclouds.Constants;
|
||||||
import org.jclouds.blobstore.TransientAsyncBlobStore;
|
import org.jclouds.blobstore.LocalAsyncBlobStore;
|
||||||
import org.jclouds.blobstore.domain.BlobMetadata;
|
import org.jclouds.blobstore.domain.BlobMetadata;
|
||||||
import org.jclouds.blobstore.domain.PageSet;
|
import org.jclouds.blobstore.domain.PageSet;
|
||||||
import org.jclouds.blobstore.domain.StorageMetadata;
|
import org.jclouds.blobstore.domain.StorageMetadata;
|
||||||
|
@ -68,7 +68,7 @@ import com.google.common.util.concurrent.ListenableFuture;
|
||||||
@Singleton
|
@Singleton
|
||||||
public class StubSwiftAsyncClient implements CommonSwiftAsyncClient {
|
public class StubSwiftAsyncClient implements CommonSwiftAsyncClient {
|
||||||
private final HttpGetOptionsListToGetOptions httpGetOptionsConverter;
|
private final HttpGetOptionsListToGetOptions httpGetOptionsConverter;
|
||||||
private final TransientAsyncBlobStore blobStore;
|
private final LocalAsyncBlobStore blobStore;
|
||||||
private final SwiftObject.Factory objectProvider;
|
private final SwiftObject.Factory objectProvider;
|
||||||
private final ObjectToBlob object2Blob;
|
private final ObjectToBlob object2Blob;
|
||||||
private final BlobToObject blob2Object;
|
private final BlobToObject blob2Object;
|
||||||
|
@ -79,7 +79,7 @@ public class StubSwiftAsyncClient implements CommonSwiftAsyncClient {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private StubSwiftAsyncClient(@Named(Constants.PROPERTY_USER_THREADS) ExecutorService service,
|
private StubSwiftAsyncClient(@Named(Constants.PROPERTY_USER_THREADS) ExecutorService service,
|
||||||
TransientAsyncBlobStore blobStore,
|
LocalAsyncBlobStore blobStore,
|
||||||
SwiftObject.Factory objectProvider, HttpGetOptionsListToGetOptions httpGetOptionsConverter,
|
SwiftObject.Factory objectProvider, HttpGetOptionsListToGetOptions httpGetOptionsConverter,
|
||||||
ObjectToBlob object2Blob, BlobToObject blob2Object, ResourceToObjectInfo blob2ObjectInfo,
|
ObjectToBlob object2Blob, BlobToObject blob2Object, ResourceToObjectInfo blob2ObjectInfo,
|
||||||
ListContainerOptionsToBlobStoreListContainerOptions container2ContainerListOptions,
|
ListContainerOptionsToBlobStoreListContainerOptions container2ContainerListOptions,
|
||||||
|
|
|
@ -28,7 +28,7 @@ import org.jclouds.vcloud.features.VAppAsyncClient;
|
||||||
import org.jclouds.vcloud.features.VAppTemplateAsyncClient;
|
import org.jclouds.vcloud.features.VAppTemplateAsyncClient;
|
||||||
import org.jclouds.vcloud.features.VDCAsyncClient;
|
import org.jclouds.vcloud.features.VDCAsyncClient;
|
||||||
import org.jclouds.vcloud.features.VmAsyncClient;
|
import org.jclouds.vcloud.features.VmAsyncClient;
|
||||||
import org.jclouds.vcloud.filters.SetVCloudTokenCookie;
|
import org.jclouds.vcloud.filters.AddVCloudAuthorizationAndCookieToRequest;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides access to VCloud resources via their REST API.
|
* Provides access to VCloud resources via their REST API.
|
||||||
|
@ -38,7 +38,7 @@ import org.jclouds.vcloud.filters.SetVCloudTokenCookie;
|
||||||
* />
|
* />
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
@RequestFilters(SetVCloudTokenCookie.class)
|
@RequestFilters(AddVCloudAuthorizationAndCookieToRequest.class)
|
||||||
public interface VCloudAsyncClient {
|
public interface VCloudAsyncClient {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -42,7 +42,7 @@ import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404;
|
||||||
import org.jclouds.vcloud.binders.BindCatalogItemToXmlPayload;
|
import org.jclouds.vcloud.binders.BindCatalogItemToXmlPayload;
|
||||||
import org.jclouds.vcloud.domain.Catalog;
|
import org.jclouds.vcloud.domain.Catalog;
|
||||||
import org.jclouds.vcloud.domain.CatalogItem;
|
import org.jclouds.vcloud.domain.CatalogItem;
|
||||||
import org.jclouds.vcloud.filters.SetVCloudTokenCookie;
|
import org.jclouds.vcloud.filters.AddVCloudAuthorizationAndCookieToRequest;
|
||||||
import org.jclouds.vcloud.functions.OrgNameAndCatalogNameToEndpoint;
|
import org.jclouds.vcloud.functions.OrgNameAndCatalogNameToEndpoint;
|
||||||
import org.jclouds.vcloud.functions.OrgNameCatalogNameItemNameToEndpoint;
|
import org.jclouds.vcloud.functions.OrgNameCatalogNameItemNameToEndpoint;
|
||||||
import org.jclouds.vcloud.options.CatalogItemOptions;
|
import org.jclouds.vcloud.options.CatalogItemOptions;
|
||||||
|
@ -57,7 +57,7 @@ import com.google.common.util.concurrent.ListenableFuture;
|
||||||
*
|
*
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
@RequestFilters(SetVCloudTokenCookie.class)
|
@RequestFilters(AddVCloudAuthorizationAndCookieToRequest.class)
|
||||||
public interface CatalogAsyncClient {
|
public interface CatalogAsyncClient {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -32,7 +32,7 @@ import org.jclouds.rest.annotations.RequestFilters;
|
||||||
import org.jclouds.rest.annotations.XMLResponseParser;
|
import org.jclouds.rest.annotations.XMLResponseParser;
|
||||||
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
|
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
|
||||||
import org.jclouds.vcloud.domain.network.OrgNetwork;
|
import org.jclouds.vcloud.domain.network.OrgNetwork;
|
||||||
import org.jclouds.vcloud.filters.SetVCloudTokenCookie;
|
import org.jclouds.vcloud.filters.AddVCloudAuthorizationAndCookieToRequest;
|
||||||
import org.jclouds.vcloud.functions.OrgNameVDCNameResourceEntityNameToEndpoint;
|
import org.jclouds.vcloud.functions.OrgNameVDCNameResourceEntityNameToEndpoint;
|
||||||
import org.jclouds.vcloud.xml.OrgNetworkHandler;
|
import org.jclouds.vcloud.xml.OrgNetworkHandler;
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@ import com.google.common.util.concurrent.ListenableFuture;
|
||||||
*
|
*
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
@RequestFilters(SetVCloudTokenCookie.class)
|
@RequestFilters(AddVCloudAuthorizationAndCookieToRequest.class)
|
||||||
public interface NetworkAsyncClient {
|
public interface NetworkAsyncClient {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -37,7 +37,7 @@ import org.jclouds.vcloud.VCloudMediaType;
|
||||||
import org.jclouds.vcloud.domain.Org;
|
import org.jclouds.vcloud.domain.Org;
|
||||||
import org.jclouds.vcloud.domain.ReferenceType;
|
import org.jclouds.vcloud.domain.ReferenceType;
|
||||||
import org.jclouds.vcloud.endpoints.OrgList;
|
import org.jclouds.vcloud.endpoints.OrgList;
|
||||||
import org.jclouds.vcloud.filters.SetVCloudTokenCookie;
|
import org.jclouds.vcloud.filters.AddVCloudAuthorizationAndCookieToRequest;
|
||||||
import org.jclouds.vcloud.functions.OrgNameToEndpoint;
|
import org.jclouds.vcloud.functions.OrgNameToEndpoint;
|
||||||
import org.jclouds.vcloud.xml.OrgHandler;
|
import org.jclouds.vcloud.xml.OrgHandler;
|
||||||
import org.jclouds.vcloud.xml.OrgListHandler;
|
import org.jclouds.vcloud.xml.OrgListHandler;
|
||||||
|
@ -50,7 +50,7 @@ import com.google.common.util.concurrent.ListenableFuture;
|
||||||
*
|
*
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
@RequestFilters(SetVCloudTokenCookie.class)
|
@RequestFilters(AddVCloudAuthorizationAndCookieToRequest.class)
|
||||||
public interface OrgAsyncClient {
|
public interface OrgAsyncClient {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -36,7 +36,7 @@ import org.jclouds.rest.annotations.XMLResponseParser;
|
||||||
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
|
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
|
||||||
import org.jclouds.vcloud.domain.Task;
|
import org.jclouds.vcloud.domain.Task;
|
||||||
import org.jclouds.vcloud.domain.TasksList;
|
import org.jclouds.vcloud.domain.TasksList;
|
||||||
import org.jclouds.vcloud.filters.SetVCloudTokenCookie;
|
import org.jclouds.vcloud.filters.AddVCloudAuthorizationAndCookieToRequest;
|
||||||
import org.jclouds.vcloud.functions.OrgNameToTasksListEndpoint;
|
import org.jclouds.vcloud.functions.OrgNameToTasksListEndpoint;
|
||||||
import org.jclouds.vcloud.xml.TaskHandler;
|
import org.jclouds.vcloud.xml.TaskHandler;
|
||||||
import org.jclouds.vcloud.xml.TasksListHandler;
|
import org.jclouds.vcloud.xml.TasksListHandler;
|
||||||
|
@ -49,7 +49,7 @@ import com.google.common.util.concurrent.ListenableFuture;
|
||||||
*
|
*
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
@RequestFilters(SetVCloudTokenCookie.class)
|
@RequestFilters(AddVCloudAuthorizationAndCookieToRequest.class)
|
||||||
public interface TaskAsyncClient {
|
public interface TaskAsyncClient {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -49,7 +49,7 @@ import org.jclouds.vcloud.binders.BindDeployVAppParamsToXmlPayload;
|
||||||
import org.jclouds.vcloud.binders.BindUndeployVAppParamsToXmlPayload;
|
import org.jclouds.vcloud.binders.BindUndeployVAppParamsToXmlPayload;
|
||||||
import org.jclouds.vcloud.domain.Task;
|
import org.jclouds.vcloud.domain.Task;
|
||||||
import org.jclouds.vcloud.domain.VApp;
|
import org.jclouds.vcloud.domain.VApp;
|
||||||
import org.jclouds.vcloud.filters.SetVCloudTokenCookie;
|
import org.jclouds.vcloud.filters.AddVCloudAuthorizationAndCookieToRequest;
|
||||||
import org.jclouds.vcloud.functions.OrgNameVDCNameResourceEntityNameToEndpoint;
|
import org.jclouds.vcloud.functions.OrgNameVDCNameResourceEntityNameToEndpoint;
|
||||||
import org.jclouds.vcloud.options.CloneVAppOptions;
|
import org.jclouds.vcloud.options.CloneVAppOptions;
|
||||||
import org.jclouds.vcloud.xml.TaskHandler;
|
import org.jclouds.vcloud.xml.TaskHandler;
|
||||||
|
@ -63,7 +63,7 @@ import com.google.common.util.concurrent.ListenableFuture;
|
||||||
*
|
*
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
@RequestFilters(SetVCloudTokenCookie.class)
|
@RequestFilters(AddVCloudAuthorizationAndCookieToRequest.class)
|
||||||
public interface VAppAsyncClient {
|
public interface VAppAsyncClient {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -52,7 +52,7 @@ import org.jclouds.vcloud.binders.BindInstantiateVAppTemplateParamsToXmlPayload;
|
||||||
import org.jclouds.vcloud.domain.Task;
|
import org.jclouds.vcloud.domain.Task;
|
||||||
import org.jclouds.vcloud.domain.VApp;
|
import org.jclouds.vcloud.domain.VApp;
|
||||||
import org.jclouds.vcloud.domain.VAppTemplate;
|
import org.jclouds.vcloud.domain.VAppTemplate;
|
||||||
import org.jclouds.vcloud.filters.SetVCloudTokenCookie;
|
import org.jclouds.vcloud.filters.AddVCloudAuthorizationAndCookieToRequest;
|
||||||
import org.jclouds.vcloud.functions.OrgNameCatalogNameVAppTemplateNameToEndpoint;
|
import org.jclouds.vcloud.functions.OrgNameCatalogNameVAppTemplateNameToEndpoint;
|
||||||
import org.jclouds.vcloud.options.CaptureVAppOptions;
|
import org.jclouds.vcloud.options.CaptureVAppOptions;
|
||||||
import org.jclouds.vcloud.options.CloneVAppTemplateOptions;
|
import org.jclouds.vcloud.options.CloneVAppTemplateOptions;
|
||||||
|
@ -69,7 +69,7 @@ import com.google.common.util.concurrent.ListenableFuture;
|
||||||
*
|
*
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
@RequestFilters(SetVCloudTokenCookie.class)
|
@RequestFilters(AddVCloudAuthorizationAndCookieToRequest.class)
|
||||||
public interface VAppTemplateAsyncClient {
|
public interface VAppTemplateAsyncClient {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -32,7 +32,7 @@ import org.jclouds.rest.annotations.RequestFilters;
|
||||||
import org.jclouds.rest.annotations.XMLResponseParser;
|
import org.jclouds.rest.annotations.XMLResponseParser;
|
||||||
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
|
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
|
||||||
import org.jclouds.vcloud.domain.VDC;
|
import org.jclouds.vcloud.domain.VDC;
|
||||||
import org.jclouds.vcloud.filters.SetVCloudTokenCookie;
|
import org.jclouds.vcloud.filters.AddVCloudAuthorizationAndCookieToRequest;
|
||||||
import org.jclouds.vcloud.functions.OrgNameAndVDCNameToEndpoint;
|
import org.jclouds.vcloud.functions.OrgNameAndVDCNameToEndpoint;
|
||||||
import org.jclouds.vcloud.xml.VDCHandler;
|
import org.jclouds.vcloud.xml.VDCHandler;
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@ import com.google.common.util.concurrent.ListenableFuture;
|
||||||
*
|
*
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
@RequestFilters(SetVCloudTokenCookie.class)
|
@RequestFilters(AddVCloudAuthorizationAndCookieToRequest.class)
|
||||||
public interface VDCAsyncClient {
|
public interface VDCAsyncClient {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -54,7 +54,7 @@ import org.jclouds.vcloud.domain.GuestCustomizationSection;
|
||||||
import org.jclouds.vcloud.domain.NetworkConnectionSection;
|
import org.jclouds.vcloud.domain.NetworkConnectionSection;
|
||||||
import org.jclouds.vcloud.domain.Task;
|
import org.jclouds.vcloud.domain.Task;
|
||||||
import org.jclouds.vcloud.domain.Vm;
|
import org.jclouds.vcloud.domain.Vm;
|
||||||
import org.jclouds.vcloud.filters.SetVCloudTokenCookie;
|
import org.jclouds.vcloud.filters.AddVCloudAuthorizationAndCookieToRequest;
|
||||||
import org.jclouds.vcloud.xml.TaskHandler;
|
import org.jclouds.vcloud.xml.TaskHandler;
|
||||||
import org.jclouds.vcloud.xml.VmHandler;
|
import org.jclouds.vcloud.xml.VmHandler;
|
||||||
|
|
||||||
|
@ -66,7 +66,7 @@ import com.google.common.util.concurrent.ListenableFuture;
|
||||||
*
|
*
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
@RequestFilters(SetVCloudTokenCookie.class)
|
@RequestFilters(AddVCloudAuthorizationAndCookieToRequest.class)
|
||||||
public interface VmAsyncClient {
|
public interface VmAsyncClient {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -28,6 +28,7 @@ import org.jclouds.http.HttpRequestFilter;
|
||||||
import org.jclouds.vcloud.VCloudToken;
|
import org.jclouds.vcloud.VCloudToken;
|
||||||
|
|
||||||
import com.google.common.base.Supplier;
|
import com.google.common.base.Supplier;
|
||||||
|
import com.google.common.collect.ImmutableMultimap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds the VCloud Token to the request as a cookie
|
* Adds the VCloud Token to the request as a cookie
|
||||||
|
@ -36,17 +37,21 @@ import com.google.common.base.Supplier;
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@Singleton
|
@Singleton
|
||||||
public class SetVCloudTokenCookie implements HttpRequestFilter {
|
public class AddVCloudAuthorizationAndCookieToRequest implements HttpRequestFilter {
|
||||||
private Supplier<String> vcloudTokenProvider;
|
private Supplier<String> vcloudTokenProvider;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public SetVCloudTokenCookie(@VCloudToken Supplier<String> authTokenProvider) {
|
public AddVCloudAuthorizationAndCookieToRequest(@VCloudToken Supplier<String> authTokenProvider) {
|
||||||
this.vcloudTokenProvider = authTokenProvider;
|
this.vcloudTokenProvider = authTokenProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public HttpRequest filter(HttpRequest request) throws HttpException {
|
public HttpRequest filter(HttpRequest request) throws HttpException {
|
||||||
return request.toBuilder().replaceHeader(HttpHeaders.COOKIE, "vcloud-token=" + vcloudTokenProvider.get()).build();
|
String token = vcloudTokenProvider.get();
|
||||||
|
return request
|
||||||
|
.toBuilder()
|
||||||
|
.replaceHeaders(
|
||||||
|
ImmutableMultimap.of("x-vcloud-authorization", token, HttpHeaders.COOKIE, "vcloud-token="
|
||||||
|
+ token)).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -73,7 +73,7 @@ public class ParseVCloudErrorFromHttpResponse implements HttpErrorHandler {
|
||||||
message = error.getMessage();
|
message = error.getMessage();
|
||||||
exception = new VCloudResponseException(command, response, error);
|
exception = new VCloudResponseException(command, response, error);
|
||||||
} else {
|
} else {
|
||||||
message = Strings2.toStringAndClose(response.getPayload().getInput());
|
message = Strings2.toString(response.getPayload());
|
||||||
exception = message != null ? new HttpResponseException(command, response, message) : exception;
|
exception = message != null ? new HttpResponseException(command, response, message) : exception;
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
|
|
@ -85,7 +85,7 @@ public class NetworkConnectionSectionHandler extends ParseSax.HandlerWithResult<
|
||||||
} else if (qName.endsWith("Info")) {
|
} else if (qName.endsWith("Info")) {
|
||||||
this.info = currentOrNull();
|
this.info = currentOrNull();
|
||||||
} else if (qName.endsWith("PrimaryNetworkConnectionIndex")) {
|
} else if (qName.endsWith("PrimaryNetworkConnectionIndex")) {
|
||||||
this.primaryNetworkConnectionIndex = new Integer(currentOrNull());
|
this.primaryNetworkConnectionIndex = Integer.valueOf(currentOrNull());
|
||||||
}
|
}
|
||||||
currentText = new StringBuilder();
|
currentText = new StringBuilder();
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,7 +32,6 @@ import org.jclouds.vcloud.VCloudApiMetadata;
|
||||||
import org.jclouds.vcloud.VCloudMediaType;
|
import org.jclouds.vcloud.VCloudMediaType;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
import com.google.common.collect.ImmutableMultimap;
|
|
||||||
import com.google.common.net.HttpHeaders;
|
import com.google.common.net.HttpHeaders;
|
||||||
import com.google.inject.Module;
|
import com.google.inject.Module;
|
||||||
|
|
||||||
|
@ -52,11 +51,9 @@ public abstract class BaseVCloudComputeServiceExpectTest extends BaseRestClientE
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
// initial auth is using basic
|
// initial auth is using basic
|
||||||
protected HttpRequest version1_0LoginRequest = HttpRequest.builder().method("POST").endpoint(
|
protected HttpRequest version1_0LoginRequest = HttpRequest.builder().method("POST").endpoint(ENDPOINT + "/v1.0/login")
|
||||||
URI.create(ENDPOINT + "/v1.0/login"))
|
.addHeader(HttpHeaders.ACCEPT, VCloudMediaType.ORGLIST_XML)
|
||||||
.headers(ImmutableMultimap.<String, String> builder()
|
.addHeader(HttpHeaders.AUTHORIZATION, "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build();
|
||||||
.put(HttpHeaders.ACCEPT, VCloudMediaType.ORGLIST_XML)
|
|
||||||
.put(HttpHeaders.AUTHORIZATION, "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build()).build();
|
|
||||||
|
|
||||||
protected String sessionToken = "AtatAgvJMrwOc9pDQq4RRCRLazThpnTKJDxSVH9oB2I=";
|
protected String sessionToken = "AtatAgvJMrwOc9pDQq4RRCRLazThpnTKJDxSVH9oB2I=";
|
||||||
|
|
||||||
|
@ -64,18 +61,16 @@ public abstract class BaseVCloudComputeServiceExpectTest extends BaseRestClientE
|
||||||
// NOTE: vCloud Director 1.5 returns ;version=1.0 on responses to requests made in 1.0 format.
|
// NOTE: vCloud Director 1.5 returns ;version=1.0 on responses to requests made in 1.0 format.
|
||||||
protected HttpResponse successfulVersion1_0LoginResponseFromVCD1_5WithSingleOrg = HttpResponse.builder().statusCode(200)
|
protected HttpResponse successfulVersion1_0LoginResponseFromVCD1_5WithSingleOrg = HttpResponse.builder().statusCode(200)
|
||||||
.message("HTTP/1.1 200 OK").payload(payloadFromResourceWithContentType("/orgList1.0-vcd15.xml", VCloudMediaType.ORGLIST_XML +";version=1.0"))
|
.message("HTTP/1.1 200 OK").payload(payloadFromResourceWithContentType("/orgList1.0-vcd15.xml", VCloudMediaType.ORGLIST_XML +";version=1.0"))
|
||||||
.headers(ImmutableMultimap.<String, String> builder()
|
.addHeader("x-vcloud-authorization", sessionToken)
|
||||||
.put("x-vcloud-authorization", sessionToken)
|
.addHeader(HttpHeaders.SET_COOKIE, String.format("vcloud-token=%s; Secure; Path=/", sessionToken)).build();
|
||||||
.put(HttpHeaders.SET_COOKIE, String.format("vcloud-token=%s; Secure; Path=/", sessionToken)).build()).build();
|
|
||||||
|
|
||||||
// objects are looked up by id and the format of the id is hex-hyphen
|
// objects are looked up by id and the format of the id is hex-hyphen
|
||||||
protected String orgId = "c076f90a-397a-49fa-89b8-b294c1599cd0";
|
protected String orgId = "c076f90a-397a-49fa-89b8-b294c1599cd0";
|
||||||
|
|
||||||
protected HttpRequest version1_0GetOrgRequest = HttpRequest.builder().method("GET").endpoint(
|
protected HttpRequest version1_0GetOrgRequest = HttpRequest.builder().method("GET").endpoint(ENDPOINT + "/v1.0/org/" + orgId)
|
||||||
URI.create(ENDPOINT + "/v1.0/org/" + orgId))
|
.addHeader(HttpHeaders.ACCEPT, VCloudMediaType.ORG_XML)
|
||||||
.headers(ImmutableMultimap.<String, String> builder()
|
.addHeader("x-vcloud-authorization", sessionToken)
|
||||||
.put(HttpHeaders.ACCEPT, VCloudMediaType.ORG_XML)
|
.addHeader(HttpHeaders.COOKIE, "vcloud-token=" + sessionToken).build();
|
||||||
.put(HttpHeaders.COOKIE, "vcloud-token=" + sessionToken).build()).build();
|
|
||||||
|
|
||||||
protected HttpResponse successfulVersion1_0GetOrgResponseFromVCD1_5WithSingleTasksListVDCAndNetwork = HttpResponse.builder().statusCode(200)
|
protected HttpResponse successfulVersion1_0GetOrgResponseFromVCD1_5WithSingleTasksListVDCAndNetwork = HttpResponse.builder().statusCode(200)
|
||||||
.message("HTTP/1.1 200 OK").payload(payloadFromResourceWithContentType("/org1.0-vcd15.xml", VCloudMediaType.ORG_XML +";version=1.0"))
|
.message("HTTP/1.1 200 OK").payload(payloadFromResourceWithContentType("/org1.0-vcd15.xml", VCloudMediaType.ORG_XML +";version=1.0"))
|
||||||
|
@ -84,11 +79,10 @@ public abstract class BaseVCloudComputeServiceExpectTest extends BaseRestClientE
|
||||||
protected String catalogId = "3155f393-1e1d-4572-8c9c-d76f72ddb658";
|
protected String catalogId = "3155f393-1e1d-4572-8c9c-d76f72ddb658";
|
||||||
protected String vdcId = "e9cd3387-ac57-4d27-a481-9bee75e0690f";
|
protected String vdcId = "e9cd3387-ac57-4d27-a481-9bee75e0690f";
|
||||||
|
|
||||||
protected HttpRequest version1_0GetCatalogRequest = HttpRequest.builder().method("GET").endpoint(
|
protected HttpRequest version1_0GetCatalogRequest = HttpRequest.builder().method("GET").endpoint(ENDPOINT + "/v1.0/catalog/" + catalogId)
|
||||||
URI.create(ENDPOINT + "/v1.0/catalog/" + catalogId))
|
.addHeader(HttpHeaders.ACCEPT, VCloudMediaType.CATALOG_XML)
|
||||||
.headers(ImmutableMultimap.<String, String> builder()
|
.addHeader("x-vcloud-authorization", sessionToken)
|
||||||
.put(HttpHeaders.ACCEPT, VCloudMediaType.CATALOG_XML)
|
.addHeader(HttpHeaders.COOKIE, "vcloud-token=" + sessionToken).build();
|
||||||
.put(HttpHeaders.COOKIE, "vcloud-token=" + sessionToken).build()).build();
|
|
||||||
|
|
||||||
protected HttpResponse successfulVersion1_0GetCatalogResponseFromVCD1_5WithSingleTemplate = HttpResponse.builder().statusCode(200)
|
protected HttpResponse successfulVersion1_0GetCatalogResponseFromVCD1_5WithSingleTemplate = HttpResponse.builder().statusCode(200)
|
||||||
.message("HTTP/1.1 200 OK").payload(payloadFromResourceWithContentType("/catalog1.0-vcd15.xml", VCloudMediaType.CATALOG_XML +";version=1.0"))
|
.message("HTTP/1.1 200 OK").payload(payloadFromResourceWithContentType("/catalog1.0-vcd15.xml", VCloudMediaType.CATALOG_XML +";version=1.0"))
|
||||||
|
@ -96,11 +90,10 @@ public abstract class BaseVCloudComputeServiceExpectTest extends BaseRestClientE
|
||||||
|
|
||||||
protected String catalogItemId = "ceb369f7-1d07-4e32-9dbd-ebb5aa6ca55c";
|
protected String catalogItemId = "ceb369f7-1d07-4e32-9dbd-ebb5aa6ca55c";
|
||||||
|
|
||||||
protected HttpRequest version1_0GetCatalogItemRequest = HttpRequest.builder().method("GET").endpoint(
|
protected HttpRequest version1_0GetCatalogItemRequest = HttpRequest.builder().method("GET").endpoint(ENDPOINT + "/v1.0/catalogItem/" + catalogItemId)
|
||||||
URI.create(ENDPOINT + "/v1.0/catalogItem/" + catalogItemId))
|
.addHeader(HttpHeaders.ACCEPT, VCloudMediaType.CATALOGITEM_XML)
|
||||||
.headers(ImmutableMultimap.<String, String> builder()
|
.addHeader("x-vcloud-authorization", sessionToken)
|
||||||
.put(HttpHeaders.ACCEPT, VCloudMediaType.CATALOGITEM_XML)
|
.addHeader(HttpHeaders.COOKIE, "vcloud-token=" + sessionToken).build();
|
||||||
.put(HttpHeaders.COOKIE, "vcloud-token=" + sessionToken).build()).build();
|
|
||||||
|
|
||||||
protected HttpResponse successfulVersion1_0GetCatalogItemResponseFromVCD1_5ForTemplate = HttpResponse.builder().statusCode(200)
|
protected HttpResponse successfulVersion1_0GetCatalogItemResponseFromVCD1_5ForTemplate = HttpResponse.builder().statusCode(200)
|
||||||
.message("HTTP/1.1 200 OK").payload(payloadFromResourceWithContentType("/catalogItem1.0-vcd15.xml", VCloudMediaType.CATALOGITEM_XML +";version=1.0"))
|
.message("HTTP/1.1 200 OK").payload(payloadFromResourceWithContentType("/catalogItem1.0-vcd15.xml", VCloudMediaType.CATALOGITEM_XML +";version=1.0"))
|
||||||
|
@ -109,11 +102,10 @@ public abstract class BaseVCloudComputeServiceExpectTest extends BaseRestClientE
|
||||||
// note vAppTemplate has a prefix in its id
|
// note vAppTemplate has a prefix in its id
|
||||||
protected String templateId = "vappTemplate-51891b97-c5dd-47dc-a687-aabae354f728";
|
protected String templateId = "vappTemplate-51891b97-c5dd-47dc-a687-aabae354f728";
|
||||||
|
|
||||||
protected HttpRequest version1_0GetVDCRequest = HttpRequest.builder().method("GET").endpoint(
|
protected HttpRequest version1_0GetVDCRequest = HttpRequest.builder().method("GET").endpoint(ENDPOINT + "/v1.0/vdc/" + vdcId)
|
||||||
URI.create(ENDPOINT + "/v1.0/vdc/" + vdcId))
|
.addHeader(HttpHeaders.ACCEPT, VCloudMediaType.VDC_XML)
|
||||||
.headers(ImmutableMultimap.<String, String> builder()
|
.addHeader("x-vcloud-authorization", sessionToken)
|
||||||
.put(HttpHeaders.ACCEPT, VCloudMediaType.VDC_XML)
|
.addHeader(HttpHeaders.COOKIE, "vcloud-token=" + sessionToken).build();
|
||||||
.put(HttpHeaders.COOKIE, "vcloud-token=" + sessionToken).build()).build();
|
|
||||||
|
|
||||||
protected HttpResponse successfulVersion1_0GetVDCResponseFromVCD1_5WithSingleTemplateAndNetwork = HttpResponse.builder().statusCode(200)
|
protected HttpResponse successfulVersion1_0GetVDCResponseFromVCD1_5WithSingleTemplateAndNetwork = HttpResponse.builder().statusCode(200)
|
||||||
.message("HTTP/1.1 200 OK").payload(payloadFromResourceWithContentType("/vdc1.0-vcd15.xml", VCloudMediaType.VDC_XML +";version=1.0"))
|
.message("HTTP/1.1 200 OK").payload(payloadFromResourceWithContentType("/vdc1.0-vcd15.xml", VCloudMediaType.VDC_XML +";version=1.0"))
|
||||||
|
@ -121,11 +113,10 @@ public abstract class BaseVCloudComputeServiceExpectTest extends BaseRestClientE
|
||||||
|
|
||||||
protected String networkId = "b466c0c5-8a5c-4335-b703-a2e2e6b5f3e1";
|
protected String networkId = "b466c0c5-8a5c-4335-b703-a2e2e6b5f3e1";
|
||||||
|
|
||||||
protected HttpRequest version1_0GetVAppTemplateRequest = HttpRequest.builder().method("GET").endpoint(
|
protected HttpRequest version1_0GetVAppTemplateRequest = HttpRequest.builder().method("GET").endpoint(ENDPOINT + "/v1.0/vAppTemplate/" + templateId)
|
||||||
URI.create(ENDPOINT + "/v1.0/vAppTemplate/" + templateId))
|
.addHeader(HttpHeaders.ACCEPT, VCloudMediaType.VAPPTEMPLATE_XML)
|
||||||
.headers(ImmutableMultimap.<String, String> builder()
|
.addHeader("x-vcloud-authorization", sessionToken)
|
||||||
.put(HttpHeaders.ACCEPT, VCloudMediaType.VAPPTEMPLATE_XML)
|
.addHeader(HttpHeaders.COOKIE, "vcloud-token=" + sessionToken).build();
|
||||||
.put(HttpHeaders.COOKIE, "vcloud-token=" + sessionToken).build()).build();
|
|
||||||
|
|
||||||
protected HttpResponse successfulVersion1_0GetVAppTemplateResponseFromVCD1_5WithSingleVMAndVDCParent = HttpResponse.builder().statusCode(200)
|
protected HttpResponse successfulVersion1_0GetVAppTemplateResponseFromVCD1_5WithSingleVMAndVDCParent = HttpResponse.builder().statusCode(200)
|
||||||
.message("HTTP/1.1 200 OK").payload(payloadFromResourceWithContentType("/template1.0-vcd15.xml", VCloudMediaType.VAPPTEMPLATE_XML +";version=1.0"))
|
.message("HTTP/1.1 200 OK").payload(payloadFromResourceWithContentType("/template1.0-vcd15.xml", VCloudMediaType.VAPPTEMPLATE_XML +";version=1.0"))
|
||||||
|
@ -135,11 +126,10 @@ public abstract class BaseVCloudComputeServiceExpectTest extends BaseRestClientE
|
||||||
.message("HTTP/1.1 200 OK").payload(payloadFromResourceWithContentType("/template1.0-vcd15-multi-vm.xml", VCloudMediaType.VAPPTEMPLATE_XML +";version=1.0"))
|
.message("HTTP/1.1 200 OK").payload(payloadFromResourceWithContentType("/template1.0-vcd15-multi-vm.xml", VCloudMediaType.VAPPTEMPLATE_XML +";version=1.0"))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
protected HttpRequest version1_0GetOVFForVAppTemplateRequest = HttpRequest.builder().method("GET").endpoint(
|
protected HttpRequest version1_0GetOVFForVAppTemplateRequest = HttpRequest.builder().method("GET").endpoint(ENDPOINT + "/v1.0/vAppTemplate/" + templateId + "/ovf")
|
||||||
URI.create(ENDPOINT + "/v1.0/vAppTemplate/" + templateId + "/ovf"))
|
.addHeader(HttpHeaders.ACCEPT, MediaType.TEXT_XML)
|
||||||
.headers(ImmutableMultimap.<String, String> builder()
|
.addHeader("x-vcloud-authorization", sessionToken)
|
||||||
.put(HttpHeaders.ACCEPT, MediaType.TEXT_XML)
|
.addHeader(HttpHeaders.COOKIE, "vcloud-token=" + sessionToken).build();
|
||||||
.put(HttpHeaders.COOKIE, "vcloud-token=" + sessionToken).build()).build();
|
|
||||||
|
|
||||||
protected HttpResponse successfulVersion1_0GetOVFForVAppTemplateResponseFromVCD1_5WithSingleVM = HttpResponse.builder().statusCode(200)
|
protected HttpResponse successfulVersion1_0GetOVFForVAppTemplateResponseFromVCD1_5WithSingleVM = HttpResponse.builder().statusCode(200)
|
||||||
.message("HTTP/1.1 200 OK").payload(payloadFromResourceWithContentType("/ovf-ubuntu64.xml", MediaType.TEXT_XML +";version=1.0"))
|
.message("HTTP/1.1 200 OK").payload(payloadFromResourceWithContentType("/ovf-ubuntu64.xml", MediaType.TEXT_XML +";version=1.0"))
|
||||||
|
|
|
@ -86,10 +86,10 @@ public class InstantiateVAppTemplateWithGroupEncodedIntoNameThenCustomizeDeployA
|
||||||
.e("AllEULAsAccepted").t("true").up()
|
.e("AllEULAsAccepted").t("true").up()
|
||||||
.asString(outputProperties);
|
.asString(outputProperties);
|
||||||
|
|
||||||
HttpRequest version1_0InstantiateWithNetworkNamedSameAsOrgNetwork = HttpRequest.builder()
|
HttpRequest version1_0InstantiateWithNetworkNamedSameAsOrgNetwork = HttpRequest.builder().method("POST")
|
||||||
.method("POST")
|
|
||||||
.endpoint(ENDPOINT + "/v1.0/vdc/" + vdcId + "/action/instantiateVAppTemplate")
|
.endpoint(ENDPOINT + "/v1.0/vdc/" + vdcId + "/action/instantiateVAppTemplate")
|
||||||
.addHeader(HttpHeaders.ACCEPT, "application/vnd.vmware.vcloud.vApp+xml")
|
.addHeader(HttpHeaders.ACCEPT, "application/vnd.vmware.vcloud.vApp+xml")
|
||||||
|
.addHeader("x-vcloud-authorization", sessionToken)
|
||||||
.addHeader(HttpHeaders.COOKIE, "vcloud-token=" + sessionToken)
|
.addHeader(HttpHeaders.COOKIE, "vcloud-token=" + sessionToken)
|
||||||
.payload(payloadFromStringWithContentType(instantiateXML, "application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml")).build();
|
.payload(payloadFromStringWithContentType(instantiateXML, "application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml")).build();
|
||||||
|
|
||||||
|
@ -143,10 +143,10 @@ public class InstantiateVAppTemplateWithGroupEncodedIntoNameThenCustomizeDeployA
|
||||||
.e("AllEULAsAccepted").t("true").up()
|
.e("AllEULAsAccepted").t("true").up()
|
||||||
.asString(outputProperties);
|
.asString(outputProperties);
|
||||||
|
|
||||||
HttpRequest version1_0InstantiateWithCustomizedNetwork = HttpRequest.builder()
|
HttpRequest version1_0InstantiateWithCustomizedNetwork = HttpRequest.builder().method("POST")
|
||||||
.method("POST")
|
|
||||||
.endpoint(ENDPOINT + "/v1.0/vdc/" + vdcId + "/action/instantiateVAppTemplate")
|
.endpoint(ENDPOINT + "/v1.0/vdc/" + vdcId + "/action/instantiateVAppTemplate")
|
||||||
.addHeader(HttpHeaders.ACCEPT, "application/vnd.vmware.vcloud.vApp+xml")
|
.addHeader(HttpHeaders.ACCEPT, "application/vnd.vmware.vcloud.vApp+xml")
|
||||||
|
.addHeader("x-vcloud-authorization", sessionToken)
|
||||||
.addHeader(HttpHeaders.COOKIE, "vcloud-token=" + sessionToken)
|
.addHeader(HttpHeaders.COOKIE, "vcloud-token=" + sessionToken)
|
||||||
.payload(payloadFromStringWithContentType(instantiateXML, "application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml")).build();
|
.payload(payloadFromStringWithContentType(instantiateXML, "application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml")).build();
|
||||||
|
|
||||||
|
|
|
@ -31,14 +31,14 @@ import com.google.common.base.Supplier;
|
||||||
/**
|
/**
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test(testName = "AddVCloudAuthorizationAndCookieToRequestTest")
|
||||||
public class SetVCloudTokenCookieTest {
|
public class AddVCloudAuthorizationAndCookieToRequestTest {
|
||||||
|
|
||||||
private SetVCloudTokenCookie filter;
|
private AddVCloudAuthorizationAndCookieToRequest filter;
|
||||||
|
|
||||||
@BeforeTest
|
@BeforeTest
|
||||||
void setUp() {
|
void setUp() {
|
||||||
filter = new SetVCloudTokenCookie(new Supplier<String>() {
|
filter = new AddVCloudAuthorizationAndCookieToRequest(new Supplier<String>() {
|
||||||
public String get() {
|
public String get() {
|
||||||
return "token";
|
return "token";
|
||||||
}
|
}
|
||||||
|
@ -49,9 +49,9 @@ public class SetVCloudTokenCookieTest {
|
||||||
public void testApply() {
|
public void testApply() {
|
||||||
HttpRequest request = HttpRequest.builder().method("GET").endpoint("http://localhost").build();
|
HttpRequest request = HttpRequest.builder().method("GET").endpoint("http://localhost").build();
|
||||||
request = filter.filter(request);
|
request = filter.filter(request);
|
||||||
assertEquals(request.getHeaders().size(), 1);
|
assertEquals(request.getHeaders().size(), 2);
|
||||||
assertEquals(request.getFirstHeaderOrNull(HttpHeaders.COOKIE), "vcloud-token=token");
|
assertEquals(request.getFirstHeaderOrNull(HttpHeaders.COOKIE), "vcloud-token=token");
|
||||||
|
assertEquals(request.getFirstHeaderOrNull("x-vcloud-authorization"), "token");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -55,7 +55,7 @@ import org.jclouds.vcloud.domain.internal.CatalogItemImpl;
|
||||||
import org.jclouds.vcloud.domain.internal.OrgImpl;
|
import org.jclouds.vcloud.domain.internal.OrgImpl;
|
||||||
import org.jclouds.vcloud.domain.internal.ReferenceTypeImpl;
|
import org.jclouds.vcloud.domain.internal.ReferenceTypeImpl;
|
||||||
import org.jclouds.vcloud.domain.internal.VDCImpl;
|
import org.jclouds.vcloud.domain.internal.VDCImpl;
|
||||||
import org.jclouds.vcloud.filters.SetVCloudTokenCookie;
|
import org.jclouds.vcloud.filters.AddVCloudAuthorizationAndCookieToRequest;
|
||||||
import org.jclouds.vcloud.xml.VAppTemplateHandlerTest;
|
import org.jclouds.vcloud.xml.VAppTemplateHandlerTest;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
@ -82,7 +82,7 @@ public abstract class BaseVCloudAsyncClientTest<T> extends BaseAsyncClientTest<T
|
||||||
@Override
|
@Override
|
||||||
protected void checkFilters(HttpRequest request) {
|
protected void checkFilters(HttpRequest request) {
|
||||||
assertEquals(request.getFilters().size(), 1);
|
assertEquals(request.getFilters().size(), 1);
|
||||||
assertEquals(request.getFilters().get(0).getClass(), SetVCloudTokenCookie.class);
|
assertEquals(request.getFilters().get(0).getClass(), AddVCloudAuthorizationAndCookieToRequest.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -55,18 +55,18 @@ public class GuestCustomizationSectionHandlerTest extends BaseHandlerTest {
|
||||||
assertEquals(result.getHref(),
|
assertEquals(result.getHref(),
|
||||||
URI.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/vm-2087535248/guestCustomizationSection/"));
|
URI.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/vm-2087535248/guestCustomizationSection/"));
|
||||||
assertEquals(result.getInfo(), "Specifies Guest OS Customization Settings");
|
assertEquals(result.getInfo(), "Specifies Guest OS Customization Settings");
|
||||||
assertEquals(result.isEnabled(), new Boolean(true));
|
assertEquals(result.isEnabled(), Boolean.TRUE);
|
||||||
assertEquals(result.shouldChangeSid(), new Boolean(false));
|
assertEquals(result.shouldChangeSid(), Boolean.FALSE);
|
||||||
assertEquals(result.getVirtualMachineId(), "2087535248");
|
assertEquals(result.getVirtualMachineId(), "2087535248");
|
||||||
assertEquals(result.isJoinDomainEnabled(), new Boolean(false));
|
assertEquals(result.isJoinDomainEnabled(), Boolean.FALSE);
|
||||||
assertEquals(result.useOrgSettings(), new Boolean(false));
|
assertEquals(result.useOrgSettings(), Boolean.FALSE);
|
||||||
assertEquals(result.getDomainName(), null);
|
assertEquals(result.getDomainName(), null);
|
||||||
assertEquals(result.getDomainUserName(), null);
|
assertEquals(result.getDomainUserName(), null);
|
||||||
assertEquals(result.getDomainUserPassword(), null);
|
assertEquals(result.getDomainUserPassword(), null);
|
||||||
assertEquals(result.isAdminPasswordEnabled(), new Boolean(true));
|
assertEquals(result.isAdminPasswordEnabled(), Boolean.TRUE);
|
||||||
assertEquals(result.isAdminPasswordAuto(), new Boolean(true));
|
assertEquals(result.isAdminPasswordAuto(), Boolean.TRUE);
|
||||||
assertEquals(result.getAdminPassword(), null);
|
assertEquals(result.getAdminPassword(), null);
|
||||||
assertEquals(result.isResetPasswordRequired(), new Boolean(false));
|
assertEquals(result.isResetPasswordRequired(), Boolean.FALSE);
|
||||||
assertEquals(result.getCustomizationScript(), "cat > /root/foo.txt<<EOF\nI '\"love\"' {asc|!}*&\nEOF\n");
|
assertEquals(result.getCustomizationScript(), "cat > /root/foo.txt<<EOF\nI '\"love\"' {asc|!}*&\nEOF\n");
|
||||||
assertEquals(result.getComputerName(), "RHEL5");
|
assertEquals(result.getComputerName(), "RHEL5");
|
||||||
assertEquals(
|
assertEquals(
|
||||||
|
|
|
@ -57,7 +57,7 @@ public class NetworkConnectionSectionHandlerTest {
|
||||||
.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/vm-2087535248/networkConnectionSection/"));
|
.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/vm-2087535248/networkConnectionSection/"));
|
||||||
assertEquals(result.getType(), VCloudMediaType.NETWORKCONNECTIONSECTION_XML);
|
assertEquals(result.getType(), VCloudMediaType.NETWORKCONNECTIONSECTION_XML);
|
||||||
assertEquals(result.getInfo(), "Specifies the available VM network connections");
|
assertEquals(result.getInfo(), "Specifies the available VM network connections");
|
||||||
assertEquals(result.getPrimaryNetworkConnectionIndex(), new Integer(0));
|
assertEquals(result.getPrimaryNetworkConnectionIndex(), Integer.valueOf(0));
|
||||||
assertEquals(result.getEdit(), new ReferenceTypeImpl(null, VCloudMediaType.NETWORKCONNECTIONSECTION_XML, URI
|
assertEquals(result.getEdit(), new ReferenceTypeImpl(null, VCloudMediaType.NETWORKCONNECTIONSECTION_XML, URI
|
||||||
.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/vm-2087535248/networkConnectionSection/")));
|
.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/vm-2087535248/networkConnectionSection/")));
|
||||||
NetworkConnectionHandlerTest.checkNetworkConnection(Iterables.getOnlyElement(result.getConnections()));
|
NetworkConnectionHandlerTest.checkNetworkConnection(Iterables.getOnlyElement(result.getConnections()));
|
||||||
|
|
|
@ -86,18 +86,18 @@ public class VAppTemplateHandlerTest {
|
||||||
URI
|
URI
|
||||||
.create("https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/vm-172837194/guestCustomizationSection/"));
|
.create("https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/vm-172837194/guestCustomizationSection/"));
|
||||||
assertEquals(guestC.getInfo(), "Specifies Guest OS Customization Settings");
|
assertEquals(guestC.getInfo(), "Specifies Guest OS Customization Settings");
|
||||||
assertEquals(guestC.isEnabled(), new Boolean(true));
|
assertEquals(guestC.isEnabled(), Boolean.TRUE);
|
||||||
assertEquals(guestC.shouldChangeSid(), new Boolean(false));
|
assertEquals(guestC.shouldChangeSid(), Boolean.FALSE);
|
||||||
assertEquals(guestC.getVirtualMachineId(), "172837194");
|
assertEquals(guestC.getVirtualMachineId(), "172837194");
|
||||||
assertEquals(guestC.isJoinDomainEnabled(), new Boolean(false));
|
assertEquals(guestC.isJoinDomainEnabled(), Boolean.FALSE);
|
||||||
assertEquals(guestC.useOrgSettings(), new Boolean(false));
|
assertEquals(guestC.useOrgSettings(), Boolean.FALSE);
|
||||||
assertEquals(guestC.getDomainName(), null);
|
assertEquals(guestC.getDomainName(), null);
|
||||||
assertEquals(guestC.getDomainUserName(), null);
|
assertEquals(guestC.getDomainUserName(), null);
|
||||||
assertEquals(guestC.getDomainUserPassword(), null);
|
assertEquals(guestC.getDomainUserPassword(), null);
|
||||||
assertEquals(guestC.isAdminPasswordEnabled(), new Boolean(true));
|
assertEquals(guestC.isAdminPasswordEnabled(), Boolean.TRUE);
|
||||||
assertEquals(guestC.isAdminPasswordAuto(), new Boolean(true));
|
assertEquals(guestC.isAdminPasswordAuto(), Boolean.TRUE);
|
||||||
assertEquals(guestC.getAdminPassword(), "%3eD%gmF");
|
assertEquals(guestC.getAdminPassword(), "%3eD%gmF");
|
||||||
assertEquals(guestC.isResetPasswordRequired(), new Boolean(false));
|
assertEquals(guestC.isResetPasswordRequired(), Boolean.FALSE);
|
||||||
assertEquals(
|
assertEquals(
|
||||||
guestC.getCustomizationScript(),
|
guestC.getCustomizationScript(),
|
||||||
"#!/bin/bash if [ \"$1\" = \"postcustomization\" ]; then echo \"post customization\" touch /root/.postcustomization sleep 30 #regenerate keys /bin/rm /etc/ssh/ssh_host_* /usr/sbin/dpkg-reconfigure openssh-server echo \"completed\" fi");
|
"#!/bin/bash if [ \"$1\" = \"postcustomization\" ]; then echo \"post customization\" touch /root/.postcustomization sleep 30 #regenerate keys /bin/rm /etc/ssh/ssh_host_* /usr/sbin/dpkg-reconfigure openssh-server echo \"completed\" fi");
|
||||||
|
|
|
@ -55,7 +55,7 @@ public class VCloudOperatingSystemSectionHandlerTest extends BaseHandlerTest {
|
||||||
assertEquals(result.getEdit(), new ReferenceTypeImpl(null,
|
assertEquals(result.getEdit(), new ReferenceTypeImpl(null,
|
||||||
"application/vnd.vmware.vcloud.operatingSystemSection+xml",
|
"application/vnd.vmware.vcloud.operatingSystemSection+xml",
|
||||||
URI.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/vm-2087535248/operatingSystemSection/")));
|
URI.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/vm-2087535248/operatingSystemSection/")));
|
||||||
assertEquals(result.getId(), new Integer(80));
|
assertEquals(result.getId(), Integer.valueOf(80));
|
||||||
assertEquals(result.getVmwOsType(), "rhel5_64Guest");
|
assertEquals(result.getVmwOsType(), "rhel5_64Guest");
|
||||||
assertEquals(result.getType(), "application/vnd.vmware.vcloud.operatingSystemSection+xml");
|
assertEquals(result.getType(), "application/vnd.vmware.vcloud.operatingSystemSection+xml");
|
||||||
assertEquals(result.getInfo(), "Specifies the operating system installed");
|
assertEquals(result.getInfo(), "Specifies the operating system installed");
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
* specific language governing permissions and limitations
|
* specific language governing permissions and limitations
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
package org.jclouds.filesystem;
|
package org.jclouds.blobstore;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
import static com.google.common.base.Preconditions.checkState;
|
import static com.google.common.base.Preconditions.checkState;
|
||||||
|
@ -26,24 +26,15 @@ import static com.google.common.collect.Iterables.filter;
|
||||||
import static com.google.common.collect.Iterables.find;
|
import static com.google.common.collect.Iterables.find;
|
||||||
import static com.google.common.collect.Iterables.size;
|
import static com.google.common.collect.Iterables.size;
|
||||||
import static com.google.common.collect.Iterables.transform;
|
import static com.google.common.collect.Iterables.transform;
|
||||||
import static com.google.common.collect.Maps.newHashMap;
|
|
||||||
import static com.google.common.collect.Sets.filter;
|
import static com.google.common.collect.Sets.filter;
|
||||||
import static com.google.common.collect.Sets.newTreeSet;
|
import static com.google.common.collect.Sets.newTreeSet;
|
||||||
import static com.google.common.io.ByteStreams.toByteArray;
|
import static com.google.common.io.ByteStreams.toByteArray;
|
||||||
import static com.google.common.util.concurrent.Futures.immediateFailedFuture;
|
import static com.google.common.util.concurrent.Futures.immediateFailedFuture;
|
||||||
import static com.google.common.util.concurrent.Futures.immediateFuture;
|
import static com.google.common.util.concurrent.Futures.immediateFuture;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.ObjectInput;
|
|
||||||
import java.io.ObjectInputStream;
|
|
||||||
import java.io.ObjectOutput;
|
|
||||||
import java.io.ObjectOutputStream;
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Map.Entry;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.SortedSet;
|
import java.util.SortedSet;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
|
@ -51,13 +42,8 @@ import java.util.concurrent.ExecutorService;
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
import javax.ws.rs.Path;
|
|
||||||
import javax.ws.rs.PathParam;
|
|
||||||
|
|
||||||
import org.jclouds.Constants;
|
import org.jclouds.Constants;
|
||||||
import org.jclouds.blobstore.BlobStoreContext;
|
|
||||||
import org.jclouds.blobstore.ContainerNotFoundException;
|
|
||||||
import org.jclouds.blobstore.KeyNotFoundException;
|
|
||||||
import org.jclouds.blobstore.domain.Blob;
|
import org.jclouds.blobstore.domain.Blob;
|
||||||
import org.jclouds.blobstore.domain.Blob.Factory;
|
import org.jclouds.blobstore.domain.Blob.Factory;
|
||||||
import org.jclouds.blobstore.domain.BlobMetadata;
|
import org.jclouds.blobstore.domain.BlobMetadata;
|
||||||
|
@ -68,21 +54,16 @@ import org.jclouds.blobstore.domain.StorageMetadata;
|
||||||
import org.jclouds.blobstore.domain.StorageType;
|
import org.jclouds.blobstore.domain.StorageType;
|
||||||
import org.jclouds.blobstore.domain.internal.MutableStorageMetadataImpl;
|
import org.jclouds.blobstore.domain.internal.MutableStorageMetadataImpl;
|
||||||
import org.jclouds.blobstore.domain.internal.PageSetImpl;
|
import org.jclouds.blobstore.domain.internal.PageSetImpl;
|
||||||
import org.jclouds.blobstore.functions.HttpGetOptionsListToGetOptions;
|
|
||||||
import org.jclouds.blobstore.internal.BaseAsyncBlobStore;
|
import org.jclouds.blobstore.internal.BaseAsyncBlobStore;
|
||||||
import org.jclouds.blobstore.options.CreateContainerOptions;
|
import org.jclouds.blobstore.options.CreateContainerOptions;
|
||||||
import org.jclouds.blobstore.options.GetOptions;
|
import org.jclouds.blobstore.options.GetOptions;
|
||||||
import org.jclouds.blobstore.options.ListContainerOptions;
|
import org.jclouds.blobstore.options.ListContainerOptions;
|
||||||
import org.jclouds.blobstore.options.PutOptions;
|
import org.jclouds.blobstore.options.PutOptions;
|
||||||
import org.jclouds.blobstore.strategy.IfDirectoryReturnNameStrategy;
|
import org.jclouds.blobstore.strategy.IfDirectoryReturnNameStrategy;
|
||||||
|
import org.jclouds.blobstore.util.BlobStoreUtils;
|
||||||
import org.jclouds.blobstore.util.BlobUtils;
|
import org.jclouds.blobstore.util.BlobUtils;
|
||||||
import org.jclouds.collect.Memoized;
|
import org.jclouds.collect.Memoized;
|
||||||
import org.jclouds.crypto.Crypto;
|
|
||||||
import org.jclouds.crypto.CryptoStreams;
|
|
||||||
import org.jclouds.date.DateService;
|
|
||||||
import org.jclouds.domain.Location;
|
import org.jclouds.domain.Location;
|
||||||
import org.jclouds.filesystem.predicates.validators.FilesystemContainerNameValidator;
|
|
||||||
import org.jclouds.filesystem.strategy.FilesystemStorageStrategy;
|
|
||||||
import org.jclouds.http.HttpCommand;
|
import org.jclouds.http.HttpCommand;
|
||||||
import org.jclouds.http.HttpRequest;
|
import org.jclouds.http.HttpRequest;
|
||||||
import org.jclouds.http.HttpResponse;
|
import org.jclouds.http.HttpResponse;
|
||||||
|
@ -91,10 +72,7 @@ import org.jclouds.http.HttpUtils;
|
||||||
import org.jclouds.io.ContentMetadata;
|
import org.jclouds.io.ContentMetadata;
|
||||||
import org.jclouds.io.ContentMetadataCodec;
|
import org.jclouds.io.ContentMetadataCodec;
|
||||||
import org.jclouds.io.Payload;
|
import org.jclouds.io.Payload;
|
||||||
import org.jclouds.io.Payloads;
|
|
||||||
import org.jclouds.io.payloads.BaseMutableContentMetadata;
|
|
||||||
import org.jclouds.logging.Logger;
|
import org.jclouds.logging.Logger;
|
||||||
import org.jclouds.rest.annotations.ParamValidators;
|
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
import com.google.common.base.Predicate;
|
import com.google.common.base.Predicate;
|
||||||
|
@ -105,43 +83,38 @@ import com.google.common.util.concurrent.Futures;
|
||||||
import com.google.common.util.concurrent.ListenableFuture;
|
import com.google.common.util.concurrent.ListenableFuture;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Implementation of {@link BaseAsyncBlobStore} which uses a pluggable
|
||||||
|
* LocalStorageStrategy.
|
||||||
*
|
*
|
||||||
* Preconditions: Blob name cannot start with / char (or \ under windows)
|
* @author Adrian Cole
|
||||||
*
|
|
||||||
* @author Alfredo "Rainbowbreeze" Morresi
|
* @author Alfredo "Rainbowbreeze" Morresi
|
||||||
|
* @author Andrew Gaul
|
||||||
|
* @author James Murty
|
||||||
*/
|
*/
|
||||||
public class FilesystemAsyncBlobStore extends BaseAsyncBlobStore {
|
public class LocalAsyncBlobStore extends BaseAsyncBlobStore {
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
protected Logger logger = Logger.NULL;
|
protected Logger logger = Logger.NULL;
|
||||||
|
|
||||||
protected final DateService dateService;
|
|
||||||
protected final Crypto crypto;
|
|
||||||
protected final HttpGetOptionsListToGetOptions httpGetOptionsConverter;
|
|
||||||
protected final ContentMetadataCodec contentMetadataCodec;
|
protected final ContentMetadataCodec contentMetadataCodec;
|
||||||
protected final IfDirectoryReturnNameStrategy ifDirectoryReturnName;
|
protected final IfDirectoryReturnNameStrategy ifDirectoryReturnName;
|
||||||
protected final Factory blobFactory;
|
protected final Factory blobFactory;
|
||||||
protected final FilesystemStorageStrategy storageStrategy;
|
protected final LocalStorageStrategy storageStrategy;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
protected FilesystemAsyncBlobStore(BlobStoreContext context,
|
protected LocalAsyncBlobStore(BlobStoreContext context,
|
||||||
DateService dateService, Crypto crypto,
|
|
||||||
HttpGetOptionsListToGetOptions httpGetOptionsConverter,
|
|
||||||
ContentMetadataCodec contentMetadataCodec,
|
|
||||||
IfDirectoryReturnNameStrategy ifDirectoryReturnName,
|
|
||||||
BlobUtils blobUtils,
|
BlobUtils blobUtils,
|
||||||
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService service,
|
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService service,
|
||||||
Supplier<Location> defaultLocation,
|
Supplier<Location> defaultLocation,
|
||||||
@Memoized Supplier<Set<? extends Location>> locations,
|
@Memoized Supplier<Set<? extends Location>> locations,
|
||||||
Factory blobFactory, FilesystemStorageStrategy storageStrategy) {
|
ContentMetadataCodec contentMetadataCodec,
|
||||||
|
IfDirectoryReturnNameStrategy ifDirectoryReturnName,
|
||||||
|
Factory blobFactory, LocalStorageStrategy storageStrategy) {
|
||||||
super(context, blobUtils, service, defaultLocation, locations);
|
super(context, blobUtils, service, defaultLocation, locations);
|
||||||
this.blobFactory = blobFactory;
|
this.blobFactory = blobFactory;
|
||||||
this.dateService = dateService;
|
|
||||||
this.crypto = crypto;
|
|
||||||
this.httpGetOptionsConverter = httpGetOptionsConverter;
|
|
||||||
this.contentMetadataCodec = contentMetadataCodec;
|
this.contentMetadataCodec = contentMetadataCodec;
|
||||||
this.ifDirectoryReturnName = ifDirectoryReturnName;
|
this.ifDirectoryReturnName = ifDirectoryReturnName;
|
||||||
this.storageStrategy = checkNotNull(storageStrategy, "Storage strategy");
|
this.storageStrategy = storageStrategy;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -170,7 +143,7 @@ public class FilesystemAsyncBlobStore extends BaseAsyncBlobStore {
|
||||||
checkState(oldBlob != null, "blob " + key + " is not present although it was in the list of "
|
checkState(oldBlob != null, "blob " + key + " is not present although it was in the list of "
|
||||||
+ container);
|
+ container);
|
||||||
checkState(oldBlob.getMetadata() != null, "blob " + container + "/" + key + " has no metadata");
|
checkState(oldBlob.getMetadata() != null, "blob " + container + "/" + key + " has no metadata");
|
||||||
MutableBlobMetadata md = copy(oldBlob.getMetadata());
|
MutableBlobMetadata md = BlobStoreUtils.copy(oldBlob.getMetadata());
|
||||||
String directoryName = ifDirectoryReturnName.execute(md);
|
String directoryName = ifDirectoryReturnName.execute(md);
|
||||||
if (directoryName != null) {
|
if (directoryName != null) {
|
||||||
md.setName(directoryName);
|
md.setName(directoryName);
|
||||||
|
@ -211,7 +184,7 @@ public class FilesystemAsyncBlobStore extends BaseAsyncBlobStore {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final String delimiter = options.isRecursive() ? null : File.separator;
|
final String delimiter = options.isRecursive() ? null : storageStrategy.getSeparator();
|
||||||
if (delimiter != null) {
|
if (delimiter != null) {
|
||||||
SortedSet<String> commonPrefixes = newTreeSet(
|
SortedSet<String> commonPrefixes = newTreeSet(
|
||||||
transform(contents, new CommonPrefixes(prefix, delimiter)));
|
transform(contents, new CommonPrefixes(prefix, delimiter)));
|
||||||
|
@ -249,37 +222,6 @@ public class FilesystemAsyncBlobStore extends BaseAsyncBlobStore {
|
||||||
storageStrategy.getAllContainerNames()));
|
storageStrategy.getAllContainerNames()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static MutableBlobMetadata copy(MutableBlobMetadata in) {
|
|
||||||
ByteArrayOutputStream bout = new ByteArrayOutputStream();
|
|
||||||
ObjectOutput os;
|
|
||||||
try {
|
|
||||||
os = new ObjectOutputStream(bout);
|
|
||||||
os.writeObject(in);
|
|
||||||
ObjectInput is = new ObjectInputStream(new ByteArrayInputStream(bout.toByteArray()));
|
|
||||||
MutableBlobMetadata metadata = (MutableBlobMetadata) is.readObject();
|
|
||||||
convertUserMetadataKeysToLowercase(metadata);
|
|
||||||
metadata.setContentMetadata(BaseMutableContentMetadata.fromContentMetadata(in.getContentMetadata().toBuilder()
|
|
||||||
.build()));
|
|
||||||
return metadata;
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw propagate(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void convertUserMetadataKeysToLowercase(MutableBlobMetadata metadata) {
|
|
||||||
Map<String, String> lowerCaseUserMetadata = newHashMap();
|
|
||||||
for (Entry<String, String> entry : metadata.getUserMetadata().entrySet()) {
|
|
||||||
lowerCaseUserMetadata.put(entry.getKey().toLowerCase(), entry.getValue());
|
|
||||||
}
|
|
||||||
metadata.setUserMetadata(lowerCaseUserMetadata);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static MutableBlobMetadata copy(MutableBlobMetadata in, String newKey) {
|
|
||||||
MutableBlobMetadata newMd = copy(in);
|
|
||||||
newMd.setName(newKey);
|
|
||||||
return newMd;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
|
@ -289,6 +231,15 @@ public class FilesystemAsyncBlobStore extends BaseAsyncBlobStore {
|
||||||
return immediateFuture(null);
|
return immediateFuture(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public ListenableFuture<Void> clearContainer(final String container) {
|
||||||
|
storageStrategy.clearContainer(container);
|
||||||
|
return immediateFuture(null);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Override parent method because it uses strange futures and listenables
|
* Override parent method because it uses strange futures and listenables
|
||||||
* that creates problem in the test if more than one test that deletes the
|
* that creates problem in the test if more than one test that deletes the
|
||||||
|
@ -303,6 +254,22 @@ public class FilesystemAsyncBlobStore extends BaseAsyncBlobStore {
|
||||||
return immediateFuture(null);
|
return immediateFuture(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ListenableFuture<Boolean> deleteContainerIfEmpty(final String container) {
|
||||||
|
Boolean returnVal = true;
|
||||||
|
if (storageStrategy.containerExists(container)) {
|
||||||
|
try {
|
||||||
|
if (Iterables.isEmpty(storageStrategy.getBlobKeysInsideContainer(container)))
|
||||||
|
storageStrategy.deleteContainer(container);
|
||||||
|
else
|
||||||
|
returnVal = false;
|
||||||
|
} catch (IOException e) {
|
||||||
|
logger.error(e, "An error occurred loading blobs contained into container %s", container);
|
||||||
|
Throwables.propagate(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return immediateFuture(returnVal);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
|
@ -324,6 +291,7 @@ public class FilesystemAsyncBlobStore extends BaseAsyncBlobStore {
|
||||||
MutableStorageMetadata cmd = create();
|
MutableStorageMetadata cmd = create();
|
||||||
cmd.setName(name);
|
cmd.setName(name);
|
||||||
cmd.setType(StorageType.CONTAINER);
|
cmd.setType(StorageType.CONTAINER);
|
||||||
|
cmd.setLocation(storageStrategy.getLocation(name));
|
||||||
return cmd;
|
return cmd;
|
||||||
}
|
}
|
||||||
}), null));
|
}), null));
|
||||||
|
@ -336,11 +304,10 @@ public class FilesystemAsyncBlobStore extends BaseAsyncBlobStore {
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
@Path("{container}")
|
|
||||||
@Override
|
@Override
|
||||||
public ListenableFuture<Boolean> createContainerInLocation(final Location location,
|
public ListenableFuture<Boolean> createContainerInLocation(final Location location,
|
||||||
@PathParam("container") @ParamValidators({ FilesystemContainerNameValidator.class }) String name) {
|
final String name) {
|
||||||
boolean result = storageStrategy.createContainer(name);
|
boolean result = storageStrategy.createContainerInLocation(name, location);
|
||||||
return immediateFuture(result);
|
return immediateFuture(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -461,18 +428,12 @@ public class FilesystemAsyncBlobStore extends BaseAsyncBlobStore {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// TODO
|
return immediateFuture(storageStrategy.putBlob(containerName, blob));
|
||||||
// must override existing file?
|
|
||||||
|
|
||||||
storageStrategy.putBlob(containerName, blob);
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
logger.error(e, "An error occurred storing the new blob with name [%s] to container [%s].", blobKey,
|
logger.error(e, "An error occurred storing the new blob with name [%s] to container [%s].", blobKey,
|
||||||
containerName);
|
containerName);
|
||||||
Throwables.propagate(e);
|
throw Throwables.propagate(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
String eTag = getEtag(blob);
|
|
||||||
return immediateFuture(eTag);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void copyPayloadHeadersToBlob(Payload payload, Blob blob) {
|
private void copyPayloadHeadersToBlob(Payload payload, Blob blob) {
|
||||||
|
@ -573,7 +534,7 @@ public class FilesystemAsyncBlobStore extends BaseAsyncBlobStore {
|
||||||
byte[] byteArray = out.toByteArray();
|
byte[] byteArray = out.toByteArray();
|
||||||
blob.setPayload(byteArray);
|
blob.setPayload(byteArray);
|
||||||
HttpUtils.copy(cmd, blob.getPayload().getContentMetadata());
|
HttpUtils.copy(cmd, blob.getPayload().getContentMetadata());
|
||||||
blob.getPayload().getContentMetadata().setContentLength(new Long(byteArray.length));
|
blob.getPayload().getContentMetadata().setContentLength(Long.valueOf(byteArray.length));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
checkNotNull(blob.getPayload(), "payload " + blob);
|
checkNotNull(blob.getPayload(), "payload " + blob);
|
||||||
|
@ -587,7 +548,7 @@ public class FilesystemAsyncBlobStore extends BaseAsyncBlobStore {
|
||||||
public ListenableFuture<BlobMetadata> blobMetadata(final String container, final String key) {
|
public ListenableFuture<BlobMetadata> blobMetadata(final String container, final String key) {
|
||||||
try {
|
try {
|
||||||
Blob blob = getBlob(container, key).get();
|
Blob blob = getBlob(container, key).get();
|
||||||
return immediateFuture(blob != null ? (BlobMetadata) copy(blob.getMetadata()) : null);
|
return immediateFuture(blob != null ? (BlobMetadata) BlobStoreUtils.copy(blob.getMetadata()) : null);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
if (size(filter(getCausalChain(e), KeyNotFoundException.class)) >= 1)
|
if (size(filter(getCausalChain(e), KeyNotFoundException.class)) >= 1)
|
||||||
return immediateFuture(null);
|
return immediateFuture(null);
|
||||||
|
@ -595,26 +556,8 @@ public class FilesystemAsyncBlobStore extends BaseAsyncBlobStore {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Calculates the object MD5 and returns it as eTag
|
|
||||||
*
|
|
||||||
* @param object
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
private String getEtag(Blob object) {
|
|
||||||
try {
|
|
||||||
Payloads.calculateMD5(object, crypto.md5());
|
|
||||||
} catch (IOException ex) {
|
|
||||||
logger.error(ex, "An error occurred calculating MD5 for object with name %s.", object.getMetadata().getName());
|
|
||||||
Throwables.propagate(ex);
|
|
||||||
}
|
|
||||||
|
|
||||||
String eTag = CryptoStreams.hex(object.getPayload().getContentMetadata().getContentMD5());
|
|
||||||
return eTag;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Blob copyBlob(Blob blob) {
|
private Blob copyBlob(Blob blob) {
|
||||||
Blob returnVal = blobFactory.create(copy(blob.getMetadata()));
|
Blob returnVal = blobFactory.create(BlobStoreUtils.copy(blob.getMetadata()));
|
||||||
returnVal.setPayload(blob.getPayload());
|
returnVal.setPayload(blob.getPayload());
|
||||||
copyPayloadHeadersToBlob(blob.getPayload(), returnVal);
|
copyPayloadHeadersToBlob(blob.getPayload(), returnVal);
|
||||||
return returnVal;
|
return returnVal;
|
|
@ -16,21 +16,20 @@
|
||||||
* specific language governing permissions and limitations
|
* specific language governing permissions and limitations
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
package org.jclouds.filesystem.strategy;
|
package org.jclouds.blobstore;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import org.jclouds.blobstore.domain.Blob;
|
import org.jclouds.blobstore.domain.Blob;
|
||||||
import org.jclouds.blobstore.options.ListContainerOptions;
|
import org.jclouds.blobstore.options.ListContainerOptions;
|
||||||
import org.jclouds.io.Payload;
|
import org.jclouds.domain.Location;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Strategy for filesystem operations related to container and blob
|
* Strategy for local operations related to container and blob
|
||||||
*
|
*
|
||||||
* @author Alfredo "Rainbowbreeze" Morresi
|
* @author Alfredo "Rainbowbreeze" Morresi
|
||||||
*/
|
*/
|
||||||
public interface FilesystemStorageStrategy {
|
public interface LocalStorageStrategy {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new container
|
* Creates a new container
|
||||||
|
@ -38,7 +37,7 @@ public interface FilesystemStorageStrategy {
|
||||||
* @param container
|
* @param container
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
boolean createContainer(String container);
|
boolean createContainerInLocation(String container, Location location);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes a container and all its content
|
* Deletes a container and all its content
|
||||||
|
@ -58,7 +57,7 @@ public interface FilesystemStorageStrategy {
|
||||||
* delete the container itself
|
* delete the container itself
|
||||||
* @param container
|
* @param container
|
||||||
*/
|
*/
|
||||||
void clearContainer(final String container);
|
void clearContainer(String container);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Like {@link #clearContainer(String)} except you can use options to do things like recursive
|
* Like {@link #clearContainer(String)} except you can use options to do things like recursive
|
||||||
|
@ -78,45 +77,7 @@ public interface FilesystemStorageStrategy {
|
||||||
Iterable<String> getAllContainerNames();
|
Iterable<String> getAllContainerNames();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determines if a directory exists
|
* Return true if a blob named by key exists
|
||||||
*
|
|
||||||
* @param container
|
|
||||||
* container where the directory resides
|
|
||||||
* @param directory
|
|
||||||
* full path to the directory
|
|
||||||
*/
|
|
||||||
boolean directoryExists(String container, String directory);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a folder or a directory marker depending on the service
|
|
||||||
*
|
|
||||||
* @param container
|
|
||||||
* container to create the directory in
|
|
||||||
* @param directory
|
|
||||||
* full path to the directory
|
|
||||||
*/
|
|
||||||
void createDirectory(String container, String directory);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Deletes a folder or a directory marker depending on the service
|
|
||||||
*
|
|
||||||
* @param container
|
|
||||||
* container to delete the directory from
|
|
||||||
* @param directory
|
|
||||||
* full path to the directory to delete
|
|
||||||
*/
|
|
||||||
void deleteDirectory(String container, String directory);
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new blob
|
|
||||||
* @param name
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
Blob newBlob(String name);
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param container
|
* @param container
|
||||||
* @param key
|
* @param key
|
||||||
* @return
|
* @return
|
||||||
|
@ -135,7 +96,7 @@ public interface FilesystemStorageStrategy {
|
||||||
*
|
*
|
||||||
* @return the blob belonging to the given container with the given key
|
* @return the blob belonging to the given container with the given key
|
||||||
*/
|
*/
|
||||||
Blob getBlob(final String containerName, final String blobName);
|
Blob getBlob(String containerName, String blobName);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns all the blobs key inside a container
|
* Returns all the blobs key inside a container
|
||||||
|
@ -146,23 +107,7 @@ public interface FilesystemStorageStrategy {
|
||||||
Iterable<String> getBlobKeysInsideContainer(String container) throws IOException;
|
Iterable<String> getBlobKeysInsideContainer(String container) throws IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Counts number of blobs inside a container
|
* Remove blob named by the given key
|
||||||
* @param container
|
|
||||||
* @param options
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
long countBlobs(String container, ListContainerOptions options);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a {@link File} object that links to the blob
|
|
||||||
* @param container
|
|
||||||
* @param key
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
File getFileForBlobKey(String container, String key);
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param container
|
* @param container
|
||||||
* @param key
|
* @param key
|
||||||
*/
|
*/
|
||||||
|
@ -172,8 +117,17 @@ public interface FilesystemStorageStrategy {
|
||||||
* Write a {@link Blob} into a file
|
* Write a {@link Blob} into a file
|
||||||
* @param container
|
* @param container
|
||||||
* @param blob
|
* @param blob
|
||||||
|
* @return etag of blob
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
void putBlob(String containerName, Blob blob) throws IOException;
|
String putBlob(String containerName, Blob blob) throws IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param containerName name of container
|
||||||
|
* @return Location of container or null
|
||||||
|
*/
|
||||||
|
Location getLocation(String containerName);
|
||||||
|
|
||||||
|
/** @return path separator, either / or \ */
|
||||||
|
String getSeparator();
|
||||||
}
|
}
|
|
@ -1,683 +0,0 @@
|
||||||
/**
|
|
||||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
|
||||||
* contributor license agreements. See the NOTICE file
|
|
||||||
* distributed with this work for additional information
|
|
||||||
* regarding copyright ownership. jclouds licenses this file
|
|
||||||
* to you 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.
|
|
||||||
*/
|
|
||||||
package org.jclouds.blobstore;
|
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
|
||||||
import static com.google.common.base.Preconditions.checkState;
|
|
||||||
import static com.google.common.base.Throwables.getCausalChain;
|
|
||||||
import static com.google.common.base.Throwables.propagate;
|
|
||||||
import static com.google.common.collect.Iterables.filter;
|
|
||||||
import static com.google.common.collect.Iterables.find;
|
|
||||||
import static com.google.common.collect.Iterables.size;
|
|
||||||
import static com.google.common.collect.Iterables.transform;
|
|
||||||
import static com.google.common.collect.Maps.newHashMap;
|
|
||||||
import static com.google.common.collect.Sets.filter;
|
|
||||||
import static com.google.common.collect.Sets.newTreeSet;
|
|
||||||
import static com.google.common.io.ByteStreams.toByteArray;
|
|
||||||
import static com.google.common.util.concurrent.Futures.immediateFailedFuture;
|
|
||||||
import static com.google.common.util.concurrent.Futures.immediateFuture;
|
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
|
||||||
import java.io.ByteArrayOutputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.ObjectInput;
|
|
||||||
import java.io.ObjectInputStream;
|
|
||||||
import java.io.ObjectOutput;
|
|
||||||
import java.io.ObjectOutputStream;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Map.Entry;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.SortedSet;
|
|
||||||
import java.util.concurrent.ExecutorService;
|
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
|
||||||
import javax.inject.Inject;
|
|
||||||
import javax.inject.Named;
|
|
||||||
import javax.inject.Provider;
|
|
||||||
import javax.ws.rs.core.HttpHeaders;
|
|
||||||
import javax.ws.rs.core.UriBuilder;
|
|
||||||
|
|
||||||
import org.jclouds.Constants;
|
|
||||||
import org.jclouds.blobstore.domain.Blob;
|
|
||||||
import org.jclouds.blobstore.domain.Blob.Factory;
|
|
||||||
import org.jclouds.blobstore.domain.BlobMetadata;
|
|
||||||
import org.jclouds.blobstore.domain.MutableBlobMetadata;
|
|
||||||
import org.jclouds.blobstore.domain.MutableStorageMetadata;
|
|
||||||
import org.jclouds.blobstore.domain.PageSet;
|
|
||||||
import org.jclouds.blobstore.domain.StorageMetadata;
|
|
||||||
import org.jclouds.blobstore.domain.StorageType;
|
|
||||||
import org.jclouds.blobstore.domain.internal.MutableStorageMetadataImpl;
|
|
||||||
import org.jclouds.blobstore.domain.internal.PageSetImpl;
|
|
||||||
import org.jclouds.blobstore.functions.HttpGetOptionsListToGetOptions;
|
|
||||||
import org.jclouds.blobstore.internal.BaseAsyncBlobStore;
|
|
||||||
import org.jclouds.blobstore.options.CreateContainerOptions;
|
|
||||||
import org.jclouds.blobstore.options.GetOptions;
|
|
||||||
import org.jclouds.blobstore.options.ListContainerOptions;
|
|
||||||
import org.jclouds.blobstore.options.PutOptions;
|
|
||||||
import org.jclouds.blobstore.strategy.IfDirectoryReturnNameStrategy;
|
|
||||||
import org.jclouds.blobstore.util.BlobUtils;
|
|
||||||
import org.jclouds.collect.Memoized;
|
|
||||||
import org.jclouds.crypto.Crypto;
|
|
||||||
import org.jclouds.crypto.CryptoStreams;
|
|
||||||
import org.jclouds.date.DateService;
|
|
||||||
import org.jclouds.domain.Location;
|
|
||||||
import org.jclouds.http.HttpCommand;
|
|
||||||
import org.jclouds.http.HttpRequest;
|
|
||||||
import org.jclouds.http.HttpResponse;
|
|
||||||
import org.jclouds.http.HttpResponseException;
|
|
||||||
import org.jclouds.http.HttpUtils;
|
|
||||||
import org.jclouds.io.ContentMetadata;
|
|
||||||
import org.jclouds.io.ContentMetadataCodec;
|
|
||||||
import org.jclouds.io.MutableContentMetadata;
|
|
||||||
import org.jclouds.io.Payload;
|
|
||||||
import org.jclouds.io.Payloads;
|
|
||||||
import org.jclouds.io.payloads.ByteArrayPayload;
|
|
||||||
import org.jclouds.io.payloads.DelegatingPayload;
|
|
||||||
import org.jclouds.logging.Logger;
|
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
|
||||||
import com.google.common.base.Predicate;
|
|
||||||
import com.google.common.base.Supplier;
|
|
||||||
import com.google.common.base.Throwables;
|
|
||||||
import com.google.common.collect.Iterables;
|
|
||||||
import com.google.common.collect.Multimaps;
|
|
||||||
import com.google.common.util.concurrent.Futures;
|
|
||||||
import com.google.common.util.concurrent.ListenableFuture;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Implementation of {@link BaseAsyncBlobStore} which keeps all data in a local Map object.
|
|
||||||
*
|
|
||||||
* @author Adrian Cole
|
|
||||||
* @author James Murty
|
|
||||||
*/
|
|
||||||
public class TransientAsyncBlobStore extends BaseAsyncBlobStore {
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
protected Logger logger = Logger.NULL;
|
|
||||||
|
|
||||||
protected final DateService dateService;
|
|
||||||
protected final Crypto crypto;
|
|
||||||
protected final HttpGetOptionsListToGetOptions httpGetOptionsConverter;
|
|
||||||
protected final ContentMetadataCodec contentMetadataCodec;
|
|
||||||
protected final IfDirectoryReturnNameStrategy ifDirectoryReturnName;
|
|
||||||
protected final Factory blobFactory;
|
|
||||||
protected final TransientStorageStrategy storageStrategy;
|
|
||||||
protected final Provider<UriBuilder> uriBuilders;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
protected TransientAsyncBlobStore(BlobStoreContext context,
|
|
||||||
DateService dateService, Crypto crypto,
|
|
||||||
HttpGetOptionsListToGetOptions httpGetOptionsConverter,
|
|
||||||
ContentMetadataCodec contentMetadataCodec,
|
|
||||||
IfDirectoryReturnNameStrategy ifDirectoryReturnName,
|
|
||||||
BlobUtils blobUtils,
|
|
||||||
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService service,
|
|
||||||
Supplier<Location> defaultLocation,
|
|
||||||
@Memoized Supplier<Set<? extends Location>> locations,
|
|
||||||
Factory blobFactory, Provider<UriBuilder> uriBuilders) {
|
|
||||||
super(context, blobUtils, service, defaultLocation, locations);
|
|
||||||
this.blobFactory = blobFactory;
|
|
||||||
this.dateService = dateService;
|
|
||||||
this.crypto = crypto;
|
|
||||||
this.httpGetOptionsConverter = httpGetOptionsConverter;
|
|
||||||
this.contentMetadataCodec = contentMetadataCodec;
|
|
||||||
this.ifDirectoryReturnName = ifDirectoryReturnName;
|
|
||||||
this.storageStrategy = new TransientStorageStrategy(defaultLocation);
|
|
||||||
this.uriBuilders = uriBuilders;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* default maxResults is 1000
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public ListenableFuture<PageSet<? extends StorageMetadata>> list(final String container, ListContainerOptions options) {
|
|
||||||
|
|
||||||
// Check if the container exists
|
|
||||||
if (!storageStrategy.containerExists(container))
|
|
||||||
return immediateFailedFuture(cnfe(container));
|
|
||||||
|
|
||||||
// Loading blobs from container
|
|
||||||
Iterable<String> blobBelongingToContainer = storageStrategy.getBlobKeysInsideContainer(container);
|
|
||||||
|
|
||||||
SortedSet<StorageMetadata> contents = newTreeSet(transform(blobBelongingToContainer,
|
|
||||||
new Function<String, StorageMetadata>() {
|
|
||||||
public StorageMetadata apply(String key) {
|
|
||||||
Blob oldBlob = loadBlob(container, key);
|
|
||||||
checkState(oldBlob != null, "blob " + key + " is not present although it was in the list of "
|
|
||||||
+ container);
|
|
||||||
checkState(oldBlob.getMetadata() != null, "blob " + container + "/" + key + " has no metadata");
|
|
||||||
MutableBlobMetadata md = copy(oldBlob.getMetadata());
|
|
||||||
String directoryName = ifDirectoryReturnName.execute(md);
|
|
||||||
if (directoryName != null) {
|
|
||||||
md.setName(directoryName);
|
|
||||||
md.setType(StorageType.RELATIVE_PATH);
|
|
||||||
}
|
|
||||||
return md;
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
|
|
||||||
String marker = null;
|
|
||||||
if (options != null) {
|
|
||||||
if (options.getMarker() != null) {
|
|
||||||
final String finalMarker = options.getMarker();
|
|
||||||
StorageMetadata lastMarkerMetadata = find(contents, new Predicate<StorageMetadata>() {
|
|
||||||
public boolean apply(StorageMetadata metadata) {
|
|
||||||
return metadata.getName().compareTo(finalMarker) > 0;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
contents = contents.tailSet(lastMarkerMetadata);
|
|
||||||
}
|
|
||||||
|
|
||||||
final String prefix = options.getDir();
|
|
||||||
if (prefix != null) {
|
|
||||||
contents = newTreeSet(filter(contents, new Predicate<StorageMetadata>() {
|
|
||||||
public boolean apply(StorageMetadata o) {
|
|
||||||
return (o != null && o.getName().startsWith(prefix) && !o.getName().equals(prefix));
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
|
|
||||||
int maxResults = options.getMaxResults() != null ? options.getMaxResults() : 1000;
|
|
||||||
if (!contents.isEmpty()) {
|
|
||||||
StorageMetadata lastElement = contents.last();
|
|
||||||
contents = newTreeSet(Iterables.limit(contents, maxResults));
|
|
||||||
if (!contents.contains(lastElement)) {
|
|
||||||
// Partial listing
|
|
||||||
marker = contents.last().getName();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final String delimiter = options.isRecursive() ? null : "/";
|
|
||||||
if (delimiter != null) {
|
|
||||||
SortedSet<String> commonPrefixes = newTreeSet(
|
|
||||||
transform(contents, new CommonPrefixes(prefix, delimiter)));
|
|
||||||
commonPrefixes.remove(CommonPrefixes.NO_PREFIX);
|
|
||||||
|
|
||||||
contents = newTreeSet(filter(contents, new DelimiterFilter(prefix, delimiter)));
|
|
||||||
|
|
||||||
Iterables.<StorageMetadata> addAll(contents, transform(commonPrefixes,
|
|
||||||
new Function<String, StorageMetadata>() {
|
|
||||||
public StorageMetadata apply(String o) {
|
|
||||||
MutableStorageMetadata md = new MutableStorageMetadataImpl();
|
|
||||||
md.setType(StorageType.RELATIVE_PATH);
|
|
||||||
md.setName(o);
|
|
||||||
return md;
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
|
|
||||||
// trim metadata, if the response isn't supposed to be detailed.
|
|
||||||
if (!options.isDetailed()) {
|
|
||||||
for (StorageMetadata md : contents) {
|
|
||||||
md.getUserMetadata().clear();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return Futures.<PageSet<? extends StorageMetadata>> immediateFuture(new PageSetImpl<StorageMetadata>(contents,
|
|
||||||
marker));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private ContainerNotFoundException cnfe(final String name) {
|
|
||||||
return new ContainerNotFoundException(name, String.format(
|
|
||||||
"container %s not in %s", name,
|
|
||||||
storageStrategy.getAllContainerNames()));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static MutableBlobMetadata copy(MutableBlobMetadata in) {
|
|
||||||
ByteArrayOutputStream bout = new ByteArrayOutputStream();
|
|
||||||
ObjectOutput os;
|
|
||||||
try {
|
|
||||||
os = new ObjectOutputStream(bout);
|
|
||||||
os.writeObject(in);
|
|
||||||
ObjectInput is = new ObjectInputStream(new ByteArrayInputStream(bout.toByteArray()));
|
|
||||||
MutableBlobMetadata metadata = (MutableBlobMetadata) is.readObject();
|
|
||||||
convertUserMetadataKeysToLowercase(metadata);
|
|
||||||
HttpUtils.copy(in.getContentMetadata(), metadata.getContentMetadata());
|
|
||||||
return metadata;
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw propagate(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void convertUserMetadataKeysToLowercase(MutableBlobMetadata metadata) {
|
|
||||||
Map<String, String> lowerCaseUserMetadata = newHashMap();
|
|
||||||
for (Entry<String, String> entry : metadata.getUserMetadata().entrySet()) {
|
|
||||||
lowerCaseUserMetadata.put(entry.getKey().toLowerCase(), entry.getValue());
|
|
||||||
}
|
|
||||||
metadata.setUserMetadata(lowerCaseUserMetadata);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static MutableBlobMetadata copy(MutableBlobMetadata in, String newKey) {
|
|
||||||
MutableBlobMetadata newMd = copy(in);
|
|
||||||
newMd.setName(newKey);
|
|
||||||
return newMd;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public ListenableFuture<Void> removeBlob(final String container, final String key) {
|
|
||||||
storageStrategy.removeBlob(container, key);
|
|
||||||
return immediateFuture(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public ListenableFuture<Void> clearContainer(final String container) {
|
|
||||||
storageStrategy.clearContainer(container);
|
|
||||||
return immediateFuture(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public ListenableFuture<Void> deleteContainer(final String container) {
|
|
||||||
deleteAndVerifyContainerGone(container);
|
|
||||||
return immediateFuture(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ListenableFuture<Boolean> deleteContainerIfEmpty(final String container) {
|
|
||||||
Boolean returnVal = true;
|
|
||||||
if (storageStrategy.containerExists(container)) {
|
|
||||||
if (Iterables.isEmpty(storageStrategy.getBlobKeysInsideContainer(container)))
|
|
||||||
storageStrategy.deleteContainer(container);
|
|
||||||
else
|
|
||||||
returnVal = false;
|
|
||||||
}
|
|
||||||
return immediateFuture(returnVal);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public ListenableFuture<Boolean> containerExists(final String containerName) {
|
|
||||||
return immediateFuture(storageStrategy.containerExists(containerName));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public ListenableFuture<PageSet<? extends StorageMetadata>> list() {
|
|
||||||
Iterable<String> containers = storageStrategy.getAllContainerNames();
|
|
||||||
|
|
||||||
return Futures.<PageSet<? extends StorageMetadata>> immediateFuture(new PageSetImpl<StorageMetadata>(transform(
|
|
||||||
containers, new Function<String, StorageMetadata>() {
|
|
||||||
public StorageMetadata apply(String name) {
|
|
||||||
MutableStorageMetadata cmd = create();
|
|
||||||
cmd.setName(name);
|
|
||||||
cmd.setType(StorageType.CONTAINER);
|
|
||||||
cmd.setLocation(storageStrategy.getLocation(name));
|
|
||||||
return cmd;
|
|
||||||
}
|
|
||||||
}), null));
|
|
||||||
}
|
|
||||||
|
|
||||||
protected MutableStorageMetadata create() {
|
|
||||||
return new MutableStorageMetadataImpl();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public ListenableFuture<Boolean> createContainerInLocation(final Location location,
|
|
||||||
final String name) {
|
|
||||||
boolean result = storageStrategy.createContainerInLocation(name, location);
|
|
||||||
return immediateFuture(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
private Blob loadBlob(final String container, final String key) {
|
|
||||||
logger.debug("Opening blob in container: %s - %s", container, key);
|
|
||||||
return storageStrategy.getBlob(container, key);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected static class DelimiterFilter implements Predicate<StorageMetadata> {
|
|
||||||
private final String prefix;
|
|
||||||
private final String delimiter;
|
|
||||||
|
|
||||||
public DelimiterFilter(String prefix, String delimiter) {
|
|
||||||
this.prefix = prefix;
|
|
||||||
this.delimiter = delimiter;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean apply(StorageMetadata metadata) {
|
|
||||||
if (prefix == null)
|
|
||||||
return metadata.getName().indexOf(delimiter) == -1;
|
|
||||||
// ensure we don't accidentally append twice
|
|
||||||
String toMatch = prefix.endsWith("/") ? prefix : prefix + delimiter;
|
|
||||||
if (metadata.getName().startsWith(toMatch)) {
|
|
||||||
String unprefixedName = metadata.getName().replaceFirst(toMatch, "");
|
|
||||||
if (unprefixedName.equals("")) {
|
|
||||||
// we are the prefix in this case, return false
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return unprefixedName.indexOf(delimiter) == -1;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected static class CommonPrefixes implements Function<StorageMetadata, String> {
|
|
||||||
private final String prefix;
|
|
||||||
private final String delimiter;
|
|
||||||
public static final String NO_PREFIX = "NO_PREFIX";
|
|
||||||
|
|
||||||
public CommonPrefixes(String prefix, String delimiter) {
|
|
||||||
this.prefix = prefix;
|
|
||||||
this.delimiter = delimiter;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String apply(StorageMetadata metadata) {
|
|
||||||
String working = metadata.getName();
|
|
||||||
if (prefix != null) {
|
|
||||||
// ensure we don't accidentally append twice
|
|
||||||
String toMatch = prefix.endsWith("/") ? prefix : prefix + delimiter;
|
|
||||||
if (working.startsWith(toMatch)) {
|
|
||||||
working = working.replaceFirst(toMatch, "");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (working.contains(delimiter)) {
|
|
||||||
return working.substring(0, working.indexOf(delimiter));
|
|
||||||
}
|
|
||||||
return NO_PREFIX;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static HttpResponseException returnResponseException(int code) {
|
|
||||||
HttpResponse response = HttpResponse.builder().statusCode(code).build();
|
|
||||||
return new HttpResponseException(new HttpCommand() {
|
|
||||||
|
|
||||||
public int getRedirectCount() {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int incrementRedirectCount() {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isReplayable() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Exception getException() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getFailureCount() {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int incrementFailureCount() {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setException(Exception exception) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public HttpRequest getCurrentRequest() {
|
|
||||||
return HttpRequest.builder().method("GET").endpoint("http://stub").build();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setCurrentRequest(HttpRequest request) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}, response);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public ListenableFuture<String> putBlob(String containerName, Blob blob) {
|
|
||||||
checkNotNull(containerName, "containerName must be set");
|
|
||||||
checkNotNull(blob, "blob must be set");
|
|
||||||
String blobKey = blob.getMetadata().getName();
|
|
||||||
|
|
||||||
logger.debug("Put blob with key [%s] to container [%s]", blobKey, containerName);
|
|
||||||
if (!storageStrategy.containerExists(containerName)) {
|
|
||||||
return Futures.immediateFailedFuture(new IllegalStateException("containerName not found: " + containerName));
|
|
||||||
}
|
|
||||||
|
|
||||||
blob = createUpdatedCopyOfBlobInContainer(containerName, blob);
|
|
||||||
|
|
||||||
storageStrategy.putBlob(containerName, blob);
|
|
||||||
|
|
||||||
String eTag = getEtag(blob);
|
|
||||||
return immediateFuture(eTag);
|
|
||||||
}
|
|
||||||
|
|
||||||
private Blob createUpdatedCopyOfBlobInContainer(String containerName, Blob in) {
|
|
||||||
checkNotNull(in, "blob");
|
|
||||||
checkNotNull(in.getPayload(), "blob.payload");
|
|
||||||
ByteArrayPayload payload = (in.getPayload() instanceof ByteArrayPayload) ? ByteArrayPayload.class.cast(in
|
|
||||||
.getPayload()) : null;
|
|
||||||
if (payload == null)
|
|
||||||
payload = (in.getPayload() instanceof DelegatingPayload) ? (DelegatingPayload.class.cast(in.getPayload())
|
|
||||||
.getDelegate() instanceof ByteArrayPayload) ? ByteArrayPayload.class.cast(DelegatingPayload.class
|
|
||||||
.cast(in.getPayload()).getDelegate()) : null : null;
|
|
||||||
try {
|
|
||||||
if (payload == null || !(payload instanceof ByteArrayPayload)) {
|
|
||||||
MutableContentMetadata oldMd = in.getPayload().getContentMetadata();
|
|
||||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
|
||||||
in.getPayload().writeTo(out);
|
|
||||||
payload = (ByteArrayPayload) Payloads.calculateMD5(Payloads.newPayload(out.toByteArray()));
|
|
||||||
HttpUtils.copy(oldMd, payload.getContentMetadata());
|
|
||||||
} else {
|
|
||||||
if (payload.getContentMetadata().getContentMD5() == null)
|
|
||||||
Payloads.calculateMD5(in, crypto.md5());
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
Throwables.propagate(e);
|
|
||||||
}
|
|
||||||
Blob blob = blobFactory.create(copy(in.getMetadata()));
|
|
||||||
blob.setPayload(payload);
|
|
||||||
blob.getMetadata().setContainer(containerName);
|
|
||||||
blob.getMetadata().setUri(
|
|
||||||
uriBuilders.get().scheme("mem").host(containerName).path(in.getMetadata().getName()).build());
|
|
||||||
blob.getMetadata().setLastModified(new Date());
|
|
||||||
String eTag = CryptoStreams.hex(payload.getContentMetadata().getContentMD5());
|
|
||||||
blob.getMetadata().setETag(eTag);
|
|
||||||
// Set HTTP headers to match metadata
|
|
||||||
blob.getAllHeaders().replaceValues(HttpHeaders.LAST_MODIFIED,
|
|
||||||
Collections.singleton(dateService.rfc822DateFormat(blob.getMetadata().getLastModified())));
|
|
||||||
blob.getAllHeaders().replaceValues(HttpHeaders.ETAG, Collections.singleton(eTag));
|
|
||||||
copyPayloadHeadersToBlob(payload, blob);
|
|
||||||
blob.getAllHeaders().putAll(Multimaps.forMap(blob.getMetadata().getUserMetadata()));
|
|
||||||
return blob;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void copyPayloadHeadersToBlob(Payload payload, Blob blob) {
|
|
||||||
blob.getAllHeaders().putAll(contentMetadataCodec.toHeaders(payload.getContentMetadata()));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public ListenableFuture<Boolean> blobExists(final String containerName, final String key) {
|
|
||||||
if (!storageStrategy.containerExists(containerName))
|
|
||||||
return immediateFailedFuture(cnfe(containerName));
|
|
||||||
return immediateFuture(storageStrategy.blobExists(containerName, key));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public ListenableFuture<Blob> getBlob(final String containerName, final String key, GetOptions options) {
|
|
||||||
logger.debug("Retrieving blob with key %s from container %s", key, containerName);
|
|
||||||
// If the container doesn't exist, an exception is thrown
|
|
||||||
if (!storageStrategy.containerExists(containerName)) {
|
|
||||||
logger.debug("Container %s does not exist", containerName);
|
|
||||||
return immediateFailedFuture(cnfe(containerName));
|
|
||||||
}
|
|
||||||
// If the blob doesn't exist, a null object is returned
|
|
||||||
if (!storageStrategy.blobExists(containerName, key)) {
|
|
||||||
logger.debug("Item %s does not exist in container %s", key, containerName);
|
|
||||||
return immediateFuture(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
Blob blob = loadBlob(containerName, key);
|
|
||||||
|
|
||||||
if (options != null) {
|
|
||||||
if (options.getIfMatch() != null) {
|
|
||||||
if (!blob.getMetadata().getETag().equals(options.getIfMatch()))
|
|
||||||
return immediateFailedFuture(returnResponseException(412));
|
|
||||||
}
|
|
||||||
if (options.getIfNoneMatch() != null) {
|
|
||||||
if (blob.getMetadata().getETag().equals(options.getIfNoneMatch()))
|
|
||||||
return immediateFailedFuture(returnResponseException(304));
|
|
||||||
}
|
|
||||||
if (options.getIfModifiedSince() != null) {
|
|
||||||
Date modifiedSince = options.getIfModifiedSince();
|
|
||||||
if (blob.getMetadata().getLastModified().before(modifiedSince)) {
|
|
||||||
HttpResponse response = HttpResponse.builder().statusCode(304).build();
|
|
||||||
return immediateFailedFuture(new HttpResponseException(String.format("%1$s is before %2$s", blob
|
|
||||||
.getMetadata().getLastModified(), modifiedSince), null, response));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
if (options.getIfUnmodifiedSince() != null) {
|
|
||||||
Date unmodifiedSince = options.getIfUnmodifiedSince();
|
|
||||||
if (blob.getMetadata().getLastModified().after(unmodifiedSince)) {
|
|
||||||
HttpResponse response = HttpResponse.builder().statusCode(412).build();
|
|
||||||
return immediateFailedFuture(new HttpResponseException(String.format("%1$s is after %2$s", blob
|
|
||||||
.getMetadata().getLastModified(), unmodifiedSince), null, response));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
blob = copyBlob(blob);
|
|
||||||
|
|
||||||
if (options.getRanges() != null && options.getRanges().size() > 0) {
|
|
||||||
byte[] data;
|
|
||||||
try {
|
|
||||||
data = toByteArray(blob.getPayload());
|
|
||||||
} catch (IOException e) {
|
|
||||||
return immediateFailedFuture(new RuntimeException(e));
|
|
||||||
}
|
|
||||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
|
||||||
for (String s : options.getRanges()) {
|
|
||||||
// HTTP uses a closed interval while Java array indexing uses a
|
|
||||||
// half-open interval.
|
|
||||||
int offset = 0;
|
|
||||||
int last = data.length - 1;
|
|
||||||
if (s.startsWith("-")) {
|
|
||||||
offset = last - Integer.parseInt(s.substring(1)) + 1;
|
|
||||||
} else if (s.endsWith("-")) {
|
|
||||||
offset = Integer.parseInt(s.substring(0, s.length() - 1));
|
|
||||||
} else if (s.contains("-")) {
|
|
||||||
String[] firstLast = s.split("\\-");
|
|
||||||
offset = Integer.parseInt(firstLast[0]);
|
|
||||||
last = Integer.parseInt(firstLast[1]);
|
|
||||||
} else {
|
|
||||||
return immediateFailedFuture(new IllegalArgumentException("illegal range: " + s));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (offset > last) {
|
|
||||||
return immediateFailedFuture(new IllegalArgumentException("illegal range: " + s));
|
|
||||||
}
|
|
||||||
if (last + 1 > data.length) {
|
|
||||||
last = data.length - 1;
|
|
||||||
}
|
|
||||||
out.write(data, offset, last - offset + 1);
|
|
||||||
}
|
|
||||||
ContentMetadata cmd = blob.getPayload().getContentMetadata();
|
|
||||||
byte[] byteArray = out.toByteArray();
|
|
||||||
blob.setPayload(byteArray);
|
|
||||||
HttpUtils.copy(cmd, blob.getPayload().getContentMetadata());
|
|
||||||
blob.getPayload().getContentMetadata().setContentLength(new Long(byteArray.length));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
checkNotNull(blob.getPayload(), "payload " + blob);
|
|
||||||
return immediateFuture(blob);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public ListenableFuture<BlobMetadata> blobMetadata(final String container, final String key) {
|
|
||||||
try {
|
|
||||||
Blob blob = getBlob(container, key).get();
|
|
||||||
return immediateFuture(blob != null ? (BlobMetadata) copy(blob.getMetadata()) : null);
|
|
||||||
} catch (Exception e) {
|
|
||||||
if (size(filter(getCausalChain(e), KeyNotFoundException.class)) >= 1)
|
|
||||||
return immediateFuture(null);
|
|
||||||
return immediateFailedFuture(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Calculates the object MD5 and returns it as eTag
|
|
||||||
*
|
|
||||||
* @param object
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
private String getEtag(Blob object) {
|
|
||||||
try {
|
|
||||||
Payloads.calculateMD5(object, crypto.md5());
|
|
||||||
} catch (IOException ex) {
|
|
||||||
logger.error(ex, "An error occurred calculating MD5 for object with name %s.", object.getMetadata().getName());
|
|
||||||
Throwables.propagate(ex);
|
|
||||||
}
|
|
||||||
|
|
||||||
String eTag = CryptoStreams.hex(object.getPayload().getContentMetadata().getContentMD5());
|
|
||||||
return eTag;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Blob copyBlob(Blob blob) {
|
|
||||||
Blob returnVal = blobFactory.create(copy(blob.getMetadata()));
|
|
||||||
returnVal.setPayload(blob.getPayload());
|
|
||||||
copyPayloadHeadersToBlob(blob.getPayload(), returnVal);
|
|
||||||
return returnVal;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected boolean deleteAndVerifyContainerGone(final String container) {
|
|
||||||
storageStrategy.deleteContainer(container);
|
|
||||||
return storageStrategy.containerExists(container);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ListenableFuture<String> putBlob(String container, Blob blob, PutOptions options) {
|
|
||||||
// TODO implement options
|
|
||||||
return putBlob(container, blob);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ListenableFuture<Boolean> createContainerInLocation(Location location, String container,
|
|
||||||
CreateContainerOptions options) {
|
|
||||||
if (options.isPublicRead())
|
|
||||||
throw new UnsupportedOperationException("publicRead");
|
|
||||||
return createContainerInLocation(location, container);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -18,37 +18,87 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.blobstore;
|
package org.jclouds.blobstore;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.ConcurrentMap;
|
import java.util.concurrent.ConcurrentMap;
|
||||||
|
import javax.inject.Provider;
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import javax.ws.rs.core.HttpHeaders;
|
||||||
|
import javax.ws.rs.core.UriBuilder;
|
||||||
|
|
||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
import com.google.common.base.Supplier;
|
import com.google.common.base.Supplier;
|
||||||
|
import com.google.common.base.Throwables;
|
||||||
|
import com.google.common.collect.Multimaps;
|
||||||
|
|
||||||
import org.jclouds.blobstore.domain.Blob;
|
import org.jclouds.blobstore.domain.Blob;
|
||||||
|
import org.jclouds.blobstore.domain.Blob.Factory;
|
||||||
|
import org.jclouds.blobstore.domain.MutableBlobMetadata;
|
||||||
|
import org.jclouds.blobstore.options.ListContainerOptions;
|
||||||
|
import org.jclouds.blobstore.util.BlobStoreUtils;
|
||||||
|
import org.jclouds.crypto.Crypto;
|
||||||
|
import org.jclouds.crypto.CryptoStreams;
|
||||||
|
import org.jclouds.date.DateService;
|
||||||
import org.jclouds.domain.Location;
|
import org.jclouds.domain.Location;
|
||||||
|
import org.jclouds.http.HttpUtils;
|
||||||
|
import org.jclouds.io.ContentMetadataCodec;
|
||||||
|
import org.jclouds.io.MutableContentMetadata;
|
||||||
|
import org.jclouds.io.Payload;
|
||||||
|
import org.jclouds.io.Payloads;
|
||||||
|
import org.jclouds.io.payloads.ByteArrayPayload;
|
||||||
|
import org.jclouds.io.payloads.DelegatingPayload;
|
||||||
|
|
||||||
public class TransientStorageStrategy {
|
public class TransientStorageStrategy implements LocalStorageStrategy {
|
||||||
private final ConcurrentMap<String, ConcurrentMap<String, Blob>> containerToBlobs = new ConcurrentHashMap<String, ConcurrentMap<String, Blob>>();
|
private final ConcurrentMap<String, ConcurrentMap<String, Blob>> containerToBlobs = new ConcurrentHashMap<String, ConcurrentMap<String, Blob>>();
|
||||||
private final ConcurrentMap<String, Location> containerToLocation = new ConcurrentHashMap<String, Location>();
|
private final ConcurrentMap<String, Location> containerToLocation = new ConcurrentHashMap<String, Location>();
|
||||||
private final Supplier<Location> defaultLocation;
|
private final Supplier<Location> defaultLocation;
|
||||||
|
private final DateService dateService;
|
||||||
|
private final Factory blobFactory;
|
||||||
|
private final Crypto crypto;
|
||||||
|
private final ContentMetadataCodec contentMetadataCodec;
|
||||||
|
private final Provider<UriBuilder> uriBuilders;
|
||||||
|
|
||||||
public TransientStorageStrategy(final Supplier<Location> defaultLocation) {
|
@Inject
|
||||||
this.defaultLocation = Preconditions.checkNotNull(defaultLocation);
|
TransientStorageStrategy(final Supplier<Location> defaultLocation,
|
||||||
|
DateService dateService, Factory blobFactory, Crypto crypto,
|
||||||
|
ContentMetadataCodec contentMetadataCodec,
|
||||||
|
Provider<UriBuilder> uriBuilders) {
|
||||||
|
this.defaultLocation = defaultLocation;
|
||||||
|
this.dateService = dateService;
|
||||||
|
this.blobFactory = blobFactory;
|
||||||
|
this.crypto = crypto;
|
||||||
|
this.contentMetadataCodec = contentMetadataCodec;
|
||||||
|
this.uriBuilders = uriBuilders;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Iterable<String> getAllContainerNames() {
|
public Iterable<String> getAllContainerNames() {
|
||||||
return containerToBlobs.keySet();
|
return containerToBlobs.keySet();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean containerExists(final String containerName) {
|
public boolean containerExists(final String containerName) {
|
||||||
return containerToBlobs.containsKey(containerName);
|
return containerToBlobs.containsKey(containerName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void clearContainer(final String containerName) {
|
public void clearContainer(final String containerName) {
|
||||||
containerToBlobs.get(containerName).clear();
|
containerToBlobs.get(containerName).clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void clearContainer(String container, ListContainerOptions options) {
|
||||||
|
// TODO implement options
|
||||||
|
clearContainer(container);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean createContainerInLocation(final String containerName, final Location location) {
|
public boolean createContainerInLocation(final String containerName, final Location location) {
|
||||||
ConcurrentMap<String, Blob> origValue = containerToBlobs.putIfAbsent(
|
ConcurrentMap<String, Blob> origValue = containerToBlobs.putIfAbsent(
|
||||||
containerName, new ConcurrentHashMap<String, Blob>());
|
containerName, new ConcurrentHashMap<String, Blob>());
|
||||||
|
@ -59,36 +109,96 @@ public class TransientStorageStrategy {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void deleteContainer(final String containerName) {
|
public void deleteContainer(final String containerName) {
|
||||||
containerToBlobs.remove(containerName);
|
containerToBlobs.remove(containerName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean blobExists(final String containerName, final String blobName) {
|
public boolean blobExists(final String containerName, final String blobName) {
|
||||||
Map<String, Blob> map = containerToBlobs.get(containerName);
|
Map<String, Blob> map = containerToBlobs.get(containerName);
|
||||||
return map != null && map.containsKey(blobName);
|
return map != null && map.containsKey(blobName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Blob getBlob(final String containerName, final String blobName) {
|
public Blob getBlob(final String containerName, final String blobName) {
|
||||||
Map<String, Blob> map = containerToBlobs.get(containerName);
|
Map<String, Blob> map = containerToBlobs.get(containerName);
|
||||||
return map == null ? null : map.get(blobName);
|
return map == null ? null : map.get(blobName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void putBlob(final String containerName, final Blob blob) {
|
@Override
|
||||||
|
public String putBlob(final String containerName, final Blob blob) throws IOException {
|
||||||
|
Blob newBlob = createUpdatedCopyOfBlobInContainer(containerName, blob);
|
||||||
Map<String, Blob> map = containerToBlobs.get(containerName);
|
Map<String, Blob> map = containerToBlobs.get(containerName);
|
||||||
map.put(blob.getMetadata().getName(), blob);
|
map.put(newBlob.getMetadata().getName(), newBlob);
|
||||||
|
Payloads.calculateMD5(newBlob, crypto.md5());
|
||||||
|
String eTag = CryptoStreams.hex(newBlob.getPayload().getContentMetadata().getContentMD5());
|
||||||
|
return eTag;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void removeBlob(final String containerName, final String blobName) {
|
public void removeBlob(final String containerName, final String blobName) {
|
||||||
Map<String, Blob> map = containerToBlobs.get(containerName);
|
Map<String, Blob> map = containerToBlobs.get(containerName);
|
||||||
if (map != null)
|
if (map != null)
|
||||||
map.remove(blobName);
|
map.remove(blobName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Iterable<String> getBlobKeysInsideContainer(final String containerName) {
|
public Iterable<String> getBlobKeysInsideContainer(final String containerName) {
|
||||||
return containerToBlobs.get(containerName).keySet();
|
return containerToBlobs.get(containerName).keySet();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Location getLocation(final String containerName) {
|
public Location getLocation(final String containerName) {
|
||||||
return containerToLocation.get(containerName);
|
return containerToLocation.get(containerName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getSeparator() {
|
||||||
|
return "/";
|
||||||
|
}
|
||||||
|
|
||||||
|
private Blob createUpdatedCopyOfBlobInContainer(String containerName, Blob in) {
|
||||||
|
checkNotNull(in, "blob");
|
||||||
|
checkNotNull(in.getPayload(), "blob.payload");
|
||||||
|
ByteArrayPayload payload = (in.getPayload() instanceof ByteArrayPayload) ? ByteArrayPayload.class.cast(in
|
||||||
|
.getPayload()) : null;
|
||||||
|
if (payload == null)
|
||||||
|
payload = (in.getPayload() instanceof DelegatingPayload) ? (DelegatingPayload.class.cast(in.getPayload())
|
||||||
|
.getDelegate() instanceof ByteArrayPayload) ? ByteArrayPayload.class.cast(DelegatingPayload.class
|
||||||
|
.cast(in.getPayload()).getDelegate()) : null : null;
|
||||||
|
try {
|
||||||
|
if (payload == null || !(payload instanceof ByteArrayPayload)) {
|
||||||
|
MutableContentMetadata oldMd = in.getPayload().getContentMetadata();
|
||||||
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||||
|
in.getPayload().writeTo(out);
|
||||||
|
payload = (ByteArrayPayload) Payloads.calculateMD5(Payloads.newPayload(out.toByteArray()));
|
||||||
|
HttpUtils.copy(oldMd, payload.getContentMetadata());
|
||||||
|
} else {
|
||||||
|
if (payload.getContentMetadata().getContentMD5() == null)
|
||||||
|
Payloads.calculateMD5(in, crypto.md5());
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
Throwables.propagate(e);
|
||||||
|
}
|
||||||
|
Blob blob = blobFactory.create(BlobStoreUtils.copy(in.getMetadata()));
|
||||||
|
blob.setPayload(payload);
|
||||||
|
blob.getMetadata().setContainer(containerName);
|
||||||
|
blob.getMetadata().setUri(
|
||||||
|
uriBuilders.get().scheme("mem").host(containerName).path(in.getMetadata().getName()).build());
|
||||||
|
blob.getMetadata().setLastModified(new Date());
|
||||||
|
String eTag = CryptoStreams.hex(payload.getContentMetadata().getContentMD5());
|
||||||
|
blob.getMetadata().setETag(eTag);
|
||||||
|
// Set HTTP headers to match metadata
|
||||||
|
blob.getAllHeaders().replaceValues(HttpHeaders.LAST_MODIFIED,
|
||||||
|
Collections.singleton(dateService.rfc822DateFormat(blob.getMetadata().getLastModified())));
|
||||||
|
blob.getAllHeaders().replaceValues(HttpHeaders.ETAG, Collections.singleton(eTag));
|
||||||
|
copyPayloadHeadersToBlob(payload, blob);
|
||||||
|
blob.getAllHeaders().putAll(Multimaps.forMap(blob.getMetadata().getUserMetadata()));
|
||||||
|
return blob;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void copyPayloadHeadersToBlob(Payload payload, Blob blob) {
|
||||||
|
blob.getAllHeaders().putAll(contentMetadataCodec.toHeaders(payload.getContentMetadata()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,6 @@ import org.jclouds.blobstore.BlobStore;
|
||||||
import org.jclouds.concurrent.Timeout;
|
import org.jclouds.concurrent.Timeout;
|
||||||
|
|
||||||
@Timeout(duration = 2, timeUnit = TimeUnit.MINUTES)
|
@Timeout(duration = 2, timeUnit = TimeUnit.MINUTES)
|
||||||
public interface TransientBlobStore extends BlobStore {
|
public interface LocalBlobStore extends BlobStore {
|
||||||
|
|
||||||
}
|
}
|
|
@ -21,8 +21,10 @@ package org.jclouds.blobstore.config;
|
||||||
import org.jclouds.blobstore.AsyncBlobStore;
|
import org.jclouds.blobstore.AsyncBlobStore;
|
||||||
import org.jclouds.blobstore.BlobRequestSigner;
|
import org.jclouds.blobstore.BlobRequestSigner;
|
||||||
import org.jclouds.blobstore.BlobStore;
|
import org.jclouds.blobstore.BlobStore;
|
||||||
import org.jclouds.blobstore.TransientAsyncBlobStore;
|
import org.jclouds.blobstore.LocalAsyncBlobStore;
|
||||||
|
import org.jclouds.blobstore.LocalStorageStrategy;
|
||||||
import org.jclouds.blobstore.TransientBlobRequestSigner;
|
import org.jclouds.blobstore.TransientBlobRequestSigner;
|
||||||
|
import org.jclouds.blobstore.TransientStorageStrategy;
|
||||||
import org.jclouds.blobstore.attr.ConsistencyModel;
|
import org.jclouds.blobstore.attr.ConsistencyModel;
|
||||||
import org.jclouds.rest.config.BinderUtils;
|
import org.jclouds.rest.config.BinderUtils;
|
||||||
|
|
||||||
|
@ -37,13 +39,14 @@ import com.google.inject.AbstractModule;
|
||||||
public class TransientBlobStoreContextModule extends AbstractModule {
|
public class TransientBlobStoreContextModule extends AbstractModule {
|
||||||
@Override
|
@Override
|
||||||
protected void configure() {
|
protected void configure() {
|
||||||
bind(AsyncBlobStore.class).to(TransientAsyncBlobStore.class).asEagerSingleton();
|
bind(AsyncBlobStore.class).to(LocalAsyncBlobStore.class).asEagerSingleton();
|
||||||
// forward all requests from TransientBlobStore to TransientAsyncBlobStore. needs above binding as cannot proxy a class
|
// forward all requests from TransientBlobStore to TransientAsyncBlobStore. needs above binding as cannot proxy a class
|
||||||
BinderUtils.bindClient(binder(), TransientBlobStore.class, AsyncBlobStore.class, ImmutableMap.<Class<?>, Class<?>>of());
|
BinderUtils.bindClient(binder(), LocalBlobStore.class, AsyncBlobStore.class, ImmutableMap.<Class<?>, Class<?>>of());
|
||||||
install(new BlobStoreObjectModule());
|
install(new BlobStoreObjectModule());
|
||||||
install(new BlobStoreMapModule());
|
install(new BlobStoreMapModule());
|
||||||
bind(BlobStore.class).to(TransientBlobStore.class);
|
bind(BlobStore.class).to(LocalBlobStore.class);
|
||||||
bind(ConsistencyModel.class).toInstance(ConsistencyModel.STRICT);
|
bind(ConsistencyModel.class).toInstance(ConsistencyModel.STRICT);
|
||||||
|
bind(LocalStorageStrategy.class).to(TransientStorageStrategy.class);
|
||||||
bind(BlobRequestSigner.class).to(TransientBlobRequestSigner.class);
|
bind(BlobRequestSigner.class).to(TransientBlobRequestSigner.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,8 +20,15 @@ package org.jclouds.blobstore.util;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.io.ObjectInput;
|
||||||
|
import java.io.ObjectInputStream;
|
||||||
|
import java.io.ObjectOutput;
|
||||||
|
import java.io.ObjectOutputStream;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
@ -32,6 +39,7 @@ import org.jclouds.blobstore.ContainerNotFoundException;
|
||||||
import org.jclouds.blobstore.KeyNotFoundException;
|
import org.jclouds.blobstore.KeyNotFoundException;
|
||||||
import org.jclouds.blobstore.domain.Blob;
|
import org.jclouds.blobstore.domain.Blob;
|
||||||
import org.jclouds.blobstore.domain.BlobMetadata;
|
import org.jclouds.blobstore.domain.BlobMetadata;
|
||||||
|
import org.jclouds.blobstore.domain.MutableBlobMetadata;
|
||||||
import org.jclouds.blobstore.domain.StorageMetadata;
|
import org.jclouds.blobstore.domain.StorageMetadata;
|
||||||
import org.jclouds.blobstore.functions.BlobName;
|
import org.jclouds.blobstore.functions.BlobName;
|
||||||
import org.jclouds.functions.ExceptionToValueOrPropagate;
|
import org.jclouds.functions.ExceptionToValueOrPropagate;
|
||||||
|
@ -41,6 +49,8 @@ import org.jclouds.http.HttpUtils;
|
||||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||||
import org.jclouds.util.Strings2;
|
import org.jclouds.util.Strings2;
|
||||||
|
|
||||||
|
import com.google.common.base.Throwables;
|
||||||
|
import com.google.common.collect.Maps;
|
||||||
import com.google.common.reflect.TypeToken;
|
import com.google.common.reflect.TypeToken;
|
||||||
import com.google.common.util.concurrent.Futures;
|
import com.google.common.util.concurrent.Futures;
|
||||||
import com.google.common.util.concurrent.ListenableFuture;
|
import com.google.common.util.concurrent.ListenableFuture;
|
||||||
|
@ -159,4 +169,34 @@ public class BlobStoreUtils {
|
||||||
public static Iterable<String> getSupportedProviders() {
|
public static Iterable<String> getSupportedProviders() {
|
||||||
return org.jclouds.rest.Providers.getSupportedProvidersOfType(TypeToken.of(BlobStoreContext.class));
|
return org.jclouds.rest.Providers.getSupportedProvidersOfType(TypeToken.of(BlobStoreContext.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static MutableBlobMetadata copy(MutableBlobMetadata in) {
|
||||||
|
ByteArrayOutputStream bout = new ByteArrayOutputStream();
|
||||||
|
ObjectOutput os;
|
||||||
|
try {
|
||||||
|
os = new ObjectOutputStream(bout);
|
||||||
|
os.writeObject(in);
|
||||||
|
ObjectInput is = new ObjectInputStream(new ByteArrayInputStream(bout.toByteArray()));
|
||||||
|
MutableBlobMetadata metadata = (MutableBlobMetadata) is.readObject();
|
||||||
|
convertUserMetadataKeysToLowercase(metadata);
|
||||||
|
HttpUtils.copy(in.getContentMetadata(), metadata.getContentMetadata());
|
||||||
|
return metadata;
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw Throwables.propagate(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static MutableBlobMetadata copy(MutableBlobMetadata in, String newKey) {
|
||||||
|
MutableBlobMetadata newMd = BlobStoreUtils.copy(in);
|
||||||
|
newMd.setName(newKey);
|
||||||
|
return newMd;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void convertUserMetadataKeysToLowercase(MutableBlobMetadata metadata) {
|
||||||
|
Map<String, String> lowerCaseUserMetadata = Maps.newHashMap();
|
||||||
|
for (Map.Entry<String, String> entry : metadata.getUserMetadata().entrySet()) {
|
||||||
|
lowerCaseUserMetadata.put(entry.getKey().toLowerCase(), entry.getValue());
|
||||||
|
}
|
||||||
|
metadata.setUserMetadata(lowerCaseUserMetadata);
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -42,7 +42,7 @@ import com.google.inject.TypeLiteral;
|
||||||
*/
|
*/
|
||||||
// NOTE:without testName, this will not call @Before* and fail w/NPE during surefire
|
// NOTE:without testName, this will not call @Before* and fail w/NPE during surefire
|
||||||
@Test(groups = "unit", testName = "TransientBlobRequestSignerTest")
|
@Test(groups = "unit", testName = "TransientBlobRequestSignerTest")
|
||||||
public class TransientBlobRequestSignerTest extends BaseAsyncClientTest<TransientAsyncBlobStore> {
|
public class TransientBlobRequestSignerTest extends BaseAsyncClientTest<LocalAsyncBlobStore> {
|
||||||
|
|
||||||
private BlobRequestSigner signer;
|
private BlobRequestSigner signer;
|
||||||
private Provider<BlobBuilder> blobFactory;
|
private Provider<BlobBuilder> blobFactory;
|
||||||
|
@ -121,8 +121,8 @@ public class TransientBlobRequestSignerTest extends BaseAsyncClientTest<Transien
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected TypeLiteral<RestAnnotationProcessor<TransientAsyncBlobStore>> createTypeLiteral() {
|
protected TypeLiteral<RestAnnotationProcessor<LocalAsyncBlobStore>> createTypeLiteral() {
|
||||||
return new TypeLiteral<RestAnnotationProcessor<TransientAsyncBlobStore>>() {
|
return new TypeLiteral<RestAnnotationProcessor<LocalAsyncBlobStore>>() {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -65,8 +65,8 @@ public class BindBlobToMultipartFormTest {
|
||||||
HttpRequest request = HttpRequest.builder().method("GET").endpoint("http://localhost:8001").build();
|
HttpRequest request = HttpRequest.builder().method("GET").endpoint("http://localhost:8001").build();
|
||||||
binder.bindToRequest(request, TEST_BLOB);
|
binder.bindToRequest(request, TEST_BLOB);
|
||||||
|
|
||||||
assertEquals(Strings2.toStringAndClose(request.getPayload().getInput()), EXPECTS);
|
assertEquals(Strings2.toString(request.getPayload()), EXPECTS);
|
||||||
assertEquals(request.getPayload().getContentMetadata().getContentLength(), new Long(113));
|
assertEquals(request.getPayload().getContentMetadata().getContentLength(), Long.valueOf(113));
|
||||||
|
|
||||||
assertEquals(request.getPayload().getContentMetadata().getContentType(), "multipart/form-data; boundary="
|
assertEquals(request.getPayload().getContentMetadata().getContentType(), "multipart/form-data; boundary="
|
||||||
+ BOUNDARY);
|
+ BOUNDARY);
|
||||||
|
|
|
@ -85,7 +85,7 @@ public class ParseBlobFromHeadersAndHttpContentTest {
|
||||||
replay(metadataParser);
|
replay(metadataParser);
|
||||||
|
|
||||||
Blob object = callable.apply(response);
|
Blob object = callable.apply(response);
|
||||||
assertEquals(object.getPayload().getContentMetadata().getContentLength(), new Long(10485760));
|
assertEquals(object.getPayload().getContentMetadata().getContentLength(), Long.valueOf(10485760));
|
||||||
assertEquals(object.getAllHeaders().get("Content-Range"), Collections.singletonList("0-10485759/20232760"));
|
assertEquals(object.getAllHeaders().get("Content-Range"), Collections.singletonList("0-10485759/20232760"));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,7 @@ public class ReturnFalseOnContainerNotFoundTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFoundIsFalse() throws SecurityException, NoSuchMethodException {
|
public void testFoundIsFalse() throws SecurityException, NoSuchMethodException {
|
||||||
assertEquals(fn.apply(new ContainerNotFoundException()), new Boolean(false));
|
assertEquals(fn.apply(new ContainerNotFoundException()), Boolean.FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expectedExceptions = { RuntimeException.class })
|
@Test(expectedExceptions = { RuntimeException.class })
|
||||||
|
|
|
@ -33,7 +33,7 @@ public class ReturnFalseOnKeyNotFoundTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFoundIsFalse() throws SecurityException, NoSuchMethodException {
|
public void testFoundIsFalse() throws SecurityException, NoSuchMethodException {
|
||||||
assertEquals(fn.apply(new KeyNotFoundException()), new Boolean(false));
|
assertEquals(fn.apply(new KeyNotFoundException()), Boolean.FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expectedExceptions = { RuntimeException.class })
|
@Test(expectedExceptions = { RuntimeException.class })
|
||||||
|
|
|
@ -637,7 +637,7 @@ public class BaseBlobIntegrationTest extends BaseBlobStoreIntegrationTest {
|
||||||
protected void validateMetadata(BlobMetadata metadata) throws IOException {
|
protected void validateMetadata(BlobMetadata metadata) throws IOException {
|
||||||
assert metadata.getContentMetadata().getContentType().startsWith("text/plain") : metadata.getContentMetadata()
|
assert metadata.getContentMetadata().getContentType().startsWith("text/plain") : metadata.getContentMetadata()
|
||||||
.getContentType();
|
.getContentType();
|
||||||
assertEquals(metadata.getContentMetadata().getContentLength(), new Long(TEST_STRING.length()));
|
assertEquals(metadata.getContentMetadata().getContentLength(), Long.valueOf(TEST_STRING.length()));
|
||||||
assertEquals(metadata.getUserMetadata().get("adrian"), "powderpuff");
|
assertEquals(metadata.getUserMetadata().get("adrian"), "powderpuff");
|
||||||
checkMD5(metadata);
|
checkMD5(metadata);
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,7 +67,7 @@ public class BaseBlobSignerLiveTest extends BaseBlobStoreIntegrationTest {
|
||||||
assertConsistencyAwareContainerSize(container, 1);
|
assertConsistencyAwareContainerSize(container, 1);
|
||||||
HttpRequest request = view.getSigner().signGetBlob(container, name);
|
HttpRequest request = view.getSigner().signGetBlob(container, name);
|
||||||
assertEquals(request.getFilters().size(), 0);
|
assertEquals(request.getFilters().size(), 0);
|
||||||
assertEquals(Strings2.toStringAndClose(view.utils().http().invoke(request).getPayload().getInput()), text);
|
assertEquals(Strings2.toString(view.utils().http().invoke(request).getPayload()), text);
|
||||||
} finally {
|
} finally {
|
||||||
returnContainer(container);
|
returnContainer(container);
|
||||||
}
|
}
|
||||||
|
@ -85,7 +85,7 @@ public class BaseBlobSignerLiveTest extends BaseBlobStoreIntegrationTest {
|
||||||
assertConsistencyAwareContainerSize(container, 1);
|
assertConsistencyAwareContainerSize(container, 1);
|
||||||
HttpRequest request = view.getSigner().signGetBlob(container, name, range(0, 1));
|
HttpRequest request = view.getSigner().signGetBlob(container, name, range(0, 1));
|
||||||
assertEquals(request.getFilters().size(), 0);
|
assertEquals(request.getFilters().size(), 0);
|
||||||
assertEquals(Strings2.toStringAndClose(view.utils().http().invoke(request).getPayload().getInput()), "fo");
|
assertEquals(Strings2.toString(view.utils().http().invoke(request).getPayload()), "fo");
|
||||||
} finally {
|
} finally {
|
||||||
returnContainer(container);
|
returnContainer(container);
|
||||||
}
|
}
|
||||||
|
@ -101,7 +101,7 @@ public class BaseBlobSignerLiveTest extends BaseBlobStoreIntegrationTest {
|
||||||
try {
|
try {
|
||||||
HttpRequest request = view.getSigner().signPutBlob(container, blob);
|
HttpRequest request = view.getSigner().signPutBlob(container, blob);
|
||||||
assertEquals(request.getFilters().size(), 0);
|
assertEquals(request.getFilters().size(), 0);
|
||||||
Strings2.toStringAndClose(view.utils().http().invoke(request).getPayload().getInput());
|
Strings2.toString(view.utils().http().invoke(request).getPayload());
|
||||||
assertConsistencyAwareContainerSize(container, 1);
|
assertConsistencyAwareContainerSize(container, 1);
|
||||||
} finally {
|
} finally {
|
||||||
returnContainer(container);
|
returnContainer(container);
|
||||||
|
|
|
@ -88,7 +88,7 @@ public class BaseContainerIntegrationTest extends BaseBlobStoreIntegrationTest {
|
||||||
|
|
||||||
assert metadata.getContentMetadata().getContentType().startsWith("text/plain") : metadata.getContentMetadata()
|
assert metadata.getContentMetadata().getContentType().startsWith("text/plain") : metadata.getContentMetadata()
|
||||||
.getContentType();
|
.getContentType();
|
||||||
assertEquals(metadata.getContentMetadata().getContentLength(), new Long(TEST_STRING.length()));
|
assertEquals(metadata.getContentMetadata().getContentLength(), Long.valueOf(TEST_STRING.length()));
|
||||||
assertEquals(metadata.getUserMetadata().get("adrian"), "powderpuff");
|
assertEquals(metadata.getUserMetadata().get("adrian"), "powderpuff");
|
||||||
checkMD5(metadata);
|
checkMD5(metadata);
|
||||||
} finally {
|
} finally {
|
||||||
|
|
|
@ -64,7 +64,7 @@ public class ListOptionsTest {
|
||||||
ListContainerOptions options = new ListContainerOptions();
|
ListContainerOptions options = new ListContainerOptions();
|
||||||
options.inDirectory("test").maxResults(1);
|
options.inDirectory("test").maxResults(1);
|
||||||
assertEquals(options.getDir(), "test");
|
assertEquals(options.getDir(), "test");
|
||||||
assertEquals(options.getMaxResults(), new Integer(1));
|
assertEquals(options.getMaxResults(), Integer.valueOf(1));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,7 +108,7 @@ public class ListOptionsTest {
|
||||||
public void testMaxResults() {
|
public void testMaxResults() {
|
||||||
ListContainerOptions options = new ListContainerOptions();
|
ListContainerOptions options = new ListContainerOptions();
|
||||||
options.maxResults(1000);
|
options.maxResults(1000);
|
||||||
assertEquals(options.getMaxResults(), new Integer(1000));
|
assertEquals(options.getMaxResults(), Integer.valueOf(1000));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -120,7 +120,7 @@ public class ListOptionsTest {
|
||||||
@Test
|
@Test
|
||||||
public void testMaxResultsStatic() {
|
public void testMaxResultsStatic() {
|
||||||
ListContainerOptions options = maxResults(1000);
|
ListContainerOptions options = maxResults(1000);
|
||||||
assertEquals(options.getMaxResults(), new Integer(1000));
|
assertEquals(options.getMaxResults(), Integer.valueOf(1000));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||||
|
|
|
@ -81,7 +81,7 @@ public class ParseAWSErrorFromXmlContent implements HttpErrorHandler {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
message = Strings2.toStringAndClose(response.getPayload().getInput());
|
message = Strings2.toString(response.getPayload());
|
||||||
exception = new HttpResponseException(command, response, message);
|
exception = new HttpResponseException(command, response, message);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,7 +67,7 @@ public class ParseAzureStorageErrorFromXmlContent implements HttpErrorHandler {
|
||||||
if (response.getPayload() != null) {
|
if (response.getPayload() != null) {
|
||||||
String contentType = response.getPayload().getContentMetadata().getContentType();
|
String contentType = response.getPayload().getContentMetadata().getContentType();
|
||||||
if (contentType != null && (contentType.indexOf("xml") != -1 || contentType.indexOf("unknown") != -1)
|
if (contentType != null && (contentType.indexOf("xml") != -1 || contentType.indexOf("unknown") != -1)
|
||||||
&& !new Long(0).equals(response.getPayload().getContentMetadata().getContentLength())) {
|
&& !Long.valueOf(0).equals(response.getPayload().getContentMetadata().getContentLength())) {
|
||||||
try {
|
try {
|
||||||
error = utils.parseAzureStorageErrorFromContent(command, response, response.getPayload().getInput());
|
error = utils.parseAzureStorageErrorFromContent(command, response, response.getPayload().getInput());
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
|
@ -76,14 +76,14 @@ public class ParseAzureStorageErrorFromXmlContent implements HttpErrorHandler {
|
||||||
}
|
}
|
||||||
} catch (RuntimeException e) {
|
} catch (RuntimeException e) {
|
||||||
try {
|
try {
|
||||||
message = Strings2.toStringAndClose(response.getPayload().getInput());
|
message = Strings2.toString(response.getPayload());
|
||||||
exception = new HttpResponseException(command, response, message);
|
exception = new HttpResponseException(command, response, message);
|
||||||
} catch (IOException e1) {
|
} catch (IOException e1) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
message = Strings2.toStringAndClose(response.getPayload().getInput());
|
message = Strings2.toString(response.getPayload());
|
||||||
exception = new HttpResponseException(command, response, message);
|
exception = new HttpResponseException(command, response, message);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
}
|
}
|
||||||
|
|
|
@ -94,7 +94,7 @@ public class ListOptions extends BaseHttpRequestOptions {
|
||||||
|
|
||||||
public Integer getMaxResults() {
|
public Integer getMaxResults() {
|
||||||
String maxresults = getFirstQueryOrNull("maxresults");
|
String maxresults = getFirstQueryOrNull("maxresults");
|
||||||
return (maxresults != null) ? new Integer(maxresults) : null;
|
return (maxresults != null) ? Integer.valueOf(maxresults) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Builder {
|
public static class Builder {
|
||||||
|
|
|
@ -137,7 +137,7 @@ public class BindVAppConfigurationToXmlPayload implements MapBinder, Function<Ob
|
||||||
private void addDiskItems(XMLBuilder sectionBuilder, VApp vApp, VAppConfiguration configuration) {
|
private void addDiskItems(XMLBuilder sectionBuilder, VApp vApp, VAppConfiguration configuration) {
|
||||||
for (ResourceAllocationSettingData disk : filter(vApp.getResourceAllocations(), CIMPredicates
|
for (ResourceAllocationSettingData disk : filter(vApp.getResourceAllocations(), CIMPredicates
|
||||||
.resourceTypeIn(ResourceType.DISK_DRIVE))) {
|
.resourceTypeIn(ResourceType.DISK_DRIVE))) {
|
||||||
if (!configuration.getDisksToDelete().contains(new Integer(disk.getAddressOnParent()))) {
|
if (!configuration.getDisksToDelete().contains(Integer.valueOf(disk.getAddressOnParent()))) {
|
||||||
addDiskWithQuantity(sectionBuilder, disk);
|
addDiskWithQuantity(sectionBuilder, disk);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -101,7 +101,7 @@ public class ParseTerremarkVCloudErrorFromHttpResponse implements HttpErrorHandl
|
||||||
String parseErrorFromContentOrNull(HttpCommand command, HttpResponse response) {
|
String parseErrorFromContentOrNull(HttpCommand command, HttpResponse response) {
|
||||||
if (response.getPayload() != null) {
|
if (response.getPayload() != null) {
|
||||||
try {
|
try {
|
||||||
return Strings2.toStringAndClose(response.getPayload().getInput());
|
return Strings2.toString(response.getPayload());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
logger.warn(e, "exception reading error from response", response);
|
logger.warn(e, "exception reading error from response", response);
|
||||||
}
|
}
|
||||||
|
|
|
@ -91,7 +91,7 @@ public class VAppHandler extends ParseSax.HandlerWithResult<VApp> {
|
||||||
String statusString = attributes.get("status");
|
String statusString = attributes.get("status");
|
||||||
status = Status.fromValue(statusString);
|
status = Status.fromValue(statusString);
|
||||||
if (attributes.containsKey("size"))
|
if (attributes.containsKey("size"))
|
||||||
size = new Long(attributes.get("size"));
|
size = Long.valueOf(attributes.get("size"));
|
||||||
} else if (qName.equals("Link")) { // type should never be missing
|
} else if (qName.equals("Link")) { // type should never be missing
|
||||||
if (attributes.containsKey("type")) {
|
if (attributes.containsKey("type")) {
|
||||||
if (attributes.get("type").equals(TerremarkVCloudMediaType.VDC_XML)) {
|
if (attributes.get("type").equals(TerremarkVCloudMediaType.VDC_XML)) {
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue