diff --git a/agent/plugins/core/src/main/java/org/apache/shardingsphere/agent/plugin/core/context/PluginContext.java b/agent/plugins/core/src/main/java/org/apache/shardingsphere/agent/plugin/core/context/PluginContext.java index 2e0a87c2b4716..c72a419351f37 100644 --- a/agent/plugins/core/src/main/java/org/apache/shardingsphere/agent/plugin/core/context/PluginContext.java +++ b/agent/plugins/core/src/main/java/org/apache/shardingsphere/agent/plugin/core/context/PluginContext.java @@ -20,7 +20,7 @@ import lombok.AccessLevel; import lombok.NoArgsConstructor; import lombok.Setter; -import org.apache.shardingsphere.agent.plugin.core.holder.ShardingSphereDataSourceHolder; +import org.apache.shardingsphere.agent.plugin.core.holder.ShardingSphereDataSourceContextHolder; import org.apache.shardingsphere.infra.config.props.ConfigurationPropertyKey; import org.apache.shardingsphere.mode.manager.ContextManager; import org.apache.shardingsphere.proxy.backend.context.ProxyContext; @@ -65,8 +65,8 @@ private Optional getContextManager() { if (isEnhancedForProxy) { return Optional.ofNullable(ProxyContext.getInstance().getContextManager()); } - return ShardingSphereDataSourceHolder.getShardingSphereDataSourceContexts().isEmpty() + return ShardingSphereDataSourceContextHolder.getShardingSphereDataSourceContexts().isEmpty() ? Optional.empty() - : Optional.of(ShardingSphereDataSourceHolder.getShardingSphereDataSourceContexts().values().iterator().next().getContextManager()); + : Optional.of(ShardingSphereDataSourceContextHolder.getShardingSphereDataSourceContexts().values().iterator().next().getContextManager()); } } diff --git a/agent/plugins/core/src/main/java/org/apache/shardingsphere/agent/plugin/core/holder/ShardingSphereDataSourceContext.java b/agent/plugins/core/src/main/java/org/apache/shardingsphere/agent/plugin/core/context/ShardingSphereDataSourceContext.java similarity index 89% rename from agent/plugins/core/src/main/java/org/apache/shardingsphere/agent/plugin/core/holder/ShardingSphereDataSourceContext.java rename to agent/plugins/core/src/main/java/org/apache/shardingsphere/agent/plugin/core/context/ShardingSphereDataSourceContext.java index 2390a4bbf2e81..f5344fa004594 100644 --- a/agent/plugins/core/src/main/java/org/apache/shardingsphere/agent/plugin/core/holder/ShardingSphereDataSourceContext.java +++ b/agent/plugins/core/src/main/java/org/apache/shardingsphere/agent/plugin/core/context/ShardingSphereDataSourceContext.java @@ -5,7 +5,7 @@ * Proprietary and confidential */ -package org.apache.shardingsphere.agent.plugin.core.holder; +package org.apache.shardingsphere.agent.plugin.core.context; import lombok.Getter; import lombok.RequiredArgsConstructor; diff --git a/agent/plugins/core/src/main/java/org/apache/shardingsphere/agent/plugin/core/holder/ShardingSphereDataSourceHolder.java b/agent/plugins/core/src/main/java/org/apache/shardingsphere/agent/plugin/core/holder/ShardingSphereDataSourceContextHolder.java similarity index 92% rename from agent/plugins/core/src/main/java/org/apache/shardingsphere/agent/plugin/core/holder/ShardingSphereDataSourceHolder.java rename to agent/plugins/core/src/main/java/org/apache/shardingsphere/agent/plugin/core/holder/ShardingSphereDataSourceContextHolder.java index a7eb5e18dc563..68fdf298f3b0b 100644 --- a/agent/plugins/core/src/main/java/org/apache/shardingsphere/agent/plugin/core/holder/ShardingSphereDataSourceHolder.java +++ b/agent/plugins/core/src/main/java/org/apache/shardingsphere/agent/plugin/core/holder/ShardingSphereDataSourceContextHolder.java @@ -19,6 +19,7 @@ import lombok.AccessLevel; import lombok.NoArgsConstructor; +import org.apache.shardingsphere.agent.plugin.core.context.ShardingSphereDataSourceContext; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @@ -27,7 +28,7 @@ * Context manager holder. */ @NoArgsConstructor(access = AccessLevel.PRIVATE) -public final class ShardingSphereDataSourceHolder { +public final class ShardingSphereDataSourceContextHolder { private static final Map DATA_SOURCE_CONTEXTS = new ConcurrentHashMap<>(); diff --git a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/jdbc/ShardingSphereDataSourceAdvice.java b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/jdbc/ShardingSphereDataSourceAdvice.java index db8b99f7ec3f4..63e8376d48554 100644 --- a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/jdbc/ShardingSphereDataSourceAdvice.java +++ b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/jdbc/ShardingSphereDataSourceAdvice.java @@ -20,8 +20,8 @@ import org.apache.shardingsphere.agent.api.advice.TargetAdviceMethod; import org.apache.shardingsphere.agent.api.advice.TargetAdviceObject; import org.apache.shardingsphere.agent.plugin.core.advice.AbstractInstanceMethodAdvice; -import org.apache.shardingsphere.agent.plugin.core.holder.ShardingSphereDataSourceContext; -import org.apache.shardingsphere.agent.plugin.core.holder.ShardingSphereDataSourceHolder; +import org.apache.shardingsphere.agent.plugin.core.context.ShardingSphereDataSourceContext; +import org.apache.shardingsphere.agent.plugin.core.holder.ShardingSphereDataSourceContextHolder; import org.apache.shardingsphere.agent.plugin.core.util.AgentReflectionUtils; import org.apache.shardingsphere.mode.manager.ContextManager; @@ -34,14 +34,14 @@ public final class ShardingSphereDataSourceAdvice extends AbstractInstanceMethod public void beforeMethod(final TargetAdviceObject target, final TargetAdviceMethod method, final Object[] args, final String pluginType) { if ("close".equals(method.getName())) { ContextManager contextManager = AgentReflectionUtils.getFieldValue(target, "contextManager"); - ShardingSphereDataSourceHolder.remove(contextManager.getComputeNodeInstanceContext().getInstance().getMetaData().getId()); + ShardingSphereDataSourceContextHolder.remove(contextManager.getComputeNodeInstanceContext().getInstance().getMetaData().getId()); } } @Override public void afterMethod(final TargetAdviceObject target, final TargetAdviceMethod method, final Object[] args, final Object result, final String pluginType) { if ("createContextManager".equals(method.getName())) { - ShardingSphereDataSourceHolder.put(((ContextManager) result).getComputeNodeInstanceContext().getInstance().getMetaData().getId(), + ShardingSphereDataSourceContextHolder.put(((ContextManager) result).getComputeNodeInstanceContext().getInstance().getMetaData().getId(), new ShardingSphereDataSourceContext(AgentReflectionUtils.getFieldValue(target, "databaseName"), (ContextManager) result)); } } diff --git a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/exporter/impl/jdbc/JDBCMetaDataInfoExporter.java b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/exporter/impl/jdbc/JDBCMetaDataInfoExporter.java index 0e778a71e4a1c..40fb92306f7b1 100644 --- a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/exporter/impl/jdbc/JDBCMetaDataInfoExporter.java +++ b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/exporter/impl/jdbc/JDBCMetaDataInfoExporter.java @@ -17,8 +17,8 @@ package org.apache.shardingsphere.agent.plugin.metrics.core.exporter.impl.jdbc; -import org.apache.shardingsphere.agent.plugin.core.holder.ShardingSphereDataSourceContext; -import org.apache.shardingsphere.agent.plugin.core.holder.ShardingSphereDataSourceHolder; +import org.apache.shardingsphere.agent.plugin.core.context.ShardingSphereDataSourceContext; +import org.apache.shardingsphere.agent.plugin.core.holder.ShardingSphereDataSourceContextHolder; import org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsCollectorRegistry; import org.apache.shardingsphere.agent.plugin.metrics.core.collector.type.GaugeMetricFamilyMetricsCollector; import org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricCollectorType; @@ -42,7 +42,7 @@ public final class JDBCMetaDataInfoExporter implements MetricsExporter { public Optional export(final String pluginType) { GaugeMetricFamilyMetricsCollector result = MetricsCollectorRegistry.get(config, pluginType); result.cleanMetrics(); - for (Entry entry : ShardingSphereDataSourceHolder.getShardingSphereDataSourceContexts().entrySet()) { + for (Entry entry : ShardingSphereDataSourceContextHolder.getShardingSphereDataSourceContexts().entrySet()) { Optional.ofNullable(entry.getValue().getContextManager().getDatabase(entry.getValue().getDatabaseName())) .ifPresent(optional -> result.addMetric(Arrays.asList(entry.getKey(), optional.getName(), "storage_unit_count"), optional.getResourceMetaData().getStorageUnits().size())); } diff --git a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/exporter/impl/jdbc/JDBCStateExporter.java b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/exporter/impl/jdbc/JDBCStateExporter.java index b5140add28e12..ee9a7b399359d 100644 --- a/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/exporter/impl/jdbc/JDBCStateExporter.java +++ b/agent/plugins/metrics/core/src/main/java/org/apache/shardingsphere/agent/plugin/metrics/core/exporter/impl/jdbc/JDBCStateExporter.java @@ -17,8 +17,8 @@ package org.apache.shardingsphere.agent.plugin.metrics.core.exporter.impl.jdbc; -import org.apache.shardingsphere.agent.plugin.core.holder.ShardingSphereDataSourceContext; -import org.apache.shardingsphere.agent.plugin.core.holder.ShardingSphereDataSourceHolder; +import org.apache.shardingsphere.agent.plugin.core.context.ShardingSphereDataSourceContext; +import org.apache.shardingsphere.agent.plugin.core.holder.ShardingSphereDataSourceContextHolder; import org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsCollectorRegistry; import org.apache.shardingsphere.agent.plugin.metrics.core.collector.type.GaugeMetricFamilyMetricsCollector; import org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricCollectorType; @@ -41,7 +41,7 @@ public final class JDBCStateExporter implements MetricsExporter { public Optional export(final String pluginType) { GaugeMetricFamilyMetricsCollector result = MetricsCollectorRegistry.get(config, pluginType); result.cleanMetrics(); - for (Entry entry : ShardingSphereDataSourceHolder.getShardingSphereDataSourceContexts().entrySet()) { + for (Entry entry : ShardingSphereDataSourceContextHolder.getShardingSphereDataSourceContexts().entrySet()) { Optional.ofNullable(entry.getValue().getContextManager().getDatabase(entry.getValue().getDatabaseName())) .ifPresent(optional -> result.addMetric(Arrays.asList(entry.getKey(), optional.getName()), entry.getValue().getContextManager().getComputeNodeInstanceContext().getInstance().getState().getCurrentState().ordinal())); diff --git a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/jdbc/ShardingSphereDataSourceAdviceTest.java b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/jdbc/ShardingSphereDataSourceAdviceTest.java index 421ec8c95a75e..fd48e7097dbdf 100644 --- a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/jdbc/ShardingSphereDataSourceAdviceTest.java +++ b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/jdbc/ShardingSphereDataSourceAdviceTest.java @@ -18,8 +18,8 @@ package org.apache.shardingsphere.agent.plugin.metrics.core.advice.jdbc; import org.apache.shardingsphere.agent.api.advice.TargetAdviceMethod; -import org.apache.shardingsphere.agent.plugin.core.holder.ShardingSphereDataSourceContext; -import org.apache.shardingsphere.agent.plugin.core.holder.ShardingSphereDataSourceHolder; +import org.apache.shardingsphere.agent.plugin.core.context.ShardingSphereDataSourceContext; +import org.apache.shardingsphere.agent.plugin.core.holder.ShardingSphereDataSourceContextHolder; import org.apache.shardingsphere.agent.plugin.core.util.AgentReflectionUtils; import org.apache.shardingsphere.agent.plugin.metrics.core.fixture.TargetAdviceObjectFixture; import org.apache.shardingsphere.mode.manager.ContextManager; @@ -49,34 +49,34 @@ class ShardingSphereDataSourceAdviceTest { @AfterEach void clean() { - ShardingSphereDataSourceHolder.getShardingSphereDataSourceContexts().clear(); + ShardingSphereDataSourceContextHolder.getShardingSphereDataSourceContexts().clear(); } @Test void assertBeforeMethod() { ContextManager contextManager = mockContextManager(); when(AgentReflectionUtils.getFieldValue(fixture, "contextManager")).thenReturn(contextManager); - ShardingSphereDataSourceHolder.put(instanceId, new ShardingSphereDataSourceContext(databaseName, mock(ContextManager.class, RETURNS_DEEP_STUBS))); - assertThat(ShardingSphereDataSourceHolder.getShardingSphereDataSourceContexts().size(), is(1)); + ShardingSphereDataSourceContextHolder.put(instanceId, new ShardingSphereDataSourceContext(databaseName, mock(ContextManager.class, RETURNS_DEEP_STUBS))); + assertThat(ShardingSphereDataSourceContextHolder.getShardingSphereDataSourceContexts().size(), is(1)); TargetAdviceMethod method = mock(TargetAdviceMethod.class); when(method.getName()).thenReturn("close"); ShardingSphereDataSourceAdvice advice = new ShardingSphereDataSourceAdvice(); advice.beforeMethod(fixture, method, new Object[]{}, "FIXTURE"); - assertThat(ShardingSphereDataSourceHolder.getShardingSphereDataSourceContexts().size(), is(0)); + assertThat(ShardingSphereDataSourceContextHolder.getShardingSphereDataSourceContexts().size(), is(0)); } @Test void assertAfterMethod() { - assertThat(ShardingSphereDataSourceHolder.getShardingSphereDataSourceContexts().size(), is(0)); + assertThat(ShardingSphereDataSourceContextHolder.getShardingSphereDataSourceContexts().size(), is(0)); when(AgentReflectionUtils.getFieldValue(fixture, "databaseName")).thenReturn(databaseName); TargetAdviceMethod method = mock(TargetAdviceMethod.class); when(method.getName()).thenReturn("createContextManager"); ShardingSphereDataSourceAdvice advice = new ShardingSphereDataSourceAdvice(); ContextManager contextManager = mockContextManager(); advice.afterMethod(fixture, method, new Object[]{}, contextManager, "FIXTURE"); - assertThat(ShardingSphereDataSourceHolder.getShardingSphereDataSourceContexts().size(), is(1)); - assertThat(ShardingSphereDataSourceHolder.getShardingSphereDataSourceContexts().keySet().iterator().next(), is(instanceId)); - assertThat(ShardingSphereDataSourceHolder.getShardingSphereDataSourceContexts().get(instanceId).getDatabaseName(), is(databaseName)); + assertThat(ShardingSphereDataSourceContextHolder.getShardingSphereDataSourceContexts().size(), is(1)); + assertThat(ShardingSphereDataSourceContextHolder.getShardingSphereDataSourceContexts().keySet().iterator().next(), is(instanceId)); + assertThat(ShardingSphereDataSourceContextHolder.getShardingSphereDataSourceContexts().get(instanceId).getDatabaseName(), is(databaseName)); } private ContextManager mockContextManager() { diff --git a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/exporter/impl/jdbc/JDBCMetaDataInfoExporterTest.java b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/exporter/impl/jdbc/JDBCMetaDataInfoExporterTest.java index c89fc2743f3fa..95c9e7ac68648 100644 --- a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/exporter/impl/jdbc/JDBCMetaDataInfoExporterTest.java +++ b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/exporter/impl/jdbc/JDBCMetaDataInfoExporterTest.java @@ -17,8 +17,8 @@ package org.apache.shardingsphere.agent.plugin.metrics.core.exporter.impl.jdbc; -import org.apache.shardingsphere.agent.plugin.core.holder.ShardingSphereDataSourceContext; -import org.apache.shardingsphere.agent.plugin.core.holder.ShardingSphereDataSourceHolder; +import org.apache.shardingsphere.agent.plugin.core.context.ShardingSphereDataSourceContext; +import org.apache.shardingsphere.agent.plugin.core.holder.ShardingSphereDataSourceContextHolder; import org.apache.shardingsphere.agent.plugin.metrics.core.collector.MetricsCollectorRegistry; import org.apache.shardingsphere.agent.plugin.metrics.core.collector.type.GaugeMetricFamilyMetricsCollector; import org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricCollectorType; @@ -51,13 +51,13 @@ void reset() { MetricCollectorType.GAUGE_METRIC_FAMILY, "Meta data information of ShardingSphere-JDBC", Arrays.asList("driver_instance", "database", "type"), Collections.emptyMap()); ((MetricsCollectorFixture) MetricsCollectorRegistry.get(config, "FIXTURE")).reset(); - ShardingSphereDataSourceHolder.remove("sharding_db"); + ShardingSphereDataSourceContextHolder.remove("sharding_db"); } @Test void assertExport() { String instanceId = UUID.randomUUID().toString(); - ShardingSphereDataSourceHolder.put(instanceId, new ShardingSphereDataSourceContext("sharding_db", mockContextManager("sharding_db"))); + ShardingSphereDataSourceContextHolder.put(instanceId, new ShardingSphereDataSourceContext("sharding_db", mockContextManager("sharding_db"))); Optional collector = new JDBCMetaDataInfoExporter().export("FIXTURE"); assertTrue(collector.isPresent()); assertThat(collector.get().toString(), containsString(instanceId));