Skip to content

Commit 1fcfbe0

Browse files
author
Hans-Peter Klett
committed
Fixed bulk pluralization and helpers for semantics
* Fixed /_rest_/buckets to be /_rest_bucket. * Updated the helpers for the new semantic changes.
1 parent 4b5c367 commit 1fcfbe0

File tree

8 files changed

+105
-48
lines changed

8 files changed

+105
-48
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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.helpers;
17+
18+
import com.spectralogic.ds3client.Ds3Client;
19+
20+
interface Ds3ClientFactory {
21+
Ds3Client GetClientForServerId(String serverId);
22+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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.helpers;
17+
18+
import com.spectralogic.ds3client.Ds3Client;
19+
20+
public class Ds3ClientFactoryImpl implements Ds3ClientFactory {
21+
private final Ds3Client client;
22+
23+
public Ds3ClientFactoryImpl(final Ds3Client client) {
24+
this.client = client;
25+
}
26+
27+
@Override
28+
public Ds3Client GetClientForServerId(final String serverId) {
29+
return this.client;
30+
}
31+
}

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

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public Ds3ClientHelpers.WriteJob startWriteJob(final String bucket, final Iterab
4848
throws SignatureException, IOException, XmlProcessingException {
4949
try(final BulkPutResponse prime = this.client.bulkPut(new BulkPutRequest(bucket, Lists.newArrayList(objectsToWrite)))) {
5050
final MasterObjectList result = prime.getResult();
51-
return new WriteJobImpl(this.client, result.getJobId(), bucket, result.getObjects());
51+
return new WriteJobImpl(new Ds3ClientFactoryImpl(this.client), result.getJobId(), bucket, result.getObjects());
5252
}
5353
}
5454

@@ -57,7 +57,7 @@ public Ds3ClientHelpers.ReadJob startReadJob(final String bucket, final Iterable
5757
throws SignatureException, IOException, XmlProcessingException {
5858
try(final BulkGetResponse prime = this.client.bulkGet(new BulkGetRequest(bucket, Lists.newArrayList(objectsToRead)))) {
5959
final MasterObjectList result = prime.getResult();
60-
return new ReadJobImpl(this.client, result.getJobId(), bucket, result.getObjects());
60+
return new ReadJobImpl(new Ds3ClientFactoryImpl(this.client), result.getJobId(), bucket, result.getObjects());
6161
}
6262
}
6363

@@ -79,7 +79,12 @@ public WriteJob recoverWriteJob(final UUID jobId) throws SignatureException, IOE
7979
try (final GetJobResponse job = this.client.getJob(new GetJobRequest(jobId))) {
8080
final JobInfo jobInfo = job.getJobInfo();
8181
checkJobType(JOB_TYPE_PUT, jobInfo.getRequestType());
82-
return new WriteJobImpl(this.client, jobInfo.getJobId(), jobInfo.getBucketName(), job.getObjectsList());
82+
return new WriteJobImpl(
83+
new Ds3ClientFactoryImpl(this.client),
84+
jobInfo.getJobId(),
85+
jobInfo.getBucketName(),
86+
job.getObjectsList()
87+
);
8388
}
8489
}
8590

@@ -88,7 +93,12 @@ public ReadJob recoverReadJob(final UUID jobId) throws SignatureException, IOExc
8893
try (final GetJobResponse job = this.client.getJob(new GetJobRequest(jobId))) {
8994
final JobInfo jobInfo = job.getJobInfo();
9095
checkJobType(JOB_TYPE_GET, jobInfo.getRequestType());
91-
return new ReadJobImpl(this.client, jobInfo.getJobId(), jobInfo.getBucketName(), convertFromJobObjectsList(job.getObjectsList()));
96+
return new ReadJobImpl(
97+
new Ds3ClientFactoryImpl(this.client),
98+
jobInfo.getJobId(),
99+
jobInfo.getBucketName(),
100+
convertFromJobObjectsList(job.getObjectsList())
101+
);
92102
}
93103
}
94104

src/main/java/com/spectralogic/ds3client/helpers/JobImpl.java

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,17 @@
3737
abstract class JobImpl implements Job {
3838
private static final int THREAD_COUNT = 10;
3939

40-
private final Ds3Client client;
40+
private final Ds3ClientFactory clientFactory;
4141
private final UUID jobId;
4242
private final String bucketName;
4343
private final Iterable<? extends Objects> objectLists;
4444

45-
//TODO: client factory
4645
public JobImpl(
47-
final Ds3Client client,
46+
final Ds3ClientFactory clientFactory,
4847
final UUID jobId,
4948
final String bucketName,
5049
final Iterable<? extends Objects> objectLists) {
51-
this.client = client;
50+
this.clientFactory = clientFactory;
5251
this.jobId = jobId;
5352
this.bucketName = bucketName;
5453
this.objectLists = objectLists;
@@ -71,34 +70,38 @@ public void Transfer(Ds3Client client, UUID jobId, String bucketName, Ds3Object
7170

7271
protected void transferAll(final Transferrer transferrer)
7372
throws SignatureException, IOException, XmlProcessingException {
73+
for (final Objects objects : this.objectLists) {
74+
this.transferObjects(transferrer, objects);
75+
}
76+
}
77+
78+
private void transferObjects(final Transferrer transferrer, final Objects objects)
79+
throws SignatureException, IOException, XmlProcessingException {
7480
final ListeningExecutorService service = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(THREAD_COUNT));
7581
try {
76-
final List<ListenableFuture<?>> tasks = new ArrayList<ListenableFuture<?>>();
77-
for (final Objects objects : this.objectLists) {
78-
tasks.add(service.submit(this.createObjectListTask(transferrer, objects)));
82+
final Ds3Client client = this.clientFactory.GetClientForServerId(objects.getServerId());
83+
final List<ListenableFuture<?>> tasks = new ArrayList<>();
84+
for (final Ds3Object ds3Object : objects) {
85+
tasks.add(this.createTransferTask(transferrer, service, client, ds3Object));
7986
}
8087
this.executeWithExceptionHandling(tasks);
8188
} finally {
8289
service.shutdown();
8390
}
8491
}
8592

86-
private Callable<?> createObjectListTask(final Transferrer transferrer, final Objects objects) {
87-
return new Callable<Object>() {
93+
private ListenableFuture<?> createTransferTask(
94+
final Transferrer transferrer,
95+
final ListeningExecutorService service,
96+
final Ds3Client client,
97+
final Ds3Object ds3Object) {
98+
return service.submit(new Callable<Object>() {
8899
@Override
89100
public Object call() throws Exception {
90-
final Ds3Client client = JobImpl.this.getClient(objects.getServerId());
91-
for (final Ds3Object ds3Object : objects) {
92-
transferrer.Transfer(client, JobImpl.this.jobId, JobImpl.this.bucketName, ds3Object);
93-
}
101+
transferrer.Transfer(client, JobImpl.this.jobId, JobImpl.this.bucketName, ds3Object);
94102
return null;
95103
}
96-
};
97-
}
98-
99-
//TODO: this needs to come from a Ds3Client factory that knows how to update the server id.
100-
private Ds3Client getClient(final String serverId) {
101-
return this.client;
104+
});
102105
}
103106

104107
private void executeWithExceptionHandling(final List<ListenableFuture<?>> tasks)

src/main/java/com/spectralogic/ds3client/helpers/ReadJobImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ class ReadJobImpl extends JobImpl implements ReadJob {
3333
private GetRequestModifier modifier;
3434

3535
public ReadJobImpl(
36-
final Ds3Client client,
36+
final Ds3ClientFactory clientFactory,
3737
final UUID jobId,
3838
final String bucketName,
3939
final Iterable<? extends Objects> objectLists) {
40-
super(client, jobId, bucketName, objectLists);
40+
super(clientFactory, jobId, bucketName, objectLists);
4141
}
4242

4343
@Override

src/main/java/com/spectralogic/ds3client/helpers/WriteJobImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ class WriteJobImpl extends JobImpl implements WriteJob {
3232
private PutRequestModifier modifier;
3333

3434
public WriteJobImpl(
35-
final Ds3Client client,
35+
final Ds3ClientFactory clientFactory,
3636
final UUID jobId,
3737
final String bucketName,
3838
final Iterable<? extends Objects> objectLists) {
39-
super(client, jobId, bucketName, objectLists);
39+
super(clientFactory, jobId, bucketName, objectLists);
4040
}
4141

4242
@Override

src/test/java/com/spectralogic/ds3client/Ds3Client_Test.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ public void runBulkTest(final BulkCommand command, final BulkTestDriver driver)
272272
queryParams.put("operation", command.toString());
273273

274274
final Ds3Client client = MockNetwork
275-
.expecting(HttpVerb.PUT, "/_rest_/buckets/bulkTest", queryParams, expectedXmlBody)
275+
.expecting(HttpVerb.PUT, "/_rest_/bucket/bulkTest", queryParams, expectedXmlBody)
276276
.returning(200, xmlResponse)
277277
.asClient();
278278

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

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import java.io.*;
2525
import java.security.SignatureException;
2626
import java.util.ArrayList;
27+
import java.util.Arrays;
2728
import java.util.List;
2829
import java.util.UUID;
2930

@@ -339,29 +340,19 @@ public MasterObjectList getResult() {
339340
private static MasterObjectList buildMasterObjectList() {
340341
final MasterObjectList masterObjectList = new MasterObjectList();
341342
masterObjectList.setJobId(jobId);
342-
masterObjectList.setObjects(makeObjectLists());
343+
masterObjectList.setObjects(Arrays.asList(
344+
makeObjects("192.168.56.100", Arrays.asList(new Ds3Object("baz", 12))),
345+
makeObjects("192.168.56.100", Arrays.asList(new Ds3Object("foo", 12))),
346+
makeObjects("192.168.56.101", Arrays.asList(new Ds3Object("bar", 12)))
347+
));
343348
return masterObjectList;
344349
}
345350

346-
private static List<Objects> makeObjectLists() {
347-
final List<Objects> objectLists = new ArrayList<>();
348-
objectLists.add(makeObjects1());
349-
return objectLists;
350-
}
351-
352-
private static Objects makeObjects1() {
353-
final Objects objects1 = new Objects();
354-
objects1.setServerId("192.168.56.100");
355-
objects1.setObject(makeObjectList1());
356-
return objects1;
357-
}
358-
359-
private static ArrayList<Ds3Object> makeObjectList1() {
360-
final ArrayList<Ds3Object> objectList1 = new ArrayList<>();
361-
objectList1.add(new Ds3Object("baz", 12));
362-
objectList1.add(new Ds3Object("foo", 12));
363-
objectList1.add(new Ds3Object("bar", 12));
364-
return objectList1;
351+
private static Objects makeObjects(final String serverId, final List<Ds3Object> objectList) {
352+
final Objects objects = new Objects();
353+
objects.setServerId(serverId);
354+
objects.setObject(objectList);
355+
return objects;
365356
}
366357

367358
private static final class StubException extends RuntimeException {

0 commit comments

Comments
 (0)