From c9e8436ebf2afbd969966182de3fca988c3bc7ff Mon Sep 17 00:00:00 2001 From: Alan Davis Date: Tue, 11 Feb 2014 22:27:32 +0000 Subject: [PATCH] Merged HEAD-BUG-FIX (4.3/Cloud) to HEAD (4.3/Cloud) 57914: Merged V4.2-BUG-FIX (4.2.1) to HEAD-BUG-FIX (Cloud/4.3) 57901: Merged V4.1-BUG-FIX (4.1.8) to V4.2-BUG-FIX (4.2.1) 57891: MNT-9559: Merged DEV to V4.1-BUG-FIX 56210: MNT-9559: JMX Dump does not report Linux distribution - In JmxDumpUtil class was added updateOSNameAttributeForLinux(String) method; - Was added JmxDumpUtilTest test. 56250: MNT-9559: JMX Dump does not report Linux distribution 56340: MNT-9559: JMX Dump does not report Linux distribution git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@61907 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../alfresco/repo/management/JmxDumpUtil.java | 48 +++++++++++++++++++ .../repo/management/JmxDumpUtilTest.java | 25 ++++++++++ 2 files changed, 73 insertions(+) create mode 100644 source/test-java/org/alfresco/repo/management/JmxDumpUtilTest.java diff --git a/source/java/org/alfresco/repo/management/JmxDumpUtil.java b/source/java/org/alfresco/repo/management/JmxDumpUtil.java index a7fd066eee..92347bcb10 100644 --- a/source/java/org/alfresco/repo/management/JmxDumpUtil.java +++ b/source/java/org/alfresco/repo/management/JmxDumpUtil.java @@ -25,6 +25,7 @@ import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Comparator; import java.util.Date; +import java.util.HashMap; import java.util.Map; import java.util.Set; import java.util.TreeMap; @@ -37,6 +38,9 @@ import javax.management.MBeanServerConnection; import javax.management.ObjectName; import javax.management.openmbean.CompositeData; +import org.alfresco.util.exec.RuntimeExec; +import org.alfresco.util.exec.RuntimeExec.ExecutionResult; + /** * A utility class providing a method to dump a local or remote MBeanServer's entire object tree for support purposes. @@ -58,6 +62,8 @@ public class JmxDumpUtil /** Place holder for unreadable values. */ private static final String UNREADABLE_VALUE = ""; + private static final String OS_NAME = "os.name"; + /** * Dumps a local or remote MBeanServer's entire object tree for support purposes. Nested arrays and CompositeData * objects in MBean attribute values are handled. @@ -143,9 +149,51 @@ public class JmxDumpUtil } attributes.put(element.getName(), value); } + if (objectName.getCanonicalName().equals("Alfresco:Name=SystemProperties")) + { + String osName = (String) attributes.get(OS_NAME); + if (osName != null && osName.toLowerCase().startsWith("linux")) + { + attributes.put(OS_NAME, updateOSNameAttributeForLinux(osName)); + } + } tabulate(JmxDumpUtil.NAME_HEADER, JmxDumpUtil.VALUE_HEADER, attributes, out, 0); } + /** + * Adds a Linux version + * + * @param osName os.name attribute + * @return + */ + public static String updateOSNameAttributeForLinux(String osName) + { + RuntimeExec exec = new RuntimeExec(); + Map commandMap = new HashMap(3, 1.0f); + commandMap.put("Linux", new String[] { "lsb_release", "-d" }); + exec.setCommandsAndArguments(commandMap); + ExecutionResult ret = exec.execute(); + if (ret.getSuccess()) + { + osName += " (" + ret.getStdOut().replace("\n", "") + ")"; + } + else + { + commandMap.put("Linux", new String[] { "uname", "-a" }); + exec.setCommandsAndArguments(commandMap); + ret = exec.execute(); + if (ret.getSuccess()) + { + osName += " (" + ret.getStdOut().replace("\n", "") + ")"; + } + else + { + osName += " (Unknown)"; + } + } + return osName; + } + /** * Dumps the details of a single CompositeData object. * diff --git a/source/test-java/org/alfresco/repo/management/JmxDumpUtilTest.java b/source/test-java/org/alfresco/repo/management/JmxDumpUtilTest.java new file mode 100644 index 0000000000..a434398598 --- /dev/null +++ b/source/test-java/org/alfresco/repo/management/JmxDumpUtilTest.java @@ -0,0 +1,25 @@ +package org.alfresco.repo.management; + +import junit.framework.TestCase; + +import org.alfresco.repo.security.authentication.AuthenticationComponent; +import org.alfresco.util.ApplicationContextHelper; +import org.springframework.context.ApplicationContext; + +public class JmxDumpUtilTest extends TestCase +{ + + private static ApplicationContext ctx = ApplicationContextHelper.getApplicationContext(); + + private AuthenticationComponent authenticationComponent; + + public void testUpdateOSNameAttribute() throws Exception + { + String osName = System.getProperty("os.name"); + if (osName.toLowerCase().startsWith("linux")) + { + String attr = JmxDumpUtil.updateOSNameAttributeForLinux(osName); + assertTrue(attr.toLowerCase().startsWith("linux (")); + } + } +}