minor changes to sli
[ccsdk/sli/core.git] / sli / provider-base / src / main / java / org / onap / ccsdk / sli / core / sli / provider / base / AbstractSvcLogicNodeExecutor.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 org.onap.ccsdk.sli.core.sli.MetricLogger;
25 import org.onap.ccsdk.sli.core.sli.SvcLogicAdaptor;
26 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
27 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
28 import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin;
29 import org.onap.ccsdk.sli.core.sli.SvcLogicNode;
30 import org.onap.ccsdk.sli.core.sli.SvcLogicRecorder;
31 import org.onap.ccsdk.sli.core.sli.SvcLogicResource;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
34
35 public abstract class AbstractSvcLogicNodeExecutor {
36         protected SvcLogicResolver resolver;
37         public abstract SvcLogicNode execute(SvcLogicServiceBase svc, SvcLogicNode node, SvcLogicContext ctx) throws SvcLogicException;
38
39         private static final Logger LOG = LoggerFactory.getLogger(AbstractSvcLogicNodeExecutor.class);
40
41     protected String evaluateNodeTest(SvcLogicNode node, SvcLogicContext ctx)
42                         throws SvcLogicException {
43                 if (node == null) {
44                         return null;
45                 }
46
47                 return (SvcLogicExpressionResolver.evaluate(node.getAttribute("test"),
48                                 node, ctx));
49
50         }
51
52     public void setResolver(SvcLogicResolver resolver) {
53                 this.resolver = resolver;
54         }
55
56         protected SvcLogicAdaptor getAdaptor(String adaptorName) {
57         return resolver.getSvcLogicAdaptor(adaptorName);
58     }
59
60     protected SvcLogicResource getSvcLogicResource(String resourceName) {
61         return resolver.getSvcLogicResource(resourceName);
62     }
63
64     protected SvcLogicRecorder getSvcLogicRecorder(String recorderName) {
65         return resolver.getSvcLogicRecorder(recorderName);
66     }
67
68     protected SvcLogicJavaPlugin getSvcLogicJavaPlugin(String pluginName){
69         return resolver.getSvcLogicJavaPlugin(pluginName);
70     }
71
72     protected SvcLogicNode getNextNode(SvcLogicNode node, String outValue) {
73         MetricLogger.resetContext();
74         SvcLogicNode nextNode = node.getOutcomeValue(outValue);
75         if (nextNode != null) {
76             if (LOG.isDebugEnabled()) {
77                 LOG.debug("about to execute " + outValue + " branch");
78             }
79             return (nextNode);
80         }
81
82         nextNode = node.getOutcomeValue("Other");
83         if (nextNode != null) {
84             if (LOG.isDebugEnabled()) {
85                 LOG.debug("about to execute Other branch");
86             }
87         } else {
88             if (LOG.isDebugEnabled()) {
89                 LOG.debug("no " + outValue + " or Other branch found");
90             }
91         }
92         return (nextNode);
93     }
94     
95 }