This is an automated email from the ASF dual-hosted git repository.
runzhiwang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-ratis.git
The following commit(s) were added to refs/heads/master by this push:
new 6f835c1 RATIS-1092. Move the group management methods from RaftClient
to a new interface. (#218)
6f835c1 is described below
commit 6f835c1d42c7fcfcca8d2c5e1309c477269a64fd
Author: Tsz-Wo Nicholas Sze <[email protected]>
AuthorDate: Mon Oct 12 19:22:18 2020 +0800
RATIS-1092. Move the group management methods from RaftClient to a new
interface. (#218)
---
.../java/org/apache/ratis/client/RaftClient.java | 17 ++---
.../ratis/client/api/GroupManagementApi.java | 43 +++++++++++
.../ratis/client/impl/GroupManagementImpl.java | 83 ++++++++++++++++++++++
.../apache/ratis/client/impl/RaftClientImpl.java | 55 ++++----------
.../apache/ratis/client/impl/UnorderedAsync.java | 2 +-
.../ratis/logservice/server/MetaStateMachine.java | 6 +-
.../org/apache/ratis/RaftExceptionBaseTest.java | 4 +-
.../ratis/server/impl/GroupInfoBaseTest.java | 14 ++--
.../ratis/server/impl/GroupManagementBaseTest.java | 28 ++++----
.../server/impl/RaftReconfigurationBaseTest.java | 2 +-
.../ratis/statemachine/TestStateMachine.java | 4 +-
11 files changed, 175 insertions(+), 83 deletions(-)
diff --git a/ratis-client/src/main/java/org/apache/ratis/client/RaftClient.java
b/ratis-client/src/main/java/org/apache/ratis/client/RaftClient.java
index 41e3451..15549a8 100644
--- a/ratis-client/src/main/java/org/apache/ratis/client/RaftClient.java
+++ b/ratis-client/src/main/java/org/apache/ratis/client/RaftClient.java
@@ -19,6 +19,7 @@ package org.apache.ratis.client;
import org.apache.ratis.RaftConfigKeys;
import org.apache.ratis.client.api.DataStreamApi;
+import org.apache.ratis.client.api.GroupManagementApi;
import org.apache.ratis.client.api.MessageStreamApi;
import org.apache.ratis.client.impl.ClientImplUtils;
import org.apache.ratis.conf.Parameters;
@@ -50,6 +51,9 @@ public interface RaftClient extends Closeable {
/** @return the {@link RaftClientRpc}. */
RaftClientRpc getClientRpc();
+ /** Get the {@link GroupManagementApi} for the given server. */
+ GroupManagementApi getGroupManagementApi(RaftPeerId server);
+
/** @return the {@link MessageStreamApi}. */
MessageStreamApi getMessageStreamApi();
@@ -101,19 +105,6 @@ public interface RaftClient extends Closeable {
/** Send set configuration request to the raft service. */
RaftClientReply setConfiguration(RaftPeer[] serversInNewConf) throws
IOException;
- /** Send groupAdd request to the given server (not the raft service). */
- RaftClientReply groupAdd(RaftGroup newGroup, RaftPeerId server) throws
IOException;
-
- /** Send groupRemove request to the given server (not the raft service). */
- RaftClientReply groupRemove(RaftGroupId groupId, boolean deleteDirectory,
- boolean renameDirectory, RaftPeerId server) throws IOException;
-
- /** Send getGroupList request to the given server.*/
- GroupListReply getGroupList(RaftPeerId server) throws IOException;
-
- /** Send getGroupInfo request to the given server.*/
- GroupInfoReply getGroupInfo(RaftGroupId group, RaftPeerId server) throws
IOException;
-
/** @return a {@link Builder}. */
static Builder newBuilder() {
return new Builder();
diff --git
a/ratis-client/src/main/java/org/apache/ratis/client/api/GroupManagementApi.java
b/ratis-client/src/main/java/org/apache/ratis/client/api/GroupManagementApi.java
new file mode 100644
index 0000000..1d3bc00
--- /dev/null
+++
b/ratis-client/src/main/java/org/apache/ratis/client/api/GroupManagementApi.java
@@ -0,0 +1,43 @@
+/*
+ * 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.client.api;
+
+import org.apache.ratis.protocol.GroupInfoReply;
+import org.apache.ratis.protocol.GroupListReply;
+import org.apache.ratis.protocol.RaftClientReply;
+import org.apache.ratis.protocol.RaftGroup;
+import org.apache.ratis.protocol.RaftGroupId;
+
+import java.io.IOException;
+
+/**
+ * APIs to support group management operations such as add, remove, list and
info to a particular server.
+ */
+public interface GroupManagementApi {
+ /** Add a new group. */
+ RaftClientReply add(RaftGroup newGroup) throws IOException;
+
+ /** Remove a group. */
+ RaftClientReply remove(RaftGroupId groupId, boolean deleteDirectory, boolean
renameDirectory) throws IOException;
+
+ /** List all the groups.*/
+ GroupListReply list() throws IOException;
+
+ /** Get the info of the given group.*/
+ GroupInfoReply info(RaftGroupId group) throws IOException;
+}
\ No newline at end of file
diff --git
a/ratis-client/src/main/java/org/apache/ratis/client/impl/GroupManagementImpl.java
b/ratis-client/src/main/java/org/apache/ratis/client/impl/GroupManagementImpl.java
new file mode 100644
index 0000000..7ed407e
--- /dev/null
+++
b/ratis-client/src/main/java/org/apache/ratis/client/impl/GroupManagementImpl.java
@@ -0,0 +1,83 @@
+/*
+ * 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.client.impl;
+
+import org.apache.ratis.client.api.GroupManagementApi;
+import org.apache.ratis.protocol.GroupInfoReply;
+import org.apache.ratis.protocol.GroupInfoRequest;
+import org.apache.ratis.protocol.GroupListReply;
+import org.apache.ratis.protocol.GroupListRequest;
+import org.apache.ratis.protocol.GroupManagementRequest;
+import org.apache.ratis.protocol.RaftClientReply;
+import org.apache.ratis.protocol.RaftGroup;
+import org.apache.ratis.protocol.RaftGroupId;
+import org.apache.ratis.protocol.RaftPeerId;
+import org.apache.ratis.util.Preconditions;
+
+import java.io.IOException;
+import java.util.Objects;
+
+class GroupManagementImpl implements GroupManagementApi {
+ private final RaftPeerId server;
+ private final RaftClientImpl client;
+
+ GroupManagementImpl(RaftPeerId server, RaftClientImpl client) {
+ this.server = Objects.requireNonNull(server, "server == null");
+ this.client = Objects.requireNonNull(client, "client == null");
+ }
+
+ @Override
+ public RaftClientReply add(RaftGroup newGroup) throws IOException {
+ Objects.requireNonNull(newGroup, "newGroup == null");
+
+ final long callId = RaftClientImpl.nextCallId();
+ client.addServers(newGroup.getPeers().stream());
+ return client.sendRequest(GroupManagementRequest.newAdd(client.getId(),
server, callId, newGroup));
+ }
+
+ @Override
+ public RaftClientReply remove(RaftGroupId groupId, boolean deleteDirectory,
boolean renameDirectory)
+ throws IOException {
+ Objects.requireNonNull(groupId, "groupId == null");
+
+ final long callId = RaftClientImpl.nextCallId();
+ return client.sendRequest(GroupManagementRequest.newRemove(client.getId(),
server,
+ callId, groupId, deleteDirectory, renameDirectory));
+ }
+
+ @Override
+ public GroupListReply list() throws IOException {
+ final long callId = RaftClientImpl.nextCallId();
+ final RaftClientReply reply = client.sendRequest(
+ new GroupListRequest(client.getId(), server, client.getGroupId(),
callId));
+ Preconditions.assertTrue(reply instanceof GroupListReply, () ->
"Unexpected reply: " + reply);
+ return (GroupListReply)reply;
+ }
+
+ @Override
+ public GroupInfoReply info(RaftGroupId groupId) throws IOException {
+ if (groupId == null) {
+ groupId = client.getGroupId();
+ }
+ final long callId = RaftClientImpl.nextCallId();
+ final RaftClientReply reply = client.sendRequest(
+ new GroupInfoRequest(client.getId(), server, groupId, callId));
+ Preconditions.assertTrue(reply instanceof GroupInfoReply, () ->
"Unexpected reply: " + reply);
+ return (GroupInfoReply)reply;
+ }
+}
diff --git
a/ratis-client/src/main/java/org/apache/ratis/client/impl/RaftClientImpl.java
b/ratis-client/src/main/java/org/apache/ratis/client/impl/RaftClientImpl.java
index 4e25fe4..f9f985f 100644
---
a/ratis-client/src/main/java/org/apache/ratis/client/impl/RaftClientImpl.java
+++
b/ratis-client/src/main/java/org/apache/ratis/client/impl/RaftClientImpl.java
@@ -17,6 +17,7 @@
*/
package org.apache.ratis.client.impl;
+import org.apache.ratis.client.api.GroupManagementApi;
import org.apache.ratis.client.retry.ClientRetryEvent;
import org.apache.ratis.client.RaftClient;
import org.apache.ratis.client.RaftClientRpc;
@@ -137,6 +138,10 @@ public final class RaftClientImpl implements RaftClient {
return leaderId;
}
+ RaftGroupId getGroupId() {
+ return groupId;
+ }
+
private RaftPeerId getHighestPriorityPeerId() {
if (peers == null) {
return null;
@@ -266,46 +271,11 @@ public final class RaftClientImpl implements RaftClient {
}
@Override
- public RaftClientReply groupAdd(RaftGroup newGroup, RaftPeerId server)
throws IOException {
- Objects.requireNonNull(newGroup, "newGroup == null");
- Objects.requireNonNull(server, "server == null");
-
- final long callId = nextCallId();
- addServers(newGroup.getPeers().stream());
- return sendRequest(GroupManagementRequest.newAdd(clientId, server, callId,
newGroup));
- }
-
- @Override
- public RaftClientReply groupRemove(RaftGroupId grpId, boolean
deleteDirectory,
- boolean renameDirectory, RaftPeerId server)
- throws IOException {
- Objects.requireNonNull(groupId, "groupId == null");
- Objects.requireNonNull(server, "server == null");
-
- final long callId = nextCallId();
- return sendRequest(GroupManagementRequest.newRemove(clientId, server,
- callId, grpId, deleteDirectory, renameDirectory));
- }
-
- @Override
- public GroupListReply getGroupList(RaftPeerId server) throws IOException {
- Objects.requireNonNull(server, "server == null");
-
- final RaftClientReply reply = sendRequest(new GroupListRequest(clientId,
server, groupId, nextCallId()));
- Preconditions.assertTrue(reply instanceof GroupListReply, () ->
"Unexpected reply: " + reply);
- return (GroupListReply)reply;
- }
-
- @Override
- public GroupInfoReply getGroupInfo(RaftGroupId raftGroupId, RaftPeerId
server) throws IOException {
- Objects.requireNonNull(server, "server == null");
- RaftGroupId rgi = raftGroupId == null ? groupId : raftGroupId;
- final RaftClientReply reply = sendRequest(new GroupInfoRequest(clientId,
server, rgi, nextCallId()));
- Preconditions.assertTrue(reply instanceof GroupInfoReply, () ->
"Unexpected reply: " + reply);
- return (GroupInfoReply)reply;
+ public GroupManagementApi getGroupManagementApi(RaftPeerId server) {
+ return new GroupManagementImpl(server, this);
}
- private void addServers(Stream<RaftPeer> peersInNewConf) {
+ void addServers(Stream<RaftPeer> peersInNewConf) {
clientRpc.addServers(
peersInNewConf.filter(p -> !peers.contains(p))::iterator);
}
@@ -358,7 +328,7 @@ public final class RaftClientImpl implements RaftClient {
return new RaftRetryFailureException(event.getRequest(), attemptCount,
retryPolicy, throwable);
}
- private RaftClientReply sendRequest(RaftClientRequest request) throws
IOException {
+ RaftClientReply sendRequest(RaftClientRequest request) throws IOException {
LOG.debug("{}: send {}", clientId, request);
RaftClientReply reply;
try {
@@ -370,7 +340,7 @@ public final class RaftClientImpl implements RaftClient {
throw ioe;
}
LOG.debug("{}: receive {}", clientId, reply);
- reply = handleLeaderException(request, reply, null);
+ reply = handleLeaderException(request, reply);
reply = handleRaftException(reply, Function.identity());
return reply;
}
@@ -391,8 +361,7 @@ public final class RaftClientImpl implements RaftClient {
* {@link NotLeaderException} or {@link LeaderNotReadyException}
* otherwise return the same reply.
*/
- RaftClientReply handleLeaderException(RaftClientRequest request,
RaftClientReply reply,
- Consumer<RaftClientRequest> handler) {
+ RaftClientReply handleLeaderException(RaftClientRequest request,
RaftClientReply reply) {
if (reply == null || reply.getException() instanceof
LeaderNotReadyException) {
return null;
}
@@ -400,7 +369,7 @@ public final class RaftClientImpl implements RaftClient {
if (nle == null) {
return reply;
}
- return handleNotLeaderException(request, nle, handler);
+ return handleNotLeaderException(request, nle, null);
}
RaftClientReply handleNotLeaderException(RaftClientRequest request,
NotLeaderException nle,
diff --git
a/ratis-client/src/main/java/org/apache/ratis/client/impl/UnorderedAsync.java
b/ratis-client/src/main/java/org/apache/ratis/client/impl/UnorderedAsync.java
index 6363c65..5d02dbe 100644
---
a/ratis-client/src/main/java/org/apache/ratis/client/impl/UnorderedAsync.java
+++
b/ratis-client/src/main/java/org/apache/ratis/client/impl/UnorderedAsync.java
@@ -77,7 +77,7 @@ public interface UnorderedAsync {
try {
LOG.debug("{}: attempt #{} receive~ {}", clientId, attemptCount,
reply);
final RaftException replyException = reply != null?
reply.getException(): null;
- reply = client.handleLeaderException(request, reply, null);
+ reply = client.handleLeaderException(request, reply);
if (reply != null) {
f.complete(reply);
return;
diff --git
a/ratis-logservice/src/main/java/org/apache/ratis/logservice/server/MetaStateMachine.java
b/ratis-logservice/src/main/java/org/apache/ratis/logservice/server/MetaStateMachine.java
index e315b4c..2982595 100644
---
a/ratis-logservice/src/main/java/org/apache/ratis/logservice/server/MetaStateMachine.java
+++
b/ratis-logservice/src/main/java/org/apache/ratis/logservice/server/MetaStateMachine.java
@@ -263,7 +263,7 @@ public class MetaStateMachine extends BaseStateMachine {
raftPeers.stream().forEach(peer -> {
try (RaftClient client =
RaftClient.newBuilder().setProperties(properties)
.setClientId(ClientId.randomId()).setRaftGroup(RaftGroup.valueOf(logServerGroupId,
peer)).build()){
- client.groupRemove(raftGroup.getGroupId(), true, false,
peer.getId());
+
client.getGroupManagementApi(peer.getId()).remove(raftGroup.getGroupId(), true,
false);
} catch (IOException e) {
e.printStackTrace();
}
@@ -319,7 +319,7 @@ public class MetaStateMachine extends BaseStateMachine {
for (RaftPeer peer : peers) {
try (RaftClient client =
RaftClient.newBuilder().setProperties(properties)
.setRaftGroup(RaftGroup.valueOf(logServerGroupId,
peer)).build()) {
- client.groupAdd(raftGroup, peer.getId());
+
client.getGroupManagementApi(peer.getId()).add(raftGroup);
} catch (IOException e) {
LOG.error("Failed to add Raft group ({}) for new
Log({})",
raftGroup.getGroupId(), name, e);
@@ -338,7 +338,7 @@ public class MetaStateMachine extends BaseStateMachine {
}
try (RaftClient client =
RaftClient.newBuilder().setProperties(properties)
.setRaftGroup(RaftGroup.valueOf(logServerGroupId,
peer)).build()) {
- client.groupRemove(raftGroup.getGroupId(), true,
false, peer.getId());
+
client.getGroupManagementApi(peer.getId()).remove(raftGroup.getGroupId(), true,
false);
} catch (IOException e) {
LOG.error("Failed to clean up Raft group ({}) for
peer ({}), "
+ "ignoring exception",
raftGroup.getGroupId(), peer, e);
diff --git
a/ratis-server/src/test/java/org/apache/ratis/RaftExceptionBaseTest.java
b/ratis-server/src/test/java/org/apache/ratis/RaftExceptionBaseTest.java
index d825d87..8b6fd2d 100644
--- a/ratis-server/src/test/java/org/apache/ratis/RaftExceptionBaseTest.java
+++ b/ratis-server/src/test/java/org/apache/ratis/RaftExceptionBaseTest.java
@@ -161,8 +161,8 @@ public abstract class RaftExceptionBaseTest<CLUSTER extends
MiniRaftCluster>
GroupMismatchException.class);
testFailureCase("groupRemove(..) with another group id",
- () -> client.groupRemove(anotherGroup.getGroupId(), false, false,
- clusterGroup.getPeers().iterator().next().getId()),
+ () ->
client.getGroupManagementApi(clusterGroup.getPeers().iterator().next().getId())
+ .remove(anotherGroup.getGroupId(), false, false),
GroupMismatchException.class);
}
}
diff --git
a/ratis-server/src/test/java/org/apache/ratis/server/impl/GroupInfoBaseTest.java
b/ratis-server/src/test/java/org/apache/ratis/server/impl/GroupInfoBaseTest.java
index 2b15b6b..bde28a7 100644
---
a/ratis-server/src/test/java/org/apache/ratis/server/impl/GroupInfoBaseTest.java
+++
b/ratis-server/src/test/java/org/apache/ratis/server/impl/GroupInfoBaseTest.java
@@ -1,4 +1,4 @@
-/**
+/*
* 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
@@ -21,6 +21,7 @@ import org.apache.log4j.Level;
import org.apache.ratis.BaseTest;
import org.apache.ratis.MiniRaftCluster;
import org.apache.ratis.client.RaftClient;
+import org.apache.ratis.client.api.GroupManagementApi;
import org.apache.ratis.protocol.*;
import org.apache.ratis.proto.RaftProtos.CommitInfoProto;
import org.apache.ratis.util.Log4jUtils;
@@ -54,23 +55,24 @@ public abstract class GroupInfoBaseTest<CLUSTER extends
MiniRaftCluster>
RaftGroup group2 = RaftGroup.valueOf(RaftGroupId.randomId(), peers);
for(RaftPeer peer : peers) {
try(final RaftClient client = cluster.createClient(peer.getId())) {
- client.groupAdd(group2, peer.getId());
+ client.getGroupManagementApi(peer.getId()).add(group2);
}
}
// check that all the peers return the list where both groups are
included. And able to return GroupInfo
// for each of them.
for (RaftPeer peer : peers) {
try (final RaftClient client = cluster.createClient(peer.getId())) {
- GroupListReply info = client.getGroupList(peer.getId());
+ final GroupManagementApi api =
client.getGroupManagementApi(peer.getId());
+ final GroupListReply info = api.list();
List<RaftGroupId> groupList = info.getGroupIds().stream()
.filter(id ->
group.getGroupId().equals(id)).collect(Collectors.toList());
assert (groupList.size() == 1);
- final GroupInfoReply gi = client.getGroupInfo(groupList.get(0),
peer.getId());
+ final GroupInfoReply gi = api.info(groupList.get(0));
assert (sameGroup(group, gi.getGroup()));
groupList = info.getGroupIds().stream()
.filter(id ->
group2.getGroupId().equals(id)).collect(Collectors.toList());
assert (groupList.size() == 1);
- final GroupInfoReply gi2 = client.getGroupInfo(groupList.get(0),
peer.getId());
+ final GroupInfoReply gi2 = api.info(groupList.get(0));
assert (sameGroup(group2, gi2.getGroup()));
}
}
@@ -101,7 +103,7 @@ public abstract class GroupInfoBaseTest<CLUSTER extends
MiniRaftCluster>
continue;
}
try(final RaftClient client = cluster.createClient(peer.getId())) {
- GroupListReply info = client.getGroupList(peer.getId());
+ final GroupListReply info =
client.getGroupManagementApi(peer.getId()).list();
Assert.assertEquals(1, info.getGroupIds().stream().filter(id ->
group.getGroupId().equals(id)).count());
for(CommitInfoProto i : info.getCommitInfos()) {
if
(RaftPeerId.valueOf(i.getServer().getId()).equals(killedFollower)) {
diff --git
a/ratis-server/src/test/java/org/apache/ratis/server/impl/GroupManagementBaseTest.java
b/ratis-server/src/test/java/org/apache/ratis/server/impl/GroupManagementBaseTest.java
index 3355cb9..f8ebf4f 100644
---
a/ratis-server/src/test/java/org/apache/ratis/server/impl/GroupManagementBaseTest.java
+++
b/ratis-server/src/test/java/org/apache/ratis/server/impl/GroupManagementBaseTest.java
@@ -22,6 +22,7 @@ import org.apache.ratis.BaseTest;
import org.apache.ratis.MiniRaftCluster;
import org.apache.ratis.RaftTestUtil;
import org.apache.ratis.client.RaftClient;
+import org.apache.ratis.client.api.GroupManagementApi;
import org.apache.ratis.conf.RaftProperties;
import org.apache.ratis.protocol.exceptions.AlreadyExistsException;
import org.apache.ratis.protocol.RaftClientReply;
@@ -72,7 +73,7 @@ public abstract class GroupManagementBaseTest extends
BaseTest {
public abstract MiniRaftCluster.Factory<? extends MiniRaftCluster>
getClusterFactory();
- public MiniRaftCluster getCluster(int peerNum) throws IOException {
+ public MiniRaftCluster getCluster(int peerNum) {
return getClusterFactory().newCluster(peerNum, prop);
}
@@ -115,7 +116,7 @@ public abstract class GroupManagementBaseTest extends
BaseTest {
// Before request, client try leader with the highest priority
Assert.assertTrue(client.getLeaderId() ==
peersWithPriority.get(suggestedLeaderIndex).getId());
for (RaftPeer p : newGroup.getPeers()) {
- client.groupAdd(newGroup, p.getId());
+ client.getGroupManagementApi(p.getId()).add(newGroup);
}
}
@@ -190,7 +191,7 @@ public abstract class GroupManagementBaseTest extends
BaseTest {
LOG.info("add new group: " + newGroup);
try (final RaftClient client = cluster.createClient(newGroup)) {
for (RaftPeer p : newGroup.getPeers()) {
- client.groupAdd(newGroup, p.getId());
+ client.getGroupManagementApi(p.getId()).add(newGroup);
}
}
Assert.assertNotNull(RaftTestUtil.waitForLeader(cluster));
@@ -274,7 +275,7 @@ public abstract class GroupManagementBaseTest extends
BaseTest {
LOG.info(i + ") starting " + groups[i]);
for(RaftPeer p : peers) {
try(final RaftClient client = cluster.createClient(p.getId(),
emptyGroup)) {
- client.groupAdd(groups[i], p.getId());
+ client.getGroupManagementApi(p.getId()).add(groups[i]);
}
}
Assert.assertNotNull(RaftTestUtil.waitForLeader(cluster, gid));
@@ -291,13 +292,14 @@ public abstract class GroupManagementBaseTest extends
BaseTest {
final RaftGroup g = groups[i];
LOG.info(i + ") close " + cluster.printServers(g.getGroupId()));
for(RaftPeer p : g.getPeers()) {
- final File root =
cluster.getServer(p.getId()).getImpl(g.getGroupId()).getState().getStorage().getStorageDir().getRoot();
+ final File root =
cluster.getServer(p.getId()).getImpl(g.getGroupId())
+ .getState().getStorage().getStorageDir().getRoot();
Assert.assertTrue(root.exists());
Assert.assertTrue(root.isDirectory());
final RaftClientReply r;
try (final RaftClient client = cluster.createClient(p.getId(), g)) {
- r = client.groupRemove(g.getGroupId(), true, false, p.getId());
+ r = client.getGroupManagementApi(p.getId()).remove(g.getGroupId(),
true, false);
}
Assert.assertTrue(r.isSuccess());
Assert.assertFalse(root.exists());
@@ -314,7 +316,7 @@ public abstract class GroupManagementBaseTest extends
BaseTest {
LOG.info(i + ") groupAdd: " +
cluster.printServers(groups[i].getGroupId()));
for (RaftPeer p : groups[i].getPeers()) {
try (final RaftClient client = cluster.createClient(p.getId(),
groups[i])) {
- client.groupAdd(newGroup, p.getId());
+ client.getGroupManagementApi(p.getId()).add(newGroup);
}
}
}
@@ -348,7 +350,7 @@ public abstract class GroupManagementBaseTest extends
BaseTest {
try (final RaftClient client = cluster.createClient()) {
Assert.assertEquals(group, cluster.getRaftServerImpl(peerId).getGroup());
try {
- client.groupAdd(group, peer.getId());
+ client.getGroupManagementApi(peer.getId()).add(group);
} catch (IOException ex) {
// HadoopRPC throws RemoteException, which makes it hard to check if
// the exception is instance of AlreadyExistsException
@@ -376,12 +378,13 @@ public abstract class GroupManagementBaseTest extends
BaseTest {
try {
// Group2 is added to one of the peers in Group1
- client.groupAdd(group2, peerId1);
+ final GroupManagementApi api1 = client.getGroupManagementApi(peerId1);
+ api1.add(group2);
List<RaftGroupId> groupIds1 =
cluster1.getServer(peerId1).getGroupIds();
Assert.assertEquals(groupIds1.size(), 2);
// Group2 is renamed from the peer1 of Group1
- client.groupRemove(group2.getGroupId(), false, true, peerId1);
+ api1.remove(group2.getGroupId(), false, true);
groupIds1 = cluster1.getServer(peerId1).getGroupIds();
Assert.assertEquals(groupIds1.size(), 1);
@@ -423,12 +426,13 @@ public abstract class GroupManagementBaseTest extends
BaseTest {
try {
// Group2 is added again to one of the peers in Group1
- client.groupAdd(group2, peerId1);
+ final GroupManagementApi api1 = client.getGroupManagementApi(peerId1);
+ api1.add(group2);
List<RaftGroupId> groupIds1 =
cluster1.getServer(peerId1).getGroupIds();
Assert.assertEquals(groupIds1.size(), 2);
// Group2 is deleted from the peer1 of Group1
- client.groupRemove(group2.getGroupId(), true, false, peerId1);
+ api1.remove(group2.getGroupId(), true, false);
groupIds1 = cluster1.getServer(peerId1).getGroupIds();
Assert.assertEquals(groupIds1.size(), 1);
diff --git
a/ratis-server/src/test/java/org/apache/ratis/server/impl/RaftReconfigurationBaseTest.java
b/ratis-server/src/test/java/org/apache/ratis/server/impl/RaftReconfigurationBaseTest.java
index 4ff27e4..ae38622 100644
---
a/ratis-server/src/test/java/org/apache/ratis/server/impl/RaftReconfigurationBaseTest.java
+++
b/ratis-server/src/test/java/org/apache/ratis/server/impl/RaftReconfigurationBaseTest.java
@@ -105,7 +105,7 @@ public abstract class RaftReconfigurationBaseTest<CLUSTER
extends MiniRaftCluste
LOG.info("add new group: " + newGroup);
try (final RaftClient client = cluster.createClient(newGroup)) {
for (RaftPeer p : newGroup.getPeers()) {
- client.groupAdd(newGroup, p.getId());
+ client.getGroupManagementApi(p.getId()).add(newGroup);
}
}
diff --git
a/ratis-test/src/test/java/org/apache/ratis/statemachine/TestStateMachine.java
b/ratis-test/src/test/java/org/apache/ratis/statemachine/TestStateMachine.java
index d0b486a..6c02e72 100644
---
a/ratis-test/src/test/java/org/apache/ratis/statemachine/TestStateMachine.java
+++
b/ratis-test/src/test/java/org/apache/ratis/statemachine/TestStateMachine.java
@@ -1,4 +1,4 @@
-/**
+/*
* 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
@@ -187,7 +187,7 @@ public class TestStateMachine extends BaseTest implements
MiniRaftClusterWithSim
LOG.info("add new group: " + newGroup);
try (final RaftClient client = cluster.createClient(newGroup)) {
for (RaftPeer p : newGroup.getPeers()) {
- client.groupAdd(newGroup, p.getId());
+ client.getGroupManagementApi(p.getId()).add(newGroup);
}
}
}