You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ozone.apache.org by GitBox <gi...@apache.org> on 2022/04/27 08:45:38 UTC

[GitHub] [ozone] sodonnel opened a new pull request, #3356: HDDS-6641. datanode usageinfo CLI should provide JSON output option

sodonnel opened a new pull request, #3356:
URL: https://github.com/apache/ozone/pull/3356

   ## What changes were proposed in this pull request?
   
   Add the option for the command `ozone admin datanode usageinfo` to output as JSON/
   
   ## What is the link to the Apache JIRA
   
   https://issues.apache.org/jira/browse/HDDS-6641
   
   ## How was this patch tested?
   
   New unit tests. Also verified the JSON out using a docker-compose cluster:
   
   ```
   bash-4.2$ ozone admin datanode usageinfo -m --json
   [ {
     "datanodeDetails" : {
       "level" : 0,
       "cost" : 0,
       "uuid" : "cf92907e-ed4d-49e5-9e4e-0283f8815e80",
       "uuidString" : "cf92907e-ed4d-49e5-9e4e-0283f8815e80",
       "ipAddress" : "172.23.0.7",
       "hostName" : "ozone_datanode_1.ozone_default",
       "ports" : [ {
         "name" : "REPLICATION",
         "value" : 9886
       }, {
         "name" : "RATIS",
         "value" : 9858
       }, {
         "name" : "RATIS_ADMIN",
         "value" : 9857
       }, {
         "name" : "RATIS_SERVER",
         "value" : 9856
       }, {
         "name" : "STANDALONE",
         "value" : 9859
       } ],
       "setupTime" : 0,
       "persistedOpState" : "IN_SERVICE",
       "persistedOpStateExpiryEpochSec" : 0,
       "initialVersion" : 0,
       "currentVersion" : 1,
       "signature" : 20570720,
       "networkName" : "cf92907e-ed4d-49e5-9e4e-0283f8815e80",
       "networkLocation" : "/default-rack",
       "networkFullPath" : "/default-rack/cf92907e-ed4d-49e5-9e4e-0283f8815e80",
       "numOfLeaves" : 1
     },
     "capacity" : 62725623808,
     "remaining" : 41445900288,
     "totalUsed" : 21279723520,
     "ozoneUsed" : 8192,
     "totalUsedPercent" : 33.93,
     "ozoneUsedPercent" : 0.00,
     "remainingPercent" : 66.07
   }, {
    ...
   ```
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


[GitHub] [ozone] adoroszlai commented on a diff in pull request #3356: HDDS-6641. datanode usageinfo CLI should provide JSON output option

Posted by GitBox <gi...@apache.org>.
adoroszlai commented on code in PR #3356:
URL: https://github.com/apache/ozone/pull/3356#discussion_r860759725


##########
hadoop-hdds/tools/src/test/java/org/apache/hadoop/hdds/scm/cli/datanode/TestUsageInfoSubcommand.java:
##########
@@ -0,0 +1,122 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hdds.scm.cli.datanode;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.apache.hadoop.hdds.protocol.proto.HddsProtos;
+import org.apache.hadoop.hdds.scm.client.ScmClient;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+import picocli.CommandLine;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.PrintStream;
+import java.io.UnsupportedEncodingException;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.UUID;
+
+import static com.fasterxml.jackson.databind.node.JsonNodeType.ARRAY;
+import static org.mockito.Mockito.mock;
+
+/**
+ * Test for the UsageInfoSubCommand class.
+ */
+public class TestUsageInfoSubcommand {
+
+  private UsageInfoSubcommand cmd;
+  private final ByteArrayOutputStream outContent = new ByteArrayOutputStream();
+  private final ByteArrayOutputStream errContent = new ByteArrayOutputStream();
+  private final PrintStream originalOut = System.out;
+  private final PrintStream originalErr = System.err;
+  private static final String DEFAULT_ENCODING = StandardCharsets.UTF_8.name();
+
+  @Before
+  public void setup() throws UnsupportedEncodingException {
+    cmd = new UsageInfoSubcommand();
+    System.setOut(new PrintStream(outContent, false, DEFAULT_ENCODING));
+    System.setErr(new PrintStream(errContent, false, DEFAULT_ENCODING));
+  }
+
+  @After
+  public void tearDown() {
+    System.setOut(originalOut);
+    System.setErr(originalErr);
+  }
+
+  @Test
+  public void testCorrectJsonValuesInReport() throws IOException {
+    ScmClient scmClient = mock(ScmClient.class);
+    Mockito.when(scmClient.getDatanodeUsageInfo(
+        Mockito.anyBoolean(), Mockito.anyInt()))
+        .thenAnswer(invocation -> getUsageProto());
+
+    CommandLine c = new CommandLine(cmd);
+    c.parseArgs("-m", "--json");
+    cmd.execute(scmClient);
+
+    ObjectMapper mapper = new ObjectMapper();
+    JsonNode json = mapper.readTree(outContent.toString("UTF-8"));
+
+    Assert.assertEquals(ARRAY, json.getNodeType());
+    Assert.assertTrue(json.get(0).get("datanodeDetails") != null);
+    Assert.assertEquals(10, json.get(0).get("ozoneUsed").longValue());
+    Assert.assertEquals(100, json.get(0).get("capacity").longValue());
+    Assert.assertEquals(80, json.get(0).get("remaining").longValue());
+    Assert.assertEquals(20, json.get(0).get("totalUsed").longValue());
+
+    Assert.assertEquals(20.00,
+        json.get(0).get("totalUsedPercent").doubleValue(), 0.001);
+    Assert.assertEquals(10.00,
+        json.get(0).get("ozoneUsedPercent").doubleValue(), 0.001);
+    Assert.assertEquals(80.00,
+        json.get(0).get("remainingPercent").doubleValue(), 0.001);
+  }
+
+  private List<HddsProtos.DatanodeUsageInfoProto> getUsageProto() {
+    List<HddsProtos.DatanodeUsageInfoProto> result = new ArrayList<>();
+    result.add(HddsProtos.DatanodeUsageInfoProto.newBuilder()
+        .setNode(createDatanodeDetails())
+        .setCapacity(100)
+        .setRemaining(80)
+        .setUsed(10)
+        .build());
+    return result;
+  }
+
+  private HddsProtos.DatanodeDetailsProto createDatanodeDetails() {
+    HddsProtos.DatanodeDetailsProto dnd =
+        HddsProtos.DatanodeDetailsProto.newBuilder()
+            .setHostName("host")
+            .setIpAddress("1.2.3.1")
+            .setNetworkLocation("/default")
+            .setNetworkName("host")
+            .addPorts(HddsProtos.Port.newBuilder()
+                .setName("ratis").setValue(5678).build())
+            .setUuid(UUID.randomUUID().toString())
+            .build();
+    return dnd;
+  }

Review Comment:
   I guess we could reuse `MockDatanodeDetails` instead.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


[GitHub] [ozone] adoroszlai merged pull request #3356: HDDS-6641. datanode usageinfo CLI should provide JSON output option

Posted by GitBox <gi...@apache.org>.
adoroszlai merged PR #3356:
URL: https://github.com/apache/ozone/pull/3356


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org