From eae5ae0fd61f860a9c2e3982f7edac463818b208 Mon Sep 17 00:00:00 2001 From: DaveTeng0 Date: Wed, 22 May 2024 10:32:47 -0700 Subject: [PATCH] fix license, findbug of dereference, line length --- .../org/apache/ratis/shell/cli/RaftUtils.java | 6 ++++-- .../apache/ratis/shell/cli/SecurityUtils.java | 21 ++++++++++++++++++- .../cli/sh/command/AbstractRatisCommand.java | 3 +-- .../cli/sh/snapshot/TakeSnapshotCommand.java | 2 +- 4 files changed, 26 insertions(+), 6 deletions(-) diff --git a/ratis-shell/src/main/java/org/apache/ratis/shell/cli/RaftUtils.java b/ratis-shell/src/main/java/org/apache/ratis/shell/cli/RaftUtils.java index 8385b749d7..00ce42dd6a 100644 --- a/ratis-shell/src/main/java/org/apache/ratis/shell/cli/RaftUtils.java +++ b/ratis-shell/src/main/java/org/apache/ratis/shell/cli/RaftUtils.java @@ -192,9 +192,11 @@ public static RaftGroupId retrieveRemoteGroupId(RaftGroupId raftGroupIdFromConfi return remoteGroupId; } - public static GroupInfoReply retrieveGroupInfoByGroupId(RaftGroupId remoteGroupId, List peers, RaftClient client, PrintStream printStream) + public static GroupInfoReply retrieveGroupInfoByGroupId(RaftGroupId remoteGroupId, List peers, + RaftClient client, PrintStream printStream) throws IOException { - GroupInfoReply groupInfoReply = runFunction(peers, p -> client.getGroupManagementApi((p.getId())).info(remoteGroupId)); + GroupInfoReply groupInfoReply = runFunction(peers, + p -> client.getGroupManagementApi((p.getId())).info(remoteGroupId)); processReply(groupInfoReply, printStream::println, "Failed to get group info for group id " + remoteGroupId.getUuid() + " from " + peers); return groupInfoReply; diff --git a/ratis-shell/src/main/java/org/apache/ratis/shell/cli/SecurityUtils.java b/ratis-shell/src/main/java/org/apache/ratis/shell/cli/SecurityUtils.java index 22e5f600e0..ec70076bf1 100644 --- a/ratis-shell/src/main/java/org/apache/ratis/shell/cli/SecurityUtils.java +++ b/ratis-shell/src/main/java/org/apache/ratis/shell/cli/SecurityUtils.java @@ -1,3 +1,20 @@ +/* + * 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.ratis.shell.cli; import org.slf4j.Logger; @@ -17,7 +34,9 @@ import java.util.Arrays; public class SecurityUtils { - static Logger LOG = LoggerFactory.getLogger(SecurityUtils.class); + private SecurityUtils() { + // prevent instantiation + } public static KeyStore getTrustStore() throws Exception { diff --git a/ratis-shell/src/main/java/org/apache/ratis/shell/cli/sh/command/AbstractRatisCommand.java b/ratis-shell/src/main/java/org/apache/ratis/shell/cli/sh/command/AbstractRatisCommand.java index 5f6283c5b3..d9334b5092 100644 --- a/ratis-shell/src/main/java/org/apache/ratis/shell/cli/sh/command/AbstractRatisCommand.java +++ b/ratis-shell/src/main/java/org/apache/ratis/shell/cli/sh/command/AbstractRatisCommand.java @@ -99,13 +99,12 @@ protected AbstractRatisCommand(Context context) { @Override public int run(CommandLine cl) throws IOException { - List peers = buildRaftPeersFromStr(cl.getOptionValue(PEER_OPTION_NAME)); RaftGroupId raftGroupIdFromConfig = buildRaftGroupIdFromStr(cl.getOptionValue(GROUPID_OPTION_NAME)); raftGroup = RaftGroup.valueOf(raftGroupIdFromConfig, peers); try (final RaftClient client = getRaftClient(cl.hasOption(TLS_ENABLED_OPTION_NAME))) { - RaftGroupId remoteGroupId = retrieveRemoteGroupId(raftGroupIdFromConfig, peers, client, printStream);; + RaftGroupId remoteGroupId = retrieveRemoteGroupId(raftGroupIdFromConfig, peers, client, printStream); groupInfoReply = retrieveGroupInfoByGroupId(remoteGroupId, peers, client, printStream); raftGroup = groupInfoReply.getGroup(); } diff --git a/ratis-shell/src/main/java/org/apache/ratis/shell/cli/sh/snapshot/TakeSnapshotCommand.java b/ratis-shell/src/main/java/org/apache/ratis/shell/cli/sh/snapshot/TakeSnapshotCommand.java index c005dae780..10b23e8492 100644 --- a/ratis-shell/src/main/java/org/apache/ratis/shell/cli/sh/snapshot/TakeSnapshotCommand.java +++ b/ratis-shell/src/main/java/org/apache/ratis/shell/cli/sh/snapshot/TakeSnapshotCommand.java @@ -67,7 +67,7 @@ public int run(CommandLine cl) throws IOException { peerId = null; } RaftClientReply reply = raftClient.getSnapshotManagementApi(peerId).create(timeout); - processReply(reply, this::println, String.format("Failed to take snapshot of peerId %s", peerId.toString())); + processReply(reply, this::println, String.format("Failed to take snapshot of peerId %s", peerId != null ? peerId.toString() : null)); printf(String.format("Successful take snapshot on peerId %s, the latest snapshot index is %d", peerId, reply.getLogIndex())); }