From f6c492295d044cf96a20856020929bd89ea18ba9 Mon Sep 17 00:00:00 2001 From: Ryan Moore Date: Tue, 22 Sep 2015 17:20:49 -0600 Subject: [PATCH] Initial delete tape implementation --- .../com/spectralogic/ds3client/Ds3Client.java | 3 ++ .../spectralogic/ds3client/Ds3ClientImpl.java | 5 ++ .../ds3client/commands/DeleteTapeRequest.java | 28 ++++++++++ .../commands/DeleteTapeResponse.java | 20 +++++++ .../ds3client/Ds3Client_Test.java | 52 ++++++++++++------- 5 files changed, 89 insertions(+), 19 deletions(-) create mode 100644 ds3-sdk/src/main/java/com/spectralogic/ds3client/commands/DeleteTapeRequest.java create mode 100644 ds3-sdk/src/main/java/com/spectralogic/ds3client/commands/DeleteTapeResponse.java diff --git a/ds3-sdk/src/main/java/com/spectralogic/ds3client/Ds3Client.java b/ds3-sdk/src/main/java/com/spectralogic/ds3client/Ds3Client.java index 2de68abc6..84ad82b09 100644 --- a/ds3-sdk/src/main/java/com/spectralogic/ds3client/Ds3Client.java +++ b/ds3-sdk/src/main/java/com/spectralogic/ds3client/Ds3Client.java @@ -286,6 +286,9 @@ DeleteTapePartitionResponse deleteTapePartition(DeleteTapePartitionRequest reque GetTapesResponse getTapes(GetTapesRequest request) throws IOException, SignatureException; + DeleteTapeResponse deleteTape(DeleteTapeRequest request) + throws IOException, SignatureException; + NotificationResponse createObjectCachedNotification(CreateObjectCachedNotificationRequest request) throws IOException, SignatureException; diff --git a/ds3-sdk/src/main/java/com/spectralogic/ds3client/Ds3ClientImpl.java b/ds3-sdk/src/main/java/com/spectralogic/ds3client/Ds3ClientImpl.java index acf24dc55..6c9020351 100644 --- a/ds3-sdk/src/main/java/com/spectralogic/ds3client/Ds3ClientImpl.java +++ b/ds3-sdk/src/main/java/com/spectralogic/ds3client/Ds3ClientImpl.java @@ -160,6 +160,11 @@ public GetTapesResponse getTapes(final GetTapesRequest request) throws IOExcepti return new GetTapesResponse(this.netClient.getResponse(request)); } + @Override + public DeleteTapeResponse deleteTape(final DeleteTapeRequest request) throws IOException, SignatureException { + return new DeleteTapeResponse(this.netClient.getResponse(request)); + } + @Override public NotificationResponse createObjectCachedNotification(final CreateObjectCachedNotificationRequest request) throws IOException, SignatureException { return new NotificationResponse(this.netClient.getResponse(request)); diff --git a/ds3-sdk/src/main/java/com/spectralogic/ds3client/commands/DeleteTapeRequest.java b/ds3-sdk/src/main/java/com/spectralogic/ds3client/commands/DeleteTapeRequest.java new file mode 100644 index 000000000..904f44275 --- /dev/null +++ b/ds3-sdk/src/main/java/com/spectralogic/ds3client/commands/DeleteTapeRequest.java @@ -0,0 +1,28 @@ +package com.spectralogic.ds3client.commands; + +import com.spectralogic.ds3client.HttpVerb; + +import java.util.UUID; + +public class DeleteTapeRequest extends AbstractRequest { + + private final UUID id; + + public DeleteTapeRequest(final UUID id) { + this.id = id; + } + + @Override + public String getPath() { + return "/_rest_/tape/" + id.toString(); + } + + @Override + public HttpVerb getVerb() { + return HttpVerb.DELETE; + } + + public UUID getId() { + return id; + } +} diff --git a/ds3-sdk/src/main/java/com/spectralogic/ds3client/commands/DeleteTapeResponse.java b/ds3-sdk/src/main/java/com/spectralogic/ds3client/commands/DeleteTapeResponse.java new file mode 100644 index 000000000..8c54e0001 --- /dev/null +++ b/ds3-sdk/src/main/java/com/spectralogic/ds3client/commands/DeleteTapeResponse.java @@ -0,0 +1,20 @@ +package com.spectralogic.ds3client.commands; + +import com.spectralogic.ds3client.networking.WebResponse; + +import java.io.IOException; + +public class DeleteTapeResponse extends AbstractResponse { + public DeleteTapeResponse(final WebResponse response) throws IOException { + super(response); + } + + @Override + protected void processResponse() throws IOException { + try { + checkStatusCode(204); + } finally { + getResponse().close(); + } + } +} diff --git a/ds3-sdk/src/test/java/com/spectralogic/ds3client/Ds3Client_Test.java b/ds3-sdk/src/test/java/com/spectralogic/ds3client/Ds3Client_Test.java index 89d2dc823..9868403ac 100644 --- a/ds3-sdk/src/test/java/com/spectralogic/ds3client/Ds3Client_Test.java +++ b/ds3-sdk/src/test/java/com/spectralogic/ds3client/Ds3Client_Test.java @@ -130,28 +130,28 @@ public void getBucket() throws IOException, SignatureException { assertThat(contentsList, is(notNullValue())); assertThat(contentsList.size(), is(3)); this.assertContentsEquals( - contentsList.get(0), - "user/hduser/gutenberg/20417.txt.utf-8", - "2014-01-03T13:26:47.000Z", - "8B19F3F41868106382A677C3435BDCE5", - 674570, - "STANDARD" + contentsList.get(0), + "user/hduser/gutenberg/20417.txt.utf-8", + "2014-01-03T13:26:47.000Z", + "8B19F3F41868106382A677C3435BDCE5", + 674570, + "STANDARD" ); this.assertContentsEquals( - contentsList.get(1), - "user/hduser/gutenberg/5000.txt.utf-8", - "2014-01-03T13:26:47.000Z", - "9DE344878423E44B129730CE22B4B137", - 1423803, - "STANDARD" + contentsList.get(1), + "user/hduser/gutenberg/5000.txt.utf-8", + "2014-01-03T13:26:47.000Z", + "9DE344878423E44B129730CE22B4B137", + 1423803, + "STANDARD" ); this.assertContentsEquals( - contentsList.get(2), - "user/hduser/gutenberg/4300.txt.utf-8", - "2014-01-03T13:26:47.000Z", - "33EE4519EA7DDAB27CA4E2742326D70B", - 1573150, - "DEEP" + contentsList.get(2), + "user/hduser/gutenberg/4300.txt.utf-8", + "2014-01-03T13:26:47.000Z", + "33EE4519EA7DDAB27CA4E2742326D70B", + 1573150, + "DEEP" ); } @@ -235,7 +235,7 @@ public void deleteFolder() throws IOException, SignatureException { .expecting(HttpVerb.DELETE, "/_rest_/folder/folderName", queryParams, null) .returning(204, "") .asClient() - .deleteFolder(new DeleteFolderRequest("bucketName","folderName")); + .deleteFolder(new DeleteFolderRequest("bucketName", "folderName")); } @Test @@ -890,4 +890,18 @@ public void getTapes() throws IOException, SignatureException { assertThat(tapes.size(), is(not(0))); assertThat(tapes.get(0).getId(), is(notNullValue())); } + + @Test + public void deleteTape() throws IOException, SignatureException { + + final UUID id = UUID.randomUUID(); + + final DeleteTapeResponse response = MockNetwork + .expecting(HttpVerb.DELETE, "/_rest_/tape/" + id.toString(), null, null) + .returning(204, "") + .asClient() + .deleteTape(new DeleteTapeRequest(id)); + + assertThat(response, is(notNullValue())); + } }