2ce4f0a98fc18f364b9ad948690b37387fe3e107
[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                 
118                 SvcLogicStore store = SvcLogicActivator.getStore();
119                 
120                 LOG.debug("Calling ["+module+","+rpc+","+version+","+mode+"]");
121                 
122                 if (store != null)
123                 {
124                         SvcLogicGraph calledGraph = store.fetch(module, rpc, version, mode);
125                         
126                         if (calledGraph != null)
127                         {
128                                 svc.execute(calledGraph, ctx);
129                                 
130                                 outValue = ctx.getStatus();
131                         }
132                         else
133                         {
134                                 LOG.debug("Could not find service logic for ["+module+","+rpc+","+version+","+mode+"]");
135                         }
136                 }
137                 else
138                 {
139                         LOG.debug("Could not get SvcLogicStore reference");
140                 }
141                 
142                 SvcLogicNode nextNode = node.getOutcomeValue(outValue);
143                 if (nextNode != null) {
144                         if (LOG.isDebugEnabled()) {
145                                 LOG.debug("about to execute " + outValue + " branch");
146                         }
147                         return (nextNode);
148                 }
149
150                 nextNode = node.getOutcomeValue("Other");
151                 if (nextNode != null) {
152                         if (LOG.isDebugEnabled()) {
153                                 LOG.debug("about to execute Other branch");
154                         }
155                 } else {
156                         if (LOG.isDebugEnabled()) {
157                                 LOG.debug("no " + outValue + " or Other branch found");
158                         }
159                 }
160                 return (nextNode);
161
162         }
163
164
165 }