|
From: <btm...@us...> - 2010-07-28 21:14:34
|
Revision: 3338
http://bigdata.svn.sourceforge.net/bigdata/?rev=3338&view=rev
Author: btmurphy
Date: 2010-07-28 21:14:27 +0000 (Wed, 28 Jul 2010)
Log Message:
-----------
[trunk]: trac #126 - Uses of InetAddress.getLocalAddress should be changed to a mechanism that returns a non-loopback address
Modified Paths:
--------------
trunk/bigdata/src/java/com/bigdata/counters/AbstractStatisticsCollector.java
trunk/bigdata/src/java/com/bigdata/resources/MoveTask.java
trunk/bigdata/src/java/com/bigdata/service/AbstractEmbeddedLoadBalancerService.java
trunk/bigdata/src/test/com/bigdata/counters/httpd/TestCounterSetHTTPDServer.java
trunk/bigdata/src/test/com/bigdata/service/TestResourceService.java
trunk/bigdata/src/test/com/bigdata/test/ExperimentDriver.java
trunk/bigdata-jini/src/java/com/bigdata/jini/start/config/JiniServiceConfiguration.java
trunk/bigdata-jini/src/java/com/bigdata/jini/start/config/MaxClientServicesPerHostConstraint.java
trunk/bigdata-jini/src/java/com/bigdata/jini/start/config/MaxDataServicesPerHostConstraint.java
trunk/bigdata-jini/src/java/com/bigdata/jini/start/config/ZookeeperServerConfiguration.java
trunk/bigdata-jini/src/java/com/bigdata/jini/start/process/JiniCoreServicesProcessHelper.java
trunk/bigdata-jini/src/java/com/bigdata/jini/start/process/ZookeeperProcessHelper.java
trunk/bigdata-jini/src/java/com/bigdata/service/jini/LoadBalancerServer.java
trunk/bigdata-jini/src/java/com/bigdata/service/jini/util/BroadcastSighup.java
trunk/bigdata-jini/src/java/com/bigdata/zookeeper/ZooHelper.java
trunk/bigdata-jini/src/test/com/bigdata/jini/start/config/TestZookeeperServerEntry.java
trunk/bigdata-jini/src/test/com/bigdata/service/jini/AbstractServerTestCase.java
trunk/bigdata-perf/lubm/src/java/edu/lehigh/swat/bench/ubt/Test.java
trunk/bigdata-rdf/src/test/com/bigdata/rdf/metrics/TestMetrics.java
trunk/bigdata-rdf/src/test/com/bigdata/rdf/store/AbstractServerTestCase.java
trunk/build.xml
trunk/src/resources/bin/pstart
Modified: trunk/bigdata/src/java/com/bigdata/counters/AbstractStatisticsCollector.java
===================================================================
--- trunk/bigdata/src/java/com/bigdata/counters/AbstractStatisticsCollector.java 2010-07-28 20:47:53 UTC (rev 3337)
+++ trunk/bigdata/src/java/com/bigdata/counters/AbstractStatisticsCollector.java 2010-07-28 21:14:27 UTC (rev 3338)
@@ -48,6 +48,7 @@
import com.bigdata.counters.win.StatisticsCollectorForWindows;
import com.bigdata.io.DirectBufferPool;
import com.bigdata.rawstore.Bytes;
+import com.bigdata.util.config.NicUtil;
import com.bigdata.util.httpd.AbstractHTTPD;
/**
@@ -64,7 +65,6 @@
* and Un*x platforms so as to support the declared counters on all platforms.
*
* @author <a href="mailto:tho...@us...">Bryan Thompson</a>
- * @version $Id$
*/
abstract public class AbstractStatisticsCollector implements IStatisticsCollector {
@@ -83,32 +83,10 @@
String s;
try {
-
-// hostname = InetAddress.getLocalHost().getHostName();
-
- s = InetAddress.getLocalHost().getCanonicalHostName();
-
- } catch (UnknownHostException e) {
-
- try {
-
- s = InetAddress.getLocalHost().getHostName();
-
- } catch(UnknownHostException e2) {
-
- final String msg = "Could not resolve hostname";
- try {
- log.error(msg);
- } catch(Throwable t) {
- System.err.println(msg);
- }
-
- s = "localhost";
-
- //throw new AssertionError(e);
-
- }
-
+ s = NicUtil.getIpAddress("default.nic", "default", false);
+ } catch(Throwable t) {//for now, maintain same failure logic as used previously
+ t.printStackTrace();
+ s = NicUtil.getIpAddressByLocalHost();
}
fullyQualifiedHostName = s;
@@ -520,7 +498,6 @@
* Options for {@link AbstractStatisticsCollector}
*
* @author <a href="mailto:tho...@us...">Bryan Thompson</a>
- * @version $Id$
*/
public interface Options {
Modified: trunk/bigdata/src/java/com/bigdata/resources/MoveTask.java
===================================================================
--- trunk/bigdata/src/java/com/bigdata/resources/MoveTask.java 2010-07-28 20:47:53 UTC (rev 3337)
+++ trunk/bigdata/src/java/com/bigdata/resources/MoveTask.java 2010-07-28 21:14:27 UTC (rev 3338)
@@ -63,6 +63,7 @@
import com.bigdata.service.IMetadataService;
import com.bigdata.service.MetadataService;
import com.bigdata.service.ResourceService;
+import com.bigdata.util.config.NicUtil;
/**
* Task moves an index partition to another {@link IDataService}.
@@ -155,7 +156,6 @@
* need to do the atomic update phase.
*
* @author <a href="mailto:tho...@us...">Bryan Thompson</a>
- * @version $Id$
*/
public class MoveTask extends AbstractPrepareTask<MoveResult> {
@@ -421,7 +421,6 @@
* successful.
*
* @author <a href="mailto:tho...@us...">Bryan Thompson</a>
- * @version $Id$
*
* @todo optimization to NOT send an empty index segment if there are no
* buffered writes on the live journal.
@@ -434,6 +433,7 @@
private final UUID targetDataServiceUUID;
private final int targetIndexPartitionId;
private final Event parentEvent;
+ private final InetAddress thisInetAddr;
/**
*
@@ -481,6 +481,11 @@
this.targetIndexPartitionId = targetIndexPartitionId;
this.parentEvent = parentEvent;
+ try {
+ this.thisInetAddr = InetAddress.getByName(NicUtil.getIpAddress("default.nic", "default", false));
+ } catch(Throwable t) {
+ throw new IllegalArgumentException(t.getMessage(), t);
+ }
}
/**
@@ -591,7 +596,7 @@
targetIndexPartitionId,//
historicalWritesBuildResult.segmentMetadata,//
bufferedWritesBuildResult.segmentMetadata,//
- InetAddress.getLocalHost(),//
+ thisInetAddr,
resourceManager
.getResourceServicePort()//
)).get();
@@ -856,7 +861,6 @@
* until the "receive" operation is complete.
*
* @author <a href="mailto:tho...@us...">Bryan Thompson</a>
- * @version $Id$
*/
private static class IsIndexRegistered_UsingWriteService implements
IIndexProcedure {
@@ -896,7 +900,6 @@
* @see InnerReceiveIndexPartitionTask
*
* @author <a href="mailto:tho...@us...">Bryan Thompson</a>
- * @version $Id$
*/
protected static class ReceiveIndexPartitionTask extends DataServiceCallable<Void> {
@@ -1039,7 +1042,6 @@
* source data service.
*
* @author <a href="mailto:tho...@us...">Bryan Thompson</a>
- * @version $Id$
*/
private static class InnerReceiveIndexPartitionTask extends AbstractTask<Void> {
Modified: trunk/bigdata/src/java/com/bigdata/service/AbstractEmbeddedLoadBalancerService.java
===================================================================
--- trunk/bigdata/src/java/com/bigdata/service/AbstractEmbeddedLoadBalancerService.java 2010-07-28 20:47:53 UTC (rev 3337)
+++ trunk/bigdata/src/java/com/bigdata/service/AbstractEmbeddedLoadBalancerService.java 2010-07-28 21:14:27 UTC (rev 3338)
@@ -5,6 +5,8 @@
import java.util.Properties;
import java.util.UUID;
+import com.bigdata.util.config.NicUtil;
+
/**
* Embedded {@link LoadBalancerService}.
*
@@ -14,7 +16,7 @@
abstract public class AbstractEmbeddedLoadBalancerService extends LoadBalancerService {
// final private UUID serviceUUID;
- final private String hostname;
+ private String hostname = NicUtil.getIpAddressByLocalHost();//for now, maintain the same failure logic as in constructor
public AbstractEmbeddedLoadBalancerService(UUID serviceUUID,
Properties properties) {
@@ -28,17 +30,11 @@
setServiceUUID(serviceUUID);
- String hostname;
try {
-
- hostname = Inet4Address.getLocalHost().getCanonicalHostName();
-
- } catch (UnknownHostException e) {
-
- hostname = "localhost";
-
+ this.hostname = NicUtil.getIpAddress("default.nic", "default", false);
+ } catch(Throwable t) {
+ t.printStackTrace();
}
- this.hostname = hostname;
}
Modified: trunk/bigdata/src/test/com/bigdata/counters/httpd/TestCounterSetHTTPDServer.java
===================================================================
--- trunk/bigdata/src/test/com/bigdata/counters/httpd/TestCounterSetHTTPDServer.java 2010-07-28 20:47:53 UTC (rev 3337)
+++ trunk/bigdata/src/test/com/bigdata/counters/httpd/TestCounterSetHTTPDServer.java 2010-07-28 21:14:27 UTC (rev 3338)
@@ -39,6 +39,7 @@
import com.bigdata.counters.Instrument;
import com.bigdata.counters.OneShotInstrument;
import com.bigdata.counters.PeriodEnum;
+import com.bigdata.util.config.NicUtil;
/**
* Utility class for testing {@link CounterSetHTTPD} or
@@ -62,12 +63,10 @@
CounterSet cset = root.makePath("localhost");
- cset.addCounter("hostname", new OneShotInstrument<String>(
- InetAddress.getLocalHost().getHostName()));
+ String localIpAddr = NicUtil.getIpAddress("default.nic", "default", true);
+ cset.addCounter("hostname", new OneShotInstrument<String>(localIpAddr));
+ cset.addCounter("ipaddr", new OneShotInstrument<String>(localIpAddr));
- cset.addCounter("ipaddr", new OneShotInstrument<String>(InetAddress
- .getLocalHost().getHostAddress()));
-
// 60 minutes of data : @todo replace with CounterSetBTree (no fixed limit).
final HistoryInstrument<Double> history1 = new HistoryInstrument<Double>(
new History<Double>(new Double[60], PeriodEnum.Minutes
Modified: trunk/bigdata/src/test/com/bigdata/service/TestResourceService.java
===================================================================
--- trunk/bigdata/src/test/com/bigdata/service/TestResourceService.java 2010-07-28 20:47:53 UTC (rev 3337)
+++ trunk/bigdata/src/test/com/bigdata/service/TestResourceService.java 2010-07-28 21:14:27 UTC (rev 3338)
@@ -43,6 +43,7 @@
import com.bigdata.service.ResourceService.ReadResourceTask;
import com.bigdata.util.concurrent.DaemonThreadFactory;
+import com.bigdata.util.config.NicUtil;
/**
* Test verifies the ability to transmit a file using the
@@ -103,14 +104,15 @@
};
+ InetAddress thisInetAddr;
+ thisInetAddr = InetAddress.getByName(NicUtil.getIpAddress("default.nic", "default", true));
try {
service.awaitRunning(100, TimeUnit.MILLISECONDS);
assertTrue(service.isOpen());
- assertEquals(tmpFile, new ReadResourceTask(InetAddress
- .getLocalHost(), service.port, allowedUUID, tmpFile).call());
+ assertEquals(tmpFile, new ReadResourceTask(thisInetAddr, service.port, allowedUUID, tmpFile).call());
if (log.isInfoEnabled())
log.info(service.counters.getCounters());
@@ -182,6 +184,8 @@
final List<File> tempFiles = new LinkedList<File>();
+ InetAddress thisInetAddr;
+ thisInetAddr = InetAddress.getByName(NicUtil.getIpAddress("default.nic", "default", true));
try {
service.awaitRunning(100, TimeUnit.MILLISECONDS);
@@ -197,8 +201,7 @@
tempFiles.add(tmpFile);
- tasks.add(new ReadResourceTask(InetAddress.getLocalHost(),
- service.port, allowedUUID, tmpFile));
+ tasks.add(new ReadResourceTask(thisInetAddr, service.port, allowedUUID, tmpFile));
}
Modified: trunk/bigdata/src/test/com/bigdata/test/ExperimentDriver.java
===================================================================
--- trunk/bigdata/src/test/com/bigdata/test/ExperimentDriver.java 2010-07-28 20:47:53 UTC (rev 3337)
+++ trunk/bigdata/src/test/com/bigdata/test/ExperimentDriver.java 2010-07-28 21:14:27 UTC (rev 3338)
@@ -68,6 +68,7 @@
import com.bigdata.journal.ProxyTestCase;
import com.bigdata.util.NV;
+import com.bigdata.util.config.NicUtil;
/**
* A harness for running comparison of different configurations.
@@ -1364,13 +1365,9 @@
props.setProperty("os.arch.cpus", ""+SystemUtil.numProcessors());
try {
-
- props.setProperty("host",InetAddress.getLocalHost().getHostName());
-
- } catch(UnknownHostException ex) {
- /*
- * ignore.
- */
+ props.setProperty( "host", NicUtil.getIpAddress("default.nic", "default", true) );
+ } catch(Throwable t) {
+ t.printStackTrace();
}
return props;
Modified: trunk/bigdata-jini/src/java/com/bigdata/jini/start/config/JiniServiceConfiguration.java
===================================================================
--- trunk/bigdata-jini/src/java/com/bigdata/jini/start/config/JiniServiceConfiguration.java 2010-07-28 20:47:53 UTC (rev 3337)
+++ trunk/bigdata-jini/src/java/com/bigdata/jini/start/config/JiniServiceConfiguration.java 2010-07-28 21:14:27 UTC (rev 3338)
@@ -78,6 +78,7 @@
import com.bigdata.service.jini.JiniClient;
import com.bigdata.service.jini.JiniClientConfig;
import com.bigdata.service.jini.JiniFederation;
+import com.bigdata.util.config.NicUtil;
import com.bigdata.zookeeper.ZNodeCreatedWatcher;
/**
@@ -130,6 +131,8 @@
public final Properties properties;
public final String[] jiniOptions;
+ private final String serviceIpAddr;
+
protected void toString(StringBuilder sb) {
super.toString(sb);
@@ -175,6 +178,12 @@
} else {
log.warn("groups = " + Arrays.toString(this.groups));
}
+
+ try {
+ this.serviceIpAddr = NicUtil.getIpAddress("default.nic", "default", false);
+ } catch(IOException e) {
+ throw new ConfigurationException(e.getMessage(), e);
+ }
}
/**
@@ -471,8 +480,7 @@
final ServiceDir serviceDir = new ServiceDir(this.serviceDir);
- final Hostname hostName = new Hostname(InetAddress.getLocalHost()
- .getCanonicalHostName().toString());
+ final Hostname hostName = new Hostname(serviceIpAddr);
final ServiceUUID serviceUUID = new ServiceUUID(this.serviceUUID);
Modified: trunk/bigdata-jini/src/java/com/bigdata/jini/start/config/MaxClientServicesPerHostConstraint.java
===================================================================
--- trunk/bigdata-jini/src/java/com/bigdata/jini/start/config/MaxClientServicesPerHostConstraint.java 2010-07-28 20:47:53 UTC (rev 3337)
+++ trunk/bigdata-jini/src/java/com/bigdata/jini/start/config/MaxClientServicesPerHostConstraint.java 2010-07-28 21:14:27 UTC (rev 3338)
@@ -10,6 +10,7 @@
import com.bigdata.jini.lookup.entry.ServiceItemFilterChain;
import com.bigdata.service.IClientService;
import com.bigdata.service.jini.JiniFederation;
+import com.bigdata.util.config.NicUtil;
/**
* Constraint on the #of {@link IClientService}s on the same host.
@@ -51,11 +52,9 @@
// */
// filter.add(ClientServiceFilter.INSTANCE);
- final String hostname = InetAddress.getLocalHost().getHostName();
+ final String hostname = NicUtil.getIpAddress("default.nic", "default", false);
+ final String canonicalHostname = hostname;
- final String canonicalHostname = InetAddress.getLocalHost()
- .getCanonicalHostName();
-
// filters for _this_ host.
filter.add(new HostnameFilter(new Hostname[] {//
new Hostname(hostname),//
Modified: trunk/bigdata-jini/src/java/com/bigdata/jini/start/config/MaxDataServicesPerHostConstraint.java
===================================================================
--- trunk/bigdata-jini/src/java/com/bigdata/jini/start/config/MaxDataServicesPerHostConstraint.java 2010-07-28 20:47:53 UTC (rev 3337)
+++ trunk/bigdata-jini/src/java/com/bigdata/jini/start/config/MaxDataServicesPerHostConstraint.java 2010-07-28 21:14:27 UTC (rev 3338)
@@ -11,6 +11,7 @@
import com.bigdata.service.IDataService;
import com.bigdata.service.jini.JiniFederation;
import com.bigdata.service.jini.lookup.DataServiceFilter;
+import com.bigdata.util.config.NicUtil;
/**
* Constraint on the #of {@link IDataService}s on the same host.
@@ -47,11 +48,9 @@
// only consider data services.
filter.add(DataServiceFilter.INSTANCE);
- final String hostname = InetAddress.getLocalHost().getHostName();
+ final String hostname = NicUtil.getIpAddress("default.nic", "default", false);
+ final String canonicalHostname = hostname;
- final String canonicalHostname = InetAddress.getLocalHost()
- .getCanonicalHostName();
-
// filters for _this_ host.
filter.add(new HostnameFilter(new Hostname[] {//
new Hostname(hostname),//
Modified: trunk/bigdata-jini/src/java/com/bigdata/jini/start/config/ZookeeperServerConfiguration.java
===================================================================
--- trunk/bigdata-jini/src/java/com/bigdata/jini/start/config/ZookeeperServerConfiguration.java 2010-07-28 20:47:53 UTC (rev 3337)
+++ trunk/bigdata-jini/src/java/com/bigdata/jini/start/config/ZookeeperServerConfiguration.java 2010-07-28 21:14:27 UTC (rev 3338)
@@ -54,6 +54,7 @@
import com.bigdata.io.FileLockUtility;
import com.bigdata.jini.start.IServiceListener;
import com.bigdata.jini.start.process.ZookeeperProcessHelper;
+import com.bigdata.util.config.NicUtil;
import com.bigdata.zookeeper.ZooHelper;
/**
@@ -213,6 +214,8 @@
*/
public final Map<String, String> other;
+ private final InetAddress thisInetAddr;
+
/**
* Adds value to {@link #other} if found in the {@link Configuration}.
*
@@ -318,6 +321,14 @@
putIfDefined(config, Options.FORCE_SYNC, Boolean.TYPE);
putIfDefined(config, Options.SKIP_ACL, Boolean.TYPE);
+ try {
+ thisInetAddr = InetAddress.getByName(NicUtil.getIpAddress("default.nic", "default", false));
+ } catch(IOException e) {
+ throw new ConfigurationException(e.getMessage(), e);
+ }
+ if (log.isInfoEnabled()) {
+ log.info("zookeeper host="+thisInetAddr.getCanonicalHostName());
+ }
}
/**
@@ -541,7 +552,7 @@
*/
public V call() throws Exception {
- if (ZooHelper.isRunning(InetAddress.getLocalHost(), clientPort)) {
+ if (ZooHelper.isRunning(thisInetAddr, clientPort)) {
/*
* Query for an instance already running on local host at that
@@ -552,7 +563,7 @@
* instance on the localhost.
*/
- ZooHelper.ruok(InetAddress.getLocalHost(), clientPort);
+ ZooHelper.ruok(thisInetAddr, clientPort);
throw new ZookeeperRunningException(
"Zookeeper already running on localhost: clientport="
@@ -625,7 +636,7 @@
* Note: We don't test this until we have the file lock.
*/
- ZooHelper.ruok(InetAddress.getLocalHost(), clientPort);
+ ZooHelper.ruok(thisInetAddr, clientPort);
throw new ZookeeperRunningException(
"Zookeeper already running on localhost: clientport="
@@ -727,7 +738,7 @@
* clientPort. That could have already been true.
*/
- ZooHelper.ruok(InetAddress.getLocalHost(), clientPort);
+ ZooHelper.ruok(thisInetAddr, clientPort);
// adjust for time remaining.
nanos = (System.nanoTime() - begin);
Modified: trunk/bigdata-jini/src/java/com/bigdata/jini/start/process/JiniCoreServicesProcessHelper.java
===================================================================
--- trunk/bigdata-jini/src/java/com/bigdata/jini/start/process/JiniCoreServicesProcessHelper.java 2010-07-28 20:47:53 UTC (rev 3337)
+++ trunk/bigdata-jini/src/java/com/bigdata/jini/start/process/JiniCoreServicesProcessHelper.java 2010-07-28 21:14:27 UTC (rev 3338)
@@ -42,6 +42,7 @@
import com.bigdata.service.jini.JiniClientConfig;
import com.bigdata.service.jini.util.JiniServicesHelper;
import com.bigdata.service.jini.util.LookupStarter;
+import com.bigdata.util.config.NicUtil;
/**
* Class for starting the jini services.
@@ -169,7 +170,7 @@
*/
if (log.isInfoEnabled())
- log.info("Will start instance: " + InetAddress.getLocalHost()
+ log.info("Will start instance: " + NicUtil.getIpAddress("default.nic", "default", false)
+ ", config=" + config);
final JiniCoreServicesStarter<JiniCoreServicesProcessHelper> serviceStarter = serviceConfig
Modified: trunk/bigdata-jini/src/java/com/bigdata/jini/start/process/ZookeeperProcessHelper.java
===================================================================
--- trunk/bigdata-jini/src/java/com/bigdata/jini/start/process/ZookeeperProcessHelper.java 2010-07-28 20:47:53 UTC (rev 3337)
+++ trunk/bigdata-jini/src/java/com/bigdata/jini/start/process/ZookeeperProcessHelper.java 2010-07-28 21:14:27 UTC (rev 3338)
@@ -16,6 +16,7 @@
import com.bigdata.jini.start.config.ZookeeperServerConfiguration;
import com.bigdata.jini.start.config.ZookeeperServerEntry;
import com.bigdata.jini.start.config.ZookeeperServerConfiguration.ZookeeperRunningException;
+import com.bigdata.util.config.NicUtil;
import com.bigdata.zookeeper.ZooHelper;
/**
@@ -40,6 +41,14 @@
protected final int clientPort;
+ protected static InetAddress thisInetAddr = null;
+ static {
+ try {
+ thisInetAddr = InetAddress.getByName
+ (NicUtil.getIpAddress("default.nic", "default", false));
+ } catch (Throwable t) { /* swallow */ }
+ }
+
/**
* @param name
* @param builder
@@ -144,11 +153,11 @@
final ZookeeperServerConfiguration serverConfig = new ZookeeperServerConfiguration(
config);
- if (ZooHelper.isRunning(InetAddress.getLocalHost(), serverConfig.clientPort)) {
+ if (ZooHelper.isRunning(thisInetAddr, serverConfig.clientPort)) {
if (log.isInfoEnabled())
log.info("Zookeeper already running: "
- + InetAddress.getLocalHost().getCanonicalHostName()
+ + thisInetAddr.getCanonicalHostName()
+ ":" + serverConfig.clientPort);
// will not consider start.
Modified: trunk/bigdata-jini/src/java/com/bigdata/service/jini/LoadBalancerServer.java
===================================================================
--- trunk/bigdata-jini/src/java/com/bigdata/service/jini/LoadBalancerServer.java 2010-07-28 20:47:53 UTC (rev 3337)
+++ trunk/bigdata-jini/src/java/com/bigdata/service/jini/LoadBalancerServer.java 2010-07-28 21:14:27 UTC (rev 3338)
@@ -31,6 +31,7 @@
import com.bigdata.service.jini.util.DumpFederation;
import com.bigdata.service.jini.util.DumpFederation.FormatRecord;
import com.bigdata.service.jini.util.DumpFederation.FormatTabTable;
+import com.bigdata.util.config.NicUtil;
import com.bigdata.util.httpd.AbstractHTTPD;
import com.bigdata.util.httpd.NanoHTTPD;
import com.bigdata.util.httpd.NanoHTTPD.Response;
@@ -547,15 +548,10 @@
* This exception gets thrown if the client has made a direct
* (vs RMI) call.
*/
-
try {
-
- clientAddr = Inet4Address.getLocalHost();
-
- } catch (UnknownHostException ex) {
-
- return "localhost";
-
+ clientAddr = InetAddress.getByName(NicUtil.getIpAddress("default.nic", "default", false));
+ } catch(Throwable t) {//for now, maintain the same failure logic as used previously
+ return NicUtil.getIpAddressByLocalHost();
}
}
Modified: trunk/bigdata-jini/src/java/com/bigdata/service/jini/util/BroadcastSighup.java
===================================================================
--- trunk/bigdata-jini/src/java/com/bigdata/service/jini/util/BroadcastSighup.java 2010-07-28 20:47:53 UTC (rev 3337)
+++ trunk/bigdata-jini/src/java/com/bigdata/service/jini/util/BroadcastSighup.java 2010-07-28 21:14:27 UTC (rev 3338)
@@ -39,6 +39,7 @@
import com.bigdata.service.ILoadBalancerService;
import com.bigdata.service.jini.JiniClient;
import com.bigdata.service.jini.JiniFederation;
+import com.bigdata.util.config.NicUtil;
import java.net.InetAddress;
import net.jini.config.Configuration;
import net.jini.core.entry.Entry;
@@ -158,8 +159,8 @@
// Set up the service template and filter used to identify the service.
- final String hostname = InetAddress.getLocalHost()
- .getCanonicalHostName().toString();
+ final String hostname =
+ NicUtil.getIpAddress("default.nic", "default", false);
ServiceTemplate template = new ServiceTemplate(null,
new Class[] { iface }, null);
ServiceItemFilter thisHostFilter = null;
Modified: trunk/bigdata-jini/src/java/com/bigdata/zookeeper/ZooHelper.java
===================================================================
--- trunk/bigdata-jini/src/java/com/bigdata/zookeeper/ZooHelper.java 2010-07-28 20:47:53 UTC (rev 3337)
+++ trunk/bigdata-jini/src/java/com/bigdata/zookeeper/ZooHelper.java 2010-07-28 21:14:27 UTC (rev 3338)
@@ -42,6 +42,7 @@
import org.apache.zookeeper.KeeperException.NoNodeException;
import com.bigdata.jini.start.config.AbstractHostConstraint;
+import com.bigdata.util.config.NicUtil;
/**
* Utility class for issuing the four letter commands to a zookeeper service.
@@ -53,6 +54,14 @@
protected static final Logger log = Logger.getLogger(ZooHelper.class);
+ private static InetAddress thisInetAddr = null;
+ static {
+ try {
+ thisInetAddr = InetAddress.getByName
+ (NicUtil.getIpAddress("default.nic", "default", false));
+ } catch (Throwable t) { /* swallow */ }
+ }
+
/**
* Inquires whether a zookeeper instance is running in a non-error state and
* returns iff the service reports "imok".
@@ -129,7 +138,7 @@
if (log.isInfoEnabled())
log.info("Killing service: @ port=" + clientPort);
- final Socket socket = new Socket(InetAddress.getLocalHost(), clientPort);
+ final Socket socket = new Socket(thisInetAddr, clientPort);
try {
@@ -180,7 +189,7 @@
if (log.isInfoEnabled())
log.info("hostname=" + addr + ", port=" + clientPort);
- final Socket socket = new Socket(InetAddress.getLocalHost(), clientPort);
+ final Socket socket = new Socket(thisInetAddr, clientPort);
try {
@@ -251,7 +260,7 @@
if (log.isInfoEnabled())
log.info("hostname=" + addr + ", port=" + clientPort);
- final Socket socket = new Socket(InetAddress.getLocalHost(), clientPort);
+ final Socket socket = new Socket(thisInetAddr, clientPort);
try {
Modified: trunk/bigdata-jini/src/test/com/bigdata/jini/start/config/TestZookeeperServerEntry.java
===================================================================
--- trunk/bigdata-jini/src/test/com/bigdata/jini/start/config/TestZookeeperServerEntry.java 2010-07-28 20:47:53 UTC (rev 3337)
+++ trunk/bigdata-jini/src/test/com/bigdata/jini/start/config/TestZookeeperServerEntry.java 2010-07-28 21:14:27 UTC (rev 3338)
@@ -27,6 +27,7 @@
package com.bigdata.jini.start.config;
+import java.io.IOException;
import java.net.InetAddress;
import java.net.SocketException;
import java.net.UnknownHostException;
@@ -34,6 +35,8 @@
import junit.framework.TestCase2;
import net.jini.config.ConfigurationException;
+import com.bigdata.util.config.NicUtil;
+
/**
* Unit tests for the {@link ZookeeperServerEntry}.
*
@@ -97,9 +100,9 @@
* @throws SocketException
* @throws UnknownHostException
*/
- public void test002() throws ConfigurationException, SocketException, UnknownHostException {
+ public void test002() throws ConfigurationException, SocketException, UnknownHostException, IOException {
- final String server = InetAddress.getLocalHost().getCanonicalHostName();
+ final String server = NicUtil.getIpAddress("default.nic", "default", true);
final String[] hosts = new String[] {
"127.0.0.1",
Modified: trunk/bigdata-jini/src/test/com/bigdata/service/jini/AbstractServerTestCase.java
===================================================================
--- trunk/bigdata-jini/src/test/com/bigdata/service/jini/AbstractServerTestCase.java 2010-07-28 20:47:53 UTC (rev 3337)
+++ trunk/bigdata-jini/src/test/com/bigdata/service/jini/AbstractServerTestCase.java 2010-07-28 21:14:27 UTC (rev 3338)
@@ -45,6 +45,8 @@
import com.bigdata.service.IDataService;
import com.bigdata.service.MetadataService;
import com.sun.jini.tool.ClassServer;
+import com.bigdata.util.config.ConfigDeployUtil;
+import com.bigdata.util.config.NicUtil;
/**
* Abstract base class for tests of remote services.
@@ -366,8 +368,7 @@
*/
// get the hostname.
- InetAddress addr = InetAddress.getLocalHost();
- String hostname = addr.getHostName();
+ String hostname = NicUtil.getIpAddress("default.nic", "default", true);
// Find the service registrar (unicast protocol).
final int timeout = 4*1000; // seconds.
Modified: trunk/bigdata-perf/lubm/src/java/edu/lehigh/swat/bench/ubt/Test.java
===================================================================
--- trunk/bigdata-perf/lubm/src/java/edu/lehigh/swat/bench/ubt/Test.java 2010-07-28 20:47:53 UTC (rev 3337)
+++ trunk/bigdata-perf/lubm/src/java/edu/lehigh/swat/bench/ubt/Test.java 2010-07-28 21:14:27 UTC (rev 3338)
@@ -36,6 +36,7 @@
import java.util.concurrent.TimeUnit;
import com.bigdata.util.concurrent.DaemonThreadFactory;
+import com.bigdata.util.config.NicUtil;
import edu.lehigh.swat.bench.ubt.api.QueryResult;
import edu.lehigh.swat.bench.ubt.api.Repository;
@@ -81,9 +82,10 @@
*/
String hostname;
try {
- hostname = InetAddress.getLocalHost().getHostName();
- } catch (UnknownHostException ex) {
- hostname = "localhost";
+ hostname = NicUtil.getIpAddress("default.nic", "default", false);
+ } catch(Throwable t) {//for now, maintain same failure logic as used previously
+ t.printStackTrace();
+ s = NicUtil.getIpAddressByLocalHost();
}
QUERY_TEST_RESULT_FILE = hostname + "-result.txt";
} else {
Modified: trunk/bigdata-rdf/src/test/com/bigdata/rdf/metrics/TestMetrics.java
===================================================================
--- trunk/bigdata-rdf/src/test/com/bigdata/rdf/metrics/TestMetrics.java 2010-07-28 20:47:53 UTC (rev 3337)
+++ trunk/bigdata-rdf/src/test/com/bigdata/rdf/metrics/TestMetrics.java 2010-07-28 21:14:27 UTC (rev 3338)
@@ -48,6 +48,7 @@
import com.bigdata.rdf.rio.LoadStats;
import com.bigdata.rdf.store.DataLoader;
import com.bigdata.rdf.store.DataLoader.ClosureEnum;
+import com.bigdata.util.config.NicUtil;
/**
* Test harness for loading randomly generated files into a repository.
@@ -588,7 +589,7 @@
* Write out the repositoryClass and all defined properties.
*/
// metricsWriter.write("repositoryClass, "+m_repo.getClass().getName()+"\n");
- metricsWriter.write("host, "+InetAddress.getLocalHost().getHostName()+"\n");
+ metricsWriter.write("host, "+NicUtil.getIpAddress("default.nic", "default", true)+"\n");
if(true) {
Map props = new TreeMap(PropertyUtil.flatten(getProperties()));
Iterator itr = props.entrySet().iterator();
Modified: trunk/bigdata-rdf/src/test/com/bigdata/rdf/store/AbstractServerTestCase.java
===================================================================
--- trunk/bigdata-rdf/src/test/com/bigdata/rdf/store/AbstractServerTestCase.java 2010-07-28 20:47:53 UTC (rev 3337)
+++ trunk/bigdata-rdf/src/test/com/bigdata/rdf/store/AbstractServerTestCase.java 2010-07-28 21:14:27 UTC (rev 3338)
@@ -50,6 +50,7 @@
import com.bigdata.service.IDataService;
import com.bigdata.service.MetadataService;
import com.bigdata.service.jini.AbstractServer;
+import com.bigdata.util.config.NicUtil;
import com.sun.jini.tool.ClassServer;
/**
@@ -371,8 +372,7 @@
*/
// get the hostname.
- InetAddress addr = InetAddress.getLocalHost();
- String hostname = addr.getHostName();
+ String hostname = NicUtil.getIpAddress("default.nic", "default", true);
// Find the service registrar (unicast protocol).
final int timeout = 4*1000; // seconds.
Modified: trunk/build.xml
===================================================================
--- trunk/build.xml 2010-07-28 20:47:53 UTC (rev 3337)
+++ trunk/build.xml 2010-07-28 21:14:27 UTC (rev 3338)
@@ -1927,6 +1927,8 @@
</echo>
<echo> policy: ${java.security.policy}
</echo>
+ <echo> default.nic: ${default.nic}
+</echo>
<echo> hostname: ${this.hostname}
</echo>
<echo> preferIPv4: ${java.net.preferIPv4Stack}
@@ -1989,6 +1991,7 @@
<sysproperty key="log4j.path" value="${bigdata.test.log4j.abs.path}"/>
<sysproperty key="app.home" value="${app.home}"/>
+ <sysproperty key="default.nic" value="${default.nic}"/>
<sysproperty key="classserver.jar" value="${dist.lib}/classserver.jar" />
<sysproperty key="colt.jar" value="${dist.lib}/colt.jar" />
Modified: trunk/src/resources/bin/pstart
===================================================================
--- trunk/src/resources/bin/pstart 2010-07-28 20:47:53 UTC (rev 3337)
+++ trunk/src/resources/bin/pstart 2010-07-28 21:14:27 UTC (rev 3338)
@@ -1,6 +1,6 @@
#!/usr/bin/python
-import os, sys, socket, getopt, fcntl, struct
+import os, sys, socket, getopt, struct
from os.path import dirname
@@ -47,13 +47,17 @@
The path to the java.util.logging configuration file
exportNic=<interfacename>
- Specifies the name of the network interface on which the Jini service
- will be exported. This property takes precedence over exportHost.
- The default value is "eth0".
+ Specifies the name of the network interface to use by default
+ for service export and remote communication. This property
+ takes precedence over exportHost. The default value for this
+ property is "eth0".
exportHost=<ipaddress|hostname>
- Specifies the IP address on which the Jini service(s) will be exported.
- This property is not used unless exportNic is "".
+ Specifies the IP address or host name to use when exporting
+ services for remote communication. This property will be
+ employed only when the value of the exportNic property
+ is set to the empty string ("") or a value that does not
+ correspond to any of the network interfaces on the system.
bigdata.codebase.host=<interfacename|ipaddress|hostname>
Specifies the network address of the codebase HTTP server. If the
@@ -71,26 +75,6 @@
print "Services: \n " + ", ".join(serviceNames)
-def get_interface_ipaddress(ifname):
- """Gets the IP address assigned to a network interface.
-
- Parameters:
- ifname The name of he interface whose IP address to get
-
- Returns:
- A string contain the IP address of the interface
- """
- if sys.platform == "linux2":
- s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
- return socket.inet_ntoa(fcntl.ioctl(
- s.fileno(),
- 0x8915, # SIOCGIFADDR
- struct.pack('256s', ifname[:15])
- )[20:24])
- else:
- raise NotImplementedError("Not implemented for " + sys.platform)
-
-
class Params:
def __init__(self):
self.serviceName = None
@@ -109,9 +93,7 @@
# The name of the service
self.serviceName = serviceName
- # appHome is the base directory of the Java applications. In the
- # source tree this is the top-level "java" directory. This will
- # always be valid.
+ # appHome is the base directory of the application being started.
self.appHome = params.appHome
# A dictionary containing all of the Java system properties to set
@@ -155,8 +137,8 @@
self.properties['bigdata.codebase.host'] = "eth0"
self.properties['bigdata.codebase.port'] = "8081"
- self.properties['log4j.configuration'] = \
- "src/resources/config/log4j.properties"
+ self.properties['log4j.configuration'] = os.path.join( \
+ self.appHome, "var", "config", "logging", "log4j.properties")
self.properties['log4j.primary.configuration'] = os.path.join( \
self.appHome, "var", "config", "logging", \
serviceName + "-logging.properties")
@@ -170,17 +152,41 @@
"""Using the params.groups, params.mGroups, and params.lookupLocators
lists, create Java system properties appropriate for the service to
convey it the information."""
- if len(params.groups) > 0:
- self.properties['groupsToJoin'] = \
- "{\"" + "\",\"".join(params.groups) + "\"}"
+ if sys.platform == "win32":
+ if len(params.groups) > 0:
+ self.properties['groupsToJoin'] = \
+ "\"" + "{" + \
+ "\\" + \
+ "\"" + \
+ "\\\",\\\"".join(params.groups) + \
+ "\\" + \
+ "\"" + \
+ "}" + "\""
+ else:
+ self.properties['groupsToJoin'] = "\"" + "{}" + "\""
+ if len(params.lookupLocators) > 0:
+ self.properties['locsToJoin'] = \
+ "\"" + "{" + \
+ "new LookupLocator(\\\"" + \
+ "\\\"),new LookupLocator(\\\"".join(params.lookupLocators) + \
+ "\\" + \
+ "\"" + \
+ ")" + \
+ "}" + "\""
+ else:
+ self.properties['locsToJoin'] = "\"" + "{}" + "\""
else:
- self.properties['groupsToJoin'] = "{}"
- if len(params.lookupLocators) > 0:
- self.properties['locsToJoin'] = "{new LookupLocator(\"" + \
- "\"),new LookupLocator(\"".join(params.lookupLocators) + \
- "\")}"
- else:
- self.properties['locsToJoin'] = "{}"
+ if len(params.groups) > 0:
+ self.properties['groupsToJoin'] = \
+ "{\"" + "\",\"".join(params.groups) + "\"}"
+ else:
+ self.properties['groupsToJoin'] = "{}"
+ if len(params.lookupLocators) > 0:
+ self.properties['locsToJoin'] = "{new LookupLocator(\"" + \
+ "\"),new LookupLocator(\"".join(params.lookupLocators) + \
+ "\")}"
+ else:
+ self.properties['locsToJoin'] = "{}"
def setProperties(self, propList):
for k, v in propList:
@@ -222,7 +228,7 @@
self.migrateProperties()
# Build the list of command line arguments
- argList = [ "java", "-cp", ":".join(starterClasspath) ]
+ argList = [ "java", "-cp", os.pathsep.join(starterClasspath) ]
propNames = self.properties.keys()
propNames.sort()
for p in propNames:
@@ -281,22 +287,50 @@
# Construct the ServiceStarter Service Descriptor list
if params.startCodebaseHttpd and serviceName != "httpd":
- self.serviceStarterArgs = [
- "com.sun.jini.start.serviceDescriptors = " + \
- "new ServiceDescriptor[] { httpdDescriptor, " + \
- serviceName + "Descriptor }" ]
+ if sys.platform == "win32":
+ self.serviceStarterArgs = [
+ "\"" + \
+ "com.sun.jini.start.serviceDescriptors = " + \
+ "new ServiceDescriptor[] { httpdDescriptor, " + \
+ serviceName + "Descriptor }" + \
+ "\"" ]
+ else:
+ self.serviceStarterArgs = [
+ "com.sun.jini.start.serviceDescriptors = " + \
+ "new ServiceDescriptor[] { httpdDescriptor, " + \
+ serviceName + "Descriptor }" ]
else:
- self.serviceStarterArgs = [
- "com.sun.jini.start.serviceDescriptors = " + \
- "new ServiceDescriptor[] { " + serviceName + "Descriptor }" ]
+ if sys.platform == "win32":
+ self.serviceStarterArgs = [
+ "\"" + \
+ "com.sun.jini.start.serviceDescriptors = " + \
+ "new ServiceDescriptor[] { " + serviceName + "Descriptor }" + \
+ "\"" ]
+ else:
+ self.serviceStarterArgs = [
+ "com.sun.jini.start.serviceDescriptors = " + \
+ "new ServiceDescriptor[] { " + serviceName + "Descriptor }" ]
def setGroupProperties(self):
BigdataServiceBase.setGroupProperties(self)
- if len(params.mGroups) > 0:
- self.properties['memberGroups'] = \
- "{\"" + "\",\"".join(params.mGroups) + "\"}"
+ if sys.platform == "win32":
+ if len(params.mGroups) > 0:
+ self.properties['memberGroups'] = \
+ "\"" + "{" + \
+ "\\" + \
+ "\"" + \
+ "\\\",\\\"".join(params.mGroups) + \
+ "\\" + \
+ "\"" + \
+ "}" + "\""
+ else:
+ self.properties['memberGroups'] = "\"" + "{}" + "\""
else:
- self.properties['memberGroups'] = "{}"
+ if len(params.mGroups) > 0:
+ self.properties['memberGroups'] = \
+ "{\"" + "\",\"".join(params.mGroups) + "\"}"
+ else:
+ self.properties['memberGroups'] = "{}"
class BigdataMetaservice(BigdataService):
@@ -328,10 +362,18 @@
break
# Construct the ServiceStarter Service Descriptor list
- self.serviceStarterArgs = [
- "com.sun.jini.start.serviceDescriptors = " + \
- "new ServiceDescriptor[] {" + \
- "Descriptor, ".join(services) + "Descriptor}" ]
+ if sys.platform == "win32":
+ self.serviceStarterArgs = [
+ "\"" +
+ "com.sun.jini.start.serviceDescriptors = " + \
+ "new ServiceDescriptor[] {" + \
+ "Descriptor, ".join(services) + "Descriptor}" + \
+ "\"" ]
+ else:
+ self.serviceStarterArgs = [
+ "com.sun.jini.start.serviceDescriptors = " + \
+ "new ServiceDescriptor[] {" + \
+ "Descriptor, ".join(services) + "Descriptor}" ]
class BigdataServiceOldLog(BigdataService):
@@ -420,7 +462,7 @@
# BTM - params.appHome = dirname(dirname( os.path.abspath(sys.argv[0])) )
- print "appHome=" + params.appHome
+ # print "appHome=" + params.appHome
# Instiantate the object for the service
serviceName = args[0]
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|