plugin: Add elasticsearch

This commit is contained in:
qianmoQ 2022-09-28 14:37:40 +08:00
parent ff292da8f8
commit 77fe3f6f60
12 changed files with 301 additions and 0 deletions

View File

@ -58,6 +58,7 @@ Here are some of the major database solutions that are supported:
<a href="https://redis.io/" target="_blank"><img src="./shared/plugin/redis.svg" alt="Redis" class="a" width="auto" height="40" /></a>
<a href="https://www.postgresql.org/" target="_blank"><img src="./shared/plugin/postgresql.png" alt="PostgreSQL" class="a" width="auto" height="40" /></a>
<a href="https://trino.io/" target="_blank"><img src="./shared/plugin/trino.jpg" alt="Trino" class="a" width="auto" height="50" /></a>
<a href="https://www.elastic.co/" target="_blank"><img src="./shared/plugin/elasticsearch.svg" alt="ElasticSearch" class="a" width="133" height="50" /></a>
</p>
## Join Us

View File

@ -0,0 +1,60 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>datacap-plugin-jdbc</artifactId>
<groupId>io.edurt.datacap.plugin.jdbc</groupId>
<version>1.0.0.20221015</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>datacap-plugin-jdbc-elasticsearch</artifactId>
<name>DataCap plugin for jdbc (ElasticSearch)</name>
<properties>
<x-pack-sql-jdbc.version>6.8.11</x-pack-sql-jdbc.version>
<plugin.name>jdbc-elasticsearch</plugin.name>
</properties>
<dependencies>
<dependency>
<groupId>io.edurt.datacap</groupId>
<artifactId>datacap-spi</artifactId>
</dependency>
<dependency>
<groupId>org.elasticsearch.plugin</groupId>
<artifactId>x-pack-sql-jdbc</artifactId>
<version>${x-pack-sql-jdbc.version}</version>
</dependency>
<dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>${assembly-plugin.version}</version>
<configuration>
<finalName>${plugin.name}</finalName>
<descriptors>
<descriptor>../../../configure/assembly/assembly-plugin.xml</descriptor>
</descriptors>
<outputDirectory>../../../dist/plugins/${plugin.name}</outputDirectory>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,13 @@
package io.edurt.datacap.plugin.jdbc.elasticsearch;
import io.edurt.datacap.spi.adapter.JdbcAdapter;
import io.edurt.datacap.spi.connection.JdbcConnection;
public class ElasticSearchAdapter
extends JdbcAdapter
{
public ElasticSearchAdapter(JdbcConnection jdbcConnection)
{
super(jdbcConnection);
}
}

View File

@ -0,0 +1,14 @@
package io.edurt.datacap.plugin.jdbc.elasticsearch;
import io.edurt.datacap.spi.connection.JdbcConfigure;
import io.edurt.datacap.spi.connection.JdbcConnection;
import io.edurt.datacap.spi.model.Response;
public class ElasticSearchConnection
extends JdbcConnection
{
public ElasticSearchConnection(JdbcConfigure jdbcConfigure, Response response)
{
super(jdbcConfigure, response);
}
}

View File

@ -0,0 +1,72 @@
package io.edurt.datacap.plugin.jdbc.elasticsearch;
import io.edurt.datacap.spi.Plugin;
import io.edurt.datacap.spi.PluginType;
import io.edurt.datacap.spi.adapter.JdbcAdapter;
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;
@Slf4j
public class ElasticSearchPlugin
implements Plugin
{
private JdbcConfigure jdbcConfigure;
private ElasticSearchConnection connection;
private Response response;
@Override
public String name()
{
return "ElasticSearch";
}
@Override
public String description()
{
return "Integrate ElasticSearch data sources";
}
@Override
public PluginType type()
{
return PluginType.SOURCE;
}
@Override
public void connect(Configure configure)
{
try {
this.response = new Response();
this.jdbcConfigure = new JdbcConfigure();
BeanUtils.copyProperties(this.jdbcConfigure, configure);
this.jdbcConfigure.setJdbcDriver("org.elasticsearch.xpack.sql.jdbc.EsDriver");
this.jdbcConfigure.setJdbcType("es");
this.connection = new ElasticSearchConnection(this.jdbcConfigure, this.response);
}
catch (Exception ex) {
this.response.setIsSuccessful(Boolean.FALSE);
this.response.setMessage(ex.getMessage());
throw new RuntimeException(ex);
}
}
@Override
public Response execute(String content)
{
log.info("Execute elasticsearch plugin logic started");
this.response = this.connection.getResponse();
JdbcAdapter processor = new ElasticSearchAdapter(this.connection);
this.response = processor.handlerJDBCExecute(content);
log.info("Execute elasticsearch plugin logic end");
return this.response;
}
@Override
public void destroy()
{
this.connection.destroy();
}
}

