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 2022/07/01 11:17:15 UTC
[shardingsphere] branch master updated: Add JDBCInstanceDefinition and ProxyInstanceDefinition (#18773)
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 8741ac3e552 Add JDBCInstanceDefinition and ProxyInstanceDefinition (#18773)
8741ac3e552 is described below
commit 8741ac3e55247690e62899ae6a4702e78bbe173e
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Fri Jul 1 19:17:08 2022 +0800
Add JDBCInstanceDefinition and ProxyInstanceDefinition (#18773)
---
.../infra/instance/InstanceContext.java | 5 +-
.../instance/definition/InstanceDefinition.java | 60 ++++++++--------------
.../definition/InstanceDefinitionBuilder.java | 9 ----
.../InstanceDefinitionBuilderFactory.java | 25 ---------
...nceDefinitionBuilder.java => InstanceType.java} | 25 ++-------
.../definition/jdbc/JDBCInstanceDefinition.java | 30 +++++++----
.../jdbc}/JDBCInstanceDefinitionBuilder.java | 9 +---
.../ProxyInstanceDefinition.java} | 44 ++++++----------
.../proxy}/ProxyInstanceDefinitionBuilder.java | 9 +---
...a.instance.definition.InstanceDefinitionBuilder | 3 +-
.../jdbc}/JDBCInstanceDefinitionBuilderTest.java | 16 ++----
.../proxy}/ProxyInstanceDefinitionBuilderTest.java | 18 ++-----
.../jdbc/core/connection/ConnectionManager.java | 10 ++--
...a.instance.definition.InstanceDefinitionBuilder | 18 -------
.../core/connection/ConnectionManagerTest.java | 7 +--
.../traffic/engine/TrafficEngine.java | 3 +-
.../algorithm/engine/TrafficEngineTest.java | 10 ++--
.../RandomTrafficLoadBalanceAlgorithmTest.java | 3 +-
.../RoundRobinTrafficLoadBalanceAlgorithmTest.java | 5 +-
.../mode/metadata/persist/node/ComputeNode.java | 10 ++--
.../metadata/persist/node/ComputeNodeTest.java | 9 ++--
.../cluster/ClusterContextManagerBuilder.java | 3 +-
.../subscriber/ProcessRegistrySubscriber.java | 5 +-
.../compute/service/ComputeNodeStatusService.java | 19 ++++---
.../watcher/ComputeNodeStateChangedWatcher.java | 10 +++-
.../ClusterContextManagerCoordinatorTest.java | 9 ++--
.../lock/DistributedLockContextTest.java | 10 ++--
.../subscriber/ProcessRegistrySubscriberTest.java | 3 +-
.../service/ComputeNodeStatusServiceTest.java | 28 +++++-----
.../StandaloneContextManagerBuilder.java | 3 +-
.../StandaloneContextManagerBuilderTextTest.java | 4 +-
.../ral/common/queryable/ShowInstanceHandler.java | 11 ++--
...a.instance.definition.InstanceDefinitionBuilder | 18 -------
33 files changed, 176 insertions(+), 275 deletions(-)
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/instance/InstanceContext.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/instance/InstanceContext.java
index ab099c167ce..b66be41676a 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/instance/InstanceContext.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/instance/InstanceContext.java
@@ -20,6 +20,7 @@ package org.apache.shardingsphere.infra.instance;
import lombok.Getter;
import org.apache.shardingsphere.infra.config.mode.ModeConfiguration;
import org.apache.shardingsphere.infra.instance.definition.InstanceDefinition;
+import org.apache.shardingsphere.infra.instance.definition.InstanceType;
import org.apache.shardingsphere.infra.instance.workerid.WorkerIdGenerator;
import org.apache.shardingsphere.infra.lock.LockContext;
@@ -139,10 +140,10 @@ public final class InstanceContext {
* @param labels collection of contained label
* @return compute node instances
*/
- public List<InstanceDefinition> getComputeNodeInstances(final String instanceType, final Collection<String> labels) {
+ public List<InstanceDefinition> getComputeNodeInstances(final InstanceType instanceType, final Collection<String> labels) {
List<InstanceDefinition> result = new ArrayList<>(computeNodeInstances.size());
for (ComputeNodeInstance each : computeNodeInstances) {
- if (each.getInstanceDefinition().getInstanceType().equals(instanceType) && labels.stream().anyMatch(((Collection<String>) each.getLabels())::contains)) {
+ if (each.getInstanceDefinition().getInstanceType() == instanceType && labels.stream().anyMatch(((Collection<String>) each.getLabels())::contains)) {
result.add(each.getInstanceDefinition());
}
}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/instance/definition/InstanceDefinition.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/instance/definition/InstanceDefinition.java
index 6ea2bf73c9c..142d919a6a2 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/instance/definition/InstanceDefinition.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/instance/definition/InstanceDefinition.java
@@ -17,56 +17,36 @@
package org.apache.shardingsphere.infra.instance.definition;
-import com.google.common.base.Joiner;
-import com.google.common.base.Splitter;
-import com.google.common.base.Strings;
-import lombok.Getter;
-import org.apache.shardingsphere.infra.instance.utils.IpUtils;
-
-import java.util.List;
-
/**
* Instance definition.
*/
-@Getter
-public final class InstanceDefinition {
-
- private static final String DELIMITER = "@";
-
- private final String instanceId;
+public interface InstanceDefinition {
- private final String instanceType;
-
- private final String ip;
-
- private final int port;
+ /**
+ * Get instance ID.
+ *
+ * @return instance ID
+ */
+ String getInstanceId();
- public InstanceDefinition(final String instanceId, final String instanceType, final int port) {
- this.instanceId = instanceId;
- this.instanceType = instanceType;
- ip = IpUtils.getIp();
- this.port = port;
- }
+ /**
+ * Get instance type.
+ *
+ * @return instance type
+ */
+ InstanceType getInstanceType();
- public InstanceDefinition(final String instanceId, final String instanceType, final String attributes) {
- this.instanceId = instanceId;
- this.instanceType = instanceType;
- if (!Strings.isNullOrEmpty(attributes) && attributes.contains(DELIMITER)) {
- List<String> attributesList = Splitter.on(DELIMITER).splitToList(attributes);
- ip = attributesList.get(0);
- port = Integer.parseInt(attributesList.get(1));
- } else {
- ip = IpUtils.getIp();
- port = -1;
- }
- }
+ /**
+ * Get IP.
+ *
+ * @return IP
+ */
+ String getIp();
/**
* Get attributes.
*
* @return attributes
*/
- public String getAttributes() {
- return -1 == port ? "" : Joiner.on(DELIMITER).join(ip, port);
- }
+ String getAttributes();
}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/instance/definition/InstanceDefinitionBuilder.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/instance/definition/InstanceDefinitionBuilder.java
index 43be5672c7b..139c0be1439 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/instance/definition/InstanceDefinitionBuilder.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/instance/definition/InstanceDefinitionBuilder.java
@@ -33,13 +33,4 @@ public interface InstanceDefinitionBuilder extends TypedSPI {
* @return built instance definition
*/
InstanceDefinition build(int port);
-
- /**
- * Build instance definition.
- *
- * @param instanceId instance ID
- * @param attributes attributes
- * @return built instance definition
- */
- InstanceDefinition build(String instanceId, String attributes);
}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/instance/definition/InstanceDefinitionBuilderFactory.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/instance/definition/InstanceDefinitionBuilderFactory.java
index 43c2f109e97..b6c0aaf0d5b 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/instance/definition/InstanceDefinitionBuilderFactory.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/instance/definition/InstanceDefinitionBuilderFactory.java
@@ -20,12 +20,8 @@ package org.apache.shardingsphere.infra.instance.definition;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.apache.shardingsphere.spi.ShardingSphereServiceLoader;
-import org.apache.shardingsphere.spi.type.typed.TypedSPI;
import org.apache.shardingsphere.spi.type.typed.TypedSPIRegistry;
-import java.util.Collection;
-import java.util.stream.Collectors;
-
/**
* Instance definition builder factory.
*/
@@ -46,25 +42,4 @@ public final class InstanceDefinitionBuilderFactory {
public static InstanceDefinition newInstance(final String type, final int port) {
return TypedSPIRegistry.getRegisteredService(InstanceDefinitionBuilder.class, type).build(port);
}
-
- /**
- * Create instance of instance definition.
- *
- * @param type type
- * @param instanceId instance ID
- * @param attributes attributes
- * @return created instance of instance definition
- */
- public static InstanceDefinition newInstance(final String type, final String instanceId, final String attributes) {
- return TypedSPIRegistry.getRegisteredService(InstanceDefinitionBuilder.class, type).build(instanceId, attributes);
- }
-
- /**
- * Get all builder types.
- *
- * @return got all builder types
- */
- public static Collection<String> getAllTypes() {
- return ShardingSphereServiceLoader.getServiceInstances(InstanceDefinitionBuilder.class).stream().map(TypedSPI::getType).collect(Collectors.toList());
- }
}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/instance/definition/InstanceDefinitionBuilder.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/instance/definition/InstanceType.java
similarity index 58%
copy from shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/instance/definition/InstanceDefinitionBuilder.java
copy to shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/instance/definition/InstanceType.java
index 43be5672c7b..8e8ccd018c7 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/instance/definition/InstanceDefinitionBuilder.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/instance/definition/InstanceType.java
@@ -17,29 +17,10 @@
package org.apache.shardingsphere.infra.instance.definition;
-import org.apache.shardingsphere.spi.annotation.SingletonSPI;
-import org.apache.shardingsphere.spi.type.typed.TypedSPI;
-
/**
- * Instance definition builder.
+ * Instance type.
*/
-@SingletonSPI
-public interface InstanceDefinitionBuilder extends TypedSPI {
-
- /**
- * Build instance definition.
- *
- * @param port port
- * @return built instance definition
- */
- InstanceDefinition build(int port);
+public enum InstanceType {
- /**
- * Build instance definition.
- *
- * @param instanceId instance ID
- * @param attributes attributes
- * @return built instance definition
- */
- InstanceDefinition build(String instanceId, String attributes);
+ JDBC, PROXY
}
diff --git a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/fixture/InstanceDefinitionBuilderFixture.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/instance/definition/jdbc/JDBCInstanceDefinition.java
similarity index 62%
rename from shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/fixture/InstanceDefinitionBuilderFixture.java
rename to shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/instance/definition/jdbc/JDBCInstanceDefinition.java
index 1a1b1280000..4c8cd5999d8 100644
--- a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/fixture/InstanceDefinitionBuilderFixture.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/instance/definition/jdbc/JDBCInstanceDefinition.java
@@ -15,25 +15,35 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.mode.manager.cluster.coordinator.fixture;
+package org.apache.shardingsphere.infra.instance.definition.jdbc;
+import lombok.Getter;
import org.apache.shardingsphere.infra.instance.definition.InstanceDefinition;
-import org.apache.shardingsphere.infra.instance.definition.InstanceDefinitionBuilder;
+import org.apache.shardingsphere.infra.instance.definition.InstanceType;
+import org.apache.shardingsphere.infra.instance.utils.IpUtils;
-public final class InstanceDefinitionBuilderFixture implements InstanceDefinitionBuilder {
+/**
+ * JDBC instance definition.
+ */
+@Getter
+public final class JDBCInstanceDefinition implements InstanceDefinition {
- @Override
- public InstanceDefinition build(final int port) {
- return new InstanceDefinition("1", getType(), port);
+ private final String instanceId;
+
+ private final String ip;
+
+ public JDBCInstanceDefinition(final String instanceId) {
+ this.instanceId = instanceId;
+ ip = IpUtils.getIp();
}
@Override
- public InstanceDefinition build(final String instanceId, final String attributes) {
- return new InstanceDefinition(instanceId, getType(), attributes);
+ public InstanceType getInstanceType() {
+ return InstanceType.JDBC;
}
@Override
- public String getType() {
- return "FIXTURE";
+ public String getAttributes() {
+ return "";
}
}
diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/instance/JDBCInstanceDefinitionBuilder.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/instance/definition/jdbc/JDBCInstanceDefinitionBuilder.java
similarity index 79%
rename from shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/instance/JDBCInstanceDefinitionBuilder.java
rename to shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/instance/definition/jdbc/JDBCInstanceDefinitionBuilder.java
index 95ab27f065c..e8c55f909d0 100644
--- a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/instance/JDBCInstanceDefinitionBuilder.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/instance/definition/jdbc/JDBCInstanceDefinitionBuilder.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.driver.instance;
+package org.apache.shardingsphere.infra.instance.definition.jdbc;
import org.apache.shardingsphere.infra.instance.definition.InstanceDefinition;
import org.apache.shardingsphere.infra.instance.definition.InstanceDefinitionBuilder;
@@ -29,12 +29,7 @@ public final class JDBCInstanceDefinitionBuilder implements InstanceDefinitionBu
@Override
public InstanceDefinition build(final int port) {
- return new InstanceDefinition(UUID.randomUUID().toString(), getType(), -1);
- }
-
- @Override
- public InstanceDefinition build(final String instanceId, final String attributes) {
- return new InstanceDefinition(instanceId, getType(), attributes);
+ return new JDBCInstanceDefinition(UUID.randomUUID().toString());
}
@Override
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/instance/definition/InstanceDefinition.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/instance/definition/proxy/ProxyInstanceDefinition.java
similarity index 55%
copy from shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/instance/definition/InstanceDefinition.java
copy to shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/instance/definition/proxy/ProxyInstanceDefinition.java
index 6ea2bf73c9c..3aa2fbfe0db 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/instance/definition/InstanceDefinition.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/instance/definition/proxy/ProxyInstanceDefinition.java
@@ -15,58 +15,48 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.infra.instance.definition;
+package org.apache.shardingsphere.infra.instance.definition.proxy;
import com.google.common.base.Joiner;
-import com.google.common.base.Splitter;
-import com.google.common.base.Strings;
import lombok.Getter;
+import org.apache.shardingsphere.infra.instance.definition.InstanceDefinition;
+import org.apache.shardingsphere.infra.instance.definition.InstanceType;
import org.apache.shardingsphere.infra.instance.utils.IpUtils;
-import java.util.List;
-
/**
- * Instance definition.
+ * Proxy instance definition.
*/
@Getter
-public final class InstanceDefinition {
+public final class ProxyInstanceDefinition implements InstanceDefinition {
private static final String DELIMITER = "@";
private final String instanceId;
- private final String instanceType;
-
private final String ip;
private final int port;
- public InstanceDefinition(final String instanceId, final String instanceType, final int port) {
+ public ProxyInstanceDefinition(final String instanceId, final int port) {
this.instanceId = instanceId;
- this.instanceType = instanceType;
ip = IpUtils.getIp();
this.port = port;
}
- public InstanceDefinition(final String instanceId, final String instanceType, final String attributes) {
+ public ProxyInstanceDefinition(final String instanceId, final String attributes) {
this.instanceId = instanceId;
- this.instanceType = instanceType;
- if (!Strings.isNullOrEmpty(attributes) && attributes.contains(DELIMITER)) {
- List<String> attributesList = Splitter.on(DELIMITER).splitToList(attributes);
- ip = attributesList.get(0);
- port = Integer.parseInt(attributesList.get(1));
- } else {
- ip = IpUtils.getIp();
- port = -1;
- }
+ String[] attributesList = attributes.split(DELIMITER);
+ ip = attributesList[0];
+ port = Integer.parseInt(attributesList[1]);
+ }
+
+ @Override
+ public InstanceType getInstanceType() {
+ return InstanceType.PROXY;
}
- /**
- * Get attributes.
- *
- * @return attributes
- */
+ @Override
public String getAttributes() {
- return -1 == port ? "" : Joiner.on(DELIMITER).join(ip, port);
+ return Joiner.on(DELIMITER).join(ip, port);
}
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/instance/ProxyInstanceDefinitionBuilder.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/instance/definition/proxy/ProxyInstanceDefinitionBuilder.java
similarity index 79%
rename from shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/instance/ProxyInstanceDefinitionBuilder.java
rename to shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/instance/definition/proxy/ProxyInstanceDefinitionBuilder.java
index 2beb6a17514..b7ea55dc5ef 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/instance/ProxyInstanceDefinitionBuilder.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/instance/definition/proxy/ProxyInstanceDefinitionBuilder.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.proxy.instance;
+package org.apache.shardingsphere.infra.instance.definition.proxy;
import org.apache.shardingsphere.infra.instance.definition.InstanceDefinition;
import org.apache.shardingsphere.infra.instance.definition.InstanceDefinitionBuilder;
@@ -29,12 +29,7 @@ public final class ProxyInstanceDefinitionBuilder implements InstanceDefinitionB
@Override
public InstanceDefinition build(final int port) {
- return new InstanceDefinition(UUID.randomUUID().toString(), getType(), port);
- }
-
- @Override
- public InstanceDefinition build(final String instanceId, final String attributes) {
- return new InstanceDefinition(instanceId, getType(), attributes);
+ return new ProxyInstanceDefinition(UUID.randomUUID().toString(), port);
}
@Override
diff --git a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/resources/META-INF/services/org.apache.shardingsphere.infra.instance.definition.InstanceDefinitionBuilder b/shardingsphere-infra/shardingsphere-infra-common/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.instance.definition.InstanceDefinitionBuilder
similarity index 81%
rename from shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/resources/META-INF/services/org.apache.shardingsphere.infra.instance.definition.InstanceDefinitionBuilder
rename to shardingsphere-infra/shardingsphere-infra-common/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.instance.definition.InstanceDefinitionBuilder
index 5ae446150b7..371b9e8613f 100644
--- a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/resources/META-INF/services/org.apache.shardingsphere.infra.instance.definition.InstanceDefinitionBuilder
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.instance.definition.InstanceDefinitionBuilder
@@ -15,4 +15,5 @@
# limitations under the License.
#
-org.apache.shardingsphere.mode.manager.cluster.coordinator.fixture.InstanceDefinitionBuilderFixture
+org.apache.shardingsphere.infra.instance.definition.jdbc.JDBCInstanceDefinitionBuilder
+org.apache.shardingsphere.infra.instance.definition.proxy.ProxyInstanceDefinitionBuilder
diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/instance/JDBCInstanceDefinitionBuilderTest.java b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/instance/definition/jdbc/JDBCInstanceDefinitionBuilderTest.java
similarity index 71%
rename from shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/instance/JDBCInstanceDefinitionBuilderTest.java
rename to shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/instance/definition/jdbc/JDBCInstanceDefinitionBuilderTest.java
index c0fd961efde..c96c3637d76 100644
--- a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/instance/JDBCInstanceDefinitionBuilderTest.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/instance/definition/jdbc/JDBCInstanceDefinitionBuilderTest.java
@@ -15,10 +15,11 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.driver.instance;
+package org.apache.shardingsphere.infra.instance.definition.jdbc;
import org.apache.shardingsphere.infra.instance.definition.InstanceDefinition;
import org.apache.shardingsphere.infra.instance.definition.InstanceDefinitionBuilderFactory;
+import org.apache.shardingsphere.infra.instance.definition.InstanceType;
import org.junit.Test;
import static org.hamcrest.CoreMatchers.is;
@@ -32,18 +33,7 @@ public final class JDBCInstanceDefinitionBuilderTest {
InstanceDefinition actual = InstanceDefinitionBuilderFactory.newInstance("JDBC", -1);
assertNotNull(actual.getInstanceId());
assertNotNull(actual.getIp());
- assertThat(actual.getPort(), is(-1));
assertThat(actual.getAttributes(), is(""));
- assertThat(actual.getInstanceType(), is("JDBC"));
- }
-
- @Test
- public void assertNewInstanceWithAttributes() {
- InstanceDefinition actual = InstanceDefinitionBuilderFactory.newInstance("JDBC", "foo_id", "");
- assertThat(actual.getInstanceId(), is("foo_id"));
- assertNotNull(actual.getIp());
- assertThat(actual.getPort(), is(-1));
- assertThat(actual.getAttributes(), is(""));
- assertThat(actual.getInstanceType(), is("JDBC"));
+ assertThat(actual.getInstanceType(), is(InstanceType.JDBC));
}
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/test/java/org/apache/shardingsphere/proxy/instance/ProxyInstanceDefinitionBuilderTest.java b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/instance/definition/proxy/ProxyInstanceDefinitionBuilderTest.java
similarity index 68%
rename from shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/test/java/org/apache/shardingsphere/proxy/instance/ProxyInstanceDefinitionBuilderTest.java
rename to shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/instance/definition/proxy/ProxyInstanceDefinitionBuilderTest.java
index 4ee9050570e..659fdc72158 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/test/java/org/apache/shardingsphere/proxy/instance/ProxyInstanceDefinitionBuilderTest.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/instance/definition/proxy/ProxyInstanceDefinitionBuilderTest.java
@@ -15,10 +15,10 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.proxy.instance;
+package org.apache.shardingsphere.infra.instance.definition.proxy;
-import org.apache.shardingsphere.infra.instance.definition.InstanceDefinition;
import org.apache.shardingsphere.infra.instance.definition.InstanceDefinitionBuilderFactory;
+import org.apache.shardingsphere.infra.instance.definition.InstanceType;
import org.junit.Test;
import static org.hamcrest.CoreMatchers.endsWith;
@@ -30,21 +30,11 @@ public final class ProxyInstanceDefinitionBuilderTest {
@Test
public void assertNewInstance() {
- InstanceDefinition actual = InstanceDefinitionBuilderFactory.newInstance("Proxy", 3307);
+ ProxyInstanceDefinition actual = (ProxyInstanceDefinition) InstanceDefinitionBuilderFactory.newInstance("Proxy", 3307);
assertNotNull(actual.getInstanceId());
assertNotNull(actual.getIp());
assertThat(actual.getPort(), is(3307));
assertThat(actual.getAttributes(), endsWith("@3307"));
- assertThat(actual.getInstanceType(), is("Proxy"));
- }
-
- @Test
- public void assertNewInstanceWithAttributes() {
- InstanceDefinition actual = InstanceDefinitionBuilderFactory.newInstance("Proxy", "foo_id", "127.0.0.1@3307");
- assertThat(actual.getInstanceId(), is("foo_id"));
- assertThat(actual.getIp(), is("127.0.0.1"));
- assertThat(actual.getPort(), is(3307));
- assertThat(actual.getAttributes(), is("127.0.0.1@3307"));
- assertThat(actual.getInstanceType(), is("Proxy"));
+ assertThat(actual.getInstanceType(), is(InstanceType.PROXY));
}
}
diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/connection/ConnectionManager.java b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/connection/ConnectionManager.java
index 4fdbd9c260b..e9145ce4d19 100644
--- a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/connection/ConnectionManager.java
+++ b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/connection/ConnectionManager.java
@@ -30,6 +30,8 @@ import org.apache.shardingsphere.infra.datasource.props.DataSourceProperties;
import org.apache.shardingsphere.infra.executor.sql.execute.engine.ConnectionMode;
import org.apache.shardingsphere.infra.executor.sql.prepare.driver.jdbc.ExecutorJDBCConnectionManager;
import org.apache.shardingsphere.infra.instance.definition.InstanceDefinition;
+import org.apache.shardingsphere.infra.instance.definition.InstanceType;
+import org.apache.shardingsphere.infra.instance.definition.proxy.ProxyInstanceDefinition;
import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
import org.apache.shardingsphere.mode.manager.ContextManager;
import org.apache.shardingsphere.mode.metadata.persist.MetaDataPersistService;
@@ -91,7 +93,7 @@ public final class ConnectionManager implements ExecutorJDBCConnectionManager, A
Preconditions.checkState(!dataSourcePropsMap.isEmpty(), "Can not get data source properties from meta data.");
DataSourceProperties dataSourcePropsSample = dataSourcePropsMap.values().iterator().next();
Collection<ShardingSphereUser> users = metaDataPersistService.get().getGlobalRuleService().loadUsers();
- Collection<InstanceDefinition> instances = contextManager.getInstanceContext().getComputeNodeInstances("Proxy", trafficRule.getLabels());
+ Collection<InstanceDefinition> instances = contextManager.getInstanceContext().getComputeNodeInstances(InstanceType.PROXY, trafficRule.getLabels());
return DataSourcePoolCreator.create(createDataSourcePropertiesMap(instances, users, dataSourcePropsSample, schema));
}
@@ -99,12 +101,12 @@ public final class ConnectionManager implements ExecutorJDBCConnectionManager, A
final DataSourceProperties dataSourcePropsSample, final String schema) {
Map<String, DataSourceProperties> result = new LinkedHashMap<>();
for (InstanceDefinition each : instances) {
- result.put(each.getInstanceId(), createDataSourceProperties(each, users, dataSourcePropsSample, schema));
+ result.put(each.getInstanceId(), createDataSourceProperties((ProxyInstanceDefinition) each, users, dataSourcePropsSample, schema));
}
return result;
}
- private DataSourceProperties createDataSourceProperties(final InstanceDefinition instanceDefinition, final Collection<ShardingSphereUser> users,
+ private DataSourceProperties createDataSourceProperties(final ProxyInstanceDefinition instanceDefinition, final Collection<ShardingSphereUser> users,
final DataSourceProperties dataSourcePropsSample, final String schema) {
Map<String, Object> props = dataSourcePropsSample.getAllLocalProperties();
props.put("jdbcUrl", createJdbcUrl(instanceDefinition, schema, props));
@@ -114,7 +116,7 @@ public final class ConnectionManager implements ExecutorJDBCConnectionManager, A
return new DataSourceProperties("com.zaxxer.hikari.HikariDataSource", props);
}
- private String createJdbcUrl(final InstanceDefinition instanceDefinition, final String schema, final Map<String, Object> props) {
+ private String createJdbcUrl(final ProxyInstanceDefinition instanceDefinition, final String schema, final Map<String, Object> props) {
String jdbcUrl = String.valueOf(props.get("jdbcUrl"));
String jdbcUrlPrefix = jdbcUrl.substring(0, jdbcUrl.indexOf("//"));
String jdbcUrlSuffix = jdbcUrl.contains("?") ? jdbcUrl.substring(jdbcUrl.indexOf("?")) : "";
diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.instance.definition.InstanceDefinitionBuilder b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.instance.definition.InstanceDefinitionBuilder
deleted file mode 100644
index 574eaa5cc8e..00000000000
--- a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.instance.definition.InstanceDefinitionBuilder
+++ /dev/null
@@ -1,18 +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.
-#
-
-org.apache.shardingsphere.driver.instance.JDBCInstanceDefinitionBuilder
diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/connection/ConnectionManagerTest.java b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/connection/ConnectionManagerTest.java
index 1e998952e83..ab28ec9dec3 100644
--- a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/connection/ConnectionManagerTest.java
+++ b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/connection/ConnectionManagerTest.java
@@ -22,7 +22,8 @@ import org.apache.shardingsphere.infra.database.DefaultDatabase;
import org.apache.shardingsphere.infra.datasource.pool.creator.DataSourcePoolCreator;
import org.apache.shardingsphere.infra.datasource.props.DataSourceProperties;
import org.apache.shardingsphere.infra.executor.sql.execute.engine.ConnectionMode;
-import org.apache.shardingsphere.infra.instance.definition.InstanceDefinition;
+import org.apache.shardingsphere.infra.instance.definition.InstanceType;
+import org.apache.shardingsphere.infra.instance.definition.proxy.ProxyInstanceDefinition;
import org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData;
import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
import org.apache.shardingsphere.mode.manager.ContextManager;
@@ -94,8 +95,8 @@ public final class ConnectionManagerTest {
when(result.getMetaDataContexts().getMetaData().getGlobalRuleMetaData()).thenReturn(globalRuleMetaData);
when(globalRuleMetaData.getSingleRule(TransactionRule.class)).thenReturn(mock(TransactionRule.class, RETURNS_DEEP_STUBS));
when(globalRuleMetaData.getSingleRule(TrafficRule.class)).thenReturn(mock(TrafficRule.class, RETURNS_DEEP_STUBS));
- when(result.getInstanceContext().getComputeNodeInstances("Proxy", Arrays.asList("OLTP", "OLAP"))).thenReturn(
- Collections.singletonList(new InstanceDefinition("127.0.0.1@3307", "Proxy", "127.0.0.1@3307")));
+ when(result.getInstanceContext().getComputeNodeInstances(InstanceType.PROXY, Arrays.asList("OLTP", "OLAP"))).thenReturn(
+ Collections.singletonList(new ProxyInstanceDefinition("127.0.0.1@3307", "127.0.0.1@3307")));
dataSourcePoolCreator = mockStatic(DataSourcePoolCreator.class);
Map<String, DataSource> trafficDataSourceMap = mockTrafficDataSourceMap();
when(DataSourcePoolCreator.create((Map) any())).thenReturn(trafficDataSourceMap);
diff --git a/shardingsphere-kernel/shardingsphere-traffic/shardingsphere-traffic-core/src/main/java/org/apache/shardingsphere/traffic/engine/TrafficEngine.java b/shardingsphere-kernel/shardingsphere-traffic/shardingsphere-traffic-core/src/main/java/org/apache/shardingsphere/traffic/engine/TrafficEngine.java
index ea7c55645a8..ee34fea4281 100644
--- a/shardingsphere-kernel/shardingsphere-traffic/shardingsphere-traffic-core/src/main/java/org/apache/shardingsphere/traffic/engine/TrafficEngine.java
+++ b/shardingsphere-kernel/shardingsphere-traffic/shardingsphere-traffic-core/src/main/java/org/apache/shardingsphere/traffic/engine/TrafficEngine.java
@@ -21,6 +21,7 @@ import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.infra.binder.LogicSQL;
import org.apache.shardingsphere.infra.instance.InstanceContext;
import org.apache.shardingsphere.infra.instance.definition.InstanceDefinition;
+import org.apache.shardingsphere.infra.instance.definition.InstanceType;
import org.apache.shardingsphere.traffic.context.TrafficContext;
import org.apache.shardingsphere.traffic.rule.TrafficRule;
import org.apache.shardingsphere.traffic.rule.TrafficStrategyRule;
@@ -52,7 +53,7 @@ public final class TrafficEngine {
if (!strategyRule.isPresent() || isInvalidStrategyRule(strategyRule.get())) {
return result;
}
- List<InstanceDefinition> instances = instanceContext.getComputeNodeInstances("Proxy", strategyRule.get().getLabels());
+ List<InstanceDefinition> instances = instanceContext.getComputeNodeInstances(InstanceType.PROXY, strategyRule.get().getLabels());
if (!instances.isEmpty()) {
TrafficLoadBalanceAlgorithm loadBalancer = strategyRule.get().getLoadBalancer();
InstanceDefinition instanceDefinition = 1 == instances.size() ? instances.iterator().next() : loadBalancer.getInstanceId(strategyRule.get().getName(), instances);
diff --git a/shardingsphere-kernel/shardingsphere-traffic/shardingsphere-traffic-core/src/test/java/org/apache/shardingsphere/traffic/algorithm/engine/TrafficEngineTest.java b/shardingsphere-kernel/shardingsphere-traffic/shardingsphere-traffic-core/src/test/java/org/apache/shardingsphere/traffic/algorithm/engine/TrafficEngineTest.java
index b6f01b286de..bffcea712ef 100644
--- a/shardingsphere-kernel/shardingsphere-traffic/shardingsphere-traffic-core/src/test/java/org/apache/shardingsphere/traffic/algorithm/engine/TrafficEngineTest.java
+++ b/shardingsphere-kernel/shardingsphere-traffic/shardingsphere-traffic-core/src/test/java/org/apache/shardingsphere/traffic/algorithm/engine/TrafficEngineTest.java
@@ -20,6 +20,8 @@ package org.apache.shardingsphere.traffic.algorithm.engine;
import org.apache.shardingsphere.infra.binder.LogicSQL;
import org.apache.shardingsphere.infra.instance.InstanceContext;
import org.apache.shardingsphere.infra.instance.definition.InstanceDefinition;
+import org.apache.shardingsphere.infra.instance.definition.InstanceType;
+import org.apache.shardingsphere.infra.instance.definition.proxy.ProxyInstanceDefinition;
import org.apache.shardingsphere.traffic.context.TrafficContext;
import org.apache.shardingsphere.traffic.engine.TrafficEngine;
import org.apache.shardingsphere.traffic.rule.TrafficRule;
@@ -91,18 +93,18 @@ public final class TrafficEngineTest {
when(strategyRule.getLabels()).thenReturn(Arrays.asList("OLTP", "OLAP"));
TrafficLoadBalanceAlgorithm loadBalancer = mock(TrafficLoadBalanceAlgorithm.class);
List<InstanceDefinition> instanceIds = mockComputeNodeInstances();
- when(loadBalancer.getInstanceId("traffic", instanceIds)).thenReturn(new InstanceDefinition("127.0.0.1@3307", "Proxy", 3307));
+ when(loadBalancer.getInstanceId("traffic", instanceIds)).thenReturn(new ProxyInstanceDefinition("127.0.0.1@3307", 3307));
when(strategyRule.getLoadBalancer()).thenReturn(loadBalancer);
when(strategyRule.getName()).thenReturn("traffic");
- when(instanceContext.getComputeNodeInstances("Proxy", Arrays.asList("OLTP", "OLAP"))).thenReturn(instanceIds);
+ when(instanceContext.getComputeNodeInstances(InstanceType.PROXY, Arrays.asList("OLTP", "OLAP"))).thenReturn(instanceIds);
TrafficContext actual = trafficEngine.dispatch(logicSQL, false);
assertThat(actual.getInstanceId(), is("127.0.0.1@3307"));
}
private List<InstanceDefinition> mockComputeNodeInstances() {
List<InstanceDefinition> result = new ArrayList<>();
- result.add(new InstanceDefinition("127.0.0.1@3307", "Proxy", "127.0.0.1@3307"));
- result.add(new InstanceDefinition("127.0.0.1@3308", "Proxy", "127.0.0.1@3308"));
+ result.add(new ProxyInstanceDefinition("127.0.0.1@3307", "127.0.0.1@3307"));
+ result.add(new ProxyInstanceDefinition("127.0.0.1@3308", "127.0.0.1@3308"));
return result;
}
}
diff --git a/shardingsphere-kernel/shardingsphere-traffic/shardingsphere-traffic-core/src/test/java/org/apache/shardingsphere/traffic/algorithm/loadbalance/RandomTrafficLoadBalanceAlgorithmTest.java b/shardingsphere-kernel/shardingsphere-traffic/shardingsphere-traffic-core/src/test/java/org/apache/shardingsphere/traffic/algorithm/loadbalance/RandomTrafficLoadBalanceAlgorithmTest.java
index 6b22f4d15dd..66bd664ab6a 100644
--- a/shardingsphere-kernel/shardingsphere-traffic/shardingsphere-traffic-core/src/test/java/org/apache/shardingsphere/traffic/algorithm/loadbalance/RandomTrafficLoadBalanceAlgorithmTest.java
+++ b/shardingsphere-kernel/shardingsphere-traffic/shardingsphere-traffic-core/src/test/java/org/apache/shardingsphere/traffic/algorithm/loadbalance/RandomTrafficLoadBalanceAlgorithmTest.java
@@ -18,6 +18,7 @@
package org.apache.shardingsphere.traffic.algorithm.loadbalance;
import org.apache.shardingsphere.infra.instance.definition.InstanceDefinition;
+import org.apache.shardingsphere.infra.instance.definition.proxy.ProxyInstanceDefinition;
import org.junit.Test;
import java.util.Arrays;
@@ -29,7 +30,7 @@ public final class RandomTrafficLoadBalanceAlgorithmTest {
@Test
public void assertGetInstanceId() {
- List<InstanceDefinition> instances = Arrays.asList(new InstanceDefinition("127.0.0.1@3307", "Proxy", "127.0.0.1@3307"), new InstanceDefinition("127.0.0.1@3308", "Proxy", "127.0.0.1@3308"));
+ List<InstanceDefinition> instances = Arrays.asList(new ProxyInstanceDefinition("127.0.0.1@3307", "127.0.0.1@3307"), new ProxyInstanceDefinition("127.0.0.1@3308", "127.0.0.1@3308"));
RandomTrafficLoadBalanceAlgorithm randomAlgorithm = new RandomTrafficLoadBalanceAlgorithm();
assertTrue(instances.contains(randomAlgorithm.getInstanceId("simple_traffic", instances)));
assertTrue(instances.contains(randomAlgorithm.getInstanceId("simple_traffic", instances)));
diff --git a/shardingsphere-kernel/shardingsphere-traffic/shardingsphere-traffic-core/src/test/java/org/apache/shardingsphere/traffic/algorithm/loadbalance/RoundRobinTrafficLoadBalanceAlgorithmTest.java b/shardingsphere-kernel/shardingsphere-traffic/shardingsphere-traffic-core/src/test/java/org/apache/shardingsphere/traffic/algorithm/loadbalance/RoundRobinTrafficLoadBalanceAlgorithmTest.java
index 70fec042edb..d7717614b65 100644
--- a/shardingsphere-kernel/shardingsphere-traffic/shardingsphere-traffic-core/src/test/java/org/apache/shardingsphere/traffic/algorithm/loadbalance/RoundRobinTrafficLoadBalanceAlgorithmTest.java
+++ b/shardingsphere-kernel/shardingsphere-traffic/shardingsphere-traffic-core/src/test/java/org/apache/shardingsphere/traffic/algorithm/loadbalance/RoundRobinTrafficLoadBalanceAlgorithmTest.java
@@ -18,6 +18,7 @@
package org.apache.shardingsphere.traffic.algorithm.loadbalance;
import org.apache.shardingsphere.infra.instance.definition.InstanceDefinition;
+import org.apache.shardingsphere.infra.instance.definition.proxy.ProxyInstanceDefinition;
import org.junit.Test;
import java.util.Arrays;
@@ -30,8 +31,8 @@ public final class RoundRobinTrafficLoadBalanceAlgorithmTest {
@Test
public void assertGetInstanceId() {
- InstanceDefinition instance1 = new InstanceDefinition("127.0.0.1@3307", "Proxy", "127.0.0.1@3307");
- InstanceDefinition instance2 = new InstanceDefinition("127.0.0.1@3308", "Proxy", "127.0.0.1@3308");
+ InstanceDefinition instance1 = new ProxyInstanceDefinition("127.0.0.1@3307", "127.0.0.1@3307");
+ InstanceDefinition instance2 = new ProxyInstanceDefinition("127.0.0.1@3308", "127.0.0.1@3308");
List<InstanceDefinition> instances = Arrays.asList(instance1, instance2);
RoundRobinTrafficLoadBalanceAlgorithm roundRobinAlgorithm = new RoundRobinTrafficLoadBalanceAlgorithm();
assertThat(roundRobinAlgorithm.getInstanceId("simple_traffic", instances), is(instance1));
diff --git a/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/metadata/persist/node/ComputeNode.java b/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/metadata/persist/node/ComputeNode.java
index f17063e9bcb..65a2c6ba34d 100644
--- a/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/metadata/persist/node/ComputeNode.java
+++ b/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/metadata/persist/node/ComputeNode.java
@@ -17,6 +17,8 @@
package org.apache.shardingsphere.mode.metadata.persist.node;
+import org.apache.shardingsphere.infra.instance.definition.InstanceType;
+
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -45,8 +47,8 @@ public final class ComputeNode {
* @param instanceType instance type
* @return path of online compute node
*/
- public static String getOnlineNodePath(final String instanceType) {
- return String.join("/", "", ROOT_NODE, COMPUTE_NODE, ONLINE_NODE, instanceType.toLowerCase());
+ public static String getOnlineNodePath(final InstanceType instanceType) {
+ return String.join("/", "", ROOT_NODE, COMPUTE_NODE, ONLINE_NODE, instanceType.name().toLowerCase());
}
/**
@@ -56,8 +58,8 @@ public final class ComputeNode {
* @param instanceType instance type
* @return path of online compute node instance
*/
- public static String getOnlineInstanceNodePath(final String instanceId, final String instanceType) {
- return String.join("/", "", ROOT_NODE, COMPUTE_NODE, ONLINE_NODE, instanceType.toLowerCase(), instanceId);
+ public static String getOnlineInstanceNodePath(final String instanceId, final InstanceType instanceType) {
+ return String.join("/", "", ROOT_NODE, COMPUTE_NODE, ONLINE_NODE, instanceType.name().toLowerCase(), instanceId);
}
/**
diff --git a/shardingsphere-mode/shardingsphere-mode-core/src/test/java/org/apache/shardingsphere/mode/metadata/persist/node/ComputeNodeTest.java b/shardingsphere-mode/shardingsphere-mode-core/src/test/java/org/apache/shardingsphere/mode/metadata/persist/node/ComputeNodeTest.java
index 55835e67444..543833d4272 100644
--- a/shardingsphere-mode/shardingsphere-mode-core/src/test/java/org/apache/shardingsphere/mode/metadata/persist/node/ComputeNodeTest.java
+++ b/shardingsphere-mode/shardingsphere-mode-core/src/test/java/org/apache/shardingsphere/mode/metadata/persist/node/ComputeNodeTest.java
@@ -17,6 +17,7 @@
package org.apache.shardingsphere.mode.metadata.persist.node;
+import org.apache.shardingsphere.infra.instance.definition.InstanceType;
import org.junit.Test;
import static org.hamcrest.CoreMatchers.is;
@@ -26,14 +27,14 @@ public final class ComputeNodeTest {
@Test
public void assertGetOnlineNodePath() {
- assertThat(ComputeNode.getOnlineNodePath("Proxy"), is("/nodes/compute_nodes/online/proxy"));
- assertThat(ComputeNode.getOnlineNodePath("JDBC"), is("/nodes/compute_nodes/online/jdbc"));
+ assertThat(ComputeNode.getOnlineNodePath(InstanceType.PROXY), is("/nodes/compute_nodes/online/proxy"));
+ assertThat(ComputeNode.getOnlineNodePath(InstanceType.JDBC), is("/nodes/compute_nodes/online/jdbc"));
}
@Test
public void assertGetOnlineInstanceNodePath() {
- assertThat(ComputeNode.getOnlineInstanceNodePath("foo_instance_1", "Proxy"), is("/nodes/compute_nodes/online/proxy/foo_instance_1"));
- assertThat(ComputeNode.getOnlineInstanceNodePath("foo_instance_2", "JDBC"), is("/nodes/compute_nodes/online/jdbc/foo_instance_2"));
+ assertThat(ComputeNode.getOnlineInstanceNodePath("foo_instance_1", InstanceType.PROXY), is("/nodes/compute_nodes/online/proxy/foo_instance_1"));
+ assertThat(ComputeNode.getOnlineInstanceNodePath("foo_instance_2", InstanceType.JDBC), is("/nodes/compute_nodes/online/jdbc/foo_instance_2"));
}
@Test
diff --git a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/ClusterContextManagerBuilder.java b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/ClusterContextManagerBuilder.java
index 939876e06b9..ff29f6f8bcb 100644
--- a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/ClusterContextManagerBuilder.java
+++ b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/ClusterContextManagerBuilder.java
@@ -25,6 +25,7 @@ import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
import org.apache.shardingsphere.infra.federation.optimizer.context.OptimizerContextFactory;
import org.apache.shardingsphere.infra.instance.ComputeNodeInstance;
import org.apache.shardingsphere.infra.instance.InstanceContext;
+import org.apache.shardingsphere.infra.instance.definition.jdbc.JDBCInstanceDefinition;
import org.apache.shardingsphere.infra.instance.definition.InstanceDefinition;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
@@ -78,7 +79,7 @@ public final class ClusterContextManagerBuilder implements ContextManagerBuilder
}
private MetaDataContexts createMetaDataContexts(final MetaDataPersistService persistService, final ContextManagerBuilderParameter parameter) throws SQLException {
- Collection<String> databaseNames = -1 == parameter.getInstanceDefinition().getPort()
+ Collection<String> databaseNames = parameter.getInstanceDefinition() instanceof JDBCInstanceDefinition
? parameter.getDatabaseConfigs().keySet()
: persistService.getSchemaMetaDataService().loadAllDatabaseNames();
Collection<RuleConfiguration> globalRuleConfigs = persistService.getGlobalRuleService().load();
diff --git a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/process/subscriber/ProcessRegistrySubscriber.java b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/process/subscriber/ProcessRegistrySubscriber.java
index 99486ba603a..10c1c130c17 100644
--- a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/process/subscriber/ProcessRegistrySubscriber.java
+++ b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/process/subscriber/ProcessRegistrySubscriber.java
@@ -25,7 +25,7 @@ import org.apache.shardingsphere.infra.executor.sql.process.model.ExecuteProcess
import org.apache.shardingsphere.infra.executor.sql.process.model.ExecuteProcessUnit;
import org.apache.shardingsphere.infra.executor.sql.process.model.yaml.YamlExecuteProcessContext;
import org.apache.shardingsphere.infra.executor.sql.process.model.yaml.YamlExecuteProcessUnit;
-import org.apache.shardingsphere.infra.instance.definition.InstanceDefinitionBuilderFactory;
+import org.apache.shardingsphere.infra.instance.definition.InstanceType;
import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.process.ShowProcessListManager;
import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.process.event.ExecuteProcessReportEvent;
import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.process.event.ExecuteProcessSummaryReportEvent;
@@ -43,6 +43,7 @@ import java.util.List;
import java.util.UUID;
import java.util.concurrent.ThreadLocalRandom;
import java.util.stream.Collectors;
+import java.util.stream.Stream;
/**
* Process registry subscriber.
@@ -79,7 +80,7 @@ public final class ProcessRegistrySubscriber {
}
private Collection<String> getTriggerPaths(final String showProcessListId) {
- return InstanceDefinitionBuilderFactory.getAllTypes().stream()
+ return Stream.of(InstanceType.values())
.flatMap(each -> repository.getChildrenKeys(ComputeNode.getOnlineNodePath(each)).stream()
.map(onlinePath -> ComputeNode.getProcessTriggerInstanceIdNodePath(onlinePath, showProcessListId)))
.collect(Collectors.toList());
diff --git a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/compute/service/ComputeNodeStatusService.java b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/compute/service/ComputeNodeStatusService.java
index b6ad2464695..7a40b8fcc0a 100644
--- a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/compute/service/ComputeNodeStatusService.java
+++ b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/compute/service/ComputeNodeStatusService.java
@@ -22,7 +22,9 @@ import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.shardingsphere.infra.instance.ComputeNodeInstance;
import org.apache.shardingsphere.infra.instance.definition.InstanceDefinition;
-import org.apache.shardingsphere.infra.instance.definition.InstanceDefinitionBuilderFactory;
+import org.apache.shardingsphere.infra.instance.definition.InstanceType;
+import org.apache.shardingsphere.infra.instance.definition.jdbc.JDBCInstanceDefinition;
+import org.apache.shardingsphere.infra.instance.definition.proxy.ProxyInstanceDefinition;
import org.apache.shardingsphere.infra.yaml.engine.YamlEngine;
import org.apache.shardingsphere.mode.metadata.persist.node.ComputeNode;
import org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepository;
@@ -120,16 +122,21 @@ public final class ComputeNodeStatusService {
*/
public Collection<ComputeNodeInstance> loadAllComputeNodeInstances() {
Collection<ComputeNodeInstance> result = new LinkedList<>();
- for (String each : InstanceDefinitionBuilderFactory.getAllTypes()) {
+ for (InstanceType each : InstanceType.values()) {
result.addAll(loadComputeNodeInstances(each));
}
return result;
}
- private Collection<ComputeNodeInstance> loadComputeNodeInstances(final String type) {
- Collection<String> onlineComputeNodes = repository.getChildrenKeys(ComputeNode.getOnlineNodePath(type));
- return onlineComputeNodes.stream().map(each -> loadComputeNodeInstance(
- InstanceDefinitionBuilderFactory.newInstance(type, each, repository.get(ComputeNode.getOnlineInstanceNodePath(each, type))))).collect(Collectors.toList());
+ private Collection<ComputeNodeInstance> loadComputeNodeInstances(final InstanceType instanceType) {
+ Collection<String> onlineComputeNodes = repository.getChildrenKeys(ComputeNode.getOnlineNodePath(instanceType));
+ return onlineComputeNodes.stream().map(each -> loadComputeNodeInstance(createInstanceDefinition(each, instanceType))).collect(Collectors.toList());
+ }
+
+ private InstanceDefinition createInstanceDefinition(final String instanceId, final InstanceType type) {
+ return InstanceType.JDBC == type
+ ? new JDBCInstanceDefinition(instanceId)
+ : new ProxyInstanceDefinition(instanceId, repository.get(ComputeNode.getOnlineInstanceNodePath(instanceId, type)));
}
/**
diff --git a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/compute/watcher/ComputeNodeStateChangedWatcher.java b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/compute/watcher/ComputeNodeStateChan [...]
index 3c087cff7ca..48b6e920d21 100644
--- a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/compute/watcher/ComputeNodeStateChangedWatcher.java
+++ b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/compute/watcher/ComputeNodeStateChangedWatcher.java
@@ -19,7 +19,9 @@ package org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.stat
import com.google.common.base.Strings;
import org.apache.shardingsphere.infra.instance.definition.InstanceDefinition;
-import org.apache.shardingsphere.infra.instance.definition.InstanceDefinitionBuilderFactory;
+import org.apache.shardingsphere.infra.instance.definition.InstanceType;
+import org.apache.shardingsphere.infra.instance.definition.jdbc.JDBCInstanceDefinition;
+import org.apache.shardingsphere.infra.instance.definition.proxy.ProxyInstanceDefinition;
import org.apache.shardingsphere.infra.yaml.engine.YamlEngine;
import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.GovernanceEvent;
import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.GovernanceWatcher;
@@ -101,7 +103,7 @@ public final class ComputeNodeStateChangedWatcher implements GovernanceWatcher<G
private Optional<GovernanceEvent> createInstanceEvent(final DataChangedEvent event) {
Matcher matcher = matchInstanceOnlinePath(event.getKey());
if (matcher.find()) {
- InstanceDefinition instanceDefinition = InstanceDefinitionBuilderFactory.newInstance(matcher.group(1).toUpperCase(), matcher.group(2), event.getValue());
+ InstanceDefinition instanceDefinition = createInstanceDefinition(matcher.group(2), InstanceType.valueOf(matcher.group(1).toUpperCase()), event.getValue());
if (Type.ADDED == event.getType()) {
return Optional.of(new InstanceOnlineEvent(instanceDefinition));
}
@@ -115,4 +117,8 @@ public final class ComputeNodeStateChangedWatcher implements GovernanceWatcher<G
private Matcher matchInstanceOnlinePath(final String onlineInstancePath) {
return Pattern.compile(ComputeNode.getOnlineInstanceNodePath() + "/[\\S]+/([\\S]+)$", Pattern.CASE_INSENSITIVE).matcher(onlineInstancePath);
}
+
+ private InstanceDefinition createInstanceDefinition(final String instanceId, final InstanceType instanceType, final String attributes) {
+ return InstanceType.JDBC == instanceType ? new JDBCInstanceDefinition(instanceId) : new ProxyInstanceDefinition(instanceId, attributes);
+ }
}
diff --git a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/ClusterContextManagerCoordinatorTest.java b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/ClusterContextManagerCoordinatorTest.java
index 93e7abadc56..3d9b3ea6f02 100644
--- a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/ClusterContextManagerCoordinatorTest.java
+++ b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/ClusterContextManagerCoordinatorTest.java
@@ -34,6 +34,7 @@ import org.apache.shardingsphere.infra.federation.optimizer.context.OptimizerCon
import org.apache.shardingsphere.infra.federation.optimizer.metadata.FederationDatabaseMetaData;
import org.apache.shardingsphere.infra.instance.ComputeNodeInstance;
import org.apache.shardingsphere.infra.instance.definition.InstanceDefinition;
+import org.apache.shardingsphere.infra.instance.definition.proxy.ProxyInstanceDefinition;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.metadata.database.resource.ShardingSphereResource;
@@ -144,7 +145,7 @@ public final class ClusterContextManagerCoordinatorTest {
private ContextManagerBuilderParameter createContextManagerBuilderParameter() {
ModeConfiguration modeConfig = new ModeConfiguration("Cluster", new ClusterPersistRepositoryConfiguration("FIXTURE", "", "", new Properties()), false);
- InstanceDefinition instanceDefinition = new InstanceDefinition("foo_instance_id", "Proxy", 3307);
+ InstanceDefinition instanceDefinition = new ProxyInstanceDefinition("foo_instance_id", 3307);
return new ContextManagerBuilderParameter(modeConfig, Collections.emptyMap(), Collections.emptyList(), new Properties(), Collections.emptyList(), instanceDefinition);
}
@@ -315,7 +316,7 @@ public final class ClusterContextManagerCoordinatorTest {
@Test
public void assertRenewInstanceOfflineEvent() {
coordinator.renew(new InstanceOfflineEvent(contextManager.getInstanceContext().getInstance().getInstanceDefinition()));
- assertThat(contextManager.getInstanceContext().getInstance().getInstanceDefinition().getPort(), is(3307));
+ assertThat(((ProxyInstanceDefinition) contextManager.getInstanceContext().getInstance().getInstanceDefinition()).getPort(), is(3307));
}
@Test
@@ -333,12 +334,12 @@ public final class ClusterContextManagerCoordinatorTest {
@Test
public void assertRenewInstanceOnlineEvent() {
- InstanceDefinition instanceDefinition1 = new InstanceDefinition("foo_instance_3307", "Proxy", 3307);
+ InstanceDefinition instanceDefinition1 = new ProxyInstanceDefinition("foo_instance_3307", 3307);
InstanceOnlineEvent instanceOnlineEvent1 = new InstanceOnlineEvent(instanceDefinition1);
coordinator.renew(instanceOnlineEvent1);
assertThat(contextManager.getInstanceContext().getComputeNodeInstances().size(), is(1));
assertThat(((LinkedList<ComputeNodeInstance>) contextManager.getInstanceContext().getComputeNodeInstances()).get(0).getInstanceDefinition(), is(instanceDefinition1));
- InstanceDefinition instanceDefinition2 = new InstanceDefinition("foo_instance_3308", "Proxy", 3308);
+ InstanceDefinition instanceDefinition2 = new ProxyInstanceDefinition("foo_instance_3308", 3308);
InstanceOnlineEvent instanceOnlineEvent2 = new InstanceOnlineEvent(instanceDefinition2);
coordinator.renew(instanceOnlineEvent2);
assertThat(contextManager.getInstanceContext().getComputeNodeInstances().size(), is(2));
diff --git a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/DistributedLockContextTest.java b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/DistributedLockContextTest.java
index 597dd24cc37..41ad42a0d16 100644
--- a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/DistributedLockContextTest.java
+++ b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/DistributedLockContextTest.java
@@ -20,7 +20,7 @@ package org.apache.shardingsphere.mode.manager.cluster.coordinator.lock;
import org.apache.shardingsphere.infra.config.mode.ModeConfiguration;
import org.apache.shardingsphere.infra.instance.ComputeNodeInstance;
import org.apache.shardingsphere.infra.instance.InstanceContext;
-import org.apache.shardingsphere.infra.instance.definition.InstanceDefinition;
+import org.apache.shardingsphere.infra.instance.definition.proxy.ProxyInstanceDefinition;
import org.apache.shardingsphere.infra.instance.workerid.WorkerIdGenerator;
import org.apache.shardingsphere.infra.lock.ShardingSphereLock;
import org.apache.shardingsphere.mode.manager.lock.definition.LockNameDefinitionFactory;
@@ -38,14 +38,14 @@ public final class DistributedLockContextTest {
@Test
public void assertGetDistributedLock() {
DistributedLockContext distributedLockContext = new DistributedLockContext(mock(ClusterPersistRepository.class));
- ComputeNodeInstance currentInstance = new ComputeNodeInstance(new InstanceDefinition("1", "Proxy", 3307));
+ ComputeNodeInstance currentInstance = new ComputeNodeInstance(new ProxyInstanceDefinition("1", 3307));
new InstanceContext(currentInstance, mock(WorkerIdGenerator.class), mock(ModeConfiguration.class), distributedLockContext);
assertThat(distributedLockContext.getLock(), instanceOf(ShardingSphereLock.class));
}
@Test
public void assertTryLock() {
- ComputeNodeInstance currentInstance = new ComputeNodeInstance(new InstanceDefinition("1", "Proxy", 3307));
+ ComputeNodeInstance currentInstance = new ComputeNodeInstance(new ProxyInstanceDefinition("1", 3307));
DistributedLockContext distributedLockContext = new DistributedLockContext(mock(ClusterPersistRepository.class));
new InstanceContext(currentInstance, mock(WorkerIdGenerator.class), mock(ModeConfiguration.class), distributedLockContext);
assertNotNull(distributedLockContext.getLock());
@@ -53,7 +53,7 @@ public final class DistributedLockContextTest {
@Test
public void assertReleaseLock() {
- ComputeNodeInstance currentInstance = new ComputeNodeInstance(new InstanceDefinition("1", "Proxy", 3307));
+ ComputeNodeInstance currentInstance = new ComputeNodeInstance(new ProxyInstanceDefinition("1", 3307));
DistributedLockContext distributedLockContext = new DistributedLockContext(mock(ClusterPersistRepository.class));
new InstanceContext(currentInstance, mock(WorkerIdGenerator.class), mock(ModeConfiguration.class), distributedLockContext);
distributedLockContext.releaseLock(LockNameDefinitionFactory.newDatabaseDefinition("database"));
@@ -61,7 +61,7 @@ public final class DistributedLockContextTest {
@Test
public void assertIsLockedDatabase() {
- ComputeNodeInstance currentInstance = new ComputeNodeInstance(new InstanceDefinition("1", "Proxy", 3307));
+ ComputeNodeInstance currentInstance = new ComputeNodeInstance(new ProxyInstanceDefinition("1", 3307));
DistributedLockContext distributedLockContext = new DistributedLockContext(mock(ClusterPersistRepository.class));
new InstanceContext(currentInstance, mock(WorkerIdGenerator.class), mock(ModeConfiguration.class), distributedLockContext);
assertFalse(distributedLockContext.isLocked(LockNameDefinitionFactory.newDatabaseDefinition("database")));
diff --git a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/process/subscriber/ProcessRegistrySubscriberTest.java b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/process/subscriber/ProcessRegistrySubscriberTest.java
index a4c4d7b87d1..4d12db5ed05 100644
--- a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/process/subscriber/ProcessRegistrySubscriberTest.java
+++ b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/process/subscriber/ProcessRegistrySubscriberTest.java
@@ -22,6 +22,7 @@ import org.apache.shardingsphere.infra.executor.sql.process.model.ExecuteProcess
import org.apache.shardingsphere.infra.executor.sql.process.model.ExecuteProcessUnit;
import org.apache.shardingsphere.infra.executor.sql.process.model.yaml.YamlExecuteProcessContext;
import org.apache.shardingsphere.infra.executor.sql.process.model.yaml.YamlExecuteProcessUnit;
+import org.apache.shardingsphere.infra.instance.definition.InstanceType;
import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.process.ShowProcessListManager;
import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.process.event.ExecuteProcessReportEvent;
import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.process.event.ExecuteProcessSummaryReportEvent;
@@ -62,7 +63,7 @@ public final class ProcessRegistrySubscriberTest {
@Test
public void assertLoadShowProcessListData() {
- when(repository.getChildrenKeys(ComputeNode.getOnlineNodePath("FIXTURE"))).thenReturn(Collections.singletonList("abc"));
+ when(repository.getChildrenKeys(ComputeNode.getOnlineNodePath(InstanceType.PROXY))).thenReturn(Collections.singletonList("abc"));
when(repository.get(any())).thenReturn(null);
ShowProcessListRequestEvent showProcessListRequestEvent = mock(ShowProcessListRequestEvent.class);
processRegistrySubscriber.loadShowProcessListData(showProcessListRequestEvent);
diff --git a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/compute/service/ComputeNodeStatusServiceTest.java b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/compute/service/ComputeNodeStatusServi [...]
index 90350ada8de..33571dc3091 100644
--- a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/compute/service/ComputeNodeStatusServiceTest.java
+++ b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/compute/service/ComputeNodeStatusServiceTest.java
@@ -19,6 +19,7 @@ package org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.stat
import org.apache.shardingsphere.infra.instance.ComputeNodeInstance;
import org.apache.shardingsphere.infra.instance.definition.InstanceDefinition;
+import org.apache.shardingsphere.infra.instance.definition.proxy.ProxyInstanceDefinition;
import org.apache.shardingsphere.infra.yaml.engine.YamlEngine;
import org.apache.shardingsphere.mode.metadata.persist.node.ComputeNode;
import org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepository;
@@ -27,8 +28,9 @@ import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
-import java.util.Collection;
+import java.util.ArrayList;
import java.util.Collections;
+import java.util.List;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
@@ -46,7 +48,7 @@ public final class ComputeNodeStatusServiceTest {
@Test
public void assertRegisterOnline() {
- InstanceDefinition instanceDefinition = new InstanceDefinition("foo_instance_id", "Proxy", 3307);
+ InstanceDefinition instanceDefinition = new ProxyInstanceDefinition("foo_instance_id", 3307);
new ComputeNodeStatusService(repository).registerOnline(instanceDefinition);
verify(repository).persistEphemeral(eq("/nodes/compute_nodes/online/proxy/" + instanceDefinition.getInstanceId()), anyString());
}
@@ -54,7 +56,7 @@ public final class ComputeNodeStatusServiceTest {
@Test
public void assertPersistInstanceLabels() {
ComputeNodeStatusService computeNodeStatusService = new ComputeNodeStatusService(repository);
- InstanceDefinition instanceDefinition = new InstanceDefinition("foo_instance_id", "Proxy", 3307);
+ InstanceDefinition instanceDefinition = new ProxyInstanceDefinition("foo_instance_id", 3307);
final String instanceId = instanceDefinition.getInstanceId();
computeNodeStatusService.persistInstanceLabels(instanceId, Collections.singletonList("test"));
verify(repository, times(1)).persistEphemeral(ComputeNode.getInstanceLabelsNodePath(instanceId), YamlEngine.marshal(Collections.singletonList("test")));
@@ -64,7 +66,7 @@ public final class ComputeNodeStatusServiceTest {
@Test
public void assertPersistInstanceWorkerId() {
- InstanceDefinition instanceDefinition = new InstanceDefinition("foo_instance_id", "Proxy", 3307);
+ InstanceDefinition instanceDefinition = new ProxyInstanceDefinition("foo_instance_id", 3307);
final String instanceId = instanceDefinition.getInstanceId();
new ComputeNodeStatusService(repository).persistInstanceWorkerId(instanceId, 100L);
verify(repository).persistEphemeral(ComputeNode.getInstanceWorkerIdNodePath(instanceId), String.valueOf(100L));
@@ -72,7 +74,7 @@ public final class ComputeNodeStatusServiceTest {
@Test
public void assertLoadInstanceLabels() {
- InstanceDefinition instanceDefinition = new InstanceDefinition("foo_instance_id", "Proxy", 3307);
+ InstanceDefinition instanceDefinition = new ProxyInstanceDefinition("foo_instance_id", 3307);
final String instanceId = instanceDefinition.getInstanceId();
new ComputeNodeStatusService(repository).loadInstanceLabels(instanceId);
verify(repository).get(ComputeNode.getInstanceLabelsNodePath(instanceId));
@@ -80,7 +82,7 @@ public final class ComputeNodeStatusServiceTest {
@Test
public void assertLoadInstanceStatus() {
- InstanceDefinition instanceDefinition = new InstanceDefinition("foo_instance_id", "Proxy", 3307);
+ InstanceDefinition instanceDefinition = new ProxyInstanceDefinition("foo_instance_id", 3307);
final String instanceId = instanceDefinition.getInstanceId();
new ComputeNodeStatusService(repository).loadInstanceStatus(instanceId);
verify(repository).get(ComputeNode.getInstanceStatusNodePath(instanceId));
@@ -88,7 +90,7 @@ public final class ComputeNodeStatusServiceTest {
@Test
public void assertLoadInstanceWorkerId() {
- InstanceDefinition instanceDefinition = new InstanceDefinition("foo_instance_id", "Proxy", 3307);
+ InstanceDefinition instanceDefinition = new ProxyInstanceDefinition("foo_instance_id", 3307);
final String instanceId = instanceDefinition.getInstanceId();
new ComputeNodeStatusService(repository).loadInstanceWorkerId(instanceId);
verify(repository).get(ComputeNode.getInstanceWorkerIdNodePath(instanceId));
@@ -96,15 +98,17 @@ public final class ComputeNodeStatusServiceTest {
@Test
public void assertLoadAllComputeNodeInstances() {
- when(repository.getChildrenKeys("/nodes/compute_nodes/online/fixture")).thenReturn(Collections.singletonList("foo_instance_3307"));
- when(repository.get("/nodes/compute_nodes/online/fixture/foo_instance_3307")).thenReturn("127.0.0.1@3307");
- Collection<ComputeNodeInstance> actual = new ComputeNodeStatusService(repository).loadAllComputeNodeInstances();
- assertThat(actual.size(), is(1));
+ when(repository.getChildrenKeys("/nodes/compute_nodes/online/jdbc")).thenReturn(Collections.singletonList("foo_instance_3307"));
+ when(repository.getChildrenKeys("/nodes/compute_nodes/online/proxy")).thenReturn(Collections.singletonList("foo_instance_3308"));
+ when(repository.get("/nodes/compute_nodes/online/proxy/foo_instance_3308")).thenReturn("127.0.0.1@3308");
+ List<ComputeNodeInstance> actual = new ArrayList<>(new ComputeNodeStatusService(repository).loadAllComputeNodeInstances());
+ assertThat(actual.size(), is(2));
+ // TODO assert more
}
@Test
public void assertLoadComputeNodeInstance() {
- InstanceDefinition instanceDefinition = new InstanceDefinition("foo_instance_id", "Proxy", 3307);
+ InstanceDefinition instanceDefinition = new ProxyInstanceDefinition("foo_instance_id", 3307);
ComputeNodeInstance actual = new ComputeNodeStatusService(repository).loadComputeNodeInstance(instanceDefinition);
assertThat(actual.getInstanceDefinition(), is(instanceDefinition));
}
diff --git a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/StandaloneContextManagerBuilder.java b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/StandaloneContextManagerBuilder.java
index b72ebcc2b5a..75710dca76b 100644
--- a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/StandaloneContextManagerBuilder.java
+++ b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/StandaloneContextManagerBuilder.java
@@ -24,6 +24,7 @@ import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
import org.apache.shardingsphere.infra.federation.optimizer.context.OptimizerContextFactory;
import org.apache.shardingsphere.infra.instance.ComputeNodeInstance;
import org.apache.shardingsphere.infra.instance.InstanceContext;
+import org.apache.shardingsphere.infra.instance.definition.jdbc.JDBCInstanceDefinition;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabasesFactory;
@@ -64,7 +65,7 @@ public final class StandaloneContextManagerBuilder implements ContextManagerBuil
}
private MetaDataContexts createMetaDataContexts(final MetaDataPersistService persistService, final ContextManagerBuilderParameter parameter) throws SQLException {
- Collection<String> databaseNames = -1 == parameter.getInstanceDefinition().getPort()
+ Collection<String> databaseNames = parameter.getInstanceDefinition() instanceof JDBCInstanceDefinition
? parameter.getDatabaseConfigs().keySet()
: persistService.getSchemaMetaDataService().loadAllDatabaseNames();
Map<String, DatabaseConfiguration> databaseConfigMap = getDatabaseConfigMap(databaseNames, persistService, parameter);
diff --git a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/standalone/StandaloneContextManagerBuilderTextTest.java b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/standalone/StandaloneContextManagerBuilderTextTest.java
index 40d5d6c3c74..6e32abdc94f 100644
--- a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/standalone/StandaloneContextManagerBuilderTextTest.java
+++ b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/standalone/StandaloneContextManagerBuilderTextTest.java
@@ -22,6 +22,7 @@ import org.apache.shardingsphere.infra.config.database.DatabaseConfiguration;
import org.apache.shardingsphere.infra.config.database.impl.DataSourceProvidedDatabaseConfiguration;
import org.apache.shardingsphere.infra.config.mode.ModeConfiguration;
import org.apache.shardingsphere.infra.instance.definition.InstanceDefinition;
+import org.apache.shardingsphere.infra.instance.definition.proxy.ProxyInstanceDefinition;
import org.apache.shardingsphere.mode.manager.ContextManager;
import org.apache.shardingsphere.mode.manager.ContextManagerBuilderParameter;
import org.apache.shardingsphere.mode.metadata.persist.node.DatabaseMetaDataNode;
@@ -37,7 +38,6 @@ import java.util.Collections;
import java.util.Map;
import java.util.Properties;
import java.util.UUID;
-import java.util.concurrent.ThreadLocalRandom;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
@@ -62,7 +62,7 @@ public final class StandaloneContextManagerBuilderTextTest {
Map<String, DatabaseConfiguration> databaseConfigs = Collections.singletonMap(
"foo_db", new DataSourceProvidedDatabaseConfiguration(Collections.singletonMap("foo_ds", new MockedDataSource()), Collections.singleton(mock(RuleConfiguration.class))));
Collection<RuleConfiguration> globalRuleConfigs = Collections.singleton(mock(RuleConfiguration.class));
- InstanceDefinition instanceDefinition = new InstanceDefinition(new UUID(ThreadLocalRandom.current().nextLong(), ThreadLocalRandom.current().nextLong()).toString(), "Proxy", 3307);
+ InstanceDefinition instanceDefinition = new ProxyInstanceDefinition(UUID.randomUUID().toString(), 3307);
return new ContextManagerBuilderParameter(modeConfig, databaseConfigs, globalRuleConfigs, new Properties(), Collections.emptyList(), instanceDefinition);
}
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/ShowInstanceHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/ShowInstanceHandler.java
index ba1e6eb9e06..0e728a5f786 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/ShowInstanceHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/ShowInstanceHandler.java
@@ -19,6 +19,9 @@ package org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.queryabl
import org.apache.shardingsphere.distsql.parser.statement.ral.common.queryable.ShowInstanceStatement;
import org.apache.shardingsphere.infra.instance.ComputeNodeInstance;
+import org.apache.shardingsphere.infra.instance.definition.InstanceDefinition;
+import org.apache.shardingsphere.infra.instance.definition.InstanceType;
+import org.apache.shardingsphere.infra.instance.definition.proxy.ProxyInstanceDefinition;
import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
import org.apache.shardingsphere.mode.manager.ContextManager;
import org.apache.shardingsphere.proxy.backend.text.distsql.ral.QueryableRALBackendHandler;
@@ -58,13 +61,15 @@ public final class ShowInstanceHandler extends QueryableRALBackendHandler<ShowIn
return Collections.singletonList(buildRow(contextManager.getInstanceContext().getInstance(), modeType));
}
Collection<ComputeNodeInstance> instances = contextManager.getInstanceContext().getComputeNodeInstances().stream()
- .filter(each -> "Proxy".equals(each.getInstanceDefinition().getInstanceType())).collect(Collectors.toList());
+ .filter(each -> InstanceType.PROXY == each.getInstanceDefinition().getInstanceType()).collect(Collectors.toList());
return instances.isEmpty() ? Collections.emptyList() : instances.stream().filter(Objects::nonNull).map(each -> buildRow(each, modeType)).collect(Collectors.toList());
}
private LocalDataQueryResultRow buildRow(final ComputeNodeInstance instance, final String modeType) {
String labels = null == instance.getLabels() ? "" : String.join(",", instance.getLabels());
- return new LocalDataQueryResultRow(instance.getInstanceDefinition().getInstanceId(),
- instance.getInstanceDefinition().getIp(), instance.getInstanceDefinition().getPort(), instance.getState().getCurrentState().name(), modeType, labels);
+ InstanceDefinition instanceDefinition = instance.getInstanceDefinition();
+ return new LocalDataQueryResultRow(instanceDefinition.getInstanceId(), instanceDefinition.getIp(),
+ instanceDefinition instanceof ProxyInstanceDefinition ? ((ProxyInstanceDefinition) instanceDefinition).getPort() : -1,
+ instance.getState().getCurrentState().name(), modeType, labels);
}
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.instance.definition.InstanceDefinitionBuilder b/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.instance.definition.InstanceDefinitionBuilder
deleted file mode 100644
index da2dbf527b3..00000000000
--- a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.instance.definition.InstanceDefinitionBuilder
+++ /dev/null
@@ -1,18 +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.
-#
-
-org.apache.shardingsphere.proxy.instance.ProxyInstanceDefinitionBuilder