2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights
7 * ================================================================================
8 * Modifications Copyright (C) 2018 IBM.
9 * ================================================================================
10 * Licensed under the Apache License, Version 2.0 (the "License");
11 * you may not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
14 * http://www.apache.org/licenses/LICENSE-2.0
16 * Unless required by applicable law or agreed to in writing, software
17 * distributed under the License is distributed on an "AS IS" BASIS,
18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 * See the License for the specific language governing permissions and
20 * limitations under the License.
21 * ============LICENSE_END=========================================================
24 package org.onap.ccsdk.sli.core.sli.provider.base;
26 import java.lang.reflect.InvocationTargetException;
27 import java.lang.reflect.Method;
28 import java.util.HashMap;
29 import java.util.Iterator;
33 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
34 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
35 import org.onap.ccsdk.sli.core.sli.SvcLogicExpression;
36 import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin;
37 import org.onap.ccsdk.sli.core.sli.SvcLogicNode;
38 import org.slf4j.Logger;
39 import org.slf4j.LoggerFactory;
41 public class ExecuteNodeExecutor extends AbstractSvcLogicNodeExecutor {
42 private static final Logger LOG = LoggerFactory
43 .getLogger(ExecuteNodeExecutor.class);
44 private static final String FAILURE="failure";
46 private static final String pluginErrorMessage = "Could not execute plugin. SvcLogic status will be set to failure.";
47 public SvcLogicNode execute(SvcLogicServiceBase 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 SvcLogicJavaPlugin plugin = getSvcLogicJavaPlugin(pluginName);
62 outValue = "not-found";
65 String methodName = evaluate(node.getAttribute("method"), node, ctx);
67 Class pluginClass = plugin.getClass();
69 Method pluginMethod = null;
72 pluginMethod = pluginClass.getMethod(methodName, Map.class, SvcLogicContext.class);
73 } catch (NoSuchMethodException e) {
74 LOG.error(pluginErrorMessage, e);
77 if (pluginMethod == null) {
78 outValue = "unsupported-method";
83 Map<String, String> parmMap = getResolvedParameters(node,ctx);
84 Object o = pluginMethod.invoke(plugin, parmMap, ctx);
85 String emitsOutcome = SvcLogicExpressionResolver.evaluate(node.getAttribute("emitsOutcome"), node, ctx);
87 outValue = mapOutcome(o, emitsOutcome);
89 } catch (InvocationTargetException e) {
90 if(e.getCause() != null){
91 LOG.error(pluginErrorMessage, e.getCause());
93 LOG.error(pluginErrorMessage, e);
96 ctx.setStatus(FAILURE);
97 } catch (IllegalAccessException e) {
98 LOG.error(pluginErrorMessage, e);
100 ctx.setStatus(FAILURE);
101 } catch (IllegalArgumentException e) {
102 LOG.error(pluginErrorMessage, e);
104 ctx.setStatus(FAILURE);
109 return (getNextNode(node, outValue));
112 protected String evaluate(SvcLogicExpression expr, SvcLogicNode node, SvcLogicContext ctx) throws SvcLogicException {
113 return SvcLogicExpressionResolver.evaluate(node.getAttribute("method"), node, ctx);
116 public String mapOutcome(Object o, String emitsOutcome) {
117 if (emitsOutcome != null) {
118 Boolean nodeEmitsOutcome = Boolean.valueOf(emitsOutcome);
119 if (nodeEmitsOutcome) {