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