Skip to content

Commit 29c2269

Browse files
author
Hans-Peter Klett
committed
Used ChunkClientProcessingOrderGuarantee
* Updated the BulkGetRequest to include ChunkClientProcessingOrderGuarantee. * Updated the read helpers to set ChunkClientProcessingOrderGuarantee to NONE.
1 parent 5e9c280 commit 29c2269

File tree

9 files changed

+94
-10
lines changed

9 files changed

+94
-10
lines changed

sdk/src/main/java/com/spectralogic/ds3client/commands/AllocateJobChunkResponse.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,11 @@ private static Objects parseChunk(final WebResponse webResponse) throws IOExcept
7777
}
7878
}
7979

80-
private static int parseRetryAfter(final WebResponse response) {
81-
return Integer.parseInt(response.getHeaders().get("Retry-After"));
80+
private static int parseRetryAfter(final WebResponse webResponse) {
81+
final String retryAfter = webResponse.getHeaders().get("Retry-After");
82+
if (retryAfter == null) {
83+
throw new RetryAfterExpectedException();
84+
}
85+
return Integer.parseInt(retryAfter);
8286
}
8387
}

sdk/src/main/java/com/spectralogic/ds3client/commands/BulkGetRequest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package com.spectralogic.ds3client.commands;
1717

1818
import com.spectralogic.ds3client.BulkCommand;
19+
import com.spectralogic.ds3client.models.bulk.ChunkClientProcessingOrderGuarantee;
1920
import com.spectralogic.ds3client.models.bulk.Ds3Object;
2021
import com.spectralogic.ds3client.models.bulk.Priority;
2122
import com.spectralogic.ds3client.models.bulk.WriteOptimization;
@@ -40,6 +41,15 @@ public BulkGetRequest withWriteOptimization(final WriteOptimization writeOptimiz
4041
super.withWriteOptimization(writeOptimization);
4142
return this;
4243
}
44+
45+
public BulkGetRequest withChunkOrdering(final ChunkClientProcessingOrderGuarantee chunkOrdering) {
46+
this.chunkOrdering = chunkOrdering;
47+
return this;
48+
}
49+
50+
public ChunkClientProcessingOrderGuarantee getChunkOrdering() {
51+
return this.chunkOrdering;
52+
}
4353

