SDNC-11 merge
[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                 String mode = null;
83                 
84                 moduleExpr = node.getAttribute("mode");
85                 if (moduleExpr != null)
86                 {
87                         mode  = SvcLogicExpressionResolver.evaluate(moduleExpr, node, ctx);
88                 }
89
90                 if ((mode == null) || (mode.length() == 0))
91                 {
92                         if (myGraph != null)
93                         {
94                                 mode = myGraph.getMode();
95
96                                 LOG.debug("myGraph.getMode() returned "+mode);
97                         }
98                 }
99                 
100                 String version = null;
101                 
102                 moduleExpr = node.getAttribute("version");
103                 if (moduleExpr != null)
104                 {
105                         version  = SvcLogicExpressionResolver.evaluate(moduleExpr, node, ctx);
106                 }
107
108                 String parentGraph = ctx.getAttribute("currentGraph");
109         ctx.setAttribute("parentGraph", parentGraph);
110                 
111                 SvcLogicStore store = SvcLogicActivator.getStore();
112                 
113         if (store != null) {
114             SvcLogicGraph calledGraph = store.fetch(module, rpc, version, mode);
115             if (calledGraph != null) {
116                 svc.execute(calledGraph, ctx);
117                 LOG.debug("Parent " + parentGraph + " is calling child " + calledGraph.toString());
118                 ctx.setAttribute("currentGraph", calledGraph.toString());
119                 outValue = ctx.getStatus();
120             } else {
121                 LOG.debug("Parent " + parentGraph + " failed to call child [" + module + "," + rpc + "," + version + "," + mode + "] because the graph could not be found");
122             }
123         } else {
124             LOG.debug("Could not get SvcLogicStore reference");
125         }
126                 
127                 SvcLogicNode nextNode = node.getOutcomeValue(outValue);
128                 if (nextNode != null) {
129                         if (LOG.isDebugEnabled()) {
130                                 LOG.debug("about to execute " + outValue + " branch");
131                         }
132             ctx.setAttribute("currentGraph", parentGraph);
133                         return (nextNode);
134                 }
135
136                 nextNode = node.getOutcomeValue("Other");
137                 if (nextNode != null) {
138                         if (LOG.isDebugEnabled()) {
139                                 LOG.debug("about to execute Other branch");
140                         }
141                 } else {
142                         if (LOG.isDebugEnabled()) {
143                                 LOG.debug("no " + outValue + " or Other branch found");
144                         }
145                 }
146         ctx.setAttribute("currentGraph", parentGraph);
147         ctx.setAttribute("parentGraph", null);
148
149                 return (nextNode);
150
151         }
152
153
154 }