From 0374ca32cfe9ab1394816afe007fbde310368f07 Mon Sep 17 00:00:00 2001
From: sodaRyCN <757083350@qq.com>
Date: Wed, 19 Jun 2024 19:22:42 +0800
Subject: [PATCH 01/15] use conf instead of resource
---
build.gradle | 44 ++++++-
eventmesh-admin-server/build.gradle | 23 ++--
.../main/resources => conf}/application.yaml | 0
.../eventmesh-admin.properties | 0
.../main/resources => conf}/eventmesh.sql | 0
eventmesh-admin-server/conf/log4j2.xml | 108 ++++++++++++++++++
.../mapper/EventMeshDataSourceMapper.xml | 0
.../mapper/EventMeshJobInfoMapper.xml | 0
.../mapper/EventMeshMysqlPositionMapper.xml | 0
...EventMeshPositionReporterHistoryMapper.xml | 0
.../EventMeshRuntimeHeartbeatMapper.xml | 0
.../mapper/EventMeshRuntimeHistoryMapper.xml | 0
.../admin/server/ExampleAdminServer.java | 2 +-
13 files changed, 167 insertions(+), 10 deletions(-)
rename eventmesh-admin-server/{src/main/resources => conf}/application.yaml (100%)
rename eventmesh-admin-server/{src/main/resources => conf}/eventmesh-admin.properties (100%)
rename eventmesh-admin-server/{src/main/resources => conf}/eventmesh.sql (100%)
create mode 100644 eventmesh-admin-server/conf/log4j2.xml
rename eventmesh-admin-server/{src/main/resources => conf}/mapper/EventMeshDataSourceMapper.xml (100%)
rename eventmesh-admin-server/{src/main/resources => conf}/mapper/EventMeshJobInfoMapper.xml (100%)
rename eventmesh-admin-server/{src/main/resources => conf}/mapper/EventMeshMysqlPositionMapper.xml (100%)
rename eventmesh-admin-server/{src/main/resources => conf}/mapper/EventMeshPositionReporterHistoryMapper.xml (100%)
rename eventmesh-admin-server/{src/main/resources => conf}/mapper/EventMeshRuntimeHeartbeatMapper.xml (100%)
rename eventmesh-admin-server/{src/main/resources => conf}/mapper/EventMeshRuntimeHistoryMapper.xml (100%)
diff --git a/build.gradle b/build.gradle
index 63e9301a43..0408231fd7 100644
--- a/build.gradle
+++ b/build.gradle
@@ -210,6 +210,48 @@ tasks.register('dist') {
}
}
+tasks.register('dist-admin') {
+ subprojects.forEach { subProject ->
+ dependsOn("${subProject.path}:jar")
+ }
+ def includedProjects =
+ [
+ "eventmesh-admin-server",
+ "eventmesh-common",
+ "eventmesh-spi",
+ "eventmesh-registry:eventmesh-registry-api",
+ "eventmesh-registry:eventmesh-registry-nacos",
+ "eventmesh-openconnect:eventmesh-openconnect-offsetmgmt-plugin:eventmesh-openconnect-offsetmgmt-api"
+ ]
+ doLast {
+ includedProjects.each {
+ def subProject = findProject(it)
+ copy {
+ from subProject.jar.archivePath
+ into rootProject.file('dist/apps')
+ }
+ copy {
+ from subProject.configurations.runtimeClasspath
+ into rootProject.file('dist/lib')
+ exclude 'eventmesh-*'
+ }
+ copy {
+ from subProject.file('bin')
+ into rootProject.file('dist/bin')
+ }
+ copy {
+ from subProject.file('conf')
+ from subProject.sourceSets.main.resources.srcDirs
+ into rootProject.file('dist/conf')
+ duplicatesStrategy = DuplicatesStrategy.EXCLUDE
+ exclude 'META-INF'
+ }
+
+ }
+ }
+
+}
+
tasks.register('installPlugin') {
var pluginProjects = subprojects.findAll {
it.file('gradle.properties').exists()
@@ -754,8 +796,8 @@ subprojects {
dependency "software.amazon.awssdk:s3:2.26.3"
dependency "com.github.rholder:guava-retrying:2.0.0"
- dependency "org.mybatis.spring.boot:mybatis-spring-boot-starter:2.3.2"
dependency "com.alibaba:druid-spring-boot-starter:1.2.23"
+ dependency "com.baomidou:mybatis-plus-boot-starter:3.5.5"
dependency "org.springframework.boot:spring-boot-starter-jetty:2.7.18"
dependency "com.baomidou:mybatis-plus:3.5.7"
dependency "com.mysql:mysql-connector-j:8.4.0"
diff --git a/eventmesh-admin-server/build.gradle b/eventmesh-admin-server/build.gradle
index 6f91f48001..6de881725a 100644
--- a/eventmesh-admin-server/build.gradle
+++ b/eventmesh-admin-server/build.gradle
@@ -31,18 +31,25 @@ dependencies {
implementation "io.grpc:grpc-stub"
implementation "io.grpc:grpc-netty-shaded"
- // https://mvnrepository.com/artifact/com.baomidou/mybatis-plus-boot-starter
- implementation 'com.baomidou:mybatis-plus-boot-starter:3.5.7'
- implementation "org.reflections:reflections:0.10.2"
+ // https://mvnrepository.com/artifact/com.baomidou/mybatis-plus-boot-starter
+ implementation "com.baomidou:mybatis-plus-boot-starter"
- // https://mvnrepository.com/artifact/com.alibaba/druid-spring-boot-starter
- implementation "com.alibaba:druid-spring-boot-starter"
- compileOnly 'com.mysql:mysql-connector-j'
- compileOnly 'org.projectlombok:lombok'
- annotationProcessor 'org.projectlombok:lombok'
+ // https://mvnrepository.com/artifact/com.alibaba/druid-spring-boot-starter
+ implementation "com.alibaba:druid-spring-boot-starter"
+ implementation 'com.mysql:mysql-connector-j'
+ compileOnly 'org.projectlombok:lombok'
+ annotationProcessor 'org.projectlombok:lombok'
}
configurations.implementation {
exclude group: "org.springframework.boot", module: "spring-boot-starter-logging"
}
+sourceSets {
+ main {
+ resources {
+ srcDirs = ['src/main/resources', 'conf']
+ }
+ }
+}
+
diff --git a/eventmesh-admin-server/src/main/resources/application.yaml b/eventmesh-admin-server/conf/application.yaml
similarity index 100%
rename from eventmesh-admin-server/src/main/resources/application.yaml
rename to eventmesh-admin-server/conf/application.yaml
diff --git a/eventmesh-admin-server/src/main/resources/eventmesh-admin.properties b/eventmesh-admin-server/conf/eventmesh-admin.properties
similarity index 100%
rename from eventmesh-admin-server/src/main/resources/eventmesh-admin.properties
rename to eventmesh-admin-server/conf/eventmesh-admin.properties
diff --git a/eventmesh-admin-server/src/main/resources/eventmesh.sql b/eventmesh-admin-server/conf/eventmesh.sql
similarity index 100%
rename from eventmesh-admin-server/src/main/resources/eventmesh.sql
rename to eventmesh-admin-server/conf/eventmesh.sql
diff --git a/eventmesh-admin-server/conf/log4j2.xml b/eventmesh-admin-server/conf/log4j2.xml
new file mode 100644
index 0000000000..6341a0e629
--- /dev/null
+++ b/eventmesh-admin-server/conf/log4j2.xml
@@ -0,0 +1,108 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/eventmesh-admin-server/src/main/resources/mapper/EventMeshDataSourceMapper.xml b/eventmesh-admin-server/conf/mapper/EventMeshDataSourceMapper.xml
similarity index 100%
rename from eventmesh-admin-server/src/main/resources/mapper/EventMeshDataSourceMapper.xml
rename to eventmesh-admin-server/conf/mapper/EventMeshDataSourceMapper.xml
diff --git a/eventmesh-admin-server/src/main/resources/mapper/EventMeshJobInfoMapper.xml b/eventmesh-admin-server/conf/mapper/EventMeshJobInfoMapper.xml
similarity index 100%
rename from eventmesh-admin-server/src/main/resources/mapper/EventMeshJobInfoMapper.xml
rename to eventmesh-admin-server/conf/mapper/EventMeshJobInfoMapper.xml
diff --git a/eventmesh-admin-server/src/main/resources/mapper/EventMeshMysqlPositionMapper.xml b/eventmesh-admin-server/conf/mapper/EventMeshMysqlPositionMapper.xml
similarity index 100%
rename from eventmesh-admin-server/src/main/resources/mapper/EventMeshMysqlPositionMapper.xml
rename to eventmesh-admin-server/conf/mapper/EventMeshMysqlPositionMapper.xml
diff --git a/eventmesh-admin-server/src/main/resources/mapper/EventMeshPositionReporterHistoryMapper.xml b/eventmesh-admin-server/conf/mapper/EventMeshPositionReporterHistoryMapper.xml
similarity index 100%
rename from eventmesh-admin-server/src/main/resources/mapper/EventMeshPositionReporterHistoryMapper.xml
rename to eventmesh-admin-server/conf/mapper/EventMeshPositionReporterHistoryMapper.xml
diff --git a/eventmesh-admin-server/src/main/resources/mapper/EventMeshRuntimeHeartbeatMapper.xml b/eventmesh-admin-server/conf/mapper/EventMeshRuntimeHeartbeatMapper.xml
similarity index 100%
rename from eventmesh-admin-server/src/main/resources/mapper/EventMeshRuntimeHeartbeatMapper.xml
rename to eventmesh-admin-server/conf/mapper/EventMeshRuntimeHeartbeatMapper.xml
diff --git a/eventmesh-admin-server/src/main/resources/mapper/EventMeshRuntimeHistoryMapper.xml b/eventmesh-admin-server/conf/mapper/EventMeshRuntimeHistoryMapper.xml
similarity index 100%
rename from eventmesh-admin-server/src/main/resources/mapper/EventMeshRuntimeHistoryMapper.xml
rename to eventmesh-admin-server/conf/mapper/EventMeshRuntimeHistoryMapper.xml
diff --git a/eventmesh-admin-server/src/main/java/org/apache/eventmesh/admin/server/ExampleAdminServer.java b/eventmesh-admin-server/src/main/java/org/apache/eventmesh/admin/server/ExampleAdminServer.java
index c6a6e16504..7f5fa22dda 100644
--- a/eventmesh-admin-server/src/main/java/org/apache/eventmesh/admin/server/ExampleAdminServer.java
+++ b/eventmesh-admin-server/src/main/java/org/apache/eventmesh/admin/server/ExampleAdminServer.java
@@ -23,7 +23,7 @@
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
-@SpringBootApplication
+@SpringBootApplication()
public class ExampleAdminServer {
public static void main(String[] args) throws Exception {
From f040cf7e6385109589af40ee0f084ed8b217154a Mon Sep 17 00:00:00 2001
From: sodaRyCN <757083350@qq.com>
Date: Sun, 30 Jun 2024 21:00:58 +0800
Subject: [PATCH 02/15] prepare for full and check
---
.../apache/eventmesh/admin/server/Admin.java | 1 +
.../eventmesh/admin/server/AdminServer.java | 11 +++----
.../admin/server/web/BaseServer.java | 6 ++--
.../admin/server/web/GrpcServer.java | 13 ++++----
.../eventmesh/common/AbstractComponent.java | 26 ++++++++++++++++
.../eventmesh/common}/ComponentLifeCycle.java | 6 ++--
.../connector/rdb/canal/RdbDBDefinition.java | 14 +++++++++
.../rdb/canal/RdbTableDefinition.java | 11 +++++++
.../connector/rdb/canal/RdbTableMgr.java | 30 +++++++++++++++++++
.../rdb/canal/SourceConnectorConfig.java | 6 ++--
.../rdb/canal/mysql/MysqlTableDef.java | 17 +++++++++++
.../openconnect/api/connector/Connector.java | 17 ++---------
12 files changed, 119 insertions(+), 39 deletions(-)
create mode 100644 eventmesh-common/src/main/java/org/apache/eventmesh/common/AbstractComponent.java
rename {eventmesh-admin-server/src/main/java/org/apache/eventmesh/admin/server => eventmesh-common/src/main/java/org/apache/eventmesh/common}/ComponentLifeCycle.java (89%)
create mode 100644 eventmesh-common/src/main/java/org/apache/eventmesh/common/config/connector/rdb/canal/RdbDBDefinition.java
create mode 100644 eventmesh-common/src/main/java/org/apache/eventmesh/common/config/connector/rdb/canal/RdbTableDefinition.java
create mode 100644 eventmesh-common/src/main/java/org/apache/eventmesh/common/config/connector/rdb/canal/RdbTableMgr.java
create mode 100644 eventmesh-common/src/main/java/org/apache/eventmesh/common/config/connector/rdb/canal/mysql/MysqlTableDef.java
diff --git a/eventmesh-admin-server/src/main/java/org/apache/eventmesh/admin/server/Admin.java b/eventmesh-admin-server/src/main/java/org/apache/eventmesh/admin/server/Admin.java
index 71c6d67be2..9ee25fadb2 100644
--- a/eventmesh-admin-server/src/main/java/org/apache/eventmesh/admin/server/Admin.java
+++ b/eventmesh-admin-server/src/main/java/org/apache/eventmesh/admin/server/Admin.java
@@ -17,6 +17,7 @@
package org.apache.eventmesh.admin.server;
+import org.apache.eventmesh.common.ComponentLifeCycle;
import org.apache.eventmesh.common.remote.Task;
import org.apache.eventmesh.common.remote.request.ReportHeartBeatRequest;
import org.apache.eventmesh.common.utils.PagedList;
diff --git a/eventmesh-admin-server/src/main/java/org/apache/eventmesh/admin/server/AdminServer.java b/eventmesh-admin-server/src/main/java/org/apache/eventmesh/admin/server/AdminServer.java
index 98247d19b6..ae2736aaaa 100644
--- a/eventmesh-admin-server/src/main/java/org/apache/eventmesh/admin/server/AdminServer.java
+++ b/eventmesh-admin-server/src/main/java/org/apache/eventmesh/admin/server/AdminServer.java
@@ -17,6 +17,8 @@
package org.apache.eventmesh.admin.server;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
import org.apache.eventmesh.common.Constants;
import org.apache.eventmesh.common.config.CommonConfiguration;
import org.apache.eventmesh.common.config.ConfigService;
@@ -28,16 +30,11 @@
import org.apache.eventmesh.registry.RegisterServerInfo;
import org.apache.eventmesh.registry.RegistryFactory;
import org.apache.eventmesh.registry.RegistryService;
-
-import org.apache.commons.lang3.StringUtils;
-
-import javax.annotation.PostConstruct;
-
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Service;
-import lombok.extern.slf4j.Slf4j;
+import javax.annotation.PostConstruct;
@Service
@Slf4j
@@ -102,7 +99,7 @@ public void start() {
}
@Override
- public void destroy() {
+ public void stop() {
if (configuration.isEventMeshRegistryPluginEnabled()) {
registryService.unRegister(adminServeInfo);
try {
diff --git a/eventmesh-admin-server/src/main/java/org/apache/eventmesh/admin/server/web/BaseServer.java b/eventmesh-admin-server/src/main/java/org/apache/eventmesh/admin/server/web/BaseServer.java
index 24085dd89e..9bbe4ce305 100644
--- a/eventmesh-admin-server/src/main/java/org/apache/eventmesh/admin/server/web/BaseServer.java
+++ b/eventmesh-admin-server/src/main/java/org/apache/eventmesh/admin/server/web/BaseServer.java
@@ -17,7 +17,7 @@
package org.apache.eventmesh.admin.server.web;
-import org.apache.eventmesh.admin.server.ComponentLifeCycle;
+import org.apache.eventmesh.common.ComponentLifeCycle;
import org.apache.eventmesh.common.remote.payload.PayloadFactory;
import javax.annotation.PostConstruct;
@@ -40,9 +40,9 @@ public void init() throws Exception {
}
@PreDestroy
- public void shutdown() {
+ public void shutdown() throws Exception {
log.info("[{}] server will destroy", this.getClass().getSimpleName());
- destroy();
+ stop();
log.info("[{}] server has be destroy", this.getClass().getSimpleName());
}
diff --git a/eventmesh-admin-server/src/main/java/org/apache/eventmesh/admin/server/web/GrpcServer.java b/eventmesh-admin-server/src/main/java/org/apache/eventmesh/admin/server/web/GrpcServer.java
index 5fbb34f489..3a4bbe3d71 100644
--- a/eventmesh-admin-server/src/main/java/org/apache/eventmesh/admin/server/web/GrpcServer.java
+++ b/eventmesh-admin-server/src/main/java/org/apache/eventmesh/admin/server/web/GrpcServer.java
@@ -17,17 +17,14 @@
package org.apache.eventmesh.admin.server.web;
+import io.grpc.Server;
+import io.grpc.netty.shaded.io.grpc.netty.NettyServerBuilder;
+import lombok.extern.slf4j.Slf4j;
import org.apache.eventmesh.admin.server.AdminServerProperties;
-
-import java.util.concurrent.TimeUnit;
-
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
-import io.grpc.Server;
-import io.grpc.netty.shaded.io.grpc.netty.NettyServerBuilder;
-
-import lombok.extern.slf4j.Slf4j;
+import java.util.concurrent.TimeUnit;
@Controller
@Slf4j
@@ -52,7 +49,7 @@ public void start() throws Exception {
}
@Override
- public void destroy() {
+ public void stop() {
try {
if (server != null) {
server.shutdown();
diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/AbstractComponent.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/AbstractComponent.java
new file mode 100644
index 0000000000..9a1c0a404f
--- /dev/null
+++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/AbstractComponent.java
@@ -0,0 +1,26 @@
+package org.apache.eventmesh.common;
+
+import lombok.extern.slf4j.Slf4j;
+
+/**
+ * @Description:
+ */
+@Slf4j
+public abstract class AbstractComponent implements ComponentLifeCycle {
+ @Override
+ public void start() throws Exception {
+ log.info("component [{}] will start", this.getClass());
+ startup();
+ log.info("component [{}] has started successfully", this.getClass());
+ }
+
+ @Override
+ public void stop() throws Exception {
+ log.info("component [{}] will stop", this.getClass());
+ shutdown();
+ log.info("component [{}] has stopped successfully", this.getClass());
+ }
+
+ protected abstract void startup() throws Exception;
+ protected abstract void shutdown() throws Exception;
+}
diff --git a/eventmesh-admin-server/src/main/java/org/apache/eventmesh/admin/server/ComponentLifeCycle.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/ComponentLifeCycle.java
similarity index 89%
rename from eventmesh-admin-server/src/main/java/org/apache/eventmesh/admin/server/ComponentLifeCycle.java
rename to eventmesh-common/src/main/java/org/apache/eventmesh/common/ComponentLifeCycle.java
index 392eebfbba..76fdd548d0 100644
--- a/eventmesh-admin-server/src/main/java/org/apache/eventmesh/admin/server/ComponentLifeCycle.java
+++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/ComponentLifeCycle.java
@@ -15,14 +15,14 @@
* limitations under the License.
*/
-package org.apache.eventmesh.admin.server;
+package org.apache.eventmesh.common;
/**
- * adminServer ComponentLifeCycle
+ * LifeCycle of EventMesh Component
*/
public interface ComponentLifeCycle {
void start() throws Exception;
- void destroy();
+ void stop() throws Exception;
}
diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/config/connector/rdb/canal/RdbDBDefinition.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/config/connector/rdb/canal/RdbDBDefinition.java
new file mode 100644
index 0000000000..450d0afce0
--- /dev/null
+++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/config/connector/rdb/canal/RdbDBDefinition.java
@@ -0,0 +1,14 @@
+package org.apache.eventmesh.common.config.connector.rdb.canal;
+
+import lombok.Data;
+
+import java.util.Set;
+
+/**
+ * @Description: as class name
+ */
+@Data
+public class RdbDBDefinition {
+ private String schemaName;
+ private Set tables;
+}
diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/config/connector/rdb/canal/RdbTableDefinition.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/config/connector/rdb/canal/RdbTableDefinition.java
new file mode 100644
index 0000000000..cae88fdaa9
--- /dev/null
+++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/config/connector/rdb/canal/RdbTableDefinition.java
@@ -0,0 +1,11 @@
+package org.apache.eventmesh.common.config.connector.rdb.canal;
+
+import lombok.Data;
+
+/**
+ * @Description:
+ */
+@Data
+public class RdbTableDefinition {
+ protected String tableName;
+}
diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/config/connector/rdb/canal/RdbTableMgr.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/config/connector/rdb/canal/RdbTableMgr.java
new file mode 100644
index 0000000000..31607a1e4d
--- /dev/null
+++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/config/connector/rdb/canal/RdbTableMgr.java
@@ -0,0 +1,30 @@
+package org.apache.eventmesh.common.config.connector.rdb.canal;
+
+import lombok.AllArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.eventmesh.common.AbstractComponent;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @Description:
+ */
+@Slf4j
+@AllArgsConstructor
+public class RdbTableMgr extends AbstractComponent {
+ private final SourceConnectorConfig config;
+ private final Map tables = new HashMap<>();
+
+ @Override
+ protected void startup() throws Exception {
+ if (config != null) {
+
+ }
+ }
+
+ @Override
+ protected void shutdown() throws Exception {
+
+ }
+}
diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/config/connector/rdb/canal/SourceConnectorConfig.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/config/connector/rdb/canal/SourceConnectorConfig.java
index e9ae466079..07501625a5 100644
--- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/config/connector/rdb/canal/SourceConnectorConfig.java
+++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/config/connector/rdb/canal/SourceConnectorConfig.java
@@ -19,6 +19,8 @@
import lombok.Data;
+import java.util.Set;
+
/**
* Represents the configuration for a database connector.
*/
@@ -37,8 +39,6 @@ public class SourceConnectorConfig {
private String passWord;
- private String schemaName;
-
- private String tableName;
+ private Set schemas;
}
diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/config/connector/rdb/canal/mysql/MysqlTableDef.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/config/connector/rdb/canal/mysql/MysqlTableDef.java
new file mode 100644
index 0000000000..4b012f8245
--- /dev/null
+++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/config/connector/rdb/canal/mysql/MysqlTableDef.java
@@ -0,0 +1,17 @@
+package org.apache.eventmesh.common.config.connector.rdb.canal.mysql;
+
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import org.apache.eventmesh.common.config.connector.rdb.canal.RdbTableDefinition;
+
+import java.util.Set;
+
+/**
+ * @Description:
+ */
+@Data
+@EqualsAndHashCode(callSuper = true)
+public class MysqlTableDef extends RdbTableDefinition {
+ private Set colNames;
+ private Set primaryKeys;
+}
diff --git a/eventmesh-openconnect/eventmesh-openconnect-java/src/main/java/org/apache/eventmesh/openconnect/api/connector/Connector.java b/eventmesh-openconnect/eventmesh-openconnect-java/src/main/java/org/apache/eventmesh/openconnect/api/connector/Connector.java
index 11c2b77454..8ac09eac38 100644
--- a/eventmesh-openconnect/eventmesh-openconnect-java/src/main/java/org/apache/eventmesh/openconnect/api/connector/Connector.java
+++ b/eventmesh-openconnect/eventmesh-openconnect-java/src/main/java/org/apache/eventmesh/openconnect/api/connector/Connector.java
@@ -17,13 +17,14 @@
package org.apache.eventmesh.openconnect.api.connector;
+import org.apache.eventmesh.common.ComponentLifeCycle;
import org.apache.eventmesh.common.config.connector.Config;
import org.apache.eventmesh.openconnect.offsetmgmt.api.data.ConnectRecord;
/**
* Connector
*/
-public interface Connector {
+public interface Connector extends ComponentLifeCycle {
/**
* Returns the class type of the configuration for this Connector.
@@ -52,13 +53,6 @@ public interface Connector {
*/
void init(ConnectorContext connectorContext) throws Exception;
- /**
- * Starts the Connector.
- *
- * @throws Exception if the start operation fails
- */
- void start() throws Exception;
-
/**
* Commits the specified ConnectRecord object.
*
@@ -73,11 +67,4 @@ public interface Connector {
*/
String name();
- /**
- * Stops the Connector.
- *
- * @throws Exception if stopping fails
- */
- void stop() throws Exception;
-
}
From 8096aa34fe8e2e38785590735f6db621591e0265 Mon Sep 17 00:00:00 2001
From: sodaRyCN <757083350@qq.com>
Date: Mon, 1 Jul 2024 20:23:24 +0800
Subject: [PATCH 03/15] more and more
---
.../eventmesh/common/AbstractComponent.java | 16 +++-
.../rdb/canal/CanalSourceFullConfig.java | 15 ++++
.../connector/rdb/canal/RdbDBDefinition.java | 4 +-
.../connector/rdb/canal/RdbFullPosition.java | 16 ++++
.../rdb/canal/RdbTableDefinition.java | 2 +-
.../connector/rdb/canal/RdbTableMgr.java | 30 --------
.../rdb/canal/SourceConnectorConfig.java | 2 +-
.../rdb/canal/mysql/MysqlTableDef.java | 2 +-
.../connector/canal/source/EntryParser.java | 15 ++--
.../connector/CanalSourceConnector.java | 10 ++-
.../connector/CanalSourceFullConnector.java | 75 +++++++++++++++++++
.../source/position/CanalFullPositionMgr.java | 65 ++++++++++++++++
.../canal/source/table/RdbSimpleTable.java | 31 ++++++++
.../canal/source/table/RdbTableMgr.java | 61 +++++++++++++++
14 files changed, 297 insertions(+), 47 deletions(-)
create mode 100644 eventmesh-common/src/main/java/org/apache/eventmesh/common/config/connector/rdb/canal/CanalSourceFullConfig.java
create mode 100644 eventmesh-common/src/main/java/org/apache/eventmesh/common/config/connector/rdb/canal/RdbFullPosition.java
delete mode 100644 eventmesh-common/src/main/java/org/apache/eventmesh/common/config/connector/rdb/canal/RdbTableMgr.java
create mode 100644 eventmesh-connectors/eventmesh-connector-canal/src/main/java/org/apache/eventmesh/connector/canal/source/connector/CanalSourceFullConnector.java
create mode 100644 eventmesh-connectors/eventmesh-connector-canal/src/main/java/org/apache/eventmesh/connector/canal/source/position/CanalFullPositionMgr.java
create mode 100644 eventmesh-connectors/eventmesh-connector-canal/src/main/java/org/apache/eventmesh/connector/canal/source/table/RdbSimpleTable.java
create mode 100644 eventmesh-connectors/eventmesh-connector-canal/src/main/java/org/apache/eventmesh/connector/canal/source/table/RdbTableMgr.java
diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/AbstractComponent.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/AbstractComponent.java
index 9a1c0a404f..bca798602f 100644
--- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/AbstractComponent.java
+++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/AbstractComponent.java
@@ -2,23 +2,35 @@
import lombok.extern.slf4j.Slf4j;
+import java.util.concurrent.atomic.AtomicBoolean;
+
/**
* @Description:
*/
@Slf4j
public abstract class AbstractComponent implements ComponentLifeCycle {
+ private final AtomicBoolean init = new AtomicBoolean(false);
+ private final AtomicBoolean stopped = new AtomicBoolean(false);
@Override
public void start() throws Exception {
+ if (!init.compareAndSet(false, true)){
+ log.info("component [{}] has started", this.getClass());
+ return;
+ }
log.info("component [{}] will start", this.getClass());
startup();
- log.info("component [{}] has started successfully", this.getClass());
+ log.info("component [{}] started successfully", this.getClass());
}
@Override
public void stop() throws Exception {
+ if (!stopped.compareAndSet(false, true)){
+ log.info("component [{}] has stopped", this.getClass());
+ return;
+ }
log.info("component [{}] will stop", this.getClass());
shutdown();
- log.info("component [{}] has stopped successfully", this.getClass());
+ log.info("component [{}] stopped successfully", this.getClass());
}
protected abstract void startup() throws Exception;
diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/config/connector/rdb/canal/CanalSourceFullConfig.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/config/connector/rdb/canal/CanalSourceFullConfig.java
new file mode 100644
index 0000000000..8c5f94bd14
--- /dev/null
+++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/config/connector/rdb/canal/CanalSourceFullConfig.java
@@ -0,0 +1,15 @@
+package org.apache.eventmesh.common.config.connector.rdb.canal;
+
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import org.apache.eventmesh.common.config.connector.SourceConfig;
+import org.apache.eventmesh.common.remote.offset.RecordPosition;
+
+import java.util.List;
+
+@Data
+@EqualsAndHashCode(callSuper = true)
+public class CanalSourceFullConfig extends SourceConfig {
+ private SourceConnectorConfig connectorConfig;
+ private List startPosition;
+}
diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/config/connector/rdb/canal/RdbDBDefinition.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/config/connector/rdb/canal/RdbDBDefinition.java
index 450d0afce0..8e8c075d54 100644
--- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/config/connector/rdb/canal/RdbDBDefinition.java
+++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/config/connector/rdb/canal/RdbDBDefinition.java
@@ -5,10 +5,10 @@
import java.util.Set;
/**
- * @Description: as class name
+ * Description: as class name
*/
@Data
public class RdbDBDefinition {
- private String schemaName;
+ private String schema;
private Set tables;
}
diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/config/connector/rdb/canal/RdbFullPosition.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/config/connector/rdb/canal/RdbFullPosition.java
new file mode 100644
index 0000000000..41267946c9
--- /dev/null
+++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/config/connector/rdb/canal/RdbFullPosition.java
@@ -0,0 +1,16 @@
+package org.apache.eventmesh.common.config.connector.rdb.canal;
+
+import lombok.Data;
+
+import java.math.BigDecimal;
+
+@Data
+public class RdbFullPosition {
+ private String jobId;
+ private String schema;
+ private String tableName;
+ private String curPrimaryKey;
+ private BigDecimal minPrimaryKeyNum;
+ private BigDecimal maxPrimaryKeyNum;
+ private boolean finished;
+}
diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/config/connector/rdb/canal/RdbTableDefinition.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/config/connector/rdb/canal/RdbTableDefinition.java
index cae88fdaa9..b2bfbc6b84 100644
--- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/config/connector/rdb/canal/RdbTableDefinition.java
+++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/config/connector/rdb/canal/RdbTableDefinition.java
@@ -3,7 +3,7 @@
import lombok.Data;
/**
- * @Description:
+ * Description: as class name
*/
@Data
public class RdbTableDefinition {
diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/config/connector/rdb/canal/RdbTableMgr.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/config/connector/rdb/canal/RdbTableMgr.java
deleted file mode 100644
index 31607a1e4d..0000000000
--- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/config/connector/rdb/canal/RdbTableMgr.java
+++ /dev/null
@@ -1,30 +0,0 @@
-package org.apache.eventmesh.common.config.connector.rdb.canal;
-
-import lombok.AllArgsConstructor;
-import lombok.extern.slf4j.Slf4j;
-import org.apache.eventmesh.common.AbstractComponent;
-
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * @Description:
- */
-@Slf4j
-@AllArgsConstructor
-public class RdbTableMgr extends AbstractComponent {
- private final SourceConnectorConfig config;
- private final Map tables = new HashMap<>();
-
- @Override
- protected void startup() throws Exception {
- if (config != null) {
-
- }
- }
-
- @Override
- protected void shutdown() throws Exception {
-
- }
-}
diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/config/connector/rdb/canal/SourceConnectorConfig.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/config/connector/rdb/canal/SourceConnectorConfig.java
index 07501625a5..01aa01fe09 100644
--- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/config/connector/rdb/canal/SourceConnectorConfig.java
+++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/config/connector/rdb/canal/SourceConnectorConfig.java
@@ -39,6 +39,6 @@ public class SourceConnectorConfig {
private String passWord;
- private Set schemas;
+ private Set databases;
}
diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/config/connector/rdb/canal/mysql/MysqlTableDef.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/config/connector/rdb/canal/mysql/MysqlTableDef.java
index 4b012f8245..8125c7e5d9 100644
--- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/config/connector/rdb/canal/mysql/MysqlTableDef.java
+++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/config/connector/rdb/canal/mysql/MysqlTableDef.java
@@ -7,7 +7,7 @@
import java.util.Set;
/**
- * @Description:
+ * Description:
*/
@Data
@EqualsAndHashCode(callSuper = true)
diff --git a/eventmesh-connectors/eventmesh-connector-canal/src/main/java/org/apache/eventmesh/connector/canal/source/EntryParser.java b/eventmesh-connectors/eventmesh-connector-canal/src/main/java/org/apache/eventmesh/connector/canal/source/EntryParser.java
index 32c55ec42c..3ca2f7ec2f 100644
--- a/eventmesh-connectors/eventmesh-connector-canal/src/main/java/org/apache/eventmesh/connector/canal/source/EntryParser.java
+++ b/eventmesh-connectors/eventmesh-connector-canal/src/main/java/org/apache/eventmesh/connector/canal/source/EntryParser.java
@@ -31,6 +31,7 @@
import java.util.List;
import java.util.Map;
+import org.apache.eventmesh.connector.canal.source.table.RdbTableMgr;
import org.springframework.util.CollectionUtils;
import com.alibaba.otter.canal.protocol.CanalEntry;
@@ -47,7 +48,7 @@
@Slf4j
public class EntryParser {
- public Map> parse(CanalSourceConfig sourceConfig, List datas) {
+ public static Map> parse(CanalSourceConfig sourceConfig, List datas) {
List recordList = new ArrayList<>();
List transactionDataBuffer = new ArrayList<>();
// need check weather the entry is loopback
@@ -116,11 +117,10 @@ private Column getColumnIgnoreCase(List columns, String columName) {
return null;
}
- private List internParse(CanalSourceConfig sourceConfig, Entry entry) {
+ private static List internParse(CanalSourceConfig sourceConfig, Entry entry, RdbTableMgr tableMgr) {
String schemaName = entry.getHeader().getSchemaName();
String tableName = entry.getHeader().getTableName();
- if (!schemaName.equalsIgnoreCase(sourceConfig.getSourceConnectorConfig().getSchemaName())
- || !tableName.equalsIgnoreCase(sourceConfig.getSourceConnectorConfig().getTableName())) {
+ if (tableMgr.getTable(schemaName, tableName) == null) {
return null;
}
@@ -155,7 +155,7 @@ private List internParse(CanalSourceConfig sourceConfig, Ent
return recordList;
}
- private CanalConnectRecord internParse(CanalSourceConfig canalSourceConfig, Entry entry, RowChange rowChange, RowData rowData) {
+ private static CanalConnectRecord internParse(CanalSourceConfig canalSourceConfig, Entry entry, RowChange rowChange, RowData rowData) {
CanalConnectRecord canalConnectRecord = new CanalConnectRecord();
canalConnectRecord.setTableName(entry.getHeader().getTableName());
canalConnectRecord.setSchemaName(entry.getHeader().getSchemaName());
@@ -242,7 +242,8 @@ private CanalConnectRecord internParse(CanalSourceConfig canalSourceConfig, Entr
return canalConnectRecord;
}
- private void checkUpdateKeyColumns(Map oldKeyColumns, Map keyColumns) {
+ private static void checkUpdateKeyColumns(Map oldKeyColumns,
+ Map keyColumns) {
if (oldKeyColumns.isEmpty()) {
return;
}
@@ -264,7 +265,7 @@ private void checkUpdateKeyColumns(Map oldKeyColumns, Map configClass() {
return CanalSourceConfig.class;
@@ -146,6 +149,8 @@ protected void startEventParserInternal(CanalEventParser parser, boolean isGroup
return instance;
}
});
+ tableMgr = RdbTableMgr.getInstance();
+ tableMgr.init(sourceConfig.getSourceConnectorConfig());
}
private Canal buildCanal(CanalSourceConfig sourceConfig) {
@@ -218,6 +223,7 @@ public void start() throws Exception {
if (running) {
return;
}
+ tableMgr.start();
canalServer.start();
canalServer.start(sourceConfig.getDestination());
@@ -288,11 +294,9 @@ public List poll() {
entries = message.getEntries();
}
- EntryParser entryParser = new EntryParser();
-
List result = new ArrayList<>();
// key: Xid offset
- Map> connectorRecordMap = entryParser.parse(sourceConfig, entries);
+ Map> connectorRecordMap = EntryParser.parse(sourceConfig, entries);
if (!connectorRecordMap.isEmpty()) {
Set>> entrySet = connectorRecordMap.entrySet();
diff --git a/eventmesh-connectors/eventmesh-connector-canal/src/main/java/org/apache/eventmesh/connector/canal/source/connector/CanalSourceFullConnector.java b/eventmesh-connectors/eventmesh-connector-canal/src/main/java/org/apache/eventmesh/connector/canal/source/connector/CanalSourceFullConnector.java
new file mode 100644
index 0000000000..434c1464d4
--- /dev/null
+++ b/eventmesh-connectors/eventmesh-connector-canal/src/main/java/org/apache/eventmesh/connector/canal/source/connector/CanalSourceFullConnector.java
@@ -0,0 +1,75 @@
+package org.apache.eventmesh.connector.canal.source.connector;
+
+import lombok.extern.slf4j.Slf4j;
+import org.apache.eventmesh.common.AbstractComponent;
+import org.apache.eventmesh.common.config.connector.Config;
+import org.apache.eventmesh.common.config.connector.rdb.canal.CanalSourceConfig;
+import org.apache.eventmesh.common.config.connector.rdb.canal.CanalSourceFullConfig;
+import org.apache.eventmesh.common.config.connector.rdb.canal.RdbDBDefinition;
+import org.apache.eventmesh.common.config.connector.rdb.canal.RdbTableDefinition;
+import org.apache.eventmesh.common.config.connector.rdb.canal.SourceConnectorConfig;
+import org.apache.eventmesh.openconnect.api.ConnectorCreateService;
+import org.apache.eventmesh.openconnect.api.connector.ConnectorContext;
+import org.apache.eventmesh.openconnect.api.connector.SourceConnectorContext;
+import org.apache.eventmesh.openconnect.api.source.Source;
+import org.apache.eventmesh.openconnect.offsetmgmt.api.data.ConnectRecord;
+
+import java.util.List;
+
+@Slf4j
+public class CanalSourceFullConnector extends AbstractComponent implements Source, ConnectorCreateService