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