Search in sources :

Example 16 with InvalidArgumentException

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

the class FuseShell method runCommand.

/**
 * @param uri that includes command information
 * @return a mock URIStatus instance
 */
public URIStatus runCommand(AlluxioURI uri) throws InvalidArgumentException {
    // TODO(bingzheng): extend some other operations.
    AlluxioURI path = uri.getParent();
    int index = uri.getPath().lastIndexOf(Constants.ALLUXIO_CLI_PATH);
    String cmdsInfo = uri.getPath().substring(index);
    String[] cmds = cmdsInfo.split("\\.");
    if (cmds.length <= 2) {
        logUsage();
        throw new InvalidArgumentException("Command is needed in Fuse shell");
    }
    FuseCommand command = (FuseCommand) mCommands.get(cmds[2]);
    if (command == null) {
        logUsage();
        throw new InvalidArgumentException(String.format("%s is an unknown command.", cmds[2]));
    }
    try {
        String[] currArgs = Arrays.copyOfRange(cmds, 2, cmds.length);
        while (command.hasSubCommand()) {
            if (currArgs.length < 2) {
                throw new InvalidArgumentException("No sub-command is specified");
            }
            if (!command.getSubCommands().containsKey(currArgs[1])) {
                throw new InvalidArgumentException("Unknown sub-command: " + currArgs[1]);
            }
            command = (FuseCommand) command.getSubCommands().get(currArgs[1]);
            currArgs = Arrays.copyOfRange(currArgs, 1, currArgs.length);
        }
        command.validateArgs(Arrays.copyOfRange(currArgs, 1, currArgs.length));
        return command.run(path, Arrays.copyOfRange(currArgs, 1, currArgs.length));
    } catch (Exception e) {
        LOG.info(command.getDescription());
        LOG.info("Usage: " + command.getUsage());
        throw new InvalidArgumentException(String.format("Invalid arguments for command %s, " + "For detailed usage please see the log formation above.", command.getCommandName()));
    }
}
Also used : InvalidArgumentException(alluxio.exception.status.InvalidArgumentException) InvalidArgumentException(alluxio.exception.status.InvalidArgumentException) AlluxioURI(alluxio.AlluxioURI)

Example 17 with InvalidArgumentException

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

the class DefaultFileSystemMaster method setAclSingleInode.

private void setAclSingleInode(RpcContext rpcContext, SetAclAction action, LockedInodePath inodePath, List<AclEntry> entries, boolean replay, long opTimeMs) throws IOException, FileDoesNotExistException {
    Preconditions.checkState(inodePath.getLockPattern().isWrite());
    Inode inode = inodePath.getInode();
    // Check that we are not removing an extended mask.
    if (action == SetAclAction.REMOVE) {
        for (AclEntry entry : entries) {
            if ((entry.isDefault() && inode.getDefaultACL().hasExtended()) || (!entry.isDefault() && inode.getACL().hasExtended())) {
                if (entry.getType() == AclEntryType.MASK) {
                    throw new InvalidArgumentException("Deleting the mask for an extended ACL is not allowed. entry: " + entry);
                }
            }
        }
    }
    // Check that we are not setting default ACL to a file
    if (inode.isFile()) {
        for (AclEntry entry : entries) {
            if (entry.isDefault()) {
                throw new UnsupportedOperationException("Can not set default ACL for a file");
            }
        }
    }
    mInodeTree.setAcl(rpcContext, SetAclEntry.newBuilder().setId(inode.getId()).setOpTimeMs(opTimeMs).setAction(ProtoUtils.toProto(action)).addAllEntries(entries.stream().map(ProtoUtils::toProto).collect(Collectors.toList())).build());
    try {
        if (!replay && inode.isPersisted()) {
            setUfsAcl(inodePath);
        }
    } catch (InvalidPathException | AccessControlException e) {
        LOG.warn("Setting ufs ACL failed for path: {}", inodePath.getUri(), e);
    // TODO(david): revert the acl and default acl to the initial state if writing to ufs failed.
    }
}
Also used : Inode(alluxio.master.file.meta.Inode) InvalidArgumentException(alluxio.exception.status.InvalidArgumentException) AclEntry(alluxio.security.authorization.AclEntry) SetAclEntry(alluxio.proto.journal.File.SetAclEntry) ProtoUtils(alluxio.util.proto.ProtoUtils) AccessControlException(alluxio.exception.AccessControlException) InvalidPathException(alluxio.exception.InvalidPathException)

Example 18 with InvalidArgumentException

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

the class StatCommand 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) AlluxioException(alluxio.exception.AlluxioException) IOException(java.io.IOException) InvalidArgumentException(alluxio.exception.status.InvalidArgumentException)

