Java Code Examples for org.apache.ratis.protocol.RaftPeerId#getRaftPeerId()

The following examples show how to use org.apache.ratis.protocol.RaftPeerId#getRaftPeerId() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FollowerAppendLogEntryGenerator.java    From hadoop-ozone with Apache License 2.0 5 votes vote down vote up
/**
 * Configure raft group before using raft service.
 */
private void configureGroup() throws IOException {

  ClientId clientId = ClientId.randomId();

  RaftGroupId groupId = RaftGroupId
      .valueOf(UUID.fromString(pipelineId));

  RaftPeerId peerId =
      RaftPeerId.getRaftPeerId(serverId);

  RaftGroup group = RaftGroup.valueOf(groupId,
      new RaftPeer(RaftPeerId.valueOf(serverId), serverAddress),
      new RaftPeer(RaftPeerId.valueOf(FAKE_LEADER_ID),
          FAKE_LEADER_ADDDRESS));
  RaftClient client = RaftClient.newBuilder()
      .setClientId(clientId)
      .setProperties(new RaftProperties(true))
      .setRaftGroup(group)
      .build();

  RaftClientReply raftClientReply = client.groupAdd(group, peerId);

  LOG.info(
      "Group is configured in the RAFT server (one follower, one fake "
          + "leader): {}", raftClientReply);
}
 
Example 2
Source File: LeaderAppendLogEntryGenerator.java    From hadoop-ozone with Apache License 2.0 5 votes vote down vote up
private void configureGroup() throws IOException {
  ClientId clientId = ClientId.randomId();

  RaftGroupId groupId = RaftGroupId
      .valueOf(UUID.fromString(pipelineId));
  RaftPeerId peerId =
      RaftPeerId.getRaftPeerId(serverId);

  RaftGroup group = RaftGroup.valueOf(groupId,
      new RaftPeer(RaftPeerId.valueOf(serverId), serverAddress),
      new RaftPeer(RaftPeerId.valueOf(FAKE_FOLLOWER_ID1),
          FAKE_LEADER_ADDDRESS1),
      new RaftPeer(RaftPeerId.valueOf(FAKE_FOLLOWER_ID1),
          FAKE_LEADER_ADDDRESS2));
  RaftClient client = RaftClient.newBuilder()
      .setClientId(clientId)
      .setProperties(new RaftProperties(true))
      .setRaftGroup(group)
      .build();

  RaftClientReply raftClientReply = client.groupAdd(group, peerId);

  LOG.info(
      "Group is configured in the RAFT server (with two fake leader leader)"
          + ": {}",
      raftClientReply);
}
 
Example 3
Source File: SegmentedRaftLog.java    From incubator-ratis with Apache License 2.0 4 votes vote down vote up
@Override
public Metadata loadMetadata() throws IOException {
  return new Metadata(
      RaftPeerId.getRaftPeerId(storage.getMetaFile().getVotedFor()),
      storage.getMetaFile().getTerm());
}
 
Example 4
Source File: SegmentedRaftLog.java    From ratis with Apache License 2.0 4 votes vote down vote up
@Override
public Metadata loadMetadata() throws IOException {
  return new Metadata(
      RaftPeerId.getRaftPeerId(storage.getMetaFile().getVotedFor()),
      storage.getMetaFile().getTerm());
}