Search in sources :

Example 6 with InvalidArgumentException

use of alluxio.exception.status.InvalidArgumentException in project alluxio by Alluxio.

the class CapacityCommand method getOptions.

/**
 * Gets the worker info options.
 *
 * @param cl CommandLine that contains the client options
 * @return GetWorkerReportOptions to get worker information
 */
private GetWorkerReportOptions getOptions(CommandLine cl) throws IOException {
    if (cl.getOptions().length > 1) {
        System.out.println(getUsage());
        throw new InvalidArgumentException("Too many arguments passed in.");
    }
    GetWorkerReportOptions workerOptions = GetWorkerReportOptions.defaults();
    Set<WorkerInfoField> fieldRange = new HashSet<>(Arrays.asList(WorkerInfoField.ADDRESS, WorkerInfoField.WORKER_CAPACITY_BYTES, WorkerInfoField.WORKER_CAPACITY_BYTES_ON_TIERS, WorkerInfoField.LAST_CONTACT_SEC, WorkerInfoField.WORKER_USED_BYTES, WorkerInfoField.WORKER_USED_BYTES_ON_TIERS));
    workerOptions.setFieldRange(fieldRange);
    if (cl.hasOption(ReportCommand.LIVE_OPTION_NAME)) {
        workerOptions.setWorkerRange(WorkerRange.LIVE);
    } else if (cl.hasOption(ReportCommand.LOST_OPTION_NAME)) {
        workerOptions.setWorkerRange(WorkerRange.LOST);
    } else if (cl.hasOption(ReportCommand.SPECIFIED_OPTION_NAME)) {
        workerOptions.setWorkerRange(WorkerRange.SPECIFIED);
        String addressString = cl.getOptionValue(ReportCommand.SPECIFIED_OPTION_NAME);
        String[] addressArray = addressString.split(",");
        // Addresses in GetWorkerReportOptions is only used when WorkerRange is SPECIFIED
        workerOptions.setAddresses(new HashSet<>(Arrays.asList(addressArray)));
    }
    return workerOptions;
}
Also used : InvalidArgumentException(alluxio.exception.status.InvalidArgumentException) GetWorkerReportOptions(alluxio.client.block.options.GetWorkerReportOptions) WorkerInfoField(alluxio.client.block.options.GetWorkerReportOptions.WorkerInfoField) HashSet(java.util.HashSet)

Example 7 with InvalidArgumentException

use of alluxio.exception.status.InvalidArgumentException in project alluxio by Alluxio.

the class CancelCommand method validateArgs.

@Override
public void validateArgs(CommandLine cl) throws InvalidArgumentException {
    CommandUtils.checkNumOfArgsEquals(this, cl, 1);
    String arg = cl.getArgs()[0];
    try {
        Long.parseLong(arg);
    } catch (Exception e) {
        throw new InvalidArgumentException(ExceptionMessage.INVALID_ARG_TYPE.getMessage(arg, "long"));
    }
}
Also used : InvalidArgumentException(alluxio.exception.status.InvalidArgumentException) InvalidArgumentException(alluxio.exception.status.InvalidArgumentException)

Example 8 with InvalidArgumentException

use of alluxio.exception.status.InvalidArgumentException in project alluxio by Alluxio.

the class QuorumCommand method stringToAddress.

/**
 * @param serverAddress the string containing the hostname and port separated by a ':
 * @return a NetAddress object composed of a hostname and a port
 * @throws InvalidArgumentException
 */
public static NetAddress stringToAddress(String serverAddress) throws InvalidArgumentException {
    String hostName;
    int port;
    try {
        hostName = serverAddress.substring(0, serverAddress.indexOf(":"));
        port = Integer.parseInt(serverAddress.substring(serverAddress.indexOf(":") + 1));
    } catch (Exception e) {
        throw new InvalidArgumentException(ExceptionMessage.INVALID_ADDRESS_VALUE.getMessage());
    }
    return NetAddress.newBuilder().setHost(hostName).setRpcPort(port).build();
}
Also used : InvalidArgumentException(alluxio.exception.status.InvalidArgumentException) InvalidArgumentException(alluxio.exception.status.InvalidArgumentException)

Example 9 with InvalidArgumentException

use of alluxio.exception.status.InvalidArgumentException 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 10 with InvalidArgumentException

use of alluxio.exception.status.InvalidArgumentException in project alluxio by Alluxio.

the class GetBlockInfoCommand method run.

@Override
public int run(CommandLine cl) throws IOException {
    if (cl.hasOption(HELP_OPTION_NAME)) {
        System.out.println(getUsage());
        System.out.println(getDescription());
        return 0;
    }
    FileSystemAdminShellUtils.checkMasterClientService(mConf);
    long blockId;
    String arg = cl.getArgs()[0];
    try {
        blockId = Long.parseLong(arg);
    } catch (NumberFormatException e) {
        throw new InvalidArgumentException(arg + " is not a valid block id.");
    }
    BlockInfo info = null;
    try {
        info = mBlockClient.getBlockInfo(blockId);
    } catch (Exception e) {
    // ignore
    }
    long fileId = BlockId.getFileId(blockId);
    String path = null;
    try {
        path = mFsClient.getFilePath(fileId);
    } catch (Exception e) {
    // ignore
    }
    if (info != null) {
        System.out.println(info);
    } else {
        System.out.println("BlockMeta is not available for blockId: " + blockId);
    }
    if (path != null) {
        System.out.printf("This block belongs to file {id=%s, path=%s}%n", fileId, path);
    } else {
        System.out.printf("This block belongs to file {id=%s}%n", fileId);
    }
    return 0;
}
Also used : InvalidArgumentException(alluxio.exception.status.InvalidArgumentException) BlockInfo(alluxio.wire.BlockInfo) IOException(java.io.IOException) InvalidArgumentException(alluxio.exception.status.InvalidArgumentException)

Aggregations

InvalidArgumentException (alluxio.exception.status.InvalidArgumentException)22 IOException (java.io.IOException)6 CommandLine (org.apache.commons.cli.CommandLine)5 AlluxioURI (alluxio.AlluxioURI)3 ParseException (org.apache.commons.cli.ParseException)3 JournalMasterClient (alluxio.client.journal.JournalMasterClient)2 AlluxioConfiguration (alluxio.conf.AlluxioConfiguration)2 AlluxioException (alluxio.exception.AlluxioException)2 InvalidPathException (alluxio.exception.InvalidPathException)2 JournalDomain (alluxio.grpc.JournalDomain)2 HashSet (java.util.HashSet)2 CommandLineParser (org.apache.commons.cli.CommandLineParser)2 DefaultParser (org.apache.commons.cli.DefaultParser)2 Options (org.apache.commons.cli.Options)2 AbstractFsAdminCommand (alluxio.cli.fsadmin.command.AbstractFsAdminCommand)1 Context (alluxio.cli.fsadmin.command.Context)1 ConfigurationCommand (alluxio.cli.fsadmin.doctor.ConfigurationCommand)1 StorageCommand (alluxio.cli.fsadmin.doctor.StorageCommand)1 CapacityCommand (alluxio.cli.fsadmin.report.CapacityCommand)1 JobServiceMetricsCommand (alluxio.cli.fsadmin.report.JobServiceMetricsCommand)1