summaryrefslogtreecommitdiffstats
path: root/a1-policy-management/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'a1-policy-management/src/main')
-rw-r--r--a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/ApplicationConfig.java4
-rw-r--r--a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/ApplicationConfigParser.java41
-rw-r--r--a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ConfigurationController.java17
-rw-r--r--a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RefreshConfigTask.java2
-rw-r--r--a1-policy-management/src/main/resources/application_configuration_schema.json151
5 files changed, 209 insertions, 6 deletions
diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/ApplicationConfig.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/ApplicationConfig.java
index 3a245190..40988e44 100644
--- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/ApplicationConfig.java
+++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/ApplicationConfig.java
@@ -45,6 +45,10 @@ public class ApplicationConfig {
private String localConfigurationFilePath;
@Getter
+ @Value("${app.config-file-schema-path:\"\"}")
+ private String configurationFileSchemaPath;
+
+ @Getter
@Value("${app.vardata-directory:null}")
private String vardataDirectory;
diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/ApplicationConfigParser.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/ApplicationConfigParser.java
index a6af2023..3cab8aa0 100644
--- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/ApplicationConfigParser.java
+++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/ApplicationConfigParser.java
@@ -24,6 +24,10 @@ import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
@@ -38,6 +42,7 @@ import javax.validation.constraints.NotNull;
import org.immutables.gson.Gson;
import org.immutables.value.Value;
+import org.json.JSONObject;
import org.onap.ccsdk.oran.a1policymanagementservice.exceptions.ServiceException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -50,6 +55,11 @@ public class ApplicationConfigParser {
private static final String CONFIG = "config";
private static final String CONTROLLER = "controller";
+ private final ApplicationConfig applicationConfig;
+
+ public ApplicationConfigParser(ApplicationConfig applicationConfig) {
+ this.applicationConfig = applicationConfig;
+ }
@Value.Immutable
@Gson.TypeAdapters
@@ -66,6 +76,8 @@ public class ApplicationConfigParser {
public ConfigParserResult parse(JsonObject root) throws ServiceException {
+ validateJsonObjectAgainstSchema(root);
+
String dmaapProducerTopicUrl = "";
String dmaapConsumerTopicUrl = "";
@@ -97,6 +109,35 @@ public class ApplicationConfigParser {
.build();
}
+ private void validateJsonObjectAgainstSchema(Object object) throws ServiceException {
+ if (applicationConfig.getConfigurationFileSchemaPath() == null
+ || applicationConfig.getConfigurationFileSchemaPath().isEmpty()) {
+ return;
+ }
+
+ try {
+ String schemaAsString = readSchemaFile();
+
+ JSONObject schemaJSON = new JSONObject(schemaAsString);
+ var schema = org.everit.json.schema.loader.SchemaLoader.load(schemaJSON);
+
+ String objectAsString = object.toString();
+ JSONObject json = new JSONObject(objectAsString);
+ schema.validate(json);
+ } catch (Exception e) {
+ throw new ServiceException("Json schema validation failure: " + e.toString());
+ }
+ }
+
+ private String readSchemaFile() throws IOException {
+ ClassLoader classLoader = getClass().getClassLoader();
+ String filePath = applicationConfig.getConfigurationFileSchemaPath();
+ URL url = classLoader.getResource(filePath);
+ File file = new File(url.getFile());
+ return new String(Files.readAllBytes(file.toPath()));
+
+ }
+
private void checkConfigurationConsistency(List<RicConfig> ricConfigs,
Map<String, ControllerConfig> controllerConfigs) throws ServiceException {
Set<String> ricUrls = new HashSet<>();
diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ConfigurationController.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ConfigurationController.java
index b677a405..e07ea284 100644
--- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ConfigurationController.java
+++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ConfigurationController.java
@@ -33,6 +33,7 @@ import io.swagger.v3.oas.annotations.tags.Tag;
import java.io.IOException;
import java.util.Optional;
+import org.onap.ccsdk.oran.a1policymanagementservice.configuration.ApplicationConfig;
import org.onap.ccsdk.oran.a1policymanagementservice.configuration.ApplicationConfigParser;
import org.onap.ccsdk.oran.a1policymanagementservice.configuration.ConfigurationFile;
import org.onap.ccsdk.oran.a1policymanagementservice.controllers.VoidResponse;
@@ -57,11 +58,17 @@ public class ConfigurationController {
public static final String API_NAME = "Management of configuration";
public static final String API_DESCRIPTION = "";
- @Autowired
- ConfigurationFile configurationFile;
+ private final ConfigurationFile configurationFile;
+ private final RefreshConfigTask refreshConfigTask;
+ private final ApplicationConfig applicationConfig;
- @Autowired
- RefreshConfigTask refreshConfigTask;
+ ConfigurationController(@Autowired ConfigurationFile configurationFile,
+ @Autowired RefreshConfigTask refreshConfigTask, @Autowired ApplicationConfig applicationConfig) {
+ this.configurationFile = configurationFile;
+ this.refreshConfigTask = refreshConfigTask;
+ this.applicationConfig = applicationConfig;
+
+ }
private static Gson gson = new GsonBuilder() //
.create(); //
@@ -85,7 +92,7 @@ public class ConfigurationController {
validateConfigFileIsUsed();
String configAsString = gson.toJson(configuration);
JsonObject configJson = JsonParser.parseString(configAsString).getAsJsonObject();
- ApplicationConfigParser configParser = new ApplicationConfigParser();
+ ApplicationConfigParser configParser = new ApplicationConfigParser(applicationConfig);
configParser.parse(configJson);
configurationFile.writeFile(configJson);
logger.info("Configuration changed through REST call.");
diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RefreshConfigTask.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RefreshConfigTask.java
index 30279815..6177ee1b 100644
--- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RefreshConfigTask.java
+++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RefreshConfigTask.java
@@ -189,7 +189,7 @@ public class RefreshConfigTask {
private Mono<ApplicationConfigParser.ConfigParserResult> parseConfiguration(JsonObject jsonObject) {
try {
- ApplicationConfigParser parser = new ApplicationConfigParser();
+ ApplicationConfigParser parser = new ApplicationConfigParser(this.appConfig);
return Mono.just(parser.parse(jsonObject));
} catch (Exception e) {
String str = e.toString();
diff --git a/a1-policy-management/src/main/resources/application_configuration_schema.json b/a1-policy-management/src/main/resources/application_configuration_schema.json
new file mode 100644
index 00000000..05135e7c
--- /dev/null
+++ b/a1-policy-management/src/main/resources/application_configuration_schema.json
@@ -0,0 +1,151 @@
+{
+ "$schema": "http://json-schema.org/draft-04/schema#",
+ "type": "object",
+ "properties": {
+ "config": {
+ "type": "object",
+ "properties": {
+ "//description": {
+ "type": "string"
+ },
+ "description": {
+ "type": "string"
+ },
+ "controller": {
+ "type": "array",
+ "items": [
+ {
+ "type": "object",
+ "properties": {
+ "name": {
+ "type": "string"
+ },
+ "baseUrl": {
+ "type": "string"
+ },
+ "userName": {
+ "type": "string"
+ },
+ "password": {
+ "type": "string"
+ }
+ },
+ "required": [
+ "name",
+ "baseUrl",
+ "userName",
+ "password"
+ ],
+ "additionalProperties": false
+ }
+ ]
+ },
+ "ric": {
+ "type": "array",
+ "items": [
+ {
+ "type": "object",
+ "properties": {
+ "name": {
+ "type": "string"
+ },
+ "baseUrl": {
+ "type": "string"
+ },
+ "controller": {
+ "type": "string"
+ },
+ "managedElementIds": {
+ "type": "array",
+ "items": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "string"
+ }
+ ]
+ }
+ },
+ "required": [
+ "name",
+ "baseUrl",
+ "managedElementIds"
+ ],
+ "additionalProperties": false
+ }
+ ]
+ },
+ "streams_publishes": {
+ "type": "object",
+ "properties": {
+ "dmaap_publisher": {
+ "type": "object",
+ "properties": {
+ "type": {
+ "type": "string"
+ },
+ "dmaap_info": {
+ "type": "object",
+ "properties": {
+ "topic_url": {
+ "type": "string"
+ }
+ },
+ "required": [
+ "topic_url"
+ ]
+ }
+ },
+ "required": [
+ "type",
+ "dmaap_info"
+ ]
+ }
+ },
+ "required": [
+ "dmaap_publisher"
+ ]
+ },
+ "streams_subscribes": {
+ "type": "object",
+ "properties": {
+ "dmaap_subscriber": {
+ "type": "object",
+ "properties": {
+ "type": {
+ "type": "string"
+ },
+ "dmaap_info": {
+ "type": "object",
+ "properties": {
+ "topic_url": {
+ "type": "string"
+ }
+ },
+ "required": [
+ "topic_url"
+ ]
+ }
+ },
+ "required": [
+ "type",
+ "dmaap_info"
+ ]
+ }
+ },
+ "required": [
+ "dmaap_subscriber"
+ ]
+ }
+ },
+ "required": [
+ "ric"
+ ],
+ "additionalProperties": false
+ }
+ },
+ "required": [
+ "config"
+ ]
+} \ No newline at end of file