Browse code

Chore: get rid of ununsed imap.notifications topic

Thomas Cataldo authored on 18/06/2019 04:38:37
Showing 8 changed files
... ...
@@ -28,5 +28,5 @@ Require-Bundle: net.bluemind.hsm.storage,
28 28
  net.bluemind.backend.cyrus.partitions,
29 29
  net.bluemind.backend.mail.api
30 30
 Export-Package: net.bluemind.hsm.processor,
31
- net.bluemind.hsm.processor.cleanup,
32 31
  net.bluemind.hsm.processor.commands
32
+Automatic-Module-Name: net.bluemind.hsm.processor
33 33
deleted file mode 100644
... ...
@@ -1,71 +0,0 @@
1
-/* BEGIN LICENSE
2
- * Copyright © Blue Mind SAS, 2012-2016
3
- *
4
- * This file is part of BlueMind. BlueMind is a messaging and collaborative
5
- * solution.
6
- *
7
- * This program is free software; you can redistribute it and/or modify
8
- * it under the terms of either the GNU Affero General Public License as
9
- * published by the Free Software Foundation (version 3 of the License).
10
- *
11
- *
12
- * This program is distributed in the hope that it will be useful,
13
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15
- *
16
- * See LICENSE.txt
17
- * END LICENSE
18
- */
19
-package net.bluemind.hsm.processor.cleanup;
20
-
21
-import java.io.IOException;
22
-
23
-import org.elasticsearch.action.search.SearchResponse;
24
-import org.elasticsearch.client.Client;
25
-import org.elasticsearch.index.query.QueryBuilders;
26
-import org.elasticsearch.search.SearchHit;
27
-import org.elasticsearch.search.SearchHits;
28
-import org.slf4j.Logger;
29
-import org.slf4j.LoggerFactory;
30
-
31
-import net.bluemind.core.api.fault.ServerFault;
32
-import net.bluemind.hsm.processor.HSMContext;
33
-import net.bluemind.lib.elasticsearch.ESearchActivator;
34
-
35
-public class HSMCleanup {
36
-	private static Logger logger = LoggerFactory.getLogger(HSMCleanup.class);
37
-
38
-	public HSMCleanup() {
39
-
40
-	}
41
-
42
-	/**
43
-	 * Removes archive from ES and Storage when archived email is deleted
44
-	 * 
45
-	 * @param context
46
-	 * @param hsmId
47
-	 * @throws ServerFault
48
-	 * @throws IOException
49
-	 */
50
-	public void remove(HSMContext context, String hsmId) throws ServerFault, IOException {
51
-
52
-		Client client = ESearchActivator.getClient();
53
-		client.admin().indices().prepareRefresh("mailspool").execute().actionGet();
54
-
55
-		SearchResponse resp = client.prepareSearch("mailspool").setTypes("msg")
56
-				.setQuery(QueryBuilders.queryStringQuery("headers.x-bm_hsm_id:" + hsmId)).addStoredField("in").execute()
57
-				.actionGet();
58
-		SearchHits hits = resp.getHits();
59
-		if (hits.getTotalHits() != 0) {
60
-			for (SearchHit hit : hits) {
61
-				logger.info("Archive is still referenced in: " + hit.field("in").getValue());
62
-			}
63
-			logger.info(hits.getTotalHits() + " references in tmailspool index. Nothing to do. x-bm_hsm_id: " + hsmId);
64
-			return;
65
-		}
66
-
67
-		logger.info("Delete from snappy store " + hsmId);
68
-		context.getHSMStorage().delete(context.getSecurityContext().getContainerUid(), context.getLoginContext().uid,
69
-				hsmId);
70
-	}
71
-}
... ...
@@ -32,4 +32,5 @@ Require-Bundle: net.bluemind.hsm.api;bundle-version="1.0.0",
32 32
  net.bluemind.backend.mail.replica.indexing;bundle-version="4.1.0"
33 33
 Bundle-Activator: net.bluemind.hsm.service.Activator
34 34
 Bundle-ActivationPolicy: lazy
35
+Automatic-Module-Name: net.bluemind.hsm.service
35 36
 
... ...
@@ -18,38 +18,15 @@
18 18
  */
19 19
 package net.bluemind.hsm.service;
20 20
 
21
-import java.util.Arrays;
22
-import java.util.Collections;
23
-import java.util.UUID;
24
-
25 21
 import org.osgi.framework.BundleActivator;
26 22
 import org.osgi.framework.BundleContext;
