Fix broken spring context in graphadmin 46/140146/2 1.15.5
authorFiete Ostkamp <Fiete.Ostkamp@telekom.de>
Wed, 5 Feb 2025 11:55:51 +0000 (12:55 +0100)
committerFiete Ostkamp <Fiete.Ostkamp@telekom.de>
Wed, 5 Feb 2025 11:59:59 +0000 (12:59 +0100)
- scan everything under org.onap.aai to get a working spring context

Issue-ID: AAI-4123
Change-Id: I7d96f57109b9acf93b99be737b3bce44bc8a39ca
Signed-off-by: Fiete Ostkamp <Fiete.Ostkamp@telekom.de>
17 files changed:
pom.xml
src/main/java/org/onap/aai/GraphAdminApp.java
src/main/java/org/onap/aai/config/SecurityConfig.java
src/main/java/org/onap/aai/datagrooming/DataGrooming.java
src/main/java/org/onap/aai/datasnapshot/DataSnapshot4HistInit.java
src/main/java/org/onap/aai/db/schema/ScriptDriver.java
src/main/java/org/onap/aai/dbgen/DupeTool.java
src/main/java/org/onap/aai/dbgen/DynamicPayloadGenerator.java
src/main/java/org/onap/aai/dbgen/schemamod/SchemaMod.java
src/main/java/org/onap/aai/dbgen/schemamod/SchemaMod4Hist.java
src/main/java/org/onap/aai/historytruncate/HistoryTruncateTasks.java
src/main/java/org/onap/aai/migration/MigrationController.java
src/main/java/org/onap/aai/schema/GenTester.java
src/main/java/org/onap/aai/schema/GenTester4Hist.java
src/main/java/org/onap/aai/util/SendDeleteMigrationNotificationsMain.java
src/main/java/org/onap/aai/util/SendMigrationNotificationsMain.java
src/main/resources/etc/appprops/datatoolscrons.properties

diff --git a/pom.xml b/pom.xml
index 648447a..eed4e41 100755 (executable)
--- a/pom.xml
+++ b/pom.xml
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-starter-security</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-validation</artifactId>
+        </dependency>
+            <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-configuration-processor</artifactId>
+            <optional>true</optional>
+        </dependency>
         <dependency>
             <groupId>org.springframework</groupId>
             <artifactId>spring-test</artifactId>
index 0a5d33d..036f216 100644 (file)
@@ -36,6 +36,7 @@ import org.springframework.boot.autoconfigure.cassandra.CassandraAutoConfigurati
 import org.springframework.boot.autoconfigure.data.cassandra.CassandraDataAutoConfiguration;
 import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
 import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
 import org.springframework.context.annotation.ComponentScan;
 import org.springframework.context.annotation.EnableAspectJAutoProxy;
 import org.springframework.core.env.Environment;
@@ -71,6 +72,7 @@ import javax.annotation.PreDestroy;
 @EnableAsync
 @EnableScheduling
 @EnableAspectJAutoProxy
