15
15
* See the License for the specific language governing permissions and
16
16
* limitations under the License.
17
17
*/
18
- package org .apache .hadoop .hdds .scm . cli . datanode ;
18
+ package org .apache .hadoop .ozone .scm ;
19
19
20
- import com .fasterxml .jackson .databind .JsonNode ;
21
- import com .fasterxml .jackson .databind .ObjectMapper ;
22
- import org .apache .hadoop .hdds .protocol .MockDatanodeDetails ;
20
+ import org .apache .hadoop .hdds .protocol .DatanodeDetails ;
23
21
import org .apache .hadoop .hdds .protocol .proto .HddsProtos ;
24
22
import org .apache .hadoop .hdds .scm .client .ScmClient ;
23
+ import org .apache .hadoop .ozone .admin .scm .VolumeFailureSubCommand ;
25
24
import org .apache .hadoop .hdds .scm .datanode .VolumeFailureInfo ;
26
25
import org .apache .hadoop .util .Time ;
27
26
import org .junit .jupiter .api .AfterEach ;
36
35
import java .nio .charset .StandardCharsets ;
37
36
import java .util .ArrayList ;
38
37
import java .util .List ;
38
+ import java .util .Random ;
39
+ import java .util .UUID ;
40
+ import java .util .concurrent .ThreadLocalRandom ;
39
41
42
+ import static org .apache .hadoop .hdds .protocol .DatanodeDetails .Port .Name .ALL_PORTS ;
40
43
import static org .mockito .Mockito .mock ;
41
44
import static org .mockito .Mockito .when ;
42
45
@@ -71,6 +74,16 @@ public void testCorrectJsonValuesInReport() throws IOException {
71
74
cmd .execute (scmClient );
72
75
}
73
76
77
+ @ Test
78
+ public void testCorrectTableValuesInReport () throws IOException {
79
+ ScmClient scmClient = mock (ScmClient .class );
80
+ when (scmClient .getVolumeFailureInfos ()).thenAnswer (invocation -> getUsageProto ());
81
+
82
+ CommandLine c = new CommandLine (cmd );
83
+ c .parseArgs ("--table" );
84
+ cmd .execute (scmClient );
85
+ }
86
+
74
87
private List <VolumeFailureInfo > getUsageProto () {
75
88
List <VolumeFailureInfo > result = new ArrayList <>();
76
89
for (int i = 0 ; i < 5 ; i ++) {
@@ -90,6 +103,23 @@ private List<VolumeFailureInfo> getUsageProto() {
90
103
}
91
104
92
105
private HddsProtos .DatanodeDetailsProto createDatanodeDetails () {
93
- return MockDatanodeDetails .randomDatanodeDetails ().getProtoBufMessage ();
106
+ Random random = ThreadLocalRandom .current ();
107
+ String ipAddress = random .nextInt (256 )
108
+ + "." + random .nextInt (256 )
109
+ + "." + random .nextInt (256 )
110
+ + "." + random .nextInt (256 );
111
+
112
+ DatanodeDetails .Builder dn = DatanodeDetails .newBuilder ()
113
+ .setUuid (UUID .randomUUID ())
114
+ .setHostName ("localhost" + "-" + ipAddress )
115
+ .setIpAddress (ipAddress )
116
+ .setPersistedOpState (HddsProtos .NodeOperationalState .IN_SERVICE )
117
+ .setPersistedOpStateExpiry (0 );
118
+
119
+ for (DatanodeDetails .Port .Name name : ALL_PORTS ) {
120
+ dn .addPort (DatanodeDetails .newPort (name , 0 ));
121
+ }
122
+
123
+ return dn .build ().getProtoBufMessage ();
94
124
}
95
125
}
0 commit comments