Search in sources :

Example 31 with CommandException

use of org.glassfish.api.admin.CommandException 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 32 with CommandException

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

the class RestoreDomainCommand method executeCommand.

/**
 */
@Override
protected int executeCommand() throws CommandException {
    try {
        RestoreManager mgr = new RestoreManager(request);
        logger.info(mgr.restore());
    } catch (BackupWarningException bwe) {
        logger.info(bwe.getMessage());
    } catch (BackupException be) {
        throw new CommandException(be);
    }
    return 0;
}
Also used : BackupException(com.sun.enterprise.backup.BackupException) BackupWarningException(com.sun.enterprise.backup.BackupWarningException) RestoreManager(com.sun.enterprise.backup.RestoreManager) CommandException(org.glassfish.api.admin.CommandException)

Example 33 with CommandException

use of org.glassfish.api.admin.CommandException 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 34 with CommandException

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

the class BackupDomainCommand method validate.

@Override
protected void validate() throws CommandException {
    // only if domain name is not specified, it should try to find one
    if (domainName == null)
        super.validate();
    checkOptions();
    setDomainName(domainName);
    initDomain();
    File domainFile = new File(new File(domainDirParam), domainName);
    if (!isWritableDirectory(domainFile)) {
        throw new CommandException(strings.get("InvalidDirectory", domainFile.getPath()));
    }
    if (force == null) {
        if (isRunning()) {
            boolean suspendAvailable = canSuspend();
            if (suspendAvailable && !isSuspended()) {
                throw new CommandException(strings.get("DomainIsNotSuspended", domainName));
            } else if (!suspendAvailable) {
                throw new CommandException(strings.get("DomainIsNotStopped", domainName));
            }
        }
    }
    int limit = 0;
    if (recycleLimit != null) {
        try {
            limit = Integer.parseInt(recycleLimit.trim());
        } catch (NumberFormatException ex) {
            limit = -1;
        }
        if (limit < 0) {
            throw new CommandException(strings.get("InvalidBackupRecycleLimit", recycleLimit));
        }
    }
    setDescription(description);
    setBackupDir(backupdir);
    setRecycleLimit(limit);
    prepareRequest();
    // in case program options changed
    initializeLogger();
}
Also used : CommandException(org.glassfish.api.admin.CommandException) File(java.io.File)

Example 35 with CommandException

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

the class ListBackupsCommand method validate.

@Override
protected void validate() throws CommandException {
    // only if domain name is not specified, it should try to find one
    if (domainName == null)
        super.validate();
    checkOptions();
    File domainFile = new File(new File(domainDirParam), domainName);
    if (!isWritableDirectory(domainFile)) {
        throw new CommandException(strings.get("InvalidDirectory", domainFile.getPath()));
    }
    setBackupDir(backupdir);
    prepareRequest();
    // in case program options changed
    initializeLogger();
}
Also used : CommandException(org.glassfish.api.admin.CommandException) File(java.io.File)

Aggregations

CommandException (org.glassfish.api.admin.CommandException)61 File (java.io.File)20 CommandValidationException (org.glassfish.api.admin.CommandValidationException)16 IOException (java.io.IOException)13 ParameterMap (org.glassfish.api.admin.ParameterMap)11 InvalidCommandException (org.glassfish.api.admin.InvalidCommandException)10 ActionReport (org.glassfish.api.ActionReport)9 ArrayList (java.util.ArrayList)6 RemoteCLICommand (com.sun.enterprise.admin.cli.remote.RemoteCLICommand)5 MiniXmlParserException (com.sun.enterprise.universal.xml.MiniXmlParserException)5 HostAndPort (com.sun.enterprise.util.HostAndPort)4 BackupException (com.sun.enterprise.backup.BackupException)3 BackupWarningException (com.sun.enterprise.backup.BackupWarningException)3 SmartFile (com.sun.enterprise.universal.io.SmartFile)3 FileNotFoundException (java.io.FileNotFoundException)3 UnknownHostException (java.net.UnknownHostException)3 Logger (java.util.logging.Logger)3 SFTPClient (org.glassfish.cluster.ssh.sftp.SFTPClient)3 CLIProcessExecutor (com.sun.enterprise.admin.cli.CLIProcessExecutor)2 PEDomainsManager (com.sun.enterprise.admin.servermgmt.pe.PEDomainsManager)2