From 20036775b2b718a36128b96665dd16ff54ff3b61 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Wed, 8 Oct 2014 19:28:58 -0700 Subject: [PATCH 1/2] True-up rackspace-cloudfiles with code in master. --- rackspace-cloudfiles-uk/pom.xml | 23 ++------ rackspace-cloudfiles-us/pom.xml | 25 +++------ rackspace-cloudfiles/pom.xml | 21 ++------ .../cloudfiles/v1/CloudFilesApi.java | 21 ++------ .../cloudfiles/v1/features/CDNApi.java | 2 +- .../ParseCDNContainerFromHeaders.java | 6 +-- .../v1/functions/RegionToCDNEndpoint.java | 12 ++--- .../v1/reference/CloudFilesConstants.java | 12 +++-- .../v1/reference/CloudFilesHeaders.java | 26 +++++---- .../CloudFilesAccountApiLiveTest.java | 2 +- .../v1/features/CloudFilesCDNApiLiveTest.java | 54 +++++++++---------- .../v1/features/CloudFilesCDNApiMockTest.java | 44 +++++++-------- 12 files changed, 102 insertions(+), 146 deletions(-) diff --git a/rackspace-cloudfiles-uk/pom.xml b/rackspace-cloudfiles-uk/pom.xml index abdb89a6f5..911189f7cb 100644 --- a/rackspace-cloudfiles-uk/pom.xml +++ b/rackspace-cloudfiles-uk/pom.xml @@ -23,6 +23,7 @@ org.apache.jclouds jclouds-project 1.8.1-SNAPSHOT + @@ -62,20 +63,6 @@ - - - - apache-snapshots - https://repository.apache.org/content/repositories/snapshots - - false - - - true - - - - org.apache.jclouds.labs @@ -101,7 +88,7 @@ rackspace-cloudfiles ${project.parent.version} - + org.apache.jclouds.api openstack-keystone ${project.parent.version} @@ -166,10 +153,9 @@ test - 5 - true - classes + ${jclouds.blobstore.httpstream.url} + ${jclouds.blobstore.httpstream.md5} ${test.rackspace-cloudfiles-uk.endpoint} ${test.rackspace-cloudfiles-uk.api-version} ${test.rackspace-cloudfiles-uk.build-version} @@ -186,4 +172,5 @@ + diff --git a/rackspace-cloudfiles-us/pom.xml b/rackspace-cloudfiles-us/pom.xml index f2282fdcad..d6224ecb51 100644 --- a/rackspace-cloudfiles-us/pom.xml +++ b/rackspace-cloudfiles-us/pom.xml @@ -23,6 +23,7 @@ org.apache.jclouds jclouds-project 1.8.1-SNAPSHOT + @@ -39,7 +40,7 @@ 1 ${test.rackspace-us.identity} - ${test.rackspace-us.credential} + ${test.rackspace-us.credential} org.jclouds.rackspace.cloudfiles.us*;version="${project.version}" org.jclouds.rest.internal;version="${jclouds.version}", @@ -62,20 +63,6 @@ - - - - apache-snapshots - https://repository.apache.org/content/repositories/snapshots - - false - - - true - - - - org.apache.jclouds.labs @@ -101,7 +88,7 @@ rackspace-cloudfiles ${project.parent.version} - + org.apache.jclouds.api openstack-keystone ${project.parent.version} @@ -166,10 +153,9 @@ test - 5 - true - classes + ${jclouds.blobstore.httpstream.url} + ${jclouds.blobstore.httpstream.md5} ${test.rackspace-cloudfiles-us.endpoint} ${test.rackspace-cloudfiles-us.api-version} ${test.rackspace-cloudfiles-us.build-version} @@ -186,4 +172,5 @@ + diff --git a/rackspace-cloudfiles/pom.xml b/rackspace-cloudfiles/pom.xml index ff2a3f3e99..a678e5d0e6 100644 --- a/rackspace-cloudfiles/pom.xml +++ b/rackspace-cloudfiles/pom.xml @@ -23,6 +23,7 @@ org.apache.jclouds jclouds-project 1.8.1-SNAPSHOT + @@ -57,20 +58,6 @@ - - - - apache-snapshots - https://repository.apache.org/content/repositories/snapshots - - false - - - true - - - - org.apache.jclouds.labs @@ -161,10 +148,9 @@ test - 5 - true - classes + ${jclouds.blobstore.httpstream.url} + ${jclouds.blobstore.httpstream.md5} ${test.rackspace-cloudfiles.endpoint} ${test.rackspace-cloudfiles.api-version} ${test.rackspace-cloudfiles.build-version} @@ -181,4 +167,5 @@ + diff --git a/rackspace-cloudfiles/src/main/java/org/jclouds/rackspace/cloudfiles/v1/CloudFilesApi.java b/rackspace-cloudfiles/src/main/java/org/jclouds/rackspace/cloudfiles/v1/CloudFilesApi.java index e88872538b..7c25ec2cb2 100644 --- a/rackspace-cloudfiles/src/main/java/org/jclouds/rackspace/cloudfiles/v1/CloudFilesApi.java +++ b/rackspace-cloudfiles/src/main/java/org/jclouds/rackspace/cloudfiles/v1/CloudFilesApi.java @@ -16,7 +16,6 @@ */ package org.jclouds.rackspace.cloudfiles.v1; -import org.jclouds.javax.annotation.Nullable; import org.jclouds.openstack.swift.v1.SwiftApi; import org.jclouds.rackspace.cloudfiles.v1.features.CDNApi; import org.jclouds.rackspace.cloudfiles.v1.functions.RegionToCDNEndpoint; @@ -32,7 +31,7 @@ *

