Index: admin/config-api/src/main/java/com/sun/enterprise/config/serverbeans/CopyConfig.java =================================================================== --- admin/config-api/src/main/java/com/sun/enterprise/config/serverbeans/CopyConfig.java (revision 62681) +++ admin/config-api/src/main/java/com/sun/enterprise/config/serverbeans/CopyConfig.java (working copy) @@ -111,9 +111,18 @@ String srcConfig = ""; srcConfig = config.getName(); + File configConfigDir = new File(env.getConfigDirPath(), + configName); + for (Config c : configs.getConfig()) { + File existingConfigConfigDir = new File(env.getConfigDirPath(), c.getName()); + if (!c.getName().equals(configName) && configConfigDir.equals(existingConfigConfigDir)) { + throw new TransactionFailure(localStrings.getLocalString( + "config.duplicate.dir", + "Config {0} is trying to use the same directory as config {1}", + configName, c.getName())); + } + } try { - File configConfigDir = new File(env.getConfigDirPath(), - configName); if (!(new File(configConfigDir, "docroot").mkdirs() && new File(configConfigDir, "lib/ext").mkdirs())) { throw new IOException(localStrings.getLocalString("config.mkdirs", Index: admin/config-api/src/main/java/com/sun/enterprise/config/serverbeans/LocalStrings.properties =================================================================== --- admin/config-api/src/main/java/com/sun/enterprise/config/serverbeans/LocalStrings.properties (revision 62681) +++ admin/config-api/src/main/java/com/sun/enterprise/config/serverbeans/LocalStrings.properties (working copy) @@ -90,6 +90,7 @@ generic.config=The existing config name to be used by this cluster +config.duplicate.dir=Config {0} is trying to use the same directory as config {1} config.copyConfigError=Error copying the config caused by {0} config.mkdirs=error creating config specific directories 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 62681) +++ cluster/admin/src/main/java/com/sun/enterprise/v3/admin/cluster/CreateInstanceCommand.java (working copy) @@ -48,7 +48,9 @@ import com.sun.enterprise.util.io.InstanceDirs; import java.io.File; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Properties; import java.util.logging.Level; import org.glassfish.api.I18n; import org.glassfish.api.Param; @@ -161,6 +163,15 @@ nodeDir = theNode.getNodeDirAbsolute(); installDir = theNode.getInstallDir(); + if (theNode.isLocal()){ + validateInstanceDirUnique(report, context); + if (report.getActionExitCode() != ActionReport.ExitCode.SUCCESS + && report.getActionExitCode() != ActionReport.ExitCode.WARNING) { + // If we couldn't update domain.xml then stop! + return; + } + } + // First, update domain.xml by calling _register-instance CommandInvocation ci = cr.getCommandInvocation("_register-instance", report, context.getSubject()); ParameterMap map = new ParameterMap(); @@ -218,6 +229,35 @@ createInstanceFilesystem(context); } + private void validateInstanceDirUnique(ActionReport report, AdminCommandContext context) { + CommandInvocation listInstances = cr.getCommandInvocation("list-instances", report, context.getSubject()); + ParameterMap map = new ParameterMap(); + map.add("whichTarget", theNode.getName()); + listInstances.parameters(map); + listInstances.execute(); + Properties pro = listInstances.report().getExtraProperties(); + if (pro != null){ + List instanceList = (List) pro.get("instanceList"); + if (instanceList == null) + return; + for (HashMap instanceMap : instanceList) { + final File nodeDirFile = (nodeDir != null + ? new File(nodeDir) + : defaultLocalNodeDirFile()); + File instanceDir = new File(new File(nodeDirFile.toString(), theNode.getName()), instance); + String instanceName = (String)instanceMap.get("name"); + File instanceListDir = new File(new File(nodeDirFile.toString(), theNode.getName()), instance); + if (instance.equalsIgnoreCase(instanceName) && instanceDir.equals(instanceListDir)) { + String msg = Strings.get("Instance.duplicateInstanceDir", instance, instanceName); + logger.warning(msg); + report.setActionExitCode(ActionReport.ExitCode.FAILURE); + report.setMessage(msg); + return; + } + } + } + } + /** * Returns the directory for the selected instance that is on the local * system. Index: cluster/admin/src/main/java/com/sun/enterprise/v3/admin/cluster/LocalStrings.properties =================================================================== --- cluster/admin/src/main/java/com/sun/enterprise/v3/admin/cluster/LocalStrings.properties (revision 62681) +++ cluster/admin/src/main/java/com/sun/enterprise/v3/admin/cluster/LocalStrings.properties (working copy) @@ -140,6 +140,7 @@ notConfigNodeType=Node {0} is not type CONFIG notRemoteNodeType=Node {0} is not a remote type (SSH or DCOM). lbenabledNotForStandaloneInstance=The lbenabled option is not supported for standalone instances. +Instance.duplicateInstanceDir=Server instance {0} is trying to use the same directory as instance {1} notAllowed=This command can only be run on DAS. ## StartClusterCommand Index: cluster/cli/src/main/java/com/sun/enterprise/admin/cli/cluster/CreateLocalInstanceCommand.java =================================================================== --- cluster/cli/src/main/java/com/sun/enterprise/admin/cli/cluster/CreateLocalInstanceCommand.java (revision 62681) +++ cluster/cli/src/main/java/com/sun/enterprise/admin/cli/cluster/CreateLocalInstanceCommand.java (working copy) @@ -199,6 +199,7 @@ } } else { + validateInstanceDirUnique(); try { registerToDAS(); _rendezvousOccurred = true; @@ -227,6 +228,22 @@ return exitCode; } + private void validateInstanceDirUnique() throws CommandException { + RemoteCLICommand rc = new RemoteCLICommand("list-instances", this.programOpts, this.env); + String[] registeredInstanceNamesOnThisNode = + rc.executeAndReturnOutput("list-instances", "--nostatus", _node).split("\r?\n"); + if (registeredInstanceNamesOnThisNode == null) + return; + for (String registeredInstanceName : registeredInstanceNamesOnThisNode) { + File instanceListDir = new File(nodeDirChild, registeredInstanceName); + if (instanceName.equalsIgnoreCase(registeredInstanceName) && instanceDir.equals(instanceListDir)) { + throw new CommandException( + Strings.get("Instance.duplicateInstanceDir", + instanceName, registeredInstanceName)); + } + } + } + private int bootstrapSecureAdminFiles() throws CommandException { RemoteCLICommand rc = new RemoteCLICommand("_bootstrap-secure-admin", this.programOpts, this.env); rc.setFileOutputDirectory(instanceDir); 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 62681) +++ cluster/cli/src/main/java/com/sun/enterprise/admin/cli/cluster/LocalStrings.properties (working copy) @@ -108,6 +108,7 @@ Keystore.not.encrypted=Error in encrypting the keystore Instance.installdir.mismatch=Attribute mismatch for node {0}: the value for the installdir attribute from the command ({1}) does not match the value in the DAS configuration ({2}) Instance.installdir.null=Attribute null for installdir on node {0}: command value is: {1}, node value is: {2} +Instance.duplicateInstanceDir=Server instance {0} is trying to use the same directory as instance {1} ########### StopInstance.noInstanceNameAllowed=No instance name allowed with --host option. StopInstance.instanceNotRunning=CLI1306 Warning - server instance is not running.