You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by bt...@apache.org on 2017/03/02 11:21:01 UTC

[1/5] james-project git commit: JAMES-1994 remove cassandra spring configuration file

Repository: james-project
Updated Branches:
  refs/heads/master afe155866 -> 35cb47ae4


JAMES-1994 remove cassandra spring configuration file


Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/35cb47ae
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/35cb47ae
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/35cb47ae

Branch: refs/heads/master
Commit: 35cb47ae4b914b7edbf217dd9fba7a6dc4be235b
Parents: d71dfc4
Author: Luc DUZAN <ld...@linagora.com>
Authored: Wed Feb 22 13:46:24 2017 +0100
Committer: benwa <bt...@linagora.com>
Committed: Thu Mar 2 18:20:35 2017 +0700

----------------------------------------------------------------------
 .../resources/META-INF/cassandra-session.xml    | 144 -------------------
 1 file changed, 144 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/35cb47ae/backends-common/cassandra/src/main/resources/META-INF/cassandra-session.xml
----------------------------------------------------------------------
diff --git a/backends-common/cassandra/src/main/resources/META-INF/cassandra-session.xml b/backends-common/cassandra/src/main/resources/META-INF/cassandra-session.xml
deleted file mode 100644
index 3fe26f0..0000000
--- a/backends-common/cassandra/src/main/resources/META-INF/cassandra-session.xml
+++ /dev/null
@@ -1,144 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
-  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.
--->
-
-<beans xmlns="http://www.springframework.org/schema/beans"
-       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-       xsi:schemaLocation="
-          http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
-          http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
-
-    <!-- Cassandra lazy initialization-->
-
-    <!--
-      The Cluster factory is responsible for connecting the cluster
-
-      The ClusterWithKeyspaceCreatedFactory is responsible for creating the keyspace if not present.
-
-      The SessionFactory is responsible for giving a session we can work with
-    -->
-
-    <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
-        <property name="ignoreUnresolvablePlaceholders" value="true"/>
-        <property name ="location" value="classpath:cassandra.properties"/>
-    </bean>
-
-    <bean id="cassandra-mailbox-uid-modseq-module"
-          class="org.apache.james.mailbox.cassandra.modules.CassandraUidAndModSeqModule"
-          lazy-init="true"/>
-
-    <bean id="cassandra-subscription-module"
-          class="org.apache.james.mailbox.cassandra.modules.CassandraSubscriptionModule"
-          lazy-init="true"/>
-
-    <bean id="cassandra-mailbox-module"
-          class="org.apache.james.mailbox.cassandra.modules.CassandraMailboxModule"
-          lazy-init="true"/>
-
-    <bean id="cassandra-mailbox-counters-module"
-          class="org.apache.james.mailbox.cassandra.modules.CassandraMailboxCounterModule"
-          lazy-init="true"/>
-
-    <bean id="cassandra-message-module"
-          class="org.apache.james.mailbox.cassandra.modules.CassandraMessageModule"
-          lazy-init="true"/>
-
-    <bean id="cassandra-mailbox-acl-module"
-          class="org.apache.james.mailbox.cassandra.modules.CassandraAclModule"
-          lazy-init="true"/>
-
-    <bean id="cassandra-mailbox-quota-module"
-          class="org.apache.james.mailbox.cassandra.modules.CassandraQuotaModule"
-          lazy-init="true"/>
-
-    <bean id="cassandra-mailbox-registration-module"
-          class="org.apache.james.mailbox.cassandra.modules.CassandraRegistrationModule"
-          lazy-init="true"/>
-
-    <bean id="cassandra-rrt-module"
-          class="org.apache.james.rrt.cassandra.CassandraRRTModule"
-          lazy-init="true"/>
-
-    <bean id="cassandra-sieve-repository-module"
-          class="org.apache.james.sieve.cassandra.CassandraSieveRepositoryModule"
-          lazy-init="true"/>
-
-    <bean id="cassandra-usersrepository-module"
-          class="org.apache.james.user.cassandra.CassandraUsersRepositoryModule"
-          lazy-init="true"/>
-
-    <bean id="cassandra-domainlist-module"
-          class="org.apache.james.domainlist.cassandra.CassandraDomainListModule"
-          lazy-init="true"/>
-
-    <bean id="cassandra-module-composite"
-          class="org.apache.james.backends.cassandra.init.CassandraModuleComposite"
-          lazy-init="true">
-        <constructor-arg index="0">
-            <list>
-                <ref bean="cassandra-mailbox-uid-modseq-module"/>
-                <ref bean="cassandra-subscription-module"/>
-                <ref bean="cassandra-mailbox-registration-module"/>
-                <ref bean="cassandra-mailbox-module"/>
-                <ref bean="cassandra-message-module"/>
-                <ref bean="cassandra-mailbox-counters-module"/>
-                <ref bean="cassandra-mailbox-acl-module"/>
-                <ref bean="cassandra-mailbox-quota-module"/>
-                <ref bean="cassandra-rrt-module"/>
-                <ref bean="cassandra-usersrepository-module"/>
-                <ref bean="cassandra-domainlist-module"/>
-                <ref bean="cassandra-sieve-repository-module"/>
-            </list>
-        </constructor-arg>
-    </bean>
-
-    <bean id="cassandra-cluster"
-          class="org.apache.james.backends.cassandra.init.ClusterBuilder"
-          factory-method="createClusterForSingleServerWithoutPassWord"
-          lazy-init="true">
-        <constructor-arg index="0" value="${cassandra.ip}"/>
-        <constructor-arg index="1" value="${cassandra.port}" type="int"/>
-    </bean>
-
-    <bean id="cassandra-cluster-initialized"
-          class="org.apache.james.backends.cassandra.init.ClusterWithKeyspaceCreatedFactory"
-          factory-method="clusterWithInitializedKeyspace"
-          lazy-init="true">
-        <constructor-arg index="0" ref="cassandra-cluster"/>
-        <constructor-arg index="1" value="${cassandra.keyspace}"/>
-        <constructor-arg index="2" value="${cassandra.replication.factor}" type="int"/>
-    </bean>
-
-    <bean id="cassandra-session"
-          class="org.apache.james.backends.cassandra.init.SpringStaticSessionFactory"
-          factory-method="createSession"
-          lazy-init="true">
-        <constructor-arg index="0" ref="cassandra-cluster-initialized"/>
-        <constructor-arg index="1" value="${cassandra.keyspace}"/>
-        <constructor-arg index="2" ref="cassandra-module-composite"/>
-    </bean>
-
-    <bean id="cassandra-type-provider"
-          class="org.apache.james.backends.cassandra.init.CassandraTypesProvider"
-          lazy-init="true">
-        <constructor-arg index="0" ref="cassandra-module-composite"/>
-        <constructor-arg index="1" ref="cassandra-session"/>
-    </bean>
-
-</beans>


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


[2/5] james-project git commit: JAMES-1944 config cassandra query slow logger

Posted by bt...@apache.org.
JAMES-1944 config cassandra query slow logger


Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/4d02ac56
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/4d02ac56
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/4d02ac56

Branch: refs/heads/master
Commit: 4d02ac56f3f370148429696bf6d396148993bec3
Parents: b8992fd
Author: Luc DUZAN <ld...@linagora.com>
Authored: Mon Feb 20 10:49:51 2017 +0100
Committer: benwa <bt...@linagora.com>
Committed: Thu Mar 2 18:20:35 2017 +0700

----------------------------------------------------------------------
 dockerfiles/run/guice/cassandra-ldap/destination/conf/logback.xml | 2 ++
 dockerfiles/run/guice/cassandra/destination/conf/logback.xml      | 2 ++
 mailbox/elasticsearch/src/test/resources/logback-test.xml         | 1 +
 .../guice/cassandra-guice/src/main/resources/logback.xml          | 1 +
 .../data-ldap-integration-testing/src/test/resources/logback.xml  | 2 ++
 server/mailet/integration-testing/src/test/resources/logback.xml  | 2 ++
 server/mailet/mailets/src/test/resources/logback-test.xml         | 2 ++
 .../src/test/resources/logback-test.xml                           | 3 +++
 8 files changed, 15 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/4d02ac56/dockerfiles/run/guice/cassandra-ldap/destination/conf/logback.xml
