aboutsummaryrefslogtreecommitdiffstats
path: root/a1-policy-management/src
diff options
context:
space:
mode:
authoraravind.est <aravindhan.a@est.tech>2024-08-16 12:50:52 +0100
committeraravind.est <aravindhan.a@est.tech>2024-08-19 13:53:29 +0100
commitfdfb070d8a5139963fa02e59814855b8b19576a3 (patch)
tree0e43340dc375533f1af29a1c86f29de2b9addc2c /a1-policy-management/src
parentb15c0ce6de0a226a5850977af717ef0b85d3c759 (diff)
Add database migration configuration
Database migration added. Issue-ID: CCSDK-4033 Change-Id: Ib7dc38826a4547a62bcd4839bf212758955b3d38 Signed-off-by: aravind.est <aravindhan.a@est.tech>
Diffstat (limited to 'a1-policy-management/src')
-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
4 files changed, 120 insertions, 30 deletions
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