Methods Summary |
---|
private void | checkOptions()A method that checks the options and operand that the user supplied.
These tests are slightly different for different CLI commands
// disallow backup & restore if server is running. list-backups is OK anytime...
if(command == CmdType.BACKUP || command == CmdType.RESTORE)
{
if(!isNotRunning())
{
throw new CommandValidationException(getLocalizedString("DomainIsNotStopped",
new String[] {command.name} ));
}
}
// make sure we have a domainsDir
if(domainsDir == null || domainsDir.length() <= 0)
{
throw new CommandValidationException(getLocalizedString("InvalidDomainPath",
new String[] {domainsDir}) );
}
File domainsDirFile = new File(domainsDir);
// make sure domainsDir exists and is a directory
if(!domainsDirFile.isDirectory())
{
throw new CommandValidationException(getLocalizedString("InvalidDomainPath",
new String[] {domainsDir}) );
}
File domainFile = new File(domainsDirFile, domainName);
// BACKUP, LIST: make sure the domain dir exists and is
// a directory and is writable
// RESTORE: It must exist if backupFilename isn't set.
boolean domainDirDoesNotHaveToExist =
(command == CmdType.RESTORE) && backupFilename != null;
if(!domainDirDoesNotHaveToExist)
{
if(!domainFile.isDirectory() || !domainFile.canWrite())
{
throw new CommandValidationException(getLocalizedString("InvalidDirectory",
new String[] {domainFile.getPath()}) );
}
}
if(backupFilename != null)
{
File f = new File(backupFilename);
if(!f.exists() || !f.canRead())
{
throw new CommandValidationException(getLocalizedString("FileDoesNotExist",
new String[] { backupFilename } ));
}
}
|
private boolean | isNotRunning()
try
{
ClientPluggableFeatureFactory cpff = getFeatureFactory();
DomainsManager dm = cpff.getDomainsManager();
DomainConfig dc = getDomainConfig(domainName);
InstancesManager im = dm.getInstancesManager(dc);
final int state = im.getInstanceStatus();
return state == Status.kInstanceNotRunningCode;
}
catch(Exception e)
{
throw new CommandValidationException(e);
}
|
private void | prepareRequest()
if(backupFilename == null)
request = new BackupRequest(domainsDir, domainName, description);
else
request = new BackupRequest(domainsDir, domainName, description, backupFilename);
request.setTerse(terse);
request.setVerbose(verbose);
|
public void | runCommand()An abstract method that executes the command
validateOptions();
try
{
if(command == CmdType.BACKUP)
{
BackupManager mgr = new BackupManager(request);
CLILogger.getInstance().printMessage(mgr.backup());
}
else if(command == CmdType.RESTORE)
{
RestoreManager mgr = new RestoreManager(request);
CLILogger.getInstance().printMessage(mgr.restore());
}
else if(command == CmdType.LIST)
{
ListManager mgr = new ListManager(request);
CLILogger.getInstance().printMessage(mgr.list());
}
else
{
// IMPOSSIBLE!!!
throw new CommandException("Internal Error");
}
}
catch(BackupWarningException bwe)
{
CLILogger.getInstance().printMessage(bwe.getMessage());
}
catch(BackupException be)
{
throw new CommandException(be);
}
|
private void | setBackupFilename()
// this option is only used for restore operations
backupFilename = getOption(FILENAME);
|
private void | setCommand()
String cmd = getName();
command = CmdType.valueOf(cmd);
if(command == null)
{
// This shouldn't happen unless somebody erred editing CLIDescriptor.xml
throw new CommandValidationException(
getLocalizedString("NoUsageText", new String[] {cmd}) );
}
|
private void | setDescription()
description = getOption(DESCRIPTION);
|
private void | setDomainName()
try
{
domainName = getDomainName();
}
catch(CommandException ce)
{
throw new CommandValidationException(ce);
}
//domainName = (String)operands.firstElement();
|
private void | setDomainsDir()
domainsDir = getOption(DOMAINSDIR);
if(domainsDir == null || domainsDir.length() <= 0)
domainsDir = System.getProperty(SystemPropertyConstants.DOMAINS_ROOT_PROPERTY);
|
private void | setOptions()A method that sets the options and operand that the user supplied.
setCommand();
setDomainsDir();
setDomainName();
setBackupFilename();
setDescription();
setVerbosity();
|
private void | setVerbosity()
if(getBooleanOption("terse"))
terse = true;
if(getBooleanOption("verbose"))
verbose = true;
// it is an error for both to be true (duh!)
if(verbose && terse)
throw new CommandValidationException(getLocalizedString("NoVerboseAndTerseAtTheSameTime"));
|
public java.lang.String | toString()
return super.toString() + "\n" + ObjectAnalyzer.toString(this);
|
public boolean | validateOptions()An abstract method that validates the options
on the specification in the xml properties file
super.validateOptions();
setOptions();
checkOptions();
prepareRequest();
// if anything went wrong, an Exception would have been thrown
// and we'd never get to this return statement...
return true;
|