Search in sources :

Example 11 with CommandValidationException

use of org.glassfish.api.admin.CommandValidationException in project Payara by payara.

the class AdminMain method executeCommand.

public int executeCommand(String[] argv) {
    CLICommand cmd = null;
    try {
        // if the first argument is an option, we're using the new form
        if (argv.length > 0 && argv[0].startsWith("-")) {
            /*
                 * Parse all the admin options, stopping at the first
                 * non-option, which is the command name.
                 */
            Parser rcp = new Parser(argv, 0, ProgramOptions.getValidOptions(), false);
            ParameterMap params = rcp.getOptions();
            po = new ProgramOptions(params, env);
            readAndMergeOptionsFromAuxInput(po);
            List<String> operands = rcp.getOperands();
            argv = operands.toArray(new String[operands.size()]);
        } else {
            po = new ProgramOptions(env);
        }
        po.toEnvironment(env);
        po.setClassPath(classPath);
        po.setClassName(className);
        po.setCommandName(getCommandName());
        if (argv.length == 0) {
            if (po.isHelp()) {
                argv = new String[] { "help" };
            } else {
                argv = new String[] { "multimode" };
            }
        }
        command = argv[0];
        cliContainer.setEnvironment(env);
        cliContainer.setProgramOptions(po);
        cmd = CLICommand.getCommand(cliContainer, command);
        int result = cmd.execute(argv);
        return result;
    } catch (CommandValidationException cve) {
        logger.severe(cve.getMessage());
        if (// error parsing program options
        cmd == null) {
            printUsage();
        } else {
            logger.severe(cmd.getUsage());
        }
        return ERROR;
    } catch (InvalidCommandException ice) {
        // find closest match with local or remote commands
        logger.severe(ice.getMessage());
        try {
            po.setEcho(false);
            CLIUtil.displayClosestMatch(command, CLIUtil.getAllCommands(cliContainer, po, env), strings.get("ClosestMatchedLocalAndRemoteCommands"), logger);
        } catch (InvalidCommandException e) {
        // not a big deal if we cannot help
        }
        return ERROR;
    } catch (CommandException ce) {
        if (ce.getCause() instanceof java.net.ConnectException) {
            // find closest match with local commands
            logger.severe(ce.getMessage());
            try {
                CLIUtil.displayClosestMatch(command, CLIUtil.getLocalCommands(cliContainer), strings.get("ClosestMatchedLocalCommands"), logger);
            } catch (InvalidCommandException e) {
                logger.info(strings.get("InvalidRemoteCommand", command));
            }
        } else {
            logger.severe(ce.getMessage());
        }
        return ERROR;
    }
}
Also used : InvalidCommandException(org.glassfish.api.admin.InvalidCommandException) CommandValidationException(org.glassfish.api.admin.CommandValidationException) ParameterMap(org.glassfish.api.admin.ParameterMap) InvalidCommandException(org.glassfish.api.admin.InvalidCommandException) CommandException(org.glassfish.api.admin.CommandException)

Example 12 with CommandValidationException

use of org.glassfish.api.admin.CommandValidationException in project Payara by payara.

the class CreateLocalInstanceCommand method validateNodeInstallDirLocal.

private void validateNodeInstallDirLocal(String nodeInstallDir, String installDir) throws CommandValidationException {
    String canonicalNodeInstallDir = FileUtils.safeGetCanonicalPath(new File(nodeInstallDir));
    String canonicalInstallDir = FileUtils.safeGetCanonicalPath(new File(installDir));
    if (canonicalNodeInstallDir == null || canonicalInstallDir == null) {
        throw new CommandValidationException(Strings.get("Instance.installdir.null", node, canonicalInstallDir, canonicalNodeInstallDir));
    }
    if (!canonicalInstallDir.equals(canonicalNodeInstallDir)) {
        throw new CommandValidationException(Strings.get("Instance.installdir.mismatch", node, canonicalInstallDir, canonicalNodeInstallDir));
    }
}
Also used : CommandValidationException(org.glassfish.api.admin.CommandValidationException) File(java.io.File)

Aggregations

CommandValidationException (org.glassfish.api.admin.CommandValidationException)12 CommandException (org.glassfish.api.admin.CommandException)9 File (java.io.File)5 CLIProcessExecutor (com.sun.enterprise.admin.cli.CLIProcessExecutor)2 InvalidCommandException (org.glassfish.api.admin.InvalidCommandException)2 StoreException (com.sun.appserv.management.client.prefs.StoreException)1 ArgumentTokenizer (com.sun.enterprise.admin.cli.ArgumentTokenizer)1 ProgramOptions (com.sun.enterprise.admin.cli.ProgramOptions)1 DomainBuilder (com.sun.enterprise.admin.servermgmt.domain.DomainBuilder)1 PEDomainsManager (com.sun.enterprise.admin.servermgmt.pe.PEDomainsManager)1 CommandModelData (com.sun.enterprise.admin.util.CommandModelData)1 ParamModelData (com.sun.enterprise.admin.util.CommandModelData.ParamModelData)1 BackupRequest (com.sun.enterprise.backup.BackupRequest)1 Console (java.io.Console)1 IOException (java.io.IOException)1 ActionReport (org.glassfish.api.ActionReport)1 ParameterMap (org.glassfish.api.admin.ParameterMap)1