From ddcd59616109caa7833af2d3e442cb9ad778ca28 Mon Sep 17 00:00:00 2001 From: wujinhu Date: Thu, 23 Feb 2017 13:40:44 +0800 Subject: [PATCH 1/4] support for hadoop jmx resource info --- .../StringSubtractFunctionExtension.java | 94 +++++++++++++++++++ .../src/main/resources/string.siddhiext | 3 +- .../StringSubtractFunctionExtensionTest.java | 62 ++++++++++++ .../src/test/resources/string.siddhiext | 19 ++++ .../hadoop_jmx_collector/hadoop_jmx_kafka.py | 8 +- .../hadoop_jmx_collector/metric_collector.py | 6 +- ....metric.HadoopMetricMonitorAppProdiver.xml | 38 ++++++++ 7 files changed, 226 insertions(+), 4 deletions(-) create mode 100644 eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/main/java/org/apache/eagle/alert/siddhiext/StringSubtractFunctionExtension.java create mode 100644 eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/test/java/org/apache/eagle/siddhiext/StringSubtractFunctionExtensionTest.java create mode 100644 eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/test/resources/string.siddhiext diff --git a/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/main/java/org/apache/eagle/alert/siddhiext/StringSubtractFunctionExtension.java b/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/main/java/org/apache/eagle/alert/siddhiext/StringSubtractFunctionExtension.java new file mode 100644 index 0000000000..9e95ebbcb1 --- /dev/null +++ b/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/main/java/org/apache/eagle/alert/siddhiext/StringSubtractFunctionExtension.java @@ -0,0 +1,94 @@ +/* + * 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.eagle.alert.siddhiext; + +import org.apache.commons.collections.ListUtils; +import org.wso2.siddhi.core.config.ExecutionPlanContext; +import org.wso2.siddhi.core.executor.ExpressionExecutor; +import org.wso2.siddhi.core.executor.function.FunctionExecutor; +import org.wso2.siddhi.query.api.definition.Attribute; +import org.wso2.siddhi.query.api.exception.ExecutionPlanValidationException; + +import java.util.Arrays; +import java.util.List; + +public class StringSubtractFunctionExtension extends FunctionExecutor { + /** + * The initialization method for StringSubtractFunctionExtension, this method will be called before the other methods. + * + * @param attributeExpressionExecutors the executors of each function parameter + * @param executionPlanContext the context of the execution plan + */ + @Override + protected void init(ExpressionExecutor[] attributeExpressionExecutors, ExecutionPlanContext executionPlanContext) { + if (attributeExpressionExecutors.length != 2) { + throw new ExecutionPlanValidationException("Invalid no of arguments passed to string:subtract() function, " + + "required 2, but found " + attributeExpressionExecutors.length); + } + + Attribute.Type attributeType = attributeExpressionExecutors[0].getReturnType(); + if (attributeType != Attribute.Type.STRING) { + throw new ExecutionPlanValidationException("Invalid parameter type found for the argument of string:subtract() function, " + + "required " + Attribute.Type.STRING + + ", but found " + attributeType.toString()); + } + } + + /** + * The main execution method which will be called upon event arrival. + * when there are more than one function parameter + * + * This method calculates subtraction of two strings + * Each String is a string list that separated by ':' + * @param data the runtime values of function parameters + * @return the function result + */ + @Override + protected Object execute(Object[] data) { + List ths = Arrays.asList(((String) data[0]).split(":")); + List rhs = Arrays.asList(((String) data[1]).split(":")); + return org.apache.commons.lang.StringUtils.join(ListUtils.subtract(rhs, ths), "\n"); + } + + @Override + protected Object execute(Object data) { + return null; + } + + @Override + public void start() { + } + + @Override + public void stop() { + } + + @Override + public Attribute.Type getReturnType() { + return Attribute.Type.STRING; + } + + @Override + public Object[] currentState() { + return null; + } + + @Override + public void restoreState(Object[] state) { + } +} diff --git a/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/main/resources/string.siddhiext b/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/main/resources/string.siddhiext index e16be99040..ac8e0996dc 100644 --- a/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/main/resources/string.siddhiext +++ b/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/main/resources/string.siddhiext @@ -15,4 +15,5 @@ * limitations under the License. */ -empty=org.apache.eagle.alert.siddhiext.StringEmptyFunctionExtension \ No newline at end of file +empty=org.apache.eagle.alert.siddhiext.StringEmptyFunctionExtension +subtract=org.apache.eagle.alert.siddhiext.StringSubtractFunctionExtension \ No newline at end of file diff --git a/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/test/java/org/apache/eagle/siddhiext/StringSubtractFunctionExtensionTest.java b/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/test/java/org/apache/eagle/siddhiext/StringSubtractFunctionExtensionTest.java new file mode 100644 index 0000000000..c8db6b6525 --- /dev/null +++ b/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/test/java/org/apache/eagle/siddhiext/StringSubtractFunctionExtensionTest.java @@ -0,0 +1,62 @@ +/* + * 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.eagle.siddhiext; + +import org.junit.*; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.wso2.siddhi.core.ExecutionPlanRuntime; +import org.wso2.siddhi.core.SiddhiManager; +import org.wso2.siddhi.core.event.Event; +import org.wso2.siddhi.core.stream.input.InputHandler; +import org.wso2.siddhi.core.stream.output.StreamCallback; +import org.wso2.siddhi.core.util.EventPrinter; + +public class StringSubtractFunctionExtensionTest { + private static final Logger LOG = LoggerFactory.getLogger(StringSubtractFunctionExtensionTest.class); + + @Test + public void testStringSubtract() throws Exception { + String ql = " define stream log(timestamp long, switchLabel string, port string, message string); " + + " from log select string:subtract(\"a:b:c:d:e:f:g\", \"g:a:e:d:z:r:s:c\") as alertKey insert into output; "; + SiddhiManager manager = new SiddhiManager(); + ExecutionPlanRuntime runtime = manager.createExecutionPlanRuntime(ql); + runtime.addCallback("output", new StreamCallback() { + @Override + public void receive(Event[] events) { + EventPrinter.print(events); + Assert.assertTrue(events.length == 1); + Assert.assertTrue(events[0].getData(0).toString().equals("z\nr\ns")); + } + }); + + runtime.start(); + + InputHandler logInput = runtime.getInputHandler("log"); + + Event e = new Event(); + e.setTimestamp(System.currentTimeMillis()); + e.setData(new Object[] {System.currentTimeMillis(), "switch-ra-slc-01", "port01", "log-message...."}); + logInput.send(e); + + Thread.sleep(1000); + runtime.shutdown(); + + } + +} diff --git a/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/test/resources/string.siddhiext b/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/test/resources/string.siddhiext new file mode 100644 index 0000000000..ac8e0996dc --- /dev/null +++ b/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/test/resources/string.siddhiext @@ -0,0 +1,19 @@ +/* + * 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. + */ + +empty=org.apache.eagle.alert.siddhiext.StringEmptyFunctionExtension +subtract=org.apache.eagle.alert.siddhiext.StringSubtractFunctionExtension \ No newline at end of file diff --git a/eagle-external/hadoop_jmx_collector/hadoop_jmx_kafka.py b/eagle-external/hadoop_jmx_collector/hadoop_jmx_kafka.py index 78183e0fd9..a30eaa9f7c 100644 --- a/eagle-external/hadoop_jmx_collector/hadoop_jmx_kafka.py +++ b/eagle-external/hadoop_jmx_collector/hadoop_jmx_kafka.py @@ -38,6 +38,11 @@ def on_bean(self, component, bean): else: self.collector.on_bean_kv(self.PREFIX, component, "hastate", 1) +class NameNodeInfo(JmxMetricListener): + def on_metric(self, metric): + if metric["metric"] == "hadoop.namenode.namenodeinfo.corruptfiles": + metric["value"] = ":".join(json.loads(str(metric["value"]))) + self.collector.collect(metric, "string") class MemoryUsageMetric(JmxMetricListener): PREFIX = "hadoop.namenode.jvm" @@ -102,6 +107,7 @@ def on_metric(self, metric): NNCapacityUsageMetric(), JournalTransactionInfoMetric(), DatanodeFSDatasetState(), - HBaseRegionServerMetric() + HBaseRegionServerMetric(), + NameNodeInfo() ) Runner.run(collector) \ No newline at end of file diff --git a/eagle-external/hadoop_jmx_collector/metric_collector.py b/eagle-external/hadoop_jmx_collector/metric_collector.py index a472bbe907..2bc042098f 100644 --- a/eagle-external/hadoop_jmx_collector/metric_collector.py +++ b/eagle-external/hadoop_jmx_collector/metric_collector.py @@ -294,12 +294,14 @@ def filter(self, *filters): def start(self): super(MetricCollector, self).start() - def collect(self, msg): + def collect(self, msg, type='float'): try: if not msg.has_key("timestamp"): msg["timestamp"] = int(round(time.time() * 1000)) - if msg.has_key("value"): + if msg.has_key("value") and type == 'float': msg["value"] = float(str(msg["value"])) + elif msg.has_key("value") and type == 'string': + msg["value"] = str(msg["value"]) if not msg.has_key("host") or len(msg["host"]) == 0: raise Exception("host is null: " + str(msg)) if not msg.has_key("site"): diff --git a/eagle-hadoop-metric/src/main/resources/META-INF/providers/org.apache.eagle.metric.HadoopMetricMonitorAppProdiver.xml b/eagle-hadoop-metric/src/main/resources/META-INF/providers/org.apache.eagle.metric.HadoopMetricMonitorAppProdiver.xml index 8262da9a59..54095466b4 100644 --- a/eagle-hadoop-metric/src/main/resources/META-INF/providers/org.apache.eagle.metric.HadoopMetricMonitorAppProdiver.xml +++ b/eagle-hadoop-metric/src/main/resources/META-INF/providers/org.apache.eagle.metric.HadoopMetricMonitorAppProdiver.xml @@ -35,6 +35,13 @@ Hadoop JMX metric kafka topic name for stream: HADOOP_JMX_METRIC_STREAM true + + dataSinkConfig.HADOOP_JMX_RESOURCE_STREAM.topic + JMX Resource Kafka Topic + hadoop_jmx_resource_${siteId} + Hadoop JMX resource kafka topic name for stream: HADOOP_JMX_RESOURCE_STREAM + true + dataSinkConfig.brokerList Kafka Brokers @@ -133,6 +140,37 @@ + + HADOOP_JMX_RESOURCE_STREAM + Hadoop JMX Resource Stream including name node, resource manager, etc. + + + host + string + + + timestamp + long + + + resource + string + + + component + string + + + site + string + + + value + string + "" + + + From 3f3fb3adda59510a2e33b739a02fd29ea4c6c65b Mon Sep 17 00:00:00 2001 From: wujinhu Date: Thu, 23 Feb 2017 13:50:02 +0800 Subject: [PATCH 2/4] support for hadoop jmx resource info --- .../eagle/alert/siddhiext/StringSubtractFunctionExtension.java | 1 - 1 file changed, 1 deletion(-) diff --git a/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/main/java/org/apache/eagle/alert/siddhiext/StringSubtractFunctionExtension.java b/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/main/java/org/apache/eagle/alert/siddhiext/StringSubtractFunctionExtension.java index 9e95ebbcb1..227f793379 100644 --- a/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/main/java/org/apache/eagle/alert/siddhiext/StringSubtractFunctionExtension.java +++ b/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/main/java/org/apache/eagle/alert/siddhiext/StringSubtractFunctionExtension.java @@ -52,7 +52,6 @@ protected void init(ExpressionExecutor[] attributeExpressionExecutors, Execution /** * The main execution method which will be called upon event arrival. * when there are more than one function parameter - * * This method calculates subtraction of two strings * Each String is a string list that separated by ':' * @param data the runtime values of function parameters From 7a698839b5b052f2a4f78b4142676c557a487f19 Mon Sep 17 00:00:00 2001 From: wujinhu Date: Thu, 23 Feb 2017 14:50:36 +0800 Subject: [PATCH 3/4] support for hadoop jmx resource info --- .../StringSubtractFunctionExtension.java | 35 ++++++++++++++++--- .../StringSubtractFunctionExtensionTest.java | 16 ++++++--- .../hadoop_jmx_collector/hadoop_jmx_kafka.py | 1 - 3 files changed, 41 insertions(+), 11 deletions(-) diff --git a/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/main/java/org/apache/eagle/alert/siddhiext/StringSubtractFunctionExtension.java b/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/main/java/org/apache/eagle/alert/siddhiext/StringSubtractFunctionExtension.java index 227f793379..b37d22830f 100644 --- a/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/main/java/org/apache/eagle/alert/siddhiext/StringSubtractFunctionExtension.java +++ b/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/main/java/org/apache/eagle/alert/siddhiext/StringSubtractFunctionExtension.java @@ -18,16 +18,22 @@ package org.apache.eagle.alert.siddhiext; import org.apache.commons.collections.ListUtils; +import org.codehaus.jettison.json.JSONArray; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.wso2.siddhi.core.config.ExecutionPlanContext; import org.wso2.siddhi.core.executor.ExpressionExecutor; import org.wso2.siddhi.core.executor.function.FunctionExecutor; import org.wso2.siddhi.query.api.definition.Attribute; import org.wso2.siddhi.query.api.exception.ExecutionPlanValidationException; +import java.util.ArrayList; import java.util.Arrays; import java.util.List; public class StringSubtractFunctionExtension extends FunctionExecutor { + private static final Logger LOG = LoggerFactory.getLogger(StringSubtractFunctionExtension.class); + /** * The initialization method for StringSubtractFunctionExtension, this method will be called before the other methods. * @@ -52,16 +58,35 @@ protected void init(ExpressionExecutor[] attributeExpressionExecutors, Execution /** * The main execution method which will be called upon event arrival. * when there are more than one function parameter - * This method calculates subtraction of two strings - * Each String is a string list that separated by ':' + * This method calculates subtraction of two List Of Strings + * Each String is a jobs string needs to be loaded * @param data the runtime values of function parameters * @return the function result */ @Override protected Object execute(Object[] data) { - List ths = Arrays.asList(((String) data[0]).split(":")); - List rhs = Arrays.asList(((String) data[1]).split(":")); - return org.apache.commons.lang.StringUtils.join(ListUtils.subtract(rhs, ths), "\n"); + try { + List ths = new ArrayList<>(); + if (!((String) data[0]).isEmpty()) { + JSONArray jsonArray = new JSONArray((String) data[0]); + for (int i = 0; i < jsonArray.length(); ++i) { + ths.add(jsonArray.getString(i)); + } + } + + List rhs = new ArrayList<>(); + if (!((String) data[1]).isEmpty()) { + JSONArray jsonArray = new JSONArray((String) data[1]); + for (int i = 0; i < jsonArray.length(); ++i) { + rhs.add(jsonArray.getString(i)); + } + } + + return org.apache.commons.lang.StringUtils.join(ListUtils.subtract(ths, rhs), "\n"); + } catch (Exception e) { + LOG.warn("exception found {}", e); + return null; + } } @Override diff --git a/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/test/java/org/apache/eagle/siddhiext/StringSubtractFunctionExtensionTest.java b/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/test/java/org/apache/eagle/siddhiext/StringSubtractFunctionExtensionTest.java index c8db6b6525..4a31c69692 100644 --- a/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/test/java/org/apache/eagle/siddhiext/StringSubtractFunctionExtensionTest.java +++ b/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/test/java/org/apache/eagle/siddhiext/StringSubtractFunctionExtensionTest.java @@ -27,13 +27,16 @@ import org.wso2.siddhi.core.stream.output.StreamCallback; import org.wso2.siddhi.core.util.EventPrinter; +import java.util.concurrent.Semaphore; + public class StringSubtractFunctionExtensionTest { private static final Logger LOG = LoggerFactory.getLogger(StringSubtractFunctionExtensionTest.class); @Test public void testStringSubtract() throws Exception { + Semaphore semp = new Semaphore(1); String ql = " define stream log(timestamp long, switchLabel string, port string, message string); " + - " from log select string:subtract(\"a:b:c:d:e:f:g\", \"g:a:e:d:z:r:s:c\") as alertKey insert into output; "; + " from log select string:subtract(switchLabel, message) as alertKey insert into output; "; SiddhiManager manager = new SiddhiManager(); ExecutionPlanRuntime runtime = manager.createExecutionPlanRuntime(ql); runtime.addCallback("output", new StreamCallback() { @@ -41,20 +44,23 @@ public void testStringSubtract() throws Exception { public void receive(Event[] events) { EventPrinter.print(events); Assert.assertTrue(events.length == 1); - Assert.assertTrue(events[0].getData(0).toString().equals("z\nr\ns")); + Assert.assertTrue(events[0].getData(0).toString().equals("a\nc\ne")); + semp.release(); } }); runtime.start(); InputHandler logInput = runtime.getInputHandler("log"); - + semp.acquire(); Event e = new Event(); e.setTimestamp(System.currentTimeMillis()); - e.setData(new Object[] {System.currentTimeMillis(), "switch-ra-slc-01", "port01", "log-message...."}); + String ths = "[\"a\", \"b\", \"c\", \"d\", \"e\"]"; + String rhs = "[\"b\", \"d\"]"; + e.setData(new Object[] {System.currentTimeMillis(), ths, "port01", rhs}); logInput.send(e); - Thread.sleep(1000); + semp.acquire(); runtime.shutdown(); } diff --git a/eagle-external/hadoop_jmx_collector/hadoop_jmx_kafka.py b/eagle-external/hadoop_jmx_collector/hadoop_jmx_kafka.py index a30eaa9f7c..1b036cd596 100644 --- a/eagle-external/hadoop_jmx_collector/hadoop_jmx_kafka.py +++ b/eagle-external/hadoop_jmx_collector/hadoop_jmx_kafka.py @@ -41,7 +41,6 @@ def on_bean(self, component, bean): class NameNodeInfo(JmxMetricListener): def on_metric(self, metric): if metric["metric"] == "hadoop.namenode.namenodeinfo.corruptfiles": - metric["value"] = ":".join(json.loads(str(metric["value"]))) self.collector.collect(metric, "string") class MemoryUsageMetric(JmxMetricListener): From 9653340a6c725dd4b002b766056ed0992164d78c Mon Sep 17 00:00:00 2001 From: wujinhu Date: Thu, 23 Feb 2017 14:55:44 +0800 Subject: [PATCH 4/4] support for hadoop jmx resource info --- .../StringSubtractFunctionExtension.java | 18 +++-------------- .../apache/eagle/alert/utils/JsonUtils.java | 20 +++++++++++++++++++ 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/main/java/org/apache/eagle/alert/siddhiext/StringSubtractFunctionExtension.java b/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/main/java/org/apache/eagle/alert/siddhiext/StringSubtractFunctionExtension.java index b37d22830f..9d26adf819 100644 --- a/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/main/java/org/apache/eagle/alert/siddhiext/StringSubtractFunctionExtension.java +++ b/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/main/java/org/apache/eagle/alert/siddhiext/StringSubtractFunctionExtension.java @@ -18,6 +18,7 @@ package org.apache.eagle.alert.siddhiext; import org.apache.commons.collections.ListUtils; +import org.apache.eagle.alert.utils.JsonUtils; import org.codehaus.jettison.json.JSONArray; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -66,21 +67,8 @@ protected void init(ExpressionExecutor[] attributeExpressionExecutors, Execution @Override protected Object execute(Object[] data) { try { - List ths = new ArrayList<>(); - if (!((String) data[0]).isEmpty()) { - JSONArray jsonArray = new JSONArray((String) data[0]); - for (int i = 0; i < jsonArray.length(); ++i) { - ths.add(jsonArray.getString(i)); - } - } - - List rhs = new ArrayList<>(); - if (!((String) data[1]).isEmpty()) { - JSONArray jsonArray = new JSONArray((String) data[1]); - for (int i = 0; i < jsonArray.length(); ++i) { - rhs.add(jsonArray.getString(i)); - } - } + List ths = JsonUtils.jsonStringToList((String) data[0]); + List rhs = JsonUtils.jsonStringToList((String) data[1]); return org.apache.commons.lang.StringUtils.join(ListUtils.subtract(ths, rhs), "\n"); } catch (Exception e) { diff --git a/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/main/java/org/apache/eagle/alert/utils/JsonUtils.java b/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/main/java/org/apache/eagle/alert/utils/JsonUtils.java index 2ee1a5f82e..cc75d34c20 100644 --- a/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/main/java/org/apache/eagle/alert/utils/JsonUtils.java +++ b/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/main/java/org/apache/eagle/alert/utils/JsonUtils.java @@ -17,9 +17,13 @@ package org.apache.eagle.alert.utils; import com.fasterxml.jackson.databind.ObjectMapper; +import org.codehaus.jettison.json.JSONArray; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.ArrayList; +import java.util.List; + public class JsonUtils { public static final ObjectMapper mapper = new ObjectMapper(); @@ -33,4 +37,20 @@ public static String writeValueAsString(Object o) { } return ""; } + + public static List jsonStringToList(String message) { + List result = new ArrayList<>(); + try { + if (!message.isEmpty()) { + JSONArray jsonArray = new JSONArray(message); + for (int i = 0; i < jsonArray.length(); ++i) { + result.add(jsonArray.getString(i)); + } + } + } catch (Exception e) { + LOG.warn("exception found {}", e); + } + + return result; + } }