You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by jb...@apache.org on 2015/02/04 17:35:47 UTC

[03/30] karaf-decanter git commit: Add elasticsearch embedded node and feature

Add elasticsearch embedded node and feature


Project: http://git-wip-us.apache.org/repos/asf/karaf-decanter/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf-decanter/commit/c63cb3b0
Tree: http://git-wip-us.apache.org/repos/asf/karaf-decanter/tree/c63cb3b0
Diff: http://git-wip-us.apache.org/repos/asf/karaf-decanter/diff/c63cb3b0

Branch: refs/heads/master
Commit: c63cb3b04653e15b6310047fba1a9ec35db1ab37
Parents: 4a3bdae
Author: Jean-Baptiste Onofré <jb...@apache.org>
Authored: Tue Oct 14 18:25:25 2014 +0200
Committer: Jean-Baptiste Onofré <jb...@apache.org>
Committed: Tue Oct 14 18:25:25 2014 +0200

----------------------------------------------------------------------
 appender/elasticsearch/pom.xml                  |  2 +-
 assembly/src/main/feature/feature.xml           |  8 +-
 elasticsearch/pom.xml                           | 82 ++++++++++++++++++
 .../karaf/decanter/elasticsearch/Activator.java | 39 +++++++++
 .../decanter/elasticsearch/EmbeddedNode.java    | 91 ++++++++++++++++++++
 pom.xml                                         |  3 +
 6 files changed, 222 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf-decanter/blob/c63cb3b0/appender/elasticsearch/pom.xml
----------------------------------------------------------------------
diff --git a/appender/elasticsearch/pom.xml b/appender/elasticsearch/pom.xml
index dc94847..f2a063d 100644
--- a/appender/elasticsearch/pom.xml
+++ b/appender/elasticsearch/pom.xml
@@ -45,7 +45,7 @@
         <dependency>
             <groupId>org.elasticsearch</groupId>
             <artifactId>elasticsearch</artifactId>
-            <version>1.3.4</version>
+            <version>${elasticsearch.version}</version>
         </dependency>
 
         <!-- OSGi -->

http://git-wip-us.apache.org/repos/asf/karaf-decanter/blob/c63cb3b0/assembly/src/main/feature/feature.xml
----------------------------------------------------------------------
diff --git a/assembly/src/main/feature/feature.xml b/assembly/src/main/feature/feature.xml
index 022f242..2d5e1c1 100644
--- a/assembly/src/main/feature/feature.xml
+++ b/assembly/src/main/feature/feature.xml
@@ -45,11 +45,15 @@
 
     <feature name="decanter-appender-elasticsearch" version="${project.version}" description="Karaf Decanter Elasticsearch Appender">
         <feature version="${project.version}">decanter-common</feature>
-        <bundle>mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.elasticsearch/1.3.4_1</bundle>
+        <bundle>mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.elasticsearch/${elasticsearch.bundle.version}</bundle>
         <bundle>mvn:org.apache.karaf.decanter.appender/org.apache.karaf.decanter.appender.elasticsearch/${project.version}</bundle>
     </feature>
 
-    <!-- TODO create elasticsearch feature (embedded in Karaf) -->
+    <feature name="elasticsearch" version="${elasticsearch.version}" description="Embedded Elasticsearch node">
+        <bundle>mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.elasticsearch/${elasticsearch.bundle.version}</bundle>
+        <bundle>mvn:org.apache.karaf.decanter/org.apache.karaf.decanter.elasticsearch/${project.version}</bundle>
+    </feature>
+
     <!-- TODO create webconsole/kibana feature (embedded in Karaf) -->
 
 </features>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/karaf-decanter/blob/c63cb3b0/elasticsearch/pom.xml