View File

@ -0,0 +1,38 @@
package io.edurt.datacap.plugin.jdbc.elasticsearch;
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 ElasticSearchPluginModule
extends AbstractPluginModule
implements PluginModule
{
@Override
public String getName()
{
return "ElasticSearch";
}
@Override
public PluginType getType()
{
return PluginType.SOURCE;
}
@Override
public AbstractPluginModule get()
{
return this;
}
protected void configure()
{
Multibinder<String> module = Multibinder.newSetBinder(this.binder(), String.class);
module.addBinding().toInstance(this.getClass().getSimpleName());
Multibinder<Plugin> plugin = Multibinder.newSetBinder(this.binder(), Plugin.class);
plugin.addBinding().to(ElasticSearchPlugin.class);
}
}

View File

@ -0,0 +1 @@
io.edurt.datacap.plugin.jdbc.elasticsearch.ElasticSearchPluginModule

View File

@ -0,0 +1,30 @@
package io.edurt.datacap.plugin.jdbc.elasticsearch;
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 ElasticSearchPluginModuleTest
{
private Injector injector;
@Before
public void before()
{
this.injector = Guice.createInjector(new ElasticSearchPluginModule());
}
@Test
public void test()
{
Set<Plugin> plugins = injector.getInstance(Key.get(new TypeLiteral<Set<Plugin>>() {}));
Assert.assertTrue(plugins.size() > 0);
}
}

View File

@ -0,0 +1,43 @@
package io.edurt.datacap.plugin.jdbc.elasticsearch;
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.Before;
import org.junit.Test;
import java.util.Optional;
import java.util.Set;
public class ElasticSearchPluginTest
{
private Injector injector;
private Configure configure;
@Before
public void before()
{
injector = Guice.createInjector(new ElasticSearchPluginModule());
configure = new Configure();
configure.setHost("127.0.0.1");
configure.setPort(9200);
}
@Test
public void test()
{
Set<Plugin> plugins = injector.getInstance(Key.get(new TypeLiteral<Set<Plugin>>() {}));
Optional<Plugin> pluginOptional = plugins.stream()
.filter(v -> v.name().equalsIgnoreCase("ElasticSearch"))
.findFirst();
if (pluginOptional.isPresent()) {
Plugin plugin = pluginOptional.get();
plugin.connect(configure);
System.out.println(plugin.execute("SHOW TABLES"));
plugin.destroy();
}
}
}

View File

@ -20,5 +20,6 @@
<module>postgresql</module>
<module>redis</module>
<module>trino</module>
<module>elasticsearch</module>
</modules>
</project>

View File

@ -99,6 +99,11 @@
<artifactId>datacap-plugin-jdbc-postgresql</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.edurt.datacap.plugin.jdbc</groupId>
<artifactId>datacap-plugin-jdbc-elasticsearch</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<build>

View File

