diff options
author | Dan Timoney <dtimoney@att.com> | 2017-03-31 15:03:13 -0400 |
---|---|---|
committer | Dan Timoney <dtimoney@att.com> | 2017-03-31 15:11:48 -0400 |
commit | 974b67dd4021e6e839eaad25366bffe6d7a414c8 (patch) | |
tree | c16b969e86323ed8b0914253b1c74d42d31a7ed1 /sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/ExecuteNodeExecutor.java | |
parent | e0451f75b26082418757f279351c2d3e29c0a5c8 (diff) |
[SDNC-5] Rebase sdnc-core
Upgrade to OpenDaylight Boron release, and sync changes made since 16.10 release to ONAP SDN-C distribution
Change-Id: I20bef9e6d0008c4436b5624ce839bbb70ecc20a5
Signed-off-by: Dan Timoney <dtimoney@att.com>
Diffstat (limited to 'sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/ExecuteNodeExecutor.java')
-rw-r--r-- | sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/ExecuteNodeExecutor.java | 93 |
1 files changed, 68 insertions, 25 deletions
diff --git a/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/ExecuteNodeExecutor.java b/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/ExecuteNodeExecutor.java index 158c843..85aede7 100644 --- a/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/ExecuteNodeExecutor.java +++ b/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/ExecuteNodeExecutor.java @@ -21,6 +21,7 @@ package org.openecomp.sdnc.sli.provider; +import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.HashMap; import java.util.Iterator; @@ -44,6 +45,7 @@ public class ExecuteNodeExecutor extends SvcLogicNodeExecutor { private static final Logger LOG = LoggerFactory .getLogger(ExecuteNodeExecutor.class); + private static final String pluginErrorMessage = "Could not execute plugin. SvcLogic status will be set to failure."; public SvcLogicNode execute(SvcLogicServiceImpl svc, SvcLogicNode node, SvcLogicContext ctx) throws SvcLogicException { @@ -55,35 +57,30 @@ public class ExecuteNodeExecutor extends SvcLogicNodeExecutor { LOG.debug("execute node encountered - looking for plugin " + pluginName); } - - BundleContext bctx = FrameworkUtil.getBundle(this.getClass()) - .getBundleContext(); - ServiceReference sref = bctx.getServiceReference(pluginName); + SvcLogicJavaPlugin plugin = getSvcLogicJavaPlugin(pluginName); - if (sref == null) { + if (plugin == null) { outValue = "not-found"; } else { - SvcLogicJavaPlugin plugin = (SvcLogicJavaPlugin) bctx - .getService(sref); - - String methodName = SvcLogicExpressionResolver.evaluate(node.getAttribute("method"), node, ctx); - + + String methodName = evaluate(node.getAttribute("method"), node, ctx); + Class pluginClass = plugin.getClass(); - + Method pluginMethod = null; - + try { pluginMethod = pluginClass.getMethod(methodName, Map.class, SvcLogicContext.class); - } catch (Exception e) { - LOG.error("Caught exception looking for method "+pluginName+"."+methodName+"(Map, SvcLogicContext)"); + } catch (NoSuchMethodException e) { + LOG.error(pluginErrorMessage, e); } - + if (pluginMethod == null) { outValue = "unsupported-method"; } else { try { - + Map<String, String> parmMap = new HashMap<String, String>(); Set<Map.Entry<String, SvcLogicExpression>> parmSet = node @@ -95,21 +92,34 @@ public class ExecuteNodeExecutor extends SvcLogicNodeExecutor { String curName = curEnt.getKey(); SvcLogicExpression curExpr = curEnt.getValue(); String curExprValue = SvcLogicExpressionResolver.evaluate(curExpr, node, ctx); - + LOG.debug("Parameter "+curName+" = "+curExpr.asParsedExpr()+" resolves to "+curExprValue); parmMap.put(curName,curExprValue); } - - pluginMethod.invoke(plugin, parmMap, ctx); - - outValue = "success"; - } catch (Exception e) { - LOG.error("Caught exception executing "+pluginName+"."+methodName, e); - + + Object o = pluginMethod.invoke(plugin, parmMap, ctx); + String emitsOutcome = SvcLogicExpressionResolver.evaluate(node.getAttribute("emitsOutcome"), node, ctx); + + outValue = mapOutcome(o, emitsOutcome); + + } catch (InvocationTargetException e) { + if(e.getCause() != null){ + LOG.error(pluginErrorMessage, e.getCause()); + }else{ + LOG.error(pluginErrorMessage, e); + } outValue = "failure"; ctx.setStatus("failure"); - } + } catch (IllegalAccessException e) { + LOG.error(pluginErrorMessage, e); + outValue = "failure"; + ctx.setStatus("failure"); + } catch (IllegalArgumentException e) { + LOG.error(pluginErrorMessage, e); + outValue = "failure"; + ctx.setStatus("failure"); + } } } @@ -135,4 +145,37 @@ public class ExecuteNodeExecutor extends SvcLogicNodeExecutor { return (nextNode); } + protected SvcLogicJavaPlugin getSvcLogicJavaPlugin(String pluginName){ + BundleContext bctx = FrameworkUtil.getBundle(this.getClass()) + .getBundleContext(); + + ServiceReference sref = bctx.getServiceReference(pluginName); + + if (sref == null) { + LOG.warn("Could not find service reference object for plugin " + pluginName); + return null; + } else { + SvcLogicJavaPlugin plugin = (SvcLogicJavaPlugin) bctx + .getService(sref); + return plugin; + } + } + protected String evaluate(SvcLogicExpression expr, SvcLogicNode node, SvcLogicContext ctx) throws SvcLogicException { + return SvcLogicExpressionResolver.evaluate(node.getAttribute("method"), node, ctx); + } + + public String mapOutcome(Object o, String emitsOutcome) { + if (emitsOutcome != null) { + Boolean nodeEmitsOutcome = Boolean.valueOf(emitsOutcome); + if (nodeEmitsOutcome) { + return (String) o; + } else { + return "success"; + } + + } else { + return "success"; + } + } + } |