2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 ONAP
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.ccsdk.sli.core.sli.provider;
23 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
24 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
25 import org.onap.ccsdk.sli.core.sli.SvcLogicExpression;
26 import org.onap.ccsdk.sli.core.sli.SvcLogicGraph;
27 import org.onap.ccsdk.sli.core.sli.SvcLogicNode;
28 import org.onap.ccsdk.sli.core.sli.SvcLogicStore;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
32 public class CallNodeExecutor extends SvcLogicNodeExecutor {
34 private static final Logger LOG = LoggerFactory
35 .getLogger(CallNodeExecutor.class);
38 public SvcLogicNode execute(SvcLogicServiceImpl svc, SvcLogicNode node, SvcLogicContext ctx)
39 throws SvcLogicException {
41 String outValue = "not-found";
43 SvcLogicGraph myGraph = node.getGraph();
47 LOG.debug("execute: getGraph returned null");
51 LOG.debug("execute: got SvcLogicGraph");
54 SvcLogicExpression moduleExpr = null;
58 moduleExpr = node.getAttribute("module");
59 if (moduleExpr != null)
61 module = SvcLogicExpressionResolver.evaluate(moduleExpr, node, ctx);
64 if ((module == null) || (module.length() == 0))
68 module = myGraph.getModule();
69 LOG.debug("myGraph.getModule() returned "+module);
73 SvcLogicExpression rpcExpr = null;
75 rpcExpr = node.getAttribute("rpc");
78 rpc = SvcLogicExpressionResolver.evaluate(rpcExpr, node, ctx);
81 if ((rpc == null) || (rpc.length() == 0))
85 rpc = myGraph.getRpc();
86 LOG.debug("myGraph.getRpc() returned "+rpc);
92 moduleExpr = node.getAttribute("mode");
93 if (moduleExpr != null)
95 mode = SvcLogicExpressionResolver.evaluate(moduleExpr, node, ctx);
98 if ((mode == null) || (mode.length() == 0))
102 mode = myGraph.getMode();
104 LOG.debug("myGraph.getMode() returned "+mode);
108 String version = null;
110 moduleExpr = node.getAttribute("version");
111 if (moduleExpr != null)
113 version = SvcLogicExpressionResolver.evaluate(moduleExpr, node, ctx);
116 String parentGraph = ctx.getAttribute("currentGraph");
117 ctx.setAttribute("parentGraph", parentGraph);
119 SvcLogicStore store = getStore();
122 SvcLogicGraph calledGraph = store.fetch(module, rpc, version, mode);
123 LOG.debug("Parent " + parentGraph + " is calling child " + calledGraph.toString());
124 ctx.setAttribute("currentGraph", calledGraph.toString());
125 if (calledGraph != null) {
126 svc.execute(calledGraph, ctx);
128 outValue = ctx.getStatus();
130 LOG.error("Could not find service logic for [" + module + "," + rpc + "," + version + "," + mode + "]");
135 LOG.debug("Could not get SvcLogicStore reference");
138 SvcLogicNode nextNode = node.getOutcomeValue(outValue);
139 if (nextNode != null) {
140 if (LOG.isDebugEnabled()) {
141 LOG.debug("about to execute " + outValue + " branch");
143 ctx.setAttribute("currentGraph", parentGraph);
147 nextNode = node.getOutcomeValue("Other");
148 if (nextNode != null) {
149 if (LOG.isDebugEnabled()) {
150 LOG.debug("about to execute Other branch");
153 if (LOG.isDebugEnabled()) {
154 LOG.debug("no " + outValue + " or Other branch found");
157 ctx.setAttribute("currentGraph", parentGraph);
158 ctx.setAttribute("parentGraph", null);