27 23
 import org.slf4j.Logger;
28 24
 import org.slf4j.LoggerFactory;
29 25
 
30
-import net.bluemind.config.InstallationId;
31
-import net.bluemind.core.container.model.ItemValue;
32
-import net.bluemind.core.context.SecurityContext;
33
-import net.bluemind.core.rest.ServerSideServiceProvider;
34
-import net.bluemind.core.sessions.Sessions;
35
-import net.bluemind.hornetq.client.MQ;
36
-import net.bluemind.hornetq.client.MQ.IMQConnectHandler;
37
-import net.bluemind.hornetq.client.OOPMessage;
38
-import net.bluemind.hornetq.client.OutOfProcessMessageHandler;
39
-import net.bluemind.hornetq.client.Topic;
40
-import net.bluemind.hsm.processor.HSMContext;
41
-import net.bluemind.hsm.processor.HSMContext.HSMLoginContext;
42
-import net.bluemind.hsm.processor.cleanup.HSMCleanup;
43
-import net.bluemind.server.api.IServer;
44
-import net.bluemind.server.api.Server;
45
-import net.bluemind.user.api.IUser;
46
-import net.bluemind.user.api.User;
47
-
48 26
 public class Activator implements BundleActivator {
49 27
 
50 28
 	private Logger logger = LoggerFactory.getLogger(Activator.class);
51 29
 	private static BundleContext context;
52
-	private HSMCleanup hsmCleanup;
53 30
 
54 31
 	static BundleContext getContext() {
55 32
 		return context;
... ...
@@ -58,20 +35,7 @@ public class Activator implements BundleActivator {
58 35
 	@Override
59 36
 	public void start(BundleContext context) throws Exception {
60 37
 		Activator.context = context;
61
-
62
-		hsmCleanup = new HSMCleanup();
63
-
64
-		MQ.init(new IMQConnectHandler() {
65
-
66
-			@Override
67
-			public void connected() {
68
-				MQ.registerConsumer(Topic.IMAP_NOTIFICATIONS, js -> {
69
-					return "checkhsm".equals(js.getString("operation"));
70
-				}, getConsumer());
71
-			}
72
-
73
-		});
74
-
38
+		logger.debug("Bundle started {}", context);
75 39
 	}
76 40
 
77 41
 	@Override
... ...
@@ -79,50 +43,4 @@ public class Activator implements BundleActivator {
79 43
 		Activator.context = null;
80 44
 
81 45
 	}
82
-
83
-	private OutOfProcessMessageHandler getConsumer() {
84
-		return new OutOfProcessMessageHandler() {
85
-
86
-			@Override
87
-			public void handle(OOPMessage msg) {
88
-				String login = msg.getStringProperty("latd");
89
-				String hsmIdsAsString = msg.getStringProperty("arguments");
90
-				logger.debug("check HSM for deletion for {} of '{}'", login, hsmIdsAsString);
91
-				String[] hsmIds = hsmIdsAsString.split(",");
92
-
93
-				String domain = login.split("@")[1];
94
-
95
-				SecurityContext userContext = null;
96
-				try {
97
-					ItemValue<User> user = ServerSideServiceProvider.getProvider(SecurityContext.SYSTEM)
98
-							.instance(IUser.class, domain).byLogin(login.split("@")[0]);
99
-
100
-					ItemValue<Server> server = ServerSideServiceProvider.getProvider(SecurityContext.SYSTEM)
101
-							.instance(IServer.class, InstallationId.getIdentifier())
102
-							.getComplete(user.value.dataLocation);
103
-					userContext = new SecurityContext(UUID.randomUUID().toString(), user.uid, Arrays.<String>asList(),
104
-							Arrays.<String>asList(), Collections.emptyMap(), domain, "en", "hsmService.activator");
105
-					Sessions.get().put(userContext.getSessionId(), userContext);
106
-
107
-					HSMContext context = HSMContext.get(userContext,
108
-							new HSMLoginContext(user.value.login, user.uid, server.value.address()));
109
-					for (String hsmId : hsmIds) {
110
-						try {
111
-							hsmCleanup.remove(context, hsmId);
112
-						} catch (Exception e) {
113
-							logger.error("error during deferencing of archive mail {}", hsmId, e);
114
-						}
115
-					}
116
-
117
-				} catch (Exception e1) {
118
-					logger.error("Fail to check HSM for deletion for {}, of '{}'", login, hsmIdsAsString);
119
-				} finally {
120
-					if (userContext != null) {
121
-						Sessions.get().invalidate(userContext.getSessionId());
122
-					}
123
-				}
124
-
125
-			}
126
-		};
127
-	}
128 46
 }
... ...
@@ -28,7 +28,6 @@ import org.slf4j.LoggerFactory;
28 28
 
29 29
 import net.bluemind.backend.mail.replica.indexing.IMailIndexService;
30 30
 import net.bluemind.eclipse.common.RunnableExtensionLoader;
31
-import net.bluemind.index.mail.MQSetup;
32 31
 import net.bluemind.index.mail.MailIndexService;
33 32
 import net.bluemind.lib.elasticsearch.ESearchActivator;
34 33
 import net.bluemind.mailindex.hook.IIndexSelectionPolicy;
... ...
@@ -53,7 +52,8 @@ public class MailIndexActivator implements BundleActivator {
53 52
 
54 53
 		RunnableExtensionLoader<IIndexSelectionPolicy> rel = new RunnableExtensionLoader<>();
55 54
 
56
-		List<IIndexSelectionPolicy> hooks = rel.loadExtensionsWithPriority("net.bluemind.mailindex", "hook", "hook", "impl");
55
+		List<IIndexSelectionPolicy> hooks = rel.loadExtensionsWithPriority("net.bluemind.mailindex", "hook", "hook",
56
+				"impl");
57 57
 		if (!hooks.isEmpty()) {
58 58
 			MailIndexActivator.mailIndexHook = hooks.get(0);
59 59
 		}
... ...
@@ -61,7 +61,6 @@ public class MailIndexActivator implements BundleActivator {
61 61
 	}
62 62
 
63 63
 	private static void init() {
64
-		MQSetup.init();
65 64
 		MailIndexActivator.mailIndexService = new MailIndexService();
66 65
 	}
67 66
 
68 67
deleted file mode 100644
... ...
@@ -1,48 +0,0 @@
1
-/* BEGIN LICENSE
2
- * Copyright © Blue Mind SAS, 2012-2016
3
- *
4
- * This file is part of BlueMind. BlueMind is a messaging and collaborative
5
- * solution.
6
- *
7
- * This program is free software; you can redistribute it and/or modify
8
- * it under the terms of either the GNU Affero General Public License as
9
- * published by the Free Software Foundation (version 3 of the License).
10
- *
11
- *
12
- * This program is distributed in the hope that it will be useful,
13
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15
- *
16
- * See LICENSE.txt
17
- * END LICENSE
18
- */
19
-package net.bluemind.index.mail;
20
-
21
-import org.slf4j.Logger;
22
-import org.slf4j.LoggerFactory;
23
-
24
-import net.bluemind.hornetq.client.MQ;
25
-import net.bluemind.hornetq.client.MQ.IMQConnectHandler;
26
-import net.bluemind.hornetq.client.Producer;
27
-import net.bluemind.hornetq.client.Topic;
28
-
29
-public class MQSetup {
30
-
31
-	private static final Logger logger = LoggerFactory.getLogger(MQSetup.class);
32
-
33
-	public static void init() {
34
-		MQ.init(new IMQConnectHandler() {
35
-
36
-			@Override
37
-			public void connected() {
38
-				MQ.registerProducer(Topic.IMAP_NOTIFICATIONS);
39
-				logger.info("MQ setup complete.");
40
-			}
41
-		});
42
-	}
43
-
44
-	public static Producer getProducer() {
45
-		return MQ.getProducer(Topic.IMAP_NOTIFICATIONS);
46
-	}
47
-
48
-}
... ...
@@ -17,3 +17,4 @@ Require-Bundle: org.eclipse.core.runtime,
17 17
 Bundle-RequiredExecutionEnvironment: JavaSE-1.8
18 18
 Export-Package: net.bluemind.hornetq.client,
19 19
  net.bluemind.hornetq.client.vertx
20
+Automatic-Module-Name: net.bluemind.hornetq.client
... ...
@@ -24,7 +24,6 @@ package net.bluemind.hornetq.client;
24 24
  */
25 25
 public final class Topic {
26 26
 
27
-	public static final String IMAP_NOTIFICATIONS = "bm.imap.notifications";
28 27
 	public static final String CONTACT_NOTIFICATIONS = "bm.contact.notifications";
29 28
 	public static final String CALENDAR_NOTIFICATIONS = "bm.calendar.notifications";
30 29
 	public static final String DIRECTORY_NOTIFICATIONS = "bm.directory.notifications";