Skip to content

Commit bd5ca46

Browse files
author
hansdude
committed
Merge pull request #66 from rpmoore/master
MultiObject Delete Support w/Minor Documentation Addition
2 parents 5acb265 + e4a47ba commit bd5ca46

File tree

17 files changed

+644
-184
lines changed

17 files changed

+644
-184
lines changed

ds3-sdk-integration/src/test/java/com/spectralogic/ds3client/integration/BucketIntegration_Test.java

Lines changed: 229 additions & 168 deletions
Large diffs are not rendered by default.

ds3-sdk-integration/src/test/java/com/spectralogic/ds3client/integration/DataIntegrity_Test.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,7 @@ public void singleFilePut() throws IOException, URISyntaxException, XmlProcessin
7676

7777
final String secondDigest = DigestUtils.sha256Hex(Files.newInputStream(tempDir.resolve(book)));
7878
assertThat(secondDigest, is(equalTo(digest)));
79-
}
80-
finally {
79+
} finally {
8180
Util.deleteAllContents(client, bucketName);
8281
}
8382
}
@@ -89,7 +88,7 @@ public void randomDataFile() throws IOException, SignatureException, URISyntaxEx
8988
final long seed = 12345689;
9089
final int length = 2048;
9190

92-
sendAndVerifySingleFile(bucketName, randomFileName, seed, length);
91+
sendAndVerifySingleFile(bucketName, randomFileName, seed, length);
9392
}
9493

9594
@Test
@@ -173,8 +172,7 @@ public SeekableByteChannel buildChannel(final String key) throws IOException {
173172

174173
final String secondDigest = DigestUtils.sha256Hex(Files.newInputStream(tempDir.resolve(fileName)));
175174
assertThat(secondDigest, is(equalTo(digest)));
176-
}
177-
finally {
175+
} finally {
178176
Util.deleteAllContents(client, bucketName);
179177
}
180178
}

ds3-sdk-integration/src/test/java/com/spectralogic/ds3client/integration/NotificationsIntegration_test.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,7 @@ public void objectPersistedRegistration() throws IOException, SignatureException
129129
assertThat(getResponse.getRegistration().getId(), is(notNullValue()));
130130

131131
assertThat(client.deleteObjectPersistedNotification(new DeleteObjectPersistedNotificationRequest(registrationId)), is(notNullValue()));
132-
}
133-
finally {
132+
} finally {
134133
Util.deleteAllContents(client, bucketName);
135134
}
136135
}

