From 1af5c38dc2016079f52df3b0159698c1619824a3 Mon Sep 17 00:00:00 2001
From: jvergara <jvergara@localhost>
Date: Tue, 09 Oct 2007 16:50:31 +0000
Subject: [PATCH] Use the actual host name of the server as the default we propose in dsreplication instead of the static "localhost". The rational behind this is that the host name must be stored in the ADS (this is updated for the "enable" subcommand) and storing "localhost" in the ADS only works in a testing environment where replication is done on several instances running on the same machine.
---
opendj-sdk/opends/src/guitools/org/opends/guitools/replicationcli/ReplicationCliArgumentParser.java | 44 ++++++++++++++++++++++++++++++++++++++------
1 files changed, 38 insertions(+), 6 deletions(-)
diff --git a/opendj-sdk/opends/src/guitools/org/opends/guitools/replicationcli/ReplicationCliArgumentParser.java b/opendj-sdk/opends/src/guitools/org/opends/guitools/replicationcli/ReplicationCliArgumentParser.java
index ee27939..8842bb9 100644
--- a/opendj-sdk/opends/src/guitools/org/opends/guitools/replicationcli/ReplicationCliArgumentParser.java
+++ b/opendj-sdk/opends/src/guitools/org/opends/guitools/replicationcli/ReplicationCliArgumentParser.java
@@ -32,6 +32,7 @@
import static org.opends.server.tools.ToolConstants.*;
import java.io.OutputStream;
+import java.net.InetAddress;
import java.util.ArrayList;
import java.util.LinkedList;
@@ -64,6 +65,8 @@
private BooleanArgument noPromptArg;
+ private String defaultLocalHostValue;
+
/**
* The 'hostName' argument for the first server.
*/
@@ -456,7 +459,7 @@
{
hostName1Arg = new StringArgument("host1", OPTION_SHORT_HOST,
- "host1", false, false, true, OPTION_VALUE_HOST, "localhost",
+ "host1", false, false, true, OPTION_VALUE_HOST, getDefaultHostValue(),
null, INFO_DESCRIPTION_ENABLE_REPLICATION_HOST1.get());
port1Arg = new IntegerArgument("port1", OPTION_SHORT_PORT, "port1",
@@ -494,7 +497,7 @@
INFO_DESCRIPTION_ENABLE_SECURE_REPLICATION1.get());
hostName2Arg = new StringArgument("host2", 'O',
- "host2", false, false, true, OPTION_VALUE_HOST, "localhost",
+ "host2", false, false, true, OPTION_VALUE_HOST, getDefaultHostValue(),
null, INFO_DESCRIPTION_ENABLE_REPLICATION_HOST2.get());
port2Arg = new IntegerArgument("port2", null, "port2",
@@ -570,6 +573,7 @@
disableReplicationSubCmd = new SubCommand(this,
DISABLE_REPLICATION_SUBCMD_NAME,
INFO_DESCRIPTION_SUBCMD_DISABLE_REPLICATION.get());
+ secureArgsList.hostNameArg.setDefaultValue(getDefaultHostValue());
secureArgsList.bindDnArg = new StringArgument("bindDN", OPTION_SHORT_BINDDN,
OPTION_LONG_BINDDN, false, false, true, OPTION_VALUE_BINDDN,
"cn=Directory Manager", null,
@@ -591,8 +595,9 @@
throws ArgumentException
{
hostNameSourceArg = new StringArgument("hostSource", OPTION_SHORT_HOST,
- "hostSource", false, false, true, OPTION_VALUE_HOST, "localhost",
- null, INFO_DESCRIPTION_INITIALIZE_REPLICATION_HOST_SOURCE.get());
+ "hostSource", false, false, true, OPTION_VALUE_HOST,
+ getDefaultHostValue(), null,
+ INFO_DESCRIPTION_INITIALIZE_REPLICATION_HOST_SOURCE.get());
portSourceArg = new IntegerArgument("portSource", OPTION_SHORT_PORT,
"portSource", false, false, true, OPTION_VALUE_PORT, 389, null,
@@ -607,8 +612,9 @@
INFO_DESCRIPTION_INITIALIZE_REPLICATION_STARTTLS_SOURCE.get());
hostNameDestinationArg = new StringArgument("hostDestination", 'O',
- "hostDestination", false, false, true, OPTION_VALUE_HOST, "localhost",
- null, INFO_DESCRIPTION_INITIALIZE_REPLICATION_HOST_DESTINATION.get());
+ "hostDestination", false, false, true, OPTION_VALUE_HOST,
+ getDefaultHostValue(), null,
+ INFO_DESCRIPTION_INITIALIZE_REPLICATION_HOST_DESTINATION.get());
portDestinationArg = new IntegerArgument("portDestination", null,
"portDestination", false, false, true, OPTION_VALUE_PORT, 389, null,
@@ -651,6 +657,7 @@
INITIALIZE_ALL_REPLICATION_SUBCMD_NAME,
INFO_DESCRIPTION_SUBCMD_INITIALIZE_ALL_REPLICATION.get(
INITIALIZE_REPLICATION_SUBCMD_NAME));
+ secureArgsList.hostNameArg.setDefaultValue(getDefaultHostValue());
Argument[] argsToAdd = { secureArgsList.hostNameArg,
secureArgsList.portArg, secureArgsList.useSSLArg,
secureArgsList.useStartTLSArg };
@@ -676,6 +683,7 @@
's',
"script-friendly",
INFO_DESCRIPTION_SCRIPT_FRIENDLY.get());
+ secureArgsList.hostNameArg.setDefaultValue(getDefaultHostValue());
Argument[] argsToAdd = { secureArgsList.hostNameArg,
secureArgsList.portArg, secureArgsList.useSSLArg,
secureArgsList.useStartTLSArg, scriptFriendlyArg };
@@ -1849,4 +1857,28 @@
}
buf.append(message);
}
+
+ /**
+ * Returns the default value to be used for the host.
+ * @return the default value to be used for the host.
+ */
+ private String getDefaultHostValue()
+ {
+ if (defaultLocalHostValue == null)
+ {
+ try
+ {
+ InetAddress localAddress = InetAddress.getLocalHost();
+ defaultLocalHostValue = localAddress.getHostName();
+ }
+ catch (Throwable t)
+ {
+ }
+ if (defaultLocalHostValue == null)
+ {
+ defaultLocalHostValue = "localhost";
+ }
+ }
+ return defaultLocalHostValue;
+ }
}
--
Gitblit v1.10.0