Search in sources :

Example 16 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)

Example 17 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 18 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 19 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)

Aggregations

CommandValidationException (org.glassfish.api.admin.CommandValidationException)19 CommandException (org.glassfish.api.admin.CommandException)10 File (java.io.File)6 EndOfFileException (org.jline.reader.EndOfFileException)6 UserInterruptException (org.jline.reader.UserInterruptException)6 ParameterMap (org.glassfish.api.admin.ParameterMap)4 InvalidCommandException (org.glassfish.api.admin.InvalidCommandException)3 CLIProcessExecutor (com.sun.enterprise.admin.cli.CLIProcessExecutor)2 DomainConfig (com.sun.enterprise.admin.servermgmt.DomainConfig)2 DomainException (com.sun.enterprise.admin.servermgmt.DomainException)2 IOException (java.io.IOException)2 ActionReport (org.glassfish.api.ActionReport)2 ParamModel (org.glassfish.api.admin.CommandModel.ParamModel)2 CommandInvocation (org.glassfish.api.admin.CommandRunner.CommandInvocation)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 RemoteCLICommand (com.sun.enterprise.admin.cli.remote.RemoteCLICommand)1 RemoteCommand (com.sun.enterprise.admin.cli.remote.RemoteCommand)1 DomainsManager (com.sun.enterprise.admin.servermgmt.DomainsManager)1