Skip to content

Commit 00d97f2

Browse files
committed
Merge pull request #34 from rpmoore/master
Delete Logic Consolidation and Adding some Job API Calls
2 parents ed31b5e + 2d65b1b commit 00d97f2

25 files changed

+217
-291
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ apply plugin: 'maven'
2525
apply plugin: 'idea'
2626
apply plugin: 'application'
2727

28-
version = '1.1.1'
28+
version = '1.1.2'
2929
group = 'com.spectralogic'
3030

3131
mainClassName = 'com.spectralogic.ds3cli.Main'

src/main/java/com/spectralogic/ds3cli/CommandValue.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
public enum CommandValue {
2525
GET_SERVICE, GET_BUCKET, GET_OBJECT, PUT_BUCKET, PUT_OBJECT, DELETE_BUCKET, DELETE_OBJECT, GET_BULK, PUT_BULK,
26-
DELETE_TAPE_DRIVE, DELETE_TAPE_PARTITION;
26+
DELETE_TAPE_DRIVE, DELETE_TAPE_PARTITION, GET_JOBS, DELETE_JOB;
2727

2828
public static String valuesString() {
2929
final ArrayList<CommandValue> list = Lists.newArrayList(CommandValue.values());

src/main/java/com/spectralogic/ds3cli/Ds3Cli.java

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,43 +39,50 @@ public class Ds3Cli implements Callable<CommandResponse> {
3939
this.views = getViews();
4040
}
4141

42-
private Map<ViewType, Map<CommandValue, View>> getViews(){
42+
private Map<ViewType, Map<CommandValue, View>> getViews() {
4343
final Map<ViewType, Map<CommandValue, View>> allViews = new HashMap<>();
4444
allViews.put( ViewType.CLI, getCliViews() );
4545
allViews.put( ViewType.JSON, getJsonViews() );
4646
//TODO XML
4747
return allViews;
4848
}
4949

50-
private Map<CommandValue, View> getCliViews(){
50+
private Map<CommandValue, View> getCliViews() {
51+
final com.spectralogic.ds3cli.views.cli.DeleteView deleteView = new com.spectralogic.ds3cli.views.cli.DeleteView();
52+
5153
final Map<CommandValue, View> cliViews = new HashMap<>();
5254
cliViews.put(CommandValue.GET_SERVICE, new com.spectralogic.ds3cli.views.cli.GetServiceView() );
5355
cliViews.put(CommandValue.GET_BUCKET, new com.spectralogic.ds3cli.views.cli.GetBucketView() );
5456
cliViews.put(CommandValue.GET_OBJECT, new com.spectralogic.ds3cli.views.cli.GetObjectView() );
55-
cliViews.put(CommandValue.DELETE_BUCKET, new com.spectralogic.ds3cli.views.cli.DeleteBucketView() );
56-
cliViews.put(CommandValue.DELETE_OBJECT, new com.spectralogic.ds3cli.views.cli.DeleteObjectView() );
57+
cliViews.put(CommandValue.DELETE_BUCKET, deleteView);
58+
cliViews.put(CommandValue.DELETE_OBJECT, deleteView);
5759
cliViews.put(CommandValue.GET_BULK, new com.spectralogic.ds3cli.views.cli.GetBulkView() );
5860
cliViews.put(CommandValue.PUT_BUCKET, new com.spectralogic.ds3cli.views.cli.PutBucketView() );
5961
cliViews.put(CommandValue.PUT_BULK, new com.spectralogic.ds3cli.views.cli.PutBulkView() );
6062
cliViews.put(CommandValue.PUT_OBJECT, new com.spectralogic.ds3cli.views.cli.PutObjectView() );
61-
cliViews.put(CommandValue.DELETE_TAPE_PARTITION, new com.spectralogic.ds3cli.views.cli.DeleteTapePartitionView());
62-
cliViews.put(CommandValue.DELETE_TAPE_DRIVE, new com.spectralogic.ds3cli.views.cli.DeleteTapeDriveView());
63+
cliViews.put(CommandValue.DELETE_TAPE_PARTITION, deleteView);
64+
cliViews.put(CommandValue.DELETE_TAPE_DRIVE, deleteView);
65+
cliViews.put(CommandValue.GET_JOBS, new com.spectralogic.ds3cli.views.cli.GetJobsView());
66+
cliViews.put(CommandValue.DELETE_JOB, deleteView);
6367
return cliViews;
6468
}
6569

66-
private Map<CommandValue, View> getJsonViews(){
70+
private Map<CommandValue, View> getJsonViews() {
71+
final com.spectralogic.ds3cli.views.json.DeleteView deleteView = new com.spectralogic.ds3cli.views.json.DeleteView();
6772
final Map<CommandValue, View> jsonViews = new HashMap<>();
6873
jsonViews.put(CommandValue.GET_SERVICE, new com.spectralogic.ds3cli.views.json.GetServiceView() );
6974
jsonViews.put(CommandValue.GET_BUCKET, new com.spectralogic.ds3cli.views.json.GetBucketView() );
7075
jsonViews.put(CommandValue.GET_BULK, new com.spectralogic.ds3cli.views.json.GetBulkView() );
7176
jsonViews.put(CommandValue.GET_OBJECT, new com.spectralogic.ds3cli.views.json.GetObjectView() );
72-
jsonViews.put(CommandValue.DELETE_BUCKET, new com.spectralogic.ds3cli.views.json.DeleteBucketView() );
73-
jsonViews.put(CommandValue.DELETE_OBJECT, new com.spectralogic.ds3cli.views.json.DeleteObjectView() );
77+
jsonViews.put(CommandValue.DELETE_BUCKET, deleteView);
78+
jsonViews.put(CommandValue.DELETE_OBJECT, deleteView);
7479
jsonViews.put(CommandValue.PUT_BUCKET, new com.spectralogic.ds3cli.views.json.PutBucketView() );
7580
jsonViews.put(CommandValue.PUT_BULK, new com.spectralogic.ds3cli.views.json.PutBulkView() );
7681
jsonViews.put(CommandValue.PUT_OBJECT, new com.spectralogic.ds3cli.views.json.PutObjectView() );
77-
jsonViews.put(CommandValue.DELETE_TAPE_PARTITION, new com.spectralogic.ds3cli.views.json.DeleteTapePartitionView());
78-
jsonViews.put(CommandValue.DELETE_TAPE_DRIVE, new com.spectralogic.ds3cli.views.json.DeleteTapeDriveView());
82+
jsonViews.put(CommandValue.DELETE_TAPE_PARTITION, deleteView);
83+
jsonViews.put(CommandValue.DELETE_TAPE_DRIVE, deleteView);
84+
jsonViews.put(CommandValue.GET_JOBS, new com.spectralogic.ds3cli.views.json.GetJobsView());
85+
jsonViews.put(CommandValue.DELETE_JOB, deleteView);
7986
return jsonViews;
8087
}
8188

@@ -135,6 +142,12 @@ private CliCommand getCommandExecutor() {
135142
case DELETE_TAPE_PARTITION: {
136143
return new DeleteTapePartition(this.ds3Provider, this.fileUtils);
137144
}
145+
case GET_JOBS: {
146+
return new GetJobs(this.ds3Provider, this.fileUtils);
147+
}
148+
case DELETE_JOB: {
149+
return new DeleteJob(this.ds3Provider, this.fileUtils);
150+
}
138151
case GET_SERVICE:
139152
default: {
140153
return new GetService(this.ds3Provider, this.fileUtils);

src/main/java/com/spectralogic/ds3cli/command/DeleteBucket.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import com.spectralogic.ds3cli.Arguments;
1919
import com.spectralogic.ds3cli.CommandException;
2020
import com.spectralogic.ds3cli.logging.Logging;
21-
import com.spectralogic.ds3cli.models.DeleteBucketResult;
21+
import com.spectralogic.ds3cli.models.DeleteResult;
2222
import com.spectralogic.ds3cli.util.Ds3Provider;
2323
import com.spectralogic.ds3cli.util.FileUtils;
2424
import com.spectralogic.ds3client.Ds3Client;
@@ -32,7 +32,7 @@
3232
import java.io.IOException;
3333
import java.security.SignatureException;
3434

35-
public class DeleteBucket extends CliCommand<DeleteBucketResult> {
35+
public class DeleteBucket extends CliCommand<DeleteResult> {
3636

3737
private String bucketName;
3838
private boolean clearBucket;
@@ -51,13 +51,13 @@ public CliCommand init(final Arguments args) throws Exception {
5151
}
5252

5353
@Override
54-
public DeleteBucketResult call() throws Exception {
54+
public DeleteResult call() throws Exception {
5555

5656
if (clearBucket) {
57-
return new DeleteBucketResult( clearObjects() );
57+
return new DeleteResult( clearObjects() );
5858
}
5959
else {
60-
return new DeleteBucketResult( deleteBucket() );
60+
return new DeleteResult( deleteBucket() );
6161
}
6262
}
6363

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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+
package com.spectralogic.ds3cli.command;
16+
17+
import com.spectralogic.ds3cli.Arguments;
18+
import com.spectralogic.ds3cli.models.DeleteResult;
19+
import com.spectralogic.ds3cli.util.Ds3Provider;
20+
import com.spectralogic.ds3cli.util.FileUtils;
21+
import com.spectralogic.ds3client.commands.CancelJobRequest;
22+
import org.apache.commons.cli.MissingOptionException;
23+
24+
import java.util.UUID;
25+
26+
public class DeleteJob extends CliCommand<DeleteResult> {
27+
28+
private UUID id;
29+
30+
public DeleteJob(final Ds3Provider ds3Provider, final FileUtils fileUtils) {
31+
super(ds3Provider, fileUtils);
32+
}
33+
34+
@Override
35+
public CliCommand init(final Arguments args) throws Exception {
36+
if (args.getId() == null) {
37+
throw new MissingOptionException("The delete tape drive command requires '-i' to be set.");
38+
}
39+
this.id = UUID.fromString(args.getId());
40+
return this;
41+
}
42+
43+
@Override
44+
public DeleteResult call() throws Exception {
45+
getClient().cancelJob(new CancelJobRequest(id));
46+
return new DeleteResult("SUCCESS: Deleted job '"+ this.id.toString() +"'");
47+
}
48+
}

src/main/java/com/spectralogic/ds3cli/command/DeleteObject.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,15 @@
1717

1818
import com.spectralogic.ds3cli.Arguments;
1919
import com.spectralogic.ds3cli.CommandException;
20-
import com.spectralogic.ds3cli.models.DeleteObjectResult;
20+
import com.spectralogic.ds3cli.models.DeleteResult;
2121
import com.spectralogic.ds3cli.util.Ds3Provider;
2222
import com.spectralogic.ds3cli.util.FileUtils;
23-
import com.spectralogic.ds3client.Ds3Client;
2423
import com.spectralogic.ds3client.commands.DeleteObjectRequest;
2524
import org.apache.commons.cli.MissingOptionException;
2625

2726
import java.io.IOException;
2827

29-
public class DeleteObject extends CliCommand<DeleteObjectResult> {
28+
public class DeleteObject extends CliCommand<DeleteResult> {
3029

3130
private String bucketName;
3231
private String objectName;
@@ -49,14 +48,14 @@ public CliCommand init(final Arguments args) throws Exception {
4948
}
5049

5150
@Override
52-
public DeleteObjectResult call() throws Exception {
51+
public DeleteResult call() throws Exception {
5352
try {
5453
getClient().deleteObject(new DeleteObjectRequest(bucketName, objectName));
5554
}
5655
catch (final IOException e) {
5756
throw new CommandException("Error: Request failed with the following error: " + e.getMessage(), e);
5857
}
5958

60-
return new DeleteObjectResult("Success: Deleted object '" + this.objectName + "' from bucket '" + this.bucketName + "'.");
59+
return new DeleteResult("Success: Deleted object '" + this.objectName + "' from bucket '" + this.bucketName + "'.");
6160
}
6261
}

src/main/java/com/spectralogic/ds3cli/command/DeleteTapeDrive.java

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

1818
import com.spectralogic.ds3cli.Arguments;
1919
import com.spectralogic.ds3cli.CommandException;
20-
import com.spectralogic.ds3cli.models.DeleteTapeDriveResult;
20+
import com.spectralogic.ds3cli.models.DeleteResult;
2121
import com.spectralogic.ds3cli.util.Ds3Provider;
2222
import com.spectralogic.ds3cli.util.FileUtils;
2323
import com.spectralogic.ds3client.commands.DeleteTapeDriveRequest;
2424
import org.apache.commons.cli.MissingOptionException;
2525

2626
import java.io.IOException;
2727

28-
public class DeleteTapeDrive extends CliCommand<DeleteTapeDriveResult> {
28+
public class DeleteTapeDrive extends CliCommand<DeleteResult> {
2929

3030
private String id;
3131

@@ -43,14 +43,14 @@ public CliCommand init(final Arguments args) throws Exception {
4343
}
4444

4545
@Override
46-
public DeleteTapeDriveResult call() throws Exception {
46+
public DeleteResult call() throws Exception {
4747
try {
4848
getClient().deleteTapeDrive(new DeleteTapeDriveRequest(this.id));
4949
}
5050
catch (final IOException e) {
5151
throw new CommandException("Error: Request failed with the following error: " + e.getMessage(), e);
5252
}
5353

54-
return new DeleteTapeDriveResult("Success: Deleted tape drive '" + this.id+ "'.");
54+
return new DeleteResult("Success: Deleted tape drive '" + this.id+ "'.");
5555
}
5656
}

src/main/java/com/spectralogic/ds3cli/command/DeleteTapePartition.java

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

1818
import com.spectralogic.ds3cli.Arguments;
1919
import com.spectralogic.ds3cli.CommandException;
20-
import com.spectralogic.ds3cli.models.DeleteTapePartitionResult;
20+
import com.spectralogic.ds3cli.models.DeleteResult;
2121
import com.spectralogic.ds3cli.util.Ds3Provider;
2222
import com.spectralogic.ds3cli.util.FileUtils;
2323
import com.spectralogic.ds3client.commands.DeleteTapePartitionRequest;
2424
import org.apache.commons.cli.MissingOptionException;
2525

2626
import java.io.IOException;
2727

28-
public class DeleteTapePartition extends CliCommand<DeleteTapePartitionResult> {
28+
public class DeleteTapePartition extends CliCommand<DeleteResult> {
2929

3030
private String id;
3131

@@ -43,14 +43,14 @@ public CliCommand init(final Arguments args) throws Exception {
4343
}
4444

4545
@Override
46-
public DeleteTapePartitionResult call() throws Exception {
46+
public DeleteResult call() throws Exception {
4747
try {
4848
getClient().deleteTapePartition(new DeleteTapePartitionRequest(this.id));
4949
}
5050
catch (final IOException e) {
5151
throw new CommandException("Error: Request failed with the following error: " + e.getMessage(), e);
5252
}
5353

54-
return new DeleteTapePartitionResult("Success: Deleted tape partition '" + this.id+ "'.");
54+
return new DeleteResult("Success: Deleted tape partition '" + this.id+ "'.");
5555
}
5656
}

src/main/java/com/spectralogic/ds3cli/command/GetBucket.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,18 @@
3131

3232
public class GetBucket extends CliCommand<GetBucketResult> {
3333
private String bucketName;
34+
private String prefix;
3435
public GetBucket(final Ds3Provider provider, final FileUtils fileUtils) {
3536
super(provider, fileUtils);
3637
}
3738

3839
@Override
3940
public CliCommand init(final Arguments args) throws Exception {
40-
bucketName = args.getBucket();
41+
this.bucketName = args.getBucket();
4142
if (bucketName == null) {
4243
throw new MissingOptionException("The get bucket command requires '-b' to be set.");
4344
}
45+
this.prefix = args.getPrefix();
4446
return this;
4547
}
4648

@@ -50,7 +52,15 @@ public GetBucketResult call() throws Exception {
5052
try {
5153
final Ds3ClientHelpers helper = Ds3ClientHelpers.wrap(getClient());
5254

53-
final Iterable<Contents> objects = helper.listObjects(bucketName);
55+
final Iterable<Contents> objects;
56+
57+
if (this.prefix == null) {
58+
objects = helper.listObjects(bucketName);
59+
}
60+
else {
61+
objects = helper.listObjects(bucketName, this.prefix);
62+
}
63+
5464
final Iterator<Contents> objIterator = objects.iterator();
5565

5666
return new GetBucketResult( bucketName, objIterator);

src/main/java/com/spectralogic/ds3cli/views/json/DeleteBucketView.java renamed to src/main/java/com/spectralogic/ds3cli/command/GetJobs.java

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

16-
package com.spectralogic.ds3cli.views.json;
16+
package com.spectralogic.ds3cli.command;
1717

18-
import com.fasterxml.jackson.core.JsonProcessingException;
19-
import com.fasterxml.jackson.databind.ObjectMapper;
20-
import com.spectralogic.ds3cli.View;
21-
import com.spectralogic.ds3cli.models.DeleteBucketResult;
22-
import com.spectralogic.ds3cli.util.JsonMapper;
18+
import com.spectralogic.ds3cli.Arguments;
19+
import com.spectralogic.ds3cli.models.GetJobsResult;
20+
import com.spectralogic.ds3cli.util.Ds3Provider;
21+
import com.spectralogic.ds3cli.util.FileUtils;
22+
import com.spectralogic.ds3client.commands.GetJobsRequest;
23+
24+
public class GetJobs extends CliCommand<GetJobsResult> {
25+
public GetJobs(final Ds3Provider ds3Provider, final FileUtils fileUtils) {
26+
super(ds3Provider, fileUtils);
27+
}
28+
29+
@Override
30+
public CliCommand init(final Arguments args) throws Exception {
31+
return this;
32+
}
2333

24-
public class DeleteBucketView implements View<DeleteBucketResult> {
2534
@Override
26-
public String render(final DeleteBucketResult result) throws JsonProcessingException {
27-
final CommonJsonView view = CommonJsonView.newView(CommonJsonView.Status.OK);
28-
return JsonMapper.toJson(view.message(result.getResult()));
35+
public GetJobsResult call() throws Exception {
36+
return new GetJobsResult(getClient().getJobs(new GetJobsRequest()).getJobs());
2937
}
3038
}

0 commit comments

Comments
 (0)