# HG changeset patch # User jbachorik # Date 1447422245 -3600 # Node ID 83f41bd1c3c896f618e7c8f7fd1380ecfe2a9743 # Parent 4f2243ba7257e90331db43fef5d997bb0fa87fed 8142398: ManagementAgent.status diagnostic command only outputs the specifically set properties Reviewed-by: sla diff -r 4f2243ba7257 -r 83f41bd1c3c8 jdk/src/java.management/share/classes/sun/management/Agent.java --- a/jdk/src/java.management/share/classes/sun/management/Agent.java Fri Dec 11 11:46:45 2015 +0100 +++ b/jdk/src/java.management/share/classes/sun/management/Agent.java Fri Nov 13 14:44:05 2015 +0100 @@ -37,9 +37,13 @@ import java.net.MalformedURLException; import java.net.UnknownHostException; import java.text.MessageFormat; +import java.util.HashMap; +import java.util.Map; import java.util.MissingResourceException; import java.util.Properties; import java.util.ResourceBundle; +import java.util.function.Function; +import java.util.function.Predicate; import javax.management.remote.JMXConnectorServer; import javax.management.remote.JMXServiceURL; @@ -60,6 +64,30 @@ * Agent status collector strategy class */ private static abstract class StatusCollector { + protected static final Map DEFAULT_PROPS = new HashMap<>(); + + static { + DEFAULT_PROPS.put(ConnectorBootstrap.PropertyNames.PORT, + ConnectorBootstrap.DefaultValues.PORT); + DEFAULT_PROPS.put(ConnectorBootstrap.PropertyNames.USE_LOCAL_ONLY, + ConnectorBootstrap.DefaultValues.USE_LOCAL_ONLY); + DEFAULT_PROPS.put(ConnectorBootstrap.PropertyNames.USE_AUTHENTICATION, + ConnectorBootstrap.DefaultValues.USE_AUTHENTICATION); + DEFAULT_PROPS.put(ConnectorBootstrap.PropertyNames.USE_SSL, + ConnectorBootstrap.DefaultValues.USE_SSL); + DEFAULT_PROPS.put(ConnectorBootstrap.PropertyNames.USE_REGISTRY_SSL, + ConnectorBootstrap.DefaultValues.USE_REGISTRY_SSL); + DEFAULT_PROPS.put(ConnectorBootstrap.PropertyNames.SSL_NEED_CLIENT_AUTH, + ConnectorBootstrap.DefaultValues.SSL_NEED_CLIENT_AUTH); + DEFAULT_PROPS.put(ConnectorBootstrap.PropertyNames.CONFIG_FILE_NAME, + ConnectorBootstrap.DefaultValues.CONFIG_FILE_NAME); + DEFAULT_PROPS.put(ConnectorBootstrap.PropertyNames.PASSWORD_FILE_NAME, + ConnectorBootstrap.DefaultValues.PASSWORD_FILE_NAME); + DEFAULT_PROPS.put(ConnectorBootstrap.PropertyNames.ACCESS_FILE_NAME, + ConnectorBootstrap.DefaultValues.ACCESS_FILE_NAME); + + } + final protected StringBuilder sb = new StringBuilder(); final public String collect() { Properties agentProps = VMSupport.getAgentProperties(); @@ -93,28 +121,49 @@ private void addConnection(boolean remote, JMXServiceURL u) { appendConnectionHeader(remote); addConnectionDetails(u); - if (remote) { - addConfigProperties(); - } + addConfigProperties(); appendConnectionFooter(remote); } private void addConfigProperties() { appendConfigPropsHeader(); - boolean[] first = new boolean[] {true}; - Properties props = configProps != null ? - configProps : getManagementProperties(); + + Properties remoteProps = configProps != null ? + configProps : getManagementProperties(); + Map props = new HashMap<>(DEFAULT_PROPS); + + if (remoteProps == null) { + // local connector only + String loc_only = System.getProperty( + ConnectorBootstrap.PropertyNames.USE_LOCAL_ONLY + ); - props.entrySet().stream().forEach((e) -> { - String key = (String)e.getKey(); - if (key.startsWith("com.sun.management.")) { - addConfigProp(key, e.getValue(), first[0]); - first[0] = false; + if (loc_only != null && + !ConnectorBootstrap.DefaultValues.USE_LOCAL_ONLY.equals(loc_only)) { + props.put( + ConnectorBootstrap.PropertyNames.USE_LOCAL_ONLY, + loc_only + ); } - }); + } else { + props.putAll(remoteProps); + } + + props.entrySet().stream() + .filter(preprocess(Map.Entry::getKey, StatusCollector::isManagementProp)) + .forEach(this::addConfigProp); + appendConfigPropsFooter(); } + private static boolean isManagementProp(Object pName) { + return pName != null && pName.toString().startsWith("com.sun.management."); + } + + private static Predicate preprocess(Function f, Predicate p) { + return (T t) -> p.test(f.apply(t)); + } + abstract protected void addAgentStatus(boolean enabled); abstract protected void appendConnectionsHeader(); abstract protected void appendConnectionsFooter(); @@ -123,7 +172,7 @@ abstract protected void appendConnectionFooter(boolean remote); abstract protected void appendConfigPropsHeader(); abstract protected void appendConfigPropsFooter(); - abstract protected void addConfigProp(String key, Object value, boolean first); + abstract protected void addConfigProp(Map.Entry prop); } /** @@ -159,11 +208,14 @@ } @Override - protected void addConfigProp(String key, Object value, boolean first) { - if (!first) { - sb.append('\n'); + protected void addConfigProp(Map.Entry prop) { + sb.append(" ").append(prop.getKey()).append(" = ") + .append(prop.getValue()); + Object defVal = DEFAULT_PROPS.get(prop.getKey()); + if (defVal != null && defVal.equals(prop.getValue())) { + sb.append(" [default]"); } - sb.append(" ").append(key).append(" = ").append(value); + sb.append("\n"); } @Override diff -r 4f2243ba7257 -r 83f41bd1c3c8 jdk/test/sun/management/jmxremote/startstop/JMXStatusTest.java --- a/jdk/test/sun/management/jmxremote/startstop/JMXStatusTest.java Fri Dec 11 11:46:45 2015 +0100 +++ b/jdk/test/sun/management/jmxremote/startstop/JMXStatusTest.java Fri Nov 13 14:44:05 2015 +0100 @@ -33,7 +33,7 @@ /** * @test - * @bug 8023093 8138748 + * @bug 8023093 8138748 8142398 * @summary Performs a sanity test for the ManagementAgent.status diagnostic command. * Management agent may be disabled, started (only local connections) and started. * The test asserts that the expected text is being printed. @@ -56,7 +56,8 @@ "Connection Type\\s*\\:\\s*local\\n+" + "Protocol\\s*\\:\\s*[a-z]+\\n+" + "Host\\s*\\:\\s*.+\\n+" + - "URL\\s*\\:\\s*service\\:jmx\\:.+", + "URL\\s*\\:\\s*service\\:jmx\\:.+\\n+" + + "Properties\\s*\\:\\n+(\\s*\\S+\\s*=\\s*\\S+(\\s+\\[default\\])?\\n*)+", Pattern.MULTILINE ); @@ -67,7 +68,7 @@ "Protocol\\s*\\: [a-z]+\\n+" + "Host\\s*\\: .+\\n+" + "URL\\s*\\: service\\:jmx\\:.+\\n+" + - "Properties\\s*\\:\\n+(\\s*\\S+\\s*=\\s*\\S+\\n*)+", + "Properties\\s*\\:\\n+(\\s*\\S+\\s*=\\s*\\S+(\\s+\\[default\\])?\\n*)+", Pattern.MULTILINE | Pattern.DOTALL );