+@EnableConfigurationProperties
 @EnableAutoConfiguration(exclude = {
     DataSourceAutoConfiguration.class,
     HibernateJpaAutoConfiguration.class,
index a2872ba..98d6bbd 100644 (file)
@@ -24,13 +24,14 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
 import org.springframework.security.config.annotation.web.builders.HttpSecurity;
+import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
 import org.springframework.security.core.userdetails.User;
 import org.springframework.security.core.userdetails.UserDetails;
 import org.springframework.security.provisioning.InMemoryUserDetailsManager;
 import org.springframework.security.web.SecurityFilterChain;
-import org.springframework.util.AntPathMatcher;
 
 @Configuration
+@EnableWebSecurity
 @ConditionalOnProperty(name = "aai.basic-auth.enabled", havingValue = "true", matchIfMissing = true)
 public class SecurityConfig {
 
index d7c36ad..74f4310 100644 (file)
@@ -298,9 +298,7 @@ public class DataGrooming {
 
                try {
                        ctx.scan(
-                                       "org.onap.aai.config",
-                                       "org.onap.aai.setup",
-                                       "org.onap.aai.introspection"
+                                       "org.onap.aai"
                        );
                        ctx.refresh();
 
index fdf81aa..dc60cc1 100644 (file)
@@ -113,9 +113,7 @@ public class DataSnapshot4HistInit {
                AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
                try {
                        ctx.scan(
-                                       "org.onap.aai.config",
-                                       "org.onap.aai.setup",
-          "org.onap.aai.introspection"
+                                       "org.onap.aai"
                        );
                        ctx.refresh();
                } catch (Exception e) {
index d71138a..b020dd9 100644 (file)
@@ -60,8 +60,7 @@ public class ScriptDriver {
                AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
                try {
                        ctx.scan(
-                                       "org.onap.aai.config",
-                                       "org.onap.aai.introspection"
+                                       "org.onap.aai"
                        );
                        ctx.refresh();
 
index d65ae25..db53caf 100644 (file)
@@ -466,9 +466,7 @@ public class DupeTool {
         AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
         try {
             ctx.scan(
-                    "org.onap.aai.config",
-                    "org.onap.aai.setup",
-                    "org.onap.aai.introspection"
+                    "org.onap.aai"
             );
             ctx.refresh();
         } catch (Exception e) {
index f9c9e4b..7ee9372 100644 (file)
@@ -149,9 +149,7 @@ public class DynamicPayloadGenerator {
                AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
                try {
                        ctx.scan(
-                                       "org.onap.aai.config",
-                                       "org.onap.aai.setup",
-          "org.onap.aai.introspection"
+                                       "org.onap.aai"
                        );
                        ctx.refresh();
                } catch (Exception e) {
index 1e96223..afc5793 100644 (file)
@@ -174,9 +174,7 @@ public class SchemaMod {
                AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
                try {
                        ctx.scan(
-                                       "org.onap.aai.config",
-                                       "org.onap.aai.setup",
-                                       "org.onap.aai.introspection"
+                                       "org.onap.aai"
                        );
                        ctx.refresh();
                } catch (Exception e) {
index e806883..6201562 100644 (file)
@@ -157,9 +157,7 @@ public class SchemaMod4Hist {
                AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
                try {
                        ctx.scan(
-                                       "org.onap.aai.config",
-                                       "org.onap.aai.setup",
-                                       "org.onap.aai.introspection"
+                                       "org.onap.aai"
                        );
                        ctx.refresh();
                } catch (Exception e) {
index 4cb33fc..794c39f 100644 (file)
@@ -32,25 +32,38 @@ import org.onap.aai.logging.LogFormatTools;
 import org.onap.aai.util.AAIConfig;
 import org.onap.logging.filter.base.ONAPComponents;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.context.annotation.PropertySource;
 import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Component;
+
+import lombok.extern.slf4j.Slf4j;
+
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+@Slf4j
 @Component
 @PropertySource("file:${server.local.startpath}/etc/appprops/datatoolscrons.properties")
 public class HistoryTruncateTasks {
 
-       @Autowired
-    private AaiScheduledTaskAuditLog auditLog;
-
        private static final Logger LOGGER = LoggerFactory.getLogger(HistoryTruncateTasks.class);
        private final SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
 
+       @Autowired
+  private AaiScheduledTaskAuditLog auditLog;
+
+       @Value("#{new Boolean('${historytruncatetasks.enabled:true}')}")
+       private Boolean historyTruncateTaskEnabled;
+
        @Scheduled(cron = "${historytruncatetasks.cron}" )
        public void historyTruncateScheduleTask() throws AAIException, Exception {
 
+               if(historyTruncateTaskEnabled != null && !historyTruncateTaskEnabled) {
+                       log.info("Skipping the scheduled history truncate task since historytruncatetasks.enabled=false");
+                       return;
+               }
+
                if(!"true".equals(AAIConfig.get("aai.disable.check.historytruncate.running", "false"))){
                        if(checkIfHistoryTruncateIsRunning()){
                                LOGGER.debug("History Truncate is already running on the system");
index 6b3b0a6..851502c 100644 (file)
@@ -46,9 +46,7 @@ public class MigrationController {
                AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
                try {
                        ctx.scan(
-                                       "org.onap.aai.config",
-                                       "org.onap.aai.setup",
-                                       "org.onap.aai.introspection"
+                                       "org.onap.aai"
                        );
                        ctx.refresh();
                } catch (Exception e) {
index 3568707..55212d8 100644 (file)
@@ -63,9 +63,7 @@ public class GenTester {
                AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
                try {
                        ctx.scan(
-                                       "org.onap.aai.config",
-                                       "org.onap.aai.setup",
-                                       "org.onap.aai.introspection");
+                                       "org.onap.aai");
                        ctx.refresh();
                } catch (Exception e) {
                        AAIException aai = ExceptionTranslator.schemaServiceExceptionTranslator(e);
index 45581d8..80b58ea 100644 (file)
@@ -54,9 +54,7 @@ public class GenTester4Hist {
                AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
                try {
                        ctx.scan(
-                                       "org.onap.aai.config",
-                                       "org.onap.aai.setup",
-                                       "org.onap.aai.introspection"
+                                       "org.onap.aai"
                        );
                        ctx.refresh();
                } catch (Exception e) {
index c3a40d2..a9b1285 100644 (file)
@@ -45,9 +45,7 @@ public class SendDeleteMigrationNotificationsMain {
                AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
                try {
                        ctx.scan(
-                                       "org.onap.aai.config",
-                                       "org.onap.aai.setup",
-                                       "org.onap.aai.introspection"
+                                       "org.onap.aai"
                        );
                        ctx.refresh();
                } catch (Exception e) {
index fbd1010..aa6b4e3 100644 (file)
@@ -42,9 +42,7 @@ public class SendMigrationNotificationsMain {
                AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
                try {
                        ctx.scan(
-                                       "org.onap.aai.config",
-                                       "org.onap.aai.setup",
-                                       "org.onap.aai.introspection"
+                                       "org.onap.aai"
                        );
                        ctx.refresh();
                } catch (Exception e) {
index bbad8d5..70fd007 100644 (file)
@@ -14,3 +14,6 @@ datasnapshotcleanup.enabled=${DATA_SNAPSHOT_CLEANUP_ENABLED:true}
 datasnapshotcleanup.cron=0 17 0 * * ?
 datasnapshottasks.enabled=${DATA_SNAPSHOT_TASKS_ENABLED:true}
 datasnapshottasks.cron=0 45 * * * ?
+
+historytruncatetasks.enabled=${HISTORY_TRUNCATE_TASK_ENABLED:true}
+historytruncatetasks.cron=0 45 * * * ?