When host name lookup fails just use the whole internet address instead of truncating to the last two octets of the IP address.

git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@5513 348d0f76-0448-11de-a6fe-93d51630548a
This commit is contained in:
kshakir 2011-03-25 18:18:22 +00:00
parent 8d8aed6a67
commit 8e67c5567c
3 changed files with 61 additions and 4 deletions

View File

@ -65,5 +65,5 @@ class QSettings {
*/
object QSettings {
/** A semi-unique job prefix using the host name and the process id. */
private val processNamePrefix = "Q-" + SystemUtils.pidAtHost.split('.')(0)
private val processNamePrefix = "Q-" + SystemUtils.pidAtHost
}

View File

@ -4,10 +4,24 @@ import java.lang.management.ManagementFactory
import java.net.InetAddress
/**
* A collection of various system utilites.
* A collection of various system utilities.
*/
object SystemUtils {
val pidAtHost = ManagementFactory.getRuntimeMXBean.getName
val inetAddress = InetAddress.getLocalHost.getHostAddress
val hostName = InetAddress.getLocalHost.getCanonicalHostName
val domainName = hostName.split('.').takeRight(2).mkString(".")
val domainName = {
if (hostName == inetAddress)
inetAddress
else
hostName.split('.').takeRight(2).mkString(".")
}
val pidAtHost = {
val mxBeanName = ManagementFactory.getRuntimeMXBean.getName
if (hostName == inetAddress)
mxBeanName
else
mxBeanName.split('.').head
}
}

View File

@ -0,0 +1,43 @@
/*
* Copyright (c) 2011, The Broad Institute
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
package org.broadinstitute.sting.queue.util
import org.testng.annotations.Test
import org.testng.Assert
class SystemUtilsUnitTest {
@Test
def testHostInfo {
val inetAddress = SystemUtils.inetAddress
val hostName = SystemUtils.hostName
val domainName = SystemUtils.domainName
if (inetAddress.split('.').takeRight(2).mkString(".") == domainName)
Assert.fail("""Invalid domain name generated:
|inetAddress: %s
|hostName: %s
|domainName: %s""".stripMargin.format(inetAddress, hostName, domainName))
}
}