You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@unomi.apache.org by sh...@apache.org on 2018/02/17 17:07:13 UTC

incubator-unomi git commit: UNOMI-165 Tool for developers : shell commands to view/manipulate internal objects

Repository: incubator-unomi
Updated Branches:
  refs/heads/master b194d7a53 -> cef61f34c


UNOMI-165 Tool for developers : shell commands to view/manipulate internal objects


Project: http://git-wip-us.apache.org/repos/asf/incubator-unomi/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-unomi/commit/cef61f34
Tree: http://git-wip-us.apache.org/repos/asf/incubator-unomi/tree/cef61f34
Diff: http://git-wip-us.apache.org/repos/asf/incubator-unomi/diff/cef61f34

Branch: refs/heads/master
Commit: cef61f34c02cc9a06120e0a85884e5aa4ef4699b
Parents: b194d7a
Author: Serge Huber <sh...@apache.org>
Authored: Sat Feb 17 18:07:10 2018 +0100
Committer: Serge Huber <sh...@apache.org>
Committed: Sat Feb 17 18:07:10 2018 +0100

----------------------------------------------------------------------
 kar/pom.xml                                     |   5 +
 kar/src/main/feature/feature.xml                |   1 +
 tools/pom.xml                                   |   1 +
 tools/shell-commands/pom.xml                    |  25 ----
 .../resources/OSGI-INF/blueprint/blueprint.xml  |   1 +
 tools/shell-dev-commands/pom.xml                | 117 ++++++++++++++++++
 .../unomi/shell/commands/ActionListCommand.java |  90 ++++++++++++++
 .../unomi/shell/commands/ActionViewCommand.java |  50 ++++++++
 .../unomi/shell/commands/RuleListCommand.java   | 118 +++++++++++++++++++
 .../shell/commands/RuleResetStatsCommand.java   |  37 ++++++
 .../unomi/shell/commands/RuleViewcommand.java   |  49 ++++++++
 .../shell/commands/SegmentListCommand.java      |  88 ++++++++++++++
 .../shell/commands/SegmentViewCommand.java      |  50 ++++++++
 .../resources/OSGI-INF/blueprint/blueprint.xml  |  77 ++++++++++++
 14 files changed, 684 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/cef61f34/kar/pom.xml
----------------------------------------------------------------------
diff --git a/kar/pom.xml b/kar/pom.xml
index 39d6316..5f2295f 100644
--- a/kar/pom.xml
+++ b/kar/pom.xml
@@ -117,6 +117,11 @@
             <version>1.3.0-incubating-SNAPSHOT</version>
         </dependency>
         <dependency>
+            <groupId>org.apache.unomi</groupId>
+            <artifactId>shell-dev-commands</artifactId>
+            <version>1.3.0-incubating-SNAPSHOT</version>
+        </dependency>
+        <dependency>
             <groupId>org.apache.servicemix.bundles</groupId>
             <artifactId>org.apache.servicemix.bundles.jakarta-regexp</artifactId>
         </dependency>

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/cef61f34/kar/src/main/feature/feature.xml
----------------------------------------------------------------------
diff --git a/kar/src/main/feature/feature.xml b/kar/src/main/feature/feature.xml
index 9c49c1c..d48e0c5 100644
--- a/kar/src/main/feature/feature.xml
+++ b/kar/src/main/feature/feature.xml
@@ -61,6 +61,7 @@
         <bundle start-level="85" start="false">mvn:org.apache.unomi/unomi-plugins-mail/${project.version}</bundle>
         <bundle start-level="85" start="false">mvn:org.apache.unomi/unomi-plugins-optimization-test/${project.version}</bundle>
         <bundle start-level="85" start="false">mvn:org.apache.unomi/cxs-lists-extension-actions/${project.version}</bundle>
