minor changes to sli
[ccsdk/sli/core.git] / sli / provider-base / src / main / java / org / onap / ccsdk / sli / core / sli / provider / base / RecordNodeExecutor.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : CCSDK
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.onap.ccsdk.sli.core.sli.provider.base;
23
24 import java.util.HashMap;
25 import java.util.Iterator;
26 import java.util.Map;
27 import java.util.Set;
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 AbstractSvcLogicNodeExecutor {
37
38     private static final Logger LOG = LoggerFactory.getLogger(RecordNodeExecutor.class);
39
40     @Override
41     public SvcLogicNode execute(SvcLogicServiceBase svc, SvcLogicNode node, SvcLogicContext ctx)
42             throws SvcLogicException {
43
44         String plugin = SvcLogicExpressionResolver.evaluate(node.getAttribute("plugin"), node, ctx);
45         String outValue = "failure";
46
47         if (LOG.isTraceEnabled()) {
48             LOG.trace(node.getNodeType() + " node encountered - looking for recorder class " + plugin);
49         }
50
51         Map<String, String> parmMap = new HashMap<String, String>();
52
53         Set<Map.Entry<String, SvcLogicExpression>> parmSet = node.getParameterSet();
54         boolean hasParms = false;
55
56         for (Iterator<Map.Entry<String, SvcLogicExpression>> iter = parmSet.iterator(); iter.hasNext();) {
57             hasParms = true;
58             Map.Entry<String, SvcLogicExpression> curEnt = iter.next();
59             String curName = curEnt.getKey();
60             SvcLogicExpression curExpr = curEnt.getValue();
61             String curExprValue = SvcLogicExpressionResolver.evaluate(curExpr, node, ctx);
62
63             if (LOG.isTraceEnabled()) {
64                 LOG.trace("executeRecordNode : parameter " + curName + " = " + curExpr + " => " + curExprValue);
65             }
66             parmMap.put(curName, curExprValue);
67         }
68
69         SvcLogicRecorder recorder = getSvcLogicRecorder(plugin);
70         if (recorder != null) {
71             try {
72                 recorder.record(parmMap);
73             } catch (SvcLogicException e) {
74                 LOG.error("Caught exception from recorder plugin", e);
75                 outValue = "failure";
76             }
77         } else {
78             LOG.warn("Could not find SvcLogicRecorder object for plugin " + plugin);
79         }
80         return (getNextNode(node, outValue));
81     }
82 }