Skip to content

Commit

Permalink
Enhancement Request 36567960 - [36401456->22.06.9] ENH: Improve to re…
Browse files Browse the repository at this point in the history
…port in the log override management-http-config.xml loaded from the classpath (merge 14.1.1.2206 -> ce/22.06 @ 108926)

[git-p4: depot-paths = "//dev/coherence-ce/release/coherence-ce-v22.06/": change = 108965]
  • Loading branch information
vasac committed May 13, 2024
1 parent 3c88645 commit 4d3c69b
Show file tree
Hide file tree
Showing 10 changed files with 99 additions and 20 deletions.
@@ -1,8 +1,8 @@
/*
* Copyright (c) 2000, 2022, Oracle and/or its affiliates.
* Copyright (c) 2000, 2024, Oracle and/or its affiliates.
*
* Licensed under the Universal Permissive License v 1.0 as shown at
* http://oss.oracle.com/licenses/upl.
* https://oss.oracle.com/licenses/upl.
*/
package com.tangosol.internal.net.management;

Expand All @@ -25,6 +25,7 @@
import com.tangosol.run.xml.XmlHelper;

import com.tangosol.util.Base;
import com.tangosol.util.Resources;

import java.net.MalformedURLException;
import java.net.URL;
Expand Down Expand Up @@ -132,7 +133,7 @@ public static boolean startService(Cluster cluster)
ProxyServiceDependencies deps = null;
try
{
URL urlConfig = classLoader.getResource(MANAGEMENT_CONFIG);
URL urlConfig = Resources.findFileOrResourceOrDefault(MANAGEMENT_CONFIG, classLoader);

if (urlConfig == null)
{
Expand All @@ -141,6 +142,7 @@ public static boolean startService(Cluster cluster)
}

XmlElement xml = XmlHelper.loadXml(urlConfig);
Logger.info("Loaded management over REST configuration from \"" + urlConfig + '"');
XmlHelper.replaceSystemProperties(xml, "system-property");

//noinspection deprecation
Expand Down
@@ -1,9 +1,9 @@
<?xml version="1.0"?>
<!--
~ Copyright (c) 2000, 2022, Oracle and/or its affiliates.
~ Copyright (c) 2000, 2024, Oracle and/or its affiliates.
~
~ Licensed under the Universal Permissive License v 1.0 as shown at
~ http://oss.oracle.com/licenses/upl.
~ https://oss.oracle.com/licenses/upl.
-->
<!--
Proxy scheme configuration descriptor for the REST Management used by Coherence.
Expand Down
Expand Up @@ -4643,7 +4643,7 @@ public static void startTestCluster(Class<?> clsMain,
propsServer1.add(SystemProperty.of("test.server.name", SERVER_PREFIX + -1));
propsServer1.add(SystemProperty.of("coherence.management.http", "inherit"));
propsServer1.add(SystemProperty.of("coherence.management.readonly", Boolean.toString(isReadOnly())));
propsServer1.add(SystemProperty.of("coherence.management.http.port", 0));
propsServer1.add(SystemProperty.of("coherence.management.http.override-port", 0));
propsServer1.add(SystemProperty.of("coherence.management.http.cluster", sClusterName));
propsServer1.add(SystemProperty.of("coherence.override", "tangosol-coherence-override-mgmt.xml"));
propsServer1.add(SystemProperty.of("test.persistence.active.dir", m_dirActive.getAbsolutePath()));
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2022, Oracle and/or its affiliates.
* Copyright (c) 2000, 2024, Oracle and/or its affiliates.
*
* Licensed under the Universal Permissive License v 1.0 as shown at
* https://oss.oracle.com/licenses/upl.
Expand Down Expand Up @@ -67,7 +67,7 @@ public static void _startup()
propsServer1.setProperty("coherence.management.extendedmbeanname", "true");
propsServer1.setProperty("coherence.member", SERVER_PREFIX + "-1");
propsServer1.setProperty("coherence.management.http", "inherit");
propsServer1.setProperty("coherence.management.http.port", "0");
propsServer1.setProperty("coherence.management.http.override-port", "0");
propsServer1.setProperty("coherence.override", "tangosol-coherence-override-mgmt.xml");

CoherenceClusterMember member1 = startCacheServer(SERVER_PREFIX + "-1", "rest",
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2022, Oracle and/or its affiliates.
* Copyright (c) 2000, 2024, Oracle and/or its affiliates.
*
* Licensed under the Universal Permissive License v 1.0 as shown at
* https://oss.oracle.com/licenses/upl.
Expand Down Expand Up @@ -58,7 +58,7 @@ public static void setup() throws Exception
System.setProperty("coherence.cluster", "Test");
System.setProperty("coherence.member", "Storage");
System.setProperty("coherence.management.http", "all");
System.setProperty("coherence.management.http.port", String.valueOf(ports.next()));
System.setProperty("coherence.management.http.override-port", String.valueOf(ports.next()));
System.setProperty("coherence.management.extendedmbeanname", "true");
System.setProperty("coherence.management.port", String.valueOf(ports.next()));

Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2022, Oracle and/or its affiliates.
* Copyright (c) 2000, 2024, Oracle and/or its affiliates.
*
* Licensed under the Universal Permissive License v 1.0 as shown at
* https://oss.oracle.com/licenses/upl.
Expand Down Expand Up @@ -80,7 +80,7 @@ public void shouldStartManagement() throws Exception
SystemProperty.of("coherence.cluster", "Storage"),
SystemProperty.of("coherence.management.extendedmbeanname", true),
SystemProperty.of("coherence.management.http", "inherit"),
SystemProperty.of("coherence.management.http.port", port),
SystemProperty.of("coherence.management.http.override-port", port),
f_testLogs))
{
URI uri = URI.create("http://localhost:" + port.get() + "/management/coherence/cluster");
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2022, Oracle and/or its affiliates.
* Copyright (c) 2000, 2024, Oracle and/or its affiliates.
*
* Licensed under the Universal Permissive License v 1.0 as shown at
* https://oss.oracle.com/licenses/upl.
Expand All @@ -18,6 +18,7 @@

import com.tangosol.net.CacheFactory;
import com.tangosol.net.NamedCache;
import com.tangosol.net.management.MBeanHelper;

import com.oracle.coherence.testing.AbstractFunctionalTest;

Expand All @@ -36,6 +37,14 @@
import java.util.Objects;
import java.util.Properties;

import javax.management.AttributeNotFoundException;
import javax.management.InstanceNotFoundException;
import javax.management.MBeanException;
import javax.management.MBeanServer;
import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;
import javax.management.ReflectionException;

import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.WebTarget;
Expand All @@ -49,6 +58,7 @@
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;

Expand Down Expand Up @@ -158,7 +168,7 @@ public void validateRunningOnConfiguredManagementPort()

propServer.put("coherence.management", "all");
propServer.put("coherence.management.http", "all");
propServer.put("coherence.management.http.port", Integer.toString(nMgmtPort));
propServer.put("coherence.management.http.override-port", Integer.toString(nMgmtPort));

try (CoherenceClusterMember member = startCacheServer(SERVER_MEMBERNAME, PROJECT_NAME, null, propServer, true))
{
Expand Down Expand Up @@ -187,7 +197,7 @@ public void testDetectionOfManagementPortConflicts()
propServer.put("coherence.management.http", "all");

// harden this test to not used a fixed port, intermittently the port was in use by another process.
propServer.put("coherence.management.http.port", "0");
propServer.put("coherence.management.http.override-port", "0");

try (CoherenceClusterMember member1 = startCacheServer(SERVER_MEMBERNAME_PREFIX + "-1", PROJECT_NAME, null, propServer, true))
{
Expand All @@ -201,7 +211,7 @@ public void testDetectionOfManagementPortConflicts()

// simulate user not setting coherence.management.port at all and using "coherence.management" set to all.
// ensure collision on port that is already in use. Make sure log message reports the port conflicted on.
propServer.put("coherence.management.http.port", Integer.toString(nPortMgmt));
propServer.put("coherence.management.http.override-port", Integer.toString(nPortMgmt));
try (CoherenceClusterMember member2 = startCacheServer(SERVER_MEMBERNAME_PREFIX + "-2", PROJECT_NAME, null, propServer, true))
{
File fileMember2Log = new File(ensureOutputDir(PROJECT_NAME), SERVER_MEMBERNAME_PREFIX + "-2.out");
Expand All @@ -213,6 +223,35 @@ public void testDetectionOfManagementPortConflicts()
}
}

@Test
public void testConfigurationOverride()
throws MalformedObjectNameException, ReflectionException,
InstanceNotFoundException, AttributeNotFoundException,
MBeanException
{
String port = "44444";
System.setProperty("coherence.management", "all");
System.setProperty("coherence.management.http", "inherit");
System.setProperty("coherence.management.remote", "true");
System.setProperty("coherence.management.http.override-port", port);
try
{
AbstractFunctionalTest._startup();
MBeanServer serverJMX = MBeanHelper.findMBeanServer();
String attr = (String) serverJMX.getAttribute(new ObjectName("Coherence:type=ConnectionManager,name=ManagementHttpProxy,nodeId=1"), "HostIP");
assertNotNull(attr);
assertTrue("Management HTTP port", attr.endsWith(":" + port));
}
finally
{
AbstractFunctionalTest._shutdown();
System.clearProperty("coherence.management");
System.clearProperty("coherence.management.http");
System.clearProperty("coherence.management.remote");
System.clearProperty("coherence.management.http.override-port");
}
}

// ----- helper methods -------------------------------------------------

/**
Expand All @@ -231,7 +270,7 @@ protected void testCase(String sMgmt, String sHttpMgmt, int nExpected)
Properties propServer = new Properties();

propServer.setProperty("coherence.management", sMgmt);
propServer.setProperty("coherence.management.http.port", "0");
propServer.setProperty("coherence.management.http.override-port", "0");

if (sHttpMgmt != null)
{
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2022, Oracle and/or its affiliates.
* Copyright (c) 2000, 2024, Oracle and/or its affiliates.
*
* Licensed under the Universal Permissive License v 1.0 as shown at
* https://oss.oracle.com/licenses/upl.
Expand Down Expand Up @@ -62,7 +62,7 @@ public static void _startup()
propsServer1.setProperty("coherence.management.extendedmbeanname", "true");
propsServer1.setProperty("coherence.member", SERVER_PREFIX + "-1");
propsServer1.setProperty("coherence.management.http", "inherit");
propsServer1.setProperty("coherence.management.http.port", "0");
propsServer1.setProperty("coherence.management.http.override-port", "0");
propsServer1.setProperty("coherence.override", "tangosol-coherence-override-mgmt.xml");

CoherenceClusterMember member1 = startCacheServer(SERVER_PREFIX + "-1", "rest",
Expand Down
Expand Up @@ -434,7 +434,7 @@ public static void startTestCluster(Class<?> clsMain,
propsServer1.add(SystemProperty.of("test.server.name", SERVER_PREFIX + -1));
propsServer1.add(SystemProperty.of("coherence.management.http", "inherit"));
propsServer1.add(SystemProperty.of("coherence.management.readonly", Boolean.toString(isReadOnly())));
propsServer1.add(SystemProperty.of("coherence.management.http.port", 0));
propsServer1.add(SystemProperty.of("coherence.management.http.override-port", 0));
propsServer1.add(SystemProperty.of("coherence.management.http.cluster", sClusterName));
propsServer1.add(SystemProperty.of("coherence.override", "tangosol-coherence-override-mgmt.xml"));
propsServer1.add(SystemProperty.of("test.persistence.active.dir", m_dirActive.getAbsolutePath()));
Expand Down
@@ -0,0 +1,38 @@
<?xml version="1.0"?>
<!--
~ Copyright (c) 2000, 2024, Oracle and/or its affiliates.
~
~ Licensed under the Universal Permissive License v 1.0 as shown at
~ https://oss.oracle.com/licenses/upl.
-->
<!--
Proxy scheme configuration descriptor for the REST Management used by Coherence.
-->
<proxy-scheme>
<!-- NOTE: this service name MUST match the name in the HttpHelper MANAGEMENT_SERVICE_NAME constant -->
<service-name>ManagementHttpProxy</service-name>
<acceptor-config>
<http-acceptor>
<class-name>com.tangosol.coherence.http.JavaHttpServer</class-name>
<init-params>
<init-param>
<param-name>back-size-limit</param-name>
<param-value>8MB</param-value>
</init-param>
</init-params>
<socket-provider system-property="coherence.management.http.provider"/>
<local-address>
<address system-property="coherence.management.http.address"/>
<port system-property="coherence.management.http.override-port">30000</port>
</local-address>
<resource-config>
<context-path>/</context-path>
<instance>
<class-factory-name>com.tangosol.internal.management.ManagementHttpHandler</class-factory-name>
<method-name>getInstance</method-name>
</instance>
</resource-config>
<auth-method system-property="coherence.management.http.auth"/>
</http-acceptor>
</acceptor-config>
</proxy-scheme>

0 comments on commit 4d3c69b

Please sign in to comment.