Search in sources :

Example 1 with InvalidArgumentException

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

the class DefaultFileSystemMaster method updateMountInternal.

private void updateMountInternal(Supplier<JournalContext> journalContext, LockedInodePath inodePath, AlluxioURI ufsPath, MountInfo mountInfo, MountContext context) throws FileAlreadyExistsException, InvalidPathException, IOException {
    long newMountId = IdUtils.createMountId();
    // lock sync manager to ensure no sync point is added before the mount point is removed
    try (LockResource r = new LockResource(mSyncManager.getLock())) {
        List<AlluxioURI> syncPoints = mSyncManager.getFilterList(mountInfo.getMountId());
        if (syncPoints != null && !syncPoints.isEmpty()) {
            throw new InvalidArgumentException("Updating a mount point with ActiveSync enabled is not" + " supported. Please remove all sync'ed paths from the mount point and try again.");
        }
        AlluxioURI alluxioPath = inodePath.getUri();
        // validate new UFS client before updating the mount table
        mUfsManager.addMount(newMountId, new AlluxioURI(ufsPath.toString()), UnderFileSystemConfiguration.defaults(ServerConfiguration.global()).setReadOnly(context.getOptions().getReadOnly()).setShared(context.getOptions().getShared()).createMountSpecificConf(context.getOptions().getPropertiesMap()));
        prepareForMount(ufsPath, newMountId, context);
        // old ufsClient is removed as part of the mount table update process
        mMountTable.update(journalContext, alluxioPath, newMountId, context.getOptions().build());
    } catch (FileAlreadyExistsException | InvalidPathException | IOException e) {
        // revert everything
        mUfsManager.removeMount(newMountId);
        throw e;
    }
}
Also used : FileAlreadyExistsException(alluxio.exception.FileAlreadyExistsException) InvalidArgumentException(alluxio.exception.status.InvalidArgumentException) LockResource(alluxio.resource.LockResource) IOException(java.io.IOException) InvalidPathException(alluxio.exception.InvalidPathException) AlluxioURI(alluxio.AlluxioURI)

Example 2 with InvalidArgumentException

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

the class ValidateEnv method validate.

/**
 * Validates environment.
 *
 * @param argv list of arguments
 * @return 0 on success, -1 on validation failures, -2 on invalid arguments
 */
public static int validate(String... argv) throws InterruptedException {
    if (argv.length < 1) {
        printHelp("Target not specified.");
        return -2;
    }
    String command = argv[0];
    String name = null;
    String[] args;
    int argsLength = 0;
    // Find all non-option command line arguments.
    while (argsLength < argv.length && !argv[argsLength].startsWith("-")) {
        argsLength++;
    }
    if (argsLength > 1) {
        name = argv[1];
        args = Arrays.copyOfRange(argv, 2, argv.length);
    } else {
        args = Arrays.copyOfRange(argv, 1, argv.length);
    }
    CommandLine cmd;
    try {
        cmd = parseArgsAndOptions(OPTIONS, args);
    } catch (InvalidArgumentException e) {
        System.err.format("Invalid argument: %s.%n", e.getMessage());
        return -1;
    }
    if (command.equals("list")) {
        // Validate against root path
        AlluxioConfiguration conf = InstancedConfiguration.defaults();
        String rootPath = conf.getString(PropertyKey.MASTER_MOUNT_TABLE_ROOT_UFS);
        ValidateEnv task = new ValidateEnv(rootPath, conf);
        task.printTasks();
        return 0;
    }
    return runTasks(command, name, cmd);
}
Also used : CommandLine(org.apache.commons.cli.CommandLine) InvalidArgumentException(alluxio.exception.status.InvalidArgumentException) AlluxioConfiguration(alluxio.conf.AlluxioConfiguration)

Example 3 with InvalidArgumentException

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

the class ValidateEnv method parseArgsAndOptions.

/**
 * Parses the command line arguments and options in {@code args}.
 *
 * After successful execution of this method, command line arguments can be
 * retrieved by invoking {@link CommandLine#getArgs()}, and options can be
 * retrieved by calling {@link CommandLine#getOptions()}.
 *
 * @param args command line arguments to parse
 * @return {@link CommandLine} object representing the parsing result
 * @throws InvalidArgumentException if command line contains invalid argument(s)
 */
private static CommandLine parseArgsAndOptions(Options options, String... args) throws InvalidArgumentException {
    CommandLineParser parser = new DefaultParser();
    CommandLine cmd;
    try {
        cmd = parser.parse(options, args);
    } catch (ParseException e) {
        throw new InvalidArgumentException("Failed to parse args for validateEnv", e);
    }
    return cmd;
}
Also used : CommandLine(org.apache.commons.cli.CommandLine) InvalidArgumentException(alluxio.exception.status.InvalidArgumentException) CommandLineParser(org.apache.commons.cli.CommandLineParser) ParseException(org.apache.commons.cli.ParseException) DefaultParser(org.apache.commons.cli.DefaultParser)

Example 4 with InvalidArgumentException

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

the class DoctorCommand method run.

@Override
public int run(CommandLine cl) throws IOException {
    String[] args = cl.getArgs();
    if (cl.hasOption(HELP_OPTION_NAME)) {
        System.out.println(getUsage());
        System.out.println(getDescription());
        return 0;
    }
    FileSystemAdminShellUtils.checkMasterClientService(mConf);
    // Get the doctor category
    Command command = Command.ALL;
    if (args.length == 1) {
        switch(args[0]) {
            case "configuration":
                command = Command.CONFIGURATION;
                break;
            case "storage":
                command = Command.STORAGE;
                break;
            default:
                System.out.println(getUsage());
                System.out.println(getDescription());
                throw new InvalidArgumentException("doctor category is invalid.");
        }
    }
    if (command.equals(Command.CONFIGURATION) || command.equals(Command.ALL)) {
        ConfigurationCommand configurationCommand = new ConfigurationCommand(mMetaClient, System.out);
        configurationCommand.run();
    }
    if (command.equals(Command.STORAGE) || command.equals(Command.ALL)) {
        StorageCommand storageCommand = new StorageCommand(mBlockClient, System.out);
        storageCommand.run();
    }
    return 0;
}
Also used : InvalidArgumentException(alluxio.exception.status.InvalidArgumentException) ConfigurationCommand(alluxio.cli.fsadmin.doctor.ConfigurationCommand) ConfigurationCommand(alluxio.cli.fsadmin.doctor.ConfigurationCommand) StorageCommand(alluxio.cli.fsadmin.doctor.StorageCommand) StorageCommand(alluxio.cli.fsadmin.doctor.StorageCommand)

Example 5 with InvalidArgumentException

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

the class SetTtlCommand method validateArgs.

@Override
public void validateArgs(CommandLine cl) throws InvalidArgumentException {
    CommandUtils.checkNumOfArgsEquals(this, cl, 2);
    String operation = cl.getOptionValue(TTL_ACTION);
    if (operation != null) {
        try {
            mAction = TtlAction.valueOf(operation.toUpperCase());
        } catch (Exception e) {
            throw new InvalidArgumentException(String.format("TTL action should be %s OR %s, not %s", TtlAction.DELETE, TtlAction.FREE, operation));
        }
    }
}
Also used : InvalidArgumentException(alluxio.exception.status.InvalidArgumentException) AlluxioException(alluxio.exception.AlluxioException) 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