+        <bundle start-level="85" start="false">mvn:org.apache.unomi/shell-dev-commands/${project.version}</bundle>
 
         <bundle start-level="99">mvn:org.apache.unomi/shell-commands/${project.version}</bundle>
     </feature>

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/cef61f34/tools/pom.xml
----------------------------------------------------------------------
diff --git a/tools/pom.xml b/tools/pom.xml
index 207e63a..494c64d 100644
--- a/tools/pom.xml
+++ b/tools/pom.xml
@@ -31,6 +31,7 @@
 
     <modules>
         <module>shell-commands</module>
+        <module>shell-dev-commands</module>
     </modules>
 
 </project>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/cef61f34/tools/shell-commands/pom.xml
----------------------------------------------------------------------
diff --git a/tools/shell-commands/pom.xml b/tools/shell-commands/pom.xml
index 13e5add..57fd11b 100644
--- a/tools/shell-commands/pom.xml
+++ b/tools/shell-commands/pom.xml
@@ -75,29 +75,4 @@
         </dependency>
     </dependencies>
 
-    <build>
-        <plugins>
-            <plugin>
-                <groupId>org.apache.felix</groupId>
-                <artifactId>maven-bundle-plugin</artifactId>
-                <extensions>true</extensions>
-                <configuration>
-                    <instructions>
-                        <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
-                        <Export-Package>org.apache.unomi*;version="${project.version}"</Export-Package>
-                        <Import-Package>!org.apache.unomi*,
-                            org.apache.aries.blueprint,
-                            org.osgi.service.blueprint.container,
-                            org.osgi.service.blueprint.reflect,
-                            org.apache.felix.service.command,
-                            org.apache.karaf.shell.commands,
-                            org.apache.karaf.shell.console,
-                            *
-                        </Import-Package>
-                    </instructions>
-                </configuration>
-            </plugin>
-        </plugins>
-    </build>
-
 </project>

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/cef61f34/tools/shell-commands/src/main/resources/OSGI-INF/blueprint/blueprint.xml
----------------------------------------------------------------------
diff --git a/tools/shell-commands/src/main/resources/OSGI-INF/blueprint/blueprint.xml b/tools/shell-commands/src/main/resources/OSGI-INF/blueprint/blueprint.xml
index 60018d9..a7aa6ce 100644
--- a/tools/shell-commands/src/main/resources/OSGI-INF/blueprint/blueprint.xml
+++ b/tools/shell-commands/src/main/resources/OSGI-INF/blueprint/blueprint.xml
@@ -78,6 +78,7 @@
                 <value>org.apache.unomi.router-core</value>
                 <value>org.apache.unomi.router-service</value>
                 <value>org.apache.unomi.router-rest</value>
