|
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.ds3cli.views.cli; |
17 |
| - |
18 |
| -import com.bethecoder.ascii_table.ASCIITable; |
19 |
| -import com.bethecoder.ascii_table.ASCIITableHeader; |
20 |
| -import com.spectralogic.ds3cli.View; |
21 |
| -import com.spectralogic.ds3cli.models.GetTapeFailureResult; |
22 |
| -import com.spectralogic.ds3client.models.DetailedTapeFailure; |
23 |
| -import com.spectralogic.ds3client.models.DetailedTapeFailureList; |
24 |
| -import com.spectralogic.ds3client.models.Ds3Bucket; |
25 |
| -import com.spectralogic.ds3client.models.ListAllMyBucketsResult; |
26 |
| - |
27 |
| -import java.text.SimpleDateFormat; |
28 |
| -import java.util.List; |
29 |
| -import java.util.TimeZone; |
30 |
| - |
31 |
| -import static com.spectralogic.ds3cli.util.Utils.nullGuard; |
32 |
| - |
33 |
| -public class GetTapeFailureView implements View<GetTapeFailureResult> { |
34 |
| - @Override |
35 |
| - public String render(final GetTapeFailureResult obj) { |
36 |
| - final DetailedTapeFailureList result = obj.getResult(); |
37 |
| - if( (result == null) |
38 |
| - || (null == result.getDetailedTapeFailures()) |
39 |
| - || (result.getDetailedTapeFailures().size() == 0) ) { |
40 |
| - return "No tape failures on remote appliance"; |
41 |
| - } |
42 |
| - |
43 |
| - return "" + result.getDetailedTapeFailures().size() + " Tape Failures:\n" + |
44 |
| - ASCIITable.getInstance().getTable(getHeaders(), formatBucketList(result)); |
45 |
| - } |
46 |
| - |
47 |
| - private String[][] formatBucketList(final DetailedTapeFailureList result) { |
48 |
| - final List<DetailedTapeFailure> failures = result.getDetailedTapeFailures(); |
49 |
| - final String [][] formatArray = new String[failures.size()][]; |
50 |
| - int i = 0; |
51 |
| - for(final DetailedTapeFailure failure : failures) { |
52 |
| - final String [] bucketArray = new String[4]; |
53 |
| - bucketArray[0] = nullGuard(failure.getType().toString()); |
54 |
| - bucketArray[1] = nullGuard(failure.getErrorMessage().toString()); |
55 |
| - bucketArray[2] = nullGuard(failure.getId().toString()); |
56 |
| - final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); |
57 |
| - DATE_FORMAT.setTimeZone(TimeZone.getTimeZone("UTC")); |
58 |
| - bucketArray[3] = DATE_FORMAT.format(failure.getDate()); |
59 |
| - formatArray[i++] = bucketArray; |
60 |
| - } |
61 |
| - return formatArray; |
62 |
| - } |
63 |
| - |
64 |
| - private ASCIITableHeader[] getHeaders() { |
65 |
| - return new ASCIITableHeader[]{ |
66 |
| - new ASCIITableHeader("Failure Type", ASCIITable.ALIGN_LEFT), |
67 |
| - new ASCIITableHeader("Failure Message", ASCIITable.ALIGN_CENTER), |
68 |
| - new ASCIITableHeader("Id", ASCIITable.ALIGN_CENTER), |
69 |
| - new ASCIITableHeader("Failure Date", ASCIITable.ALIGN_RIGHT) |
70 |
| - }; |
71 |
| - } |
72 |
| -} |
| 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.ds3cli.views.cli; |
| 17 | + |
| 18 | +import com.bethecoder.ascii_table.ASCIITable; |
| 19 | +import com.bethecoder.ascii_table.ASCIITableHeader; |
| 20 | +import com.spectralogic.ds3cli.View; |
| 21 | +import com.spectralogic.ds3cli.models.GetTapeFailureResult; |
| 22 | +import com.spectralogic.ds3client.models.DetailedTapeFailure; |
| 23 | +import com.spectralogic.ds3client.models.DetailedTapeFailureList; |
| 24 | + |
| 25 | +import java.text.SimpleDateFormat; |
| 26 | +import java.util.List; |
| 27 | +import java.util.TimeZone; |
| 28 | + |
| 29 | +import static com.spectralogic.ds3cli.util.Utils.nullGuard; |
| 30 | + |
| 31 | +public class GetTapeFailureView implements View<GetTapeFailureResult> { |
| 32 | + @Override |
| 33 | + public String render(final GetTapeFailureResult obj) { |
| 34 | + final DetailedTapeFailureList result = obj.getResult(); |
| 35 | + if( (result == null) |
| 36 | + || (null == result.getDetailedTapeFailures()) |
| 37 | + || (result.getDetailedTapeFailures().size() == 0) ) { |
| 38 | + return "No tape failures on remote appliance"; |
| 39 | + } |
| 40 | + |
| 41 | + return "" + result.getDetailedTapeFailures().size() + " Tape Failures:\n" + |
| 42 | + ASCIITable.getInstance().getTable(getHeaders(), formatBucketList(result)); |
| 43 | + } |
| 44 | + |
| 45 | + private String[][] formatBucketList(final DetailedTapeFailureList result) { |
| 46 | + final List<DetailedTapeFailure> failures = result.getDetailedTapeFailures(); |
| 47 | + final String [][] formatArray = new String[failures.size()][]; |
| 48 | + int i = 0; |
| 49 | + for(final DetailedTapeFailure failure : failures) { |
| 50 | + final String [] bucketArray = new String[4]; |
| 51 | + bucketArray[0] = nullGuard(failure.getType().toString()); |
| 52 | + bucketArray[1] = nullGuard(failure.getErrorMessage()); |
| 53 | + bucketArray[2] = nullGuard(failure.getId().toString()); |
| 54 | + final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); |
| 55 | + DATE_FORMAT.setTimeZone(TimeZone.getTimeZone("UTC")); |
| 56 | + bucketArray[3] = DATE_FORMAT.format(failure.getDate()); |
| 57 | + formatArray[i++] = bucketArray; |
| 58 | + } |
| 59 | + return formatArray; |
| 60 | + } |
| 61 | + |
| 62 | + private ASCIITableHeader[] getHeaders() { |
| 63 | + return new ASCIITableHeader[]{ |
| 64 | + new ASCIITableHeader("Failure Type", ASCIITable.ALIGN_LEFT), |
| 65 | + new ASCIITableHeader("Failure Message", ASCIITable.ALIGN_CENTER), |
| 66 | + new ASCIITableHeader("Id", ASCIITable.ALIGN_CENTER), |
| 67 | + new ASCIITableHeader("Failure Date", ASCIITable.ALIGN_RIGHT) |
| 68 | + }; |
| 69 | + } |
| 70 | +} |
0 commit comments