----------------------------------------------------------------------
diff --git a/dockerfiles/run/guice/cassandra-ldap/destination/conf/logback.xml b/dockerfiles/run/guice/cassandra-ldap/destination/conf/logback.xml
index 7685591..ee7900e 100644
--- a/dockerfiles/run/guice/cassandra-ldap/destination/conf/logback.xml
+++ b/dockerfiles/run/guice/cassandra-ldap/destination/conf/logback.xml
@@ -25,4 +25,6 @@
                 <appender-ref ref="LOG_FILE" />
         </root>
 
+        <logger name="com.datastax.driver.core.QueryLogger.SLOW" level="DEBUG" />
+
 </configuration>

http://git-wip-us.apache.org/repos/asf/james-project/blob/4d02ac56/dockerfiles/run/guice/cassandra/destination/conf/logback.xml
----------------------------------------------------------------------
diff --git a/dockerfiles/run/guice/cassandra/destination/conf/logback.xml b/dockerfiles/run/guice/cassandra/destination/conf/logback.xml
index 7685591..ee7900e 100644
--- a/dockerfiles/run/guice/cassandra/destination/conf/logback.xml
+++ b/dockerfiles/run/guice/cassandra/destination/conf/logback.xml
@@ -25,4 +25,6 @@
                 <appender-ref ref="LOG_FILE" />
         </root>
 
+        <logger name="com.datastax.driver.core.QueryLogger.SLOW" level="DEBUG" />
+
 </configuration>

http://git-wip-us.apache.org/repos/asf/james-project/blob/4d02ac56/mailbox/elasticsearch/src/test/resources/logback-test.xml
----------------------------------------------------------------------
diff --git a/mailbox/elasticsearch/src/test/resources/logback-test.xml b/mailbox/elasticsearch/src/test/resources/logback-test.xml
index 8678b2f..15e1365 100644
--- a/mailbox/elasticsearch/src/test/resources/logback-test.xml
+++ b/mailbox/elasticsearch/src/test/resources/logback-test.xml
@@ -21,5 +21,6 @@
                 <appender-ref ref="CONSOLE" />
         </logger>
 
+        <logger name="com.datastax.driver.core.QueryLogger.SLOW" level="DEBUG" />
 
 </configuration>

http://git-wip-us.apache.org/repos/asf/james-project/blob/4d02ac56/server/container/guice/cassandra-guice/src/main/resources/logback.xml
----------------------------------------------------------------------
diff --git a/server/container/guice/cassandra-guice/src/main/resources/logback.xml b/server/container/guice/cassandra-guice/src/main/resources/logback.xml
index 0e1ff22..f6f0c68 100644
--- a/server/container/guice/cassandra-guice/src/main/resources/logback.xml
+++ b/server/container/guice/cassandra-guice/src/main/resources/logback.xml
@@ -18,5 +18,6 @@
 
         <logger name="org.apache.james" level="INFO"/>
 
+        <logger name="com.datastax.driver.core.QueryLogger.SLOW" level="DEBUG" />
 
 </configuration>

http://git-wip-us.apache.org/repos/asf/james-project/blob/4d02ac56/server/data/data-ldap-integration-testing/src/test/resources/logback.xml
----------------------------------------------------------------------
diff --git a/server/data/data-ldap-integration-testing/src/test/resources/logback.xml b/server/data/data-ldap-integration-testing/src/test/resources/logback.xml
index 5c69ee7..4801b91 100644
--- a/server/data/data-ldap-integration-testing/src/test/resources/logback.xml
+++ b/server/data/data-ldap-integration-testing/src/test/resources/logback.xml
@@ -19,4 +19,6 @@
         <logger name="org.testcontainers" level="INFO"/>
         <logger name="org.apache.james" level="DEBUG"/>
 
+        <logger name="com.datastax.driver.core.QueryLogger.SLOW" level="DEBUG" />
+
 </configuration>

http://git-wip-us.apache.org/repos/asf/james-project/blob/4d02ac56/server/mailet/integration-testing/src/test/resources/logback.xml
----------------------------------------------------------------------
diff --git a/server/mailet/integration-testing/src/test/resources/logback.xml b/server/mailet/integration-testing/src/test/resources/logback.xml
index 52c0153..b6c3147 100644
--- a/server/mailet/integration-testing/src/test/resources/logback.xml
+++ b/server/mailet/integration-testing/src/test/resources/logback.xml
@@ -18,4 +18,6 @@
 
         <logger name="org.apache.james.mailetcontainer.impl.JamesMailetContext" level="DEBUG"/>
 
+        <logger name="com.datastax.driver.core.QueryLogger.SLOW" level="DEBUG" />
+
 </configuration>

http://git-wip-us.apache.org/repos/asf/james-project/blob/4d02ac56/server/mailet/mailets/src/test/resources/logback-test.xml
----------------------------------------------------------------------
diff --git a/server/mailet/mailets/src/test/resources/logback-test.xml b/server/mailet/mailets/src/test/resources/logback-test.xml
index 0210dd6..43f4151 100644
--- a/server/mailet/mailets/src/test/resources/logback-test.xml
+++ b/server/mailet/mailets/src/test/resources/logback-test.xml
@@ -18,4 +18,6 @@
 
         <logger name="org.apache.james" level="DEBUG"/>
 
+        <logger name="com.datastax.driver.core.QueryLogger.SLOW" level="DEBUG" />
+
 </configuration>

http://git-wip-us.apache.org/repos/asf/james-project/blob/4d02ac56/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/resources/logback-test.xml
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/resources/logback-test.xml b/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/resources/logback-test.xml
index dd2d81e..6f13ac9 100644
--- a/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/resources/logback-test.xml
+++ b/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/resources/logback-test.xml
@@ -9,4 +9,7 @@
     <root level="WARN">
         <appender-ref ref="STDOUT" />
     </root>
+
+    <logger name="com.datastax.driver.core.QueryLogger.SLOW" level="DEBUG" />
+
 </configuration>
\ No newline at end of file


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


[5/5] james-project git commit: JAMES-1944 add QueryLogger parameter to CassandraBuilder

Posted by bt...@apache.org.
JAMES-1944 add QueryLogger parameter to CassandraBuilder


Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/b8992fdf
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/b8992fdf
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/b8992fdf

Branch: refs/heads/master
Commit: b8992fdf519ce8c0b5b07923cb6eb45e32b3d009
Parents: 4eb8aaf
Author: Luc DUZAN <ld...@linagora.com>
Authored: Mon Feb 20 10:49:20 2017 +0100
Committer: benwa <bt...@linagora.com>
Committed: Thu Mar 2 18:20:35 2017 +0700

----------------------------------------------------------------------
 .../backends/cassandra/init/ClusterBuilder.java |  22 ++-
 .../init/QueryLoggerConfiguration.java          | 136 +++++++++++++++++++
 .../backends/cassandra/CassandraCluster.java    |  16 +--
 server/container/guice/cassandra-guice/pom.xml  |   5 +
 .../modules/mailbox/CassandraSessionModule.java |  84 +++++++++---
 server/src/site/xdoc/config-cassandra.xml       |  25 ++++
 6 files changed, 254 insertions(+), 34 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/b8992fdf/backends-common/cassandra/src/main/java/org/apache/james/backends/cassandra/init/ClusterBuilder.java
----------------------------------------------------------------------
diff --git a/backends-common/cassandra/src/main/java/org/apache/james/backends/cassandra/init/ClusterBuilder.java b/backends-common/cassandra/src/main/java/org/apache/james/backends/cassandra/init/ClusterBuilder.java
index 3761da1..ec504dc 100644
--- a/backends-common/cassandra/src/main/java/org/apache/james/backends/cassandra/init/ClusterBuilder.java
+++ b/backends-common/cassandra/src/main/java/org/apache/james/backends/cassandra/init/ClusterBuilder.java
@@ -38,7 +38,6 @@ public class ClusterBuilder {
         return new ClusterBuilder();
     }
 
