Author: matthieu
Date: Tue Nov  3 16:47:57 2015
New Revision: 1712331

URL: http://svn.apache.org/viewvc?rev=1712331&view=rev
Log:
JAMES-1626 Add ElasticSearch support to cassandra-guice application

Added:
    
james/project/trunk/server/container/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/ElasticSearchMailboxModule.java
    
james/project/trunk/server/container/cassandra-guice/src/test/java/org/apache/james/modules/
    
james/project/trunk/server/container/cassandra-guice/src/test/java/org/apache/james/modules/TestElasticSearchModule.java
    
james/project/trunk/server/container/cassandra-guice/src/test/resources/elasticsearch.properties
Modified:
    james/project/trunk/server/container/cassandra-guice/pom.xml
    
james/project/trunk/server/container/cassandra-guice/src/main/java/org/apache/james/CassandraJamesServerMain.java
    
james/project/trunk/server/container/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/CassandraMailboxModule.java
    
james/project/trunk/server/container/cassandra-guice/src/test/java/org/apache/james/CassandraJamesServerTest.java
    james/project/trunk/server/pom.xml

Modified: james/project/trunk/server/container/cassandra-guice/pom.xml
URL: 
http://svn.apache.org/viewvc/james/project/trunk/server/container/cassandra-guice/pom.xml?rev=1712331&r1=1712330&r2=1712331&view=diff
==============================================================================
--- james/project/trunk/server/container/cassandra-guice/pom.xml (original)
+++ james/project/trunk/server/container/cassandra-guice/pom.xml Tue Nov  3 
16:47:57 2015
@@ -188,6 +188,12 @@
                 </dependency>
                 <dependency>
                     <groupId>${project.groupId}</groupId>
+                    <artifactId>apache-james-mailbox-elasticsearch</artifactId>
+                    <type>test-jar</type>
+                    <scope>test</scope>
+                </dependency>
+                <dependency>
+                    <groupId>${project.groupId}</groupId>
                     <artifactId>apache-james-mailbox-tika</artifactId>
                 </dependency>
                 <dependency>

Modified: 
james/project/trunk/server/container/cassandra-guice/src/main/java/org/apache/james/CassandraJamesServerMain.java
URL: 
http://svn.apache.org/viewvc/james/project/trunk/server/container/cassandra-guice/src/main/java/org/apache/james/CassandraJamesServerMain.java?rev=1712331&r1=1712330&r2=1712331&view=diff
==============================================================================
--- 
james/project/trunk/server/container/cassandra-guice/src/main/java/org/apache/james/CassandraJamesServerMain.java
 (original)
+++ 
james/project/trunk/server/container/cassandra-guice/src/main/java/org/apache/james/CassandraJamesServerMain.java
 Tue Nov  3 16:47:57 2015
@@ -24,9 +24,9 @@ import org.apache.james.modules.data.Cas
 import org.apache.james.modules.data.CassandraUsersRepositoryModule;
 import org.apache.james.modules.mailbox.CassandraMailboxModule;
 import org.apache.james.modules.mailbox.CassandraSessionModule;
+import org.apache.james.modules.mailbox.ElasticSearchMailboxModule;
 import org.apache.james.modules.server.ConfigurationPerformerModule;
 import org.apache.james.modules.server.DNSServiceModule;
-import org.apache.james.modules.server.SimpleMessageSearchModule;
 
 import com.google.inject.Module;
 import com.google.inject.util.Modules;
