Browse code

[cli] FEATBL-669 Feat: add cli tool to inspect hollow content

Thomas Cataldo authored on 05/12/2018 14:04:59
Showing 10 changed files
... ...
@@ -34,6 +34,7 @@
34 34
       <plugin id="com.google.guava"/>
35 35
       <plugin id="com.hazelcast"/>
36 36
       <plugin id="com.hazelcast.client" fragment="true"/>
37
+      <plugin id="com.netflix.hollow"/>
37 38
       <plugin id="com.netflix.spectator.api"/>
38 39
       <plugin id="com.ning.async-http-client"/>
39 40
       <plugin id="io.airlift.airline"/>
... ...
@@ -56,6 +57,7 @@
56 57
       <plugin id="net.bluemind.cli.cmd.api"/>
57 58
       <plugin id="net.bluemind.cli.contact"/>
58 59
       <plugin id="net.bluemind.cli.directory.common"/>
60
+      <plugin id="net.bluemind.cli.hollow"/>
59 61
       <plugin id="net.bluemind.cli.index"/>
60 62
       <plugin id="net.bluemind.cli.launcher"/>
61 63
       <plugin id="net.bluemind.cli.metrics"/>
... ...
@@ -76,6 +78,8 @@
76 78
       <plugin id="net.bluemind.core.task.spi"/>
77 79
       <plugin id="net.bluemind.dataprotect.api"/>
78 80
       <plugin id="net.bluemind.directory.api"/>
81
+      <plugin id="net.bluemind.directory.hollow.datamodel"/>
82
+      <plugin id="net.bluemind.directory.hollow.datamodel.consumer"/>
79 83
       <plugin id="net.bluemind.domain.api"/>
80 84
       <plugin id="net.bluemind.eclipse.common"/>
81 85
       <plugin id="net.bluemind.group.api"/>
... ...
@@ -95,6 +99,7 @@
95 99
       <plugin id="net.bluemind.neko.common"/>
96 100
       <plugin id="net.bluemind.resource.api"/>
97 101
       <plugin id="net.bluemind.role.api"/>
102
+      <plugin id="net.bluemind.serialization.client"/>
98 103
       <plugin id="net.bluemind.server.api"/>
99 104
       <plugin id="net.bluemind.slf4j"/>
100 105
       <plugin id="net.bluemind.slf4j.configuration" fragment="true"/>
