From 7277f5ed1826e3ff926e483af466c9bef16898e2 Mon Sep 17 00:00:00 2001 From: Huxing Zhang Date: Thu, 16 Aug 2018 16:55:52 +0800 Subject: [PATCH] Qos enhancement (#2153) * Not to accept foreign ip by default. * Log if fail to start qos server. #2046 * Fix typo. No functional change. * Remove redundant declaration. * Sync dubbo.xsd to compact dubbo.xsd. * Simplify code and add comments. * Add log message if qos is not enabled. * Fix UT failure. --- .../dubbo/config/ApplicationConfig.java | 3 + .../main/resources/META-INF/compat/dubbo.xsd | 353 +++++++++--------- .../src/main/resources/META-INF/dubbo.xsd | 348 ++++++++--------- .../qos/protocol/QosProtocolWrapper.java | 18 +- .../qos/protocol/QosProtocolWrapperTest.java | 6 +- .../integration/RegistryProtocol.java | 17 +- 6 files changed, 381 insertions(+), 364 deletions(-) diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ApplicationConfig.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ApplicationConfig.java index a3d46a0895f..86d40012dc8 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ApplicationConfig.java +++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ApplicationConfig.java @@ -71,10 +71,13 @@ public class ApplicationConfig extends AbstractConfig { // directory for saving thread dump private String dumpDirectory; + // whether to enable qos or not private Boolean qosEnable; + // the qos port to listen private Integer qosPort; + // should we accept foreign ip or not? private Boolean qosAcceptForeignIp; // customized parameters diff --git a/dubbo-config/dubbo-config-spring/src/main/resources/META-INF/compat/dubbo.xsd b/dubbo-config/dubbo-config-spring/src/main/resources/META-INF/compat/dubbo.xsd index 30558cc7afe..6206048311b 100644 --- a/dubbo-config/dubbo-config-spring/src/main/resources/META-INF/compat/dubbo.xsd +++ b/dubbo-config/dubbo-config-spring/src/main/resources/META-INF/compat/dubbo.xsd @@ -15,58 +15,58 @@ - + - + - + - + - + - + - + - + - + - + - + @@ -81,82 +81,82 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + @@ -169,49 +169,49 @@ - + - + - + - + - + - + - + - + - + @@ -223,86 +223,86 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + @@ -361,17 +361,17 @@ - + - + - + @@ -404,17 +404,17 @@ - + - + - + @@ -430,110 +430,110 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + @@ -544,42 +544,42 @@ - + - + - + - + - + - + - + - + @@ -597,7 +597,7 @@ - + @@ -616,54 +616,54 @@ - + - + - + - + - + - + - + - + - + - + @@ -674,17 +674,17 @@ - + - + - + @@ -698,32 +698,32 @@ - + - + - + - + - + - + @@ -750,22 +750,22 @@ - + - + - + - + @@ -784,163 +784,168 @@ - + - + - + - + - + - + + + + + + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + @@ -955,128 +960,128 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + @@ -1105,28 +1110,28 @@ - + - + - + - + - + @@ -1142,7 +1147,7 @@ - + @@ -1288,4 +1293,4 @@ - + \ No newline at end of file diff --git a/dubbo-config/dubbo-config-spring/src/main/resources/META-INF/dubbo.xsd b/dubbo-config/dubbo-config-spring/src/main/resources/META-INF/dubbo.xsd index adaa9369dfb..ecf7d7b7a5d 100644 --- a/dubbo-config/dubbo-config-spring/src/main/resources/META-INF/dubbo.xsd +++ b/dubbo-config/dubbo-config-spring/src/main/resources/META-INF/dubbo.xsd @@ -15,58 +15,58 @@ - + - + - + - + - + - + - + - + - + - + - + @@ -81,82 +81,82 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + @@ -169,49 +169,49 @@ - + - + - + - + - + - + - + - + - + @@ -223,86 +223,86 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + @@ -361,17 +361,17 @@ - + - + - + @@ -404,17 +404,17 @@ - + - + - + @@ -430,110 +430,110 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + @@ -544,42 +544,42 @@ - + - + - + - + - + - + - + - + @@ -597,7 +597,7 @@ - + @@ -616,54 +616,54 @@ - + - + - + - + - + - + - + - + - + - + @@ -674,17 +674,17 @@ - + - + - + @@ -698,32 +698,32 @@ - + - + - + - + - + - + @@ -750,22 +750,22 @@ - + - + - + - + @@ -784,168 +784,168 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + @@ -960,128 +960,128 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + @@ -1110,28 +1110,28 @@ - + - + - + - + - + @@ -1147,7 +1147,7 @@ - + diff --git a/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/protocol/QosProtocolWrapper.java b/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/protocol/QosProtocolWrapper.java index 681f5224c72..5c83ab06056 100644 --- a/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/protocol/QosProtocolWrapper.java +++ b/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/protocol/QosProtocolWrapper.java @@ -18,6 +18,9 @@ import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.URL; +import org.apache.dubbo.common.logger.Logger; +import org.apache.dubbo.common.logger.LoggerFactory; +import org.apache.dubbo.qos.common.QosConstants; import org.apache.dubbo.qos.server.Server; import org.apache.dubbo.rpc.Exporter; import org.apache.dubbo.rpc.Invoker; @@ -30,7 +33,11 @@ import static org.apache.dubbo.common.Constants.QOS_ENABLE; import static org.apache.dubbo.common.Constants.QOS_PORT; + public class QosProtocolWrapper implements Protocol { + + private final Logger logger = LoggerFactory.getLogger(QosProtocolWrapper.class); + private static AtomicBoolean hasStarted = new AtomicBoolean(false); private Protocol protocol; @@ -76,20 +83,23 @@ private void startQosServer(URL url) { } try { - boolean qosEnable = Boolean.parseBoolean(url.getParameter(QOS_ENABLE,"true")); + boolean qosEnable = url.getParameter(QOS_ENABLE,true); if (!qosEnable) { + logger.info("qos won't be started because it is disabled. " + + "Please check dubbo.application.qos.enable is configured either in system property, " + + "dubbo.properties or XML/spring-boot configuration."); return; } - int port = Integer.parseInt(url.getParameter(QOS_PORT,"22222")); - boolean acceptForeignIp = Boolean.parseBoolean(url.getParameter(ACCEPT_FOREIGN_IP,"true")); + int port = url.getParameter(QOS_PORT, QosConstants.DEFAULT_PORT); + boolean acceptForeignIp = Boolean.parseBoolean(url.getParameter(ACCEPT_FOREIGN_IP,"false")); Server server = Server.getInstance(); server.setPort(port); server.setAcceptForeignIp(acceptForeignIp); server.start(); } catch (Throwable throwable) { - //throw new RpcException("fail to start qos server", throwable); + logger.warn("Fail to start qos server: ", throwable); } } diff --git a/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/protocol/QosProtocolWrapperTest.java b/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/protocol/QosProtocolWrapperTest.java index 85851cc2413..1ac65d4c24f 100644 --- a/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/protocol/QosProtocolWrapperTest.java +++ b/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/protocol/QosProtocolWrapperTest.java @@ -42,9 +42,9 @@ public class QosProtocolWrapperTest { @Before public void setUp() throws Exception { - when(url.getParameter(Constants.QOS_ENABLE, "true")).thenReturn("true"); - when(url.getParameter(Constants.QOS_PORT, "22222")).thenReturn("12345"); - when(url.getParameter(Constants.ACCEPT_FOREIGN_IP, "true")).thenReturn("false"); + when(url.getParameter(Constants.QOS_ENABLE, true)).thenReturn(true); + when(url.getParameter(Constants.QOS_PORT, 22222)).thenReturn(12345); + when(url.getParameter(Constants.ACCEPT_FOREIGN_IP, true)).thenReturn(false); when(invoker.getUrl()).thenReturn(url); when(url.getProtocol()).thenReturn(Constants.REGISTRY_PROTOCOL); } diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryProtocol.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryProtocol.java index b1e4c3d349d..63744566ea2 100644 --- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryProtocol.java +++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryProtocol.java @@ -136,26 +136,26 @@ public Exporter export(final Invoker originInvoker) throws RpcExceptio //registry provider final Registry registry = getRegistry(originInvoker); - final URL registedProviderUrl = getRegistedProviderUrl(originInvoker); + final URL registeredProviderUrl = getRegisteredProviderUrl(originInvoker); //to judge to delay publish whether or not - boolean register = registedProviderUrl.getParameter("register", true); + boolean register = registeredProviderUrl.getParameter("register", true); - ProviderConsumerRegTable.registerProvider(originInvoker, registryUrl, registedProviderUrl); + ProviderConsumerRegTable.registerProvider(originInvoker, registryUrl, registeredProviderUrl); if (register) { - register(registryUrl, registedProviderUrl); + register(registryUrl, registeredProviderUrl); ProviderConsumerRegTable.getProviderWrapper(originInvoker).setReg(true); } // Subscribe the override data // FIXME When the provider subscribes, it will affect the scene : a certain JVM exposes the service and call the same service. Because the subscribed is cached key with the name of the service, it causes the subscription information to cover. - final URL overrideSubscribeUrl = getSubscribedOverrideUrl(registedProviderUrl); + final URL overrideSubscribeUrl = getSubscribedOverrideUrl(registeredProviderUrl); final OverrideListener overrideSubscribeListener = new OverrideListener(overrideSubscribeUrl, originInvoker); overrideListeners.put(overrideSubscribeUrl, overrideSubscribeListener); registry.subscribe(overrideSubscribeUrl, overrideSubscribeListener); //Ensure that a new exporter instance is returned every time export - return new DestroyableExporter(exporter, originInvoker, overrideSubscribeUrl, registedProviderUrl); + return new DestroyableExporter(exporter, originInvoker, overrideSubscribeUrl, registeredProviderUrl); } @SuppressWarnings("unchecked") @@ -220,10 +220,10 @@ private URL getRegistryUrl(Invoker originInvoker) { * @param originInvoker * @return */ - private URL getRegistedProviderUrl(final Invoker originInvoker) { + private URL getRegisteredProviderUrl(final Invoker originInvoker) { URL providerUrl = getProviderUrl(originInvoker); //The address you see at the registry - final URL registedProviderUrl = providerUrl.removeParameters(getFilteredKeys(providerUrl)) + return providerUrl.removeParameters(getFilteredKeys(providerUrl)) .removeParameter(Constants.MONITOR_KEY) .removeParameter(Constants.BIND_IP_KEY) .removeParameter(Constants.BIND_PORT_KEY) @@ -232,7 +232,6 @@ private URL getRegistedProviderUrl(final Invoker originInvoker) { .removeParameter(ACCEPT_FOREIGN_IP) .removeParameter(VALIDATION_KEY) .removeParameter(INTERFACES); - return registedProviderUrl; } private URL getSubscribedOverrideUrl(URL registedProviderUrl) {