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/02/17 11:20:46 UTC

[GitHub] [ozone] adoroszlai commented on a change in pull request #3105: HDDS-6290. operational-state and node-state options in datanode list CLI not working correctly

adoroszlai commented on a change in pull request #3105:
URL: https://github.com/apache/ozone/pull/3105#discussion_r808943087



##########
File path: hadoop-hdds/tools/src/main/java/org/apache/hadoop/hdds/scm/cli/datanode/ListInfoSubcommand.java
##########
@@ -71,28 +71,24 @@
   @Override
   public void execute(ScmClient scmClient) throws IOException {
     pipelines = scmClient.listPipelines();
-    if (Strings.isNullOrEmpty(ipaddress) && Strings.isNullOrEmpty(uuid)) {
-      getAllNodes(scmClient).forEach(this::printDatanodeInfo);
-    } else {
-      Stream<DatanodeWithAttributes> allNodes = getAllNodes(scmClient).stream();
-      if (!Strings.isNullOrEmpty(ipaddress)) {
-        allNodes = allNodes.filter(p -> p.getDatanodeDetails().getIpAddress()
-            .compareToIgnoreCase(ipaddress) == 0);
-      }
-      if (!Strings.isNullOrEmpty(uuid)) {
-        allNodes = allNodes.filter(p ->
-            p.getDatanodeDetails().getUuidString().equals(uuid));
-      }
-      if (!Strings.isNullOrEmpty(nodeOperationalState)) {
-        allNodes = allNodes.filter(p -> p.getOpState().toString()
-            .compareToIgnoreCase(nodeOperationalState) == 0);
-      }
-      if (!Strings.isNullOrEmpty(nodeState)) {
-        allNodes = allNodes.filter(p -> p.getHealthState().toString()
-            .compareToIgnoreCase(nodeState) == 0);
-      }
-      allNodes.forEach(this::printDatanodeInfo);
+    Stream<DatanodeWithAttributes> allNodes = getAllNodes(scmClient).stream();
+    if (!Strings.isNullOrEmpty(ipaddress)) {
+      allNodes = allNodes.filter(p -> p.getDatanodeDetails().getIpAddress()
+          .compareToIgnoreCase(ipaddress) == 0);

Review comment:
       Yes, the assignment is needed.  `Stream.filter` returns a new stream and the original can no longer be used.
   
   ```
   jshell> var strings = Stream.of("a","aa","aaa","aaaa","aaaaa")
   strings ==> java.util.stream.ReferencePipeline$Head@6ee52dcd
   
   jshell> strings.filter(x -> x.length() > 2)
   $22 ==> java.util.stream.ReferencePipeline$2@57e1b0c
   
   jshell> strings.filter(x -> x.length() < 5)
   |  Exception java.lang.IllegalStateException: stream has already been operated upon or closed
   |        at AbstractPipeline.<init> (AbstractPipeline.java:203)
   ```
   
   ```
   jshell> var strings = Stream.of("a","aa","aaa","aaaa","aaaaa")
   strings ==> java.util.stream.ReferencePipeline$Head@480bdb19
   
   jshell> strings = strings.filter(x -> x.length() < 5)
   strings ==> java.util.stream.ReferencePipeline$2@2a742aa2
   
   jshell> strings = strings.filter(x -> x.length() > 2)
   strings ==> java.util.stream.ReferencePipeline$2@467aecef
   
   jshell> strings.count()
   $27 ==> 2
   ```




-- 
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