Search in sources :

Example 6 with CommandValidationException

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

the class CreateDomainCommand method executeCommand.

/**
 */
@Override
protected int executeCommand() throws CommandException, CommandValidationException {
    // domain validation upfront (i.e. before we prompt)
    try {
        DomainsManager manager = new PEDomainsManager();
        DomainConfig config = new DomainConfig(domainName, domainDir);
        manager.validateDomain(config, false);
        verifyPortBase();
    } catch (DomainException e) {
        logger.fine(e.getLocalizedMessage());
        throw new CommandException(strings.get("CouldNotCreateDomain", domainName), e);
    }
    /*
         * The admin user is specified with the --user program option. If not
         * specified (because the user hit Enter at the prompt), we use the
         * default, which allows unauthenticated login.
         */
    adminUser = programOpts.getUser();
    if (!ok(adminUser)) {
        adminUser = SystemPropertyConstants.DEFAULT_ADMIN_USER;
        adminPassword = SystemPropertyConstants.DEFAULT_ADMIN_PASSWORD;
    } else if (noPassword) {
        adminPassword = SystemPropertyConstants.DEFAULT_ADMIN_PASSWORD;
    } else {
        char[] pwdArr = getAdminPassword();
        adminPassword = pwdArr != null ? new String(pwdArr) : null;
        boolean haveAdminPwd = true;
    }
    if (saveMasterPassword) {
        useMasterPassword = true;
    }
    if (masterPassword == null) {
        if (useMasterPassword) {
            char[] mpArr = getMasterPassword();
            masterPassword = mpArr != null ? new String(mpArr) : null;
        } else {
            masterPassword = DEFAULT_MASTER_PASSWORD;
        }
    }
    try {
        // verify admin port is valid if specified on command line
        if (adminPort != null) {
            verifyPortIsValid(adminPort);
        }
        // instance option is entered then verify instance port is valid
        if (instancePort != null) {
            verifyPortIsValid(instancePort);
        }
        // saving the login information happens inside this method
        createTheDomain(domainDir, domainProperties);
    } catch (CommandException ce) {
        logger.info(ce.getLocalizedMessage());
        throw new CommandException(strings.get("CouldNotCreateDomain", domainName), ce);
    } catch (Exception e) {
        logger.fine(e.getLocalizedMessage());
        throw new CommandException(strings.get("CouldNotCreateDomain", domainName), e);
    }
    return 0;
}
Also used : PEDomainsManager(com.sun.enterprise.admin.servermgmt.pe.PEDomainsManager) CommandException(org.glassfish.api.admin.CommandException) PEDomainsManager(com.sun.enterprise.admin.servermgmt.pe.PEDomainsManager) CommandException(org.glassfish.api.admin.CommandException) CommandValidationException(org.glassfish.api.admin.CommandValidationException)

Example 7 with CommandValidationException

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

the class RestoreDomainCommand method validate.

/**
 */
@Override
protected void validate() throws CommandException, CommandValidationException {
    boolean domainExists = true;
    if (backupFilename == null && domainName == null) {
        if (!force) {
            throw new CommandException(strings.get("UseForceOption"));
        }
        // this will properly initialize the domain dir
        // see LocalDomainCommand.initDomain())
        super.validate();
    }
    checkOptions();
    try {
        setDomainName(domainName);
        initDomain();
    } catch (CommandException e) {
        if (e.getCause() != null && (e.getCause() instanceof java.io.IOException)) {
            // The domain does not exist which is allowed if the
            // force option is used (checked later).
            domainExists = false;
        } else {
            throw e;
        }
    }
    if (domainExists && isRunning()) {
        throw new CommandException(strings.get("DomainIsNotStopped", domainName));
    }
    if (backupFilename != null) {
        File f = new File(backupFilename);
        if (!f.exists()) {
            throw new CommandValidationException(strings.get("FileDoesNotExist", backupFilename));
        }
        if (!f.canRead()) {
            throw new CommandValidationException(strings.get("FileCanNotRead", backupFilename));
        }
        if (f.isDirectory()) {
            throw new CommandValidationException(strings.get("FileIsDirectory", backupFilename));
        }
    }
    setBackupDir(backupdir);
    initRequest();
    // in case program options changed
    initializeLogger();
}
Also used : CommandValidationException(org.glassfish.api.admin.CommandValidationException) CommandException(org.glassfish.api.admin.CommandException) File(java.io.File)

Example 8 with CommandValidationException

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

the class RestoreDomainCommand method initRequest.

private void initRequest() throws CommandValidationException {
    File backupdir_f = null;
    if (backupdir != null) {
        backupdir_f = new File(backupdir);
        if (!backupdir_f.isAbsolute()) {
            throw new CommandValidationException(strings.get("InvalidBackupDirPath", backupdir));
        }
    }
    boolean configonlybackup = false;
    if ((configonly != null) && (Boolean.valueOf(configonly))) {
        configonlybackup = true;
    }
    request = new BackupRequest(domainDirParam, domainName, backupdir_f, backupConfig, backupFilename, configonlybackup);
    request.setTerse(programOpts.isTerse());
    request.setVerbose(verbose);
    request.setForce(force);
}
Also used : BackupRequest(com.sun.enterprise.backup.BackupRequest) CommandValidationException(org.glassfish.api.admin.CommandValidationException) File(java.io.File)

