You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by me...@apache.org on 2022/06/25 16:53:05 UTC
[shardingsphere] branch master updated: Refactor InstanceDefinition's constructor to distinguish InstanceType (#18594)
This is an automated email from the ASF dual-hosted git repository.
menghaoran 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 0c5dca254a7 Refactor InstanceDefinition's constructor to distinguish InstanceType (#18594)
0c5dca254a7 is described below
commit 0c5dca254a7cccd28579fd1c887dd900f722ef36
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Sun Jun 26 00:53:00 2022 +0800
Refactor InstanceDefinition's constructor to distinguish InstanceType (#18594)
---
.../infra/instance/ComputeNodeInstance.java | 4 ++--
.../instance/definition/InstanceDefinition.java | 18 ++++++++--------
.../core/datasource/ShardingSphereDataSource.java | 2 +-
.../core/connection/ConnectionManagerTest.java | 4 ++--
.../algorithm/engine/TrafficEngineTest.java | 2 +-
.../compute/service/ComputeNodeStatusService.java | 24 +++++++++++----------
.../watcher/ComputeNodeStateChangedWatcher.java | 25 +++++++++++-----------
.../ClusterContextManagerCoordinatorTest.java | 11 +++++-----
.../lock/DistributedLockContextTest.java | 9 ++++----
.../service/ComputeNodeStatusServiceTest.java | 15 ++++++-------
.../StandaloneContextManagerBuilderTextTest.java | 2 +-
.../proxy/initializer/BootstrapInitializer.java | 2 +-
12 files changed, 58 insertions(+), 60 deletions(-)
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/instance/ComputeNodeInstance.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/instance/ComputeNodeInstance.java
index 24faee66088..85cb12122b4 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/instance/ComputeNodeInstance.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/instance/ComputeNodeInstance.java
@@ -36,10 +36,10 @@ public final class ComputeNodeInstance {
private final InstanceDefinition instanceDefinition;
- private Collection<String> labels;
-
private final StateContext state = new StateContext();
+ private Collection<String> labels;
+
private Long workerId;
/**
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 452c95855c6..b30c8bc8a08 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
@@ -34,25 +34,25 @@ public final class InstanceDefinition {
private static final String DELIMITER = "@";
- private static final AtomicLong ATOMIC_LONG = new AtomicLong();
+ private static final AtomicLong COUNTER = new AtomicLong();
private final InstanceType instanceType;
private final String instanceId;
- private String ip;
+ private final String ip;
- private String uniqueSign;
+ private final String uniqueSign;
- public InstanceDefinition(final InstanceType instanceType, final String instanceId) {
- this.instanceType = instanceType;
+ public InstanceDefinition(final String instanceId) {
+ instanceType = InstanceType.JDBC;
this.instanceId = instanceId;
ip = IpUtils.getIp();
- uniqueSign = String.join("", ManagementFactory.getRuntimeMXBean().getName().split(DELIMITER)[0], String.valueOf(ATOMIC_LONG.incrementAndGet()));
+ uniqueSign = String.join("", ManagementFactory.getRuntimeMXBean().getName().split(DELIMITER)[0], String.valueOf(COUNTER.incrementAndGet()));
}
- public InstanceDefinition(final InstanceType instanceType, final Integer port, final String instanceId) {
- this.instanceType = instanceType;
+ public InstanceDefinition(final int port, final String instanceId) {
+ instanceType = InstanceType.PROXY;
this.instanceId = instanceId;
ip = IpUtils.getIp();
uniqueSign = String.valueOf(port);
@@ -69,7 +69,7 @@ public final class InstanceDefinition {
/**
* Get instance attributes.
*
- * @return ip@uniqueSign
+ * @return got instance attributes, format is ip@uniqueSign
*/
public String getAttributes() {
return Joiner.on(DELIMITER).join(ip, uniqueSign);
diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/datasource/ShardingSphereDataSource.java b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/datasource/ShardingSphereDataSource.java
index 161cf3e817c..76bbbca67fd 100644
--- a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/datasource/ShardingSphereDataSource.java
+++ b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/datasource/ShardingSphereDataSource.java
@@ -75,7 +75,7 @@ public final class ShardingSphereDataSource extends AbstractDataSourceAdapter im
private ContextManager createContextManager(final String databaseName, final ModeConfiguration modeConfig, final Map<String, DataSource> dataSourceMap,
final Collection<RuleConfiguration> ruleConfigs, final Properties props) throws SQLException {
- InstanceDefinition instanceDefinition = new InstanceDefinition(InstanceType.JDBC, InstanceIdGeneratorFactory.getInstance(modeConfig).generate(InstanceType.JDBC));
+ InstanceDefinition instanceDefinition = new InstanceDefinition(InstanceIdGeneratorFactory.getInstance(modeConfig).generate(InstanceType.JDBC));
Collection<RuleConfiguration> globalRuleConfigs = ruleConfigs.stream().filter(each -> each instanceof GlobalRuleConfiguration).collect(Collectors.toList());
ContextManagerBuilderParameter parameter = new ContextManagerBuilderParameter(modeConfig, Collections.singletonMap(databaseName,
new DataSourceProvidedDatabaseConfiguration(dataSourceMap, ruleConfigs)), globalRuleConfigs, props, Collections.emptyList(), instanceDefinition);
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 271f7a05f64..143f65b632a 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
@@ -95,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(InstanceType.PROXY, Arrays.asList("OLTP", "OLAP"))).thenReturn(Collections.singletonList(new InstanceDefinition(InstanceType.PROXY,
- "127.0.0.1@3307", "127.0.0.1@3307")));
+ when(result.getInstanceContext().getComputeNodeInstances(InstanceType.PROXY, Arrays.asList("OLTP", "OLAP"))).thenReturn(
+ Collections.singletonList(new InstanceDefinition(InstanceType.PROXY, "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/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 dd3a8bd80fa..befd048a2d2 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
@@ -92,7 +92,7 @@ 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(InstanceType.PROXY, 3307, "127.0.0.1@3307"));
+ when(loadBalancer.getInstanceId("traffic", instanceIds)).thenReturn(new InstanceDefinition(3307, "127.0.0.1@3307"));
when(strategyRule.getLoadBalancer()).thenReturn(loadBalancer);
when(strategyRule.getName()).thenReturn("traffic");
when(instanceContext.getComputeNodeInstances(InstanceType.PROXY, Arrays.asList("OLTP", "OLAP"))).thenReturn(instanceIds);
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 59893674fe4..1f9ceb12c8f 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
@@ -28,9 +28,10 @@ import org.apache.shardingsphere.mode.metadata.persist.node.ComputeNode;
import org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepository;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.Collection;
+import java.util.LinkedList;
import java.util.Optional;
+import java.util.stream.Collectors;
/**
* Compute node status service.
@@ -47,8 +48,7 @@ public final class ComputeNodeStatusService {
* @param instanceDefinition instance definition
*/
public void registerOnline(final InstanceDefinition instanceDefinition) {
- repository.persistEphemeral(ComputeNode.getOnlineInstanceNodePath(instanceDefinition.getInstanceId(), instanceDefinition.getInstanceType()),
- instanceDefinition.getAttributes());
+ repository.persistEphemeral(ComputeNode.getOnlineInstanceNodePath(instanceDefinition.getInstanceId(), instanceDefinition.getInstanceType()), instanceDefinition.getAttributes());
}
/**
@@ -119,17 +119,19 @@ public final class ComputeNodeStatusService {
* @return compute node instances
*/
public Collection<ComputeNodeInstance> loadAllComputeNodeInstances() {
- Collection<ComputeNodeInstance> result = new ArrayList<>();
- Arrays.stream(InstanceType.values()).forEach(instanceType -> {
- Collection<String> onlineComputeNodes = repository.getChildrenKeys(ComputeNode.getOnlineNodePath(instanceType));
- onlineComputeNodes.forEach(each -> {
- InstanceDefinition instanceDefinition = new InstanceDefinition(instanceType, each, repository.get(ComputeNode.getOnlineInstanceNodePath(each, instanceType)));
- result.add(loadComputeNodeInstance(instanceDefinition));
- });
- });
+ Collection<ComputeNodeInstance> result = new LinkedList<>();
+ for (InstanceType each : InstanceType.values()) {
+ result.addAll(loadComputeNodeInstances(each));
+ }
return result;
}
+ private Collection<ComputeNodeInstance> loadComputeNodeInstances(final InstanceType type) {
+ Collection<String> onlineComputeNodes = repository.getChildrenKeys(ComputeNode.getOnlineNodePath(type));
+ return onlineComputeNodes.stream()
+ .map(each -> loadComputeNodeInstance(new InstanceDefinition(type, each, repository.get(ComputeNode.getOnlineInstanceNodePath(each, type))))).collect(Collectors.toList());
+ }
+
/**
* Load compute node instance by instance definition.
*
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 9a473a2bb2e..5bb5928cece 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
@@ -57,6 +57,7 @@ public final class ComputeNodeStateChangedWatcher implements GovernanceWatcher<G
return Arrays.asList(Type.ADDED, Type.UPDATED, Type.DELETED);
}
+ @SuppressWarnings("unchecked")
@Override
public Optional<GovernanceEvent> createGovernanceEvent(final DataChangedEvent event) {
String instanceId = ComputeNode.getInstanceIdByComputeNode(event.getKey());
@@ -64,9 +65,11 @@ public final class ComputeNodeStateChangedWatcher implements GovernanceWatcher<G
if (event.getKey().equals(ComputeNode.getInstanceStatusNodePath(instanceId))) {
Collection<String> status = Strings.isNullOrEmpty(event.getValue()) ? new ArrayList<>() : YamlEngine.unmarshal(event.getValue(), Collection.class);
return Optional.of(new StateEvent(instanceId, status));
- } else if (event.getKey().equals(ComputeNode.getInstanceWorkerIdNodePath(instanceId))) {
+ }
+ if (event.getKey().equals(ComputeNode.getInstanceWorkerIdNodePath(instanceId))) {
return Optional.of(new WorkerIdEvent(instanceId, Strings.isNullOrEmpty(event.getValue()) ? null : Long.valueOf(event.getValue())));
- } else if (event.getKey().equals(ComputeNode.getInstanceLabelsNodePath(instanceId))) {
+ }
+ if (event.getKey().equals(ComputeNode.getInstanceLabelsNodePath(instanceId))) {
return Optional.of(new LabelsEvent(instanceId, Strings.isNullOrEmpty(event.getValue()) ? new ArrayList<>() : YamlEngine.unmarshal(event.getValue(), Collection.class)));
}
} else if (event.getKey().startsWith(ComputeNode.getOnlineInstanceNodePath())) {
@@ -84,24 +87,25 @@ public final class ComputeNodeStateChangedWatcher implements GovernanceWatcher<G
}
if (Type.ADDED == event.getType()) {
return Optional.of(new ShowProcessListTriggerEvent(matcher.group(1), matcher.group(2)));
- } else if (Type.DELETED == event.getType()) {
+ }
+ if (Type.DELETED == event.getType()) {
return Optional.of(new ShowProcessListUnitCompleteEvent(matcher.group(2)));
}
return Optional.empty();
}
private static Matcher getShowProcessTriggerMatcher(final DataChangedEvent event) {
- Pattern pattern = Pattern.compile(ComputeNode.getProcessTriggerNodePatch() + "/([\\S]+):([\\S]+)$", Pattern.CASE_INSENSITIVE);
- return pattern.matcher(event.getKey());
+ return Pattern.compile(ComputeNode.getProcessTriggerNodePatch() + "/([\\S]+):([\\S]+)$", Pattern.CASE_INSENSITIVE).matcher(event.getKey());
}
private Optional<GovernanceEvent> createInstanceEvent(final DataChangedEvent event) {
Matcher matcher = matchInstanceOnlinePath(event.getKey());
if (matcher.find()) {
- InstanceDefinition instanceDefinition = new InstanceDefinition(getInstanceType(matcher.group(1)), matcher.group(2), event.getValue());
+ InstanceDefinition instanceDefinition = new InstanceDefinition(InstanceType.valueOf(matcher.group(1).toUpperCase()), matcher.group(2), event.getValue());
if (Type.ADDED == event.getType()) {
return Optional.of(new InstanceOnlineEvent(instanceDefinition));
- } else if (Type.DELETED == event.getType()) {
+ }
+ if (Type.DELETED == event.getType()) {
return Optional.of(new InstanceOfflineEvent(instanceDefinition));
}
}
@@ -109,11 +113,6 @@ public final class ComputeNodeStateChangedWatcher implements GovernanceWatcher<G
}
private Matcher matchInstanceOnlinePath(final String onlineInstancePath) {
- Pattern pattern = Pattern.compile(ComputeNode.getOnlineInstanceNodePath() + "/" + "(proxy|jdbc)" + "/([\\S]+)$", Pattern.CASE_INSENSITIVE);
- return pattern.matcher(onlineInstancePath);
- }
-
- private InstanceType getInstanceType(final String instanceType) {
- return InstanceType.PROXY.name().equalsIgnoreCase(instanceType) ? InstanceType.PROXY : InstanceType.JDBC;
+ return Pattern.compile(ComputeNode.getOnlineInstanceNodePath() + "/" + "(proxy|jdbc)" + "/([\\S]+)$", Pattern.CASE_INSENSITIVE).matcher(onlineInstancePath);
}
}
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 38cec876fcc..71455884608 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,7 +34,6 @@ 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.InstanceType;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.metadata.database.resource.ShardingSphereResource;
@@ -49,6 +48,7 @@ import org.apache.shardingsphere.infra.state.StateType;
import org.apache.shardingsphere.mode.manager.ContextManager;
import org.apache.shardingsphere.mode.manager.ContextManagerBuilderParameter;
import org.apache.shardingsphere.mode.manager.cluster.ClusterContextManagerBuilder;
+import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.config.event.datasource.DataSourceChangedEvent;
import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.config.event.props.PropertiesChangedEvent;
import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.config.event.rule.GlobalRuleConfigurationsChangedEvent;
import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.config.event.rule.RuleConfigurationsChangedEvent;
@@ -56,7 +56,6 @@ import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.confi
import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.config.event.version.DatabaseVersionChangedEvent;
import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.metadata.event.DatabaseAddedEvent;
import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.metadata.event.DatabaseDeletedEvent;
-import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.config.event.datasource.DataSourceChangedEvent;
import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.metadata.event.SchemaAddedEvent;
import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.process.ShowProcessListManager;
import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.process.lock.ShowProcessListSimpleLock;
@@ -67,8 +66,8 @@ import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.statu
import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.compute.event.ShowProcessListUnitCompleteEvent;
import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.compute.event.StateEvent;
import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.compute.event.WorkerIdEvent;
-import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.storage.event.StorageNodeChangedEvent;
import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.storage.event.PrimaryStateChangedEvent;
+import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.storage.event.StorageNodeChangedEvent;
import org.apache.shardingsphere.mode.manager.cluster.coordinator.util.ReflectionUtil;
import org.apache.shardingsphere.mode.metadata.MetaDataContexts;
import org.apache.shardingsphere.mode.metadata.persist.MetaDataPersistService;
@@ -145,7 +144,7 @@ public final class ClusterContextManagerCoordinatorTest {
private ContextManagerBuilderParameter createContextManagerBuilderParameter() {
ModeConfiguration modeConfig = new ModeConfiguration("Cluster", new ClusterPersistRepositoryConfiguration("FIXTURE", "", "", new Properties()), false);
- InstanceDefinition instanceDefinition = new InstanceDefinition(InstanceType.PROXY, 3307, "foo_instance_id");
+ InstanceDefinition instanceDefinition = new InstanceDefinition(3307, "foo_instance_id");
return new ContextManagerBuilderParameter(modeConfig, Collections.emptyMap(), Collections.emptyList(), new Properties(), Collections.emptyList(), instanceDefinition);
}
@@ -334,12 +333,12 @@ public final class ClusterContextManagerCoordinatorTest {
@Test
public void assertRenewInstanceOnlineEvent() {
- InstanceDefinition instanceDefinition1 = new InstanceDefinition(InstanceType.PROXY, 3307, "foo_instance_3307");
+ InstanceDefinition instanceDefinition1 = new InstanceDefinition(3307, "foo_instance_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(InstanceType.PROXY, 3308, "foo_instance_3308");
+ InstanceDefinition instanceDefinition2 = new InstanceDefinition(3308, "foo_instance_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 d1d7ca62c95..4257371100e 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
@@ -21,7 +21,6 @@ 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.InstanceType;
import org.apache.shardingsphere.infra.instance.workerid.WorkerIdGenerator;
import org.apache.shardingsphere.infra.lock.ShardingSphereLock;
import org.apache.shardingsphere.mode.manager.lock.definition.LockNameDefinitionFactory;
@@ -39,14 +38,14 @@ public final class DistributedLockContextTest {
@Test
public void assertGetDistributedLock() {
DistributedLockContext distributedLockContext = new DistributedLockContext(mock(ClusterPersistRepository.class));
- ComputeNodeInstance currentInstance = new ComputeNodeInstance(new InstanceDefinition(InstanceType.PROXY, "127.0.0.1@3307"));
+ ComputeNodeInstance currentInstance = new ComputeNodeInstance(new InstanceDefinition(3307, "1"));
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(InstanceType.PROXY, "127.0.0.1@3307"));
+ ComputeNodeInstance currentInstance = new ComputeNodeInstance(new InstanceDefinition(3307, "1"));
DistributedLockContext distributedLockContext = new DistributedLockContext(mock(ClusterPersistRepository.class));
new InstanceContext(currentInstance, mock(WorkerIdGenerator.class), mock(ModeConfiguration.class), distributedLockContext);
assertNotNull(distributedLockContext.getLock());
@@ -54,7 +53,7 @@ public final class DistributedLockContextTest {
@Test
public void assertReleaseLock() {
- ComputeNodeInstance currentInstance = new ComputeNodeInstance(new InstanceDefinition(InstanceType.PROXY, "127.0.0.1@3307"));
+ ComputeNodeInstance currentInstance = new ComputeNodeInstance(new InstanceDefinition(3307, "1"));
DistributedLockContext distributedLockContext = new DistributedLockContext(mock(ClusterPersistRepository.class));
new InstanceContext(currentInstance, mock(WorkerIdGenerator.class), mock(ModeConfiguration.class), distributedLockContext);
distributedLockContext.releaseLock(LockNameDefinitionFactory.newDatabaseDefinition("database"));
@@ -62,7 +61,7 @@ public final class DistributedLockContextTest {
@Test
public void assertIsLockedDatabase() {
- ComputeNodeInstance currentInstance = new ComputeNodeInstance(new InstanceDefinition(InstanceType.PROXY, "127.0.0.1@3307"));
+ ComputeNodeInstance currentInstance = new ComputeNodeInstance(new InstanceDefinition(3307, "1"));
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/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 a0ca06c1641..bfae0728fef 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,7 +19,6 @@ 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.InstanceType;
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;
@@ -47,7 +46,7 @@ public final class ComputeNodeStatusServiceTest {
@Test
public void assertRegisterOnline() {
- InstanceDefinition instanceDefinition = new InstanceDefinition(InstanceType.PROXY, 3307, "foo_instance_id");
+ InstanceDefinition instanceDefinition = new InstanceDefinition(3307, "foo_instance_id");
new ComputeNodeStatusService(repository).registerOnline(instanceDefinition);
verify(repository).persistEphemeral(eq("/nodes/compute_nodes/online/proxy/" + instanceDefinition.getInstanceId()), anyString());
}
@@ -55,7 +54,7 @@ public final class ComputeNodeStatusServiceTest {
@Test
public void assertPersistInstanceLabels() {
ComputeNodeStatusService computeNodeStatusService = new ComputeNodeStatusService(repository);
- InstanceDefinition instanceDefinition = new InstanceDefinition(InstanceType.PROXY, 3307, "foo_instance_id");
+ InstanceDefinition instanceDefinition = new InstanceDefinition(3307, "foo_instance_id");
final String instanceId = instanceDefinition.getInstanceId();
computeNodeStatusService.persistInstanceLabels(instanceId, Collections.singletonList("test"));
verify(repository, times(1)).persistEphemeral(ComputeNode.getInstanceLabelsNodePath(instanceId), YamlEngine.marshal(Collections.singletonList("test")));
@@ -65,7 +64,7 @@ public final class ComputeNodeStatusServiceTest {
@Test
public void assertPersistInstanceWorkerId() {
- InstanceDefinition instanceDefinition = new InstanceDefinition(InstanceType.PROXY, 3307, "foo_instance_id");
+ InstanceDefinition instanceDefinition = new InstanceDefinition(3307, "foo_instance_id");
final String instanceId = instanceDefinition.getInstanceId();
new ComputeNodeStatusService(repository).persistInstanceWorkerId(instanceId, 100L);
verify(repository).persistEphemeral(ComputeNode.getInstanceWorkerIdNodePath(instanceId), String.valueOf(100L));
@@ -73,7 +72,7 @@ public final class ComputeNodeStatusServiceTest {
@Test
public void assertLoadInstanceLabels() {
- InstanceDefinition instanceDefinition = new InstanceDefinition(InstanceType.PROXY, 3307, "foo_instance_id");
+ InstanceDefinition instanceDefinition = new InstanceDefinition(3307, "foo_instance_id");
final String instanceId = instanceDefinition.getInstanceId();
new ComputeNodeStatusService(repository).loadInstanceLabels(instanceId);
verify(repository).get(ComputeNode.getInstanceLabelsNodePath(instanceId));
@@ -81,7 +80,7 @@ public final class ComputeNodeStatusServiceTest {
@Test
public void assertLoadInstanceStatus() {
- InstanceDefinition instanceDefinition = new InstanceDefinition(InstanceType.PROXY, 3307, "foo_instance_id");
+ InstanceDefinition instanceDefinition = new InstanceDefinition(3307, "foo_instance_id");
final String instanceId = instanceDefinition.getInstanceId();
new ComputeNodeStatusService(repository).loadInstanceStatus(instanceId);
verify(repository).get(ComputeNode.getInstanceStatusNodePath(instanceId));
@@ -89,7 +88,7 @@ public final class ComputeNodeStatusServiceTest {
@Test
public void assertLoadInstanceWorkerId() {
- InstanceDefinition instanceDefinition = new InstanceDefinition(InstanceType.PROXY, 3307, "foo_instance_id");
+ InstanceDefinition instanceDefinition = new InstanceDefinition(3307, "foo_instance_id");
final String instanceId = instanceDefinition.getInstanceId();
new ComputeNodeStatusService(repository).loadInstanceWorkerId(instanceId);
verify(repository).get(ComputeNode.getInstanceWorkerIdNodePath(instanceId));
@@ -107,7 +106,7 @@ public final class ComputeNodeStatusServiceTest {
@Test
public void assertLoadComputeNodeInstance() {
- InstanceDefinition instanceDefinition = new InstanceDefinition(InstanceType.PROXY, 3307, "foo_instance_id");
+ InstanceDefinition instanceDefinition = new InstanceDefinition(3307, "foo_instance_id");
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/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 8f5f05ca71e..ba71d3d0d14 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
@@ -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(InstanceType.PROXY, 3307, InstanceIdGeneratorFactory.getInstance(null).generate(InstanceType.PROXY));
+ InstanceDefinition instanceDefinition = new InstanceDefinition(3307, InstanceIdGeneratorFactory.getInstance(null).generate(InstanceType.PROXY));
return new ContextManagerBuilderParameter(modeConfig, databaseConfigs, globalRuleConfigs, new Properties(), Collections.emptyList(), instanceDefinition);
}
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/initializer/BootstrapInitializer.java b/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/initializer/BootstrapInitializer.java
index 358dd4c801c..3d5a016e130 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/initializer/BootstrapInitializer.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/initializer/BootstrapInitializer.java
@@ -61,7 +61,7 @@ public final class BootstrapInitializer {
private ContextManager createContextManager(final YamlProxyConfiguration yamlConfig, final ModeConfiguration modeConfig, final int port) throws SQLException {
ProxyConfiguration proxyConfig = new YamlProxyConfigurationSwapper().swap(yamlConfig);
- InstanceDefinition instanceDefinition = new InstanceDefinition(InstanceType.PROXY, port, InstanceIdGeneratorFactory.getInstance(modeConfig).generate(InstanceType.PROXY));
+ InstanceDefinition instanceDefinition = new InstanceDefinition(port, InstanceIdGeneratorFactory.getInstance(modeConfig).generate(InstanceType.PROXY));
ContextManagerBuilderParameter parameter = new ContextManagerBuilderParameter(modeConfig, proxyConfig.getDatabaseConfigurations(),
proxyConfig.getGlobalConfiguration().getRules(), proxyConfig.getGlobalConfiguration().getProperties(), proxyConfig.getGlobalConfiguration().getLabels(), instanceDefinition);
return ContextManagerBuilderFactory.getInstance(modeConfig).build(parameter);