[teiid-commits] teiid SVN: r2059 - in trunk: build/kit-jboss-container/deploy/teiid and 6 other directories.

teiid-commits at lists.jboss.org teiid-commits at lists.jboss.org
Thu Apr 15 16:03:07 EDT 2010


Author: rareddy
Date: 2010-04-15 16:03:04 -0400 (Thu, 15 Apr 2010)
New Revision: 2059

Removed:
   trunk/common-core/src/main/java/com/metamatrix/common/util/NetUtils.java
   trunk/common-core/src/test/java/com/metamatrix/common/util/TestNetUtils.java
Modified:
   trunk/adminshell/src/main/resources/scripts/adminapi.bsh
   trunk/build/kit-jboss-container/deploy/teiid/teiid-jboss-beans.xml
   trunk/client/src/main/java/org/teiid/net/HostInfo.java
   trunk/client/src/main/java/org/teiid/net/socket/SocketServerConnectionFactory.java
   trunk/engine/src/main/java/org/teiid/dqp/internal/process/DQPConfiguration.java
   trunk/runtime/src/main/java/org/teiid/transport/SocketConfiguration.java
Log:
TEIID-1047: Host name resolution now match that of the JBoss AS. If user specifies "-b" option with JBoss, then Teiid will use that address. Otherwise "InetAddress.getLocalAddress()" is used. User can override JBoss bind address behavior by specifying the address in the Teiid configuration.

Modified: trunk/adminshell/src/main/resources/scripts/adminapi.bsh
===================================================================
--- trunk/adminshell/src/main/resources/scripts/adminapi.bsh	2010-04-15 15:56:33 UTC (rev 2058)
+++ trunk/adminshell/src/main/resources/scripts/adminapi.bsh	2010-04-15 20:03:04 UTC (rev 2059)
@@ -1,5 +1,5 @@
 import org.teiid.adminapi.*;
-
+import org.teiid.adminapi.Admin.DataSourceType;
 import com.metamatrix.core.util.ObjectConverterUtil;
 
 

Modified: trunk/build/kit-jboss-container/deploy/teiid/teiid-jboss-beans.xml
===================================================================
--- trunk/build/kit-jboss-container/deploy/teiid/teiid-jboss-beans.xml	2010-04-15 15:56:33 UTC (rev 2058)
+++ trunk/build/kit-jboss-container/deploy/teiid/teiid-jboss-beans.xml	2010-04-15 20:03:04 UTC (rev 2059)
@@ -73,8 +73,6 @@
         <property name="securityHelper"><inject bean="SecurityHelper"/></property>
         <property name="VDBRepository"><inject bean="VDBRepository"/></property>
         
-        <!-- Name of the process that uniquely identifies this process -->
-        <property name="processName">localhost</property>
         <!-- Process pool maximum thread count. (default 32) Increase this value if your load includes a large number of XQueries or if the system's available processors is larger than 8. -->
         <property name="maxThreads">32</property>
         <!-- Query processor time slice, in milliseconds. (default 2000) -->
@@ -102,7 +100,7 @@
     <!-- JDBC Socket connection properties (SSL see below) -->
     <bean name="JdbcSocketConfiguration" class="org.teiid.transport.SocketConfiguration">
         <property name="enabled">true</property>
-        <property name="bindAddress">localhost</property>
+        <!-- property name="bindAddress">localhost</property-->
         <property name="portNumber">31000</property>
         <!-- Max number of threads dedicated to initial request processing (default 15) -->
         <property name="maxSocketThreads">15</property>
@@ -130,7 +128,7 @@
     <!-- Admin Socket connection settings (SSL see below) -->
     <bean name="AdminSocketConfiguration" class="org.teiid.transport.SocketConfiguration">
         <property name="enabled">true</property>
-        <property name="bindAddress">localhost</property>
+        <!-- property name="bindAddress">localhost</property-->
         <property name="portNumber">31443</property>
         <!-- Max number of threads dedicated to Admin and initial request processing (default 4) -->
         <property name="maxSocketThreads">4</property>

Modified: trunk/client/src/main/java/org/teiid/net/HostInfo.java
===================================================================
--- trunk/client/src/main/java/org/teiid/net/HostInfo.java	2010-04-15 15:56:33 UTC (rev 2058)
+++ trunk/client/src/main/java/org/teiid/net/HostInfo.java	2010-04-15 20:03:04 UTC (rev 2059)
@@ -25,7 +25,6 @@
 import java.net.InetAddress;
 import java.net.UnknownHostException;
 
-import com.metamatrix.common.util.NetUtils;
 import com.metamatrix.core.util.ArgCheck;
 import com.metamatrix.core.util.HashCodeUtil;
 