----------------------------------------------------------------------
diff --git a/elasticsearch/pom.xml b/elasticsearch/pom.xml
new file mode 100644
index 0000000..c862e41
--- /dev/null
+++ b/elasticsearch/pom.xml
@@ -0,0 +1,82 @@
+<?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">
+
+    <!--
+
+        Licensed to the Apache Software Foundation (ASF) under one or more
+        contributor license agreements.  See the NOTICE file distributed with
+        this work for additional information regarding copyright ownership.
+        The ASF licenses this file to You under the Apache License, Version 2.0
+        (the "License"); you may not use this file except in compliance with
+        the License.  You may obtain a copy of the License at
+
+           http://www.apache.org/licenses/LICENSE-2.0
+
+        Unless required by applicable law or agreed to in writing, software
+        distributed under the License is distributed on an "AS IS" BASIS,
+        WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+        See the License for the specific language governing permissions and
+        limitations under the License.
+    -->
+
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>org.apache.karaf</groupId>
+        <artifactId>decanter</artifactId>
+        <version>3.0.0-SNAPSHOT</version>
+        <relativePath>../pom.xml</relativePath>
+    </parent>
+
+    <groupId>org.apache.karaf.decanter</groupId>
+    <artifactId>org.apache.karaf.decanter.elasticsearch</artifactId>
+    <packaging>bundle</packaging>
+    <name>Apache Karaf :: Decanter :: Elasticsearch</name>
+
+    <dependencies>
+
+        <!-- Elasticsearch -->
+        <dependency>
+            <groupId>org.elasticsearch</groupId>
+            <artifactId>elasticsearch</artifactId>
+            <version>${elasticsearch.version}</version>
+        </dependency>
+
+        <!-- SLF4J -->
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-api</artifactId>
+        </dependency>
+
+        <!-- OSGi -->
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.core</artifactId>
+        </dependency>
+
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-bundle-plugin</artifactId>
+                <inherited>true</inherited>
+                <extensions>true</extensions>
+                <configuration>
+                    <instructions>
+                        <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
+                        <Bundle-Version>${project.version}</Bundle-Version>
+                        <Bundle-Activator>org.apache.karaf.decanter.elasticsearch.Activator</Bundle-Activator>
+                        <Import-Package>
+                            org.elasticsearch*;version="[1,2)",
+                            org.slf4j;version="[1.7,2)";resolution:=optional,
+                            *
+                        </Import-Package>
+                    </instructions>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+
+</project>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/karaf-decanter/blob/c63cb3b0/elasticsearch/src/main/java/org/apache/karaf/decanter/elasticsearch/Activator.java
----------------------------------------------------------------------
diff --git a/elasticsearch/src/main/java/org/apache/karaf/decanter/elasticsearch/Activator.java b/elasticsearch/src/main/java/org/apache/karaf/decanter/elasticsearch/Activator.java
new file mode 100644
index 0000000..2a55d6a
--- /dev/null
+++ b/elasticsearch/src/main/java/org/apache/karaf/decanter/elasticsearch/Activator.java
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.karaf.decanter.elasticsearch;
+
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+
+public class Activator implements BundleActivator {
+
+    private EmbeddedNode node;
+
+    public void start(BundleContext bundleContext) throws Exception {
+        if (node == null) {
+            node = new EmbeddedNode();
+        }
+        node.start();
+    }
+
+    public void stop(BundleContext bundleContext) throws Exception {
+        if (node != null) {
+            node.stop();
+        }
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/karaf-decanter/blob/c63cb3b0/elasticsearch/src/main/java/org/apache/karaf/decanter/elasticsearch/EmbeddedNode.java
----------------------------------------------------------------------
diff --git a/elasticsearch/src/main/java/org/apache/karaf/decanter/elasticsearch/EmbeddedNode.java b/elasticsearch/src/main/java/org/apache/karaf/decanter/elasticsearch/EmbeddedNode.java
new file mode 100644
index 0000000..8ccb26a
--- /dev/null
+++ b/elasticsearch/src/main/java/org/apache/karaf/decanter/elasticsearch/EmbeddedNode.java
@@ -0,0 +1,91 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.karaf.decanter.elasticsearch;
+
+import org.elasticsearch.common.settings.ImmutableSettings;
+import org.elasticsearch.common.settings.Settings;
+import org.elasticsearch.node.Node;
+import org.elasticsearch.node.internal.InternalNode;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.File;
+
+import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
+
+/**
+ * Start an Elasticsearch node internally to Karaf.
+ */
+public class EmbeddedNode {
+
+    private final static Logger LOGGER = LoggerFactory.getLogger(EmbeddedNode.class);
+
+    private final static String DATA_DIRECTORY = "data/elasticsearch";
+    private final static String NODE_NAME = "KARAF";
+    private static Node node;
+
+    public EmbeddedNode() throws Exception {
+        LOGGER.info("Starting Elasticsearch node ...");
+
+        LOGGER.debug("Creating elasticsearch settings");
+        String karafHome = System.getProperty("karaf.home");
+        File pluginsFile = new File("file://" + karafHome + "/elasticsearch/plugins");
+        Settings settings = settingsBuilder()
+                .put("cluster.name", "elasticsearch")
+                .put("http.enabled", "true")
+                .put("node.data", true)
+                .put("path.data", DATA_DIRECTORY)
+                .put("name", NODE_NAME)
+                .put("discovery.type", "zen")
+                .put("discovery.zen.multicast.enabled", false)
+                .put("discovery.zen.ping.unicast.enabled", true)
+                .put("discovery.zen.unicast.hosts", "127.0.0.1")
+                .put("network.host", "127.0.0.1")
+                .put("gateway.type", "none")
+                .put("cluster.routing.schedule", "50ms")
+                .put("path.plugins", pluginsFile.getAbsolutePath())
+                .build();
+
+        LOGGER.debug("Creating the elasticsearch node");
+        ImmutableSettings.Builder builder = ImmutableSettings.settingsBuilder();
+        builder.put(settings);
+        builder.classLoader(Settings.class.getClassLoader());
+        node = new InternalNode(builder.build(), false);
+
+        LOGGER.info("Elasticsearch node started");
+    }
+
+    public void start() throws Exception {
+        if (node != null) {
+            node.start();
+        }
+    }
+
+    public void stop() throws Exception {
+        if (node != null) {
+            node.close();
+        }
+    }
+
+    public boolean isStarted() throws Exception {
+        if (node != null) {
+            return !node.isClosed();
+        }
+        return false;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/karaf-decanter/blob/c63cb3b0/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index f37ba82..5ef1e58 100644
--- a/pom.xml
+++ b/pom.xml
@@ -35,6 +35,8 @@
     <name>Apache Karaf :: Decanter</name>
 
     <properties>
+        <elasticsearch.version>1.3.4</elasticsearch.version>
+        <elasticsearch.bundle.version>1.3.4_1</elasticsearch.bundle.version>
         <karaf.version>3.0.2-SNAPSHOT</karaf.version>
         <slf4j.version>1.7.7</slf4j.version>
     </properties>
@@ -45,6 +47,7 @@
         <module>collector</module>
         <module>dispatcher</module>
         <module>appender</module>
+        <module>elasticsearch</module>
         <!-- TODO complete command -->
         <!-- TODO add angularjs or bootstrap webconsole/kibana (embedded) -->
         <module>assembly</module>