From 6bcffa9b9096f1e570747df983c582611e20d3b0 Mon Sep 17 00:00:00 2001
From: qianmoQ
Date: Mon, 6 Mar 2023 22:43:39 +0800
Subject: [PATCH] [Plugin] Support kafka for native
---
README.md | 3 +
assets/plugin/kafka.png | Bin 0 -> 6683 bytes
core/datacap-server/pom.xml | 5 +
.../main/etc/conf/plugins/native/kafka.json | 19 +++
.../public/static/images/plugin/Kafka.png | Bin 0 -> 2742 bytes
plugin/datacap-native-kafka/pom.xml | 71 +++++++++
.../plugin/natived/kafka/KafkaAdapter.java | 147 ++++++++++++++++++
.../plugin/natived/kafka/KafkaConnection.java | 60 +++++++
.../plugin/natived/kafka/KafkaParser.java | 27 ++++
.../plugin/natived/kafka/KafkaPlugin.java | 80 ++++++++++
.../natived/kafka/KafkaPluginModule.java | 38 +++++
.../io.edurt.datacap.spi.PluginModule | 1 +
.../natived/kafka/KafkaPluginModuleTest.java | 30 ++++
.../plugin/natived/kafka/KafkaPluginTest.java | 43 +++++
pom.xml | 1 +
15 files changed, 525 insertions(+)
create mode 100644 assets/plugin/kafka.png
create mode 100644 core/datacap-server/src/main/etc/conf/plugins/native/kafka.json
create mode 100644 core/datacap-web/console-fe/public/static/images/plugin/Kafka.png
create mode 100644 plugin/datacap-native-kafka/pom.xml
create mode 100644 plugin/datacap-native-kafka/src/main/java/io/edurt/datacap/plugin/natived/kafka/KafkaAdapter.java
create mode 100644 plugin/datacap-native-kafka/src/main/java/io/edurt/datacap/plugin/natived/kafka/KafkaConnection.java
create mode 100644 plugin/datacap-native-kafka/src/main/java/io/edurt/datacap/plugin/natived/kafka/KafkaParser.java
create mode 100644 plugin/datacap-native-kafka/src/main/java/io/edurt/datacap/plugin/natived/kafka/KafkaPlugin.java
create mode 100644 plugin/datacap-native-kafka/src/main/java/io/edurt/datacap/plugin/natived/kafka/KafkaPluginModule.java
create mode 100644 plugin/datacap-native-kafka/src/main/resources/META-INF/services/io.edurt.datacap.spi.PluginModule
create mode 100644 plugin/datacap-native-kafka/src/test/java/io/edurt/datacap/plugin/natived/kafka/KafkaPluginModuleTest.java
create mode 100644 plugin/datacap-native-kafka/src/test/java/io/edurt/datacap/plugin/natived/kafka/KafkaPluginTest.java
diff --git a/README.md b/README.md
index 857691e2..3c9bc2e5 100644
--- a/README.md
+++ b/README.md
@@ -143,6 +143,9 @@ Here are some of the major database solutions that are supported:
+
+
+
diff --git a/assets/plugin/kafka.png b/assets/plugin/kafka.png
new file mode 100644
index 0000000000000000000000000000000000000000..7668eed988f4af939c20307fb92cef39d204a520
GIT binary patch
literal 6683
zcmXw8dpy(M|L-D^WYNV`%Vvfo%(WO{jW?EDQgbWJklQC++>%eBHqB+5#-^s+l55Ci
z7=0qlHMxtaOz!u~M3>(_-|zSL&-?Mdobx=d_w#igugmk0E?qR2+$Xnh$BrG6fCbua
z$BvzV@SY(iD!gViv}oZP7KEebBTvBeoahf0k
ziTzOc-n|5VRph`EGfxYPzhp(Y_rkun4PCRXtl4^&XCJw}5t+`HoNFIhsB`TLdY*Ug
z@~>}z7_{+}`pilE@??6H(XW*@bsOVfYdt-Q#=kdDE|*=4`n5it9`*aRF(L-^7}f`m
z+Mcg`RT(s96uH)IZlms2JJ{QnqMpvH4O?AnkTNz*%LADnk3U3%d;FX$>pEktks;tk
zEKcVa*M)EW5{%6@NI)C=WRbxB`PDAtdW~A!$kh(LnK%jP0h3DL{-0lhqu=STrHp?r
zvA55}fCjSK;L}G2a&)b%*Mx?ai>2|8Ub}bG9bfjLF#%-i5}gFNHOOPLB*mePyejO<
z=b(CyMiD1l)AHYEYw25glCyFiNb@qDDG_y(!Eb12h;?_h%GxU&@8-{h(-7shVe2z}
z`IC&L#k%c3orHV1lc4I&>AxxIRd4Lkg4Uv
z>kYy&icP#j|9$>-=f@tG68L0JXM*M6f`
zFt#^ORAZ&5&LPKL(%$8^X!5hKw2YXsdSC0kSDwUdIx^mzlDMT2
zV6sxD$7MZ=;feV1Q;Hsp7o2#Ko-*yReupj>zo3t~t&;z`yrwSX)z>Mv
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&;GmciM4iDW6o_X$i#MDKq66kD=j8pbJU+Mia>QQNiJG8M**p7wtwE26@
z{k1=$Sm&w9zMC~dHMi^{4tNP}4aX{u`6X($7J$Q{jdupMxvaygi0blttU%W
ziWR5B6iHr=Gjg2AwAE#nlG>|6zNJ=%xl>FufwfpVKE?NE&UgWnVx?uM@q~YgaN6Eb
z3tZzVadUBh8l0xanAWGfRbb%L$coQQM-21=sOwgZu^?EQI}JS(C;{zk71q0MT}f;k
z5BLLD8NL6Z?ID&AgO^r{w+7XG!7u)+C`T#hXk)1hAO98PfdEp6($%~{q*e7*ie`%)$GKD-icZb}b`h?mC0{9a
ziNxnnxA?+guovP3uEk62=r
z{YwnG(db150cX+`6%!?(8%+UJjdOH;SO5VUQzZ(e#rVm3eb1>g6*~y^r-Fvc?>Sh?
z34KXBLyKvtOGJ54F`h}LM8BQ@>bv0gE&T*H%J)p1KeX|n@bn@&@XffTo_k
s2|nhWYo!*Wf3C;cP7K=l?$6G@z3e(u;PUr{hdw)i3m4Hvrq>_-ACh|Zn*aa+
literal 0
HcmV?d00001
diff --git a/core/datacap-server/pom.xml b/core/datacap-server/pom.xml
index 7bad66bd..fd7a8418 100644
--- a/core/datacap-server/pom.xml
+++ b/core/datacap-server/pom.xml
@@ -274,6 +274,11 @@
datacap-native-alioss
${project.version}
+
+ io.edurt.datacap
+ datacap-native-kafka
+ ${project.version}
+
diff --git a/core/datacap-server/src/main/etc/conf/plugins/native/kafka.json b/core/datacap-server/src/main/etc/conf/plugins/native/kafka.json
new file mode 100644
index 00000000..5f9c4db7
--- /dev/null
+++ b/core/datacap-server/src/main/etc/conf/plugins/native/kafka.json
@@ -0,0 +1,19 @@
+{
+ "name": "Kafka",
+ "supportTime": "2023-03-06",
+ "configures": [
+ {
+ "field": "name",
+ "type": "String",
+ "required": true,
+ "message": "name is a required field, please be sure to enter"
+ },
+ {
+ "field": "host",
+ "type": "String",
+ "required": true,
+ "value": "127.0.0.1:9092",
+ "message": "host is a required field, please be sure to enter"
+ }
+ ]
+}
diff --git a/core/datacap-web/console-fe/public/static/images/plugin/Kafka.png b/core/datacap-web/console-fe/public/static/images/plugin/Kafka.png
new file mode 100644
index 0000000000000000000000000000000000000000..72c6a29279bcc47bf94c16ee3f617c029b6bf910
GIT binary patch
literal 2742
zcmV;n3Q6^eP)^8Wq%%abQhZiQ9(?Af!+r%#{k%ku{aoqmm`3ckZ{PkSTnRsZ{Agd|@R&kua<3Ju2Fdp){$RM+m@g|*O`d}P
z!BDXg!iv*^U%q^?FMUW16Z_k@Z~vE4t@+@=gIkw>bPN+4*K9@EA~p5v*RO9)7ml6U
znmqsT;lqD^c8hP`ys>ZLa2O&s%@Qld8fl&&?AEIM`Sa(ki1zokcytUI0mXe2dewTF
zW{Q#$Xx1DVL&UZsSRx#&KLSF$y^iJc=g;l09SYsWRzf%pmK?lz@#3FrEy*Mz^dA-7
z#U_+m5iD~B!MxdPSyBZY72U=53>7YY%aD2C_w4m7kK9J>F1BaR=%|$dV`s0qL5NN0k9Fp!}VFy*gQYVTjlua(a~Ti?Ks^az1~uN|_AyXSaw5HGqJK
zscx_G-kFdyV3^p7QL9B(e(9>__r31l9@BR1NDLDj)IL$V#nRfEND_%6dt{}L3hzV3
z1~gIZfYfB^36+Q^P?=M0)WC4D*}P~acxj$SXnW0CB&_!qe7M*NUPC0x+&%FG$~k+@
z+9WlUdWi_85gU+Onelc|B4hxgr(7(EHl^=FB|V2;m`ZHGKu1cOL`u0@+n3&EjV1S|
zAsW$%loWmMy>3XHPV5B28_k!!@Q%?z7*=xbfd>nmvVEN`BJkR4^WG7VE};FLHS%*k
zFs;}Lm>4@aiKTnrYfx)xwPyDA?-QBWtuejWdq$~tzGFoyojq0P1Z6LPNzodo*bD5v
zR>^BJiM)*(YWdbU#a=+Et8;5(@6blcwN;#AFW|Xw%CTJRd5=VIhp!Z;*bD4A|I*jP
z<$I41X!-l)%f`Fc)Xe
z-T*V4Ri^f*X-^_l>0l{$g66)4(yVE{&pnOUoO@um=!`5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)f$TCpGM{mW|}o()_&yqVawR
z?^`7zpD*w72U<&I~oje&bfjpr$IaqaLwp0ws)IN
z>75bwdX_b6?z@WaVtaKep|}K|QLD8xb{BDVVsF*GiMf8@8qi&AuSJSu&OK_RJS(;5
zmf~#aF1E5~9WA>OltTxnLF)(x+X`TryU*)2Yv{D)I{j-vcd>yLVU5uP^U5PLN}c{)
z#}KhSlLj$b>P_!6J>6ht3=vyten7%5Iex20PDu9Z_9c&wVI$z>*Co?-AuE$roSp{k
zm03$3eG>!>6PplSdh$ahlOngAyCw`18z^O14c0hXd<_^XHc-r336I<{vluQmh?uMh
zPoe+D6k-E!>oY>UK?6`b^;|
+
+ 4.0.0
+
+ io.edurt.datacap
+ datacap
+ 1.7.0-SNAPSHOT
+ ../../pom.xml
+
+
+ datacap-native-kafka
+ DataCap - Kafka
+
+
+ 2.8.0
+ native-kafka
+
+
+
+
+ io.edurt.datacap
+ datacap-spi
+ provided
+
+
+ io.edurt.datacap
+ datacap-common
+
+
+ commons-beanutils
+ commons-beanutils
+
+
+ io.edurt.datacap
+ datacap-parser
+
+
+ org.apache.kafka
+ kafka-clients
+ ${kafka.version}
+
+
+
+
+
+
+ maven-assembly-plugin
+ ${assembly-plugin.version}
+
+ ${plugin.name}
+
+ ../../configure/assembly/assembly-plugin.xml
+
+ ../../dist/plugins/${plugin.name}
+
+
+
+ make-assembly
+ package
+
+ single
+
+
+
+
+
+
+
+
diff --git a/plugin/datacap-native-kafka/src/main/java/io/edurt/datacap/plugin/natived/kafka/KafkaAdapter.java b/plugin/datacap-native-kafka/src/main/java/io/edurt/datacap/plugin/natived/kafka/KafkaAdapter.java
new file mode 100644
index 00000000..10bae61c
--- /dev/null
+++ b/plugin/datacap-native-kafka/src/main/java/io/edurt/datacap/plugin/natived/kafka/KafkaAdapter.java
@@ -0,0 +1,147 @@
+package io.edurt.datacap.plugin.natived.kafka;
+
+import com.google.common.base.Preconditions;
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
+import io.edurt.datacap.spi.adapter.NativeAdapter;
+import io.edurt.datacap.spi.model.Configure;
+import io.edurt.datacap.spi.model.Response;
+import io.edurt.datacap.spi.model.Time;
+import io.edurt.datacap.sql.SqlBase;
+import io.edurt.datacap.sql.SqlBaseToken;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.ObjectUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.lang3.exception.ExceptionUtils;
+import org.apache.kafka.clients.admin.AdminClient;
+import org.apache.kafka.clients.admin.ConsumerGroupDescription;
+import org.apache.kafka.clients.admin.DescribeConsumerGroupsResult;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Date;
+import java.util.List;
+
+@Slf4j
+@SuppressFBWarnings(value = {"RCN_REDUNDANT_NULLCHECK_WOULD_HAVE_BEEN_A_NPE", "REC_CATCH_EXCEPTION"},
+ justification = "I prefer to suppress these FindBugs warnings")
+public class KafkaAdapter
+ extends NativeAdapter
+{
+ protected KafkaConnection kafkaConnection;
+ private final KafkaParser parser;
+
+ public KafkaAdapter(KafkaConnection kafkaConnection, KafkaParser parser)
+ {
+ super(kafkaConnection, parser);
+ this.kafkaConnection = kafkaConnection;
+ this.parser = parser;
+ }
+
+ @Override
+ public Response handlerExecute(String content)
+ {
+ Time processorTime = new Time();
+ processorTime.setStart(new Date().getTime());
+ Response response = this.kafkaConnection.getResponse();
+ Configure configure = this.kafkaConnection.getConfigure();
+ if (response.getIsConnected()) {
+ List headers = new ArrayList<>();
+ List types = new ArrayList<>();
+ List