@@ -37,7 +37,7 @@ public class CassandraJamesServerMain {
             new CassandraMailboxModule(),
             new ConfigurationPerformerModule(),
             new CassandraSessionModule(),
-            new SimpleMessageSearchModule(),
+            new ElasticSearchMailboxModule(),
             new CassandraUsersRepositoryModule(),
             new CassandraDomainListModule(),
             new CassandraRecipientRewriteTableModule(),

Modified: 
james/project/trunk/server/container/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/CassandraMailboxModule.java
URL: 
http://svn.apache.org/viewvc/james/project/trunk/server/container/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/CassandraMailboxModule.java?rev=1712331&r1=1712330&r2=1712331&view=diff
==============================================================================
--- 
james/project/trunk/server/container/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/CassandraMailboxModule.java
 (original)
+++ 
james/project/trunk/server/container/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/CassandraMailboxModule.java
 Tue Nov  3 16:47:57 2015
@@ -31,12 +31,14 @@ import org.apache.james.mailbox.cassandr
 import org.apache.james.mailbox.cassandra.CassandraSubscriptionManager;
 import org.apache.james.mailbox.cassandra.mail.CassandraModSeqProvider;
 import org.apache.james.mailbox.cassandra.mail.CassandraUidProvider;
+import 
org.apache.james.mailbox.elasticsearch.events.ElasticSearchListeningMessageSearchIndex;
 import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.mailbox.store.Authenticator;
 import org.apache.james.mailbox.store.NoMailboxPathLocker;
 import org.apache.james.mailbox.store.mail.MessageMapperFactory;
 import org.apache.james.mailbox.store.mail.ModSeqProvider;
 import org.apache.james.mailbox.store.mail.UidProvider;
+import org.apache.james.mailbox.store.search.MessageSearchIndex;
 
 import com.google.inject.AbstractModule;
 import com.google.inject.Provides;
@@ -50,6 +52,8 @@ public class CassandraMailboxModule exte
 
     @Override
     protected void configure() {
+        bind(new TypeLiteral<MessageSearchIndex<CassandraId>>(){}).to(new 
TypeLiteral<ElasticSearchListeningMessageSearchIndex<CassandraId>>(){});
+
         bind(SubscriptionManager.class).to(CassandraSubscriptionManager.class);
         bind(new 
TypeLiteral<MessageMapperFactory<CassandraId>>(){}).to(CassandraMailboxSessionMapperFactory.class);
 

Added: 
james/project/trunk/server/container/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/ElasticSearchMailboxModule.java
URL: 
http://svn.apache.org/viewvc/james/project/trunk/server/container/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/ElasticSearchMailboxModule.java?rev=1712331&view=auto
==============================================================================
--- 
james/project/trunk/server/container/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/ElasticSearchMailboxModule.java
 (added)
+++ 
james/project/trunk/server/container/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/ElasticSearchMailboxModule.java
 Tue Nov  3 16:47:57 2015
@@ -0,0 +1,58 @@
+/****************************************************************
+ * 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.james.modules.mailbox;
+
+import com.google.inject.AbstractModule;
+import com.google.inject.Provides;
+import com.google.inject.TypeLiteral;
+import org.apache.james.mailbox.cassandra.CassandraId;
+import org.apache.james.mailbox.elasticsearch.*;
+import 
org.apache.james.mailbox.elasticsearch.events.ElasticSearchListeningMessageSearchIndex;
+import org.apache.james.mailbox.store.extractor.TextExtractor;
+import org.apache.james.mailbox.store.search.MessageSearchIndex;
+import org.apache.james.mailbox.tika.extractor.TikaTextExtractor;
+import org.apache.james.utils.PropertiesReader;
+
+import javax.inject.Singleton;
+
+public class ElasticSearchMailboxModule extends AbstractModule {
+
+    @Override
+    protected void configure() {
+        bind(new TypeLiteral<MessageSearchIndex<CassandraId>>(){}).to(new 
TypeLiteral<ElasticSearchListeningMessageSearchIndex<CassandraId>>() {});
+        bind(TextExtractor.class).to(TikaTextExtractor.class);
+        bind(new TypeLiteral<MessageSearchIndex<CassandraId>>() {})
+            .to(new 
TypeLiteral<ElasticSearchListeningMessageSearchIndex<CassandraId>>() {});
+    }
+
+    @Provides
+    @Singleton
+    protected ClientProvider provideClientProvider() {
+        PropertiesReader propertiesReader = new 
PropertiesReader("elasticsearch.properties");
+        ClientProvider clientProvider = new 
ClientProviderImpl(propertiesReader.getProperty("elasticsearch.masterHost"),
+            
Integer.parseInt(propertiesReader.getProperty("elasticsearch.port")));
+        IndexCreationFactory.createIndex(clientProvider,
+            
Integer.parseInt(propertiesReader.getProperty("elasticsearch.nb.shards")),
+            
Integer.parseInt(propertiesReader.getProperty("elasticsearch.nb.replica")));
+        NodeMappingFactory.applyMapping(clientProvider);
+        return clientProvider;
+    }
+
+}

Modified: 
james/project/trunk/server/container/cassandra-guice/src/test/java/org/apache/james/CassandraJamesServerTest.java
URL: 
http://svn.apache.org/viewvc/james/project/trunk/server/container/cassandra-guice/src/test/java/org/apache/james/CassandraJamesServerTest.java?rev=1712331&r1=1712330&r2=1712331&view=diff
==============================================================================
--- 
james/project/trunk/server/container/cassandra-guice/src/test/java/org/apache/james/CassandraJamesServerTest.java
 (original)
+++ 
james/project/trunk/server/container/cassandra-guice/src/test/java/org/apache/james/CassandraJamesServerTest.java
 Tue Nov  3 16:47:57 2015
@@ -27,9 +27,14 @@ import javax.mail.Store;
 
 import org.apache.james.backends.cassandra.CassandraCluster;
 import org.apache.james.backends.cassandra.components.CassandraModule;
+import org.apache.james.mailbox.elasticsearch.EmbeddedElasticSearch;
+import org.apache.james.modules.TestElasticSearchModule;
 import org.junit.After;
 import org.junit.Before;
+import org.junit.Rule;
 import org.junit.Test;
+import org.junit.rules.RuleChain;
+import org.junit.rules.TemporaryFolder;
 
 import com.google.inject.AbstractModule;
 import com.google.inject.Provides;
@@ -41,11 +46,17 @@ public class CassandraJamesServerTest {
     private static final int IMAP_PORT = 1143; // You need to be root 
(superuser) to bind to ports under 1024.
 
     private CassandraJamesServer server;
+    private TemporaryFolder temporaryFolder = new TemporaryFolder();
+    private EmbeddedElasticSearch embeddedElasticSearch = new 
EmbeddedElasticSearch(temporaryFolder);
+
+    @Rule
+    public RuleChain chain = 
RuleChain.outerRule(temporaryFolder).around(embeddedElasticSearch);
 
     @Before
     public void setup() throws Exception {
         server = new 
CassandraJamesServer(Modules.override(CassandraJamesServerMain.defaultModule)
-                .with(new AbstractModule() {
+                .with(new TestElasticSearchModule(embeddedElasticSearch), 
+                        new AbstractModule() {
                     
                     @Override
                     protected void configure() {
@@ -68,10 +79,10 @@ public class CassandraJamesServerTest {
     }
 
     @Test (expected = AuthenticationFailedException.class)
-    public void connectShouldThrowWhenNoCrendentials() throws Exception {
+    public void connectIMAPServerShouldThrowWhenNoCredentials() throws 
Exception {
         store().connect();
     }
-    
+
     private Store store() throws NoSuchProviderException {
         Properties properties = new Properties();
         properties.put("mail.imap.host", "localhost");

Added: 
james/project/trunk/server/container/cassandra-guice/src/test/java/org/apache/james/modules/TestElasticSearchModule.java
URL: 
http://svn.apache.org/viewvc/james/project/trunk/server/container/cassandra-guice/src/test/java/org/apache/james/modules/TestElasticSearchModule.java?rev=1712331&view=auto
==============================================================================
--- 
james/project/trunk/server/container/cassandra-guice/src/test/java/org/apache/james/modules/TestElasticSearchModule.java
 (added)
+++ 
james/project/trunk/server/container/cassandra-guice/src/test/java/org/apache/james/modules/TestElasticSearchModule.java
 Tue Nov  3 16:47:57 2015
@@ -0,0 +1,52 @@
+/****************************************************************
+ * 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.james.modules;
+
+import com.google.inject.AbstractModule;
+import com.google.inject.Provides;
+import org.apache.james.mailbox.elasticsearch.ClientProvider;
+import org.apache.james.mailbox.elasticsearch.EmbeddedElasticSearch;
+import org.apache.james.mailbox.elasticsearch.IndexCreationFactory;
+import org.apache.james.mailbox.elasticsearch.NodeMappingFactory;
+import org.apache.james.mailbox.elasticsearch.utils.TestingClientProvider;
+
+import javax.inject.Singleton;
+
+public class TestElasticSearchModule extends AbstractModule{
+
+    private final EmbeddedElasticSearch embeddedElasticSearch;
+
+    public TestElasticSearchModule(EmbeddedElasticSearch 
embeddedElasticSearch) {
+        this.embeddedElasticSearch = embeddedElasticSearch;
+    }
+
+    @Override
+    protected void configure() {
+
+    }
+
+    @Provides
+    @Singleton
+    protected ClientProvider provideClientProvider() {
+        return NodeMappingFactory.applyMapping(
+            IndexCreationFactory.createIndex(new 
TestingClientProvider(embeddedElasticSearch.getNode()))
+        );
+    }
+}

Added: 
james/project/trunk/server/container/cassandra-guice/src/test/resources/elasticsearch.properties
URL: 
http://svn.apache.org/viewvc/james/project/trunk/server/container/cassandra-guice/src/test/resources/elasticsearch.properties?rev=1712331&view=auto
==============================================================================
--- 
james/project/trunk/server/container/cassandra-guice/src/test/resources/elasticsearch.properties
 (added)
+++ 
james/project/trunk/server/container/cassandra-guice/src/test/resources/elasticsearch.properties
 Tue Nov  3 16:47:57 2015
@@ -0,0 +1,26 @@
+#  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.
+
+#  This template file can be used as example for James Server configuration
+#  DO NOT USE IT AS SUCH AND ADAPT IT TO YOUR NEEDS
+
+# Configuration file for ElasticSearch
+
+elasticsearch.masterHost=127.0.0.1
+elasticsearch.port=9300
+elasticsearch.nb.shards=1
+elasticsearch.nb.replica=0
\ No newline at end of file

Modified: james/project/trunk/server/pom.xml
URL: 
http://svn.apache.org/viewvc/james/project/trunk/server/pom.xml?rev=1712331&r1=1712330&r2=1712331&view=diff
==============================================================================
--- james/project/trunk/server/pom.xml (original)
+++ james/project/trunk/server/pom.xml Tue Nov  3 16:47:57 2015
@@ -548,6 +548,12 @@
             </dependency>
             <dependency>
                 <groupId>org.apache.james</groupId>
+                <artifactId>apache-james-mailbox-elasticsearch</artifactId>
+                <version>${mailbox.version}</version>
+                <type>test-jar</type>
+            </dependency>
+            <dependency>
+                <groupId>org.apache.james</groupId>
                 <artifactId>apache-james-mailbox-tika</artifactId>
                 <version>${mailbox.version}</version>
             </dependency>



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to