Example 19 with InvalidArgumentException

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

the class AddCommand method run.

@Override
public int run(CommandLine cl) throws IOException {
    AlluxioURI path = new AlluxioURI(cl.getArgs()[0]);
    Map<PropertyKey, String> propertyMap = new HashMap<>();
    if (cl.hasOption(PROPERTY_OPTION_NAME)) {
        Map<String, String> properties = Maps.fromProperties(cl.getOptionProperties(PROPERTY_OPTION_NAME));
        for (Map.Entry<String, String> property : properties.entrySet()) {
            PropertyKey key = PropertyKey.fromString(property.getKey());
            if (!GrpcUtils.contains(key.getScope(), Scope.CLIENT)) {
                throw new InvalidArgumentException(nonClientScopePropertyException(key));
            }
            propertyMap.put(key, property.getValue());
        }
    }
    mMetaConfigClient.setPathConfiguration(path, propertyMap);
    return 0;
}
Also used : InvalidArgumentException(alluxio.exception.status.InvalidArgumentException) HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map) PropertyKey(alluxio.conf.PropertyKey) AlluxioURI(alluxio.AlluxioURI)

Example 20 with InvalidArgumentException

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

the class ReportCommand method run.

@Override
public int run(CommandLine cl) throws IOException {
    String[] args = cl.getArgs();
    if (cl.hasOption(HELP_OPTION_NAME) && !(args.length > 0 && args[0].equals("capacity"))) {
        // if category is capacity, we print report capacity usage inside CapacityCommand.
        System.out.println(getUsage());
        System.out.println(getDescription());
        return 0;
    }
    FileSystemAdminShellUtils.checkMasterClientService(mConf);
    // Get the report category
    Command command = Command.SUMMARY;
    if (args.length == 1) {
        switch(args[0]) {
            case "capacity":
                command = Command.CAPACITY;
                break;
            case "metrics":
                command = Command.METRICS;
                break;
            case "summary":
                command = Command.SUMMARY;
                break;
            case "ufs":
                command = Command.UFS;
                break;
            case "jobservice":
                command = Command.JOBSERVICE;
                break;
            default:
                System.out.println(getUsage());
                System.out.println(getDescription());
                throw new InvalidArgumentException("report category is invalid.");
        }
    }
    // Only capacity category has [category args]
    if (!command.equals(Command.CAPACITY)) {
        if (cl.getOptions().length > 0) {
            throw new InvalidArgumentException(String.format("report %s does not support arguments: %s", command.toString().toLowerCase(), cl.getOptions()[0].getOpt()));
        }
    }
    switch(command) {
        case CAPACITY:
            CapacityCommand capacityCommand = new CapacityCommand(mBlockClient, mPrintStream);
            capacityCommand.run(cl);
            break;
        case METRICS:
            MetricsCommand metricsCommand = new MetricsCommand(mMetricsClient, mPrintStream);
            metricsCommand.run();
            break;
        case SUMMARY:
            SummaryCommand summaryCommand = new SummaryCommand(mMetaClient, mBlockClient, mConf.getString(PropertyKey.USER_DATE_FORMAT_PATTERN), mPrintStream);
            summaryCommand.run();
            break;
        case UFS:
            UfsCommand ufsCommand = new UfsCommand(mFsClient);
            ufsCommand.run();
            break;
        case JOBSERVICE:
            JobServiceMetricsCommand jobmetricsCommand = new JobServiceMetricsCommand(mJobMasterClient, mPrintStream, mConf.getString(PropertyKey.USER_DATE_FORMAT_PATTERN));
            jobmetricsCommand.run();
            break;
        default:
            break;
    }
    return 0;
}
Also used : JobServiceMetricsCommand(alluxio.cli.fsadmin.report.JobServiceMetricsCommand) MetricsCommand(alluxio.cli.fsadmin.report.MetricsCommand) SummaryCommand(alluxio.cli.fsadmin.report.SummaryCommand) InvalidArgumentException(alluxio.exception.status.InvalidArgumentException) JobServiceMetricsCommand(alluxio.cli.fsadmin.report.JobServiceMetricsCommand) SummaryCommand(alluxio.cli.fsadmin.report.SummaryCommand) CapacityCommand(alluxio.cli.fsadmin.report.CapacityCommand) JobServiceMetricsCommand(alluxio.cli.fsadmin.report.JobServiceMetricsCommand) MetricsCommand(alluxio.cli.fsadmin.report.MetricsCommand) UfsCommand(alluxio.cli.fsadmin.report.UfsCommand) UfsCommand(alluxio.cli.fsadmin.report.UfsCommand) CapacityCommand(alluxio.cli.fsadmin.report.CapacityCommand)

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