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/11/29 19:53:58 UTC

incubator-unomi git commit: UNOMI-215 New rule monitoring commands & other new commands - New condition list & view shell commands - New rule tail & rule shell commands

Repository: incubator-unomi
Updated Branches:
  refs/heads/master ac325f945 -> f67674e89


UNOMI-215 New rule monitoring commands & other new commands
- New condition list & view shell commands
- New rule tail & rule shell commands

Signed-off-by: Serge Huber <sh...@apache.org>


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

Branch: refs/heads/master
Commit: f67674e896cf1532a359600a62f8c1c7859b438e
Parents: ac325f9
Author: Serge Huber <sh...@apache.org>
Authored: Thu Nov 29 20:53:52 2018 +0100
Committer: Serge Huber <sh...@apache.org>
Committed: Thu Nov 29 20:53:52 2018 +0100

----------------------------------------------------------------------
 .../unomi/api/services/RuleListenerService.java |  61 +++++++++++
 manual/src/main/asciidoc/shell-commands.adoc    |  37 +++++--
 .../services/services/RulesServiceImpl.java     |  44 +++++++-
 .../resources/OSGI-INF/blueprint/blueprint.xml  |   8 ++
 .../shell/commands/ConditionListCommand.java    |  64 +++++++++++
 .../shell/commands/ConditionViewCommand.java    |  51 +++++++++
 .../unomi/shell/commands/EventTailCommand.java  |  59 +++-------
 .../unomi/shell/commands/RuleListCommand.java   |   2 +-
 .../unomi/shell/commands/RuleTailCommand.java   |  91 ++++++++++++++++
 .../unomi/shell/commands/RuleWatchCommand.java  | 108 +++++++++++++++++++
 .../shell/commands/TailCommandSupport.java      |  99 +++++++++++++++++
 .../resources/OSGI-INF/blueprint/blueprint.xml  |  18 ++++
 12 files changed, 587 insertions(+), 55 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/f67674e8/api/src/main/java/org/apache/unomi/api/services/RuleListenerService.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/unomi/api/services/RuleListenerService.java b/api/src/main/java/org/apache/unomi/api/services/RuleListenerService.java
