diff --git a/scala/src/org/broadinstitute/sting/queue/QSettings.scala b/scala/src/org/broadinstitute/sting/queue/QSettings.scala index 687ea8b0b..e001f8665 100644 --- a/scala/src/org/broadinstitute/sting/queue/QSettings.scala +++ b/scala/src/org/broadinstitute/sting/queue/QSettings.scala @@ -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 } diff --git a/scala/src/org/broadinstitute/sting/queue/util/SystemUtils.scala b/scala/src/org/broadinstitute/sting/queue/util/SystemUtils.scala index b4cd22909..fb13f6ebb 100644 --- a/scala/src/org/broadinstitute/sting/queue/util/SystemUtils.scala +++ b/scala/src/org/broadinstitute/sting/queue/util/SystemUtils.scala @@ -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 + } } diff --git a/scala/test/org/broadinstitute/sting/queue/util/SystemUtilsUnitTest.scala b/scala/test/org/broadinstitute/sting/queue/util/SystemUtilsUnitTest.scala new file mode 100644 index 000000000..cafb1994d --- /dev/null +++ b/scala/test/org/broadinstitute/sting/queue/util/SystemUtilsUnitTest.scala @@ -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)) + } +}