1616package com .spectralogic .ds3client ;
1717
1818import java .io .IOException ;
19- import java .net .URI ;
20- import java .net .URISyntaxException ;
2119import java .security .SignatureException ;
2220
2321import com .spectralogic .ds3client .commands .*;
24- import com .spectralogic .ds3client .models .Credentials ;
25- import com .spectralogic .ds3client .networking .NetworkClient ;
2622
2723/**
28- * The main class for communicating with a DS3 appliance. All communication with a DS3 appliance should start with
24+ * The main interface for communicating with a DS3 appliance. All communication with a DS3 appliance should start with
2925 * this class.
3026 *
31- * Here is an example showing how the Ds3Client class is used to get a list of buckets from a remote DS3 appliance.
27+ * Here is an example showing how the Ds3Client interface is used to get a list of buckets from a remote DS3 appliance.
3228 *
3329 * <pre>
3430 * {@code
35- * final Ds3Client client = Ds3Client.builder ("ds3Endpoint:8080",
31+ * final Ds3Client client = Ds3ClientBuilder.create ("ds3Endpoint:8080",
3632 * new Credentials("accessKey", "secretKey")).build();
3733 *
3834 * final GetServiceResponse response = client.getService(new GetServiceRequest());
4339 * }
4440 * </pre>
4541 */
46- public class Ds3Client {
47-
48- /**
49- * A Builder class used to create a Ds3Client instance.
50- */
51- public static class Builder implements com .spectralogic .ds3client .utils .Builder <Ds3Client > {
52-
53- final private String endpoint ;
54- final private Credentials credentials ;
55-
56- private boolean secure = true ;
57- private URI proxy = null ;
58- private int retries = 5 ;
59-
60- private Builder (final String endpoint , final Credentials credentials ) throws IllegalArgumentException {
61- if (endpoint == null || endpoint .isEmpty ()) {
62- throw new IllegalArgumentException ("Endpoint must be non empty" );
63- }
64- if (credentials == null || !credentials .isValid ()) {
65- throw new IllegalArgumentException ("Credentials must be filled out." );
66- }
67- this .endpoint = endpoint ;
68- this .credentials = credentials ;
69- }
70-
71- /**
72- * Specifies if the library should use HTTP or HTTPS. The default is HTTP.
73- * @param secure True will use HTTPS, false will use HTTP.
74- * @return The current builder.
75- */
76- public Builder withHttpSecure (final boolean secure ) {
77- this .secure = secure ;
78- return this ;
79- }
80-
81- /**
82- * Sets a HTTP proxy.
83- * @param proxy The endpoint of the HTTP proxy.
84- * @return The current builder.
85- * @throws IllegalArgumentException This will be thrown if the proxy endpoint is not a valid URI.
86- */
87- public Builder withProxy (final String proxy ) throws IllegalArgumentException {
88- try {
89- final URI proxyUri ;
90- if (!proxy .startsWith ("http" )) {
91- throw new IllegalArgumentException ("Invalid proxy format. The web address must start with either http or https." );
92- }
93- proxyUri = new URI (proxy );
94-
95- this .proxy = proxyUri ;
96- } catch (final URISyntaxException e ) {
97- throw new IllegalArgumentException ("Invalid proxy format. Must be a web address." );
98- }
99-
100- return this ;
101- }
102-
103- /**
104- * Sets the number of retries the library will attempt to perform when it receives 307 redirects from a
105- * DS3 appliance. The default is 5.
106- * @param retries The number of times the library should perform retries on 307.
107- * @return The current builder.
108- */
109- public Builder withRedirectRetries (final int retries ) {
110- this .retries = retries ;
111- return this ;
112- }
113-
114- /**
115- * Returns a new Ds3Client instance.
116- */
117- @ Override
118- public Ds3Client build () {
119- final ConnectionDetailsImpl .Builder connBuilder = ConnectionDetailsImpl .builder (endpoint , credentials )
120- .withProxy (proxy ).withSecure (secure ).withRedirectRetries (retries );
121-
122- final NetworkClient netClient = new NetworkClientImpl (connBuilder .build ());
123- return new Ds3Client (netClient );
124- }
125- }
126-
127- /**
128- * Returns a Builder which is used to customize the behavior of the Ds3Client library.
129- * @param endpoint The DS3 endpoint the library should connect to.
130- * @param creds The {@link Credentials} used for connecting to a DS3 endpoint.
131- * @return The Builder for the {@link Ds3Client} object.
132- */
133- public static Builder builder (final String endpoint , final Credentials creds ) {
134- return new Builder (endpoint , creds );
135- }
136-
137- private final NetworkClient netClient ;
138-
139- Ds3Client (final NetworkClient netClient ) {
140- this .netClient = netClient ;
141- }
142-
143- NetworkClient getNetClient () {
144- return netClient ;
145- }
42+ public interface Ds3Client {
14643
14744 /**
14845 * Gets the list of buckets.
@@ -151,9 +48,8 @@ NetworkClient getNetClient() {
15148 * @throws IOException
15249 * @throws SignatureException
15350 */
154- public GetServiceResponse getService (final GetServiceRequest request ) throws IOException , SignatureException {
155- return new GetServiceResponse (netClient .getResponse (request ));
156- }
51+ public abstract GetServiceResponse getService (GetServiceRequest request )
52+ throws IOException , SignatureException ;
15753
15854 /**
15955 * Gets the list of objects in a bucket.
@@ -167,9 +63,8 @@ public GetServiceResponse getService(final GetServiceRequest request) throws IOE
16763 * @throws IOException
16864 * @throws SignatureException
16965 */
170- public GetBucketResponse getBucket (final GetBucketRequest request ) throws IOException , SignatureException {
171- return new GetBucketResponse (netClient .getResponse (request ));
172- }
66+ public abstract GetBucketResponse getBucket (GetBucketRequest request )
67+ throws IOException , SignatureException ;
17368
17469 /**
17570 * Puts a new bucket to a DS3 endpoint
@@ -182,9 +77,8 @@ public GetBucketResponse getBucket(final GetBucketRequest request) throws IOExce
18277 * @throws IOException
18378 * @throws SignatureException
18479 */
185- public PutBucketResponse putBucket (final PutBucketRequest request ) throws IOException , SignatureException {
186- return new PutBucketResponse (netClient .getResponse (request ));
187- }
80+ public abstract PutBucketResponse putBucket (PutBucketRequest request )
81+ throws IOException , SignatureException ;
18882
18983 /**
19084 * Performs a HTTP HEAD for a bucket. The HEAD will return information about if the bucket exists, or if the user
@@ -195,9 +89,8 @@ public PutBucketResponse putBucket(final PutBucketRequest request) throws IOExce
19589 * @throws IOException
19690 * @throws SignatureException
19791 */
198- public HeadBucketResponse headBucket (final HeadBucketRequest request ) throws IOException , SignatureException {
199- return new HeadBucketResponse (netClient .getResponse (request ));
200- }
92+ public abstract HeadBucketResponse headBucket (HeadBucketRequest request )
93+ throws IOException , SignatureException ;
20194
20295 /**
20396 * Deletes a bucket from a DS3 endpoint. <b>Note:</b> all objects must be deleted first before deleteBucket will
@@ -211,9 +104,8 @@ public HeadBucketResponse headBucket(final HeadBucketRequest request) throws IOE
211104 * @throws IOException
212105 * @throws SignatureException
213106 */
214- public DeleteBucketResponse deleteBucket (final DeleteBucketRequest request ) throws IOException , SignatureException {
215- return new DeleteBucketResponse (netClient .getResponse (request ));
216- }
107+ public abstract DeleteBucketResponse deleteBucket (
108+ DeleteBucketRequest request ) throws IOException , SignatureException ;
217109
218110 /**
219111 * Deletes an object in a bucket from a DS3 endpoint
@@ -226,9 +118,8 @@ public DeleteBucketResponse deleteBucket(final DeleteBucketRequest request) thro
226118 * @throws IOException
227119 * @throws SignatureException
228120 */
229- public DeleteObjectResponse deleteObject (final DeleteObjectRequest request ) throws IOException , SignatureException {
230- return new DeleteObjectResponse (netClient .getResponse (request ));
231- }
121+ public abstract DeleteObjectResponse deleteObject (
122+ DeleteObjectRequest request ) throws IOException , SignatureException ;
232123
233124 /**
234125 * Get an object in a bucket from a DS3 endpoint
@@ -240,9 +131,8 @@ public DeleteObjectResponse deleteObject(final DeleteObjectRequest request) thro
240131 * @throws IOException
241132 * @throws SignatureException
242133 */
243- public GetObjectResponse getObject (final GetObjectRequest request ) throws IOException , SignatureException {
244- return new GetObjectResponse (netClient .getResponse (request ));
245- }
134+ public abstract GetObjectResponse getObject (GetObjectRequest request )
135+ throws IOException , SignatureException ;
246136
247137 /**
248138 * Puts a new object to an existing bucket to a DS3 endpoint
@@ -255,9 +145,8 @@ public GetObjectResponse getObject(final GetObjectRequest request) throws IOExce
255145 * @throws IOException
256146 * @throws SignatureException
257147 */
258- public PutObjectResponse putObject (final PutObjectRequest request ) throws IOException , SignatureException {
259- return new PutObjectResponse (netClient .getResponse (request ));
260- }
148+ public abstract PutObjectResponse putObject (PutObjectRequest request )
149+ throws IOException , SignatureException ;
261150
262151 /**
263152 * Primes the Ds3 appliance for a Bulk Get. This does not perform the gets for each individual files. See
@@ -270,9 +159,8 @@ public PutObjectResponse putObject(final PutObjectRequest request) throws IOExce
270159 * @throws IOException
271160 * @throws SignatureException
272161 */
273- public BulkGetResponse bulkGet (final BulkGetRequest request ) throws IOException , SignatureException {
274- return new BulkGetResponse (netClient .getResponse (request ));
275- }
162+ public abstract BulkGetResponse bulkGet (BulkGetRequest request )
163+ throws IOException , SignatureException ;
276164
277165 /**
278166 * Primes the Ds3 appliance for a Bulk Put. This does not perform the puts for each individual files. See
@@ -285,8 +173,23 @@ public BulkGetResponse bulkGet(final BulkGetRequest request) throws IOException,
285173 * @throws IOException
286174 * @throws SignatureException
287175 */
288- public BulkPutResponse bulkPut (final BulkPutRequest request ) throws IOException , SignatureException {
289- return new BulkPutResponse (netClient .getResponse (request ));
290- }
291- }
176+ public abstract BulkPutResponse bulkPut (BulkPutRequest request )
177+ throws IOException , SignatureException ;
292178
179+ /**
180+ * Queries the list of active jobs on the server.
181+ * @throws IOException
182+ * @throws SignatureException
183+ */
184+ public abstract GetJobListResponse getJobList (GetJobListRequest request )
185+ throws IOException , SignatureException ;
186+
187+ /**
188+ * Queries the job details for a given job id. Includes the objects that are in cache or haven't been transferred.
189+ * @throws IOException
190+ * @throws SignatureException
191+ */
192+ public abstract GetJobResponse getJob (GetJobRequest request )
193+ throws IOException , SignatureException ;
194+
195+ }
0 commit comments