Skip to content

Commit 2a1ec2b

Browse files
authored
Merge pull request #541 from RachelTucker/4_1_autogen
4.1 API
2 parents dc59ff7 + 870e8a6 commit 2a1ec2b

16 files changed

+411
-9
lines changed

ds3-sdk/src/main/java/com/spectralogic/ds3client/commands/HeadObjectResponse.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,39 @@
1919
import com.spectralogic.ds3client.commands.interfaces.AbstractResponse;
2020
import com.spectralogic.ds3client.networking.Metadata;
2121
import com.spectralogic.ds3client.models.ChecksumType;
22+
import com.google.common.collect.ImmutableMap;
2223

2324
public class HeadObjectResponse extends AbstractResponse {
2425

2526
public enum Status { EXISTS, DOESNTEXIST, UNKNOWN }
2627

28+
private final ImmutableMap<Long, String> blobChecksums;
29+
30+
private final ChecksumType.Type blobChecksumType;
31+
2732
private final Metadata metadata;
2833

2934
private final long objectSize;
3035

3136
private final Status status;
3237

33-
public HeadObjectResponse(final Metadata metadata, final long objectSize, final Status status, final String checksum, final ChecksumType.Type checksumType) {
38+
public HeadObjectResponse(final ImmutableMap<Long, String> blobChecksums, final ChecksumType.Type blobChecksumType, final Metadata metadata, final long objectSize, final Status status, final String checksum, final ChecksumType.Type checksumType) {
3439
super(checksum, checksumType);
40+
this.blobChecksums = blobChecksums;
41+
this.blobChecksumType = blobChecksumType;
3542
this.metadata = metadata;
3643
this.objectSize = objectSize;
3744
this.status = status;
3845
}
3946

47+
public ImmutableMap<Long, String> getBlobChecksums() {
48+
return this.blobChecksums;
49+
}
50+
51+
public ChecksumType.Type getBlobChecksumType() {
52+
return this.blobChecksumType;
53+
}
54+
4055
public Metadata getMetadata() {
4156
return this.metadata;
4257
}

ds3-sdk/src/main/java/com/spectralogic/ds3client/commands/parsers/HeadObjectResponseParser.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,15 @@
1818

1919
import com.spectralogic.ds3client.commands.interfaces.MetadataImpl;
2020
import com.spectralogic.ds3client.networking.Metadata;
21+
import com.google.common.collect.ImmutableMap;
22+
import com.spectralogic.ds3client.models.ChecksumType;
2123
import com.spectralogic.ds3client.commands.HeadObjectResponse;
2224
import com.spectralogic.ds3client.commands.parsers.interfaces.AbstractResponseParser;
2325
import com.spectralogic.ds3client.commands.parsers.utils.ResponseParserUtils;
2426
import com.spectralogic.ds3client.networking.WebResponse;
2527
import java.io.IOException;
2628

27-
import static com.spectralogic.ds3client.commands.parsers.utils.ResponseParserUtils.getSizeFromHeaders;
29+
import static com.spectralogic.ds3client.commands.parsers.utils.ResponseParserUtils.*;
2830

2931
public class HeadObjectResponseParser extends AbstractResponseParser<HeadObjectResponse> {
3032
private final int[] expectedStatusCodes = new int[]{200, 404};
@@ -37,10 +39,12 @@ public HeadObjectResponse parseXmlResponse(final WebResponse response) throws IO
3739
final long objectSize = getSizeFromHeaders(response.getHeaders());
3840
switch (statusCode) {
3941
case 200:
40-
return new HeadObjectResponse(metadata, objectSize, HeadObjectResponse.Status.EXISTS, this.getChecksum(), this.getChecksumType());
42+
final ChecksumType.Type blobChecksumType = getBlobChecksumType(response.getHeaders());
43+
final ImmutableMap<Long, String> blobChecksumMap = getBlobChecksumMap(response.getHeaders());
44+
return new HeadObjectResponse(blobChecksumMap, blobChecksumType, metadata, objectSize, HeadObjectResponse.Status.EXISTS, this.getChecksum(), this.getChecksumType());
4145

4246
case 404:
43-
return new HeadObjectResponse(metadata, objectSize, HeadObjectResponse.Status.DOESNTEXIST, this.getChecksum(), this.getChecksumType());
47+
return new HeadObjectResponse(ImmutableMap.of(), ChecksumType.Type.NONE, metadata, objectSize, HeadObjectResponse.Status.DOESNTEXIST, this.getChecksum(), this.getChecksumType());
4448

4549
default:
4650
assert false: "validateStatusCode should have made it impossible to reach this line";

ds3-sdk/src/main/java/com/spectralogic/ds3client/commands/parsers/utils/ResponseParserUtils.java

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import com.google.common.base.Preconditions;
1919
import com.google.common.base.Strings;
20+
import com.google.common.collect.ImmutableMap;
2021
import com.google.common.collect.ImmutableSet;
2122
import com.spectralogic.ds3client.models.ChecksumType;
2223
import com.spectralogic.ds3client.models.Error;
@@ -41,6 +42,9 @@ public final class ResponseParserUtils {
4142
private final static Logger LOG = LoggerFactory.getLogger(ResponseParserUtils.class);
4243
final public static String UTF8 = "UTF-8";
4344

45+
private static final String BLOB_CHECKSUM_TYPE_HEADER = "ds3-blob-checksum-type";
46+
private static final String BLOB_CHECKSUM_HEADER = "ds3-blob-checksum-offset-";
47+
4448
private ResponseParserUtils() {
4549
// pass
4650
}
@@ -145,4 +149,72 @@ private static String readResponseString(final WebResponse response) throws IOEx
145149
return writer.toString();
146150
}
147151
}
152+
153+
/**
154+
* Retrieves the blob checksum type from the response headers. If there is no blob checksum
155+
* type header, than NONE is returned. If there is more than one value for the blob checksum
156+
* type header, than an illegal argument exception is thrown.
157+
*/
158+
public static ChecksumType.Type getBlobChecksumType(final Headers headers) {
159+
final List<String> types = headers.get(BLOB_CHECKSUM_TYPE_HEADER);
160+
switch (types.size()) {
161+
case 0:
162+
return ChecksumType.Type.NONE;
163+
case 1:
164+
return toBlobChecksumType(types.get(0));
165+
default:
166+
throw new IllegalArgumentException(String.format("Response has more than one header value for '%s'", BLOB_CHECKSUM_TYPE_HEADER));
167+
}
168+
}
169+
170+
/**
171+
* Converts the response header value for {@code BLOB_CHECKSUM_TYPE_HEADER} into a {@code ChecksumType.Type}
172+
*/
173+
static ChecksumType.Type toBlobChecksumType(final String checksumType) {
174+
if (Guard.isStringNullOrEmpty(checksumType)) {
175+
return ChecksumType.Type.NONE;
176+
}
177+
return ChecksumType.Type.valueOf(checksumType);
178+
}
179+
180+
/**
181+
* Retrieves a map of blob offset to blob checksum from response headers.
182+
*/
183+
public static ImmutableMap<Long, String> getBlobChecksumMap(final Headers headers) {
184+
if (headers.keys() == null) {
185+
return ImmutableMap.of();
186+
}
187+
188+
final ImmutableMap.Builder<Long, String> builder = ImmutableMap.builder();
189+
headers.keys().stream()
190+
.filter(key -> key.startsWith(BLOB_CHECKSUM_HEADER))
191+
.forEach(key -> builder.put(getOffsetFromHeaderKey(key), getBlobChecksumValue(key, headers)));
192+
193+
return builder.build();
194+
}
195+
196+
/**
197+
* Retrieves the offset from the blob checksum header key. This assumes that the
198+
* provided key has the prefix {@code BLOB_CHECKSUM_HEADER} and that the postfix can be
199+
* converted into a Long.
200+
*/
201+
private static Long getOffsetFromHeaderKey(final String key) {
202+
final String offset = key.substring(BLOB_CHECKSUM_HEADER.length());
203+
return Long.valueOf(offset);
204+
}
205+
206+
/**
207+
* Retrieves the value from the specified header key assuming there is at most one value.
208+
* If there are no values for the key, then an empty string is returned.
209+
* If there is more than one value for the given key, an illegal argument exception is thrown.
210+
*/
211+
private static String getBlobChecksumValue(final String key, final Headers headers) {
212+
final List<String> values = headers.get(key);
213+
switch (values.size()) {
214+
case 1:
215+
return values.get(0);
216+
default:
217+
throw new IllegalArgumentException(String.format("Expected response to have 1 value for blob checksum header '%s', but found '%d' values", key, values.size()));
218+
}
219+
}
148220
}

ds3-sdk/src/main/java/com/spectralogic/ds3client/commands/spectrads3/GetTapeDrivesSpectraS3Request.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import com.spectralogic.ds3client.commands.interfaces.AbstractPaginationRequest;
2121
import java.util.UUID;
2222
import com.google.common.net.UrlEscapers;
23+
import com.spectralogic.ds3client.models.ReservedTaskType;
2324
import com.spectralogic.ds3client.models.TapeDriveState;
2425
import com.spectralogic.ds3client.models.TapeDriveType;
2526

@@ -37,6 +38,8 @@ public class GetTapeDrivesSpectraS3Request extends AbstractPaginationRequest {
3738

3839
private String partitionId;
3940

41+
private ReservedTaskType reservedTaskType;
42+
4043
private String serialNumber;
4144

4245
private TapeDriveState state;
@@ -103,6 +106,13 @@ public GetTapeDrivesSpectraS3Request withPartitionId(final String partitionId) {
103106
}
104107

105108

109+
public GetTapeDrivesSpectraS3Request withReservedTaskType(final ReservedTaskType reservedTaskType) {
110+
this.reservedTaskType = reservedTaskType;
111+
this.updateQueryParam("reserved_task_type", reservedTaskType);
112+
return this;
113+
}
114+
115+
106116
public GetTapeDrivesSpectraS3Request withSerialNumber(final String serialNumber) {
107117
this.serialNumber = serialNumber;
108118
this.updateQueryParam("serial_number", serialNumber);
@@ -160,6 +170,11 @@ public String getPartitionId() {
160170
}
161171

162172

173+
public ReservedTaskType getReservedTaskType() {
174+
return this.reservedTaskType;
175+
}
176+
177+
163178
public String getSerialNumber() {
164179
return this.serialNumber;
165180
}

ds3-sdk/src/main/java/com/spectralogic/ds3client/commands/spectrads3/ModifyDataPathBackendSpectraS3Request.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,14 @@ public class ModifyDataPathBackendSpectraS3Request extends AbstractRequest {
3030

3131
private boolean activated;
3232

33+
private boolean allowNewJobRequests;
34+
3335
private Integer autoActivateTimeoutInMins;
3436

3537
private AutoInspectMode autoInspect;
3638

39+
private int cacheAvailableRetryAfterInSeconds;
40+
3741
private ImportConflictResolutionMode defaultImportConflictResolutionMode;
3842

3943
private Priority defaultVerifyDataAfterImport;
@@ -62,6 +66,13 @@ public ModifyDataPathBackendSpectraS3Request withActivated(final boolean activat
6266
}
6367

6468

69+
public ModifyDataPathBackendSpectraS3Request withAllowNewJobRequests(final boolean allowNewJobRequests) {
70+
this.allowNewJobRequests = allowNewJobRequests;
71+
this.updateQueryParam("allow_new_job_requests", allowNewJobRequests);
72+
return this;
73+
}
74+
75+
6576
public ModifyDataPathBackendSpectraS3Request withAutoActivateTimeoutInMins(final Integer autoActivateTimeoutInMins) {
6677
this.autoActivateTimeoutInMins = autoActivateTimeoutInMins;
6778
this.updateQueryParam("auto_activate_timeout_in_mins", autoActivateTimeoutInMins);
@@ -76,6 +87,13 @@ public ModifyDataPathBackendSpectraS3Request withAutoInspect(final AutoInspectMo
7687
}
7788

7889

90+
public ModifyDataPathBackendSpectraS3Request withCacheAvailableRetryAfterInSeconds(final int cacheAvailableRetryAfterInSeconds) {
91+
this.cacheAvailableRetryAfterInSeconds = cacheAvailableRetryAfterInSeconds;
92+
this.updateQueryParam("cache_available_retry_after_in_seconds", cacheAvailableRetryAfterInSeconds);
93+
return this;
94+
}
95+
96+
7997
public ModifyDataPathBackendSpectraS3Request withDefaultImportConflictResolutionMode(final ImportConflictResolutionMode defaultImportConflictResolutionMode) {
8098
this.defaultImportConflictResolutionMode = defaultImportConflictResolutionMode;
8199
this.updateQueryParam("default_import_conflict_resolution_mode", defaultImportConflictResolutionMode);
@@ -141,6 +159,11 @@ public boolean getActivated() {
141159
}
142160

143161

162+
public boolean getAllowNewJobRequests() {
163+
return this.allowNewJobRequests;
164+
}
165+
166+
144167
public Integer getAutoActivateTimeoutInMins() {
145168
return this.autoActivateTimeoutInMins;
146169
}
@@ -151,6 +174,11 @@ public AutoInspectMode getAutoInspect() {
151174
}
152175

153176

177+
public int getCacheAvailableRetryAfterInSeconds() {
178+
return this.cacheAvailableRetryAfterInSeconds;
179+
}
180+
181+
154182
public ImportConflictResolutionMode getDefaultImportConflictResolutionMode() {
155183
return this.defaultImportConflictResolutionMode;
156184
}

ds3-sdk/src/main/java/com/spectralogic/ds3client/commands/spectrads3/ModifyTapeDriveSpectraS3Request.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import com.spectralogic.ds3client.networking.HttpVerb;
2020
import com.spectralogic.ds3client.commands.interfaces.AbstractRequest;
2121
import com.spectralogic.ds3client.models.Quiesced;
22+
import com.spectralogic.ds3client.models.ReservedTaskType;
2223
import java.util.UUID;
2324
import com.google.common.net.UrlEscapers;
2425

@@ -30,6 +31,8 @@ public class ModifyTapeDriveSpectraS3Request extends AbstractRequest {
3031

3132
private Quiesced quiesced;
3233

34+
private ReservedTaskType reservedTaskType;
35+
3336
// Constructor
3437

3538

@@ -51,6 +54,13 @@ public ModifyTapeDriveSpectraS3Request withQuiesced(final Quiesced quiesced) {
5154
}
5255

5356

57+
public ModifyTapeDriveSpectraS3Request withReservedTaskType(final ReservedTaskType reservedTaskType) {
58+
this.reservedTaskType = reservedTaskType;
59+
this.updateQueryParam("reserved_task_type", reservedTaskType);
60+
return this;
61+
}
62+
63+
5464

5565
@Override
5666
public HttpVerb getVerb() {
@@ -71,4 +81,9 @@ public Quiesced getQuiesced() {
7181
return this.quiesced;
7282
}
7383

84+
85+
public ReservedTaskType getReservedTaskType() {
86+
return this.reservedTaskType;
87+
}
88+
7489
}

ds3-sdk/src/main/java/com/spectralogic/ds3client/commands/spectrads3/ModifyTapePartitionSpectraS3Request.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ public class ModifyTapePartitionSpectraS3Request extends AbstractRequest {
2727

2828
private final String tapePartition;
2929

30+
private int minimumReadReservedDrives;
31+
32+
private int minimumWriteReservedDrives;
33+
3034
private Quiesced quiesced;
3135

3236
// Constructor
@@ -37,6 +41,20 @@ public ModifyTapePartitionSpectraS3Request(final String tapePartition) {
3741

3842
}
3943

44+
public ModifyTapePartitionSpectraS3Request withMinimumReadReservedDrives(final int minimumReadReservedDrives) {
45+
this.minimumReadReservedDrives = minimumReadReservedDrives;
46+
this.updateQueryParam("minimum_read_reserved_drives", minimumReadReservedDrives);
47+
return this;
48+
}
49+
50+
51+
public ModifyTapePartitionSpectraS3Request withMinimumWriteReservedDrives(final int minimumWriteReservedDrives) {
52+
this.minimumWriteReservedDrives = minimumWriteReservedDrives;
53+
this.updateQueryParam("minimum_write_reserved_drives", minimumWriteReservedDrives);
54+
return this;
55+
}
56+
57+
4058
public ModifyTapePartitionSpectraS3Request withQuiesced(final Quiesced quiesced) {
4159
this.quiesced = quiesced;
4260
this.updateQueryParam("quiesced", quiesced);
@@ -60,6 +78,16 @@ public String getTapePartition() {
6078
}
6179

6280

81+
public int getMinimumReadReservedDrives() {
82+
return this.minimumReadReservedDrives;
83+
}
84+
85+
86+
public int getMinimumWriteReservedDrives() {
87+
return this.minimumWriteReservedDrives;
88+
}
89+
90+
6391
public Quiesced getQuiesced() {
6492
return this.quiesced;
6593
}

0 commit comments

Comments
 (0)