This is an automated email from the ASF dual-hosted git repository.

brahma pushed a commit to branch branch-2.7
in repository https://gitbox.apache.org/repos/asf/ambari.git


The following commit(s) were added to refs/heads/branch-2.7 by this push:
     new 4f7c909b48 Replace StandardEvaluationContext with 
SimpleEvaluationContext in Metricsource.Contributed by Vishal Suvagia.
4f7c909b48 is described below

commit 4f7c909b48b33cf0810548bcf2a33e56b02076c7
Author: Brahma Reddy Battula <bra...@apache.org>
AuthorDate: Sun Oct 9 09:13:27 2022 +0530

    Replace StandardEvaluationContext with SimpleEvaluationContext in 
Metricsource.Contributed by Vishal Suvagia.
---
 .../java/org/apache/ambari/server/state/alert/MetricSource.java   | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/state/alert/MetricSource.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/state/alert/MetricSource.java
index d81deaf0a4..5d29ae8c58 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/state/alert/MetricSource.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/state/alert/MetricSource.java
@@ -29,7 +29,7 @@ import org.apache.ambari.server.state.UriInfo;
 import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.collections.ListUtils;
 import org.springframework.expression.spel.standard.SpelExpressionParser;
-import org.springframework.expression.spel.support.StandardEvaluationContext;
+import org.springframework.expression.spel.support.SimpleEvaluationContext;
 
 import com.fasterxml.jackson.annotation.JsonAutoDetect;
 import com.fasterxml.jackson.annotation.JsonInclude;
@@ -185,8 +185,10 @@ public class MetricSource extends Source {
      * then it is evaluated in the context of the metrics parameters.
      */
     public Object eval(List<Object> metrics) {
-      StandardEvaluationContext context = new StandardEvaluationContext();
-      context.setVariables(range(0, metrics.size()).boxed().collect(toMap(i -> 
"var" + i, metrics::get)));
+      SimpleEvaluationContext context = 
SimpleEvaluationContext.forReadWriteDataBinding().build();
+      for(int i = 0; i < metrics.size(); i++) {
+        context.setVariable("var" + i, metrics.get(i));
+      }
       return new SpelExpressionParser()
         .parseExpression(value.replaceAll("(\\{(\\d+)\\})", "#var$2"))
         .getValue(context);


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@ambari.apache.org
For additional commands, e-mail: commits-h...@ambari.apache.org

Reply via email to