+                <value>org.apache.unomi.shell-dev-commands</value>
             </list>
         </property>
         <property name="bundleContext" ref="blueprintBundleContext"/>

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/cef61f34/tools/shell-dev-commands/pom.xml
----------------------------------------------------------------------
diff --git a/tools/shell-dev-commands/pom.xml b/tools/shell-dev-commands/pom.xml
new file mode 100644
index 0000000..533758f
--- /dev/null
+++ b/tools/shell-dev-commands/pom.xml
@@ -0,0 +1,117 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    Licensed to the Apache Software Foundation (ASF) under one or more
+    contributor license agreements.  See the NOTICE file distributed with
+    this work for additional information regarding copyright ownership.
+    The ASF licenses this file to You under the Apache License, Version 2.0
+    (the "License"); you may not use this file except in compliance with
+    the License.  You may obtain a copy of the License at
+
+        http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+-->
+<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">
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <artifactId>unomi-tools</artifactId>
+        <groupId>org.apache.unomi</groupId>
+        <version>1.3.0-incubating-SNAPSHOT</version>
+    </parent>
+
+    <artifactId>shell-dev-commands</artifactId>
+    <name>Apache Unomi :: Tools :: Shell Dev commands</name>
+    <description>Provides the shell developer commands to interact with Apache Unomi Context Server</description>
+    <packaging>bundle</packaging>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.karaf.shell</groupId>
+            <artifactId>org.apache.karaf.shell.console</artifactId>
+            <version>3.0.8</version>
+            <scope>provided</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.karaf.shell</groupId>
+            <artifactId>org.apache.karaf.shell.table</artifactId>
+            <version>3.0.8</version>
+            <scope>provided</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.unomi</groupId>
+            <artifactId>unomi-api</artifactId>
+            <version>1.3.0-incubating-SNAPSHOT</version>
+            <scope>provided</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>com.fasterxml.jackson.core</groupId>
+            <artifactId>jackson-core</artifactId>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>com.fasterxml.jackson.core</groupId>
+            <artifactId>jackson-databind</artifactId>
+            <scope>provided</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.unomi</groupId>
+            <artifactId>unomi-persistence-spi</artifactId>
+            <version>1.3.0-incubating-SNAPSHOT</version>
+            <scope>provided</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.httpcomponents</groupId>
+            <artifactId>httpclient-osgi</artifactId>
+            <type>bundle</type>
+            <scope>provided</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.commons</groupId>
+            <artifactId>commons-lang3</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>org.json</groupId>
+            <artifactId>json</artifactId>
+            <version>20160212</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.core</artifactId>
+            <scope>provided</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.compendium</artifactId>
+            <scope>provided</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.unomi</groupId>
+            <artifactId>unomi-common</artifactId>
+            <version>1.3.0-incubating-SNAPSHOT</version>
+            <scope>provided</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <version>4.11</version>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
+
+</project>

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/cef61f34/tools/shell-dev-commands/src/main/java/org/apache/unomi/shell/commands/ActionListCommand.java
----------------------------------------------------------------------
diff --git a/tools/shell-dev-commands/src/main/java/org/apache/unomi/shell/commands/ActionListCommand.java b/tools/shell-dev-commands/src/main/java/org/apache/unomi/shell/commands/ActionListCommand.java
new file mode 100644
index 0000000..fa20217
--- /dev/null
+++ b/tools/shell-dev-commands/src/main/java/org/apache/unomi/shell/commands/ActionListCommand.java
@@ -0,0 +1,90 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.unomi.shell.commands;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.karaf.shell.commands.Command;
+import org.apache.karaf.shell.commands.Option;
+import org.apache.karaf.shell.console.OsgiCommandSupport;
+import org.apache.karaf.shell.table.Row;
+import org.apache.karaf.shell.table.ShellTable;
+import org.apache.unomi.api.actions.ActionType;
+import org.apache.unomi.api.services.DefinitionsService;
+import org.apache.unomi.common.DataTable;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+@Command(scope = "action", name = "list", description = "This will list all the actions deployed in the Apache Unomi Context Server")
+public class ActionListCommand extends OsgiCommandSupport{
+
+    DefinitionsService definitionsService;
+
+    public void setDefinitionsService(DefinitionsService definitionsService) {
+        this.definitionsService = definitionsService;
+    }
+
+    @Option(name = "--no-format", description = "Disable table rendered output", required = false, multiValued = false)
+    boolean noFormat;
+
+    @Option(name = "--csv", description = "Output table in CSV format", required = false, multiValued = false)
+    boolean csv;
+
+    @Override
+    protected Object doExecute() throws Exception {
+        Collection<ActionType> allActions = definitionsService.getAllActionTypes();
+
+        String[] headers = {
+                "Id",
+                "Name",
+                "System tags"
+        };
+
+        DataTable dataTable = new DataTable();
+
+        for (ActionType actionType : allActions) {
+            ArrayList<Object> rowData = new ArrayList<Object>();
+            rowData.add(actionType.getItemId());
+            rowData.add(actionType.getMetadata().getName());
+            rowData.add(StringUtils.join(actionType.getMetadata().getSystemTags(), ","));
+            dataTable.addRow(rowData.toArray(new Comparable[rowData.size()]));
+        }
+
+        dataTable.sort(new DataTable.SortCriteria(2, DataTable.SortOrder.ASCENDING));
+
+        if (csv) {
+            System.out.println(dataTable.toCSV(headers));
+            return null;
+        }
+
+        ShellTable shellTable = new ShellTable();
+        for (String header : headers) {
+            shellTable.column(header);
+        }
+        for (DataTable.Row dataTableRow : dataTable.getRows()) {
+            ArrayList<Object> rowData = new ArrayList<Object>();
+            for (int i=0 ; i < dataTable.getMaxColumns(); i++) {
+                rowData.add(dataTableRow.getData(i));
+            }
+            Row row = shellTable.addRow();
+            row.addContent(rowData);
+        }
+
+        shellTable.print(System.out, !noFormat);
+        return null;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/cef61f34/tools/shell-dev-commands/src/main/java/org/apache/unomi/shell/commands/ActionViewCommand.java
----------------------------------------------------------------------
diff --git a/tools/shell-dev-commands/src/main/java/org/apache/unomi/shell/commands/ActionViewCommand.java b/tools/shell-dev-commands/src/main/java/org/apache/unomi/shell/commands/ActionViewCommand.java
new file mode 100644
index 0000000..6cfad94
--- /dev/null
+++ b/tools/shell-dev-commands/src/main/java/org/apache/unomi/shell/commands/ActionViewCommand.java
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.unomi.shell.commands;
+
+import org.apache.karaf.shell.commands.Argument;
+import org.apache.karaf.shell.commands.Command;
+import org.apache.karaf.shell.console.OsgiCommandSupport;
+import org.apache.unomi.api.actions.ActionType;
+import org.apache.unomi.api.services.DefinitionsService;
+import org.apache.unomi.persistence.spi.CustomObjectMapper;
+
+@Command(scope = "action", name = "view", description = "This will display a single action deployed in the Apache Unomi Context Server")
+public class ActionViewCommand extends OsgiCommandSupport {
+
+    DefinitionsService definitionsService;
+
+    @Argument(index = 0, name = "actionId", description = "The identifier for the action", required = true, multiValued = false)
+    String actionTypeIdentifier;
+
+
+    public void setDefinitionsService(DefinitionsService definitionsService) {
+        this.definitionsService = definitionsService;
+    }
+
+    @Override
+    protected Object doExecute() throws Exception {
+        ActionType actionType = definitionsService.getActionType(actionTypeIdentifier);
+        if (actionType == null) {
+            System.out.println("Couldn't find an action with id=" + actionTypeIdentifier);
+            return null;
+        }
+        String jsonRule = CustomObjectMapper.getObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(actionType);
+        System.out.println(jsonRule);
+        return null;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/cef61f34/tools/shell-dev-commands/src/main/java/org/apache/unomi/shell/commands/RuleListCommand.java
----------------------------------------------------------------------
diff --git a/tools/shell-dev-commands/src/main/java/org/apache/unomi/shell/commands/RuleListCommand.java b/tools/shell-dev-commands/src/main/java/org/apache/unomi/shell/commands/RuleListCommand.java
new file mode 100644
index 0000000..e48df18
--- /dev/null
+++ b/tools/shell-dev-commands/src/main/java/org/apache/unomi/shell/commands/RuleListCommand.java
@@ -0,0 +1,118 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.unomi.shell.commands;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.karaf.shell.commands.Command;
+import org.apache.karaf.shell.commands.Option;
+import org.apache.karaf.shell.console.OsgiCommandSupport;
+import org.apache.karaf.shell.table.Row;
+import org.apache.karaf.shell.table.ShellTable;
+import org.apache.unomi.api.Metadata;
+import org.apache.unomi.api.rules.RuleStatistics;
+import org.apache.unomi.api.services.RulesService;
+import org.apache.unomi.common.DataTable;
+
+import java.util.ArrayList;
+import java.util.Map;
+import java.util.Set;
+
+@Command(scope = "rule", name = "list", description = "This will list all the rules deployed in the Apache Unomi Context Server")
+public class RuleListCommand extends OsgiCommandSupport {
+
+    RulesService rulesService;
+
+    @Option(name = "--no-format", description = "Disable table rendered output", required = false, multiValued = false)
+    boolean noFormat;
+
+    @Option(name = "--csv", description = "Output table in CSV format", required = false, multiValued = false)
+    boolean csv;
+
+    public void setRulesService(RulesService rulesService) {
+        this.rulesService = rulesService;
+    }
+
+    @Override
+    protected Object doExecute() throws Exception {
+        Set<Metadata> ruleMetadatas = rulesService.getRuleMetadatas();
+        Map<String,RuleStatistics> allRuleStatistics = rulesService.getAllRuleStatistics();
+
+        String[] headers = {
+                "Activated",
+                "Hidden",
+                "Read-only",
+                "Identifier",
+                "Scope",
+                "Name",
+                "Tags",
+                "System tags",
+                "Executions",
+                "Conditions [ms]",
+                "Actions [ms]"
+        };
+
+        DataTable dataTable = new DataTable();
+        for (Metadata ruleMetadata : ruleMetadatas) {
+            ArrayList<Comparable> rowData = new ArrayList<Comparable>();
+            String ruleId = ruleMetadata.getId();
+            rowData.add(ruleMetadata.isEnabled() ? "x" : "");
+            rowData.add(ruleMetadata.isHidden() ? "x" : "");
+            rowData.add(ruleMetadata.isReadOnly() ? "x" : "");
+            rowData.add(ruleId);
+            rowData.add(ruleMetadata.getScope());
+            rowData.add(ruleMetadata.getName());
+            rowData.add(StringUtils.join(ruleMetadata.getTags(), ","));
+            rowData.add(StringUtils.join(ruleMetadata.getSystemTags(), ","));
+            RuleStatistics ruleStatistics = allRuleStatistics.get(ruleId);
+            if (ruleStatistics != null) {
+                rowData.add(ruleStatistics.getExecutionCount());
+                rowData.add(ruleStatistics.getConditionsTime());
+                rowData.add(ruleStatistics.getActionsTime());
+            } else {
+                rowData.add(0L);
+                rowData.add(0L);
+                rowData.add(0L);
+            }
+            dataTable.addRow(rowData.toArray(new Comparable[rowData.size()]));
+        }
+        dataTable.sort(new DataTable.SortCriteria(9, DataTable.SortOrder.DESCENDING),
+                new DataTable.SortCriteria(10, DataTable.SortOrder.DESCENDING),
+                new DataTable.SortCriteria(5, DataTable.SortOrder.ASCENDING));
+
+        if (csv) {
+            System.out.println(dataTable.toCSV(headers));
+            return null;
+        }
+
+        ShellTable shellTable = new ShellTable();
+        for (String header : headers) {
+            shellTable.column(header);
+        }
+        for (DataTable.Row dataTableRow : dataTable.getRows()) {
+            ArrayList<Object> rowData = new ArrayList<Object>();
+            for (int i=0 ; i < dataTable.getMaxColumns(); i++) {
+                rowData.add(dataTableRow.getData(i));
+            }
+            Row row = shellTable.addRow();
+            row.addContent(rowData);
+        }
+
+        shellTable.print(System.out, !noFormat);
+
+        return null;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/cef61f34/tools/shell-dev-commands/src/main/java/org/apache/unomi/shell/commands/RuleResetStatsCommand.java
----------------------------------------------------------------------
diff --git a/tools/shell-dev-commands/src/main/java/org/apache/unomi/shell/commands/RuleResetStatsCommand.java b/tools/shell-dev-commands/src/main/java/org/apache/unomi/shell/commands/RuleResetStatsCommand.java
new file mode 100644
index 0000000..4ee6db0
--- /dev/null
+++ b/tools/shell-dev-commands/src/main/java/org/apache/unomi/shell/commands/RuleResetStatsCommand.java
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.unomi.shell.commands;
+
+import org.apache.karaf.shell.commands.Command;
+import org.apache.karaf.shell.console.OsgiCommandSupport;
+import org.apache.unomi.api.services.RulesService;
+
+@Command(scope = "rule", name = "reset-stats", description = "This command will reset the rule statistics")
+public class RuleResetStatsCommand extends OsgiCommandSupport {
+
+    RulesService rulesService;
+    public void setRulesService(RulesService rulesService) {
+        this.rulesService = rulesService;
+    }
+
+    @Override
+    protected Object doExecute() throws Exception {
+        rulesService.resetAllRuleStatistics();
+        System.out.println("Rule statistics successfully reset.");
+        return null;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/cef61f34/tools/shell-dev-commands/src/main/java/org/apache/unomi/shell/commands/RuleViewcommand.java
----------------------------------------------------------------------
diff --git a/tools/shell-dev-commands/src/main/java/org/apache/unomi/shell/commands/RuleViewcommand.java b/tools/shell-dev-commands/src/main/java/org/apache/unomi/shell/commands/RuleViewcommand.java
new file mode 100644
index 0000000..2379230
--- /dev/null
+++ b/tools/shell-dev-commands/src/main/java/org/apache/unomi/shell/commands/RuleViewcommand.java
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.unomi.shell.commands;
+
+import org.apache.karaf.shell.commands.Argument;
+import org.apache.karaf.shell.commands.Command;
+import org.apache.karaf.shell.console.OsgiCommandSupport;
+import org.apache.unomi.api.rules.Rule;
+import org.apache.unomi.api.services.RulesService;
+import org.apache.unomi.persistence.spi.CustomObjectMapper;
+
+@Command(scope = "rule", name = "view", description = "This will allows to view a rule in the Apache Unomi Context Server")
+public class RuleViewcommand extends OsgiCommandSupport {
+
+    RulesService rulesService;
+
+    @Argument(index = 0, name = "rule", description = "The identifier for the rule", required = true, multiValued = false)
+    String ruleIdentifier;
+
+    public void setRulesService(RulesService rulesService) {
+        this.rulesService = rulesService;
+    }
+
+    @Override
+    protected Object doExecute() throws Exception {
+        Rule rule = rulesService.getRule(ruleIdentifier);
+        if (rule == null) {
+            System.out.println("Couldn't find a rule with id=" + ruleIdentifier);
+            return null;
+        }
+        String jsonRule = CustomObjectMapper.getObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(rule);
+        System.out.println(jsonRule);
+        return null;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/cef61f34/tools/shell-dev-commands/src/main/java/org/apache/unomi/shell/commands/SegmentListCommand.java
----------------------------------------------------------------------
diff --git a/tools/shell-dev-commands/src/main/java/org/apache/unomi/shell/commands/SegmentListCommand.java b/tools/shell-dev-commands/src/main/java/org/apache/unomi/shell/commands/SegmentListCommand.java
new file mode 100644
index 0000000..c30360f
--- /dev/null
+++ b/tools/shell-dev-commands/src/main/java/org/apache/unomi/shell/commands/SegmentListCommand.java
@@ -0,0 +1,88 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.unomi.shell.commands;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.karaf.shell.commands.Command;
+import org.apache.karaf.shell.commands.Option;
+import org.apache.karaf.shell.console.OsgiCommandSupport;
+import org.apache.karaf.shell.table.Row;
+import org.apache.karaf.shell.table.ShellTable;
+import org.apache.unomi.api.Metadata;
+import org.apache.unomi.api.PartialList;
+import org.apache.unomi.api.services.SegmentService;
+import org.apache.unomi.common.DataTable;
+
+import java.util.ArrayList;
+
+@Command(scope = "segment", name = "list", description = "This will list all the segments present in the Apache Unomi Context Server")
+public class SegmentListCommand extends OsgiCommandSupport {
+
+    private SegmentService segmentService;
+
+    public void setSegmentService(SegmentService segmentService) {
+        this.segmentService = segmentService;
+    }
+
+    @Option(name = "--no-format", description = "Disable table rendered output", required = false, multiValued = false)
+    boolean noFormat;
+
+    @Option(name = "--csv", description = "Output table in CSV format", required = false, multiValued = false)
+    boolean csv;
+
+    @Override
+    protected Object doExecute() throws Exception {
+        PartialList<Metadata> segmentMetadatas = segmentService.getSegmentMetadatas(0, -1, null);
+
+        String[] headers = {
+                "Enabled",
+                "Hidden",
+                "Id",
+                "Scope",
+                "Name",
+                "System tags"
+        };
+
+        DataTable dataTable = new DataTable();
+        for (Metadata metadata : segmentMetadatas.getList()) {
+            ArrayList<Object> rowData = new ArrayList<Object>();
+            rowData.add(metadata.isEnabled() ? "x" : "");
+            rowData.add(metadata.isHidden() ? "x" : "");
+            rowData.add(metadata.getId());
+            rowData.add(metadata.getScope());
+            rowData.add(metadata.getName());
+            rowData.add(StringUtils.join(metadata.getSystemTags(), ","));
+            dataTable.addRow(rowData.toArray(new Comparable[rowData.size()]));
+        }
+
+        ShellTable shellTable = new ShellTable();
+        for (String header : headers) {
+            shellTable.column(header);
+        }
+        for (DataTable.Row dataTableRow : dataTable.getRows()) {
+            ArrayList<Object> rowData = new ArrayList<Object>();
+            for (int i=0 ; i < dataTable.getMaxColumns(); i++) {
+                rowData.add(dataTableRow.getData(i));
+            }
+            Row row = shellTable.addRow();
+            row.addContent(rowData);
+        }
+        shellTable.print(System.out, !noFormat);
+
+        return null;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/cef61f34/tools/shell-dev-commands/src/main/java/org/apache/unomi/shell/commands/SegmentViewCommand.java
----------------------------------------------------------------------
diff --git a/tools/shell-dev-commands/src/main/java/org/apache/unomi/shell/commands/SegmentViewCommand.java b/tools/shell-dev-commands/src/main/java/org/apache/unomi/shell/commands/SegmentViewCommand.java
new file mode 100644
index 0000000..ed448e4
--- /dev/null
+++ b/tools/shell-dev-commands/src/main/java/org/apache/unomi/shell/commands/SegmentViewCommand.java
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.unomi.shell.commands;
+
+import org.apache.karaf.shell.commands.Argument;
+import org.apache.karaf.shell.commands.Command;
+import org.apache.karaf.shell.console.OsgiCommandSupport;
+import org.apache.unomi.api.segments.Segment;
+import org.apache.unomi.api.services.SegmentService;
+import org.apache.unomi.persistence.spi.CustomObjectMapper;
+
+@Command(scope = "segment", name = "view", description = "This will allows to view a segment in the Apache Unomi Context Server")
+public class SegmentViewCommand extends OsgiCommandSupport {
+
+    private SegmentService segmentService;
+
+    @Argument(index = 0, name = "segmentId", description = "The identifier for the segment", required = true, multiValued = false)
+    String segmentIdentifier;
+
+
+    public void setSegmentService(SegmentService segmentService) {
+        this.segmentService = segmentService;
+    }
+
+    @Override
+    protected Object doExecute() throws Exception {
+        Segment segment = segmentService.getSegmentDefinition(segmentIdentifier);
+        if (segment == null) {
+            System.out.println("Couldn't find an action with id=" + segmentIdentifier);
+            return null;
+        }
+        String jsonRule = CustomObjectMapper.getObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(segment);
+        System.out.println(jsonRule);
+        return null;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/cef61f34/tools/shell-dev-commands/src/main/resources/OSGI-INF/blueprint/blueprint.xml
----------------------------------------------------------------------
diff --git a/tools/shell-dev-commands/src/main/resources/OSGI-INF/blueprint/blueprint.xml b/tools/shell-dev-commands/src/main/resources/OSGI-INF/blueprint/blueprint.xml
new file mode 100644
index 0000000..fb1ea70
--- /dev/null
+++ b/tools/shell-dev-commands/src/main/resources/OSGI-INF/blueprint/blueprint.xml
@@ -0,0 +1,77 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ Licensed to the Apache Software Foundation (ASF) under one or more
+  ~ contributor license agreements.  See the NOTICE file distributed with
+  ~ this work for additional information regarding copyright ownership.
+  ~ The ASF licenses this file to You under the Apache License, Version 2.0
+  ~ (the "License"); you may not use this file except in compliance with
+  ~ the License.  You may obtain a copy of the License at
+  ~
+  ~      http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing, software
+  ~ distributed under the License is distributed on an "AS IS" BASIS,
+  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  ~ See the License for the specific language governing permissions and
+  ~ limitations under the License.
+  -->
+
+<blueprint xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+           xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0"
+           xmlns:cxf="http://cxf.apache.org/blueprint/core" xmlns:jaxrs="http://cxf.apache.org/blueprint/jaxrs"
+           xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
+           xmlns:shell="http://karaf.apache.org/xmlns/shell/v1.1.0"
+           xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
+  http://cxf.apache.org/blueprint/jaxrs http://cxf.apache.org/schemas/blueprint/jaxrs.xsd
+  http://cxf.apache.org/blueprint/core http://cxf.apache.org/schemas/blueprint/core.xsd
+  http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0 http://aries.apache.org/schemas/blueprint-cm/blueprint-cm-1.1.0.xsd">
+
+    <reference id="segmentService" interface="org.apache.unomi.api.services.SegmentService"/>
+    <reference id="userListService" interface="org.apache.unomi.api.services.UserListService"/>
+    <reference id="definitionsService" interface="org.apache.unomi.api.services.DefinitionsService"/>
+    <reference id="goalsService" interface="org.apache.unomi.api.services.GoalsService"/>
+    <reference id="rulesService" interface="org.apache.unomi.api.services.RulesService"/>
+    <reference id="profileService" interface="org.apache.unomi.api.services.ProfileService"/>
+    <reference id="clusterService" interface="org.apache.unomi.api.services.ClusterService"/>
+    <reference id="queryService" interface="org.apache.unomi.api.services.QueryService"/>
+    <reference id="eventService" interface="org.apache.unomi.api.services.EventService"/>
+
+    <shell:command-bundle>
+        <shell:command>
+            <shell:action class="org.apache.unomi.shell.commands.RuleListCommand">
+                <shell:property name="rulesService" ref="rulesService" />
+            </shell:action>
+        </shell:command>
+        <shell:command>
+            <shell:action class="org.apache.unomi.shell.commands.RuleViewcommand">
+                <shell:property name="rulesService" ref="rulesService" />
+            </shell:action>
+        </shell:command>
+        <shell:command>
+            <shell:action class="org.apache.unomi.shell.commands.RuleResetStatsCommand">
+                <shell:property name="rulesService" ref="rulesService" />
+            </shell:action>
+        </shell:command>
+        <shell:command>
+            <shell:action class="org.apache.unomi.shell.commands.ActionListCommand">
+                <shell:property name="definitionsService" ref="definitionsService" />
+            </shell:action>
+        </shell:command>
+        <shell:command>
+            <shell:action class="org.apache.unomi.shell.commands.ActionViewCommand">
+                <shell:property name="definitionsService" ref="definitionsService" />
+            </shell:action>
+        </shell:command>
+        <shell:command>
+            <shell:action class="org.apache.unomi.shell.commands.SegmentListCommand">
+                <shell:property name="segmentService" ref="segmentService" />
+            </shell:action>
+        </shell:command>
+        <shell:command>
+            <shell:action class="org.apache.unomi.shell.commands.SegmentViewCommand">
+                <shell:property name="segmentService" ref="segmentService" />
+            </shell:action>
+        </shell:command>
+    </shell:command-bundle>
+
+</blueprint>