Skip to content

Commit

Permalink
Move QualifiedDataSourceDeletedEvent to mode module
Browse files Browse the repository at this point in the history
  • Loading branch information
terrymanu committed Dec 13, 2024
1 parent 6912699 commit b5bdbd6
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -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()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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))));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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"))));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@
* limitations under the License.
*/

package org.apache.shardingsphere.readwritesplitting.cluster;
package org.apache.shardingsphere.mode.event.deliver.pojo;

import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.infra.metadata.database.schema.QualifiedDataSource;
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;
}

0 comments on commit b5bdbd6

Please sign in to comment.