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.FileInputStream;
\r
24 import java.io.IOException;
\r
25 import java.util.List;
\r
26 import java.util.Properties;
\r
27 import org.onap.ccsdk.sli.core.sli.ConfigurationException;
\r
28 import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin;
\r
29 import org.onap.ccsdk.sli.core.sli.SvcLogicLoader;
\r
30 import org.onap.ccsdk.sli.core.sli.SvcLogicRecorder;
\r
31 import org.onap.ccsdk.sli.core.sli.SvcLogicStore;
\r
32 import org.onap.ccsdk.sli.core.sli.SvcLogicStoreFactory;
\r
33 import org.onap.ccsdk.sli.core.sli.provider.base.HashMapResolver;
\r
34 import org.onap.ccsdk.sli.core.sli.provider.base.SvcLogicPropertiesProvider;
\r
35 import org.onap.ccsdk.sli.core.sli.provider.base.SvcLogicServiceBase;
\r
36 import org.onap.ccsdk.sli.core.sli.provider.base.SvcLogicServiceImplBase;
\r
37 import org.onap.ccsdk.sli.core.sli.recording.Slf4jRecorder;
\r
38 import org.onap.ccsdk.sli.core.slipluginutils.SliPluginUtils;
\r
39 import org.onap.ccsdk.sli.core.slipluginutils.SliStringUtils;
\r
40 import org.onap.ccsdk.sli.plugins.prop.PropertiesNode;
\r
41 import org.onap.ccsdk.sli.plugins.restapicall.RestapiCallNode;
\r
42 import org.slf4j.Logger;
\r
43 import org.slf4j.LoggerFactory;
\r
44 import org.springframework.beans.factory.annotation.Autowired;
\r
45 import org.springframework.context.annotation.Bean;
\r
46 import org.springframework.context.annotation.Configuration;
\r
47 import org.springframework.stereotype.Service;
\r
51 public class SvcLogicFactory {
\r
52 private static final Logger log = LoggerFactory.getLogger(SvcLogicFactory.class);
\r
55 List<SvcLogicRecorder> recorders;
\r
58 List<SvcLogicJavaPlugin> plugins;
\r
61 public SvcLogicStore getStore() throws Exception {
\r
62 SvcLogicPropertiesProvider propProvider = new SvcLogicPropertiesProvider() {
\r
65 public Properties getProperties() {
\r
66 Properties props = new Properties();
\r
69 String propPath = System.getProperty("serviceLogicProperties", "");
\r
71 if ("".equals(propPath)) {
\r
72 propPath = System.getenv("SVCLOGIC_PROPERTIES");
\r
76 if ((propPath == null) || propPath.length() == 0) {
\r
77 propPath = "src/main/resources/svclogic.properties";
\r
79 System.out.println(propPath);
\r
80 try (FileInputStream fileInputStream = new FileInputStream(propPath)) {
\r
81 props = new Properties();
\r
82 props.load(fileInputStream);
\r
83 } catch (final IOException e) {
\r
84 log.error("Failed to load properties for file: {}", propPath,
\r
85 new ConfigurationException("Failed to load properties for file: " + propPath, e));
\r
90 SvcLogicStore store = SvcLogicStoreFactory.getSvcLogicStore(propProvider.getProperties());
\r
95 public SvcLogicLoader createLoader() throws Exception {
\r
96 String serviceLogicDirectory = System.getProperty("serviceLogicDirectory");
\r
97 if (serviceLogicDirectory == null) {
\r
98 serviceLogicDirectory = "src/main/resources";
\r
101 System.out.println("serviceLogicDirectory is " + serviceLogicDirectory);
\r
102 SvcLogicLoader loader = new SvcLogicLoader(serviceLogicDirectory, getStore());
\r
105 loader.loadAndActivate();
\r
106 } catch (IOException e) {
\r
107 log.error("Cannot load directed graphs", e);
\r
113 public SvcLogicServiceBase createService() throws Exception {
\r
114 HashMapResolver resolver = new HashMapResolver();
\r
115 for (SvcLogicRecorder recorder : recorders) {
\r
116 resolver.addSvcLogicRecorder(recorder.getClass().getName(), recorder);
\r
119 for (SvcLogicJavaPlugin plugin : plugins) {
\r
120 resolver.addSvcLogicSvcLogicJavaPlugin(plugin.getClass().getName(), plugin);
\r
123 return new SvcLogicServiceImplBase(getStore(), resolver);
\r
127 public Slf4jRecorder slf4jRecorderNode() {
\r
128 return new Slf4jRecorder();
\r
132 public SliPluginUtils sliPluginUtil() {
\r
133 return new SliPluginUtils();
\r
137 public SliStringUtils sliStringUtils() {
\r
138 return new SliStringUtils();
\r
142 public RestapiCallNode restapiCallNode() {
\r
143 return new RestapiCallNode();
\r
147 public PropertiesNode propertiesNode() {
\r
148 return new PropertiesNode();
\r