Update groupId to org.onap.ccsdk.sli
[ccsdk/sli/core.git] / sli / provider / src / main / java / org / openecomp / sdnc / sli / provider / RecordNodeExecutor.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 java.util.HashMap;
25 import java.util.Iterator;
26 import java.util.Map;
27 import java.util.Set;
28
29 import org.openecomp.sdnc.sli.SvcLogicContext;
30 import org.openecomp.sdnc.sli.SvcLogicException;
31 import org.openecomp.sdnc.sli.SvcLogicExpression;
32 import org.openecomp.sdnc.sli.SvcLogicNode;
33 import org.openecomp.sdnc.sli.SvcLogicRecorder;
34 import org.slf4j.Logger;
35 import org.slf4j.LoggerFactory;
36
37 public class RecordNodeExecutor extends SvcLogicNodeExecutor {
38
39         private static final Logger LOG = LoggerFactory
40                         .getLogger(RecordNodeExecutor.class);
41         
42         @Override
43         public SvcLogicNode execute(SvcLogicServiceImpl svc, SvcLogicNode node,
44                         SvcLogicContext ctx) throws SvcLogicException {
45
46                 String plugin = SvcLogicExpressionResolver.evaluate(
47                                 node.getAttribute("plugin"), node, ctx);
48                 String outValue = "failure";
49
50                 if (LOG.isTraceEnabled()) {
51                         LOG.trace(node.getNodeType()
52                                         + " node encountered - looking for recorder class "
53                                         + plugin);
54                 }
55
56                 Map<String, String> parmMap = new HashMap<String, String>();
57
58                 Set<Map.Entry<String, SvcLogicExpression>> parmSet = node
59                                 .getParameterSet();
60                 boolean hasParms = false;
61
62                 for (Iterator<Map.Entry<String, SvcLogicExpression>> iter = parmSet
63                                 .iterator(); iter.hasNext();) {
64                         hasParms = true;
65                         Map.Entry<String, SvcLogicExpression> curEnt = iter.next();
66                         String curName = curEnt.getKey();
67                         SvcLogicExpression curExpr = curEnt.getValue();
68                         String curExprValue = SvcLogicExpressionResolver.evaluate(curExpr,
69                                         node, ctx);
70
71                         if (LOG.isTraceEnabled()) {
72                                 LOG.trace("executeRecordNode : parameter " + curName + " = "
73                                                 + curExpr + " => " + curExprValue);
74                         }
75                         parmMap.put(curName, curExprValue);
76                 }
77
78
79                         SvcLogicRecorder recorder = getSvcLogicRecorder(plugin);
80
81                         if (recorder != null) {
82
83                                 try {
84                                         recorder.record(parmMap);
85                                 } catch (SvcLogicException e) {
86                                         LOG.error("Caught exception from recorder plugin", e);
87                                         outValue = "failure";
88                                 }
89                         } else {
90                                 LOG.warn("Could not find SvcLogicRecorder object for plugin "
91                                                 + plugin);
92                         }
93
94                 SvcLogicNode nextNode = node.getOutcomeValue(outValue);
95                 if (nextNode != null) {
96                         if (LOG.isDebugEnabled()) {
97                                 LOG.debug("about to execute " + outValue + " branch");
98                         }
99                         return (nextNode);
100                 }
101
102                 nextNode = node.getOutcomeValue("Other");
103                 if (nextNode != null) {
104                         if (LOG.isDebugEnabled()) {
105                                 LOG.debug("about to execute Other branch");
106                         }
107                 } else {
108                         if (LOG.isTraceEnabled()) {
109                                 LOG.trace("no failure or Other branch found");
110                         }
111                 }
112                 return (nextNode);
113         }
114
115
116
117
118
119 }