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