new file mode 100644
index 0000000..be67f7f
--- /dev/null
+++ b/api/src/main/java/org/apache/unomi/api/services/RuleListenerService.java
@@ -0,0 +1,61 @@
+/*
+ * 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.api.services;
+
+import org.apache.unomi.api.Event;
+import org.apache.unomi.api.rules.Rule;
+
+/**
+ * A service that gets called when a rule's conditions are evaluated or when a rule's actions are executed.
+ */
+public interface RuleListenerService {
+
+    /**
+     * This enum indicates which type of already raised event we are dealing with
+     */
+    enum AlreadyRaisedFor {
+        SESSION,
+        PROFILE
+    }
+
+    /**
+     * Called before a rule's conditions are evaluated. Be careful when implemented this listener because rule's condition
+     * are called in very high frequencies and the performance of this listener might have a huge impact on rule's
+     * performance
+     * @param rule the rule that is being evaluated
+     * @param event the event we are processing and evaluating against the rule
+     */
+    void onEvaluate(Rule rule, Event event);
+
+    /**
+     * Called when a rule has already been raised either for a session or a profile.
+     * @param alreadyRaisedFor an enum that indicates if the rule was already raised once for the session or for the
+     *                         profile
+     * @param rule the rule that has already been raised
+     * @param event the event for which this rule has already been raised.
+     */
+    void onAlreadyRaised(AlreadyRaisedFor alreadyRaisedFor, Rule rule, Event event);
+
+    /**
+     * Called just before a matching rule's actions are about to be executed.
+     * @param rule the matching rule for the current event
+     * @param event the event we are processing that matched the current rule.
+     */
+    void onExecuteActions(Rule rule, Event event);
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/f67674e8/manual/src/main/asciidoc/shell-commands.adoc
----------------------------------------------------------------------
diff --git a/manual/src/main/asciidoc/shell-commands.adoc b/manual/src/main/asciidoc/shell-commands.adoc
index e69e2bc..e544436 100644
--- a/manual/src/main/asciidoc/shell-commands.adoc
+++ b/manual/src/main/asciidoc/shell-commands.adoc
@@ -83,34 +83,57 @@ These commands are available once the application is running. If an argument is
 .Table Runtime commands
 |===
 |Command|Arguments|Description
+
 |rule-list
-|[--csv]
-|Lists all the rules registered in the Apache Unomi server. If you add the "--csv" option the list will be output
-as a CSV formatted table
+|[maxEntries] [--csv]
+|Lists all the rules registered in the Apache Unomi server. The maxEntries (defaults to 100) will allow you to specify
+how many entries need to be retrieved. If the value is inferior to the total value, a message will display the total
+value of rules registered in the server. If you add the "--csv" option the list will be output as a CSV formatted table
 |rule-view
 |rule-id
 |Dumps a single rule in JSON. The rule-id argument can be retrieved from the `rule-list` command output.
 |rule-reset-stats
 |n/a
 |Resets the rule statistics. This is notably useful when trying to understand rule performance and impact
+|rule-tail
+|n/a
+|Dumps any rule that is executed by the server. Only executed rules are logged here. If you want to have more detailed
+information about a particular rule's condition evaluation and if it's already been raised use the `rule-watch` command
+instead. This tail will continue until a CTRL+C key combination is pressed.
+|rule-watch
+|rule-ids
+|Dumps detailed evaluation and execution information about the rules that are where specified in the `rule-ids` arguments
+(you can specify multiple rule identifiers separated by spaces). The `Status` column has the following values: EVALUATE -
+indicates that the rule's conditions are being evaluated (but they might not be satisfied), AR PROFILE - means the rule
+has already been raised for the profile and will therefore not execute again for this profile, AR SESSION - means the
+rule has already been executed for this session and will therefore only executed when another session for the profile is
+created, EXECUTE means the rule's actions are being executed.
+
 |event-tail
 |n/a
 |Dumps any incoming events to the Apache Unomi server to the console. Use CTRL+C to exit tail
 |event-view
 |event-id
 |Dumps a single event in JSON. The `event-id` can be retrieved from the event-tail command output.
+
 |action-list
 |[--csv]
 |Lists all the rule actions registered in the Apache Unomi server. This command is useful when developing plugins to
-check that everything is properly registered. If you add the "--csv" option the list will be output
-                                              as a CSV formatted table
+check that everything is properly registered. If you add the "--csv" option the list will be output as a CSV formatted table
 |action-view
 |action-id
 |Dumps a single action in JSON. The action-id argument can be retrieved from the `action-list` command output.
+
+|condition-list
+|[csv]
+|List all the conditions registered in the server. If you add the "--csv" option the list will be output as a CSV formatted table
+|condition-view
+|condition-id
+|Dumps a single condition in JSON. The condition-id can be retrieved from the `condition-list` command output.
+
 |profile-list
 |[--csv]
-|List the last 10 modified profiles. If you add the "--csv" option the list will be output
-                                     as a CSV formatted table
+|List the last 10 modified profiles. If you add the "--csv" option the list will be output as a CSV formatted table
 |profile-view
 |profile-id
 |Dumps a single profile in JSON. The profile-id argument can be retrieved from the `profile-list` command output.

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/f67674e8/services/src/main/java/org/apache/unomi/services/services/RulesServiceImpl.java
----------------------------------------------------------------------
diff --git a/services/src/main/java/org/apache/unomi/services/services/RulesServiceImpl.java b/services/src/main/java/org/apache/unomi/services/services/RulesServiceImpl.java
index ac4baf0..36f349b 100644
--- a/services/src/main/java/org/apache/unomi/services/services/RulesServiceImpl.java
+++ b/services/src/main/java/org/apache/unomi/services/services/RulesServiceImpl.java
@@ -17,7 +17,10 @@
 
 package org.apache.unomi.services.services;
 
-import org.apache.unomi.api.*;
+import org.apache.unomi.api.Event;
+import org.apache.unomi.api.Item;
+import org.apache.unomi.api.Metadata;
+import org.apache.unomi.api.PartialList;
 import org.apache.unomi.api.actions.Action;
 import org.apache.unomi.api.actions.ActionExecutor;
 import org.apache.unomi.api.conditions.Condition;
@@ -58,6 +61,8 @@ public class RulesServiceImpl implements RulesService, EventListenerService, Syn
     private Integer rulesRefreshInterval = 1000;
     private Integer rulesStatisticsRefreshInterval = 10000;
 
+    private List<RuleListenerService> ruleListeners = new ArrayList<RuleListenerService>();
+
     public void setBundleContext(BundleContext bundleContext) {
         this.bundleContext = bundleContext;
     }
@@ -184,6 +189,8 @@ public class RulesServiceImpl implements RulesService, EventListenerService, Syn
                     continue;
                 }
 
