From ff910a708f6de78703be8f8a53ddfee7d392fd15 Mon Sep 17 00:00:00 2001 From: qianmoQ Date: Thu, 23 Feb 2023 23:23:14 +0800 Subject: [PATCH] [Plugin] Support alioss for native --- assets/plugin/alioss.png | Bin 0 -> 4018 bytes core/server/pom.xml | 5 ++ .../main/etc/conf/plugins/native/alioss.json | 39 +++++++++ .../public/static/images/plugin/Alioss.png | Bin 0 -> 4018 bytes plugin/native/alioss/pom.xml | 66 ++++++++++++++ .../plugin/natived/alioss/AliossAdapter.java | 82 ++++++++++++++++++ .../natived/alioss/AliossConnection.java | 57 ++++++++++++ .../plugin/natived/alioss/AliossParser.java | 27 ++++++ .../plugin/natived/alioss/AliossPlugin.java | 80 +++++++++++++++++ .../natived/alioss/AliossPluginModule.java | 38 ++++++++ .../io.edurt.datacap.spi.PluginModule | 1 + .../alioss/AliossPluginModuleTest.java | 30 +++++++ .../natived/alioss/AliossPluginTest.java | 46 ++++++++++ plugin/native/pom.xml | 1 + 14 files changed, 472 insertions(+) create mode 100644 assets/plugin/alioss.png create mode 100644 core/server/src/main/etc/conf/plugins/native/alioss.json create mode 100644 core/web/console-fe/public/static/images/plugin/Alioss.png create mode 100644 plugin/native/alioss/pom.xml create mode 100644 plugin/native/alioss/src/main/java/io/edurt/datacap/plugin/natived/alioss/AliossAdapter.java create mode 100644 plugin/native/alioss/src/main/java/io/edurt/datacap/plugin/natived/alioss/AliossConnection.java create mode 100644 plugin/native/alioss/src/main/java/io/edurt/datacap/plugin/natived/alioss/AliossParser.java create mode 100644 plugin/native/alioss/src/main/java/io/edurt/datacap/plugin/natived/alioss/AliossPlugin.java create mode 100644 plugin/native/alioss/src/main/java/io/edurt/datacap/plugin/natived/alioss/AliossPluginModule.java create mode 100644 plugin/native/alioss/src/main/resources/META-INF/services/io.edurt.datacap.spi.PluginModule create mode 100644 plugin/native/alioss/src/test/java/io/edurt/datacap/plugin/natived/alioss/AliossPluginModuleTest.java create mode 100644 plugin/native/alioss/src/test/java/io/edurt/datacap/plugin/natived/alioss/AliossPluginTest.java diff --git a/assets/plugin/alioss.png b/assets/plugin/alioss.png new file mode 100644 index 0000000000000000000000000000000000000000..09a1b7e90376e9fe37f00a64c071ab0c32c40bbe GIT binary patch literal 4018 zcmds4`8N~{_oq>2$~r2`Gniq989PbY24f$~6e+~m*NBIQjD0+^6lO4q$r_Q8ERkf3 zcx25|vJ|43C(>Y;X-s&%f57+G?+@<}cRTmq^SS4qd+s@(%uDu`f+wX;^6>BoT3eYp z9NFdn3h=~{MmJB!^6&@~tj$cW#Nand#)sjS(&>xMhpCq8Uv}kOL^|M5Q8N)Q*u(pL zu%$Q0U2>61yh-I`NGin5P-3DlMFo89Buy?uL}cP`An%)UaZrZb26~E>$<CZKU?>YZYGCzFJ~ zKZT&SE+$1AjPDe0ts<9S<&}D7mQri#W-$q?uOpzHqCV1 z8kTJ!#9}C$3(!y9d&~ISduI8CGP7MB5!%=od+5@IvY&m2@nCx9oi;sej9T#x!B2`p zU>&<_=Adz2Jv2IQBAv@oI05?P(kz9I5qkgjI`b>HcFJh6)umky>nu3KyBO0V%w*!a z_c_k2#5i9atTV_?Z{Q~W!&}|D(aFloz1YCX{asQ*phtml`^&#LIRTHi49eW5GhP;_N&L-fD|VPCV^ELi-mSl?_&o*D*(Gm#M^#=G&a=EP9T z3}%i?{Mqz!XHWTK+NsOEEfoVRwE;)_AS?*CIelIF3Z$ANmtCt+S0|P+s;PYUG66Z~ zm*ptof{*tldZX6THS7>${f~)AQ}ct+c64Ldssm-yStQv~>8PSTCC9@JUw)Y}_YiK7S@SEp^Q{v!|& zpOj(wnM@{nyYysqwG+D10wi9MYEwS2d?>2~mNph%zwN7G{2>rB(5JKsfb#(-*Fi|v|1 zr+luQ?0l3kTYmpcphD?3&0A)<+v3^2#L;Y@+I?u3sO{H@Ik|&FrnfnCc<^IKBhNyE zy{17GO1KbYOPS$dwe}#%Dm-|$da~qx4TDB@K`uiA*FVELS4e^&@cL)Zk*T*_|Ax9WunYhkvQ>u*{*1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vrDW^8OHRB^o%0H6`WV-TmC5WA8)o9etzW-MA=1 zF+f?$FmjDrO)h;r%qGbm9A=j^B!MDdC}?K)(72{xEnyj7a(VqKdSzY zSdB|5EPwQ4T1YgPF^g`MFOiJLVa$RJS$&=MmGps73%QhHYFZFValZ7+s9TOI#p)6>9p5tVGY74eJPS4?4jtr2qt(Tkfv1`m`-FS+>v<0R{a?FA|a+de|WBP=6J(YTZns{T%N)hbd~#wz6>1z4%C%8i^4?qQbiO zwX>~56|c;r`fqeEMh_k!Ms&T}hY5&q;L@}}LZr5(2TdO6;8XRo-jF^NKiC@!bft#H z`_Fc@4oB2#f?Pi?ma1>fVGF5(K_aOUj{4t<@5YNJmp@8_Em{q?16kV2Qy~gT1;Z}} zzhDas0CazfEa>|PjAT{VZ}7?BsY4@ogK2D?M~HQ z#FAUipPHJdl3mHh(0?zc0O&z{qU%F1b|k=6tNAoZ)TCI(cd|7GP8)wEyIv(wSJO!z zeNjs#Z#RaF+2}e$<(ZAPdR|C%y1%F%*ndAn+0UXCJtz;$^A87b8ahM7Ir3KUs`wF0 z)sZI10`ht=hK8#--EB@CR zQ4aNgg*3RCh3ael45e@It1DJXEtWn!-oLoJgTPi^t?$m!|OUX z2(%b7w@LvL>!xdv@?Y6a!p{7?d6V3^!)Se<~Zru+v4z*AEI literal 0 HcmV?d00001 diff --git a/core/server/pom.xml b/core/server/pom.xml index f18480be..69e6dfa8 100644 --- a/core/server/pom.xml +++ b/core/server/pom.xml @@ -265,6 +265,11 @@ datacap-plugin-jdbc-duckdb ${project.version} + + io.edurt.datacap.plugin.natived + datacap-plugin-native-alioss + ${project.version} + diff --git a/core/server/src/main/etc/conf/plugins/native/alioss.json b/core/server/src/main/etc/conf/plugins/native/alioss.json new file mode 100644 index 00000000..e6adbd72 --- /dev/null +++ b/core/server/src/main/etc/conf/plugins/native/alioss.json @@ -0,0 +1,39 @@ +{ + "name": "Alioss", + "supportTime": "2023-02-23", + "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": "https://oss-cn-regison.aliyuncs.com", + "message": "host is a required field, please be sure to enter" + }, + { + "field": "username", + "type": "String", + "required": true, + "group": "authorization" + }, + { + "field": "password", + "type": "String", + "required": true, + "group": "authorization" + }, + { + "field": "database", + "type": "String", + "required": true, + "value": "default", + "message": "database is a required field, please be sure to enter", + "group": "advanced" + } + ] +} diff --git a/core/web/console-fe/public/static/images/plugin/Alioss.png b/core/web/console-fe/public/static/images/plugin/Alioss.png new file mode 100644 index 0000000000000000000000000000000000000000..09a1b7e90376e9fe37f00a64c071ab0c32c40bbe GIT binary patch literal 4018 zcmds4`8N~{_oq>2$~r2`Gniq989PbY24f$~6e+~m*NBIQjD0+^6lO4q$r_Q8ERkf3 zcx25|vJ|43C(>Y;X-s&%f57+G?+@<}cRTmq^SS4qd+s@(%uDu`f+wX;^6>BoT3eYp z9NFdn3h=~{MmJB!^6&@~tj$cW#Nand#)sjS(&>xMhpCq8Uv}kOL^|M5Q8N)Q*u(pL zu%$Q0U2>61yh-I`NGin5P-3DlMFo89Buy?uL}cP`An%)UaZrZb26~E>$<CZKU?>YZYGCzFJ~ zKZT&SE+$1AjPDe0ts<9S<&}D7mQri#W-$q?uOpzHqCV1 z8kTJ!#9}C$3(!y9d&~ISduI8CGP7MB5!%=od+5@IvY&m2@nCx9oi;sej9T#x!B2`p zU>&<_=Adz2Jv2IQBAv@oI05?P(kz9I5qkgjI`b>HcFJh6)umky>nu3KyBO0V%w*!a z_c_k2#5i9atTV_?Z{Q~W!&}|D(aFloz1YCX{asQ*phtml`^&#LIRTHi49eW5GhP;_N&L-fD|VPCV^ELi-mSl?_&o*D*(Gm#M^#=G&a=EP9T z3}%i?{Mqz!XHWTK+NsOEEfoVRwE;)_AS?*CIelIF3Z$ANmtCt+S0|P+s;PYUG66Z~ zm*ptof{*tldZX6THS7>${f~)AQ}ct+c64Ldssm-yStQv~>8PSTCC9@JUw)Y}_Y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d^T$;pDsY7>mrkI-_Bz7HZU{`dehG+%6ZEbQ+t?{#M2El3Mqi7yaAJrFNf8On8I7s|{cEb$y^d z`E4mVb%fNBVe@Q3=b32EE)&iF51ggieP(_1;NPT0>Bc0GDA_X*k;NyRFR~0wte)_F z=rWr)rt3w$LXJF_vsc$_qz-4a`hShg`E6S{U}BLHwN^|fIE$OeNP>5I+;`(imx_$m zEv2eo((ys8MwNN6iwnJzw(?XS*vrDW^8OHRB^o%0H6`WV-TmC5WA8)o9etzW-MA=1 zF+f?$FmjDrO)h;r%qGbm9A=j^B!MDdC}?K)(72{xEnyj7a(VqKdSzY zSdB|5EPwQ4T1YgPF^g`MFOiJLVa$RJS$&=MmGps73%QhHYFZFValZ7+s9TOI#p)6>9p5tVGY74eJPS4?4jtr2qt(Tkfv1`m`-FS+>v<0R{a?FA|a+de|WBP=6J(YTZns{T%N)hbd~#wz6>1z4%C%8i^4?qQbiO zwX>~56|c;r`fqeEMh_k!Ms&T}hY5&q;L@}}LZr5(2TdO6;8XRo-jF^NKiC@!bft#H z`_Fc@4oB2#f?Pi?ma1>fVGF5(K_aOUj{4t<@5YNJmp@8_Em{q?16kV2Qy~gT1;Z}} zzhDas0CazfEa>|PjAT{VZ}7?BsY4@ogK2D?M~HQ z#FAUipPHJdl3mHh(0?zc0O&z{qU%F1b|k=6tNAoZ)TCI(cd|7GP8)wEyIv(wSJO!z zeNjs#Z#RaF+2}e$<(ZAPdR|C%y1%F%*ndAn+0UXCJtz;$^A87b8ahM7Ir3KUs`wF0 z)sZI10`ht=hK8#--EB@CR zQ4aNgg*3RCh3ael45e@It1DJXEtWn!-oLoJgTPi^t?$m!|OUX z2(%b7w@LvL>!xdv@?Y6a!p{7?d6V3^!)Se<~Zru+v4z*AEI literal 0 HcmV?d00001 diff --git a/plugin/native/alioss/pom.xml b/plugin/native/alioss/pom.xml new file mode 100644 index 00000000..08f2fb0e --- /dev/null +++ b/plugin/native/alioss/pom.xml @@ -0,0 +1,66 @@ + + + 4.0.0 + + io.edurt.datacap.plugin.natived + datacap-plugin-native + 1.6.0-SNAPSHOT + + + datacap-plugin-native-alioss + DataCap plugin for native (Ali oss) + + + 3.16.1 + native-alioss + + + + + io.edurt.datacap + datacap-spi + provided + + + io.edurt.datacap.common + datacap-common + + + commons-beanutils + commons-beanutils + + + com.aliyun.oss + aliyun-sdk-oss + ${alioss.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/native/alioss/src/main/java/io/edurt/datacap/plugin/natived/alioss/AliossAdapter.java b/plugin/native/alioss/src/main/java/io/edurt/datacap/plugin/natived/alioss/AliossAdapter.java new file mode 100644 index 00000000..23a5a2ff --- /dev/null +++ b/plugin/native/alioss/src/main/java/io/edurt/datacap/plugin/natived/alioss/AliossAdapter.java @@ -0,0 +1,82 @@ +package io.edurt.datacap.plugin.natived.alioss; + +import com.aliyun.oss.OSS; +import com.aliyun.oss.model.ObjectListing; +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 lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.ObjectUtils; + +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 AliossAdapter + extends NativeAdapter +{ + protected AliossConnection aliossConnection; + private final AliossParser parser; + + public AliossAdapter(AliossConnection aliossConnection, AliossParser parser) + { + super(aliossConnection, parser); + this.aliossConnection = aliossConnection; + this.parser = parser; + } + + @Override + public Response handlerExecute(String content) + { + Time processorTime = new Time(); + processorTime.setStart(new Date().getTime()); + Response response = this.aliossConnection.getResponse(); + Configure configure = this.aliossConnection.getConfigure(); + if (response.getIsConnected()) { + List headers = new ArrayList<>(); + List types = new ArrayList<>(); + List columns = new ArrayList<>(); + try { + SqlBase sqlBase = this.parser.getSqlBase(); + if (sqlBase.isSuccessful()) { + OSS client = this.aliossConnection.getOssClient(); + if (ObjectUtils.isNotEmpty(this.parser.getSqlBase().getColumns())) { + headers.addAll(this.parser.getSqlBase().getColumns()); + } + else { + headers.add("*"); + } + types.add("String"); + ObjectListing objectListing = client.listObjects(configure.getDatabase().get(), sqlBase.getTable()); + objectListing.getObjectSummaries() + .forEach(column -> columns.add(handlerFormatter(configure.getFormat(), headers, Collections.singletonList(column.getKey())))); + response.setIsSuccessful(Boolean.TRUE); + } + else { + Preconditions.checkArgument(!sqlBase.isSuccessful(), sqlBase.getMessage()); + } + } + catch (Exception ex) { + log.error("Execute content failed content {} exception ", content, ex); + response.setIsSuccessful(Boolean.FALSE); + response.setMessage(ex.getMessage()); + } + finally { + response.setHeaders(headers); + response.setTypes(types); + response.setColumns(columns); + } + } + processorTime.setEnd(new Date().getTime()); + response.setProcessor(processorTime); + return response; + } +} diff --git a/plugin/native/alioss/src/main/java/io/edurt/datacap/plugin/natived/alioss/AliossConnection.java b/plugin/native/alioss/src/main/java/io/edurt/datacap/plugin/natived/alioss/AliossConnection.java new file mode 100644 index 00000000..1446378b --- /dev/null +++ b/plugin/native/alioss/src/main/java/io/edurt/datacap/plugin/natived/alioss/AliossConnection.java @@ -0,0 +1,57 @@ +package io.edurt.datacap.plugin.natived.alioss; + +import com.aliyun.oss.OSS; +import com.aliyun.oss.OSSClientBuilder; +import io.edurt.datacap.spi.connection.Connection; +import io.edurt.datacap.spi.model.Configure; +import io.edurt.datacap.spi.model.Response; +import lombok.Getter; +import lombok.extern.slf4j.Slf4j; + +@Slf4j +public class AliossConnection + extends Connection +{ + private Configure configure; + private Response response; + + @Getter + private OSS ossClient; + + public AliossConnection(Configure configure, Response response) + { + super(configure, response); + } + + @Override + protected String formatJdbcUrl() + { + return null; + } + + @Override + protected java.sql.Connection openConnection() + { + try { + this.configure = getConfigure(); + this.response = getResponse(); + log.info("Connection url {}", formatJdbcUrl()); + this.ossClient = new OSSClientBuilder() + .build(configure.getHost(), configure.getUsername().get(), configure.getPassword().get()); + response.setIsConnected(Boolean.TRUE); + } + catch (Exception ex) { + log.error("Connection failed ", ex); + response.setIsConnected(Boolean.FALSE); + response.setMessage(ex.getMessage()); + } + return null; + } + + @Override + public void destroy() + { + this.ossClient.shutdown(); + log.info("Connection close successful"); + } +} diff --git a/plugin/native/alioss/src/main/java/io/edurt/datacap/plugin/natived/alioss/AliossParser.java b/plugin/native/alioss/src/main/java/io/edurt/datacap/plugin/natived/alioss/AliossParser.java new file mode 100644 index 00000000..97d3a225 --- /dev/null +++ b/plugin/native/alioss/src/main/java/io/edurt/datacap/plugin/natived/alioss/AliossParser.java @@ -0,0 +1,27 @@ +package io.edurt.datacap.plugin.natived.alioss; + +import io.edurt.datacap.spi.parser.SqlParser; +import io.edurt.datacap.sql.SqlBase; +import io.edurt.datacap.sql.SqlBaseToken; + +public class AliossParser + extends SqlParser +{ + public AliossParser(String content) + { + super(content); + } + + @Override + public String getExecuteContext() + { + SqlBase sqlBase = this.getSqlBase(); + if (sqlBase.getToken() == SqlBaseToken.SHOW) { + return sqlBase.getTable(); + } + else if (sqlBase.getToken() == SqlBaseToken.SELECT) { + return sqlBase.getTable(); + } + return null; + } +} diff --git a/plugin/native/alioss/src/main/java/io/edurt/datacap/plugin/natived/alioss/AliossPlugin.java b/plugin/native/alioss/src/main/java/io/edurt/datacap/plugin/natived/alioss/AliossPlugin.java new file mode 100644 index 00000000..614d2662 --- /dev/null +++ b/plugin/native/alioss/src/main/java/io/edurt/datacap/plugin/natived/alioss/AliossPlugin.java @@ -0,0 +1,80 @@ +package io.edurt.datacap.plugin.natived.alioss; + +import io.edurt.datacap.spi.Plugin; +import io.edurt.datacap.spi.PluginType; +import io.edurt.datacap.spi.adapter.Adapter; +import io.edurt.datacap.spi.connection.JdbcConfigure; +import io.edurt.datacap.spi.model.Configure; +import io.edurt.datacap.spi.model.Response; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.beanutils.BeanUtils; +import org.apache.commons.lang3.ObjectUtils; + +@Slf4j +public class AliossPlugin + implements Plugin +{ + private Configure configure; + private AliossConnection connection; + private Response response; + + @Override + public String validator() + { + return "SELECT * FROM default"; + } + + @Override + public String name() + { + return "Alioss"; + } + + @Override + public String description() + { + return "Integrate Alioss data sources"; + } + + @Override + public PluginType type() + { + return PluginType.NATIVE; + } + + @Override + public void connect(Configure configure) + { + try { + this.response = new Response(); + this.configure = new JdbcConfigure(); + BeanUtils.copyProperties(this.configure, configure); + this.connection = new AliossConnection(this.configure, this.response); + } + catch (Exception ex) { + this.response.setIsConnected(Boolean.FALSE); + this.response.setMessage(ex.getMessage()); + } + } + + @Override + public Response execute(String content) + { + if (ObjectUtils.isNotEmpty(this.connection)) { + log.info("Execute alioss plugin logic started"); + this.response = this.connection.getResponse(); + Adapter processor = new AliossAdapter(this.connection, new AliossParser(content)); + this.response = processor.handlerExecute(content); + log.info("Execute alioss plugin logic end"); + } + return this.response; + } + + @Override + public void destroy() + { + if (ObjectUtils.isNotEmpty(this.connection)) { + this.connection.destroy(); + } + } +} diff --git a/plugin/native/alioss/src/main/java/io/edurt/datacap/plugin/natived/alioss/AliossPluginModule.java b/plugin/native/alioss/src/main/java/io/edurt/datacap/plugin/natived/alioss/AliossPluginModule.java new file mode 100644 index 00000000..818696ae --- /dev/null +++ b/plugin/native/alioss/src/main/java/io/edurt/datacap/plugin/natived/alioss/AliossPluginModule.java @@ -0,0 +1,38 @@ +package io.edurt.datacap.plugin.natived.alioss; + +import com.google.inject.multibindings.Multibinder; +import io.edurt.datacap.spi.AbstractPluginModule; +import io.edurt.datacap.spi.Plugin; +import io.edurt.datacap.spi.PluginModule; +import io.edurt.datacap.spi.PluginType; + +public class AliossPluginModule + extends AbstractPluginModule + implements PluginModule +{ + @Override + public String getName() + { + return "Alioss"; + } + + @Override + public PluginType getType() + { + return PluginType.NATIVE; + } + + @Override + public AbstractPluginModule get() + { + return this; + } + + protected void configure() + { + Multibinder module = Multibinder.newSetBinder(this.binder(), String.class); + module.addBinding().toInstance(this.getClass().getSimpleName()); + Multibinder plugin = Multibinder.newSetBinder(this.binder(), Plugin.class); + plugin.addBinding().to(AliossPlugin.class); + } +} diff --git a/plugin/native/alioss/src/main/resources/META-INF/services/io.edurt.datacap.spi.PluginModule b/plugin/native/alioss/src/main/resources/META-INF/services/io.edurt.datacap.spi.PluginModule new file mode 100644 index 00000000..1730c9f2 --- /dev/null +++ b/plugin/native/alioss/src/main/resources/META-INF/services/io.edurt.datacap.spi.PluginModule @@ -0,0 +1 @@ +io.edurt.datacap.plugin.natived.alioss.AliossPluginModule diff --git a/plugin/native/alioss/src/test/java/io/edurt/datacap/plugin/natived/alioss/AliossPluginModuleTest.java b/plugin/native/alioss/src/test/java/io/edurt/datacap/plugin/natived/alioss/AliossPluginModuleTest.java new file mode 100644 index 00000000..0f39bc6a --- /dev/null +++ b/plugin/native/alioss/src/test/java/io/edurt/datacap/plugin/natived/alioss/AliossPluginModuleTest.java @@ -0,0 +1,30 @@ +package io.edurt.datacap.plugin.natived.alioss; + +import com.google.inject.Guice; +import com.google.inject.Injector; +import com.google.inject.Key; +import com.google.inject.TypeLiteral; +import io.edurt.datacap.spi.Plugin; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import java.util.Set; + +public class AliossPluginModuleTest +{ + private Injector injector; + + @Before + public void before() + { + this.injector = Guice.createInjector(new AliossPluginModule()); + } + + @Test + public void test() + { + Set plugins = injector.getInstance(Key.get(new TypeLiteral>() {})); + Assert.assertTrue(plugins.size() > 0); + } +} \ No newline at end of file diff --git a/plugin/native/alioss/src/test/java/io/edurt/datacap/plugin/natived/alioss/AliossPluginTest.java b/plugin/native/alioss/src/test/java/io/edurt/datacap/plugin/natived/alioss/AliossPluginTest.java new file mode 100644 index 00000000..861e7c4d --- /dev/null +++ b/plugin/native/alioss/src/test/java/io/edurt/datacap/plugin/natived/alioss/AliossPluginTest.java @@ -0,0 +1,46 @@ +package io.edurt.datacap.plugin.natived.alioss; + +import com.google.inject.Guice; +import com.google.inject.Injector; +import com.google.inject.Key; +import com.google.inject.TypeLiteral; +import io.edurt.datacap.spi.Plugin; +import io.edurt.datacap.spi.model.Configure; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import java.util.Optional; +import java.util.Set; + +public class AliossPluginTest +{ + private Injector injector; + private Configure configure; + + @Before + public void before() + { + injector = Guice.createInjector(new AliossPluginModule()); + configure = new Configure(); + configure.setHost("https://oss-cn-regison.aliyuncs.com"); + configure.setUsername(Optional.of("yourAccessKeyId")); + configure.setPassword(Optional.of("yourAccessKeySecret")); + configure.setDatabase(Optional.of("exampleBucket")); + } + + @Test + public void test() + { + Set plugins = injector.getInstance(Key.get(new TypeLiteral>() {})); + Optional pluginOptional = plugins.stream() + .filter(v -> v.name().equalsIgnoreCase("Alioss")) + .findFirst(); + if (pluginOptional.isPresent()) { + Plugin plugin = pluginOptional.get(); + plugin.connect(configure); + Assert.assertNotNull(plugin.execute(plugin.validator()).getConnection()); + plugin.destroy(); + } + } +} diff --git a/plugin/native/pom.xml b/plugin/native/pom.xml index cab6ea0e..0d456ec2 100644 --- a/plugin/native/pom.xml +++ b/plugin/native/pom.xml @@ -16,5 +16,6 @@ redis zookeeper + alioss \ No newline at end of file