@@ -43,7 +42,7 @@
     	if (inetAddress != null) {
     		return inetAddress;
     	}
-    	return NetUtils.resolveHostByName(hostName);
+    	return InetAddress.getByName(this.hostName);
     }
     
     public HostInfo (String host, int port) {
@@ -53,8 +52,8 @@
     	
     	//only cache inetaddresses if they represent the ip. 
     	try {
-			InetAddress addr = NetUtils.resolveHostByName(hostName);
-			if (addr.getHostAddress().equalsIgnoreCase(hostName)) {
+			InetAddress addr = InetAddress.getByName(this.hostName);
+			if (addr.getHostAddress().equalsIgnoreCase(this.hostName)) {
 				this.inetAddress = addr;
 			}
 		} catch (UnknownHostException e) {

Modified: trunk/client/src/main/java/org/teiid/net/socket/SocketServerConnectionFactory.java
===================================================================
--- trunk/client/src/main/java/org/teiid/net/socket/SocketServerConnectionFactory.java	2010-04-15 15:56:33 UTC (rev 2058)
+++ trunk/client/src/main/java/org/teiid/net/socket/SocketServerConnectionFactory.java	2010-04-15 20:03:04 UTC (rev 2059)
@@ -45,10 +45,9 @@
 import org.teiid.net.CommunicationException;
 import org.teiid.net.ConnectionException;
 import org.teiid.net.HostInfo;
-import org.teiid.net.TeiidURL;
 import org.teiid.net.ServerConnectionFactory;
+import org.teiid.net.TeiidURL;
 
-import com.metamatrix.common.util.NetUtils;
 import com.metamatrix.common.util.PropertiesUtils;
 import com.metamatrix.core.MetaMatrixCoreException;
 import com.metamatrix.core.util.ReflectionHelper;
@@ -264,7 +263,7 @@
 
 	static void updateConnectionProperties(Properties connectionProperties) {
 		try {
-			InetAddress addr = NetUtils.getInstance().getInetAddress();
+			InetAddress addr = InetAddress.getLocalHost();
 			connectionProperties.put(TeiidURL.CONNECTION.CLIENT_IP_ADDRESS, addr.getHostAddress());
 			connectionProperties.put(TeiidURL.CONNECTION.CLIENT_HOSTNAME, addr.getCanonicalHostName());
         } catch (UnknownHostException err1) {

Deleted: trunk/common-core/src/main/java/com/metamatrix/common/util/NetUtils.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/common/util/NetUtils.java	2010-04-15 15:56:33 UTC (rev 2058)
+++ trunk/common-core/src/main/java/com/metamatrix/common/util/NetUtils.java	2010-04-15 20:03:04 UTC (rev 2059)
@@ -1,172 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership.  Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- * 
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- * 
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- * 
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package com.metamatrix.common.util;
-
-import java.io.IOException;
-import java.net.Inet6Address;
-import java.net.InetAddress;
-import java.net.NetworkInterface;
-import java.net.Socket;
-import java.net.SocketException;
-import java.net.UnknownHostException;
-import java.util.Enumeration;
-
-
-public class NetUtils {
-	private InetAddress inetAddress;
-	
-	private static NetUtils INSTANCE = new NetUtils();
-	
-	public static NetUtils getInstance() {
-		return INSTANCE;
-	}
-	    
-    public InetAddress getInetAddress() throws UnknownHostException {
-    	resolveHostName();
-    	return this.inetAddress; 
-    }
-    
-
-    /**
-     * Resolves the given host name into InetAddress; if host name can not be resolved then it will
-     * throw {@link UnknownHostException}
-     * @param hostName
-     * @return
-     * @throws UnknownHostException
-     */
-    public static InetAddress resolveHostByName(String hostName) throws UnknownHostException {
-        if( hostName.equalsIgnoreCase("localhost")) { //$NON-NLS-1$
-            try {
-				return getInstance().getInetAddress();
-			} catch (UnknownHostException e) {
-			}
-        } 
-       	return InetAddress.getByName(hostName);
-    }
-    
-    /*
-     * Dynamically resolving the host name should only be done when setupmm is being run
-     * or when the vm initially starts up and the configuration Host has to be found based on that resolution.  
-     * After that, the {@link VMNaming} class should be used to obtain the logical and physical host addresses. 
-     */
-    private synchronized void resolveHostName() throws UnknownHostException {
-    	UnknownHostException une = null;
-
-    	boolean preferIPv6=Boolean.getBoolean("java.net.preferIPv6Addresses");//$NON-NLS-1$
-
-    	// majority of the times we will find the address with this below call 
-    	if (this.inetAddress == null) {
-	    	try {
-	        	InetAddress addr = InetAddress.getLocalHost();
-	        	if(!addr.isLoopbackAddress()) {
-	        		this.inetAddress = addr;
-	        	}
-	        } catch(UnknownHostException e) {
-	        	une=e;
-	        }     
-    	}
-
-    	// see if you can find a non-loopback address, based on the preference
-    	if (this.inetAddress == null) {
-    		this.inetAddress = findAddress(preferIPv6, false);
-    	}
-    	
-    	// if no-addresses found so far then resort to IPv4 loopback address
-    	if (this.inetAddress == null) {
-    		this.inetAddress = findAddress(false, true);
-    	}
-    	
-    	if (this.inetAddress == null) {
-    		if (une != null) throw une;
-    		throw new UnknownHostException("failed to resolve the address for localhost"); //$NON-NLS-1$
-    	}
-    }
-
-    
-    
-    /**
-     * Finds a InetAddress of the current host where the JVM is running, by querying NetworkInterfaces installed
-     * and filters them by given preferences. It will return the first Address which UP and meets the criteria
-     * @param preferIPv6 
-     * @param perferLoopback
-     * @return null is returned if requested criteria is not met.
-     * @throws UnknownHostException
-     * http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4665037 (Linux issue with resolving to loopback in the DHCP situations)
-     */
-    private InetAddress findAddress(boolean preferIPv6, boolean perferLoopback) throws UnknownHostException {
-    	try {
-			Enumeration<NetworkInterface> ne = NetworkInterface.getNetworkInterfaces();
-			while (ne.hasMoreElements()) {
-				NetworkInterface ni = ne.nextElement();
-				//## JDBC4.0-begin ##
-				if (ni.isUp()) {
-				//## JDBC4.0-end ##
-					Enumeration<InetAddress> addrs = ni.getInetAddresses();
-					while (addrs.hasMoreElements()) {
-						InetAddress addr = addrs.nextElement();
-						
-						boolean isIPv6 = (addr instanceof Inet6Address);
-						if (preferIPv6 == isIPv6 && perferLoopback == addr.isLoopbackAddress() ) {
-							return addr;
-						}
-					}
-				//## JDBC4.0-begin ##		
-				}
-				//## JDBC4.0-end ##
-			}
-		} catch (SocketException e) {
-			// treat this as address not found and return null;
-		}
-    	return null;
-    }
-    
-    /**
-     * Call to determine if a port is available to be opened.  
-     * This is used to determine if a port is already opened 
-     * by some other process. If the port is available, then
-     * it's not in use.   
-     * @param host
-     * @param port
-     * @return true if the port is not opened.
-     * @since 4.3
-     */
-    public boolean isPortAvailable(String host, int port) throws UnknownHostException {
-        
-        try {
-            //using Socket to try to connect to an existing opened socket
-            Socket ss = new Socket(host, port);
-            
-            try {
-                ss.close();
-            } catch (Exception ce) {
-                // it was open and considered available, then dont worry about the close error
-            }
-            return false;
-        } catch (UnknownHostException ce) {
-            throw ce;
-        } catch (IOException e) {
-        	//ignore
-        }
-        return true;
-    }
-}

Deleted: trunk/common-core/src/test/java/com/metamatrix/common/util/TestNetUtils.java
===================================================================
--- trunk/common-core/src/test/java/com/metamatrix/common/util/TestNetUtils.java	2010-04-15 15:56:33 UTC (rev 2058)
+++ trunk/common-core/src/test/java/com/metamatrix/common/util/TestNetUtils.java	2010-04-15 20:03:04 UTC (rev 2059)
@@ -1,46 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership.  Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- * 
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- * 
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- * 
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package com.metamatrix.common.util;
-
-import java.net.UnknownHostException;
-
-import junit.framework.TestCase;
-
-
-public class TestNetUtils extends TestCase {
-
-    public TestNetUtils(String name) {
-        super(name);
-    }
-   
-    public void testResolveHostName() {
-        
-        try {
-            String hostname = NetUtils.getInstance().getInetAddress().getCanonicalHostName();
-            assertNotNull(hostname, "Host name is not resolved");//$NON-NLS-1$
-        } catch (UnknownHostException err) {
-            fail("Unable to get host name"); //$NON-NLS-1$
-        }
-
-    }
-}

Modified: trunk/engine/src/main/java/org/teiid/dqp/internal/process/DQPConfiguration.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/dqp/internal/process/DQPConfiguration.java	2010-04-15 15:56:33 UTC (rev 2058)
+++ trunk/engine/src/main/java/org/teiid/dqp/internal/process/DQPConfiguration.java	2010-04-15 20:03:04 UTC (rev 2059)
@@ -38,7 +38,6 @@
     public static final int DEFAULT_MAX_PROCESS_WORKERS = 16;
 	
     
-	private String processName = "localhost"; //$NON-NLS-1$
 	private int maxThreads = DEFAULT_MAX_PROCESS_WORKERS;
 	private int timeSliceInMilli = DEFAULT_PROCESSOR_TIMESLICE;
 	private boolean processDebugAllowed;
@@ -52,15 +51,6 @@
 	private int maxResultSetCacheEntries = DQPConfiguration.DEFAULT_MAX_RESULTSET_CACHE_ENTRIES;
 	private boolean useEntitlements = false;
 	
-	@ManagementProperty (description="Name of the process that uniquely identifies this process")
-	public String getProcessName() {
-		return processName;
-	}
-
-	public void setProcessName(String processName) {
-		this.processName = processName;
-	}
-
 	@ManagementProperty(description="Process pool maximum thread count. (default 16) Increase this value if your load includes a large number of XQueries or if the system's available processors is larger than 8")
 	public int getMaxThreads() {
 		return maxThreads;

Modified: trunk/runtime/src/main/java/org/teiid/transport/SocketConfiguration.java
===================================================================
--- trunk/runtime/src/main/java/org/teiid/transport/SocketConfiguration.java	2010-04-15 15:56:33 UTC (rev 2058)
+++ trunk/runtime/src/main/java/org/teiid/transport/SocketConfiguration.java	2010-04-15 20:03:04 UTC (rev 2059)
@@ -29,11 +29,13 @@
 import org.jboss.managed.api.annotation.ManagementProperties;
 import org.jboss.managed.api.annotation.ManagementProperty;
 
-import com.metamatrix.common.util.NetUtils;
 import com.metamatrix.core.MetaMatrixRuntimeException;
 
 @ManagementObject(componentType=@ManagementComponent(type="teiid",subtype="dqp"), properties=ManagementProperties.EXPLICIT)
 public class SocketConfiguration {
+	private static final String ANY = "0.0.0.0"; //$NON-NLS-1$
+	private static final String JBOSS_SERVER_BIND_ADDRESS = "jboss.bind.address";
+	
 	private int outputBufferSize;
 	private int inputBufferSize;
 	private int maxSocketThreads;
@@ -41,12 +43,11 @@
 	private InetAddress hostAddress;
 	private SSLConfiguration sslConfiguration;
 	private boolean enabled;
-	private String hostName; 
+	private String hostName;
 	
 	
 	public void setBindAddress(String addr) {
 		this.hostName = addr;
-		this.hostAddress = resolveHostAddress(addr);
 	}
 	
 	public void setPortNumber(int port) {
@@ -69,12 +70,17 @@
 		this.sslConfiguration = value;
 	}	
  	
- 	private InetAddress resolveHostAddress(String bindAddress) {
+	private void resolveHostName() {
 		try {
-			if (bindAddress == null) {
-				return NetUtils.getInstance().getInetAddress();
+			// if host name not specified try to get it from the JBoss configuration
+			if (this.hostName == null) {
+				this.hostName = System.getProperty(JBOSS_SERVER_BIND_ADDRESS);
 			}
-			return NetUtils.resolveHostByName(bindAddress);	
+			
+			// if not defined then see if can bind to local address; if supplied resolve it by name
+			if (this.hostName == null || ANY.equals(this.hostName)) {
+				this.hostName = InetAddress.getLocalHost().getHostName();
+			}
 		} catch (UnknownHostException e) {
 			throw new MetaMatrixRuntimeException("Failed to resolve the bind address"); //$NON-NLS-1$
 		}
@@ -110,11 +116,25 @@
 	}
 
 	public InetAddress getHostAddress() {
-		return hostAddress;
+		resolveHostName();
+		if (this.hostAddress != null) {
+			return hostAddress;
+		}
+    	try {
+    		//only cache inetaddresses if they represent the ip. 
+			InetAddress addr = InetAddress.getByName(this.hostName);
+			if (addr.getHostAddress().equalsIgnoreCase(this.hostName)) {
+				this.hostAddress = addr;
+			}
+			return addr;
+		} catch (UnknownHostException e) {
+			throw new MetaMatrixRuntimeException("Failed to resolve the bind address"); //$NON-NLS-1$
+		}		
 	}
 	
 	@ManagementProperty(description="Host Name",readOnly=true)
 	public String getHostName() {
+		resolveHostName();
 		return this.hostName;
 	}
 



More information about the teiid-commits mailing list