+                fireEvaluate(rule, event);
+
                 if (!persistenceService.testMatch(eventCondition, event)) {
                     updateRuleStatistics(ruleStatistics, ruleConditionStartTime);
                     continue;
@@ -199,12 +206,14 @@ public class RulesServiceImpl implements RulesService, EventListenerService, Syn
                     hasEventAlreadyBeenRaisedForProfile = hasEventAlreadyBeenRaisedForProfile != null ? hasEventAlreadyBeenRaisedForProfile : eventService.hasEventAlreadyBeenRaised(event, false);
                     if (hasEventAlreadyBeenRaisedForProfile) {
                         updateRuleStatistics(ruleStatistics, ruleConditionStartTime);
+                        fireAlreadyRaised(RuleListenerService.AlreadyRaisedFor.PROFILE, rule, event);
                         continue;
                     }
                 } else if (rule.isRaiseEventOnlyOnceForSession()) {
                     hasEventAlreadyBeenRaisedForSession = hasEventAlreadyBeenRaisedForSession != null ? hasEventAlreadyBeenRaisedForSession : eventService.hasEventAlreadyBeenRaised(event, true);
                     if (hasEventAlreadyBeenRaisedForSession) {
                         updateRuleStatistics(ruleStatistics, ruleConditionStartTime);
+                        fireAlreadyRaised(RuleListenerService.AlreadyRaisedFor.SESSION, rule, event);
                         continue;
                     }
                 }
@@ -260,6 +269,8 @@ public class RulesServiceImpl implements RulesService, EventListenerService, Syn
         int changes = EventService.NO_CHANGE;
         for (Rule rule : rules) {
             logger.debug("Fired rule " + rule.getMetadata().getId() + " for " + event.getEventType() + " - " + event.getItemId());
+            fireExecuteActions(rule, event);
+
             long actionsStartTime = System.currentTimeMillis();
             for (Action action : rule.getActions()) {
                 changes |= actionExecutorDispatcher.execute(action, event);
@@ -470,4 +481,35 @@ public class RulesServiceImpl implements RulesService, EventListenerService, Syn
             }
         }
     }
