Browse code

BM-15555 Fix: wait for smtp server assignments prior to ms probe

Thomas Fricker authored on 10/01/2020 16:05:36
Showing 1 changed files
... ...
@@ -29,11 +29,13 @@ import net.bluemind.backend.cyrus.CyrusService;
29 29
 import net.bluemind.backend.cyrus.replication.link.probe.ReplicationLatencyTimer;
30 30
 import net.bluemind.backend.cyrus.replication.link.probe.SharedMailboxProbe;
31 31
 import net.bluemind.config.InstallationId;
32
+import net.bluemind.core.container.model.ItemValue;
32 33
 import net.bluemind.core.context.SecurityContext;
33 34
 import net.bluemind.core.rest.IServiceProvider;
34 35
 import net.bluemind.core.rest.ServerSideServiceProvider;
35 36
 import net.bluemind.server.api.Assignment;
36 37
 import net.bluemind.server.api.IServer;
38
+import net.bluemind.server.api.Server;
37 39
 
38 40
 public class CyrusServiceVerticle extends Verticle {
39 41
 
... ...
@@ -44,30 +46,40 @@ public class CyrusServiceVerticle extends Verticle {
44 46
 		EventBus eventBus = vertx.eventBus();
45 47
 
46 48
 		eventBus.registerHandler("mailreplica.receiver.ready", message -> {
47
-			IServiceProvider prov = ServerSideServiceProvider.getProvider(SecurityContext.SYSTEM);
48
-			IServer service = prov.instance(IServer.class, InstallationId.getIdentifier());
49
+			probe(0);
50
+		});
51
+	}
49 52
 
50
-			service.allComplete().stream().filter(s -> s.value.tags.contains("mail/imap")).forEach(s -> {
51
-				CyrusService cyrusService = new CyrusService(s.value.address());
52
-				cyrusService.reload();
53
+	private void probe(long id) {
54
+		IServiceProvider prov = ServerSideServiceProvider.getProvider(SecurityContext.SYSTEM);
55
+		IServer service = prov.instance(IServer.class, InstallationId.getIdentifier());
53 56
 
54
-				List<Assignment> assignments = service.getServerAssignments(s.uid).stream()
55
-						.filter(as -> "mail/imap".equals(as.tag)).collect(Collectors.toList());
56
-				for (Assignment domainServerPair : assignments) {
57
-					try {
58
-						SharedMailboxProbe probe = new SharedMailboxProbe.Builder()//
59
-								.forBackend(domainServerPair)//
60
-								.server(s)//
61
-								.provider(prov)//
62
-								.build();
63
-						logger.info("Probe mailbox is {}", probe);
64
-						new ReplicationLatencyTimer(vertx, probe).start();
65
-					} catch (Exception e) {
66
-						logger.error(e.getMessage(), e);
67
-					}
68
-				}
69
-			});
57
+		List<ItemValue<Server>> servers = service.allComplete().stream().filter(s -> s.value.tags.contains("mail/imap"))
58
+				.collect(Collectors.toList());
59
+		if (servers.isEmpty()) {
60
+			vertx.setTimer(60000, this::probe);
61
+			return;
62
+		}
70 63
 
64
+		servers.forEach(s -> {
65
+			CyrusService cyrusService = new CyrusService(s.value.address());
66
+			cyrusService.reload();
67
+
68
+			List<Assignment> assignments = service.getServerAssignments(s.uid).stream()
69
+					.filter(as -> "mail/imap".equals(as.tag)).collect(Collectors.toList());
70
+			for (Assignment domainServerPair : assignments) {
71
+				try {
72
+					SharedMailboxProbe probe = new SharedMailboxProbe.Builder()//
73
+							.forBackend(domainServerPair)//
74
+							.server(s)//
75
+							.provider(prov)//
76
+							.build();
77
+					logger.info("Probe mailbox is {}", probe);
78
+					new ReplicationLatencyTimer(vertx, probe).start();
79
+				} catch (Exception e) {
80
+					logger.error(e.getMessage(), e);
81
+				}
82
+			}
71 83
 		});
72 84
 	}
73 85