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 ro...@apache.org on 2019/11/15 13:24:19 UTC

[james-project] branch master updated (fa6f51b -> 5887c6c)

This is an automated email from the ASF dual-hosted git repository.

rouazana pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git.


    from fa6f51b  [Refactoring] Move remaining abstract test classes in mailbox api and their implementations to JUnit 5
     new bcf4d36  JAMES-2981 Keyspace creation should be optional
     new 5887c6c  JAMES-2981 update cassandra configuration documentation

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../backends/cassandra/init/KeyspaceFactory.java   |  6 ++++
 .../init/configuration/ClusterConfiguration.java   | 33 ++++++++++++++++++----
 .../james/backends/cassandra/CassandraCluster.java |  1 +
 .../SessionWithInitializedTablesFactoryTest.java   |  1 +
 .../destination/conf/cassandra.properties          |  1 +
 .../destination/conf/cassandra.properties          |  1 +
 .../destination/conf/cassandra.properties          |  1 +
 .../destination/conf/cassandra.properties          |  1 +
 .../CassandraRabbitMQAwsS3SmtpTestRuleFactory.java |  1 +
 .../mpt/smtp/CassandraSmtpTestRuleFactory.java     |  1 +
 .../AuthenticatedCassandraJamesServerTest.java     |  1 +
 .../james/CassandraAuthenticationExtension.java    |  1 +
 .../org/apache/james/CassandraNodeConfTest.java    |  1 +
 .../java/org/apache/james/DockerCassandraRule.java |  1 +
 src/site/xdoc/server/config-cassandra.xml          |  5 ++++
 15 files changed, 51 insertions(+), 5 deletions(-)


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


[james-project] 02/02: JAMES-2981 update cassandra configuration documentation

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rouazana pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 5887c6c3886b8fc38afc6014ce06e29b8f76f0e8
Author: RĂ©mi KOWALSKI <rk...@linagora.com>
AuthorDate: Wed Nov 13 17:17:14 2019 +0100

    JAMES-2981 update cassandra configuration documentation
---
 src/site/xdoc/server/config-cassandra.xml | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/src/site/xdoc/server/config-cassandra.xml b/src/site/xdoc/server/config-cassandra.xml
index ad9a400..34a05df 100644
--- a/src/site/xdoc/server/config-cassandra.xml
+++ b/src/site/xdoc/server/config-cassandra.xml
@@ -35,6 +35,11 @@
         <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.create</strong></dt>
+        <dd>Indicate if the keyspace should be created by James. Optional, default value: <b>false</b><br />
+            If set to true James will attempt to create the keyspace when starting up.<br />
+        </dd>
+
         <dt><strong>cassandra.keyspace</strong></dt>
         <dd>Is the name of the keyspace used by James. Optional, default value: <b>apache_james</b></dd>
 


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


[james-project] 01/02: JAMES-2981 Keyspace creation should be optional

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rouazana pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit bcf4d36500fb8a7ce7d272929621c6e7ec7d042b
Author: Antoine DUPRAT <ad...@linagora.com>
AuthorDate: Tue Nov 12 12:07:33 2019 +0100

    JAMES-2981 Keyspace creation should be optional
---
 .../backends/cassandra/init/KeyspaceFactory.java   |  6 ++++
 .../init/configuration/ClusterConfiguration.java   | 33 ++++++++++++++++++----
 .../james/backends/cassandra/CassandraCluster.java |  1 +
 .../SessionWithInitializedTablesFactoryTest.java   |  1 +
 .../destination/conf/cassandra.properties          |  1 +
 .../destination/conf/cassandra.properties          |  1 +
 .../destination/conf/cassandra.properties          |  1 +
 .../destination/conf/cassandra.properties          |  1 +
 .../CassandraRabbitMQAwsS3SmtpTestRuleFactory.java |  1 +
 .../mpt/smtp/CassandraSmtpTestRuleFactory.java     |  1 +
 .../AuthenticatedCassandraJamesServerTest.java     |  1 +
 .../james/CassandraAuthenticationExtension.java    |  1 +
 .../org/apache/james/CassandraNodeConfTest.java    |  1 +
 .../java/org/apache/james/DockerCassandraRule.java |  1 +
 14 files changed, 46 insertions(+), 5 deletions(-)

