From 6f275fe85d086f5caabd82a9e1154d5fd04816e7 Mon Sep 17 00:00:00 2001 From: Alvaro Vega Date: Thu, 10 Mar 2022 08:31:37 +0100 Subject: [PATCH 1/3] extract simple name from normalized ruleName --- .../telefonica/iot/perseo/GenericListener.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/perseo-main/src/main/java/com/telefonica/iot/perseo/GenericListener.java b/perseo-main/src/main/java/com/telefonica/iot/perseo/GenericListener.java index 96a0006..1f78a67 100644 --- a/perseo-main/src/main/java/com/telefonica/iot/perseo/GenericListener.java +++ b/perseo-main/src/main/java/com/telefonica/iot/perseo/GenericListener.java @@ -27,11 +27,16 @@ import com.espertech.esper.runtime.client.EPStatement; import com.espertech.esper.runtime.client.EPRuntime; import org.json.JSONObject; +import org.json.JSONArray; +import org.json.JSONException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.util.HashMap; import java.util.Map; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; /** * @@ -59,19 +64,27 @@ public void update(EventBean[] newEvents, EventBean[] oldEvents, EPStatement sta // Get Rule Information from TimeRulesStore String ruleName = (String) eventMap.get("ruleName"); + + // TBD: include service and subservice JSONObject rule = TimeRulesStore.getInstance().getRuleInfo(ruleName); + LOGGER.debug(String.format("Rule name: %s event %s jo %s", + ruleName, event, jo)); // Alt. if event.getEventType().getName().endsWith("_wrapoutwild_") -> Timed rule? if (rule != null) { // Is a timed Rule. Set special headers using rule saved information Utils.setTimerRuleHeaders(rule); + // Timed rule is stored in TImesRuleStored with normalized/unique name) + // But simple rule name should be restored in order to post perseo-fe + List name = new ArrayList(Arrays.asList(ruleName.split("@"))); + jo.put("ruleName", name.get(0)); LOGGER.info(String.format("Firing temporal rule: %s with name %s from event: %s", rule.toString(), ruleName, event)); } else { - LOGGER.info(String.format("Firing Rule with name: %s from Event: %s", - ruleName, event)); + LOGGER.info(String.format("Firing Rule with name: %s from Event: %s Jo: %s", + ruleName, event, jo)); } LOGGER.debug(String.format("result errors: %s",jo.optJSONObject("errors"))); From 74a86966a5a578d73a40c7995e35f43e1ccd9471 Mon Sep 17 00:00:00 2001 From: Alvaro Vega Date: Thu, 10 Mar 2022 10:10:12 +0100 Subject: [PATCH 2/3] update logs --- .../com/telefonica/iot/perseo/GenericListener.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/perseo-main/src/main/java/com/telefonica/iot/perseo/GenericListener.java b/perseo-main/src/main/java/com/telefonica/iot/perseo/GenericListener.java index 1f78a67..42ad1e5 100644 --- a/perseo-main/src/main/java/com/telefonica/iot/perseo/GenericListener.java +++ b/perseo-main/src/main/java/com/telefonica/iot/perseo/GenericListener.java @@ -67,7 +67,7 @@ public void update(EventBean[] newEvents, EventBean[] oldEvents, EPStatement sta // TBD: include service and subservice JSONObject rule = TimeRulesStore.getInstance().getRuleInfo(ruleName); - LOGGER.debug(String.format("Rule name: %s event %s jo %s", + LOGGER.debug(String.format("Rule name: %s event %s jo %s", ruleName, event, jo)); // Alt. if event.getEventType().getName().endsWith("_wrapoutwild_") -> Timed rule? @@ -76,7 +76,7 @@ public void update(EventBean[] newEvents, EventBean[] oldEvents, EPStatement sta // Is a timed Rule. Set special headers using rule saved information Utils.setTimerRuleHeaders(rule); // Timed rule is stored in TImesRuleStored with normalized/unique name) - // But simple rule name should be restored in order to post perseo-fe + // But simple rule name should be used in order to post perseo-fe List name = new ArrayList(Arrays.asList(ruleName.split("@"))); jo.put("ruleName", name.get(0)); LOGGER.info(String.format("Firing temporal rule: %s with name %s from event: %s", @@ -86,8 +86,10 @@ public void update(EventBean[] newEvents, EventBean[] oldEvents, EPStatement sta LOGGER.info(String.format("Firing Rule with name: %s from Event: %s Jo: %s", ruleName, event, jo)); } - - LOGGER.debug(String.format("result errors: %s",jo.optJSONObject("errors"))); + JSONObject errors = jo.optJSONObject("errors"); + if (errors != null) { + LOGGER.info(String.format("result errors: %s", errors)); + } LOGGER.debug(String.format("result json: %s", jo)); boolean ok = Utils.DoHTTPPost(Configuration.getActionURL(), jo.toString()); From e65f51a9cf2f75c6ea6fec18b723c72d4c0e11f3 Mon Sep 17 00:00:00 2001 From: Alvaro Vega Date: Thu, 10 Mar 2022 10:16:54 +0100 Subject: [PATCH 3/3] Update CHANGES_NEXT_RELEASE --- CHANGES_NEXT_RELEASE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES_NEXT_RELEASE b/CHANGES_NEXT_RELEASE index f033d3f..728c9bb 100644 --- a/CHANGES_NEXT_RELEASE +++ b/CHANGES_NEXT_RELEASE @@ -1,5 +1,5 @@ ADD: Set default internal timer msec resolution (millisecond resolutuion of the internal timer thread) (#194) -FIX: Ensure timerules are stored with unique name by using full name which includes service and subservice (#191) +FIX: Ensure timerules are stored with unique name by using full name which includes service and subservice (#191) (needs perseo 1.21 or upper) FIX: upgrade docker based image from Tomcat8 to Tomcat9 FIX: migrate log4j v1 (1.7.25) to v2 (2.17.2) (#184) ADD: allow use WARN as WARNING log level