aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMuthuramalingam, Brinda Santh(bs2796) <bs2796@att.com>2018-08-27 17:29:51 +0000
committerMuthuramalingam, Brinda Santh(bs2796) <bs2796@att.com>2018-08-27 17:29:51 +0000
commit208cb6ae94922c0198648aea817085793ce8bc47 (patch)
tree9dd0a599ec52c4ee3baac207980729383a2cb1d7
parent522a86b6dc2d08b16ba6aba682d5d1fd8558ad25 (diff)
Controller Blueprints Microservice
Optimise model type repository search for DB and file in blueprint repo service. Change-Id: If5458e218b723d3fff451789a73a667dd75bc91c Issue-ID: CCSDK-487 Signed-off-by: Muthuramalingam, Brinda Santh(bs2796) <bs2796@att.com>
-rw-r--r--ms/controllerblueprints/application/load/model_type/node_type/source-db.json44
-rw-r--r--ms/controllerblueprints/application/load/model_type/node_type/source-default.json18
-rw-r--r--ms/controllerblueprints/application/load/model_type/node_type/source-input.json18
-rw-r--r--ms/controllerblueprints/application/load/model_type/node_type/source-rest.json61
-rw-r--r--ms/controllerblueprints/application/load/model_type/node_type/tosca.nodes.ResourceSource.json5
-rw-r--r--ms/controllerblueprints/application/src/main/java/org/onap/ccsdk/apps/controllerblueprints/ApplicationExceptionHandler.java5
-rw-r--r--ms/controllerblueprints/modules/core/pom.xml4
-rw-r--r--ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintEnhancerService.kt6
-rw-r--r--ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRepoService.kt71
-rw-r--r--ms/controllerblueprints/modules/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRepoFileServiceTest.kt8
-rw-r--r--ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/ResourceSource.java2
-rw-r--r--ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDictionaryValidationService.kt3
-rw-r--r--ms/controllerblueprints/modules/service/load/resource_dictionary/input-source.json2
-rw-r--r--ms/controllerblueprints/modules/service/load/resource_dictionary/v4-ip-type.json2
-rw-r--r--ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/BluePrintRepoDBService.java63
-rw-r--r--ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDictionaryService.java96
-rw-r--r--ms/controllerblueprints/modules/service/src/test/resources/resourcedictionary/default_definition.json4
17 files changed, 291 insertions, 121 deletions
diff --git a/ms/controllerblueprints/application/load/model_type/node_type/source-db.json b/ms/controllerblueprints/application/load/model_type/node_type/source-db.json
new file mode 100644
index 00000000..661a9503
--- /dev/null
+++ b/ms/controllerblueprints/application/load/model_type/node_type/source-db.json
@@ -0,0 +1,44 @@
+{
+ "description": "This is Database Resource Source Node Type",
+ "version": "1.0.0",
+ "properties": {
+ "type": {
+ "required": true,
+ "type": "string",
+ "constraints": [
+ {
+ "valid_values": [
+ "SQL",
+ "PLSQL"
+ ]
+ }
+ ]
+ },
+ "query": {
+ "required": true,
+ "type": "string"
+ },
+ "input-key-mapping": {
+ "required": false,
+ "type": "map",
+ "entry_schema": {
+ "type": "string"
+ }
+ },
+ "output-key-mapping": {
+ "required": false,
+ "type": "map",
+ "entry_schema": {
+ "type": "string"
+ }
+ },
+ "key-dependencies": {
+ "required": true,
+ "type": "list",
+ "entry_schema": {
+ "type": "string"
+ }
+ }
+ },
+ "derived_from": "tosca.nodes.ResourceSource"
+} \ No newline at end of file
diff --git a/ms/controllerblueprints/application/load/model_type/node_type/source-default.json b/ms/controllerblueprints/application/load/model_type/node_type/source-default.json
new file mode 100644
index 00000000..13e234e1
--- /dev/null
+++ b/ms/controllerblueprints/application/load/model_type/node_type/source-default.json
@@ -0,0 +1,18 @@
+{
+ "description": "This is Default Resource Source Node Type",
+ "version": "1.0.0",
+ "properties": {
+ "key": {
+ "required": false,
+ "type": "string"
+ },
+ "key-dependencies": {
+ "required": true,
+ "type": "list",
+ "entry_schema": {
+ "type": "string"
+ }
+ }
+ },
+ "derived_from": "tosca.nodes.ResourceSource"
+} \ No newline at end of file
diff --git a/ms/controllerblueprints/application/load/model_type/node_type/source-input.json b/ms/controllerblueprints/application/load/model_type/node_type/source-input.json
new file mode 100644
index 00000000..126ea30b
--- /dev/null
+++ b/ms/controllerblueprints/application/load/model_type/node_type/source-input.json
@@ -0,0 +1,18 @@
+{
+ "description": "This is Input Resource Source Node Type",
+ "version": "1.0.0",
+ "properties": {
+ "key": {
+ "required": false,
+ "type": "string"
+ },
+ "key-dependencies": {
+ "required": true,
+ "type": "list",
+ "entry_schema": {
+ "type": "string"
+ }
+ }
+ },
+ "derived_from": "tosca.nodes.ResourceSource"
+} \ No newline at end of file
diff --git a/ms/controllerblueprints/application/load/model_type/node_type/source-rest.json b/ms/controllerblueprints/application/load/model_type/node_type/source-rest.json
new file mode 100644
index 00000000..f8dd8b6f
--- /dev/null
+++ b/ms/controllerblueprints/application/load/model_type/node_type/source-rest.json
@@ -0,0 +1,61 @@
+{
+ "description": "This is Rest Resource Source Node Type",
+ "version": "1.0.0",
+ "properties": {
+ "type": {
+ "required": false,
+ "type": "string",
+ "default": "JSON",
+ "constraints": [
+ {
+ "valid_values": [
+ "JSON"
+ ]
+ }
+ ]
+ },
+ "url-path": {
+ "required": true,
+ "type": "string"
+ },
+ "path": {
+ "required": true,
+ "type": "string"
+ },
+ "expression-type": {
+ "required": false,
+ "type": "string",
+ "default": "JSON_PATH",
+ "constraints": [
+ {
+ "valid_values": [
+ "JSON_PATH",
+ "JSON_POINTER"
+ ]
+ }
+ ]
+ },
+ "input-key-mapping": {
+ "required": false,
+ "type": "map",
+ "entry_schema": {
+ "type": "string"
+ }
+ },
+ "output-key-mapping": {
+ "required": false,
+ "type": "map",
+ "entry_schema": {
+ "type": "string"
+ }
+ },
+ "key-dependencies": {
+ "required": true,
+ "type": "list",
+ "entry_schema": {
+ "type": "string"
+ }
+ }
+ },
+ "derived_from": "tosca.nodes.ResourceSource"
+} \ No newline at end of file
diff --git a/ms/controllerblueprints/application/load/model_type/node_type/tosca.nodes.ResourceSource.json b/ms/controllerblueprints/application/load/model_type/node_type/tosca.nodes.ResourceSource.json
new file mode 100644
index 00000000..2ef553e2
--- /dev/null
+++ b/ms/controllerblueprints/application/load/model_type/node_type/tosca.nodes.ResourceSource.json
@@ -0,0 +1,5 @@
+{
+ "description": "TOSCA base type for Resource Sources",
+ "version": "1.0.0",
+ "derived_from": "tosca.nodes.Root"
+} \ No newline at end of file
diff --git a/ms/controllerblueprints/application/src/main/java/org/onap/ccsdk/apps/controllerblueprints/ApplicationExceptionHandler.java b/ms/controllerblueprints/application/src/main/java/org/onap/ccsdk/apps/controllerblueprints/ApplicationExceptionHandler.java
index d02be5c2..d9380a2f 100644
--- a/ms/controllerblueprints/application/src/main/java/org/onap/ccsdk/apps/controllerblueprints/ApplicationExceptionHandler.java
+++ b/ms/controllerblueprints/application/src/main/java/org/onap/ccsdk/apps/controllerblueprints/ApplicationExceptionHandler.java
@@ -16,6 +16,8 @@
package org.onap.ccsdk.apps.controllerblueprints;
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException;
import org.onap.ccsdk.apps.controllerblueprints.service.common.ErrorMessage;
import org.springframework.http.HttpStatus;
@@ -28,14 +30,17 @@ import org.springframework.web.context.request.WebRequest;
@ControllerAdvice
@RestController
public class ApplicationExceptionHandler {
+ private static EELFLogger log = EELFManager.getInstance().getLogger(ApplicationExceptionHandler.class);
@ExceptionHandler(Exception.class)
public final ResponseEntity<ErrorMessage> handleAllExceptions(Exception ex, WebRequest request) {
+ log.error("Application Exception", ex);
ErrorMessage exceptionResponse = new ErrorMessage( ex.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR.value(), ex.getLocalizedMessage());
return new ResponseEntity<>(exceptionResponse, HttpStatus.INTERNAL_SERVER_ERROR);
}
@ExceptionHandler(BluePrintException.class)
public final ResponseEntity<ErrorMessage> handleBlueprintException(BluePrintException ex, WebRequest request) {
+ log.error("Application Blueprint Exception", ex);
ErrorMessage exceptionResponse = new ErrorMessage( ex.getMessage(), ex.getCode(), ex.getLocalizedMessage());
return new ResponseEntity<>(exceptionResponse, HttpStatus.INTERNAL_SERVER_ERROR);
}
diff --git a/ms/controllerblueprints/modules/core/pom.xml b/ms/controllerblueprints/modules/core/pom.xml
index 51b3af35..ba38de63 100644
--- a/ms/controllerblueprints/modules/core/pom.xml
+++ b/ms/controllerblueprints/modules/core/pom.xml
@@ -44,6 +44,10 @@
<artifactId>jackson-module-jsonSchema</artifactId>
</dependency>
<dependency>
+ <groupId>io.projectreactor</groupId>
+ <artifactId>reactor-core</artifactId>
+ </dependency>
+ <dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
</dependency>
diff --git a/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintEnhancerService.kt b/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintEnhancerService.kt
index 64fc57fc..8bc0e6e0 100644
--- a/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintEnhancerService.kt
+++ b/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintEnhancerService.kt
@@ -217,21 +217,21 @@ open class BluePrintEnhancerDefaultService(val bluePrintRepoService: BluePrintRe
}
open fun populateNodeType(nodeTypeName: String): NodeType {
- val nodeType = bluePrintRepoService.getNodeType(nodeTypeName)
+ val nodeType = bluePrintRepoService.getNodeType(nodeTypeName)?.block()
?: throw BluePrintException(format("Couldn't get NodeType({}) from repo.", nodeTypeName))
serviceTemplate.nodeTypes?.put(nodeTypeName, nodeType)
return nodeType
}
open fun populateArtifactType(artifactTypeName: String): ArtifactType {
- val artifactType = bluePrintRepoService.getArtifactType(artifactTypeName)
+ val artifactType = bluePrintRepoService.getArtifactType(artifactTypeName)?.block()
?: throw BluePrintException(format("Couldn't get ArtifactType({}) from repo.", artifactTypeName))
serviceTemplate.artifactTypes?.put(artifactTypeName, artifactType)
return artifactType
}
open fun populateDataTypes(dataTypeName: String): DataType {
- val dataType = bluePrintRepoService.getDataType(dataTypeName)
+ val dataType = bluePrintRepoService.getDataType(dataTypeName)?.block()
?: throw BluePrintException(format("Couldn't get DataType({}) from repo.", dataTypeName))
serviceTemplate.dataTypes?.put(dataTypeName, dataType)
return dataType
diff --git a/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRepoService.kt b/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRepoService.kt
index a529a85f..8c444618 100644
--- a/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRepoService.kt
+++ b/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRepoService.kt
@@ -17,11 +17,16 @@
package org.onap.ccsdk.apps.controllerblueprints.core.service
+import com.google.common.base.Preconditions
import org.apache.commons.io.FileUtils
+import org.apache.commons.lang3.StringUtils
import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants
import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException
import org.onap.ccsdk.apps.controllerblueprints.core.data.*
import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils
+import org.slf4j.Logger
+import org.slf4j.LoggerFactory
+import reactor.core.publisher.Mono
import java.io.File
import java.io.Serializable
import java.nio.charset.Charset
@@ -35,25 +40,27 @@ import java.nio.charset.Charset
interface BluePrintRepoService : Serializable {
@Throws(BluePrintException::class)
- fun getNodeType(nodeTypeName: String): NodeType?
+ fun getNodeType(nodeTypeName: String): Mono<NodeType>?
@Throws(BluePrintException::class)
- fun getDataType(dataTypeName: String): DataType?
+ fun getDataType(dataTypeName: String): Mono<DataType>?
@Throws(BluePrintException::class)
- fun getArtifactType(artifactTypeName: String): ArtifactType?
+ fun getArtifactType(artifactTypeName: String): Mono<ArtifactType>?
@Throws(BluePrintException::class)
- fun getRelationshipType(relationshipTypeName: String): RelationshipType?
+ fun getRelationshipType(relationshipTypeName: String): Mono<RelationshipType>?
@Throws(BluePrintException::class)
- fun getCapabilityDefinition(capabilityDefinitionName: String): CapabilityDefinition?
+ fun getCapabilityDefinition(capabilityDefinitionName: String): Mono<CapabilityDefinition>?
}
class BluePrintRepoFileService(val basePath: String) : BluePrintRepoService {
+ private val log: Logger = LoggerFactory.getLogger(BluePrintRepoFileService::class.java)
+
val dataTypePath = basePath.plus(BluePrintConstants.PATH_DIVIDER).plus(BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE)
val nodeTypePath = basePath.plus(BluePrintConstants.PATH_DIVIDER).plus(BluePrintConstants.MODEL_DEFINITION_TYPE_NODE_TYPE)
val artifactTypePath = basePath.plus(BluePrintConstants.PATH_DIVIDER).plus(BluePrintConstants.MODEL_DEFINITION_TYPE_ARTIFACT_TYPE)
@@ -61,33 +68,47 @@ class BluePrintRepoFileService(val basePath: String) : BluePrintRepoService {
val relationshipTypePath = basePath.plus(BluePrintConstants.PATH_DIVIDER).plus(BluePrintConstants.MODEL_DEFINITION_TYPE_RELATIONSHIP_TYPE)
val extension = ".json"
- override fun getDataType(dataTypeName: String): DataType? {
- val content = FileUtils.readFileToString(File(dataTypePath.plus(BluePrintConstants.PATH_DIVIDER)
- .plus(dataTypeName).plus(extension)), Charset.defaultCharset())
- return JacksonUtils.readValue(content)
+ override fun getDataType(dataTypeName: String): Mono<DataType>? {
+ val fileName = dataTypePath.plus(BluePrintConstants.PATH_DIVIDER)
+ .plus(dataTypeName).plus(extension)
+ return getModelType(fileName, DataType::class.java)
+ }
+
+ override fun getNodeType(nodeTypeName: String): Mono<NodeType>? {
+ val fileName = nodeTypePath.plus(BluePrintConstants.PATH_DIVIDER).plus(nodeTypeName).plus(extension)
+ return getModelType(fileName, NodeType::class.java)
}
- override fun getNodeType(nodeTypeName: String): NodeType? {
- val content = FileUtils.readFileToString(File(nodeTypePath.plus(BluePrintConstants.PATH_DIVIDER)
- .plus(nodeTypeName).plus(extension)), Charset.defaultCharset())
- return JacksonUtils.readValue(content)
+ override fun getArtifactType(artifactTypeName: String): Mono<ArtifactType>? {
+ val fileName = artifactTypePath.plus(BluePrintConstants.PATH_DIVIDER)
+ .plus(artifactTypeName).plus(extension)
+ return getModelType(fileName, ArtifactType::class.java)
}
- override fun getArtifactType(artifactTypeName: String): ArtifactType? {
- val content = FileUtils.readFileToString(File(artifactTypePath.plus(BluePrintConstants.PATH_DIVIDER)
- .plus(artifactTypeName).plus(extension)), Charset.defaultCharset())
- return JacksonUtils.readValue(content)
+ override fun getRelationshipType(relationshipTypeName: String): Mono<RelationshipType>? {
+ val fileName = relationshipTypePath.plus(BluePrintConstants.PATH_DIVIDER)
+ .plus(relationshipTypeName).plus(extension)
+ return getModelType(fileName, RelationshipType::class.java)
}
- override fun getRelationshipType(relationshipTypeName: String): RelationshipType? {
- val content = FileUtils.readFileToString(File(relationshipTypePath.plus(BluePrintConstants.PATH_DIVIDER)
- .plus(relationshipTypeName).plus(extension)), Charset.defaultCharset())
- return JacksonUtils.readValue(content)
+ override fun getCapabilityDefinition(capabilityDefinitionName: String): Mono<CapabilityDefinition>? {
+ val fileName = capabilityTypePath.plus(BluePrintConstants.PATH_DIVIDER)
+ .plus(capabilityDefinitionName).plus(extension)
+ return getModelType(fileName, CapabilityDefinition::class.java)
+ }
+
+ private fun <T> getModelType(fileName: String, valueType: Class<T>): Mono<T> {
+ return getFileContent(fileName).map { content ->
+ Preconditions.checkArgument(StringUtils.isNotBlank(content),
+ String.format("Failed to get model content for file (%s)", fileName))
+
+ JacksonUtils.readValue(content, valueType)
+ ?: throw BluePrintException(String.format("Failed to get model file from content for file (%s)", fileName))
+
+ }
}
- override fun getCapabilityDefinition(capabilityDefinitionName: String): CapabilityDefinition? {
- val content = FileUtils.readFileToString(File(capabilityTypePath.plus(BluePrintConstants.PATH_DIVIDER)
- .plus(capabilityDefinitionName).plus(extension)), Charset.defaultCharset())
- return JacksonUtils.readValue(content)
+ private fun getFileContent(fileName: String): Mono<String> {
+ return Mono.just(FileUtils.readFileToString(File(fileName), Charset.defaultCharset()))
}
} \ No newline at end of file
diff --git a/ms/controllerblueprints/modules/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRepoFileServiceTest.kt b/ms/controllerblueprints/modules/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRepoFileServiceTest.kt
index 574eae6d..4731935e 100644
--- a/ms/controllerblueprints/modules/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRepoFileServiceTest.kt
+++ b/ms/controllerblueprints/modules/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRepoFileServiceTest.kt
@@ -18,6 +18,7 @@
package org.onap.ccsdk.apps.controllerblueprints.core.service
import org.junit.Test
+import java.io.FileNotFoundException
import kotlin.test.assertNotNull
/**
@@ -49,4 +50,11 @@ class BluePrintRepoFileServiceTest {
val nodeType = bluePrintEnhancerRepoFileService.getArtifactType("artifact-template-velocity")
assertNotNull(nodeType, "Failed to get ArtifactType from repo")
}
+
+ @Test(expected = FileNotFoundException::class)
+ fun testModelNotFound() {
+ val bluePrintEnhancerRepoFileService = BluePrintRepoFileService(basePath)
+ val dataType = bluePrintEnhancerRepoFileService.getDataType("dt-not-found")
+ assertNotNull(dataType, "Failed to get DataType from repo")
+ }
} \ No newline at end of file
diff --git a/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/ResourceSource.java b/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/ResourceSource.java
index 735832cb..1ef69fa9 100644
--- a/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/ResourceSource.java
+++ b/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/ResourceSource.java
@@ -17,6 +17,6 @@
package org.onap.ccsdk.apps.controllerblueprints.resource.dict.data;
import java.io.Serializable;
-
+@Deprecated
public interface ResourceSource extends Serializable {
}
diff --git a/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDictionaryValidationService.kt b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDictionaryValidationService.kt
index cef1f158..5a1e3812 100644
--- a/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDictionaryValidationService.kt
+++ b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDictionaryValidationService.kt
@@ -1,5 +1,6 @@
/*
* Copyright © 2018 IBM.
+ * Modifications Copyright © 2017-2018 AT&T Intellectual Property.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -46,7 +47,7 @@ open class ResourceDictionaryDefaultValidationService(val bluePrintRepoService:
resourceDefinition.sources.forEach { (name, nodeTemplate) ->
val sourceType = nodeTemplate.type
- val sourceNodeType = bluePrintRepoService.getNodeType(sourceType)
+ val sourceNodeType = bluePrintRepoService.getNodeType(sourceType)?.block()
?: throw BluePrintException(format("Failed to get node type definition for source({})", sourceType))
// Validate Property Name, expression, values and Data Type
diff --git a/ms/controllerblueprints/modules/service/load/resource_dictionary/input-source.json b/ms/controllerblueprints/modules/service/load/resource_dictionary/input-source.json
index c34c252b..610e8fc0 100644
--- a/ms/controllerblueprints/modules/service/load/resource_dictionary/input-source.json
+++ b/ms/controllerblueprints/modules/service/load/resource_dictionary/input-source.json
@@ -7,7 +7,7 @@
"resource-path": "action-name",
"resource-type": "ONAP",
"updated-by": "brindasanth@onap.com",
- "tags": null,
+ "tags": "action-name, brindasanth",
"sources": {
"input": {
"type": "source-input",
diff --git a/ms/controllerblueprints/modules/service/load/resource_dictionary/v4-ip-type.json b/ms/controllerblueprints/modules/service/load/resource_dictionary/v4-ip-type.json
index 349183bd..e7e06000 100644
--- a/ms/controllerblueprints/modules/service/load/resource_dictionary/v4-ip-type.json
+++ b/ms/controllerblueprints/modules/service/load/resource_dictionary/v4-ip-type.json
@@ -7,7 +7,7 @@
"resource-path": "vnf/v4-ip-type",
"resource-type": "ONAP",
"updated-by": "brindasanth@onap.com",
- "tags": null,
+ "tags": "v4-ip-type, source-input, brindasanth",
"sources": {
"input": {
"type": "source-input",
diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/BluePrintRepoDBService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/BluePrintRepoDBService.java
index 4a26119c..4c11d8c6 100644
--- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/BluePrintRepoDBService.java
+++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/BluePrintRepoDBService.java
@@ -26,6 +26,7 @@ import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils;
import org.onap.ccsdk.apps.controllerblueprints.service.domain.ModelType;
import org.onap.ccsdk.apps.controllerblueprints.service.repository.ModelTypeRepository;
import org.springframework.stereotype.Service;
+import reactor.core.publisher.Mono;
import java.util.Optional;
@@ -43,59 +44,51 @@ public class BluePrintRepoDBService implements BluePrintRepoService {
this.modelTypeRepository = modelTypeRepository;
}
-
@Override
- public NodeType getNodeType(String nodeTypeName) throws BluePrintException {
- Preconditions.checkArgument(StringUtils.isNotBlank(nodeTypeName), "NodeType name is missing");
- String content = getModelDefinitions(nodeTypeName);
- Preconditions.checkArgument(StringUtils.isNotBlank(content), "NodeType content is missing");
- return JacksonUtils.readValue(content, NodeType.class);
+ public Mono<NodeType> getNodeType(String nodeTypeName) throws BluePrintException {
+ return getModelType(nodeTypeName, NodeType.class);
}
-
@Override
- public DataType getDataType(String dataTypeName) throws BluePrintException {
- Preconditions.checkArgument(StringUtils.isNotBlank(dataTypeName), "DataType name is missing");
- String content = getModelDefinitions(dataTypeName);
- Preconditions.checkArgument(StringUtils.isNotBlank(content), "DataType content is missing");
- return JacksonUtils.readValue(content, DataType.class);
+ public Mono<DataType> getDataType(String dataTypeName) throws BluePrintException {
+ return getModelType(dataTypeName, DataType.class);
}
-
@Override
- public ArtifactType getArtifactType(String artifactTypeName) throws BluePrintException {
- Preconditions.checkArgument(StringUtils.isNotBlank(artifactTypeName), "ArtifactType name is missing");
- String content = getModelDefinitions(artifactTypeName);
- Preconditions.checkArgument(StringUtils.isNotBlank(content), "ArtifactType content is missing");
- return JacksonUtils.readValue(content, ArtifactType.class);
+ public Mono<ArtifactType> getArtifactType(String artifactTypeName) throws BluePrintException {
+ return getModelType(artifactTypeName, ArtifactType.class);
}
-
@Override
- public RelationshipType getRelationshipType(String relationshipTypeName) throws BluePrintException {
- Preconditions.checkArgument(StringUtils.isNotBlank(relationshipTypeName), "RelationshipType name is missing");
- String content = getModelDefinitions(relationshipTypeName);
- Preconditions.checkArgument(StringUtils.isNotBlank(content), "RelationshipType content is missing");
- return JacksonUtils.readValue(content, RelationshipType.class);
+ public Mono<RelationshipType> getRelationshipType(String relationshipTypeName) throws BluePrintException {
+ return getModelType(relationshipTypeName, RelationshipType.class);
}
-
@Override
- public CapabilityDefinition getCapabilityDefinition(String capabilityDefinitionName) throws BluePrintException {
- Preconditions.checkArgument(StringUtils.isNotBlank(capabilityDefinitionName), "CapabilityDefinition name is missing");
- String content = getModelDefinitions(capabilityDefinitionName);
- Preconditions.checkArgument(StringUtils.isNotBlank(content), "CapabilityDefinition content is missing");
- return JacksonUtils.readValue(content, CapabilityDefinition.class);
+ public Mono<CapabilityDefinition> getCapabilityDefinition(String capabilityDefinitionName) throws BluePrintException {
+ return getModelType(capabilityDefinitionName, CapabilityDefinition.class);
}
- private String getModelDefinitions(String modelName) throws BluePrintException {
+ private <T> Mono<T> getModelType(String modelName, Class<T> valueClass) throws BluePrintException {
+ Preconditions.checkArgument(StringUtils.isNotBlank(modelName),
+ "Failed to get model from repo, model name is missing");
+
+ return getModelDefinitions(modelName).map(content -> {
+ Preconditions.checkArgument(StringUtils.isNotBlank(content),
+ String.format("Failed to get model content for model name (%s)", modelName));
+ return JacksonUtils.readValue(content, valueClass);
+ }
+ );
+ }
+
+ private Mono<String> getModelDefinitions(String modelName) throws BluePrintException {
String modelDefinition = null;
- Optional<ModelType> modelTypedb = modelTypeRepository.findByModelName(modelName);
- if (modelTypedb.isPresent()) {
- modelDefinition = modelTypedb.get().getDefinition();
+ Optional<ModelType> modelTypeDb = modelTypeRepository.findByModelName(modelName);
+ if (modelTypeDb.isPresent()) {
+ modelDefinition = modelTypeDb.get().getDefinition();
} else {
throw new BluePrintException(String.format("failed to get model definition (%s) from repo", modelName));
}
- return modelDefinition;
+ return Mono.just(modelDefinition);
}
}
diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDictionaryService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDictionaryService.java
index 5420dd39..629b94c0 100644
--- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDictionaryService.java
+++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDictionaryService.java
@@ -17,6 +17,7 @@
package org.onap.ccsdk.apps.controllerblueprints.service;
+import com.google.common.base.Preconditions;
import org.apache.commons.lang3.StringUtils;
import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException;
import org.onap.ccsdk.apps.controllerblueprints.core.data.EntrySchema;
@@ -112,60 +113,51 @@ public class ResourceDictionaryService {
*/
public ResourceDictionary saveResourceDictionary(ResourceDictionary resourceDictionary)
throws BluePrintException {
- if (resourceDictionary != null) {
- ResourceDictionaryValidator.validateResourceDictionary(resourceDictionary);
-
- ResourceDefinition resourceDefinition =
- JacksonUtils.readValue(resourceDictionary.getDefinition(), ResourceDefinition.class);
- // Check the Source already Present
- resourceDictionaryValidationService.validate(resourceDefinition);
-
- if (resourceDefinition == null) {
- throw new BluePrintException(
- "Resource dictionary definition is not valid content " + resourceDictionary.getDefinition());
- }
-
- resourceDefinition.setName(resourceDictionary.getName());
- resourceDefinition.setResourcePath(resourceDictionary.getResourcePath());
- resourceDefinition.setResourceType(resourceDictionary.getResourceType());
-
- PropertyDefinition propertyDefinition = new PropertyDefinition();
- propertyDefinition.setType(resourceDictionary.getDataType());
- propertyDefinition.setDescription(resourceDictionary.getDescription());
- if (StringUtils.isNotBlank(resourceDictionary.getEntrySchema())) {
- EntrySchema entrySchema = new EntrySchema();
- entrySchema.setType(resourceDictionary.getEntrySchema());
- propertyDefinition.setEntrySchema(entrySchema);
- } else {
- propertyDefinition.setEntrySchema(null);
- }
- resourceDefinition.setTags(resourceDictionary.getTags());
- resourceDefinition.setUpdatedBy(resourceDictionary.getUpdatedBy());
-
- String definitionContent = JacksonUtils.getJson(resourceDefinition, true);
- resourceDictionary.setDefinition(definitionContent);
-
- Optional<ResourceDictionary> dbResourceDictionaryData =
- resourceDictionaryRepository.findByName(resourceDictionary.getName());
- if (dbResourceDictionaryData.isPresent()) {
- ResourceDictionary dbResourceDictionary = dbResourceDictionaryData.get();
-
- dbResourceDictionary.setName(resourceDictionary.getName());
- dbResourceDictionary.setDefinition(resourceDictionary.getDefinition());
- dbResourceDictionary.setDescription(resourceDictionary.getDescription());
- dbResourceDictionary.setResourceType(resourceDictionary.getResourceType());
- dbResourceDictionary.setResourcePath(resourceDictionary.getResourcePath());
- dbResourceDictionary.setDataType(resourceDictionary.getDataType());
- dbResourceDictionary.setEntrySchema(resourceDictionary.getEntrySchema());
- dbResourceDictionary.setTags(resourceDictionary.getTags());
- dbResourceDictionary.setValidValues(resourceDictionary.getValidValues());
- resourceDictionary = resourceDictionaryRepository.save(dbResourceDictionary);
- } else {
- resourceDictionary = resourceDictionaryRepository.save(resourceDictionary);
- }
+ Preconditions.checkNotNull(resourceDictionary, "Resource Dictionary information is missing");
+ Preconditions.checkArgument(StringUtils.isNotBlank(resourceDictionary.getDefinition()),
+ "Resource Dictionary definition information is missing");
+
+ ResourceDefinition resourceDefinition =
+ JacksonUtils.readValue(resourceDictionary.getDefinition(), ResourceDefinition.class);
+ // Validate the Resource Definitions
+ resourceDictionaryValidationService.validate(resourceDefinition);
+
+ resourceDictionary.setResourceType(resourceDefinition.getResourceType());
+ resourceDictionary.setResourcePath(resourceDefinition.getResourcePath());
+ resourceDictionary.setTags(resourceDefinition.getTags());
+ resourceDefinition.setUpdatedBy(resourceDictionary.getUpdatedBy());
+ // Set the Property Definitions
+ PropertyDefinition propertyDefinition = resourceDefinition.getProperty();
+ resourceDictionary.setDescription(propertyDefinition.getDescription());
+ resourceDictionary.setDataType(propertyDefinition.getType());
+ if(propertyDefinition.getEntrySchema() != null){
+ resourceDictionary.setEntrySchema(propertyDefinition.getEntrySchema().getType());
+ }
+
+ String definitionContent = JacksonUtils.getJson(resourceDefinition, true);
+ resourceDictionary.setDefinition(definitionContent);
+
+ ResourceDictionaryValidator.validateResourceDictionary(resourceDictionary);
+
+ Optional<ResourceDictionary> dbResourceDictionaryData =
+ resourceDictionaryRepository.findByName(resourceDictionary.getName());
+ if (dbResourceDictionaryData.isPresent()) {
+ ResourceDictionary dbResourceDictionary = dbResourceDictionaryData.get();
+
+ dbResourceDictionary.setName(resourceDictionary.getName());
+ dbResourceDictionary.setDefinition(resourceDictionary.getDefinition());
+ dbResourceDictionary.setDescription(resourceDictionary.getDescription());
+ dbResourceDictionary.setResourceType(resourceDictionary.getResourceType());
+ dbResourceDictionary.setResourcePath(resourceDictionary.getResourcePath());
+ dbResourceDictionary.setTags(resourceDictionary.getTags());
+ dbResourceDictionary.setUpdatedBy(resourceDictionary.getUpdatedBy());
+ dbResourceDictionary.setDataType(resourceDictionary.getDataType());
+ dbResourceDictionary.setEntrySchema(resourceDictionary.getEntrySchema());
+ resourceDictionary = resourceDictionaryRepository.save(dbResourceDictionary);
} else {
- throw new BluePrintException("Resource Dictionary information is missing");
+ resourceDictionary = resourceDictionaryRepository.save(resourceDictionary);
}
+
return resourceDictionary;
}
diff --git a/ms/controllerblueprints/modules/service/src/test/resources/resourcedictionary/default_definition.json b/ms/controllerblueprints/modules/service/src/test/resources/resourcedictionary/default_definition.json
index 986ba706..198823bb 100644
--- a/ms/controllerblueprints/modules/service/src/test/resources/resourcedictionary/default_definition.json
+++ b/ms/controllerblueprints/modules/service/src/test/resources/resourcedictionary/default_definition.json
@@ -1,5 +1,5 @@
{
- "name": "v4-aggregat-list",
+ "name": "ipaddress",
"property": {
"description": "name of the ",
"type": "list",
@@ -10,7 +10,7 @@
"updated-by": "Brinda Santh (bs2796)",
"resource-type": "ONAP",
"resource-path": "/v4-aggregat-list",
- "tags": null,
+ "tags": "ipaddress",
"sources": {
"input": {
"type": "source-input"