2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.openecomp.sdnc.sli.provider;
24 import java.lang.reflect.InvocationTargetException;
25 import java.lang.reflect.Method;
26 import java.util.HashMap;
27 import java.util.Iterator;
31 import org.openecomp.sdnc.sli.SvcLogicContext;
32 import org.openecomp.sdnc.sli.SvcLogicException;
33 import org.openecomp.sdnc.sli.SvcLogicExpression;
34 import org.openecomp.sdnc.sli.SvcLogicJavaPlugin;
35 import org.openecomp.sdnc.sli.SvcLogicNode;
36 import org.slf4j.Logger;
37 import org.slf4j.LoggerFactory;
39 public class ExecuteNodeExecutor extends SvcLogicNodeExecutor {
40 private static final Logger LOG = LoggerFactory
41 .getLogger(ExecuteNodeExecutor.class);
43 private static final String pluginErrorMessage = "Could not execute plugin. SvcLogic status will be set to failure.";
44 public SvcLogicNode execute(SvcLogicServiceImpl svc, SvcLogicNode node,
45 SvcLogicContext ctx) throws SvcLogicException {
47 String pluginName = SvcLogicExpressionResolver.evaluate(
48 node.getAttribute("plugin"), node, ctx);
49 String outValue = "failure";
51 if (LOG.isDebugEnabled()) {
52 LOG.debug("execute node encountered - looking for plugin "
56 SvcLogicJavaPlugin plugin = getSvcLogicJavaPlugin(pluginName);
59 outValue = "not-found";
62 String methodName = evaluate(node.getAttribute("method"), node, ctx);
64 Class pluginClass = plugin.getClass();
66 Method pluginMethod = null;
69 pluginMethod = pluginClass.getMethod(methodName, Map.class, SvcLogicContext.class);
70 } catch (NoSuchMethodException e) {
71 LOG.error(pluginErrorMessage, e);
74 if (pluginMethod == null) {
75 outValue = "unsupported-method";
79 Map<String, String> parmMap = new HashMap<String, String>();
81 Set<Map.Entry<String, SvcLogicExpression>> parmSet = node
84 for (Iterator<Map.Entry<String, SvcLogicExpression>> iter = parmSet
85 .iterator(); iter.hasNext();) {
86 Map.Entry<String, SvcLogicExpression> curEnt = iter.next();
87 String curName = curEnt.getKey();
88 SvcLogicExpression curExpr = curEnt.getValue();
89 String curExprValue = SvcLogicExpressionResolver.evaluate(curExpr, node, ctx);
91 LOG.debug("Parameter "+curName+" = "+curExpr.asParsedExpr()+" resolves to "+curExprValue);
93 parmMap.put(curName,curExprValue);
96 Object o = pluginMethod.invoke(plugin, parmMap, ctx);
97 String emitsOutcome = SvcLogicExpressionResolver.evaluate(node.getAttribute("emitsOutcome"), node, ctx);
99 outValue = mapOutcome(o, emitsOutcome);
101 } catch (InvocationTargetException e) {
102 if(e.getCause() != null){
103 LOG.error(pluginErrorMessage, e.getCause());
105 LOG.error(pluginErrorMessage, e);
107 outValue = "failure";
108 ctx.setStatus("failure");
109 } catch (IllegalAccessException e) {
110 LOG.error(pluginErrorMessage, e);
111 outValue = "failure";
112 ctx.setStatus("failure");
113 } catch (IllegalArgumentException e) {
114 LOG.error(pluginErrorMessage, e);
115 outValue = "failure";
116 ctx.setStatus("failure");
122 SvcLogicNode nextNode = node.getOutcomeValue(outValue);
123 if (nextNode != null) {
124 if (LOG.isDebugEnabled()) {
125 LOG.debug("about to execute " + outValue + " branch");
130 nextNode = node.getOutcomeValue("Other");
131 if (nextNode != null) {
132 if (LOG.isDebugEnabled()) {
133 LOG.debug("about to execute Other branch");
136 if (LOG.isDebugEnabled()) {
137 LOG.debug("no " + outValue + " or Other branch found");
143 protected String evaluate(SvcLogicExpression expr, SvcLogicNode node, SvcLogicContext ctx) throws SvcLogicException {
144 return SvcLogicExpressionResolver.evaluate(node.getAttribute("method"), node, ctx);
147 public String mapOutcome(Object o, String emitsOutcome) {
148 if (emitsOutcome != null) {
149 Boolean nodeEmitsOutcome = Boolean.valueOf(emitsOutcome);
150 if (nodeEmitsOutcome) {