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()));
}
}
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.
}
}
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"));
}
}
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;
}
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;
}
Aggregations