Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create a separate Guice module for OpenPaaS communication #1261

Merged
merged 21 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions tmail-backend/apps/distributed/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@
<groupId>${project.groupId}</groupId>
<artifactId>tmail-mailets</artifactId>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>tmail-openpaas</artifactId>
<version>1.0.0-SNAPSHOT</version>
HoussemNasri marked this conversation as resolved.
Show resolved Hide resolved
HoussemNasri marked this conversation as resolved.
Show resolved Hide resolved
</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 @@ -113,6 +113,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 @@ -340,6 +342,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 @@ -423,6 +426,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,46 @@
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;
import com.linagora.tmail.module.LinagoraTestJMAPServerModule;

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(new LinagoraTestJMAPServerModule())
.overrideWith(binder -> Multibinder.newSetBinder(binder, GuiceProbe.class).addBinding().to(UsersRepositoryClassProbe.class)))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this module override needed?

Copy link
Member Author

@HoussemNasri HoussemNasri Nov 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably not, we don't use jmap in this test. The test passes even after removing the module. It is hard to tell for sure which modules or extensions are needed and which are not.

I removed it.

.extension(new DockerOpenSearchExtension())
.extension(new CassandraExtension())
.extension(new RabbitMQExtension())
.extension(new LdapExtension())
.extension(new RedisExtension())
.lifeCycle(JamesServerExtension.Lifecycle.PER_CLASS)
.build();

@Test
void serverShouldStartWithOpenPaasRabbitMqConfigured() {
}

}
35 changes: 32 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,26 @@
<groupId>${project.groupId}</groupId>
<artifactId>tmail-mailets</artifactId>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>tmail-openpaas</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>tmail-openpaas</artifactId>
<version>1.0.0-SNAPSHOT</version>
<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 +103,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 +168,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 @@ -182,6 +184,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 @@ -227,6 +230,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() {

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