aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Timoney <dtimoney@att.com>2024-08-22 13:31:32 +0000
committerGerrit Code Review <gerrit@onap.org>2024-08-22 13:31:32 +0000
commita01eb33c635ff73525a2e184517aacb765c32ccd (patch)
tree9692bb7e1d259933b0748a2b2f1431f54bb60ab2
parent65d88c2fe722a1af41b87283862f7c5f3428148a (diff)
parentfdfb070d8a5139963fa02e59814855b8b19576a3 (diff)
Merge "Add database migration configuration"
-rw-r--r--a1-policy-management/config/application.yaml16
-rw-r--r--a1-policy-management/pom.xml4
-rw-r--r--a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/BeanFactory.java27
-rw-r--r--a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/DatabaseIndependentBeanFactory.java (renamed from a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/database/ExcludeDatabaseAutoConfiguration.java)31
-rw-r--r--a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/database/DatabaseDependentBeanFactory.java57
-rw-r--r--a1-policy-management/src/main/resources/db/migration/V1__create_base_schema.sql35
6 files changed, 140 insertions, 30 deletions
diff --git a/a1-policy-management/config/application.yaml b/a1-policy-management/config/application.yaml
index 3ef68023..9dcfc338 100644
--- a/a1-policy-management/config/application.yaml
+++ b/a1-policy-management/config/application.yaml
@@ -3,6 +3,7 @@
# ONAP : ccsdk oran
# ================================================================================
# Copyright (C) 2020-2023 Nordix Foundation. All rights reserved.
+# Copyright (C) 2024 OpenInfra Foundation Europe. All rights reserved.
# ================================================================================
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -29,9 +30,21 @@ spring:
aop:
auto: false
r2dbc:
+ # Configuration of the postgres database to be used by the application.
+ # These values can be passed via configmap/secret/env variable based on the installation.
url: "r2dbc:postgresql://127.0.0.1:5432/a1pms"
username: a1pms
password: mypwd
+ flyway:
+ # Configuration of the postgres database to be used for database migration.
+ # This is where the flyway maintains the information about the sql files loaded.
+ # These values can be passed via configmap/secret/env variable based on the installation.
+ # By default, Flyway uses location classpath:db/migration to load the sql files.
+ # This can be overridden using "flyway.locations" to have a different location.
+ url: "jdbc:postgresql://127.0.0.1:5432/a1pms"
+ user: a1pms
+ password: mypwd
+ baseline-on-migrate: true
management:
tracing:
propagation:
@@ -111,6 +124,9 @@ app:
accessKeyId: minio
secretAccessKey: miniostorage
bucket:
+ # Postgres database usage is enabled using the below parameter.
+ # If this is enabled, the application will use postgres database for storage.
+ # This overrides the s3(s3.bucket) or file store(vardata-directory) configuration if enabled.
database-enabled: false
otel:
sdk:
diff --git a/a1-policy-management/pom.xml b/a1-policy-management/pom.xml
index 0bea5fd5..1455bad1 100644
--- a/a1-policy-management/pom.xml
+++ b/a1-policy-management/pom.xml
@@ -108,6 +108,10 @@
<scope>runtime</scope>
</dependency>
<dependency>
+ <groupId>org.flywaydb</groupId>
+ <artifactId>flyway-core</artifactId>
+ </dependency>
+ <dependency>
<!-- May be possible to remove this later when ccsdk parent bom stabilizes -->
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/BeanFactory.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/BeanFactory.java
index 0f077a13..4d1fa331 100644
--- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/BeanFactory.java
+++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/BeanFactory.java
@@ -21,15 +21,11 @@
package org.onap.ccsdk.oran.a1policymanagementservice;
-
import org.apache.catalina.connector.Connector;
import org.onap.ccsdk.oran.a1policymanagementservice.clients.A1ClientFactory;
import org.onap.ccsdk.oran.a1policymanagementservice.clients.SecurityContext;
import org.onap.ccsdk.oran.a1policymanagementservice.configuration.ApplicationConfig;
-import org.onap.ccsdk.oran.a1policymanagementservice.repository.Policies;
-import org.onap.ccsdk.oran.a1policymanagementservice.repository.PolicyTypes;
import org.onap.ccsdk.oran.a1policymanagementservice.repository.Rics;
-import org.onap.ccsdk.oran.a1policymanagementservice.repository.Services;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.web.embedded.tomcat.TomcatReactiveWebServerFactory;
@@ -37,7 +33,6 @@ import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactor
import org.springframework.boot.web.reactive.server.ReactiveWebServerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
-import org.springframework.context.annotation.DependsOn;
@Configuration
public class BeanFactory {
@@ -56,28 +51,6 @@ public class BeanFactory {
}
@Bean
- @DependsOn("springContextProvider")
- public Services getServices(@Autowired ApplicationConfig applicationConfig) {
- Services services = new Services(applicationConfig);
- services.restoreFromDatabase().subscribe();
- return services;
- }
-
- @Bean
- @DependsOn("springContextProvider")
- public PolicyTypes getPolicyTypes(@Autowired ApplicationConfig applicationConfig) {
- PolicyTypes types = new PolicyTypes(applicationConfig);
- types.restoreFromDatabase().blockLast();
- return types;
- }
-
- @Bean
- @DependsOn("springContextProvider")
- public Policies getPolicies(@Autowired ApplicationConfig applicationConfig) {
- return new Policies(applicationConfig);
- }
-
- @Bean
public A1ClientFactory getA1ClientFactory(@Autowired ApplicationConfig applicationConfig,
@Autowired SecurityContext securityContext) {
return new A1ClientFactory(applicationConfig, securityContext);
diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/database/ExcludeDatabaseAutoConfiguration.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/DatabaseIndependentBeanFactory.java
index 799a8cb2..305499d0 100644
--- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/database/ExcludeDatabaseAutoConfiguration.java
+++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/DatabaseIndependentBeanFactory.java
@@ -18,15 +18,40 @@
* ========================LICENSE_END===================================
*/
-package org.onap.ccsdk.oran.a1policymanagementservice.database;
+package org.onap.ccsdk.oran.a1policymanagementservice;
+import org.onap.ccsdk.oran.a1policymanagementservice.configuration.ApplicationConfig;
+import org.onap.ccsdk.oran.a1policymanagementservice.repository.Policies;
+import org.onap.ccsdk.oran.a1policymanagementservice.repository.PolicyTypes;
+import org.onap.ccsdk.oran.a1policymanagementservice.repository.Services;
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration;
import org.springframework.boot.autoconfigure.r2dbc.R2dbcAutoConfiguration;
+import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
@ConditionalOnProperty(prefix = "app", name = "database-enabled", havingValue = "false")
-@EnableAutoConfiguration(exclude = R2dbcAutoConfiguration.class)
-public class ExcludeDatabaseAutoConfiguration {
+@EnableAutoConfiguration(exclude = { R2dbcAutoConfiguration.class, FlywayAutoConfiguration.class })
+public class DatabaseIndependentBeanFactory {
+ @Bean
+ public Services getServices(@Autowired ApplicationConfig applicationConfig) {
+ Services services = new Services(applicationConfig);
+ services.restoreFromDatabase().subscribe();
+ return services;
+ }
+
+ @Bean
+ public PolicyTypes getPolicyTypes(@Autowired ApplicationConfig applicationConfig) {
+ PolicyTypes types = new PolicyTypes(applicationConfig);
+ types.restoreFromDatabase().blockLast();
+ return types;
+ }
+
+ @Bean
+ public Policies getPolicies(@Autowired ApplicationConfig applicationConfig) {
+ return new Policies(applicationConfig);
+ }
}
diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/database/DatabaseDependentBeanFactory.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/database/DatabaseDependentBeanFactory.java
new file mode 100644
index 00000000..f463ecd0
--- /dev/null
+++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/database/DatabaseDependentBeanFactory.java
@@ -0,0 +1,57 @@
+/*-
+ * ========================LICENSE_START=================================
+ * ONAP : ccsdk oran
+ * ======================================================================
+ * Copyright (C) 2024 OpenInfra Foundation Europe. All rights reserved.
+ * ======================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ========================LICENSE_END===================================
+ */
+
+package org.onap.ccsdk.oran.a1policymanagementservice.database;
+
+import org.onap.ccsdk.oran.a1policymanagementservice.configuration.ApplicationConfig;
+import org.onap.ccsdk.oran.a1policymanagementservice.repository.Policies;
+import org.onap.ccsdk.oran.a1policymanagementservice.repository.PolicyTypes;
+import org.onap.ccsdk.oran.a1policymanagementservice.repository.Services;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.DependsOn;
+
+@Configuration
+@ConditionalOnProperty(prefix = "app", name = "database-enabled", havingValue = "true")
+public class DatabaseDependentBeanFactory {
+ @Bean
+ @DependsOn({ "springContextProvider", "flywayInitializer" })
+ public Services getServices(@Autowired ApplicationConfig applicationConfig) {
+ Services services = new Services(applicationConfig);
+ services.restoreFromDatabase().subscribe();
+ return services;
+ }
+
+ @Bean
+ @DependsOn({ "springContextProvider", "flywayInitializer" })
+ public PolicyTypes getPolicyTypes(@Autowired ApplicationConfig applicationConfig) {
+ PolicyTypes types = new PolicyTypes(applicationConfig);
+ types.restoreFromDatabase().blockLast();
+ return types;
+ }
+
+ @Bean
+ @DependsOn({ "springContextProvider", "flywayInitializer" })
+ public Policies getPolicies(@Autowired ApplicationConfig applicationConfig) {
+ return new Policies(applicationConfig);
+ }
+}
diff --git a/a1-policy-management/src/main/resources/db/migration/V1__create_base_schema.sql b/a1-policy-management/src/main/resources/db/migration/V1__create_base_schema.sql
new file mode 100644
index 00000000..a6d49989
--- /dev/null
+++ b/a1-policy-management/src/main/resources/db/migration/V1__create_base_schema.sql
@@ -0,0 +1,35 @@
+-- ============LICENSE_START=======================================================
+-- Copyright (C) 2024 OpenInfra Foundation Europe
+-- ================================================================================
+-- Licensed under the Apache License, Version 2.0 (the "License");
+-- you may not use this file except in compliance with the License.
+-- You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+-- SPDX-License-Identifier: Apache-2.0
+-- ============LICENSE_END=========================================================
+
+CREATE TABLE IF NOT EXISTS policies (
+ id varchar NOT NULL,
+ payload varchar NOT NULL,
+ CONSTRAINT policies_pk PRIMARY KEY (id)
+);
+
+CREATE TABLE IF NOT EXISTS policy_types (
+ id varchar NOT NULL,
+ payload varchar NOT NULL,
+ CONSTRAINT policy_types_pk PRIMARY KEY (id)
+);
+
+CREATE TABLE IF NOT EXISTS services (
+ id varchar NOT NULL,
+ payload varchar NOT NULL,
+ CONSTRAINT services_pk PRIMARY KEY (id)
+); \ No newline at end of file