7b79c19f6b8d993051060777d52e0a2487eb1fc2
[sdnc/core.git] / sli / provider / src / main / java / org / openecomp / sdnc / sli / provider / CallNodeExecutor.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * openECOMP : SDN-C
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights
6  *                                              reserved.
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
11  * 
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  * 
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=========================================================
20  */
21
22 package org.openecomp.sdnc.sli.provider;
23
24 import org.openecomp.sdnc.sli.SvcLogicContext;
25 import org.openecomp.sdnc.sli.SvcLogicException;
26 import org.openecomp.sdnc.sli.SvcLogicExpression;
27 import org.openecomp.sdnc.sli.SvcLogicGraph;
28 import org.openecomp.sdnc.sli.SvcLogicNode;
29 import org.openecomp.sdnc.sli.SvcLogicStore;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
32
33 public class CallNodeExecutor extends SvcLogicNodeExecutor {
34
35         private static final Logger LOG = LoggerFactory
36                         .getLogger(CallNodeExecutor.class);
37         
38         @Override
39         public SvcLogicNode execute(SvcLogicServiceImpl svc, SvcLogicNode node, SvcLogicContext ctx)
40                         throws SvcLogicException {
41
42                 String outValue = "not-found";
43                 
44                 SvcLogicGraph myGraph = node.getGraph();
45                 
46                 if (myGraph == null)
47                 {
48                         LOG.debug("execute: getGraph returned null");
49                 }
50                 else
51                 {
52                         LOG.debug("execute: got SvcLogicGraph");
53                 }
54                 
55                 SvcLogicExpression moduleExpr = null;
56                 
57                 String module = null;
58                 
59                 moduleExpr = node.getAttribute("module");
60                 if (moduleExpr != null)
61                 {
62                         module  = SvcLogicExpressionResolver.evaluate(moduleExpr, node, ctx);
63                 }
64                 
65                 if ((module == null) || (module.length() == 0))
66                 {
67                         if (myGraph != null)
68                         {
69                                 module = myGraph.getModule();
70                                 LOG.debug("myGraph.getModule() returned "+module);
71                         }
72                 }
73                 
74                 SvcLogicExpression rpcExpr = null;
75                 String rpc = null;
76                 rpcExpr = node.getAttribute("rpc");
77                 if (rpcExpr != null)
78                 {
79                         rpc  = SvcLogicExpressionResolver.evaluate(rpcExpr, node, ctx);
80                 }
81                 
82                 if ((rpc == null) || (rpc.length() == 0))
83                 {
84                         if (myGraph != null)
85                         {
86                                 rpc = myGraph.getRpc();
87                                 LOG.debug("myGraph.getRpc() returned "+rpc);
88                         }
89                 }
90                 
91                 String mode = null;
92                 
93                 moduleExpr = node.getAttribute("mode");
94                 if (moduleExpr != null)
95                 {
96                         mode  = SvcLogicExpressionResolver.evaluate(moduleExpr, node, ctx);
97                 }
98
99                 if ((mode == null) || (mode.length() == 0))
100                 {
101                         if (myGraph != null)
102                         {
103                                 mode = myGraph.getMode();
104
105                                 LOG.debug("myGraph.getMode() returned "+mode);
106                         }
107                 }
108                 
109                 String version = null;
110                 
111                 moduleExpr = node.getAttribute("version");
112                 if (moduleExpr != null)
113                 {
114                         version  = SvcLogicExpressionResolver.evaluate(moduleExpr, node, ctx);
115                 }
116
117                 String parentGraph = ctx.getAttribute("currentGraph");
118         ctx.setAttribute("parentGraph", parentGraph);
119                 
120                 SvcLogicStore store = getStore();
121                 
122         if (store != null) {
123                         SvcLogicGraph calledGraph = store.fetch(module, rpc, version, mode);
124             LOG.debug("Parent " + parentGraph + " is calling child " + calledGraph.toString());
125             ctx.setAttribute("currentGraph", calledGraph.toString());
126             if (calledGraph != null) {
127                                 svc.execute(calledGraph, ctx);
128                                 
129                                 outValue = ctx.getStatus();
130             } else {
131                 LOG.error("Could not find service logic for [" + module + "," + rpc + "," + version + "," + mode + "]");
132                         }
133                 }
134                 else
135                 {
136                         LOG.debug("Could not get SvcLogicStore reference");
137                 }
138                 
139                 SvcLogicNode nextNode = node.getOutcomeValue(outValue);
140                 if (nextNode != null) {
141                         if (LOG.isDebugEnabled()) {
142                                 LOG.debug("about to execute " + outValue + " branch");
143                         }
144             ctx.setAttribute("currentGraph", parentGraph);
145                         return (nextNode);
146                 }
147
148                 nextNode = node.getOutcomeValue("Other");
149                 if (nextNode != null) {
150                         if (LOG.isDebugEnabled()) {
151                                 LOG.debug("about to execute Other branch");
152                         }
153                 } else {
154                         if (LOG.isDebugEnabled()) {
155                                 LOG.debug("no " + outValue + " or Other branch found");
156                         }
157                 }
158         ctx.setAttribute("currentGraph", parentGraph);
159         ctx.setAttribute("parentGraph", null);
160
161                 return (nextNode);
162
163         }
164
165 }