2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights
7 * ================================================================================
8 * Modifications Copyright (C) 2018 IBM.
9 * ================================================================================
10 * Licensed under the Apache License, Version 2.0 (the "License");
11 * you may not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
14 * http://www.apache.org/licenses/LICENSE-2.0
16 * Unless required by applicable law or agreed to in writing, software
17 * distributed under the License is distributed on an "AS IS" BASIS,
18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 * See the License for the specific language governing permissions and
20 * limitations under the License.
21 * ============LICENSE_END=========================================================
24 package org.onap.ccsdk.sli.core.sli.provider;
26 import java.util.Properties;
27 import org.onap.ccsdk.sli.core.dblib.DbLibService;
28 import org.onap.ccsdk.sli.core.sli.ConfigurationException;
29 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
30 import org.onap.ccsdk.sli.core.sli.SvcLogicDblibStore;
31 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
32 import org.onap.ccsdk.sli.core.sli.SvcLogicGraph;
33 import org.onap.ccsdk.sli.core.sli.SvcLogicStore;
34 import org.onap.ccsdk.sli.core.sli.SvcLogicStoreFactory;
35 import org.onap.ccsdk.sli.core.sli.provider.base.SvcLogicPropertiesProvider;
36 import org.onap.ccsdk.sli.core.sli.provider.base.SvcLogicResolver;
37 import org.onap.ccsdk.sli.core.sli.provider.base.SvcLogicServiceImplBase;
38 import org.onap.logging.ref.slf4j.ONAPLogConstants;
39 import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
40 import org.slf4j.Logger;
41 import org.slf4j.LoggerFactory;
44 public class SvcLogicServiceImpl extends SvcLogicServiceImplBase implements SvcLogicService {
46 private static final Logger LOG = LoggerFactory.getLogger(SvcLogicServiceImpl.class);
48 public SvcLogicServiceImpl(SvcLogicPropertiesProvider resourceProvider, SvcLogicResolver resolver)
49 throws SvcLogicException {
51 this.resolver = resolver;
52 properties = resourceProvider.getProperties();
53 this.store = getStore();
56 public SvcLogicServiceImpl(SvcLogicPropertiesProvider resourceProvider, DbLibService dbSvc,
57 SvcLogicResolver resolver) throws SvcLogicException {
59 this.resolver = resolver;
60 properties = resourceProvider.getProperties();
61 this.store = new SvcLogicDblibStore(dbSvc);
65 public Properties execute(String module, String rpc, String version, String mode, Properties props)
66 throws SvcLogicException {
67 SvcLogicGraph graph = store.fetch(module, rpc, version, mode);
70 Properties retProps = new Properties();
71 retProps.setProperty("error-code", "401");
72 retProps.setProperty("error-message",
73 "No service logic found for [" + module + "," + rpc + "," + version + "," + mode + "]");
77 SvcLogicContext ctx = new SvcLogicContext(props);
78 ctx.setAttribute(CURRENT_GRAPH, graph.toString());
79 // To support legacy code we should not stop populating X-ECOMP-RequestID
80 ctx.setAttribute("X-ECOMP-RequestID", MDC.get(ONAPLogConstants.MDCs.REQUEST_ID));
82 return (ctx.toProperties());
87 // DomDataBroker is not being used, this should be removed eventually
88 public Properties execute(String module, String rpc, String version, String mode, Properties props,
89 DOMDataBroker domDataBroker) throws SvcLogicException {
90 return (execute(module, rpc, version, mode, props));
94 public SvcLogicStore getStore() throws SvcLogicException {
95 // Create and initialize SvcLogicStore object - used to access
96 // saved service logic.
102 store = SvcLogicStoreFactory.getSvcLogicStore(properties);
103 } catch (Exception e) {
104 throw new ConfigurationException("Could not get service logic store", e);
109 store.init(properties);
110 } catch (SvcLogicException e) {
111 throw new ConfigurationException("Could not get service logic store", e);