From b5bdbd604c6badbd036d83d178740febad89f817 Mon Sep 17 00:00:00 2001 From: zhangliang Date: Sat, 14 Dec 2024 00:33:53 +0800 Subject: [PATCH] Move QualifiedDataSourceDeletedEvent to mode module --- ...dwriteSplittingQualifiedDataSourceDeletedSubscriber.java | 3 ++- .../ReadwriteSplittingStaticDataSourceRuleAttribute.java | 4 ++-- ...teSplittingQualifiedDataSourceDeletedSubscriberTest.java | 3 ++- ...ReadwriteSplittingStaticDataSourceRuleAttributeTest.java | 6 +++--- .../event/deliver/pojo/QualifiedDataSourceDeletedEvent.java | 6 +++--- 5 files changed, 12 insertions(+), 10 deletions(-) rename features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/cluster/ReadwriteSplittingQualifiedDataSourceDeletedEvent.java => mode/api/src/main/java/org/apache/shardingsphere/mode/event/deliver/pojo/QualifiedDataSourceDeletedEvent.java (83%) diff --git a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/cluster/ReadwriteSplittingQualifiedDataSourceDeletedSubscriber.java b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/cluster/ReadwriteSplittingQualifiedDataSourceDeletedSubscriber.java index e730c4e5f6e16..73d5936091ada 100644 --- a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/cluster/ReadwriteSplittingQualifiedDataSourceDeletedSubscriber.java +++ b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/cluster/ReadwriteSplittingQualifiedDataSourceDeletedSubscriber.java @@ -21,6 +21,7 @@ import lombok.RequiredArgsConstructor; import org.apache.shardingsphere.infra.util.eventbus.EventSubscriber; import org.apache.shardingsphere.metadata.persist.node.QualifiedDataSourceNode; +import org.apache.shardingsphere.mode.event.deliver.pojo.QualifiedDataSourceDeletedEvent; import org.apache.shardingsphere.mode.spi.PersistRepository; /** @@ -37,7 +38,7 @@ public final class ReadwriteSplittingQualifiedDataSourceDeletedSubscriber implem * @param event qualified data source deleted event */ @Subscribe - public void delete(final ReadwriteSplittingQualifiedDataSourceDeletedEvent event) { + public void delete(final QualifiedDataSourceDeletedEvent event) { repository.delete(QualifiedDataSourceNode.getQualifiedDataSourceNodePath(event.getQualifiedDataSource())); } } diff --git a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/rule/attribute/ReadwriteSplittingStaticDataSourceRuleAttribute.java b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/rule/attribute/ReadwriteSplittingStaticDataSourceRuleAttribute.java index 6667067e160b2..c6254d814b700 100644 --- a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/rule/attribute/ReadwriteSplittingStaticDataSourceRuleAttribute.java +++ b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/rule/attribute/ReadwriteSplittingStaticDataSourceRuleAttribute.java @@ -23,7 +23,7 @@ import org.apache.shardingsphere.infra.metadata.database.schema.QualifiedDataSource; import org.apache.shardingsphere.infra.rule.attribute.datasource.StaticDataSourceRuleAttribute; import org.apache.shardingsphere.infra.state.datasource.DataSourceState; -import org.apache.shardingsphere.readwritesplitting.cluster.ReadwriteSplittingQualifiedDataSourceDeletedEvent; +import org.apache.shardingsphere.mode.event.deliver.pojo.QualifiedDataSourceDeletedEvent; import org.apache.shardingsphere.readwritesplitting.exception.logic.ReadwriteSplittingDataSourceRuleNotFoundException; import org.apache.shardingsphere.readwritesplitting.rule.ReadwriteSplittingDataSourceGroupRule; @@ -69,6 +69,6 @@ public void cleanStorageNodeDataSources() { private void deleteStorageNodeDataSources(final ReadwriteSplittingDataSourceGroupRule rule) { rule.getReadwriteSplittingGroup().getReadDataSources().forEach(each -> computeNodeInstanceContext.getEventBusContext() - .post(new ReadwriteSplittingQualifiedDataSourceDeletedEvent(new QualifiedDataSource(databaseName, rule.getName(), each)))); + .post(new QualifiedDataSourceDeletedEvent(new QualifiedDataSource(databaseName, rule.getName(), each)))); } } diff --git a/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/cluster/ReadwriteSplittingQualifiedDataSourceDeletedSubscriberTest.java b/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/cluster/ReadwriteSplittingQualifiedDataSourceDeletedSubscriberTest.java index 66b2bc9a67c67..60cb412bd8ced 100644 --- a/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/cluster/ReadwriteSplittingQualifiedDataSourceDeletedSubscriberTest.java +++ b/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/cluster/ReadwriteSplittingQualifiedDataSourceDeletedSubscriberTest.java @@ -18,6 +18,7 @@ package org.apache.shardingsphere.readwritesplitting.cluster; import org.apache.shardingsphere.infra.metadata.database.schema.QualifiedDataSource; +import org.apache.shardingsphere.mode.event.deliver.pojo.QualifiedDataSourceDeletedEvent; import org.apache.shardingsphere.mode.spi.PersistRepository; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -42,7 +43,7 @@ void setUp() { @Test void assertDeleteStorageNodeDataSourceDataSourceState() { - subscriber.delete(new ReadwriteSplittingQualifiedDataSourceDeletedEvent(new QualifiedDataSource("foo_db", "foo_group", "foo_ds"))); + subscriber.delete(new QualifiedDataSourceDeletedEvent(new QualifiedDataSource("foo_db", "foo_group", "foo_ds"))); verify(repository).delete("/nodes/qualified_data_sources/foo_db.foo_group.foo_ds"); } } diff --git a/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/rule/attribute/ReadwriteSplittingStaticDataSourceRuleAttributeTest.java b/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/rule/attribute/ReadwriteSplittingStaticDataSourceRuleAttributeTest.java index 23fa810329a8b..96f744e6b1c12 100644 --- a/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/rule/attribute/ReadwriteSplittingStaticDataSourceRuleAttributeTest.java +++ b/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/rule/attribute/ReadwriteSplittingStaticDataSourceRuleAttributeTest.java @@ -20,7 +20,7 @@ import org.apache.shardingsphere.infra.instance.ComputeNodeInstanceContext; import org.apache.shardingsphere.infra.metadata.database.schema.QualifiedDataSource; import org.apache.shardingsphere.infra.state.datasource.DataSourceState; -import org.apache.shardingsphere.readwritesplitting.cluster.ReadwriteSplittingQualifiedDataSourceDeletedEvent; +import org.apache.shardingsphere.mode.event.deliver.pojo.QualifiedDataSourceDeletedEvent; import org.apache.shardingsphere.readwritesplitting.exception.logic.ReadwriteSplittingDataSourceRuleNotFoundException; import org.apache.shardingsphere.readwritesplitting.rule.ReadwriteSplittingDataSourceGroupRule; import org.junit.jupiter.api.Test; @@ -75,7 +75,7 @@ void assertCleanStorageNodeDataSource() { ReadwriteSplittingStaticDataSourceRuleAttribute ruleAttribute = new ReadwriteSplittingStaticDataSourceRuleAttribute( "foo_db", Collections.singletonMap("foo_group", dataSourceGroupRule), computeNodeInstanceContext); ruleAttribute.cleanStorageNodeDataSource("foo_group"); - verify(computeNodeInstanceContext.getEventBusContext()).post(deepEq(new ReadwriteSplittingQualifiedDataSourceDeletedEvent(new QualifiedDataSource("foo_db.foo_group.read_ds")))); + verify(computeNodeInstanceContext.getEventBusContext()).post(deepEq(new QualifiedDataSourceDeletedEvent(new QualifiedDataSource("foo_db.foo_group.read_ds")))); } @Test @@ -87,6 +87,6 @@ void assertCleanStorageNodeDataSources() { ReadwriteSplittingStaticDataSourceRuleAttribute ruleAttribute = new ReadwriteSplittingStaticDataSourceRuleAttribute( "foo_db", Collections.singletonMap("foo_group", dataSourceGroupRule), computeNodeInstanceContext); ruleAttribute.cleanStorageNodeDataSources(); - verify(computeNodeInstanceContext.getEventBusContext()).post(deepEq(new ReadwriteSplittingQualifiedDataSourceDeletedEvent(new QualifiedDataSource("foo_db.foo_group.read_ds")))); + verify(computeNodeInstanceContext.getEventBusContext()).post(deepEq(new QualifiedDataSourceDeletedEvent(new QualifiedDataSource("foo_db.foo_group.read_ds")))); } } diff --git a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/cluster/ReadwriteSplittingQualifiedDataSourceDeletedEvent.java b/mode/api/src/main/java/org/apache/shardingsphere/mode/event/deliver/pojo/QualifiedDataSourceDeletedEvent.java similarity index 83% rename from features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/cluster/ReadwriteSplittingQualifiedDataSourceDeletedEvent.java rename to mode/api/src/main/java/org/apache/shardingsphere/mode/event/deliver/pojo/QualifiedDataSourceDeletedEvent.java index 9d8b26d6bd394..bab5b1395c20c 100644 --- a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/cluster/ReadwriteSplittingQualifiedDataSourceDeletedEvent.java +++ b/mode/api/src/main/java/org/apache/shardingsphere/mode/event/deliver/pojo/QualifiedDataSourceDeletedEvent.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.readwritesplitting.cluster; +package org.apache.shardingsphere.mode.event.deliver.pojo; import lombok.Getter; import lombok.RequiredArgsConstructor; @@ -23,11 +23,11 @@ import org.apache.shardingsphere.infra.util.event.DeliverEvent; /** - * Readwrite-splitting qualified data source deleted event. + * Qualified data source deleted event. */ @RequiredArgsConstructor @Getter -public final class ReadwriteSplittingQualifiedDataSourceDeletedEvent implements DeliverEvent { +public final class QualifiedDataSourceDeletedEvent implements DeliverEvent { private final QualifiedDataSource qualifiedDataSource; }