You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by pa...@apache.org on 2020/08/05 11:13:33 UTC
[shardingsphere] branch master updated: Remove port from system
environment (#6645)
This is an automated email from the ASF dual-hosted git repository.
panjuan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new af4aa1a Remove port from system environment (#6645)
af4aa1a is described below
commit af4aa1abb77b9245e85938eab80451c900963d54
Author: Haoran Meng <me...@gmail.com>
AuthorDate: Wed Aug 5 19:13:24 2020 +0800
Remove port from system environment (#6645)
---
.../core/config/ConfigCenterNode.java | 5 +--
.../core/config/ConfigCenterTest.java | 5 +--
.../registry/instance/OrchestrationInstance.java | 17 +++++-----
.../shardingsphere/infra/constant/Constants.java | 36 ----------------------
.../org/apache/shardingsphere/proxy/Bootstrap.java | 2 --
.../proxy/arg/BootstrapArguments.java | 6 ++--
6 files changed, 12 insertions(+), 59 deletions(-)
diff --git a/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-config/src/main/java/org/apache/shardingsphere/orchestration/core/config/ConfigCenterNode.java b/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-config/src/main/java/org/apache/shardingsphere/orchestration/core/config/ConfigCenterNode.java
index f92f9d6..b615765 100644
--- a/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-config/src/main/java/org/apache/shardingsphere/orchestration/core/config/ConfigCenterNode.java
+++ b/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-config/src/main/java/org/apache/shardingsphere/orchestration/core/config/ConfigCenterNode.java
@@ -21,8 +21,6 @@ import com.google.common.base.Joiner;
import com.google.common.base.Splitter;
import com.google.common.base.Strings;
import lombok.RequiredArgsConstructor;
-import org.apache.shardingsphere.infra.constant.Constants;
-import org.apache.shardingsphere.orchestration.core.common.utils.IpUtils;
import java.util.ArrayList;
import java.util.Collection;
@@ -176,7 +174,6 @@ public final class ConfigCenterNode {
* @return metrics node path
*/
public String getMetricsPath() {
- String path = String.join(":", IpUtils.getIp(), System.getProperty(Constants.PORT_KEY, String.valueOf(Constants.DEFAULT_PORT)));
- return Joiner.on(PATH_SEPARATOR).join("", name, ROOT, METRICS_NODE, path);
+ return getFullPath(METRICS_NODE);
}
}
diff --git a/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-config/src/test/java/org/apache/shardingsphere/orchestration/core/config/ConfigCenterTest.java b/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-config/src/test/java/org/apache/shardingsphere/orchestration/core/config/ConfigCenterTest.java
index 50b18d7..43da0e5 100644
--- a/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-config/src/test/java/org/apache/shardingsphere/orchestration/core/config/ConfigCenterTest.java
+++ b/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-config/src/test/java/org/apache/shardingsphere/orchestration/core/config/ConfigCenterTest.java
@@ -30,14 +30,12 @@ import org.apache.shardingsphere.infra.config.DataSourceConfiguration;
import org.apache.shardingsphere.infra.config.RuleConfiguration;
import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmConfiguration;
import org.apache.shardingsphere.infra.config.properties.ConfigurationPropertyKey;
-import org.apache.shardingsphere.infra.constant.Constants;
import org.apache.shardingsphere.infra.yaml.config.YamlRootRuleConfigurations;
import org.apache.shardingsphere.infra.yaml.engine.YamlEngine;
import org.apache.shardingsphere.infra.yaml.swapper.YamlRuleConfigurationSwapperEngine;
import org.apache.shardingsphere.masterslave.api.config.MasterSlaveRuleConfiguration;
import org.apache.shardingsphere.metrics.configuration.config.MetricsConfiguration;
import org.apache.shardingsphere.orchestration.repository.api.ConfigurationRepository;
-import org.apache.shardingsphere.orchestration.core.common.utils.IpUtils;
import org.apache.shardingsphere.orchestration.core.common.yaml.config.YamlDataSourceConfiguration;
import org.apache.shardingsphere.shadow.api.config.ShadowRuleConfiguration;
import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
@@ -507,8 +505,7 @@ public final class ConfigCenterTest {
@Test
public void assertLoadMetricsConfiguration() {
- String metricsPath = "/test/config/metrics/" + IpUtils.getIp() + ":" + System.getProperty(Constants.PORT_KEY, String.valueOf(Constants.DEFAULT_PORT));
- when(configurationRepository.get(metricsPath)).thenReturn(METRICS_YAML);
+ when(configurationRepository.get("/test/config/metrics")).thenReturn(METRICS_YAML);
ConfigCenter configurationService = new ConfigCenter("test", configurationRepository);
MetricsConfiguration actual = configurationService.loadMetricsConfiguration();
assertNotNull(actual);
diff --git a/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-registry/src/main/java/org/apache/shardingsphere/orchestration/core/registry/instance/OrchestrationInstance.java b/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-registry/src/main/java/org/apache/shardingsphere/orchestration/core/registry/instance/OrchestrationInstance.java
index a97f1d4..dd6a500 100644
--- a/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-registry/src/main/java/org/apache/shardingsphere/orchestration/core/registry/instance/OrchestrationInstance.java
+++ b/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-registry/src/main/java/org/apache/shardingsphere/orchestration/core/registry/instance/OrchestrationInstance.java
@@ -17,8 +17,7 @@
package org.apache.shardingsphere.orchestration.core.registry.instance;
-import com.google.common.base.Strings;
-import org.apache.shardingsphere.infra.constant.Constants;
+import com.google.common.base.Joiner;
import org.apache.shardingsphere.orchestration.core.common.utils.IpUtils;
import java.lang.management.ManagementFactory;
@@ -30,17 +29,16 @@ import java.util.UUID;
public final class OrchestrationInstance {
private static final String DELIMITER = "@";
-
+
private static final OrchestrationInstance INSTANCE = new OrchestrationInstance();
private final String instanceId;
-
+
private OrchestrationInstance() {
- String tag = Strings.isNullOrEmpty(System.getProperty(Constants.PORT_KEY))
- ? ManagementFactory.getRuntimeMXBean().getName().split(DELIMITER)[0] : System.getProperty(Constants.PORT_KEY);
- instanceId = IpUtils.getIp() + DELIMITER + tag + DELIMITER + UUID.randomUUID().toString();
+ instanceId = Joiner.on(DELIMITER).join(IpUtils.getIp(), ManagementFactory.getRuntimeMXBean().getName().split(DELIMITER)[0],
+ UUID.randomUUID().toString());
}
-
+
/**
* Getter for instanceId.
*
@@ -49,7 +47,7 @@ public final class OrchestrationInstance {
public String getInstanceId() {
return instanceId;
}
-
+
/**
* Get instance.
*
@@ -58,5 +56,4 @@ public final class OrchestrationInstance {
public static OrchestrationInstance getInstance() {
return INSTANCE;
}
-
}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/constant/Constants.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/constant/Constants.java
deleted file mode 100644
index 5deccc9..0000000
--- a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/constant/Constants.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.infra.constant;
-
-/**
- * ShardingSphere of constants.
- */
-// TODO remove the class, ref #6546
-public final class Constants {
-
- /**
- * PORT_KEY.
- */
- public static final String PORT_KEY = "shardingsphere.port";
-
- /**
- * DEFAULT_PORT.
- */
- public static final int DEFAULT_PORT = 3307;
-}
-
diff --git a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/Bootstrap.java b/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/Bootstrap.java
index 3a03e0f..a04404f 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/Bootstrap.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/Bootstrap.java
@@ -25,7 +25,6 @@ import org.apache.shardingsphere.control.panel.spi.engine.ControlPanelFacadeEngi
import org.apache.shardingsphere.control.panel.spi.opentracing.OpenTracingConfiguration;
import org.apache.shardingsphere.db.protocol.mysql.constant.MySQLServerInfo;
import org.apache.shardingsphere.infra.config.properties.ConfigurationPropertyKey;
-import org.apache.shardingsphere.infra.constant.Constants;
import org.apache.shardingsphere.kernel.context.SchemaContexts;
import org.apache.shardingsphere.kernel.context.SchemaContextsBuilder;
import org.apache.shardingsphere.orchestration.core.facade.OrchestrationFacade;
@@ -63,7 +62,6 @@ public final class Bootstrap {
public static void main(final String[] args) throws Exception {
BootstrapArguments bootstrapArgs = new BootstrapArguments(args);
int port = bootstrapArgs.getPort();
- System.setProperty(Constants.PORT_KEY, String.valueOf(port));
YamlProxyConfiguration yamlConfig = ProxyConfigurationLoader.load(bootstrapArgs.getConfigurationPath());
if (null == yamlConfig.getServerConfiguration().getOrchestration()) {
init(new YamlProxyConfigurationSwapper().swap(yamlConfig), port, false);
diff --git a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/arg/BootstrapArguments.java b/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/arg/BootstrapArguments.java
index 798f0ed..7a97c81 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/arg/BootstrapArguments.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/arg/BootstrapArguments.java
@@ -18,7 +18,6 @@
package org.apache.shardingsphere.proxy.arg;
import lombok.Getter;
-import org.apache.shardingsphere.infra.constant.Constants;
/**
* Bootstrap arguments.
@@ -28,6 +27,8 @@ public final class BootstrapArguments {
private static final String DEFAULT_CONFIG_PATH = "/conf/";
+ private static final int DEFAULT_PORT = 3307;
+
private final int port;
private final String configurationPath;
@@ -39,8 +40,7 @@ public final class BootstrapArguments {
private int getPort(final String[] args) {
if (0 == args.length) {
- // TODO move Constants.DEFAULT_PORT to private attributes of BootstrapArguments
- return Constants.DEFAULT_PORT;
+ return DEFAULT_PORT;
}
try {
return Integer.parseInt(args[0]);