This is an automated email from the ASF dual-hosted git repository.
szetszwo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ozone.git
The following commit(s) were added to refs/heads/master by this push:
new 0807a77b46 HDDS-10422. Fix some warnings about exposing internal
representation in hdds-common (#6351)
0807a77b46 is described below
commit 0807a77b4669e8bc935cc6cf11804f6b1ded252e
Author: Doroszlai, Attila <[email protected]>
AuthorDate: Wed May 22 21:55:09 2024 +0200
HDDS-10422. Fix some warnings about exposing internal representation in
hdds-common (#6351)
---
.../hadoop/hdds/conf/OzoneConfiguration.java | 9 +--
.../hadoop/hdds/freon/FakeClusterTopology.java | 38 ++++++----
.../hadoop/hdds/protocol/DatanodeDetails.java | 11 ++-
.../java/org/apache/hadoop/hdds/scm/ScmInfo.java | 11 +--
.../apache/hadoop/hdds/scm/XceiverClientReply.java | 3 +-
.../scm/container/common/helpers/ExcludeList.java | 19 ++---
.../org/apache/hadoop/hdds/scm/ha/SCMHAUtils.java | 6 +-
.../apache/hadoop/hdds/scm/pipeline/Pipeline.java | 14 ++--
.../hdds/scm/storage/ContainerProtocolCalls.java | 2 +-
.../apache/hadoop/hdds/utils/BatchOperation.java | 88 ----------------------
.../apache/hadoop/ozone/common/ChecksumData.java | 5 +-
.../ozone/common/statemachine/StateMachine.java | 10 +--
.../ozone/container/common/helpers/ChunkInfo.java | 13 +---
.../hadoop/ozone/util/ShutdownHookManager.java | 38 +++-------
.../container/common/helpers/DatanodeIdYaml.java | 6 +-
.../container/keyvalue/helpers/ChunkUtils.java | 4 +-
.../hdds/scm/node/NodeDecommissionManager.java | 7 +-
.../GenerateOzoneRequiredConfigurations.java | 3 +-
18 files changed, 91 insertions(+), 196 deletions(-)
diff --git
a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/conf/OzoneConfiguration.java
b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/conf/OzoneConfiguration.java
index e324a63d3b..b8742c6ba9 100644
---
a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/conf/OzoneConfiguration.java
+++
b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/conf/OzoneConfiguration.java
@@ -30,6 +30,7 @@ import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
+import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.List;
@@ -163,15 +164,11 @@ public class OzoneConfiguration extends Configuration
}
public XMLConfiguration(List<Property> properties) {
- this.properties = properties;
+ this.properties = new ArrayList<>(properties);
}
public List<Property> getProperties() {
- return properties;
- }
-
- public void setProperties(List<Property> properties) {
- this.properties = properties;
+ return Collections.unmodifiableList(properties);
}
}
diff --git
a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/freon/FakeClusterTopology.java
b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/freon/FakeClusterTopology.java
index 2d29dc8565..ba203f9c8e 100644
---
a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/freon/FakeClusterTopology.java
+++
b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/freon/FakeClusterTopology.java
@@ -18,6 +18,7 @@
package org.apache.hadoop.hdds.freon;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
import java.util.Random;
import java.util.UUID;
@@ -36,40 +37,49 @@ import org.slf4j.LoggerFactory;
* Class to store pre-generated topology information for load-tests.
*/
@SuppressWarnings("java:S2245") // no need for secure random
-public class FakeClusterTopology {
+public final class FakeClusterTopology {
private static final Logger LOGGER =
LoggerFactory.getLogger(FakeClusterTopology.class);
- public static final FakeClusterTopology INSTANCE = new FakeClusterTopology();
+ public static final FakeClusterTopology INSTANCE = newFakeClusterTopology();
- private List<DatanodeDetailsProto> datanodes = new ArrayList<>();
+ private final List<DatanodeDetailsProto> datanodes;
- private List<Pipeline> pipelines = new ArrayList<>();
+ private final List<Pipeline> pipelines;
- private Random random = new Random();
+ private final Random random = new Random();
- public FakeClusterTopology() {
+ private static FakeClusterTopology newFakeClusterTopology() {
+ final int nodeCount = 9;
+ final List<DatanodeDetailsProto> datanodes = new ArrayList<>(nodeCount);
+ final List<Pipeline> pipelines = new ArrayList<>(nodeCount / 3);
try {
- for (int i = 0; i < 9; i++) {
+ for (int i = 0; i < nodeCount; i++) {
datanodes.add(createDatanode());
if ((i + 1) % 3 == 0) {
pipelines.add(Pipeline.newBuilder()
.setId(PipelineID.randomId().getProtobuf())
.setFactor(ReplicationFactor.THREE)
.setType(ReplicationType.RATIS)
- .addMembers(getDatanode(i - 2))
- .addMembers(getDatanode(i - 1))
- .addMembers(getDatanode(i))
+ .addMembers(datanodes.get(i - 2))
+ .addMembers(datanodes.get(i - 1))
+ .addMembers(datanodes.get(i))
.build());
}
}
} catch (Exception ex) {
LOGGER.error("Can't initialize FakeClusterTopology", ex);
}
+ return new FakeClusterTopology(datanodes, pipelines);
}
- private DatanodeDetailsProto createDatanode() {
+ private FakeClusterTopology(List<DatanodeDetailsProto> datanodes,
List<Pipeline> pipelines) {
+ this.datanodes = Collections.unmodifiableList(datanodes);
+ this.pipelines = Collections.unmodifiableList(pipelines);
+ }
+
+ private static DatanodeDetailsProto createDatanode() {
return DatanodeDetailsProto.newBuilder()
.setUuid(UUID.randomUUID().toString())
.setHostName("localhost")
@@ -79,15 +89,11 @@ public class FakeClusterTopology {
.build();
}
- public DatanodeDetailsProto getDatanode(int i) {
- return datanodes.get(i);
- }
-
public Pipeline getRandomPipeline() {
return pipelines.get(random.nextInt(pipelines.size()));
}
- public List<DatanodeDetailsProto> getAllDatanodes() {
+ public Iterable<DatanodeDetailsProto> getAllDatanodes() {
return datanodes;
}
}
diff --git
a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/protocol/DatanodeDetails.java
b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/protocol/DatanodeDetails.java
index 224f961158..f54b96eb04 100644
---
a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/protocol/DatanodeDetails.java
+++
b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/protocol/DatanodeDetails.java
@@ -242,7 +242,16 @@ public class DatanodeDetails extends NodeImpl implements
* @return DataNode Ports
*/
public synchronized List<Port> getPorts() {
- return ports;
+ return new ArrayList<>(ports);
+ }
+
+ public synchronized boolean hasPort(int port) {
+ for (Port p : ports) {
+ if (p.getValue() == port) {
+ return true;
+ }
+ }
+ return false;
}
/**
diff --git
a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/scm/ScmInfo.java
b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/scm/ScmInfo.java
index b9d823e8d8..19c39698de 100644
--- a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/scm/ScmInfo.java
+++ b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/scm/ScmInfo.java
@@ -19,6 +19,7 @@
package org.apache.hadoop.hdds.scm;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
/**
@@ -26,9 +27,9 @@ import java.util.List;
* contains clusterId and the SCM Id.
*/
public final class ScmInfo {
- private String clusterId;
- private String scmId;
- private List<String> peerRoles;
+ private final String clusterId;
+ private final String scmId;
+ private final List<String> peerRoles;
/**
* Builder for ScmInfo.
@@ -36,7 +37,7 @@ public final class ScmInfo {
public static class Builder {
private String clusterId;
private String scmId;
- private List<String> peerRoles;
+ private final List<String> peerRoles;
public Builder() {
peerRoles = new ArrayList<>();
@@ -80,7 +81,7 @@ public final class ScmInfo {
private ScmInfo(String clusterId, String scmId, List<String> peerRoles) {
this.clusterId = clusterId;
this.scmId = scmId;
- this.peerRoles = peerRoles;
+ this.peerRoles = Collections.unmodifiableList(peerRoles);
}
/**
diff --git
a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/scm/XceiverClientReply.java
b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/scm/XceiverClientReply.java
index b6834aba1e..61fd0d8f03 100644
---
a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/scm/XceiverClientReply.java
+++
b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/scm/XceiverClientReply.java
@@ -22,6 +22,7 @@ import org.apache.hadoop.hdds.protocol.DatanodeDetails;
import org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos
.ContainerCommandResponseProto;
+import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.CompletableFuture;
@@ -60,7 +61,7 @@ public class XceiverClientReply {
}
public List<DatanodeDetails> getDatanodes() {
- return datanodes;
+ return Collections.unmodifiableList(datanodes);
}
public void addDatanode(DatanodeDetails dn) {
diff --git
a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/scm/container/common/helpers/ExcludeList.java
b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/scm/container/common/helpers/ExcludeList.java
index 2577a1e5ea..258c0be896 100644
---
a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/scm/container/common/helpers/ExcludeList.java
+++
b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/scm/container/common/helpers/ExcludeList.java
@@ -25,6 +25,7 @@ import org.apache.hadoop.hdds.scm.pipeline.PipelineID;
import java.time.Clock;
import java.time.ZoneOffset;
import java.util.Collection;
+import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
@@ -38,28 +39,24 @@ import java.util.concurrent.ConcurrentHashMap;
*/
public class ExcludeList {
- private final Map<DatanodeDetails, Long> datanodes;
- private final Set<ContainerID> containerIds;
- private final Set<PipelineID> pipelineIds;
+ private final Map<DatanodeDetails, Long> datanodes = new
ConcurrentHashMap<>();
+ private final Set<ContainerID> containerIds = new HashSet<>();
+ private final Set<PipelineID> pipelineIds = new HashSet<>();
private long expiryTime = 0;
- private java.time.Clock clock;
+ private final Clock clock;
public ExcludeList() {
- datanodes = new ConcurrentHashMap<>();
- containerIds = new HashSet<>();
- pipelineIds = new HashSet<>();
clock = Clock.system(ZoneOffset.UTC);
}
- public ExcludeList(long autoExpiryTime, java.time.Clock clock) {
- this();
+ public ExcludeList(long autoExpiryTime, Clock clock) {
this.expiryTime = autoExpiryTime;
this.clock = clock;
}
public Set<ContainerID> getContainerIds() {
- return containerIds;
+ return Collections.unmodifiableSet(containerIds);
}
public Set<DatanodeDetails> getDatanodes() {
@@ -99,7 +96,7 @@ public class ExcludeList {
}
public Set<PipelineID> getPipelineIds() {
- return pipelineIds;
+ return Collections.unmodifiableSet(pipelineIds);
}
public HddsProtos.ExcludeListProto getProtoBuf() {
diff --git
a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/scm/ha/SCMHAUtils.java
b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/scm/ha/SCMHAUtils.java
index 80e09af172..af4e729938 100644
---
a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/scm/ha/SCMHAUtils.java
+++
b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/scm/ha/SCMHAUtils.java
@@ -65,7 +65,7 @@ public final class SCMHAUtils {
public static final Logger LOG =
LoggerFactory.getLogger(SCMHAUtils.class);
- private static final List<Class<? extends Exception>>
+ private static final ImmutableList<Class<? extends Exception>>
RETRIABLE_WITH_NO_FAILOVER_EXCEPTION_LIST =
ImmutableList.<Class<? extends Exception>>builder()
.add(LeaderNotReadyException.class)
@@ -74,7 +74,7 @@ public final class SCMHAUtils {
.add(ResourceUnavailableException.class)
.build();
- private static final List<Class<? extends Exception>>
+ private static final ImmutableList<Class<? extends Exception>>
NON_RETRIABLE_EXCEPTION_LIST =
ImmutableList.<Class<? extends Exception>>builder()
.add(SCMException.class)
@@ -316,7 +316,7 @@ public final class SCMHAUtils {
return null;
}
- public static List<Class<? extends
+ private static List<Class<? extends
Exception>> getRetriableWithNoFailoverExceptionList() {
return RETRIABLE_WITH_NO_FAILOVER_EXCEPTION_LIST;
}
diff --git
a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/scm/pipeline/Pipeline.java
b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/scm/pipeline/Pipeline.java
index 05d83a8b8b..6ea92f74c1 100644
---
a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/scm/pipeline/Pipeline.java
+++
b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/scm/pipeline/Pipeline.java
@@ -23,7 +23,6 @@ import java.time.Instant;
import java.time.ZoneId;
import java.util.ArrayList;
import java.util.Collections;
-import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedList;
@@ -113,7 +112,7 @@ public final class Pipeline {
suggestedLeaderId = b.suggestedLeaderId;
nodeStatus = b.nodeStatus;
nodesInOrder = b.nodesInOrder != null ?
ImmutableList.copyOf(b.nodesInOrder) : ImmutableList.of();
- replicaIndexes = b.replicaIndexes != null ?
ImmutableMap.copyOf(b.replicaIndexes) : ImmutableMap.of();
+ replicaIndexes = b.replicaIndexes;
creationTimestamp = b.creationTimestamp != null ? b.creationTimestamp :
Instant.now();
stateEnterTime = Instant.now();
}
@@ -541,7 +540,7 @@ public final class Pipeline {
private UUID leaderId = null;
private Instant creationTimestamp = null;
private UUID suggestedLeaderId = null;
- private Map<DatanodeDetails, Integer> replicaIndexes;
+ private Map<DatanodeDetails, Integer> replicaIndexes = ImmutableMap.of();
public Builder() { }
@@ -555,13 +554,14 @@ public final class Pipeline {
this.creationTimestamp = pipeline.getCreationTimestamp();
this.suggestedLeaderId = pipeline.getSuggestedLeaderId();
if (nodeStatus != null) {
- replicaIndexes = new HashMap<>();
+ final ImmutableMap.Builder<DatanodeDetails, Integer> b =
ImmutableMap.builder();
for (DatanodeDetails dn : nodeStatus.keySet()) {
int index = pipeline.getReplicaIndex(dn);
if (index > 0) {
- replicaIndexes.put(dn, index);
+ b.put(dn, index);
}
}
+ replicaIndexes = b.build();
}
}
@@ -598,7 +598,7 @@ public final class Pipeline {
public Builder setNodeOrder(List<Integer> orders) {
// for build from ProtoBuf
- this.nodeOrder = orders;
+ this.nodeOrder = Collections.unmodifiableList(orders);
return this;
}
@@ -624,7 +624,7 @@ public final class Pipeline {
public Builder setReplicaIndexes(Map<DatanodeDetails, Integer> indexes) {
- this.replicaIndexes = indexes;
+ this.replicaIndexes = indexes == null ? ImmutableMap.of() :
ImmutableMap.copyOf(indexes);
return this;
}
diff --git
a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/scm/storage/ContainerProtocolCalls.java
b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/scm/storage/ContainerProtocolCalls.java
index 6bb87654c0..66c8459a01 100644
---
a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/scm/storage/ContainerProtocolCalls.java
+++
b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/scm/storage/ContainerProtocolCalls.java
@@ -746,7 +746,7 @@ public final class ContainerProtocolCalls {
response.getMessage(), response.getResult());
}
- public static List<Validator> getValidatorList() {
+ private static List<Validator> getValidatorList() {
return VALIDATORS;
}
diff --git
a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/utils/BatchOperation.java
b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/utils/BatchOperation.java
deleted file mode 100644
index c5640cb154..0000000000
---
a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/utils/BatchOperation.java
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- * 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
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * 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.utils;
-
-import com.google.common.collect.Lists;
-
-import java.util.List;
-import java.util.Objects;
-
-/**
- * An utility class to store a batch of DB write operations.
- */
-public class BatchOperation {
-
- /**
- * Enum for write operations.
- */
- public enum Operation {
- DELETE, PUT
- }
-
- private List<SingleOperation> operations =
- Lists.newArrayList();
-
- /**
- * Add a PUT operation into the batch.
- */
- public void put(byte[] key, byte[] value) {
- operations.add(new SingleOperation(Operation.PUT, key, value));
- }
-
- /**
- * Add a DELETE operation into the batch.
- */
- public void delete(byte[] key) {
- operations.add(new SingleOperation(Operation.DELETE, key, null));
-
- }
-
- public List<SingleOperation> getOperations() {
- return operations;
- }
-
- /**
- * A SingleOperation represents a PUT or DELETE operation
- * and the data the operation needs to manipulates.
- */
- static class SingleOperation {
-
- private final Operation opt;
- private final byte[] key;
- private final byte[] value;
-
- SingleOperation(Operation opt, byte[] key, byte[] value) {
- this.opt = opt;
- this.key = Objects.requireNonNull(key, "key cannot be null");
- this.value = value;
- }
-
- public Operation getOpt() {
- return opt;
- }
-
- public byte[] getKey() {
- return key;
- }
-
- public byte[] getValue() {
- return value;
- }
- }
-}
diff --git
a/hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/common/ChecksumData.java
b/hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/common/ChecksumData.java
index aea5c51066..4f6bfa450b 100644
---
a/hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/common/ChecksumData.java
+++
b/hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/common/ChecksumData.java
@@ -21,6 +21,7 @@ import com.google.common.base.Preconditions;
import java.util.Collections;
import java.util.List;
+
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos;
import org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos
@@ -33,7 +34,7 @@ import
org.apache.ratis.thirdparty.com.google.protobuf.ByteString;
*/
public class ChecksumData {
- private ChecksumType type;
+ private final ChecksumType type;
// Checksum will be computed for every bytesPerChecksum number of bytes and
// stored sequentially in checksumList
private final int bytesPerChecksum;
@@ -47,7 +48,7 @@ public class ChecksumData {
List<ByteString> checksums) {
this.type = checksumType;
this.bytesPerChecksum = bytesPerChecksum;
- this.checksums = checksums;
+ this.checksums = Collections.unmodifiableList(checksums);
}
/**
diff --git
a/hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/common/statemachine/StateMachine.java
b/hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/common/statemachine/StateMachine.java
index 97122e6898..4c78ca777f 100644
---
a/hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/common/statemachine/StateMachine.java
+++
b/hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/common/statemachine/StateMachine.java
@@ -18,10 +18,10 @@
package org.apache.hadoop.ozone.common.statemachine;
-import com.google.common.base.Supplier;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
+import com.google.common.collect.ImmutableSet;
import java.util.HashMap;
import java.util.Map;
@@ -33,16 +33,16 @@ import java.util.Set;
* @param <EVENT> events allowed
*/
public class StateMachine<STATE extends Enum<?>, EVENT extends Enum<?>> {
- private STATE initialState;
- private Set<STATE> finalStates;
+ private final STATE initialState;
+ private final ImmutableSet<STATE> finalStates;
private final LoadingCache<EVENT, Map<STATE, STATE>> transitions =
CacheBuilder.newBuilder().build(
- CacheLoader.from((Supplier<Map<STATE, STATE>>) () -> new HashMap()));
+ CacheLoader.from(() -> new HashMap<>()));
public StateMachine(STATE initState, Set<STATE> finalStates) {
this.initialState = initState;
- this.finalStates = finalStates;
+ this.finalStates = finalStates == null ? ImmutableSet.of() :
ImmutableSet.copyOf(finalStates);
}
public STATE getInitialState() {
diff --git
a/hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/container/common/helpers/ChunkInfo.java
b/hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/container/common/helpers/ChunkInfo.java
index cbbbb70278..75408d65a6 100644
---
a/hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/container/common/helpers/ChunkInfo.java
+++
b/hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/container/common/helpers/ChunkInfo.java
@@ -64,7 +64,6 @@ public class ChunkInfo {
*
* @param key - Key Name.
* @param value - Value.
- * @throws IOException
*/
public void addMetadata(String key, String value) throws IOException {
synchronized (this.metadata) {
@@ -80,7 +79,6 @@ public class ChunkInfo {
*
* @param info - Protobuf class
* @return ChunkInfo
- * @throws IOException
*/
public static ChunkInfo getFromProtoBuf(ContainerProtos.ChunkInfo info)
throws IOException {
@@ -182,14 +180,9 @@ public class ChunkInfo {
public void setStripeChecksum(ByteString stripeChecksum) {
this.stripeChecksum = stripeChecksum;
}
-
- /**
- * Returns Metadata associated with this Chunk.
- *
- * @return - Map of Key,values.
- */
- public Map<String, String> getMetadata() {
- return metadata;
+
+ public String getMetadata(String key) {
+ return metadata.get(key);
}
@Override
diff --git
a/hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/util/ShutdownHookManager.java
b/hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/util/ShutdownHookManager.java
index b3ffe59f1d..b3142c579f 100644
---
a/hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/util/ShutdownHookManager.java
+++
b/hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/util/ShutdownHookManager.java
@@ -18,7 +18,6 @@
package org.apache.hadoop.ozone.util;
-import com.google.common.annotations.VisibleForTesting;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
import org.apache.hadoop.hdds.HddsUtils;
import org.apache.hadoop.hdds.conf.ConfigurationSource;
@@ -122,9 +121,7 @@ public final class ShutdownHookManager {
* This is exposed purely for testing: do not invoke it.
* @return the number of shutdown hooks which timed out.
*/
- @InterfaceAudience.Private
- @VisibleForTesting
- int executeShutdown() {
+ private int executeShutdown() {
int timeouts = 0;
for (HookEntry entry: getShutdownHooksInOrder()) {
Future<?> future = EXECUTOR.submit(entry.getHook());
@@ -190,9 +187,7 @@ public final class ShutdownHookManager {
* {@link org.apache.hadoop.ozone.conf.OzoneServiceConfig
* #OZONE_SHUTDOWN_TIMEOUT_MINIMUM}
*/
- @InterfaceAudience.Private
- @VisibleForTesting
- static long getShutdownTimeout(ConfigurationSource conf) {
+ private static long getShutdownTimeout(ConfigurationSource conf) {
long duration = HddsUtils.getShutDownTimeOut(conf);
if (duration < OZONE_SHUTDOWN_TIMEOUT_MINIMUM) {
duration = OZONE_SHUTDOWN_TIMEOUT_MINIMUM;
@@ -204,9 +199,7 @@ public final class ShutdownHookManager {
* Private structure to store ShutdownHook, its priority and timeout
* settings.
*/
- @InterfaceAudience.Private
- @VisibleForTesting
- static class HookEntry {
+ private static class HookEntry {
private final Runnable hook;
private final int priority;
private final long timeout;
@@ -260,12 +253,9 @@ public final class ShutdownHookManager {
private final Set<HookEntry> hooks =
Collections.synchronizedSet(new HashSet<>());
- private AtomicBoolean shutdownInProgress = new AtomicBoolean(false);
+ private final AtomicBoolean shutdownInProgress = new AtomicBoolean(false);
- //private to constructor to ensure singularity
- @VisibleForTesting
- @InterfaceAudience.Private
- ShutdownHookManager() {
+ private ShutdownHookManager() {
}
/**
@@ -274,21 +264,13 @@ public final class ShutdownHookManager {
*
* @return the list of shutdownHooks in order of execution.
*/
- @InterfaceAudience.Private
- @VisibleForTesting
- List<HookEntry > getShutdownHooksInOrder() {
- List<HookEntry > list;
+ private List<HookEntry > getShutdownHooksInOrder() {
+ List<HookEntry> list;
synchronized (hooks) {
- list = new ArrayList<HookEntry>(hooks);
+ list = new ArrayList<>(hooks);
}
- Collections.sort(list, new Comparator< HookEntry >() {
-
- //reversing comparison so highest priority hooks are first
- @Override
- public int compare(HookEntry o1, HookEntry o2) {
- return o2.priority - o1.priority;
- }
- });
+ //reversing comparison so highest priority hooks are first
+ list.sort(Comparator.comparing(HookEntry::getPriority).reversed());
return list;
}
diff --git
a/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/helpers/DatanodeIdYaml.java
b/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/helpers/DatanodeIdYaml.java
index f8acbc7e2d..85de8c08cc 100644
---
a/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/helpers/DatanodeIdYaml.java
+++
b/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/helpers/DatanodeIdYaml.java
@@ -26,6 +26,7 @@ import java.io.Writer;
import java.lang.reflect.Field;
import java.nio.charset.StandardCharsets;
import java.util.LinkedHashMap;
+import java.util.List;
import java.util.Map;
import java.util.UUID;
@@ -238,8 +239,9 @@ public final class DatanodeIdYaml {
= new DatanodeLayoutStorage(conf, datanodeDetails.getUuidString());
Map<String, Integer> portDetails = new LinkedHashMap<>();
- if (!CollectionUtils.isEmpty(datanodeDetails.getPorts())) {
- for (DatanodeDetails.Port port : datanodeDetails.getPorts()) {
+ final List<DatanodeDetails.Port> ports = datanodeDetails.getPorts();
+ if (!CollectionUtils.isEmpty(ports)) {
+ for (DatanodeDetails.Port port : ports) {
Field f = null;
try {
f = DatanodeDetails.Port.Name.class
diff --git
a/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/keyvalue/helpers/ChunkUtils.java
b/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/keyvalue/helpers/ChunkUtils.java
index 7266904139..c3f6ac9212 100644
---
a/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/keyvalue/helpers/ChunkUtils.java
+++
b/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/keyvalue/helpers/ChunkUtils.java
@@ -377,8 +377,8 @@ public final class ChunkUtils {
* @param chunkInfo - Chunk info
* @return true if the user asks for it.
*/
- public static boolean isOverWritePermitted(ChunkInfo chunkInfo) {
- String overWrite =
chunkInfo.getMetadata().get(OzoneConsts.CHUNK_OVERWRITE);
+ private static boolean isOverWritePermitted(ChunkInfo chunkInfo) {
+ String overWrite = chunkInfo.getMetadata(OzoneConsts.CHUNK_OVERWRITE);
return Boolean.parseBoolean(overWrite);
}
diff --git
a/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/node/NodeDecommissionManager.java
b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/node/NodeDecommissionManager.java
index df224d1d44..a593062bcd 100644
---
a/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/node/NodeDecommissionManager.java
+++
b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/node/NodeDecommissionManager.java
@@ -254,12 +254,7 @@ public class NodeDecommissionManager {
* @return True if port is used by the datanode. False otherwise.
*/
private boolean validateDNPortMatch(int port, DatanodeDetails dn) {
- for (DatanodeDetails.Port p : dn.getPorts()) {
- if (p.getValue() == port) {
- return true;
- }
- }
- return false;
+ return dn.hasPort(port);
}
public NodeDecommissionManager(OzoneConfiguration config, NodeManager nm,
ContainerManager cm,
diff --git
a/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/genconf/GenerateOzoneRequiredConfigurations.java
b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/genconf/GenerateOzoneRequiredConfigurations.java
index cfdc924486..927e9186ff 100644
---
a/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/genconf/GenerateOzoneRequiredConfigurations.java
+++
b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/genconf/GenerateOzoneRequiredConfigurations.java
@@ -159,8 +159,7 @@ public final class GenerateOzoneRequiredConfigurations
extends GenericCli {
}
OzoneConfiguration.XMLConfiguration generatedConfig =
- new OzoneConfiguration.XMLConfiguration();
- generatedConfig.setProperties(requiredProperties);
+ new OzoneConfiguration.XMLConfiguration(requiredProperties);
File output = new File(path, "ozone-site.xml");
if (output.createNewFile()) {
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]