Skip to content

Commit 8dc3782

Browse files
committed
Adding the API calls to get Tape Library information.
1 parent da21654 commit 8dc3782

File tree

9 files changed

+311
-0
lines changed

9 files changed

+311
-0
lines changed

ds3-sdk/src/main/java/com/spectralogic/ds3client/Ds3Client.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,11 @@ GetSystemHealthResponse getSystemHealth(GetSystemHealthRequest request)
303303
GetSystemInformationResponse getSystemInformation(GetSystemInformationRequest request)
304304
throws IOException, SignatureException;
305305

306+
GetTapeLibrariesResponse getTapeLibraries(GetTapeLibrariesRequest request)
307+
throws IOException, SignatureException;
308+
309+
GetTapeLibraryResponse getTapeLibrary(GetTapeLibraryRequest request)
310+
throws IOException, SignatureException;
306311

307312
/**
308313
* Creates a new Ds3Client instance for the system pointed to by Node.

ds3-sdk/src/main/java/com/spectralogic/ds3client/Ds3ClientImpl.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,16 @@ public GetSystemInformationResponse getSystemInformation(final GetSystemInformat
255255
return new GetSystemInformationResponse(this.netClient.getResponse(request));
256256
}
257257

258+
@Override
259+
public GetTapeLibrariesResponse getTapeLibraries(final GetTapeLibrariesRequest request) throws IOException, SignatureException {
260+
return new GetTapeLibrariesResponse(this.netClient.getResponse(request));
261+
}
262+
263+
@Override
264+
public GetTapeLibraryResponse getTapeLibrary(final GetTapeLibraryRequest request) throws IOException, SignatureException {
265+
return new GetTapeLibraryResponse(this.netClient.getResponse(request));
266+
}
267+
258268
@Override
259269
public Ds3Client newForNode(final Node node) {
260270
final ConnectionDetails newConnectionDetails = ConnectionDetailsImpl.newForNode(node, this.getConnectionDetails());
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* ******************************************************************************
3+
* Copyright 2014-2015 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.commands;
17+
18+
import com.spectralogic.ds3client.HttpVerb;
19+
20+
public class GetTapeLibrariesRequest extends AbstractRequest {
21+
@Override
22+
public String getPath() {
23+
return "/_rest_/tape_library";
24+
}
25+
26+
@Override
27+
public HttpVerb getVerb() {
28+
return HttpVerb.GET;
29+
}
30+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* ******************************************************************************
3+
* Copyright 2014-2015 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.commands;
17+
18+
import com.spectralogic.ds3client.models.tape.TapeLibraries;
19+
import com.spectralogic.ds3client.models.tape.TapeLibrary;
20+
import com.spectralogic.ds3client.networking.WebResponse;
21+
import com.spectralogic.ds3client.serializer.XmlOutput;
22+
23+
import java.io.IOException;
24+
import java.io.InputStream;
25+
import java.util.List;
26+
27+
public class GetTapeLibrariesResponse extends AbstractResponse{
28+
29+
private List<TapeLibrary> tapeLibraries;
30+
31+
public GetTapeLibrariesResponse(final WebResponse response) throws IOException {
32+
super(response);
33+
}
34+
35+
@Override
36+
protected void processResponse() throws IOException {
37+
try (final WebResponse response = getResponse()) {
38+
this.checkStatusCode(200);
39+
try (final InputStream inputStream = response.getResponseStream()) {
40+
this.tapeLibraries = XmlOutput.fromXml(inputStream, TapeLibraries.class).getTapeLibraries();
41+
}
42+
}
43+
}
44+
45+
public List<TapeLibrary> getTapeLibraries() {
46+
return tapeLibraries;
47+
}
48+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* ******************************************************************************
3+
* Copyright 2014-2015 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.commands;
17+
18+
import com.spectralogic.ds3client.HttpVerb;
19+
20+
import java.util.UUID;
21+
22+
public class GetTapeLibraryRequest extends AbstractRequest {
23+
24+
private final UUID id;
25+
26+
public GetTapeLibraryRequest(final UUID id) {
27+
this.id = id;
28+
}
29+
30+
@Override
31+
public String getPath() {
32+
return "/_rest_/tape_library/" + id.toString();
33+
}
34+
35+
@Override
36+
public HttpVerb getVerb() {
37+
return HttpVerb.GET;
38+
}
39+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* ******************************************************************************
3+
* Copyright 2014-2015 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.commands;
17+
18+
import com.spectralogic.ds3client.models.tape.TapeLibrary;
19+
import com.spectralogic.ds3client.networking.WebResponse;
20+
import com.spectralogic.ds3client.serializer.XmlOutput;
21+
22+
import java.io.IOException;
23+
import java.io.InputStream;
24+
25+
public class GetTapeLibraryResponse extends AbstractResponse {
26+
private TapeLibrary tapeLibrary;
27+
public GetTapeLibraryResponse(final WebResponse response) throws IOException {
28+
super(response);
29+
}
30+
31+
@Override
32+
protected void processResponse() throws IOException {
33+
try (final WebResponse response = getResponse()) {
34+
this.checkStatusCode(200);
35+
try (final InputStream inputStream = response.getResponseStream()) {
36+
this.tapeLibrary = XmlOutput.fromXml(inputStream, TapeLibrary.class);
37+
}
38+
}
39+
40+
}
41+
42+
public TapeLibrary getTapeLibrary() {
43+
return tapeLibrary;
44+
}
45+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* ******************************************************************************
3+
* Copyright 2014-2015 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.models.tape;
17+
18+
import com.fasterxml.jackson.annotation.JsonProperty;
19+
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
20+
21+
import java.util.List;
22+
23+
@JacksonXmlRootElement(namespace = "Data")
24+
public class TapeLibraries {
25+
@JsonProperty("TapeLibrary")
26+
private List<TapeLibrary> tapeLibraries;
27+
28+
public List<TapeLibrary> getTapeLibraries() {
29+
return tapeLibraries;
30+
}
31+
32+
public void setTapeLibraries(List<TapeLibrary> tapeLibraries) {
33+
this.tapeLibraries = tapeLibraries;
34+
}
35+
36+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* ******************************************************************************
3+
* Copyright 2014-2015 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.models.tape;
17+
18+
19+
import com.fasterxml.jackson.annotation.JsonProperty;
20+
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
21+
22+
import java.util.UUID;
23+
24+
@JacksonXmlRootElement(namespace = "Data")
25+
public class TapeLibrary {
26+
@JsonProperty("Id")
27+
private UUID id;
28+
@JsonProperty("ManagementUrl")
29+
private String managementUrl;
30+
@JsonProperty("Name")
31+
private String name;
32+
@JsonProperty("SerialNumber")
33+
private String serialNumber;
34+
35+
public UUID getId() {
36+
return id;
37+
}
38+
39+
public void setId(UUID id) {
40+
this.id = id;
41+
}
42+
43+
public String getManagementUrl() {
44+
return managementUrl;
45+
}
46+
47+
public void setManagementUrl(String managementUrl) {
48+
this.managementUrl = managementUrl;
49+
}
50+
51+
public String getName() {
52+
return name;
53+
}
54+
55+
public void setName(String name) {
56+
this.name = name;
57+
}
58+
59+
public String getSerialNumber() {
60+
return serialNumber;
61+
}
62+
63+
public void setSerialNumber(String serialNumber) {
64+
this.serialNumber = serialNumber;
65+
}
66+
}

ds3-sdk/src/test/java/com/spectralogic/ds3client/Ds3Client_Test.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import com.spectralogic.ds3client.models.*;
2323
import com.spectralogic.ds3client.models.bulk.*;
2424
import com.spectralogic.ds3client.models.bulk.Objects;
25+
import com.spectralogic.ds3client.models.tape.TapeLibrary;
2526
import com.spectralogic.ds3client.networking.FailedRequestException;
2627
import com.spectralogic.ds3client.serializer.XmlProcessingException;
2728
import com.spectralogic.ds3client.utils.ByteArraySeekableByteChannel;
@@ -705,4 +706,35 @@ public void systemInformation() throws IOException, SignatureException {
705706

706707
assertThat(response.getSystemInformation(), is(notNullValue()));
707708
}
709+
710+
@Test
711+
public void getTapeLibraries() throws IOException, SignatureException {
712+
final String responsePayload = "<Data><TapeLibrary><Id>f4dae25d-e52a-4430-82bd-525e4f15493c</Id><ManagementUrl>a</ManagementUrl><Name>test library</Name><SerialNumber>test library</SerialNumber></TapeLibrary><TapeLibrary><Id>82bdab72-d79a-4b43-95d7-f2c16cd9aa45</Id><ManagementUrl>a</ManagementUrl><Name>test library 2</Name><SerialNumber>test library 2</SerialNumber></TapeLibrary></Data>";
713+
714+
final GetTapeLibrariesResponse response = MockNetwork
715+
.expecting(HttpVerb.GET, "/_rest_/tape_library", null, null)
716+
.returning(200, responsePayload)
717+
.asClient()
718+
.getTapeLibraries(new GetTapeLibrariesRequest());
719+
720+
final List<TapeLibrary> libraries = response.getTapeLibraries();
721+
722+
assertThat(libraries.size(), is(2));
723+
assertThat(libraries.get(0).getId().toString(), is("f4dae25d-e52a-4430-82bd-525e4f15493c"));
724+
}
725+
726+
@Test
727+
public void getTapeLibrary() throws IOException, SignatureException {
728+
final String responsePayload = "<Data><Id>e23030e5-9b8d-4594-bdd1-15d3c45abb9f</Id><ManagementUrl>a</ManagementUrl><Name>125ca16e-60e3-43b2-a26f-0bc81843745f</Name><SerialNumber>test library</SerialNumber></Data>";
729+
730+
final GetTapeLibraryResponse response = MockNetwork
731+
.expecting(HttpVerb.GET, "/_rest_/tape_library/e23030e5-9b8d-4594-bdd1-15d3c45abb9f", null, null)
732+
.returning(200, responsePayload)
733+
.asClient()
734+
.getTapeLibrary(new GetTapeLibraryRequest(UUID.fromString("e23030e5-9b8d-4594-bdd1-15d3c45abb9f")));
735+
736+
assertThat(response.getTapeLibrary(), is(notNullValue()));
737+
assertThat(response.getTapeLibrary().getId().toString(), is("e23030e5-9b8d-4594-bdd1-15d3c45abb9f"));
738+
739+
}
708740
}

0 commit comments

Comments
 (0)