101 106
new file mode 100644
... ...
@@ -0,0 +1,7 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<classpath>
3
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
4
+	<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
5
+	<classpathentry kind="src" path="src"/>
6
+	<classpathentry kind="output" path="bin"/>
7
+</classpath>
0 8
new file mode 100644
... ...
@@ -0,0 +1,28 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<projectDescription>
3
+	<name>net.bluemind.cli.hollow</name>
4
+	<comment></comment>
5
+	<projects>
6
+	</projects>
7
+	<buildSpec>
8
+		<buildCommand>
9
+			<name>org.eclipse.jdt.core.javabuilder</name>
10
+			<arguments>
11
+			</arguments>
12
+		</buildCommand>
13
+		<buildCommand>
14
+			<name>org.eclipse.pde.ManifestBuilder</name>
15
+			<arguments>
16
+			</arguments>
17
+		</buildCommand>
18
+		<buildCommand>
19
+			<name>org.eclipse.pde.SchemaBuilder</name>
20
+			<arguments>
21
+			</arguments>
22
+		</buildCommand>
23
+	</buildSpec>
24
+	<natures>
25
+		<nature>org.eclipse.pde.PluginNature</nature>
26
+		<nature>org.eclipse.jdt.core.javanature</nature>
27
+	</natures>
28
+</projectDescription>
0 29
new file mode 100644
... ...
@@ -0,0 +1,15 @@
1
+Manifest-Version: 1.0
2
+Bundle-ManifestVersion: 2
3
+Bundle-Name: net.bluemind.cli.hollow
4
+Bundle-SymbolicName: net.bluemind.cli.hollow;singleton:=true
5
+Bundle-Version: 4.1.0.qualifier
6
+Bundle-Activator: net.bluemind.cli.hollow.CliHollowActivator
7
+Bundle-Vendor: bluemind.net
8
+Require-Bundle: org.eclipse.core.runtime,
9
+ net.bluemind.cli.cmd.api,
10
+ net.bluemind.directory.hollow.datamodel.consumer;bundle-version="4.1.0",
11
+ net.bluemind.cli.utils;bundle-version="4.1.0",
12
+ com.google.guava
13
+Bundle-RequiredExecutionEnvironment: JavaSE-1.8
14
+Automatic-Module-Name: net.bluemind.cli.hollow
15
+Bundle-ActivationPolicy: lazy
0 16
new file mode 100644
... ...
@@ -0,0 +1,5 @@
1
+source.. = src/
2
+output.. = bin/
3
+bin.includes = META-INF/,\
4
+               .,\
5
+               plugin.xml
0 6
new file mode 100644
... ...
@@ -0,0 +1,11 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<?eclipse version="3.4"?>
3
+<plugin>
4
+   <extension
5
+         point="net.bluemind.cli.cmd.api.cmdlet">
6
+      <registration
7
+            impl="net.bluemind.cli.hollow.DirectoryDumpCommand$Reg">
8
+      </registration>
9
+   </extension>
10
+
11
+</plugin>
0 12
new file mode 100644
... ...
@@ -0,0 +1,11 @@
1
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
2
+  <modelVersion>4.0.0</modelVersion>
3
+  <parent>
4
+    <groupId>net.bluemind</groupId>
5
+    <version>4.1.0-SNAPSHOT</version>
6
+    <artifactId>net.bluemind.directory.plugins</artifactId>
7
+  </parent>
8
+  <artifactId>net.bluemind.cli.hollow</artifactId>
9
+  <packaging>eclipse-plugin</packaging>
10
+  
11
+</project>
0 12
new file mode 100644
... ...
@@ -0,0 +1,30 @@
1
+package net.bluemind.cli.hollow;
2
+
3
+import org.osgi.framework.BundleActivator;
4
+import org.osgi.framework.BundleContext;
5
+
6
+public class CliHollowActivator implements BundleActivator {
7
+
8
+	private static BundleContext context;
9
+
10
+	static BundleContext getContext() {
11
+		return context;
12
+	}
13
+
14
+	/*
15
+	 * (non-Javadoc)
16
+	 * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
17
+	 */
18
+	public void start(BundleContext bundleContext) throws Exception {
19
+		CliHollowActivator.context = bundleContext;
20
+	}
21
+
22
+	/*
23
+	 * (non-Javadoc)
24
+	 * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
25
+	 */
26
+	public void stop(BundleContext bundleContext) throws Exception {
27
+		CliHollowActivator.context = null;
28
+	}
29
+
30
+}
0 31
new file mode 100644
... ...
@@ -0,0 +1,86 @@
1
+/* BEGIN LICENSE
2
+  * Copyright © Blue Mind SAS, 2012-2018
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
+  * This program is distributed in the hope that it will be useful,
12
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14
+  *
15
+  * See LICENSE.txt
16
+  * END LICENSE
17
+  */
18
+package net.bluemind.cli.hollow;
19
+
20
+import java.util.Collection;
21
+import java.util.Optional;
22
+
23
+import com.google.common.base.MoreObjects;
24
+
25
+import io.airlift.airline.Arguments;
26
+import io.airlift.airline.Command;
27
+import net.bluemind.cli.cmd.api.CliContext;
28
+import net.bluemind.cli.cmd.api.ICmdLet;
29
+import net.bluemind.cli.cmd.api.ICmdLetRegistration;
30
+import net.bluemind.cli.utils.CliUtils;
31
+import net.bluemind.core.api.fault.ServerFault;
32
+import net.bluemind.directory.hollow.datamodel.consumer.AddressBookRecord;
33
+import net.bluemind.directory.hollow.datamodel.consumer.DirectorySearchFactory;
34
+import net.bluemind.directory.hollow.datamodel.consumer.SerializedDirectorySearch;
35
+
36
+@Command(name = "directory", description = "List items in hollow directory")
37
+public class DirectoryDumpCommand implements ICmdLet, Runnable {
38
+
39
+	public static class Reg implements ICmdLetRegistration {
40
+
41
+		@Override
42
+		public Optional<String> group() {
43
+			return Optional.of("hollow");
44
+		}
45
+
46
+		@Override
47
+		public Class<? extends ICmdLet> commandClass() {
48
+			return DirectoryDumpCommand.class;
49
+		}
50
+	}
51
+
52
+	private CliContext ctx;
53
+
54
+	@Arguments(required = true, description = "the domain (uid or alias)")
55
+	public String domain;
56
+
57
+	@Override
58
+	public void run() {
59
+		CliUtils cli = new CliUtils(ctx);
60
+		String domUid = cli.getDomainUidFromDomain(domain);
61
+		if (domUid == null) {
62
+			throw new ServerFault("domain " + domain + " not found");
63
+		}
64
+		SerializedDirectorySearch hollow = DirectorySearchFactory.get(domUid);
65
+		Collection<AddressBookRecord> bookItems = hollow.all();
66
+		System.out.println("Hollow directory of '" + domUid + "' has " + bookItems.size() + " item(s).");
67
+		for (AddressBookRecord abr : bookItems) {
68
+			System.out.println(stringify(abr));
69
+		}
70
+	}
71
+
72
+	private String stringify(AddressBookRecord abr) {
73
+		return MoreObjects.toStringHelper("Record")//
74
+				.add("uid", Optional.ofNullable(abr.getUid()).map(v -> v.getValue()).orElse("<uid is missing>"))//
75
+				.add("dn",
76
+						Optional.ofNullable(abr.getDistinguishedName()).map(v -> v.getValue())
77
+								.orElse("<dn is missing>"))//
78
+				.toString();
79
+	}
80
+
81
+	@Override
82
+	public Runnable forContext(CliContext ctx) {
83
+		this.ctx = ctx;
84
+		return this;
85
+	}
86
+}
... ...
@@ -24,6 +24,7 @@
24 24
 		<module>net.bluemind.directory.hollow.datamodel.producer</module>
25 25
 		<module>net.bluemind.directory.hollow.datamodel.producer.tests</module>
26 26
 		<module>net.bluemind.directory.hollow.datamodel.utils</module>
27
+		<module>net.bluemind.cli.hollow</module>
27 28
 	</modules>
28 29
 
29 30
 </project>