Sync local changes to support GRA microservice 74/125474/2
authorDan Timoney <dtimoney@att.com>
Fri, 29 Oct 2021 18:40:13 +0000 (14:40 -0400)
committerDan Timoney <dtimoney@att.com>
Fri, 29 Oct 2021 19:31:05 +0000 (15:31 -0400)
Sync changes made downstream to support GRA microservice

Issue-ID: CCSDK-3504
Change-Id: I5fd99b978edb9598c5fe38f188635b365ad4e24c
Signed-off-by: Dan Timoney <dtimoney@att.com>
ms/neng/pom.xml
ms/pom.xml
ms/sliboot/src/main/dc/docker-compose.yaml
ms/sliboot/src/main/java/org/onap/ccsdk/apps/ms/sliboot/FilterConfiguration.java [new file with mode: 0644]
ms/sliboot/src/main/java/org/onap/ccsdk/apps/ms/sliboot/SlibootApp.java
services/src/main/java/org/onap/ccsdk/apps/filters/AuditLogFilter.java
services/src/main/java/org/onap/ccsdk/apps/filters/ContentTypeFilter.java
services/src/main/java/org/onap/ccsdk/apps/filters/PayloadLoggingFilter.java
services/src/main/java/org/onap/ccsdk/apps/services/SvcLogicFactory.java

index ed28306..4a40ad1 100644 (file)
@@ -18,6 +18,7 @@
  * limitations under the License.
  * ============LICENSE_END=========================================================
   -->
+
 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
     <modelVersion>4.0.0</modelVersion>
 
index 5eefe80..7912d7c 100644 (file)
@@ -18,6 +18,7 @@
  * limitations under the License.
  * ============LICENSE_END=========================================================
  -->
+
 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
     <modelVersion>4.0.0</modelVersion>
 
index 7b85745..a6bd9b5 100755 (executable)
@@ -30,11 +30,13 @@ services:
     links:
       - db:dbhost
     environment:
-      - MYSQL_HOST=dbhost
+      - MYSQL_DB_HOST=dbhost
+      - MYSQL_DB_USER=${MYSQL_USER}
+      - MYSQL_DB_PASSWD=${MYSQL_PASSWORD}
+      - MYSQL_DB_DATABASE=${MYSQL_DATABASE}
       - MYSQL_USER=${MYSQL_USER}
       - MYSQL_PASSWORD=${MYSQL_PASSWORD}
       - MYSQL_DATABASE=${MYSQL_DATABASE}
-      - MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}
       - SDNC_CONFIG_DIR=/opt/onap/ccsdk/config
     logging:       
       driver:   "json-file"
diff --git a/ms/sliboot/src/main/java/org/onap/ccsdk/apps/ms/sliboot/FilterConfiguration.java b/ms/sliboot/src/main/java/org/onap/ccsdk/apps/ms/sliboot/FilterConfiguration.java
new file mode 100644 (file)
index 0000000..295953a
--- /dev/null
@@ -0,0 +1,66 @@
+package org.onap.ccsdk.apps.ms.sliboot;
+
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+import java.util.Properties;
+
+import org.onap.aaf.cadi.filter.CadiFilter;
+import org.onap.ccsdk.sli.core.utils.common.EnvProperties;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.boot.web.servlet.FilterRegistrationBean;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.core.annotation.Order;
+
+@Configuration
+@ConditionalOnProperty("cadi.properties.path")
+public class FilterConfiguration {
+    private static final Logger log = LoggerFactory.getLogger(FilterConfiguration.class);
+
+       @Value( "${cadi.properties.path:none}" )
+       private String cadiPropFile;
+
+       @Bean
+       @Order(1)
+       public FilterRegistrationBean<CadiFilter> cadiFilter() {
+               CadiFilter filter = new CadiFilter();
+               
+               FilterRegistrationBean<CadiFilter> registrationBean = new FilterRegistrationBean<>();
+               registrationBean.setFilter(filter);
+               if ("none".equals(cadiPropFile)) {
+            log.info("cadi.properties.path undefined, AAF CADI disabled");
+                       registrationBean.setEnabled(false);
+                       registrationBean.addUrlPatterns("/xxxx/*");
+               } else {
+                       // Note: assume that cadi.properties.path specifies full path to properties file
+                       File cadiFile = new File(cadiPropFile);
+                       if (!cadiFile.exists()) {
+                               log.info("cadi properties file {} not found, AAF CADI disabled", cadiPropFile);
+                               registrationBean.setEnabled(false);
+                               registrationBean.addUrlPatterns("/xxxx/*");
+                       } else {
+                               Properties cadiProperties = new EnvProperties();
+                               try {
+                                       cadiProperties.load(new FileReader(cadiFile));
+                                       cadiProperties.forEach((k, v) -> {
+                                               registrationBean.addInitParameter((String) k, cadiProperties.getProperty((String) k));
+                                       });
+                                       registrationBean.addUrlPatterns("/*");
+                                       log.info("Installed and configured CADI filter");
+                               } catch (IOException e) {
+                                       log.info("Caught exception loading cadi properties file {}, AAF CADI disabled", cadiPropFile, e);
+                                       registrationBean.setEnabled(false);
+                                       registrationBean.addUrlPatterns("/xxxx/*");
+                               }
+                       }
+
+               }
+
+               return registrationBean;
+       }
+
+}
index 2bca1db..0fd23a9 100644 (file)
@@ -7,9 +7,9 @@
  * Licensed under the Apache License, Version 2.0 (the "License");\r
  * you may not use this file except in compliance with the License.\r
  * You may obtain a copy of the License at\r
- * \r
+ *\r
  *      http://www.apache.org/licenses/LICENSE-2.0\r
- * \r
+ *\r
  * Unless required by applicable law or agreed to in writing, software\r
  * distributed under the License is distributed on an "AS IS" BASIS,\r
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
@@ -67,6 +67,6 @@ public class SlibootApp {
                }\r
 \r
                return registrationBean;\r
-       } \r
+       }\r
 \r
 }\r
index b6d52c5..45ce55f 100644 (file)
@@ -7,7 +7,6 @@ import org.onap.logging.ref.slf4j.ONAPLogConstants;
 import org.slf4j.MDC;
 import org.springframework.stereotype.Component;
 
-@Component
 public class AuditLogFilter extends AuditLogServletFilter {
     private static final String MDC_HTTP_METHOD_KEY = "HttpMethod";
 
@@ -40,4 +39,4 @@ public class AuditLogFilter extends AuditLogServletFilter {
         return null;
     }
 
-}
\ No newline at end of file
+}
index 20f9ec4..f2f638f 100644 (file)
@@ -62,7 +62,7 @@ public class ContentTypeFilter implements Filter {
                         contentType = "application/json";
                     } else if ("application/yang-data+xml".equalsIgnoreCase(contentType)) {
                         contentType = "application/xml";
-                    } else if (contentType.startsWith("text/plain")) {
+                    } else if (contentType.startsWith("text/plain") || contentType.startsWith("*/*")) {
                         // Use Accept header, if present, to determine content type.
                         boolean acceptsXml = false;
                         boolean acceptsJson = false;
index e53c50a..dd591fb 100644 (file)
@@ -36,7 +36,6 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.stereotype.Component;
 
-@Component
 public class PayloadLoggingFilter extends AbstractServletFilter implements Filter {
 
        private static final Logger log = LoggerFactory.getLogger(PayloadLoggingFilter.class);
@@ -319,4 +318,4 @@ public class PayloadLoggingFilter extends AbstractServletFilter implements Filte
                        }
                }
        }
-}
\ No newline at end of file
+}
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