diff --git a/backends-common/cassandra/src/main/java/org/apache/james/backends/cassandra/init/KeyspaceFactory.java b/backends-common/cassandra/src/main/java/org/apache/james/backends/cassandra/init/KeyspaceFactory.java
index 3f71803..be1630b 100644
--- a/backends-common/cassandra/src/main/java/org/apache/james/backends/cassandra/init/KeyspaceFactory.java
+++ b/backends-common/cassandra/src/main/java/org/apache/james/backends/cassandra/init/KeyspaceFactory.java
@@ -26,6 +26,12 @@ import com.datastax.driver.core.Session;
 
 public class KeyspaceFactory {
     public static void createKeyspace(ClusterConfiguration clusterConfiguration, Cluster cluster) {
+        if (clusterConfiguration.shouldCreateKeyspace()) {
+            doCreateKeyspace(clusterConfiguration, cluster);
+        }
+    }
+
+    private static void doCreateKeyspace(ClusterConfiguration clusterConfiguration, Cluster cluster) {
         try (Session session = cluster.connect()) {
             session.execute("CREATE KEYSPACE IF NOT EXISTS " + clusterConfiguration.getKeyspace()
                 + " WITH replication = {'class':'SimpleStrategy', 'replication_factor':" + clusterConfiguration.getReplicationFactor() + "}"
diff --git a/backends-common/cassandra/src/main/java/org/apache/james/backends/cassandra/init/configuration/ClusterConfiguration.java b/backends-common/cassandra/src/main/java/org/apache/james/backends/cassandra/init/configuration/ClusterConfiguration.java
index d310627..09a10b0 100644
--- a/backends-common/cassandra/src/main/java/org/apache/james/backends/cassandra/init/configuration/ClusterConfiguration.java
+++ b/backends-common/cassandra/src/main/java/org/apache/james/backends/cassandra/init/configuration/ClusterConfiguration.java
@@ -37,6 +37,7 @@ public class ClusterConfiguration {
 
     public static class Builder {
         private ImmutableList.Builder<Host> hosts;
+        private boolean createKeyspace;
         private Optional<String> keyspace;
         private Optional<Integer> replicationFactor;
         private Optional<Integer> minDelay;
@@ -52,6 +53,7 @@ public class ClusterConfiguration {
 
         public Builder() {
             hosts = ImmutableList.builder();
+            createKeyspace = false;
             keyspace = Optional.empty();
             replicationFactor = Optional.empty();
             minDelay = Optional.empty();
@@ -81,6 +83,11 @@ public class ClusterConfiguration {
             return this;
         }
 
+        public Builder createKeyspace() {
+            this.createKeyspace = true;
+            return this;
+        }
+
         public Builder keyspace(Optional<String> keyspace) {
             this.keyspace = keyspace;
             return this;
@@ -189,6 +196,7 @@ public class ClusterConfiguration {
         public ClusterConfiguration build() {
             return new ClusterConfiguration(
                 hosts.build(),
+                createKeyspace,
                 keyspace.orElse(DEFAULT_KEYSPACE),
                 replicationFactor.orElse(DEFAULT_REPLICATION_FACTOR),
                 minDelay.orElse(DEFAULT_CONNECTION_MIN_DELAY),
@@ -205,6 +213,7 @@ public class ClusterConfiguration {
     }
 
     private static final String CASSANDRA_NODES = "cassandra.nodes";
+    public static final String CASSANDRA_CREATE_KEYSPACE = "cassandra.keyspace.create";
     public static final String CASSANDRA_KEYSPACE = "cassandra.keyspace";
     public static final String CASSANDRA_USER = "cassandra.user";
     public static final String CASSANDRA_PASSWORD = "cassandra.password";
@@ -230,7 +239,11 @@ public class ClusterConfiguration {
     }
 
     public static ClusterConfiguration from(Configuration configuration) {
-        return ClusterConfiguration.builder()
+        boolean createKeySpace = Optional.ofNullable(configuration.getBoolean(CASSANDRA_CREATE_KEYSPACE, null))
+            .filter(Boolean::booleanValue)
+            .isPresent();
+
+        ClusterConfiguration.Builder builder = ClusterConfiguration.builder()
             .hosts(listCassandraServers(configuration))
             .keyspace(Optional.ofNullable(configuration.getString(CASSANDRA_KEYSPACE, null)))
             .replicationFactor(Optional.ofNullable(configuration.getInteger(REPLICATION_FACTOR, null)))
@@ -242,8 +255,11 @@ public class ClusterConfiguration {
             .connectTimeoutMillis(Optional.ofNullable(configuration.getInteger(CONNECT_TIMEOUT_MILLIS, null)))
             .useSsl(Optional.ofNullable(configuration.getBoolean(CASSANDRA_SSL, null)))
             .username(Optional.ofNullable(configuration.getString(CASSANDRA_USER, null)))
-            .password(Optional.ofNullable(configuration.getString(CASSANDRA_PASSWORD, null)))
-            .build();
+            .password(Optional.ofNullable(configuration.getString(CASSANDRA_PASSWORD, null)));
+        if (createKeySpace) {
+            builder = builder.createKeyspace();
+        }
+        return builder.build();
     }
 
     private static List<Host> listCassandraServers(Configuration configuration) {
@@ -286,6 +302,7 @@ public class ClusterConfiguration {
     }
 
     private final List<Host> hosts;
+    private final boolean createKeyspace;
     private final String keyspace;
     private final int replicationFactor;
     private final int minDelay;
@@ -299,11 +316,12 @@ public class ClusterConfiguration {
     private final Optional<String> password;
     private final boolean durableWrites;
 
-    public ClusterConfiguration(List<Host> hosts, String keyspace, int replicationFactor, int minDelay, int maxRetry,
+    public ClusterConfiguration(List<Host> hosts, boolean createKeyspace, String keyspace, int replicationFactor, int minDelay, int maxRetry,
                                 Optional<QueryLoggerConfiguration> queryLoggerConfiguration, Optional<PoolingOptions> poolingOptions,
                                 int readTimeoutMillis, int connectTimeoutMillis, boolean useSsl, Optional<String> username,
                                 Optional<String> password, boolean durableWrites) {
         this.hosts = hosts;
+        this.createKeyspace = createKeyspace;
         this.keyspace = keyspace;
         this.replicationFactor = replicationFactor;
         this.minDelay = minDelay;
@@ -326,6 +344,10 @@ public class ClusterConfiguration {
         return hosts;
     }
 
+    public boolean shouldCreateKeyspace() {
+        return createKeyspace;
+    }
+
     public String getKeyspace() {
         return keyspace;
     }
@@ -378,6 +400,7 @@ public class ClusterConfiguration {
             return Objects.equals(this.minDelay, that.minDelay)
                 && Objects.equals(this.maxRetry, that.maxRetry)
                 && Objects.equals(this.hosts, that.hosts)
+                && Objects.equals(this.createKeyspace, that.createKeyspace)
                 && Objects.equals(this.keyspace, that.keyspace)
                 && Objects.equals(this.replicationFactor, that.replicationFactor)
                 && Objects.equals(this.queryLoggerConfiguration, that.queryLoggerConfiguration)
@@ -393,7 +416,7 @@ public class ClusterConfiguration {
 
     @Override
     public final int hashCode() {
-        return Objects.hash(hosts, keyspace, replicationFactor, minDelay, maxRetry, queryLoggerConfiguration, poolingOptions,
+        return Objects.hash(hosts, createKeyspace, keyspace, replicationFactor, minDelay, maxRetry, queryLoggerConfiguration, poolingOptions,
             readTimeoutMillis, connectTimeoutMillis, username, useSsl, password);
     }
 }
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 d83fc26..f4be201 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
@@ -60,6 +60,7 @@ public final class CassandraCluster implements AutoCloseable {
             ClusterConfiguration clusterConfiguration = ClusterConfiguration.builder()
                 .host(host)
                 .keyspace(KEYSPACE)
+                .createKeyspace()
                 .disableDurableWrites()
                 .build();
             cluster = ClusterFactory.create(clusterConfiguration);
diff --git a/backends-common/cassandra/src/test/java/org/apache/james/backends/cassandra/init/SessionWithInitializedTablesFactoryTest.java b/backends-common/cassandra/src/test/java/org/apache/james/backends/cassandra/init/SessionWithInitializedTablesFactoryTest.java
index 3235b40..fb557e2 100644
--- a/backends-common/cassandra/src/test/java/org/apache/james/backends/cassandra/init/SessionWithInitializedTablesFactoryTest.java
+++ b/backends-common/cassandra/src/test/java/org/apache/james/backends/cassandra/init/SessionWithInitializedTablesFactoryTest.java
@@ -123,6 +123,7 @@ class SessionWithInitializedTablesFactoryTest {
         ClusterConfiguration clusterConfiguration = ClusterConfiguration.builder()
             .host(cassandraServer.getHost())
             .keyspace(KEYSPACE)
+            .createKeyspace()
             .replicationFactor(1)
             .disableDurableWrites()
             .build();
diff --git a/dockerfiles/run/guice/cassandra-ldap/destination/conf/cassandra.properties b/dockerfiles/run/guice/cassandra-ldap/destination/conf/cassandra.properties
index cebfe65..0e19020 100644
--- a/dockerfiles/run/guice/cassandra-ldap/destination/conf/cassandra.properties
+++ b/dockerfiles/run/guice/cassandra-ldap/destination/conf/cassandra.properties
@@ -2,6 +2,7 @@
 # Read https://james.apache.org/server/config-cassandra.html for further details
 
 cassandra.nodes=cassandra
+cassandra.keyspace.create=true
 cassandra.keyspace=apache_james
 #cassandra.user=cassandra
 #cassandra.password=cassandra
diff --git a/dockerfiles/run/guice/cassandra-rabbitmq-ldap/destination/conf/cassandra.properties b/dockerfiles/run/guice/cassandra-rabbitmq-ldap/destination/conf/cassandra.properties
index 842f56d..137b2cc 100644
--- a/dockerfiles/run/guice/cassandra-rabbitmq-ldap/destination/conf/cassandra.properties
+++ b/dockerfiles/run/guice/cassandra-rabbitmq-ldap/destination/conf/cassandra.properties
@@ -2,6 +2,7 @@
 # Read https://james.apache.org/server/config-cassandra.html for further details
 
 cassandra.nodes=cassandra
+cassandra.keyspace.create=true
 cassandra.keyspace=apache_james
 #cassandra.user=cassandra
 #cassandra.password=cassandra
diff --git a/dockerfiles/run/guice/cassandra-rabbitmq/destination/conf/cassandra.properties b/dockerfiles/run/guice/cassandra-rabbitmq/destination/conf/cassandra.properties
index 842f56d..137b2cc 100644
--- a/dockerfiles/run/guice/cassandra-rabbitmq/destination/conf/cassandra.properties
+++ b/dockerfiles/run/guice/cassandra-rabbitmq/destination/conf/cassandra.properties
@@ -2,6 +2,7 @@
 # Read https://james.apache.org/server/config-cassandra.html for further details
 
 cassandra.nodes=cassandra
+cassandra.keyspace.create=true
 cassandra.keyspace=apache_james
 #cassandra.user=cassandra
 #cassandra.password=cassandra
diff --git a/dockerfiles/run/guice/cassandra/destination/conf/cassandra.properties b/dockerfiles/run/guice/cassandra/destination/conf/cassandra.properties
index 413a2ad..b96beef 100644
--- a/dockerfiles/run/guice/cassandra/destination/conf/cassandra.properties
+++ b/dockerfiles/run/guice/cassandra/destination/conf/cassandra.properties
@@ -2,6 +2,7 @@
 # Read https://james.apache.org/server/config-cassandra.html for further details
 
 cassandra.nodes=cassandra
+cassandra.keyspace.create=true
 cassandra.keyspace=apache_james
 #cassandra.user=cassandra
 #cassandra.password=cassandra
diff --git a/mpt/impl/smtp/cassandra-rabbitmq-object-storage/src/test/java/org/apache/james/mpt/smtp/CassandraRabbitMQAwsS3SmtpTestRuleFactory.java b/mpt/impl/smtp/cassandra-rabbitmq-object-storage/src/test/java/org/apache/james/mpt/smtp/CassandraRabbitMQAwsS3SmtpTestRuleFactory.java
index 5229411..91cebea 100644
--- a/mpt/impl/smtp/cassandra-rabbitmq-object-storage/src/test/java/org/apache/james/mpt/smtp/CassandraRabbitMQAwsS3SmtpTestRuleFactory.java
+++ b/mpt/impl/smtp/cassandra-rabbitmq-object-storage/src/test/java/org/apache/james/mpt/smtp/CassandraRabbitMQAwsS3SmtpTestRuleFactory.java
@@ -67,6 +67,7 @@ public final class CassandraRabbitMQAwsS3SmtpTestRuleFactory {
                     ClusterConfiguration.builder()
                         .host(cassandraHost)
                         .keyspace("testing")
+                        .createKeyspace()
                         .replicationFactor(1)
                         .build()),
                 binder -> binder.bind(DNSService.class).toInstance(dnsService),
diff --git a/mpt/impl/smtp/cassandra/src/test/java/org/apache/james/mpt/smtp/CassandraSmtpTestRuleFactory.java b/mpt/impl/smtp/cassandra/src/test/java/org/apache/james/mpt/smtp/CassandraSmtpTestRuleFactory.java
index f8f95ff..322bca0 100644
--- a/mpt/impl/smtp/cassandra/src/test/java/org/apache/james/mpt/smtp/CassandraSmtpTestRuleFactory.java
+++ b/mpt/impl/smtp/cassandra/src/test/java/org/apache/james/mpt/smtp/CassandraSmtpTestRuleFactory.java
@@ -55,6 +55,7 @@ public final class CassandraSmtpTestRuleFactory {
                     ClusterConfiguration.builder()
                         .host(cassandraHost)
                         .keyspace("testing")
+                        .createKeyspace()
                         .replicationFactor(1)
                         .build()),
                 binder -> binder.bind(DNSService.class).toInstance(dnsService));
diff --git a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/AuthenticatedCassandraJamesServerTest.java b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/AuthenticatedCassandraJamesServerTest.java
index 48a450c..3bb5636 100644
--- a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/AuthenticatedCassandraJamesServerTest.java
+++ b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/AuthenticatedCassandraJamesServerTest.java
@@ -68,6 +68,7 @@ class AuthenticatedCassandraJamesServerTest {
                 .toInstance(ClusterConfiguration.builder()
                     .host(cassandraExtension.getCassandra().getHost())
                     .keyspace("testing")
+                    .createKeyspace()
                     .replicationFactor(1)
                     .maxRetry(1)
                     .minDelay(100)
diff --git a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraAuthenticationExtension.java b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraAuthenticationExtension.java
index 8351bce..35daa6a 100644
--- a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraAuthenticationExtension.java
+++ b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraAuthenticationExtension.java
@@ -64,6 +64,7 @@ public class CassandraAuthenticationExtension implements GuiceModuleTestExtensio
                 .toInstance(configurationBuilder
                     .host(authenticatedCassandra.getHost())
                     .keyspace("testing")
+                    .createKeyspace()
                     .username("cassandra")
                     .replicationFactor(1)
                     .build()),
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
index 9edf24c..396ddab 100644
--- 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
@@ -128,6 +128,7 @@ class CassandraNodeConfTest {
         return ClusterConfiguration.builder()
             .hosts(hosts)
             .keyspace("apache_james")
+            .createKeyspace()
             .replicationFactor(1)
             .maxRetry(10)
             .minDelay(5000)
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 98a4fa5..542eef3 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
@@ -49,6 +49,7 @@ public class DockerCassandraRule implements GuiceModuleTestRule {
             .toInstance(ClusterConfiguration.builder()
                 .host(cassandraContainer.getHost())
                 .keyspace("testing")
+                .createKeyspace()
                 .replicationFactor(1)
                 .maxRetry(20)
                 .minDelay(5000)


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