Example 9 with CommandValidationException

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

the class StopDatabaseCommand method executeCommand.

/**
 * Executes the command
 *
 * @throws CommandException
 */
@Override
protected int executeCommand() throws CommandException, CommandValidationException {
    try {
        prepareProcessExecutor();
        CLIProcessExecutor cpe = new CLIProcessExecutor();
        cpe.execute("pingDatabaseCmd", pingDatabaseCmd(false), true);
        if (cpe.exitValue() > 0) {
            // if ping is unsuccesfull then database is not up and running
            throw new CommandException(strings.get("StopDatabaseStatus", dbHost, dbPort));
        } else if (cpe.exitValue() < 0) {
            // Something terribly wrong!
            throw new CommandException(strings.get("UnableToStopDatabase", dbManager.getLogFileName()));
        } else {
            // Database is running so go ahead and stop the database
            cpe.execute("stopDatabaseCmd", stopDatabaseCmd(), true);
            if (cpe.exitValue() > 0) {
                throw new CommandException(strings.get("UnableToStopDatabase", dbManager.getLogFileName()));
            }
        }
    } catch (Exception e) {
        throw new CommandException(strings.get("UnableToStopDatabase", dbManager.getLogFileName()), e);
    }
    return 0;
}
Also used : CLIProcessExecutor(com.sun.enterprise.admin.cli.CLIProcessExecutor) CommandException(org.glassfish.api.admin.CommandException) CommandValidationException(org.glassfish.api.admin.CommandValidationException) CommandException(org.glassfish.api.admin.CommandException)

Example 10 with CommandValidationException

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

the class LocalOSGiShellCommand method executeCommands.

/**
 * Read commands from the specified BufferedReader
 * and execute them.  If printPrompt is set, prompt first.
 *
 * @return the exit code of the last command executed
 */
private int executeCommands(ConsoleReader reader) throws CommandException, CommandValidationException, IOException {
    String line = null;
    int rc = 0;
    /*
         * Any program options we start with are copied to the environment
         * to serve as defaults for commands we run, and then we give each
         * command an empty program options.
         */
    programOpts.toEnvironment(env);
    String sessionId = startSession();
    try {
        for (; ; ) {
            if (printPrompt) {
                line = reader.readLine(shellType + "$ ");
            } else {
                line = reader.readLine();
            }
            if (line == null) {
                if (printPrompt) {
                    System.out.println();
                }
                break;
            }
            if (// ignore comment lines
            line.trim().startsWith("#")) {
                continue;
            }
            String[] args = null;
            try {
                args = getArgs(line);
            } catch (ArgumentTokenizer.ArgumentException ex) {
                logger.info(ex.getMessage());
                continue;
            }
            if (args.length == 0) {
                continue;
            }
            String command = args[0];
            if (command.trim().length() == 0) {
                continue;
            }
            // XXX - care about their arguments?
            if (command.equals("exit") || command.equals("quit")) {
                break;
            }
            ProgramOptions po = null;
            try {
                /*
                     * Every command gets its own copy of program options
                     * so that any program options specified in its
                     * command line options don't effect other commands.
                     * But all commands share the same environment.
                     */
                po = new ProgramOptions(env);
                // copy over AsadminMain info
                po.setClassPath(programOpts.getClassPath());
                po.setClassName(programOpts.getClassName());
                // remove the old one and replace it
                atomicReplace(locator, po);
                args = prepareArguments(sessionId, args);
                args = enhanceForTarget(args);
                String output = cmd.executeAndReturnOutput(args).trim();
                if (output != null && output.length() > 0) {
                    logger.info(output);
                }
            } catch (CommandValidationException cve) {
                logger.severe(cve.getMessage());
                logger.severe(cmd.getUsage());
                rc = ERROR;
            } catch (InvalidCommandException ice) {
                // find closest match with local or remote commands
                logger.severe(ice.getMessage());
            } catch (CommandException ce) {
                logger.severe(ce.getMessage());
                rc = ERROR;
            } finally {
                // restore the original program options
                // XXX - is this necessary?
                atomicReplace(locator, programOpts);
            }
            CLIUtil.writeCommandToDebugLog(name, env, args, rc);
        }
    } finally {
        // what if something breaks on the wire?
        rc = stopSession(sessionId);
    }
    return rc;
}
Also used : InvalidCommandException(org.glassfish.api.admin.InvalidCommandException) CommandValidationException(org.glassfish.api.admin.CommandValidationException) ArgumentTokenizer(com.sun.enterprise.admin.cli.ArgumentTokenizer) InvalidCommandException(org.glassfish.api.admin.InvalidCommandException) CommandException(org.glassfish.api.admin.CommandException) ProgramOptions(com.sun.enterprise.admin.cli.ProgramOptions)

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