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.Method;
25 import java.util.HashMap;
26 import java.util.Iterator;
30 import org.openecomp.sdnc.sli.SvcLogicAdaptor;
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.openecomp.sdnc.sli.SvcLogicResource;
37 import org.osgi.framework.BundleContext;
38 import org.osgi.framework.FrameworkUtil;
39 import org.osgi.framework.ServiceReference;
40 import org.slf4j.Logger;
41 import org.slf4j.LoggerFactory;
43 public class ExecuteNodeExecutor extends SvcLogicNodeExecutor {
44 private static final Logger LOG = LoggerFactory
45 .getLogger(ExecuteNodeExecutor.class);
47 public SvcLogicNode execute(SvcLogicServiceImpl svc, SvcLogicNode node,
48 SvcLogicContext ctx) throws SvcLogicException {
50 String pluginName = SvcLogicExpressionResolver.evaluate(
51 node.getAttribute("plugin"), node, ctx);
52 String outValue = "failure";
54 if (LOG.isDebugEnabled()) {
55 LOG.debug("execute node encountered - looking for plugin "
59 BundleContext bctx = FrameworkUtil.getBundle(this.getClass())
62 ServiceReference sref = bctx.getServiceReference(pluginName);
65 outValue = "not-found";
67 SvcLogicJavaPlugin plugin = (SvcLogicJavaPlugin) bctx
70 String methodName = SvcLogicExpressionResolver.evaluate(node.getAttribute("method"), node, ctx);
72 Class pluginClass = plugin.getClass();
74 Method pluginMethod = null;
77 pluginMethod = pluginClass.getMethod(methodName, Map.class, SvcLogicContext.class);
78 } catch (Exception e) {
79 LOG.error("Caught exception looking for method "+pluginName+"."+methodName+"(Map, SvcLogicContext)");
82 if (pluginMethod == null) {
83 outValue = "unsupported-method";
87 Map<String, String> parmMap = new HashMap<String, String>();
89 Set<Map.Entry<String, SvcLogicExpression>> parmSet = node
92 for (Iterator<Map.Entry<String, SvcLogicExpression>> iter = parmSet
93 .iterator(); iter.hasNext();) {
94 Map.Entry<String, SvcLogicExpression> curEnt = iter.next();
95 String curName = curEnt.getKey();
96 SvcLogicExpression curExpr = curEnt.getValue();
97 String curExprValue = SvcLogicExpressionResolver.evaluate(curExpr, node, ctx);
99 LOG.debug("Parameter "+curName+" = "+curExpr.asParsedExpr()+" resolves to "+curExprValue);
101 parmMap.put(curName,curExprValue);
104 pluginMethod.invoke(plugin, parmMap, ctx);
106 outValue = "success";
107 } catch (Exception e) {
108 LOG.error("Caught exception executing "+pluginName+"."+methodName, e);
110 outValue = "failure";
111 ctx.setStatus("failure");
117 SvcLogicNode nextNode = node.getOutcomeValue(outValue);
118 if (nextNode != null) {
119 if (LOG.isDebugEnabled()) {
120 LOG.debug("about to execute " + outValue + " branch");
125 nextNode = node.getOutcomeValue("Other");
126 if (nextNode != null) {
127 if (LOG.isDebugEnabled()) {
128 LOG.debug("about to execute Other branch");
131 if (LOG.isDebugEnabled()) {
132 LOG.debug("no " + outValue + " or Other branch found");