You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jclouds.apache.org by jd...@apache.org on 2014/05/22 17:12:05 UTC
[2/2] git commit: JCLOUDS-545: Use established conventions for
OpenStack APIs, updates JavaDocs and tests
JCLOUDS-545: Use established conventions for OpenStack APIs, updates JavaDocs and tests
Project: http://git-wip-us.apache.org/repos/asf/jclouds-labs-openstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/jclouds-labs-openstack/commit/3fc89736
Tree: http://git-wip-us.apache.org/repos/asf/jclouds-labs-openstack/tree/3fc89736
Diff: http://git-wip-us.apache.org/repos/asf/jclouds-labs-openstack/diff/3fc89736
Branch: refs/heads/master
Commit: 3fc8973629b896b1e495c8212388a5ed2f5fd2e3
Parents: 1c74873
Author: Jeremy Daggett <je...@rackspace.com>
Authored: Wed Apr 23 12:39:14 2014 -0700
Committer: Jeremy Daggett <je...@rackspace.com>
Committed: Thu May 22 07:56:37 2014 -0700
----------------------------------------------------------------------
.../jclouds/openstack/swift/v1/SwiftApi.java | 56 +++++++++-
.../blobstore/RegionScopedSwiftBlobStore.java | 45 ++++----
.../RegionScopedTemporaryUrlBlobSigner.java | 2 +-
.../openstack/swift/v1/domain/Account.java | 6 +-
.../swift/v1/domain/BulkDeleteResponse.java | 17 +--
.../openstack/swift/v1/domain/Container.java | 9 +-
.../swift/v1/domain/ExtractArchiveResponse.java | 15 +--
.../openstack/swift/v1/domain/ObjectList.java | 4 +-
.../openstack/swift/v1/domain/Segment.java | 38 ++++---
.../openstack/swift/v1/domain/SwiftObject.java | 20 ++--
.../openstack/swift/v1/features/AccountApi.java | 2 +-
.../openstack/swift/v1/features/BulkApi.java | 8 +-
.../swift/v1/features/ContainerApi.java | 88 +++++++++++----
.../openstack/swift/v1/features/ObjectApi.java | 107 +++++++++++++++----
.../swift/v1/features/StaticLargeObjectApi.java | 2 +-
.../v1/options/CreateContainerOptions.java | 6 +-
.../openstack/swift/v1/options/PutOptions.java | 59 ++++++++++
.../swift/v1/AuthenticationMockTest.java | 2 +-
.../swift/v1/SwiftErrorHandlerTest.java | 9 +-
.../swift/v1/TemporaryUrlSignerLiveTest.java | 27 +++--
.../swift/v1/TemporaryUrlSignerMockTest.java | 4 +-
.../swift/v1/features/AccountApiLiveTest.java | 6 +-
.../swift/v1/features/AccountApiMockTest.java | 8 +-
.../swift/v1/features/BulkApiLiveTest.java | 40 +++----
.../swift/v1/features/BulkApiMockTest.java | 16 +--
.../swift/v1/features/ContainerApiLiveTest.java | 24 ++---
.../swift/v1/features/ContainerApiMockTest.java | 33 +++---
.../features/CreatePublicContainerLiveTest.java | 10 +-
.../swift/v1/features/ObjectApiLiveTest.java | 77 +++++++------
.../swift/v1/features/ObjectApiMockTest.java | 52 ++++-----
.../features/StaticLargeObjectApiLiveTest.java | 53 ++++-----
.../features/StaticLargeObjectApiMockTest.java | 6 +-
.../swift/v1/internal/BaseSwiftApiLiveTest.java | 6 +-
.../rackspace/cloudfiles/v1/CloudFilesApi.java | 4 +-
.../cloudfiles/v1/features/CDNApi.java | 15 ++-
.../features/CloudFilesAccountApiLiveTest.java | 4 +-
.../v1/features/CloudFilesCDNApiLiveTest.java | 38 +++----
.../v1/features/CloudFilesCDNApiMockTest.java | 38 +++----
38 files changed, 598 insertions(+), 358 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/jclouds-labs-openstack/blob/3fc89736/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/SwiftApi.java
----------------------------------------------------------------------
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
index 7874403..20cda73 100644
--- 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
@@ -44,33 +44,81 @@ import com.google.inject.Provides;
* <p/>
* 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.
+ * {@code org.jclouds.openstack.swift.SwiftClient} in jclouds 2.0 and it is recommended you adopt it sooner than later.
*
- * @author Adrian Cole
- * @author Jeremy Daggett
- * @author Zack Shoylev
*/
@Beta
public interface SwiftApi extends Closeable {
@Provides
@Region
+ Set<String> 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<String> 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(
http://git-wip-us.apache.org/repos/asf/jclouds-labs-openstack/blob/3fc89736/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/blobstore/RegionScopedSwiftBlobStore.java
----------------------------------------------------------------------
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
index 480034a..211f8c8 100644
--- 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
@@ -22,6 +22,7 @@ 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;
@@ -49,7 +50,7 @@ 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.ByteArrayPayload;
+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;
@@ -67,8 +68,8 @@ 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.ImmutableMap;
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;
@@ -82,6 +83,7 @@ public class RegionScopedSwiftBlobStore implements BlobStore {
Optional<? extends Location> 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;
@@ -98,6 +100,7 @@ public class RegionScopedSwiftBlobStore implements BlobStore {
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;
@@ -110,14 +113,14 @@ public class RegionScopedSwiftBlobStore implements BlobStore {
@Override
public PageSet<? extends StorageMetadata> list() {
// TODO: there may eventually be >10k containers..
- FluentIterable<StorageMetadata> containers = api.containerApiInRegion(region.getId()).list()
+ FluentIterable<StorageMetadata> containers = api.getContainerApiForRegion(regionId).list()
.transform(toResourceMetadata);
return new PageSetImpl<StorageMetadata>(containers, null);
}
@Override
public boolean containerExists(String container) {
- Container val = api.containerApiInRegion(region.getId()).get(container);
+ Container val = api.getContainerApiForRegion(regionId).get(container);
containerCache.put(container, Optional.fromNullable(val));
return val != null;
}
@@ -131,9 +134,9 @@ public class RegionScopedSwiftBlobStore implements BlobStore {
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.containerApiInRegion(region.getId()).createIfAbsent(container, ANYBODY_READ);
+ return api.getContainerApiForRegion(regionId).create(container, ANYBODY_READ);
}
- return api.containerApiInRegion(region.getId()).createIfAbsent(container, BASIC_CONTAINER);
+ 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();
@@ -147,7 +150,7 @@ public class RegionScopedSwiftBlobStore implements BlobStore {
@Override
public PageSet<? extends StorageMetadata> list(final String container, ListContainerOptions options) {
- ObjectApi objectApi = api.objectApiInRegionForContainer(region.getId(), container);
+ ObjectApi objectApi = api.getObjectApiForRegionAndContainer(regionId, container);
ObjectList objects = objectApi.list(toListContainerOptions.apply(options));
if (objects == null) {
containerCache.put(container, Optional.<Container> absent());
@@ -188,13 +191,13 @@ public class RegionScopedSwiftBlobStore implements BlobStore {
if (options.isMultipart()) {
throw new UnsupportedOperationException();
}
- ObjectApi objectApi = api.objectApiInRegionForContainer(region.getId(), container);
- return objectApi.replace(blob.getMetadata().getName(), blob.getPayload(), blob.getMetadata().getUserMetadata());
+ 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.objectApiInRegionForContainer(region.getId(), container).head(name);
+ SwiftObject object = api.getObjectApiForRegionAndContainer(regionId, container).get(name);
if (object == null) {
return null;
}
@@ -208,7 +211,7 @@ public class RegionScopedSwiftBlobStore implements BlobStore {
@Override
public Blob getBlob(String container, String name, GetOptions options) {
- ObjectApi objectApi = api.objectApiInRegionForContainer(region.getId(), container);
+ ObjectApi objectApi = api.getObjectApiForRegionAndContainer(regionId, container);
SwiftObject object = objectApi.get(name, toGetOptions.apply(options));
if (object == null) {
return null;
@@ -221,7 +224,7 @@ public class RegionScopedSwiftBlobStore implements BlobStore {
@Override
public void removeBlob(String container, String name) {
- api.objectApiInRegionForContainer(region.getId(), container).delete(name);
+ api.getObjectApiForRegionAndContainer(regionId, container).delete(name);
}
@Override
@@ -236,17 +239,17 @@ public class RegionScopedSwiftBlobStore implements BlobStore {
@Override
public boolean directoryExists(String containerName, String directory) {
- return api.objectApiInRegionForContainer(region.getId(), containerName)
- .head(directory) != null;
+ return api.getObjectApiForRegionAndContainer(regionId, containerName)
+ .get(directory) != null;
}
@Override
public void createDirectory(String containerName, String directory) {
- api.objectApiInRegionForContainer(region.getId(), containerName)
- .replace(directory, directoryPayload, ImmutableMap.<String, String> of());
+ api.getObjectApiForRegionAndContainer(regionId, containerName)
+ .put(directory, directoryPayload);
}
- private final Payload directoryPayload = new ByteArrayPayload(new byte[] {}) {
+ private final Payload directoryPayload = new ByteSourcePayload(ByteSource.wrap(new byte[] {})) {
{
getContentMetadata().setContentType("application/directory");
}
@@ -254,12 +257,12 @@ public class RegionScopedSwiftBlobStore implements BlobStore {
@Override
public void deleteDirectory(String containerName, String directory) {
- api.objectApiInRegionForContainer(region.getId(), containerName).delete(directory);
+ api.getObjectApiForRegionAndContainer(regionId, containerName).delete(directory);
}
@Override
public long countBlobs(String containerName) {
- Container container = api.containerApiInRegion(region.getId()).get(containerName);
+ Container container = api.getContainerApiForRegion(regionId).get(containerName);
// undefined if container doesn't exist, so default to zero
return container != null ? container.getObjectCount() : 0;
}
@@ -278,14 +281,14 @@ public class RegionScopedSwiftBlobStore implements BlobStore {
@Override
public void deleteContainer(String container) {
clearContainer(container, recursive());
- api.containerApiInRegion(region.getId()).deleteIfEmpty(container);
+ api.getContainerApiForRegion(regionId).deleteIfEmpty(container);
containerCache.invalidate(container);
}
protected final LoadingCache<String, Optional<Container>> containerCache = CacheBuilder.newBuilder().build(
new CacheLoader<String, Optional<Container>>() {
public Optional<Container> load(String container) {
- return Optional.fromNullable(api.containerApiInRegion(region.getId()).get(container));
+ return Optional.fromNullable(api.getContainerApiForRegion(regionId).get(container));
}
});
http://git-wip-us.apache.org/repos/asf/jclouds-labs-openstack/blob/3fc89736/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/blobstore/RegionScopedTemporaryUrlBlobSigner.java
----------------------------------------------------------------------
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
index 78dc63f..41ae522 100644
--- 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
@@ -53,7 +53,7 @@ public class RegionScopedTemporaryUrlBlobSigner implements BlobRequestSigner {
@Assisted String regionId) {
checkNotNull(regionId, "regionId");
this.timestamp = timestamp;
- this.signer = TemporaryUrlSigner.checkApiEvery(api.accountApiInRegion(regionId), seconds);
+ this.signer = TemporaryUrlSigner.checkApiEvery(api.getAccountApiForRegion(regionId), seconds);
this.storageUrl = regionToUris.get().get(regionId).get();
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-openstack/blob/3fc89736/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/domain/Account.java
----------------------------------------------------------------------
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
index 044a16b..7ec15e0 100644
--- 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
@@ -31,9 +31,7 @@ import com.google.common.collect.ImmutableMap;
/**
* Represents an Account in OpenStack Object Storage.
*
- * @author Jeremy Daggett
- *
- * @see AccountApi
+ * @see org.jclouds.openstack.swift.v1.features.AccountApi
*/
public class Account {
@@ -116,7 +114,7 @@ public class Account {
}
protected ToStringHelper string() {
- return toStringHelper("")
+ return toStringHelper(this)
.add("containerCount", getContainerCount())
.add("objectCount", getObjectCount())
.add("bytesUsed", getBytesUsed())
http://git-wip-us.apache.org/repos/asf/jclouds-labs-openstack/blob/3fc89736/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/domain/BulkDeleteResponse.java
----------------------------------------------------------------------
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
index 26edd76..9933a1c 100644
--- 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
@@ -23,13 +23,12 @@ 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.
*
- * @author Jeremy Daggett
- *
- * @see BulkApi
+ * @see org.jclouds.openstack.swift.v1.features.BulkApi
*/
public class BulkDeleteResponse {
public static BulkDeleteResponse create(int deleted, int notFound, Map<String, String> errors) {
@@ -88,11 +87,15 @@ public class BulkDeleteResponse {
return Objects.hashCode(getDeleted(), getNotFound(), getErrors());
}
- @Override
- public String toString() {
- return toStringHelper("")
+ protected ToStringHelper string() {
+ return toStringHelper(this)
.add("deleted", getDeleted())
.add("notFound", getNotFound())
- .add("errors", getErrors()).toString();
+ .add("errors", getErrors());
+ }
+
+ @Override
+ public String toString() {
+ return string().toString();
}
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-openstack/blob/3fc89736/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/domain/Container.java
----------------------------------------------------------------------
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
index ddc5d3e..1c80c4e 100644
--- 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
@@ -32,10 +32,7 @@ import com.google.common.collect.ImmutableMap;
/**
* Represents a Container in OpenStack Object Storage.
*
- * @author Adrian Cole
- * @author Jeremy Daggett
- *
- * @see ContainerApi
+ * @see org.jclouds.openstack.swift.v1.features.ContainerApi
*/
public class Container implements Comparable<Container> {
@@ -81,7 +78,7 @@ public class Container implements Comparable<Container> {
*
* @return true if this container is publicly readable, false otherwise.
*
- * @see CreateContainerOptions#anybodyRead()
+ * @see org.jclouds.openstack.swift.v1.options.CreateContainerOptions#anybodyRead()
*/
public Optional<Boolean> getAnybodyRead() {
return anybodyRead;
@@ -125,7 +122,7 @@ public class Container implements Comparable<Container> {
}
protected ToStringHelper string() {
- return toStringHelper("").omitNullValues()
+ return toStringHelper(this).omitNullValues()
.add("name", getName())
.add("objectCount", getObjectCount())
.add("bytesUsed", getBytesUsed())
http://git-wip-us.apache.org/repos/asf/jclouds-labs-openstack/blob/3fc89736/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/domain/ExtractArchiveResponse.java
----------------------------------------------------------------------
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
index b20d404..e569cf4 100644
--- 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
@@ -23,13 +23,12 @@ 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.
*
- * @author Jeremy Daggett
- *
- * @see BulkApi
+ * @see org.jclouds.openstack.swift.v1.features.BulkApi
*/
public class ExtractArchiveResponse {
public static ExtractArchiveResponse create(int created, Map<String, String> errors) {
@@ -78,10 +77,14 @@ public class ExtractArchiveResponse {
return Objects.hashCode(getCreated(), getErrors());
}
+ protected ToStringHelper string() {
+ return toStringHelper(this)
+ .add("created", getCreated())
+ .add("errors", getErrors());
+ }
+
@Override
public String toString() {
- return toStringHelper("")
- .add("created", getCreated())
- .add("errors", getErrors()).toString();
+ return string().toString();
}
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-openstack/blob/3fc89736/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/domain/ObjectList.java
----------------------------------------------------------------------
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
index 871093b..5bc3136 100644
--- 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
@@ -25,11 +25,9 @@ import com.google.common.collect.ForwardingList;
/**
* Represents a list of objects in a container.
*
- * @author Jeremy Daggett
- *
* @see Container
* @see SwiftObject
- * @see ObjectApi#list()
+ * @see org.jclouds.openstack.swift.v1.features.ObjectApi#list()
*/
public class ObjectList extends ForwardingList<SwiftObject> {
http://git-wip-us.apache.org/repos/asf/jclouds-labs-openstack/blob/3fc89736/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/domain/Segment.java
----------------------------------------------------------------------
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
index 2cb996d..ee4bc58 100644
--- 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
@@ -20,26 +20,27 @@ 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.
*
- * @author Adrian Cole
- * @author Jeremy Daggett
- *
- * @see StaticLargeObjectApi
+ * @see org.jclouds.openstack.swift.v1.features.StaticLargeObjectApi
*/
public class Segment {
private final String path;
private final String etag;
- private final long size_bytes;
+ @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.size_bytes = checkNotNull(sizeBytes, "sizeBytes of %s", path);
+ this.sizeBytes = checkNotNull(sizeBytes, "sizeBytes of %s", path);
}
/**
@@ -51,16 +52,25 @@ public class Segment {
/**
* @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 size_bytes;
+ return sizeBytes;
}
@Override
@@ -71,7 +81,7 @@ public class Segment {
if (object instanceof Segment) {
Segment that = Segment.class.cast(object);
return equal(getPath(), that.getPath())
- && equal(getEtag(), that.getEtag())
+ && equal(getETag(), that.getETag())
&& equal(getSizeBytes(), that.getSizeBytes());
} else {
return false;
@@ -80,15 +90,19 @@ public class Segment {
@Override
public int hashCode() {
- return Objects.hashCode(getPath(), getEtag(), getSizeBytes());
+ return Objects.hashCode(getPath(), getETag(), getSizeBytes());
}
@Override
public String toString() {
- return toStringHelper("")
+ return string().toString();
+ }
+
+ protected ToStringHelper string() {
+ return toStringHelper(this)
.add("path", getPath())
- .add("etag", getEtag())
- .add("sizeBytes", getSizeBytes()).toString();
+ .add("etag", getETag())
+ .add("sizeBytes", getSizeBytes());
}
public static Builder builder() {
http://git-wip-us.apache.org/repos/asf/jclouds-labs-openstack/blob/3fc89736/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/domain/SwiftObject.java
----------------------------------------------------------------------
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
index 099c1e7..3d00b25 100644
--- 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
@@ -78,12 +78,20 @@ public class SwiftObject implements Comparable<SwiftObject> {
/**
* @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() {
@@ -130,7 +138,7 @@ public class SwiftObject implements Comparable<SwiftObject> {
final SwiftObject that = SwiftObject.class.cast(object);
return equal(getName(), that.getName())
&& equal(getUri(), that.getUri())
- && equal(getEtag(), that.getEtag());
+ && equal(getETag(), that.getETag());
} else {
return false;
}
@@ -138,7 +146,7 @@ public class SwiftObject implements Comparable<SwiftObject> {
@Override
public int hashCode() {
- return Objects.hashCode(getName(), getUri(), getEtag());
+ return Objects.hashCode(getName(), getUri(), getETag());
}
@Override
@@ -147,10 +155,10 @@ public class SwiftObject implements Comparable<SwiftObject> {
}
protected ToStringHelper string() {
- return toStringHelper("")
+ return toStringHelper(this)
.add("name", getName())
.add("uri", getUri())
- .add("etag", getEtag())
+ .add("etag", getETag())
.add("lastModified", getLastModified())
.add("metadata", getMetadata());
}
@@ -198,7 +206,7 @@ public class SwiftObject implements Comparable<SwiftObject> {
}
/**
- * @see SwiftObject#getEtag()
+ * @see SwiftObject#getETag()
*/
public Builder etag(String etag) {
this.etag = etag;
@@ -251,7 +259,7 @@ public class SwiftObject implements Comparable<SwiftObject> {
public Builder fromObject(SwiftObject from) {
return name(from.getName())
.uri(from.getUri())
- .etag(from.getEtag())
+ .etag(from.getETag())
.lastModified(from.getLastModified())
.headers(from.getHeaders())
.metadata(from.getMetadata())
http://git-wip-us.apache.org/repos/asf/jclouds-labs-openstack/blob/3fc89736/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/features/AccountApi.java
----------------------------------------------------------------------
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
index ede3dc9..cb83d5d 100644
--- 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
@@ -42,7 +42,7 @@ import org.jclouds.rest.annotations.ResponseParser;
import com.google.common.annotations.Beta;
/**
- * Provides access to the Swift Account API features.
+ * Provides access to the OpenStack Object Storage (Swift) Account API features.
*
* <p/>
* Account metadata prefixed with {@code X-Account-Meta-} will be converted
http://git-wip-us.apache.org/repos/asf/jclouds-labs-openstack/blob/3fc89736/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/features/BulkApi.java
----------------------------------------------------------------------
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
index ac7677e..51177eb 100644
--- 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
@@ -45,14 +45,12 @@ import com.google.common.annotations.Beta;
import com.google.common.base.Joiner;
/**
- * Provides access to the Swift Bulk API.
+ * Provides access to the OpenStack Object Storage (Swift) Bulk API features.
* <p/>
* 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.
*
- * @author Adrian Cole
- * @author Jeremy Daggett
*/
@Beta
@RequestFilters(AuthenticateRequest.class)
@@ -64,8 +62,8 @@ public interface BulkApi {
*
* @param path
* the path to extract under.
- * @param tar
- * a valid tar archive.
+ * @param payload
+ * the {@link Payload payload} archive.
* @param format
* one of {@code tar}, {@code tar.gz}, or {@code tar.bz2}
*
http://git-wip-us.apache.org/repos/asf/jclouds-labs-openstack/blob/3fc89736/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/features/ContainerApi.java
----------------------------------------------------------------------
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
index 6f5aa97..92c42b9 100644
--- 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
@@ -52,15 +52,12 @@ import com.google.common.annotations.Beta;
import com.google.common.collect.FluentIterable;
/**
- * Provides access to the Swift Container API features.
+ * Provides access to the OpenStack Object Storage (Swift) Container API features.
* <p/>
* 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.
+ * {@code org.jclouds.openstack.swift.SwiftClient} in jclouds 2.0 and it is recommended you adopt it sooner than later.
*
- * @author Adrian Cole
- * @author Zack Shoylev
- * @author Jeremy Daggett
*/
@Beta
@RequestFilters(AuthenticateRequest.class)
@@ -70,6 +67,11 @@ public interface ContainerApi {
/**
* Lists up to 10,000 containers.
*
+ * <h3>NOTE</h3>
+ * This method returns a list of {@link Container} objects <b>without</b> metadata. To retrieve
+ * the {@link Container} metadata, use the {@link #get(String)} method.
+ * <p/>
+ *
* @return a list of {@link Container containers} ordered by name.
*/
@Named("container:list")
@@ -82,6 +84,11 @@ public interface ContainerApi {
/**
* Lists containers with the supplied {@link ListContainerOptions}.
*
+ * <h3>NOTE</h3>
+ * This method returns a list of {@link Container} objects <b>without</b> metadata. To retrieve
+ * the {@link Container} metadata, use the {@link #get(String)} method.
+ * <p/>
+ *
* @param options
* the options to control the output list.
*
@@ -96,36 +103,33 @@ public interface ContainerApi {
/**
* 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:createIfAbsent")
+ @Named("container:create")
@PUT
@ResponseParser(FalseOnAccepted.class)
@Path("/{containerName}")
- boolean createIfAbsent(@PathParam("containerName") String containerName, CreateContainerOptions options);
+ boolean create(@PathParam("containerName") String containerName);
/**
- * Gets the {@link Container} metadata, including the number of objects in the container and
- * the total bytes for all objects stored in the container.
- *
+ * Creates a container, if not already present.
+ *
* @param containerName
* corresponds to {@link Container#getName()}.
- *
- * @return the {@link Container}, or {@code null} if not found.
+ * @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:get")
- @HEAD
- @ResponseParser(ParseContainerFromHeaders.class)
- @Fallback(NullOnNotFoundOr404.class)
+ @Named("container:create")
+ @PUT
+ @ResponseParser(FalseOnAccepted.class)
@Path("/{containerName}")
- @Nullable
- Container head(@PathParam("containerName") String containerName);
+ boolean create(@PathParam("containerName") String containerName, CreateContainerOptions options);
/**
* Gets the {@link Container}.
@@ -194,4 +198,44 @@ public interface ContainerApi {
@Fallback(FalseOnNotFoundOr404.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);
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-openstack/blob/3fc89736/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/features/ObjectApi.java
----------------------------------------------------------------------
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
index 665fa37..e4fccc6 100644
--- 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
@@ -16,6 +16,7 @@
*/
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;
@@ -49,6 +50,7 @@ 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;
@@ -59,14 +61,11 @@ import org.jclouds.rest.annotations.ResponseParser;
import com.google.common.annotations.Beta;
/**
- * Provides access to the Swift Object API features.
+ * Provides access to the OpenStack Object Storage (Swift) Object API features.
* <p/>
* 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.
- *
- * @author Adrian Cole
- * @author Jeremy Daggett
*/
@Beta
@RequestFilters(AuthenticateRequest.class)
@@ -76,9 +75,6 @@ public interface ObjectApi {
/**
* Lists up to 10,000 objects.
*
- * @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")
@@ -116,36 +112,70 @@ public interface ObjectApi {
* 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.
+ */
+ @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}.
*
- * @return {@link SwiftObject#getEtag()} of the object.
+ * @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:replace")
+ @Named("object:put")
@PUT
+ @Headers(keys = EXPECT, values = "100-continue")
@ResponseParser(ETagHeader.class)
@Path("/{objectName}")
- String replace(@PathParam("objectName") String objectName, @BinderParam(SetPayload.class) Payload payload,
- @BinderParam(BindObjectMetadataToHeaders.class) Map<String, String> metadata);
+ String put(@PathParam("objectName") String objectName, @BinderParam(SetPayload.class) Payload payload,
+ PutOptions options);
/**
- * Gets the {@link SwiftObject} metadata without its {@link Payload#getInput() body}.
+ * 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:head")
+ @Named("object:getWithoutBody")
@HEAD
@ResponseParser(ParseObjectFromResponse.class)
@Fallback(NullOnNotFoundOr404.class)
@Path("/{objectName}")
@Nullable
- SwiftObject head(@PathParam("objectName") String objectName);
+ SwiftObject getWithoutBody(@PathParam("objectName") String objectName);
/**
- * Gets the {@link SwiftObject} including its {@link Payload#getInput() body}.
+ * 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()}.
@@ -226,7 +256,7 @@ public interface ObjectApi {
*
* @return {@code true} if the object was successfully copied, {@code false} if not.
*
- * @throws CopyObjectException if the source or destination container do not exist.
+ * @throws org.jclouds.openstack.swift.v1.CopyObjectException if the source or destination container do not exist.
*/
@Named("object:copy")
@PUT
@@ -236,4 +266,45 @@ public interface ObjectApi {
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<String, String> metadata);
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-openstack/blob/3fc89736/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/features/StaticLargeObjectApi.java
----------------------------------------------------------------------
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
index c230fa0..fe6f0e8 100644
--- 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
@@ -43,7 +43,7 @@ import org.jclouds.rest.binders.BindToJsonPayload;
import com.google.common.annotations.Beta;
/**
- * Provides access to the Swift Static Large Object API features.
+ * Provides access to the OpenStack Object Storage (Swift) Static Large Object API features.
* <p/>
* 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
http://git-wip-us.apache.org/repos/asf/jclouds-labs-openstack/blob/3fc89736/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/options/CreateContainerOptions.java
----------------------------------------------------------------------
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
index 2b61d53..1fd146d 100644
--- 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
@@ -29,9 +29,13 @@ import org.jclouds.openstack.swift.v1.binders.BindMetadataToHeaders;
/**
* Options for creating a {@link Container}.
*
- * @see ContainerApi#createIfAbsent(String, CreateContainerOptions)
+ * @see ContainerApi#create(String, CreateContainerOptions)
*/
public class CreateContainerOptions extends BaseHttpRequestOptions {
+ /**
+ * @deprecated This field will be removed in jclouds 1.8.
+ */
+ @Deprecated
public static final CreateContainerOptions NONE = new CreateContainerOptions();
/**
http://git-wip-us.apache.org/repos/asf/jclouds-labs-openstack/blob/3fc89736/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/options/PutOptions.java
----------------------------------------------------------------------
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
new file mode 100644
index 0000000..1897e6d
--- /dev/null
+++ b/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/options/PutOptions.java
@@ -0,0 +1,59 @@
+/*
+ * 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;
+
+/**
+ * Options for creating an Object.
+ */
+public class PutOptions extends BaseHttpRequestOptions {
+ /**
+ * @deprecated This field will be removed in jclouds 1.8
+ */
+ @Deprecated
+ public static final PutOptions NONE = new PutOptions();
+
+ /**
+ * Sets the metadata on a container at creation.
+ */
+ public PutOptions metadata(Map<String, String> metadata) {
+ if (!metadata.isEmpty()) {
+ this.headers.putAll(bindMetadataToHeaders.toHeaders(metadata));
+ }
+ return this;
+ }
+
+ public static class Builder {
+
+ /**
+ * @see PutOptions#metadata
+ */
+ public static PutOptions metadata(Map<String, String> metadata) {
+ PutOptions options = new PutOptions();
+ return options.metadata(metadata);
+ }
+
+ }
+
+ private static final BindMetadataToHeaders bindMetadataToHeaders = new BindMetadataToHeaders(OBJECT_METADATA_PREFIX);
+}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-openstack/blob/3fc89736/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/AuthenticationMockTest.java
----------------------------------------------------------------------
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
index 93f387b..9999ae4 100644
--- 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
@@ -60,7 +60,7 @@ public class AuthenticationMockTest extends BaseOpenStackMockTest<SwiftApi> {
SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift", overrides);
- api.accountApiInRegion("DFW").get();
+ api.getAccountApiForRegion("DFW").get();
assertEquals(server.getRequestCount(), 2);
RecordedRequest authRequest = server.takeRequest();
http://git-wip-us.apache.org/repos/asf/jclouds-labs-openstack/blob/3fc89736/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/SwiftErrorHandlerTest.java
----------------------------------------------------------------------
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
index 5483175..703da9b 100644
--- 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
@@ -21,6 +21,7 @@ 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;
@@ -33,8 +34,10 @@ import org.jclouds.http.HttpResponse;
import org.jclouds.openstack.swift.v1.handlers.SwiftErrorHandler;
import org.testng.annotations.Test;
+import com.google.common.io.ByteSource;
+
/**
- * @author Adrian Cole
+ * Tests the {@link SwiftErrorHandler}
*/
@Test(groups = "unit", testName = "SwiftErrorHandlerTest")
public class SwiftErrorHandlerTest {
@@ -79,7 +82,8 @@ public class SwiftErrorHandlerTest {
HttpCommand command = createMock(HttpCommand.class);
HttpRequest request = HttpRequest.builder().method(method).endpoint(uri).build();
- HttpResponse response = HttpResponse.builder().statusCode(statusCode).message(message).payload(content).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();
@@ -110,5 +114,4 @@ public class SwiftErrorHandlerTest {
});
return null;
}
-
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-openstack/blob/3fc89736/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/TemporaryUrlSignerLiveTest.java
----------------------------------------------------------------------
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
index 9a00c14..bf2a4ff 100644
--- 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
@@ -17,7 +17,7 @@
package org.jclouds.openstack.swift.v1;
import static java.lang.String.format;
-import static org.jclouds.io.Payloads.newStringPayload;
+import static org.jclouds.io.Payloads.newByteSourcePayload;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.fail;
@@ -28,14 +28,13 @@ import java.util.UUID;
import org.jclouds.openstack.swift.v1.domain.SwiftObject;
import org.jclouds.openstack.swift.v1.internal.BaseSwiftApiLiveTest;
-import org.jclouds.openstack.swift.v1.options.CreateContainerOptions;
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.collect.ImmutableMap;
+import com.google.common.io.ByteSource;
@Test(groups = "live", testName = "TemporaryUrlSignerLiveTest")
public class TemporaryUrlSignerLiveTest extends BaseSwiftApiLiveTest<SwiftApi> {
@@ -44,11 +43,11 @@ public class TemporaryUrlSignerLiveTest extends BaseSwiftApiLiveTest<SwiftApi> {
private String containerName = getClass().getSimpleName() + "Container";
public void signForPublicAccess() throws Exception {
- for (String regionId : api.configuredRegions()) {
- SwiftObject object = api.objectApiInRegionForContainer(regionId, containerName).head(name);
+ for (String regionId : api.getConfiguredRegions()) {
+ SwiftObject object = api.getObjectApiForRegionAndContainer(regionId, containerName).get(name);
long expires = System.currentTimeMillis() / 1000 + 5;
- String signature = TemporaryUrlSigner.checkApiEvery(api.accountApiInRegion(regionId), 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));
@@ -71,20 +70,20 @@ public class TemporaryUrlSignerLiveTest extends BaseSwiftApiLiveTest<SwiftApi> {
public void setup() {
super.setup();
String key = UUID.randomUUID().toString();
- for (String regionId : api.configuredRegions()) {
- api.accountApiInRegion(regionId).updateTemporaryUrlKey(key);
- api.containerApiInRegion(regionId).createIfAbsent(containerName, CreateContainerOptions.NONE);
- api.objectApiInRegionForContainer(regionId, containerName)
- .replace(name, newStringPayload("swifty"), ImmutableMap.<String, String> of());
+ 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.configuredRegions()) {
- api.objectApiInRegionForContainer(regionId, containerName).delete(name);
- api.containerApiInRegion(regionId).deleteIfEmpty(containerName);
+ for (String regionId : api.getConfiguredRegions()) {
+ api.getObjectApiForRegionAndContainer(regionId, containerName).delete(name);
+ api.getContainerApiForRegion(regionId).deleteIfEmpty(containerName);
}
super.tearDown();
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-openstack/blob/3fc89736/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/TemporaryUrlSignerMockTest.java
----------------------------------------------------------------------
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
index 91fe3df..903d5ec 100644
--- 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
@@ -16,8 +16,8 @@
*/
package org.jclouds.openstack.swift.v1;
-import static org.jclouds.openstack.swift.v1.reference.SwiftHeaders.ACCOUNT_TEMPORARY_URL_KEY;
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;
@@ -41,7 +41,7 @@ public class TemporaryUrlSignerMockTest extends BaseOpenStackMockTest<SwiftApi>
try {
SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift");
- String signature = TemporaryUrlSigner.checkApiEvery(api.accountApiInRegion("DFW"), 10000)
+ String signature = TemporaryUrlSigner.checkApiEvery(api.getAccountApiForRegion("DFW"), 10000)
.sign("GET", "/v1/AUTH_account/container/object", 1323479485l);
assertEquals(signature, "d9fc2067e52b06598421664cf6610bfc8fc431f6");
http://git-wip-us.apache.org/repos/asf/jclouds-labs-openstack/blob/3fc89736/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/AccountApiLiveTest.java
----------------------------------------------------------------------
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
index 4359a71..c62d238 100644
--- 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
@@ -36,7 +36,7 @@ public class AccountApiLiveTest extends BaseSwiftApiLiveTest<SwiftApi> {
public void testGet() throws Exception {
for (String regionId : regions) {
- AccountApi accountApi = api.accountApiInRegion(regionId);
+ AccountApi accountApi = api.getAccountApiForRegion(regionId);
Account account = accountApi.get();
assertNotNull(account);
@@ -48,7 +48,7 @@ public class AccountApiLiveTest extends BaseSwiftApiLiveTest<SwiftApi> {
public void testUpdateMetadata() throws Exception {
for (String regionId : regions) {
- AccountApi accountApi = api.accountApiInRegion(regionId);
+ AccountApi accountApi = api.getAccountApiForRegion(regionId);
Map<String, String> meta = ImmutableMap.of("MyAdd1", "foo", "MyAdd2", "bar");
@@ -60,7 +60,7 @@ public class AccountApiLiveTest extends BaseSwiftApiLiveTest<SwiftApi> {
public void testDeleteMetadata() throws Exception {
for (String regionId : regions) {
- AccountApi accountApi = api.accountApiInRegion(regionId);
+ AccountApi accountApi = api.getAccountApiForRegion(regionId);
Map<String, String> meta = ImmutableMap.of("MyDelete1", "foo", "MyDelete2", "bar");
http://git-wip-us.apache.org/repos/asf/jclouds-labs-openstack/blob/3fc89736/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/AccountApiMockTest.java
----------------------------------------------------------------------
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
index 97abb9d..45abf70 100644
--- 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
@@ -55,7 +55,7 @@ public class AccountApiMockTest extends BaseOpenStackMockTest<SwiftApi> {
try {
SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift");
- Account account = api.accountApiInRegion("DFW").get();
+ Account account = api.getAccountApiForRegion("DFW").get();
assertEquals(account.getContainerCount(), 3l);
assertEquals(account.getObjectCount(), 42l);
assertEquals(account.getBytesUsed(), 323479l);
@@ -80,7 +80,7 @@ public class AccountApiMockTest extends BaseOpenStackMockTest<SwiftApi> {
try {
SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift");
- assertTrue(api.accountApiInRegion("DFW").updateMetadata(metadata));
+ assertTrue(api.getAccountApiForRegion("DFW").updateMetadata(metadata));
assertEquals(server.getRequestCount(), 2);
assertAuthentication(server);
@@ -102,7 +102,7 @@ public class AccountApiMockTest extends BaseOpenStackMockTest<SwiftApi> {
try {
SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift");
- assertTrue(api.accountApiInRegion("DFW").updateTemporaryUrlKey("foobar"));
+ assertTrue(api.getAccountApiForRegion("DFW").updateTemporaryUrlKey("foobar"));
assertEquals(server.getRequestCount(), 2);
assertAuthentication(server);
@@ -122,7 +122,7 @@ public class AccountApiMockTest extends BaseOpenStackMockTest<SwiftApi> {
try {
SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift");
- assertTrue(api.accountApiInRegion("DFW").deleteMetadata(metadata));
+ assertTrue(api.getAccountApiForRegion("DFW").deleteMetadata(metadata));
assertEquals(server.getRequestCount(), 2);
assertEquals(server.takeRequest().getRequestLine(), "POST /tokens HTTP/1.1");
http://git-wip-us.apache.org/repos/asf/jclouds-labs-openstack/blob/3fc89736/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/BulkApiLiveTest.java
----------------------------------------------------------------------
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
index fa8e6b6..22191c4 100644
--- 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
@@ -27,12 +27,13 @@ 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.Payloads;
+import org.jclouds.io.ByteSources;
+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.jclouds.openstack.swift.v1.options.CreateContainerOptions;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
@@ -40,18 +41,19 @@ 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.ByteStreams;
+import com.google.common.io.ByteSource;
@Test(groups = "live", testName = "BulkApiLiveTest")
public class BulkApiLiveTest extends BaseSwiftApiLiveTest<SwiftApi> {
- static final int OBJECT_COUNT = 10;
-
+ private static final int OBJECT_COUNT = 10;
private String containerName = getClass().getSimpleName();
+ List<String> paths = Lists.newArrayList();
+ byte[] tarGz;
public void testNotPresentWhenDeleting() throws Exception {
for (String regionId : regions) {
- BulkDeleteResponse deleteResponse = api.bulkApiInRegion(regionId).bulkDelete(
+ BulkDeleteResponse deleteResponse = api.getBulkApiForRegion(regionId).bulkDelete(
ImmutableList.of(UUID.randomUUID().toString()));
assertEquals(deleteResponse.getDeleted(), 0);
assertEquals(deleteResponse.getNotFound(), 1);
@@ -61,15 +63,16 @@ public class BulkApiLiveTest extends BaseSwiftApiLiveTest<SwiftApi> {
public void testExtractArchive() throws Exception {
for (String regionId : regions) {
- ExtractArchiveResponse extractResponse = api.bulkApiInRegion(regionId).extractArchive(containerName,
- Payloads.newPayload(tarGz), "tar.gz");
+ 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.containerApiInRegion(regionId).get(containerName).getObjectCount(), OBJECT_COUNT);
+ assertEquals(api.getContainerApiForRegion(regionId).get(containerName).getObjectCount(), OBJECT_COUNT);
// repeat the command
- extractResponse = api.bulkApiInRegion(regionId).extractArchive(containerName, Payloads.newPayload(tarGz),
- "tar.gz");
+ extractResponse = api.getBulkApiForRegion(regionId).extractArchive(containerName, payload, "tar.gz");
assertEquals(extractResponse.getCreated(), OBJECT_COUNT);
assertTrue(extractResponse.getErrors().isEmpty());
}
@@ -78,24 +81,20 @@ public class BulkApiLiveTest extends BaseSwiftApiLiveTest<SwiftApi> {
@Test(dependsOnMethods = "testExtractArchive")
public void testBulkDelete() throws Exception {
for (String regionId : regions) {
- BulkDeleteResponse deleteResponse = api.bulkApiInRegion(regionId).bulkDelete(paths);
+ BulkDeleteResponse deleteResponse = api.getBulkApiForRegion(regionId).bulkDelete(paths);
assertEquals(deleteResponse.getDeleted(), OBJECT_COUNT);
assertEquals(deleteResponse.getNotFound(), 0);
assertTrue(deleteResponse.getErrors().isEmpty());
- assertEquals(api.containerApiInRegion(regionId).get(containerName).getObjectCount(), 0);
+ assertEquals(api.getContainerApiForRegion(regionId).get(containerName).getObjectCount(), 0);
}
}
- List<String> paths = Lists.newArrayList();
- byte[] tarGz;
-
@Override
@BeforeClass(groups = "live")
public void setup() {
super.setup();
for (String regionId : regions) {
- boolean created = api.containerApiInRegion(regionId).createIfAbsent(containerName,
- CreateContainerOptions.NONE);
+ boolean created = api.getContainerApiForRegion(regionId).create(containerName);
if (!created) {
deleteAllObjectsInContainer(regionId, containerName);
}
@@ -106,8 +105,9 @@ public class BulkApiLiveTest extends BaseSwiftApiLiveTest<SwiftApi> {
paths.add(containerName + "/file" + i);
files.add(content, "/file" + i);
}
+
try {
- tarGz = ByteStreams.toByteArray(files.as(TarGzExporter.class).exportAsInputStream());
+ tarGz = ByteSources.asByteSource(files.as(TarGzExporter.class).exportAsInputStream()).read();
} catch (IOException e) {
throw Throwables.propagate(e);
}
@@ -118,7 +118,7 @@ public class BulkApiLiveTest extends BaseSwiftApiLiveTest<SwiftApi> {
public void tearDown() {
for (String regionId : regions) {
deleteAllObjectsInContainer(regionId, containerName);
- api.containerApiInRegion(regionId).deleteIfEmpty(containerName);
+ api.getContainerApiForRegion(regionId).deleteIfEmpty(containerName);
}
super.tearDown();
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-openstack/blob/3fc89736/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/BulkApiMockTest.java
----------------------------------------------------------------------
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
index 5b4c200..73ba82b 100644
--- 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
@@ -16,7 +16,6 @@
*/
package org.jclouds.openstack.swift.v1.features;
-import static org.jclouds.io.Payloads.newByteArrayPayload;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
@@ -24,12 +23,15 @@ 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.openstack.v2_0.internal.BaseOpenStackMockTest;
+import org.jclouds.io.ByteSources;
+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.ByteStreams;
+import com.google.common.io.ByteSource;
import com.squareup.okhttp.mockwebserver.MockResponse;
import com.squareup.okhttp.mockwebserver.MockWebServer;
import com.squareup.okhttp.mockwebserver.RecordedRequest;
@@ -43,7 +45,8 @@ public class BulkApiMockTest extends BaseOpenStackMockTest<SwiftApi> {
for (int i = 0; i < 10; i++) {
files.add(content, "/file" + i);
}
- byte[] tarGz = ByteStreams.toByteArray(files.as(TarGzExporter.class).exportAsInputStream());
+
+ byte[] tarGz = ByteSources.asByteSource(files.as(TarGzExporter.class).exportAsInputStream()).read();
MockWebServer server = mockOpenStackServer();
server.enqueue(addCommonHeaders(new MockResponse().setBody(stringFromResource("/access.json"))));
@@ -51,8 +54,9 @@ public class BulkApiMockTest extends BaseOpenStackMockTest<SwiftApi> {
try {
SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift");
- ExtractArchiveResponse response = api.bulkApiInRegion("DFW").extractArchive("myContainer",
- newByteArrayPayload(tarGz), "tar.gz");
+ 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());
http://git-wip-us.apache.org/repos/asf/jclouds-labs-openstack/blob/3fc89736/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/ContainerApiLiveTest.java
----------------------------------------------------------------------
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
index 19e0d14..fb53927 100644
--- 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
@@ -27,7 +27,6 @@ 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.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
@@ -47,7 +46,7 @@ public class ContainerApiLiveTest extends BaseSwiftApiLiveTest<SwiftApi> {
public void testList() throws Exception {
for (String regionId : regions) {
- ContainerApi containerApi = api.containerApiInRegion(regionId);
+ ContainerApi containerApi = api.getContainerApiForRegion(regionId);
FluentIterable<Container> response = containerApi.list();
assertNotNull(response);
for (Container container : response) {
@@ -62,16 +61,7 @@ public class ContainerApiLiveTest extends BaseSwiftApiLiveTest<SwiftApi> {
String lexicographicallyBeforeName = name.substring(0, name.length() - 1);
for (String regionId : regions) {
ListContainerOptions options = ListContainerOptions.Builder.marker(lexicographicallyBeforeName);
- Container container = api.containerApiInRegion(regionId).list(options).get(0);
- assertEquals(container.getName(), name);
- assertTrue(container.getObjectCount() == 0);
- assertTrue(container.getBytesUsed() == 0);
- }
- }
-
- public void testHead() throws Exception {
- for (String regionId : regions) {
- Container container = api.containerApiInRegion(regionId).head(name);
+ Container container = api.getContainerApiForRegion(regionId).list(options).get(0);
assertEquals(container.getName(), name);
assertTrue(container.getObjectCount() == 0);
assertTrue(container.getBytesUsed() == 0);
@@ -80,7 +70,7 @@ public class ContainerApiLiveTest extends BaseSwiftApiLiveTest<SwiftApi> {
public void testGet() throws Exception {
for (String regionId : regions) {
- Container container = api.containerApiInRegion(regionId).get(name);
+ Container container = api.getContainerApiForRegion(regionId).get(name);
assertEquals(container.getName(), name);
assertTrue(container.getObjectCount() == 0);
assertTrue(container.getBytesUsed() == 0);
@@ -91,7 +81,7 @@ public class ContainerApiLiveTest extends BaseSwiftApiLiveTest<SwiftApi> {
Map<String, String> meta = ImmutableMap.of("MyAdd1", "foo", "MyAdd2", "bar");
for (String regionId : regions) {
- ContainerApi containerApi = api.containerApiInRegion(regionId);
+ ContainerApi containerApi = api.getContainerApiForRegion(regionId);
assertTrue(containerApi.updateMetadata(name, meta));
containerHasMetadata(containerApi, name, meta);
}
@@ -101,7 +91,7 @@ public class ContainerApiLiveTest extends BaseSwiftApiLiveTest<SwiftApi> {
Map<String, String> meta = ImmutableMap.of("MyDelete1", "foo", "MyDelete2", "bar");
for (String regionId : regions) {
- ContainerApi containerApi = api.containerApiInRegion(regionId);
+ ContainerApi containerApi = api.getContainerApiForRegion(regionId);
// update
assertTrue(containerApi.updateMetadata(name, meta));
containerHasMetadata(containerApi, name, meta);
@@ -129,7 +119,7 @@ public class ContainerApiLiveTest extends BaseSwiftApiLiveTest<SwiftApi> {
public void setup() {
super.setup();
for (String regionId : regions) {
- api.containerApiInRegion(regionId).createIfAbsent(name, CreateContainerOptions.NONE);
+ api.getContainerApiForRegion(regionId).create(name);
}
}
@@ -137,7 +127,7 @@ public class ContainerApiLiveTest extends BaseSwiftApiLiveTest<SwiftApi> {
@AfterClass(groups = "live")
public void tearDown() {
for (String regionId : regions) {
- api.containerApiInRegion(regionId).deleteIfEmpty(name);
+ api.getContainerApiForRegion(regionId).deleteIfEmpty(name);
}
super.tearDown();
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-openstack/blob/3fc89736/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/ContainerApiMockTest.java
----------------------------------------------------------------------
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
index bdbee64..a6bb7cd 100644
--- 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
@@ -34,7 +34,6 @@ 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.CreateContainerOptions;
import org.jclouds.openstack.swift.v1.options.ListContainerOptions;
import org.jclouds.openstack.v2_0.internal.BaseOpenStackMockTest;
import org.testng.annotations.Test;
@@ -55,7 +54,7 @@ public class ContainerApiMockTest extends BaseOpenStackMockTest<SwiftApi> {
try {
SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift");
- ImmutableList<Container> containers = api.containerApiInRegion("DFW").list().toList();
+ ImmutableList<Container> containers = api.getContainerApiForRegion("DFW").list().toList();
assertEquals(containers, ImmutableList.of(
Container.builder()
.name("test_container_1")
@@ -84,7 +83,7 @@ public class ContainerApiMockTest extends BaseOpenStackMockTest<SwiftApi> {
try {
SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift");
- ImmutableList<Container> containers = api.containerApiInRegion("DFW").list(options).toList();
+ ImmutableList<Container> containers = api.getContainerApiForRegion("DFW").list(options).toList();
assertEquals(containers, ImmutableList.of(
Container.builder()
.name("test_container_1")
@@ -113,9 +112,9 @@ public class ContainerApiMockTest extends BaseOpenStackMockTest<SwiftApi> {
try {
SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift");
- assertTrue(api.containerApiInRegion("DFW").createIfAbsent("myContainer", anybodyRead().metadata(metadata)));
+ assertTrue(api.getContainerApiForRegion("DFW").create("myContainer", anybodyRead().metadata(metadata)));
- Container container = api.containerApiInRegion("DFW").head("myContainer");
+ Container container = api.getContainerApiForRegion("DFW").get("myContainer");
assertEquals(container.getName(), "myContainer");
assertEquals(container.getObjectCount(), 42l);
assertEquals(container.getBytesUsed(), 323479l);
@@ -139,23 +138,23 @@ public class ContainerApiMockTest extends BaseOpenStackMockTest<SwiftApi> {
try {
SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift");
- assertTrue(api.containerApiInRegion("DFW").createIfAbsent("myContainer", anybodyRead().metadata(metadata)));
+ assertTrue(api.getContainerApiForRegion("DFW").create("myContainer", anybodyRead().metadata(metadata)));
// the head call will throw the ContainerNotFoundException
- api.containerApiInRegion("DFW").head("myContainer");
+ api.getContainerApiForRegion("DFW").get("myContainer");
} finally {
server.shutdown();
}
}
- public void testCreateIfAbsent() throws Exception {
+ 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.containerApiInRegion("DFW").createIfAbsent("myContainer", CreateContainerOptions.NONE));
+ assertTrue(api.getContainerApiForRegion("DFW").create("myContainer"));
assertEquals(server.getRequestCount(), 2);
assertAuthentication(server);
@@ -172,7 +171,7 @@ public class ContainerApiMockTest extends BaseOpenStackMockTest<SwiftApi> {
try {
SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift");
- assertTrue(api.containerApiInRegion("DFW").createIfAbsent("myContainer", anybodyRead().metadata(metadata)));
+ assertTrue(api.getContainerApiForRegion("DFW").create("myContainer", anybodyRead().metadata(metadata)));
assertEquals(server.getRequestCount(), 2);
assertAuthentication(server);
@@ -197,7 +196,7 @@ public class ContainerApiMockTest extends BaseOpenStackMockTest<SwiftApi> {
try {
SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift");
- assertFalse(api.containerApiInRegion("DFW").createIfAbsent("myContainer", CreateContainerOptions.NONE));
+ assertFalse(api.getContainerApiForRegion("DFW").create("myContainer"));
assertEquals(server.getRequestCount(), 2);
assertAuthentication(server);
@@ -218,7 +217,7 @@ public class ContainerApiMockTest extends BaseOpenStackMockTest<SwiftApi> {
try {
SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift");
- Container container = api.containerApiInRegion("DFW").get("myContainer");
+ Container container = api.getContainerApiForRegion("DFW").get("myContainer");
assertEquals(container.getName(), "myContainer");
assertEquals(container.getObjectCount(), 42l);
assertEquals(container.getBytesUsed(), 323479l);
@@ -243,7 +242,7 @@ public class ContainerApiMockTest extends BaseOpenStackMockTest<SwiftApi> {
try {
SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift");
- assertTrue(api.containerApiInRegion("DFW").updateMetadata("myContainer", metadata));
+ assertTrue(api.getContainerApiForRegion("DFW").updateMetadata("myContainer", metadata));
assertEquals(server.getRequestCount(), 2);
assertEquals(server.takeRequest().getRequestLine(), "POST /tokens HTTP/1.1");
@@ -265,7 +264,7 @@ public class ContainerApiMockTest extends BaseOpenStackMockTest<SwiftApi> {
try {
SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift");
- assertTrue(api.containerApiInRegion("DFW").deleteMetadata("myContainer", metadata));
+ assertTrue(api.getContainerApiForRegion("DFW").deleteMetadata("myContainer", metadata));
assertEquals(server.getRequestCount(), 2);
assertEquals(server.takeRequest().getRequestLine(), "POST /tokens HTTP/1.1");
@@ -287,7 +286,7 @@ public class ContainerApiMockTest extends BaseOpenStackMockTest<SwiftApi> {
try {
SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift");
- assertTrue(api.containerApiInRegion("DFW").deleteIfEmpty("myContainer"));
+ assertTrue(api.getContainerApiForRegion("DFW").deleteIfEmpty("myContainer"));
assertEquals(server.getRequestCount(), 2);
assertEquals(server.takeRequest().getRequestLine(), "POST /tokens HTTP/1.1");
@@ -306,7 +305,7 @@ public class ContainerApiMockTest extends BaseOpenStackMockTest<SwiftApi> {
try {
SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift");
- assertFalse(api.containerApiInRegion("DFW").deleteIfEmpty("myContainer"));
+ assertFalse(api.getContainerApiForRegion("DFW").deleteIfEmpty("myContainer"));
assertEquals(server.getRequestCount(), 2);
assertEquals(server.takeRequest().getRequestLine(), "POST /tokens HTTP/1.1");
@@ -326,7 +325,7 @@ public class ContainerApiMockTest extends BaseOpenStackMockTest<SwiftApi> {
try {
SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift");
- api.containerApiInRegion("DFW").deleteIfEmpty("myContainer");
+ api.getContainerApiForRegion("DFW").deleteIfEmpty("myContainer");
} finally {
assertEquals(server.getRequestCount(), 2);