Skip to content

Commit

Permalink
1.0.0.RC1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
jprante committed Jan 20, 2014
1 parent 114a9ac commit 39ecd2d
Show file tree
Hide file tree
Showing 126 changed files with 4,012 additions and 2,404 deletions.
11 changes: 5 additions & 6 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@ It is implemented as an `Elasticsearch plugin <http://www.elasticsearch.org/guid
The relational data is internally transformed into structured JSON objects for the schema-less indexing model in Elasticsearch.

Creating a JDBC river is easy. Install the plugin. Download a JDBC driver jar from your vendor's site (here MySQL) and put the jar into the folder of the plugin `$ES_HOME/plugins/river-jdbc`.
Then issue this command::
Then issue this simple command::

curl -XPUT 'localhost:9200/_river/my_jdbc_river/_meta' -d '{
"type" : "jdbc",
"jdbc" : {
"driver" : "com.mysql.jdbc.Driver",
"url" : "jdbc:mysql://localhost:3306/test",
"user" : "",
"password" : "",
Expand All @@ -39,8 +38,8 @@ Prerequisites
============= =========== ================= ===========================================================
ES version Plugin Release date Command
------------- ----------- ----------------- -----------------------------------------------------------
0.90.7 **2.3.1** Dec 14, 2013 ./bin/plugin -install river-jdbc -url http://bit.ly/1ctvKka
1.0.0.RC1 1.0.0.RC1.1 Jan 16, 2014 ./bin/plugin -install river-jdbc -url http://bit.ly/1fzvNCy
0.90.7 2.3.1 Dec 14, 2013 ./bin/plugin -install river-jdbc -url http://bit.ly/1ctvKka
1.0.0.RC1 1.0.0.RC1.2 Jan 20, 2014 ./bin/plugin -install river-jdbc -url http://bit.ly/1dKqNJy
============= =========== ================= ===========================================================

Do not forget to restart the node after installing.
Expand All @@ -59,6 +58,8 @@ Binaries are available at `Bintray <https://bintray.com/pkg/show/general/jprante
Documentation
-------------

Attention: working on the documentation for 1.0.0.RC1.2 is still in progress!

`Quickstart <../../../elasticsearch-river-jdbc/wiki/Quickstart>`_

`JDBC river parameters <../../../elasticsearch-river-jdbc/wiki/JDBC-River-parameters>`_
Expand All @@ -77,8 +78,6 @@ Documentation

`Setting up the river with PostgreSQL <../../../elasticsearch-river-jdbc/wiki/Step-by-step-recipe-for-setting-up-the-river-with-PostgreSQL>`_

`Loading from CSV <../../../elasticsearch-river-jdbc/wiki/Loading-CSV>`_

License
=======

Expand Down
11 changes: 0 additions & 11 deletions bin/create-csv-river.sh

This file was deleted.

7 changes: 3 additions & 4 deletions bin/create-mysql-river.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@

curl -XPUT 'localhost:9200/_river/my_jdbc_river/_meta' -d '{
curl -XPUT '0:9200/_river/my_jdbc_river/_meta' -d '{
"type" : "jdbc",
"jdbc" : {
"driver" : "com.mysql.jdbc.Driver",
"url" : "jdbc:mysql://localhost:3306/test",
"user" : "",
"password" : "",
"sql" : "select * from orders",
"strategy" : "simple"
"sql" : "select *, created as _id from orders",
"schedule" : "0/20 0-59 0-23 ? * *"
}
}'
10 changes: 10 additions & 0 deletions bin/create-oneshot-mysql-river.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

curl -XPUT '0:9200/_river/my_jdbc_river/_meta' -d '{
"type" : "jdbc",
"jdbc" : {
"url" : "jdbc:mysql://localhost:3306/test",
"user" : "",
"password" : "",
"sql" : "select *, created as _id from orders"
}
}'
17 changes: 10 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<groupId>org.xbib.elasticsearch.plugin</groupId>
<artifactId>elasticsearch-river-jdbc</artifactId>
<version>1.0.0.RC1.1</version>
<version>1.0.0.RC1.2</version>

