Sync local changes to support GRA microservice
[ccsdk/apps.git] / services / src / main / java / org / onap / ccsdk / apps / services / SvcLogicFactory.java
index 9ab5656..54d612f 100644 (file)
 \r
 package org.onap.ccsdk.apps.services;\r
 \r
+import java.io.File;\r
 import java.io.FileInputStream;\r
+import java.io.FileReader;\r
 import java.io.IOException;\r
+import java.io.InputStream;\r
 import java.util.List;\r
 import java.util.Properties;\r
 \r
@@ -41,6 +44,8 @@ import org.onap.ccsdk.sli.core.dblib.DBLIBResourceProvider;
 import org.onap.ccsdk.sli.core.dblib.DBResourceManager;\r
 import org.onap.ccsdk.sli.core.dblib.DbLibService;\r
 import org.onap.ccsdk.sli.core.sli.ConfigurationException;\r
+import org.onap.ccsdk.sli.core.sli.SvcLogicAdaptor;\r
+import org.onap.ccsdk.sli.core.sli.SvcLogicException;\r
 import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin;\r
 import org.onap.ccsdk.sli.core.sli.SvcLogicLoader;\r
 import org.onap.ccsdk.sli.core.sli.SvcLogicRecorder;\r
@@ -67,147 +72,149 @@ import org.springframework.stereotype.Service;
 @Configuration\r
 @Service\r
 public class SvcLogicFactory {\r
-  private static final Logger log = LoggerFactory.getLogger(SvcLogicFactory.class);\r
-\r
-  @Autowired\r
-  List<SvcLogicRecorder> recorders;\r
-\r
-  @Autowired\r
-  List<SvcLogicJavaPlugin> plugins;\r
-\r
-  @Autowired\r
-  List<SvcLogicResource> svcLogicResources;\r
+    private static final Logger log = LoggerFactory.getLogger(SvcLogicFactory.class);\r
+    private static final String SDNC_CONFIG_DIR = "SDNC_CONFIG_DIR";\r
+    private static final String CONTRAIL_PROPERTIES = "contrail-adaptor.properties";\r
+\r
+    @Autowired\r
+    List<SvcLogicRecorder> recorders;\r
+\r
+    @Autowired\r
+    List<SvcLogicJavaPlugin> plugins;\r
+\r
+    @Autowired\r
+    List<SvcLogicResource> svcLogicResources;\r
+\r
+\r
+    @Bean\r
+    public SvcLogicStore getStore() throws Exception {\r
+        SvcLogicPropertiesProvider propProvider = new SvcLogicPropertiesProvider() {\r
+\r
+            @Override\r
+            public Properties getProperties() {\r
+                Properties props = new Properties();\r
+\r
+                String propPath = System.getProperty("serviceLogicProperties", "");\r
+\r
+                if ("".equals(propPath)) {\r
+                    propPath = System.getenv("SVCLOGIC_PROPERTIES");\r
+                }\r
+\r
+                if ((propPath == null) || propPath.length() == 0) {\r
+                    propPath = "src/main/resources/svclogic.properties";\r
+                }\r
+                System.out.println(propPath);\r
+                try (FileInputStream fileInputStream = new FileInputStream(propPath)) {\r
+                    props = new EnvProperties();\r
+                    props.load(fileInputStream);\r
+                } catch (final IOException e) {\r
+                    log.error("Failed to load properties for file: {}", propPath,\r
+                            new ConfigurationException("Failed to load properties for file: " + propPath, e));\r
+                }\r
+                return props;\r
+            }\r
+        };\r
+        SvcLogicStore store = SvcLogicStoreFactory.getSvcLogicStore(propProvider.getProperties());\r
+        return store;\r
+    }\r
 \r
-  @Bean\r
-  public SvcLogicStore getStore() throws Exception {\r
-    SvcLogicPropertiesProvider propProvider = new SvcLogicPropertiesProvider() {\r
+    @Bean\r
+    public SvcLogicLoader createLoader() throws Exception {\r
+        String serviceLogicDirectory = System.getProperty("serviceLogicDirectory");\r
+        if (serviceLogicDirectory == null) {\r
+            serviceLogicDirectory = "src/main/resources";\r
+        }\r
 \r
-      @Override\r
-      public Properties getProperties() {\r
-        Properties props = new Properties();\r
+        System.out.println("serviceLogicDirectory is " + serviceLogicDirectory);\r
+        SvcLogicLoader loader = new SvcLogicLoader(serviceLogicDirectory, getStore());\r
 \r
+        try {\r
+            loader.loadAndActivate();\r
+        } catch (IOException e) {\r
+            log.error("Cannot load directed graphs", e);\r
+        }\r
+        return loader;\r
+    }\r
 \r
-        String propPath = System.getProperty("serviceLogicProperties", "");\r
+    @Bean\r
+    public SvcLogicServiceBase createService() throws Exception {\r
+        HashMapResolver resolver = new HashMapResolver();\r
+        for (SvcLogicRecorder recorder : recorders) {\r
+            log.info("Registering SvcLogicRecorder {}", recorder.getClass().getName());\r
+            resolver.addSvcLogicRecorder(recorder.getClass().getName(), recorder);\r
 \r
-        if ("".equals(propPath)) {\r
-          propPath = System.getenv("SVCLOGIC_PROPERTIES");\r
         }\r
 \r
+        for (SvcLogicJavaPlugin plugin : plugins) {\r
+            log.info("Registering SvcLogicJavaPlugin {}", plugin.getClass().getName());\r
+            resolver.addSvcLogicSvcLogicJavaPlugin(plugin.getClass().getName(), plugin);\r
 \r
-        if ((propPath == null) || propPath.length() == 0) {\r
-          propPath = "src/main/resources/svclogic.properties";\r
         }\r
-        System.out.println(propPath);\r
-        try (FileInputStream fileInputStream = new FileInputStream(propPath)) {\r
-          props = new EnvProperties();\r
-          props.load(fileInputStream);\r
-        } catch (final IOException e) {\r
-          log.error("Failed to load properties for file: {}", propPath,\r
-              new ConfigurationException("Failed to load properties for file: " + propPath, e));\r
+        for (SvcLogicResource svcLogicResource : svcLogicResources) {\r
+            log.info("Registering SvcLogicResource {}", svcLogicResource.getClass().getName());\r
+            resolver.addSvcLogicResource(svcLogicResource.getClass().getName(), svcLogicResource);\r
         }\r
-        return props;\r
-      }\r
-    };\r
-    SvcLogicStore store = SvcLogicStoreFactory.getSvcLogicStore(propProvider.getProperties());\r
-    return store;\r
-  }\r
-\r
-  @Bean\r
-  public SvcLogicLoader createLoader() throws Exception {\r
-    String serviceLogicDirectory = System.getProperty("serviceLogicDirectory");\r
-    if (serviceLogicDirectory == null) {\r
-      serviceLogicDirectory = "src/main/resources";\r
+\r
+        return new SvcLogicServiceImplBase(getStore(), resolver);\r
     }\r
 \r
-    System.out.println("serviceLogicDirectory is " + serviceLogicDirectory);\r
-    SvcLogicLoader loader = new SvcLogicLoader(serviceLogicDirectory, getStore());\r
+    @Bean\r
+    public Slf4jRecorder slf4jRecorderNode() {\r
+        return new Slf4jRecorder();\r
+    }\r
 \r
-    try {\r
-      loader.loadAndActivate();\r
-    } catch (IOException e) {\r
-      log.error("Cannot load directed graphs", e);\r
+    // Beans from sli/core\r
+\r
+    @Bean\r
+    public SliPluginUtils sliPluginUtil() {\r
+        return new SliPluginUtils();\r
     }\r
-    return loader;\r
-  }\r
 \r
-  @Bean\r
-  public SvcLogicServiceBase createService() throws Exception {\r
-    HashMapResolver resolver = new HashMapResolver();\r
-    for (SvcLogicRecorder recorder : recorders) {\r
-      resolver.addSvcLogicRecorder(recorder.getClass().getName(), recorder);\r
+    @Bean\r
+    public SliStringUtils sliStringUtils() {\r
+        return new SliStringUtils();\r
+    }\r
 \r
+    // Beans from sli/adaptors\r
+\r
+    @Bean\r
+    AAIService aaiService() {\r
+        return new AAIService(new AAIServiceProvider());\r
+    }\r
+\r
+    @Bean\r
+    public ConfigResource configResource() {\r
+        return new ConfigResource(new MdsalResourcePropertiesProviderImpl());\r
+    }\r
+\r
+    @Bean\r
+    public OperationalResource operationalResource() {\r
+        return new OperationalResource(new MdsalResourcePropertiesProviderImpl());\r
     }\r
-    for (SvcLogicJavaPlugin plugin : plugins) {\r
-      resolver.addSvcLogicSvcLogicJavaPlugin(plugin.getClass().getName(), plugin);\r
 \r
+    @Bean\r
+    public PublisherApi publisherApi() {\r
+        return new PublisherApiImpl();\r
     }\r
-    for (SvcLogicResource svcLogicResource : svcLogicResources) {\r
-      resolver.addSvcLogicResource(svcLogicResource.getClass().getName(), svcLogicResource);\r
+\r
+    @Bean\r
+    public NetboxClient netboxClient() {\r
+        return new NetboxClientImpl();\r
     }\r
 \r
-    return new SvcLogicServiceImplBase(getStore(), resolver);\r
-  }\r
-\r
-  @Bean\r
-  public Slf4jRecorder slf4jRecorderNode() {\r
-    return new Slf4jRecorder();\r
-  }\r
-\r
-  // Beans from sli/core\r
-\r
-  @Bean\r
-  public SliPluginUtils sliPluginUtil() {\r
-    return new SliPluginUtils();\r
-  }\r
-\r
-  @Bean\r
-  public SliStringUtils sliStringUtils() {\r
-    return new SliStringUtils();\r
-  }\r
-\r
-  // Beans from sli/adaptors\r
-\r
-  @Bean AAIService aaiService() {\r
-    return new AAIService(new AAIServiceProvider());\r
-  }\r
-  \r
-  @Bean\r
-  public ConfigResource configResource() {\r
-    return new ConfigResource(new MdsalResourcePropertiesProviderImpl());\r
-  }\r
-\r
-  @Bean\r
-  public OperationalResource operationalResource() {\r
-    return new OperationalResource(new MdsalResourcePropertiesProviderImpl());\r
-  }\r
-\r
-  @Bean \r
-  public PublisherApi publisherApi() {\r
-    return new PublisherApiImpl();\r
-  }\r
-  \r
-  \r
-  @Bean \r
-  public NetboxClient netboxClient() {\r
-    return new NetboxClientImpl();\r
-  }\r
-  \r
-  \r
-  @Bean\r
-  public SqlResource sqlResource() {\r
-    return new SqlResource();\r
-  }\r
-\r
-  \r
-  @Bean\r
-  public RestapiCallNode restapiCallNode() {\r
-      return new RestapiCallNode();\r
-  }\r
-  \r
-  @Bean\r
-  public PropertiesNode propertiesNode() {\r
-      return new PropertiesNode();\r
-  }\r
+    @Bean\r
+    public SqlResource sqlResource() {\r
+        return new SqlResource();\r
+    }\r
 \r
+    @Bean\r
+    public RestapiCallNode restapiCallNode() {\r
+        return new RestapiCallNode();\r
+    }\r
+\r
+    @Bean\r
+    public PropertiesNode propertiesNode() {\r
+        return new PropertiesNode();\r
+    }\r
 \r
 }\r