This is an automated email from the ASF dual-hosted git repository.
adoroszlai 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 3964ece656 HDDS-8744. Clean up checked functional interfaces (#4816)
3964ece656 is described below
commit 3964ece6561b0402165c4158d51b65e9d82c8860
Author: Doroszlai, Attila <[email protected]>
AuthorDate: Fri Jun 2 21:43:49 2023 +0200
HDDS-8744. Clean up checked functional interfaces (#4816)
---
.../apache/hadoop/hdds/scm/XceiverClientGrpc.java | 18 ++++-----
.../hadoop/hdds/scm/storage/BlockInputStream.java | 5 ++-
.../hadoop/hdds/scm/storage/ChunkInputStream.java | 23 ++++-------
.../java/org/apache/hadoop/hdds/HddsUtils.java | 2 +-
.../apache/hadoop/hdds/scm/XceiverClientSpi.java | 25 ++++++------
.../hadoop/hdds/scm/storage/CheckedBiFunction.java | 31 ---------------
.../hdds/scm/storage/ContainerProtocolCalls.java | 46 +++++++---------------
.../org/apache/hadoop/hdds/utils/Scheduler.java | 4 +-
.../org/apache/hadoop/util/CheckedRunnable.java | 28 -------------
.../org/apache/hadoop/util/CheckedSupplier.java | 29 --------------
.../java/org/apache/hadoop/util/MetricUtil.java | 2 +
.../scm/container/ContainerStateManagerImpl.java | 14 +++----
.../apache/hadoop/hdds/scm/ha/CheckedConsumer.java | 39 ------------------
.../apache/hadoop/hdds/scm/ha/CheckedFunction.java | 32 ---------------
.../apache/hadoop/hdds/scm/ha/ExecutionUtil.java | 19 ++++-----
.../hadoop/ozone/MiniOzoneHAClusterImpl.java | 4 +-
.../transport/server/ratis/TestCSMMetrics.java | 29 ++++++--------
.../container/server/TestContainerServer.java | 13 ++----
.../server/TestSecureContainerServer.java | 8 +---
.../om/request/volume/acl/OMVolumeAclRequest.java | 38 +++++++++---------
.../request/volume/acl/OMVolumeAddAclRequest.java | 17 +++-----
.../volume/acl/OMVolumeRemoveAclRequest.java | 17 +++-----
.../request/volume/acl/OMVolumeSetAclRequest.java | 17 +++-----
23 files changed, 126 insertions(+), 334 deletions(-)
diff --git
a/hadoop-hdds/client/src/main/java/org/apache/hadoop/hdds/scm/XceiverClientGrpc.java
b/hadoop-hdds/client/src/main/java/org/apache/hadoop/hdds/scm/XceiverClientGrpc.java
index 1fee58c3b4..332f667816 100644
---
a/hadoop-hdds/client/src/main/java/org/apache/hadoop/hdds/scm/XceiverClientGrpc.java
+++
b/hadoop-hdds/client/src/main/java/org/apache/hadoop/hdds/scm/XceiverClientGrpc.java
@@ -46,7 +46,6 @@ import
org.apache.hadoop.hdds.protocol.datanode.proto.XceiverClientProtocolServi
import org.apache.hadoop.hdds.protocol.proto.HddsProtos;
import org.apache.hadoop.hdds.scm.client.HddsClientUtils;
import org.apache.hadoop.hdds.scm.pipeline.Pipeline;
-import org.apache.hadoop.hdds.scm.storage.CheckedBiFunction;
import org.apache.hadoop.hdds.security.exception.SCMSecurityException;
import org.apache.hadoop.hdds.security.x509.SecurityConfig;
import org.apache.hadoop.hdds.tracing.GrpcClientInterceptor;
@@ -85,7 +84,8 @@ import static
org.apache.hadoop.hdds.HddsUtils.processForDebug;
* how it works, and how it is integrated with the Ozone client.
*/
public class XceiverClientGrpc extends XceiverClientSpi {
- static final Logger LOG = LoggerFactory.getLogger(XceiverClientGrpc.class);
+ private static final Logger LOG =
+ LoggerFactory.getLogger(XceiverClientGrpc.class);
private final Pipeline pipeline;
private final ConfigurationSource config;
private final Map<UUID, XceiverClientProtocolServiceStub> asyncStubs;
@@ -235,7 +235,7 @@ public class XceiverClientGrpc extends XceiverClientSpi {
* and the method waits to finish all ongoing communication.
*
* Note: the method wait 1 hour per channel tops and if that is not enough
- * to finish ongoing communication, then interrupts the connection anyways.
+ * to finish ongoing communication, then interrupts the connection anyway.
*/
@Override
public synchronized void close() {
@@ -317,7 +317,7 @@ public class XceiverClientGrpc extends XceiverClientSpi {
@Override
public ContainerCommandResponseProto sendCommand(
- ContainerCommandRequestProto request, List<CheckedBiFunction> validators)
+ ContainerCommandRequestProto request, List<Validator> validators)
throws IOException {
try {
XceiverClientReply reply;
@@ -335,7 +335,7 @@ public class XceiverClientGrpc extends XceiverClientSpi {
}
private XceiverClientReply sendCommandWithTraceIDAndRetry(
- ContainerCommandRequestProto request, List<CheckedBiFunction> validators)
+ ContainerCommandRequestProto request, List<Validator> validators)
throws IOException {
String spanName = "XceiverClientGrpc." + request.getCmdType().name();
@@ -352,13 +352,13 @@ public class XceiverClientGrpc extends XceiverClientSpi {
}
private XceiverClientReply sendCommandWithRetry(
- ContainerCommandRequestProto request, List<CheckedBiFunction> validators)
+ ContainerCommandRequestProto request, List<Validator> validators)
throws IOException {
ContainerCommandResponseProto responseProto = null;
IOException ioException = null;
// In case of an exception or an error, we will try to read from the
- // datanodes in the pipeline in a round robin fashion.
+ // datanodes in the pipeline in a round-robin fashion.
XceiverClientReply reply = new XceiverClientReply(null);
List<DatanodeDetails> datanodeList = null;
@@ -406,8 +406,8 @@ public class XceiverClientGrpc extends XceiverClientSpi {
reply.addDatanode(dn);
responseProto = sendCommandAsync(request, dn).getResponse().get();
if (validators != null && !validators.isEmpty()) {
- for (CheckedBiFunction validator : validators) {
- validator.apply(request, responseProto);
+ for (Validator validator : validators) {
+ validator.accept(request, responseProto);
}
}
if (request.getCmdType() == ContainerProtos.Type.GetBlock) {
diff --git
a/hadoop-hdds/client/src/main/java/org/apache/hadoop/hdds/scm/storage/BlockInputStream.java
b/hadoop-hdds/client/src/main/java/org/apache/hadoop/hdds/scm/storage/BlockInputStream.java
index 8ba7200d6d..9a256ff991 100644
---
a/hadoop-hdds/client/src/main/java/org/apache/hadoop/hdds/scm/storage/BlockInputStream.java
+++
b/hadoop-hdds/client/src/main/java/org/apache/hadoop/hdds/scm/storage/BlockInputStream.java
@@ -38,6 +38,7 @@ import
org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.GetBlockRe
import org.apache.hadoop.hdds.protocol.proto.HddsProtos;
import org.apache.hadoop.hdds.scm.XceiverClientFactory;
import org.apache.hadoop.hdds.scm.XceiverClientSpi;
+import org.apache.hadoop.hdds.scm.XceiverClientSpi.Validator;
import org.apache.hadoop.hdds.scm.client.HddsClientUtils;
import
org.apache.hadoop.hdds.scm.container.common.helpers.StorageContainerException;
import org.apache.hadoop.hdds.scm.pipeline.Pipeline;
@@ -259,11 +260,11 @@ public class BlockInputStream extends
BlockExtendedInputStream {
}
}
- private static final List<CheckedBiFunction> VALIDATORS
+ private static final List<Validator> VALIDATORS
= ContainerProtocolCalls.toValidatorList(
(request, response) -> validate(response));
- static void validate(ContainerCommandResponseProto response)
+ private static void validate(ContainerCommandResponseProto response)
throws IOException {
if (!response.hasGetBlock()) {
throw new IllegalArgumentException("Not GetBlock: response=" + response);
diff --git
a/hadoop-hdds/client/src/main/java/org/apache/hadoop/hdds/scm/storage/ChunkInputStream.java
b/hadoop-hdds/client/src/main/java/org/apache/hadoop/hdds/scm/storage/ChunkInputStream.java
index 97ff33915a..fb9e345586 100644
---
a/hadoop-hdds/client/src/main/java/org/apache/hadoop/hdds/scm/storage/ChunkInputStream.java
+++
b/hadoop-hdds/client/src/main/java/org/apache/hadoop/hdds/scm/storage/ChunkInputStream.java
@@ -26,12 +26,11 @@ import org.apache.hadoop.fs.ByteBufferReadable;
import org.apache.hadoop.fs.CanUnbuffer;
import org.apache.hadoop.fs.Seekable;
import org.apache.hadoop.hdds.client.BlockID;
-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.datanode.proto.ContainerProtos.ChunkInfo;
import
org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.ReadChunkResponseProto;
import org.apache.hadoop.hdds.scm.XceiverClientFactory;
import org.apache.hadoop.hdds.scm.XceiverClientSpi;
+import org.apache.hadoop.hdds.scm.XceiverClientSpi.Validator;
import org.apache.hadoop.hdds.scm.pipeline.Pipeline;
import org.apache.hadoop.ozone.common.Checksum;
import org.apache.hadoop.ozone.common.ChecksumData;
@@ -48,6 +47,7 @@ import java.nio.ByteBuffer;
import java.util.Arrays;
import java.util.List;
import java.util.function.Supplier;
+
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -275,7 +275,7 @@ public class ChunkInputStream extends InputStream
}
@Override
- public boolean seekToNewSource(long targetPos) throws IOException {
+ public boolean seekToNewSource(long targetPos) {
return false;
}
@@ -324,7 +324,7 @@ public class ChunkInputStream extends InputStream
if (buffersHaveData()) {
// Data is available from buffers
ByteBuffer bb = buffers[bufferIndex];
- return len > bb.remaining() ? bb.remaining() : len;
+ return Math.min(len, bb.remaining());
} else if (dataRemainingInChunk()) {
// There is more data in the chunk stream which has not
// been read into the buffers yet.
@@ -424,7 +424,7 @@ public class ChunkInputStream extends InputStream
throws IOException {
ReadChunkResponseProto readChunkResponse;
- List<CheckedBiFunction> validators =
+ List<Validator> validators =
ContainerProtocolCalls.toValidatorList(validator);
readChunkResponse = ContainerProtocolCalls.readChunk(xceiverClient,
@@ -443,8 +443,7 @@ public class ChunkInputStream extends InputStream
}
}
- private CheckedBiFunction<ContainerCommandRequestProto,
- ContainerCommandResponseProto, IOException> validator =
+ private final Validator validator =
(request, response) -> {
final ChunkInfo reqChunkInfo =
request.getReadChunk().getChunkData();
@@ -642,15 +641,7 @@ public class ChunkInputStream extends InputStream
* Check if current buffer had been read till the end.
*/
private boolean bufferEOF() {
- if (!allocated) {
- // Chunk data has not been read yet
- return false;
- }
-
- if (!buffers[bufferIndex].hasRemaining()) {
- return true;
- }
- return false;
+ return allocated && !buffers[bufferIndex].hasRemaining();
}
/**
diff --git
a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/HddsUtils.java
b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/HddsUtils.java
index c26ab40368..a24a0b7c05 100644
--- a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/HddsUtils.java
+++ b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/HddsUtils.java
@@ -83,10 +83,10 @@ import static
org.apache.hadoop.hdds.scm.ScmConfigKeys.OZONE_SCM_NAMES;
import org.apache.hadoop.security.AccessControlException;
import org.apache.hadoop.security.token.SecretManager;
-import org.apache.hadoop.util.CheckedSupplier;
import org.apache.ratis.thirdparty.com.google.protobuf.ByteString;
import org.apache.ratis.util.SizeInBytes;
import org.apache.hadoop.ozone.conf.OzoneServiceConfig;
+import org.apache.ratis.util.function.CheckedSupplier;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
diff --git
a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/scm/XceiverClientSpi.java
b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/scm/XceiverClientSpi.java
index 79c71a3217..24137d762d 100644
---
a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/scm/XceiverClientSpi.java
+++
b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/scm/XceiverClientSpi.java
@@ -32,15 +32,24 @@ import
org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.ContainerC
import
org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.ContainerCommandResponseProto;
import org.apache.hadoop.hdds.protocol.proto.HddsProtos;
import org.apache.hadoop.hdds.scm.pipeline.Pipeline;
-import org.apache.hadoop.hdds.scm.storage.CheckedBiFunction;
import com.google.common.annotations.VisibleForTesting;
+import org.apache.ratis.util.function.CheckedBiConsumer;
/**
* A Client for the storageContainer protocol.
*/
public abstract class XceiverClientSpi implements Closeable {
+ /**
+ * Validator for container command request/response.
+ */
+ public interface Validator extends
+ CheckedBiConsumer<ContainerCommandRequestProto,
+ ContainerCommandResponseProto, IOException> {
+ // just a shortcut to avoid having to repeat long list of generic
parameters
+ }
+
private final AtomicInteger referenceCount;
private boolean isEvicted;
@@ -103,7 +112,6 @@ public abstract class XceiverClientSpi implements Closeable
{
* Sends a given command to server and gets the reply back.
* @param request Request
* @return Response to the command
- * @throws IOException
*/
public ContainerCommandResponseProto sendCommand(
ContainerCommandRequestProto request) throws IOException {
@@ -126,17 +134,17 @@ public abstract class XceiverClientSpi implements
Closeable {
* @param request Request
* @param validators functions to validate the response
* @return Response to the command
- * @throws IOException
*/
public ContainerCommandResponseProto sendCommand(
- ContainerCommandRequestProto request, List<CheckedBiFunction> validators)
+ ContainerCommandRequestProto request,
+ List<Validator> validators)
throws IOException {
try {
XceiverClientReply reply;
reply = sendCommandAsync(request);
ContainerCommandResponseProto responseProto = reply.getResponse().get();
- for (CheckedBiFunction function : validators) {
- function.apply(request, responseProto);
+ for (Validator function : validators) {
+ function.accept(request, responseProto);
}
return responseProto;
} catch (InterruptedException e) {
@@ -158,7 +166,6 @@ public abstract class XceiverClientSpi implements Closeable
{
*
* @param request Request
* @return Response to the command
- * @throws IOException
*/
public abstract XceiverClientReply
sendCommandAsync(ContainerCommandRequestProto request)
@@ -176,10 +183,6 @@ public abstract class XceiverClientSpi implements
Closeable {
* @param index index to watch for
* @return reply containing the min commit index replicated to all or
majority
* servers in case of a failure
- * @throws InterruptedException
- * @throws ExecutionException
- * @throws TimeoutException
- * @throws IOException
*/
public abstract XceiverClientReply watchForCommit(long index)
throws InterruptedException, ExecutionException, TimeoutException,
diff --git
a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/scm/storage/CheckedBiFunction.java
b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/scm/storage/CheckedBiFunction.java
deleted file mode 100644
index df84859ab0..0000000000
---
a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/scm/storage/CheckedBiFunction.java
+++ /dev/null
@@ -1,31 +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.scm.storage;
-
-
-import java.io.IOException;
-
-/**
- * Defines a functional interface having two inputs which throws IOException.
- */
-@FunctionalInterface
-public interface CheckedBiFunction<LEFT, RIGHT,
- THROWABLE extends IOException> {
- void apply(LEFT left, RIGHT right) throws THROWABLE;
-}
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 d3c4de22f3..2932fdafbf 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
@@ -58,6 +58,7 @@ import
org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.Type;
import
org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.WriteChunkRequestProto;
import org.apache.hadoop.hdds.scm.XceiverClientReply;
import org.apache.hadoop.hdds.scm.XceiverClientSpi;
+import org.apache.hadoop.hdds.scm.XceiverClientSpi.Validator;
import
org.apache.hadoop.hdds.scm.container.common.helpers.BlockNotCommittedException;
import
org.apache.hadoop.hdds.scm.container.common.helpers.ContainerNotOpenException;
import
org.apache.hadoop.hdds.scm.container.common.helpers.StorageContainerException;
@@ -73,6 +74,8 @@ import org.apache.ratis.util.function.CheckedFunction;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import static java.util.Collections.singletonList;
+
/**
* Implementation of all container protocol calls performed by Container
* clients.
@@ -164,7 +167,7 @@ public final class ContainerProtocolCalls {
* @throws IOException if there is an I/O error while performing the call
*/
public static GetBlockResponseProto getBlock(XceiverClientSpi xceiverClient,
- List<CheckedBiFunction> validators,
+ List<Validator> validators,
DatanodeBlockID datanodeBlockID,
Token<? extends TokenIdentifier> token) throws IOException {
GetBlockRequestProto.Builder readBlockRequest = GetBlockRequestProto
@@ -196,7 +199,7 @@ public final class ContainerProtocolCalls {
}
private static GetBlockResponseProto getBlock(XceiverClientSpi xceiverClient,
- List<CheckedBiFunction> validators,
+ List<Validator> validators,
ContainerCommandRequestProto.Builder builder,
DatanodeDetails datanode) throws IOException {
final ContainerCommandRequestProto request = builder
@@ -279,8 +282,6 @@ public final class ContainerProtocolCalls {
* @param token a token for this block (may be null)
* @return putBlockResponse
* @throws IOException if there is an error while performing the call
- * @throws InterruptedException
- * @throws ExecutionException
*/
public static XceiverClientReply putBlockAsync(XceiverClientSpi
xceiverClient,
BlockData containerBlockData, boolean eof,
@@ -323,7 +324,7 @@ public final class ContainerProtocolCalls {
*/
public static ContainerProtos.ReadChunkResponseProto readChunk(
XceiverClientSpi xceiverClient, ChunkInfo chunk, BlockID blockID,
- List<CheckedBiFunction> validators,
+ List<Validator> validators,
Token<? extends TokenIdentifier> token) throws IOException {
ReadChunkRequestProto.Builder readChunkRequest =
ReadChunkRequestProto.newBuilder()
@@ -346,7 +347,7 @@ public final class ContainerProtocolCalls {
private static ContainerProtos.ReadChunkResponseProto readChunk(
XceiverClientSpi xceiverClient, ChunkInfo chunk, BlockID blockID,
- List<CheckedBiFunction> validators,
+ List<Validator> validators,
ContainerCommandRequestProto.Builder builder,
DatanodeDetails d) throws IOException {
final ContainerCommandRequestProto request = builder
@@ -463,7 +464,6 @@ public final class ContainerProtocolCalls {
* @param data - Data to be written into the container.
* @param token a token for this block (may be null)
* @return container protocol writeSmallFile response
- * @throws IOException
*/
public static PutSmallFileResponseProto writeSmallFile(
XceiverClientSpi client, BlockID blockID, byte[] data,
@@ -521,7 +521,6 @@ public final class ContainerProtocolCalls {
* @param containerID - ID of container
* @param encodedToken - encodedToken if security is enabled
* @param replicaIndex - index position of the container replica
- * @throws IOException
*/
@InterfaceStability.Evolving
public static void createRecoveringContainer(XceiverClientSpi client,
@@ -536,7 +535,6 @@ public final class ContainerProtocolCalls {
* @param client - client
* @param containerID - ID of container
* @param encodedToken - encodedToken if security is enabled
- * @throws IOException
*/
public static void createContainer(XceiverClientSpi client, long containerID,
String encodedToken) throws IOException {
@@ -549,7 +547,6 @@ public final class ContainerProtocolCalls {
* @param encodedToken - encodedToken if security is enabled
* @param state - state of the container
* @param replicaIndex - index position of the container replica
- * @throws IOException
*/
public static void createContainer(XceiverClientSpi client,
long containerID, String encodedToken,
@@ -582,10 +579,8 @@ public final class ContainerProtocolCalls {
/**
* Deletes a container from a pipeline.
*
- * @param client
* @param force whether or not to forcibly delete the container.
* @param encodedToken - encodedToken if security is enabled
- * @throws IOException
*/
public static void deleteContainer(XceiverClientSpi client, long containerID,
boolean force, String encodedToken) throws IOException {
@@ -609,10 +604,7 @@ public final class ContainerProtocolCalls {
/**
* Close a container.
*
- * @param client
- * @param containerID
* @param encodedToken - encodedToken if security is enabled
- * @throws IOException
*/
public static void closeContainer(XceiverClientSpi client,
long containerID, String encodedToken)
@@ -636,7 +628,6 @@ public final class ContainerProtocolCalls {
*
* @param client - client
* @param encodedToken - encodedToken if security is enabled
- * @throws IOException
*/
public static ReadContainerResponseProto readContainer(
XceiverClientSpi client, long containerID, String encodedToken)
@@ -661,11 +652,9 @@ public final class ContainerProtocolCalls {
/**
* Reads the data given the blockID.
*
- * @param client
* @param blockID - ID of the block
* @param token a token for this block (may be null)
* @return GetSmallFileResponseProto
- * @throws IOException
*/
public static GetSmallFileResponseProto readSmallFile(XceiverClientSpi
client,
BlockID blockID,
@@ -718,25 +707,20 @@ public final class ContainerProtocolCalls {
response.getMessage(), response.getResult());
}
- public static List<CheckedBiFunction> getValidatorList() {
+ public static List<Validator> getValidatorList() {
return VALIDATORS;
}
- private static final List<CheckedBiFunction> VALIDATORS = createValidators();
+ private static final List<Validator> VALIDATORS = createValidators();
- private static List<CheckedBiFunction> createValidators() {
- CheckedBiFunction<ContainerProtos.ContainerCommandRequestProto,
- ContainerProtos.ContainerCommandResponseProto, IOException>
- validator = (request, response) -> validateContainerResponse(response);
- return Collections.singletonList(validator);
+ private static List<Validator> createValidators() {
+ return singletonList(
+ (request, response) -> validateContainerResponse(response));
}
- public static List<CheckedBiFunction> toValidatorList(
- CheckedBiFunction<ContainerCommandRequestProto,
- ContainerCommandResponseProto, IOException> validator) {
- final List<CheckedBiFunction> defaults
- = ContainerProtocolCalls.getValidatorList();
- final List<CheckedBiFunction> validators
+ public static List<Validator> toValidatorList(Validator validator) {
+ final List<Validator> defaults = getValidatorList();
+ final List<Validator> validators
= new ArrayList<>(defaults.size() + 1);
validators.addAll(defaults);
validators.add(validator);
diff --git
a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/utils/Scheduler.java
b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/utils/Scheduler.java
index 829e253471..6b17c340cf 100644
---
a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/utils/Scheduler.java
+++
b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/utils/Scheduler.java
@@ -38,7 +38,7 @@ public class Scheduler {
private volatile boolean isClosed;
- private String threadName;
+ private final String threadName;
/**
* Creates a ScheduledExecutorService based on input arguments.
@@ -63,7 +63,7 @@ public class Scheduler {
scheduledExecutorService.schedule(runnable, delay, timeUnit);
}
- public void schedule(CheckedRunnable runnable, long delay,
+ public void schedule(CheckedRunnable<?> runnable, long delay,
TimeUnit timeUnit, Logger logger, String errMsg) {
scheduledExecutorService.schedule(() -> {
try {
diff --git
a/hadoop-hdds/common/src/main/java/org/apache/hadoop/util/CheckedRunnable.java
b/hadoop-hdds/common/src/main/java/org/apache/hadoop/util/CheckedRunnable.java
deleted file mode 100644
index bc1ab873fb..0000000000
---
a/hadoop-hdds/common/src/main/java/org/apache/hadoop/util/CheckedRunnable.java
+++ /dev/null
@@ -1,28 +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.util;
-
-import java.io.IOException;
-
-/**
- * This presents a block of code with a possibility of throwing an IOException.
- */
-@FunctionalInterface
-public interface CheckedRunnable<E extends IOException> {
- void run() throws E;
-}
diff --git
a/hadoop-hdds/common/src/main/java/org/apache/hadoop/util/CheckedSupplier.java
b/hadoop-hdds/common/src/main/java/org/apache/hadoop/util/CheckedSupplier.java
deleted file mode 100644
index 1a2bd48e7b..0000000000
---
a/hadoop-hdds/common/src/main/java/org/apache/hadoop/util/CheckedSupplier.java
+++ /dev/null
@@ -1,29 +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.util;
-
-import java.io.IOException;
-
-/**
- * Similar to {@link java.util.function.Supplier}, this class presents a block
- * of code generating a value with a possibility of throwing an IOException.
- */
-@FunctionalInterface
-public interface CheckedSupplier<T, E extends IOException> {
- T get() throws E;
-}
diff --git
a/hadoop-hdds/common/src/main/java/org/apache/hadoop/util/MetricUtil.java
b/hadoop-hdds/common/src/main/java/org/apache/hadoop/util/MetricUtil.java
index 029158e066..5f791c17c4 100644
--- a/hadoop-hdds/common/src/main/java/org/apache/hadoop/util/MetricUtil.java
+++ b/hadoop-hdds/common/src/main/java/org/apache/hadoop/util/MetricUtil.java
@@ -18,6 +18,8 @@
package org.apache.hadoop.util;
import org.apache.hadoop.metrics2.lib.MutableRate;
+import org.apache.ratis.util.function.CheckedRunnable;
+import org.apache.ratis.util.function.CheckedSupplier;
import java.io.IOException;
import java.util.function.Consumer;
diff --git
a/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/ContainerStateManagerImpl.java
b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/ContainerStateManagerImpl.java
index f79542885a..e978c1b8f5 100644
---
a/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/ContainerStateManagerImpl.java
+++
b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/ContainerStateManagerImpl.java
@@ -41,7 +41,6 @@ import org.apache.hadoop.hdds.scm.ScmConfigKeys;
import
org.apache.hadoop.hdds.scm.container.replication.ContainerReplicaPendingOps;
import org.apache.hadoop.hdds.scm.container.states.ContainerState;
import org.apache.hadoop.hdds.scm.container.states.ContainerStateMap;
-import org.apache.hadoop.hdds.scm.ha.CheckedConsumer;
import org.apache.hadoop.hdds.scm.ha.ExecutionUtil;
import org.apache.hadoop.hdds.scm.ha.SCMHAInvocationHandler;
import org.apache.hadoop.hdds.scm.ha.SCMRatisServer;
@@ -58,6 +57,7 @@ import org.apache.hadoop.ozone.lock.LockManager;
import org.apache.hadoop.hdds.conf.ConfigurationSource;
import org.apache.hadoop.hdds.conf.OzoneConfiguration;
+import org.apache.ratis.util.function.CheckedConsumer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -86,8 +86,6 @@ import static
org.apache.hadoop.hdds.protocol.proto.HddsProtos.LifeCycleState.DE
public final class ContainerStateManagerImpl
implements ContainerStateManager {
- private ConfigurationSource confSrc;
-
private final LockManager<ContainerID> lockManager;
/**
@@ -157,7 +155,7 @@ public final class ContainerStateManagerImpl
final Table<ContainerID, ContainerInfo> containerStore,
final DBTransactionBuffer buffer,
final ContainerReplicaPendingOps pendingOps) throws IOException {
- this.confSrc = OzoneConfiguration.of(conf);
+ ConfigurationSource confSrc = OzoneConfiguration.of(conf);
this.pipelineManager = pipelineManager;
this.containerStore = containerStore;
this.stateMachine = newStateMachine();
@@ -385,8 +383,8 @@ public final class ContainerStateManagerImpl
transactionBuffer.addToBuffer(containerStore, id, oldInfo);
containers.updateState(id, newState, oldState);
}).execute();
- containerStateChangeActions.getOrDefault(event, info -> {
- }).execute(oldInfo);
+ containerStateChangeActions.getOrDefault(event, info -> { })
+ .accept(oldInfo);
}
}
} finally {
@@ -485,8 +483,8 @@ public final class ContainerStateManagerImpl
// space in the headset, we need to pass true to deal with the
// situation that we have a lone container that has space. That is we
// ignored the last used container under the assumption we can find
- // other containers with space, but if have a single container that is
- // not true. Hence we need to include the last used container as the
+ // other containers with space, but if we have a single container that is
+ // not true. Hence, we need to include the last used container as the
// last element in the sorted set.
resultSet = containerIDs.headSet(lastID, true);
diff --git
a/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/ha/CheckedConsumer.java
b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/ha/CheckedConsumer.java
deleted file mode 100644
index f6a4e3e9e1..0000000000
---
a/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/ha/CheckedConsumer.java
+++ /dev/null
@@ -1,39 +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
- * <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.ha;
-
-
-/**
- * Represents an operation that accepts a single input argument and returns no
- * result.
- *
- * @param <T> the type of the input to the operation
- *
- * @since 1.8
- */
-@FunctionalInterface
-public interface CheckedConsumer<T, E extends Throwable> {
-
- /**
- * Performs the operation on the given argument.
- *
- * @param t the input argument
- * @throws E in case the exception during execution
- */
- void execute(T t) throws E;
-}
diff --git
a/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/ha/CheckedFunction.java
b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/ha/CheckedFunction.java
deleted file mode 100644
index da8a9a418f..0000000000
---
a/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/ha/CheckedFunction.java
+++ /dev/null
@@ -1,32 +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
- * <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.ha;
-
-/**
- * Represents a function that accepts no argument and returns no result.
- */
-@FunctionalInterface
-public interface CheckedFunction<E extends Throwable> {
-
- /**
- * Executes the given logic.
- *
- * @throws E in case the exception during execution
- */
- void execute() throws E;
-}
diff --git
a/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/ha/ExecutionUtil.java
b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/ha/ExecutionUtil.java
index 24fbfb8e07..e6359ba4e1 100644
---
a/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/ha/ExecutionUtil.java
+++
b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/ha/ExecutionUtil.java
@@ -17,6 +17,7 @@
package org.apache.hadoop.hdds.scm.ha;
+import org.apache.ratis.util.function.CheckedRunnable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -31,23 +32,23 @@ public final class ExecutionUtil<E extends Throwable> {
private static final Logger LOG = LoggerFactory.getLogger(
ExecutionUtil.class);
- private final CheckedFunction<E> fn;
+ private final CheckedRunnable<E> fn;
- private CheckedFunction<E> onException;
+ private CheckedRunnable<E> onException;
private volatile boolean completed;
- private ExecutionUtil(final CheckedFunction<E> fn) {
+ private ExecutionUtil(final CheckedRunnable<E> fn) {
this.fn = fn;
this.completed = false;
}
- public static<E extends Exception> ExecutionUtil<E> create(
- CheckedFunction<E> tryBlock) {
+ public static <E extends Exception> ExecutionUtil<E> create(
+ CheckedRunnable<E> tryBlock) {
return new ExecutionUtil<>(tryBlock);
}
- public ExecutionUtil<E> onException(CheckedFunction<E> catchBlock) {
+ public ExecutionUtil<E> onException(CheckedRunnable<E> catchBlock) {
onException = catchBlock;
return this;
}
@@ -56,14 +57,14 @@ public final class ExecutionUtil<E extends Throwable> {
if (!completed) {
completed = true;
try {
- fn.execute();
+ fn.run();
} catch (Exception ex) {
try {
- onException.execute();
+ onException.run();
} catch (Exception error) {
LOG.warn("Got error while doing clean-up.", error);
}
- throw (E) ex;
+ throw ex;
}
}
}
diff --git
a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/MiniOzoneHAClusterImpl.java
b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/MiniOzoneHAClusterImpl.java
index 3cb2b22447..91ff85e1af 100644
---
a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/MiniOzoneHAClusterImpl.java
+++
b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/MiniOzoneHAClusterImpl.java
@@ -27,7 +27,6 @@ import org.apache.hadoop.hdds.conf.ConfigurationTarget;
import org.apache.hadoop.hdds.conf.OzoneConfiguration;
import org.apache.hadoop.hdds.scm.ScmConfigKeys;
import org.apache.hadoop.hdds.scm.HddsTestUtils;
-import org.apache.hadoop.hdds.scm.ha.CheckedConsumer;
import org.apache.hadoop.hdds.scm.safemode.HealthyPipelineSafeModeRule;
import org.apache.hadoop.hdds.scm.server.SCMConfigurator;
import org.apache.hadoop.hdds.scm.server.StorageContainerManager;
@@ -42,6 +41,7 @@ import
org.apache.hadoop.ozone.om.ratis.OzoneManagerRatisServer;
import org.apache.hadoop.ozone.recon.ReconServer;
import
org.apache.hadoop.security.authentication.client.AuthenticationException;
import org.apache.ozone.test.GenericTestUtils;
+import org.apache.ratis.util.function.CheckedConsumer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -976,7 +976,7 @@ public class MiniOzoneHAClusterImpl extends
MiniOzoneClusterImpl {
if (!inactiveServices.contains(service)) {
throw new IOException(serviceName + " is already active.");
} else {
- serviceStarter.execute(service);
+ serviceStarter.accept(service);
activeServices.add(service);
inactiveServices.remove(service);
}
diff --git
a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/container/common/transport/server/ratis/TestCSMMetrics.java
b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/container/common/transport/server/ratis/TestCSMMetrics.java
index b3d6589cff..cfc10ac345 100644
---
a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/container/common/transport/server/ratis/TestCSMMetrics.java
+++
b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/container/common/transport/server/ratis/TestCSMMetrics.java
@@ -37,7 +37,6 @@ import
org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos
.ContainerCommandResponseProto;
import org.apache.hadoop.hdds.scm.XceiverClientRatis;
import org.apache.hadoop.hdds.scm.XceiverClientSpi;
-import
org.apache.hadoop.hdds.scm.container.common.helpers.StorageContainerException;
import org.apache.hadoop.hdds.scm.pipeline.MockPipeline;
import org.apache.hadoop.hdds.scm.pipeline.Pipeline;
import org.apache.hadoop.metrics2.MetricsRecordBuilder;
@@ -54,6 +53,7 @@ import org.apache.ozone.test.GenericTestUtils;
import org.apache.hadoop.hdds.conf.OzoneConfiguration;
import static org.apache.ratis.rpc.SupportedRpcType.GRPC;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import org.apache.ratis.protocol.RaftGroupId;
@@ -63,6 +63,7 @@ import org.apache.ratis.util.function.CheckedBiConsumer;
import java.util.Map;
import java.util.function.BiConsumer;
+import org.apache.ratis.util.function.CheckedBiFunction;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.Assert;
@@ -71,13 +72,9 @@ import org.junit.Assert;
* This class tests the metrics of ContainerStateMachine.
*/
public class TestCSMMetrics {
- static final String TEST_DIR =
+ private static final String TEST_DIR =
GenericTestUtils.getTestDir("dfs").getAbsolutePath()
+ File.separator;
- @FunctionalInterface
- interface CheckedBiFunction<LEFT, RIGHT, OUT, THROWABLE extends Throwable> {
- OUT apply(LEFT left, RIGHT right) throws THROWABLE;
- }
@BeforeClass
public static void setup() {
@@ -96,9 +93,9 @@ public class TestCSMMetrics {
static void runContainerStateMachineMetrics(
int numDatanodes,
BiConsumer<Pipeline, OzoneConfiguration> initConf,
- TestCSMMetrics.CheckedBiFunction<Pipeline, OzoneConfiguration,
- XceiverClientSpi, IOException> createClient,
- TestCSMMetrics.CheckedBiFunction<DatanodeDetails, OzoneConfiguration,
+ CheckedBiFunction<Pipeline, OzoneConfiguration,
+ XceiverClientSpi, IOException> createClient,
+ CheckedBiFunction<DatanodeDetails, OzoneConfiguration,
XceiverServerSpi, IOException> createServer,
CheckedBiConsumer<DatanodeDetails, Pipeline, IOException> initServer)
throws Exception {
@@ -121,7 +118,7 @@ public class TestCSMMetrics {
// Before Read Chunk/Write Chunk
MetricsRecordBuilder metric = getMetrics(CSMMetrics.SOURCE_NAME +
- RaftGroupId.valueOf(pipeline.getId().getId()).toString());
+ RaftGroupId.valueOf(pipeline.getId().getId()));
assertCounter("NumWriteStateMachineOps", 0L, metric);
assertCounter("NumReadStateMachineOps", 0L, metric);
assertCounter("NumApplyTransactionOps", 0L, metric);
@@ -132,10 +129,10 @@ public class TestCSMMetrics {
assertCounter("WriteChunkMsNumOps", 0L, metric);
double applyTransactionLatency = getDoubleGauge(
"ApplyTransactionNsAvgTime", metric);
- assertTrue(applyTransactionLatency == 0.0);
+ assertEquals(0.0, applyTransactionLatency, 0.0);
double writeStateMachineLatency = getDoubleGauge(
"WriteStateMachineDataNsAvgTime", metric);
- assertTrue(writeStateMachineLatency == 0.0);
+ assertEquals(0.0, writeStateMachineLatency, 0.0);
// Write Chunk
BlockID blockID = ContainerTestHelper.getTestBlockID(ContainerTestHelper.
@@ -149,7 +146,7 @@ public class TestCSMMetrics {
response.getResult());
metric = getMetrics(CSMMetrics.SOURCE_NAME +
- RaftGroupId.valueOf(pipeline.getId().getId()).toString());
+ RaftGroupId.valueOf(pipeline.getId().getId()));
assertCounter("NumWriteStateMachineOps", 1L, metric);
assertCounter("NumBytesWrittenCount", 1024L, metric);
assertCounter("NumApplyTransactionOps", 1L, metric);
@@ -167,7 +164,7 @@ public class TestCSMMetrics {
response.getResult());
metric = getMetrics(CSMMetrics.SOURCE_NAME +
- RaftGroupId.valueOf(pipeline.getId().getId()).toString());
+ RaftGroupId.valueOf(pipeline.getId().getId()));
assertCounter("NumQueryStateMachineOps", 1L, metric);
assertCounter("NumApplyTransactionOps", 1L, metric);
applyTransactionLatency = getDoubleGauge(
@@ -181,7 +178,7 @@ public class TestCSMMetrics {
if (client != null) {
client.close();
}
- servers.stream().forEach(XceiverServerSpi::stop);
+ servers.forEach(XceiverServerSpi::stop);
}
}
@@ -214,7 +211,7 @@ public class TestCSMMetrics {
@Override
public void validateContainerCommand(
- ContainerCommandRequestProto msg) throws StorageContainerException {
+ ContainerCommandRequestProto msg) {
}
@Override
diff --git
a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/container/server/TestContainerServer.java
b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/container/server/TestContainerServer.java
index 99eb6087d7..814c54378e 100644
---
a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/container/server/TestContainerServer.java
+++
b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/container/server/TestContainerServer.java
@@ -34,7 +34,6 @@ import
org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.ContainerC
import org.apache.hadoop.hdds.scm.XceiverClientGrpc;
import org.apache.hadoop.hdds.scm.XceiverClientRatis;
import org.apache.hadoop.hdds.scm.XceiverClientSpi;
-import
org.apache.hadoop.hdds.scm.container.common.helpers.StorageContainerException;
import org.apache.hadoop.hdds.scm.pipeline.MockPipeline;
import org.apache.hadoop.hdds.scm.pipeline.Pipeline;
import org.apache.hadoop.hdds.security.x509.SecurityConfig;
@@ -65,6 +64,7 @@ import static
org.apache.hadoop.hdds.protocol.MockDatanodeDetails.randomDatanode
import org.apache.ratis.rpc.RpcType;
import static org.apache.ratis.rpc.SupportedRpcType.GRPC;
import org.apache.ratis.util.function.CheckedBiConsumer;
+import org.apache.ratis.util.function.CheckedBiFunction;
import org.junit.Assert;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
@@ -110,11 +110,6 @@ public class TestContainerServer {
});
}
- @FunctionalInterface
- interface CheckedBiFunction<LEFT, RIGHT, OUT, THROWABLE extends Throwable> {
- OUT apply(LEFT left, RIGHT right) throws THROWABLE;
- }
-
@Test
public void testClientServerRatisGrpc() throws Exception {
runTestClientServerRatis(GRPC, 1);
@@ -147,7 +142,7 @@ public class TestContainerServer {
int numDatanodes,
CheckedBiConsumer<Pipeline, OzoneConfiguration, IOException> initConf,
CheckedBiFunction<Pipeline, OzoneConfiguration, XceiverClientSpi,
- IOException> createClient,
+ IOException> createClient,
CheckedBiFunction<DatanodeDetails, OzoneConfiguration, XceiverServerSpi,
IOException> createServer,
CheckedBiConsumer<DatanodeDetails, Pipeline, IOException> initServer)
@@ -180,7 +175,7 @@ public class TestContainerServer {
if (client != null) {
client.close();
}
- servers.stream().forEach(XceiverServerSpi::stop);
+ servers.forEach(XceiverServerSpi::stop);
}
}
@@ -265,7 +260,7 @@ public class TestContainerServer {
@Override
public void validateContainerCommand(
- ContainerCommandRequestProto msg) throws StorageContainerException {
+ ContainerCommandRequestProto msg) {
}
@Override
diff --git
a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/container/server/TestSecureContainerServer.java
b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/container/server/TestSecureContainerServer.java
index 1890a95daa..14c11233e2 100644
---
a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/container/server/TestSecureContainerServer.java
+++
b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/container/server/TestSecureContainerServer.java
@@ -97,6 +97,7 @@ import static org.apache.ratis.rpc.SupportedRpcType.GRPC;
import org.apache.ratis.util.ExitUtils;
import org.apache.ratis.util.function.CheckedBiConsumer;
+import org.apache.ratis.util.function.CheckedBiFunction;
import org.junit.After;
import static org.junit.Assert.assertEquals;
@@ -199,11 +200,6 @@ public class TestSecureContainerServer {
return hddsDispatcher;
}
- @FunctionalInterface
- interface CheckedBiFunction<LEFT, RIGHT, OUT, THROWABLE extends Throwable> {
- OUT apply(LEFT left, RIGHT right) throws THROWABLE;
- }
-
@Test
public void testClientServerRatisGrpc() throws Exception {
runTestClientServerRatis(GRPC, 1);
@@ -241,7 +237,7 @@ public class TestSecureContainerServer {
int numDatanodes,
CheckedBiConsumer<Pipeline, OzoneConfiguration, IOException> initConf,
CheckedBiFunction<Pipeline, OzoneConfiguration, XceiverClientSpi,
- IOException> createClient,
+ IOException> createClient,
CheckedBiFunction<DatanodeDetails, OzoneConfiguration, XceiverServerSpi,
IOException> createServer,
CheckedBiConsumer<DatanodeDetails, Pipeline, IOException> initServer,
diff --git
a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/volume/acl/OMVolumeAclRequest.java
b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/volume/acl/OMVolumeAclRequest.java
index 3fc2834c89..f710e43611 100644
---
a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/volume/acl/OMVolumeAclRequest.java
+++
b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/volume/acl/OMVolumeAclRequest.java
@@ -18,7 +18,6 @@
package org.apache.hadoop.ozone.om.request.volume.acl;
-import org.apache.hadoop.hdds.scm.storage.CheckedBiFunction;
import org.apache.hadoop.ozone.OzoneAcl;
import org.apache.hadoop.ozone.OzoneConsts;
import org.apache.hadoop.ozone.audit.AuditLogger;
@@ -36,6 +35,7 @@ import org.apache.hadoop.ozone.security.acl.IAccessAuthorizer;
import org.apache.hadoop.ozone.security.acl.OzoneObj;
import org.apache.hadoop.hdds.utils.db.cache.CacheKey;
import org.apache.hadoop.hdds.utils.db.cache.CacheValue;
+import org.apache.ratis.util.function.CheckedBiConsumer;
import java.io.IOException;
import java.util.List;
@@ -48,11 +48,18 @@ import static
org.apache.hadoop.ozone.om.lock.OzoneManagerLock.Resource.VOLUME_L
*/
public abstract class OMVolumeAclRequest extends OMVolumeRequest {
- private CheckedBiFunction<List<OzoneAcl>, OmVolumeArgs, IOException>
- omVolumeAclOp;
+ /**
+ * Volume ACL operation.
+ */
+ public interface VolumeAclOp extends
+ CheckedBiConsumer<List<OzoneAcl>, OmVolumeArgs, IOException> {
+ // just a shortcut to avoid having to repeat long list of generic
parameters
+ }
+
+ private final VolumeAclOp omVolumeAclOp;
- public OMVolumeAclRequest(OzoneManagerProtocolProtos.OMRequest omRequest,
- CheckedBiFunction<List<OzoneAcl>, OmVolumeArgs, IOException> aclOp) {
+ OMVolumeAclRequest(OzoneManagerProtocolProtos.OMRequest omRequest,
+ VolumeAclOp aclOp) {
super(omRequest);
omVolumeAclOp = aclOp;
}
@@ -66,7 +73,6 @@ public abstract class OMVolumeAclRequest extends
OMVolumeRequest {
OMMetrics omMetrics = ozoneManager.getMetrics();
omMetrics.incNumVolumeUpdates();
- OmVolumeArgs omVolumeArgs = null;
OMResponse.Builder omResponse = onInit();
OMClientResponse omClientResponse = null;
@@ -74,7 +80,7 @@ public abstract class OMVolumeAclRequest extends
OMVolumeRequest {
OMMetadataManager omMetadataManager = ozoneManager.getMetadataManager();
boolean lockAcquired = false;
- Result result = null;
+ Result result;
try {
// check Acl
if (ozoneManager.getAclsEnabled()) {
@@ -84,12 +90,12 @@ public abstract class OMVolumeAclRequest extends
OMVolumeRequest {
}
lockAcquired = omMetadataManager.getLock().acquireWriteLock(
VOLUME_LOCK, volume);
- omVolumeArgs = getVolumeInfo(omMetadataManager, volume);
+ OmVolumeArgs omVolumeArgs = getVolumeInfo(omMetadataManager, volume);
// result is false upon add existing acl or remove non-existing acl
boolean applyAcl = true;
try {
- omVolumeAclOp.apply(ozoneAcls, omVolumeArgs);
+ omVolumeAclOp.accept(ozoneAcls, omVolumeArgs);
} catch (OMException ex) {
applyAcl = false;
}
@@ -168,27 +174,20 @@ public abstract class OMVolumeAclRequest extends
OMVolumeRequest {
// TODO: Finer grain metrics can be moved to these callbacks. They can also
// be abstracted into separate interfaces in future.
/**
- * Get the initial om response builder with lock.
+ * Get the initial OM response builder with lock.
* @return om response builder.
*/
abstract OMResponse.Builder onInit();
/**
- * Get the om client response on success case with lock.
- * @param omResponse
- * @param omVolumeArgs
- * @param aclApplied
- * @return OMClientResponse
+ * Get the OM client response on success case with lock.
*/
abstract OMClientResponse onSuccess(
OMResponse.Builder omResponse, OmVolumeArgs omVolumeArgs,
boolean aclApplied);
/**
- * Get the om client response on failure case with lock.
- * @param omResponse
- * @param ex
- * @return OMClientResponse
+ * Get the OM client response on failure case with lock.
*/
abstract OMClientResponse onFailure(OMResponse.Builder omResponse,
IOException ex);
@@ -196,7 +195,6 @@ public abstract class OMVolumeAclRequest extends
OMVolumeRequest {
/**
* Completion hook for final processing before return without lock.
* Usually used for logging without lock.
- * @param ex
*/
abstract void onComplete(Result result, IOException ex, long trxnLogIndex,
AuditLogger auditLogger, Map<String, String> auditMap);
diff --git
a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/volume/acl/OMVolumeAddAclRequest.java
b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/volume/acl/OMVolumeAddAclRequest.java
index e776df0859..359603efb9 100644
---
a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/volume/acl/OMVolumeAddAclRequest.java
+++
b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/volume/acl/OMVolumeAddAclRequest.java
@@ -19,7 +19,6 @@ package org.apache.hadoop.ozone.om.request.volume.acl;
import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
-import org.apache.hadoop.hdds.scm.storage.CheckedBiFunction;
import org.apache.hadoop.ozone.OzoneAcl;
import org.apache.hadoop.ozone.audit.AuditLogger;
import org.apache.hadoop.ozone.audit.OMAction;
@@ -49,12 +48,8 @@ public class OMVolumeAddAclRequest extends
OMVolumeAclRequest {
private static final Logger LOG =
LoggerFactory.getLogger(OMVolumeAddAclRequest.class);
- private static CheckedBiFunction<List<OzoneAcl>,
- OmVolumeArgs, IOException> volumeAddAclOp;
-
- static {
- volumeAddAclOp = (acls, volArgs) -> volArgs.addAcl(acls.get(0));
- }
+ private static final VolumeAclOp VOLUME_ADD_ACL_OP =
+ (acls, volArgs) -> volArgs.addAcl(acls.get(0));
@Override
public OMRequest preExecute(OzoneManager ozoneManager) throws IOException {
@@ -69,12 +64,12 @@ public class OMVolumeAddAclRequest extends
OMVolumeAclRequest {
.build();
}
- private List<OzoneAcl> ozoneAcls;
- private String volumeName;
- private OzoneObj obj;
+ private final List<OzoneAcl> ozoneAcls;
+ private final String volumeName;
+ private final OzoneObj obj;
public OMVolumeAddAclRequest(OMRequest omRequest) {
- super(omRequest, volumeAddAclOp);
+ super(omRequest, VOLUME_ADD_ACL_OP);
OzoneManagerProtocolProtos.AddAclRequest addAclRequest =
getOmRequest().getAddAclRequest();
Preconditions.checkNotNull(addAclRequest);
diff --git
a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/volume/acl/OMVolumeRemoveAclRequest.java
b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/volume/acl/OMVolumeRemoveAclRequest.java
index ff2792d44f..3981d3a2a2 100644
---
a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/volume/acl/OMVolumeRemoveAclRequest.java
+++
b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/volume/acl/OMVolumeRemoveAclRequest.java
@@ -19,7 +19,6 @@ package org.apache.hadoop.ozone.om.request.volume.acl;
import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
-import org.apache.hadoop.hdds.scm.storage.CheckedBiFunction;
import org.apache.hadoop.ozone.OzoneAcl;
import org.apache.hadoop.ozone.audit.AuditLogger;
import org.apache.hadoop.ozone.audit.OMAction;
@@ -49,12 +48,8 @@ public class OMVolumeRemoveAclRequest extends
OMVolumeAclRequest {
private static final Logger LOG =
LoggerFactory.getLogger(OMVolumeRemoveAclRequest.class);
- private static CheckedBiFunction<List<OzoneAcl>,
- OmVolumeArgs, IOException> volumeRemoveAclOp;
-
- static {
- volumeRemoveAclOp = (acls, volArgs) -> volArgs.removeAcl(acls.get(0));
- }
+ private static final VolumeAclOp VOLUME_REMOVE_ACL_OP =
+ (acls, volArgs) -> volArgs.removeAcl(acls.get(0));
@Override
public OMRequest preExecute(OzoneManager ozoneManager) throws IOException {
@@ -69,12 +64,12 @@ public class OMVolumeRemoveAclRequest extends
OMVolumeAclRequest {
.build();
}
- private List<OzoneAcl> ozoneAcls;
- private String volumeName;
- private OzoneObj obj;
+ private final List<OzoneAcl> ozoneAcls;
+ private final String volumeName;
+ private final OzoneObj obj;
public OMVolumeRemoveAclRequest(OMRequest omRequest) {
- super(omRequest, volumeRemoveAclOp);
+ super(omRequest, VOLUME_REMOVE_ACL_OP);
OzoneManagerProtocolProtos.RemoveAclRequest removeAclRequest =
getOmRequest().getRemoveAclRequest();
Preconditions.checkNotNull(removeAclRequest);
diff --git
a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/volume/acl/OMVolumeSetAclRequest.java
b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/volume/acl/OMVolumeSetAclRequest.java
index 95d98f4ddd..0ca2b40c89 100644
---
a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/volume/acl/OMVolumeSetAclRequest.java
+++
b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/volume/acl/OMVolumeSetAclRequest.java
@@ -18,7 +18,6 @@
package org.apache.hadoop.ozone.om.request.volume.acl;
import com.google.common.base.Preconditions;
-import org.apache.hadoop.hdds.scm.storage.CheckedBiFunction;
import org.apache.hadoop.ozone.OzoneAcl;
import org.apache.hadoop.ozone.audit.AuditLogger;
import org.apache.hadoop.ozone.audit.OMAction;
@@ -49,12 +48,8 @@ public class OMVolumeSetAclRequest extends
OMVolumeAclRequest {
private static final Logger LOG =
LoggerFactory.getLogger(OMVolumeSetAclRequest.class);
- private static CheckedBiFunction<List<OzoneAcl>,
- OmVolumeArgs, IOException> volumeSetAclOp;
-
- static {
- volumeSetAclOp = (acls, volArgs) -> volArgs.setAcls(acls);
- }
+ private static final VolumeAclOp VOLUME_SET_ACL_OP =
+ (acls, volArgs) -> volArgs.setAcls(acls);
@Override
public OMRequest preExecute(OzoneManager ozoneManager) throws IOException {
@@ -69,12 +64,12 @@ public class OMVolumeSetAclRequest extends
OMVolumeAclRequest {
.build();
}
- private List<OzoneAcl> ozoneAcls;
- private String volumeName;
- private OzoneObj obj;
+ private final List<OzoneAcl> ozoneAcls;
+ private final String volumeName;
+ private final OzoneObj obj;
public OMVolumeSetAclRequest(OMRequest omRequest) {
- super(omRequest, volumeSetAclOp);
+ super(omRequest, VOLUME_SET_ACL_OP);
OzoneManagerProtocolProtos.SetAclRequest setAclRequest =
getOmRequest().getSetAclRequest();
Preconditions.checkNotNull(setAclRequest);
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]