4454
@Override
4555
public BulkCommand getCommand() {

sdk/src/main/java/com/spectralogic/ds3client/commands/BulkRequest.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,7 @@
1717

1818
import com.spectralogic.ds3client.BulkCommand;
1919
import com.spectralogic.ds3client.HttpVerb;
20-
import com.spectralogic.ds3client.models.bulk.Ds3Object;
21-
import com.spectralogic.ds3client.models.bulk.Ds3ObjectList;
22-
import com.spectralogic.ds3client.models.bulk.Priority;
23-
import com.spectralogic.ds3client.models.bulk.WriteOptimization;
20+
import com.spectralogic.ds3client.models.bulk.*;
2421
import com.spectralogic.ds3client.serializer.XmlOutput;
2522

2623
import java.io.ByteArrayInputStream;
@@ -35,6 +32,7 @@ abstract class BulkRequest extends AbstractRequest {
3532
private long size;
3633
private Priority priority;
3734
private WriteOptimization writeOptimization;
35+
protected ChunkClientProcessingOrderGuarantee chunkOrdering;
3836

3937
public BulkRequest(final String bucket, final List<Ds3Object> objects) {
4038
this.bucket = bucket;
@@ -57,6 +55,7 @@ private InputStream generateStream() {
5755
objects.setObjects(this.ds3Objects);
5856
objects.setPriority(this.priority);
5957
objects.setWriteOptimization(this.writeOptimization);
58+
objects.setChunkClientProcessingOrderGuarantee(this.chunkOrdering);
6059
final String xmlOutput = XmlOutput.toXml(objects, this.getCommand());
6160

6261
final byte[] stringBytes = xmlOutput.getBytes();

sdk/src/main/java/com/spectralogic/ds3client/commands/GetAvailableJobChunksResponse.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ private static MasterObjectList parseMasterObjectList(final WebResponse webRespo
7979
}
8080

8181
private static int parseRetryAfter(final WebResponse webResponse) {
82-
return Integer.parseInt(webResponse.getHeaders().get("Retry-After"));
82+
final String retryAfter = webResponse.getHeaders().get("Retry-After");
83+
if (retryAfter == null) {
84+
throw new RetryAfterExpectedException();
85+
}
86+
return Integer.parseInt(retryAfter);
8387
}
8488
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* ******************************************************************************
3+
* Copyright 2014 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+
public class RetryAfterExpectedException extends RuntimeException {
19+
private static final long serialVersionUID = 6193215224073981762L;
20+
21+
public RetryAfterExpectedException() {
22+
super("Based on the response the server should have returned a Retry-After HTTP header.");
23+
}
24+
}

sdk/src/main/java/com/spectralogic/ds3client/helpers/Ds3ClientHelpersImpl.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import com.spectralogic.ds3client.helpers.options.WriteJobOptions;
2323
import com.spectralogic.ds3client.models.Contents;
2424
import com.spectralogic.ds3client.models.ListBucketResult;
25+
import com.spectralogic.ds3client.models.bulk.ChunkClientProcessingOrderGuarantee;
2526
import com.spectralogic.ds3client.models.bulk.Ds3Object;
2627
import com.spectralogic.ds3client.serializer.XmlProcessingException;
2728

@@ -90,6 +91,7 @@ public Ds3ClientHelpers.Job startReadJob(final String bucket, final Iterable<Ds3
9091
private Ds3ClientHelpers.Job innerStartReadJob(final String bucket, final Iterable<Ds3Object> objectsToRead, final ReadJobOptions options)
9192
throws SignatureException, IOException, XmlProcessingException {
9293
final BulkGetResponse prime = this.client.bulkGet(new BulkGetRequest(bucket, Lists.newArrayList(objectsToRead))
94+
.withChunkOrdering(ChunkClientProcessingOrderGuarantee.NONE)
9395
.withPriority(options.getPriority()));
9496
return new ReadJobImpl(this.client, prime.getResult());
9597
}

sdk/src/main/java/com/spectralogic/ds3client/models/bulk/Ds3ObjectList.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ public class Ds3ObjectList {
1717
@JacksonXmlProperty(isAttribute = true, namespace = "", localName = "WriteOptimization")
1818
private WriteOptimization writeOptimization;
1919

20+
@JacksonXmlProperty(isAttribute = true, namespace = "", localName = "ChunkClientProcessingOrderGuarantee")
21+
private ChunkClientProcessingOrderGuarantee chunkClientProcessingOrderGuarantee;
22+
2023
public Ds3ObjectList() {
2124
}
2225

@@ -41,10 +44,18 @@ public void setPriority(final Priority priority) {
4144
}
4245

4346
public WriteOptimization getWriteOptimization() {
44-
return writeOptimization;
47+
return this.writeOptimization;
4548
}
4649

4750
public void setWriteOptimization(final WriteOptimization writeOptimization) {
4851
this.writeOptimization = writeOptimization;
4952
}
53+
54+
public ChunkClientProcessingOrderGuarantee getChunkClientProcessingOrderGuarantee() {
55+
return this.chunkClientProcessingOrderGuarantee;
56+
}
57+
58+
public void setChunkClientProcessingOrderGuarantee(final ChunkClientProcessingOrderGuarantee chunkClientProcessingOrderGuarantee) {
59+
this.chunkClientProcessingOrderGuarantee = chunkClientProcessingOrderGuarantee;
60+
}
5061
}

sdk/src/test/java/com/spectralogic/ds3client/helpers/Ds3ClientHelpers_Test.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public void testReadObjects() throws SignatureException, IOException, XmlProcess
5353
final Ds3Client ds3Client = buildDs3ClientForBulk();
5454

5555
final BulkGetResponse buildBulkGetResponse = buildBulkGetResponse();
56-
Mockito.when(ds3Client.bulkGet(Mockito.any(BulkGetRequest.class))).thenReturn(buildBulkGetResponse);
56+
Mockito.when(ds3Client.bulkGet(hasChunkOrdering(ChunkClientProcessingOrderGuarantee.NONE))).thenReturn(buildBulkGetResponse);
5757

5858
Mockito.when(ds3Client.getObject(getRequestHas(MYBUCKET, "foo", jobId, 0))).then(getObjectAnswer("foo co"));
5959
Mockito.when(ds3Client.getObject(getRequestHas(MYBUCKET, "bar", jobId, 0))).then(getObjectAnswer("bar contents"));
@@ -97,7 +97,7 @@ public void testReadObjectsWithFailedGet() throws SignatureException, IOExceptio
9797
Mockito.when(ds3Client.buildFactory(Mockito.<Iterable<Node>>any())).thenReturn(ds3ClientFactory);
9898

9999
final BulkGetResponse buildBulkGetResponse = buildBulkGetResponse();
100-
Mockito.when(ds3Client.bulkGet(Mockito.any(BulkGetRequest.class))).thenReturn(buildBulkGetResponse);
100+
Mockito.when(ds3Client.bulkGet(hasChunkOrdering(ChunkClientProcessingOrderGuarantee.NONE))).thenReturn(buildBulkGetResponse);
101101

102102
final GetAvailableJobChunksResponse jobChunksResponse = buildJobChunksResponse2();
103103
Mockito.when(ds3Client.getAvailableJobChunks(hasJobId(jobId))).thenReturn(jobChunksResponse);

sdk/src/test/java/com/spectralogic/ds3client/helpers/RequestMatchers.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package com.spectralogic.ds3client.helpers;
1717

1818
import com.spectralogic.ds3client.commands.*;
19+
import com.spectralogic.ds3client.models.bulk.ChunkClientProcessingOrderGuarantee;
1920

2021
import org.apache.commons.io.IOUtils;
2122
import org.hamcrest.Description;
@@ -30,6 +31,35 @@
3031
import static org.mockito.Matchers.*;
3132

3233
public class RequestMatchers {
34+
public static BulkGetRequest hasChunkOrdering(final ChunkClientProcessingOrderGuarantee chunkOrdering) {
35+
return argThat(new TypeSafeMatcher<BulkGetRequest>() {
36+
@Override
37+
protected boolean matchesSafely(final BulkGetRequest item) {
38+
return item.getChunkOrdering() == null
39+
? chunkOrdering == null
40+
: item.getChunkOrdering().equals(chunkOrdering);
41+
}
42+
43+
@Override
44+
public void describeTo(final Description description) {
45+
describe(chunkOrdering, description);
46+
}
47+
48+
@Override
49+
protected void describeMismatchSafely(final BulkGetRequest item, final Description mismatchDescription) {
50+
describe(item.getChunkOrdering(), mismatchDescription);
51+
}
52+
53+
private void describe(
54+
final ChunkClientProcessingOrderGuarantee chunkOrdering,
55+
final Description description) {
56+
description
57+
.appendText("BulkGetRequest with Chunk Ordering: ")
58+
.appendValue(chunkOrdering);
59+
}
60+
});
61+
}
62+
3363
public static GetAvailableJobChunksRequest hasJobId(final UUID jobId) {
3464
return argThat(new TypeSafeMatcher<GetAvailableJobChunksRequest>() {
3565
@Override

0 commit comments

Comments
 (0)