ds3-sdk/src/main/java/com/spectralogic/ds3client/Ds3Client.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,11 @@ public abstract DeleteBucketResponse deleteBucket(
110110
* @throws IOException
111111
* @throws SignatureException
112112
*/
113-
public abstract DeleteObjectResponse deleteObject(
114-
DeleteObjectRequest request) throws IOException, SignatureException;
113+
public abstract DeleteObjectResponse deleteObject(DeleteObjectRequest request)
114+
throws IOException, SignatureException;
115+
116+
public abstract DeleteMultipleObjectsResponse deleteMultipleObjects(DeleteMultipleObjectsRequest request)
117+
throws IOException, SignatureException;
115118

116119
/**
117120
* Retrieves an object from DS3

ds3-sdk/src/main/java/com/spectralogic/ds3client/Ds3ClientImpl.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ public DeleteObjectResponse deleteObject(final DeleteObjectRequest request) thro
7171
return new DeleteObjectResponse(this.netClient.getResponse(request));
7272
}
7373

74+
@Override
75+
public DeleteMultipleObjectsResponse deleteMultipleObjects(final DeleteMultipleObjectsRequest request) throws IOException, SignatureException {
76+
return new DeleteMultipleObjectsResponse(this.netClient.getResponse(request));
77+
}
78+
7479
@Override
7580
public GetObjectResponse getObject(final GetObjectRequest request) throws IOException, SignatureException {
7681
return new GetObjectResponse(

ds3-sdk/src/main/java/com/spectralogic/ds3client/NetworkClientImpl.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,11 +197,24 @@ private void addHeaders(final HttpRequest httpRequest) throws IOException, Signa
197197
this.ds3Request.getContentType().toString(),
198198
date,
199199
canonicalizeAmzHeaders(this.ds3Request.getHeaders()),
200-
UrlEscapers.urlFragmentEscaper().escape(this.ds3Request.getPath()),
200+
canonicalizeResource(this.ds3Request.getPath(), this.ds3Request.getQueryParams()),
201201
NetworkClientImpl.this.connectionDetails.getCredentials()
202202
)));
203203
}
204-
204+
205+
206+
private String canonicalizeResource(final String path, final Map<String, String> queryParams) {
207+
208+
final StringBuilder canonicalizedResource = new StringBuilder();
209+
canonicalizedResource.append(UrlEscapers.urlFragmentEscaper().escape(path));
210+
211+
if (queryParams.containsKey("delete")) {
212+
canonicalizedResource.append("?delete");
213+
}
214+
215+
return canonicalizedResource.toString();
216+
}
217+
205218
private String canonicalizeAmzHeaders(
206219
final Multimap<String, String> customHeaders) {
207220
StringBuilder ret = new StringBuilder();
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/*
2+
* ******************************************************************************
3+
* Copyright 2014-2015 Spectra Logic Corporation. All Rights Reserved.
4+
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use
5+
* this file except in compliance with the License. A copy of the License is located at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* or in the "license" file accompanying this file.
10+
* This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11+
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
12+
* specific language governing permissions and limitations under the License.
13+
* ****************************************************************************
14+
*/
15+
16+
package com.spectralogic.ds3client.commands;
17+
18+
import com.spectralogic.ds3client.HttpVerb;
19+
import com.spectralogic.ds3client.models.Contents;
20+
import com.spectralogic.ds3client.models.delete.Delete;
21+
import com.spectralogic.ds3client.models.delete.DeleteObject;
22+
import com.spectralogic.ds3client.serializer.XmlOutput;
23+
24+
import java.io.ByteArrayInputStream;
25+
import java.io.InputStream;
26+
import java.util.ArrayList;
27+
import java.util.List;
28+
29+
public class DeleteMultipleObjectsRequest extends AbstractRequest {
30+
31+
private final String bucketName;
32+
private final List<String> objects;
33+
34+
private boolean quiet = false;
35+
36+
private long size;
37+
38+
public DeleteMultipleObjectsRequest(final String bucketName, final List<String> objects) {
39+
this.bucketName = bucketName;
40+
this.objects = objects;
41+
this.getQueryParams().put("delete", null);
42+
}
43+
44+
public DeleteMultipleObjectsRequest(final String bucketName, final Iterable<Contents> objs) {
45+
this(bucketName, contentsToString(objs));
46+
}
47+
48+
static private List<String> contentsToString(final Iterable<Contents> objs) {
49+
final List<String> objKeyList = new ArrayList<>();
50+
for (final Contents obj : objs) {
51+
objKeyList.add(obj.getKey());
52+
}
53+
return objKeyList;
54+
}
55+
56+
public DeleteMultipleObjectsRequest withQuiet(final boolean quiet) {
57+
this.quiet = quiet;
58+
return this;
59+
}
60+
61+
@Override
62+
public InputStream getStream() {
63+
64+
final Delete delete = new Delete();
65+
delete.setQuiet(quiet);
66+
final List<DeleteObject> deleteObjects = new ArrayList<>();
67+
68+
for(final String objName : objects) {
69+
deleteObjects.add(new DeleteObject(objName));
70+
}
71+
72+
delete.setDeleteObjectList(deleteObjects);
73+
74+
final String xmlOutput = XmlOutput.toXml(delete);
75+
final byte[] stringBytes = xmlOutput.getBytes();
76+
this.size = stringBytes.length;
77+
78+
return new ByteArrayInputStream(stringBytes);
79+
}
80+
81+
@Override
82+
public long getSize() {
83+
return this.size;
84+
}
85+
86+
@Override
87+
public String getPath() {
88+
return "/" + bucketName;
89+
}
90+
91+
@Override
92+
public HttpVerb getVerb() {
93+
return HttpVerb.POST;
94+
}
95+
96+
public List<String> getObjects() {
97+
return objects;
98+
}
99+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* ******************************************************************************
3+
* Copyright 2014-2015 Spectra Logic Corporation. All Rights Reserved.
4+
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use
5+
* this file except in compliance with the License. A copy of the License is located at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* or in the "license" file accompanying this file.
10+
* This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11+
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
12+
* specific language governing permissions and limitations under the License.
13+
* ****************************************************************************
14+
*/
15+
16+
package com.spectralogic.ds3client.commands;
17+
18+
import com.spectralogic.ds3client.models.delete.DeleteResult;
19+
import com.spectralogic.ds3client.networking.WebResponse;
20+
import com.spectralogic.ds3client.serializer.XmlOutput;
21+
import org.apache.commons.io.IOUtils;
22+
23+
import java.io.IOException;
24+
import java.io.InputStream;
25+
import java.io.StringWriter;
26+
27+
public class DeleteMultipleObjectsResponse extends AbstractResponse {
28+
29+
private DeleteResult result;
30+
31+
public DeleteMultipleObjectsResponse(final WebResponse response) throws IOException {
32+
super(response);
33+
}
34+
35+
public DeleteResult getResult() {
36+
return result;
37+
}
38+
39+
@Override
40+
protected void processResponse() throws IOException {
41+
try {
42+
this.checkStatusCode(200);
43+
try (final InputStream content = getResponse().getResponseStream();
44+
final StringWriter writer = new StringWriter()) {
45+
IOUtils.copy(content, writer, UTF8);
46+
this.result = XmlOutput.fromXml(writer.toString(), DeleteResult.class);
47+
}
48+
} finally {
49+
this.getResponse().close();
50+
}
51+
}
52+
}

ds3-sdk/src/main/java/com/spectralogic/ds3client/helpers/Ds3ClientHelpers.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public interface Job {
5959
public Job withMaxParallelRequests(int maxParallelRequests);
6060

6161
/**
62-
* Transfers the files in this job using the given seekable channel creator.
62+
* Transfers the files in this job using the given seekable channel creator. The is a blocking call.
6363
* @throws SignatureException
6464
* @throws IOException
6565
* @throws XmlProcessingException
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* ******************************************************************************
3+
* Copyright 2014-2015 Spectra Logic Corporation. All Rights Reserved.
4+
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use
5+
* this file except in compliance with the License. A copy of the License is located at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* or in the "license" file accompanying this file.
10+
* This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11+
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
12+
* specific language governing permissions and limitations under the License.
13+
* ****************************************************************************
14+
*/
15+
16+
package com.spectralogic.ds3client.models.delete;
17+
18+
import com.fasterxml.jackson.annotation.JsonProperty;
19+
20+
import java.util.List;
21+
22+
public class Delete {
23+
24+
@JsonProperty("Quiet")
25+
private boolean quiet;
26+
27+
@JsonProperty("Object")
28+
private List<DeleteObject> deleteObjectList;
29+
30+
public Delete() {
31+
}
32+
33+
public boolean isQuiet() {
34+
return quiet;
35+
}
36+
37+
public void setQuiet(final boolean quiet) {
38+
this.quiet = quiet;
39+
}
40+
41+
public List<DeleteObject> getDeleteObjectList() {
42+
return deleteObjectList;
43+
}
44+
45+
public void setDeleteObjectList(final List<DeleteObject> deleteObjectList) {
46+
this.deleteObjectList = deleteObjectList;
47+
}
48+
}

0 commit comments

Comments
 (0)