@ -0,0 +1,23 @@
<svg width="500" height="172" viewBox="0 0 500 172" fill="none" xmlns="http://www.w3.org/2000/svg">
<g clip-path="url(#clip0_15_21)">
<path d="M172.05 89.79C172.066 82.8086 169.924 75.9929 165.915 70.2767C161.907 64.5606 156.229 60.2236 149.66 57.86C150.258 54.813 150.559 51.7152 150.56 48.61C150.566 38.3319 147.312 28.3167 141.267 20.0043C135.222 11.6919 126.697 5.51043 116.917 2.3487C107.138 -0.813038 96.6072 -0.792202 86.8401 2.40821C77.073 5.60863 68.5722 11.8238 62.5601 20.16C58.1246 16.7229 52.6898 14.8248 47.0788 14.7535C41.4678 14.6822 35.9865 16.4414 31.465 19.7646C26.9435 23.0879 23.6283 27.7942 22.0214 33.1707C20.4146 38.5471 20.6037 44.3007 22.5601 49.56C15.9754 51.9601 10.2837 56.3191 6.25042 62.0507C2.21719 67.7824 0.0359539 74.6117 0.000115291 81.62C-0.018156 88.6256 2.13571 95.4646 6.16517 101.195C10.1946 106.926 15.9015 111.267 22.5001 113.62C21.916 116.666 21.618 119.759 21.6101 122.86C21.6003 133.126 24.8511 143.13 30.8937 151.43C36.9364 159.729 45.4586 165.895 55.2317 169.039C65.0048 172.182 75.5237 172.141 85.2717 168.92C95.0197 165.7 103.493 159.467 109.47 151.12C113.893 154.566 119.318 156.475 124.924 156.559C130.53 156.643 136.01 154.896 140.533 151.584C145.057 148.271 148.377 143.574 149.989 138.205C151.602 132.835 151.42 127.087 149.47 121.83C156.058 119.434 161.754 115.076 165.789 109.344C169.825 103.612 172.006 96.7803 172.04 89.77" fill="white"/>
<path d="M67.64 73.81L105.29 91L143.29 57.72C143.837 54.974 144.109 52.1801 144.1 49.38C144.098 40.315 141.195 31.4886 135.815 24.1923C130.436 16.896 122.863 11.5129 114.203 8.83068C105.544 6.14846 96.254 6.30793 87.6921 9.28575C79.1301 12.2636 71.7459 17.9034 66.62 25.38L60.29 58.12L67.64 73.81Z" fill="#FEC514"/>
<path d="M28.6701 113.68C28.115 116.469 27.8369 119.306 27.8401 122.15C27.8403 131.253 30.7583 140.116 36.1659 147.438C41.5735 154.761 49.1858 160.157 57.8857 162.835C66.5856 165.513 75.9149 165.332 84.5043 162.318C93.0937 159.305 100.491 153.617 105.61 146.09L111.88 113.42L103.51 97.4201L65.7201 80.2001L28.6701 113.68Z" fill="#00BFB3"/>
<path d="M28.4401 48.53L54.2401 54.62L59.8901 25.28C56.3809 22.6191 52.1042 21.1665 47.7004 21.1397C43.2965 21.1128 39.0024 22.5133 35.4611 25.1313C31.9198 27.7492 29.3218 31.4439 28.0561 35.662C26.7904 39.8802 26.9251 44.3948 28.4401 48.53Z" fill="#F04E98"/>
<path d="M26.2002 54.67C20.5394 56.5802 15.6146 60.2071 12.1108 65.0461C8.60695 69.8852 6.69825 75.6959 6.65015 81.67C6.64608 87.4439 8.39949 93.0822 11.6773 97.8354C14.955 102.589 19.6019 106.232 25.0002 108.28L61.2002 75.56L54.5502 61.36L26.2002 54.67Z" fill="#1BA9F5"/>
<path d="M112.23 146.09C115.734 148.737 120 150.181 124.391 150.204C128.782 150.227 133.063 148.83 136.594 146.22C140.126 143.61 142.718 139.927 143.985 135.722C145.251 131.518 145.123 127.016 143.62 122.89L117.84 116.89L112.23 146.09Z" fill="#93C90E"/>
<path d="M117.47 110.1L145.85 116.73C151.514 114.825 156.442 111.2 159.947 106.359C163.452 101.519 165.358 95.7057 165.4 89.7301C165.395 83.9684 163.638 78.3445 160.363 73.6044C157.087 68.8644 152.448 65.2323 147.06 63.1901L109.94 95.6901L117.47 110.1Z" fill="#0077CC"/>
<path d="M240.56 120.4L244 120.05L244.24 127.05C236.585 128.206 228.861 128.841 221.12 128.95C212.587 128.95 206.54 126.48 202.98 121.54C199.42 116.6 197.643 108.913 197.65 98.48C197.65 77.7 205.91 67.3067 222.43 67.3C230.43 67.3 236.397 69.5334 240.33 74C244.264 78.4667 246.237 85.4667 246.25 95L245.78 101.76H206.66C206.66 108.32 207.847 113.18 210.22 116.34C212.594 119.5 216.72 121.08 222.6 121.08C228.494 121.1 234.48 120.873 240.56 120.4ZM237.36 94.68C237.36 87.4067 236.197 82.27 233.87 79.27C231.543 76.27 227.75 74.7667 222.49 74.76C217.23 74.76 213.277 76.34 210.63 79.5C207.984 82.66 206.62 87.72 206.54 94.68H237.36Z" fill="#1C1E23"/>
<path d="M258.65 128.48V50.48H267.54V128.48H258.65Z" fill="#1C1E23"/>
<path d="M323.53 86.38V116.28C323.53 119.28 330.91 119.12 330.91 119.12L330.46 126.98C324.21 126.98 319.04 127.5 315.94 124.49C309.227 127.472 301.955 128.989 294.61 128.94C289.163 128.94 285.013 127.397 282.16 124.31C279.307 121.223 277.883 116.787 277.89 111C277.89 105.227 279.353 100.977 282.28 98.25C285.207 95.5234 289.79 93.8567 296.03 93.25L314.64 91.48V86.38C314.64 82.38 313.773 79.4934 312.04 77.72C311.09 76.8285 309.97 76.1385 308.746 75.6917C307.522 75.2449 306.221 75.0504 304.92 75.12H281.56V67.29H304.33C311.05 67.29 315.93 68.8334 318.97 71.92C322.01 75.0067 323.53 79.8267 323.53 86.38ZM287 110.56C287 117.833 290 121.47 296 121.47C301.413 121.464 306.786 120.541 311.89 118.74L314.61 117.79V98.23L297.1 99.89C293.54 100.21 290.97 101.237 289.39 102.97C287.81 104.703 287.013 107.233 287 110.56Z" fill="#1C1E23"/>
<path d="M358.24 75.24C349.62 75.24 345.31 78.24 345.31 84.24C345.31 87.0134 346.31 88.97 348.31 90.11C350.31 91.25 354.814 92.4367 361.82 93.67C368.86 94.9034 373.84 96.6234 376.76 98.83C379.68 101.037 381.144 105.183 381.15 111.27C381.15 117.363 379.194 121.83 375.28 124.67C371.367 127.51 365.657 128.933 358.15 128.94C353.25 128.94 336.89 127.12 336.89 127.12L337.37 119.42C346.77 120.32 353.56 120.99 358.15 120.99C362.74 120.99 366.23 120.26 368.64 118.8C371.05 117.34 372.25 114.89 372.25 111.45C372.25 108.01 371.25 105.68 369.17 104.45C367.09 103.22 362.61 102.06 355.66 100.95C348.71 99.84 343.76 98.22 340.84 96.09C337.92 93.96 336.45 90 336.45 84.23C336.45 78.46 338.45 74.23 342.56 71.43C346.67 68.63 351.71 67.28 357.79 67.28C362.61 67.28 379.34 68.51 379.34 68.51V76.26C370.51 75.87 363.29 75.24 358.24 75.24Z" fill="#1C1E23"/>
<path d="M424 76.1801H405.15V104.52C405.15 111.313 405.643 115.777 406.63 117.91C407.63 120.05 409.97 121.11 413.68 121.11L424.23 120.4L424.83 127.75C420.835 128.489 416.79 128.926 412.73 129.06C406.57 129.06 402.303 127.557 399.93 124.55C397.557 121.543 396.373 115.813 396.38 107.36V76.1801H388V68.4801H396.42V50.3401H405.19V68.4801H424V76.1801Z" fill="#1C1E23"/>
<path d="M436.36 60.9101V50.5901H445.25V60.9101H436.36ZM436.36 128.48V68.4801H445.25V128.48H436.36Z" fill="#1C1E23"/>
<path d="M483.76 67.29C488.2 67.4795 492.622 67.9572 497 68.72L499.84 69.07L499.49 76.3C494.844 75.7114 490.172 75.3576 485.49 75.24C478.77 75.24 474.207 76.84 471.8 80.04C469.393 83.24 468.187 89.1667 468.18 97.82C468.18 106.487 469.307 112.513 471.56 115.9C473.813 119.287 478.513 120.987 485.66 121L499.66 119.94L500.02 127.29C494.57 128.213 489.065 128.768 483.54 128.95C474.3 128.95 467.92 126.577 464.4 121.83C460.88 117.083 459.12 109.083 459.12 97.83C459.12 86.57 461.017 78.6667 464.81 74.12C468.603 69.5734 474.92 67.2967 483.76 67.29Z" fill="#1C1E23"/>
</g>
<defs>
<clipPath id="clip0_15_21">
<rect width="500" height="171.38" fill="white"/>
</clipPath>
</defs>
</svg>

After

Width:  |  Height:  |  Size: 6.5 KiB