Search in sources :

Example 1 with JournalMasterClient

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;
}
Also used : JournalMasterClient(alluxio.client.journal.JournalMasterClient) QuorumServerInfo(alluxio.grpc.QuorumServerInfo) Arrays(java.util.Arrays) NetAddress(alluxio.grpc.NetAddress) ExceptionMessage(alluxio.exception.ExceptionMessage) Options(org.apache.commons.cli.Options) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) List(java.util.List) Context(alluxio.cli.fsadmin.command.Context) GetQuorumInfoPResponse(alluxio.grpc.GetQuorumInfoPResponse) AbstractFsAdminCommand(alluxio.cli.fsadmin.command.AbstractFsAdminCommand) AlluxioConfiguration(alluxio.conf.AlluxioConfiguration) CommandLine(org.apache.commons.cli.CommandLine) Optional(java.util.Optional) VisibleForTesting(com.google.common.annotations.VisibleForTesting) JournalDomain(alluxio.grpc.JournalDomain) InvalidArgumentException(alluxio.exception.status.InvalidArgumentException) InvalidArgumentException(alluxio.exception.status.InvalidArgumentException) GetQuorumInfoPResponse(alluxio.grpc.GetQuorumInfoPResponse) QuorumServerInfo(alluxio.grpc.QuorumServerInfo) JournalMasterClient(alluxio.client.journal.JournalMasterClient) JournalDomain(alluxio.grpc.JournalDomain)

Example 2 with JournalMasterClient

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;
}
Also used : GetQuorumInfoPResponse(alluxio.grpc.GetQuorumInfoPResponse) AtomicReference(java.util.concurrent.atomic.AtomicReference) QuorumServerInfo(alluxio.grpc.QuorumServerInfo) IOException(java.io.IOException) IOException(java.io.IOException) InvalidArgumentException(alluxio.exception.status.InvalidArgumentException) JournalMasterClient(alluxio.client.journal.JournalMasterClient) NetAddress(alluxio.grpc.NetAddress)

Example 3 with JournalMasterClient

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;
}
Also used : InvalidArgumentException(alluxio.exception.status.InvalidArgumentException) JournalMasterClient(alluxio.client.journal.JournalMasterClient) JournalDomain(alluxio.grpc.JournalDomain)

Aggregations

JournalMasterClient (alluxio.client.journal.JournalMasterClient)3 InvalidArgumentException (alluxio.exception.status.InvalidArgumentException)3 GetQuorumInfoPResponse (alluxio.grpc.GetQuorumInfoPResponse)2 JournalDomain (alluxio.grpc.JournalDomain)2 NetAddress (alluxio.grpc.NetAddress)2 QuorumServerInfo (alluxio.grpc.QuorumServerInfo)2 IOException (java.io.IOException)2 AbstractFsAdminCommand (alluxio.cli.fsadmin.command.AbstractFsAdminCommand)1 Context (alluxio.cli.fsadmin.command.Context)1 AlluxioConfiguration (alluxio.conf.AlluxioConfiguration)1 ExceptionMessage (alluxio.exception.ExceptionMessage)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Arrays (java.util.Arrays)1 List (java.util.List)1 Optional (java.util.Optional)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Collectors (java.util.stream.Collectors)1 CommandLine (org.apache.commons.cli.CommandLine)1 Options (org.apache.commons.cli.Options)1