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 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.
|
||||
We offer several API abstractions as java and clojure libraries. The following are the most mature:
|
||||
jclouds allows provisioning and control of cloud resources, including blobstore
|
||||
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
|
||||
--------
|
||||
|
|
12
README.txt
12
README.txt
|
@ -1,11 +1,11 @@
|
|||
Overview:
|
||||
|
||||
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 to
|
||||
freedom to use portable abstractions or cloud-specific features. We have
|
||||
two abstractions at the moment: compute and blobstore. compute helps you
|
||||
bootstrap machines in the cloud. blobstore helps you manage key-value
|
||||
data.
|
||||
jclouds allows provisioning and control of cloud resources, including blobstore
|
||||
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
|
||||
|
||||
our current version is 1.4.2
|
||||
our next maintenance version is 1.4.2-SNAPSHOT
|
||||
|
|
|
@ -71,7 +71,7 @@ public class ParseAtmosErrorFromXmlContent implements HttpErrorHandler {
|
|||
AtmosError error = null;
|
||||
if (response.getPayload() != null) {
|
||||
try {
|
||||
String content = Strings2.toStringAndClose(response.getPayload().getInput());
|
||||
String content = Strings2.toString(response.getPayload());
|
||||
if (content != null && content.indexOf('<') >= 0) {
|
||||
error = utils.parseAtmosErrorFromContent(command, response, Strings2.toInputStream(content));
|
||||
} else {
|
||||
|
|
|
@ -72,7 +72,7 @@ public class ListOptions extends BaseHttpRequestOptions {
|
|||
|
||||
public Integer getLimit() {
|
||||
String maxresults = getFirstHeaderOrNull("x-emc-limit");
|
||||
return (maxresults != null) ? new Integer(maxresults) : null;
|
||||
return (maxresults != null) ? Integer.valueOf(maxresults) : null;
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
|
|
|
@ -239,19 +239,19 @@ public class AtmosClientLiveTest extends BaseBlobStoreIntegrationTest {
|
|||
private static void verifyHeadObject(AtmosClient connection, String path, String metadataValue)
|
||||
throws InterruptedException, ExecutionException, TimeoutException, IOException {
|
||||
AtmosObject getBlob = connection.headFile(path);
|
||||
assertEquals(Strings2.toStringAndClose(getBlob.getPayload().getInput()), "");
|
||||
assertEquals(Strings2.toString(getBlob.getPayload()), "");
|
||||
verifyMetadata(metadataValue, getBlob);
|
||||
}
|
||||
|
||||
private static void verifyObject(AtmosClient connection, String path, String compare, String metadataValue)
|
||||
throws InterruptedException, ExecutionException, TimeoutException, IOException {
|
||||
AtmosObject getBlob = connection.readFile(path);
|
||||
assertEquals(Strings2.toStringAndClose(getBlob.getPayload().getInput()), compare);
|
||||
assertEquals(Strings2.toString(getBlob.getPayload()), compare);
|
||||
verifyMetadata(metadataValue, 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");
|
||||
assertEquals(getBlob.getUserMetadata().getMetadata().get("Metadata"), metadataValue);
|
||||
SystemMetadata md = getBlob.getSystemMetadata();
|
||||
|
|
|
@ -43,7 +43,7 @@ import org.jclouds.atmos.domain.SystemMetadata;
|
|||
import org.jclouds.atmos.domain.UserMetadata;
|
||||
import org.jclouds.atmos.options.ListOptions;
|
||||
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.BlobMetadata;
|
||||
import org.jclouds.blobstore.functions.HttpGetOptionsListToGetOptions;
|
||||
|
@ -61,7 +61,7 @@ import com.google.common.util.concurrent.ListenableFuture;
|
|||
*/
|
||||
public class StubAtmosAsyncClient implements AtmosAsyncClient {
|
||||
private final HttpGetOptionsListToGetOptions httpGetOptionsConverter;
|
||||
private final TransientAsyncBlobStore blobStore;
|
||||
private final LocalAsyncBlobStore blobStore;
|
||||
private final AtmosObject.Factory objectProvider;
|
||||
private final ObjectToBlob object2Blob;
|
||||
private final BlobToObject blob2Object;
|
||||
|
@ -71,7 +71,7 @@ public class StubAtmosAsyncClient implements AtmosAsyncClient {
|
|||
private final ExecutorService service;
|
||||
|
||||
@Inject
|
||||
private StubAtmosAsyncClient(TransientAsyncBlobStore blobStore, AtmosObject.Factory objectProvider,
|
||||
private StubAtmosAsyncClient(LocalAsyncBlobStore blobStore, AtmosObject.Factory objectProvider,
|
||||
HttpGetOptionsListToGetOptions httpGetOptionsConverter, ObjectToBlob object2Blob, BlobToObject blob2Object,
|
||||
BlobMetadataToObject blob2ObjectInfo, ListOptionsToBlobStoreListOptions container2ContainerListOptions,
|
||||
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService service,
|
||||
|
|
|
@ -85,7 +85,7 @@ public class ParseCloudLoadBalancersErrorFromHttpResponse implements HttpErrorHa
|
|||
String parseErrorFromContentOrNull(HttpCommand command, HttpResponse response) {
|
||||
if (response.getPayload() != null) {
|
||||
try {
|
||||
return Strings2.toStringAndClose(response.getPayload().getInput());
|
||||
return Strings2.toString(response.getPayload());
|
||||
} catch (IOException e) {
|
||||
logger.warn(e, "exception reading error from response", response);
|
||||
}
|
||||
|
|
|
@ -136,7 +136,7 @@ public class LoadBalancerClientLiveTest extends BaseCloudLoadBalancersClientLive
|
|||
assertEquals(lb.getRegion(), region);
|
||||
assertEquals(lb.getName(), name);
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
|
@ -85,7 +85,7 @@ public class ParseCloudServersErrorFromHttpResponse implements HttpErrorHandler
|
|||
String parseErrorFromContentOrNull(HttpCommand command, HttpResponse response) {
|
||||
if (response.getPayload() != null) {
|
||||
try {
|
||||
return Strings2.toStringAndClose(response.getPayload().getInput());
|
||||
return Strings2.toString(response.getPayload());
|
||||
} catch (IOException e) {
|
||||
logger.warn(e, "exception reading error from response", response);
|
||||
}
|
||||
|
|
|
@ -344,8 +344,8 @@ public class CloudServersClientLiveTest extends BaseComputeServiceContextLiveTes
|
|||
assertNotNull(server.getHostId());
|
||||
assertEquals(server.getStatus(), ServerStatus.ACTIVE);
|
||||
assert server.getProgress() >= 0 : "newDetails.getProgress()" + server.getProgress();
|
||||
assertEquals(new Integer(14362), server.getImageId());
|
||||
assertEquals(new Integer(1), server.getFlavorId());
|
||||
assertEquals(Integer.valueOf(14362), server.getImageId());
|
||||
assertEquals(Integer.valueOf(1), server.getFlavorId());
|
||||
assertNotNull(server.getAddresses());
|
||||
// listAddresses tests..
|
||||
assertEquals(client.getAddresses(serverId), server.getAddresses());
|
||||
|
@ -383,7 +383,7 @@ public class CloudServersClientLiveTest extends BaseComputeServiceContextLiveTes
|
|||
try {
|
||||
client.connect();
|
||||
Payload etcPasswd = client.get("/etc/jclouds.txt");
|
||||
String etcPasswdContents = Strings2.toStringAndClose(etcPasswd.getInput());
|
||||
String etcPasswdContents = Strings2.toString(etcPasswd);
|
||||
assertEquals("rackspace", etcPasswdContents.trim());
|
||||
} finally {
|
||||
if (client != null)
|
||||
|
@ -445,7 +445,7 @@ public class CloudServersClientLiveTest extends BaseComputeServiceContextLiveTes
|
|||
blockUntilServerActive(serverId2);
|
||||
assertIpConfigured(server, adminPass2);
|
||||
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) {
|
||||
|
@ -518,7 +518,7 @@ public class CloudServersClientLiveTest extends BaseComputeServiceContextLiveTes
|
|||
public void testCreateImage() throws Exception {
|
||||
Image image = client.createImageFromServer("hoofie", serverId);
|
||||
assertEquals("hoofie", image.getName());
|
||||
assertEquals(new Integer(serverId), image.getServerId());
|
||||
assertEquals(Integer.valueOf(serverId), image.getServerId());
|
||||
imageId = image.getId();
|
||||
blockUntilImageActive(imageId);
|
||||
}
|
||||
|
@ -528,7 +528,7 @@ public class CloudServersClientLiveTest extends BaseComputeServiceContextLiveTes
|
|||
client.rebuildServer(serverId, new RebuildServerOptions().withImage(imageId));
|
||||
blockUntilServerActive(serverId);
|
||||
// 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")
|
||||
|
@ -549,7 +549,7 @@ public class CloudServersClientLiveTest extends BaseComputeServiceContextLiveTes
|
|||
blockUntilServerVerifyResize(serverId);
|
||||
client.revertResizeServer(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")
|
||||
|
@ -558,7 +558,7 @@ public class CloudServersClientLiveTest extends BaseComputeServiceContextLiveTes
|
|||
blockUntilServerVerifyResize(serverId2);
|
||||
client.confirmResizeServer(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" })
|
||||
|
|
|
@ -67,13 +67,13 @@ public class ParseFlavorListFromJsonResponseTest {
|
|||
List<Flavor> response = parser.apply(HttpResponse.builder().statusCode(200).message("ok").payload(is).build());
|
||||
assertEquals(response.get(0).getId(), 1);
|
||||
assertEquals(response.get(0).getName(), "256 MB Server");
|
||||
assertEquals(response.get(0).getDisk(), new Integer(10));
|
||||
assertEquals(response.get(0).getRam(), new Integer(256));
|
||||
assertEquals(response.get(0).getDisk(), Integer.valueOf(10));
|
||||
assertEquals(response.get(0).getRam(), Integer.valueOf(256));
|
||||
|
||||
assertEquals(response.get(1).getId(), 2);
|
||||
assertEquals(response.get(1).getName(), "512 MB Server");
|
||||
assertEquals(response.get(1).getDisk(), new Integer(20));
|
||||
assertEquals(response.get(1).getRam(), new Integer(512));
|
||||
assertEquals(response.get(1).getDisk(), Integer.valueOf(20));
|
||||
assertEquals(response.get(1).getRam(), Integer.valueOf(512));
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -63,8 +63,8 @@ public class ParseImageFromJsonResponseTest {
|
|||
assertEquals(response.getId(), 2);
|
||||
assertEquals(response.getName(), "CentOS 5.2");
|
||||
assertEquals(response.getCreated(), dateService.iso8601SecondsDateParse("2010-08-10T12:00:00Z"));
|
||||
assertEquals(response.getProgress(), new Integer(80));
|
||||
assertEquals(response.getServerId(), new Integer(12));
|
||||
assertEquals(response.getProgress(), Integer.valueOf(80));
|
||||
assertEquals(response.getServerId(), Integer.valueOf(12));
|
||||
assertEquals(response.getStatus(), ImageStatus.SAVING);
|
||||
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).getCreated(), dateService.iso8601SecondsDateParse("2009-07-07T09:56:16-05:00"));
|
||||
;
|
||||
assertEquals(response.get(1).getProgress(), new Integer(80));
|
||||
assertEquals(response.get(1).getServerId(), new Integer(12));
|
||||
assertEquals(response.get(1).getProgress(), Integer.valueOf(80));
|
||||
assertEquals(response.get(1).getServerId(), Integer.valueOf(12));
|
||||
assertEquals(response.get(1).getStatus(), ImageStatus.SAVING);
|
||||
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.getName(), "sample-server");
|
||||
assertEquals(response.getImageId(), new Integer(2));
|
||||
assertEquals(response.getFlavorId(), new Integer(1));
|
||||
assertEquals(response.getImageId(), Integer.valueOf(2));
|
||||
assertEquals(response.getFlavorId(), Integer.valueOf(1));
|
||||
assertEquals(response.getHostId(), "e4d909c290d0fb1ca068ffaddf22cbd0");
|
||||
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> privateAddresses = Lists.newArrayList("10.176.42.16");
|
||||
Addresses addresses1 = new Addresses();
|
||||
|
|
|
@ -73,11 +73,11 @@ public class ParseServerListFromJsonResponseTest {
|
|||
|
||||
assertEquals(response.get(0).getId(), 1234);
|
||||
assertEquals(response.get(0).getName(), "sample-server");
|
||||
assertEquals(response.get(0).getImageId(), new Integer(2));
|
||||
assertEquals(response.get(0).getFlavorId(), new Integer(1));
|
||||
assertEquals(response.get(0).getImageId(), Integer.valueOf(2));
|
||||
assertEquals(response.get(0).getFlavorId(), Integer.valueOf(1));
|
||||
assertEquals(response.get(0).getHostId(), "e4d909c290d0fb1ca068ffaddf22cbd0");
|
||||
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> privateAddresses = Lists.newArrayList("10.176.42.16");
|
||||
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(1).getId(), 5678);
|
||||
assertEquals(response.get(1).getName(), "sample-server2");
|
||||
assertEquals(response.get(1).getImageId(), new Integer(2));
|
||||
assertEquals(response.get(1).getFlavorId(), new Integer(1));
|
||||
assertEquals(response.get(1).getImageId(), Integer.valueOf(2));
|
||||
assertEquals(response.get(1).getFlavorId(), Integer.valueOf(1));
|
||||
assertEquals(response.get(1).getHostId(), "9e107d9d372bb6826bd81d3542a419d6");
|
||||
assertEquals(response.get(1).getStatus(), ServerStatus.ACTIVE);
|
||||
assertEquals(response.get(1).getProgress(), null);
|
||||
|
|
|
@ -69,7 +69,7 @@ public class MapToDriveInfo implements Function<Map<String, String>, DriveInfo>
|
|||
if (from.containsKey("readers"))
|
||||
builder.readers(Splitter.on(' ').split(from.get("readers")));
|
||||
if (from.containsKey("size"))
|
||||
builder.size(new Long(from.get("size")));
|
||||
builder.size(Long.valueOf(from.get("size")));
|
||||
Map<String, String> metadata = Maps.newLinkedHashMap();
|
||||
for (Entry<String, String> entry : from.entrySet()) {
|
||||
if (entry.getKey().startsWith("user:"))
|
||||
|
@ -78,7 +78,7 @@ public class MapToDriveInfo implements Function<Map<String, String>, DriveInfo>
|
|||
if (from.containsKey("use"))
|
||||
builder.use(Splitter.on(' ').split(from.get("use")));
|
||||
if (from.containsKey("bits"))
|
||||
builder.bits(new Integer(from.get("bits")));
|
||||
builder.bits(Integer.valueOf(from.get("bits")));
|
||||
if (from.containsKey("url"))
|
||||
builder.url(URI.create(from.get("url")));
|
||||
builder.encryptionKey(from.get("encryption:key"));
|
||||
|
@ -88,9 +88,9 @@ public class MapToDriveInfo implements Function<Map<String, String>, DriveInfo>
|
|||
if (from.containsKey("drive_type"))
|
||||
builder.driveType(Splitter.on(',').split(from.get("drive_type")));
|
||||
if (from.containsKey("autoexpanding"))
|
||||
builder.autoexpanding(new Boolean(from.get("autoexpanding")));
|
||||
builder.autoexpanding(Boolean.valueOf(from.get("autoexpanding")));
|
||||
if (from.containsKey("free"))
|
||||
builder.free(new Boolean(from.get("free")));
|
||||
builder.free(Boolean.valueOf(from.get("free")));
|
||||
if (from.containsKey("type"))
|
||||
builder.type(DriveType.fromValue(from.get("type")));
|
||||
try {
|
||||
|
@ -104,13 +104,13 @@ public class MapToDriveInfo implements Function<Map<String, String>, DriveInfo>
|
|||
protected DriveMetrics buildMetrics(Map<String, String> from) {
|
||||
DriveMetrics.Builder metricsBuilder = new DriveMetrics.Builder();
|
||||
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"))
|
||||
metricsBuilder.readRequests(new Long(from.get("read:requests")));
|
||||
metricsBuilder.readRequests(Long.valueOf(from.get("read:requests")));
|
||||
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"))
|
||||
metricsBuilder.writeRequests(new Long(from.get("write:requests")));
|
||||
metricsBuilder.writeRequests(Long.valueOf(from.get("write:requests")));
|
||||
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) {
|
||||
DriveMetrics.Builder builder = new DriveMetrics.Builder();
|
||||
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"))
|
||||
builder.readRequests(new Long(from.get(key + ":read:requests")));
|
||||
builder.readRequests(Long.valueOf(from.get(key + ":read:requests")));
|
||||
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"))
|
||||
builder.writeRequests(new Long(from.get(key + ":write:requests")));
|
||||
builder.writeRequests(Long.valueOf(from.get(key + ":write:requests")));
|
||||
return builder.build();
|
||||
}
|
||||
}
|
|
@ -68,12 +68,12 @@ public class MapToServerInfo implements Function<Map<String, String>, ServerInfo
|
|||
if (from.containsKey("status"))
|
||||
builder.status(ServerStatus.fromValue(from.get("status")));
|
||||
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.mem(Integer.parseInt(from.get("mem")));
|
||||
builder.user(from.get("user"));
|
||||
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.vnc(new VNC(from.get("vnc:ip"), from.get("vnc:password"), from.containsKey("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) {
|
||||
ServerMetrics.Builder metricsBuilder = new ServerMetrics.Builder();
|
||||
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"))
|
||||
metricsBuilder.tx(new Long(from.get("tx")));
|
||||
metricsBuilder.tx(Long.valueOf(from.get("tx")));
|
||||
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"))
|
||||
metricsBuilder.rx(new Long(from.get("rx")));
|
||||
metricsBuilder.rx(Long.valueOf(from.get("rx")));
|
||||
metricsBuilder.driveMetrics(mapToDriveMetrics.apply(from));
|
||||
|
||||
ServerMetrics metrics = metricsBuilder.build();
|
||||
|
|
|
@ -94,7 +94,7 @@ public class CloudSigmaErrorHandler implements HttpErrorHandler {
|
|||
if (response.getPayload() == null)
|
||||
return null;
|
||||
try {
|
||||
return Strings2.toStringAndClose(response.getPayload().getInput());
|
||||
return Strings2.toString(response.getPayload());
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
|
|
|
@ -103,7 +103,7 @@ public class Account extends ForwardingSet<User> {
|
|||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -473,7 +473,7 @@ public class Account extends ForwardingSet<User> {
|
|||
}
|
||||
|
||||
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,
|
||||
|
|
|
@ -75,7 +75,7 @@ public class Capacity implements Comparable<Capacity> {
|
|||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -91,7 +91,7 @@ public class ResourceLimit {
|
|||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -80,7 +80,7 @@ public class UsageRecord {
|
|||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -588,7 +588,7 @@ public class VirtualMachine {
|
|||
@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 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.account = account;
|
||||
this.cpuCount = cpuCount;
|
||||
|
|
|
@ -108,7 +108,7 @@ public class Volume {
|
|||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -92,7 +92,7 @@ public class CloudStackErrorHandler implements HttpErrorHandler {
|
|||
if (response.getPayload() == null)
|
||||
return null;
|
||||
try {
|
||||
return Strings2.toStringAndClose(response.getPayload().getInput());
|
||||
return Strings2.toString(response.getPayload());
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
|
|
|
@ -87,7 +87,7 @@ public class DeltacloudErrorHandler implements HttpErrorHandler {
|
|||
if (response.getPayload() == null)
|
||||
return null;
|
||||
try {
|
||||
return Strings2.toStringAndClose(response.getPayload().getInput());
|
||||
return Strings2.toString(response.getPayload());
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
|
|
|
@ -87,7 +87,7 @@ public class HardwarePropertyHandler extends ParseSax.HandlerWithResult<Hardware
|
|||
if (DOUBLE.matcher(in).matches())
|
||||
return new Double(in);
|
||||
else if (LONG.matcher(in).matches())
|
||||
return new Long(in);
|
||||
return Long.valueOf(in);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
@ -65,13 +65,13 @@ public class HardwareProfileHandlerTest {
|
|||
HardwareProfile expects = new HardwareProfile(
|
||||
URI.create("http://localhost:3001/api/hardware_profiles/m1-xlarge"), "m1-xlarge", "m1-xlarge",
|
||||
ImmutableSet.<HardwareProperty> of(
|
||||
new FixedHardwareProperty("cpu", "count", new Long(4)),
|
||||
new RangeHardwareProperty("memory", "MB", new Long(12288), new HardwareParameter(URI
|
||||
new FixedHardwareProperty("cpu", "count", Long.valueOf(4)),
|
||||
new RangeHardwareProperty("memory", "MB", Long.valueOf(12288), new HardwareParameter(URI
|
||||
.create("http://localhost:3001/api/instances"), "post", "hwp_memory", "create"),
|
||||
new Long(12288), new Long(32768)),
|
||||
new EnumHardwareProperty("storage", "GB", new Long(1024), new HardwareParameter(URI
|
||||
Long.valueOf(12288), Long.valueOf(32768)),
|
||||
new EnumHardwareProperty("storage", "GB", Long.valueOf(1024), new HardwareParameter(URI
|
||||
.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"))
|
||||
);
|
||||
assertEquals(parseHardwareProfile(), expects);
|
||||
|
|
|
@ -50,27 +50,27 @@ public class HardwareProfilesHandlerTest extends BaseHandlerTest {
|
|||
Set<? extends HardwareProfile> expects = ImmutableSet.of(
|
||||
new HardwareProfile(URI.create("http://localhost:3001/api/hardware_profiles/m1-small"), "m1-small",
|
||||
"m1-small", ImmutableSet.<HardwareProperty> of(
|
||||
new FixedHardwareProperty("cpu", "count", new Long(1)), new FixedHardwareProperty("memory",
|
||||
"MB", new Double(1740.8)), new FixedHardwareProperty("storage", "GB", new Long(160)),
|
||||
new FixedHardwareProperty("cpu", "count", Long.valueOf(1)), new FixedHardwareProperty("memory",
|
||||
"MB", new Double(1740.8)), new FixedHardwareProperty("storage", "GB", Long.valueOf(160)),
|
||||
new FixedHardwareProperty("architecture", "label", "i386"))),
|
||||
new HardwareProfile(URI.create("http://localhost:3001/api/hardware_profiles/m1-large"), "m1-large",
|
||||
"m1-large", ImmutableSet.<HardwareProperty> of(
|
||||
new FixedHardwareProperty("cpu", "count", new Long(2)),
|
||||
new RangeHardwareProperty("memory", "MB", new Long(10240), new HardwareParameter(URI
|
||||
new FixedHardwareProperty("cpu", "count", Long.valueOf(2)),
|
||||
new RangeHardwareProperty("memory", "MB", Long.valueOf(10240), new HardwareParameter(URI
|
||||
.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",
|
||||
"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 HardwareProfile(URI.create("http://localhost:3001/api/hardware_profiles/m1-xlarge"), "m1-xlarge",
|
||||
"m1-xlarge", ImmutableSet.<HardwareProperty> of(
|
||||
new FixedHardwareProperty("cpu", "count", new Long(4)),
|
||||
new RangeHardwareProperty("memory", "MB", new Long(12288), new HardwareParameter(URI
|
||||
new FixedHardwareProperty("cpu", "count", Long.valueOf(4)),
|
||||
new RangeHardwareProperty("memory", "MB", Long.valueOf(12288), new HardwareParameter(URI
|
||||
.create("http://localhost:3001/api/instances"), "post", "hwp_memory", "create"),
|
||||
new Long(12288), new Long(32768)),
|
||||
new EnumHardwareProperty("storage", "GB", new Long(1024), new HardwareParameter(URI
|
||||
Long.valueOf(12288), Long.valueOf(32768)),
|
||||
new EnumHardwareProperty("storage", "GB", Long.valueOf(1024), new HardwareParameter(URI
|
||||
.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 HardwareProfile(URI.create("http://localhost:3001/api/hardware_profiles/opaque"), "opaque", "opaque",
|
||||
ImmutableSet.<HardwareProperty> of()));
|
||||
|
|
|
@ -65,7 +65,7 @@ public class MapToDriveInfo implements Function<Map<String, String>, DriveInfo>
|
|||
if (from.containsKey("readers"))
|
||||
builder.readers(Splitter.on(' ').split(from.get("readers")));
|
||||
if (from.containsKey("size"))
|
||||
builder.size(new Long(from.get("size")));
|
||||
builder.size(Long.valueOf(from.get("size")));
|
||||
Map<String, String> metadata = Maps.newLinkedHashMap();
|
||||
for (Entry<String, String> entry : from.entrySet()) {
|
||||
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) {
|
||||
DriveMetrics.Builder metricsBuilder = new DriveMetrics.Builder();
|
||||
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"))
|
||||
metricsBuilder.readRequests(new Long(from.get("read:requests")));
|
||||
metricsBuilder.readRequests(Long.valueOf(from.get("read:requests")));
|
||||
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"))
|
||||
metricsBuilder.writeRequests(new Long(from.get("write:requests")));
|
||||
metricsBuilder.writeRequests(Long.valueOf(from.get("write:requests")));
|
||||
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) {
|
||||
DriveMetrics.Builder builder = new DriveMetrics.Builder();
|
||||
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"))
|
||||
builder.readRequests(new Long(from.get(key + ":read:requests")));
|
||||
builder.readRequests(Long.valueOf(from.get(key + ":read:requests")));
|
||||
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"))
|
||||
builder.writeRequests(new Long(from.get(key + ":write:requests")));
|
||||
builder.writeRequests(Long.valueOf(from.get(key + ":write:requests")));
|
||||
return builder.build();
|
||||
}
|
||||
}
|
|
@ -68,16 +68,16 @@ public class MapToServerInfo implements Function<Map<String, String>, ServerInfo
|
|||
|
||||
|
||||
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"))) {
|
||||
builder.smp(new Integer(from.get("smp")));
|
||||
builder.smp(Integer.valueOf(from.get("smp")));
|
||||
}
|
||||
|
||||
builder.cpu(Integer.parseInt(from.get("cpu")));
|
||||
builder.mem(Integer.parseInt(from.get("mem")));
|
||||
builder.user(from.get("user"));
|
||||
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"));
|
||||
if (from.containsKey("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) {
|
||||
ServerMetrics.Builder metricsBuilder = new ServerMetrics.Builder();
|
||||
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"))
|
||||
metricsBuilder.tx(new Long(from.get("tx")));
|
||||
metricsBuilder.tx(Long.valueOf(from.get("tx")));
|
||||
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"))
|
||||
metricsBuilder.rx(new Long(from.get("rx")));
|
||||
metricsBuilder.rx(Long.valueOf(from.get("rx")));
|
||||
metricsBuilder.driveMetrics(mapToDriveMetrics.apply(from));
|
||||
|
||||
ServerMetrics metrics = metricsBuilder.build();
|
||||
|
|
|
@ -92,7 +92,7 @@ public class ElasticStackErrorHandler implements HttpErrorHandler {
|
|||
if (response.getPayload() == null)
|
||||
return null;
|
||||
try {
|
||||
return Strings2.toStringAndClose(response.getPayload().getInput());
|
||||
return Strings2.toString(response.getPayload());
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
|
|
|
@ -326,7 +326,7 @@ public class ElasticStackClientLiveTest
|
|||
public void testWeCanReadAndWriteToDrive() throws IOException {
|
||||
drive2 = client.createDrive(new CreateDriveRequest.Builder().name(prefix + "2").size(1 * 1024 * 1024l).build());
|
||||
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")
|
||||
|
@ -341,7 +341,7 @@ public class ElasticStackClientLiveTest
|
|||
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 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 {
|
||||
client.destroyDrive(drive2.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.BlobRequestSigner;
|
||||
import org.jclouds.blobstore.BlobStore;
|
||||
import org.jclouds.blobstore.LocalAsyncBlobStore;
|
||||
import org.jclouds.blobstore.LocalStorageStrategy;
|
||||
import org.jclouds.blobstore.TransientBlobRequestSigner;
|
||||
import org.jclouds.blobstore.attr.ConsistencyModel;
|
||||
import org.jclouds.blobstore.config.BlobStoreMapModule;
|
||||
import org.jclouds.blobstore.config.BlobStoreObjectModule;
|
||||
import org.jclouds.blobstore.config.LocalBlobStore;
|
||||
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.FilesystemContainerNameValidator;
|
||||
import org.jclouds.filesystem.predicates.validators.internal.FilesystemBlobKeyValidatorImpl;
|
||||
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.util.internal.FileSystemBlobUtilsImpl;
|
||||
import org.jclouds.rest.config.BinderUtils;
|
||||
|
@ -48,15 +48,15 @@ public class FilesystemBlobStoreContextModule extends AbstractModule {
|
|||
|
||||
@Override
|
||||
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
|
||||
BinderUtils.bindClient(binder(), FilesystemBlobStore.class, AsyncBlobStore.class, ImmutableMap.<Class<?>, Class<?>>of());
|
||||
bind(BlobStore.class).to(FilesystemBlobStore.class);
|
||||
BinderUtils.bindClient(binder(), LocalBlobStore.class, AsyncBlobStore.class, ImmutableMap.<Class<?>, Class<?>>of());
|
||||
bind(BlobStore.class).to(LocalBlobStore.class);
|
||||
|
||||
install(new BlobStoreObjectModule());
|
||||
install(new BlobStoreMapModule());
|
||||
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(FilesystemBlobKeyValidator.class).to(FilesystemBlobKeyValidatorImpl.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.filefilter.DirectoryFileFilter;
|
||||
import org.jclouds.blobstore.LocalStorageStrategy;
|
||||
import org.jclouds.blobstore.domain.Blob;
|
||||
import org.jclouds.blobstore.domain.BlobBuilder;
|
||||
import org.jclouds.blobstore.options.ListContainerOptions;
|
||||
import org.jclouds.crypto.Crypto;
|
||||
import org.jclouds.crypto.CryptoStreams;
|
||||
import org.jclouds.domain.Location;
|
||||
import org.jclouds.filesystem.predicates.validators.FilesystemBlobKeyValidator;
|
||||
import org.jclouds.filesystem.predicates.validators.FilesystemContainerNameValidator;
|
||||
import org.jclouds.filesystem.reference.FilesystemConstants;
|
||||
import org.jclouds.filesystem.strategy.FilesystemStorageStrategy;
|
||||
import org.jclouds.io.Payload;
|
||||
import org.jclouds.io.Payloads;
|
||||
import org.jclouds.logging.Logger;
|
||||
import org.jclouds.rest.annotations.ParamValidators;
|
||||
|
||||
|
@ -55,7 +58,7 @@ import com.google.common.io.Files;
|
|||
*
|
||||
* @author Alfredo "Rainbowbreeze" Morresi
|
||||
*/
|
||||
public class FilesystemStorageStrategyImpl implements FilesystemStorageStrategy {
|
||||
public class FilesystemStorageStrategyImpl implements LocalStorageStrategy {
|
||||
|
||||
private static final String BACK_SLASH = "\\";
|
||||
|
||||
|
@ -66,17 +69,20 @@ public class FilesystemStorageStrategyImpl implements FilesystemStorageStrategy
|
|||
protected final String baseDirectory;
|
||||
protected final FilesystemContainerNameValidator filesystemContainerNameValidator;
|
||||
protected final FilesystemBlobKeyValidator filesystemBlobKeyValidator;
|
||||
private final Crypto crypto;
|
||||
|
||||
@Inject
|
||||
protected FilesystemStorageStrategyImpl(Provider<BlobBuilder> blobBuilders,
|
||||
@Named(FilesystemConstants.PROPERTY_BASEDIR) String baseDir,
|
||||
FilesystemContainerNameValidator filesystemContainerNameValidator,
|
||||
FilesystemBlobKeyValidator filesystemBlobKeyValidator) {
|
||||
FilesystemBlobKeyValidator filesystemBlobKeyValidator,
|
||||
Crypto crypto) {
|
||||
this.blobBuilders = checkNotNull(blobBuilders, "filesystem storage strategy blobBuilders");
|
||||
this.baseDirectory = checkNotNull(baseDir, "filesystem storage strategy base directory");
|
||||
this.filesystemContainerNameValidator = checkNotNull(filesystemContainerNameValidator,
|
||||
"filesystem container name validator");
|
||||
this.filesystemBlobKeyValidator = checkNotNull(filesystemBlobKeyValidator, "filesystem blob key validator");
|
||||
this.crypto = crypto;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -109,8 +115,14 @@ public class FilesystemStorageStrategyImpl implements FilesystemStorageStrategy
|
|||
return blob;
|
||||
}
|
||||
|
||||
@Override
|
||||
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);
|
||||
filesystemContainerNameValidator.validate(container);
|
||||
return createDirectoryWithResult(container, null);
|
||||
|
@ -151,7 +163,6 @@ public class FilesystemStorageStrategyImpl implements FilesystemStorageStrategy
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Blob newBlob(@ParamValidators({ FilesystemBlobKeyValidator.class }) String name) {
|
||||
filesystemBlobKeyValidator.validate(name);
|
||||
return blobBuilders.get().name(name).build();
|
||||
|
@ -195,7 +206,6 @@ public class FilesystemStorageStrategyImpl implements FilesystemStorageStrategy
|
|||
* @param blobKey
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public File getFileForBlobKey(String container, String blobKey) {
|
||||
filesystemContainerNameValidator.validate(container);
|
||||
filesystemBlobKeyValidator.validate(blobKey);
|
||||
|
@ -205,7 +215,7 @@ public class FilesystemStorageStrategyImpl implements FilesystemStorageStrategy
|
|||
}
|
||||
|
||||
@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();
|
||||
Payload payload = blob.getPayload();
|
||||
filesystemContainerNameValidator.validate(containerName);
|
||||
|
@ -220,6 +230,9 @@ public class FilesystemStorageStrategyImpl implements FilesystemStorageStrategy
|
|||
output = new FileOutputStream(outputFile);
|
||||
payload.writeTo(output);
|
||||
}
|
||||
Payloads.calculateMD5(payload, crypto.md5());
|
||||
String eTag = CryptoStreams.hex(payload.getContentMetadata().getContentMD5());
|
||||
return eTag;
|
||||
} catch (IOException ex) {
|
||||
if (outputFile != null) {
|
||||
outputFile.delete();
|
||||
|
@ -263,16 +276,23 @@ public class FilesystemStorageStrategyImpl implements FilesystemStorageStrategy
|
|||
}
|
||||
|
||||
@Override
|
||||
public Location getLocation(final String containerName) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSeparator() {
|
||||
return File.separator;
|
||||
}
|
||||
|
||||
public boolean directoryExists(String container, String directory) {
|
||||
return buildPathAndChecksIfDirectoryExists(container, directory);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createDirectory(String container, String directory) {
|
||||
createDirectoryWithResult(container, directory);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteDirectory(String container, String directory) {
|
||||
// create complete dir path
|
||||
String fullDirPath = buildPathStartingFromBaseDir(container, directory);
|
||||
|
@ -284,7 +304,6 @@ public class FilesystemStorageStrategyImpl implements FilesystemStorageStrategy
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public long countBlobs(String container, ListContainerOptions options) {
|
||||
// TODO
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
|
|
|
@ -23,27 +23,28 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
|||
import javax.inject.Provider;
|
||||
|
||||
import org.jclouds.blobstore.AsyncBlobStore;
|
||||
import org.jclouds.blobstore.LocalStorageStrategy;
|
||||
import org.jclouds.blobstore.domain.BlobBuilder;
|
||||
import org.jclouds.blobstore.options.ListContainerOptions;
|
||||
import org.jclouds.blobstore.util.BlobUtils;
|
||||
import org.jclouds.filesystem.strategy.FilesystemStorageStrategy;
|
||||
import org.jclouds.filesystem.strategy.internal.FilesystemStorageStrategyImpl;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
public class FileSystemBlobUtilsImpl implements BlobUtils {
|
||||
|
||||
protected final FilesystemStorageStrategy storageStrategy;
|
||||
protected final FilesystemStorageStrategyImpl storageStrategy;
|
||||
protected final Provider<BlobBuilder> blobBuilders;
|
||||
|
||||
@Inject
|
||||
public FileSystemBlobUtilsImpl(FilesystemStorageStrategy storageStrategy, Provider<BlobBuilder> blobBuilders) {
|
||||
this.storageStrategy = checkNotNull(storageStrategy, "Filesystem Storage Strategy");
|
||||
public FileSystemBlobUtilsImpl(LocalStorageStrategy storageStrategy, Provider<BlobBuilder> blobBuilders) {
|
||||
this.storageStrategy = (FilesystemStorageStrategyImpl) checkNotNull(storageStrategy, "Filesystem Storage Strategy");
|
||||
this.blobBuilders = checkNotNull(blobBuilders, "Filesystem blobBuilders");
|
||||
}
|
||||
|
||||
|
|
|
@ -656,7 +656,7 @@ public class FilesystemAsyncBlobStoreTest {
|
|||
assertEquals(metadata.getUserMetadata().size(), 0, "Wrong blob UserMetadata");
|
||||
// metadata.getLastModified()
|
||||
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() {
|
||||
|
|
|
@ -42,7 +42,6 @@ import org.jclouds.blobstore.options.ListContainerOptions;
|
|||
import org.jclouds.encryption.internal.JCECrypto;
|
||||
import org.jclouds.filesystem.predicates.validators.internal.FilesystemBlobKeyValidatorImpl;
|
||||
import org.jclouds.filesystem.predicates.validators.internal.FilesystemContainerNameValidatorImpl;
|
||||
import org.jclouds.filesystem.strategy.FilesystemStorageStrategy;
|
||||
import org.jclouds.filesystem.utils.TestUtils;
|
||||
import org.jclouds.io.payloads.FilePayload;
|
||||
import org.testng.annotations.AfterMethod;
|
||||
|
@ -73,7 +72,7 @@ public class FilesystemStorageStrategyImplTest {
|
|||
System.setProperty(LOGGING_CONFIG_KEY, LOGGING_CONFIG_VALUE);
|
||||
}
|
||||
|
||||
private FilesystemStorageStrategy storageStrategy;
|
||||
private FilesystemStorageStrategyImpl storageStrategy;
|
||||
|
||||
@BeforeMethod
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -409,12 +408,12 @@ public class FilesystemStorageStrategyImplTest {
|
|||
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 absoluteContainerPath = absoluteBasePath + CONTAINER_NAME + FS;
|
||||
|
||||
// create storageStrategy with an absolute path
|
||||
FilesystemStorageStrategy storageStrategyAbsolute = new FilesystemStorageStrategyImpl(
|
||||
FilesystemStorageStrategyImpl storageStrategyAbsolute = new FilesystemStorageStrategyImpl(
|
||||
new Provider<BlobBuilder>() {
|
||||
@Override
|
||||
public BlobBuilder get() {
|
||||
|
@ -424,7 +423,7 @@ public class FilesystemStorageStrategyImplTest {
|
|||
return null;
|
||||
}
|
||||
}
|
||||
}, absoluteBasePath, new FilesystemContainerNameValidatorImpl(), new FilesystemBlobKeyValidatorImpl());
|
||||
}, absoluteBasePath, new FilesystemContainerNameValidatorImpl(), new FilesystemBlobKeyValidatorImpl(), new JCECrypto());
|
||||
TestUtils.cleanDirectoryContent(absoluteContainerPath);
|
||||
|
||||
String blobKey;
|
||||
|
|
|
@ -85,7 +85,7 @@ public class ParseNovaErrorFromHttpResponse implements HttpErrorHandler {
|
|||
String parseErrorFromContentOrNull(HttpCommand command, HttpResponse response) {
|
||||
if (response.getPayload() != null) {
|
||||
try {
|
||||
return Strings2.toStringAndClose(response.getPayload().getInput());
|
||||
return Strings2.toString(response.getPayload());
|
||||
} catch (IOException e) {
|
||||
logger.warn(e, "exception reading error from response", response);
|
||||
}
|
||||
|
|
|
@ -264,8 +264,8 @@ public class NovaClientLiveTest extends BaseComputeServiceContextLiveTest {
|
|||
assertNotNull(server.getHostId());
|
||||
assertEquals(server.getStatus(), ServerStatus.ACTIVE);
|
||||
assert server.getProgress() >= 0 : "newDetails.getProgress()" + server.getProgress();
|
||||
assertEquals(new Integer(14362), server.getImage());
|
||||
assertEquals(new Integer(1), server.getFlavor());
|
||||
assertEquals(Integer.valueOf(14362), server.getImage());
|
||||
assertEquals(Integer.valueOf(1), server.getFlavor());
|
||||
assertNotNull(server.getAddresses());
|
||||
// listAddresses tests..
|
||||
assertEquals(client.getAddresses(serverId), server.getAddresses());
|
||||
|
@ -303,7 +303,7 @@ public class NovaClientLiveTest extends BaseComputeServiceContextLiveTest {
|
|||
try {
|
||||
client.connect();
|
||||
Payload etcPasswd = client.get("/etc/jclouds.txt");
|
||||
String etcPasswdContents = Strings2.toStringAndClose(etcPasswd.getInput());
|
||||
String etcPasswdContents = Strings2.toString(etcPasswd);
|
||||
assertEquals("nova", etcPasswdContents.trim());
|
||||
} finally {
|
||||
if (client != null)
|
||||
|
@ -332,7 +332,7 @@ public class NovaClientLiveTest extends BaseComputeServiceContextLiveTest {
|
|||
public void testCreateImage() throws Exception {
|
||||
Image image = client.createImageFromServer("hoofie", serverId);
|
||||
assertEquals("hoofie", image.getName());
|
||||
assertEquals(new Integer(serverId), image.getServerRef());
|
||||
assertEquals(Integer.valueOf(serverId), image.getServerRef());
|
||||
createdImageRef = image.getId()+"";
|
||||
blockUntilImageActive(createdImageRef);
|
||||
}
|
||||
|
@ -341,7 +341,7 @@ public class NovaClientLiveTest extends BaseComputeServiceContextLiveTest {
|
|||
public void testRebuildServer() throws Exception {
|
||||
client.rebuildServer(serverId, new RebuildServerOptions().withImage(createdImageRef));
|
||||
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")
|
||||
|
@ -362,7 +362,7 @@ public class NovaClientLiveTest extends BaseComputeServiceContextLiveTest {
|
|||
blockUntilServerVerifyResize(serverId);
|
||||
client.revertResizeServer(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")
|
||||
|
@ -371,7 +371,7 @@ public class NovaClientLiveTest extends BaseComputeServiceContextLiveTest {
|
|||
blockUntilServerVerifyResize(serverId2);
|
||||
client.confirmResizeServer(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" })
|
||||
|
|
|
@ -64,7 +64,7 @@ public class ParseImageFromJsonResponseTest {
|
|||
assertEquals(response.getId(), 2);
|
||||
assertEquals(response.getName(), "CentOS 5.2");
|
||||
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.getUpdated(), dateService.iso8601SecondsDateParse(("2010-10-10T12:00:00Z")));
|
||||
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).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).getUpdated(), dateService.iso8601SecondsDateParse("2010-10-10T12:00:00Z"));
|
||||
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.getHostId(), "e4d909c290d0fb1ca068ffaddf22cbd0");
|
||||
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);
|
||||
dateFormat.setTimeZone(new SimpleTimeZone(0, "GMT"));
|
||||
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.getHostId(), "e4d909c290d0fb1ca068ffaddf22cbd0");
|
||||
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);
|
||||
dateFormat.setTimeZone(new SimpleTimeZone(0, "GMT"));
|
||||
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).getUuid(), "d84e2086-fc0d-11e0-8e08-2837371c69ae");
|
||||
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(
|
||||
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() {
|
||||
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.contentMD5(CryptoStreams.hex(Strings2.replaceAll(currentETag, '"', "")));
|
||||
} else if (qName.equals("Size")) {
|
||||
builder.contentLength(new Long(currentOrNull(currentText)));
|
||||
builder.contentLength(Long.valueOf(currentOrNull(currentText)));
|
||||
} else if (qName.equals("Owner")) {
|
||||
builder.owner(currentOwner);
|
||||
currentOwner = null;
|
||||
|
|
|
@ -284,7 +284,7 @@ public class S3ClientLiveTest extends BaseBlobStoreIntegrationTest {
|
|||
assertConsistencyAwareContainerSize(sourceContainer, 1);
|
||||
S3Object newObject = getApi().getObject(sourceContainer, key);
|
||||
assert newObject != null;
|
||||
assertEquals(Strings2.toStringAndClose(newObject.getPayload().getInput()), TEST_STRING);
|
||||
assertEquals(Strings2.toString(newObject.getPayload()), TEST_STRING);
|
||||
return newObject;
|
||||
}
|
||||
|
||||
|
|
|
@ -37,12 +37,13 @@ import org.jclouds.Constants;
|
|||
import org.jclouds.aws.domain.Region;
|
||||
import org.jclouds.blobstore.AsyncBlobStore;
|
||||
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.BlobMetadata;
|
||||
import org.jclouds.blobstore.domain.MutableBlobMetadata;
|
||||
import org.jclouds.blobstore.functions.HttpGetOptionsListToGetOptions;
|
||||
import org.jclouds.blobstore.options.ListContainerOptions;
|
||||
import org.jclouds.blobstore.util.BlobStoreUtils;
|
||||
import org.jclouds.concurrent.Futures;
|
||||
import org.jclouds.date.DateService;
|
||||
import org.jclouds.domain.Location;
|
||||
|
@ -102,7 +103,7 @@ public class StubS3AsyncClient implements S3AsyncClient {
|
|||
|
||||
@Inject
|
||||
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,
|
||||
S3Object.Factory objectProvider, Blob.Factory blobProvider,
|
||||
HttpGetOptionsListToGetOptions httpGetOptionsConverter, ObjectToBlob object2Blob, BlobToObject blob2Object,
|
||||
|
@ -157,25 +158,25 @@ public class StubS3AsyncClient implements S3AsyncClient {
|
|||
Blob object = source.get(sourceObject);
|
||||
if (options.getIfMatch() != null) {
|
||||
if (!object.getMetadata().getETag().equals(options.getIfMatch()))
|
||||
return immediateFailedFuture(TransientAsyncBlobStore.returnResponseException(412));
|
||||
return immediateFailedFuture(LocalAsyncBlobStore.returnResponseException(412));
|
||||
}
|
||||
if (options.getIfNoneMatch() != null) {
|
||||
if (object.getMetadata().getETag().equals(options.getIfNoneMatch()))
|
||||
return immediateFailedFuture(TransientAsyncBlobStore.returnResponseException(412));
|
||||
return immediateFailedFuture(LocalAsyncBlobStore.returnResponseException(412));
|
||||
}
|
||||
if (options.getIfModifiedSince() != null) {
|
||||
Date modifiedSince = dateService.rfc822DateParse(options.getIfModifiedSince());
|
||||
if (modifiedSince.after(object.getMetadata().getLastModified()))
|
||||
return immediateFailedFuture(TransientAsyncBlobStore.returnResponseException(412));
|
||||
return immediateFailedFuture(LocalAsyncBlobStore.returnResponseException(412));
|
||||
|
||||
}
|
||||
if (options.getIfUnmodifiedSince() != null) {
|
||||
Date unmodifiedSince = dateService.rfc822DateParse(options.getIfUnmodifiedSince());
|
||||
if (unmodifiedSince.before(object.getMetadata().getLastModified()))
|
||||
return immediateFailedFuture(TransientAsyncBlobStore.returnResponseException(412));
|
||||
return immediateFailedFuture(LocalAsyncBlobStore.returnResponseException(412));
|
||||
}
|
||||
Blob sourceS3 = source.get(sourceObject);
|
||||
MutableBlobMetadata newMd = TransientAsyncBlobStore.copy(sourceS3.getMetadata(), destinationObject);
|
||||
MutableBlobMetadata newMd = BlobStoreUtils.copy(sourceS3.getMetadata(), destinationObject);
|
||||
if (options.getAcl() != null)
|
||||
keyToAcl.put(destinationBucket + "/" + destinationObject, options.getAcl());
|
||||
|
||||
|
@ -183,7 +184,7 @@ public class StubS3AsyncClient implements S3AsyncClient {
|
|||
Blob newBlob = blobProvider.create(newMd);
|
||||
newBlob.setPayload(sourceS3.getPayload());
|
||||
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 + "/"
|
||||
+ sourceObject));
|
||||
|
|
|
@ -164,7 +164,7 @@ public class ParallelMultipartUploadStrategy implements AsyncMultipartUploadStra
|
|||
CountDownLatch latch = new CountDownLatch(effectiveParts);
|
||||
int part;
|
||||
while ((part = algorithm.getNextPart()) <= parts) {
|
||||
Integer partKey = new Integer(part);
|
||||
Integer partKey = Integer.valueOf(part);
|
||||
activeParts.put(partKey);
|
||||
|
||||
prepareUploadPart(container, blob, key, partKey, payload,
|
||||
|
@ -173,7 +173,7 @@ public class ParallelMultipartUploadStrategy implements AsyncMultipartUploadStra
|
|||
blob2Object);
|
||||
}
|
||||
if (remaining > 0) {
|
||||
Integer partKey = new Integer(part);
|
||||
Integer partKey = Integer.valueOf(part);
|
||||
activeParts.put(partKey);
|
||||
prepareUploadPart(container, blob, key, partKey, payload,
|
||||
algorithm.getNextChunkOffset(), remaining, etags,
|
||||
|
@ -187,7 +187,7 @@ public class ParallelMultipartUploadStrategy implements AsyncMultipartUploadStra
|
|||
CountDownLatch retryLatch = new CountDownLatch(atOnce);
|
||||
for (int i = 0; i < atOnce; i++) {
|
||||
Part failedPart = toRetry.poll();
|
||||
Integer partKey = new Integer(failedPart.getPart());
|
||||
Integer partKey = Integer.valueOf(failedPart.getPart());
|
||||
activeParts.put(partKey);
|
||||
prepareUploadPart(container, blob, key, partKey, payload,
|
||||
failedPart.getOffset(), failedPart.getSize(), etags,
|
||||
|
|
|
@ -57,7 +57,7 @@ public class ListContainerOptions extends BaseHttpRequestOptions {
|
|||
|
||||
public int getMaxResults() {
|
||||
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());
|
||||
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();
|
||||
|
||||
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;
|
||||
// Test GET of object (including updated metadata)
|
||||
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(),
|
||||
// object.getMetadata().getName());
|
||||
assertEquals(getBlob.getInfo().getBytes(), new Long(data.length()));
|
||||
assertEquals(getBlob.getInfo().getBytes(), Long.valueOf(data.length()));
|
||||
testGetObjectContentType(getBlob);
|
||||
assertEquals(CryptoStreams.hex(md5), CryptoStreams.hex(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));
|
||||
assertEquals(getBlob.getInfo().getHash(), CryptoStreams.hex(newEtag));
|
||||
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 {
|
||||
returnContainer(containerName);
|
||||
|
|
|
@ -33,7 +33,7 @@ import javax.inject.Named;
|
|||
import javax.inject.Singleton;
|
||||
|
||||
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.PageSet;
|
||||
import org.jclouds.blobstore.domain.StorageMetadata;
|
||||
|
@ -68,7 +68,7 @@ import com.google.common.util.concurrent.ListenableFuture;
|
|||
@Singleton
|
||||
public class StubSwiftAsyncClient implements CommonSwiftAsyncClient {
|
||||
private final HttpGetOptionsListToGetOptions httpGetOptionsConverter;
|
||||
private final TransientAsyncBlobStore blobStore;
|
||||
private final LocalAsyncBlobStore blobStore;
|
||||
private final SwiftObject.Factory objectProvider;
|
||||
private final ObjectToBlob object2Blob;
|
||||
private final BlobToObject blob2Object;
|
||||
|
@ -79,7 +79,7 @@ public class StubSwiftAsyncClient implements CommonSwiftAsyncClient {
|
|||
|
||||
@Inject
|
||||
private StubSwiftAsyncClient(@Named(Constants.PROPERTY_USER_THREADS) ExecutorService service,
|
||||
TransientAsyncBlobStore blobStore,
|
||||
LocalAsyncBlobStore blobStore,
|
||||
SwiftObject.Factory objectProvider, HttpGetOptionsListToGetOptions httpGetOptionsConverter,
|
||||
ObjectToBlob object2Blob, BlobToObject blob2Object, ResourceToObjectInfo blob2ObjectInfo,
|
||||
ListContainerOptionsToBlobStoreListContainerOptions container2ContainerListOptions,
|
||||
|
|
|
@ -28,7 +28,7 @@ import org.jclouds.vcloud.features.VAppAsyncClient;
|
|||
import org.jclouds.vcloud.features.VAppTemplateAsyncClient;
|
||||
import org.jclouds.vcloud.features.VDCAsyncClient;
|
||||
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.
|
||||
|
@ -38,7 +38,7 @@ import org.jclouds.vcloud.filters.SetVCloudTokenCookie;
|
|||
* />
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@RequestFilters(SetVCloudTokenCookie.class)
|
||||
@RequestFilters(AddVCloudAuthorizationAndCookieToRequest.class)
|
||||
public interface VCloudAsyncClient {
|
||||
|
||||
/**
|
||||
|
|
|
@ -42,7 +42,7 @@ import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404;
|
|||
import org.jclouds.vcloud.binders.BindCatalogItemToXmlPayload;
|
||||
import org.jclouds.vcloud.domain.Catalog;
|
||||
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.OrgNameCatalogNameItemNameToEndpoint;
|
||||
import org.jclouds.vcloud.options.CatalogItemOptions;
|
||||
|
@ -57,7 +57,7 @@ import com.google.common.util.concurrent.ListenableFuture;
|
|||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@RequestFilters(SetVCloudTokenCookie.class)
|
||||
@RequestFilters(AddVCloudAuthorizationAndCookieToRequest.class)
|
||||
public interface CatalogAsyncClient {
|
||||
|
||||
/**
|
||||
|
|
|
@ -32,7 +32,7 @@ import org.jclouds.rest.annotations.RequestFilters;
|
|||
import org.jclouds.rest.annotations.XMLResponseParser;
|
||||
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
|
||||
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.xml.OrgNetworkHandler;
|
||||
|
||||
|
@ -44,7 +44,7 @@ import com.google.common.util.concurrent.ListenableFuture;
|
|||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@RequestFilters(SetVCloudTokenCookie.class)
|
||||
@RequestFilters(AddVCloudAuthorizationAndCookieToRequest.class)
|
||||
public interface NetworkAsyncClient {
|
||||
|
||||
/**
|
||||
|
|
|
@ -37,7 +37,7 @@ import org.jclouds.vcloud.VCloudMediaType;
|
|||
import org.jclouds.vcloud.domain.Org;
|
||||
import org.jclouds.vcloud.domain.ReferenceType;
|
||||
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.xml.OrgHandler;
|
||||
import org.jclouds.vcloud.xml.OrgListHandler;
|
||||
|
@ -50,7 +50,7 @@ import com.google.common.util.concurrent.ListenableFuture;
|
|||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@RequestFilters(SetVCloudTokenCookie.class)
|
||||
@RequestFilters(AddVCloudAuthorizationAndCookieToRequest.class)
|
||||
public interface OrgAsyncClient {
|
||||
|
||||
/**
|
||||
|
|
|
@ -36,7 +36,7 @@ import org.jclouds.rest.annotations.XMLResponseParser;
|
|||
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
|
||||
import org.jclouds.vcloud.domain.Task;
|
||||
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.xml.TaskHandler;
|
||||
import org.jclouds.vcloud.xml.TasksListHandler;
|
||||
|
@ -49,7 +49,7 @@ import com.google.common.util.concurrent.ListenableFuture;
|
|||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@RequestFilters(SetVCloudTokenCookie.class)
|
||||
@RequestFilters(AddVCloudAuthorizationAndCookieToRequest.class)
|
||||
public interface TaskAsyncClient {
|
||||
|
||||
/**
|
||||
|
|
|
@ -49,7 +49,7 @@ import org.jclouds.vcloud.binders.BindDeployVAppParamsToXmlPayload;
|
|||
import org.jclouds.vcloud.binders.BindUndeployVAppParamsToXmlPayload;
|
||||
import org.jclouds.vcloud.domain.Task;
|
||||
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.options.CloneVAppOptions;
|
||||
import org.jclouds.vcloud.xml.TaskHandler;
|
||||
|
@ -63,7 +63,7 @@ import com.google.common.util.concurrent.ListenableFuture;
|
|||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@RequestFilters(SetVCloudTokenCookie.class)
|
||||
@RequestFilters(AddVCloudAuthorizationAndCookieToRequest.class)
|
||||
public interface VAppAsyncClient {
|
||||
|
||||
/**
|
||||
|
|
|
@ -52,7 +52,7 @@ import org.jclouds.vcloud.binders.BindInstantiateVAppTemplateParamsToXmlPayload;
|
|||
import org.jclouds.vcloud.domain.Task;
|
||||
import org.jclouds.vcloud.domain.VApp;
|
||||
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.options.CaptureVAppOptions;
|
||||
import org.jclouds.vcloud.options.CloneVAppTemplateOptions;
|
||||
|
@ -69,7 +69,7 @@ import com.google.common.util.concurrent.ListenableFuture;
|
|||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@RequestFilters(SetVCloudTokenCookie.class)
|
||||
@RequestFilters(AddVCloudAuthorizationAndCookieToRequest.class)
|
||||
public interface VAppTemplateAsyncClient {
|
||||
|
||||
/**
|
||||
|
|
|
@ -32,7 +32,7 @@ import org.jclouds.rest.annotations.RequestFilters;
|
|||
import org.jclouds.rest.annotations.XMLResponseParser;
|
||||
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
|
||||
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.xml.VDCHandler;
|
||||
|
||||
|
@ -44,7 +44,7 @@ import com.google.common.util.concurrent.ListenableFuture;
|
|||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@RequestFilters(SetVCloudTokenCookie.class)
|
||||
@RequestFilters(AddVCloudAuthorizationAndCookieToRequest.class)
|
||||
public interface VDCAsyncClient {
|
||||
|
||||
/**
|
||||
|
|
|
@ -54,7 +54,7 @@ import org.jclouds.vcloud.domain.GuestCustomizationSection;
|
|||
import org.jclouds.vcloud.domain.NetworkConnectionSection;
|
||||
import org.jclouds.vcloud.domain.Task;
|
||||
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.VmHandler;
|
||||
|
||||
|
@ -66,7 +66,7 @@ import com.google.common.util.concurrent.ListenableFuture;
|
|||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@RequestFilters(SetVCloudTokenCookie.class)
|
||||
@RequestFilters(AddVCloudAuthorizationAndCookieToRequest.class)
|
||||
public interface VmAsyncClient {
|
||||
|
||||
/**
|
||||
|
|
|
@ -28,6 +28,7 @@ import org.jclouds.http.HttpRequestFilter;
|
|||
import org.jclouds.vcloud.VCloudToken;
|
||||
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.collect.ImmutableMultimap;
|
||||
|
||||
/**
|
||||
* Adds the VCloud Token to the request as a cookie
|
||||
|
@ -36,17 +37,21 @@ import com.google.common.base.Supplier;
|
|||
*
|
||||
*/
|
||||
@Singleton
|
||||
public class SetVCloudTokenCookie implements HttpRequestFilter {
|
||||
public class AddVCloudAuthorizationAndCookieToRequest implements HttpRequestFilter {
|
||||
private Supplier<String> vcloudTokenProvider;
|
||||
|
||||
@Inject
|
||||
public SetVCloudTokenCookie(@VCloudToken Supplier<String> authTokenProvider) {
|
||||
public AddVCloudAuthorizationAndCookieToRequest(@VCloudToken Supplier<String> authTokenProvider) {
|
||||
this.vcloudTokenProvider = authTokenProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
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();
|
||||
exception = new VCloudResponseException(command, response, error);
|
||||
} else {
|
||||
message = Strings2.toStringAndClose(response.getPayload().getInput());
|
||||
message = Strings2.toString(response.getPayload());
|
||||
exception = message != null ? new HttpResponseException(command, response, message) : exception;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
|
|
|
@ -85,7 +85,7 @@ public class NetworkConnectionSectionHandler extends ParseSax.HandlerWithResult<
|
|||
} else if (qName.endsWith("Info")) {
|
||||
this.info = currentOrNull();
|
||||
} else if (qName.endsWith("PrimaryNetworkConnectionIndex")) {
|
||||
this.primaryNetworkConnectionIndex = new Integer(currentOrNull());
|
||||
this.primaryNetworkConnectionIndex = Integer.valueOf(currentOrNull());
|
||||
}
|
||||
currentText = new StringBuilder();
|
||||
}
|
||||
|
|
|
@ -32,7 +32,6 @@ import org.jclouds.vcloud.VCloudApiMetadata;
|
|||
import org.jclouds.vcloud.VCloudMediaType;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.ImmutableMultimap;
|
||||
import com.google.common.net.HttpHeaders;
|
||||
import com.google.inject.Module;
|
||||
|
||||
|
@ -52,11 +51,9 @@ public abstract class BaseVCloudComputeServiceExpectTest extends BaseRestClientE
|
|||
.build();
|
||||
|
||||
// initial auth is using basic
|
||||
protected HttpRequest version1_0LoginRequest = HttpRequest.builder().method("POST").endpoint(
|
||||
URI.create(ENDPOINT + "/v1.0/login"))
|
||||
.headers(ImmutableMultimap.<String, String> builder()
|
||||
.put(HttpHeaders.ACCEPT, VCloudMediaType.ORGLIST_XML)
|
||||
.put(HttpHeaders.AUTHORIZATION, "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build()).build();
|
||||
protected HttpRequest version1_0LoginRequest = HttpRequest.builder().method("POST").endpoint(ENDPOINT + "/v1.0/login")
|
||||
.addHeader(HttpHeaders.ACCEPT, VCloudMediaType.ORGLIST_XML)
|
||||
.addHeader(HttpHeaders.AUTHORIZATION, "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build();
|
||||
|
||||
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.
|
||||
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"))
|
||||
.headers(ImmutableMultimap.<String, String> builder()
|
||||
.put("x-vcloud-authorization", sessionToken)
|
||||
.put(HttpHeaders.SET_COOKIE, String.format("vcloud-token=%s; Secure; Path=/", sessionToken)).build()).build();
|
||||
.addHeader("x-vcloud-authorization", sessionToken)
|
||||
.addHeader(HttpHeaders.SET_COOKIE, String.format("vcloud-token=%s; Secure; Path=/", sessionToken)).build();
|
||||
|
||||
// objects are looked up by id and the format of the id is hex-hyphen
|
||||
protected String orgId = "c076f90a-397a-49fa-89b8-b294c1599cd0";
|
||||
|
||||
protected HttpRequest version1_0GetOrgRequest = HttpRequest.builder().method("GET").endpoint(
|
||||
URI.create(ENDPOINT + "/v1.0/org/" + orgId))
|
||||
.headers(ImmutableMultimap.<String, String> builder()
|
||||
.put(HttpHeaders.ACCEPT, VCloudMediaType.ORG_XML)
|
||||
.put(HttpHeaders.COOKIE, "vcloud-token=" + sessionToken).build()).build();
|
||||
protected HttpRequest version1_0GetOrgRequest = HttpRequest.builder().method("GET").endpoint(ENDPOINT + "/v1.0/org/" + orgId)
|
||||
.addHeader(HttpHeaders.ACCEPT, VCloudMediaType.ORG_XML)
|
||||
.addHeader("x-vcloud-authorization", sessionToken)
|
||||
.addHeader(HttpHeaders.COOKIE, "vcloud-token=" + sessionToken).build();
|
||||
|
||||
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"))
|
||||
|
@ -84,11 +79,10 @@ public abstract class BaseVCloudComputeServiceExpectTest extends BaseRestClientE
|
|||
protected String catalogId = "3155f393-1e1d-4572-8c9c-d76f72ddb658";
|
||||
protected String vdcId = "e9cd3387-ac57-4d27-a481-9bee75e0690f";
|
||||
|
||||
protected HttpRequest version1_0GetCatalogRequest = HttpRequest.builder().method("GET").endpoint(
|
||||
URI.create(ENDPOINT + "/v1.0/catalog/" + catalogId))
|
||||
.headers(ImmutableMultimap.<String, String> builder()
|
||||
.put(HttpHeaders.ACCEPT, VCloudMediaType.CATALOG_XML)
|
||||
.put(HttpHeaders.COOKIE, "vcloud-token=" + sessionToken).build()).build();
|
||||
protected HttpRequest version1_0GetCatalogRequest = HttpRequest.builder().method("GET").endpoint(ENDPOINT + "/v1.0/catalog/" + catalogId)
|
||||
.addHeader(HttpHeaders.ACCEPT, VCloudMediaType.CATALOG_XML)
|
||||
.addHeader("x-vcloud-authorization", sessionToken)
|
||||
.addHeader(HttpHeaders.COOKIE, "vcloud-token=" + sessionToken).build();
|
||||
|
||||
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"))
|
||||
|
@ -96,11 +90,10 @@ public abstract class BaseVCloudComputeServiceExpectTest extends BaseRestClientE
|
|||
|
||||
protected String catalogItemId = "ceb369f7-1d07-4e32-9dbd-ebb5aa6ca55c";
|
||||
|
||||
protected HttpRequest version1_0GetCatalogItemRequest = HttpRequest.builder().method("GET").endpoint(
|
||||
URI.create(ENDPOINT + "/v1.0/catalogItem/" + catalogItemId))
|
||||
.headers(ImmutableMultimap.<String, String> builder()
|
||||
.put(HttpHeaders.ACCEPT, VCloudMediaType.CATALOGITEM_XML)
|
||||
.put(HttpHeaders.COOKIE, "vcloud-token=" + sessionToken).build()).build();
|
||||
protected HttpRequest version1_0GetCatalogItemRequest = HttpRequest.builder().method("GET").endpoint(ENDPOINT + "/v1.0/catalogItem/" + catalogItemId)
|
||||
.addHeader(HttpHeaders.ACCEPT, VCloudMediaType.CATALOGITEM_XML)
|
||||
.addHeader("x-vcloud-authorization", sessionToken)
|
||||
.addHeader(HttpHeaders.COOKIE, "vcloud-token=" + sessionToken).build();
|
||||
|
||||
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"))
|
||||
|
@ -109,23 +102,21 @@ public abstract class BaseVCloudComputeServiceExpectTest extends BaseRestClientE
|
|||
// note vAppTemplate has a prefix in its id
|
||||
protected String templateId = "vappTemplate-51891b97-c5dd-47dc-a687-aabae354f728";
|
||||
|
||||
protected HttpRequest version1_0GetVDCRequest = HttpRequest.builder().method("GET").endpoint(
|
||||
URI.create(ENDPOINT + "/v1.0/vdc/" + vdcId))
|
||||
.headers(ImmutableMultimap.<String, String> builder()
|
||||
.put(HttpHeaders.ACCEPT, VCloudMediaType.VDC_XML)
|
||||
.put(HttpHeaders.COOKIE, "vcloud-token=" + sessionToken).build()).build();
|
||||
|
||||
protected HttpRequest version1_0GetVDCRequest = HttpRequest.builder().method("GET").endpoint(ENDPOINT + "/v1.0/vdc/" + vdcId)
|
||||
.addHeader(HttpHeaders.ACCEPT, VCloudMediaType.VDC_XML)
|
||||
.addHeader("x-vcloud-authorization", sessionToken)
|
||||
.addHeader(HttpHeaders.COOKIE, "vcloud-token=" + sessionToken).build();
|
||||
|
||||
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"))
|
||||
.build();
|
||||
|
||||
protected String networkId = "b466c0c5-8a5c-4335-b703-a2e2e6b5f3e1";
|
||||
|
||||
protected HttpRequest version1_0GetVAppTemplateRequest = HttpRequest.builder().method("GET").endpoint(
|
||||
URI.create(ENDPOINT + "/v1.0/vAppTemplate/" + templateId))
|
||||
.headers(ImmutableMultimap.<String, String> builder()
|
||||
.put(HttpHeaders.ACCEPT, VCloudMediaType.VAPPTEMPLATE_XML)
|
||||
.put(HttpHeaders.COOKIE, "vcloud-token=" + sessionToken).build()).build();
|
||||
protected HttpRequest version1_0GetVAppTemplateRequest = HttpRequest.builder().method("GET").endpoint(ENDPOINT + "/v1.0/vAppTemplate/" + templateId)
|
||||
.addHeader(HttpHeaders.ACCEPT, VCloudMediaType.VAPPTEMPLATE_XML)
|
||||
.addHeader("x-vcloud-authorization", sessionToken)
|
||||
.addHeader(HttpHeaders.COOKIE, "vcloud-token=" + sessionToken).build();
|
||||
|
||||
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"))
|
||||
|
@ -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"))
|
||||
.build();
|
||||
|
||||
protected HttpRequest version1_0GetOVFForVAppTemplateRequest = HttpRequest.builder().method("GET").endpoint(
|
||||
URI.create(ENDPOINT + "/v1.0/vAppTemplate/" + templateId + "/ovf"))
|
||||
.headers(ImmutableMultimap.<String, String> builder()
|
||||
.put(HttpHeaders.ACCEPT, MediaType.TEXT_XML)
|
||||
.put(HttpHeaders.COOKIE, "vcloud-token=" + sessionToken).build()).build();
|
||||
protected HttpRequest version1_0GetOVFForVAppTemplateRequest = HttpRequest.builder().method("GET").endpoint(ENDPOINT + "/v1.0/vAppTemplate/" + templateId + "/ovf")
|
||||
.addHeader(HttpHeaders.ACCEPT, MediaType.TEXT_XML)
|
||||
.addHeader("x-vcloud-authorization", sessionToken)
|
||||
.addHeader(HttpHeaders.COOKIE, "vcloud-token=" + sessionToken).build();
|
||||
|
||||
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"))
|
||||
|
|
|
@ -86,10 +86,10 @@ public class InstantiateVAppTemplateWithGroupEncodedIntoNameThenCustomizeDeployA
|
|||
.e("AllEULAsAccepted").t("true").up()
|
||||
.asString(outputProperties);
|
||||
|
||||
HttpRequest version1_0InstantiateWithNetworkNamedSameAsOrgNetwork = HttpRequest.builder()
|
||||
.method("POST")
|
||||
HttpRequest version1_0InstantiateWithNetworkNamedSameAsOrgNetwork = HttpRequest.builder().method("POST")
|
||||
.endpoint(ENDPOINT + "/v1.0/vdc/" + vdcId + "/action/instantiateVAppTemplate")
|
||||
.addHeader(HttpHeaders.ACCEPT, "application/vnd.vmware.vcloud.vApp+xml")
|
||||
.addHeader("x-vcloud-authorization", sessionToken)
|
||||
.addHeader(HttpHeaders.COOKIE, "vcloud-token=" + sessionToken)
|
||||
.payload(payloadFromStringWithContentType(instantiateXML, "application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml")).build();
|
||||
|
||||
|
@ -143,12 +143,12 @@ public class InstantiateVAppTemplateWithGroupEncodedIntoNameThenCustomizeDeployA
|
|||
.e("AllEULAsAccepted").t("true").up()
|
||||
.asString(outputProperties);
|
||||
|
||||
HttpRequest version1_0InstantiateWithCustomizedNetwork = HttpRequest.builder()
|
||||
.method("POST")
|
||||
.endpoint(ENDPOINT + "/v1.0/vdc/" + vdcId + "/action/instantiateVAppTemplate")
|
||||
.addHeader(HttpHeaders.ACCEPT, "application/vnd.vmware.vcloud.vApp+xml")
|
||||
.addHeader(HttpHeaders.COOKIE, "vcloud-token=" + sessionToken)
|
||||
.payload(payloadFromStringWithContentType(instantiateXML, "application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml")).build();
|
||||
HttpRequest version1_0InstantiateWithCustomizedNetwork = HttpRequest.builder().method("POST")
|
||||
.endpoint(ENDPOINT + "/v1.0/vdc/" + vdcId + "/action/instantiateVAppTemplate")
|
||||
.addHeader(HttpHeaders.ACCEPT, "application/vnd.vmware.vcloud.vApp+xml")
|
||||
.addHeader("x-vcloud-authorization", sessionToken)
|
||||
.addHeader(HttpHeaders.COOKIE, "vcloud-token=" + sessionToken)
|
||||
.payload(payloadFromStringWithContentType(instantiateXML, "application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml")).build();
|
||||
|
||||
ComputeService compute = requestsSendResponses(ImmutableMap.<HttpRequest, HttpResponse> builder()
|
||||
.put(versionsRequest, versionsResponseFromVCD1_5)
|
||||
|
|
|
@ -31,14 +31,14 @@ import com.google.common.base.Supplier;
|
|||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test
|
||||
public class SetVCloudTokenCookieTest {
|
||||
@Test(testName = "AddVCloudAuthorizationAndCookieToRequestTest")
|
||||
public class AddVCloudAuthorizationAndCookieToRequestTest {
|
||||
|
||||
private SetVCloudTokenCookie filter;
|
||||
private AddVCloudAuthorizationAndCookieToRequest filter;
|
||||
|
||||
@BeforeTest
|
||||
void setUp() {
|
||||
filter = new SetVCloudTokenCookie(new Supplier<String>() {
|
||||
filter = new AddVCloudAuthorizationAndCookieToRequest(new Supplier<String>() {
|
||||
public String get() {
|
||||
return "token";
|
||||
}
|
||||
|
@ -49,9 +49,9 @@ public class SetVCloudTokenCookieTest {
|
|||
public void testApply() {
|
||||
HttpRequest request = HttpRequest.builder().method("GET").endpoint("http://localhost").build();
|
||||
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("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.ReferenceTypeImpl;
|
||||
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.testng.annotations.Test;
|
||||
|
||||
|
@ -82,7 +82,7 @@ public abstract class BaseVCloudAsyncClientTest<T> extends BaseAsyncClientTest<T
|
|||
@Override
|
||||
protected void checkFilters(HttpRequest request) {
|
||||
assertEquals(request.getFilters().size(), 1);
|
||||
assertEquals(request.getFilters().get(0).getClass(), SetVCloudTokenCookie.class);
|
||||
assertEquals(request.getFilters().get(0).getClass(), AddVCloudAuthorizationAndCookieToRequest.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -55,18 +55,18 @@ public class GuestCustomizationSectionHandlerTest extends BaseHandlerTest {
|
|||
assertEquals(result.getHref(),
|
||||
URI.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/vm-2087535248/guestCustomizationSection/"));
|
||||
assertEquals(result.getInfo(), "Specifies Guest OS Customization Settings");
|
||||
assertEquals(result.isEnabled(), new Boolean(true));
|
||||
assertEquals(result.shouldChangeSid(), new Boolean(false));
|
||||
assertEquals(result.isEnabled(), Boolean.TRUE);
|
||||
assertEquals(result.shouldChangeSid(), Boolean.FALSE);
|
||||
assertEquals(result.getVirtualMachineId(), "2087535248");
|
||||
assertEquals(result.isJoinDomainEnabled(), new Boolean(false));
|
||||
assertEquals(result.useOrgSettings(), new Boolean(false));
|
||||
assertEquals(result.isJoinDomainEnabled(), Boolean.FALSE);
|
||||
assertEquals(result.useOrgSettings(), Boolean.FALSE);
|
||||
assertEquals(result.getDomainName(), null);
|
||||
assertEquals(result.getDomainUserName(), null);
|
||||
assertEquals(result.getDomainUserPassword(), null);
|
||||
assertEquals(result.isAdminPasswordEnabled(), new Boolean(true));
|
||||
assertEquals(result.isAdminPasswordAuto(), new Boolean(true));
|
||||
assertEquals(result.isAdminPasswordEnabled(), Boolean.TRUE);
|
||||
assertEquals(result.isAdminPasswordAuto(), Boolean.TRUE);
|
||||
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.getComputerName(), "RHEL5");
|
||||
assertEquals(
|
||||
|
|
|
@ -57,7 +57,7 @@ public class NetworkConnectionSectionHandlerTest {
|
|||
.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/vm-2087535248/networkConnectionSection/"));
|
||||
assertEquals(result.getType(), VCloudMediaType.NETWORKCONNECTIONSECTION_XML);
|
||||
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
|
||||
.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/vm-2087535248/networkConnectionSection/")));
|
||||
NetworkConnectionHandlerTest.checkNetworkConnection(Iterables.getOnlyElement(result.getConnections()));
|
||||
|
|
|
@ -86,18 +86,18 @@ public class VAppTemplateHandlerTest {
|
|||
URI
|
||||
.create("https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/vm-172837194/guestCustomizationSection/"));
|
||||
assertEquals(guestC.getInfo(), "Specifies Guest OS Customization Settings");
|
||||
assertEquals(guestC.isEnabled(), new Boolean(true));
|
||||
assertEquals(guestC.shouldChangeSid(), new Boolean(false));
|
||||
assertEquals(guestC.isEnabled(), Boolean.TRUE);
|
||||
assertEquals(guestC.shouldChangeSid(), Boolean.FALSE);
|
||||
assertEquals(guestC.getVirtualMachineId(), "172837194");
|
||||
assertEquals(guestC.isJoinDomainEnabled(), new Boolean(false));
|
||||
assertEquals(guestC.useOrgSettings(), new Boolean(false));
|
||||
assertEquals(guestC.isJoinDomainEnabled(), Boolean.FALSE);
|
||||
assertEquals(guestC.useOrgSettings(), Boolean.FALSE);
|
||||
assertEquals(guestC.getDomainName(), null);
|
||||
assertEquals(guestC.getDomainUserName(), null);
|
||||
assertEquals(guestC.getDomainUserPassword(), null);
|
||||
assertEquals(guestC.isAdminPasswordEnabled(), new Boolean(true));
|
||||
assertEquals(guestC.isAdminPasswordAuto(), new Boolean(true));
|
||||
assertEquals(guestC.isAdminPasswordEnabled(), Boolean.TRUE);
|
||||
assertEquals(guestC.isAdminPasswordAuto(), Boolean.TRUE);
|
||||
assertEquals(guestC.getAdminPassword(), "%3eD%gmF");
|
||||
assertEquals(guestC.isResetPasswordRequired(), new Boolean(false));
|
||||
assertEquals(guestC.isResetPasswordRequired(), Boolean.FALSE);
|
||||
assertEquals(
|
||||
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");
|
||||
|
|
|
@ -55,7 +55,7 @@ public class VCloudOperatingSystemSectionHandlerTest extends BaseHandlerTest {
|
|||
assertEquals(result.getEdit(), new ReferenceTypeImpl(null,
|
||||
"application/vnd.vmware.vcloud.operatingSystemSection+xml",
|
||||
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.getType(), "application/vnd.vmware.vcloud.operatingSystemSection+xml");
|
||||
assertEquals(result.getInfo(), "Specifies the operating system installed");
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
* specific language governing permissions and limitations
|
||||
* 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.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.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.File;
|
||||
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.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
import java.util.SortedSet;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
|
@ -51,13 +42,8 @@ import java.util.concurrent.ExecutorService;
|
|||
import javax.annotation.Resource;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.PathParam;
|
||||
|
||||
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.Factory;
|
||||
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.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.BlobStoreUtils;
|
||||
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.filesystem.predicates.validators.FilesystemContainerNameValidator;
|
||||
import org.jclouds.filesystem.strategy.FilesystemStorageStrategy;
|
||||
import org.jclouds.http.HttpCommand;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
|
@ -91,10 +72,7 @@ import org.jclouds.http.HttpUtils;
|
|||
import org.jclouds.io.ContentMetadata;
|
||||
import org.jclouds.io.ContentMetadataCodec;
|
||||
import org.jclouds.io.Payload;
|
||||
import org.jclouds.io.Payloads;
|
||||
import org.jclouds.io.payloads.BaseMutableContentMetadata;
|
||||
import org.jclouds.logging.Logger;
|
||||
import org.jclouds.rest.annotations.ParamValidators;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Predicate;
|
||||
|
@ -105,43 +83,38 @@ import com.google.common.util.concurrent.Futures;
|
|||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
|
||||
/**
|
||||
*
|
||||
* Preconditions: Blob name cannot start with / char (or \ under windows)
|
||||
*
|
||||
* Implementation of {@link BaseAsyncBlobStore} which uses a pluggable
|
||||
* LocalStorageStrategy.
|
||||
*
|
||||
* @author Adrian Cole
|
||||
* @author Alfredo "Rainbowbreeze" Morresi
|
||||
* @author Andrew Gaul
|
||||
* @author James Murty
|
||||
*/
|
||||
public class FilesystemAsyncBlobStore extends BaseAsyncBlobStore {
|
||||
public class LocalAsyncBlobStore 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 FilesystemStorageStrategy storageStrategy;
|
||||
protected final LocalStorageStrategy storageStrategy;
|
||||
|
||||
@Inject
|
||||
protected FilesystemAsyncBlobStore(BlobStoreContext context,
|
||||
DateService dateService, Crypto crypto,
|
||||
HttpGetOptionsListToGetOptions httpGetOptionsConverter,
|
||||
ContentMetadataCodec contentMetadataCodec,
|
||||
IfDirectoryReturnNameStrategy ifDirectoryReturnName,
|
||||
protected LocalAsyncBlobStore(BlobStoreContext context,
|
||||
BlobUtils blobUtils,
|
||||
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService service,
|
||||
Supplier<Location> defaultLocation,
|
||||
@Memoized Supplier<Set<? extends Location>> locations,
|
||||
Factory blobFactory, FilesystemStorageStrategy storageStrategy) {
|
||||
ContentMetadataCodec contentMetadataCodec,
|
||||
IfDirectoryReturnNameStrategy ifDirectoryReturnName,
|
||||
Factory blobFactory, LocalStorageStrategy storageStrategy) {
|
||||
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 = 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 "
|
||||
+ container);
|
||||
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);
|
||||
if (directoryName != null) {
|
||||
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) {
|
||||
SortedSet<String> commonPrefixes = newTreeSet(
|
||||
transform(contents, new CommonPrefixes(prefix, delimiter)));
|
||||
|
@ -249,37 +222,6 @@ public class FilesystemAsyncBlobStore extends BaseAsyncBlobStore {
|
|||
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}
|
||||
*/
|
||||
|
@ -289,6 +231,15 @@ public class FilesystemAsyncBlobStore extends BaseAsyncBlobStore {
|
|||
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
|
||||
* 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);
|
||||
}
|
||||
|
||||
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}
|
||||
*/
|
||||
|
@ -324,6 +291,7 @@ public class FilesystemAsyncBlobStore extends BaseAsyncBlobStore {
|
|||
MutableStorageMetadata cmd = create();
|
||||
cmd.setName(name);
|
||||
cmd.setType(StorageType.CONTAINER);
|
||||
cmd.setLocation(storageStrategy.getLocation(name));
|
||||
return cmd;
|
||||
}
|
||||
}), null));
|
||||
|
@ -336,11 +304,10 @@ public class FilesystemAsyncBlobStore extends BaseAsyncBlobStore {
|
|||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Path("{container}")
|
||||
@Override
|
||||
public ListenableFuture<Boolean> createContainerInLocation(final Location location,
|
||||
@PathParam("container") @ParamValidators({ FilesystemContainerNameValidator.class }) String name) {
|
||||
boolean result = storageStrategy.createContainer(name);
|
||||
final String name) {
|
||||
boolean result = storageStrategy.createContainerInLocation(name, location);
|
||||
return immediateFuture(result);
|
||||
}
|
||||
|
||||
|
@ -461,18 +428,12 @@ public class FilesystemAsyncBlobStore extends BaseAsyncBlobStore {
|
|||
}
|
||||
|
||||
try {
|
||||
// TODO
|
||||
// must override existing file?
|
||||
|
||||
storageStrategy.putBlob(containerName, blob);
|
||||
return immediateFuture(storageStrategy.putBlob(containerName, blob));
|
||||
} catch (IOException e) {
|
||||
logger.error(e, "An error occurred storing the new blob with name [%s] to container [%s].", blobKey,
|
||||
containerName);
|
||||
Throwables.propagate(e);
|
||||
throw Throwables.propagate(e);
|
||||
}
|
||||
|
||||
String eTag = getEtag(blob);
|
||||
return immediateFuture(eTag);
|
||||
}
|
||||
|
||||
private void copyPayloadHeadersToBlob(Payload payload, Blob blob) {
|
||||
|
@ -573,7 +534,7 @@ public class FilesystemAsyncBlobStore extends BaseAsyncBlobStore {
|
|||
byte[] byteArray = out.toByteArray();
|
||||
blob.setPayload(byteArray);
|
||||
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);
|
||||
|
@ -587,7 +548,7 @@ public class FilesystemAsyncBlobStore extends BaseAsyncBlobStore {
|
|||
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);
|
||||
return immediateFuture(blob != null ? (BlobMetadata) BlobStoreUtils.copy(blob.getMetadata()) : null);
|
||||
} catch (Exception e) {
|
||||
if (size(filter(getCausalChain(e), KeyNotFoundException.class)) >= 1)
|
||||
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) {
|
||||
Blob returnVal = blobFactory.create(copy(blob.getMetadata()));
|
||||
Blob returnVal = blobFactory.create(BlobStoreUtils.copy(blob.getMetadata()));
|
||||
returnVal.setPayload(blob.getPayload());
|
||||
copyPayloadHeadersToBlob(blob.getPayload(), returnVal);
|
||||
return returnVal;
|
|
@ -16,21 +16,20 @@
|
|||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.jclouds.filesystem.strategy;
|
||||
package org.jclouds.blobstore;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.jclouds.blobstore.domain.Blob;
|
||||
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
|
||||
*/
|
||||
public interface FilesystemStorageStrategy {
|
||||
public interface LocalStorageStrategy {
|
||||
|
||||
/**
|
||||
* Creates a new container
|
||||
|
@ -38,7 +37,7 @@ public interface FilesystemStorageStrategy {
|
|||
* @param container
|
||||
* @return
|
||||
*/
|
||||
boolean createContainer(String container);
|
||||
boolean createContainerInLocation(String container, Location location);
|
||||
|
||||
/**
|
||||
* Deletes a container and all its content
|
||||
|
@ -58,17 +57,17 @@ public interface FilesystemStorageStrategy {
|
|||
* delete the container itself
|
||||
* @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
|
||||
* deletes, or clear at a different path than root.
|
||||
*
|
||||
* @param container
|
||||
* what to clear
|
||||
* @param options
|
||||
* recursion and path to clear
|
||||
*/
|
||||
* Like {@link #clearContainer(String)} except you can use options to do things like recursive
|
||||
* deletes, or clear at a different path than root.
|
||||
*
|
||||
* @param container
|
||||
* what to clear
|
||||
* @param options
|
||||
* recursion and path to clear
|
||||
*/
|
||||
void clearContainer(String container, ListContainerOptions options);
|
||||
|
||||
/**
|
||||
|
@ -78,64 +77,26 @@ public interface FilesystemStorageStrategy {
|
|||
Iterable<String> getAllContainerNames();
|
||||
|
||||
/**
|
||||
* Determines if a directory 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);
|
||||
|
||||
/**
|
||||
*
|
||||
* Return true if a blob named by key exists
|
||||
* @param container
|
||||
* @param key
|
||||
* @return
|
||||
*/
|
||||
boolean blobExists(String container, String key);
|
||||
|
||||
/**
|
||||
* Load the blob with the given key belonging to the container with the given
|
||||
* name. There must exist a resource on the file system whose complete name
|
||||
* is given concatenating the container name and the key
|
||||
*
|
||||
* @param container
|
||||
* it's the name of the container the blob belongs to
|
||||
* @param key
|
||||
* it's the key of the blob
|
||||
*
|
||||
* @return the blob belonging to the given container with the given key
|
||||
*/
|
||||
Blob getBlob(final String containerName, final String blobName);
|
||||
/**
|
||||
* Load the blob with the given key belonging to the container with the given
|
||||
* name. There must exist a resource on the file system whose complete name
|
||||
* is given concatenating the container name and the key
|
||||
*
|
||||
* @param container
|
||||
* it's the name of the container the blob belongs to
|
||||
* @param key
|
||||
* it's the key of the blob
|
||||
*
|
||||
* @return the blob belonging to the given container with the given key
|
||||
*/
|
||||
Blob getBlob(String containerName, String blobName);
|
||||
|
||||
/**
|
||||
* Returns all the blobs key inside a container
|
||||
|
@ -146,23 +107,7 @@ public interface FilesystemStorageStrategy {
|
|||
Iterable<String> getBlobKeysInsideContainer(String container) throws IOException;
|
||||
|
||||
/**
|
||||
* Counts number of blobs inside a container
|
||||
* @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);
|
||||
|
||||
/**
|
||||
*
|
||||
* Remove blob named by the given key
|
||||
* @param container
|
||||
* @param key
|
||||
*/
|
||||
|
@ -172,8 +117,17 @@ public interface FilesystemStorageStrategy {
|
|||
* Write a {@link Blob} into a file
|
||||
* @param container
|
||||
* @param blob
|
||||
* @return etag of blob
|
||||
* @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;
|
||||
|
||||
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.concurrent.ConcurrentHashMap;
|
||||
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.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.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.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, Location> containerToLocation = new ConcurrentHashMap<String, Location>();
|
||||
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) {
|
||||
this.defaultLocation = Preconditions.checkNotNull(defaultLocation);
|
||||
@Inject
|
||||
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() {
|
||||
return containerToBlobs.keySet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containerExists(final String containerName) {
|
||||
return containerToBlobs.containsKey(containerName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearContainer(final String containerName) {
|
||||
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) {
|
||||
ConcurrentMap<String, Blob> origValue = containerToBlobs.putIfAbsent(
|
||||
containerName, new ConcurrentHashMap<String, Blob>());
|
||||
|
@ -59,36 +109,96 @@ public class TransientStorageStrategy {
|
|||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteContainer(final String containerName) {
|
||||
containerToBlobs.remove(containerName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean blobExists(final String containerName, final String blobName) {
|
||||
Map<String, Blob> map = containerToBlobs.get(containerName);
|
||||
return map != null && map.containsKey(blobName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Blob getBlob(final String containerName, final String blobName) {
|
||||
Map<String, Blob> map = containerToBlobs.get(containerName);
|
||||
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.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) {
|
||||
Map<String, Blob> map = containerToBlobs.get(containerName);
|
||||
if (map != null)
|
||||
map.remove(blobName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<String> getBlobKeysInsideContainer(final String containerName) {
|
||||
return containerToBlobs.get(containerName).keySet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Location getLocation(final String 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;
|
||||
|
||||
@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.BlobRequestSigner;
|
||||
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.TransientStorageStrategy;
|
||||
import org.jclouds.blobstore.attr.ConsistencyModel;
|
||||
import org.jclouds.rest.config.BinderUtils;
|
||||
|
||||
|
@ -37,13 +39,14 @@ import com.google.inject.AbstractModule;
|
|||
public class TransientBlobStoreContextModule extends AbstractModule {
|
||||
@Override
|
||||
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
|
||||
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 BlobStoreMapModule());
|
||||
bind(BlobStore.class).to(TransientBlobStore.class);
|
||||
bind(BlobStore.class).to(LocalBlobStore.class);
|
||||
bind(ConsistencyModel.class).toInstance(ConsistencyModel.STRICT);
|
||||
bind(LocalStorageStrategy.class).to(TransientStorageStrategy.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 java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
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.Pattern;
|
||||
|
||||
|
@ -32,6 +39,7 @@ import org.jclouds.blobstore.ContainerNotFoundException;
|
|||
import org.jclouds.blobstore.KeyNotFoundException;
|
||||
import org.jclouds.blobstore.domain.Blob;
|
||||
import org.jclouds.blobstore.domain.BlobMetadata;
|
||||
import org.jclouds.blobstore.domain.MutableBlobMetadata;
|
||||
import org.jclouds.blobstore.domain.StorageMetadata;
|
||||
import org.jclouds.blobstore.functions.BlobName;
|
||||
import org.jclouds.functions.ExceptionToValueOrPropagate;
|
||||
|
@ -41,6 +49,8 @@ import org.jclouds.http.HttpUtils;
|
|||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||
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.util.concurrent.Futures;
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
|
@ -159,4 +169,34 @@ public class BlobStoreUtils {
|
|||
public static Iterable<String> getSupportedProviders() {
|
||||
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
|
||||
@Test(groups = "unit", testName = "TransientBlobRequestSignerTest")
|
||||
public class TransientBlobRequestSignerTest extends BaseAsyncClientTest<TransientAsyncBlobStore> {
|
||||
public class TransientBlobRequestSignerTest extends BaseAsyncClientTest<LocalAsyncBlobStore> {
|
||||
|
||||
private BlobRequestSigner signer;
|
||||
private Provider<BlobBuilder> blobFactory;
|
||||
|
@ -121,8 +121,8 @@ public class TransientBlobRequestSignerTest extends BaseAsyncClientTest<Transien
|
|||
}
|
||||
|
||||
@Override
|
||||
protected TypeLiteral<RestAnnotationProcessor<TransientAsyncBlobStore>> createTypeLiteral() {
|
||||
return new TypeLiteral<RestAnnotationProcessor<TransientAsyncBlobStore>>() {
|
||||
protected TypeLiteral<RestAnnotationProcessor<LocalAsyncBlobStore>> createTypeLiteral() {
|
||||
return new TypeLiteral<RestAnnotationProcessor<LocalAsyncBlobStore>>() {
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -65,8 +65,8 @@ public class BindBlobToMultipartFormTest {
|
|||
HttpRequest request = HttpRequest.builder().method("GET").endpoint("http://localhost:8001").build();
|
||||
binder.bindToRequest(request, TEST_BLOB);
|
||||
|
||||
assertEquals(Strings2.toStringAndClose(request.getPayload().getInput()), EXPECTS);
|
||||
assertEquals(request.getPayload().getContentMetadata().getContentLength(), new Long(113));
|
||||
assertEquals(Strings2.toString(request.getPayload()), EXPECTS);
|
||||
assertEquals(request.getPayload().getContentMetadata().getContentLength(), Long.valueOf(113));
|
||||
|
||||
assertEquals(request.getPayload().getContentMetadata().getContentType(), "multipart/form-data; boundary="
|
||||
+ BOUNDARY);
|
||||
|
|
|
@ -85,7 +85,7 @@ public class ParseBlobFromHeadersAndHttpContentTest {
|
|||
replay(metadataParser);
|
||||
|
||||
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"));
|
||||
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ public class ReturnFalseOnContainerNotFoundTest {
|
|||
|
||||
@Test
|
||||
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 })
|
||||
|
|
|
@ -33,7 +33,7 @@ public class ReturnFalseOnKeyNotFoundTest {
|
|||
|
||||
@Test
|
||||
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 })
|
||||
|
|
|
@ -637,7 +637,7 @@ public class BaseBlobIntegrationTest extends BaseBlobStoreIntegrationTest {
|
|||
protected void validateMetadata(BlobMetadata metadata) throws IOException {
|
||||
assert metadata.getContentMetadata().getContentType().startsWith("text/plain") : metadata.getContentMetadata()
|
||||
.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");
|
||||
checkMD5(metadata);
|
||||
}
|
||||
|
|
|
@ -67,7 +67,7 @@ public class BaseBlobSignerLiveTest extends BaseBlobStoreIntegrationTest {
|
|||
assertConsistencyAwareContainerSize(container, 1);
|
||||
HttpRequest request = view.getSigner().signGetBlob(container, name);
|
||||
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 {
|
||||
returnContainer(container);
|
||||
}
|
||||
|
@ -85,7 +85,7 @@ public class BaseBlobSignerLiveTest extends BaseBlobStoreIntegrationTest {
|
|||
assertConsistencyAwareContainerSize(container, 1);
|
||||
HttpRequest request = view.getSigner().signGetBlob(container, name, range(0, 1));
|
||||
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 {
|
||||
returnContainer(container);
|
||||
}
|
||||
|
@ -101,7 +101,7 @@ public class BaseBlobSignerLiveTest extends BaseBlobStoreIntegrationTest {
|
|||
try {
|
||||
HttpRequest request = view.getSigner().signPutBlob(container, blob);
|
||||
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);
|
||||
} finally {
|
||||
returnContainer(container);
|
||||
|
|
|
@ -88,7 +88,7 @@ public class BaseContainerIntegrationTest extends BaseBlobStoreIntegrationTest {
|
|||
|
||||
assert metadata.getContentMetadata().getContentType().startsWith("text/plain") : metadata.getContentMetadata()
|
||||
.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");
|
||||
checkMD5(metadata);
|
||||
} finally {
|
||||
|
|
|
@ -64,7 +64,7 @@ public class ListOptionsTest {
|
|||
ListContainerOptions options = new ListContainerOptions();
|
||||
options.inDirectory("test").maxResults(1);
|
||||
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() {
|
||||
ListContainerOptions options = new ListContainerOptions();
|
||||
options.maxResults(1000);
|
||||
assertEquals(options.getMaxResults(), new Integer(1000));
|
||||
assertEquals(options.getMaxResults(), Integer.valueOf(1000));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -120,7 +120,7 @@ public class ListOptionsTest {
|
|||
@Test
|
||||
public void testMaxResultsStatic() {
|
||||
ListContainerOptions options = maxResults(1000);
|
||||
assertEquals(options.getMaxResults(), new Integer(1000));
|
||||
assertEquals(options.getMaxResults(), Integer.valueOf(1000));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||
|
|
|
@ -81,7 +81,7 @@ public class ParseAWSErrorFromXmlContent implements HttpErrorHandler {
|
|||
}
|
||||
} else {
|
||||
try {
|
||||
message = Strings2.toStringAndClose(response.getPayload().getInput());
|
||||
message = Strings2.toString(response.getPayload());
|
||||
exception = new HttpResponseException(command, response, message);
|
||||
} catch (IOException e) {
|
||||
}
|
||||
|
|
|
@ -67,7 +67,7 @@ public class ParseAzureStorageErrorFromXmlContent implements HttpErrorHandler {
|
|||
if (response.getPayload() != null) {
|
||||
String contentType = response.getPayload().getContentMetadata().getContentType();
|
||||
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 {
|
||||
error = utils.parseAzureStorageErrorFromContent(command, response, response.getPayload().getInput());
|
||||
if (error != null) {
|
||||
|
@ -76,14 +76,14 @@ public class ParseAzureStorageErrorFromXmlContent implements HttpErrorHandler {
|
|||
}
|
||||
} catch (RuntimeException e) {
|
||||
try {
|
||||
message = Strings2.toStringAndClose(response.getPayload().getInput());
|
||||
message = Strings2.toString(response.getPayload());
|
||||
exception = new HttpResponseException(command, response, message);
|
||||
} catch (IOException e1) {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
message = Strings2.toStringAndClose(response.getPayload().getInput());
|
||||
message = Strings2.toString(response.getPayload());
|
||||
exception = new HttpResponseException(command, response, message);
|
||||
} catch (IOException e) {
|
||||
}
|
||||
|
|
|
@ -94,7 +94,7 @@ public class ListOptions extends BaseHttpRequestOptions {
|
|||
|
||||
public Integer getMaxResults() {
|
||||
String maxresults = getFirstQueryOrNull("maxresults");
|
||||
return (maxresults != null) ? new Integer(maxresults) : null;
|
||||
return (maxresults != null) ? Integer.valueOf(maxresults) : null;
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
|
|
|
@ -137,7 +137,7 @@ public class BindVAppConfigurationToXmlPayload implements MapBinder, Function<Ob
|
|||
private void addDiskItems(XMLBuilder sectionBuilder, VApp vApp, VAppConfiguration configuration) {
|
||||
for (ResourceAllocationSettingData disk : filter(vApp.getResourceAllocations(), CIMPredicates
|
||||
.resourceTypeIn(ResourceType.DISK_DRIVE))) {
|
||||
if (!configuration.getDisksToDelete().contains(new Integer(disk.getAddressOnParent()))) {
|
||||
if (!configuration.getDisksToDelete().contains(Integer.valueOf(disk.getAddressOnParent()))) {
|
||||
addDiskWithQuantity(sectionBuilder, disk);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -101,7 +101,7 @@ public class ParseTerremarkVCloudErrorFromHttpResponse implements HttpErrorHandl
|
|||
String parseErrorFromContentOrNull(HttpCommand command, HttpResponse response) {
|
||||
if (response.getPayload() != null) {
|
||||
try {
|
||||
return Strings2.toStringAndClose(response.getPayload().getInput());
|
||||
return Strings2.toString(response.getPayload());
|
||||
} catch (IOException e) {
|
||||
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");
|
||||
status = Status.fromValue(statusString);
|
||||
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
|
||||
if (attributes.containsKey("type")) {
|
||||
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