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;
}
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;
}
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;
}
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;
}
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);
}
}
Aggregations