Skip to content

Commit

Permalink
Create a separate Guice module for OpenPaaS communication (#1261)
Browse files Browse the repository at this point in the history
  • Loading branch information
HoussemNasri authored Nov 5, 2024
1 parent 018d6e2 commit bba278e
Show file tree
Hide file tree
Showing 24 changed files with 885 additions and 23 deletions.
4 changes: 4 additions & 0 deletions tmail-backend/apps/distributed/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@
<groupId>${project.groupId}</groupId>
<artifactId>tmail-mailets</artifactId>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>tmail-openpaas</artifactId>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>tmail-rate-limiter-cassandra</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.apache.james.vault.VaultConfiguration;

import com.github.fge.lambdas.Throwing;
import com.linagora.tmail.OpenPaasModuleChooserConfiguration;
import com.linagora.tmail.blob.guice.BlobStoreConfiguration;
import com.linagora.tmail.combined.identity.UsersRepositoryModuleChooser;
import com.linagora.tmail.encrypted.MailboxConfiguration;
Expand All @@ -33,6 +34,7 @@ public record DistributedJamesConfiguration(ConfigurationPath configurationPath,
MailQueueViewChoice mailQueueViewChoice,
FirebaseModuleChooserConfiguration firebaseModuleChooserConfiguration,
LinagoraServicesDiscoveryModuleChooserConfiguration linagoraServicesDiscoveryModuleChooserConfiguration,
OpenPaasModuleChooserConfiguration openPaasModuleChooserConfiguration,
boolean jmapEnabled,
PropertiesProvider propertiesProvider,
FileConfigurationProvider fileConfigurationProvider,
Expand All @@ -50,6 +52,7 @@ public static class Builder {
private Optional<MailQueueViewChoice> mailQueueViewChoice;
private Optional<FirebaseModuleChooserConfiguration> firebaseModuleChooserConfiguration;
private Optional<LinagoraServicesDiscoveryModuleChooserConfiguration> linagoraServicesDiscoveryModuleChooserConfiguration;
private Optional<OpenPaasModuleChooserConfiguration> openPaasModuleChooserConfiguration;
private Optional<Boolean> jmapEnabled;
private Optional<EventBusKeysChoice> eventBusKeysChoice;
private Optional<Boolean> quotaCompatibilityMode;
Expand All @@ -66,6 +69,7 @@ private Builder() {
mailQueueViewChoice = Optional.empty();
firebaseModuleChooserConfiguration = Optional.empty();
linagoraServicesDiscoveryModuleChooserConfiguration = Optional.empty();
openPaasModuleChooserConfiguration = Optional.empty();
jmapEnabled = Optional.empty();
quotaCompatibilityMode = Optional.empty();
eventBusKeysChoice = Optional.empty();
Expand Down Expand Up @@ -136,6 +140,11 @@ public Builder linagoraServicesDiscoveryModuleChooserConfiguration(LinagoraServi
return this;
}

public Builder openPassModuleChooserConfiguration(OpenPaasModuleChooserConfiguration openPaasModuleChooserConfiguration) {
this.openPaasModuleChooserConfiguration = Optional.of(openPaasModuleChooserConfiguration);
return this;
}

public Builder jmapEnabled(boolean enable) {
this.jmapEnabled = Optional.of(enable);
return this;
Expand Down Expand Up @@ -193,6 +202,9 @@ public DistributedJamesConfiguration build() {
LinagoraServicesDiscoveryModuleChooserConfiguration servicesDiscoveryModuleChooserConfiguration = this.linagoraServicesDiscoveryModuleChooserConfiguration
.orElseGet(Throwing.supplier(() -> LinagoraServicesDiscoveryModuleChooserConfiguration.parse(propertiesProvider)));

OpenPaasModuleChooserConfiguration openPaasModuleChooserConfiguration = this.openPaasModuleChooserConfiguration
.orElseGet(Throwing.supplier(() -> OpenPaasModuleChooserConfiguration.parse(propertiesProvider)));

boolean jmapEnabled = this.jmapEnabled.orElseGet(() -> {
try {
return JMAPModule.parseConfiguration(propertiesProvider).isEnabled();
Expand Down Expand Up @@ -246,6 +258,7 @@ public DistributedJamesConfiguration build() {
mailQueueViewChoice,
firebaseModuleChooserConfiguration,
servicesDiscoveryModuleChooserConfiguration,
openPaasModuleChooserConfiguration,
jmapEnabled,
propertiesProvider,
configurationProvider,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@
import com.google.inject.multibindings.ProvidesIntoSet;
import com.google.inject.name.Names;
import com.google.inject.util.Modules;
import com.linagora.tmail.OpenPaasModule;
import com.linagora.tmail.OpenPaasModuleChooserConfiguration;
import com.linagora.tmail.ScheduledReconnectionHandler;
import com.linagora.tmail.blob.guice.BlobStoreCacheModulesChooser;
import com.linagora.tmail.blob.guice.BlobStoreConfiguration;
Expand Down Expand Up @@ -361,6 +363,7 @@ public static GuiceJamesServer createServer(DistributedJamesConfiguration config
.combineWith(UsersRepositoryModuleChooser.chooseModules(configuration.usersRepositoryImplementation()))
.combineWith(chooseFirebase(configuration.firebaseModuleChooserConfiguration()))
.combineWith(chooseLinagoraServicesDiscovery(configuration.linagoraServicesDiscoveryModuleChooserConfiguration()))
.combineWith(chooseOpenPaasModule(configuration.openPaasModuleChooserConfiguration()))
.combineWith(chooseRedisRateLimiterModule(configuration))
.combineWith(chooseRspamdModule(configuration))
.combineWith(chooseQuotaModule(configuration))
Expand Down Expand Up @@ -462,6 +465,13 @@ private static List<Module> chooseLinagoraServicesDiscovery(LinagoraServicesDisc
return List.of();
}

private static List<Module> chooseOpenPaasModule(OpenPaasModuleChooserConfiguration openPaasModuleChooserConfiguration) {
if (openPaasModuleChooserConfiguration.enabled()) {
return List.of(new OpenPaasModule());
}
return List.of();
}

private static List<Module> chooseRedisRateLimiterModule(DistributedJamesConfiguration configuration) {
try {
configuration.propertiesProvider().getConfiguration("redis");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.linagora.tmail.james.app;

import org.apache.james.JamesServerBuilder;
import org.apache.james.JamesServerExtension;
import org.apache.james.SearchConfiguration;
import org.apache.james.backends.redis.RedisExtension;
import org.apache.james.utils.GuiceProbe;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import com.google.inject.multibindings.Multibinder;

import com.linagora.tmail.OpenPaasModuleChooserConfiguration;
import com.linagora.tmail.combined.identity.LdapExtension;
import com.linagora.tmail.combined.identity.UsersRepositoryClassProbe;
import com.linagora.tmail.combined.identity.UsersRepositoryModuleChooser;

public class DistributedServerWithOpenPaasRabbitMqConfiguredTest {
@RegisterExtension
static JamesServerExtension
testExtension = new JamesServerBuilder<DistributedJamesConfiguration>(tmpDir ->
DistributedJamesConfiguration.builder()
.workingDirectory(tmpDir)
.configurationFromClasspath()
.searchConfiguration(SearchConfiguration.openSearch())
.usersRepository(UsersRepositoryModuleChooser.Implementation.COMBINED)
.eventBusKeysChoice(EventBusKeysChoice.REDIS)
.openPassModuleChooserConfiguration(OpenPaasModuleChooserConfiguration.ENABLED)
.build())
.server(configuration -> DistributedServer.createServer(configuration)
.overrideWith(binder -> Multibinder.newSetBinder(binder, GuiceProbe.class).addBinding().to(UsersRepositoryClassProbe.class)))
.extension(new DockerOpenSearchExtension())
.extension(new CassandraExtension())
.extension(new RabbitMQExtension())
.extension(new LdapExtension())
.extension(new RedisExtension())
.lifeCycle(JamesServerExtension.Lifecycle.PER_CLASS)
.build();

@Test
void serverShouldStartWithOpenPaasRabbitMqConfigured() {
}

}
33 changes: 30 additions & 3 deletions tmail-backend/apps/memory/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@
<groupId>${project.groupId}</groupId>
<artifactId>team-mailboxes-guice</artifactId>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>tmail-guice-distributed</artifactId>
<scope>test</scope>
<type>test-jar</type>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>tmail-guice-jmap</artifactId>
Expand All @@ -63,10 +69,24 @@
<groupId>${project.groupId}</groupId>
<artifactId>tmail-mailets</artifactId>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>tmail-openpaas</artifactId>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>tmail-openpaas</artifactId>
<scope>test</scope>
<type>test-jar</type>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>tmail-webadmin-mailbox</artifactId>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>tmail-webadmin-team-mailboxes</artifactId>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>webadmin-email-address-contact</artifactId>
Expand All @@ -81,13 +101,15 @@
</dependency>
<dependency>
<groupId>${james.groupId}</groupId>
<artifactId>apache-james-linshare</artifactId>
<artifactId>apache-james-backends-rabbitmq</artifactId>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>tmail-webadmin-team-mailboxes</artifactId>
<groupId>${james.groupId}</groupId>
<artifactId>apache-james-linshare</artifactId>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>${james.groupId}</groupId>
Expand Down Expand Up @@ -144,6 +166,11 @@
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>${james.groupId}</groupId>
<artifactId>queue-rabbitmq-guice</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.linagora.tmail</groupId>
<artifactId>logback-json-classic</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.apache.james.utils.PropertiesProvider;

import com.github.fge.lambdas.Throwing;
import com.linagora.tmail.OpenPaasModuleChooserConfiguration;
import com.linagora.tmail.encrypted.MailboxConfiguration;
import com.linagora.tmail.james.jmap.firebase.FirebaseModuleChooserConfiguration;
import com.linagora.tmail.james.jmap.service.discovery.LinagoraServicesDiscoveryModuleChooserConfiguration;
Expand All @@ -26,6 +27,7 @@ public record MemoryConfiguration(ConfigurationPath configurationPath, JamesDire
UsersRepositoryModuleChooser.Implementation usersRepositoryImplementation,
FirebaseModuleChooserConfiguration firebaseModuleChooserConfiguration,
LinagoraServicesDiscoveryModuleChooserConfiguration linagoraServicesDiscoveryModuleChooserConfiguration,
OpenPaasModuleChooserConfiguration openPaasModuleChooserConfiguration,
FileConfigurationProvider fileConfigurationProvider,
boolean jmapEnabled,
boolean dropListEnabled) implements Configuration {
Expand All @@ -36,6 +38,7 @@ public static class Builder {
private Optional<UsersRepositoryModuleChooser.Implementation> usersRepositoryImplementation;
private Optional<FirebaseModuleChooserConfiguration> firebaseModuleChooserConfiguration;
private Optional<LinagoraServicesDiscoveryModuleChooserConfiguration> linagoraServicesDiscoveryModuleChooserConfiguration;
private Optional<OpenPaasModuleChooserConfiguration> openPaasModuleChooserConfiguration;
private Optional<Boolean> jmapEnabled;
private Optional<Boolean> dropListsEnabled;

Expand All @@ -46,6 +49,7 @@ private Builder() {
usersRepositoryImplementation = Optional.empty();
firebaseModuleChooserConfiguration = Optional.empty();
linagoraServicesDiscoveryModuleChooserConfiguration = Optional.empty();
openPaasModuleChooserConfiguration = Optional.empty();
jmapEnabled = Optional.empty();
dropListsEnabled = Optional.empty();
}
Expand Down Expand Up @@ -98,6 +102,11 @@ public Builder linagoraServiceDiscoveryModuleChooserConfiguration(LinagoraServic
return this;
}

public Builder openPaasModuleChooserConfiguration(OpenPaasModuleChooserConfiguration openPaasModuleChooserConfiguration) {
this.openPaasModuleChooserConfiguration = Optional.of(openPaasModuleChooserConfiguration);
return this;
}

public Builder jmapEnabled(boolean enable) {
this.jmapEnabled = Optional.of(enable);
return this;
Expand Down Expand Up @@ -133,6 +142,9 @@ public MemoryConfiguration build() {
LinagoraServicesDiscoveryModuleChooserConfiguration servicesDiscoveryModuleChooserConfiguration = this.linagoraServicesDiscoveryModuleChooserConfiguration.orElseGet(Throwing.supplier(
() -> LinagoraServicesDiscoveryModuleChooserConfiguration.parse(new PropertiesProvider(fileSystem, configurationPath))));

OpenPaasModuleChooserConfiguration openPaasModuleChooserConfiguration = this.openPaasModuleChooserConfiguration.orElseGet(Throwing.supplier(
() -> OpenPaasModuleChooserConfiguration.parse(new PropertiesProvider(fileSystem, configurationPath))));

boolean jmapEnabled = this.jmapEnabled.orElseGet(() -> {
PropertiesProvider propertiesProvider = new PropertiesProvider(fileSystem, configurationPath);
try {
Expand Down Expand Up @@ -162,6 +174,7 @@ public MemoryConfiguration build() {
usersRepositoryChoice,
firebaseModuleChooserConfiguration,
servicesDiscoveryModuleChooserConfiguration,
openPaasModuleChooserConfiguration,
configurationProvider,
jmapEnabled,
dropListsEnabled);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
import com.google.inject.Provides;
import com.google.inject.Singleton;
import com.google.inject.util.Modules;
import com.linagora.tmail.OpenPaasModule;
import com.linagora.tmail.OpenPaasModuleChooserConfiguration;
import com.linagora.tmail.encrypted.ClearEmailContentFactory;
import com.linagora.tmail.encrypted.EncryptedMailboxManager;
import com.linagora.tmail.encrypted.InMemoryEncryptedEmailContentStore;
Expand Down Expand Up @@ -184,6 +186,7 @@ public static GuiceJamesServer createServer(MemoryConfiguration configuration) {
.chooseModules(configuration.usersRepositoryImplementation()))
.combineWith(chooseFirebase(configuration.firebaseModuleChooserConfiguration()))
.combineWith(chooseLinagoraServiceDiscovery(configuration.linagoraServicesDiscoveryModuleChooserConfiguration()))
.combineWith(chooseOpenPaas(configuration.openPaasModuleChooserConfiguration()))
.combineWith(choosePop3ServerModule(configuration))
.overrideWith(chooseMailbox(configuration.mailboxConfiguration()))
.overrideWith(chooseJmapModule(configuration))
Expand Down Expand Up @@ -229,6 +232,13 @@ private static List<Module> chooseLinagoraServiceDiscovery(LinagoraServicesDisco
return List.of();
}

private static List<Module> chooseOpenPaas(OpenPaasModuleChooserConfiguration moduleChooserConfiguration) {
if (moduleChooserConfiguration.enabled()) {
return List.of(new OpenPaasModule());
}
return List.of();
}

private static Module chooseDropListsModule(MemoryConfiguration configuration) {
if (configuration.dropListEnabled()) {
return Modules.combine(new MemoryDropListsModule(), new DropListsRoutesModule());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.linagora.tmail.james.app;

import static org.apache.james.data.UsersRepositoryModuleChooser.Implementation.DEFAULT;

import org.apache.james.JamesServerBuilder;
import org.apache.james.JamesServerExtension;
import org.apache.james.modules.queue.rabbitmq.RabbitMQModule;
import org.apache.james.utils.GuiceProbe;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import com.google.inject.multibindings.Multibinder;
import com.linagora.tmail.OpenPaasModuleChooserConfiguration;
import com.linagora.tmail.encrypted.MailboxConfiguration;
import com.linagora.tmail.encrypted.MailboxManagerClassProbe;
import com.linagora.tmail.module.LinagoraTestJMAPServerModule;

class MemoryServerWithOpenPaasRabbitMqConfiguredTest {
@RegisterExtension
static JamesServerExtension jamesServerExtension = new JamesServerBuilder<MemoryConfiguration>(tmpDir ->
MemoryConfiguration.builder()
.workingDirectory(tmpDir)
.configurationFromClasspath()
.mailbox(new MailboxConfiguration(false))
.usersRepository(DEFAULT)
.openPaasModuleChooserConfiguration(OpenPaasModuleChooserConfiguration.ENABLED)
.build())
.server(configuration -> MemoryServer.createServer(configuration)
.overrideWith(new LinagoraTestJMAPServerModule())
.overrideWith(binder -> Multibinder.newSetBinder(binder, GuiceProbe.class).addBinding().to(MailboxManagerClassProbe.class))
.overrideWith(new RabbitMQModule()))
.extension(new RabbitMQExtension())
.build();

@Test
public void serverShouldStartWithOpenPaasRabbitMqConfigured() {

}
}
5 changes: 5 additions & 0 deletions tmail-backend/guice/distributed/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@
<groupId>${project.groupId}</groupId>
<artifactId>tmail-event-bus-redis</artifactId>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>tmail-openpaas</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>${james.groupId}</groupId>
<artifactId>apache-james-backends-redis</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static org.apache.james.backends.rabbitmq.RabbitMQFixture.DEFAULT_MANAGEMENT_CREDENTIAL;

import java.net.URI;
import java.net.URISyntaxException;
import java.time.Duration;

Expand All @@ -18,6 +19,8 @@
import com.google.inject.AbstractModule;
import com.google.inject.Provides;
import com.google.inject.multibindings.Multibinder;
import com.linagora.tmail.AmqpUri;
import com.linagora.tmail.configuration.OpenPaasConfiguration;
import com.linagora.tmail.james.jmap.RabbitMQEmailAddressContactConfiguration;

public class TestRabbitMQModule extends AbstractModule {
Expand Down Expand Up @@ -83,6 +86,17 @@ private RabbitMQMailQueueConfiguration getMailQueueSizeConfiguration() {
return RabbitMQMailQueueConfiguration.sizeMetricsEnabled();
}

@Provides
@Singleton
public OpenPaasConfiguration provideOpenPaasConfiguration() throws URISyntaxException {
return new OpenPaasConfiguration(
AmqpUri.from(rabbitMQ.amqpUri()),
URI.create("http://localhost:8081"),
"user",
"password"
);
}

public static class QueueCleanUp implements CleanupTasksPerformer.CleanupTask {
private final RabbitMQMailQueueManagement api;

Expand Down
Loading

0 comments on commit bba278e

Please sign in to comment.