* Additionally, Cloud Files provides a simple yet powerful way to publish and distribute content * behind a Content Distribution Network. - * + * * @see CDNApi * @see SwiftApi */ @@ -41,24 +40,12 @@ public interface CloudFilesApi extends SwiftApi { /** * Provides access to Cloud Files CDN features. - * + * * @param region the region to access the CDN API. - * + * * @return the {@link CDNApi} for the specified region. */ @Delegate - CDNApi getCDNApiForRegion(@EndpointParam(parser = RegionToCDNEndpoint.class) @Nullable String region); + CDNApi getCDNApi(@EndpointParam(parser = RegionToCDNEndpoint.class) String region); - /** - * Provides access to Cloud Files CDN features. - * - * @param region the region to access the CDN API. - * - * @return the {@link CDNApi} for the specified region. - * - * @deprecated Please use {@link #getCDNApiForRegion(String)}. This method will be removed in jclouds 1.8. - */ - @Deprecated - @Delegate - CDNApi cdnApiInRegion(@EndpointParam(parser = RegionToCDNEndpoint.class) @Nullable String region); } diff --git a/rackspace-cloudfiles/src/main/java/org/jclouds/rackspace/cloudfiles/v1/features/CDNApi.java b/rackspace-cloudfiles/src/main/java/org/jclouds/rackspace/cloudfiles/v1/features/CDNApi.java index 3628e2d122..e88626f57e 100644 --- a/rackspace-cloudfiles/src/main/java/org/jclouds/rackspace/cloudfiles/v1/features/CDNApi.java +++ b/rackspace-cloudfiles/src/main/java/org/jclouds/rackspace/cloudfiles/v1/features/CDNApi.java @@ -64,7 +64,7 @@ * noted in the service catalog for Cloud Files during Authentication and set the * X-CDN-Enabled header to true. * - * @see {@link CloudFilesApi#getCDNApiForRegion(String)} + * @see {@link org.jclouds.rackspace.cloudfiles.v1.CloudFilesApi#getCDNApi(String)} */ @Beta @RequestFilters(AuthenticateRequest.class) diff --git a/rackspace-cloudfiles/src/main/java/org/jclouds/rackspace/cloudfiles/v1/functions/ParseCDNContainerFromHeaders.java b/rackspace-cloudfiles/src/main/java/org/jclouds/rackspace/cloudfiles/v1/functions/ParseCDNContainerFromHeaders.java index 3d4e0f9773..38430d62dc 100644 --- a/rackspace-cloudfiles/src/main/java/org/jclouds/rackspace/cloudfiles/v1/functions/ParseCDNContainerFromHeaders.java +++ b/rackspace-cloudfiles/src/main/java/org/jclouds/rackspace/cloudfiles/v1/functions/ParseCDNContainerFromHeaders.java @@ -57,11 +57,11 @@ public CDNContainer apply(final HttpResponse from) { String enabled = checkNotNull(from.getFirstHeaderOrNull(CDN_ENABLED), CDN_ENABLED); String logRetention = checkNotNull(from.getFirstHeaderOrNull(CDN_LOG_RETENTION), CDN_LOG_RETENTION); String ttl = checkNotNull(from.getFirstHeaderOrNull(CDN_TTL), CDN_TTL); - + // just need the name from the path List parts = newArrayList(Splitter.on('/').split(request.getEndpoint().getPath())); - checkArgument(parts.size() > 0); - + checkArgument(!parts.isEmpty()); + return CDNContainer.builder().name(parts.get(parts.size() - 1)) .enabled(Boolean.parseBoolean(enabled)) .logRetention(Boolean.parseBoolean(logRetention)) diff --git a/rackspace-cloudfiles/src/main/java/org/jclouds/rackspace/cloudfiles/v1/functions/RegionToCDNEndpoint.java b/rackspace-cloudfiles/src/main/java/org/jclouds/rackspace/cloudfiles/v1/functions/RegionToCDNEndpoint.java index 866c34f753..07f6f250a2 100644 --- a/rackspace-cloudfiles/src/main/java/org/jclouds/rackspace/cloudfiles/v1/functions/RegionToCDNEndpoint.java +++ b/rackspace-cloudfiles/src/main/java/org/jclouds/rackspace/cloudfiles/v1/functions/RegionToCDNEndpoint.java @@ -34,15 +34,15 @@ import com.google.common.base.Supplier; /** - * This class ensures that the correct Cloud Files CDN endpoint is retrieved from the endpoint - * supplier. The CDN API should never be instantiated directly, but rather accessed through the + * This class ensures that the correct Cloud Files CDN endpoint is retrieved from the endpoint + * supplier. The CDN API should never be instantiated directly, but rather accessed through the * {@link CloudFilesApi#cdnApiInRegion(String)} API. *

*

NOTE

* The Cloud Files Service Type will always default to OpenStack Object Storage ("object-storage"). *

- * - * + * + * * @see CloudFilesApi#cdnApiInRegion(String) * @see CDNApi * @see RegionToEndpoint @@ -53,7 +53,7 @@ * Service Access Endpoints */ @Singleton -public class RegionToCDNEndpoint implements Function { +public class RegionToCDNEndpoint implements Function { private final Supplier>> endpointsSupplier; @@ -65,7 +65,7 @@ public RegionToCDNEndpoint(@ApiVersion final String apiVersion, final RegionIdTo public URI apply(@Nullable Object from) { checkArgument(from != null && from instanceof String, "you must specify a region, as a String argument"); Map> regionToEndpoint = endpointsSupplier.get(); - checkState(regionToEndpoint.size() > 0, "no region name to endpoint mappings configured!"); + checkState(!regionToEndpoint.isEmpty(), "no region name to endpoint mappings configured!"); checkArgument(regionToEndpoint.containsKey(from), "requested location %s, which is not in the configured locations: %s", from, regionToEndpoint); return regionToEndpoint.get(from).get(); diff --git a/rackspace-cloudfiles/src/main/java/org/jclouds/rackspace/cloudfiles/v1/reference/CloudFilesConstants.java b/rackspace-cloudfiles/src/main/java/org/jclouds/rackspace/cloudfiles/v1/reference/CloudFilesConstants.java index 095ea104e0..57ff302de1 100644 --- a/rackspace-cloudfiles/src/main/java/org/jclouds/rackspace/cloudfiles/v1/reference/CloudFilesConstants.java +++ b/rackspace-cloudfiles/src/main/java/org/jclouds/rackspace/cloudfiles/v1/reference/CloudFilesConstants.java @@ -20,8 +20,12 @@ /** * Constants specified by Rackspace Cloud Files. */ -public interface CloudFilesConstants { - int CDN_TTL_MIN = 900; - int CDN_TTL_MAX = 31536000; - int CDN_TTL_DEFAULT = 259200; +public final class CloudFilesConstants { + public static final int CDN_TTL_MIN = 900; + public static final int CDN_TTL_MAX = 31536000; + public static final int CDN_TTL_DEFAULT = 259200; + + private CloudFilesConstants() { + throw new AssertionError("intentionally unimplemented"); + } } diff --git a/rackspace-cloudfiles/src/main/java/org/jclouds/rackspace/cloudfiles/v1/reference/CloudFilesHeaders.java b/rackspace-cloudfiles/src/main/java/org/jclouds/rackspace/cloudfiles/v1/reference/CloudFilesHeaders.java index e4d862ba1f..1563c61b3c 100644 --- a/rackspace-cloudfiles/src/main/java/org/jclouds/rackspace/cloudfiles/v1/reference/CloudFilesHeaders.java +++ b/rackspace-cloudfiles/src/main/java/org/jclouds/rackspace/cloudfiles/v1/reference/CloudFilesHeaders.java @@ -21,20 +21,24 @@ /** * Additional headers specified by Rackspace Cloud Files. */ -public interface CloudFilesHeaders extends SwiftHeaders { +public final class CloudFilesHeaders { // Access logs - String CONTAINER_ACCESS_LOG_DELIVERY = CONTAINER_METADATA_PREFIX + "Access-Log-Delivery"; + public static final String CONTAINER_ACCESS_LOG_DELIVERY = SwiftHeaders.CONTAINER_METADATA_PREFIX + "Access-Log-Delivery"; // Common CDN Headers - String CDN_ENABLED = "X-Cdn-Enabled"; - String CDN_LOG_RETENTION = "X-Log-Retention"; - String CDN_TTL = "X-Ttl"; - String CDN_URI = "X-Cdn-Uri"; - String CDN_SSL_URI = "X-Cdn-Ssl-Uri"; - String CDN_STREAMING_URI = "X-Cdn-Streaming-Uri"; - String CDN_IOS_URI = "X-Cdn-Ios-Uri"; + public static final String CDN_ENABLED = "X-Cdn-Enabled"; + public static final String CDN_LOG_RETENTION = "X-Log-Retention"; + public static final String CDN_TTL = "X-Ttl"; + public static final String CDN_URI = "X-Cdn-Uri"; + public static final String CDN_SSL_URI = "X-Cdn-Ssl-Uri"; + public static final String CDN_STREAMING_URI = "X-Cdn-Streaming-Uri"; + public static final String CDN_IOS_URI = "X-Cdn-Ios-Uri"; // CDN Purge - String CDN_PURGE_OBJECT_EMAIL = "X-Purge-Email"; - String CDN_PURGE_OBJECT_FAILED = "X-Purge-Failed-Reason"; + public static final String CDN_PURGE_OBJECT_EMAIL = "X-Purge-Email"; + public static final String CDN_PURGE_OBJECT_FAILED = "X-Purge-Failed-Reason"; + + private CloudFilesHeaders() { + throw new AssertionError("intentionally unimplemented"); + } } diff --git a/rackspace-cloudfiles/src/test/java/org/jclouds/rackspace/cloudfiles/v1/features/CloudFilesAccountApiLiveTest.java b/rackspace-cloudfiles/src/test/java/org/jclouds/rackspace/cloudfiles/v1/features/CloudFilesAccountApiLiveTest.java index 8e57cf5fce..95de2b3ac4 100644 --- a/rackspace-cloudfiles/src/test/java/org/jclouds/rackspace/cloudfiles/v1/features/CloudFilesAccountApiLiveTest.java +++ b/rackspace-cloudfiles/src/test/java/org/jclouds/rackspace/cloudfiles/v1/features/CloudFilesAccountApiLiveTest.java @@ -37,7 +37,7 @@ public CloudFilesAccountApiLiveTest() { public void testUrlKeyExists() throws Exception { for (String regionId : regions) { - Account account = api.getAccountApiForRegion(regionId).get(); + Account account = api.getAccountApi(regionId).get(); assertTrue(account.getTemporaryUrlKey().isPresent()); } } diff --git a/rackspace-cloudfiles/src/test/java/org/jclouds/rackspace/cloudfiles/v1/features/CloudFilesCDNApiLiveTest.java b/rackspace-cloudfiles/src/test/java/org/jclouds/rackspace/cloudfiles/v1/features/CloudFilesCDNApiLiveTest.java index 39e95cc6e0..beeb15a037 100644 --- a/rackspace-cloudfiles/src/test/java/org/jclouds/rackspace/cloudfiles/v1/features/CloudFilesCDNApiLiveTest.java +++ b/rackspace-cloudfiles/src/test/java/org/jclouds/rackspace/cloudfiles/v1/features/CloudFilesCDNApiLiveTest.java @@ -54,9 +54,9 @@ public CloudFilesCDNApiLiveTest() { public void testEnable() throws Exception { for (String regionId : regions) { - assertNotNull(api.getCDNApiForRegion(regionId).enable(name)); - - CDNContainer container = api.getCDNApiForRegion(regionId).get(name); + assertNotNull(api.getCDNApi(regionId).enable(name)); + + CDNContainer container = api.getCDNApi(regionId).get(name); assertCDNContainerNotNull(container); assertTrue(container.isEnabled()); } @@ -64,9 +64,9 @@ public void testEnable() throws Exception { public void testEnableWithTTL() throws Exception { for (String regionId : regions) { - assertNotNull(api.getCDNApiForRegion(regionId).enable(name, 777777)); + assertNotNull(api.getCDNApi(regionId).enable(name, 777777)); - CDNContainer container = api.getCDNApiForRegion(regionId).get(name); + CDNContainer container = api.getCDNApi(regionId).get(name); assertCDNContainerNotNull(container); assertTrue(container.isEnabled()); assertTrue(container.getTtl() == 777777); @@ -75,18 +75,18 @@ public void testEnableWithTTL() throws Exception { public void testDisable() throws Exception { for (String regionId : regions) { - assertTrue(api.getCDNApiForRegion(regionId).disable(name)); + assertTrue(api.getCDNApi(regionId).disable(name)); - CDNContainer container = api.getCDNApiForRegion(regionId).get(name); + CDNContainer container = api.getCDNApi(regionId).get(name); assertFalse(container.isEnabled()); } } public void testList() throws Exception { for (String regionId : regions) { - List cdnResponse = api.getCDNApiForRegion(regionId).list().toList(); + List cdnResponse = api.getCDNApi(regionId).list().toList(); assertNotNull(cdnResponse); - + for (CDNContainer cdnContainer : cdnResponse) { assertCDNContainerNotNull(cdnContainer); assertTrue(cdnContainer.isEnabled()); @@ -98,8 +98,8 @@ public void testListWithOptions() throws Exception { String lexicographicallyBeforeName = name.substring(0, name.length() - 1); for (String regionId : regions) { ListCDNContainerOptions options = new ListCDNContainerOptions().marker(lexicographicallyBeforeName); - - CDNContainer cdnContainer = api.getCDNApiForRegion(regionId).list(options).get(0); + + CDNContainer cdnContainer = api.getCDNApi(regionId).list(options).get(0); assertCDNContainerNotNull(cdnContainer); assertTrue(cdnContainer.isEnabled()); } @@ -107,7 +107,7 @@ public void testListWithOptions() throws Exception { public void testGet() throws Exception { for (String regionId : regions) { - CDNContainer container = api.getCDNApiForRegion(regionId).get(name); + CDNContainer container = api.getCDNApi(regionId).get(name); assertCDNContainerNotNull(container); assertTrue(container.isEnabled()); } @@ -117,14 +117,14 @@ public void testPurgeObject() throws Exception { for (String regionId : regions) { String objectName = "testPurge"; Payload payload = Payloads.newByteSourcePayload(ByteSource.wrap(new byte[] {1, 2, 3})); - ObjectApi objectApi = api.getObjectApiForRegionAndContainer(regionId, name); - + ObjectApi objectApi = api.getObjectApi(regionId, name); + // create a new object objectApi.put(objectName, payload); - - CDNApi cdnApi = api.getCDNApiForRegion(regionId); + + CDNApi cdnApi = api.getCDNApi(regionId); assertTrue(cdnApi.purgeObject(name, "testPurge", ImmutableList.of())); - + // delete the object objectApi.delete(objectName); assertNull(objectApi.get(objectName, GetOptions.NONE)); @@ -134,10 +134,10 @@ public void testPurgeObject() throws Exception { public void testUpdate() throws Exception { for (String regionId : regions) { // enable with a ttl - assertNotNull(api.getCDNApiForRegion(regionId).enable(name, 777777)); - + assertNotNull(api.getCDNApi(regionId).enable(name, 777777)); + // now get the container - CDNContainer original = api.getCDNApiForRegion(regionId).get(name); + CDNContainer original = api.getCDNApi(regionId).get(name); assertTrue(original.isEnabled()); assertCDNContainerNotNull(original); @@ -147,13 +147,13 @@ public void testUpdate() throws Exception { .logRetention(true) .enabled(false); // update the container - assertTrue(api.getCDNApiForRegion(regionId).update(name, opts)); - + assertTrue(api.getCDNApi(regionId).update(name, opts)); + // now get the updated container - CDNContainer updated = api.getCDNApiForRegion(regionId).get(name); + CDNContainer updated = api.getCDNApi(regionId).get(name); assertFalse(updated.isEnabled()); assertCDNContainerNotNull(updated); - + assertNotEquals(original.getTtl(), updated.getTtl()); assertTrue(updated.isLogRetentionEnabled()); } @@ -174,7 +174,7 @@ private static void assertCDNContainerNotNull(CDNContainer container) { public void setup() { super.setup(); for (String regionId : regions) { - api.getContainerApiForRegion(regionId).create(name); + api.getContainerApi(regionId).create(name); } } @@ -182,8 +182,8 @@ public void setup() { @AfterClass(groups = "live") public void tearDown() { for (String regionId : regions) { - api.getCDNApiForRegion(regionId).disable(name); - api.getContainerApiForRegion(regionId).deleteIfEmpty(name); + api.getCDNApi(regionId).disable(name); + api.getContainerApi(regionId).deleteIfEmpty(name); } super.tearDown(); } diff --git a/rackspace-cloudfiles/src/test/java/org/jclouds/rackspace/cloudfiles/v1/features/CloudFilesCDNApiMockTest.java b/rackspace-cloudfiles/src/test/java/org/jclouds/rackspace/cloudfiles/v1/features/CloudFilesCDNApiMockTest.java index de550581b1..a3fa13c858 100644 --- a/rackspace-cloudfiles/src/test/java/org/jclouds/rackspace/cloudfiles/v1/features/CloudFilesCDNApiMockTest.java +++ b/rackspace-cloudfiles/src/test/java/org/jclouds/rackspace/cloudfiles/v1/features/CloudFilesCDNApiMockTest.java @@ -61,7 +61,7 @@ public void testList() throws Exception { try { CloudFilesApi api = api(server.getUrl("/").toString(), "rackspace-cloudfiles"); - CDNApi cdnApi = api.getCDNApiForRegion("DFW"); + CDNApi cdnApi = api.getCDNApi("DFW"); ImmutableList cdnContainers = cdnApi.list().toList(); @@ -82,7 +82,7 @@ public void testListIsEmpty() throws Exception { try { CloudFilesApi api = api(server.getUrl("/").toString(), "rackspace-cloudfiles"); - CDNApi cdnApi = api.getCDNApiForRegion("DFW"); + CDNApi cdnApi = api.getCDNApi("DFW"); List cdnContainers = cdnApi.list().toList(); @@ -104,7 +104,7 @@ public void testListWithOptions() throws Exception { try { CloudFilesApi api = api(server.getUrl("/").toString(), "rackspace-cloudfiles"); ListCDNContainerOptions options = new ListCDNContainerOptions().marker("cdn-container-3"); - ImmutableList containers = api.getCDNApiForRegion("DFW").list(options).toList(); + ImmutableList containers = api.getCDNApi("DFW").list(options).toList(); for (CDNContainer container : containers) { assertCDNContainerNotNull(container); @@ -128,7 +128,7 @@ public void testListWithOptionsIsEmpty() throws Exception { try { CloudFilesApi api = api(server.getUrl("/").toString(), "rackspace-cloudfiles"); ListCDNContainerOptions options = ListCDNContainerOptions.Builder.marker("cdn-container-3"); - FluentIterable containers = api.getCDNApiForRegion("DFW").list(options); + FluentIterable containers = api.getCDNApi("DFW").list(options); assertEquals(server.getRequestCount(), 2); assertAuthentication(server); @@ -150,7 +150,7 @@ public void testEnable() throws Exception { CloudFilesApi api = api(server.getUrl("/").toString(), "rackspace-cloudfiles"); // enable a CDN Container - URI enabledContainer = api.getCDNApiForRegion("DFW").enable("container-1"); + URI enabledContainer = api.getCDNApi("DFW").enable("container-1"); assertNotNull(enabledContainer); assertEquals(server.getRequestCount(), 2); @@ -165,11 +165,11 @@ public void testEnableFail() throws Exception { MockWebServer server = mockOpenStackServer(); server.enqueue(addCommonHeaders(new MockResponse().setBody(stringFromResource("/access.json")))); server.enqueue(addCommonHeaders(enabledResponse().setResponseCode(404))); - + try { CloudFilesApi api = api(server.getUrl("/").toString(), "rackspace-cloudfiles"); // enable a CDN Container - assertNull(api.getCDNApiForRegion("DFW").enable("container-1")); + assertNull(api.getCDNApi("DFW").enable("container-1")); assertEquals(server.getRequestCount(), 2); assertAuthentication(server); @@ -188,7 +188,7 @@ public void testEnableWithTTL() throws Exception { CloudFilesApi api = api(server.getUrl("/").toString(), "rackspace-cloudfiles"); // enable a CDN Container with a TTL - URI enabledContainer = api.getCDNApiForRegion("DFW").enable("container-1", 777777); + URI enabledContainer = api.getCDNApi("DFW").enable("container-1", 777777); assertNotNull(enabledContainer); assertEquals(server.getRequestCount(), 2); @@ -208,7 +208,7 @@ public void testEnableWithTTLFail() throws Exception { CloudFilesApi api = api(server.getUrl("/").toString(), "rackspace-cloudfiles"); // enable a CDN Container with a TTL - URI enabledContainer = api.getCDNApiForRegion("DFW").enable("container-1", 777777); + URI enabledContainer = api.getCDNApi("DFW").enable("container-1", 777777); assertNull(enabledContainer); assertEquals(server.getRequestCount(), 2); @@ -228,7 +228,7 @@ public void testDisable() throws Exception { CloudFilesApi api = api(server.getUrl("/").toString(), "rackspace-cloudfiles"); // disable a CDN Container - assertTrue(api.getCDNApiForRegion("DFW").disable("container-1")); + assertTrue(api.getCDNApi("DFW").disable("container-1")); assertEquals(server.getRequestCount(), 2); assertAuthentication(server); @@ -247,7 +247,7 @@ public void testDisableFail() throws Exception { CloudFilesApi api = api(server.getUrl("/").toString(), "rackspace-cloudfiles"); // disable a CDN Container - boolean disbledContainer = api.getCDNApiForRegion("DFW").disable("container-1"); + boolean disbledContainer = api.getCDNApi("DFW").disable("container-1"); assertFalse(disbledContainer); assertEquals(server.getRequestCount(), 2); @@ -262,11 +262,11 @@ public void testGet() throws Exception { MockWebServer server = mockOpenStackServer(); server.enqueue(addCommonHeaders(new MockResponse().setBody(stringFromResource("/access.json")))); server.enqueue(addCommonHeaders(enabledResponse().setResponseCode(201))); - + try { CloudFilesApi api = api(server.getUrl("/").toString(), "rackspace-cloudfiles"); - CDNContainer cdnContainer = api.getCDNApiForRegion("DFW").get("container-1"); + CDNContainer cdnContainer = api.getCDNApi("DFW").get("container-1"); assertCDNContainerNotNull(cdnContainer); assertEquals(mockCDNContainer, cdnContainer); @@ -286,7 +286,7 @@ public void testGetCDNContainerWithSpaces() throws Exception { try { CloudFilesApi api = api(server.getUrl("/").toString(), "rackspace-cloudfiles"); - CDNContainer cdnContainer = api.getCDNApiForRegion("DFW").get("cdn-container with spaces"); + CDNContainer cdnContainer = api.getCDNApi("DFW").get("cdn-container with spaces"); assertCDNContainerNotNull(cdnContainer); assertEquals(mockCDNContainerWithSpaces, cdnContainer); @@ -306,7 +306,7 @@ public void testGetFail() throws Exception { try { CloudFilesApi api = api(server.getUrl("/").toString(), "rackspace-cloudfiles"); - CDNContainer cdnContainer = api.getCDNApiForRegion("DFW").get("container-1"); + CDNContainer cdnContainer = api.getCDNApi("DFW").get("container-1"); assertAuthentication(server); assertRequest(server.takeRequest(), "HEAD", "/v1/MossoCloudFS_5bcf396e-39dd-45ff-93a1-712b9aba90a9/container-1"); @@ -325,7 +325,7 @@ public void testPurgeObject() throws Exception { CloudFilesApi api = api(server.getUrl("/").toString(), "rackspace-cloudfiles"); // purge the object - assertTrue(api.getCDNApiForRegion("DFW").purgeObject("myContainer", "myObject", emails)); + assertTrue(api.getCDNApi("DFW").purgeObject("myContainer", "myObject", emails)); assertEquals(server.getRequestCount(), 2); assertAuthentication(server); @@ -344,7 +344,7 @@ public void testPurgeObjectFail() throws Exception { CloudFilesApi api = api(server.getUrl("/").toString(), "rackspace-cloudfiles"); // purge the object - assertFalse(api.getCDNApiForRegion("DFW").purgeObject("myContainer", "myObject", emails)); + assertFalse(api.getCDNApi("DFW").purgeObject("myContainer", "myObject", emails)); assertEquals(server.getRequestCount(), 2); assertAuthentication(server); @@ -364,13 +364,13 @@ public void testUpdate() throws Exception { try { CloudFilesApi api = api(server.getUrl("/").toString(), "rackspace-cloudfiles"); - CDNContainer cdnContainer = api.getCDNApiForRegion("DFW").get("container-1"); + CDNContainer cdnContainer = api.getCDNApi("DFW").get("container-1"); assertCDNContainerNotNull(cdnContainer); // update the CDN Container - assertTrue(api.getCDNApiForRegion("DFW").update("container-1", enabled(false).logRetention(true).ttl(7654321))); + assertTrue(api.getCDNApi("DFW").update("container-1", enabled(false).logRetention(true).ttl(7654321))); - cdnContainer = api.getCDNApiForRegion("DFW").get("container-1"); + cdnContainer = api.getCDNApi("DFW").get("container-1"); assertCDNContainerNotNull(cdnContainer); CDNContainer updatedContainer = CDNContainer.builder() @@ -405,11 +405,11 @@ public void testUpdateFail() throws Exception { try { CloudFilesApi api = api(server.getUrl("/").toString(), "rackspace-cloudfiles"); - CDNContainer cdnContainer = api.getCDNApiForRegion("DFW").get("container-1"); + CDNContainer cdnContainer = api.getCDNApi("DFW").get("container-1"); assertCDNContainerNotNull(cdnContainer); // update the CDN Container - assertFalse(api.getCDNApiForRegion("DFW").update("container-1", enabled(false).logRetention(true).ttl(7654321))); + assertFalse(api.getCDNApi("DFW").update("container-1", enabled(false).logRetention(true).ttl(7654321))); assertEquals(server.getRequestCount(), 3); assertAuthentication(server); From ee9a298fad6af3aa3fb9588907742f60763436b5 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Wed, 8 Oct 2014 13:10:32 -0700 Subject: [PATCH 2/2] Swift is now out of labs. --- README.md | 1 - openstack-swift/README.md | 10 - openstack-swift/pom.xml | 168 ------ .../swift/v1/CopyObjectException.java | 47 -- .../jclouds/openstack/swift/v1/SwiftApi.java | 126 ----- .../openstack/swift/v1/SwiftApiMetadata.java | 99 ---- .../swift/v1/TemporaryUrlSigner.java | 89 --- .../v1/binders/BindMetadataToHeaders.java | 141 ----- .../swift/v1/binders/SetPayload.java | 72 --- .../RegionScopedBlobStoreContext.java | 193 ------- .../blobstore/RegionScopedSwiftBlobStore.java | 312 ----------- .../RegionScopedTemporaryUrlBlobSigner.java | 109 ---- .../config/SignUsingTemporaryUrls.java | 67 --- .../config/SwiftBlobStoreContextModule.java | 63 --- .../blobstore/functions/ToBlobMetadata.java | 71 --- .../functions/ToListContainerOptions.java | 52 -- .../functions/ToResourceMetadata.java | 44 -- .../v1/config/BaseSwiftHttpApiModule.java | 46 -- .../swift/v1/config/SwiftHttpApiModule.java | 32 -- .../swift/v1/config/SwiftTypeAdapters.java | 119 ---- .../openstack/swift/v1/domain/Account.java | 219 -------- .../swift/v1/domain/BulkDeleteResponse.java | 101 ---- .../openstack/swift/v1/domain/Container.java | 237 -------- .../v1/domain/ExtractArchiveResponse.java | 90 ---- .../openstack/swift/v1/domain/ObjectList.java | 57 -- .../openstack/swift/v1/domain/Segment.java | 145 ----- .../swift/v1/domain/SwiftObject.java | 267 --------- .../swift/v1/features/AccountApi.java | 115 ---- .../openstack/swift/v1/features/BulkApi.java | 106 ---- .../swift/v1/features/ContainerApi.java | 259 --------- .../swift/v1/features/ObjectApi.java | 310 ----------- .../v1/features/StaticLargeObjectApi.java | 91 ---- .../swift/v1/functions/ETagHeader.java | 32 -- .../functions/EntriesWithoutMetaPrefix.java | 48 -- .../swift/v1/functions/FalseOnAccepted.java | 30 -- .../v1/functions/MetadataFromHeaders.java | 31 -- .../v1/functions/ParseAccountFromHeaders.java | 38 -- .../functions/ParseContainerFromHeaders.java | 54 -- .../v1/functions/ParseObjectFromResponse.java | 80 --- .../ParseObjectListFromResponse.java | 108 ---- .../swift/v1/handlers/SwiftErrorHandler.java | 91 ---- .../v1/options/CreateContainerOptions.java | 108 ---- .../v1/options/ListContainerOptions.java | 132 ----- .../swift/v1/options/PutOptions.java | 71 --- .../v1/options/UpdateContainerOptions.java | 107 ---- .../swift/v1/reference/SwiftHeaders.java | 94 ---- .../services/org.jclouds.apis.ApiMetadata | 18 - .../swift/v1/AuthenticationMockTest.java | 71 --- .../swift/v1/SwiftApiMetadataTest.java | 32 -- .../swift/v1/SwiftErrorHandlerTest.java | 117 ---- .../swift/v1/TemporaryUrlSignerLiveTest.java | 90 ---- .../swift/v1/TemporaryUrlSignerMockTest.java | 76 --- .../RegionScopedBlobStoreContextLiveTest.java | 95 ---- .../SwiftBlobIntegrationLiveTest.java | 76 --- .../integration/SwiftBlobLiveTest.java | 39 -- .../integration/SwiftBlobSignerLiveTest.java | 39 -- .../SwiftContainerIntegrationLiveTest.java | 54 -- .../integration/SwiftContainerLiveTest.java | 39 -- .../SwiftServiceIntegrationLiveTest.java | 39 -- .../v1/config/SwiftTypeAdaptersTest.java | 90 ---- .../swift/v1/features/AccountApiLiveTest.java | 87 --- .../swift/v1/features/AccountApiMockTest.java | 145 ----- .../swift/v1/features/BulkApiLiveTest.java | 125 ----- .../swift/v1/features/BulkApiMockTest.java | 72 --- .../v1/features/ContainerApiLiveTest.java | 197 ------- .../v1/features/ContainerApiMockTest.java | 364 ------------- .../CreatePublicContainerLiveTest.java | 47 -- .../swift/v1/features/ObjectApiLiveTest.java | 291 ---------- .../swift/v1/features/ObjectApiMockTest.java | 506 ------------------ .../StaticLargeObjectApiLiveTest.java | 129 ----- .../StaticLargeObjectApiMockTest.java | 107 ---- .../UrlEncodeAndJoinOnNewlineTest.java | 44 -- .../v1/internal/BaseSwiftApiLiveTest.java | 88 --- .../options/CreateContainerOptionsTest.java | 69 --- .../swift/v1/options/PutOptionsTest.java | 48 -- .../options/UpdateContainerOptionsTest.java | 122 ----- .../src/test/resources/access.json | 249 --------- .../src/test/resources/container_list.json | 12 - .../src/test/resources/logback.xml | 71 --- .../src/test/resources/object_list.json | 23 - pom.xml | 1 - rackspace-cloudfiles-uk/pom.xml | 4 +- rackspace-cloudfiles-us/pom.xml | 4 +- rackspace-cloudfiles/pom.xml | 4 +- 84 files changed, 6 insertions(+), 8560 deletions(-) delete mode 100644 openstack-swift/README.md delete mode 100644 openstack-swift/pom.xml delete mode 100644 openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/CopyObjectException.java delete mode 100644 openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/SwiftApi.java delete mode 100644 openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/SwiftApiMetadata.java delete mode 100644 openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/TemporaryUrlSigner.java delete mode 100644 openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/binders/BindMetadataToHeaders.java delete mode 100644 openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/binders/SetPayload.java delete mode 100644 openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/blobstore/RegionScopedBlobStoreContext.java delete mode 100644 openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/blobstore/RegionScopedSwiftBlobStore.java delete mode 100644 openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/blobstore/RegionScopedTemporaryUrlBlobSigner.java delete mode 100644 openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/blobstore/config/SignUsingTemporaryUrls.java delete mode 100644 openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/blobstore/config/SwiftBlobStoreContextModule.java delete mode 100644 openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/blobstore/functions/ToBlobMetadata.java delete mode 100644 openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/blobstore/functions/ToListContainerOptions.java delete mode 100644 openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/blobstore/functions/ToResourceMetadata.java delete mode 100644 openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/config/BaseSwiftHttpApiModule.java delete mode 100644 openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/config/SwiftHttpApiModule.java delete mode 100644 openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/config/SwiftTypeAdapters.java delete mode 100644 openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/domain/Account.java delete mode 100644 openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/domain/BulkDeleteResponse.java delete mode 100644 openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/domain/Container.java delete mode 100644 openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/domain/ExtractArchiveResponse.java delete mode 100644 openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/domain/ObjectList.java delete mode 100644 openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/domain/Segment.java delete mode 100644 openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/domain/SwiftObject.java delete mode 100644 openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/features/AccountApi.java delete mode 100644 openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/features/BulkApi.java delete mode 100644 openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/features/ContainerApi.java delete mode 100644 openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/features/ObjectApi.java delete mode 100644 openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/features/StaticLargeObjectApi.java delete mode 100644 openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/functions/ETagHeader.java delete mode 100644 openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/functions/EntriesWithoutMetaPrefix.java delete mode 100644 openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/functions/FalseOnAccepted.java delete mode 100644 openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/functions/MetadataFromHeaders.java delete mode 100644 openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/functions/ParseAccountFromHeaders.java delete mode 100644 openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/functions/ParseContainerFromHeaders.java delete mode 100644 openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/functions/ParseObjectFromResponse.java delete mode 100644 openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/functions/ParseObjectListFromResponse.java delete mode 100644 openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/handlers/SwiftErrorHandler.java delete mode 100644 openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/options/CreateContainerOptions.java delete mode 100644 openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/options/ListContainerOptions.java delete mode 100644 openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/options/PutOptions.java delete mode 100644 openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/options/UpdateContainerOptions.java delete mode 100644 openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/reference/SwiftHeaders.java delete mode 100644 openstack-swift/src/main/resources/META-INF/services/org.jclouds.apis.ApiMetadata delete mode 100644 openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/AuthenticationMockTest.java delete mode 100644 openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/SwiftApiMetadataTest.java delete mode 100644 openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/SwiftErrorHandlerTest.java delete mode 100644 openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/TemporaryUrlSignerLiveTest.java delete mode 100644 openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/TemporaryUrlSignerMockTest.java delete mode 100644 openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/blobstore/RegionScopedBlobStoreContextLiveTest.java delete mode 100644 openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/blobstore/integration/SwiftBlobIntegrationLiveTest.java delete mode 100644 openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/blobstore/integration/SwiftBlobLiveTest.java delete mode 100644 openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/blobstore/integration/SwiftBlobSignerLiveTest.java delete mode 100644 openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/blobstore/integration/SwiftContainerIntegrationLiveTest.java delete mode 100644 openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/blobstore/integration/SwiftContainerLiveTest.java delete mode 100644 openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/blobstore/integration/SwiftServiceIntegrationLiveTest.java delete mode 100644 openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/config/SwiftTypeAdaptersTest.java delete mode 100644 openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/AccountApiLiveTest.java delete mode 100644 openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/AccountApiMockTest.java delete mode 100644 openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/BulkApiLiveTest.java delete mode 100644 openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/BulkApiMockTest.java delete mode 100644 openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/ContainerApiLiveTest.java delete mode 100644 openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/ContainerApiMockTest.java delete mode 100644 openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/CreatePublicContainerLiveTest.java delete mode 100644 openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/ObjectApiLiveTest.java delete mode 100644 openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/ObjectApiMockTest.java delete mode 100644 openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/StaticLargeObjectApiLiveTest.java delete mode 100644 openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/StaticLargeObjectApiMockTest.java delete mode 100644 openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/UrlEncodeAndJoinOnNewlineTest.java delete mode 100644 openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/internal/BaseSwiftApiLiveTest.java delete mode 100644 openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/options/CreateContainerOptionsTest.java delete mode 100644 openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/options/PutOptionsTest.java delete mode 100644 openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/options/UpdateContainerOptionsTest.java delete mode 100644 openstack-swift/src/test/resources/access.json delete mode 100644 openstack-swift/src/test/resources/container_list.json delete mode 100644 openstack-swift/src/test/resources/logback.xml delete mode 100644 openstack-swift/src/test/resources/object_list.json diff --git a/README.md b/README.md index 8304294b1d..2913b7965d 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,6 @@ Although this is a "labs" repository, some of the providers and APIs here are pr | openstack-glance | API | No | | openstack-marconi | API | No | | openstack-neutron | API | Yes | -| openstack-swift | API | Beta | | rackspace-autoscale | API | No | | rackspace-cloudfiles | API | No | | rackspace-autoscale-us | Provider | No | diff --git a/openstack-swift/README.md b/openstack-swift/README.md deleted file mode 100644 index 59bd846911..0000000000 --- a/openstack-swift/README.md +++ /dev/null @@ -1,10 +0,0 @@ -OpenStack Swift -=============== - -Swift is a distributed object storage system designed to scale from a single machine to thousands of servers. - -Production ready? -Beta - -This API is new to jclouds and hence is in Beta. That means we need people to use it and give us feedback. Based on that feedback, minor changes to the interfaces may happen. This code will replace org.jclouds.openstack.swift.SwiftClient in jclouds 2.0 and it is recommended you adopt it sooner than later. - diff --git a/openstack-swift/pom.xml b/openstack-swift/pom.xml deleted file mode 100644 index b1a2471ef2..0000000000 --- a/openstack-swift/pom.xml +++ /dev/null @@ -1,168 +0,0 @@ - - - - 4.0.0 - - org.apache.jclouds - jclouds-project - 1.8.1-SNAPSHOT - - - - org.apache.jclouds.labs - openstack-swift - 1.8.1-SNAPSHOT - jclouds openstack-swift api - jclouds components to access an implementation of OpenStack Swift - bundle - - - - http://localhost:5000/v2.0/ - 1.0 - - FIXME_IDENTITY - FIXME_CREDENTIALS - passwordCredentials - http://archive.apache.org/dist/commons/logging/binaries/commons-logging-1.1.1-bin.tar.gz - e5de09672af9b386c30a311654d8541a - org.jclouds.openstack.swift.v1*;version="${project.version}" - org.jclouds*;version="${project.version}",* - - - - - apache-snapshots - https://repository.apache.org/content/repositories/snapshots - - false - - - true - - - - - - - - apache-snapshots - https://repository.apache.org/content/repositories/snapshots - - false - - - true - - - - - - - org.apache.jclouds.api - openstack-keystone - ${project.parent.version} - - - org.apache.jclouds - jclouds-blobstore - ${project.parent.version} - - - org.apache.jclouds - jclouds-core - ${project.parent.version} - test-jar - test - - - org.apache.jclouds.api - openstack-keystone - ${project.parent.version} - test-jar - test - - - org.apache.jclouds - jclouds-blobstore - ${project.parent.version} - test-jar - test - - - org.jboss.shrinkwrap - shrinkwrap-depchain - 1.2.0 - pom - test - - - org.apache.jclouds.driver - jclouds-slf4j - ${project.parent.version} - test - - - ch.qos.logback - logback-classic - test - - - com.squareup.okhttp - mockwebserver - test - - - - - - live - - - - org.apache.maven.plugins - maven-surefire-plugin - - - integration - integration-test - - test - - - - ${test.openstack-swift.endpoint} - ${test.openstack-swift.api-version} - ${test.openstack-swift.build-version} - ${test.openstack-swift.identity} - ${test.openstack-swift.credential} - ${test.jclouds.keystone.credential-type} - ${jclouds.blobstore.httpstream.url} - ${jclouds.blobstore.httpstream.md5} - - - - - - - - - - diff --git a/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/CopyObjectException.java b/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/CopyObjectException.java deleted file mode 100644 index 9a1925a595..0000000000 --- a/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/CopyObjectException.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF 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.openstack.swift.v1; - -import org.jclouds.rest.ResourceNotFoundException; - -/** - * Thrown when an object cannot be copied. - * - * - * @see {@link SwiftErrorHandler#handleError(HttpCommand, HttpResponse)} - */ -public class CopyObjectException extends ResourceNotFoundException { - - private String sourcePath; - private String destinationPath; - - public CopyObjectException(String sourcePath, String destinationPath, String message) { - super(String.format("Either the source path '%s' or the destination path '%s' was not found. " + - "(message: %s)", sourcePath, destinationPath, message)); - this.sourcePath = sourcePath; - this.destinationPath = destinationPath; - } - - public String getSourcePath() { - return sourcePath; - } - - public String getDestinationPath() { - return destinationPath; - } - -} diff --git a/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/SwiftApi.java b/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/SwiftApi.java deleted file mode 100644 index 6d8b2a71da..0000000000 --- a/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/SwiftApi.java +++ /dev/null @@ -1,126 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF 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.openstack.swift.v1; - -import java.io.Closeable; -import java.util.Set; - -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; - -import org.jclouds.javax.annotation.Nullable; -import org.jclouds.location.Region; -import org.jclouds.location.functions.RegionToEndpoint; -import org.jclouds.openstack.swift.v1.features.AccountApi; -import org.jclouds.openstack.swift.v1.features.BulkApi; -import org.jclouds.openstack.swift.v1.features.ContainerApi; -import org.jclouds.openstack.swift.v1.features.ObjectApi; -import org.jclouds.openstack.swift.v1.features.StaticLargeObjectApi; -import org.jclouds.rest.annotations.Delegate; -import org.jclouds.rest.annotations.EndpointParam; - -import com.google.common.annotations.Beta; -import com.google.inject.Provides; - -/** - * Provides access to the OpenStack Object Storage (Swift) API. - *

- * OpenStack Object Storage is an object-based storage system that stores content and metadata - * as objects. You create, modify, and get objects and metadata using this API. - *

- * This API is new to jclouds and hence is in Beta. That means we need people to use it and give us feedback. Based - * on that feedback, minor changes to the interfaces may happen. This code will replace - * {@code org.jclouds.openstack.swift.SwiftClient} in jclouds 2.0 and it is recommended you adopt it sooner than later. - */ -@Beta -public interface SwiftApi extends Closeable { - - @Provides - @Region - Set getConfiguredRegions(); - - @Delegate - AccountApi getAccountApiForRegion(@EndpointParam(parser = RegionToEndpoint.class) @Nullable String region); - - @Delegate - BulkApi getBulkApiForRegion(@EndpointParam(parser = RegionToEndpoint.class) @Nullable String region); - - @Delegate - ContainerApi getContainerApiForRegion(@EndpointParam(parser = RegionToEndpoint.class) @Nullable String region); - - @Delegate - @Path("/{containerName}") - ObjectApi getObjectApiForRegionAndContainer(@EndpointParam(parser = RegionToEndpoint.class) @Nullable String region, - @PathParam("containerName") String containerName); - - @Delegate - @Path("/{containerName}") - StaticLargeObjectApi getStaticLargeObjectApiForRegionAndContainer( - @EndpointParam(parser = RegionToEndpoint.class) @Nullable String region, - @PathParam("containerName") String containerName); - - /** - * @deprecated Please use {@link #getConfiguredRegions()} as this method will be removed in jclouds 1.8. - */ - @Deprecated - @Provides - @Region - Set configuredRegions(); - - /** - * @deprecated Please use {@link #getAccountApiForRegion(String)} as this method will be removed in jclouds 1.8. - */ - @Deprecated - @Delegate - AccountApi accountApiInRegion(@EndpointParam(parser = RegionToEndpoint.class) @Nullable String region); - - /** - * @deprecated Please use {@link #getBulkApiForRegion(String)} as this method will be removed in jclouds 1.8. - */ - @Deprecated - @Delegate - BulkApi bulkApiInRegion(@EndpointParam(parser = RegionToEndpoint.class) @Nullable String region); - - /** - * @deprecated Please use {@link #getContainerApiForRegion(String)} as this method will be removed in - * jclouds 1.8. - */ - @Deprecated - @Delegate - ContainerApi containerApiInRegion(@EndpointParam(parser = RegionToEndpoint.class) @Nullable String region); - - /** - * @deprecated Please use {@link #getObjectApiForRegionAndContainer(String, String)} as this method will be - * removed in jclouds 1.8. - */ - @Deprecated - @Delegate - @Path("/{containerName}") - ObjectApi objectApiInRegionForContainer(@EndpointParam(parser = RegionToEndpoint.class) @Nullable String region, - @PathParam("containerName") String containerName); - - /** - * @deprecated Please use {@link #getStaticLargeObjectApiForRegionAndContainer(String, String)} as this method - * will be removed in jclouds 1.8. - */ - @Deprecated - @Delegate - @Path("/{containerName}") - StaticLargeObjectApi staticLargeObjectApiInRegionForContainer( - @EndpointParam(parser = RegionToEndpoint.class) @Nullable String region, - @PathParam("containerName") String containerName); -} diff --git a/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/SwiftApiMetadata.java b/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/SwiftApiMetadata.java deleted file mode 100644 index 9f110f40d9..0000000000 --- a/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/SwiftApiMetadata.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF 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.openstack.swift.v1; - -import static org.jclouds.openstack.keystone.v2_0.config.KeystoneProperties.CREDENTIAL_TYPE; -import static org.jclouds.openstack.keystone.v2_0.config.KeystoneProperties.SERVICE_TYPE; -import static org.jclouds.reflect.Reflection2.typeToken; - -import java.net.URI; -import java.util.Properties; - -import org.jclouds.openstack.keystone.v2_0.config.AuthenticationApiModule; -import org.jclouds.openstack.keystone.v2_0.config.CredentialTypes; -import org.jclouds.openstack.keystone.v2_0.config.KeystoneAuthenticationModule; -import org.jclouds.openstack.keystone.v2_0.config.KeystoneAuthenticationModule.RegionModule; -import org.jclouds.openstack.swift.v1.blobstore.RegionScopedBlobStoreContext; -import org.jclouds.openstack.swift.v1.blobstore.config.SignUsingTemporaryUrls; -import org.jclouds.openstack.swift.v1.blobstore.config.SwiftBlobStoreContextModule; -import org.jclouds.openstack.swift.v1.config.SwiftHttpApiModule; -import org.jclouds.openstack.swift.v1.config.SwiftTypeAdapters; -import org.jclouds.openstack.v2_0.ServiceType; -import org.jclouds.rest.internal.BaseHttpApiMetadata; - -import com.google.common.collect.ImmutableSet; -import com.google.inject.Module; - -/** - * Implementation of {@link ApiMetadata} for the Swift API. - */ -public class SwiftApiMetadata extends BaseHttpApiMetadata { - - @Override - public Builder toBuilder() { - return new Builder().fromApiMetadata(this); - } - - public SwiftApiMetadata() { - this(new Builder()); - } - - protected SwiftApiMetadata(Builder builder) { - super(builder); - } - - public static Properties defaultProperties() { - Properties properties = BaseHttpApiMetadata.defaultProperties(); - properties.setProperty(SERVICE_TYPE, ServiceType.OBJECT_STORE); - properties.setProperty(CREDENTIAL_TYPE, CredentialTypes.PASSWORD_CREDENTIALS); - return properties; - } - - public static class Builder extends BaseHttpApiMetadata.Builder { - - protected Builder() { - id("openstack-swift") - .name("OpenStack Swift Grizzly+ API") - .identityName("${tenantName}:${userName} or ${userName}, if your keystone supports a default tenant") - .credentialName("${password}") - .documentation(URI.create("http://docs.openstack.org/api/openstack-object-storage/1.0/content/ch_object-storage-dev-overview.html")) - .version("1") - .endpointName("Keystone base url ending in /v2.0/") - .defaultEndpoint("http://localhost:5000/v2.0/") - .defaultProperties(SwiftApiMetadata.defaultProperties()) - .view(typeToken(RegionScopedBlobStoreContext.class)) - .defaultModules(ImmutableSet.>builder() - .add(AuthenticationApiModule.class) - .add(KeystoneAuthenticationModule.class) - .add(RegionModule.class) - .add(SwiftTypeAdapters.class) - .add(SwiftHttpApiModule.class) - .add(SwiftBlobStoreContextModule.class) - .add(SignUsingTemporaryUrls.class).build()); - } - - @Override - public SwiftApiMetadata build() { - return new SwiftApiMetadata(this); - } - - @Override - protected Builder self() { - return this; - } - } -} diff --git a/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/TemporaryUrlSigner.java b/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/TemporaryUrlSigner.java deleted file mode 100644 index c6d60300f8..0000000000 --- a/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/TemporaryUrlSigner.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF 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.openstack.swift.v1; - -import static com.google.common.base.Charsets.UTF_8; -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.base.Preconditions.checkState; -import static com.google.common.base.Suppliers.memoizeWithExpiration; -import static com.google.common.base.Throwables.propagate; -import static com.google.common.io.BaseEncoding.base16; -import static java.lang.String.format; -import static java.util.concurrent.TimeUnit.SECONDS; - -import javax.crypto.Mac; -import javax.crypto.spec.SecretKeySpec; - -import org.jclouds.openstack.swift.v1.features.AccountApi; - -import com.google.common.base.Supplier; - -/** - * Use this utility to create temporary urls. - */ -public class TemporaryUrlSigner { - - public static TemporaryUrlSigner checkApiEvery(final AccountApi api, long seconds) { - Supplier keySupplier = memoizeWithExpiration(new TemporaryUrlKeyFromAccount(api), seconds, SECONDS); - return new TemporaryUrlSigner(keySupplier); - } - - private final Supplier keySupplier; - - TemporaryUrlSigner(Supplier keySupplier) { - this.keySupplier = keySupplier; - } - - public String sign(String method, String path, long expirationTimestampSeconds) { - checkNotNull(method, "method"); - checkNotNull(path, "path"); - checkArgument(expirationTimestampSeconds > 0, "expirationTimestamp must be a unix epoch timestamp"); - String hmacBody = format("%s\n%s\n%s", method, expirationTimestampSeconds, path); - return base16().lowerCase().encode(hmacSHA1(hmacBody)); - } - - byte[] hmacSHA1(String data) { - try { - String key = keySupplier.get(); - checkState(key != null, "%s returned a null temporaryUrlKey!", keySupplier); - Mac mac = Mac.getInstance("HmacSHA1"); - mac.init(new SecretKeySpec(key.getBytes(UTF_8), "HmacSHA1")); - return mac.doFinal(data.getBytes(UTF_8)); - } catch (Exception e) { - throw propagate(e); - } - } - - static class TemporaryUrlKeyFromAccount implements Supplier { - private final AccountApi api; - - private TemporaryUrlKeyFromAccount(AccountApi api) { - this.api = checkNotNull(api, "accountApi"); - } - - @Override - public String get() { - return api.get().getTemporaryUrlKey().orNull(); - } - - @Override - public String toString() { - return format("get().getTemporaryUrlKey() using %s", api); - } - } -} diff --git a/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/binders/BindMetadataToHeaders.java b/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/binders/BindMetadataToHeaders.java deleted file mode 100644 index 4dabc68b40..0000000000 --- a/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/binders/BindMetadataToHeaders.java +++ /dev/null @@ -1,141 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF 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.openstack.swift.v1.binders; - -import static org.jclouds.openstack.swift.v1.reference.SwiftHeaders.ACCOUNT_METADATA_PREFIX; -import static org.jclouds.openstack.swift.v1.reference.SwiftHeaders.CONTAINER_METADATA_PREFIX; -import static org.jclouds.openstack.swift.v1.reference.SwiftHeaders.OBJECT_METADATA_PREFIX; - -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; - -import java.util.Map; -import java.util.Map.Entry; - -import org.jclouds.http.HttpRequest; -import org.jclouds.rest.Binder; - -import com.google.common.collect.ImmutableMultimap; -import com.google.common.collect.ImmutableMultimap.Builder; - -/** - * Will lower-case header keys due to a swift implementation to return headers - * in a different case than sent. ex. - * - *

- * >> X-Account-Meta-MyDelete1: foo
- * >> X-Account-Meta-MyDelete2: bar
- * 
- * - * results in: - * - *
- * << X-Account-Meta-Mydelete1: foo
- * << X-Account-Meta-Mydelete2: bar
- * 
- * - *

Note


- * HTTP response headers keys are known to be case-insensitive, but this - * practice of mixing up case will prevent metadata keys such as those in - * Turkish from working. - */ -public class BindMetadataToHeaders implements Binder { - - public static class BindAccountMetadataToHeaders extends BindMetadataToHeaders { - BindAccountMetadataToHeaders() { - super(ACCOUNT_METADATA_PREFIX); - } - } - - public static class BindRemoveAccountMetadataToHeaders extends BindMetadataToHeaders.ForRemoval { - BindRemoveAccountMetadataToHeaders() { - super(ACCOUNT_METADATA_PREFIX); - } - } - - public static class BindContainerMetadataToHeaders extends BindMetadataToHeaders { - BindContainerMetadataToHeaders() { - super(CONTAINER_METADATA_PREFIX); - } - } - - public static class BindRemoveContainerMetadataToHeaders extends BindMetadataToHeaders.ForRemoval { - BindRemoveContainerMetadataToHeaders() { - super(CONTAINER_METADATA_PREFIX); - } - } - - public static class BindObjectMetadataToHeaders extends BindMetadataToHeaders { - BindObjectMetadataToHeaders() { - super(OBJECT_METADATA_PREFIX); - } - } - - public static class BindRemoveObjectMetadataToHeaders extends BindMetadataToHeaders.ForRemoval { - BindRemoveObjectMetadataToHeaders() { - super(OBJECT_METADATA_PREFIX); - } - } - - /** - * @see documentation - */ - public abstract static class ForRemoval extends BindMetadataToHeaders { - ForRemoval(String metadataPrefix) { - super(metadataPrefix); - } - - @Override - protected void putMetadata(Builder headers, String key, String value) { - headers.put(String.format("x-remove%s", key.substring(1)), "ignored"); - } - } - - private final String metadataPrefix; - - public BindMetadataToHeaders(String metadataPrefix) { - this.metadataPrefix = checkNotNull(metadataPrefix, "metadataPrefix"); - } - - @SuppressWarnings("unchecked") - @Override - public R bindToRequest(R request, Object input) { - checkNotNull(request, "request"); - checkArgument(input instanceof Map, "input must be a non-null java.util.Map!"); - Map metadata = Map.class.cast(input); - ImmutableMultimap headers = toHeaders(metadata); - return (R) request.toBuilder().replaceHeaders(headers).build(); - } - - protected void putMetadata(Builder headers, String key, String value) { - headers.put(key, value); - } - - public ImmutableMultimap toHeaders(Map metadata) { - Builder builder = ImmutableMultimap. builder(); - for (Entry keyVal : metadata.entrySet()) { - String keyInLowercase = keyVal.getKey().toLowerCase(); - if (keyVal.getKey().startsWith(metadataPrefix)) { - putMetadata(builder, keyInLowercase, keyVal.getValue()); - } else { - putMetadata(builder, String.format("%s%s", metadataPrefix, keyInLowercase), keyVal.getValue()); - } - } - return builder.build(); - } -} diff --git a/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/binders/SetPayload.java b/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/binders/SetPayload.java deleted file mode 100644 index f24a3adf1f..0000000000 --- a/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/binders/SetPayload.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF 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.openstack.swift.v1.binders; - -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.io.BaseEncoding.base16; -import static com.google.common.net.HttpHeaders.ETAG; -import static com.google.common.net.HttpHeaders.TRANSFER_ENCODING; -import static java.util.concurrent.TimeUnit.MILLISECONDS; -import static org.jclouds.openstack.swift.v1.reference.SwiftHeaders.OBJECT_DELETE_AT; - -import java.util.Date; - -import javax.ws.rs.core.MediaType; - -import org.jclouds.http.HttpRequest; -import org.jclouds.http.HttpRequest.Builder; -import org.jclouds.io.Payload; -import org.jclouds.rest.Binder; - -import com.google.common.hash.HashCode; - -public class SetPayload implements Binder { - - @SuppressWarnings("unchecked") - @Override - public R bindToRequest(R request, Object input) { - Builder builder = request.toBuilder(); - Payload payload = Payload.class.cast(input); - - if (payload.getContentMetadata().getContentType() == null) { - // TODO: use `X-Detect-Content-Type` here. Should be configurable via a property. - payload.getContentMetadata().setContentType(MediaType.APPLICATION_OCTET_STREAM); - } - - Long contentLength = payload.getContentMetadata().getContentLength(); - if (contentLength != null && contentLength >= 0) { - checkArgument(contentLength <= 5l * 1024 * 1024 * 1024, "maximum size for put object is 5GB, %s", - contentLength); - } else { - builder.replaceHeader(TRANSFER_ENCODING, "chunked").build(); - } - - HashCode md5 = payload.getContentMetadata().getContentMD5AsHashCode(); - if (md5 != null) { - // Swift will validate the md5, if placed as an ETag header - builder.replaceHeader(ETAG, base16().lowerCase().encode(md5.asBytes())); - } - - Date expires = payload.getContentMetadata().getExpires(); - if (expires != null) { - builder.addHeader(OBJECT_DELETE_AT, - String.valueOf(MILLISECONDS.toSeconds(expires.getTime()))).build(); - } - - return (R) builder.payload(payload).build(); - } -} diff --git a/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/blobstore/RegionScopedBlobStoreContext.java b/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/blobstore/RegionScopedBlobStoreContext.java deleted file mode 100644 index 439359798e..0000000000 --- a/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/blobstore/RegionScopedBlobStoreContext.java +++ /dev/null @@ -1,193 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF 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.openstack.swift.v1.blobstore; - -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; -import static org.jclouds.Constants.PROPERTY_USER_THREADS; - -import java.util.Set; - -import javax.inject.Inject; -import javax.inject.Named; - -import org.jclouds.Context; -import org.jclouds.blobstore.BlobRequestSigner; -import org.jclouds.blobstore.BlobStore; -import org.jclouds.blobstore.BlobStoreContext; -import org.jclouds.blobstore.attr.ConsistencyModel; -import org.jclouds.internal.BaseView; -import org.jclouds.location.Provider; -import org.jclouds.location.Region; -import org.jclouds.rest.Utils; - -import com.google.common.base.Function; -import com.google.common.base.Supplier; -import com.google.common.reflect.TypeToken; -import com.google.common.util.concurrent.ListeningExecutorService; - -/** - * Implementation of {@link BlobStoreContext} which allows you to employ - * multiple regions. - * - * Example. - * - *
- * ctx = contextBuilder.buildView(RegionScopedBlobStoreContext.class);
- *
- * Set<String> regionIds = ctx.getConfiguredRegions();
- *
- * // isolated to a specific region
- * BlobStore texasBlobStore = ctx.getBlobStore("US-TX");
- * BlobStore virginiaBlobStore = ctx.getBlobStore("US-VA");
- * 
- */ -public class RegionScopedBlobStoreContext extends BaseView implements BlobStoreContext { - - /** - * @return regions supported in this context. - * - * @deprecated Please use {{@link #getConfiguredRegions()} as this method will be removed in jclouds 2.0. - */ - @Deprecated - public Set configuredRegions() { - return getConfiguredRegions(); - } - - /** - * @return regions supported in this context. - */ - public Set getConfiguredRegions() { - return regionIds.get(); - } - - /** - * @param regionId - * valid region id from {@link #getConfiguredRegions()} - * @throws IllegalArgumentException - * if {@code regionId} was invalid. - * - * @deprecated Please use {{@link #getBlobStore(String)} as this method will be removed in jclouds 2.0. - */ - @Deprecated - public BlobStore blobStoreInRegion(String regionId) { - return getBlobStore(regionId); - } - - /** - * @param regionId - * valid region id from {@link #getConfiguredRegions()} - * @throws IllegalArgumentException - * if {@code regionId} was invalid. - */ - public BlobStore getBlobStore(String regionId) { - checkRegionId(regionId); - return blobStore.apply(regionId); - } - - /** - * @param regionId - * valid region id from {@link #getConfiguredRegions()} - * @throws IllegalArgumentException - * if {@code regionId} was invalid. - * - * @deprecated Please use {{@link #getSigner(String)} as this method will be removed in jclouds 2.0. - */ - @Deprecated - public BlobRequestSigner signerInRegion(String regionId) { - return getSigner(regionId); - } - - /** - * @param regionId - * valid region id from {@link #getConfiguredRegions()} - * @throws IllegalArgumentException - * if {@code regionId} was invalid. - */ - public BlobRequestSigner getSigner(String regionId) { - checkRegionId(regionId); - return blobRequestSigner.apply(regionId); - } - - protected void checkRegionId(String regionId) { - checkArgument(getConfiguredRegions().contains(checkNotNull(regionId, "regionId was null")), "region %s not in %s", - regionId, getConfiguredRegions()); - } - - private final Supplier> regionIds; - private final Supplier implicitRegionId; - // factory functions are decoupled so that you can exchange how requests are - // signed or decorate without a class hierarchy dependency - private final Function blobStore; - private final Function blobRequestSigner; - private final Utils utils; - private final ListeningExecutorService executor; - - @Inject - public RegionScopedBlobStoreContext(@Provider Context backend, @Provider TypeToken backendType, - @Region Supplier> regionIds, @Region Supplier implicitRegionId, - Function blobStore, Function blobRequestSigner, Utils utils, - @Named(PROPERTY_USER_THREADS) ListeningExecutorService executor) { - super(backend, backendType); - this.regionIds = checkNotNull(regionIds, "regionIds"); - this.implicitRegionId = checkNotNull(implicitRegionId, "implicitRegionId"); - this.blobStore = checkNotNull(blobStore, "blobStore"); - this.blobRequestSigner = checkNotNull(blobRequestSigner, "blobRequestSigner"); - this.utils = checkNotNull(utils, "utils"); - this.executor = checkNotNull(executor, "executor"); - } - - @Override - public ConsistencyModel getConsistencyModel() { - return ConsistencyModel.EVENTUAL; - } - - @Override - public BlobStore getBlobStore() { - return getBlobStore(implicitRegionId.get()); - } - - @Override - public BlobRequestSigner getSigner() { - return getSigner(implicitRegionId.get()); - } - - @Override - public Utils utils() { - return utils; - } - - @Override - public void close() { - delegate().close(); - } - - public int hashCode() { - return delegate().hashCode(); - } - - @Override - public String toString() { - return delegate().toString(); - } - - @Override - public boolean equals(Object obj) { - return delegate().equals(obj); - } - -} diff --git a/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/blobstore/RegionScopedSwiftBlobStore.java b/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/blobstore/RegionScopedSwiftBlobStore.java deleted file mode 100644 index 4ba6a1e42f..0000000000 --- a/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/blobstore/RegionScopedSwiftBlobStore.java +++ /dev/null @@ -1,312 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF 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.openstack.swift.v1.blobstore; - -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.collect.Iterables.tryFind; -import static com.google.common.collect.Lists.transform; -import static org.jclouds.blobstore.options.ListContainerOptions.Builder.recursive; -import static org.jclouds.location.predicates.LocationPredicates.idEquals; -import static org.jclouds.openstack.swift.v1.options.PutOptions.Builder.metadata; - -import java.util.List; -import java.util.Set; - -import javax.inject.Inject; - -import org.jclouds.blobstore.BlobStore; -import org.jclouds.blobstore.BlobStoreContext; -import org.jclouds.blobstore.domain.Blob; -import org.jclouds.blobstore.domain.BlobBuilder; -import org.jclouds.blobstore.domain.BlobMetadata; -import org.jclouds.blobstore.domain.MutableBlobMetadata; -import org.jclouds.blobstore.domain.PageSet; -import org.jclouds.blobstore.domain.StorageMetadata; -import org.jclouds.blobstore.domain.StorageType; -import org.jclouds.blobstore.domain.internal.BlobBuilderImpl; -import org.jclouds.blobstore.domain.internal.BlobImpl; -import org.jclouds.blobstore.domain.internal.PageSetImpl; -import org.jclouds.blobstore.functions.BlobToHttpGetOptions; -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.ClearListStrategy; -import org.jclouds.collect.Memoized; -import org.jclouds.domain.Location; -import org.jclouds.io.Payload; -import org.jclouds.io.payloads.ByteSourcePayload; -import org.jclouds.openstack.swift.v1.SwiftApi; -import org.jclouds.openstack.swift.v1.blobstore.functions.ToBlobMetadata; -import org.jclouds.openstack.swift.v1.blobstore.functions.ToListContainerOptions; -import org.jclouds.openstack.swift.v1.blobstore.functions.ToResourceMetadata; -import org.jclouds.openstack.swift.v1.domain.Container; -import org.jclouds.openstack.swift.v1.domain.ObjectList; -import org.jclouds.openstack.swift.v1.domain.SwiftObject; -import org.jclouds.openstack.swift.v1.features.ObjectApi; - -import com.google.common.base.Function; -import com.google.common.base.Optional; -import com.google.common.base.Supplier; -import com.google.common.cache.CacheBuilder; -import com.google.common.cache.CacheLoader; -import com.google.common.cache.LoadingCache; -import com.google.common.collect.FluentIterable; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableSet; -import com.google.common.io.ByteSource; -import com.google.inject.AbstractModule; -import com.google.inject.Injector; -import com.google.inject.assistedinject.Assisted; - -public class RegionScopedSwiftBlobStore implements BlobStore { - - @Inject - protected RegionScopedSwiftBlobStore(Injector baseGraph, BlobStoreContext context, SwiftApi api, - @Memoized Supplier> locations, @Assisted String regionId) { - checkNotNull(regionId, "regionId"); - Optional found = tryFind(locations.get(), idEquals(regionId)); - checkArgument(found.isPresent(), "region %s not in %s", regionId, locations.get()); - this.region = found.get(); - this.regionId = regionId; - this.toResourceMetadata = new ToResourceMetadata(found.get()); - this.context = context; - this.api = api; - // until we parameterize ClearListStrategy with a factory - this.clearList = baseGraph.createChildInjector(new AbstractModule() { - @Override - protected void configure() { - bind(BlobStore.class).toInstance(RegionScopedSwiftBlobStore.this); - } - }).getInstance(ClearListStrategy.class); - } - - private final BlobStoreContext context; - private final ClearListStrategy clearList; - private final SwiftApi api; - private final Location region; - private final String regionId; - private final BlobToHttpGetOptions toGetOptions = new BlobToHttpGetOptions(); - private final ToListContainerOptions toListContainerOptions = new ToListContainerOptions(); - private final ToResourceMetadata toResourceMetadata; - - @Override - public Set listAssignableLocations() { - return ImmutableSet.of(region); - } - - @Override - public PageSet list() { - // TODO: there may eventually be >10k containers.. - FluentIterable containers = api.getContainerApiForRegion(regionId).list() - .transform(toResourceMetadata); - return new PageSetImpl(containers, null); - } - - @Override - public boolean containerExists(String container) { - Container val = api.getContainerApiForRegion(regionId).get(container); - containerCache.put(container, Optional.fromNullable(val)); - return val != null; - } - - @Override - public boolean createContainerInLocation(Location location, String container) { - return createContainerInLocation(location, container, CreateContainerOptions.NONE); - } - - @Override - public boolean createContainerInLocation(Location location, String container, CreateContainerOptions options) { - checkArgument(location == null || location.equals(region), "location must be null or %s", region); - if (options.isPublicRead()) { - return api.getContainerApiForRegion(regionId).create(container, ANYBODY_READ); - } - return api.getContainerApiForRegion(regionId).create(container, BASIC_CONTAINER); - } - - private static final org.jclouds.openstack.swift.v1.options.CreateContainerOptions BASIC_CONTAINER = new org.jclouds.openstack.swift.v1.options.CreateContainerOptions(); - private static final org.jclouds.openstack.swift.v1.options.CreateContainerOptions ANYBODY_READ = new org.jclouds.openstack.swift.v1.options.CreateContainerOptions() - .anybodyRead(); - - @Override - public PageSet list(String container) { - return list(container, ListContainerOptions.NONE); - } - - @Override - public PageSet list(final String container, ListContainerOptions options) { - ObjectApi objectApi = api.getObjectApiForRegionAndContainer(regionId, container); - ObjectList objects = objectApi.list(toListContainerOptions.apply(options)); - if (objects == null) { - containerCache.put(container, Optional. absent()); - return new PageSetImpl(ImmutableList. of(), null); - } else { - containerCache.put(container, Optional.of(objects.getContainer())); - List list = transform(objects, toBlobMetadata(container)); - int limit = Optional.fromNullable(options.getMaxResults()).or(10000); - String marker = list.size() == limit ? list.get(limit - 1).getName() : null; - // TODO: we should probably deprecate this option - if (options.isDetailed()) { - list = transform(list, new Function() { - @Override - public StorageMetadata apply(StorageMetadata input) { - if (input.getType() != StorageType.BLOB) { - return input; - } - return blobMetadata(container, input.getName()); - } - }); - } - return new PageSetImpl(list, marker); - } - } - - @Override - public boolean blobExists(String container, String name) { - return blobMetadata(container, name) != null; - } - - @Override - public String putBlob(String container, Blob blob) { - return putBlob(container, blob, PutOptions.NONE); - } - - @Override - public String putBlob(String container, Blob blob, PutOptions options) { - if (options.isMultipart()) { - throw new UnsupportedOperationException(); - } - ObjectApi objectApi = api.getObjectApiForRegionAndContainer(regionId, container); - return objectApi.put(blob.getMetadata().getName(), blob.getPayload(), metadata(blob.getMetadata().getUserMetadata())); - } - - @Override - public BlobMetadata blobMetadata(String container, String name) { - SwiftObject object = api.getObjectApiForRegionAndContainer(regionId, container).get(name); - if (object == null) { - return null; - } - return toBlobMetadata(container).apply(object); - } - - @Override - public Blob getBlob(String container, String key) { - return getBlob(container, key, GetOptions.NONE); - } - - @Override - public Blob getBlob(String container, String name, GetOptions options) { - ObjectApi objectApi = api.getObjectApiForRegionAndContainer(regionId, container); - SwiftObject object = objectApi.get(name, toGetOptions.apply(options)); - if (object == null) { - return null; - } - Blob blob = new BlobImpl(toBlobMetadata(container).apply(object)); - blob.setPayload(object.getPayload()); - blob.setAllHeaders(object.getHeaders()); - return blob; - } - - @Override - public void removeBlob(String container, String name) { - api.getObjectApiForRegionAndContainer(regionId, container).delete(name); - } - - @Override - public BlobStoreContext getContext() { - return context; - } - - @Override - public BlobBuilder blobBuilder(String name) { - return new BlobBuilderImpl().name(name); - } - - @Override - public boolean directoryExists(String containerName, String directory) { - return api.getObjectApiForRegionAndContainer(regionId, containerName) - .get(directory) != null; - } - - @Override - public void createDirectory(String containerName, String directory) { - api.getObjectApiForRegionAndContainer(regionId, containerName) - .put(directory, directoryPayload); - } - - private final Payload directoryPayload = new ByteSourcePayload(ByteSource.wrap(new byte[] {})) { - { - getContentMetadata().setContentType("application/directory"); - } - }; - - @Override - public void deleteDirectory(String containerName, String directory) { - api.getObjectApiForRegionAndContainer(regionId, containerName).delete(directory); - } - - @Override - public long countBlobs(String containerName) { - Container container = api.getContainerApiForRegion(regionId).get(containerName); - // undefined if container doesn't exist, so default to zero - return container != null ? container.getObjectCount() : 0; - } - - @Override - public void clearContainer(String containerName) { - clearContainer(containerName, recursive()); - } - - @Override - public void clearContainer(String containerName, ListContainerOptions options) { - // this could be implemented to use bulk delete - clearList.execute(containerName, options); - } - - @Override - public void deleteContainer(String container) { - clearContainer(container, recursive()); - api.getContainerApiForRegion(regionId).deleteIfEmpty(container); - containerCache.invalidate(container); - } - - @Override - public boolean deleteContainerIfEmpty(String container) { - boolean deleted = api.getContainerApiForRegion(regionId).deleteIfEmpty(container); - if (deleted) { - containerCache.invalidate(container); - } - return deleted; - } - - protected final LoadingCache> containerCache = CacheBuilder.newBuilder().build( - new CacheLoader>() { - public Optional load(String container) { - return Optional.fromNullable(api.getContainerApiForRegion(regionId).get(container)); - } - }); - - protected Function toBlobMetadata(String container) { - return new ToBlobMetadata(containerCache.getUnchecked(container).get()); - } - - @Override - public long countBlobs(String containerName, ListContainerOptions options) { - throw new UnsupportedOperationException(); - } -} diff --git a/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/blobstore/RegionScopedTemporaryUrlBlobSigner.java b/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/blobstore/RegionScopedTemporaryUrlBlobSigner.java deleted file mode 100644 index 41ae522fd2..0000000000 --- a/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/blobstore/RegionScopedTemporaryUrlBlobSigner.java +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF 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.openstack.swift.v1.blobstore; - -import static com.google.common.base.Preconditions.checkNotNull; -import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL; - -import java.net.URI; -import java.util.Map; -import java.util.concurrent.TimeUnit; - -import javax.inject.Provider; - -import org.jclouds.blobstore.BlobRequestSigner; -import org.jclouds.blobstore.domain.Blob; -import org.jclouds.blobstore.functions.BlobToHttpGetOptions; -import org.jclouds.date.TimeStamp; -import org.jclouds.http.HttpRequest; -import org.jclouds.http.Uris; -import org.jclouds.http.options.GetOptions; -import org.jclouds.location.Region; -import org.jclouds.openstack.swift.v1.SwiftApi; -import org.jclouds.openstack.swift.v1.TemporaryUrlSigner; - -import com.google.common.base.Supplier; -import com.google.inject.Inject; -import com.google.inject.assistedinject.Assisted; -import com.google.inject.name.Named; - -/** - * Uses {@link TemporaryUrlSigner} to sign requests for access to blobs. If no - * interval is supplied, it defaults to a year. - */ -public class RegionScopedTemporaryUrlBlobSigner implements BlobRequestSigner { - - @Inject - protected RegionScopedTemporaryUrlBlobSigner(@Region Supplier>> regionToUris, - @Named(PROPERTY_SESSION_INTERVAL) long seconds, @TimeStamp Provider timestamp, SwiftApi api, - @Assisted String regionId) { - checkNotNull(regionId, "regionId"); - this.timestamp = timestamp; - this.signer = TemporaryUrlSigner.checkApiEvery(api.getAccountApiForRegion(regionId), seconds); - this.storageUrl = regionToUris.get().get(regionId).get(); - } - - private static final long YEAR = TimeUnit.DAYS.toSeconds(365); - private final BlobToHttpGetOptions toGetOptions = new BlobToHttpGetOptions(); - private final Provider timestamp; - private final TemporaryUrlSigner signer; - private final URI storageUrl; - - @Override - public HttpRequest signGetBlob(String container, String name) { - return signGetBlob(container, name, YEAR); - } - - @Override - public HttpRequest signGetBlob(String container, String name, long timeInSeconds) { - return sign("GET", container, name, GetOptions.NONE, timestamp.get() + timeInSeconds); - } - - @Override - public HttpRequest signGetBlob(String container, String name, org.jclouds.blobstore.options.GetOptions options) { - return sign("GET", container, name, toGetOptions.apply(options), timestamp.get() + YEAR); - } - - @Override - public HttpRequest signPutBlob(String container, Blob blob) { - return signPutBlob(container, blob, YEAR); - } - - @Override - public HttpRequest signPutBlob(String container, Blob blob, long timeInSeconds) { - return sign("PUT", container, blob.getMetadata().getName(), GetOptions.NONE, timestamp.get() + timeInSeconds); - } - - @Override - public HttpRequest signRemoveBlob(String container, String name) { - return sign("DELETE", container, name, GetOptions.NONE, timestamp.get() + YEAR); - } - - private HttpRequest sign(String method, String container, String name, GetOptions options, long expires) { - checkNotNull(container, "container"); - checkNotNull(name, "name"); - URI url = Uris.uriBuilder(storageUrl).appendPath(container).appendPath(name).build(); - String signature = signer.sign(method, url.getPath(), expires); - return HttpRequest.builder() - .method(method) - .endpoint(url) - .addQueryParams(options.buildQueryParameters()) - .addQueryParam("temp_url_sig", signature) - .addQueryParam("temp_url_expires", String.valueOf(expires)) - .headers(options.buildRequestHeaders()).build(); - } -} diff --git a/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/blobstore/config/SignUsingTemporaryUrls.java b/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/blobstore/config/SignUsingTemporaryUrls.java deleted file mode 100644 index 43a876da4e..0000000000 --- a/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/blobstore/config/SignUsingTemporaryUrls.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF 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.openstack.swift.v1.blobstore.config; - -import javax.inject.Inject; - -import org.jclouds.blobstore.BlobRequestSigner; -import org.jclouds.date.TimeStamp; -import org.jclouds.openstack.swift.v1.blobstore.RegionScopedTemporaryUrlBlobSigner; - -import com.google.common.base.Function; -import com.google.common.collect.ForwardingObject; -import com.google.inject.AbstractModule; -import com.google.inject.Provides; -import com.google.inject.assistedinject.FactoryModuleBuilder; - -public class SignUsingTemporaryUrls extends AbstractModule { - - @Override - protected void configure() { - install(new FactoryModuleBuilder().build(Factory.class)); - } - - interface Factory { - RegionScopedTemporaryUrlBlobSigner create(String in); - } - - @Provides - Function blobRequestSigner(FactoryFunction in) { - return in; - } - - static class FactoryFunction extends ForwardingObject implements Function { - @Inject - Factory delegate; - - @Override - protected Factory delegate() { - return delegate; - } - - @Override - public BlobRequestSigner apply(String in) { - return delegate.create(in); - } - } - - @Provides - @TimeStamp - protected Long unixEpochTimestamp() { - return System.currentTimeMillis() / 1000; - } -} diff --git a/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/blobstore/config/SwiftBlobStoreContextModule.java b/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/blobstore/config/SwiftBlobStoreContextModule.java deleted file mode 100644 index 614b1e506c..0000000000 --- a/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/blobstore/config/SwiftBlobStoreContextModule.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF 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.openstack.swift.v1.blobstore.config; - -import javax.inject.Inject; - -import org.jclouds.blobstore.BlobStore; -import org.jclouds.blobstore.BlobStoreContext; -import org.jclouds.openstack.swift.v1.blobstore.RegionScopedBlobStoreContext; -import org.jclouds.openstack.swift.v1.blobstore.RegionScopedSwiftBlobStore; - -import com.google.common.base.Function; -import com.google.common.collect.ForwardingObject; -import com.google.inject.AbstractModule; -import com.google.inject.Provides; -import com.google.inject.assistedinject.FactoryModuleBuilder; - -public class SwiftBlobStoreContextModule extends AbstractModule { - - @Override - protected void configure() { - bind(BlobStoreContext.class).to(RegionScopedBlobStoreContext.class); - install(new FactoryModuleBuilder().build(Factory.class)); - } - - interface Factory { - RegionScopedSwiftBlobStore create(String in); - } - - @Provides - Function blobStore(FactoryFunction in) { - return in; - } - - static class FactoryFunction extends ForwardingObject implements Function { - @Inject - Factory delegate; - - @Override - protected Factory delegate() { - return delegate; - } - - @Override - public BlobStore apply(String in) { - return delegate.create(in); - } - } -} diff --git a/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/blobstore/functions/ToBlobMetadata.java b/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/blobstore/functions/ToBlobMetadata.java deleted file mode 100644 index 6a1b8c5de1..0000000000 --- a/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/blobstore/functions/ToBlobMetadata.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF 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.openstack.swift.v1.blobstore.functions; - -import static com.google.common.base.Preconditions.checkNotNull; - -import org.jclouds.blobstore.domain.MutableBlobMetadata; -import org.jclouds.blobstore.domain.StorageType; -import org.jclouds.blobstore.domain.internal.MutableBlobMetadataImpl; -import org.jclouds.blobstore.strategy.IfDirectoryReturnNameStrategy; -import org.jclouds.blobstore.strategy.internal.MarkersIfDirectoryReturnNameStrategy; -import org.jclouds.openstack.swift.v1.domain.Container; -import org.jclouds.openstack.swift.v1.domain.SwiftObject; - -import com.google.common.base.Function; - -public class ToBlobMetadata implements Function { - - private final IfDirectoryReturnNameStrategy ifDirectoryReturnName = new MarkersIfDirectoryReturnNameStrategy(); - private final Container container; - - public ToBlobMetadata(Container container) { - this.container = checkNotNull(container, "container"); - } - - @Override - public MutableBlobMetadata apply(SwiftObject from) { - if (from == null) - return null; - MutableBlobMetadata to = new MutableBlobMetadataImpl(); - to.setContainer(container.getName()); - if (container.getAnybodyRead().isPresent()) { - to.setPublicUri(from.getUri()); - } - to.setUri(from.getUri()); - to.setETag(from.getETag()); - to.setName(from.getName()); - to.setLastModified(from.getLastModified()); - to.setContentMetadata(from.getPayload().getContentMetadata()); - to.getContentMetadata().setContentMD5(from.getPayload().getContentMetadata().getContentMD5AsHashCode()); - to.getContentMetadata().setExpires(from.getPayload().getContentMetadata().getExpires()); - to.setUserMetadata(from.getMetadata()); - String directoryName = ifDirectoryReturnName.execute(to); - if (directoryName != null) { - to.setName(directoryName); - to.setType(StorageType.RELATIVE_PATH); - } else { - to.setType(StorageType.BLOB); - } - return to; - } - - @Override - public String toString() { - return "ObjectToBlobMetadata(" + container + ")"; - } -} diff --git a/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/blobstore/functions/ToListContainerOptions.java b/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/blobstore/functions/ToListContainerOptions.java deleted file mode 100644 index 2650f5b389..0000000000 --- a/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/blobstore/functions/ToListContainerOptions.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF 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.openstack.swift.v1.blobstore.functions; - -import static com.google.common.base.Preconditions.checkNotNull; - -import org.jclouds.blobstore.options.ListContainerOptions; - -import com.google.common.base.Function; - -public class ToListContainerOptions implements - Function { - - @Override - public org.jclouds.openstack.swift.v1.options.ListContainerOptions apply(ListContainerOptions from) { - checkNotNull(from, "set options to instance NONE instead of passing null"); - org.jclouds.openstack.swift.v1.options.ListContainerOptions options = new org.jclouds.openstack.swift.v1.options.ListContainerOptions(); - if ((from.getDir() == null) && (from.isRecursive())) { - options.prefix(""); - } - if ((from.getDir() == null) && (!from.isRecursive())) { - options.path(""); - } - if ((from.getDir() != null) && (from.isRecursive())) { - options.prefix(from.getDir().endsWith("/") ? from.getDir() : from.getDir() + "/"); - } - if ((from.getDir() != null) && (!from.isRecursive())) { - options.path(from.getDir()); - } - if (from.getMarker() != null) { - options.marker(from.getMarker()); - } - if (from.getMaxResults() != null) { - options.limit(from.getMaxResults()); - } - return options; - } -} diff --git a/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/blobstore/functions/ToResourceMetadata.java b/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/blobstore/functions/ToResourceMetadata.java deleted file mode 100644 index bc5e1868c6..0000000000 --- a/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/blobstore/functions/ToResourceMetadata.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF 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.openstack.swift.v1.blobstore.functions; - -import org.jclouds.blobstore.domain.MutableStorageMetadata; -import org.jclouds.blobstore.domain.StorageMetadata; -import org.jclouds.blobstore.domain.StorageType; -import org.jclouds.blobstore.domain.internal.MutableStorageMetadataImpl; -import org.jclouds.domain.Location; -import org.jclouds.openstack.swift.v1.domain.Container; - -import com.google.common.base.Function; - -public class ToResourceMetadata implements Function { - private Location region; - - public ToResourceMetadata(Location region) { - this.region = region; - } - - @Override - public StorageMetadata apply(Container from) { - MutableStorageMetadata to = new MutableStorageMetadataImpl(); - to.setName(from.getName()); - to.setLocation(region); - to.setType(StorageType.CONTAINER); - to.setUserMetadata(from.getMetadata()); - return to; - } -} diff --git a/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/config/BaseSwiftHttpApiModule.java b/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/config/BaseSwiftHttpApiModule.java deleted file mode 100644 index d6d8b6a243..0000000000 --- a/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/config/BaseSwiftHttpApiModule.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF 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.openstack.swift.v1.config; - -import org.jclouds.http.HttpErrorHandler; -import org.jclouds.http.annotation.ClientError; -import org.jclouds.http.annotation.Redirection; -import org.jclouds.http.annotation.ServerError; -import org.jclouds.openstack.swift.v1.SwiftApi; -import org.jclouds.openstack.swift.v1.handlers.SwiftErrorHandler; -import org.jclouds.rest.ConfiguresHttpApi; -import org.jclouds.rest.config.HttpApiModule; - -@ConfiguresHttpApi -public abstract class BaseSwiftHttpApiModule extends HttpApiModule { - - protected BaseSwiftHttpApiModule(Class api) { - super(api); - } - - @Override - protected void configure() { - super.configure(); - } - - @Override - protected void bindErrorHandlers() { - bind(HttpErrorHandler.class).annotatedWith(Redirection.class).to(SwiftErrorHandler.class); - bind(HttpErrorHandler.class).annotatedWith(ClientError.class).to(SwiftErrorHandler.class); - bind(HttpErrorHandler.class).annotatedWith(ServerError.class).to(SwiftErrorHandler.class); - } -} diff --git a/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/config/SwiftHttpApiModule.java b/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/config/SwiftHttpApiModule.java deleted file mode 100644 index cb93760588..0000000000 --- a/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/config/SwiftHttpApiModule.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF 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.openstack.swift.v1.config; -import org.jclouds.openstack.swift.v1.SwiftApi; -import org.jclouds.rest.ConfiguresHttpApi; - -@ConfiguresHttpApi -public class SwiftHttpApiModule extends BaseSwiftHttpApiModule { - - public SwiftHttpApiModule() { - super(SwiftApi.class); - } - - @Override - protected void configure() { - super.configure(); - } -} diff --git a/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/config/SwiftTypeAdapters.java b/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/config/SwiftTypeAdapters.java deleted file mode 100644 index 4eafdb697c..0000000000 --- a/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/config/SwiftTypeAdapters.java +++ /dev/null @@ -1,119 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF 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.openstack.swift.v1.config; - -import java.io.IOException; -import java.lang.reflect.Type; -import java.net.URI; -import java.util.Map; - -import org.jclouds.json.config.GsonModule.DateAdapter; -import org.jclouds.json.config.GsonModule.Iso8601DateAdapter; -import org.jclouds.openstack.swift.v1.domain.BulkDeleteResponse; -import org.jclouds.openstack.swift.v1.domain.ExtractArchiveResponse; - -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableMap.Builder; -import com.google.gson.TypeAdapter; -import com.google.gson.stream.JsonReader; -import com.google.gson.stream.JsonWriter; -import com.google.inject.AbstractModule; -import com.google.inject.Provides; - -public class SwiftTypeAdapters extends AbstractModule { - - @Override - protected void configure() { - bind(DateAdapter.class).to(Iso8601DateAdapter.class); - } - - @Provides - public Map provideCustomAdapterBindings() { - return ImmutableMap. builder() - .put(ExtractArchiveResponse.class, new ExtractArchiveResponseAdapter()) - .put(BulkDeleteResponse.class, new BulkDeleteResponseAdapter()).build(); - } - - static class ExtractArchiveResponseAdapter extends TypeAdapter { - - @Override - public ExtractArchiveResponse read(JsonReader reader) throws IOException { - int created = 0; - Builder errors = ImmutableMap. builder(); - reader.beginObject(); - while (reader.hasNext()) { - String key = reader.nextName(); - if (key.equals("Number Files Created")) { - created = reader.nextInt(); - } else if (key.equals("Errors")) { - readErrors(reader, errors); - } else { - reader.skipValue(); - } - } - reader.endObject(); - return ExtractArchiveResponse.create(created, errors.build()); - } - - @Override - public void write(JsonWriter arg0, ExtractArchiveResponse arg1) throws IOException { - throw new UnsupportedOperationException(); - } - } - - static class BulkDeleteResponseAdapter extends TypeAdapter { - - @Override - public BulkDeleteResponse read(JsonReader reader) throws IOException { - int deleted = 0; - int notFound = 0; - Builder errors = ImmutableMap. builder(); - reader.beginObject(); - while (reader.hasNext()) { - String key = reader.nextName(); - if (key.equals("Number Deleted")) { - deleted = reader.nextInt(); - } else if (key.equals("Number Not Found")) { - notFound = reader.nextInt(); - } else if (key.equals("Errors")) { - readErrors(reader, errors); - } else { - reader.skipValue(); - } - } - reader.endObject(); - return BulkDeleteResponse.create(deleted, notFound, errors.build()); - } - - @Override - public void write(JsonWriter arg0, BulkDeleteResponse arg1) throws IOException { - throw new UnsupportedOperationException(); - } - } - - static void readErrors(JsonReader reader, Builder errors) throws IOException { - reader.beginArray(); - while (reader.hasNext()) { - reader.beginArray(); - String decodedPath = URI.create(reader.nextString()).getPath(); - errors.put(decodedPath, reader.nextString()); - reader.endArray(); - } - reader.endArray(); - } - -} diff --git a/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/domain/Account.java b/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/domain/Account.java deleted file mode 100644 index 34b63bc688..0000000000 --- a/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/domain/Account.java +++ /dev/null @@ -1,219 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF 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.openstack.swift.v1.domain; - -import static com.google.common.base.Objects.equal; -import static com.google.common.base.Objects.toStringHelper; -import static com.google.common.base.Preconditions.checkNotNull; - -import java.util.Map; -import java.util.Map.Entry; - -import com.google.common.base.Objects; -import com.google.common.base.Objects.ToStringHelper; -import com.google.common.base.Optional; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableMultimap; -import com.google.common.collect.Multimap; - -/** - * Represents an Account in OpenStack Object Storage. - * - * @see org.jclouds.openstack.swift.v1.features.AccountApi - */ -public class Account { - - private final long containerCount; - private final long objectCount; - private final long bytesUsed; - private final Map metadata; - private final Multimap headers; - - // parsed from headers, so ConstructorProperties here would be misleading - protected Account(long containerCount, long objectCount, long bytesUsed, Map metadata, - Multimap headers) { - this.containerCount = containerCount; - this.objectCount = objectCount; - this.bytesUsed = bytesUsed; - this.metadata = metadata == null ? ImmutableMap. of() : metadata; - this.headers = headers == null ? ImmutableMultimap. of() : headers; - } - - /** - * @return The count of containers for this account. - */ - public long getContainerCount() { - return containerCount; - } - - /** - * @return The count of objects for this account. - */ - public long getObjectCount() { - return objectCount; - } - - /** - * @return The number of bytes used by this account. - */ - public long getBytesUsed() { - return bytesUsed; - } - - /** - * @return The {@link Optional<String>} temporary URL key for this account. - */ - public Optional getTemporaryUrlKey() { - return Optional.fromNullable(metadata.get("temp-url-key")); - } - - /** - *

NOTE

- * In current swift implementations, headers keys are lower-cased. This means - * characters such as turkish will probably not work out well. - * - * @return a {@code Map} containing the account metadata. - */ - public Map getMetadata() { - return metadata; - } - - /** - * @return The HTTP headers for this account. - */ - public Multimap getHeaders() { - return headers; - } - - @Override - public boolean equals(Object object) { - if (this == object) { - return true; - } - if (object instanceof Account) { - Account that = Account.class.cast(object); - return equal(getContainerCount(), that.getContainerCount()) - && equal(getObjectCount(), that.getObjectCount()) - && equal(getBytesUsed(), that.getBytesUsed()) - && equal(getMetadata(), that.getMetadata()); - } else { - return false; - } - } - - @Override - public int hashCode() { - return Objects.hashCode(getContainerCount(), getObjectCount(), getBytesUsed(), getMetadata()); - } - - @Override - public String toString() { - return string().toString(); - } - - protected ToStringHelper string() { - return toStringHelper(this) - .add("containerCount", getContainerCount()) - .add("objectCount", getObjectCount()) - .add("bytesUsed", getBytesUsed()) - .add("metadata", getMetadata()); - } - - public static Builder builder() { - return new Builder(); - } - - public Builder toBuilder() { - return builder().fromAccount(this); - } - - public static class Builder { - protected long containerCount; - protected long objectCount; - protected long bytesUsed; - protected Multimap headers = ImmutableMultimap.of(); - protected Map metadata = ImmutableMap.of(); - - /** - * @param containerCount the count of containers for this account. - * - * @see Account#getContainerCount() - */ - public Builder containerCount(long containerCount) { - this.containerCount = containerCount; - return this; - } - - /** - * @param objectCount the count of objects for this account. - * - * @see Account#getObjectCount() - */ - public Builder objectCount(long objectCount) { - this.objectCount = objectCount; - return this; - } - - /** - * @param bytesUsed the number of bytes used by this account. - * - * @see Account#getBytesUsed() - */ - public Builder bytesUsed(long bytesUsed) { - this.bytesUsed = bytesUsed; - return this; - } - - /** - *

NOTE

- * This method will lower-case all metadata keys due to a Swift implementation - * decision. - * - * @param metadata the metadata for this account. - * - * @see Account#getMetadata() - */ - public Builder metadata(Map metadata) { - ImmutableMap.Builder builder = ImmutableMap. builder(); - for (Entry entry : checkNotNull(metadata, "metadata").entrySet()) { - builder.put(entry.getKey().toLowerCase(), entry.getValue()); - } - this.metadata = builder.build(); - return this; - } - - /** - * @see Account#getHeaders() - */ - public Builder headers(Multimap headers) { - this.headers = headers; - return this; - } - - public Account build() { - return new Account(containerCount, objectCount, bytesUsed, metadata, headers); - } - - public Builder fromAccount(Account from) { - return containerCount(from.getContainerCount()) - .objectCount(from.getObjectCount()) - .bytesUsed(from.getBytesUsed()) - .metadata(from.getMetadata()) - .headers(from.getHeaders()); - } - } -} diff --git a/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/domain/BulkDeleteResponse.java b/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/domain/BulkDeleteResponse.java deleted file mode 100644 index 9933a1cf15..0000000000 --- a/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/domain/BulkDeleteResponse.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF 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.openstack.swift.v1.domain; - -import static com.google.common.base.Objects.equal; -import static com.google.common.base.Objects.toStringHelper; -import static com.google.common.base.Preconditions.checkNotNull; - -import java.util.Map; - -import com.google.common.base.Objects; -import com.google.common.base.Objects.ToStringHelper; - -/** - * Represents a response from a Bulk Delete request. - * - * @see org.jclouds.openstack.swift.v1.features.BulkApi - */ -public class BulkDeleteResponse { - public static BulkDeleteResponse create(int deleted, int notFound, Map errors) { - return new BulkDeleteResponse(deleted, notFound, errors); - } - - private final int deleted; - private final int notFound; - private final Map errors; - - private BulkDeleteResponse(int deleted, int notFound, Map errors) { - this.deleted = deleted; - this.notFound = notFound; - this.errors = checkNotNull(errors, "errors"); - } - - /** - * @return The number of files deleted. - * */ - public int getDeleted() { - return deleted; - } - - /** - * @return The number of files not found. - */ - public int getNotFound() { - return notFound; - } - - /** - * @return a {@code Map} containing each path that failed - * to be deleted and its corresponding error response. - */ - public Map getErrors() { - return errors; - } - - @Override - public boolean equals(Object object) { - if (this == object) { - return true; - } - if (object instanceof BulkDeleteResponse) { - BulkDeleteResponse that = BulkDeleteResponse.class.cast(object); - return equal(getDeleted(), that.getDeleted()) - && equal(getNotFound(), that.getNotFound()) - && equal(getErrors(), that.getErrors()); - } else { - return false; - } - } - - @Override - public int hashCode() { - return Objects.hashCode(getDeleted(), getNotFound(), getErrors()); - } - - protected ToStringHelper string() { - return toStringHelper(this) - .add("deleted", getDeleted()) - .add("notFound", getNotFound()) - .add("errors", getErrors()); - } - - @Override - public String toString() { - return string().toString(); - } -} diff --git a/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/domain/Container.java b/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/domain/Container.java deleted file mode 100644 index cc671dee8b..0000000000 --- a/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/domain/Container.java +++ /dev/null @@ -1,237 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF 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.openstack.swift.v1.domain; - -import static com.google.common.base.Objects.equal; -import static com.google.common.base.Objects.toStringHelper; -import static com.google.common.base.Preconditions.checkNotNull; - -import java.beans.ConstructorProperties; -import java.util.Map; -import java.util.Map.Entry; - -import com.google.common.base.Objects; -import com.google.common.base.Objects.ToStringHelper; -import com.google.common.base.Optional; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableMultimap; -import com.google.common.collect.Multimap; - -/** - * Represents a Container in OpenStack Object Storage. - * - * @see org.jclouds.openstack.swift.v1.features.ContainerApi - */ -public class Container implements Comparable { - - private final String name; - private final long objectCount; - private final long bytesUsed; - private final Optional anybodyRead; - private final Map metadata; - private final Multimap headers; - - @ConstructorProperties({ "name", "count", "bytes", "anybodyRead", "metadata", "headers"}) - protected Container(String name, long objectCount, long bytesUsed, Optional anybodyRead, - Map metadata, Multimap headers) { - this.name = checkNotNull(name, "name"); - this.objectCount = objectCount; - this.bytesUsed = bytesUsed; - this.anybodyRead = anybodyRead == null ? Optional. absent() : anybodyRead; - this.metadata = metadata == null ? ImmutableMap. of() : metadata; - this.headers = headers == null ? ImmutableMultimap. of() : headers; - } - - /** - * @return The name of this container. - */ - public String getName() { - return name; - } - - /** - * @return The count of objects for this container. - */ - public long getObjectCount() { - return objectCount; - } - - /** - * @return The number of bytes used by this container. - */ - public long getBytesUsed() { - return bytesUsed; - } - - /** - * Absent except in {@link ContainerApi#get(String) Get Container} commands. - * - * @return true if this container is publicly readable, false otherwise. - * - * @see org.jclouds.openstack.swift.v1.options.CreateContainerOptions#anybodyRead() - */ - public Optional getAnybodyRead() { - return anybodyRead; - } - - /** - *

NOTE

- * In current swift implementations, headers keys are lower-cased. This means - * characters such as turkish will probably not work out well. - * - * @return a {@code Map} containing this container's metadata. - */ - public Map getMetadata() { - return metadata; - } - - /** - * @return The HTTP headers for this account. - */ - public Multimap getHeaders() { - return headers; - } - - @Override - public boolean equals(Object object) { - if (this == object) { - return true; - } - if (object instanceof Container) { - final Container that = Container.class.cast(object); - return equal(getName(), that.getName()) - && equal(getObjectCount(), that.getObjectCount()) - && equal(getBytesUsed(), that.getBytesUsed()) - && equal(getMetadata(), that.getMetadata()); - } else { - return false; - } - } - - @Override - public int hashCode() { - return Objects.hashCode(getName(), getObjectCount(), getBytesUsed(), getAnybodyRead(), getMetadata()); - } - - @Override - public String toString() { - return string().toString(); - } - - protected ToStringHelper string() { - return toStringHelper(this).omitNullValues() - .add("name", getName()) - .add("objectCount", getObjectCount()) - .add("bytesUsed", getBytesUsed()) - .add("anybodyRead", getAnybodyRead().orNull()) - .add("metadata", getMetadata()); - } - - @Override - public int compareTo(Container that) { - if (that == null) - return 1; - if (this == that) - return 0; - return this.getName().compareTo(that.getName()); - } - - public static Builder builder() { - return new Builder(); - } - - public Builder toBuilder() { - return builder().fromContainer(this); - } - - public static class Builder { - protected String name; - protected long objectCount; - protected long bytesUsed; - protected Optional anybodyRead = Optional.absent(); - protected Map metadata = ImmutableMap.of(); - protected Multimap headers = ImmutableMultimap.of(); - - /** - * @see Container#getName() - */ - public Builder name(String name) { - this.name = checkNotNull(name, "name"); - return this; - } - - /** - * @see Container#getObjectCount() - */ - public Builder objectCount(long objectCount) { - this.objectCount = objectCount; - return this; - } - - /** - * @see Container#getBytesUsed() - */ - public Builder bytesUsed(long bytesUsed) { - this.bytesUsed = bytesUsed; - return this; - } - - /** - * @see Container#getAnybodyRead() - */ - public Builder anybodyRead(Boolean anybodyRead) { - this.anybodyRead = Optional.fromNullable(anybodyRead); - return this; - } - - /** - *

NOTE

- * This method will lower-case all metadata keys. - * - * @see Container#getMetadata() - */ - public Builder metadata(Map metadata) { - ImmutableMap.Builder builder = ImmutableMap. builder(); - for (Entry entry : checkNotNull(metadata, "metadata").entrySet()) { - builder.put(entry.getKey().toLowerCase(), entry.getValue()); - } - this.metadata = builder.build(); - return this; - } - - /** - * @see Container#getHeaders() - */ - public Builder headers(Multimap headers) { - this.headers = headers; - return this; - } - - public Container build() { - return new Container(name, objectCount, bytesUsed, anybodyRead, metadata, headers); - } - - public Builder fromContainer(Container from) { - return name(from.getName()) - .objectCount(from.getObjectCount()) - .bytesUsed(from.getBytesUsed()) - .anybodyRead(from.getAnybodyRead().orNull()) - .metadata(from.getMetadata()) - .headers(from.getHeaders()); - } - } -} diff --git a/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/domain/ExtractArchiveResponse.java b/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/domain/ExtractArchiveResponse.java deleted file mode 100644 index e569cf448b..0000000000 --- a/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/domain/ExtractArchiveResponse.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF 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.openstack.swift.v1.domain; - -import static com.google.common.base.Objects.equal; -import static com.google.common.base.Objects.toStringHelper; -import static com.google.common.base.Preconditions.checkNotNull; - -import java.util.Map; - -import com.google.common.base.Objects; -import com.google.common.base.Objects.ToStringHelper; - -/** - * Represents a response from an Extract Archive request. - * - * @see org.jclouds.openstack.swift.v1.features.BulkApi - */ -public class ExtractArchiveResponse { - public static ExtractArchiveResponse create(int created, Map errors) { - return new ExtractArchiveResponse(created, errors); - } - - private final int created; - private final Map errors; - - private ExtractArchiveResponse(int created, Map errors) { - this.created = created; - this.errors = checkNotNull(errors, "errors"); - } - - /** - * @return The number of files created. - */ - public int getCreated() { - return created; - } - - /** - * @return a {@code Map} containing each path that failed - * to be created and its corresponding error response. - */ - public Map getErrors() { - return errors; - } - - @Override - public boolean equals(Object object) { - if (this == object) { - return true; - } - if (object instanceof ExtractArchiveResponse) { - ExtractArchiveResponse that = ExtractArchiveResponse.class.cast(object); - return equal(getCreated(), that.getCreated()) - && equal(getErrors(), that.getErrors()); - } else { - return false; - } - } - - @Override - public int hashCode() { - return Objects.hashCode(getCreated(), getErrors()); - } - - protected ToStringHelper string() { - return toStringHelper(this) - .add("created", getCreated()) - .add("errors", getErrors()); - } - - @Override - public String toString() { - return string().toString(); - } -} diff --git a/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/domain/ObjectList.java b/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/domain/ObjectList.java deleted file mode 100644 index 5bc3136fb5..0000000000 --- a/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/domain/ObjectList.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF 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.openstack.swift.v1.domain; - -import static com.google.common.base.Preconditions.checkNotNull; - -import java.util.List; - -import com.google.common.collect.ForwardingList; - -/** - * Represents a list of objects in a container. - * - * @see Container - * @see SwiftObject - * @see org.jclouds.openstack.swift.v1.features.ObjectApi#list() - */ -public class ObjectList extends ForwardingList { - - public static ObjectList create(List objects, Container container) { - return new ObjectList(objects, container); - } - - private final List objects; - private final Container container; - - protected ObjectList(List objects, Container container) { - this.objects = checkNotNull(objects, "objects"); - this.container = checkNotNull(container, "container"); - } - - /** - * @return the parent {@link Container} the objects reside in. - */ - public Container getContainer() { - return container; - } - - @Override - protected List delegate() { - return objects; - } -} diff --git a/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/domain/Segment.java b/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/domain/Segment.java deleted file mode 100644 index ee4bc5825e..0000000000 --- a/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/domain/Segment.java +++ /dev/null @@ -1,145 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF 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.openstack.swift.v1.domain; - -import static com.google.common.base.Objects.equal; -import static com.google.common.base.Objects.toStringHelper; -import static com.google.common.base.Preconditions.checkNotNull; - -import javax.inject.Named; - -import com.google.common.base.Objects; -import com.google.common.base.Objects.ToStringHelper; - -/** - * Represents a single segment of a multi-part upload. - * - * @see org.jclouds.openstack.swift.v1.features.StaticLargeObjectApi - */ -public class Segment { - - private final String path; - private final String etag; - @Named("size_bytes") - private final long sizeBytes; - - private Segment(String path, String etag, long sizeBytes) { - this.path = checkNotNull(path, "path"); - this.etag = checkNotNull(etag, "etag of %s", path); - this.sizeBytes = checkNotNull(sizeBytes, "sizeBytes of %s", path); - } - - /** - * @return The container and object name in the format: {@code /} - */ - public String getPath() { - return path; - } - - /** - * @return The ETag of the content of the segment object. - * @deprecated Please use {@link #getETag()} as this method will be removed in jclouds 1.8. - */ - @Deprecated - public String getEtag() { - return etag; - } - - /** - * @return The ETag of the content of the segment object. - */ - public String getETag() { - return etag; - } - - /** - * @return The size of the segment object. - */ - public long getSizeBytes() { - return sizeBytes; - } - - @Override - public boolean equals(Object object) { - if (this == object) { - return true; - } - if (object instanceof Segment) { - Segment that = Segment.class.cast(object); - return equal(getPath(), that.getPath()) - && equal(getETag(), that.getETag()) - && equal(getSizeBytes(), that.getSizeBytes()); - } else { - return false; - } - } - - @Override - public int hashCode() { - return Objects.hashCode(getPath(), getETag(), getSizeBytes()); - } - - @Override - public String toString() { - return string().toString(); - } - - protected ToStringHelper string() { - return toStringHelper(this) - .add("path", getPath()) - .add("etag", getETag()) - .add("sizeBytes", getSizeBytes()); - } - - public static Builder builder() { - return new Builder(); - } - - public static class Builder { - protected String path; - protected String etag; - protected long sizeBytes; - - /** - * @see Segment#getPath() - */ - public Builder path(String path) { - this.path = path; - return this; - } - - /** - * @see Segment#getEtag() - */ - public Builder etag(String etag) { - this.etag = etag; - return this; - } - - /** - * @see Segment#getSizeBytes() - */ - public Builder sizeBytes(long sizeBytes) { - this.sizeBytes = sizeBytes; - return this; - } - - public Segment build() { - return new Segment(path, etag, sizeBytes); - } - } -} diff --git a/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/domain/SwiftObject.java b/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/domain/SwiftObject.java deleted file mode 100644 index 375f89a967..0000000000 --- a/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/domain/SwiftObject.java +++ /dev/null @@ -1,267 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF 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.openstack.swift.v1.domain; - -import static com.google.common.base.Objects.equal; -import static com.google.common.base.Objects.toStringHelper; -import static com.google.common.base.Preconditions.checkNotNull; - -import java.net.URI; -import java.util.Date; -import java.util.Map; -import java.util.Map.Entry; - -import org.jclouds.io.Payload; - -import com.google.common.base.Objects; -import com.google.common.base.Objects.ToStringHelper; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableMultimap; -import com.google.common.collect.Multimap; - -/** - * Represents an object in OpenStack Object Storage. - * - * - * @see ObjectApi - */ -public class SwiftObject implements Comparable { - - private final String name; - private final URI uri; - private final String etag; - private final Date lastModified; - private final Multimap headers; - private final Map metadata; - private final Payload payload; - - protected SwiftObject(String name, URI uri, String etag, Date lastModified, - Multimap headers, Map metadata, Payload payload) { - this.name = checkNotNull(name, "name"); - this.uri = checkNotNull(uri, "uri of %s", uri); - this.etag = checkNotNull(etag, "etag of %s", name).replace("\"", ""); - this.lastModified = checkNotNull(lastModified, "lastModified of %s", name); - this.headers = headers == null ? ImmutableMultimap. of() : checkNotNull(headers, "headers of %s", name); - this.metadata = metadata == null ? ImmutableMap. of() : metadata; - this.payload = checkNotNull(payload, "payload of %s", name); - } - - /** - * @return The name of this object. - */ - public String getName() { - return name; - } - - /** - * @return The {@link URI} for this object. - */ - public URI getUri() { - return uri; - } - - /** - * @return The ETag of the content of this object. - * @deprecated Please use {@link #getETag()} as this method will be removed in jclouds 1.8. - */ - public String getEtag() { - return etag; - } - - /** - * @return The ETag of the content of this object. - */ - public String getETag() { - return etag; - } - - /** - * @return The {@link Date} that this object was last modified. - */ - public Date getLastModified() { - return lastModified; - } - - /** - * @return The HTTP headers for this object. - */ - public Multimap getHeaders() { - return headers; - } - - /** - *

NOTE

- * In current swift implementations, headers keys are lower-cased. This means - * characters such as turkish will probably not work out well. - * - * @return a {@code Map} containing this object's metadata. The map is empty - * except in {@link ObjectApi#head(String) GetObjectMetadata} or - * {@link ObjectApi#get(String) GetObject} commands. - */ - public Map getMetadata() { - return metadata; - } - - /** - *

NOTE

- * The object will only have a {@link Payload#getInput()} when retrieved via the - * {@link ObjectApi#get(String) GetObject} command. - * - * @return The {@link Payload} for this object. - */ - public Payload getPayload() { - return payload; - } - - @Override - public boolean equals(Object object) { - if (this == object) { - return true; - } - if (object instanceof SwiftObject) { - final SwiftObject that = SwiftObject.class.cast(object); - return equal(getName(), that.getName()) - && equal(getUri(), that.getUri()) - && equal(getETag(), that.getETag()); - } else { - return false; - } - } - - @Override - public int hashCode() { - return Objects.hashCode(getName(), getUri(), getETag()); - } - - @Override - public String toString() { - return string().toString(); - } - - protected ToStringHelper string() { - return toStringHelper(this) - .add("name", getName()) - .add("uri", getUri()) - .add("etag", getETag()) - .add("lastModified", getLastModified()) - .add("metadata", getMetadata()); - } - - @Override - public int compareTo(SwiftObject that) { - if (that == null) - return 1; - if (this == that) - return 0; - return this.getName().compareTo(that.getName()); - } - - public static Builder builder() { - return new Builder(); - } - - public Builder toBuilder() { - return builder().fromObject(this); - } - - public static class Builder { - protected String name; - protected URI uri; - protected String etag; - protected Date lastModified; - protected Payload payload; - protected Multimap headers = ImmutableMultimap.of(); - protected Map metadata = ImmutableMap.of(); - - /** - * @see SwiftObject#getName() - */ - public Builder name(String name) { - this.name = checkNotNull(name, "name"); - return this; - } - - /** - * @see SwiftObject#getUri() - */ - public Builder uri(URI uri) { - this.uri = checkNotNull(uri, "uri"); - return this; - } - - /** - * @see SwiftObject#getETag() - */ - public Builder etag(String etag) { - this.etag = etag; - return this; - } - - /** - * @see SwiftObject#getLastModified() - */ - public Builder lastModified(Date lastModified) { - this.lastModified = lastModified; - return this; - } - - /** - * @see SwiftObject#getPayload() - */ - public Builder payload(Payload payload) { - this.payload = payload; - return this; - } - - /** - * @see SwiftObject#getHeaders() - */ - public Builder headers(Multimap headers) { - this.headers = headers; - return this; - } - - /** - * Will lower-case all metadata keys due to a swift implementation - * decision. - * - * @see SwiftObject#getMetadata() - */ - public Builder metadata(Map metadata) { - ImmutableMap.Builder builder = ImmutableMap. builder(); - for (Entry entry : checkNotNull(metadata, "metadata").entrySet()) { - builder.put(entry.getKey().toLowerCase(), entry.getValue()); - } - this.metadata = builder.build(); - return this; - } - - public SwiftObject build() { - return new SwiftObject(name, uri, etag, lastModified, headers, metadata, payload); - } - - public Builder fromObject(SwiftObject from) { - return name(from.getName()) - .uri(from.getUri()) - .etag(from.getETag()) - .lastModified(from.getLastModified()) - .headers(from.getHeaders()) - .metadata(from.getMetadata()) - .payload(from.getPayload()); - } - } -} diff --git a/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/features/AccountApi.java b/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/features/AccountApi.java deleted file mode 100644 index 21582a1ced..0000000000 --- a/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/features/AccountApi.java +++ /dev/null @@ -1,115 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF 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.openstack.swift.v1.features; - -import static javax.ws.rs.core.MediaType.APPLICATION_JSON; -import static org.jclouds.openstack.swift.v1.reference.SwiftHeaders.ACCOUNT_TEMPORARY_URL_KEY; - -import java.util.Map; - -import javax.inject.Named; -import javax.ws.rs.Consumes; -import javax.ws.rs.HEAD; -import javax.ws.rs.HeaderParam; -import javax.ws.rs.POST; -import javax.ws.rs.Path; - -import org.jclouds.Fallbacks.FalseOnNotFoundOr404; -import org.jclouds.openstack.keystone.v2_0.filters.AuthenticateRequest; -import org.jclouds.openstack.swift.v1.binders.BindMetadataToHeaders.BindAccountMetadataToHeaders; -import org.jclouds.openstack.swift.v1.binders.BindMetadataToHeaders.BindRemoveAccountMetadataToHeaders; -import org.jclouds.openstack.swift.v1.domain.Account; -import org.jclouds.openstack.swift.v1.functions.ParseAccountFromHeaders; -import org.jclouds.rest.annotations.BinderParam; -import org.jclouds.rest.annotations.Fallback; -import org.jclouds.rest.annotations.RequestFilters; -import org.jclouds.rest.annotations.ResponseParser; - -import com.google.common.annotations.Beta; - -/** - * Provides access to the OpenStack Object Storage (Swift) Account API features. - * - *

- * Account metadata prefixed with {@code X-Account-Meta-} will be converted - * appropriately using a binder/parser. - *

- * This API is new to jclouds and hence is in Beta. That means we need people to use it and give us feedback. Based - * on that feedback, minor changes to the interfaces may happen. This code will replace - * org.jclouds.openstack.swift.SwiftClient in jclouds 2.0 and it is recommended you adopt it sooner than later. - * - * - * @see {@link Account} - */ -@Beta -@RequestFilters(AuthenticateRequest.class) -@Consumes(APPLICATION_JSON) -public interface AccountApi { - - /** - * Gets the {@link Account}. - * - * @return The {@link Account} object. - */ - @Named("account:get") - @HEAD - @ResponseParser(ParseAccountFromHeaders.class) - @Path("/") - Account get(); - - /** - * Creates or updates the {@link Account} metadata. - * - * @param metadata the metadata to create or update. - * - * @return {@code true} if the metadata was successfully created or updated, - * {@code false} if not. - */ - @Named("account:updateMetadata") - @POST - @Fallback(FalseOnNotFoundOr404.class) - @Path("/") - boolean updateMetadata(@BinderParam(BindAccountMetadataToHeaders.class) Map metadata); - - /** - * Replaces the temporary URL key for the {@link Account}. - * - * @param temporaryUrlKey the temporary URL key to update. - * - * @return {@code true} if the temporary URL key was successfully updated, - * {@code false} if not. - */ - @Named("account:updateTemporaryUrlKey") - @POST - @Fallback(FalseOnNotFoundOr404.class) - @Path("/") - boolean updateTemporaryUrlKey(@HeaderParam(ACCOUNT_TEMPORARY_URL_KEY) String temporaryUrlKey); - - /** - * Deletes metadata from the {@link Account}. - * - * @param metadata the metadata to delete. - * - * @return {@code true} if the metadata was successfully deleted, - * {@code false} if not. - */ - @Named("account:deleteMetadata") - @POST - @Fallback(FalseOnNotFoundOr404.class) - @Path("/") - boolean deleteMetadata(@BinderParam(BindRemoveAccountMetadataToHeaders.class) Map metadata); -} diff --git a/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/features/BulkApi.java b/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/features/BulkApi.java deleted file mode 100644 index 002ca3b130..0000000000 --- a/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/features/BulkApi.java +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF 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.openstack.swift.v1.features; - -import static com.google.common.collect.Iterables.transform; -import static com.google.common.net.UrlEscapers.urlFragmentEscaper; -import static javax.ws.rs.core.MediaType.APPLICATION_JSON; -import static javax.ws.rs.core.MediaType.TEXT_PLAIN; - -import javax.inject.Named; -import javax.ws.rs.Consumes; -import javax.ws.rs.DELETE; -import javax.ws.rs.PUT; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.QueryParam; - -import org.jclouds.http.HttpRequest; -import org.jclouds.io.Payload; -import org.jclouds.io.Payloads; -import org.jclouds.openstack.keystone.v2_0.filters.AuthenticateRequest; -import org.jclouds.openstack.swift.v1.binders.SetPayload; -import org.jclouds.openstack.swift.v1.domain.BulkDeleteResponse; -import org.jclouds.openstack.swift.v1.domain.ExtractArchiveResponse; -import org.jclouds.rest.Binder; -import org.jclouds.rest.annotations.BinderParam; -import org.jclouds.rest.annotations.QueryParams; -import org.jclouds.rest.annotations.RequestFilters; - -import com.google.common.annotations.Beta; -import com.google.common.base.Joiner; - -/** - * Provides access to the OpenStack Object Storage (Swift) Bulk API features. - *

- * This API is new to jclouds and hence is in Beta. That means we need people to use it and give us feedback. Based - * on that feedback, minor changes to the interfaces may happen. This code will replace - * org.jclouds.openstack.swift.SwiftClient in jclouds 2.0 and it is recommended you adopt it sooner than later. - */ -@Beta -@RequestFilters(AuthenticateRequest.class) -@Consumes(APPLICATION_JSON) -public interface BulkApi { - - /** - * Extracts a tar archive at the path specified as {@code path}. - * - * @param path - * the path to extract under. - * @param payload - * the {@link Payload payload} archive. - * @param format - * one of {@code tar}, {@code tar.gz}, or {@code tar.bz2} - * - * @return {@link BulkDeleteResponse#getErrors()} are empty on success. - */ - @Named("bulk:extractArchive") - @PUT - @Path("/{path}") - ExtractArchiveResponse extractArchive(@PathParam("path") String path, - @BinderParam(SetPayload.class) Payload payload, @QueryParam("extract-archive") String format); - - /** - * Deletes multiple objects or containers, if present. - * - * @param paths - * format of {@code container}, for an empty container, or - * {@code container/object} for an object. - * - * @return {@link BulkDeleteResponse#getErrors()} are empty on success. - */ - @Named("bulk:delete") - @DELETE - @Path("/") - @QueryParams(keys = "bulk-delete") - BulkDeleteResponse bulkDelete(@BinderParam(UrlEncodeAndJoinOnNewline.class) Iterable paths); - - // NOTE: this cannot be tested on MWS and is also brittle, as it relies on - // sending a body on DELETE. - // https://bugs.launchpad.net/swift/+bug/1232787 - static class UrlEncodeAndJoinOnNewline implements Binder { - @SuppressWarnings("unchecked") - @Override - public R bindToRequest(R request, Object input) { - String encodedAndNewlineDelimited = Joiner.on('\n').join( - transform(Iterable.class.cast(input), urlFragmentEscaper().asFunction())); - Payload payload = Payloads.newStringPayload(encodedAndNewlineDelimited); - payload.getContentMetadata().setContentType(TEXT_PLAIN); - return (R) request.toBuilder().payload(payload).build(); - } - } -} diff --git a/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/features/ContainerApi.java b/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/features/ContainerApi.java deleted file mode 100644 index eb33d7cc72..0000000000 --- a/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/features/ContainerApi.java +++ /dev/null @@ -1,259 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF 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.openstack.swift.v1.features; - -import static javax.ws.rs.core.MediaType.APPLICATION_JSON; - -import java.util.Map; - -import javax.inject.Named; -import javax.ws.rs.Consumes; -import javax.ws.rs.DELETE; -import javax.ws.rs.GET; -import javax.ws.rs.HEAD; -import javax.ws.rs.POST; -import javax.ws.rs.PUT; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; - -import org.jclouds.Fallbacks.EmptyFluentIterableOnNotFoundOr404; -import org.jclouds.Fallbacks.FalseOnNotFoundOr404; -import org.jclouds.Fallbacks.NullOnNotFoundOr404; -import org.jclouds.Fallbacks.TrueOnNotFoundOr404; -import org.jclouds.javax.annotation.Nullable; -import org.jclouds.openstack.keystone.v2_0.filters.AuthenticateRequest; -import org.jclouds.openstack.swift.v1.binders.BindMetadataToHeaders.BindContainerMetadataToHeaders; -import org.jclouds.openstack.swift.v1.binders.BindMetadataToHeaders.BindRemoveContainerMetadataToHeaders; -import org.jclouds.openstack.swift.v1.domain.Container; -import org.jclouds.openstack.swift.v1.functions.FalseOnAccepted; -import org.jclouds.openstack.swift.v1.functions.ParseContainerFromHeaders; -import org.jclouds.openstack.swift.v1.options.CreateContainerOptions; -import org.jclouds.openstack.swift.v1.options.ListContainerOptions; -import org.jclouds.openstack.swift.v1.options.UpdateContainerOptions; -import org.jclouds.rest.annotations.BinderParam; -import org.jclouds.rest.annotations.Fallback; -import org.jclouds.rest.annotations.QueryParams; -import org.jclouds.rest.annotations.RequestFilters; -import org.jclouds.rest.annotations.ResponseParser; - -import com.google.common.annotations.Beta; -import com.google.common.collect.FluentIterable; - -/** - * Provides access to the OpenStack Object Storage (Swift) Container API features. - *

- * This API is new to jclouds and hence is in Beta. That means we need people to use it and give us feedback. Based - * on that feedback, minor changes to the interfaces may happen. This code will replace - * {@code org.jclouds.openstack.swift.SwiftClient} in jclouds 2.0 and it is recommended you adopt it sooner than later. - */ -@Beta -@RequestFilters(AuthenticateRequest.class) -@Consumes(APPLICATION_JSON) -public interface ContainerApi { - - /** - * Lists up to 10,000 containers. - * - *

NOTE

- * This method returns a list of {@link Container} objects without metadata. To retrieve - * the {@link Container} metadata, use the {@link #get(String)} method. - *

- * - * @return a list of {@link Container containers} ordered by name. - */ - @Named("container:list") - @GET - @QueryParams(keys = "format", values = "json") - @Fallback(EmptyFluentIterableOnNotFoundOr404.class) - @Path("/") - FluentIterable list(); - - /** - * Lists containers with the supplied {@link ListContainerOptions}. - * - *

NOTE

- * This method returns a list of {@link Container} objects without metadata. To retrieve - * the {@link Container} metadata, use the {@link #get(String)} method. - *

- * - * @param options - * the options to control the output list. - * - * @return a list of {@link Container containers} ordered by name. - */ - @Named("container:list") - @GET - @QueryParams(keys = "format", values = "json") - @Fallback(EmptyFluentIterableOnNotFoundOr404.class) - @Path("/") - FluentIterable list(ListContainerOptions options); - - /** - * Creates a container, if not already present. - * - * @param containerName - * corresponds to {@link Container#getName()}. - * - * @return {@code true} if the container was created, {@code false} if the container already existed. - */ - @Named("container:create") - @PUT - @ResponseParser(FalseOnAccepted.class) - @Path("/{containerName}") - boolean create(@PathParam("containerName") String containerName); - - /** - * Creates a container, if not already present. - * - * @param containerName - * corresponds to {@link Container#getName()}. - * @param options - * the options to use when creating the container. - * - * @return {@code true} if the container was created, {@code false} if the container already existed. - */ - @Named("container:create") - @PUT - @ResponseParser(FalseOnAccepted.class) - @Path("/{containerName}") - boolean create(@PathParam("containerName") String containerName, CreateContainerOptions options); - - /** - * Gets the {@link Container}. - * - * @param containerName - * corresponds to {@link Container#getName()}. - * - * @return the {@link Container}, or {@code null} if not found. - */ - @Named("container:get") - @HEAD - @ResponseParser(ParseContainerFromHeaders.class) - @Fallback(NullOnNotFoundOr404.class) - @Path("/{containerName}") - @Nullable - Container get(@PathParam("containerName") String containerName); - - /** - * Updates the {@link Container}. - * - * @param containerName - * the container name corresponding to {@link Container#getName()}. - * @param options - * the container options to update. - * - * @return {@code true} if the container metadata was successfully created or updated, - * {@code false} if not. - */ - @Named("container:update") - @POST - @Fallback(FalseOnNotFoundOr404.class) - @Path("/{containerName}") - boolean update(@PathParam("containerName") String containerName, UpdateContainerOptions options); - - /** - * Creates or updates the {@link Container} metadata. - * - * @param containerName - * the container name corresponding to {@link Container#getName()}. - * @param metadata - * the container metadata to create or update. - * - * @return {@code true} if the container metadata was successfully created or updated, - * {@code false} if not. - */ - @Named("container:updateMetadata") - @POST - @Fallback(FalseOnNotFoundOr404.class) - @Path("/{containerName}") - boolean updateMetadata(@PathParam("containerName") String containerName, - @BinderParam(BindContainerMetadataToHeaders.class) Map metadata); - - /** - * Deletes {@link Container} metadata. - * - * @param containerName - * corresponds to {@link Container#getName()}. - * @param metadata - * the container metadata to delete. - * - * @return {@code true} if the container metadata was successfully deleted, - * {@code false} if not. - */ - @Named("container:deleteMetadata") - @POST - @Fallback(FalseOnNotFoundOr404.class) - @Path("/{containerName}") - boolean deleteMetadata(@PathParam("containerName") String containerName, - @BinderParam(BindRemoveContainerMetadataToHeaders.class) Map metadata); - - /** - * Deletes a {@link Container}, if empty. - * - * @param containerName - * corresponds to {@link Container#getName()}. - * - * @return {@code true} if the container was deleted or not present. - * - * @throws IllegalStateException if the container was not empty. - */ - @Named("container:deleteIfEmpty") - @DELETE - @Fallback(TrueOnNotFoundOr404.class) - @Path("/{containerName}") - boolean deleteIfEmpty(@PathParam("containerName") String containerName) throws IllegalStateException; - - /** - * Creates a container, if not already present. - * - * @param containerName - * corresponds to {@link Container#getName()}. - * @param options - * the options to use when creating the container. - * - * @return {@code true} if the container was created, {@code false} if the container already existed. - * - * @deprecated Please use either {@link #create(String)} or {@link #create(String, CreateContainerOptions)} - * as this method will be removed in jclouds 1.8. - */ - @Deprecated - @Named("container:createIfAbsent") - @PUT - @ResponseParser(FalseOnAccepted.class) - @Path("/{containerName}") - boolean createIfAbsent(@PathParam("containerName") String containerName, CreateContainerOptions options); - - /** - * Gets the {@link Container} metadata, including the number of objects in the container and - * the total bytes for all objects stored in the container. - * - * @param containerName - * corresponds to {@link Container#getName()}. - * - * @return the {@link Container}, or {@code null} if not found. - * - * @deprecated Please use {@link #get(String)} as this method will be removed in jclouds 1.8. - */ - @Deprecated - @Named("container:get") - @HEAD - @ResponseParser(ParseContainerFromHeaders.class) - @Fallback(NullOnNotFoundOr404.class) - @Path("/{containerName}") - @Nullable - Container head(@PathParam("containerName") String containerName); -} diff --git a/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/features/ObjectApi.java b/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/features/ObjectApi.java deleted file mode 100644 index e4fccc620c..0000000000 --- a/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/features/ObjectApi.java +++ /dev/null @@ -1,310 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF 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.openstack.swift.v1.features; - -import static com.google.common.net.HttpHeaders.EXPECT; -import static javax.ws.rs.core.MediaType.APPLICATION_JSON; -import static org.jclouds.openstack.swift.v1.reference.SwiftHeaders.OBJECT_COPY_FROM; - -import java.util.Map; - -import javax.inject.Named; -import javax.ws.rs.Consumes; -import javax.ws.rs.DELETE; -import javax.ws.rs.GET; -import javax.ws.rs.HEAD; -import javax.ws.rs.POST; -import javax.ws.rs.PUT; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; - -import org.jclouds.Fallbacks.FalseOnNotFoundOr404; -import org.jclouds.Fallbacks.NullOnNotFoundOr404; -import org.jclouds.Fallbacks.VoidOnNotFoundOr404; -import org.jclouds.blobstore.BlobStoreFallbacks.FalseOnContainerNotFound; -import org.jclouds.http.options.GetOptions; -import org.jclouds.io.Payload; -import org.jclouds.javax.annotation.Nullable; -import org.jclouds.openstack.keystone.v2_0.filters.AuthenticateRequest; -import org.jclouds.openstack.swift.v1.binders.BindMetadataToHeaders.BindObjectMetadataToHeaders; -import org.jclouds.openstack.swift.v1.binders.BindMetadataToHeaders.BindRemoveObjectMetadataToHeaders; -import org.jclouds.openstack.swift.v1.binders.SetPayload; -import org.jclouds.openstack.swift.v1.domain.ObjectList; -import org.jclouds.openstack.swift.v1.domain.SwiftObject; -import org.jclouds.openstack.swift.v1.functions.ETagHeader; -import org.jclouds.openstack.swift.v1.functions.ParseObjectFromResponse; -import org.jclouds.openstack.swift.v1.functions.ParseObjectListFromResponse; -import org.jclouds.openstack.swift.v1.options.ListContainerOptions; -import org.jclouds.openstack.swift.v1.options.PutOptions; -import org.jclouds.rest.annotations.BinderParam; -import org.jclouds.rest.annotations.Fallback; -import org.jclouds.rest.annotations.Headers; -import org.jclouds.rest.annotations.QueryParams; -import org.jclouds.rest.annotations.RequestFilters; -import org.jclouds.rest.annotations.ResponseParser; - -import com.google.common.annotations.Beta; - -/** - * Provides access to the OpenStack Object Storage (Swift) Object API features. - *

- * This API is new to jclouds and hence is in Beta. That means we need people to use it and give us feedback. Based - * on that feedback, minor changes to the interfaces may happen. This code will replace - * org.jclouds.openstack.swift.SwiftClient in jclouds 2.0 and it is recommended you adopt it sooner than later. - */ -@Beta -@RequestFilters(AuthenticateRequest.class) -@Consumes(APPLICATION_JSON) -public interface ObjectApi { - - /** - * Lists up to 10,000 objects. - * - * @return an {@link ObjectList} of {@link SwiftObject} ordered by name or {@code null}. - */ - @Named("object:list") - @GET - @QueryParams(keys = "format", values = "json") - @ResponseParser(ParseObjectListFromResponse.class) - @Fallback(NullOnNotFoundOr404.class) - @Path("/") - @Nullable - ObjectList list(); - - /** - * Lists up to 10,000 objects. To control a large list of containers beyond - * 10,000 objects, use the {@code marker} and {@code endMarker} parameters in the - * {@link ListContainerOptions} class. - * - * @param options - * the {@link ListContainerOptions} for controlling the returned list. - * - * @return an {@link ObjectList} of {@link SwiftObject} ordered by name or {@code null}. - */ - @Named("object:list") - @GET - @QueryParams(keys = "format", values = "json") - @ResponseParser(ParseObjectListFromResponse.class) - @Fallback(NullOnNotFoundOr404.class) - @Path("/") - @Nullable - ObjectList list(ListContainerOptions options); - - /** - * Creates or updates a {@link SwiftObject}. - * - * @param objectName - * corresponds to {@link SwiftObject#getName()}. - * @param payload - * corresponds to {@link SwiftObject#getPayload()}. - * - * @return {@link SwiftObject#getETag()} of the object. - */ - @Named("object:put") - @PUT - @Headers(keys = EXPECT, values = "100-continue") - @ResponseParser(ETagHeader.class) - @Path("/{objectName}") - String put(@PathParam("objectName") String objectName, @BinderParam(SetPayload.class) Payload payload); - - /** - * Creates or updates a {@link SwiftObject}. - * - * @param objectName - * corresponds to {@link SwiftObject#getName()}. - * @param payload - * corresponds to {@link SwiftObject#getPayload()}. - * @param options - * {@link PutOptions options} to control creating the {@link SwiftObject}. - * - * @return {@link SwiftObject#getETag()} of the object. - */ - @Named("object:put") - @PUT - @Headers(keys = EXPECT, values = "100-continue") - @ResponseParser(ETagHeader.class) - @Path("/{objectName}") - String put(@PathParam("objectName") String objectName, @BinderParam(SetPayload.class) Payload payload, - PutOptions options); - - /** - * Gets the {@link SwiftObject} metadata without its {@link Payload#openStream() body}. - * - * @param objectName - * corresponds to {@link SwiftObject#getName()}. - * - * @return the {@link SwiftObject} or {@code null}, if not found. - */ - @Named("object:getWithoutBody") - @HEAD - @ResponseParser(ParseObjectFromResponse.class) - @Fallback(NullOnNotFoundOr404.class) - @Path("/{objectName}") - @Nullable - SwiftObject getWithoutBody(@PathParam("objectName") String objectName); - - /** - * Gets the {@link SwiftObject} including its {@link Payload#openStream() body}. - * - * @param objectName - * corresponds to {@link SwiftObject#getName()}. - * - * @return the {@link SwiftObject} or {@code null}, if not found. - */ - @Named("object:get") - @GET - @ResponseParser(ParseObjectFromResponse.class) - @Fallback(NullOnNotFoundOr404.class) - @Path("/{objectName}") - @Nullable - SwiftObject get(@PathParam("objectName") String objectName); - - /** - * Gets the {@link SwiftObject} including its {@link Payload#openStream() body}. - * - * @param objectName - * corresponds to {@link SwiftObject#getName()}. - * @param options - * options to control the download. - * - * @return the {@link SwiftObject} or {@code null}, if not found. - */ - @Named("object:get") - @GET - @ResponseParser(ParseObjectFromResponse.class) - @Fallback(NullOnNotFoundOr404.class) - @Path("/{objectName}") - @Nullable - SwiftObject get(@PathParam("objectName") String objectName, GetOptions options); - - /** - * Creates or updates the metadata for a {@link SwiftObject}. - * - * @param objectName - * corresponds to {@link SwiftObject#getName()}. - * @param metadata - * the metadata to create or update. - * - * @return {@code true} if the metadata was successfully created or updated, - * {@code false} if not. - */ - @Named("object:updateMetadata") - @POST - @Fallback(FalseOnNotFoundOr404.class) - @Path("/{objectName}") - @Produces("") - boolean updateMetadata(@PathParam("objectName") String objectName, - @BinderParam(BindObjectMetadataToHeaders.class) Map metadata); - - /** - * Deletes the metadata from a {@link SwiftObject}. - * - * @param objectName - * corresponds to {@link SwiftObject#getName()}. - * @param metadata - * corresponds to {@link SwiftObject#getMetadata()}. - * - * @return {@code true} if the metadata was successfully deleted, - * {@code false} if not. - */ - @Named("object:deleteMetadata") - @POST - @Fallback(FalseOnNotFoundOr404.class) - @Path("/{objectName}") - boolean deleteMetadata(@PathParam("objectName") String objectName, - @BinderParam(BindRemoveObjectMetadataToHeaders.class) Map metadata); - - /** - * Deletes an object, if present. - * - * @param objectName - * corresponds to {@link SwiftObject#getName()}. - */ - @Named("object:delete") - @DELETE - @Fallback(VoidOnNotFoundOr404.class) - @Path("/{objectName}") - void delete(@PathParam("objectName") String objectName); - - /** - * Copies an object from one container to another. - * - *

NOTE

- * This is a server side copy. - * - * @param destinationObject - * the destination object name. - * @param sourceContainer - * the source container name. - * @param sourceObject - * the source object name. - * - * @return {@code true} if the object was successfully copied, {@code false} if not. - * - * @throws org.jclouds.openstack.swift.v1.CopyObjectException if the source or destination container do not exist. - */ - @Named("object:copy") - @PUT - @Path("/{destinationObject}") - @Headers(keys = OBJECT_COPY_FROM, values = "/{sourceContainer}/{sourceObject}") - @Fallback(FalseOnContainerNotFound.class) - boolean copy(@PathParam("destinationObject") String destinationObject, - @PathParam("sourceContainer") String sourceContainer, - @PathParam("sourceObject") String sourceObject); - - /** - * Gets the {@link SwiftObject} metadata without its {@link Payload#openStream() body}. - * - * @param objectName - * corresponds to {@link SwiftObject#getName()}. - * - * @return the {@link SwiftObject} or {@code null}, if not found. - * - * @deprecated Please use {@link #getWithoutBody(String)} as this method will be removed in jclouds 1.8. - */ - @Deprecated - @Named("object:head") - @HEAD - @ResponseParser(ParseObjectFromResponse.class) - @Fallback(NullOnNotFoundOr404.class) - @Path("/{objectName}") - @Nullable - SwiftObject head(@PathParam("objectName") String objectName); - - /** - * Creates or updates a {@link SwiftObject}. - * - * @param objectName - * corresponds to {@link SwiftObject#getName()}. - * @param payload - * corresponds to {@link SwiftObject#getPayload()}. - * @param metadata - * corresponds to {@link SwiftObject#getMetadata()}. - * - * @return {@link SwiftObject#getEtag()} of the object. - * - * @deprecated Please use {@link #put(String, Payload)} or {@link #put(String, Payload, PutOptions)} - * as this method will be removed in jclouds 1.8. - */ - @Named("object:replace") - @PUT - @ResponseParser(ETagHeader.class) - @Path("/{objectName}") - String replace(@PathParam("objectName") String objectName, @BinderParam(SetPayload.class) Payload payload, - @BinderParam(BindObjectMetadataToHeaders.class) Map metadata); -} diff --git a/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/features/StaticLargeObjectApi.java b/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/features/StaticLargeObjectApi.java deleted file mode 100644 index 385428e909..0000000000 --- a/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/features/StaticLargeObjectApi.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF 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.openstack.swift.v1.features; - -import static javax.ws.rs.core.MediaType.APPLICATION_JSON; - -import java.util.List; -import java.util.Map; - -import javax.inject.Named; -import javax.ws.rs.Consumes; -import javax.ws.rs.DELETE; -import javax.ws.rs.PUT; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; - -import org.jclouds.Fallbacks.VoidOnNotFoundOr404; -import org.jclouds.openstack.keystone.v2_0.filters.AuthenticateRequest; -import org.jclouds.openstack.swift.v1.binders.BindMetadataToHeaders.BindObjectMetadataToHeaders; -import org.jclouds.openstack.swift.v1.domain.Segment; -import org.jclouds.openstack.swift.v1.functions.ETagHeader; -import org.jclouds.rest.annotations.BinderParam; -import org.jclouds.rest.annotations.Fallback; -import org.jclouds.rest.annotations.QueryParams; -import org.jclouds.rest.annotations.RequestFilters; -import org.jclouds.rest.annotations.ResponseParser; -import org.jclouds.rest.binders.BindToJsonPayload; - -import com.google.common.annotations.Beta; - -/** - * Provides access to the OpenStack Object Storage (Swift) Static Large Object API features. - *

- * This API is new to jclouds and hence is in Beta. That means we need people to use it and give us feedback. Based - * on that feedback, minor changes to the interfaces may happen. This code will replace - * org.jclouds.openstack.swift.SwiftClient in jclouds 2.0 and it is recommended you adopt it sooner than later. - */ -@Beta -@RequestFilters(AuthenticateRequest.class) -@Consumes(APPLICATION_JSON) -public interface StaticLargeObjectApi { - - /** - * Creates or updates a static large object's manifest. - * - * @param objectName - * corresponds to {@link SwiftObject#getName()}. - * @param segments - * ordered parts which will be concatenated upon download. - * @param metadata - * corresponds to {@link SwiftObject#getMetadata()}. - * - * @return {@link SwiftObject#getEtag()} of the object, which is the MD5 - * checksum of the concatenated ETag values of the {@code segments}. - */ - @Named("staticLargeObject:replaceManifest") - @PUT - @ResponseParser(ETagHeader.class) - @Path("/{objectName}") - @QueryParams(keys = "multipart-manifest", values = "put") - String replaceManifest(@PathParam("objectName") String objectName, - @BinderParam(BindToJsonPayload.class) List segments, - @BinderParam(BindObjectMetadataToHeaders.class) Map metadata); - - /** - * Deletes a static large object, if present, including all of its segments. - * - * @param objectName - * corresponds to {@link SwiftObject#getName()}. - */ - @Named("staticLargeObject:delete") - @DELETE - @Fallback(VoidOnNotFoundOr404.class) - @Path("/{objectName}") - @QueryParams(keys = "multipart-manifest", values = "delete") - void delete(@PathParam("objectName") String objectName); -} diff --git a/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/functions/ETagHeader.java b/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/functions/ETagHeader.java deleted file mode 100644 index 25a749b8c5..0000000000 --- a/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/functions/ETagHeader.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF 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.openstack.swift.v1.functions; - -import static com.google.common.net.HttpHeaders.ETAG; - -import org.jclouds.http.HttpResponse; - -import com.google.common.base.Function; - -public class ETagHeader implements Function { - - @Override - public String apply(HttpResponse from) { - String etag = from.getFirstHeaderOrNull(ETAG); - return etag != null ? etag.replace("\"", "") : null; - } -} diff --git a/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/functions/EntriesWithoutMetaPrefix.java b/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/functions/EntriesWithoutMetaPrefix.java deleted file mode 100644 index 473da3e43e..0000000000 --- a/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/functions/EntriesWithoutMetaPrefix.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF 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.openstack.swift.v1.functions; - -import java.util.Map; -import java.util.Map.Entry; - -import com.google.common.base.Function; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.Multimap; - -/** - * Extracts entries whose keys start with {@code .*-Meta-}. - * - * @param from - * a {@link Multimap} containing the prefixed headers. - * - * @return the extracted metadata without the prefixed keys. - */ -public enum EntriesWithoutMetaPrefix implements Function, Map> { - INSTANCE; - - @Override - public Map apply(Multimap arg0) { - ImmutableMap.Builder metadata = ImmutableMap.builder(); - for (Entry header : arg0.entries()) { - int index = header.getKey().indexOf("-Meta-"); - if (index != -1) { - metadata.put(header.getKey().substring(index + 6), header.getValue()); - } - } - return metadata.build(); - } -} diff --git a/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/functions/FalseOnAccepted.java b/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/functions/FalseOnAccepted.java deleted file mode 100644 index 68da52498c..0000000000 --- a/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/functions/FalseOnAccepted.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF 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.openstack.swift.v1.functions; - -import org.jclouds.http.HttpResponse; - -import com.google.common.base.Function; - -/** Returns {@code false} on HTTP 202 {@code Accepted}. */ -public class FalseOnAccepted implements Function { - - @Override - public Boolean apply(HttpResponse from) { - return from.getStatusCode() == 202 ? false : true; - } -} diff --git a/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/functions/MetadataFromHeaders.java b/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/functions/MetadataFromHeaders.java deleted file mode 100644 index cdd49f16b8..0000000000 --- a/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/functions/MetadataFromHeaders.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF 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.openstack.swift.v1.functions; - -import java.util.Map; - -import org.jclouds.http.HttpResponse; - -import com.google.common.base.Function; - -/** Extracts metadata entries from http response headers. */ -public class MetadataFromHeaders implements Function> { - @Override - public Map apply(HttpResponse from) { - return EntriesWithoutMetaPrefix.INSTANCE.apply(from.getHeaders()); - } -} diff --git a/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/functions/ParseAccountFromHeaders.java b/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/functions/ParseAccountFromHeaders.java deleted file mode 100644 index 9debe67f3e..0000000000 --- a/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/functions/ParseAccountFromHeaders.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF 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.openstack.swift.v1.functions; - -import static org.jclouds.openstack.swift.v1.reference.SwiftHeaders.ACCOUNT_BYTES_USED; -import static org.jclouds.openstack.swift.v1.reference.SwiftHeaders.ACCOUNT_CONTAINER_COUNT; -import static org.jclouds.openstack.swift.v1.reference.SwiftHeaders.ACCOUNT_OBJECT_COUNT; - -import org.jclouds.http.HttpResponse; -import org.jclouds.openstack.swift.v1.domain.Account; - -import com.google.common.base.Function; - -public class ParseAccountFromHeaders implements Function { - - @Override - public Account apply(HttpResponse from) { - return Account.builder() - .bytesUsed(Long.parseLong(from.getFirstHeaderOrNull(ACCOUNT_BYTES_USED))) - .containerCount(Long.parseLong(from.getFirstHeaderOrNull(ACCOUNT_CONTAINER_COUNT))) - .objectCount(Long.parseLong(from.getFirstHeaderOrNull(ACCOUNT_OBJECT_COUNT))) - .metadata(EntriesWithoutMetaPrefix.INSTANCE.apply(from.getHeaders())).build(); - } -} diff --git a/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/functions/ParseContainerFromHeaders.java b/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/functions/ParseContainerFromHeaders.java deleted file mode 100644 index d61635117f..0000000000 --- a/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/functions/ParseContainerFromHeaders.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF 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.openstack.swift.v1.functions; - -import static org.jclouds.openstack.swift.v1.reference.SwiftHeaders.CONTAINER_ACL_ANYBODY_READ; -import static org.jclouds.openstack.swift.v1.reference.SwiftHeaders.CONTAINER_BYTES_USED; -import static org.jclouds.openstack.swift.v1.reference.SwiftHeaders.CONTAINER_OBJECT_COUNT; -import static org.jclouds.openstack.swift.v1.reference.SwiftHeaders.CONTAINER_READ; - -import org.jclouds.http.HttpRequest; -import org.jclouds.http.HttpResponse; -import org.jclouds.openstack.swift.v1.domain.Container; -import org.jclouds.rest.InvocationContext; -import org.jclouds.rest.internal.GeneratedHttpRequest; - -import com.google.common.base.Function; - -public class ParseContainerFromHeaders implements Function, - InvocationContext { - - String name; - - @Override - public Container apply(HttpResponse from) { - Container c = - Container.builder() - .name(name) - .bytesUsed(Long.parseLong(from.getFirstHeaderOrNull(CONTAINER_BYTES_USED))) - .objectCount(Long.parseLong(from.getFirstHeaderOrNull(CONTAINER_OBJECT_COUNT))) - .anybodyRead(CONTAINER_ACL_ANYBODY_READ.equals(from.getFirstHeaderOrNull(CONTAINER_READ))) - .metadata(EntriesWithoutMetaPrefix.INSTANCE.apply(from.getHeaders())).build(); - return c; - } - - @Override - public ParseContainerFromHeaders setContext(HttpRequest request) { - this.name = GeneratedHttpRequest.class.cast(request).getInvocation().getArgs().get(0).toString(); - return this; - } -} diff --git a/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/functions/ParseObjectFromResponse.java b/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/functions/ParseObjectFromResponse.java deleted file mode 100644 index 714a403785..0000000000 --- a/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/functions/ParseObjectFromResponse.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF 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.openstack.swift.v1.functions; - -import static com.google.common.net.HttpHeaders.ETAG; -import static com.google.common.net.HttpHeaders.LAST_MODIFIED; -import static org.jclouds.openstack.swift.v1.reference.SwiftHeaders.OBJECT_DELETE_AT; - -import java.net.URI; -import java.util.Date; - -import javax.inject.Inject; - -import org.jclouds.date.DateService; -import org.jclouds.http.HttpRequest; -import org.jclouds.http.HttpResponse; -import org.jclouds.io.MutableContentMetadata; -import org.jclouds.io.Payload; -import org.jclouds.openstack.swift.v1.domain.SwiftObject; -import org.jclouds.rest.InvocationContext; -import org.jclouds.rest.internal.GeneratedHttpRequest; - -import com.google.common.base.Function; - -public class ParseObjectFromResponse implements Function, - InvocationContext { - private final DateService dates; - - @Inject - ParseObjectFromResponse(DateService dates) { - this.dates = dates; - } - - private String uri; - private String name; - - @Override - public SwiftObject apply(HttpResponse from) { - - Payload payload = from.getPayload(); - MutableContentMetadata contentMeta = payload.getContentMetadata(); - - String deleteAt = from.getFirstHeaderOrNull(OBJECT_DELETE_AT); - if (deleteAt != null) { - long fromEpoch = Long.parseLong(from.getFirstHeaderOrNull(OBJECT_DELETE_AT)) * 1000; - contentMeta.setExpires(new Date(fromEpoch)); - payload.setContentMetadata(contentMeta); - } - - return SwiftObject.builder() - .uri(URI.create(uri)) - .name(name) - .etag(from.getFirstHeaderOrNull(ETAG)) - .payload(payload) - .lastModified(dates.rfc822DateParse(from.getFirstHeaderOrNull(LAST_MODIFIED))) - .headers(from.getHeaders()) - .metadata(EntriesWithoutMetaPrefix.INSTANCE.apply(from.getHeaders())).build(); - } - - @Override - public ParseObjectFromResponse setContext(HttpRequest request) { - this.uri = request.getEndpoint().toString(); - this.name = GeneratedHttpRequest.class.cast(request).getInvocation().getArgs().get(0).toString(); - return this; - } -} diff --git a/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/functions/ParseObjectListFromResponse.java b/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/functions/ParseObjectListFromResponse.java deleted file mode 100644 index 73f5a29bf6..0000000000 --- a/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/functions/ParseObjectListFromResponse.java +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF 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.openstack.swift.v1.functions; - -import static org.jclouds.http.Uris.uriBuilder; - -import java.util.Date; -import java.util.List; - -import javax.inject.Inject; - -import org.jclouds.http.HttpRequest; -import org.jclouds.http.HttpResponse; -import org.jclouds.http.functions.ParseJson; -import org.jclouds.io.Payload; -import org.jclouds.io.Payloads; -import org.jclouds.openstack.swift.v1.domain.Container; -import org.jclouds.openstack.swift.v1.domain.ObjectList; -import org.jclouds.openstack.swift.v1.domain.SwiftObject; -import org.jclouds.rest.InvocationContext; -import org.jclouds.rest.internal.GeneratedHttpRequest; - -import com.google.common.base.Function; -import com.google.common.collect.Lists; -import com.google.common.io.ByteSource; - -public class ParseObjectListFromResponse implements Function, - InvocationContext { - - private static final class InternalObject { - String name; - String hash; - long bytes; - String content_type; - Date last_modified; - Date expires; - } - - private final ParseJson> json; - private final ParseContainerFromHeaders parseContainer; - - @Inject - ParseObjectListFromResponse(ParseJson> json, ParseContainerFromHeaders parseContainer) { - this.json = json; - this.parseContainer = parseContainer; - } - - private ToSwiftObject toSwiftObject; - - @Override - public ObjectList apply(HttpResponse from) { - List objects = Lists.transform(json.apply(from), toSwiftObject); - Container container = parseContainer.apply(from); - return ObjectList.create(objects, container); - } - - static class ToSwiftObject implements Function { - private final String containerUri; - - ToSwiftObject(String containerUri) { - this.containerUri = containerUri; - } - - @Override - public SwiftObject apply(InternalObject input) { - return SwiftObject.builder() - .uri(uriBuilder(containerUri).clearQuery().appendPath(input.name).build()) - .name(input.name) - .etag(input.hash) - .payload(payload(input.bytes, input.content_type, input.expires)) - .lastModified(input.last_modified).build(); - } - } - - @Override - public ParseObjectListFromResponse setContext(HttpRequest request) { - parseContainer.name = GeneratedHttpRequest.class.cast(request).getCaller().get().getArgs().get(1).toString(); - String containerUri = request.getEndpoint().toString(); - int queryIndex = containerUri.indexOf('?'); - if (queryIndex != -1) { - containerUri = containerUri.substring(0, queryIndex); - } - toSwiftObject = new ToSwiftObject(containerUri); - return this; - } - - private static Payload payload(long bytes, String contentType, Date expires) { - Payload payload = Payloads.newByteSourcePayload(ByteSource.empty()); - payload.getContentMetadata().setContentLength(bytes); - payload.getContentMetadata().setContentType(contentType); - payload.getContentMetadata().setExpires(expires); - return payload; - } -} diff --git a/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/handlers/SwiftErrorHandler.java b/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/handlers/SwiftErrorHandler.java deleted file mode 100644 index 2bde41c980..0000000000 --- a/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/handlers/SwiftErrorHandler.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF 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.openstack.swift.v1.handlers; - -import static org.jclouds.http.HttpUtils.closeClientButKeepContentStream; - -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import org.jclouds.blobstore.ContainerNotFoundException; -import org.jclouds.blobstore.KeyNotFoundException; -import org.jclouds.http.HttpCommand; -import org.jclouds.http.HttpErrorHandler; -import org.jclouds.http.HttpResponse; -import org.jclouds.http.HttpResponseException; -import org.jclouds.openstack.swift.v1.CopyObjectException; -import org.jclouds.openstack.swift.v1.reference.SwiftHeaders; -import org.jclouds.rest.AuthorizationException; -import org.jclouds.rest.InsufficientResourcesException; - -// TODO: is there error spec someplace? let's type errors, etc. -public class SwiftErrorHandler implements HttpErrorHandler { - public static final String PREFIX = "^/v[0-9][^/]*/[a-zA-Z]+_[^/]+/"; - public static final Pattern CONTAINER_PATH = Pattern.compile(PREFIX + "([^/]+)$"); - public static final Pattern CONTAINER_KEY_PATH = Pattern.compile(PREFIX + "([^/]+)/(.*)"); - - public void handleError(HttpCommand command, HttpResponse response) { - // it is important to always read fully and close streams - byte[] data = closeClientButKeepContentStream(response); - String message = data != null ? new String(data) : null; - - Exception exception = message != null ? new HttpResponseException(command, response, message) - : new HttpResponseException(command, response); - message = message != null ? message : String.format("%s -> %s", command.getCurrentRequest().getRequestLine(), - response.getStatusLine()); - switch (response.getStatusCode()) { - case 401: - exception = new AuthorizationException(exception.getMessage(), exception); - break; - case 404: - Exception oldException = exception; - String sourcePath = command.getCurrentRequest().getFirstHeaderOrNull(SwiftHeaders.OBJECT_COPY_FROM); - if (sourcePath != null) { - // the path returned here is in the form "/v1/tenant-id/destContainer/destObject" - String path = command.getCurrentRequest().getEndpoint().getPath(); - int startOfDestinationPath = path.lastIndexOf("/", path.lastIndexOf("/") - 1); - // get the "/destContainer/destObject" portion of the path - String destinationPath = path.substring(startOfDestinationPath); - - exception = new CopyObjectException(sourcePath, destinationPath, message); - exception.initCause(oldException); - } else if (!command.getCurrentRequest().getMethod().equals("DELETE")) { - String path = command.getCurrentRequest().getEndpoint().getPath(); - Matcher matcher = CONTAINER_PATH.matcher(path); - - if (matcher.find()) { - exception = new ContainerNotFoundException(matcher.group(1), message); - exception.initCause(oldException); - } else { - matcher = CONTAINER_KEY_PATH.matcher(path); - if (matcher.find()) { - exception = new KeyNotFoundException(matcher.group(1), matcher.group(2), message); - exception.initCause(oldException); - } - } - } - break; - case 409: - exception = new IllegalStateException(exception.getMessage(), exception); - break; - case 413: - exception = new InsufficientResourcesException(exception.getMessage(), exception); - break; - } - command.setException(exception); - } -} diff --git a/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/options/CreateContainerOptions.java b/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/options/CreateContainerOptions.java deleted file mode 100644 index 2014f616d6..0000000000 --- a/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/options/CreateContainerOptions.java +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF 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.openstack.swift.v1.options; - -import static org.jclouds.openstack.swift.v1.reference.SwiftHeaders.CONTAINER_ACL_ANYBODY_READ; -import static org.jclouds.openstack.swift.v1.reference.SwiftHeaders.CONTAINER_METADATA_PREFIX; -import static org.jclouds.openstack.swift.v1.reference.SwiftHeaders.CONTAINER_READ; -import static org.jclouds.openstack.swift.v1.reference.SwiftHeaders.VERSIONS_LOCATION; - -import java.util.Map; - -import org.jclouds.http.options.BaseHttpRequestOptions; -import org.jclouds.openstack.swift.v1.binders.BindMetadataToHeaders; - -import com.google.common.collect.Multimap; - -/** - * Options for creating a {@link Container} - * - * @see ContainerApi#create(String, CreateContainerOptions) - */ -public class CreateContainerOptions extends BaseHttpRequestOptions { - - public static final CreateContainerOptions NONE = new CreateContainerOptions(); - - /** - * Sets the headers on a container at creation. - */ - public CreateContainerOptions headers(Multimap headers) { - this.headers.putAll(headers); - return this; - } - - /** - * Sets the metadata on a container at creation. - */ - public CreateContainerOptions metadata(Map metadata) { - this.headers.putAll(bindMetadataToHeaders.toHeaders(metadata)); - return this; - } - - /** - * Sets the public ACL on the container so that anybody can read it. - */ - public CreateContainerOptions anybodyRead() { - this.headers.put(CONTAINER_READ, CONTAINER_ACL_ANYBODY_READ); - return this; - } - - /** - * Sets the container that will contain object versions. - */ - public CreateContainerOptions versionsLocation(String containerName) { - this.headers.put(VERSIONS_LOCATION, containerName); - return this; - } - - public static class Builder { - - /** - * @see CreateContainerOptions#anybodyRead - */ - public static CreateContainerOptions anybodyRead() { - CreateContainerOptions options = new CreateContainerOptions(); - return options.anybodyRead(); - } - - /** - * @see CreateContainerOptions#headers - */ - public static CreateContainerOptions headers(Multimap headers) { - CreateContainerOptions options = new CreateContainerOptions(); - return options.headers(headers); - } - - /** - * @see CreateContainerOptions#metadata - */ - public static CreateContainerOptions metadata(Map metadata) { - CreateContainerOptions options = new CreateContainerOptions(); - return options.metadata(metadata); - } - - /** - * @see CreateContainerOptions#versionsLocation - */ - public static CreateContainerOptions versionsLocation(String containerName) { - CreateContainerOptions options = new CreateContainerOptions(); - return options.versionsLocation(containerName); - } - } - - private static final BindMetadataToHeaders bindMetadataToHeaders = new BindMetadataToHeaders(CONTAINER_METADATA_PREFIX); -} diff --git a/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/options/ListContainerOptions.java b/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/options/ListContainerOptions.java deleted file mode 100644 index 8b01aae725..0000000000 --- a/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/options/ListContainerOptions.java +++ /dev/null @@ -1,132 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF 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.openstack.swift.v1.options; - -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.base.Preconditions.checkState; - -import org.jclouds.http.options.BaseHttpRequestOptions; - -/** - * Options for listing containers. - * - * @see ContainerApi#list(ListContainerOptions) - */ -public class ListContainerOptions extends BaseHttpRequestOptions { - public static final ListContainerOptions NONE = new ListContainerOptions(); - - /** - * list operation returns no more than this amount. - */ - public ListContainerOptions limit(int limit) { - checkState(limit >= 0, "limit must be >= 0"); - checkState(limit <= 10000, "limit must be <= 10000"); - queryParameters.put("limit", Integer.toString(limit)); - return this; - } - - /** - * object names greater in value than the specified marker are returned. - */ - public ListContainerOptions marker(String marker) { - queryParameters.put("marker", checkNotNull(marker, "marker")); - return this; - } - - /** - * object names less in value than the specified marker are returned. - */ - public ListContainerOptions endMarker(String endMarker) { - queryParameters.put("end_marker", checkNotNull(endMarker, "endMarker")); - return this; - } - - /** - * object names beginning with this substring are returned. - */ - public ListContainerOptions prefix(String prefix) { - queryParameters.put("prefix", checkNotNull(prefix, "prefix")); - return this; - } - - /** - * object names nested in the container are returned. - */ - public ListContainerOptions delimiter(char delimiter) { - queryParameters.put("delimiter", Character.toString(delimiter)); - return this; - } - - /** - * object names nested in the pseudo path are returned. - */ - public ListContainerOptions path(String path) { - queryParameters.put("path", checkNotNull(path, "path")); - return this; - } - - public static class Builder { - - /** - * @see ListContainerOptions#limit - */ - public static ListContainerOptions limit(int limit) { - ListContainerOptions options = new ListContainerOptions(); - return options.limit(limit); - } - - /** - * @see ListContainerOptions#marker - */ - public static ListContainerOptions marker(String marker) { - ListContainerOptions options = new ListContainerOptions(); - return options.marker(marker); - } - - /** - * @see ListContainerOptions#endMarker - */ - public static ListContainerOptions endMarker(String endMarker) { - ListContainerOptions options = new ListContainerOptions(); - return options.endMarker(endMarker); - } - - /** - * @see ListContainerOptions#prefix - */ - public static ListContainerOptions prefix(String prefix) { - ListContainerOptions options = new ListContainerOptions(); - return options.prefix(prefix); - } - - /** - * @see ListContainerOptions#delimiter - */ - public static ListContainerOptions delimiter(char delimiter) { - ListContainerOptions options = new ListContainerOptions(); - return options.delimiter(delimiter); - } - - /** - * @see ListContainerOptions#path - */ - public static ListContainerOptions path(String path) { - ListContainerOptions options = new ListContainerOptions(); - return options.path(path); - } - } -} diff --git a/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/options/PutOptions.java b/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/options/PutOptions.java deleted file mode 100644 index d4a1ed3503..0000000000 --- a/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/options/PutOptions.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF 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.openstack.swift.v1.options; - -import static org.jclouds.openstack.swift.v1.reference.SwiftHeaders.OBJECT_METADATA_PREFIX; - -import java.util.Map; - -import org.jclouds.http.options.BaseHttpRequestOptions; -import org.jclouds.openstack.swift.v1.binders.BindMetadataToHeaders; - -import com.google.common.collect.Multimap; - -/** - * Options for creating an Object. - */ -public class PutOptions extends BaseHttpRequestOptions { - - public static final PutOptions NONE = new PutOptions(); - - /** - * Sets the metadata on a container at creation. - */ - public PutOptions metadata(Map metadata) { - this.headers.putAll(bindMetadataToHeaders.toHeaders(metadata)); - return this; - } - - /** - * Sets the headers on a container at creation. - */ - public PutOptions headers(Multimap headers) { - this.headers.putAll(headers); - return this; - } - - public static class Builder { - - /** - * @see PutOptions#headers - */ - public static PutOptions headers(Multimap headers) { - PutOptions options = new PutOptions(); - return options.headers(headers); - } - - /** - * @see PutOptions#metadata - */ - public static PutOptions metadata(Map metadata) { - PutOptions options = new PutOptions(); - return options.metadata(metadata); - } - } - - private static final BindMetadataToHeaders bindMetadataToHeaders = new BindMetadataToHeaders(OBJECT_METADATA_PREFIX); -} diff --git a/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/options/UpdateContainerOptions.java b/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/options/UpdateContainerOptions.java deleted file mode 100644 index f74b7fe18a..0000000000 --- a/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/options/UpdateContainerOptions.java +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF 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.openstack.swift.v1.options; - -import static org.jclouds.openstack.swift.v1.reference.SwiftHeaders.CONTAINER_ACL_ANYBODY_READ; -import static org.jclouds.openstack.swift.v1.reference.SwiftHeaders.CONTAINER_METADATA_PREFIX; -import static org.jclouds.openstack.swift.v1.reference.SwiftHeaders.CONTAINER_READ; -import static org.jclouds.openstack.swift.v1.reference.SwiftHeaders.VERSIONS_LOCATION; - -import java.util.Map; - -import org.jclouds.http.options.BaseHttpRequestOptions; -import org.jclouds.openstack.swift.v1.binders.BindMetadataToHeaders; - -import com.google.common.collect.Multimap; - -/** - * Options for updating a {@link Container}. - * - * @see org.jclouds.openstack.swift.v1.features.ContainerApi#update(String, UpdateContainerOptions) - */ -public class UpdateContainerOptions extends BaseHttpRequestOptions { - public static final UpdateContainerOptions NONE = new UpdateContainerOptions(); - - /** - * Sets the headers on a container at creation. - */ - public UpdateContainerOptions headers(Multimap headers) { - this.headers.putAll(headers); - return this; - } - - /** - * Sets the metadata on a container at creation. - */ - public UpdateContainerOptions metadata(Map metadata) { - this.headers.putAll(bindMetadataToHeaders.toHeaders(metadata)); - return this; - } - - /** - * Sets the public ACL on the container so that anybody can read it. - */ - public UpdateContainerOptions anybodyRead() { - this.headers.put(CONTAINER_READ, CONTAINER_ACL_ANYBODY_READ); - return this; - } - - /** - * Sets the container that will contain object versions. - */ - public UpdateContainerOptions versionsLocation(String containerName) { - this.headers.put(VERSIONS_LOCATION, containerName); - return this; - } - - public static class Builder { - - /** - * @see UpdateContainerOptions#anybodyRead - */ - public static UpdateContainerOptions anybodyRead() { - UpdateContainerOptions options = new UpdateContainerOptions(); - return options.anybodyRead(); - } - - /** - * @see UpdateContainerOptions#headers - */ - public static UpdateContainerOptions headers(Multimap headers) { - UpdateContainerOptions options = new UpdateContainerOptions(); - return options.headers(headers); - } - - /** - * @see UpdateContainerOptions#metadata - */ - public static UpdateContainerOptions metadata(Map metadata) { - UpdateContainerOptions options = new UpdateContainerOptions(); - return options.metadata(metadata); - } - - /** - * @see UpdateContainerOptions#versionsLocation - */ - public static UpdateContainerOptions versionsLocation(String containerName) { - UpdateContainerOptions options = new UpdateContainerOptions(); - return options.versionsLocation(containerName); - } - } - - private static final BindMetadataToHeaders bindMetadataToHeaders = new BindMetadataToHeaders(CONTAINER_METADATA_PREFIX); -} diff --git a/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/reference/SwiftHeaders.java b/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/reference/SwiftHeaders.java deleted file mode 100644 index bd889ec66b..0000000000 --- a/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/reference/SwiftHeaders.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF 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.openstack.swift.v1.reference; - -/** - * Common headers in Swift. - */ -public interface SwiftHeaders { - - // Common Metadata Prefixes - String ACCOUNT_METADATA_PREFIX = "X-Account-Meta-"; - String CONTAINER_METADATA_PREFIX = "X-Container-Meta-"; - String OBJECT_METADATA_PREFIX = "X-Object-Meta-"; - String USER_METADATA_PREFIX = OBJECT_METADATA_PREFIX; - - // Metadata Removal Prefixes - String ACCOUNT_REMOVE_METADATA_PREFIX = "X-Remove-Account-Meta-"; - String CONTAINER_REMOVE_METADATA_PREFIX = "X-Remove-Container-Meta-"; - String OBJECT_REMOVE_METADATA_PREFIX = "X-Remove-Object-Meta-"; - - // TempURL - String ACCOUNT_TEMPORARY_URL_KEY = ACCOUNT_METADATA_PREFIX + "Temp-Url-Key"; - String ACCOUNT_TEMPORARY_URL_KEY_2 = ACCOUNT_TEMPORARY_URL_KEY + "-2"; - - // Account Headers - String ACCOUNT_BYTES_USED = "X-Account-Bytes-Used"; - String ACCOUNT_CONTAINER_COUNT = "X-Account-Container-Count"; - String ACCOUNT_OBJECT_COUNT = "X-Account-Object-Count"; - - // Container Headers - String CONTAINER_BYTES_USED = "X-Container-Bytes-Used"; - String CONTAINER_OBJECT_COUNT = "X-Container-Object-Count"; - - // Public access - not supported in all Swift Impls - String CONTAINER_READ = "X-Container-Read"; - String CONTAINER_WRITE = "X-Container-Write"; - String CONTAINER_ACL_ANYBODY_READ = ".r:*,.rlistings"; - - // CORS - String CONTAINER_ACCESS_CONTROL_ALLOW_ORIGIN = CONTAINER_METADATA_PREFIX + "Access-Control-Allow-Origin"; - String CONTAINER_ACCESS_CONTROL_MAX_AGE = CONTAINER_METADATA_PREFIX + "Access-Control-Max-Age"; - String CONTAINER_ACCESS_CONTROL_EXPOSE_HEADERS = CONTAINER_METADATA_PREFIX + "Access-Control-Expose-Headers"; - - // Container Quota - String CONTAINER_QUOTA_BYTES = CONTAINER_METADATA_PREFIX + "Quota-Bytes"; - String CONTAINER_QUOTA_COUNT = CONTAINER_METADATA_PREFIX + "Quota-Count"; - - // Container Sync - String CONTAINER_SYNC_KEY = "X-Container-Sync-Key"; - String CONTAINER_SYNC_TO = "X-Container-Sync-To"; - - // Versioning - String VERSIONS_LOCATION = "X-Versions-Location"; - - /** - * @deprecated Please use {@link #VERSIONS_LOCATION}. This field will be removed in jclouds 1.8. - */ - @Deprecated - String CONTAINER_VERSIONS_LOCATION = "X-Versions-Location"; - - // Misc functionality - String CONTAINER_WEB_MODE = "X-Web-Mode"; - - String OBJECT_COPY_FROM = "X-Copy-From"; - String OBJECT_DELETE_AFTER = "X-Delete-After"; - String OBJECT_DELETE_AT = "X-Delete-At"; - String OBJECT_MANIFEST = "X-Object-Manifest"; - /** Get the newest version of the object for GET and HEAD requests */ - String OBJECT_NEWEST = "X-Newest"; - - // Static Large Object - String STATIC_LARGE_OBJECT = "X-Static-Large-Object"; - - // Static Web - String STATIC_WEB_INDEX = CONTAINER_METADATA_PREFIX + "Web-Index"; - String STATIC_WEB_DIRECTORY_TYPE = CONTAINER_METADATA_PREFIX + "Web-Directory-Type"; - String STATIC_WEB_ERROR = CONTAINER_METADATA_PREFIX + "Web-Error"; - String STATIC_WEB_LISTINGS = CONTAINER_METADATA_PREFIX + "Web-Listings"; - String STATIC_WEB_LISTINGS_CSS = CONTAINER_METADATA_PREFIX + "Web-Listings-CSS"; -} diff --git a/openstack-swift/src/main/resources/META-INF/services/org.jclouds.apis.ApiMetadata b/openstack-swift/src/main/resources/META-INF/services/org.jclouds.apis.ApiMetadata deleted file mode 100644 index c5b801728d..0000000000 --- a/openstack-swift/src/main/resources/META-INF/services/org.jclouds.apis.ApiMetadata +++ /dev/null @@ -1,18 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF 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. -# - -org.jclouds.openstack.swift.v1.SwiftApiMetadata diff --git a/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/AuthenticationMockTest.java b/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/AuthenticationMockTest.java deleted file mode 100644 index d80eea34e2..0000000000 --- a/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/AuthenticationMockTest.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF 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.openstack.swift.v1; - -import static com.google.common.base.Charsets.UTF_8; -import static org.jclouds.openstack.swift.v1.features.AccountApiMockTest.accountResponse; -import static org.testng.Assert.assertEquals; - -import java.util.Properties; - -import org.jclouds.openstack.v2_0.internal.BaseOpenStackMockTest; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; - -import com.squareup.okhttp.mockwebserver.MockResponse; -import com.squareup.okhttp.mockwebserver.MockWebServer; -import com.squareup.okhttp.mockwebserver.RecordedRequest; - -/** - * @see KeystoneProperties#CREDENTIAL_TYPE - */ -@Test -public class AuthenticationMockTest extends BaseOpenStackMockTest { - - @DataProvider(name = "jclouds.keystone.credential-type") - Object[][] credentialTypeToPostBody() { - Object[][] credentialTypeToPostBody = new Object[2][2]; - credentialTypeToPostBody[0][0] = "apiAccessKeyCredentials"; - credentialTypeToPostBody[0][1] = "{\"auth\":{\"apiAccessKeyCredentials\":{\"accessKey\":\"joe\",\"secretKey\":\"letmein\"},\"tenantName\":\"jclouds\"}}"; - credentialTypeToPostBody[1][0] = "passwordCredentials"; - credentialTypeToPostBody[1][1] = "{\"auth\":{\"passwordCredentials\":{\"username\":\"joe\",\"password\":\"letmein\"},\"tenantName\":\"jclouds\"}}"; - return credentialTypeToPostBody; - } - - @Test(dataProvider = "jclouds.keystone.credential-type") - public void authenticateCredentialType(String credentialType, String expectedPost) throws Exception { - MockWebServer server = mockOpenStackServer(); - server.enqueue(addCommonHeaders(new MockResponse().setBody(stringFromResource("/access.json")))); - server.enqueue(addCommonHeaders(accountResponse())); - - try { - Properties overrides = new Properties(); - overrides.setProperty("jclouds.keystone.credential-type", credentialType); - - SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift", overrides); - - api.getAccountApiForRegion("DFW").get(); - - assertEquals(server.getRequestCount(), 2); - RecordedRequest authRequest = server.takeRequest(); - assertEquals(authRequest.getRequestLine(), "POST /tokens HTTP/1.1"); - assertEquals(new String(authRequest.getBody(), UTF_8), expectedPost); - } finally { - server.shutdown(); - } - } -} diff --git a/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/SwiftApiMetadataTest.java b/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/SwiftApiMetadataTest.java deleted file mode 100644 index 6fbe4d974c..0000000000 --- a/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/SwiftApiMetadataTest.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF 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.openstack.swift.v1; - -import org.jclouds.View; -import org.jclouds.apis.internal.BaseApiMetadataTest; -import org.testng.annotations.Test; - -import com.google.common.collect.ImmutableSet; -import com.google.common.reflect.TypeToken; - -@Test(groups = "unit", testName = "SwiftApiMetadataTest") -// public class SwiftApiMetadataTest extends BaseBlobStoreApiMetadataTest { -public class SwiftApiMetadataTest extends BaseApiMetadataTest { - public SwiftApiMetadataTest() { - super(new SwiftApiMetadata(), ImmutableSet.> of()); - } -} diff --git a/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/SwiftErrorHandlerTest.java b/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/SwiftErrorHandlerTest.java deleted file mode 100644 index 703da9b455..0000000000 --- a/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/SwiftErrorHandlerTest.java +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF 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.openstack.swift.v1; - -import static org.easymock.EasyMock.createMock; -import static org.easymock.EasyMock.expect; -import static org.easymock.EasyMock.replay; -import static org.easymock.EasyMock.reportMatcher; -import static org.easymock.EasyMock.verify; -import static org.jclouds.io.Payloads.newByteSourcePayload; - -import java.net.URI; - -import org.easymock.IArgumentMatcher; -import org.jclouds.blobstore.ContainerNotFoundException; -import org.jclouds.blobstore.KeyNotFoundException; -import org.jclouds.http.HttpCommand; -import org.jclouds.http.HttpRequest; -import org.jclouds.http.HttpResponse; -import org.jclouds.openstack.swift.v1.handlers.SwiftErrorHandler; -import org.testng.annotations.Test; - -import com.google.common.io.ByteSource; - -/** - * Tests the {@link SwiftErrorHandler} - */ -@Test(groups = "unit", testName = "SwiftErrorHandlerTest") -public class SwiftErrorHandlerTest { - - @Test - public void test404SetsKeyNotFoundExceptionMosso() { - assertCodeMakes("HEAD", URI - .create("http://host/v1/MossoCloudFS_7064cdb1d49d4dcba3c899ac33e8409d/adriancole-blobstore1/key"), 404, - "Not Found", "", KeyNotFoundException.class); - } - - @Test - public void test404SetsKeyNotFoundExceptionSwift() { - assertCodeMakes("HEAD", URI - .create("http://67.202.39.175:8080/v1/AUTH_7064cdb1d49d4dcba3c899ac33e8409d/adriancole-blobstore1/key"), - 404, "Not Found", "", KeyNotFoundException.class); - } - - @Test - public void test404SetsContainerNotFoundExceptionMosso() { - assertCodeMakes("HEAD", URI - .create("http://host/v1/MossoCloudFS_7064cdb1d49d4dcba3c899ac33e8409d/adriancole-blobstore1"), 404, - "Not Found", "", ContainerNotFoundException.class); - } - - @Test - public void test404SetsContainerNotFoundExceptionSwift() { - assertCodeMakes("HEAD", URI - .create("http://67.202.39.175:8080/v1/AUTH_7064cdb1d49d4dcba3c899ac33e8409d/adriancole-blobstore1"), - 404, "Not Found", "", ContainerNotFoundException.class); - } - - private void assertCodeMakes(String method, URI uri, int statusCode, String message, String content, - Class expected) { - assertCodeMakes(method, uri, statusCode, message, "text/plain", content, expected); - } - - private void assertCodeMakes(String method, URI uri, int statusCode, String message, String contentType, - String content, Class expected) { - - SwiftErrorHandler function = new SwiftErrorHandler(); - - HttpCommand command = createMock(HttpCommand.class); - HttpRequest request = HttpRequest.builder().method(method).endpoint(uri).build(); - HttpResponse response = HttpResponse.builder().statusCode(statusCode).message(message) - .payload(newByteSourcePayload(ByteSource.wrap(content.getBytes()))).build(); - response.getPayload().getContentMetadata().setContentType(contentType); - - expect(command.getCurrentRequest()).andReturn(request).atLeastOnce(); - command.setException(classEq(expected)); - - replay(command); - - function.handleError(command, response); - - verify(command); - } - - public static Exception classEq(final Class in) { - reportMatcher(new IArgumentMatcher() { - - @Override - public void appendTo(StringBuffer buffer) { - buffer.append("classEq("); - buffer.append(in); - buffer.append(")"); - } - - @Override - public boolean matches(Object arg) { - return arg.getClass() == in; - } - - }); - return null; - } -} diff --git a/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/TemporaryUrlSignerLiveTest.java b/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/TemporaryUrlSignerLiveTest.java deleted file mode 100644 index bf2a4ff526..0000000000 --- a/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/TemporaryUrlSignerLiveTest.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF 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.openstack.swift.v1; - -import static java.lang.String.format; -import static org.jclouds.io.Payloads.newByteSourcePayload; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.fail; - -import java.io.IOException; -import java.io.InputStream; -import java.net.URI; -import java.util.UUID; - -import org.jclouds.openstack.swift.v1.domain.SwiftObject; -import org.jclouds.openstack.swift.v1.internal.BaseSwiftApiLiveTest; -import org.jclouds.util.Strings2; -import org.testng.annotations.AfterClass; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; - -import com.google.common.io.ByteSource; - -@Test(groups = "live", testName = "TemporaryUrlSignerLiveTest") -public class TemporaryUrlSignerLiveTest extends BaseSwiftApiLiveTest { - - private String name = getClass().getSimpleName(); - private String containerName = getClass().getSimpleName() + "Container"; - - public void signForPublicAccess() throws Exception { - for (String regionId : api.getConfiguredRegions()) { - SwiftObject object = api.getObjectApiForRegionAndContainer(regionId, containerName).get(name); - - long expires = System.currentTimeMillis() / 1000 + 5; - String signature = TemporaryUrlSigner.checkApiEvery(api.getAccountApiForRegion(regionId), 5) - .sign("GET", object.getUri().getPath(), expires); - - URI signed = URI.create(format("%s?temp_url_sig=%s&temp_url_expires=%s", object.getUri(), signature, expires)); - - InputStream publicStream = signed.toURL().openStream(); - assertEquals(Strings2.toStringAndClose(publicStream), "swifty"); - - // let it expire - Thread.sleep(5000); - try { - signed.toURL().openStream(); - fail("should have expired!"); - } catch (IOException e) { - } - } - } - - @Override - @BeforeClass(groups = "live") - public void setup() { - super.setup(); - String key = UUID.randomUUID().toString(); - for (String regionId : api.getConfiguredRegions()) { - api.getAccountApiForRegion(regionId).updateTemporaryUrlKey(key); - api.getContainerApiForRegion(regionId).create(containerName); - api.getObjectApiForRegionAndContainer(regionId, containerName) - .put(name, newByteSourcePayload(ByteSource.wrap("swifty".getBytes()))); - } - } - - @AfterMethod - @AfterClass(groups = "live") - public void tearDown() { - for (String regionId : api.getConfiguredRegions()) { - api.getObjectApiForRegionAndContainer(regionId, containerName).delete(name); - api.getContainerApiForRegion(regionId).deleteIfEmpty(containerName); - } - super.tearDown(); - } -} diff --git a/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/TemporaryUrlSignerMockTest.java b/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/TemporaryUrlSignerMockTest.java deleted file mode 100644 index 903d5ec1a0..0000000000 --- a/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/TemporaryUrlSignerMockTest.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF 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.openstack.swift.v1; - -import static org.jclouds.openstack.swift.v1.features.AccountApiMockTest.accountResponse; -import static org.jclouds.openstack.swift.v1.reference.SwiftHeaders.ACCOUNT_TEMPORARY_URL_KEY; -import static org.testng.Assert.assertEquals; - -import org.jclouds.openstack.v2_0.internal.BaseOpenStackMockTest; -import org.testng.annotations.Test; - -import com.squareup.okhttp.mockwebserver.MockResponse; -import com.squareup.okhttp.mockwebserver.MockWebServer; - -@Test(groups = "unit", testName = "TemporaryUrlSignerMockTest") -public class TemporaryUrlSignerMockTest extends BaseOpenStackMockTest { - - @Test(expectedExceptions = NullPointerException.class, expectedExceptionsMessageRegExp = "accountApi") - public void whenAccountApiIsNull() { - TemporaryUrlSigner.checkApiEvery(null, 10000); - } - - public void whenAccountApiHasKey() throws Exception { - MockWebServer server = mockOpenStackServer(); - server.enqueue(addCommonHeaders(new MockResponse().setBody(stringFromResource("/access.json")))); - server.enqueue(addCommonHeaders(accountResponse().addHeader(ACCOUNT_TEMPORARY_URL_KEY, "mykey"))); - - try { - SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift"); - String signature = TemporaryUrlSigner.checkApiEvery(api.getAccountApiForRegion("DFW"), 10000) - .sign("GET", "/v1/AUTH_account/container/object", 1323479485l); - - assertEquals(signature, "d9fc2067e52b06598421664cf6610bfc8fc431f6"); - - assertEquals(server.getRequestCount(), 2); - assertEquals(server.takeRequest().getRequestLine(), "POST /tokens HTTP/1.1"); - assertEquals(server.takeRequest().getRequestLine(), - "HEAD /v1/MossoCloudFS_5bcf396e-39dd-45ff-93a1-712b9aba90a9/ HTTP/1.1"); - } finally { - server.shutdown(); - } - } - - @Test(expectedExceptions = IllegalStateException.class, expectedExceptionsMessageRegExp = ".*returned a null temporaryUrlKey!") - public void whenAccountApiDoesntHaveKey() throws Exception { - MockWebServer server = mockOpenStackServer(); - server.enqueue(addCommonHeaders(new MockResponse().setBody(stringFromResource("/access.json")))); - server.enqueue(addCommonHeaders(accountResponse())); - - try { - SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift"); - TemporaryUrlSigner.checkApiEvery(api.accountApiInRegion("DFW"), 10000) - .sign("GET", "/v1/AUTH_account/container/object", 1323479485l); - } finally { - assertEquals(server.getRequestCount(), 2); - assertEquals(server.takeRequest().getRequestLine(), "POST /tokens HTTP/1.1"); - assertEquals(server.takeRequest().getRequestLine(), - "HEAD /v1/MossoCloudFS_5bcf396e-39dd-45ff-93a1-712b9aba90a9/ HTTP/1.1"); - server.shutdown(); - } - } -} diff --git a/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/blobstore/RegionScopedBlobStoreContextLiveTest.java b/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/blobstore/RegionScopedBlobStoreContextLiveTest.java deleted file mode 100644 index a762b8b46b..0000000000 --- a/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/blobstore/RegionScopedBlobStoreContextLiveTest.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF 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.openstack.swift.v1.blobstore; - -import static org.jclouds.openstack.keystone.v2_0.config.KeystoneProperties.CREDENTIAL_TYPE; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertFalse; -import static org.testng.Assert.assertNotNull; - -import java.util.Properties; -import java.util.Set; -import java.util.concurrent.ExecutionException; - -import org.jclouds.blobstore.BlobStore; -import org.jclouds.blobstore.domain.PageSet; -import org.jclouds.blobstore.domain.StorageMetadata; -import org.jclouds.blobstore.integration.internal.BaseBlobStoreIntegrationTest; -import org.jclouds.domain.Location; -import org.jclouds.http.HttpRequest; -import org.testng.annotations.Test; - -import com.google.common.collect.Iterables; - -@Test(groups = "live") -public class RegionScopedBlobStoreContextLiveTest extends BaseBlobStoreIntegrationTest { - - public RegionScopedBlobStoreContextLiveTest() { - provider = "openstack-swift"; - } - - @Override - protected Properties setupProperties() { - Properties props = super.setupProperties(); - setIfTestSystemPropertyPresent(props, CREDENTIAL_TYPE); - return props; - } - - @Test - public void regionsAreNotEmpty() { - assertFalse(RegionScopedBlobStoreContext.class.cast(view).getConfiguredRegions().isEmpty()); - } - - @Test - public void locationsMatch() { - RegionScopedBlobStoreContext ctx = RegionScopedBlobStoreContext.class.cast(view); - for (String regionId : ctx.getConfiguredRegions()) { - Set locations = ctx.getBlobStore(regionId).listAssignableLocations(); - assertEquals(locations.size(), 1, "expected one region " + regionId + " " + locations); - Location location = locations.iterator().next(); - assertEquals(location.getId(), regionId, "region id " + regionId + " didn't match getId(): " + location); - } - } - - @Test - public void tryList() throws InterruptedException, ExecutionException { - RegionScopedBlobStoreContext ctx = RegionScopedBlobStoreContext.class.cast(view); - for (String regionId : ctx.getConfiguredRegions()) { - ctx.getBlobStore(regionId).list(); - } - } - - @Test - public void trySign() throws InterruptedException, ExecutionException { - RegionScopedBlobStoreContext ctx = RegionScopedBlobStoreContext.class.cast(view); - for (String regionId : ctx.getConfiguredRegions()) { - BlobStore region = ctx.getBlobStore(regionId); - PageSet containers = region.list(); - if (containers.isEmpty()) { - continue; - } - String containerName = Iterables.getLast(containers).getName(); - PageSet blobs = region.list(containerName); - if (blobs.isEmpty()) { - continue; - } - String blobName = Iterables.getLast(blobs).getName(); - HttpRequest request = ctx.getSigner(regionId).signGetBlob(containerName, blobName); - assertNotNull(request, "regionId=" + regionId + ", container=" + containerName + ", blob=" + blobName); - } - } -} diff --git a/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/blobstore/integration/SwiftBlobIntegrationLiveTest.java b/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/blobstore/integration/SwiftBlobIntegrationLiveTest.java deleted file mode 100644 index 6d26100d16..0000000000 --- a/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/blobstore/integration/SwiftBlobIntegrationLiveTest.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF 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.openstack.swift.v1.blobstore.integration; - -import static org.jclouds.openstack.keystone.v2_0.config.KeystoneProperties.CREDENTIAL_TYPE; - -import java.util.Properties; - -import org.jclouds.blobstore.domain.Blob; -import org.jclouds.blobstore.integration.internal.BaseBlobIntegrationTest; -import org.testng.SkipException; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; - -@Test(groups = "live", testName = "SwiftBlobIntegrationLiveTest") -public class SwiftBlobIntegrationLiveTest extends BaseBlobIntegrationTest { - - public SwiftBlobIntegrationLiveTest() { - provider = "openstack-swift"; - } - - @Override - protected Properties setupProperties() { - Properties props = super.setupProperties(); - setIfTestSystemPropertyPresent(props, CREDENTIAL_TYPE); - return props; - } - - // Object/Container name contains forbidden chars from "<> - @Override - @DataProvider(name = "delete") - public Object[][] createData() { - return new Object[][] { { "normal" }, { "sp ace" }, { "qu?stion" }, { "unic₪de" }, { "path/foo" }, { "colon:" }, - { "asteri*k" }, { "p|pe" } }; - } - - @Override - public void testGetTwoRanges() { - throw new SkipException("unsupported in swift"); - } - - @Override - public void testCreateBlobWithExpiry() throws InterruptedException { - throw new SkipException("unsupported in swift"); - } - - @Test(groups = { "integration", "live" }) - public void testGetIfUnmodifiedSince() throws InterruptedException { - throw new SkipException("unsupported in swift"); - } - - @Override - protected int getIncorrectContentMD5StatusCode() { - return 422; - } - - @Override - protected void checkContentLanguage(Blob blob, String contentLanguage) { - assert blob.getPayload().getContentMetadata().getContentLanguage() == null; - assert blob.getMetadata().getContentMetadata().getContentLanguage() == null; - } -} diff --git a/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/blobstore/integration/SwiftBlobLiveTest.java b/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/blobstore/integration/SwiftBlobLiveTest.java deleted file mode 100644 index d9996bf43f..0000000000 --- a/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/blobstore/integration/SwiftBlobLiveTest.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF 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.openstack.swift.v1.blobstore.integration; - -import static org.jclouds.openstack.keystone.v2_0.config.KeystoneProperties.CREDENTIAL_TYPE; - -import java.util.Properties; - -import org.jclouds.blobstore.integration.internal.BaseBlobLiveTest; -import org.testng.annotations.Test; - -@Test(groups = "live", testName = "SwiftBlobLiveTest") -public class SwiftBlobLiveTest extends BaseBlobLiveTest { - - public SwiftBlobLiveTest() { - provider = "openstack-swift"; - } - - @Override - protected Properties setupProperties() { - Properties props = super.setupProperties(); - setIfTestSystemPropertyPresent(props, CREDENTIAL_TYPE); - return props; - } -} diff --git a/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/blobstore/integration/SwiftBlobSignerLiveTest.java b/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/blobstore/integration/SwiftBlobSignerLiveTest.java deleted file mode 100644 index 9dd603f7c2..0000000000 --- a/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/blobstore/integration/SwiftBlobSignerLiveTest.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF 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.openstack.swift.v1.blobstore.integration; - -import static org.jclouds.openstack.keystone.v2_0.config.KeystoneProperties.CREDENTIAL_TYPE; - -import java.util.Properties; - -import org.jclouds.blobstore.integration.internal.BaseBlobSignerLiveTest; -import org.testng.annotations.Test; - -@Test(groups = "live", testName = "SwiftBlobSignerLiveTest") -public class SwiftBlobSignerLiveTest extends BaseBlobSignerLiveTest { - - public SwiftBlobSignerLiveTest() { - provider = "openstack-swift"; - } - - @Override - protected Properties setupProperties() { - Properties props = super.setupProperties(); - setIfTestSystemPropertyPresent(props, CREDENTIAL_TYPE); - return props; - } -} diff --git a/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/blobstore/integration/SwiftContainerIntegrationLiveTest.java b/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/blobstore/integration/SwiftContainerIntegrationLiveTest.java deleted file mode 100644 index d954867c96..0000000000 --- a/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/blobstore/integration/SwiftContainerIntegrationLiveTest.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF 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.openstack.swift.v1.blobstore.integration; - -import static org.jclouds.openstack.keystone.v2_0.config.KeystoneProperties.CREDENTIAL_TYPE; -import static org.testng.Assert.assertTrue; - -import java.util.Properties; - -import org.jclouds.blobstore.integration.internal.BaseContainerIntegrationTest; -import org.testng.annotations.Test; - -@Test(groups = "live", testName = "SwiftContainerIntegrationLiveTest") -public class SwiftContainerIntegrationLiveTest extends BaseContainerIntegrationTest { - - public SwiftContainerIntegrationLiveTest() { - provider = "openstack-swift"; - } - - @Override - protected Properties setupProperties() { - Properties props = super.setupProperties(); - setIfTestSystemPropertyPresent(props, CREDENTIAL_TYPE); - return props; - } - - @Override - public void testListRootUsesDelimiter() throws InterruptedException { - try { - super.testListRootUsesDelimiter(); - } catch (AssertionError e) { - // swift doesn't have the "common prefixes" in the response that s3 - // does. If we wanted this to pass, we'd need to create - // pseudo-directories implicitly, which is costly and troublesome. It - // is better to fail this assertion. - assertTrue(e.getMessage().matches(".*16.* but .*15.*"), e.getMessage()); - // ^^ squishy regex to deal with various formats of testng messages. - } - } -} diff --git a/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/blobstore/integration/SwiftContainerLiveTest.java b/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/blobstore/integration/SwiftContainerLiveTest.java deleted file mode 100644 index 9bd85d6f5f..0000000000 --- a/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/blobstore/integration/SwiftContainerLiveTest.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF 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.openstack.swift.v1.blobstore.integration; - -import static org.jclouds.openstack.keystone.v2_0.config.KeystoneProperties.CREDENTIAL_TYPE; - -import java.util.Properties; - -import org.jclouds.blobstore.integration.internal.BaseContainerLiveTest; -import org.testng.annotations.Test; - -@Test(groups = "live", testName = "SwiftContainerLiveTest") -public class SwiftContainerLiveTest extends BaseContainerLiveTest { - - public SwiftContainerLiveTest() { - provider = "openstack-swift"; - } - - @Override - protected Properties setupProperties() { - Properties props = super.setupProperties(); - setIfTestSystemPropertyPresent(props, CREDENTIAL_TYPE); - return props; - } -} diff --git a/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/blobstore/integration/SwiftServiceIntegrationLiveTest.java b/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/blobstore/integration/SwiftServiceIntegrationLiveTest.java deleted file mode 100644 index 1da1a68d3e..0000000000 --- a/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/blobstore/integration/SwiftServiceIntegrationLiveTest.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF 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.openstack.swift.v1.blobstore.integration; - -import static org.jclouds.openstack.keystone.v2_0.config.KeystoneProperties.CREDENTIAL_TYPE; - -import java.util.Properties; - -import org.jclouds.blobstore.integration.internal.BaseServiceIntegrationTest; -import org.testng.annotations.Test; - -@Test(groups = "live", testName = "SwiftServiceIntegrationLiveTest") -public class SwiftServiceIntegrationLiveTest extends BaseServiceIntegrationTest { - - public SwiftServiceIntegrationLiveTest() { - provider = "openstack-swift"; - } - - @Override - protected Properties setupProperties() { - Properties props = super.setupProperties(); - setIfTestSystemPropertyPresent(props, CREDENTIAL_TYPE); - return props; - } -} diff --git a/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/config/SwiftTypeAdaptersTest.java b/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/config/SwiftTypeAdaptersTest.java deleted file mode 100644 index e4225fcab5..0000000000 --- a/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/config/SwiftTypeAdaptersTest.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF 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.openstack.swift.v1.config; - -import static org.testng.Assert.assertEquals; - -import org.jclouds.openstack.swift.v1.config.SwiftTypeAdapters.BulkDeleteResponseAdapter; -import org.jclouds.openstack.swift.v1.config.SwiftTypeAdapters.ExtractArchiveResponseAdapter; -import org.jclouds.openstack.swift.v1.domain.BulkDeleteResponse; -import org.jclouds.openstack.swift.v1.domain.ExtractArchiveResponse; -import org.testng.annotations.Test; - -import com.google.common.collect.ImmutableMap; -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; - -@Test -public class SwiftTypeAdaptersTest { - Gson gson = new GsonBuilder() - .registerTypeAdapter(ExtractArchiveResponse.class, new ExtractArchiveResponseAdapter()) - .registerTypeAdapter(BulkDeleteResponse.class, new BulkDeleteResponseAdapter()) - .create(); - - public void extractArchiveWithoutErrors() { - assertEquals(gson.fromJson("" - + "{\n" - + " \"Response Status\": \"201 Created\",\n" - + " \"Response Body\": \"\",\n" - + " \"Errors\": [],\n" - + " \"Number Files Created\": 10\n" - + "}", ExtractArchiveResponse.class), ExtractArchiveResponse.create(10, ImmutableMap. of())); - } - - public void extractArchiveWithErrorsAndDecodesPaths() { - assertEquals( - gson.fromJson("" - + "{\n" - + " \"Response Status\": \"201 Created\",\n" - + " \"Response Body\": \"\",\n" - + " \"Errors\": [\n" - + " [\"/v1/12345678912345/mycontainer/home/xx%3Cyy\", \"400 Bad Request\"],\n" - + " [\"/v1/12345678912345/mycontainer/../image.gif\", \"400 Bad Request\"]\n" - + " ],\n" - + " \"Number Files Created\": 8\n" - + "}", ExtractArchiveResponse.class), - ExtractArchiveResponse.create( - 8, - ImmutableMap. builder() - .put("/v1/12345678912345/mycontainer/home/xx of())); - } - - public void bulkDeleteWithErrorsAndDecodesPaths() { - assertEquals(gson.fromJson("" - + "{\n" - + " \"Response Status\": \"400 Bad Request\",\n" - + " \"Response Body\": \"\",\n" - + " \"Errors\": [\n" - + " [\"/v1/12345678912345/Not%20Empty\", \"409 Conflict\"]" - + " ],\n" - + " \"Number Deleted\": 0\n" - + "}", BulkDeleteResponse.class), - BulkDeleteResponse.create(0, 0, ImmutableMap.of("/v1/12345678912345/Not Empty", "409 Conflict"))); - } -} diff --git a/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/AccountApiLiveTest.java b/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/AccountApiLiveTest.java deleted file mode 100644 index c62d23805f..0000000000 --- a/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/AccountApiLiveTest.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF 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.openstack.swift.v1.features; - -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertFalse; -import static org.testng.Assert.assertNotNull; -import static org.testng.Assert.assertTrue; - -import java.util.Map; -import java.util.Map.Entry; - -import org.jclouds.openstack.swift.v1.SwiftApi; -import org.jclouds.openstack.swift.v1.domain.Account; -import org.jclouds.openstack.swift.v1.internal.BaseSwiftApiLiveTest; -import org.testng.annotations.Test; - -import com.google.common.collect.ImmutableMap; - -@Test(groups = "live", testName = "AccountApiLiveTest") -public class AccountApiLiveTest extends BaseSwiftApiLiveTest { - - public void testGet() throws Exception { - for (String regionId : regions) { - AccountApi accountApi = api.getAccountApiForRegion(regionId); - Account account = accountApi.get(); - - assertNotNull(account); - assertTrue(account.getContainerCount() >= 0); - assertTrue(account.getObjectCount() >= 0); - assertTrue(account.getBytesUsed() >= 0); - } - } - - public void testUpdateMetadata() throws Exception { - for (String regionId : regions) { - AccountApi accountApi = api.getAccountApiForRegion(regionId); - - Map meta = ImmutableMap.of("MyAdd1", "foo", "MyAdd2", "bar"); - - assertTrue(accountApi.updateMetadata(meta)); - - accountHasMetadata(accountApi, meta); - } - } - - public void testDeleteMetadata() throws Exception { - for (String regionId : regions) { - AccountApi accountApi = api.getAccountApiForRegion(regionId); - - Map meta = ImmutableMap.of("MyDelete1", "foo", "MyDelete2", "bar"); - - assertTrue(accountApi.updateMetadata(meta)); - accountHasMetadata(accountApi, meta); - - assertTrue(accountApi.deleteMetadata(meta)); - Account account = accountApi.get(); - for (Entry entry : meta.entrySet()) { - // note keys are returned in lower-case! - assertFalse(account.getMetadata().containsKey(entry.getKey().toLowerCase())); - } - } - } - - static void accountHasMetadata(AccountApi accountApi, Map meta) { - Account account = accountApi.get(); - for (Entry entry : meta.entrySet()) { - // note keys are returned in lower-case! - assertEquals(account.getMetadata().get(entry.getKey().toLowerCase()), entry.getValue(), - account + " didn't have metadata: " + entry); - } - } -} diff --git a/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/AccountApiMockTest.java b/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/AccountApiMockTest.java deleted file mode 100644 index 3e57527d47..0000000000 --- a/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/AccountApiMockTest.java +++ /dev/null @@ -1,145 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF 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.openstack.swift.v1.features; - -import static org.jclouds.openstack.swift.v1.reference.SwiftHeaders.ACCOUNT_BYTES_USED; -import static org.jclouds.openstack.swift.v1.reference.SwiftHeaders.ACCOUNT_CONTAINER_COUNT; -import static org.jclouds.openstack.swift.v1.reference.SwiftHeaders.ACCOUNT_METADATA_PREFIX; -import static org.jclouds.openstack.swift.v1.reference.SwiftHeaders.ACCOUNT_OBJECT_COUNT; -import static org.jclouds.openstack.swift.v1.reference.SwiftHeaders.ACCOUNT_REMOVE_METADATA_PREFIX; -import static org.jclouds.openstack.swift.v1.reference.SwiftHeaders.ACCOUNT_TEMPORARY_URL_KEY; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertTrue; - -import java.util.Map; -import java.util.Map.Entry; - -import org.jclouds.openstack.swift.v1.SwiftApi; -import org.jclouds.openstack.swift.v1.domain.Account; -import org.jclouds.openstack.v2_0.internal.BaseOpenStackMockTest; -import org.testng.annotations.Test; - -import com.google.common.collect.ImmutableMap; -import com.squareup.okhttp.mockwebserver.MockResponse; -import com.squareup.okhttp.mockwebserver.MockWebServer; -import com.squareup.okhttp.mockwebserver.RecordedRequest; - -@Test(groups = "unit", testName = "AccountApiMockTest") -public class AccountApiMockTest extends BaseOpenStackMockTest { - - /** upper-cases first char, and lower-cases rest!! **/ - public void getKnowingServerMessesWithMetadataKeyCaseFormat() throws Exception { - MockWebServer server = mockOpenStackServer(); - server.enqueue(addCommonHeaders(new MockResponse().setBody(stringFromResource("/access.json")))); - server.enqueue(addCommonHeaders(accountResponse() - // note silly casing - .addHeader(ACCOUNT_METADATA_PREFIX + "Apiname", "swift") - .addHeader(ACCOUNT_METADATA_PREFIX + "Apiversion", "v1.1"))); - - try { - SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift"); - Account account = api.getAccountApiForRegion("DFW").get(); - assertEquals(account.getContainerCount(), 3l); - assertEquals(account.getObjectCount(), 42l); - assertEquals(account.getBytesUsed(), 323479l); - for (Entry entry : metadata.entrySet()) { - assertEquals(account.getMetadata().get(entry.getKey().toLowerCase()), entry.getValue()); - } - - assertEquals(server.getRequestCount(), 2); - assertAuthentication(server); - assertRequest(server.takeRequest(), "HEAD", "/v1/MossoCloudFS_5bcf396e-39dd-45ff-93a1-712b9aba90a9/"); - } finally { - server.shutdown(); - } - } - - public void updateMetadata() throws Exception { - MockWebServer server = mockOpenStackServer(); - server.enqueue(addCommonHeaders(new MockResponse().setBody(stringFromResource("/access.json")))); - server.enqueue(addCommonHeaders(accountResponse() - .addHeader(ACCOUNT_METADATA_PREFIX + "ApiName", "swift") - .addHeader(ACCOUNT_METADATA_PREFIX + "ApiVersion", "v1.1"))); - - try { - SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift"); - assertTrue(api.getAccountApiForRegion("DFW").updateMetadata(metadata)); - - assertEquals(server.getRequestCount(), 2); - assertAuthentication(server); - - RecordedRequest replaceRequest = server.takeRequest(); - assertRequest(replaceRequest, "POST", "/v1/MossoCloudFS_5bcf396e-39dd-45ff-93a1-712b9aba90a9/"); - for (Entry entry : metadata.entrySet()) { - assertEquals(replaceRequest.getHeader(ACCOUNT_METADATA_PREFIX + entry.getKey().toLowerCase()), entry.getValue()); - } - } finally { - server.shutdown(); - } - } - - public void updateTemporaryUrlKey() throws Exception { - MockWebServer server = mockOpenStackServer(); - server.enqueue(addCommonHeaders(new MockResponse().setBody(stringFromResource("/access.json")))); - server.enqueue(addCommonHeaders(accountResponse())); - - try { - SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift"); - assertTrue(api.getAccountApiForRegion("DFW").updateTemporaryUrlKey("foobar")); - - assertEquals(server.getRequestCount(), 2); - assertAuthentication(server); - - RecordedRequest replaceRequest = server.takeRequest(); - assertRequest(replaceRequest, "POST", "/v1/MossoCloudFS_5bcf396e-39dd-45ff-93a1-712b9aba90a9/"); - assertEquals(replaceRequest.getHeader(ACCOUNT_TEMPORARY_URL_KEY), "foobar"); - } finally { - server.shutdown(); - } - } - - public void deleteMetadata() throws Exception { - MockWebServer server = mockOpenStackServer(); - server.enqueue(addCommonHeaders(new MockResponse().setBody(stringFromResource("/access.json")))); - server.enqueue(addCommonHeaders(accountResponse())); - - try { - SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift"); - assertTrue(api.getAccountApiForRegion("DFW").deleteMetadata(metadata)); - - assertEquals(server.getRequestCount(), 2); - assertEquals(server.takeRequest().getRequestLine(), "POST /tokens HTTP/1.1"); - RecordedRequest deleteRequest = server.takeRequest(); - assertEquals(deleteRequest.getRequestLine(), - "POST /v1/MossoCloudFS_5bcf396e-39dd-45ff-93a1-712b9aba90a9/ HTTP/1.1"); - for (String key : metadata.keySet()) { - assertEquals(deleteRequest.getHeader(ACCOUNT_REMOVE_METADATA_PREFIX + key.toLowerCase()), "ignored"); - } - } finally { - server.shutdown(); - } - } - - private static final Map metadata = ImmutableMap.of("ApiName", "swift", "ApiVersion", "v1.1"); - - public static MockResponse accountResponse() { - return new MockResponse() - .addHeader(ACCOUNT_CONTAINER_COUNT, "3") - .addHeader(ACCOUNT_OBJECT_COUNT, "42") - .addHeader(ACCOUNT_BYTES_USED, "323479"); - } -} diff --git a/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/BulkApiLiveTest.java b/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/BulkApiLiveTest.java deleted file mode 100644 index bf313d7ee7..0000000000 --- a/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/BulkApiLiveTest.java +++ /dev/null @@ -1,125 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF 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.openstack.swift.v1.features; - -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertTrue; - -import java.io.IOException; -import java.util.List; -import java.util.UUID; - -import org.jboss.shrinkwrap.api.GenericArchive; -import org.jboss.shrinkwrap.api.ShrinkWrap; -import org.jboss.shrinkwrap.api.asset.StringAsset; -import org.jboss.shrinkwrap.api.exporter.TarGzExporter; -import org.jclouds.io.ByteStreams2; -import org.jclouds.io.Payload; -import org.jclouds.io.payloads.ByteSourcePayload; -import org.jclouds.openstack.swift.v1.SwiftApi; -import org.jclouds.openstack.swift.v1.domain.BulkDeleteResponse; -import org.jclouds.openstack.swift.v1.domain.ExtractArchiveResponse; -import org.jclouds.openstack.swift.v1.internal.BaseSwiftApiLiveTest; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; - -import com.google.common.base.Throwables; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.Lists; -import com.google.common.io.ByteSource; - -@Test(groups = "live", testName = "BulkApiLiveTest") -public class BulkApiLiveTest extends BaseSwiftApiLiveTest { - - private static final int OBJECT_COUNT = 10; - private String containerName = getClass().getSimpleName(); - List paths = Lists.newArrayList(); - byte[] tarGz; - - public void testNotPresentWhenDeleting() throws Exception { - for (String regionId : regions) { - BulkDeleteResponse deleteResponse = api.getBulkApiForRegion(regionId).bulkDelete( - ImmutableList.of(UUID.randomUUID().toString())); - assertEquals(deleteResponse.getDeleted(), 0); - assertEquals(deleteResponse.getNotFound(), 1); - assertTrue(deleteResponse.getErrors().isEmpty()); - } - } - - public void testExtractArchive() throws Exception { - for (String regionId : regions) { - Payload payload = new ByteSourcePayload(ByteSource.wrap(tarGz)); - - ExtractArchiveResponse extractResponse = api.getBulkApiForRegion(regionId) - .extractArchive(containerName, payload, "tar.gz"); - assertEquals(extractResponse.getCreated(), OBJECT_COUNT); - assertTrue(extractResponse.getErrors().isEmpty()); - assertEquals(api.getContainerApiForRegion(regionId).get(containerName).getObjectCount(), OBJECT_COUNT); - - // repeat the command - extractResponse = api.getBulkApiForRegion(regionId).extractArchive(containerName, payload, "tar.gz"); - assertEquals(extractResponse.getCreated(), OBJECT_COUNT); - assertTrue(extractResponse.getErrors().isEmpty()); - } - } - - @Test(dependsOnMethods = "testExtractArchive") - public void testBulkDelete() throws Exception { - for (String regionId : regions) { - BulkDeleteResponse deleteResponse = api.getBulkApiForRegion(regionId).bulkDelete(paths); - assertEquals(deleteResponse.getDeleted(), OBJECT_COUNT); - assertEquals(deleteResponse.getNotFound(), 0); - assertTrue(deleteResponse.getErrors().isEmpty()); - assertEquals(api.getContainerApiForRegion(regionId).get(containerName).getObjectCount(), 0); - } - } - - @Override - @BeforeClass(groups = "live") - public void setup() { - super.setup(); - for (String regionId : regions) { - boolean created = api.getContainerApiForRegion(regionId).create(containerName); - if (!created) { - deleteAllObjectsInContainer(regionId, containerName); - } - } - GenericArchive files = ShrinkWrap.create(GenericArchive.class, "files.tar.gz"); - StringAsset content = new StringAsset("foo"); - for (int i = 0; i < OBJECT_COUNT; i++) { - paths.add(containerName + "/file" + i); - files.add(content, "/file" + i); - } - - try { - tarGz = ByteStreams2.toByteArrayAndClose(files.as(TarGzExporter.class).exportAsInputStream()); - } catch (IOException e) { - throw Throwables.propagate(e); - } - } - - @Override - @AfterClass(groups = "live") - public void tearDown() { - for (String regionId : regions) { - deleteAllObjectsInContainer(regionId, containerName); - api.getContainerApiForRegion(regionId).deleteIfEmpty(containerName); - } - super.tearDown(); - } -} diff --git a/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/BulkApiMockTest.java b/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/BulkApiMockTest.java deleted file mode 100644 index 5b7a5201e5..0000000000 --- a/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/BulkApiMockTest.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF 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.openstack.swift.v1.features; - -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertTrue; - -import org.jboss.shrinkwrap.api.GenericArchive; -import org.jboss.shrinkwrap.api.ShrinkWrap; -import org.jboss.shrinkwrap.api.asset.StringAsset; -import org.jboss.shrinkwrap.api.exporter.TarGzExporter; -import org.jclouds.io.ByteStreams2; -import org.jclouds.io.Payload; -import org.jclouds.io.Payloads; -import org.jclouds.openstack.swift.v1.SwiftApi; -import org.jclouds.openstack.swift.v1.domain.ExtractArchiveResponse; -import org.jclouds.openstack.v2_0.internal.BaseOpenStackMockTest; -import org.testng.annotations.Test; - -import com.google.common.io.ByteSource; -import com.squareup.okhttp.mockwebserver.MockResponse; -import com.squareup.okhttp.mockwebserver.MockWebServer; -import com.squareup.okhttp.mockwebserver.RecordedRequest; - -@Test(groups = "unit", testName = "BulkApiMockTest") -public class BulkApiMockTest extends BaseOpenStackMockTest { - - public void testExtractArchive() throws Exception { - GenericArchive files = ShrinkWrap.create(GenericArchive.class, "files.tar.gz"); - StringAsset content = new StringAsset("foo"); - for (int i = 0; i < 10; i++) { - files.add(content, "/file" + i); - } - - byte[] tarGz = ByteStreams2.toByteArrayAndClose(files.as(TarGzExporter.class).exportAsInputStream()); - - MockWebServer server = mockOpenStackServer(); - server.enqueue(addCommonHeaders(new MockResponse().setBody(stringFromResource("/access.json")))); - server.enqueue(addCommonHeaders(new MockResponse().setResponseCode(201).setBody("{\"Number Files Created\": 10, \"Errors\": []}"))); - - try { - SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift"); - Payload payload = Payloads.newByteSourcePayload(ByteSource.wrap(tarGz)); - ExtractArchiveResponse response = api.getBulkApiForRegion("DFW").extractArchive("myContainer", payload, "tar.gz"); - - assertEquals(response.getCreated(), 10); - assertTrue(response.getErrors().isEmpty()); - - assertEquals(server.getRequestCount(), 2); - assertAuthentication(server); - RecordedRequest extractRequest = server.takeRequest(); - assertRequest(extractRequest, "PUT", "/v1/MossoCloudFS_5bcf396e-39dd-45ff-93a1-712b9aba90a9/myContainer?extract-archive=tar.gz"); - assertEquals(extractRequest.getBody(), tarGz); - } finally { - server.shutdown(); - } - } -} diff --git a/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/ContainerApiLiveTest.java b/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/ContainerApiLiveTest.java deleted file mode 100644 index 04585a017f..0000000000 --- a/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/ContainerApiLiveTest.java +++ /dev/null @@ -1,197 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF 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.openstack.swift.v1.features; - -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertFalse; -import static org.testng.Assert.assertNotNull; -import static org.testng.Assert.assertTrue; - -import java.util.Map; -import java.util.Map.Entry; - -import org.jclouds.openstack.swift.v1.SwiftApi; -import org.jclouds.openstack.swift.v1.domain.Container; -import org.jclouds.openstack.swift.v1.internal.BaseSwiftApiLiveTest; -import org.jclouds.openstack.swift.v1.options.CreateContainerOptions; -import org.jclouds.openstack.swift.v1.options.ListContainerOptions; -import org.jclouds.openstack.swift.v1.options.UpdateContainerOptions; -import org.jclouds.openstack.swift.v1.reference.SwiftHeaders; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; - -import com.google.common.collect.FluentIterable; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableMultimap; - -/** - * Provides live tests for the {@link ContainerApi}. - */ -@Test(groups = "live", testName = "ContainerApiLiveTest") -public class ContainerApiLiveTest extends BaseSwiftApiLiveTest { - - private String name = getClass().getSimpleName(); - - public void testCreateWithOptions() throws Exception { - for (String regionId : regions) { - ImmutableMultimap headers = - ImmutableMultimap.of(SwiftHeaders.STATIC_WEB_INDEX, "__index.html", - SwiftHeaders.STATIC_WEB_ERROR, "__error.html"); - CreateContainerOptions opts = new CreateContainerOptions().headers(headers); - - assertNotNull(api.getContainerApiForRegion(regionId).create(name, opts)); - - Container container = api.getContainerApiForRegion(regionId).get(name); - assertNotNull(container); - assertEquals(container.getName(), name); - assertEquals(container.getMetadata().size(), 2); - assertEquals(container.getMetadata().get("web-index"), "__index.html"); - assertEquals(container.getMetadata().get("web-error"), "__error.html"); - - assertTrue(api.getContainerApiForRegion(regionId).deleteIfEmpty(name)); - } - } - - public void testCreateWithSpacesAndSpecialCharacters() throws Exception { - final String nameWithSpaces = "container # ! special"; - - for (String regionId : regions) { - assertTrue(api.getContainerApiForRegion(regionId).create(nameWithSpaces)); - Container container = api.getContainerApiForRegion(regionId).get(nameWithSpaces); - assertNotNull(container); - assertEquals(container.getName(), nameWithSpaces); - - assertTrue(api.getContainerApiForRegion(regionId).deleteIfEmpty(nameWithSpaces)); - } - } - - public void testList() throws Exception { - for (String regionId : regions) { - ContainerApi containerApi = api.getContainerApiForRegion(regionId); - FluentIterable response = containerApi.list(); - assertNotNull(response); - for (Container container : response) { - assertNotNull(container.getName()); - assertTrue(container.getObjectCount() >= 0); - assertTrue(container.getBytesUsed() >= 0); - } - } - } - - public void testListWithOptions() throws Exception { - String lexicographicallyBeforeName = name.substring(0, name.length() - 1); - for (String regionId : regions) { - ListContainerOptions options = ListContainerOptions.Builder.marker(lexicographicallyBeforeName); - Container container = api.getContainerApiForRegion(regionId).list(options).get(0); - assertEquals(container.getName(), name); - assertTrue(container.getObjectCount() == 0); - assertTrue(container.getBytesUsed() == 0); - } - } - - public void testUpdate() throws Exception { - for (String regionId : regions) { - ImmutableMultimap headers = - ImmutableMultimap.of(SwiftHeaders.STATIC_WEB_INDEX, "__index.html", - SwiftHeaders.STATIC_WEB_ERROR, "__error.html"); - UpdateContainerOptions opts = new UpdateContainerOptions().headers(headers); - - assertNotNull(api.getContainerApiForRegion(regionId).create(name)); - - Container container = api.getContainerApiForRegion(regionId).get(name); - assertNotNull(container); - assertEquals(container.getName(), name); - assertTrue(container.getMetadata().isEmpty()); - - assertNotNull(api.getContainerApiForRegion(regionId).update(name, opts)); - - Container updatedContainer = api.getContainerApiForRegion(regionId).get(name); - assertNotNull(updatedContainer); - assertEquals(updatedContainer.getName(), name); - assertEquals(updatedContainer.getMetadata().size(), 2); - assertEquals(updatedContainer.getMetadata().get("web-index"), "__index.html"); - assertEquals(updatedContainer.getMetadata().get("web-error"), "__error.html"); - - assertTrue(api.getContainerApiForRegion(regionId).deleteIfEmpty(name)); - } - } - - public void testGet() throws Exception { - for (String regionId : regions) { - Container container = api.getContainerApiForRegion(regionId).get(name); - assertEquals(container.getName(), name); - assertTrue(container.getObjectCount() == 0); - assertTrue(container.getBytesUsed() == 0); - } - } - - public void testUpdateMetadata() throws Exception { - Map meta = ImmutableMap.of("MyAdd1", "foo", "MyAdd2", "bar"); - - for (String regionId : regions) { - ContainerApi containerApi = api.getContainerApiForRegion(regionId); - assertTrue(containerApi.updateMetadata(name, meta)); - containerHasMetadata(containerApi, name, meta); - } - } - - public void testDeleteMetadata() throws Exception { - Map meta = ImmutableMap.of("MyDelete1", "foo", "MyDelete2", "bar"); - - for (String regionId : regions) { - ContainerApi containerApi = api.getContainerApiForRegion(regionId); - // update - assertTrue(containerApi.updateMetadata(name, meta)); - containerHasMetadata(containerApi, name, meta); - // delete - assertTrue(containerApi.deleteMetadata(name, meta)); - Container container = containerApi.get(name); - for (Entry entry : meta.entrySet()) { - // note keys are returned in lower-case! - assertFalse(container.getMetadata().containsKey(entry.getKey().toLowerCase())); - } - } - } - - static void containerHasMetadata(ContainerApi containerApi, String name, Map meta) { - Container container = containerApi.get(name); - for (Entry entry : meta.entrySet()) { - // note keys are returned in lower-case! - assertEquals(container.getMetadata().get(entry.getKey().toLowerCase()), entry.getValue(), - container + " didn't have metadata: " + entry); - } - } - - @Override - @BeforeClass(groups = "live") - public void setup() { - super.setup(); - for (String regionId : regions) { - api.getContainerApiForRegion(regionId).create(name); - } - } - - @Override - @AfterClass(groups = "live") - public void tearDown() { - for (String regionId : regions) { - api.getContainerApiForRegion(regionId).deleteIfEmpty(name); - } - super.tearDown(); - } -} diff --git a/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/ContainerApiMockTest.java b/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/ContainerApiMockTest.java deleted file mode 100644 index 73cf6b32ee..0000000000 --- a/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/ContainerApiMockTest.java +++ /dev/null @@ -1,364 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF 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.openstack.swift.v1.features; - -import static org.jclouds.openstack.swift.v1.options.CreateContainerOptions.Builder.anybodyRead; -import static org.jclouds.openstack.swift.v1.reference.SwiftHeaders.CONTAINER_ACL_ANYBODY_READ; -import static org.jclouds.openstack.swift.v1.reference.SwiftHeaders.CONTAINER_BYTES_USED; -import static org.jclouds.openstack.swift.v1.reference.SwiftHeaders.CONTAINER_METADATA_PREFIX; -import static org.jclouds.openstack.swift.v1.reference.SwiftHeaders.CONTAINER_OBJECT_COUNT; -import static org.jclouds.openstack.swift.v1.reference.SwiftHeaders.CONTAINER_READ; -import static org.jclouds.openstack.swift.v1.reference.SwiftHeaders.CONTAINER_REMOVE_METADATA_PREFIX; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertFalse; -import static org.testng.Assert.assertNotNull; -import static org.testng.Assert.assertTrue; - -import java.util.Map; -import java.util.Map.Entry; - -import org.jclouds.blobstore.ContainerNotFoundException; -import org.jclouds.openstack.swift.v1.SwiftApi; -import org.jclouds.openstack.swift.v1.domain.Container; -import org.jclouds.openstack.swift.v1.options.ListContainerOptions; -import org.jclouds.openstack.v2_0.internal.BaseOpenStackMockTest; -import org.testng.annotations.Test; - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; -import com.squareup.okhttp.mockwebserver.MockResponse; -import com.squareup.okhttp.mockwebserver.MockWebServer; -import com.squareup.okhttp.mockwebserver.RecordedRequest; - -@Test(groups = "unit", testName = "ContainerApiMockTest") -public class ContainerApiMockTest extends BaseOpenStackMockTest { - - public void testList() throws Exception { - MockWebServer server = mockOpenStackServer(); - server.enqueue(addCommonHeaders(new MockResponse().setBody(stringFromResource("/access.json")))); - server.enqueue(addCommonHeaders(new MockResponse().setBody(stringFromResource("/container_list.json")))); - - try { - SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift"); - ImmutableList containers = api.getContainerApiForRegion("DFW").list().toList(); - assertEquals(containers, ImmutableList.of( - Container.builder() - .name("test_container_1") - .objectCount(2) - .bytesUsed(78).build(), - Container.builder() - .name("test_container_2") - .objectCount(1) - .bytesUsed(17).build())); - - assertEquals(server.getRequestCount(), 2); - assertAuthentication(server); - assertRequest(server.takeRequest(), "GET", "/v1/MossoCloudFS_5bcf396e-39dd-45ff-93a1-712b9aba90a9/?format=json"); - } finally { - server.shutdown(); - } - } - - public void testListWithOptions() throws Exception { - MockWebServer server = mockOpenStackServer(); - server.enqueue(addCommonHeaders(new MockResponse().setBody(stringFromResource("/access.json")))); - server.enqueue(addCommonHeaders(new MockResponse().setBody(stringFromResource("/container_list.json")))); - - ListContainerOptions options = ListContainerOptions.Builder.marker("test"); - assertNotNull(options); - - try { - SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift"); - ImmutableList containers = api.getContainerApiForRegion("DFW").list(options).toList(); - assertEquals(containers, ImmutableList.of( - Container.builder() - .name("test_container_1") - .objectCount(2) - .bytesUsed(78).build(), - Container.builder() - .name("test_container_2") - .objectCount(1) - .bytesUsed(17).build())); - - assertEquals(server.getRequestCount(), 2); - assertAuthentication(server); - assertRequest(server.takeRequest(), "GET", "/v1/MossoCloudFS_5bcf396e-39dd-45ff-93a1-712b9aba90a9/?format=json&marker=test"); - } finally { - server.shutdown(); - } - } - - public void testContainerExists() throws Exception { - MockWebServer server = mockOpenStackServer(); - server.enqueue(addCommonHeaders(new MockResponse().setBody(stringFromResource("/access.json")))); - server.enqueue(addCommonHeaders(new MockResponse().setResponseCode(201))); - server.enqueue(addCommonHeaders(containerResponse() - .addHeader(CONTAINER_METADATA_PREFIX + "ApiName", "swift") - .addHeader(CONTAINER_METADATA_PREFIX + "ApiVersion", "v1.1"))); - - try { - SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift"); - assertTrue(api.getContainerApiForRegion("DFW").create("myContainer", anybodyRead().metadata(metadata))); - - Container container = api.getContainerApiForRegion("DFW").get("myContainer"); - assertEquals(container.getName(), "myContainer"); - assertEquals(container.getObjectCount(), 42l); - assertEquals(container.getBytesUsed(), 323479l); - for (Entry entry : container.getMetadata().entrySet()) { - assertEquals(container.getMetadata().get(entry.getKey().toLowerCase()), entry.getValue()); - } - assertEquals(server.getRequestCount(), 3); - assertAuthentication(server); - assertRequest(server.takeRequest(), "PUT", "/v1/MossoCloudFS_5bcf396e-39dd-45ff-93a1-712b9aba90a9/myContainer"); - assertRequest(server.takeRequest(), "HEAD", "/v1/MossoCloudFS_5bcf396e-39dd-45ff-93a1-712b9aba90a9/myContainer"); - } finally { - server.shutdown(); - } - } - - @Test(expectedExceptions = ContainerNotFoundException.class) - public void testContainerDoesNotExist() throws Exception { - MockWebServer server = mockOpenStackServer(); - server.enqueue(addCommonHeaders(new MockResponse().setBody(stringFromResource("/access.json")))); - server.enqueue(addCommonHeaders(new MockResponse().setResponseCode(404))); - - try { - SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift"); - assertTrue(api.getContainerApiForRegion("DFW").create("myContainer", anybodyRead().metadata(metadata))); - - // the head call will throw the ContainerNotFoundException - api.getContainerApiForRegion("DFW").get("myContainer"); - } finally { - server.shutdown(); - } - } - - public void testCreate() throws Exception { - MockWebServer server = mockOpenStackServer(); - server.enqueue(addCommonHeaders(new MockResponse().setBody(stringFromResource("/access.json")))); - server.enqueue(addCommonHeaders(new MockResponse().setResponseCode(201))); - - try { - SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift"); - assertTrue(api.getContainerApiForRegion("DFW").create("myContainer")); - - assertEquals(server.getRequestCount(), 2); - assertAuthentication(server); - assertRequest(server.takeRequest(), "PUT", "/v1/MossoCloudFS_5bcf396e-39dd-45ff-93a1-712b9aba90a9/myContainer"); - } finally { - server.shutdown(); - } - } - - public void testCreateWithOptions() throws Exception { - MockWebServer server = mockOpenStackServer(); - server.enqueue(addCommonHeaders(new MockResponse().setBody(stringFromResource("/access.json")))); - server.enqueue(addCommonHeaders(new MockResponse().setResponseCode(201))); - - try { - SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift"); - assertTrue(api.getContainerApiForRegion("DFW").create("myContainer", anybodyRead().metadata(metadata))); - - assertEquals(server.getRequestCount(), 2); - assertAuthentication(server); - - RecordedRequest createRequest = server.takeRequest(); - assertRequest(createRequest, "PUT", "/v1/MossoCloudFS_5bcf396e-39dd-45ff-93a1-712b9aba90a9/myContainer"); - - assertEquals(createRequest.getHeader(CONTAINER_READ), CONTAINER_ACL_ANYBODY_READ); - - for (Entry entry : metadata.entrySet()) { - assertEquals(createRequest.getHeader(CONTAINER_METADATA_PREFIX + entry.getKey().toLowerCase()), entry.getValue()); - } - } finally { - server.shutdown(); - } - } - - public void testCreateWithSpacesAndSpecialCharacters() throws Exception { - MockWebServer server = mockOpenStackServer(); - server.enqueue(addCommonHeaders(new MockResponse().setBody(stringFromResource("/access.json")))); - server.enqueue(addCommonHeaders(new MockResponse().setResponseCode(201))); - - try { - SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift"); - assertTrue(api.getContainerApiForRegion("DFW").create("container # ! special")); - - assertEquals(server.getRequestCount(), 2); - assertAuthentication(server); - assertRequest(server.takeRequest(), "PUT", "/v1/MossoCloudFS_5bcf396e-39dd-45ff-93a1-712b9aba90a9/container%20%23%20%21%20special"); - } finally { - server.shutdown(); - } - } - - public void testAlreadyCreated() throws Exception { - MockWebServer server = mockOpenStackServer(); - server.enqueue(addCommonHeaders(new MockResponse().setBody(stringFromResource("/access.json")))); - server.enqueue(addCommonHeaders(new MockResponse().setResponseCode(202))); - - try { - SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift"); - assertFalse(api.getContainerApiForRegion("DFW").create("myContainer")); - - assertEquals(server.getRequestCount(), 2); - assertAuthentication(server); - assertRequest(server.takeRequest(), "PUT", "/v1/MossoCloudFS_5bcf396e-39dd-45ff-93a1-712b9aba90a9/myContainer"); - } finally { - server.shutdown(); - } - } - - /** upper-cases first char, and lower-cases rest!! **/ - public void testGetKnowingServerMessesWithMetadataKeyCaseFormat() throws Exception { - MockWebServer server = mockOpenStackServer(); - server.enqueue(addCommonHeaders(new MockResponse().setBody(stringFromResource("/access.json")))); - server.enqueue(addCommonHeaders(containerResponse() - // note silly casing - .addHeader(CONTAINER_METADATA_PREFIX + "Apiname", "swift") - .addHeader(CONTAINER_METADATA_PREFIX + "Apiversion", "v1.1"))); - - try { - SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift"); - Container container = api.getContainerApiForRegion("DFW").get("myContainer"); - assertEquals(container.getName(), "myContainer"); - assertEquals(container.getObjectCount(), 42l); - assertEquals(container.getBytesUsed(), 323479l); - for (Entry entry : container.getMetadata().entrySet()) { - assertEquals(container.getMetadata().get(entry.getKey().toLowerCase()), entry.getValue()); - } - - assertEquals(server.getRequestCount(), 2); - assertAuthentication(server); - assertRequest(server.takeRequest(), "HEAD", "/v1/MossoCloudFS_5bcf396e-39dd-45ff-93a1-712b9aba90a9/myContainer"); - } finally { - server.shutdown(); - } - } - - public void testUpdateMetadata() throws Exception { - MockWebServer server = mockOpenStackServer(); - server.enqueue(addCommonHeaders(new MockResponse().setBody(stringFromResource("/access.json")))); - server.enqueue(addCommonHeaders(containerResponse() - .addHeader(CONTAINER_METADATA_PREFIX + "ApiName", "swift") - .addHeader(CONTAINER_METADATA_PREFIX + "ApiVersion", "v1.1"))); - - try { - SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift"); - assertTrue(api.getContainerApiForRegion("DFW").updateMetadata("myContainer", metadata)); - - assertEquals(server.getRequestCount(), 2); - assertEquals(server.takeRequest().getRequestLine(), "POST /tokens HTTP/1.1"); - RecordedRequest replaceRequest = server.takeRequest(); - assertEquals(replaceRequest.getRequestLine(), - "POST /v1/MossoCloudFS_5bcf396e-39dd-45ff-93a1-712b9aba90a9/myContainer HTTP/1.1"); - for (Entry entry : metadata.entrySet()) { - assertEquals(replaceRequest.getHeader(CONTAINER_METADATA_PREFIX + entry.getKey().toLowerCase()), entry.getValue()); - } - } finally { - server.shutdown(); - } - } - - public void testDeleteMetadata() throws Exception { - MockWebServer server = mockOpenStackServer(); - server.enqueue(addCommonHeaders(new MockResponse().setBody(stringFromResource("/access.json")))); - server.enqueue(addCommonHeaders(containerResponse())); - - try { - SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift"); - assertTrue(api.getContainerApiForRegion("DFW").deleteMetadata("myContainer", metadata)); - - assertEquals(server.getRequestCount(), 2); - assertEquals(server.takeRequest().getRequestLine(), "POST /tokens HTTP/1.1"); - RecordedRequest deleteRequest = server.takeRequest(); - assertEquals(deleteRequest.getRequestLine(), - "POST /v1/MossoCloudFS_5bcf396e-39dd-45ff-93a1-712b9aba90a9/myContainer HTTP/1.1"); - for (String key : metadata.keySet()) { - assertEquals(deleteRequest.getHeader(CONTAINER_REMOVE_METADATA_PREFIX + key.toLowerCase()), "ignored"); - } - } finally { - server.shutdown(); - } - } - - public void testDeleteIfEmpty() throws Exception { - MockWebServer server = mockOpenStackServer(); - server.enqueue(addCommonHeaders(new MockResponse().setBody(stringFromResource("/access.json")))); - server.enqueue(addCommonHeaders(new MockResponse().setResponseCode(204))); - - try { - SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift"); - assertTrue(api.getContainerApiForRegion("DFW").deleteIfEmpty("myContainer")); - - assertEquals(server.getRequestCount(), 2); - assertEquals(server.takeRequest().getRequestLine(), "POST /tokens HTTP/1.1"); - RecordedRequest deleteRequest = server.takeRequest(); - assertEquals(deleteRequest.getRequestLine(), - "DELETE /v1/MossoCloudFS_5bcf396e-39dd-45ff-93a1-712b9aba90a9/myContainer HTTP/1.1"); - } finally { - server.shutdown(); - } - } - - public void testAlreadyDeleted() throws Exception { - MockWebServer server = mockOpenStackServer(); - server.enqueue(addCommonHeaders(new MockResponse().setBody(stringFromResource("/access.json")))); - server.enqueue(addCommonHeaders(new MockResponse().setResponseCode(404))); - - try { - SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift"); - assertTrue(api.getContainerApiForRegion("DFW").deleteIfEmpty("myContainer")); - - assertEquals(server.getRequestCount(), 2); - assertEquals(server.takeRequest().getRequestLine(), "POST /tokens HTTP/1.1"); - RecordedRequest deleteRequest = server.takeRequest(); - assertEquals(deleteRequest.getRequestLine(), - "DELETE /v1/MossoCloudFS_5bcf396e-39dd-45ff-93a1-712b9aba90a9/myContainer HTTP/1.1"); - } finally { - server.shutdown(); - } - } - - @Test(expectedExceptions = IllegalStateException.class) - public void testDeleteWhenNotEmpty() throws Exception { - MockWebServer server = mockOpenStackServer(); - server.enqueue(addCommonHeaders(new MockResponse().setBody(stringFromResource("/access.json")))); - server.enqueue(addCommonHeaders(new MockResponse().setResponseCode(409))); - - try { - SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift"); - api.getContainerApiForRegion("DFW").deleteIfEmpty("myContainer"); - - } finally { - assertEquals(server.getRequestCount(), 2); - assertEquals(server.takeRequest().getRequestLine(), "POST /tokens HTTP/1.1"); - RecordedRequest deleteRequest = server.takeRequest(); - assertEquals(deleteRequest.getRequestLine(), - "DELETE /v1/MossoCloudFS_5bcf396e-39dd-45ff-93a1-712b9aba90a9/myContainer HTTP/1.1"); - server.shutdown(); - } - } - - private static final Map metadata = ImmutableMap.of("ApiName", "swift", "ApiVersion", "v1.1"); - - static MockResponse containerResponse() { - return new MockResponse() - .addHeader(CONTAINER_OBJECT_COUNT, "42") - .addHeader(CONTAINER_BYTES_USED, "323479"); - } -} diff --git a/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/CreatePublicContainerLiveTest.java b/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/CreatePublicContainerLiveTest.java deleted file mode 100644 index 41df875f61..0000000000 --- a/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/CreatePublicContainerLiveTest.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF 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.openstack.swift.v1.features; - -import static org.jclouds.openstack.swift.v1.options.CreateContainerOptions.Builder.anybodyRead; -import static org.testng.Assert.assertTrue; - -import org.jclouds.openstack.swift.v1.SwiftApi; -import org.jclouds.openstack.swift.v1.internal.BaseSwiftApiLiveTest; -import org.testng.annotations.AfterClass; -import org.testng.annotations.Test; - -@Test(groups = "live", testName = "CreatePublicContainerLiveTest") -public class CreatePublicContainerLiveTest extends BaseSwiftApiLiveTest { - - private String name = getClass().getSimpleName(); - - public void testAnybodyReadUpdatesMetadata() throws Exception { - for (String regionId : api.getConfiguredRegions()) { - api.getContainerApiForRegion(regionId).create(name, anybodyRead()); - assertTrue(api.getContainerApiForRegion(regionId).get(name).getAnybodyRead().get()); - } - } - - @Override - @AfterClass(groups = "live") - public void tearDown() { - for (String regionId : api.getConfiguredRegions()) { - api.getContainerApiForRegion(regionId).deleteIfEmpty(name); - } - super.tearDown(); - } -} diff --git a/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/ObjectApiLiveTest.java b/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/ObjectApiLiveTest.java deleted file mode 100644 index c0b2a6e889..0000000000 --- a/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/ObjectApiLiveTest.java +++ /dev/null @@ -1,291 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF 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.openstack.swift.v1.features; - -import static org.jclouds.http.options.GetOptions.Builder.tail; -import static org.jclouds.io.Payloads.newByteSourcePayload; -import static org.jclouds.openstack.swift.v1.options.ListContainerOptions.Builder.marker; -import static org.jclouds.util.Strings2.toStringAndClose; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertFalse; -import static org.testng.Assert.assertNotNull; -import static org.testng.Assert.assertTrue; -import static org.testng.Assert.fail; - -import java.io.IOException; -import java.util.Date; -import java.util.Map; -import java.util.Map.Entry; -import java.util.concurrent.TimeUnit; - -import javax.ws.rs.PathParam; - -import org.jclouds.http.options.GetOptions; -import org.jclouds.io.Payload; -import org.jclouds.openstack.swift.v1.CopyObjectException; -import org.jclouds.openstack.swift.v1.SwiftApi; -import org.jclouds.openstack.swift.v1.binders.SetPayload; -import org.jclouds.openstack.swift.v1.domain.ObjectList; -import org.jclouds.openstack.swift.v1.domain.SwiftObject; -import org.jclouds.openstack.swift.v1.internal.BaseSwiftApiLiveTest; -import org.jclouds.openstack.swift.v1.options.ListContainerOptions; -import org.jclouds.rest.annotations.BinderParam; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; - -import com.google.common.collect.ImmutableMap; -import com.google.common.io.ByteSource; - -/** - * Provides live tests for the {@link ObjectApi}. - */ -@Test(groups = "live", testName = "ObjectApiLiveTest", singleThreaded = true) -public class ObjectApiLiveTest extends BaseSwiftApiLiveTest { - - private String name = getClass().getSimpleName(); - private String containerName = getClass().getSimpleName() + "Container"; - static final Payload PAYLOAD = newByteSourcePayload(ByteSource.wrap("swifty".getBytes())); - - public void testCreateWithSpacesAndSpecialCharacters() throws Exception { - final String containerName = "container # ! special"; - final String objectName = "object # ! special"; - - for (String regionId : regions) { - assertNotNull(api.getContainerApiForRegion(regionId).create(containerName)); - assertNotNull(api.getObjectApiForRegionAndContainer(regionId, containerName).put(objectName, PAYLOAD)); - - SwiftObject object = api.getObjectApiForRegionAndContainer(regionId, containerName).get(objectName); - assertEquals(object.getName(), objectName); - checkObject(object); - assertEquals(toStringAndClose(object.getPayload().openStream()), "swifty"); - - api.getObjectApiForRegionAndContainer(regionId, containerName).delete(objectName); - api.getContainerApiForRegion(regionId).deleteIfEmpty(containerName); - } - } - - public void testPutWithExpiration() throws Exception { - String objectName = "test-expiration"; - - long expireMillis = new Date().getTime() + 1000 * 60 * 60 * 24; - Date expireAt = new Date(expireMillis); - - Payload payload = newByteSourcePayload(ByteSource.wrap("swifty".getBytes())); - payload.getContentMetadata().setExpires(expireAt); - - for (String regionId : regions) { - String etag = api.getObjectApiForRegionAndContainer(regionId, containerName) - .put(objectName, payload); - assertNotNull(etag); - - SwiftObject object = api.getObjectApiForRegionAndContainer(regionId, containerName).get(objectName); - assertEquals(object.getName(), objectName); - checkObject(object); - assertEquals(toStringAndClose(object.getPayload().openStream()), "swifty"); - - api.getObjectApiForRegionAndContainer(regionId, containerName).delete(objectName); - } - } - public void testCopyObject() throws Exception { - for (String regionId : regions) { - // source - String sourceContainer = "src" + containerName; - String sourceObjectName = "original.txt"; - String badSource = "badSource"; - - // destination - String destinationContainer = "dest" + containerName; - String destinationObject = "copy.txt"; - String destinationPath = "/" + destinationContainer + "/" + destinationObject; - - ContainerApi containerApi = api.getContainerApiForRegion(regionId); - - // create source and destination dirs - containerApi.create(sourceContainer); - containerApi.create(destinationContainer); - - // get the api for this region and container - ObjectApi srcApi = api.getObjectApiForRegionAndContainer(regionId, sourceContainer); - ObjectApi destApi = api.getObjectApiForRegionAndContainer(regionId, destinationContainer); - - // Create source object - assertNotNull(srcApi.put(sourceObjectName, PAYLOAD)); - SwiftObject sourceObject = srcApi.get(sourceObjectName); - checkObject(sourceObject); - - // Create the destination object - assertNotNull(destApi.put(destinationObject, PAYLOAD)); - SwiftObject object = destApi.get(destinationObject); - checkObject(object); - - // check the copy operation - assertTrue(destApi.copy(destinationObject, sourceContainer, sourceObjectName)); - assertNotNull(destApi.get(destinationObject)); - - // now get a real SwiftObject - SwiftObject destSwiftObject = destApi.get(destinationObject); - assertEquals(toStringAndClose(destSwiftObject.getPayload().openStream()), "swifty"); - - // test exception thrown on bad source name - try { - destApi.copy(destinationObject, badSource, sourceObjectName); - fail("Expected CopyObjectException"); - } catch (CopyObjectException e) { - assertEquals(e.getSourcePath(), "/" + badSource + "/" + sourceObjectName); - assertEquals(e.getDestinationPath(), destinationPath); - } - - deleteAllObjectsInContainer(regionId, sourceContainer); - containerApi.deleteIfEmpty(sourceContainer); - - deleteAllObjectsInContainer(regionId, destinationContainer); - containerApi.deleteIfEmpty(destinationContainer); - } - } - - public void testList() throws Exception { - for (String regionId : regions) { - ObjectApi objectApi = api.getObjectApiForRegionAndContainer(regionId, containerName); - ObjectList response = objectApi.list(); - assertEquals(response.getContainer(), api.getContainerApiForRegion(regionId).get(containerName)); - for (SwiftObject object : response) { - checkObject(object); - } - } - } - - public void testListWithOptions() throws Exception { - for (String regionId : regions) { - ObjectApi objectApi = api.getObjectApiForRegionAndContainer(regionId, containerName); - ObjectList response = objectApi.list(ListContainerOptions.NONE); - assertEquals(response.getContainer(), api.getContainerApiForRegion(regionId).get(containerName)); - for (SwiftObject object : response) { - checkObject(object); - } - } - } - - public void testMetadata() throws Exception { - for (String regionId : regions) { - SwiftObject object = api.getObjectApiForRegionAndContainer(regionId, containerName).get(name); - assertEquals(object.getName(), name); - checkObject(object); - assertEquals(toStringAndClose(object.getPayload().openStream()), "swifty"); - } - } - - public void testUpdateMetadata() throws Exception { - for (String regionId : regions) { - ObjectApi objectApi = api.getObjectApiForRegionAndContainer(regionId, containerName); - - Map meta = ImmutableMap.of("MyAdd1", "foo", "MyAdd2", "bar"); - assertTrue(objectApi.updateMetadata(name, meta)); - - SwiftObject object = objectApi.get(name); - for (Entry entry : meta.entrySet()) { - // note keys are returned in lower-case! - assertEquals(object.getMetadata().get(entry.getKey().toLowerCase()), entry.getValue(), - object + " didn't have metadata: " + entry); - } - } - } - - public void testGet() throws Exception { - for (String regionId : regions) { - SwiftObject object = api.getObjectApiForRegionAndContainer(regionId, containerName).get(name, GetOptions.NONE); - assertEquals(object.getName(), name); - checkObject(object); - assertEquals(toStringAndClose(object.getPayload().openStream()), "swifty"); - } - } - - public void testPrivateByDefault() throws Exception { - for (String regionId : regions) { - SwiftObject object = api.getObjectApiForRegionAndContainer(regionId, containerName).get(name); - try { - object.getUri().toURL().openStream(); - fail("shouldn't be able to access " + object); - } catch (IOException expected) { - } - } - } - - public void testGetOptions() throws Exception { - for (String regionId : regions) { - SwiftObject object = api.getObjectApiForRegionAndContainer(regionId, containerName).get(name, tail(1)); - assertEquals(object.getName(), name); - checkObject(object); - assertEquals(toStringAndClose(object.getPayload().openStream()), "y"); - } - } - - public void testListOptions() throws Exception { - String lexicographicallyBeforeName = name.substring(0, name.length() - 1); - for (String regionId : regions) { - SwiftObject object = api.getObjectApiForRegionAndContainer(regionId, containerName) - .list(marker(lexicographicallyBeforeName)).get(0); - assertEquals(object.getName(), name); - checkObject(object); - } - } - - public void testDeleteMetadata() throws Exception { - for (String regionId : regions) { - ObjectApi objectApi = api.getObjectApiForRegionAndContainer(regionId, containerName); - - Map meta = ImmutableMap.of("MyDelete1", "foo", "MyDelete2", "bar"); - - assertTrue(objectApi.updateMetadata(name, meta)); - assertFalse(objectApi.get(name).getMetadata().isEmpty()); - - assertTrue(objectApi.deleteMetadata(name, meta)); - assertTrue(objectApi.get(name).getMetadata().isEmpty()); - } - } - - @Override - @BeforeClass(groups = "live") - public void setup() { - super.setup(); - for (String regionId : regions) { - api.getContainerApiForRegion(regionId).create(containerName); - api.getObjectApiForRegionAndContainer(regionId, containerName).put(name, PAYLOAD); - } - } - - @Override - @AfterClass(groups = "live") - public void tearDown() { - for (String regionId : regions) { - deleteAllObjectsInContainer(regionId, containerName); - api.getObjectApiForRegionAndContainer(regionId, containerName).delete(name); - api.getContainerApiForRegion(regionId).deleteIfEmpty(containerName); - } - - super.tearDown(); - } - - static void checkObject(SwiftObject object) { - assertNotNull(object.getName()); - assertNotNull(object.getUri()); - assertNotNull(object.getETag()); - assertTrue(object.getLastModified().getTime() <= System.currentTimeMillis() + TimeUnit.MINUTES.toMillis(5)); - assertNotNull(object.getPayload().getContentMetadata().getContentLength()); - assertNotNull(object.getPayload().getContentMetadata().getContentType()); - } -} diff --git a/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/ObjectApiMockTest.java b/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/ObjectApiMockTest.java deleted file mode 100644 index 972a1e7165..0000000000 --- a/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/ObjectApiMockTest.java +++ /dev/null @@ -1,506 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF 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.openstack.swift.v1.features; - -import static com.google.common.base.Charsets.US_ASCII; -import static com.google.common.net.HttpHeaders.EXPIRES; -import static com.google.common.net.HttpHeaders.RANGE; -import static com.google.common.net.HttpHeaders.LAST_MODIFIED; -import static org.jclouds.Constants.PROPERTY_MAX_RETRIES; -import static org.jclouds.Constants.PROPERTY_RETRY_DELAY_START; -import static org.jclouds.Constants.PROPERTY_SO_TIMEOUT; -import static org.jclouds.http.options.GetOptions.Builder.tail; -import static org.jclouds.io.Payloads.newByteSourcePayload; -import static org.jclouds.openstack.swift.v1.features.ContainerApiMockTest.containerResponse; -import static org.jclouds.openstack.swift.v1.options.ListContainerOptions.Builder.marker; -import static org.jclouds.openstack.swift.v1.options.PutOptions.Builder.metadata; -import static org.jclouds.openstack.swift.v1.reference.SwiftHeaders.CONTAINER_ACL_ANYBODY_READ; -import static org.jclouds.openstack.swift.v1.reference.SwiftHeaders.CONTAINER_READ; -import static org.jclouds.openstack.swift.v1.reference.SwiftHeaders.OBJECT_METADATA_PREFIX; -import static org.jclouds.openstack.swift.v1.reference.SwiftHeaders.OBJECT_REMOVE_METADATA_PREFIX; -import static org.jclouds.util.Strings2.toStringAndClose; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertTrue; -import static org.testng.Assert.fail; - -import java.io.IOException; -import java.net.URI; -import java.util.Date; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Properties; - -import org.jclouds.date.internal.SimpleDateFormatDateService; -import org.jclouds.http.HttpResponseException; -import org.jclouds.io.Payload; -import org.jclouds.io.payloads.ByteSourcePayload; -import org.jclouds.openstack.swift.v1.CopyObjectException; -import org.jclouds.openstack.swift.v1.SwiftApi; -import org.jclouds.openstack.swift.v1.domain.ObjectList; -import org.jclouds.openstack.swift.v1.domain.SwiftObject; -import org.jclouds.openstack.swift.v1.options.ListContainerOptions; -import org.jclouds.openstack.swift.v1.reference.SwiftHeaders; -import org.jclouds.openstack.v2_0.internal.BaseOpenStackMockTest; -import org.testng.annotations.Test; - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; -import com.google.common.io.ByteSource; -import com.squareup.okhttp.mockwebserver.MockResponse; -import com.squareup.okhttp.mockwebserver.MockWebServer; -import com.squareup.okhttp.mockwebserver.RecordedRequest; - -/** - * Provides mock tests for the {@link ObjectApi}. - */ -@Test(groups = "unit", testName = "ObjectApiMockTest") -public class ObjectApiMockTest extends BaseOpenStackMockTest { - SimpleDateFormatDateService dates = new SimpleDateFormatDateService(); - - static final Payload PAYLOAD = newByteSourcePayload(ByteSource.wrap("swifty".getBytes())); - - protected ImmutableList parsedObjectsForUrl(String baseUri) { - baseUri += "v1/MossoCloudFS_5bcf396e-39dd-45ff-93a1-712b9aba90a9/myContainer"; - return ImmutableList.of( - SwiftObject.builder() - .name("test_obj_1") - .uri(URI.create(baseUri + "/test_obj_1")) - .etag("4281c348eaf83e70ddce0e07221c3d28") - .payload(payload(14, "application/octet-stream", new Date(1406243553))) - .lastModified(dates.iso8601DateParse("2009-02-03T05:26:32.612278")).build(), - SwiftObject.builder() - .name("test_obj_2") - .uri(URI.create(baseUri + "/test_obj_2")) - .etag("b039efe731ad111bc1b0ef221c3849d0") - .payload(payload(64l, "application/octet-stream", null)) - .lastModified(dates.iso8601DateParse("2009-02-03T05:26:32.612278")).build(), - SwiftObject.builder() - .name("test obj 3") - .uri(URI.create(baseUri + "/test%20obj%203")) - .etag("0b2e80bd0744d9ebb20484149a57c82e") - .payload(payload(14, "application/octet-stream", new Date())) - .lastModified(dates.iso8601DateParse("2014-05-20T05:26:32.612278")).build()); - } - - public void testList() throws Exception { - MockWebServer server = mockOpenStackServer(); - server.enqueue(addCommonHeaders(new MockResponse().setBody(stringFromResource("/access.json")))); - server.enqueue(addCommonHeaders(containerResponse() - .addHeader(CONTAINER_READ, CONTAINER_ACL_ANYBODY_READ) - .setBody(stringFromResource("/object_list.json")))); - - try { - SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift"); - ObjectList objects = api.getObjectApiForRegionAndContainer("DFW", "myContainer").list(); - assertEquals(objects, parsedObjectsForUrl(server.getUrl("/").toString())); - assertEquals(objects.getContainer().getName(), "myContainer"); - assertTrue(objects.getContainer().getAnybodyRead().get()); - - assertEquals(server.getRequestCount(), 2); - assertAuthentication(server); - assertRequest(server.takeRequest(), "GET", "/v1/MossoCloudFS_5bcf396e-39dd-45ff-93a1-712b9aba90a9/myContainer/?format=json"); - } finally { - server.shutdown(); - } - } - - public void testListWithOptions() throws Exception { - MockWebServer server = mockOpenStackServer(); - server.enqueue(addCommonHeaders(new MockResponse().setBody(stringFromResource("/access.json")))); - server.enqueue(addCommonHeaders(containerResponse() - .addHeader(CONTAINER_READ, CONTAINER_ACL_ANYBODY_READ) - .setBody(stringFromResource("/object_list.json")))); - - try { - SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift"); - ObjectList objects = api.getObjectApiForRegionAndContainer("DFW", "myContainer").list(new ListContainerOptions()); - assertEquals(objects, parsedObjectsForUrl(server.getUrl("/").toString())); - assertEquals(objects.getContainer().getName(), "myContainer"); - assertTrue(objects.getContainer().getAnybodyRead().get()); - - assertEquals(server.getRequestCount(), 2); - assertAuthentication(server); - assertRequest(server.takeRequest(), "GET", "/v1/MossoCloudFS_5bcf396e-39dd-45ff-93a1-712b9aba90a9/myContainer/?format=json"); - } finally { - server.shutdown(); - } - } - - public void testListOptions() throws Exception { - MockWebServer server = mockOpenStackServer(); - server.enqueue(addCommonHeaders(new MockResponse().setBody(stringFromResource("/access.json")))); - server.enqueue(addCommonHeaders(containerResponse().setBody(stringFromResource("/object_list.json")))); - - try { - SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift"); - ObjectList objects = api.getObjectApiForRegionAndContainer("DFW", "myContainer").list(marker("test")); - assertEquals(objects, parsedObjectsForUrl(server.getUrl("/").toString())); - - assertEquals(server.getRequestCount(), 2); - assertAuthentication(server); - assertRequest(server.takeRequest(), "GET", "/v1/MossoCloudFS_5bcf396e-39dd-45ff-93a1-712b9aba90a9/myContainer/?format=json&marker=test"); - } finally { - server.shutdown(); - } - } - - public void testCreate() throws Exception { - MockWebServer server = mockOpenStackServer(); - server.enqueue(addCommonHeaders(new MockResponse().setBody(stringFromResource("/access.json")))); - server.enqueue(addCommonHeaders(new MockResponse() - .setResponseCode(201) - .addHeader("ETag", "d9f5eb4bba4e2f2f046e54611bc8196b")) - .addHeader("Expires", "1406243553")); - - try { - SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift"); - assertEquals( - api.getObjectApiForRegionAndContainer("DFW", "myContainer").put("myObject", PAYLOAD, - metadata(metadata)), "d9f5eb4bba4e2f2f046e54611bc8196b"); - - assertEquals(server.getRequestCount(), 2); - assertAuthentication(server); - RecordedRequest replace = server.takeRequest(); - assertRequest(replace, "PUT", "/v1/MossoCloudFS_5bcf396e-39dd-45ff-93a1-712b9aba90a9/myContainer/myObject"); - - assertEquals(new String(replace.getBody()), "swifty"); - for (Entry entry : metadata.entrySet()) { - assertEquals(replace.getHeader(OBJECT_METADATA_PREFIX + entry.getKey().toLowerCase()), entry.getValue()); - } - } finally { - server.shutdown(); - } - } - - public void testCreateWithSpacesAndSpecialCharacters() throws Exception { - MockWebServer server = mockOpenStackServer(); - server.enqueue(addCommonHeaders(new MockResponse().setBody(stringFromResource("/access.json")))); - server.enqueue(addCommonHeaders(new MockResponse().setResponseCode(201).addHeader("ETag", "d9f5eb4bba4e2f2f046e54611bc8196b"))); - - final String containerName = "container # ! special"; - final String objectName = "object # ! special"; - - try { - SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift"); - assertEquals( - api.getObjectApiForRegionAndContainer("DFW", containerName).put(objectName, PAYLOAD, - metadata(metadata)), "d9f5eb4bba4e2f2f046e54611bc8196b"); - - assertEquals(server.getRequestCount(), 2); - assertAuthentication(server); - RecordedRequest replace = server.takeRequest(); - assertRequest(replace, "PUT", "/v1/MossoCloudFS_5bcf396e-39dd-45ff-93a1-712b9aba90a9/container%20%23%20%21%20special/object%20%23%20%21%20special"); - - assertEquals(new String(replace.getBody()), "swifty"); - } finally { - server.shutdown(); - } - } - - public void testCreateWith408Retry() throws Exception { - MockWebServer server = mockOpenStackServer(); - server.enqueue(addCommonHeaders(new MockResponse().setBody(stringFromResource("/access.json")))); - server.enqueue(addCommonHeaders(new MockResponse().setResponseCode(408))); // 1 - server.enqueue(addCommonHeaders(new MockResponse().setResponseCode(408))); // 2 - server.enqueue(addCommonHeaders(new MockResponse().setResponseCode(408))); // 3 - - // Finally success - server.enqueue(addCommonHeaders(new MockResponse() - .setResponseCode(201) - .addHeader("ETag", "d9f5eb4bba4e2f2f046e54611bc8196b"))); - - try { - Properties overrides = new Properties(); - overrides.setProperty(PROPERTY_MAX_RETRIES, 5 + ""); - - SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift", overrides); - assertEquals( - api.getObjectApiForRegionAndContainer("DFW", "myContainer").put("myObject", PAYLOAD, - metadata(metadata)), "d9f5eb4bba4e2f2f046e54611bc8196b"); - - assertEquals(server.getRequestCount(), 5); - assertAuthentication(server); - RecordedRequest replace = server.takeRequest(); - // This should take a while. - assertRequest(replace, "PUT", "/v1/MossoCloudFS_5bcf396e-39dd-45ff-93a1-712b9aba90a9/myContainer/myObject"); - - assertEquals(new String(replace.getBody()), "swifty"); - for (Entry entry : metadata.entrySet()) { - assertEquals(replace.getHeader(OBJECT_METADATA_PREFIX + entry.getKey().toLowerCase()), entry.getValue()); - } - } finally { - server.shutdown(); - } - } - - /** upper-cases first char, and lower-cases rest!! **/ - public void testGetWithoutKnowingServerMessesWithMetadataKeyCaseFormat() throws Exception { - MockWebServer server = mockOpenStackServer(); - server.enqueue(addCommonHeaders(new MockResponse().setBody(stringFromResource("/access.json")))); - server.enqueue(addCommonHeaders(objectResponse() - // note silly casing - .addHeader(OBJECT_METADATA_PREFIX + "Apiname", "swift") - .addHeader(OBJECT_METADATA_PREFIX + "Apiversion", "v1.1"))); - - try { - SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift"); - SwiftObject object = api.getObjectApiForRegionAndContainer("DFW", "myContainer").getWithoutBody("myObject"); - assertEquals(object.getName(), "myObject"); - assertEquals(object.getETag(), "8a964ee2a5e88be344f36c22562a6486"); - assertEquals(object.getLastModified(), dates.rfc822DateParse("Fri, 12 Jun 2010 13:40:18 GMT")); - for (Entry entry : object.getMetadata().entrySet()) { - assertEquals(object.getMetadata().get(entry.getKey().toLowerCase()), entry.getValue()); - } - assertEquals(object.getPayload().getContentMetadata().getContentType(), "text/plain; charset=UTF-8"); - assertEquals(toStringAndClose(object.getPayload().openStream()), ""); - - assertEquals(server.getRequestCount(), 2); - assertAuthentication(server); - assertRequest(server.takeRequest(), "HEAD", "/v1/MossoCloudFS_5bcf396e-39dd-45ff-93a1-712b9aba90a9/myContainer/myObject"); - } finally { - server.shutdown(); - } - } - - public void testGet() throws Exception { - MockWebServer server = mockOpenStackServer(); - server.enqueue(addCommonHeaders(new MockResponse().setBody(stringFromResource("/access.json")))); - server.enqueue(addCommonHeaders(objectResponse() - // note silly casing - .addHeader(OBJECT_METADATA_PREFIX + "Apiname", "swift") - .addHeader(OBJECT_METADATA_PREFIX + "Apiversion", "v1.1"))); - - try { - SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift"); - SwiftObject object = api.getObjectApiForRegionAndContainer("DFW", "myContainer").get("myObject", tail(1)); - assertEquals(object.getName(), "myObject"); - assertEquals(object.getETag(), "8a964ee2a5e88be344f36c22562a6486"); - assertEquals(object.getLastModified(), dates.rfc822DateParse("Fri, 12 Jun 2010 13:40:18 GMT")); - for (Entry entry : object.getMetadata().entrySet()) { - assertEquals(object.getMetadata().get(entry.getKey().toLowerCase()), entry.getValue()); - } - - Payload payload = object.getPayload(); - assertEquals(payload.getContentMetadata().getContentLength(), new Long(4)); - assertEquals(payload.getContentMetadata().getContentType(), "text/plain; charset=UTF-8"); - assertEquals(payload.getContentMetadata().getExpires(), dates.rfc822DateParse("Wed, 23 Jul 2014 14:00:00 GMT")); - - assertEquals(toStringAndClose(payload.openStream()), "ABCD"); - - assertEquals(server.getRequestCount(), 2); - assertEquals(server.takeRequest().getRequestLine(), "POST /tokens HTTP/1.1"); - RecordedRequest get = server.takeRequest(); - assertEquals(get.getRequestLine(), - "GET /v1/MossoCloudFS_5bcf396e-39dd-45ff-93a1-712b9aba90a9/myContainer/myObject HTTP/1.1"); - } finally { - server.shutdown(); - } - } - - @Test(expectedExceptions = HttpResponseException.class, timeOut = 20000) - public void testCreateWithTimeout() throws Exception { - MockWebServer server = mockOpenStackServer(); - server.enqueue(addCommonHeaders(new MockResponse().setBody(stringFromResource("/access.json")))); - // Typically we would enqueue a response for the put. However, in this case, test the timeout by not providing one. - - try { - Properties overrides = new Properties(); - - overrides.setProperty(PROPERTY_SO_TIMEOUT, 5000 + ""); // This time-outs the connection - overrides.setProperty(PROPERTY_MAX_RETRIES, 0 + ""); // 0 retries == 1 try. Semantics. - overrides.setProperty(PROPERTY_RETRY_DELAY_START, 0 + ""); // exponential backoff already working for this call. This is the delay BETWEEN attempts. - - final SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift", overrides); - - api.getObjectApiForRegionAndContainer("DFW", "myContainer").put("myObject", new ByteSourcePayload(ByteSource.wrap("swifty".getBytes())), metadata(metadata)); - - fail("testReplaceTimeout test should have failed with an HttpResponseException."); - } finally { - server.shutdown(); - } - } - - public void testUpdateMetadata() throws Exception { - MockWebServer server = mockOpenStackServer(); - server.enqueue(addCommonHeaders(new MockResponse().setBody(stringFromResource("/access.json")))); - server.enqueue(addCommonHeaders(objectResponse() - .addHeader(OBJECT_METADATA_PREFIX + "ApiName", "swift") - .addHeader(OBJECT_METADATA_PREFIX + "ApiVersion", "v1.1"))); - - try { - SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift"); - assertTrue(api.getObjectApiForRegionAndContainer("DFW", "myContainer").updateMetadata("myObject", metadata)); - - assertEquals(server.getRequestCount(), 2); - assertEquals(server.takeRequest().getRequestLine(), "POST /tokens HTTP/1.1"); - RecordedRequest replaceRequest = server.takeRequest(); - assertEquals(replaceRequest.getRequestLine(), - "POST /v1/MossoCloudFS_5bcf396e-39dd-45ff-93a1-712b9aba90a9/myContainer/myObject HTTP/1.1"); - for (Entry entry : metadata.entrySet()) { - assertEquals(replaceRequest.getHeader(OBJECT_METADATA_PREFIX + entry.getKey().toLowerCase()), entry.getValue()); - } - } finally { - server.shutdown(); - } - } - - public void testUpdateMetadataContentType() throws Exception { - MockWebServer server = mockOpenStackServer(); - server.enqueue(addCommonHeaders(new MockResponse().setBody(stringFromResource("/access.json")))); - server.enqueue(addCommonHeaders(objectResponse() - .addHeader(OBJECT_METADATA_PREFIX + "ApiName", "swift") - .addHeader(OBJECT_METADATA_PREFIX + "ApiVersion", "v1.1"))); - - try { - SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift"); - assertTrue(api.getObjectApiForRegionAndContainer("DFW", "myContainer").updateMetadata("myObject", metadata)); - - assertEquals(server.getRequestCount(), 2); - assertEquals(server.takeRequest().getRequestLine(), "POST /tokens HTTP/1.1"); - RecordedRequest replaceRequest = server.takeRequest(); - assertEquals(replaceRequest.getHeaders("Content-Type").get(0), "", "updateMetadata should send an empty content-type header, but sent " - + replaceRequest.getHeaders("Content-Type").get(0).toString()); - - assertEquals(replaceRequest.getRequestLine(), - "POST /v1/MossoCloudFS_5bcf396e-39dd-45ff-93a1-712b9aba90a9/myContainer/myObject HTTP/1.1"); - for (Entry entry : metadata.entrySet()) { - assertEquals(replaceRequest.getHeader(OBJECT_METADATA_PREFIX + entry.getKey().toLowerCase()), entry.getValue()); - } - } finally { - server.shutdown(); - } - } - - public void testDeleteMetadata() throws Exception { - MockWebServer server = mockOpenStackServer(); - server.enqueue(addCommonHeaders(new MockResponse().setBody(stringFromResource("/access.json")))); - server.enqueue(addCommonHeaders(objectResponse())); - - try { - SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift"); - assertTrue(api.getObjectApiForRegionAndContainer("DFW", "myContainer").deleteMetadata("myObject", metadata)); - - assertEquals(server.getRequestCount(), 2); - assertEquals(server.takeRequest().getRequestLine(), "POST /tokens HTTP/1.1"); - RecordedRequest deleteRequest = server.takeRequest(); - assertEquals(deleteRequest.getRequestLine(), - "POST /v1/MossoCloudFS_5bcf396e-39dd-45ff-93a1-712b9aba90a9/myContainer/myObject HTTP/1.1"); - for (String key : metadata.keySet()) { - assertEquals(deleteRequest.getHeader(OBJECT_REMOVE_METADATA_PREFIX + key.toLowerCase()), "ignored"); - } - } finally { - server.shutdown(); - } - } - - public void testDelete() throws Exception { - MockWebServer server = mockOpenStackServer(); - server.enqueue(addCommonHeaders(new MockResponse().setBody(stringFromResource("/access.json")))); - server.enqueue(addCommonHeaders(new MockResponse().setResponseCode(204))); - - try { - SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift"); - api.getObjectApiForRegionAndContainer("DFW", "myContainer").delete("myObject"); - - assertEquals(server.getRequestCount(), 2); - assertEquals(server.takeRequest().getRequestLine(), "POST /tokens HTTP/1.1"); - RecordedRequest deleteRequest = server.takeRequest(); - assertEquals(deleteRequest.getRequestLine(), - "DELETE /v1/MossoCloudFS_5bcf396e-39dd-45ff-93a1-712b9aba90a9/myContainer/myObject HTTP/1.1"); - } finally { - server.shutdown(); - } - } - - public void testAlreadyDeleted() throws Exception { - MockWebServer server = mockOpenStackServer(); - server.enqueue(addCommonHeaders(new MockResponse().setBody(stringFromResource("/access.json")))); - server.enqueue(addCommonHeaders(new MockResponse().setResponseCode(404))); - - try { - SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift"); - api.getObjectApiForRegionAndContainer("DFW", "myContainer").delete("myObject"); - - assertEquals(server.getRequestCount(), 2); - assertEquals(server.takeRequest().getRequestLine(), "POST /tokens HTTP/1.1"); - RecordedRequest deleteRequest = server.takeRequest(); - assertEquals(deleteRequest.getRequestLine(), - "DELETE /v1/MossoCloudFS_5bcf396e-39dd-45ff-93a1-712b9aba90a9/myContainer/myObject HTTP/1.1"); - } finally { - server.shutdown(); - } - } - - public void testCopyObject() throws Exception { - MockWebServer server = mockOpenStackServer(); - server.enqueue(addCommonHeaders(new MockResponse().setBody(stringFromResource("/access.json")))); - server.enqueue(addCommonHeaders(new MockResponse().setResponseCode(201) - .addHeader(SwiftHeaders.OBJECT_COPY_FROM, "/bar/foo.txt"))); - try { - SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift"); - assertTrue(api.getObjectApiForRegionAndContainer("DFW", "foo") - .copy("bar.txt", "bar", "foo.txt")); - - assertEquals(server.getRequestCount(), 2); - assertEquals(server.takeRequest().getRequestLine(), "POST /tokens HTTP/1.1"); - - RecordedRequest copyRequest = server.takeRequest(); - assertEquals(copyRequest.getRequestLine(), - "PUT /v1/MossoCloudFS_5bcf396e-39dd-45ff-93a1-712b9aba90a9/foo/bar.txt HTTP/1.1"); - } finally { - server.shutdown(); - } - } - - @Test(expectedExceptions = CopyObjectException.class) - public void testCopyObjectFail() throws InterruptedException, IOException { - MockWebServer server = mockOpenStackServer(); - server.enqueue(addCommonHeaders(new MockResponse().setBody(stringFromResource("/access.json")))); - server.enqueue(addCommonHeaders(new MockResponse().setResponseCode(404) - .addHeader(SwiftHeaders.OBJECT_COPY_FROM, "/bogus/foo.txt"))); - - try { - SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift"); - // the following line will throw the CopyObjectException - api.getObjectApiForRegionAndContainer("DFW", "foo").copy("bar.txt", "bogus", "foo.txt"); - } finally { - server.shutdown(); - } - } - - private static final Map metadata = ImmutableMap.of("ApiName", "swift", "ApiVersion", "v1.1"); - - static MockResponse objectResponse() { - return new MockResponse() - .addHeader("Last-Modified", "Fri, 12 Jun 2010 13:40:18 GMT") - .addHeader("ETag", "8a964ee2a5e88be344f36c22562a6486") - // TODO: MWS doesn't allow you to return content length w/o content - // on HEAD! - .setBody("ABCD".getBytes(US_ASCII)) - .addHeader("Content-Length", "4") - .addHeader("Content-Type", "text/plain; charset=UTF-8") - .addHeader(EXPIRES, "Wed, 23 Jul 2014 14:00:00 GMT"); - } - - static Payload payload(long bytes, String contentType, Date expires) { - Payload payload = newByteSourcePayload(ByteSource.empty()); - payload.getContentMetadata().setContentLength(bytes); - payload.getContentMetadata().setContentType(contentType); - payload.getContentMetadata().setExpires(expires); - return payload; - } -} diff --git a/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/StaticLargeObjectApiLiveTest.java b/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/StaticLargeObjectApiLiveTest.java deleted file mode 100644 index 28a5c8dcf6..0000000000 --- a/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/StaticLargeObjectApiLiveTest.java +++ /dev/null @@ -1,129 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF 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.openstack.swift.v1.features; - -import static java.lang.String.format; -import static org.jclouds.io.Payloads.newByteSourcePayload; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNotNull; - -import java.util.Arrays; -import java.util.List; -import java.util.UUID; - -import org.jclouds.openstack.swift.v1.SwiftApi; -import org.jclouds.openstack.swift.v1.domain.Segment; -import org.jclouds.openstack.swift.v1.domain.SwiftObject; -import org.jclouds.openstack.swift.v1.internal.BaseSwiftApiLiveTest; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; -import com.google.common.io.ByteSource; - -@Test(groups = "live", testName = "StaticLargeObjectApiLiveTest") -public class StaticLargeObjectApiLiveTest extends BaseSwiftApiLiveTest { - - private String name = getClass().getSimpleName(); - private String containerName = getClass().getSimpleName() + "Container"; - private byte[] megOf1s; - private byte[] megOf2s; - - public void testNotPresentWhenDeleting() throws Exception { - for (String regionId : regions) { - api.getStaticLargeObjectApiForRegionAndContainer(regionId, containerName).delete(UUID.randomUUID().toString()); - } - } - - public void testReplaceManifest() throws Exception { - for (String regionId : regions) { - ObjectApi objectApi = api.getObjectApiForRegionAndContainer(regionId, containerName); - - String etag1s = objectApi.put(name + "/1", newByteSourcePayload(ByteSource.wrap(megOf1s))); - assertMegabyteAndETagMatches(regionId, name + "/1", etag1s); - - String etag2s = objectApi.put(name + "/2", newByteSourcePayload(ByteSource.wrap(megOf2s))); - assertMegabyteAndETagMatches(regionId, name + "/2", etag2s); - - List segments = ImmutableList. builder() - .add(Segment.builder() - .path(format("%s/%s/1", containerName, name)).etag(etag1s).sizeBytes(1024 * 1024) - .build()) - .add(Segment.builder() - .path(format("%s/%s/2", containerName, name)).etag(etag2s).sizeBytes(1024 * 1024) - .build()) - .build(); - - String etagOfEtags = api.getStaticLargeObjectApiForRegionAndContainer(regionId, containerName).replaceManifest( - name, segments, ImmutableMap.of("myfoo", "Bar")); - - assertNotNull(etagOfEtags); - - SwiftObject bigObject = api.getObjectApiForRegionAndContainer(regionId, containerName).get(name); - assertEquals(bigObject.getETag(), etagOfEtags); - assertEquals(bigObject.getPayload().getContentMetadata().getContentLength(), new Long(2 * 1024 * 1024)); - assertEquals(bigObject.getMetadata(), ImmutableMap.of("myfoo", "Bar")); - - // segments are visible - assertEquals(api.getContainerApiForRegion(regionId).get(containerName).getObjectCount(), 3); - } - } - - @Test(dependsOnMethods = "testReplaceManifest") - public void testDelete() throws Exception { - for (String regionId : regions) { - api.getStaticLargeObjectApiForRegionAndContainer(regionId, containerName).delete(name); - assertEquals(api.getContainerApiForRegion(regionId).get(containerName).getObjectCount(), 0); - } - } - - protected void assertMegabyteAndETagMatches(String regionId, String name, String etag1s) { - SwiftObject object1s = api.getObjectApiForRegionAndContainer(regionId, containerName).get(name); - assertEquals(object1s.getETag(), etag1s); - assertEquals(object1s.getPayload().getContentMetadata().getContentLength(), new Long(1024 * 1024)); - } - - @Override - @BeforeClass(groups = "live") - public void setup() { - super.setup(); - for (String regionId : regions) { - boolean created = api.getContainerApiForRegion(regionId).create(containerName); - if (!created) { - deleteAllObjectsInContainer(regionId, containerName); - } - } - - megOf1s = new byte[1024 * 1024]; - megOf2s = new byte[1024 * 1024]; - - Arrays.fill(megOf1s, (byte) 1); - Arrays.fill(megOf2s, (byte) 2); - } - - @Override - @AfterClass(groups = "live") - public void tearDown() { - for (String regionId : regions) { - deleteAllObjectsInContainer(regionId, containerName); - api.getContainerApiForRegion(regionId).deleteIfEmpty(containerName); - } - super.tearDown(); - } -} diff --git a/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/StaticLargeObjectApiMockTest.java b/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/StaticLargeObjectApiMockTest.java deleted file mode 100644 index 0d150d5433..0000000000 --- a/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/StaticLargeObjectApiMockTest.java +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF 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.openstack.swift.v1.features; - -import static org.jclouds.openstack.swift.v1.reference.SwiftHeaders.OBJECT_METADATA_PREFIX; -import static org.testng.Assert.assertEquals; - -import org.jclouds.openstack.swift.v1.SwiftApi; -import org.jclouds.openstack.swift.v1.domain.Segment; -import org.jclouds.openstack.v2_0.internal.BaseOpenStackMockTest; -import org.testng.annotations.Test; - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; -import com.google.common.net.HttpHeaders; -import com.squareup.okhttp.mockwebserver.MockResponse; -import com.squareup.okhttp.mockwebserver.MockWebServer; -import com.squareup.okhttp.mockwebserver.RecordedRequest; - -@Test(groups = "unit", testName = "StaticLargeObjectApiMockTest") -public class StaticLargeObjectApiMockTest extends BaseOpenStackMockTest { - - public void testReplaceManifest() throws Exception { - MockWebServer server = mockOpenStackServer(); - server.enqueue(addCommonHeaders(new MockResponse().setBody(stringFromResource("/access.json")))); - server.enqueue(addCommonHeaders(new MockResponse().addHeader(HttpHeaders.ETAG, "\"abcd\""))); - - try { - SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift"); - assertEquals( - api.getStaticLargeObjectApiForRegionAndContainer("DFW", "myContainer").replaceManifest( - "myObject", - ImmutableList - . builder() - .add(Segment.builder().path("/mycontainer/objseg1").etag("0228c7926b8b642dfb29554cd1f00963") - .sizeBytes(1468006).build()) - .add(Segment.builder().path("/mycontainer/pseudodir/seg-obj2") - .etag("5bfc9ea51a00b790717eeb934fb77b9b").sizeBytes(1572864).build()) - .add(Segment.builder().path("/other-container/seg-final") - .etag("b9c3da507d2557c1ddc51f27c54bae51").sizeBytes(256).build()).build(), - ImmutableMap.of("MyFoo", "Bar")), "abcd"); - - assertEquals(server.getRequestCount(), 2); - assertAuthentication(server); - - RecordedRequest replaceRequest = server.takeRequest(); - assertRequest(replaceRequest, "PUT", "/v1/MossoCloudFS_5bcf396e-39dd-45ff-93a1-712b9aba90a9/myContainer/myObject?multipart-manifest=put"); - assertEquals(replaceRequest.getHeader(OBJECT_METADATA_PREFIX + "myfoo"), "Bar"); - assertEquals( - new String(replaceRequest.getBody()), - "[{\"path\":\"/mycontainer/objseg1\",\"etag\":\"0228c7926b8b642dfb29554cd1f00963\",\"size_bytes\":1468006}," + - "{\"path\":\"/mycontainer/pseudodir/seg-obj2\",\"etag\":\"5bfc9ea51a00b790717eeb934fb77b9b\",\"size_bytes\":1572864}," + - "{\"path\":\"/other-container/seg-final\",\"etag\":\"b9c3da507d2557c1ddc51f27c54bae51\",\"size_bytes\":256}]"); - } finally { - server.shutdown(); - } - } - - public void testDelete() throws Exception { - MockWebServer server = mockOpenStackServer(); - server.enqueue(addCommonHeaders(new MockResponse().setBody(stringFromResource("/access.json")))); - server.enqueue(addCommonHeaders(new MockResponse().setResponseCode(204))); - - try { - SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift"); - api.getStaticLargeObjectApiForRegionAndContainer("DFW", "myContainer").delete("myObject"); - - assertEquals(server.getRequestCount(), 2); - assertAuthentication(server); - assertRequest(server.takeRequest(), "DELETE", "/v1/MossoCloudFS_5bcf396e-39dd-45ff-93a1-712b9aba90a9/myContainer/myObject?multipart-manifest=delete"); - - } finally { - server.shutdown(); - } - } - - public void testAlreadyDeleted() throws Exception { - MockWebServer server = mockOpenStackServer(); - server.enqueue(addCommonHeaders(new MockResponse().setBody(stringFromResource("/access.json")))); - server.enqueue(addCommonHeaders(new MockResponse().setResponseCode(404))); - - try { - SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift"); - api.getStaticLargeObjectApiForRegionAndContainer("DFW", "myContainer").delete("myObject"); - - assertEquals(server.getRequestCount(), 2); - assertAuthentication(server); - assertRequest(server.takeRequest(), "DELETE", "/v1/MossoCloudFS_5bcf396e-39dd-45ff-93a1-712b9aba90a9/myContainer/myObject?multipart-manifest=delete"); - } finally { - server.shutdown(); - } - } -} diff --git a/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/UrlEncodeAndJoinOnNewlineTest.java b/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/UrlEncodeAndJoinOnNewlineTest.java deleted file mode 100644 index c811571c59..0000000000 --- a/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/UrlEncodeAndJoinOnNewlineTest.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF 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.openstack.swift.v1.features; - -import static org.testng.Assert.assertEquals; - -import org.jclouds.http.HttpRequest; -import org.jclouds.openstack.swift.v1.features.BulkApi.UrlEncodeAndJoinOnNewline; -import org.testng.annotations.Test; - -import com.google.common.collect.ImmutableList; - -@Test(groups = "unit", testName = "UrlEncodeAndJoinOnNewlineTest") -public class UrlEncodeAndJoinOnNewlineTest { - UrlEncodeAndJoinOnNewline binder = new UrlEncodeAndJoinOnNewline(); - - public void urlEncodesPaths() { - HttpRequest request = HttpRequest.builder() - .method("DELETE") - .endpoint("https://storage101.dfw1.clouddrive.com/v1/MossoCloudFS_XXXXXX/") - .addQueryParam("bulk-delete").build(); - - request = binder.bindToRequest(request, ImmutableList. builder() - .add("/v1/12345678912345/mycontainer/home/xx extends BaseApiLiveTest { - - protected Set regions; - - protected BaseSwiftApiLiveTest() { - provider = "openstack-swift"; - } - - @Override - @BeforeClass(groups = "live") - public void setup() { - super.setup(); - String providedRegion = System.getProperty("test." + LocationConstants.PROPERTY_REGION); - if (providedRegion != null) { - regions = ImmutableSet.of(providedRegion); - } else { - regions = api.getConfiguredRegions(); - } - } - - @Override - protected Properties setupProperties() { - Properties props = super.setupProperties(); - setIfTestSystemPropertyPresent(props, KeystoneProperties.CREDENTIAL_TYPE); - setIfTestSystemPropertyPresent(props, LocationConstants.PROPERTY_REGION); - return props; - } - - protected void deleteAllObjectsInContainer(String regionId, final String containerName) { - Uninterruptibles.sleepUninterruptibly(10, TimeUnit.SECONDS); - - ObjectList objects = api.getObjectApiForRegionAndContainer(regionId, containerName).list(new ListContainerOptions()); - if (objects == null) { - return; - } - List pathsToDelete = Lists.transform(objects, new Function() { - public String apply(SwiftObject input) { - return containerName + "/" + input.getName(); - } - }); - if (!pathsToDelete.isEmpty()) { - BulkDeleteResponse response = api.getBulkApiForRegion(regionId).bulkDelete(pathsToDelete); - checkState(response.getErrors().isEmpty(), "Errors deleting paths %s: %s", pathsToDelete, response); - } - } -} diff --git a/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/options/CreateContainerOptionsTest.java b/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/options/CreateContainerOptionsTest.java deleted file mode 100644 index 1da648bfe4..0000000000 --- a/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/options/CreateContainerOptionsTest.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF 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.openstack.swift.v1.options; - -import static org.jclouds.openstack.swift.v1.reference.SwiftHeaders.CONTAINER_ACL_ANYBODY_READ; -import static org.jclouds.openstack.swift.v1.reference.SwiftHeaders.CONTAINER_METADATA_PREFIX; -import static org.jclouds.openstack.swift.v1.reference.SwiftHeaders.CONTAINER_READ; -import static org.jclouds.openstack.swift.v1.reference.SwiftHeaders.VERSIONS_LOCATION; -import static org.jclouds.openstack.swift.v1.reference.SwiftHeaders.CONTAINER_QUOTA_BYTES; -import static org.testng.Assert.assertEquals; - -import org.testng.annotations.Test; - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableMultimap; -import com.google.common.collect.Multimap; - -/** - * Tests behavior of {@link CreateContainerOptions}. - */ -@Test(groups = "unit") -public class CreateContainerOptionsTest { - - public void testMetadata() { - CreateContainerOptions options = - new CreateContainerOptions().metadata(ImmutableMap.of("ApiName", "swift", "metaKey2", "Value2", "METAKEY3", "VALUE 3 ")); - - Multimap headers = options.buildRequestHeaders(); - assertEquals(headers.get(CONTAINER_METADATA_PREFIX + "apiname"), ImmutableList.of("swift")); - assertEquals(headers.get(CONTAINER_METADATA_PREFIX + "metakey2"), ImmutableList.of("Value2")); - assertEquals(headers.get(CONTAINER_METADATA_PREFIX + "metakey3"), ImmutableList.of("VALUE 3 ")); - } - - public void testHeaders() { - CreateContainerOptions options = - new CreateContainerOptions().headers(ImmutableMultimap.of(CONTAINER_QUOTA_BYTES, "5120", CONTAINER_METADATA_PREFIX + "apiname", "swift")); - - Multimap headers = options.buildRequestHeaders(); - assertEquals(headers.get(CONTAINER_QUOTA_BYTES), ImmutableList.of("5120")); - assertEquals(headers.get(CONTAINER_METADATA_PREFIX + "apiname"), ImmutableList.of("swift")); - } - - public void testAnybodyRead() { - CreateContainerOptions options = - new CreateContainerOptions().headers(ImmutableMultimap.of(CONTAINER_READ, CONTAINER_ACL_ANYBODY_READ)); - assertEquals(options.buildRequestHeaders().get(CONTAINER_READ), ImmutableList.of(CONTAINER_ACL_ANYBODY_READ)); - } - - public void testVersionsLocation() { - CreateContainerOptions options = - new CreateContainerOptions().headers(ImmutableMultimap.of(VERSIONS_LOCATION, "containerWithVersions")); - assertEquals(options.buildRequestHeaders().get(VERSIONS_LOCATION), ImmutableList.of("containerWithVersions")); - } -} diff --git a/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/options/PutOptionsTest.java b/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/options/PutOptionsTest.java deleted file mode 100644 index fddf4cd6f7..0000000000 --- a/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/options/PutOptionsTest.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF 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.openstack.swift.v1.options; - -import static org.jclouds.openstack.swift.v1.reference.SwiftHeaders.OBJECT_METADATA_PREFIX; -import static org.jclouds.openstack.swift.v1.reference.SwiftHeaders.OBJECT_DELETE_AT; -import static org.testng.Assert.assertEquals; - -import org.testng.annotations.Test; - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableMultimap; - -/** - * Tests behavior of {@link PutOptions}. - */ -@Test(groups = "unit") -public class PutOptionsTest { - - public void testPutMetadata() { - PutOptions options = - new PutOptions().metadata(ImmutableMap.of("ApiName", "swift")); - assertEquals(options.buildRequestHeaders().get(OBJECT_METADATA_PREFIX + "apiname"), ImmutableList.of("swift")); - - } - - public void testPutHeaders() { - PutOptions options = - new PutOptions().headers(ImmutableMultimap.of(OBJECT_DELETE_AT, "123456789")); - assertEquals(options.buildRequestHeaders().get(OBJECT_DELETE_AT), ImmutableList.of("123456789")); - } - -} diff --git a/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/options/UpdateContainerOptionsTest.java b/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/options/UpdateContainerOptionsTest.java deleted file mode 100644 index 00f95f76d8..0000000000 --- a/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/options/UpdateContainerOptionsTest.java +++ /dev/null @@ -1,122 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF 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.openstack.swift.v1.options; - -import static org.jclouds.openstack.swift.v1.reference.SwiftHeaders.CONTAINER_ACL_ANYBODY_READ; -import static org.jclouds.openstack.swift.v1.reference.SwiftHeaders.CONTAINER_METADATA_PREFIX; -import static org.jclouds.openstack.swift.v1.reference.SwiftHeaders.CONTAINER_QUOTA_BYTES; -import static org.jclouds.openstack.swift.v1.reference.SwiftHeaders.CONTAINER_READ; -import static org.jclouds.openstack.swift.v1.reference.SwiftHeaders.VERSIONS_LOCATION; -import static org.jclouds.openstack.swift.v1.reference.SwiftHeaders.STATIC_WEB_DIRECTORY_TYPE; -import static org.jclouds.openstack.swift.v1.reference.SwiftHeaders.STATIC_WEB_ERROR; -import static org.jclouds.openstack.swift.v1.reference.SwiftHeaders.STATIC_WEB_INDEX; -import static org.jclouds.openstack.swift.v1.reference.SwiftHeaders.STATIC_WEB_LISTINGS; -import static org.jclouds.openstack.swift.v1.reference.SwiftHeaders.STATIC_WEB_LISTINGS_CSS; -import static org.testng.Assert.assertEquals; - -import org.testng.annotations.Test; - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableMultimap; -import com.google.common.collect.Multimap; -import com.google.common.net.MediaType; - -/** - * Tests behavior of {@link UpdateContainerOptions}. - */ -@Test(groups = "unit") -public class UpdateContainerOptionsTest { - - public void testAnybodyRead() { - UpdateContainerOptions options = new UpdateContainerOptions().anybodyRead(); - assertEquals(options.buildRequestHeaders().get(CONTAINER_READ), ImmutableList.of(CONTAINER_ACL_ANYBODY_READ)); - } - - public void testAnybodyReadViaHeaders() { - UpdateContainerOptions options = - new UpdateContainerOptions().headers(ImmutableMultimap.of(CONTAINER_READ, CONTAINER_ACL_ANYBODY_READ)); - assertEquals(options.buildRequestHeaders().get(CONTAINER_READ), ImmutableList.of(CONTAINER_ACL_ANYBODY_READ)); - } - - public void testVersionsLocation() { - UpdateContainerOptions options = new UpdateContainerOptions().versionsLocation("containerWithVersions"); - assertEquals(options.buildRequestHeaders().get(VERSIONS_LOCATION), ImmutableList.of("containerWithVersions")); - } - - public void testVersionsLocationViaHeaders() { - UpdateContainerOptions options = - new UpdateContainerOptions().headers(ImmutableMultimap.of(VERSIONS_LOCATION, "containerWithVersions")); - assertEquals(options.buildRequestHeaders().get(VERSIONS_LOCATION), ImmutableList.of("containerWithVersions")); - } - - public void testMetadata() { - UpdateContainerOptions options = - new UpdateContainerOptions().metadata(ImmutableMap.of("ApiName", "swift", "metaKey2", "Value2", "METAKEY3", "VALUE 3 ")); - - Multimap headers = options.buildRequestHeaders(); - assertEquals(headers.get(CONTAINER_METADATA_PREFIX + "apiname"), ImmutableList.of("swift")); - assertEquals(headers.get(CONTAINER_METADATA_PREFIX + "metakey2"), ImmutableList.of("Value2")); - assertEquals(headers.get(CONTAINER_METADATA_PREFIX + "metakey3"), ImmutableList.of("VALUE 3 ")); - } - - public void testHeaders() { - UpdateContainerOptions options = - new UpdateContainerOptions().headers(ImmutableMultimap.of(CONTAINER_QUOTA_BYTES, "5120", CONTAINER_METADATA_PREFIX + "apiname", "swift")); - - Multimap headers = options.buildRequestHeaders(); - assertEquals(headers.get(CONTAINER_QUOTA_BYTES), ImmutableList.of("5120")); - assertEquals(headers.get(CONTAINER_METADATA_PREFIX + "apiname"), ImmutableList.of("swift")); - } - - public void testStaticWebsiteDirectoryType() { - MediaType appDir = MediaType.create("application", "directory"); - Multimap headers = ImmutableMultimap.of(STATIC_WEB_DIRECTORY_TYPE, appDir.toString()); - UpdateContainerOptions options = new UpdateContainerOptions().headers(headers); - assertEquals(options.buildRequestHeaders().get(STATIC_WEB_DIRECTORY_TYPE), ImmutableList.of(appDir.toString())); - } - - public void testStaticWebsiteIndexPage() { - Multimap headers = ImmutableMultimap.of(STATIC_WEB_INDEX, "index.html"); - UpdateContainerOptions options = new UpdateContainerOptions().headers(headers); - assertEquals(options.buildRequestHeaders().get(STATIC_WEB_INDEX), ImmutableList.of("index.html")); - } - - public void testStaticWebsiteErrorPage() { - Multimap headers = ImmutableMultimap.of(STATIC_WEB_ERROR, "error.html"); - UpdateContainerOptions options = new UpdateContainerOptions().headers(headers); - assertEquals(options.buildRequestHeaders().get(STATIC_WEB_ERROR), ImmutableList.of("error.html")); - } - - public void testEnableStaticWebsiteListings() { - Multimap headers = ImmutableMultimap.of(STATIC_WEB_LISTINGS, "true"); - UpdateContainerOptions options = new UpdateContainerOptions().headers(headers); - assertEquals(options.buildRequestHeaders().get(STATIC_WEB_LISTINGS), ImmutableList.of("true")); - } - - public void testDiableStaticWebsiteListings() { - Multimap headers = ImmutableMultimap.of(STATIC_WEB_LISTINGS, "false"); - UpdateContainerOptions options = new UpdateContainerOptions().headers(headers); - assertEquals(options.buildRequestHeaders().get(STATIC_WEB_LISTINGS), ImmutableList.of("false")); - } - - public void testStaticWebsiteListingsCSS() { - Multimap headers = ImmutableMultimap.of(STATIC_WEB_LISTINGS_CSS, "listings.css"); - UpdateContainerOptions options = new UpdateContainerOptions().headers(headers); - assertEquals(options.buildRequestHeaders().get(STATIC_WEB_LISTINGS_CSS), ImmutableList.of("listings.css")); - } -} diff --git a/openstack-swift/src/test/resources/access.json b/openstack-swift/src/test/resources/access.json deleted file mode 100644 index 8e0a69c78b..0000000000 --- a/openstack-swift/src/test/resources/access.json +++ /dev/null @@ -1,249 +0,0 @@ -{ - "access":{ - "token":{ - "id":"bb03a23aa8271291a7aaa9aaa2aaaaaa", - "expires":"2013-08-02T16:55:24.229-05:00", - "tenant":{ - "id":"888888", - "name":"888888" - }, - "RAX-AUTH:authenticatedBy":[ - "PASSWORD" - ] - }, - "serviceCatalog":[ - { - "name":"cloudFilesCDN", - "endpoints":[ - { - "region":"ORD", - "tenantId":"MossoCloudFS_5bcf396e-39dd-45ff-93a1-712b9aba90a9", - "publicURL":"URL/v1\/MossoCloudFS_5bcf396e-39dd-45ff-93a1-712b9aba90a9" - }, - { - "region":"DFW", - "tenantId":"MossoCloudFS_5bcf396e-39dd-45ff-93a1-712b9aba90a9", - "publicURL":"URL/v1\/MossoCloudFS_5bcf396e-39dd-45ff-93a1-712b9aba90a9" - }, - { - "region":"SYD", - "tenantId":"MossoCloudFS_5bcf396e-39dd-45ff-93a1-712b9aba90a9", - "publicURL":"URL/v1\/MossoCloudFS_5bcf396e-39dd-45ff-93a1-712b9aba90a9" - } - ], - "type":"rax:object-cdn" - }, - { - "name":"cloudFiles", - "endpoints":[ - { - "region":"ORD", - "tenantId":"MossoCloudFS_5bcf396e-39dd-45ff-93a1-712b9aba90a9", - "publicURL":"URL/v1\/MossoCloudFS_5bcf396e-39dd-45ff-93a1-712b9aba90a9", - "internalURL":"URL/v1\/MossoCloudFS_5bcf396e-39dd-45ff-93a1-712b9aba90a9" - }, - { - "region":"DFW", - "tenantId":"MossoCloudFS_5bcf396e-39dd-45ff-93a1-712b9aba90a9", - "publicURL":"URL/v1\/MossoCloudFS_5bcf396e-39dd-45ff-93a1-712b9aba90a9", - "internalURL":"URL/v1\/MossoCloudFS_5bcf396e-39dd-45ff-93a1-712b9aba90a9" - }, - { - "region":"SYD", - "tenantId":"MossoCloudFS_5bcf396e-39dd-45ff-93a1-712b9aba90a9", - "publicURL":"URL/v1\/MossoCloudFS_5bcf396e-39dd-45ff-93a1-712b9aba90a9", - "internalURL":"URL/v1\/MossoCloudFS_5bcf396e-39dd-45ff-93a1-712b9aba90a9" - } - ], - "type":"object-store" - }, - { - "name":"cloudLoadBalancers", - "endpoints":[ - { - "region":"SYD", - "tenantId":"888888", - "publicURL":"URL/v1.0\/888888" - }, - { - "region":"DFW", - "tenantId":"888888", - "publicURL":"URL/v1.0\/888888" - }, - { - "region":"ORD", - "tenantId":"888888", - "publicURL":"URL/v1.0\/888888" - } - ], - "type":"rax:load-balancer" - }, - { - "name":"cloudDatabases", - "endpoints":[ - { - "region":"SYD", - "tenantId":"888888", - "publicURL":"URL/v1.0\/888888" - }, - { - "region":"DFW", - "tenantId":"888888", - "publicURL":"URL/v1.0\/888888" - }, - { - "region":"ORD", - "tenantId":"888888", - "publicURL":"URL/v1.0\/888888" - } - ], - "type":"rax:database" - }, - { - "name":"cloudBlockStorage", - "endpoints":[ - { - "region":"SYD", - "tenantId":"888888", - "publicURL":"URL/v1\/888888" - }, - { - "region":"DFW", - "tenantId":"888888", - "publicURL":"URL/v1\/888888" - }, - { - "region":"ORD", - "tenantId":"888888", - "publicURL":"URL/v1\/888888" - } - ], - "type":"volume" - }, - { - "name":"cloudServersOpenStack", - "endpoints":[ - { - "region":"SYD", - "tenantId":"888888", - "publicURL":"URL/v2\/888888", - "versionInfo":"https:\/\/syd.servers.api.rackspacecloud.com\/v2", - "versionList":"https:\/\/syd.servers.api.rackspacecloud.com\/", - "versionId":"2" - }, - { - "region":"DFW", - "tenantId":"888888", - "publicURL":"URL/v2\/888888", - "versionInfo":"https:\/\/dfw.servers.api.rackspacecloud.com\/v2", - "versionList":"https:\/\/dfw.servers.api.rackspacecloud.com\/", - "versionId":"2" - }, - { - "region":"ORD", - "tenantId":"888888", - "publicURL":"URL/v2\/888888", - "versionInfo":"https:\/\/ord.servers.api.rackspacecloud.com\/v2", - "versionList":"https:\/\/ord.servers.api.rackspacecloud.com\/", - "versionId":"2" - } - ], - "type":"compute" - }, - { - "name":"autoscale", - "endpoints":[ - { - "region":"ORD", - "tenantId":"888888", - "publicURL":"URL/v1.0\/888888", - "versionInfo":null, - "versionList":null, - "versionId":"1.0" - }, - { - "region":"DFW", - "tenantId":"888888", - "publicURL":"URL/v1.0\/888888", - "versionInfo":null, - "versionList":null, - "versionId":"1.0" - } - ], - "type":"rax:autoscale" - }, - { - "name":"cloudMonitoring", - "endpoints":[ - { - "tenantId":"888888", - "publicURL":"URL/v1.0\/888888" - } - ], - "type":"rax:monitor" - }, - { - "name":"cloudBackup", - "endpoints":[ - { - "tenantId":"888888", - "publicURL":"URL/v1.0\/888888" - } - ], - "type":"rax:backup" - }, - { - "name":"cloudServers", - "endpoints":[ - { - "tenantId":"888888", - "publicURL":"URL/v1.0\/888888", - "versionInfo":"https:\/\/servers.api.rackspacecloud.com\/v1.0", - "versionList":"https:\/\/servers.api.rackspacecloud.com\/", - "versionId":"1.0" - } - ], - "type":"compute" - }, - { - "name":"cloudDNS", - "endpoints":[ - { - "tenantId":"888888", - "publicURL":"URL/v1.0\/888888" - } - ], - "type":"rax:dns" - } - ], - "user":{ - "id":"335853", - "roles":[ - { - "id":"10000150", - "description":"Checkmate Access role", - "name":"checkmate" - }, - { - "tenantId":"MossoCloudFS_5bcf396e-39dd-45ff-93a1-712b9aba90a9", - "id":"5", - "description":"A Role that allows a user access to keystone Service methods", - "name":"object-store:default" - }, - { - "tenantId":"888888", - "id":"6", - "description":"A Role that allows a user access to keystone Service methods", - "name":"compute:default" - }, - { - "id":"3", - "description":"User Admin Role.", - "name":"identity:user-admin" - } - ], - "name":"test", - "RAX-AUTH:defaultRegion":"ORD" - } - } -} diff --git a/openstack-swift/src/test/resources/container_list.json b/openstack-swift/src/test/resources/container_list.json deleted file mode 100644 index 554f5de299..0000000000 --- a/openstack-swift/src/test/resources/container_list.json +++ /dev/null @@ -1,12 +0,0 @@ -[ - { - "name": "test_container_1", - "count": 2, - "bytes": 78 - }, - { - "name": "test_container_2", - "count": 1, - "bytes": 17 - } -] diff --git a/openstack-swift/src/test/resources/logback.xml b/openstack-swift/src/test/resources/logback.xml deleted file mode 100644 index ce891f1098..0000000000 --- a/openstack-swift/src/test/resources/logback.xml +++ /dev/null @@ -1,71 +0,0 @@ - - - - - target/test-data/jclouds.log - - - %d %-5p [%c] [%thread] %m%n - - - - - target/test-data/jclouds-wire.log - - - %d %-5p [%c] [%thread] %m%n - - - - - target/test-data/jclouds-blobstore.log - - - %d %-5p [%c] [%thread] %m%n - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/openstack-swift/src/test/resources/object_list.json b/openstack-swift/src/test/resources/object_list.json deleted file mode 100644 index afe8c77470..0000000000 --- a/openstack-swift/src/test/resources/object_list.json +++ /dev/null @@ -1,23 +0,0 @@ -[ - { - "name": "test_obj_1", - "hash": "4281c348eaf83e70ddce0e07221c3d28", - "bytes": 14, - "content_type": "application/octet-stream", - "last_modified": "2009-02-03T05:26:32.612278" - }, - { - "name": "test_obj_2", - "hash": "b039efe731ad111bc1b0ef221c3849d0", - "bytes": 64, - "content_type": "application/octet-stream", - "last_modified": "2009-02-03T05:26:32.612278" - }, - { - "name": "test obj 3", - "hash": "0b2e80bd0744d9ebb20484149a57c82e", - "bytes": 123, - "content_type": "application/octet-stream", - "last_modified": "2014-05-20T05:26:32.612278" - } -] diff --git a/pom.xml b/pom.xml index b86ff9e1c5..226c58304f 100644 --- a/pom.xml +++ b/pom.xml @@ -71,7 +71,6 @@ openstack-glance openstack-heat openstack-neutron - openstack-swift openstack-marconi rackspace-autoscale rackspace-autoscale-uk diff --git a/rackspace-cloudfiles-uk/pom.xml b/rackspace-cloudfiles-uk/pom.xml index 911189f7cb..9327619d59 100644 --- a/rackspace-cloudfiles-uk/pom.xml +++ b/rackspace-cloudfiles-uk/pom.xml @@ -65,14 +65,14 @@ - org.apache.jclouds.labs + org.apache.jclouds.api openstack-swift ${project.parent.version} test-jar test - org.apache.jclouds.labs + org.apache.jclouds.api openstack-swift ${project.parent.version} diff --git a/rackspace-cloudfiles-us/pom.xml b/rackspace-cloudfiles-us/pom.xml index d6224ecb51..ac09cbbec7 100644 --- a/rackspace-cloudfiles-us/pom.xml +++ b/rackspace-cloudfiles-us/pom.xml @@ -65,14 +65,14 @@ - org.apache.jclouds.labs + org.apache.jclouds.api openstack-swift ${project.parent.version} test-jar test - org.apache.jclouds.labs + org.apache.jclouds.api openstack-swift ${project.parent.version} diff --git a/rackspace-cloudfiles/pom.xml b/rackspace-cloudfiles/pom.xml index a678e5d0e6..fc1a03320c 100644 --- a/rackspace-cloudfiles/pom.xml +++ b/rackspace-cloudfiles/pom.xml @@ -60,12 +60,12 @@ - org.apache.jclouds.labs + org.apache.jclouds.api openstack-swift ${project.parent.version} - org.apache.jclouds.labs + org.apache.jclouds.api openstack-swift ${project.parent.version} test-jar