diff --git a/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/freon/BaseFreonGenerator.java b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/freon/BaseFreonGenerator.java index 0a639ec148ca..53267fd267ca 100644 --- a/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/freon/BaseFreonGenerator.java +++ b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/freon/BaseFreonGenerator.java @@ -27,6 +27,7 @@ import java.util.function.Consumer; import java.util.regex.Matcher; import java.util.regex.Pattern; +import java.util.stream.Stream; import org.apache.hadoop.hdds.conf.OzoneConfiguration; import org.apache.hadoop.hdds.scm.pipeline.Pipeline; @@ -345,19 +346,24 @@ public StorageContainerLocationProtocol createStorageContainerLocationClient( return HAUtils.getScmContainerClient(ozoneConf); } + @SuppressWarnings("java:S3864") // Stream.peek (for debug) public static Pipeline findPipelineForTest(String pipelineId, StorageContainerLocationProtocol client, Logger log) throws IOException { - List pipelines = client.listPipelines(); + Stream pipelines = client.listPipelines().stream(); Pipeline pipeline; + if (log.isDebugEnabled()) { + pipelines = pipelines + .peek(p -> log.debug("Found pipeline {}", p.getId().getId())); + } if (pipelineId != null && pipelineId.length() > 0) { - pipeline = pipelines.stream() + pipeline = pipelines .filter(p -> p.getId().toString().equals(pipelineId)) .findFirst() .orElseThrow(() -> new IllegalArgumentException( "Pipeline ID is defined, but there is no such pipeline: " + pipelineId)); } else { - pipeline = pipelines.stream() + pipeline = pipelines .filter(p -> p.getReplicationConfig().getRequiredNodes() == 3) .findFirst() .orElseThrow(() -> new IllegalArgumentException( diff --git a/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/freon/DatanodeChunkValidator.java b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/freon/DatanodeChunkValidator.java index 5d86bc595dd6..b290da2da1f5 100644 --- a/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/freon/DatanodeChunkValidator.java +++ b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/freon/DatanodeChunkValidator.java @@ -18,15 +18,12 @@ import java.io.IOException; import java.util.concurrent.Callable; -import java.util.stream.Stream; import org.apache.hadoop.hdds.cli.HddsVersionProvider; -import org.apache.hadoop.hdds.client.ReplicationConfig; import org.apache.hadoop.hdds.conf.OzoneConfiguration; import org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos; import org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.ContainerCommandRequestProto; import org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.ContainerCommandResponseProto; -import org.apache.hadoop.hdds.protocol.proto.HddsProtos; import org.apache.hadoop.hdds.scm.XceiverClientManager; import org.apache.hadoop.hdds.scm.XceiverClientSpi; import org.apache.hadoop.hdds.scm.pipeline.Pipeline; @@ -79,7 +76,6 @@ public class DatanodeChunkValidator extends BaseFreonGenerator @Override - @SuppressWarnings("java:S3864") // Stream.peek (for debug) public Void call() throws Exception { init(); @@ -91,33 +87,9 @@ public Void call() throws Exception { ); } - try (StorageContainerLocationProtocol scmLocationClient = + try (StorageContainerLocationProtocol scmClient = createStorageContainerLocationClient(ozoneConf)) { - Stream pipelines = scmLocationClient.listPipelines().stream(); - if (LOG.isDebugEnabled()) { - pipelines = pipelines - .peek(p -> LOG.debug("Found pipeline {}", p.getId())); - } - Pipeline pipeline; - if (pipelineId != null && pipelineId.length() > 0) { - pipeline = pipelines - .filter(p -> p.getId().getId().toString().equals(pipelineId)) - .findFirst() - .orElseThrow(() -> new IllegalArgumentException( - "Pipeline ID is defined, but there is no such pipeline: " - + pipelineId)); - - } else { - pipeline = pipelines - .filter( - p -> ReplicationConfig.getLegacyFactor(p.getReplicationConfig()) - == HddsProtos.ReplicationFactor.THREE) - .findFirst() - .orElseThrow(() -> new IllegalArgumentException( - "Pipeline ID is NOT defined, and no pipeline " + - "has been found with factor=THREE")); - LOG.info("Using pipeline {}", pipeline.getId()); - } + Pipeline pipeline = findPipelineForTest(pipelineId, scmClient, LOG); try (XceiverClientManager xceiverClientManager = new XceiverClientManager(ozoneConf)) {