use of alluxio.client.journal.JournalMasterClient in project alluxio by Alluxio.
the class QuorumInfoCommand method run.
@Override
public int run(CommandLine cl) throws IOException {
JournalMasterClient jmClient = mMasterJournalMasterClient;
String domainVal = cl.getOptionValue(DOMAIN_OPTION_NAME);
try {
JournalDomain domain = JournalDomain.valueOf(domainVal);
if (domain == JournalDomain.JOB_MASTER) {
jmClient = mJobMasterJournalMasterClient;
}
} catch (IllegalArgumentException e) {
throw new InvalidArgumentException(ExceptionMessage.INVALID_OPTION_VALUE.getMessage(DOMAIN_OPTION_NAME, Arrays.toString(JournalDomain.values())));
}
GetQuorumInfoPResponse quorumInfo = jmClient.getQuorumInfo();
Optional<QuorumServerInfo> leadingMasterInfoOpt = quorumInfo.getServerInfoList().stream().filter(QuorumServerInfo::getIsLeader).findFirst();
String leadingMasterAddr = leadingMasterInfoOpt.isPresent() ? netAddressToString(leadingMasterInfoOpt.get().getServerAddress()) : "UNKNOWN";
List<String[]> table = quorumInfo.getServerInfoList().stream().map(info -> new String[] { info.getServerState().toString(), Integer.toString(info.getPriority()), netAddressToString(info.getServerAddress()) }).collect(Collectors.toList());
table.add(0, new String[] { "STATE", "PRIORITY", "SERVER ADDRESS" });
mPrintStream.println(String.format(OUTPUT_HEADER_DOMAIN, quorumInfo.getDomain()));
mPrintStream.println(String.format(OUTPUT_HEADER_QUORUM_SIZE, quorumInfo.getServerInfoList().size()));
mPrintStream.println(String.format(OUTPUT_HEADER_LEADING_MASTER, leadingMasterAddr));
mPrintStream.println();
for (String[] output : table) {
mPrintStream.printf(OUTPUT_SERVER_INFO, output);
}
return 0;
}
use of alluxio.client.journal.JournalMasterClient in project alluxio by Alluxio.
the class QuorumElectCommand method run.
@Override
public int run(CommandLine cl) throws IOException {
JournalMasterClient jmClient = mMasterJournalMasterClient;
String serverAddress = cl.getOptionValue(ADDRESS_OPTION_NAME);
NetAddress address = QuorumCommand.stringToAddress(serverAddress);
boolean success = false;
try {
mPrintStream.println(String.format(TRANSFER_INIT, serverAddress));
String transferId = jmClient.transferLeadership(address);
AtomicReference<String> errorMessage = new AtomicReference<>("");
// wait for confirmation of leadership transfer
// in milliseconds
final int TIMEOUT_3MIN = 3 * 60 * 1000;
CommonUtils.waitFor("election to finalize.", () -> {
try {
errorMessage.set(jmClient.getTransferLeaderMessage(transferId).getTransMsg().getMsg());
if (!errorMessage.get().isEmpty()) {
// if an error is reported, end the retry immediately
return true;
}
GetQuorumInfoPResponse quorumInfo = jmClient.getQuorumInfo();
Optional<QuorumServerInfo> leadingMasterInfoOpt = quorumInfo.getServerInfoList().stream().filter(QuorumServerInfo::getIsLeader).findFirst();
NetAddress leaderAddress = leadingMasterInfoOpt.isPresent() ? leadingMasterInfoOpt.get().getServerAddress() : null;
return address.equals(leaderAddress);
} catch (IOException e) {
return false;
}
}, WaitForOptions.defaults().setTimeoutMs(TIMEOUT_3MIN));
if (!errorMessage.get().isEmpty()) {
throw new Exception(errorMessage.get());
}
mPrintStream.println(String.format(TRANSFER_SUCCESS, serverAddress));
success = true;
} catch (Exception e) {
mPrintStream.println(String.format(TRANSFER_FAILED, serverAddress, e.getMessage()));
}
// reset priorities regardless of transfer success
try {
mPrintStream.println(String.format(RESET_INIT, success ? "successful" : "failed"));
jmClient.resetPriorities();
mPrintStream.println(RESET_SUCCESS);
} catch (IOException e) {
mPrintStream.println(String.format(RESET_FAILED, e));
success = false;
}
return success ? 0 : -1;
}
use of alluxio.client.journal.JournalMasterClient in project alluxio by Alluxio.
the class QuorumRemoveCommand method run.
@Override
public int run(CommandLine cl) throws IOException {
JournalMasterClient jmClient = mMasterJournalMasterClient;
String domainVal = cl.getOptionValue(DOMAIN_OPTION_NAME);
try {
JournalDomain domain = JournalDomain.valueOf(domainVal);
if (domain == JournalDomain.JOB_MASTER) {
jmClient = mJobMasterJournalMasterClient;
}
} catch (IllegalArgumentException e) {
throw new InvalidArgumentException(ExceptionMessage.INVALID_OPTION_VALUE.getMessage(DOMAIN_OPTION_NAME, Arrays.toString(JournalDomain.values())));
}
String serverAddress = cl.getOptionValue(ADDRESS_OPTION_NAME);
jmClient.removeQuorumServer(QuorumCommand.stringToAddress(serverAddress));
mPrintStream.println(String.format(OUTPUT_RESULT, serverAddress, domainVal));
return 0;
}
Aggregations