validateOptions();
//verify for no-spaces in agentdir option on non-windows platform
String agentDirValue = getOption(AGENTDIR);
if ((agentDirValue != null) && !isWindows() && isSpaceInPath(agentDirValue))
throw new CommandException(getLocalizedString("SpaceNotAllowedInPath",
new Object[]{AGENTDIR}));
//domain validation upfront (i.e. before we prompt)
String agentName=null;
try {
// check to see in the nodeagent name was supplied
if (operands.isEmpty()) {
// no name, default to hostname
agentName=NetUtils.getHostName();
} else {
// name supplied, use it
agentName=(String)operands.firstElement();
}
// log agentname for debug
CLILogger.getInstance().printDebugMessage("agentName = " + agentName);
AgentConfig agentConfig = new AgentConfig(agentName,
getAgentPath());
AgentManager manager = getAgentManager(agentConfig);
manager.validateNodeAgent(agentConfig, false);
} catch (Exception e) {
if (e.getLocalizedMessage() != null)
CLILogger.getInstance().printDetailMessage(e.getLocalizedMessage());
throw new CommandException(getLocalizedString(
"CommandUnSuccessful", new Object[] {name} ), e);
}
try {
Properties agentProperties = getAgentProperties(getOption(AGENT_PROPERTIES));
final String adminUser = getUser();
final String adminPassword = getPassword();
//need to call setOption before calling getMasterPassword() since
//getMasterPassword() needs to get ADMIN_PASSWORD first.
setOption(ADMIN_PASSWORD, adminPassword);
boolean saveMasterPasswordSpecified = getBooleanOption(SAVE_MASTER_PASSWORD);
String masterPassword = null;
if (saveMasterPasswordSpecified)
{
masterPassword = getMasterPasswordWithDefaultPrompt(null, null);
}
final String adminPort = String.valueOf(getPort());
final String adminHost = getHost();
Boolean saveMasterPassword = getSaveMasterPassword(masterPassword);
//The --secure option is a synonymn for --agentproperties agent.das.isSecure=false
if (!getBooleanOption(SECURE)) {
agentProperties.setProperty(AgentConfig.AGENT_DAS_IS_SECURE, "false");
}
//System.out.println("adminPassword=" + adminPassword + " masterPassword=" + masterPassword +
// " saveMasterPassword=" + saveMasterPassword);
if (adminHost == null || adminPort == null || adminUser == null || adminPassword == null) {
throw new CommandValidationException(_strMgr.getString("InvalidDASConfiguration"));
}
// defaulted protocol and clientHostName until moved to cli if deemed appropriate ???
// temporary fix to remove agent user & password, for now map them to das user & password???
AgentConfig agentConfig = new AgentConfig(agentName, getAgentPath(), adminUser,
adminPassword, new Integer(getAdminPort()),
adminHost, adminPort, adminUser, adminPassword,
masterPassword,
saveMasterPassword, agentProperties);
AgentManager manager = getAgentManager(agentConfig);
//Create the node agent
manager.createNodeAgent();
try {
//If the DAS and Node Agent were created together on the same machine (i.e. by the
//installer), the we attempt to pre-register the new node agent's config directly
//in the domain.xml of the domain.
rendezvousWithDAS(agentConfig, agentProperties);
} catch (Exception ex) {
try {
//if we could not register, then cleanup
manager.deleteNodeAgent();
} catch (Exception ex2) {
//eat any exceptions occuring during cleanup time.
}
throw ex;
}
CLILogger.getInstance().printDetailMessage(getLocalizedString(
"CommandSuccessful",
new Object[] {name}));
} catch (Exception e) {
if (e.getLocalizedMessage() != null)
CLILogger.getInstance().printDetailMessage(e.getLocalizedMessage());
throw new CommandException(getLocalizedString(
"CommandUnSuccessful", new Object[] {name} ), e);
}
}