+
+    public void bind(ServiceReference<RuleListenerService> serviceReference) {
+        RuleListenerService ruleListenerService = bundleContext.getService(serviceReference);
+        ruleListeners.add(ruleListenerService);
+    }
+
+    public void unbind(ServiceReference<RuleListenerService> serviceReference) {
+        if (serviceReference != null) {
+            RuleListenerService ruleListenerService = bundleContext.getService(serviceReference);
+            ruleListeners.remove(ruleListenerService);
+        }
+    }
+
+    public void fireEvaluate(Rule rule, Event event) {
+        for (RuleListenerService ruleListenerService : ruleListeners) {
+            ruleListenerService.onEvaluate(rule, event);
+        }
+    }
+
+    public void fireAlreadyRaised(RuleListenerService.AlreadyRaisedFor alreadyRaisedFor, Rule rule, Event event) {
+        for (RuleListenerService ruleListenerService : ruleListeners) {
+            ruleListenerService.onAlreadyRaised(alreadyRaisedFor, rule, event);
+        }
+    }
+
+    public void fireExecuteActions(Rule rule, Event event) {
+        for (RuleListenerService ruleListenerService : ruleListeners) {
+            ruleListenerService.onExecuteActions(rule, event);
+        }
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/f67674e8/services/src/main/resources/OSGI-INF/blueprint/blueprint.xml
----------------------------------------------------------------------
diff --git a/services/src/main/resources/OSGI-INF/blueprint/blueprint.xml b/services/src/main/resources/OSGI-INF/blueprint/blueprint.xml
index 085eec6..9569e67 100644
--- a/services/src/main/resources/OSGI-INF/blueprint/blueprint.xml
+++ b/services/src/main/resources/OSGI-INF/blueprint/blueprint.xml
@@ -260,6 +260,14 @@
                 bind-method="bind" unbind-method="unbind" ref="eventServiceImpl"/>
     </reference-list>
 
+    <!-- We use a listener here because using the list directly for listening to proxies coming from the same bundle didn't seem to work -->
+    <reference-list id="ruleListenerServices"
+                    interface="org.apache.unomi.api.services.RuleListenerService"
+                    availability="optional">
+        <reference-listener
+                bind-method="bind" unbind-method="unbind" ref="rulesServiceImpl"/>
+    </reference-list>
+
     <reference-list id="actionExecutors"
                     interface="org.apache.unomi.api.actions.ActionExecutor"
                     availability="optional">

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/f67674e8/tools/shell-dev-commands/src/main/java/org/apache/unomi/shell/commands/ConditionListCommand.java
----------------------------------------------------------------------
diff --git a/tools/shell-dev-commands/src/main/java/org/apache/unomi/shell/commands/ConditionListCommand.java b/tools/shell-dev-commands/src/main/java/org/apache/unomi/shell/commands/ConditionListCommand.java
new file mode 100644
index 0000000..4cf5be0
--- /dev/null
+++ b/tools/shell-dev-commands/src/main/java/org/apache/unomi/shell/commands/ConditionListCommand.java
@@ -0,0 +1,64 @@
+/*
+ * 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.unomi.api.conditions.ConditionType;
+import org.apache.unomi.api.services.DefinitionsService;
+import org.apache.unomi.common.DataTable;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+@Command(scope = "unomi", name = "condition-list", description = "This will list all the conditions deployed in the Apache Unomi Context Server")
+public class ConditionListCommand extends ListCommandSupport {
+
+    private DefinitionsService definitionsService;
+
+    public void setDefinitionsService(DefinitionsService definitionsService) {
+        this.definitionsService = definitionsService;
+    }
+
+    @Override
+    protected String[] getHeaders() {
+        return new String[] {
+                "Id",
+                "Name",
+                "System tags"
+        };
+    }
+
+    @Override
+    protected DataTable buildDataTable() {
+        Collection<ConditionType> allConditionTypes = definitionsService.getAllConditionTypes();
+
+        DataTable dataTable = new DataTable();
+
+        for (ConditionType conditionType : allConditionTypes) {
+            ArrayList<Comparable> rowData = new ArrayList<>();
+            rowData.add(conditionType.getItemId());
+            rowData.add(conditionType.getMetadata().getName());
+            rowData.add(StringUtils.join(conditionType.getMetadata().getSystemTags(), ","));
+            dataTable.addRow(rowData.toArray(new Comparable[rowData.size()]));
+        }
+
+        dataTable.sort(new DataTable.SortCriteria(1, DataTable.SortOrder.ASCENDING));
+        return dataTable;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/f67674e8/tools/shell-dev-commands/src/main/java/org/apache/unomi/shell/commands/ConditionViewCommand.java
----------------------------------------------------------------------
diff --git a/tools/shell-dev-commands/src/main/java/org/apache/unomi/shell/commands/ConditionViewCommand.java b/tools/shell-dev-commands/src/main/java/org/apache/unomi/shell/commands/ConditionViewCommand.java
new file mode 100644
index 0000000..0c96b17
--- /dev/null
+++ b/tools/shell-dev-commands/src/main/java/org/apache/unomi/shell/commands/ConditionViewCommand.java
@@ -0,0 +1,51 @@
+/*
+ * 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.conditions.ConditionType;
+import org.apache.unomi.api.services.DefinitionsService;
+import org.apache.unomi.persistence.spi.CustomObjectMapper;
+
+@Command(scope = "unomi", name = "condition-view", description = "This will display a single condition deployed in the Apache Unomi Context Server")
+public class ConditionViewCommand extends OsgiCommandSupport {
+
+    private DefinitionsService definitionsService;
+
+    @Argument(index = 0, name = "conditionId", description = "The identifier for the condition", required = true, multiValued = false)
+    String conditionTypeIdentifier;
+
+    public void setDefinitionsService(DefinitionsService definitionsService) {
+        this.definitionsService = definitionsService;
+    }
+
+    @Override
+    protected Object doExecute() throws Exception {
+        ConditionType conditionType = definitionsService.getConditionType(conditionTypeIdentifier);
+        if (conditionType == null) {
+            System.out.println("Couldn't find an action with id=" + conditionTypeIdentifier);
+            return null;
+        }
+        String jsonRule = CustomObjectMapper.getObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(conditionType);
+        System.out.println(jsonRule);
+        return null;
+    }
+
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/f67674e8/tools/shell-dev-commands/src/main/java/org/apache/unomi/shell/commands/EventTailCommand.java
----------------------------------------------------------------------
diff --git a/tools/shell-dev-commands/src/main/java/org/apache/unomi/shell/commands/EventTailCommand.java b/tools/shell-dev-commands/src/main/java/org/apache/unomi/shell/commands/EventTailCommand.java
index 811aa5d..51f4ece 100644
--- a/tools/shell-dev-commands/src/main/java/org/apache/unomi/shell/commands/EventTailCommand.java
+++ b/tools/shell-dev-commands/src/main/java/org/apache/unomi/shell/commands/EventTailCommand.java
@@ -16,24 +16,20 @@
  */
 package org.apache.unomi.shell.commands;
 
-import org.apache.commons.lang3.StringUtils;
 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.Event;
 import org.apache.unomi.api.services.EventListenerService;
 import org.apache.unomi.api.services.EventService;
-import org.osgi.framework.ServiceRegistration;
 
 import java.io.PrintStream;
 import java.util.ArrayList;
-import java.util.Hashtable;
 import java.util.List;
 
 @Command(scope = "unomi", name = "event-tail", description = "This will tail all the events coming into the Apache Unomi Context Server")
-public class EventTailCommand extends OsgiCommandSupport  {
+public class EventTailCommand extends TailCommandSupport  {
 
-    @Argument(index = 0, name = "withInternal", description = "The identifier for the event", required = false, multiValued = false)
+    @Argument(index = 0, name = "withInternal", description = "Whether to also monitor internal events (such as profileUpdated)", required = false, multiValued = false)
     boolean withInternal = false;
 
     int[] columnSizes = new int[] { 36, 14, 36, 36, 29, 15, 5 };
@@ -48,43 +44,18 @@ public class EventTailCommand extends OsgiCommandSupport  {
     };
 
     @Override
-    protected Object doExecute() throws Exception {
-        // Do not use System.out as it may write to the wrong console depending on the thread that calls our log handler
-        PrintStream out = session.getConsole();
-        out.flush();
-        TailEventListener tailEventListener = new TailEventListener(out);
+    public int[] getColumnSizes() {
+        return columnSizes;
+    }
 
-        StringBuilder headerLine = new StringBuilder();
-        for (int i=0; i < columnSizes.length; i++) {
-            headerLine.append(getColumn(columnSizes[i], columnHeaders[i]));
-            headerLine.append("|");
-        }
-        out.println(headerLine.toString());
-        out.println(StringUtils.repeat("-", headerLine.length()));
-        ServiceRegistration<EventListenerService> tailServiceRegistration = bundleContext.registerService(EventListenerService.class, tailEventListener, new Hashtable<>());
-        try {
-            synchronized (this) {
-                wait();
-            }
-        } catch (InterruptedException e) {
-            // Ignore as it will happen if the user breaks the tail using Ctrl-C
-        } finally {
-            tailServiceRegistration.unregister();
-        }
-        return null;
+    @Override
+    public String[] getColumnHeaders() {
+        return columnHeaders;
     }
 
-    protected String getColumn(int columnSize, String columnContent) {
-        if (columnContent == null) {
-            columnContent = "null";
-        }
-        if (columnContent.length() == columnSize) {
-            return columnContent;
-        }
-        if (columnContent.length() < columnSize) {
-            return columnContent + StringUtils.repeat(" ", columnSize - columnContent.length());
-        }
-        return columnContent.substring(0, columnSize);
+    @Override
+    public Object getListener() {
+        return new TailEventListener(session.getConsole());
     }
 
     class TailEventListener implements EventListenerService {
@@ -113,13 +84,9 @@ public class EventTailCommand extends OsgiCommandSupport  {
             eventInfo.add(event.getTimeStamp().toString());
             eventInfo.add(event.getScope());
             eventInfo.add(Boolean.toString(event.isPersistent()));
-            StringBuilder eventLine = new StringBuilder();
-            for (int i=0; i < columnSizes.length; i++) {
-                eventLine.append(getColumn(columnSizes[i], eventInfo.get(i)));
-                eventLine.append("|");
-            }
-            out.println(eventLine.toString());
+            outputLine(out, eventInfo);
             return EventService.NO_CHANGE;
         }
+
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/f67674e8/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
index 23c9df3..3d70d72 100644
--- 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
@@ -73,7 +73,7 @@ public class RuleListCommand extends ListCommandSupport {
         query.setLimit(maxEntries);
         PartialList<Metadata> ruleMetadatas = rulesService.getRuleMetadatas(query);
         if (ruleMetadatas.getList().size() != ruleMetadatas.getTotalSize()) {
-            System.out.println("WARNING : Only the first " + ruleMetadatas.getPageSize() + " have been retrieved, there are " + ruleMetadatas + " rules registered. Use the maxEntries parameter to retrieve more rules");
+            System.out.println("WARNING : Only the first " + ruleMetadatas.getPageSize() + " rules have been retrieved, there are " + ruleMetadatas.getTotalSize() + " rules registered in total. Use the maxEntries parameter to retrieve more rules");
         }
         Map<String,RuleStatistics> allRuleStatistics = rulesService.getAllRuleStatistics();
 

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/f67674e8/tools/shell-dev-commands/src/main/java/org/apache/unomi/shell/commands/RuleTailCommand.java
----------------------------------------------------------------------
diff --git a/tools/shell-dev-commands/src/main/java/org/apache/unomi/shell/commands/RuleTailCommand.java b/tools/shell-dev-commands/src/main/java/org/apache/unomi/shell/commands/RuleTailCommand.java
new file mode 100644
index 0000000..910c1e2
--- /dev/null
+++ b/tools/shell-dev-commands/src/main/java/org/apache/unomi/shell/commands/RuleTailCommand.java
@@ -0,0 +1,91 @@
+/*
+ * 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.unomi.api.Event;
+import org.apache.unomi.api.rules.Rule;
+import org.apache.unomi.api.services.RuleListenerService;
+
+import java.io.PrintStream;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * This command will list all the rules executions in the shell console.
+ */
+@Command(scope = "unomi", name = "rule-tail", description = "This will tail all the rules executed in the Apache Unomi Context Server")
+public class RuleTailCommand extends TailCommandSupport {
+
+    int[] columnSizes = new int[] { 36, 36, 14, 36, 29, 15, 5 };
+    String[] columnHeaders = new String[] {
+            "Rule ID",
+            "Rule Name",
+            "Event Type",
+            "Session",
+            "Profile",
+            "Timestamp",
+            "Scope",
+    };
+
+    @Override
+    public int[] getColumnSizes() {
+        return columnSizes;
+    }
+
+    @Override
+    public String[] getColumnHeaders() {
+        return columnHeaders;
+    }
+
+    @Override
+    public Object getListener() {
+        return new TailRuleListener(session.getConsole());
+    }
+
+    class TailRuleListener implements RuleListenerService {
+
+        PrintStream out;
+
+        public TailRuleListener(PrintStream out) {
+            this.out = out;
+        }
+
+        @Override
+        public void onEvaluate(Rule rule, Event event) {
+            // this method is not used by this command
+        }
+
+        @Override
+        public void onAlreadyRaised(AlreadyRaisedFor alreadyRaisedFor, Rule rule, Event event) {
+            // not displayed using this command, see the rule watch command instead.
+        }
+
+        @Override
+        public void onExecuteActions(Rule rule, Event event) {
+            List<String> ruleExecutionInfo = new ArrayList<>();
+            ruleExecutionInfo.add(rule.getItemId());
+            ruleExecutionInfo.add(rule.getMetadata().getName());
+            ruleExecutionInfo.add(event.getEventType());
+            ruleExecutionInfo.add(event.getSessionId());
+            ruleExecutionInfo.add(event.getProfileId());
+            ruleExecutionInfo.add(event.getTimeStamp().toString());
+            ruleExecutionInfo.add(event.getScope());
+            outputLine(out, ruleExecutionInfo);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/f67674e8/tools/shell-dev-commands/src/main/java/org/apache/unomi/shell/commands/RuleWatchCommand.java
----------------------------------------------------------------------
diff --git a/tools/shell-dev-commands/src/main/java/org/apache/unomi/shell/commands/RuleWatchCommand.java b/tools/shell-dev-commands/src/main/java/org/apache/unomi/shell/commands/RuleWatchCommand.java
new file mode 100644
index 0000000..1012c14
--- /dev/null
+++ b/tools/shell-dev-commands/src/main/java/org/apache/unomi/shell/commands/RuleWatchCommand.java
@@ -0,0 +1,108 @@
+/*
+ * 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.ArrayUtils;
+import org.apache.karaf.shell.commands.Argument;
+import org.apache.karaf.shell.commands.Command;
+import org.apache.unomi.api.Event;
+import org.apache.unomi.api.rules.Rule;
+import org.apache.unomi.api.services.RuleListenerService;
+
+import java.io.PrintStream;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * This command can watch the evaluations of the conditions as well as the executions of a specified number of rules.
+ */
+@Command(scope = "unomi", name = "rule-watch", description = "This will watch the specified rules evaluating and executing in the Apache Unomi Context Server")
+public class RuleWatchCommand extends TailCommandSupport {
+
+    @Argument(index = 0, name = "ruleIds", description = "Identifier(s) of rule(s) to watch", required = true, multiValued = true)
+    String[] ruleIds;
+
+    int[] columnSizes = new int[] { 10, 36, 36, 14, 36, 29, 15, 5 };
+    String[] columnHeaders = new String[] {
+            "Status",
+            "Rule ID",
+            "Rule Name",
+            "Event Type",
+            "Session",
+            "Profile",
+            "Timestamp",
+            "Scope",
+    };
+
+    @Override
+    public int[] getColumnSizes() {
+        return columnSizes;
+    }
+
+    @Override
+    public String[] getColumnHeaders() {
+        return columnHeaders;
+    }
+
+    @Override
+    public Object getListener() {
+        return new RuleWatchListener(session.getConsole());
+    }
+
+    class RuleWatchListener implements RuleListenerService {
+
+        PrintStream out;
+
+        public RuleWatchListener(PrintStream out) {
+            this.out = out;
+        }
+
+        @Override
+        public void onEvaluate(Rule rule, Event event) {
+            populateRuleInfo(rule, event, "EVALUATE");
+        }
+
+
+        @Override
+        public void onAlreadyRaised(AlreadyRaisedFor alreadyRaisedFor, Rule rule, Event event) {
+            populateRuleInfo(rule, event, "AR " + alreadyRaisedFor.toString());
+        }
+
+        @Override
+        public void onExecuteActions(Rule rule, Event event) {
+            populateRuleInfo(rule, event, "EXECUTE");
+        }
+
+        public void populateRuleInfo(Rule rule, Event event, String status) {
+            if (!ArrayUtils.contains(ruleIds, rule.getItemId())) {
+                return;
+            }
+            List<String> ruleExecutionInfo = new ArrayList<>();
+            ruleExecutionInfo.add(status);
+            ruleExecutionInfo.add(rule.getItemId());
+            ruleExecutionInfo.add(rule.getMetadata().getName());
+            ruleExecutionInfo.add(event.getEventType());
+            ruleExecutionInfo.add(event.getSessionId());
+            ruleExecutionInfo.add(event.getProfileId());
+            ruleExecutionInfo.add(event.getTimeStamp().toString());
+            ruleExecutionInfo.add(event.getScope());
+            outputLine(out, ruleExecutionInfo);
+        }
+
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/f67674e8/tools/shell-dev-commands/src/main/java/org/apache/unomi/shell/commands/TailCommandSupport.java
----------------------------------------------------------------------
diff --git a/tools/shell-dev-commands/src/main/java/org/apache/unomi/shell/commands/TailCommandSupport.java b/tools/shell-dev-commands/src/main/java/org/apache/unomi/shell/commands/TailCommandSupport.java
new file mode 100644
index 0000000..ba0a0ad
--- /dev/null
+++ b/tools/shell-dev-commands/src/main/java/org/apache/unomi/shell/commands/TailCommandSupport.java
@@ -0,0 +1,99 @@
+/*
+ * 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.console.OsgiCommandSupport;
+import org.osgi.framework.ServiceRegistration;
+
+import java.io.PrintStream;
+import java.util.ArrayList;
+import java.util.Hashtable;
+import java.util.List;
+
+public abstract class TailCommandSupport extends OsgiCommandSupport {
+
+    public abstract int[] getColumnSizes();
+
+    public abstract String[] getColumnHeaders();
+
+    public void outputHeaders(PrintStream out) {
+        StringBuilder headerLine = new StringBuilder();
+        int[] columnSizes = getColumnSizes();
+        String[] columnHeaders = getColumnHeaders();
+        for (int i=0; i < columnSizes.length; i++) {
+            headerLine.append(getColumn(columnSizes[i], columnHeaders[i]));
+            headerLine.append("|");
+        }
+        out.println(headerLine.toString());
+        out.println(StringUtils.repeat("-", headerLine.length()));
+    }
+
+    public String getColumn(int columnSize, String columnContent) {
+        if (columnContent == null) {
+            columnContent = "null";
+        }
+        if (columnContent.length() == columnSize) {
+            return columnContent;
+        }
+        if (columnContent.length() < columnSize) {
+            return columnContent + StringUtils.repeat(" ", columnSize - columnContent.length());
+        }
+        return columnContent.substring(0, columnSize);
+    }
+
+    public void outputLine(PrintStream out, List<String> eventInfo) {
+        StringBuilder eventLine = new StringBuilder();
+        int[] columnSizes = getColumnSizes();
+        for (int i=0; i < columnSizes.length; i++) {
+            eventLine.append(getColumn(columnSizes[i], eventInfo.get(i)));
+            eventLine.append("|");
+        }
+        out.println(eventLine.toString());
+    }
+    
+    public abstract Object getListener();
+
+
+    @Override
+    protected Object doExecute() throws Exception {
+        // Do not use System.out as it may write to the wrong console depending on the thread that calls our log handler
+        PrintStream out = session.getConsole();
+        out.flush();
+        outputHeaders(out);
+
+        Object listener = getListener();
+
+        List<String> interfaces = new ArrayList<>();
+        for (Class<?> listenerInterface : listener.getClass().getInterfaces()) {
+            interfaces.add(listenerInterface.getName());
+        }
+
+        ServiceRegistration<?> tailServiceRegistration = bundleContext.registerService(interfaces.toArray(new String[interfaces.size()]), listener, new Hashtable<>());
+        try {
+            synchronized (this) {
+                wait();
+            }
+        } catch (InterruptedException e) {
+            // Ignore as it will happen if the user breaks the tail using Ctrl-C
+        } finally {
+            tailServiceRegistration.unregister();
+        }
+        return null;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/f67674e8/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
index 48ea840..16f60fb 100644
--- 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
@@ -50,6 +50,14 @@
             </shell:action>
         </shell:command>
         <shell:command>
+            <shell:action class="org.apache.unomi.shell.commands.RuleTailCommand">
+            </shell:action>
+        </shell:command>
+        <shell:command>
+            <shell:action class="org.apache.unomi.shell.commands.RuleWatchCommand">
+            </shell:action>
+        </shell:command>
+        <shell:command>
             <shell:action class="org.apache.unomi.shell.commands.ActionListCommand">
                 <shell:property name="definitionsService" ref="definitionsService" />
             </shell:action>
@@ -60,6 +68,16 @@
             </shell:action>
         </shell:command>
         <shell:command>
+            <shell:action class="org.apache.unomi.shell.commands.ConditionListCommand">
+                <shell:property name="definitionsService" ref="definitionsService" />
+            </shell:action>
+        </shell:command>
+        <shell:command>
+            <shell:action class="org.apache.unomi.shell.commands.ConditionViewCommand">
+                <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>