<packaging>jar</packaging>

Expand Down Expand Up @@ -64,11 +64,6 @@
<enabled>false</enabled>
</snapshots>
</repository>
<!-- for modified CSV JDBC driver -->
<repository>
<id>github-release-repo</id>
<url>https://github.com/xbib/maven-repo/raw/master/releases</url>
</repository>
</repositories>

<properties>
Expand Down Expand Up @@ -96,7 +91,7 @@
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
<version>1.3</version>
<version>1.1</version>
<type>jar</type>
<scope>test</scope>
</dependency>
Expand Down Expand Up @@ -144,14 +139,22 @@
<skip>false</skip>
<forkMode>once</forkMode>
<useSystemClassLoader>false</useSystemClassLoader>
<!--
<systemPropertyVariables>
<java.io.tmpdir>${project.build.directory}</java.io.tmpdir>
<java.net.preferIPv4Stack>true</java.net.preferIPv4Stack>
<log4j.configuration>file:${project.build.testOutputDirectory}/log4j.properties</log4j.configuration>
</systemPropertyVariables>
-->
<includes>
<include>**/*Tests.java</include>
</includes>
<properties>
<property>
<name>listener</name>
<value>org.xbib.elasticsearch.river.jdbc.Listener</value>
</property>
</properties>
</configuration>
</plugin>
<plugin>
Expand Down
20 changes: 3 additions & 17 deletions src/main/assemblies/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,9 @@
<useProjectArtifact>true</useProjectArtifact>
<unpack>false</unpack>
<scope>compile</scope>
<excludes>
<exclude>org.elasticsearch</exclude>
<exclude>org.apache.lucene</exclude>
<exclude>com.spatial4j</exclude>
</excludes>
</dependencySet>
</dependencySets>
<fileSets>
<fileSet>
<directory>${project.build.directory}</directory>
<outputDirectory>/</outputDirectory>
<includes>
<include>*.jar</include>
<include>org.xbib.elasticsearch.plugin</include>
</includes>
<excludes>
<exclude>*sources*.jar</exclude>
</excludes>
</fileSet>
</fileSets>
</dependencySet>
</dependencySets>
</assembly>
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
import org.elasticsearch.plugins.AbstractPlugin;
import org.elasticsearch.rest.RestModule;
import org.elasticsearch.river.RiversModule;

import org.xbib.elasticsearch.rest.action.RestJDBCRiverCreateAction;
import org.xbib.elasticsearch.rest.action.RestJDBCRiverInduceAction;
import org.xbib.elasticsearch.rest.action.RestJDBCRiverStateAction;
import org.xbib.elasticsearch.river.jdbc.JDBCRiver;
import org.xbib.elasticsearch.river.jdbc.JDBCRiverModule;

Expand All @@ -16,8 +19,6 @@
* binds a JDBCRiver instance to a River interface - and the
* REST move is configured. Also, a concurrent bulk move
* is registered.
*
* @author Jörg Prante <joergprante@gmail.com>
*/
public class JDBCRiverPlugin extends AbstractPlugin {

Expand All @@ -36,21 +37,23 @@ public String description() {
}

/**
* Register the JDBC river to Elasticsearch node
* Register the river to Elasticsearch
*
* @param module
* @param module the rivers module
*/
public void onModule(RiversModule module) {
module.registerRiver(JDBCRiver.TYPE, JDBCRiverModule.class);
}

/**
* Register the REST move to Elasticsearch node
* Register the REST actions of this river
*
* @param module
* @param module the REST module
*/
public void onModule(RestModule module) {
module.addRestAction(RestJDBCRiverCreateAction.class);
module.addRestAction(RestJDBCRiverInduceAction.class);
module.addRestAction(RestJDBCRiverStateAction.class);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package org.xbib.elasticsearch.rest.action;

import java.io.IOException;
import java.lang.reflect.Field;

import org.elasticsearch.client.Client;
import org.elasticsearch.common.collect.ImmutableMap;
import org.elasticsearch.common.inject.Injector;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.rest.BaseRestHandler;
import org.elasticsearch.rest.RestChannel;
import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.rest.RestStatus;
import org.elasticsearch.rest.XContentRestResponse;
import org.elasticsearch.rest.XContentThrowableRestResponse;
import org.elasticsearch.rest.action.support.RestXContentBuilder;
import org.elasticsearch.river.River;
import org.elasticsearch.river.RiverName;
import org.elasticsearch.river.RiversService;

public abstract class AbstractRestRiverAction extends BaseRestHandler {

protected Injector injector;

public AbstractRestRiverAction(Settings settings, Client client, Injector injector) {
super(settings, client);
this.injector = injector;
}

protected void respond(boolean success, RestRequest request, RestChannel channel, String error, RestStatus status) {
try {
XContentBuilder builder = RestXContentBuilder.restContentBuilder(request);
builder.startObject();
builder.field("success", success);
if (error != null) {
builder.field("error", error);
}
builder.endObject();
channel.sendResponse(new XContentRestResponse(request, status, builder));
} catch (IOException e) {
errorResponse(request, channel, e);
}
}

protected void errorResponse(RestRequest request, RestChannel channel, Throwable e) {
try {
channel.sendResponse(new XContentThrowableRestResponse(request, e));
} catch (IOException e1) {
logger.error("Failed to send failure response", e1);
}
}

/**
* Retrieve the registered rivers using reflection (UGLY HACK!!)
* TODO: Obtain the rivers using public API
* @param injector injector
* @return map of rivers or null if not possible
*/
protected ImmutableMap<RiverName, River> rivers(Injector injector) {
RiversService riversService = injector.getInstance(RiversService.class);
try {
Field field = RiversService.class.getDeclaredField("rivers");
field.setAccessible(true);
return (ImmutableMap<RiverName, River>) field.get(riversService);
} catch (NoSuchFieldException e) {
return null;
} catch (IllegalAccessException e) {
return null;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package org.xbib.elasticsearch.rest.action;

import java.io.IOException;

import org.elasticsearch.client.Client;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.inject.Injector;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentHelper;
import org.elasticsearch.rest.RestChannel;
import org.elasticsearch.rest.RestController;
import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.rest.XContentRestResponse;
import org.elasticsearch.rest.XContentThrowableRestResponse;
import org.elasticsearch.river.RiverName;
import org.elasticsearch.river.RiverSettings;

import org.xbib.elasticsearch.river.jdbc.JDBCRiver;

import static org.elasticsearch.rest.RestStatus.OK;
import static org.elasticsearch.rest.action.support.RestXContentBuilder.restContentBuilder;

public class RestJDBCRiverCreateAction extends AbstractRestRiverAction {

private Settings settings = ImmutableSettings.EMPTY;

@Inject
public RestJDBCRiverCreateAction(Settings settings, Client client,
RestController controller, Injector injector) {
super(settings, client, injector);
this.settings = settings;
controller.registerHandler(RestRequest.Method.POST, "/_river/jdbc/{river}/create", this);
}

@Override
public void handleRequest(RestRequest request, RestChannel channel) {
try {
String riverName = request.param("river");
RiverSettings riverSettings = new RiverSettings(settings,
XContentHelper.convertToMap(request.content(), true).v2()) ;
JDBCRiver river = new JDBCRiver(new RiverName("jdbc", riverName), riverSettings, client);
river.start();
XContentBuilder builder = restContentBuilder(request);
builder.startObject()
.field("active", river.riverFlow().isActive())
.endObject();
channel.sendResponse(new XContentRestResponse(request, OK, builder));
} catch (IOException ioe) {
try {
channel.sendResponse(new XContentThrowableRestResponse(request, ioe));
} catch (IOException e) {
logger.error("unable to send response to client");
}
}
}

}
Loading

0 comments on commit 39ecd2d

Please sign in to comment.