Browse code

Feat: directory version monitoring

qvigand authored on 08/06/2018 15:14:30
Showing 8 changed files
... ...
@@ -35,7 +35,8 @@ Require-Bundle: net.bluemind.core.rest,
35 35
  net.bluemind.core.caches.registry,
36 36
  net.bluemind.server.api,
37 37
  net.bluemind.hornetq.client,
38
- net.bluemind.core.task.service
38
+ net.bluemind.core.task.service,
39
+ net.bluemind.metrics.registry
39 40
 Export-Package: net.bluemind.directory.service,
40 41
  net.bluemind.directory.service.internal
41 42
 Bundle-Activator: net.bluemind.directory.service.DirectoryActivator
... ...
@@ -50,5 +50,12 @@
50 50
             implementation="net.bluemind.directory.service.DirDomainValueSanitizer$Factory">
51 51
       </sanitizerfactory>
52 52
    </extension>
53
+      <extension
54
+         point="net.bluemind.lib.vertx.verticles">
55
+      <verticle
56
+            impl="net.bluemind.directory.service.internal.DirectoryVerticle">
57
+      </verticle>
58
+   </extension>
59
+   
53 60
 
54 61
 </plugin>
... ...
@@ -33,7 +33,8 @@ public class DirEventProducer {
33 33
 
34 34
 	}
35 35
 
36
-	public void changed(String uid) {
37
-		eventBus.publish(address, new JsonObject().putString("domain", domainUid).putString("uid", uid));
36
+	public void changed(String uid, long version) {
37
+		eventBus.publish(address, new JsonObject().putString("domain", domainUid).putString("uid", uid)
38
+				.putString("version", Long.toString(version)));
38 39
 	}
39 40
 }
40 41
new file mode 100644
... ...
@@ -0,0 +1,41 @@
0
+package net.bluemind.directory.service.internal;
1
+
2
+import org.apache.commons.lang.StringUtils;
3
+import org.vertx.java.core.Handler;
4
+import org.vertx.java.core.eventbus.Message;
5
+import org.vertx.java.core.json.JsonObject;
6
+import org.vertx.java.platform.Verticle;
7
+
8
+import com.netflix.spectator.api.Registry;
9
+
10
+import net.bluemind.metrics.registry.IdFactory;
11
+import net.bluemind.metrics.registry.MetricsRegistry;
12
+
13
+public class DirectoryVerticle extends Verticle {
14
+	private static final Registry registry = MetricsRegistry.get();
15
+	private static final IdFactory idFactory = new IdFactory(MetricsRegistry.get(), DirectoryVerticle.class);
16
+
17
+	@Override
18
+	public void start() {
19
+		getVertx().eventBus().registerHandler("dir.changed", new Handler<Message<JsonObject>>() {
20
+			@Override
21
+			public void handle(Message<JsonObject> event) {
22
+				String domain = event.body().getString("domain");
23
+				String version = event.body().getString("version");
24
+				if (containsValidVersion(domain, version)) {
25
+					registry.gauge(idFactory.name("dirVersion", "domainUid", domain)).set(Long.parseLong(version));
26
+				}
27
+			}
28
+		});
29
+	}
30
+
31
+	private boolean containsValidVersion(String domain, String version) {
32
+		if (domain == null || domain.equals("")) {
33
+			return false;
34
+		}
35
+		if (!StringUtils.isNumeric(version) || version.equals("")) {
36
+			return false;
37
+		}
38
+		return true;
39
+	}
40
+}
... ...
@@ -78,26 +78,26 @@ public class InCoreDirectory implements IInCoreDirectory {
78 78
 	public void create(String path, DirEntry entry) throws ServerFault {
79 79
 		itemStore.create(path, entry.displayName, entry);
80 80
 		logger.debug("direntry {}:{} created", domainUid, path);
81
-		new DirEventProducer(domainUid, VertxPlatform.eventBus()).changed(entry.entryUid);
81
+		new DirEventProducer(domainUid, VertxPlatform.eventBus()).changed(entry.entryUid, itemStore.getVersion());
82 82
 	}
83 83
 
84 84
 	@Override
85 85
 	public void update(String path, DirEntry entry) throws ServerFault {
86 86
 		itemStore.update(path, entry.displayName, entry);
87 87
 		logger.debug("direntry {}:{} updated", domainUid, path);
88
-		new DirEventProducer(domainUid, VertxPlatform.eventBus()).changed(entry.entryUid);
88
+		new DirEventProducer(domainUid, VertxPlatform.eventBus()).changed(entry.entryUid, itemStore.getVersion());
89 89
 	}
90 90
 
91 91
 	@Override
92 92
 	public void delete(String path) throws ServerFault {
93 93
 		itemStore.delete(path);
94 94
 		logger.debug("direntry {}:{} deleted", domainUid, path);
95
-		new DirEventProducer(domainUid, VertxPlatform.eventBus()).changed(path);
95
+		new DirEventProducer(domainUid, VertxPlatform.eventBus()).changed(path, itemStore.getVersion());
96 96
 	}
97 97
 
98 98
 	@Override
99 99
 	public void updateAccountType(String uid, AccountType accountType) throws ServerFault {
100 100
 		itemStore.updateAccountType(uid, accountType);
101
-		new DirEventProducer(domainUid, VertxPlatform.eventBus()).changed(uid);
101
+		new DirEventProducer(domainUid, VertxPlatform.eventBus()).changed(uid, itemStore.getVersion());
102 102
 	}
103 103
 }
