Search in sources :

Example 1 with CommandException

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

the class DBControl method createTempLogFile.

/**
 * creates a temporary log file.
 *
 * @return
 * @throws org.glassfish.api.admin.CommandException
 */
private String createTempLogFile() throws CommandException {
    String tempFileName = "";
    try {
        final File fTemp = File.createTempFile("foo", null);
        fTemp.deleteOnExit();
        tempFileName = fTemp.toString();
    } catch (IOException ioe) {
        final StringManager localManager = StringManager.getManager(this.getClass());
        throw new CommandException(localManager.getString("UnableToAccessDatabaseLog", tempFileName));
    }
    return tempFileName;
}
Also used : IOException(java.io.IOException) CommandException(org.glassfish.api.admin.CommandException) File(java.io.File) StringManager(com.sun.enterprise.util.i18n.StringManager)

Example 2 with CommandException

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

the class BackupDomainCommand method executeCommand.

/**
 */
@Override
protected int executeCommand() throws CommandException {
    try {
        BackupManager mgr = new BackupManager(request);
        logger.info(mgr.backup());
    } 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) CommandException(org.glassfish.api.admin.CommandException) BackupManager(com.sun.enterprise.backup.BackupManager)

Example 3 with CommandException

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

the class ListBackupsCommand method executeCommand.

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

Example 4 with CommandException

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

the class StartDatabaseCommand method executeCommand.

/**
 * Execute the command
 *
 * @throws CommandException
 */
@Override
protected int executeCommand() throws CommandException, CommandValidationException {
    final CLIProcessExecutor cpe = new CLIProcessExecutor();
    String dbLog = "";
    int exitCode = 0;
    try {
        prepareProcessExecutor();
        dbHome = getDatabaseHomeDir();
        if (dbHome != null) {
            dbLog = dbHome + File.separator + dbManager.getLogFileName();
        }
        logger.finer("Ping Database");
        cpe.execute("pingDatabaseCmd", pingDatabaseCmd(true), true);
        // if ping is unsuccesfull then database is not up and running
        if (cpe.exitValue() > 0) {
            logger.finer("Start Database");
            cpe.execute("startDatabaseCmd", startDatabaseCmd(), false);
            if (cpe.exitValue() != 0) {
                throw new CommandException(strings.get("UnableToStartDatabase", dbLog));
            }
        } else if (cpe.exitValue() < 0) {
            // Something terribly wrong!
            throw new CommandException(strings.get("CommandUnSuccessful", name));
        } else {
            // Database already started
            logger.info(strings.get("StartDatabaseStatus", dbHost, dbPort));
        }
    } catch (IllegalThreadStateException ite) {
        // IllegalThreadStateException is thrown if the
        // process has not yet teminated and is still running.
        // see http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Process.html#exitValue()
        // This is good since that means the database is up and running.
        CLIProcessExecutor cpePing = new CLIProcessExecutor();
        CLIProcessExecutor cpeSysInfo = new CLIProcessExecutor();
        try {
            if (!programOpts.isTerse()) {
                // try getting sysinfo
                logger.fine(strings.get("database.info.msg", dbHost, dbPort));
            }
            cpePing.execute("pingDatabaseCmd", pingDatabaseCmd(true), true);
            int counter = 0;
            // Give time for the database to be started
            while (cpePing.exitValue() != 0 && counter < 10) {
                cpePing.execute("pingDatabaseCmd", pingDatabaseCmd(true), true);
                Thread.sleep(500);
                counter++;
                // break out if start-database failed
                try {
                    cpe.exitValue();
                    break;
                } catch (IllegalThreadStateException itse) {
                    continue;
                }
            }
            if (!programOpts.isTerse()) {
                logger.finer("Database SysInfo");
                if (cpePing.exitValue() == 0) {
                    cpeSysInfo.execute("sysinfoCmd", sysinfoCmd(), true);
                    if (cpeSysInfo.exitValue() != 0) {
                        logger.info(strings.get("CouldNotGetSysInfo"));
                    }
                }
            }
        } catch (Exception e) {
            throw new CommandException(strings.get("CommandUnSuccessful", name), e);
        }
        if (cpePing.exitValue() == 0) {
            logger.info(strings.get("DatabaseStartMsg"));
            if ((new File(dbLog)).canWrite()) {
                logger.info(strings.get("LogRedirectedTo", dbLog));
            }
        } else {
            throw new CommandException(strings.get("UnableToStartDatabase", dbLog));
        }
    } catch (CommandException ce) {
        throw ce;
    } catch (Exception e) {
        throw new CommandException(strings.get("CommandUnSuccessful", name), e);
    }
    return exitCode;
}
Also used : CLIProcessExecutor(com.sun.enterprise.admin.cli.CLIProcessExecutor) CommandException(org.glassfish.api.admin.CommandException) File(java.io.File) IOException(java.io.IOException) CommandValidationException(org.glassfish.api.admin.CommandValidationException) CommandException(org.glassfish.api.admin.CommandException)

Example 5 with CommandException

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

the class StopDeploymentGroupCommand method execute.

@Override
public void execute(AdminCommandContext context) {
    ActionReport report = context.getActionReport();
    Logger logger = context.getLogger();
    logger.info(Strings.get("stop.dg", deploymentGroup));
    // Require that we be a DAS
    if (!env.isDas()) {
        String msg = Strings.get("cluster.command.notDas");
        logger.warning(msg);
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setMessage(msg);
        return;
    }
    ClusterCommandHelper clusterHelper = new ClusterCommandHelper(domain, runner);
    ParameterMap map = null;
    if (kill) {
        map = new ParameterMap();
        map.add("kill", "true");
    }
    try {
        // Run start-instance against each instance in the cluster
        String commandName = "stop-instance";
        clusterHelper.runCommand(commandName, map, deploymentGroup, context, verbose);
    } catch (CommandException e) {
        String msg = e.getLocalizedMessage();
        logger.warning(msg);
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setMessage(msg);
    }
}
Also used : ClusterCommandHelper(com.sun.enterprise.v3.admin.cluster.ClusterCommandHelper) ParameterMap(org.glassfish.api.admin.ParameterMap) CommandException(org.glassfish.api.admin.CommandException) ActionReport(org.glassfish.api.ActionReport) Logger(java.util.logging.Logger)

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