Skip to content

Commit 61d07cd

Browse files
committed
Merge pull request #43 from hansdude/master
Updated the client helpers to use the new requests.
2 parents ea8489c + 3eebfb9 commit 61d07cd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+2707
-427
lines changed

sdk/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ dependencies {
99
compile 'org.codehaus.woodstox:woodstox-core-asl:4.2.0'
1010
compile 'com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.2.3'
1111
compile 'com.google.guava:guava:16.0.1'
12+
compile 'org.hamcrest:hamcrest-library:1.3'
1213
}

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

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

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

2021
import java.io.IOException;
2122
import java.security.SignatureException;
@@ -236,4 +237,9 @@ public abstract CancelJobResponse cancelJob(CancelJobRequest request)
236237
*/
237238
public abstract ModifyJobResponse modifyJob(ModifyJobRequest request)
238239
throws IOException, SignatureException;
240+
241+
/**
242+
* Creates a factory based on a set of nodes that can return clients by node id.
243+
*/
244+
public abstract Ds3ClientFactory buildFactory(Iterable<Node> nodes);
239245
}

sdk/src/main/java/com/spectralogic/ds3client/helpers/Ds3ClientFactory.java renamed to sdk/src/main/java/com/spectralogic/ds3client/Ds3ClientFactory.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,10 @@
1313
* ****************************************************************************
1414
*/
1515

16-
package com.spectralogic.ds3client.helpers;
17-
18-
import com.spectralogic.ds3client.Ds3Client;
16+
package com.spectralogic.ds3client;
1917

2018
import java.util.UUID;
2119

22-
interface Ds3ClientFactory {
20+
public interface Ds3ClientFactory {
2321
Ds3Client getClientForNodeId(UUID nodeId);
2422
}

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

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

1818
import com.spectralogic.ds3client.commands.*;
19+
import com.spectralogic.ds3client.models.bulk.Node;
1920
import com.spectralogic.ds3client.networking.NetworkClient;
2021

2122
import java.io.IOException;
2223
import java.security.SignatureException;
24+
import java.util.UUID;
2325

2426
class Ds3ClientImpl implements Ds3Client {
2527
private final NetworkClient netClient;
@@ -115,4 +117,15 @@ public CancelJobResponse cancelJob(final CancelJobRequest request) throws IOExce
115117
public ModifyJobResponse modifyJob(final ModifyJobRequest request) throws IOException, SignatureException {
116118
return new ModifyJobResponse(this.netClient.getResponse(request));
117119
}
120+
121+
@Override
122+
public Ds3ClientFactory buildFactory(final Iterable<Node> nodes) {
123+
return new Ds3ClientFactory() {
124+
@Override
125+
public Ds3Client getClientForNodeId(final UUID nodeId) {
126+
//TODO: pay attention to actual nodes.
127+
return Ds3ClientImpl.this;
128+
}
129+
};
130+
}
118131
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,4 @@ private String readResponseString() throws IOException {
9696
public String getMd5() {
9797
return md5;
9898
}
99-
}
99+
}

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public class AllocateJobChunkResponse extends AbstractResponse {
3131
private int retryAfterSeconds;
3232

3333
static public enum Status {
34-
ALLOCATED, RETRYLATER, NOTFOUND
34+
ALLOCATED, RETRYLATER
3535
}
3636

3737
public AllocateJobChunkResponse(final WebResponse response) throws IOException {
@@ -53,7 +53,7 @@ public int getRetryAfterSeconds() {
5353
@Override
5454
protected void processResponse() throws IOException {
5555
try (final WebResponse response = this.getResponse()) {
56-
checkStatusCode(200, 503, 404);
56+
checkStatusCode(200, 503);
5757
switch (this.getStatusCode()) {
5858
case 200:
5959
this.status = Status.ALLOCATED;
@@ -63,9 +63,6 @@ protected void processResponse() throws IOException {
6363
this.status = Status.RETRYLATER;
6464
this.retryAfterSeconds = parseRetryAfter(response);
6565
break;
66-
case 404:
67-
this.status = Status.NOTFOUND;
68-
break;
6966
default:
7067
assert false : "checkStatusCode should have made it impossible to reach this line.";
7168
}
@@ -80,7 +77,11 @@ private static Objects parseChunk(final WebResponse webResponse) throws IOExcept
8077
}
8178
}
8279

83-
private static int parseRetryAfter(final WebResponse response) {
84-
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);
8586
}
8687
}

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: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public class GetAvailableJobChunksResponse extends AbstractResponse {
3131
private int retryAfterSeconds;
3232

3333
static public enum Status {
34-
AVAILABLE, RETRYLATER, NOTFOUND
34+
AVAILABLE, RETRYLATER
3535
}
3636

3737
public Status getStatus() {
@@ -53,7 +53,7 @@ public GetAvailableJobChunksResponse(final WebResponse response) throws IOExcept
5353
@Override
5454
protected void processResponse() throws IOException {
5555
try (final WebResponse webResponse = this.getResponse()) {
56-
this.checkStatusCode(200, 404);
56+
this.checkStatusCode(200);
5757
switch (this.getStatusCode()) {
5858
case 200:
5959
this.masterObjectList = parseMasterObjectList(webResponse);
@@ -64,9 +64,6 @@ protected void processResponse() throws IOException {
6464
this.status = Status.AVAILABLE;
6565
}
6666
break;
67-
case 404:
68-
this.status = Status.NOTFOUND;
69-
break;
7067
default:
7168
assert false : "checkStatusCode should have made it impossible to reach this line.";
7269
}
@@ -82,6 +79,10 @@ private static MasterObjectList parseMasterObjectList(final WebResponse webRespo
8279
}
8380

8481
private static int parseRetryAfter(final WebResponse webResponse) {
85-
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);
8687
}
8788
}
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+
}

0 commit comments

Comments
 (0)