Index: cluster/cli/src/main/java/com/sun/enterprise/admin/cli/cluster/SynchronizeInstanceCommand.java =================================================================== --- cluster/cli/src/main/java/com/sun/enterprise/admin/cli/cluster/SynchronizeInstanceCommand.java (revision 43731) +++ cluster/cli/src/main/java/com/sun/enterprise/admin/cli/cluster/SynchronizeInstanceCommand.java (working copy) @@ -116,7 +116,8 @@ Strings.get("Sync.noDASConfigured", dasProperties.toString())); return false; } - + validateDasOptions(programOpts.getHost(), String.valueOf(programOpts.getPort()), + String.valueOf(programOpts.isSecure()), dasProperties); setDasDefaults(dasProperties); /* Index: cluster/cli/src/main/java/com/sun/enterprise/admin/cli/cluster/DeleteLocalInstanceCommand.java =================================================================== --- cluster/cli/src/main/java/com/sun/enterprise/admin/cli/cluster/DeleteLocalInstanceCommand.java (revision 43731) +++ cluster/cli/src/main/java/com/sun/enterprise/admin/cli/cluster/DeleteLocalInstanceCommand.java (working copy) @@ -111,6 +111,8 @@ File dasProperties = getServerDirs().getDasPropertiesFile(); if (dasProperties.isFile()) { + validateDasOptions(programOpts.getHost(), String.valueOf(programOpts.getPort()), + String.valueOf(programOpts.isSecure()), dasProperties); setDasDefaults(dasProperties); } Index: cluster/cli/src/main/java/com/sun/enterprise/admin/cli/cluster/CreateLocalInstanceFilesystemCommand.java =================================================================== --- cluster/cli/src/main/java/com/sun/enterprise/admin/cli/cluster/CreateLocalInstanceFilesystemCommand.java (revision 43731) +++ cluster/cli/src/main/java/com/sun/enterprise/admin/cli/cluster/CreateLocalInstanceFilesystemCommand.java (working copy) @@ -99,6 +99,8 @@ dasPropsFile = new File(agentConfigDir, "das.properties"); if (dasPropsFile.isFile()) { + validateDasOptions(programOpts.getHost(), String.valueOf(programOpts.getPort()), + String.valueOf(programOpts.isSecure()), dasPropsFile); setDasDefaults(dasPropsFile); if (!setDasDefaultsOnly) { String nodeDirChildName = nodeDirChild != null ? nodeDirChild.getName() : ""; Index: cluster/cli/src/main/java/com/sun/enterprise/admin/cli/cluster/LocalInstanceCommand.java =================================================================== --- cluster/cli/src/main/java/com/sun/enterprise/admin/cli/cluster/LocalInstanceCommand.java (revision 43731) +++ cluster/cli/src/main/java/com/sun/enterprise/admin/cli/cluster/LocalInstanceCommand.java (working copy) @@ -209,59 +209,96 @@ * Set the programOpts based on the das.properties file. */ protected final void setDasDefaults(File propfile) throws CommandException { + Properties dasprops = getDasProperties(propfile); + + // read properties and set them in programOpts + // properties are: + // agent.das.port + // agent.das.host + // agent.das.isSecure + // agent.das.user XXX - not in v2? + String p; + p = dasprops.getProperty("agent.das.host"); + if (p != null) { + programOpts.setHost(p); + } + p = dasprops.getProperty("agent.das.port"); + int port = -1; + if (p != null) { + port = Integer.parseInt(p); + } + p = dasprops.getProperty("agent.das.protocol"); + if (p != null && p.equals("rmi_jrmp")) { + programOpts.setPort(updateDasPort(dasprops, port, propfile)); + } else if (p == null || p.equals("http")) { + programOpts.setPort(port); + } else { + throw new CommandException(Strings.get("Instance.badProtocol", + propfile.toString(), p)); + } + p = dasprops.getProperty("agent.das.isSecure"); + if (p != null) { + programOpts.setSecure(Boolean.parseBoolean(p)); + } + p = dasprops.getProperty("agent.das.user"); + if (p != null) { + programOpts.setUser(p); + } + // XXX - what about the DAS admin password? + } + + /** + * Checks if programOpts values match das.properties file. + */ + protected final void validateDasOptions(String hostOption, String portOption, + String isSecureOption, File propfile) throws CommandException { + if (propfile != null) { + Properties dasprops = getDasProperties(propfile); + if (!dasprops.isEmpty()) { + String errorMsg = ""; + String nodeName = nodeDirChild != null ? nodeDirChild.getName() : ""; + String hostProp = dasprops.getProperty("agent.das.host"); + String portProp = dasprops.getProperty("agent.das.port"); + String secureProp = dasprops.getProperty("agent.das.isSecure"); + if (hostProp != null && !hostProp.equals(hostOption)) { + errorMsg = errorMsg + Strings.get("Instance.DasHostInvalid", hostOption, nodeName) + "\n"; + } + if (portProp != null && !portProp.equals(portOption)) { + errorMsg = errorMsg + Strings.get("Instance.DasPortInvalid", portOption, nodeName) + "\n"; + } + if (secureProp != null && !secureProp.equals(isSecureOption)) { + errorMsg = errorMsg + Strings.get("Instance.DasIsSecureInvalid", isSecureOption, nodeName) + "\n"; + } + if (!errorMsg.isEmpty()) { + errorMsg = errorMsg + Strings.get("Instance.DasConfig", nodeName, hostProp, portProp, secureProp); + throw new CommandException(errorMsg); + } + } + } + } + + final protected Properties getDasProperties(File propfile) throws CommandException { Properties dasprops = new Properties(); FileInputStream fis = null; try { - // read properties and set them in programOpts - // properties are: - // agent.das.port - // agent.das.host - // agent.das.isSecure - // agent.das.user XXX - not in v2? fis = new FileInputStream(propfile); dasprops.load(fis); fis.close(); fis = null; - String p; - p = dasprops.getProperty("agent.das.host"); - if (p != null) - programOpts.setHost(p); - p = dasprops.getProperty("agent.das.port"); - int port = -1; - if (p != null) - port = Integer.parseInt(p); - p = dasprops.getProperty("agent.das.protocol"); - if (p != null && p.equals("rmi_jrmp")) { - programOpts.setPort(updateDasPort(dasprops, port, propfile)); - } - else if (p == null || p.equals("http")) - programOpts.setPort(port); - else - throw new CommandException(Strings.get("Instance.badProtocol", - propfile.toString(), p)); - p = dasprops.getProperty("agent.das.isSecure"); - if (p != null) - programOpts.setSecure(Boolean.parseBoolean(p)); - p = dasprops.getProperty("agent.das.user"); - if (p != null) - programOpts.setUser(p); - // XXX - what about the DAS admin password? - } - catch (IOException ioex) { + } catch (IOException ioex) { throw new CommandException( Strings.get("Instance.cantReadDasProperties", propfile.getPath())); - } - finally { + } finally { if (fis != null) { try { fis.close(); - } - catch (IOException cex) { + } catch (IOException cex) { // ignore it } } } + return dasprops; } final protected void whackFilesystem() throws CommandException { Index: cluster/cli/src/main/java/com/sun/enterprise/admin/cli/cluster/LocalStrings.properties =================================================================== --- cluster/cli/src/main/java/com/sun/enterprise/admin/cli/cluster/LocalStrings.properties (revision 43731) +++ cluster/cli/src/main/java/com/sun/enterprise/admin/cli/cluster/LocalStrings.properties (working copy) @@ -91,6 +91,10 @@ to the DAS or because the DAS host is known by a different name on \ the instance host {2}. To change the hostname that the DAS uses to identify \ itself please update the DAS admin HTTP listener address. +Instance.DasHostInvalid=DAS host {0} does not match DAS host used by node {1}. +Instance.DasPortInvalid=DAS port {0} does not match DAS port used by node {1}. +Instance.DasIsSecureInvalid=DAS secure flag of {0} does not match DAS secure flag used by node {1}. +Instance.DasConfig=Node {0} is configured to connect to DAS on {1}:{2} with secure = {3}. create.local.instance.usagetext=create-local-instance\n\t[--config | --cluster ]\n\t[--lbenabled[=]]\n\t[--systemproperties ] [--portbase ]\n\t[--checkports[=]]\n\t[--bootstrap[=]]\n\t[--savemasterpassword[=]]\n\t[--nodedir ] [--node ]\n\t[-?|--help[=]] instance_name masterPasswordFileNotCreated=Error creating master password file {0} fileNotFound=File {0} not found. syncBundleExport = null; Index: cluster/admin/src/main/java/com/sun/enterprise/v3/admin/cluster/CreateInstanceCommand.java =================================================================== --- cluster/admin/src/main/java/com/sun/enterprise/v3/admin/cluster/CreateInstanceCommand.java (revision 43731) +++ cluster/admin/src/main/java/com/sun/enterprise/v3/admin/cluster/CreateInstanceCommand.java (working copy) @@ -193,6 +193,11 @@ return; } + if (!validateDasOptions(context)) { + report.setActionExitCode(ActionReport.ExitCode.FAILURE); + return; + } + // First, update domain.xml by calling _register-instance CommandInvocation ci = cr.getCommandInvocation("_register-instance", report); ParameterMap map = new ParameterMap(); @@ -423,6 +428,53 @@ report.setActionExitCode(ActionReport.ExitCode.SUCCESS); } + public boolean validateDasOptions(AdminCommandContext context) { + boolean isDasOptionsValid = true; + if (theNode.isLocal() || (!theNode.isLocal() && !theNode.getType().equals("SSH"))) { + ActionReport report = ctx.getActionReport(); + report.setActionExitCode(ActionReport.ExitCode.SUCCESS); + + NodeUtils nodeUtils = new NodeUtils(habitat, logger); + Server dasServer = + servers.getServer(SystemPropertyConstants.DAS_SERVER_NAME); + String dasHost = dasServer.getAdminHost(); + String dasPort = Integer.toString(dasServer.getAdminPort()); + + ArrayList command = new ArrayList(); + String humanCommand = null; + + if (!theNode.isLocal()) { + // Only specify the DAS host if the node is remote. See issue 13993 + command.add("--host"); + command.add(dasHost); + } + + command.add("--port"); + command.add(dasPort); + + command.add("_validate-das-options"); + + if (nodeDir != null) { + command.add("--nodedir"); + command.add(nodeDir); //XXX escape spaces? + } + + command.add("--node"); + command.add(node); + + command.add(instance); + + // Run the command on the node + nodeUtils.runAdminCommandOnNode(theNode, command, ctx, "", null, null); + + if (report.getActionExitCode() != ActionReport.ExitCode.SUCCESS) { + report.setActionExitCode(ActionReport.ExitCode.FAILURE); + isDasOptionsValid = false; + } + } + return isDasOptionsValid; + } + private String makeCommandHuman(List command) { StringBuilder fullCommand = new StringBuilder();