... ...
@@ -99,7 +99,7 @@ public class OrgUnits implements IOrgUnits {
99 99
 		validator.create(value);
100 100
 
101 101
 		storeService.create(uid, value);
102
-		dirEventProducer.changed(uid);
102
+		dirEventProducer.changed(uid, storeService.getVersion());
103 103
 	}
104 104
 
105 105
 	@Override
... ...
@@ -123,7 +123,7 @@ public class OrgUnits implements IOrgUnits {
123 123
 			throw new ServerFault("Parent change is not allowed", ErrorCode.INVALID_PARAMETER);
124 124
 		}
125 125
 		storeService.update(uid, value);
126
-		dirEventProducer.changed(uid);
126
+		dirEventProducer.changed(uid, storeService.getVersion());
127 127
 	}
128 128
 
129 129
 	@Override
... ...
@@ -146,7 +146,7 @@ public class OrgUnits implements IOrgUnits {
146 146
 		}
147 147
 
148 148
 		storeService.delete(uid);
149
-		dirEventProducer.changed(uid);
149
+		dirEventProducer.changed(uid, storeService.getVersion());
150 150
 	}
151 151
 
152 152
 	@Override
... ...
@@ -21,4 +21,5 @@ Require-Bundle: net.bluemind.system.domaintemplate;bundle-version="3.1.0",
21 21
  net.bluemind.core.task.service,
22 22
  net.bluemind.lib.ldap,
23 23
  com.google.guava,
24
- net.bluemind.group.api
24
+ net.bluemind.group.api,
25
+ net.bluemind.metrics.registry
... ...
@@ -42,6 +42,7 @@ import org.slf4j.Logger;
42 42
 import org.slf4j.LoggerFactory;
43 43
 
44 44
 import com.google.common.base.Strings;
45
+import com.netflix.spectator.api.Registry;
45 46
 
46 47
 import net.bluemind.config.InstallationId;
47 48
 import net.bluemind.core.api.fault.ErrorCode;
... ...
@@ -58,6 +59,8 @@ import net.bluemind.domain.api.IDomains;
58 58
 import net.bluemind.group.api.Group;
59 59
 import net.bluemind.group.api.IGroup;
60 60
 import net.bluemind.group.api.Member;
61
+import net.bluemind.metrics.registry.IdFactory;
62
+import net.bluemind.metrics.registry.MetricsRegistry;
61 63
 import net.bluemind.server.api.IServer;
62 64
 import net.bluemind.server.api.Server;
63 65
 import net.bluemind.system.ldap.export.hook.LdapServerHook;
... ...
@@ -72,6 +75,8 @@ import net.bluemind.user.api.User;
72 72
 
73 73
 public class LdapExportService {
74 74
 	private static final Logger logger = LoggerFactory.getLogger(LdapExportService.class);
75
+	private static final Registry registry = MetricsRegistry.get();
76
+	private static final IdFactory idFactory = new IdFactory(MetricsRegistry.get(), LdapExportService.class);
75 77
 
76 78
 	public static LdapExportService build(BmContext context, ItemValue<Server> server, ItemValue<Domain> domain) {
77 79
 		IDirectory dirService = context.provider().instance(IDirectory.class, domain.uid);
... ...
@@ -143,8 +148,8 @@ public class LdapExportService {
143 143
 			}
144 144
 
145 145
 			doSync(ldapCon, changeset);
146
-
147 146
 			setVersion(ldapCon, changeset.version);
147
+			registry.gauge(idFactory.name("dirVersion", "domainUid", domain.uid)).set(changeset.version);
148 148
 		} catch (Exception e) {
149 149
 			logger.error("Fail to update LDAP with changes from {} to {}", lastVersion,
150 150
 					(changeset == null) ? "unknown" : changeset.version);