2 * ============LICENSE_START=======================================================
\r
4 * ================================================================================
\r
5 * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
\r
6 * ================================================================================
\r
7 * Licensed under the Apache License, Version 2.0 (the "License");
\r
8 * you may not use this file except in compliance with the License.
\r
9 * You may obtain a copy of the License at
\r
11 * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * Unless required by applicable law or agreed to in writing, software
\r
14 * distributed under the License is distributed on an "AS IS" BASIS,
\r
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 * See the License for the specific language governing permissions and
\r
17 * limitations under the License.
\r
18 * ============LICENSE_END=========================================================
\r
21 package org.onap.ccsdk.apps.services;
\r
23 import java.io.File;
\r
24 import java.io.FileInputStream;
\r
25 import java.io.FileReader;
\r
26 import java.io.IOException;
\r
27 import java.io.InputStream;
\r
28 import java.util.List;
\r
29 import java.util.Properties;
\r
31 import org.onap.ccsdk.sli.adaptors.aai.AAIService;
\r
32 import org.onap.ccsdk.sli.adaptors.aai.AAIServiceProvider;
\r
33 import org.onap.ccsdk.sli.adaptors.messagerouter.publisher.api.PublisherApi;
\r
34 import org.onap.ccsdk.sli.adaptors.messagerouter.publisher.provider.impl.PublisherApiImpl;
\r
35 import org.onap.ccsdk.sli.adaptors.netbox.api.NetboxClient;
\r
36 import org.onap.ccsdk.sli.adaptors.netbox.impl.NetboxClientImpl;
\r
37 import org.onap.ccsdk.sli.adaptors.netbox.impl.NetboxHttpClient;
\r
38 import org.onap.ccsdk.sli.adaptors.netbox.property.NetboxProperties;
\r
39 import org.onap.ccsdk.sli.adaptors.resource.mdsal.ConfigResource;
\r
40 import org.onap.ccsdk.sli.adaptors.resource.mdsal.MdsalResourcePropertiesProviderImpl;
\r
41 import org.onap.ccsdk.sli.adaptors.resource.mdsal.OperationalResource;
\r
42 import org.onap.ccsdk.sli.adaptors.resource.sql.SqlResource;
\r
43 import org.onap.ccsdk.sli.core.dblib.DBLIBResourceProvider;
\r
44 import org.onap.ccsdk.sli.core.dblib.DBResourceManager;
\r
45 import org.onap.ccsdk.sli.core.dblib.DbLibService;
\r
46 import org.onap.ccsdk.sli.core.sli.ConfigurationException;
\r
47 import org.onap.ccsdk.sli.core.sli.SvcLogicAdaptor;
\r
48 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
\r
49 import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin;
\r
50 import org.onap.ccsdk.sli.core.sli.SvcLogicLoader;
\r
51 import org.onap.ccsdk.sli.core.sli.SvcLogicRecorder;
\r
52 import org.onap.ccsdk.sli.core.sli.SvcLogicResource;
\r
53 import org.onap.ccsdk.sli.core.sli.SvcLogicStore;
\r
54 import org.onap.ccsdk.sli.core.sli.SvcLogicStoreFactory;
\r
55 import org.onap.ccsdk.sli.core.sli.provider.base.HashMapResolver;
\r
56 import org.onap.ccsdk.sli.core.sli.provider.base.SvcLogicPropertiesProvider;
\r
57 import org.onap.ccsdk.sli.core.sli.provider.base.SvcLogicServiceBase;
\r
58 import org.onap.ccsdk.sli.core.sli.provider.base.SvcLogicServiceImplBase;
\r
59 import org.onap.ccsdk.sli.core.sli.recording.Slf4jRecorder;
\r
60 import org.onap.ccsdk.sli.core.slipluginutils.SliPluginUtils;
\r
61 import org.onap.ccsdk.sli.core.slipluginutils.SliStringUtils;
\r
62 import org.onap.ccsdk.sli.core.utils.common.EnvProperties;
\r
63 import org.onap.ccsdk.sli.plugins.prop.PropertiesNode;
\r
64 import org.onap.ccsdk.sli.plugins.restapicall.RestapiCallNode;
\r
65 import org.slf4j.Logger;
\r
66 import org.slf4j.LoggerFactory;
\r
67 import org.springframework.beans.factory.annotation.Autowired;
\r
68 import org.springframework.context.annotation.Bean;
\r
69 import org.springframework.context.annotation.Configuration;
\r
70 import org.springframework.stereotype.Service;
\r
74 public class SvcLogicFactory {
\r
75 private static final Logger log = LoggerFactory.getLogger(SvcLogicFactory.class);
\r
76 private static final String SDNC_CONFIG_DIR = "SDNC_CONFIG_DIR";
\r
77 private static final String CONTRAIL_PROPERTIES = "contrail-adaptor.properties";
\r
80 * In Springboot 2.6, these autowired lists become a circular dependency with the RestconfApiController.
\r
81 * For now, comment these out and instead just explicitly add wiring for the sli classes
\r
83 List<SvcLogicRecorder> recorders;
\r
86 List<SvcLogicJavaPlugin> plugins;
\r
89 List<SvcLogicResource> svcLogicResources;
\r
97 public SvcLogicStore getStore() throws Exception {
\r
98 SvcLogicPropertiesProvider propProvider = new SvcLogicPropertiesProvider() {
\r
101 public Properties getProperties() {
\r
102 Properties props = new Properties();
\r
104 String propPath = System.getProperty("serviceLogicProperties", "");
\r
106 if ("".equals(propPath)) {
\r
107 propPath = System.getenv("SVCLOGIC_PROPERTIES");
\r
110 if ((propPath == null) || propPath.length() == 0) {
\r
111 propPath = "src/main/resources/svclogic.properties";
\r
113 System.out.println(propPath);
\r
114 try (FileInputStream fileInputStream = new FileInputStream(propPath)) {
\r
115 props = new EnvProperties();
\r
116 props.load(fileInputStream);
\r
117 } catch (final IOException e) {
\r
118 log.error("Failed to load properties for file: {}", propPath,
\r
119 new ConfigurationException("Failed to load properties for file: " + propPath, e));
\r
124 SvcLogicStore store = SvcLogicStoreFactory.getSvcLogicStore(propProvider.getProperties());
\r
129 public SvcLogicLoader createLoader() throws Exception {
\r
130 String serviceLogicDirectory = System.getProperty("serviceLogicDirectory");
\r
131 if (serviceLogicDirectory == null) {
\r
132 serviceLogicDirectory = "src/main/resources";
\r
135 System.out.println("serviceLogicDirectory is " + serviceLogicDirectory);
\r
136 SvcLogicLoader loader = new SvcLogicLoader(serviceLogicDirectory, getStore());
\r
139 loader.loadAndActivate();
\r
140 } catch (IOException e) {
\r
141 log.error("Cannot load directed graphs", e);
\r
147 public SvcLogicServiceBase createService() throws Exception {
\r
148 HashMapResolver resolver = new HashMapResolver();
\r
151 * See comment above re: autowired lists. Need to explicitly register
\r
152 * SLI features to avoid circular dependency issue in springboot 2.6
\r
154 * for (SvcLogicRecorder recorder : recorders) {
\r
155 * log.info("Registering SvcLogicRecorder {}", recorder.getClass().getName());
\r
156 * resolver.addSvcLogicRecorder(recorder.getClass().getName(), recorder);
\r
160 * for (SvcLogicJavaPlugin plugin : plugins) {
\r
161 * log.info("Registering SvcLogicJavaPlugin {}", plugin.getClass().getName());
\r
162 * resolver.addSvcLogicSvcLogicJavaPlugin(plugin.getClass().getName(), plugin);
\r
165 * for (SvcLogicResource svcLogicResource : svcLogicResources) {
\r
166 * log.info("Registering SvcLogicResource {}",
\r
167 * svcLogicResource.getClass().getName());
\r
168 * resolver.addSvcLogicResource(svcLogicResource.getClass().getName(),
\r
169 * svcLogicResource);
\r
173 Slf4jRecorder slf4jRecorder = slf4jRecorderNode();
\r
175 SliPluginUtils sliPluginUtils = sliPluginUtil();
\r
177 SliStringUtils sliStringUtils = sliStringUtils();
\r
179 AAIService aaiService = aaiService();
\r
181 ConfigResource configResource = configResource();
\r
183 OperationalResource operationalResource = operationalResource();
\r
185 NetboxClient netboxClient = netboxClient();
\r
187 SqlResource sqlResource = sqlResource();
\r
189 RestapiCallNode restapiCallNode = restapiCallNode();
\r
191 PropertiesNode propertiesNode = propertiesNode();
\r
192 // Register recorder (there is only one)
\r
193 resolver.addSvcLogicRecorder(Slf4jRecorder.class.getName(), new Slf4jRecorder());
\r
195 // Register plugins
\r
196 resolver.addSvcLogicSvcLogicJavaPlugin(sliPluginUtils.getClass().getName(), sliPluginUtils);
\r
197 resolver.addSvcLogicSvcLogicJavaPlugin(sliStringUtils.getClass().getName(), sliStringUtils);
\r
198 resolver.addSvcLogicSvcLogicJavaPlugin(restapiCallNode.getClass().getName(), restapiCallNode);
\r
199 resolver.addSvcLogicSvcLogicJavaPlugin(propertiesNode.getClass().getName(), propertiesNode);
\r
200 resolver.addSvcLogicSvcLogicJavaPlugin(netboxClient.getClass().getName(), netboxClient);
\r
202 // Register resources
\r
203 resolver.addSvcLogicResource(aaiService.getClass().getName(), aaiService);
\r
204 resolver.addSvcLogicResource(configResource.getClass().getName(), configResource);
\r
205 resolver.addSvcLogicResource(operationalResource.getClass().getName(), operationalResource);
\r
206 resolver.addSvcLogicResource(sqlResource.getClass().getName(), sqlResource);
\r
208 return new SvcLogicServiceImplBase(getStore(), resolver);
\r
213 public Slf4jRecorder slf4jRecorderNode() {
\r
214 return new Slf4jRecorder();
\r
217 // Beans from sli/core
\r
220 public SliPluginUtils sliPluginUtil() {
\r
221 return new SliPluginUtils();
\r
225 public SliStringUtils sliStringUtils() {
\r
226 return new SliStringUtils();
\r
229 // Beans from sli/adaptors
\r
232 AAIService aaiService() {
\r
233 return new AAIService(new AAIServiceProvider());
\r
237 public ConfigResource configResource() {
\r
238 return new ConfigResource(new MdsalResourcePropertiesProviderImpl());
\r
242 public OperationalResource operationalResource() {
\r
243 return new OperationalResource(new MdsalResourcePropertiesProviderImpl());
\r
247 public PublisherApi publisherApi() {
\r
248 return new PublisherApiImpl();
\r
252 public NetboxClient netboxClient() {
\r
253 return new NetboxClientImpl();
\r
257 public SqlResource sqlResource() {
\r
258 return new SqlResource();
\r
262 public RestapiCallNode restapiCallNode() {
\r
263 return new RestapiCallNode();
\r
267 public PropertiesNode propertiesNode() {
\r
268 return new PropertiesNode();
\r