-
     private Optional<String> username;
     private Optional<String> password;
 
@@ -49,6 +48,8 @@ public class ClusterBuilder {
     private Optional<Integer> refreshSchemaIntervalMillis;
     private boolean forTest;
 
+    private Optional<QueryLoggerConfiguration> queryLogger;
+
     private ClusterBuilder() {
         username = Optional.empty();
         password = Optional.empty();
@@ -59,6 +60,8 @@ public class ClusterBuilder {
 
         refreshSchemaIntervalMillis = Optional.empty();
         forTest = false;
+
+        queryLogger = Optional.empty();
     }
 
     public ClusterBuilder username(String username) {
@@ -109,6 +112,12 @@ public class ClusterBuilder {
         return this;
     }
 
+    public ClusterBuilder queryLoggerConfiguration(QueryLoggerConfiguration queryLogger) {
+        this.queryLogger = Optional.of(queryLogger);
+
+        return this;
+    }
+
     public Cluster build() {
         Preconditions.checkState(!(servers.isPresent() && host.isPresent()), "You can't specify a list of servers and a host at the same time");
         Preconditions.checkState(!(servers.isPresent() && port.isPresent()), "You can't specify a list of servers and a port at the same time");
@@ -122,19 +131,18 @@ public class ClusterBuilder {
 
         username.map(username ->
             password.map(password ->
-                clusterBuilder.withCredentials(username, password)
-            )
-        );
+                clusterBuilder.withCredentials(username, password)));
 
         getRefreshSchemaIntervalMillis().map(refreshSchemaIntervalMillis ->
             clusterBuilder.withQueryOptions(
                 new QueryOptions()
-                    .setRefreshSchemaIntervalMillis(refreshSchemaIntervalMillis)
-            )
-        );
+                    .setRefreshSchemaIntervalMillis(refreshSchemaIntervalMillis)));
 
         Cluster cluster = clusterBuilder.build();
 
+        queryLogger.map(queryLoggerConfiguration ->
+            cluster.register(queryLoggerConfiguration.getQueryLogger(cluster)));
+
         return cluster;
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/b8992fdf/backends-common/cassandra/src/main/java/org/apache/james/backends/cassandra/init/QueryLoggerConfiguration.java
----------------------------------------------------------------------
diff --git a/backends-common/cassandra/src/main/java/org/apache/james/backends/cassandra/init/QueryLoggerConfiguration.java b/backends-common/cassandra/src/main/java/org/apache/james/backends/cassandra/init/QueryLoggerConfiguration.java
new file mode 100644
index 0000000..3a254e0
--- /dev/null
+++ b/backends-common/cassandra/src/main/java/org/apache/james/backends/cassandra/init/QueryLoggerConfiguration.java
@@ -0,0 +1,136 @@
+/****************************************************************
+ * 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.backends.cassandra.init;
+
+import com.datastax.driver.core.Cluster;
+import com.datastax.driver.core.PerHostPercentileTracker;
+import com.datastax.driver.core.QueryLogger;
+import com.google.common.base.Preconditions;
+import java.util.Optional;
+
+public class QueryLoggerConfiguration {
+    private final Optional<Long> constantThreshold;
+    private final Optional<PerHostPercentileTracker> percentileTracker;
+    private final Optional<Double> slowQueryLatencyThresholdPercentile;
+    private final Optional<Integer> maxLoggedParameters;
+    private final Optional<Integer> maxParameterValueLength;
+    private final Optional<Integer> maxQueryStringLength;
+
+    public static class Builder {
+        private Optional<Long> constantThreshold;
+        private Optional<PerHostPercentileTracker> percentileTracker;
+        private Optional<Double> slowQueryLatencyThresholdPercentile;
+        private Optional<Integer> maxLoggedParameters;
+        private Optional<Integer> maxParameterValueLength;
+        private Optional<Integer> maxQueryStringLength;
+
+        private Builder() {
+            constantThreshold = Optional.empty();
+            percentileTracker = Optional.empty();
+            slowQueryLatencyThresholdPercentile = Optional.empty();
+            maxLoggedParameters = Optional.empty();
+            maxParameterValueLength = Optional.empty();
+            maxQueryStringLength = Optional.empty();
+        }
+
+        public Builder withConstantThreshold(long constantThreshold) {
+            this.constantThreshold = Optional.of(constantThreshold);
+
+            return this;
+        }
+
+        public Builder withDynamicThreshold(PerHostPercentileTracker percentileTracker,
+                                            double slowQueryLatencyThresholdPercentile) {
+            this.percentileTracker = Optional.of(percentileTracker);
+            this.slowQueryLatencyThresholdPercentile = Optional.of(slowQueryLatencyThresholdPercentile);
+
+            return this;
+        }
+
+        public Builder withMaxLoggedParameters(int maxLoggedParameters) {
+            this.maxLoggedParameters = Optional.of(maxLoggedParameters);
+
+            return this;
+        }
+
+        public Builder withMaxParameterValueLength(int maxParameterValueLength) {
+            this.maxParameterValueLength = Optional.of(maxParameterValueLength);
+
+            return this;
+        }
+
+        public Builder withMaxQueryStringLength(int maxQueryStringLength) {
+            this.maxQueryStringLength = Optional.of(maxQueryStringLength);
+
+            return this;
+        }
+
+        public QueryLoggerConfiguration build() {
+            Preconditions.checkState(!(constantThreshold.isPresent() && percentileTracker.isPresent()),
+                "You can not use slowQueryLatencyTheresholdMillis and percentileTracker at the same time");
+
+            return new QueryLoggerConfiguration(
+                constantThreshold,
+                percentileTracker,
+                slowQueryLatencyThresholdPercentile,
+                maxLoggedParameters,
+                maxParameterValueLength,
+                maxQueryStringLength
+            );
+        }
+    }
+
+    public static Builder builder() {
+        return new Builder();
+    }
+
+    private QueryLoggerConfiguration(
+        Optional<Long> constantThreshold,
+        Optional<PerHostPercentileTracker> percentileTracker,
+        Optional<Double> slowQueryLatencyThresholdPercentile,
+        Optional<Integer> maxLoggedParameters,
+        Optional<Integer> maxParameterValueLength,
+        Optional<Integer> maxQueryStringLength) {
+        this.constantThreshold = constantThreshold;
+        this.percentileTracker = percentileTracker;
+        this.slowQueryLatencyThresholdPercentile = slowQueryLatencyThresholdPercentile;
+        this.maxLoggedParameters = maxLoggedParameters;
+        this.maxParameterValueLength = maxParameterValueLength;
+        this.maxQueryStringLength = maxQueryStringLength;
+    }
+
+    public QueryLogger getQueryLogger(Cluster cluster) {
+        QueryLogger.Builder builder = QueryLogger.builder(cluster);
+
+        percentileTracker.map(percentileTracker ->
+            slowQueryLatencyThresholdPercentile.map(slowQueryLatencyThresholdPercentile ->
+                builder.withDynamicThreshold(percentileTracker, slowQueryLatencyThresholdPercentile)
+            )
+        );
+
+        constantThreshold.ifPresent(builder::withConstantThreshold);
+        constantThreshold.ifPresent(builder::withConstantThreshold);
+        maxLoggedParameters.ifPresent(builder::withMaxLoggedParameters);
+        maxParameterValueLength.ifPresent(builder::withMaxParameterValueLength);
+        maxQueryStringLength.ifPresent(builder::withMaxQueryStringLength);
+
+        return builder.build();
+    }
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/b8992fdf/backends-common/cassandra/src/test/java/org/apache/james/backends/cassandra/CassandraCluster.java
----------------------------------------------------------------------
diff --git a/backends-common/cassandra/src/test/java/org/apache/james/backends/cassandra/CassandraCluster.java b/backends-common/cassandra/src/test/java/org/apache/james/backends/cassandra/CassandraCluster.java
index 6e987fb..07fecaf 100644
--- a/backends-common/cassandra/src/test/java/org/apache/james/backends/cassandra/CassandraCluster.java
+++ b/backends-common/cassandra/src/test/java/org/apache/james/backends/cassandra/CassandraCluster.java
@@ -18,11 +18,10 @@
  ****************************************************************/
 package org.apache.james.backends.cassandra;
 
-import java.util.Optional;
-
-import javax.annotation.PreDestroy;
-import javax.inject.Inject;
-
+import com.datastax.driver.core.Cluster;
+import com.datastax.driver.core.Session;
+import com.datastax.driver.core.exceptions.NoHostAvailableException;
+import com.google.common.base.Throwables;
 import org.apache.james.backends.cassandra.components.CassandraModule;
 import org.apache.james.backends.cassandra.init.CassandraTableManager;
 import org.apache.james.backends.cassandra.init.CassandraTypesProvider;
@@ -31,10 +30,9 @@ import org.apache.james.backends.cassandra.init.ClusterWithKeyspaceCreatedFactor
 import org.apache.james.backends.cassandra.init.SessionWithInitializedTablesFactory;
 import org.apache.james.backends.cassandra.utils.FunctionRunnerWithRetry;
 
-import com.datastax.driver.core.Cluster;
-import com.datastax.driver.core.Session;
-import com.datastax.driver.core.exceptions.NoHostAvailableException;
-import com.google.common.base.Throwables;
+import javax.annotation.PreDestroy;
+import javax.inject.Inject;
+import java.util.Optional;
 
 public final class CassandraCluster {
     private static final String CLUSTER_IP = "localhost";

http://git-wip-us.apache.org/repos/asf/james-project/blob/b8992fdf/server/container/guice/cassandra-guice/pom.xml
----------------------------------------------------------------------
diff --git a/server/container/guice/cassandra-guice/pom.xml b/server/container/guice/cassandra-guice/pom.xml
index 14d0079..e4c3e67 100644
--- a/server/container/guice/cassandra-guice/pom.xml
+++ b/server/container/guice/cassandra-guice/pom.xml
@@ -192,6 +192,11 @@
             </build>
             <dependencies>
                 <dependency>
+                    <groupId>org.hdrhistogram</groupId>
+                    <artifactId>HdrHistogram</artifactId>
+                    <version>2.1.4</version>
+                </dependency>
+                <dependency>
                     <groupId>${project.groupId}</groupId>
                     <artifactId>apache-james-backends-cassandra</artifactId>
                     <type>test-jar</type>

http://git-wip-us.apache.org/repos/asf/james-project/blob/b8992fdf/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/CassandraSessionModule.java
----------------------------------------------------------------------
diff --git a/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/CassandraSessionModule.java b/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/CassandraSessionModule.java
index a464bc7..8146c5a 100644
--- a/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/CassandraSessionModule.java
+++ b/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/CassandraSessionModule.java
@@ -18,13 +18,17 @@
  ****************************************************************/
 package org.apache.james.modules.mailbox;
 
-import java.io.FileNotFoundException;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Set;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.ScheduledExecutorService;
-
+import com.datastax.driver.core.Cluster;
+import com.datastax.driver.core.PerHostPercentileTracker;
+import com.datastax.driver.core.QueryLogger;
+import com.datastax.driver.core.Session;
+import com.datastax.driver.core.exceptions.NoHostAvailableException;
+import com.github.steveash.guavate.Guavate;
+import com.google.inject.AbstractModule;
+import com.google.inject.Provides;
+import com.google.inject.Singleton;
+import com.google.inject.multibindings.Multibinder;
+import com.nurkiewicz.asyncretry.AsyncRetryExecutor;
 import org.apache.commons.configuration.ConfigurationException;
 import org.apache.commons.configuration.PropertiesConfiguration;
 import org.apache.james.backends.cassandra.components.CassandraModule;
@@ -32,24 +36,25 @@ import org.apache.james.backends.cassandra.init.CassandraModuleComposite;
 import org.apache.james.backends.cassandra.init.CassandraZonedDateTimeModule;
 import org.apache.james.backends.cassandra.init.ClusterBuilder;
 import org.apache.james.backends.cassandra.init.ClusterWithKeyspaceCreatedFactory;
+import org.apache.james.backends.cassandra.init.QueryLoggerConfiguration;
 import org.apache.james.backends.cassandra.init.SessionWithInitializedTablesFactory;
 import org.apache.james.filesystem.api.FileSystem;
 import org.apache.james.util.Host;
 
-import com.datastax.driver.core.Cluster;
-import com.datastax.driver.core.Session;
-import com.datastax.driver.core.exceptions.NoHostAvailableException;
-import com.github.steveash.guavate.Guavate;
-import com.google.inject.AbstractModule;
-import com.google.inject.Provides;
-import com.google.inject.Singleton;
-import com.google.inject.multibindings.Multibinder;
-import com.nurkiewicz.asyncretry.AsyncRetryExecutor;
+import java.io.FileNotFoundException;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Optional;
+import java.util.Set;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
 
 public class CassandraSessionModule extends AbstractModule {
 
     private static final int DEFAULT_CONNECTION_MAX_RETRIES = 10;
     private static final int DEFAULT_CONNECTION_MIN_DELAY = 5000;
+    private static final long CASSANDRA_HIGHEST_TRACKABLE_LATENCY_MILLIS = TimeUnit.SECONDS.toMillis(10);
 
     @Override
     protected void configure() {
@@ -84,12 +89,14 @@ public class CassandraSessionModule extends AbstractModule {
     Cluster provideCluster(CassandraSessionConfiguration cassandraSessionConfiguration, AsyncRetryExecutor executor) throws FileNotFoundException, ConfigurationException, ExecutionException, InterruptedException {
         PropertiesConfiguration configuration = cassandraSessionConfiguration.getConfiguration();
         List<Host> servers = listCassandraServers(configuration);
+        QueryLoggerConfiguration queryLoggerConfiguration = getCassandraQueryLoggerConf(configuration);
 
         return getRetryer(executor, configuration)
                 .getWithRetry(ctx -> ClusterWithKeyspaceCreatedFactory
                         .config(
                             ClusterBuilder.builder()
                                 .servers(servers)
+                                .queryLoggerConfiguration(queryLoggerConfiguration)
                                 .build(),
                             configuration.getString("cassandra.keyspace"))
                         .replicationFactor(configuration.getInt("cassandra.replication.factor"))
@@ -105,6 +112,48 @@ public class CassandraSessionModule extends AbstractModule {
                 .collect(Guavate.toImmutableList());
     }
 
+    private Optional<Integer> getOptionalIntegerFromConf(PropertiesConfiguration configuration, String key) {
+        return Optional.ofNullable(configuration.getInteger(key, null));
+    }
+
+    private Optional<Double> getOptionalDoubleFromConf(PropertiesConfiguration configuration, String key) {
+        return Optional.ofNullable(configuration.getDouble(key, null));
+    }
+
+    private QueryLoggerConfiguration getCassandraQueryLoggerConf(PropertiesConfiguration configuration) {
+        QueryLoggerConfiguration.Builder builder = QueryLoggerConfiguration.builder();
+
+        Optional<Long> constantThreshold = getOptionalIntegerFromConf(configuration, "cassandra.query.logger.constant.threshold")
+            .map(Long::valueOf);
+
+        constantThreshold.ifPresent(builder::withConstantThreshold);
+
+        getOptionalIntegerFromConf(configuration, "cassandra.query.logger.max.logged.parameters")
+            .ifPresent(builder::withMaxLoggedParameters);
+
+        getOptionalIntegerFromConf(configuration, "cassandra.query.logger.max.query.string.length")
+            .ifPresent(builder::withMaxQueryStringLength);
+
+        getOptionalIntegerFromConf(configuration, "cassandra.query.logger.max.parameter.value.length")
+            .ifPresent(builder::withMaxParameterValueLength);
+
+        Optional<Double> percentileLatencyConf = getOptionalDoubleFromConf(configuration, "cassandra.query.slow.query.latency.threshold.percentile");
+
+        if (!percentileLatencyConf.isPresent() && !constantThreshold.isPresent()) {
+            percentileLatencyConf = Optional.of(QueryLogger.DEFAULT_SLOW_QUERY_THRESHOLD_PERCENTILE);
+        }
+
+        percentileLatencyConf.ifPresent(slowQueryLatencyThresholdPercentile -> {
+            PerHostPercentileTracker tracker = PerHostPercentileTracker
+                .builderWithHighestTrackableLatencyMillis(CASSANDRA_HIGHEST_TRACKABLE_LATENCY_MILLIS)
+                .build();
+
+            builder.withDynamicThreshold(tracker, slowQueryLatencyThresholdPercentile);
+        });
+
+        return builder.build();
+    }
+
     private static AsyncRetryExecutor getRetryer(AsyncRetryExecutor executor, PropertiesConfiguration configuration) {
         return executor.retryOn(NoHostAvailableException.class)
                 .withProportionalJitter()
@@ -120,5 +169,4 @@ public class CassandraSessionModule extends AbstractModule {
     private PropertiesConfiguration getConfiguration(FileSystem fileSystem) throws FileNotFoundException, ConfigurationException {
         return new PropertiesConfiguration(fileSystem.getFile(FileSystem.FILE_PROTOCOL_AND_CONF + "cassandra.properties"));
     }
-
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/b8992fdf/server/src/site/xdoc/config-cassandra.xml
----------------------------------------------------------------------
diff --git a/server/src/site/xdoc/config-cassandra.xml b/server/src/site/xdoc/config-cassandra.xml
index 70160c7..484fbb0 100644
--- a/server/src/site/xdoc/config-cassandra.xml
+++ b/server/src/site/xdoc/config-cassandra.xml
@@ -32,12 +32,37 @@
       <dl>
         <dt><strong>cassandra.nodes</strong></dt>
         <dd>List of some nodes of the cassandra's cluster in following format host:port or host, if the port is not specified we use 9042</dd>
+
         <dt><strong>cassandra.keyspace</strong></dt>
         <dd>Is the name of the keyspace used by James.</dd>
+
         <dt><strong>cassandra.replication.factor</strong></dt>
         <dd>Is the replication factor. (should be 1, as cluster is not yet supported)</dd>
+
+        <dt><strong>cassandra.query.logger.constant.threshold</strong></dt>
+        <dd>Optional.
+        If specified all queries that take more than the given integer in millisecond will be considered slow and logged.
+          If not specified by default a DynamicThresholdQueryLogger will be used (see above)</dd>
+
+        <dt><strong>cassandra.query.slow.query.latency.threshold.percentile</strong></dt>
+        <dd>Default is com.datastax.driver.core.QueryLogger.DEFAULT_SLOW_QUERY_THRESHOLD_PERCENTILE.
+        The latency percentile beyond which queries are considered 'slow' and will be logged.
+          If you specify cassandra.query.logger.constant.threshold, you should not specify this property</dd>
+
+        <dt><strong>cassandra.query.logger.max.query.string.length</strong></dt>
+        <dd>Default is com.datastax.driver.core.QueryLogger.DEFAULT_MAX_QUERY_STRING.LENGTH.
+          The maximum length of a CQL query string that can be logged verbatim by the cassandra driver</dd>
+
+        <dt><strong>cassandra.query.logger.max.logged.parameters</strong></dt>
+        <dd>Default is com.datastax.driver.core.QueryLogger.DEFAULT_MAX_LOGGED_PARAMETERS.
+          The maximum number of query parameters that can be logged by the cassandra driver</dd>
+
+        <dt><strong>cassandra.query.logger.max.parameter.value.length</strong></dt>
+        <dd>Default is com.datastax.driver.core.QueryLogger.DEFAULT_MAX_PARAMETER_VALUE_LENGTH.
+          The maximum length of query parameter value that can be logged by the cassandra driver</dd>
       </dl>
 
+
 <p>If you want more explanation about Cassandra configuration, you should visit the dedicated <a href="http://docs.datastax.com/en/cassandra/2.1/cassandra/gettingStartedCassandraIntro.html">documentation</a>.</p>
 
   </section>


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


[4/5] james-project git commit: JAMES-1944 add integration test about querryLogger config

Posted by bt...@apache.org.
JAMES-1944 add integration test about querryLogger config


Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/d71dfc4f
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/d71dfc4f
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/d71dfc4f

Branch: refs/heads/master
Commit: d71dfc4fc4458ffed7fbce91f8e0d197d45ce8aa
Parents: 4d02ac5
Author: Luc DUZAN <ld...@linagora.com>
Authored: Tue Feb 21 17:57:30 2017 +0100
Committer: benwa <bt...@linagora.com>
Committed: Thu Mar 2 18:20:35 2017 +0700

----------------------------------------------------------------------
 .../org/apache/james/CassandraConfTest.java     | 119 -----------------
 .../james/CassandraLogConfigurationTest.java    | 130 +++++++++++++++++++
 .../org/apache/james/CassandraNodeConfTest.java | 119 +++++++++++++++++
 .../org/apache/james/DockerCassandraRule.java   |   2 +-
 4 files changed, 250 insertions(+), 120 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/d71dfc4f/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraConfTest.java
----------------------------------------------------------------------
diff --git a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraConfTest.java b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraConfTest.java
deleted file mode 100644
index 6d1f0a2..0000000
--- a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraConfTest.java
+++ /dev/null
@@ -1,119 +0,0 @@
-/****************************************************************
- * 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;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-import java.io.IOException;
-import java.net.InetSocketAddress;
-import java.nio.ByteBuffer;
-import java.nio.channels.SocketChannel;
-import java.nio.charset.Charset;
-
-import org.apache.commons.configuration.PropertiesConfiguration;
-import org.apache.james.modules.mailbox.CassandraSessionConfiguration;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.testcontainers.DockerClientFactory;
-
-public class CassandraConfTest {
-
-    private static final int IMAP_PORT = 1143;
-
-    private static String getDockerHostIp() {
-        return DockerClientFactory.instance().dockerHostIpAddress();
-    }
-
-    private final DockerCassandraRule dockerCassandraRule = new DockerCassandraRule();
-
-    @Rule
-    public CassandraJmapTestRule cassandraJmapTestRule = new CassandraJmapTestRule(dockerCassandraRule,
-            new EmbeddedElasticSearchRule());
-
-    private GuiceJamesServerImpl jamesServer;
-    private SocketChannel socketChannel;
-
-    @Before
-    public void setUp() throws IOException {
-        socketChannel = SocketChannel.open();
-    }
-
-    @After
-    public void after() throws IOException {
-        socketChannel.close();
-        if (jamesServer != null) {
-            jamesServer.stop();
-        }
-    }
-
-    @Test
-    public void serverShouldStartServiceWhenNodeIsReachable() throws Exception {
-        jamesServer = cassandraJmapTestRule.jmapServer();
-
-        assertThatServerStartCorrectly();
-    }
-
-    @Test
-    public void serverShouldStartWhenOneCassandraNodeIsUnreachable() throws Exception {
-        String unreachableNode = "10.2.3.42";
-        PropertiesConfiguration configuration = getCassandraConfigurationForDocker(unreachableNode + "," + dockerCassandraRule.getIp());
-
-        jamesServer = cassandraJmapTestRule.jmapServer(
-                (binder) -> binder.bind(CassandraSessionConfiguration.class).toInstance(() -> configuration));
-
-        assertThatServerStartCorrectly();
-    }
-
-    @Test
-    public void configShouldWorkWithNonDefaultPort() throws Exception {
-        PropertiesConfiguration configuration = getCassandraConfigurationForDocker(getDockerHostIp() + ":" + dockerCassandraRule.getBindingPort());
-        jamesServer = cassandraJmapTestRule.jmapServer(
-                (binder) -> binder.bind(CassandraSessionConfiguration.class).toInstance(() -> configuration));
-
-        assertThatServerStartCorrectly();
-    }
-
-    private void assertThatServerStartCorrectly() throws Exception, IOException {
-        jamesServer.start();
-        socketChannel.connect(new InetSocketAddress("127.0.0.1", IMAP_PORT));
-        assertThat(getServerConnectionResponse(socketChannel)).startsWith("* OK JAMES IMAP4rev1 Server");
-    }
-
-    private PropertiesConfiguration getCassandraConfigurationForDocker(String confIps) {
-        PropertiesConfiguration configuration = new PropertiesConfiguration();
-
-        configuration.addProperty("cassandra.nodes", confIps);
-        configuration.addProperty("cassandra.keyspace", "apache_james");
-        configuration.addProperty("cassandra.replication.factor", 1);
-        configuration.addProperty("cassandra.retryConnection.maxRetries", 10);
-        configuration.addProperty("cassandra.retryConnection", 5000);
-
-        return configuration;
-    }
-
-    private String getServerConnectionResponse(SocketChannel socketChannel) throws IOException {
-        ByteBuffer byteBuffer = ByteBuffer.allocate(1000);
-        socketChannel.read(byteBuffer);
-        byte[] bytes = byteBuffer.array();
-        return new String(bytes, Charset.forName("UTF-8"));
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/james-project/blob/d71dfc4f/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraLogConfigurationTest.java
----------------------------------------------------------------------
diff --git a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraLogConfigurationTest.java b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraLogConfigurationTest.java
new file mode 100644
index 0000000..5d7f156
--- /dev/null
+++ b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraLogConfigurationTest.java
@@ -0,0 +1,130 @@
+/****************************************************************
+ * 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;
+
+import com.google.inject.ProvisionException;
+import org.apache.commons.configuration.PropertiesConfiguration;
+import org.apache.james.modules.mailbox.CassandraSessionConfiguration;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+import java.io.IOException;
+import java.net.InetSocketAddress;
+import java.nio.ByteBuffer;
+import java.nio.channels.SocketChannel;
+import java.nio.charset.Charset;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class CassandraLogConfigurationTest {
+
+    private static final int IMAP_PORT = 1143;
+
+    private final DockerCassandraRule dockerCassandraRule = new DockerCassandraRule();
+
+    @Rule
+    public CassandraJmapTestRule cassandraJmapTestRule = new CassandraJmapTestRule(dockerCassandraRule,
+            new EmbeddedElasticSearchRule());
+
+    @Rule
+    public ExpectedException thrown = ExpectedException.none();
+
+    private GuiceJamesServerImpl jamesServer;
+    private SocketChannel socketChannel;
+
+    @Before
+    public void setUp() throws IOException {
+        socketChannel = SocketChannel.open();
+    }
+
+    @After
+    public void after() throws IOException {
+        socketChannel.close();
+        if (jamesServer != null) {
+            jamesServer.stop();
+        }
+    }
+
+    @Test
+    public void serverShouldStartWithMinimalConfigAboutAConstantThresholdSlowQueryLogger() throws Exception {
+        jamesServer = cassandraJmapTestRule.jmapServer(
+            (binder) -> binder.bind(CassandraSessionConfiguration.class).toInstance(() -> {
+                PropertiesConfiguration configuration = dockerCassandraRule.getCassandraConfigurationForDocker();
+
+                configuration.addProperty("cassandra.query.logger.constant.threshold", 100);
+
+                return configuration;
+            }));
+
+        assertThatServerStartCorrectly();
+    }
+
+    @Test
+    public void serverShouldStartWithPersonalizedConfigAboutPercentileSlowQuerryLogger() throws Exception {
+        jamesServer = cassandraJmapTestRule.jmapServer(
+            (binder) ->
+                binder.bind(CassandraSessionConfiguration.class).toInstance(() -> {
+                    PropertiesConfiguration configuration = dockerCassandraRule.getCassandraConfigurationForDocker();
+
+                    configuration.addProperty("cassandra.query.slow.query.latency.threshold.percentile", 90);
+                    configuration.addProperty("cassandra.query.logger.max.logged.parameters", 9);
+                    configuration.addProperty("cassandra.query.logger.max.query.string.length", 9000);
+                    configuration.addProperty("cassandra.query.logger.max.parameter.value.length", 90);
+
+                    return configuration;
+                }));
+
+        assertThatServerStartCorrectly();
+    }
+
+    @Test
+    public void serverStartShouldFailIfConfigAboutLoggerIsInvalid() throws Exception {
+        thrown.expect(ProvisionException.class);
+
+        jamesServer = cassandraJmapTestRule.jmapServer(
+            (binder) ->
+                binder.bind(CassandraSessionConfiguration.class).toInstance(() -> {
+                    PropertiesConfiguration configuration = dockerCassandraRule.getCassandraConfigurationForDocker();
+
+                    configuration.addProperty("cassandra.query.slow.query.latency.threshold.percentile", 90);
+                    configuration.addProperty("cassandra.query.logger.constant.threshold", 100);
+
+                    return configuration;
+                }));
+
+        assertThatServerStartCorrectly();
+    }
+
+    private void assertThatServerStartCorrectly() throws Exception {
+        jamesServer.start();
+        socketChannel.connect(new InetSocketAddress("127.0.0.1", IMAP_PORT));
+        assertThat(getServerConnectionResponse(socketChannel)).startsWith("* OK JAMES IMAP4rev1 Server");
+    }
+
+    private String getServerConnectionResponse(SocketChannel socketChannel) throws IOException {
+        ByteBuffer byteBuffer = ByteBuffer.allocate(1000);
+        socketChannel.read(byteBuffer);
+        byte[] bytes = byteBuffer.array();
+        return new String(bytes, Charset.forName("UTF-8"));
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/d71dfc4f/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraNodeConfTest.java
----------------------------------------------------------------------
diff --git a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraNodeConfTest.java b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraNodeConfTest.java
new file mode 100644
index 0000000..180aea6
--- /dev/null
+++ b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraNodeConfTest.java
@@ -0,0 +1,119 @@
+/****************************************************************
+ * 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;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.io.IOException;
+import java.net.InetSocketAddress;
+import java.nio.ByteBuffer;
+import java.nio.channels.SocketChannel;
+import java.nio.charset.Charset;
+
+import org.apache.commons.configuration.PropertiesConfiguration;
+import org.apache.james.modules.mailbox.CassandraSessionConfiguration;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.testcontainers.DockerClientFactory;
+
+public class CassandraNodeConfTest {
+
+    private static final int IMAP_PORT = 1143;
+
+    private static String getDockerHostIp() {
+        return DockerClientFactory.instance().dockerHostIpAddress();
+    }
+
+    private final DockerCassandraRule dockerCassandraRule = new DockerCassandraRule();
+
+    @Rule
+    public CassandraJmapTestRule cassandraJmapTestRule = new CassandraJmapTestRule(dockerCassandraRule,
+            new EmbeddedElasticSearchRule());
+
+    private GuiceJamesServerImpl jamesServer;
+    private SocketChannel socketChannel;
+
+    @Before
+    public void setUp() throws IOException {
+        socketChannel = SocketChannel.open();
+    }
+
+    @After
+    public void after() throws IOException {
+        socketChannel.close();
+        if (jamesServer != null) {
+            jamesServer.stop();
+        }
+    }
+
+    @Test
+    public void serverShouldStartServiceWhenNodeIsReachable() throws Exception {
+        jamesServer = cassandraJmapTestRule.jmapServer();
+
+        assertThatServerStartCorrectly();
+    }
+
+    @Test
+    public void serverShouldStartWhenOneCassandraNodeIsUnreachable() throws Exception {
+        String unreachableNode = "10.2.3.42";
+        PropertiesConfiguration configuration = getCassandraConfigurationForDocker(unreachableNode + "," + dockerCassandraRule.getIp());
+
+        jamesServer = cassandraJmapTestRule.jmapServer(
+                (binder) -> binder.bind(CassandraSessionConfiguration.class).toInstance(() -> configuration));
+
+        assertThatServerStartCorrectly();
+    }
+
+    @Test
+    public void configShouldWorkWithNonDefaultPort() throws Exception {
+        PropertiesConfiguration configuration = getCassandraConfigurationForDocker(getDockerHostIp() + ":" + dockerCassandraRule.getBindingPort());
+        jamesServer = cassandraJmapTestRule.jmapServer(
+                (binder) -> binder.bind(CassandraSessionConfiguration.class).toInstance(() -> configuration));
+
+        assertThatServerStartCorrectly();
+    }
+
+    private void assertThatServerStartCorrectly() throws Exception {
+        jamesServer.start();
+        socketChannel.connect(new InetSocketAddress("127.0.0.1", IMAP_PORT));
+        assertThat(getServerConnectionResponse(socketChannel)).startsWith("* OK JAMES IMAP4rev1 Server");
+    }
+
+    private PropertiesConfiguration getCassandraConfigurationForDocker(String confIps) {
+        PropertiesConfiguration configuration = new PropertiesConfiguration();
+
+        configuration.addProperty("cassandra.nodes", confIps);
+        configuration.addProperty("cassandra.keyspace", "apache_james");
+        configuration.addProperty("cassandra.replication.factor", 1);
+        configuration.addProperty("cassandra.retryConnection.maxRetries", 10);
+        configuration.addProperty("cassandra.retryConnection", 5000);
+
+        return configuration;
+    }
+
+    private String getServerConnectionResponse(SocketChannel socketChannel) throws IOException {
+        ByteBuffer byteBuffer = ByteBuffer.allocate(1000);
+        socketChannel.read(byteBuffer);
+        byte[] bytes = byteBuffer.array();
+        return new String(bytes, Charset.forName("UTF-8"));
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/d71dfc4f/server/container/guice/cassandra-guice/src/test/java/org/apache/james/DockerCassandraRule.java
----------------------------------------------------------------------
diff --git a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/DockerCassandraRule.java b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/DockerCassandraRule.java
index e482214..4980f38 100644
--- a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/DockerCassandraRule.java
+++ b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/DockerCassandraRule.java
@@ -41,7 +41,7 @@ public class DockerCassandraRule implements GuiceModuleTestRule {
         return bindingIp == null || bindingIp.equals("0.0.0.0");
     }
 
-    private PropertiesConfiguration getCassandraConfigurationForDocker() {
+    public PropertiesConfiguration getCassandraConfigurationForDocker() {
         PropertiesConfiguration configuration = new PropertiesConfiguration();
 
         configuration.addProperty("cassandra.nodes", getIp() + ":" + CASSANDRA_PORT);


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


[3/5] james-project git commit: JAMES-1944 transform ClusterFactory into a Builder

Posted by bt...@apache.org.
JAMES-1944 transform ClusterFactory into a Builder


Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/4eb8aaf4
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/4eb8aaf4
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/4eb8aaf4

Branch: refs/heads/master
Commit: 4eb8aaf4017b38e07bc970591cc7683b120bee1d
Parents: afe1558
Author: Luc DUZAN <ld...@linagora.com>
Authored: Thu Feb 16 18:17:44 2017 +0100
Committer: benwa <bt...@linagora.com>
Committed: Thu Mar 2 18:20:35 2017 +0700

----------------------------------------------------------------------
 .../backends/cassandra/init/ClusterBuilder.java | 155 +++++++++++++++++++
 .../backends/cassandra/init/ClusterFactory.java |  72 ---------
 .../resources/META-INF/cassandra-session.xml    |   2 +-
 .../backends/cassandra/CassandraCluster.java    |   7 +-
 .../modules/mailbox/CassandraSessionModule.java |   8 +-
 5 files changed, 166 insertions(+), 78 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/4eb8aaf4/backends-common/cassandra/src/main/java/org/apache/james/backends/cassandra/init/ClusterBuilder.java
----------------------------------------------------------------------
diff --git a/backends-common/cassandra/src/main/java/org/apache/james/backends/cassandra/init/ClusterBuilder.java b/backends-common/cassandra/src/main/java/org/apache/james/backends/cassandra/init/ClusterBuilder.java
new file mode 100644
index 0000000..3761da1
--- /dev/null
+++ b/backends-common/cassandra/src/main/java/org/apache/james/backends/cassandra/init/ClusterBuilder.java
@@ -0,0 +1,155 @@
+/****************************************************************
+ * 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.backends.cassandra.init;
+
+import java.util.Collection;
+import java.util.Optional;
+
+import org.apache.james.util.Host;
+
+import com.datastax.driver.core.Cluster;
+import com.datastax.driver.core.QueryOptions;
+import com.google.common.base.Preconditions;
+import com.google.common.collect.ImmutableList;
+
+public class ClusterBuilder {
+
+    private final static String DEFAULT_CLUSTER_IP = "localhost";
+    public static final int DEFAULT_CASSANDRA_PORT = 9042;
+
+    public static ClusterBuilder builder() {
+        return new ClusterBuilder();
+    }
+
+
+    private Optional<String> username;
+    private Optional<String> password;
+
+    private Optional<String> host;
+    private Optional<Integer> port;
+    private Optional<Collection<Host>> servers;
+
+    private Optional<Integer> refreshSchemaIntervalMillis;
+    private boolean forTest;
+
+    private ClusterBuilder() {
+        username = Optional.empty();
+        password = Optional.empty();
+
+        host = Optional.empty();
+        port = Optional.empty();
+        servers = Optional.empty();
+
+        refreshSchemaIntervalMillis = Optional.empty();
+        forTest = false;
+    }
+
+    public ClusterBuilder username(String username) {
+        this.username = Optional.of(username);
+
+        return this;
+    }
+
+    public ClusterBuilder password(String password) {
+        this.password = Optional.of(password);
+
+        return this;
+    }
+
+    public ClusterBuilder host(String host) {
+        this.host = Optional.of(host);
+
+        return this;
+    }
+
+    public ClusterBuilder port(int port) {
+        this.port = Optional.of(port);
+
+        return this;
+    }
+
+    public ClusterBuilder refreshSchemaIntervalMillis(int refreshSchemaIntervalMillis) {
+        this.refreshSchemaIntervalMillis = Optional.of(refreshSchemaIntervalMillis);
+
+        return this;
+    }
+
+    public ClusterBuilder servers(Host... servers) {
+        this.servers = Optional.of(ImmutableList.copyOf(servers));
+
+        return this;
+    }
+
+    public ClusterBuilder servers(Collection<Host> servers) {
+        this.servers = Optional.of(servers);
+
+        return this;
+    }
+
+    public ClusterBuilder forTest() {
+        this.forTest = true;
+
+        return this;
+    }
+
+    public Cluster build() {
+        Preconditions.checkState(!(servers.isPresent() && host.isPresent()), "You can't specify a list of servers and a host at the same time");
+        Preconditions.checkState(!(servers.isPresent() && port.isPresent()), "You can't specify a list of servers and a port at the same time");
+        Preconditions.checkState(username.isPresent() == password.isPresent(), "If you specify username, you must specify password");
+        Preconditions.checkState(forTest == refreshSchemaIntervalMillis.isPresent(), "You can't specify refreshSchemaIntervalMillis for test");
+
+        Cluster.Builder clusterBuilder = Cluster.builder();
+        getServers().forEach(
+                (server) -> clusterBuilder.addContactPoint(server.getHostName()).withPort(server.getPort())
+        );
+
+        username.map(username ->
+            password.map(password ->
+                clusterBuilder.withCredentials(username, password)
+            )
+        );
+
+        getRefreshSchemaIntervalMillis().map(refreshSchemaIntervalMillis ->
+            clusterBuilder.withQueryOptions(
+                new QueryOptions()
+                    .setRefreshSchemaIntervalMillis(refreshSchemaIntervalMillis)
+            )
+        );
+
+        Cluster cluster = clusterBuilder.build();
+
+        return cluster;
+    }
+
+    private Optional<Integer> getRefreshSchemaIntervalMillis() {
+        return forTest ? Optional.of(0) : refreshSchemaIntervalMillis;
+    }
+
+    private Collection<Host> getServers() {
+        return servers.orElse(getServersFromHostAndPort());
+    }
+
+    private Collection<Host> getServersFromHostAndPort() {
+        String host = this.host.orElse(DEFAULT_CLUSTER_IP);
+        int port = this.port.orElse(DEFAULT_CASSANDRA_PORT);
+
+        return ImmutableList.of(Host.from(host, port));
+    }
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/4eb8aaf4/backends-common/cassandra/src/main/java/org/apache/james/backends/cassandra/init/ClusterFactory.java
----------------------------------------------------------------------
diff --git a/backends-common/cassandra/src/main/java/org/apache/james/backends/cassandra/init/ClusterFactory.java b/backends-common/cassandra/src/main/java/org/apache/james/backends/cassandra/init/ClusterFactory.java
deleted file mode 100644
index 56eeebc..0000000
--- a/backends-common/cassandra/src/main/java/org/apache/james/backends/cassandra/init/ClusterFactory.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/****************************************************************
- * 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.backends.cassandra.init;
-
-import java.util.List;
-import java.util.Optional;
-
-import org.apache.james.util.Host;
-
-import com.datastax.driver.core.Cluster;
-import com.datastax.driver.core.QueryOptions;
-import com.google.common.base.Strings;
-import com.google.common.collect.ImmutableList;
-
-public class ClusterFactory {
-
-    private final static String DEFAULT_CLUSTER_IP = "localhost";
-    public static final int DEFAULT_CASSANDRA_PORT = 9042;
-
-    public static Cluster createClusterForClusterWithPassWord(List<Host> servers, String userName, String password,
-                                                              Optional<Integer> refreshSchemaIntervalMillis) {
-
-        Cluster.Builder clusterBuilder = Cluster.builder();
-        servers.forEach(
-            (server) -> clusterBuilder.addContactPoint(server.getHostName()).withPort(server.getPort())
-        );
-        if(!Strings.isNullOrEmpty(userName) && !Strings.isNullOrEmpty(password)) {
-            clusterBuilder.withCredentials(userName, password);
-        }
-        if (refreshSchemaIntervalMillis.isPresent()) {
-            clusterBuilder.withQueryOptions(new QueryOptions().setRefreshSchemaIntervalMillis(refreshSchemaIntervalMillis.get()));
-        }
-        return clusterBuilder.build();
-    }
-
-    public static Cluster createClusterForClusterWithoutPassWord(List<Host> servers) {
-        return createClusterForClusterWithPassWord(servers, null, null, Optional.empty());
-    }
-
-    public static Cluster createClusterForSingleServerWithPassWord(String ip, int port, String userName, String password) {
-        return createClusterForClusterWithPassWord(ImmutableList.of(Host.from(ip, port)), userName, password, Optional.empty());
-    }
-
-    public static Cluster createClusterForSingleServerWithoutPassWord(String ip, int port) {
-        return createClusterForClusterWithPassWord(ImmutableList.of(Host.from(ip, port)), null, null, Optional.empty());
-    }
-
-    public static Cluster createTestingCluster(String ip, int port) {
-        return createClusterForClusterWithPassWord(ImmutableList.of(Host.from(ip, port)), null, null, Optional.of(0));
-    }
-
-    public static Cluster createDefaultSession() {
-        return createClusterForSingleServerWithoutPassWord(DEFAULT_CLUSTER_IP, DEFAULT_CASSANDRA_PORT);
-    }
-}

http://git-wip-us.apache.org/repos/asf/james-project/blob/4eb8aaf4/backends-common/cassandra/src/main/resources/META-INF/cassandra-session.xml
----------------------------------------------------------------------
diff --git a/backends-common/cassandra/src/main/resources/META-INF/cassandra-session.xml b/backends-common/cassandra/src/main/resources/META-INF/cassandra-session.xml
index e8bda8d..3fe26f0 100644
--- a/backends-common/cassandra/src/main/resources/META-INF/cassandra-session.xml
+++ b/backends-common/cassandra/src/main/resources/META-INF/cassandra-session.xml
@@ -109,7 +109,7 @@
     </bean>
 
     <bean id="cassandra-cluster"
-          class="org.apache.james.backends.cassandra.init.ClusterFactory"
+          class="org.apache.james.backends.cassandra.init.ClusterBuilder"
           factory-method="createClusterForSingleServerWithoutPassWord"
           lazy-init="true">
         <constructor-arg index="0" value="${cassandra.ip}"/>

http://git-wip-us.apache.org/repos/asf/james-project/blob/4eb8aaf4/backends-common/cassandra/src/test/java/org/apache/james/backends/cassandra/CassandraCluster.java
----------------------------------------------------------------------
diff --git a/backends-common/cassandra/src/test/java/org/apache/james/backends/cassandra/CassandraCluster.java b/backends-common/cassandra/src/test/java/org/apache/james/backends/cassandra/CassandraCluster.java
index fbf3e8e..6e987fb 100644
--- a/backends-common/cassandra/src/test/java/org/apache/james/backends/cassandra/CassandraCluster.java
+++ b/backends-common/cassandra/src/test/java/org/apache/james/backends/cassandra/CassandraCluster.java
@@ -26,7 +26,7 @@ import javax.inject.Inject;
 import org.apache.james.backends.cassandra.components.CassandraModule;
 import org.apache.james.backends.cassandra.init.CassandraTableManager;
 import org.apache.james.backends.cassandra.init.CassandraTypesProvider;
-import org.apache.james.backends.cassandra.init.ClusterFactory;
+import org.apache.james.backends.cassandra.init.ClusterBuilder;
 import org.apache.james.backends.cassandra.init.ClusterWithKeyspaceCreatedFactory;
 import org.apache.james.backends.cassandra.init.SessionWithInitializedTablesFactory;
 import org.apache.james.backends.cassandra.utils.FunctionRunnerWithRetry;
@@ -92,7 +92,10 @@ public final class CassandraCluster {
     }
 
     public Cluster getCluster() {
-        return ClusterFactory.createTestingCluster(CLUSTER_IP, CLUSTER_PORT_TEST);
+        return ClusterBuilder.builder()
+                .host(CLUSTER_IP)
+                .port(CLUSTER_PORT_TEST)
+                .build();
     }
 
     private void sleep(long sleepMs) {

http://git-wip-us.apache.org/repos/asf/james-project/blob/4eb8aaf4/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/CassandraSessionModule.java
----------------------------------------------------------------------
diff --git a/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/CassandraSessionModule.java b/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/CassandraSessionModule.java
index 640472f..a464bc7 100644
--- a/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/CassandraSessionModule.java
+++ b/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/CassandraSessionModule.java
@@ -30,7 +30,7 @@ import org.apache.commons.configuration.PropertiesConfiguration;
 import org.apache.james.backends.cassandra.components.CassandraModule;
 import org.apache.james.backends.cassandra.init.CassandraModuleComposite;
 import org.apache.james.backends.cassandra.init.CassandraZonedDateTimeModule;
-import org.apache.james.backends.cassandra.init.ClusterFactory;
+import org.apache.james.backends.cassandra.init.ClusterBuilder;
 import org.apache.james.backends.cassandra.init.ClusterWithKeyspaceCreatedFactory;
 import org.apache.james.backends.cassandra.init.SessionWithInitializedTablesFactory;
 import org.apache.james.filesystem.api.FileSystem;
@@ -88,7 +88,9 @@ public class CassandraSessionModule extends AbstractModule {
         return getRetryer(executor, configuration)
                 .getWithRetry(ctx -> ClusterWithKeyspaceCreatedFactory
                         .config(
-                            ClusterFactory.createClusterForClusterWithoutPassWord(servers),
+                            ClusterBuilder.builder()
+                                .servers(servers)
+                                .build(),
                             configuration.getString("cassandra.keyspace"))
                         .replicationFactor(configuration.getInt("cassandra.replication.factor"))
                         .clusterWithInitializedKeyspace())
@@ -99,7 +101,7 @@ public class CassandraSessionModule extends AbstractModule {
         String[] ipAndPorts = configuration.getStringArray("cassandra.nodes");
 
         return Arrays.stream(ipAndPorts)
-                .map(string -> Host.parseConfString(string, ClusterFactory.DEFAULT_CASSANDRA_PORT))
+                .map(string -> Host.parseConfString(string, ClusterBuilder.DEFAULT_CASSANDRA_PORT))
                 .collect(Guavate.toImmutableList());
     }
 


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org