You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jclouds.apache.org by ga...@apache.org on 2016/01/25 22:27:27 UTC
jclouds git commit: Return response from StaticLargeObjectApi.delete
Repository: jclouds
Updated Branches:
refs/heads/master a3376d4ef -> 68ff250c3
Return response from StaticLargeObjectApi.delete
Project: http://git-wip-us.apache.org/repos/asf/jclouds/repo
Commit: http://git-wip-us.apache.org/repos/asf/jclouds/commit/68ff250c
Tree: http://git-wip-us.apache.org/repos/asf/jclouds/tree/68ff250c
Diff: http://git-wip-us.apache.org/repos/asf/jclouds/diff/68ff250c
Branch: refs/heads/master
Commit: 68ff250c382cc8fac757cff28eb8ad9b9dfdd6dc
Parents: a3376d4
Author: Andrew Gaul <ga...@apache.org>
Authored: Fri Jan 22 13:48:50 2016 -0800
Committer: Andrew Gaul <ga...@apache.org>
Committed: Mon Jan 25 13:26:03 2016 -0800
----------------------------------------------------------------------
apis/openstack-swift/pom.xml | 5 +++
.../swift/v1/config/SwiftTypeAdapters.java | 39 +++++++++++++++++++-
.../domain/DeleteStaticLargeObjectResponse.java | 39 ++++++++++++++++++++
.../swift/v1/features/StaticLargeObjectApi.java | 3 +-
.../features/StaticLargeObjectApiLiveTest.java | 26 ++++++++++++-
.../features/StaticLargeObjectApiMockTest.java | 21 ++++++++---
6 files changed, 124 insertions(+), 9 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/jclouds/blob/68ff250c/apis/openstack-swift/pom.xml
----------------------------------------------------------------------
diff --git a/apis/openstack-swift/pom.xml b/apis/openstack-swift/pom.xml
index 389eb1c..bc13fb8 100644
--- a/apis/openstack-swift/pom.xml
+++ b/apis/openstack-swift/pom.xml
@@ -107,6 +107,11 @@
<artifactId>auto-service</artifactId>
<optional>true</optional>
</dependency>
+ <dependency>
+ <groupId>com.google.auto.value</groupId>
+ <artifactId>auto-value</artifactId>
+ <scope>provided</scope>
+ </dependency>
</dependencies>
<profiles>
http://git-wip-us.apache.org/repos/asf/jclouds/blob/68ff250c/apis/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/config/SwiftTypeAdapters.java
----------------------------------------------------------------------
diff --git a/apis/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/config/SwiftTypeAdapters.java b/apis/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/config/SwiftTypeAdapters.java
index 4eafdb6..e2311bb 100644
--- a/apis/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/config/SwiftTypeAdapters.java
+++ b/apis/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/config/SwiftTypeAdapters.java
@@ -25,6 +25,7 @@ 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 org.jclouds.openstack.swift.v1.domain.DeleteStaticLargeObjectResponse;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableMap.Builder;
@@ -45,7 +46,9 @@ public class SwiftTypeAdapters extends AbstractModule {
public Map<Type, Object> provideCustomAdapterBindings() {
return ImmutableMap.<Type, Object> builder()
.put(ExtractArchiveResponse.class, new ExtractArchiveResponseAdapter())
- .put(BulkDeleteResponse.class, new BulkDeleteResponseAdapter()).build();
+ .put(BulkDeleteResponse.class, new BulkDeleteResponseAdapter())
+ .put(DeleteStaticLargeObjectResponse.class, new StaticLargeObjectResponseAdapter())
+ .build();
}
static class ExtractArchiveResponseAdapter extends TypeAdapter<ExtractArchiveResponse> {
@@ -105,6 +108,40 @@ public class SwiftTypeAdapters extends AbstractModule {
}
}
+ static final class StaticLargeObjectResponseAdapter extends TypeAdapter<DeleteStaticLargeObjectResponse> {
+
+ @Override
+ public DeleteStaticLargeObjectResponse read(JsonReader reader) throws IOException {
+ String status = "";
+ int deleted = 0;
+ int notFound = 0;
+ Builder<String, String> errors = ImmutableMap.<String, String> builder();
+ reader.beginObject();
+ while (reader.hasNext()) {
+ String key = reader.nextName();
+ if (key.equals("Response Status")) {
+ status = reader.nextString();
+ } else 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 {
+ // Response Body
+ reader.skipValue();
+ }
+ }
+ reader.endObject();
+ return DeleteStaticLargeObjectResponse.create(status, deleted, notFound, errors.build());
+ }
+
+ @Override
+ public void write(JsonWriter arg0, DeleteStaticLargeObjectResponse arg1) throws IOException {
+ throw new UnsupportedOperationException();
+ }
+ }
+
static void readErrors(JsonReader reader, Builder<String, String> errors) throws IOException {
reader.beginArray();
while (reader.hasNext()) {
http://git-wip-us.apache.org/repos/asf/jclouds/blob/68ff250c/apis/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/domain/DeleteStaticLargeObjectResponse.java
----------------------------------------------------------------------
diff --git a/apis/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/domain/DeleteStaticLargeObjectResponse.java b/apis/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/domain/DeleteStaticLargeObjectResponse.java
new file mode 100644
index 0000000..2263c30
--- /dev/null
+++ b/apis/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/domain/DeleteStaticLargeObjectResponse.java
@@ -0,0 +1,39 @@
+/*
+ * 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 java.util.Map;
+
+import com.google.auto.value.AutoValue;
+
+/**
+ * Represents a response from a Static Large Object Delete request.
+ *
+ * @see org.jclouds.openstack.swift.v1.features.StaticLargeObjectApi
+ */
+@AutoValue
+public abstract class DeleteStaticLargeObjectResponse {
+ public static DeleteStaticLargeObjectResponse create(String status, int deleted, int notFound, Map<String, String> errors) {
+ return new AutoValue_DeleteStaticLargeObjectResponse(status, deleted, notFound, errors);
+ }
+
+ public abstract String status();
+ public abstract int deleted();
+ public abstract int notFound();
+ public abstract Map<String, String> errors();
+}
http://git-wip-us.apache.org/repos/asf/jclouds/blob/68ff250c/apis/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/features/StaticLargeObjectApi.java
----------------------------------------------------------------------
diff --git a/apis/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/features/StaticLargeObjectApi.java b/apis/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/features/StaticLargeObjectApi.java
index b81df13..1e48489 100644
--- a/apis/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/features/StaticLargeObjectApi.java
+++ b/apis/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/features/StaticLargeObjectApi.java
@@ -35,6 +35,7 @@ import org.jclouds.openstack.keystone.v2_0.filters.AuthenticateRequest;
import org.jclouds.openstack.swift.v1.binders.BindManifestToJsonPayload;
import org.jclouds.openstack.swift.v1.binders.BindMetadataToHeaders.BindObjectMetadataToHeaders;
import org.jclouds.openstack.swift.v1.binders.BindToHeaders;
+import org.jclouds.openstack.swift.v1.domain.DeleteStaticLargeObjectResponse;
import org.jclouds.openstack.swift.v1.domain.Segment;
import org.jclouds.openstack.swift.v1.functions.ETagHeader;
import org.jclouds.rest.annotations.BinderParam;
@@ -114,7 +115,7 @@ public interface StaticLargeObjectApi {
@DELETE
@Fallback(VoidOnNotFoundOr404.class)
@QueryParams(keys = "multipart-manifest", values = "delete")
- void delete(@PathParam("objectName") String objectName);
+ DeleteStaticLargeObjectResponse delete(@PathParam("objectName") String objectName);
/**
* Get a static large object's manifest.
http://git-wip-us.apache.org/repos/asf/jclouds/blob/68ff250c/apis/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/StaticLargeObjectApiLiveTest.java
----------------------------------------------------------------------
diff --git a/apis/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/StaticLargeObjectApiLiveTest.java b/apis/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/StaticLargeObjectApiLiveTest.java
index 3e92af5..6eca88c 100644
--- a/apis/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/StaticLargeObjectApiLiveTest.java
+++ b/apis/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/StaticLargeObjectApiLiveTest.java
@@ -17,6 +17,7 @@
package org.jclouds.openstack.swift.v1.features;
import static java.lang.String.format;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.jclouds.io.Payloads.newByteSourcePayload;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
@@ -26,6 +27,7 @@ import java.util.List;
import java.util.UUID;
import org.jclouds.openstack.swift.v1.SwiftApi;
+import org.jclouds.openstack.swift.v1.domain.DeleteStaticLargeObjectResponse;
import org.jclouds.openstack.swift.v1.domain.Segment;
import org.jclouds.openstack.swift.v1.domain.SwiftObject;
import org.jclouds.openstack.swift.v1.internal.BaseSwiftApiLiveTest;
@@ -47,7 +49,11 @@ public class StaticLargeObjectApiLiveTest extends BaseSwiftApiLiveTest<SwiftApi>
public void testNotPresentWhenDeleting() throws Exception {
for (String regionId : regions) {
- api.getStaticLargeObjectApi(regionId, containerName).delete(UUID.randomUUID().toString());
+ DeleteStaticLargeObjectResponse resp = api.getStaticLargeObjectApi(regionId, containerName).delete(UUID.randomUUID().toString());
+ assertThat(resp.status()).isEqualTo("200 OK");
+ assertThat(resp.deleted()).isZero();
+ assertThat(resp.notFound()).isEqualTo(1);
+ assertThat(resp.errors()).isEmpty();
}
}
@@ -88,11 +94,27 @@ public class StaticLargeObjectApiLiveTest extends BaseSwiftApiLiveTest<SwiftApi>
@Test(dependsOnMethods = "testReplaceManifest")
public void testDelete() throws Exception {
for (String regionId : regions) {
- api.getStaticLargeObjectApi(regionId, containerName).delete(name);
+ DeleteStaticLargeObjectResponse resp = api.getStaticLargeObjectApi(regionId, containerName).delete(name);
+ assertThat(resp.status()).isEqualTo("200 OK");
+ assertThat(resp.deleted()).isEqualTo(3);
+ assertThat(resp.notFound()).isZero();
+ assertThat(resp.errors()).isEmpty();
assertEquals(api.getContainerApi(regionId).get(containerName).getObjectCount(), 0);
}
}
+ public void testDeleteSinglePartObjectWithMultiPartDelete() throws Exception {
+ String objectName = "testDeleteSinglePartObjectWithMultiPartDelete";
+ for (String regionId : regions) {
+ api.getObjectApi(regionId, containerName).put(objectName, newByteSourcePayload(ByteSource.wrap("swifty".getBytes())));
+ DeleteStaticLargeObjectResponse resp = api.getStaticLargeObjectApi(regionId, containerName).delete(objectName);
+ assertThat(resp.status()).isEqualTo("400 Bad Request");
+ assertThat(resp.deleted()).isZero();
+ assertThat(resp.notFound()).isZero();
+ assertThat(resp.errors()).hasSize(1);
+ }
+ }
+
protected void assertMegabyteAndETagMatches(String regionId, String name, String etag1s) {
SwiftObject object1s = api.getObjectApi(regionId, containerName).get(name);
assertEquals(object1s.getETag(), etag1s);
http://git-wip-us.apache.org/repos/asf/jclouds/blob/68ff250c/apis/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/StaticLargeObjectApiMockTest.java
----------------------------------------------------------------------
diff --git a/apis/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/StaticLargeObjectApiMockTest.java b/apis/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/StaticLargeObjectApiMockTest.java
index ec135c1..e466b1c 100644
--- a/apis/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/StaticLargeObjectApiMockTest.java
+++ b/apis/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/StaticLargeObjectApiMockTest.java
@@ -16,12 +16,14 @@
*/
package org.jclouds.openstack.swift.v1.features;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.jclouds.openstack.swift.v1.reference.SwiftHeaders.OBJECT_METADATA_PREFIX;
import static org.testng.Assert.assertEquals;
import java.util.List;
import org.jclouds.openstack.swift.v1.SwiftApi;
+import org.jclouds.openstack.swift.v1.domain.DeleteStaticLargeObjectResponse;
import org.jclouds.openstack.swift.v1.domain.Segment;
import org.jclouds.openstack.v2_0.internal.BaseOpenStackMockTest;
import org.testng.annotations.Test;
@@ -168,16 +170,20 @@ public class StaticLargeObjectApiMockTest extends BaseOpenStackMockTest<SwiftApi
public void testDelete() throws Exception {
MockWebServer server = mockOpenStackServer();
server.enqueue(addCommonHeaders(new MockResponse().setBody(stringFromResource("/access.json"))));
- server.enqueue(addCommonHeaders(new MockResponse().setResponseCode(204)));
+ server.enqueue(addCommonHeaders(new MockResponse().setResponseCode(200)
+ .setBody("{\"Number Not Found\": 0, \"Response Status\": \"200 OK\", \"Errors\": [], \"Number Deleted\": 6, \"Response Body\": \"\"}")));
try {
SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift");
- api.getStaticLargeObjectApi("DFW", "myContainer").delete("myObject");
+ DeleteStaticLargeObjectResponse response = api.getStaticLargeObjectApi("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");
-
+ assertThat(response.status()).isEqualTo("200 OK");
+ assertThat(response.deleted()).isEqualTo(6);
+ assertThat(response.notFound()).isZero();
+ assertThat(response.errors()).isEmpty();
} finally {
server.shutdown();
}
@@ -186,15 +192,20 @@ public class StaticLargeObjectApiMockTest extends BaseOpenStackMockTest<SwiftApi
public void testAlreadyDeleted() throws Exception {
MockWebServer server = mockOpenStackServer();
server.enqueue(addCommonHeaders(new MockResponse().setBody(stringFromResource("/access.json"))));
- server.enqueue(addCommonHeaders(new MockResponse().setResponseCode(404)));
+ server.enqueue(addCommonHeaders(new MockResponse().setResponseCode(200)
+ .setBody("{\"Number Not Found\": 1, \"Response Status\": \"200 OK\", \"Errors\": [], \"Number Deleted\": 0, \"Response Body\": \"\"}")));
try {
SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift");
- api.getStaticLargeObjectApi("DFW", "myContainer").delete("myObject");
+ DeleteStaticLargeObjectResponse response = api.getStaticLargeObjectApi("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");
+ assertThat(response.status()).isEqualTo("200 OK");
+ assertThat(response.deleted()).isZero();
+ assertThat(response.notFound()).isEqualTo(1);
+ assertThat(response.errors()).isEmpty();
} finally {
server.shutdown();
}