From c0e77765214b94cc493b181bcc1d58165ac8b09f Mon Sep 17 00:00:00 2001 From: "Muthuramalingam, Brinda Santh(bs2796)" Date: Tue, 28 Aug 2018 23:58:12 +0000 Subject: Controller Blueprints Microservice Add Resource Assignment Validation Service and their Test cases. Change-Id: I106be2bfc03115867041ca341947a4662cf126c4 Issue-ID: CCSDK-487 Signed-off-by: Muthuramalingam, Brinda Santh(bs2796) --- .../core/service/BluePrintRepoService.kt | 12 +- .../core/utils/JacksonUtils.kt | 18 ++- .../core/service/BluePrintRepoFileServiceTest.kt | 5 +- .../service/ResourceAssignmentValidationService.kt | 133 +++++++++++++++++++++ .../service/ResourceDictionaryValidationService.kt | 14 ++- .../ResourceAssignmentValidationServiceTest.kt | 56 +++++++++ .../src/test/resources/validation/cyclic.json | 111 +++++++++++++++++ .../src/test/resources/validation/duplicate.json | 110 +++++++++++++++++ .../src/test/resources/validation/success.json | 110 +++++++++++++++++ .../service/BluePrintRepoDBService.java | 22 ++-- .../service/repository/ModelTypeRepository.java | 25 ++-- 11 files changed, 583 insertions(+), 33 deletions(-) create mode 100644 ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceAssignmentValidationService.kt create mode 100644 ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceAssignmentValidationServiceTest.kt create mode 100644 ms/controllerblueprints/modules/resource-dict/src/test/resources/validation/cyclic.json create mode 100644 ms/controllerblueprints/modules/resource-dict/src/test/resources/validation/duplicate.json create mode 100644 ms/controllerblueprints/modules/resource-dict/src/test/resources/validation/success.json (limited to 'ms/controllerblueprints/modules') 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 8c444618..8c254732 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 @@ -61,12 +61,12 @@ 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) - val capabilityTypePath = basePath.plus(BluePrintConstants.PATH_DIVIDER).plus(BluePrintConstants.MODEL_DEFINITION_TYPE_CAPABILITY_TYPE) - val relationshipTypePath = basePath.plus(BluePrintConstants.PATH_DIVIDER).plus(BluePrintConstants.MODEL_DEFINITION_TYPE_RELATIONSHIP_TYPE) - val extension = ".json" + private val dataTypePath = basePath.plus(BluePrintConstants.PATH_DIVIDER).plus(BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE) + private val nodeTypePath = basePath.plus(BluePrintConstants.PATH_DIVIDER).plus(BluePrintConstants.MODEL_DEFINITION_TYPE_NODE_TYPE) + private val artifactTypePath = basePath.plus(BluePrintConstants.PATH_DIVIDER).plus(BluePrintConstants.MODEL_DEFINITION_TYPE_ARTIFACT_TYPE) + private val capabilityTypePath = basePath.plus(BluePrintConstants.PATH_DIVIDER).plus(BluePrintConstants.MODEL_DEFINITION_TYPE_CAPABILITY_TYPE) + private val relationshipTypePath = basePath.plus(BluePrintConstants.PATH_DIVIDER).plus(BluePrintConstants.MODEL_DEFINITION_TYPE_RELATIONSHIP_TYPE) + private val extension = ".json" override fun getDataType(dataTypeName: String): Mono? { val fileName = dataTypePath.plus(BluePrintConstants.PATH_DIVIDER) diff --git a/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonUtils.kt b/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonUtils.kt index 697a7100..886c3d2a 100644 --- a/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonUtils.kt +++ b/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonUtils.kt @@ -102,6 +102,20 @@ object JacksonUtils { return objectMapper.readValue>(content, javaType) } + @JvmStatic + fun getListFromFile(fileName: String, valueType: Class): List? { + val content: String = FileUtils.readFileToString(File(fileName), Charset.defaultCharset()) + ?: throw BluePrintException(format("Failed to read json file : {}", fileName)) + return getListFromJson(content, valueType) + } + + @JvmStatic + fun getListFromClassPathFile(fileName: String, valueType: Class): List? { + val content: String = IOUtils.toString(JacksonUtils::class.java.classLoader.getResourceAsStream(fileName), Charset.defaultCharset()) + ?: throw BluePrintException(String.format("Failed to read json file : %s", fileName)) + return getListFromJson(content, valueType) + } + @JvmStatic fun getMapFromJson(content: String, valueType: Class): MutableMap? { val objectMapper = jacksonObjectMapper() @@ -110,13 +124,13 @@ object JacksonUtils { } @JvmStatic - fun checkJsonNodeValueOfType(type: String, jsonNode: JsonNode) : Boolean { + fun checkJsonNodeValueOfType(type: String, jsonNode: JsonNode): Boolean { if (BluePrintTypes.validPrimitiveTypes().contains(type)) { return checkJsonNodeValueOfPrimitiveType(type, jsonNode) } else if (BluePrintTypes.validCollectionTypes().contains(type)) { return checkJsonNodeValueOfCollectionType(type, jsonNode) } - return false; + return false } @JvmStatic 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 4731935e..081f4fe3 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 @@ -29,31 +29,28 @@ import kotlin.test.assertNotNull class BluePrintRepoFileServiceTest { val basePath = "load/model_type" + private val bluePrintEnhancerRepoFileService = BluePrintRepoFileService(basePath) @Test fun testGetDataType() { - val bluePrintEnhancerRepoFileService = BluePrintRepoFileService(basePath) val dataType = bluePrintEnhancerRepoFileService.getDataType("dt-v4-aggregate") assertNotNull(dataType, "Failed to get DataType from repo") } @Test fun testGetNodeType() { - val bluePrintEnhancerRepoFileService = BluePrintRepoFileService(basePath) val nodeType = bluePrintEnhancerRepoFileService.getNodeType("component-resource-assignment") assertNotNull(nodeType, "Failed to get NodeType from repo") } @Test fun testGetArtifactType() { - val bluePrintEnhancerRepoFileService = BluePrintRepoFileService(basePath) 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") } diff --git a/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceAssignmentValidationService.kt b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceAssignmentValidationService.kt new file mode 100644 index 00000000..6809831f --- /dev/null +++ b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceAssignmentValidationService.kt @@ -0,0 +1,133 @@ +/* + * 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. + * 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. + */ + +package org.onap.ccsdk.apps.controllerblueprints.resource.dict.service + +import org.apache.commons.lang3.text.StrBuilder +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException +import org.onap.ccsdk.apps.controllerblueprints.core.utils.TopologicalSortingUtils +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.validator.ResourceAssignmentValidator +import org.slf4j.LoggerFactory +import org.apache.commons.collections.CollectionUtils +import org.apache.commons.lang3.StringUtils +import java.io.Serializable +/** + * ResourceAssignmentValidationService. + * + * @author Brinda Santh + */ +interface ResourceAssignmentValidationService : Serializable { + + @Throws(BluePrintException::class) + fun validate(resourceAssignments: List): Boolean +} + +/** + * ResourceAssignmentValidationDefaultService. + * + * @author Brinda Santh + */ +open class ResourceAssignmentValidationDefaultService : ResourceAssignmentValidationService { + private val log = LoggerFactory.getLogger(ResourceAssignmentValidator::class.java) + open var resourceAssignments: List = arrayListOf() + open var resourceAssignmentMap: MutableMap = hashMapOf() + open val validationMessage = StrBuilder() + + override fun validate(resourceAssignments: List): Boolean { + this.resourceAssignments = resourceAssignments + validateSources(resourceAssignments) + validateDuplicateDictionaryKeys() + validateCyclicDependency() + if (StringUtils.isNotBlank(validationMessage)) { + throw BluePrintException("Resource Assignment Validation :" + validationMessage.toString()) + } + return true + } + + open fun validateSources(resourceAssignments: List) { + log.info("validating resource assignment sources") + } + + open fun validateDuplicateDictionaryKeys() { + val uniqueDictionaryKeys = hashSetOf() + + this.resourceAssignments.forEach { resourceAssignment -> + // Check Duplicate Names + if (!resourceAssignmentMap.containsKey(resourceAssignment.name)) { + resourceAssignmentMap[resourceAssignment.name] = resourceAssignment + } else { + validationMessage.appendln(String.format("Duplicate Assignment Template Key (%s) is Present", + resourceAssignment.name)) + } + // Check duplicate Dictionary Keys + if (!uniqueDictionaryKeys.contains(resourceAssignment.dictionaryName!!)) { + uniqueDictionaryKeys.add(resourceAssignment.dictionaryName!!) + } else { + validationMessage.appendln( + String.format("Duplicate Assignment Dictionary Key (%s) present with Template Key (%s)", + resourceAssignment.dictionaryName, resourceAssignment.name)) + } + } + } + + open fun validateCyclicDependency() { + val startResourceAssignment = ResourceAssignment() + startResourceAssignment.name = "*" + + val topologySorting = TopologicalSortingUtils() + this.resourceAssignmentMap.forEach { assignmentKey, assignment -> + if (CollectionUtils.isNotEmpty(assignment.dependencies)) { + for (dependency in assignment.dependencies!!) { + topologySorting.add(resourceAssignmentMap[dependency]!!, assignment) + } + } else { + topologySorting.add(startResourceAssignment, assignment) + } + } + + if (!topologySorting.isDag) { + val graph = getTopologicalGraph(topologySorting) + validationMessage.appendln("Cyclic Dependency :$graph") + } + } + + open fun getTopologicalGraph(topologySorting: TopologicalSortingUtils): String { + val s = StringBuilder() + val neighbors = topologySorting.getNeighbors() + + neighbors.forEach { v, vs -> + if (v.name == "*") { + s.append("\n * -> [") + for (resourceAssignment in vs) { + s.append("(" + resourceAssignment.dictionaryName + ":" + resourceAssignment.name + + "),") + } + s.append("]") + } else { + s.append("\n (" + v.dictionaryName + ":" + v.name + ") -> [") + for (resourceAssignment in vs) { + s.append("(" + resourceAssignment.dictionaryName + ":" + resourceAssignment.name + + "),") + } + s.append("]") + } + } + return s.toString() + } + + +} \ No newline at end of file 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 81bb37d0..e4835a06 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 @@ -31,15 +31,23 @@ import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition import org.slf4j.LoggerFactory import java.io.Serializable - +/** + * ResourceDictionaryValidationService. + * + * @author Brinda Santh + */ interface ResourceDictionaryValidationService : Serializable { @Throws(BluePrintException::class) fun validate(resourceDefinition: ResourceDefinition) } - -open class ResourceDictionaryDefaultValidationService(val bluePrintRepoService: BluePrintRepoService) : ResourceDictionaryValidationService { +/** + * ResourceDictionaryDefaultValidationService. + * + * @author Brinda Santh + */ +open class ResourceDictionaryDefaultValidationService(private val bluePrintRepoService: BluePrintRepoService) : ResourceDictionaryValidationService { private val log = LoggerFactory.getLogger(ResourceDictionaryDefaultValidationService::class.java) diff --git a/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceAssignmentValidationServiceTest.kt b/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceAssignmentValidationServiceTest.kt new file mode 100644 index 00000000..4d8301f4 --- /dev/null +++ b/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceAssignmentValidationServiceTest.kt @@ -0,0 +1,56 @@ +/* + * 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. + * 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. + */ + +package org.onap.ccsdk.apps.controllerblueprints.resource.dict.service + +import org.junit.Assert +import org.junit.Test +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException +import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment +import org.slf4j.LoggerFactory +/** + * ResourceAssignmentValidationServiceTest. + * + * @author Brinda Santh + */ +class ResourceAssignmentValidationServiceTest { + private val log = LoggerFactory.getLogger(ResourceAssignmentValidationServiceTest::class.java) + @Test + fun testValidateSuccess() { + log.info("**************** testValidateSuccess *****************") + val assignments = JacksonUtils.getListFromClassPathFile("validation/success.json", ResourceAssignment::class.java) + val resourceAssignmentValidator = ResourceAssignmentValidationDefaultService() + val result = resourceAssignmentValidator.validate(assignments!!) + Assert.assertTrue("Failed to Validate", result) + } + + @Test(expected = BluePrintException::class) + fun testValidateDuplicate() { + log.info(" **************** testValidateDuplicate *****************") + val assignments = JacksonUtils.getListFromClassPathFile("validation/duplicate.json", ResourceAssignment::class.java) + val resourceAssignmentValidator = ResourceAssignmentValidationDefaultService() + resourceAssignmentValidator.validate(assignments!!) + } + + @Test(expected = BluePrintException::class) + fun testValidateCyclic() { + log.info(" **************** testValidateCyclic *****************") + val assignments = JacksonUtils.getListFromClassPathFile("validation/cyclic.json", ResourceAssignment::class.java) + val resourceAssignmentValidator = ResourceAssignmentValidationDefaultService() + resourceAssignmentValidator.validate(assignments!!) + } +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/resource-dict/src/test/resources/validation/cyclic.json b/ms/controllerblueprints/modules/resource-dict/src/test/resources/validation/cyclic.json new file mode 100644 index 00000000..d837dc5d --- /dev/null +++ b/ms/controllerblueprints/modules/resource-dict/src/test/resources/validation/cyclic.json @@ -0,0 +1,111 @@ +[ + { + "name": "vnf-id", + "input-param": true, + "property": { + "type": "string", + "required": true + }, + "dictionary-name": "vnf-id", + "dictionary-source": "input", + "dependencies": [] + }, + { + "name": "service-instance-id", + "input-param": true, + "property": { + "type": "string", + "required": true + }, + "dictionary-name": "service-instance-id", + "dictionary-source": "input", + "dependencies": [] + }, + { + "name": "bundle-id", + "input-param": true, + "property": { + "type": "string", + "required": true + }, + "dictionary-name": "bundle-id", + "dictionary-source": "mdsal", + "dependencies": [ + "vnf-id" + ] + }, + { + "name": "bundle-ip", + "input-param": true, + "property": { + "type": "string", + "required": true + }, + "dictionary-name": "bundle-ip", + "dictionary-source": "mdsal", + "dependencies": [ + "vnf-id" + ] + }, + { + "name": "bundle-mac", + "input-param": true, + "property": { + "type": "string" + }, + "dictionary-name": "bundle-mac", + "dictionary-source": "mdsal", + "dependencies": [ + "vnf-id", + "bundle-id" + ] + }, + { + "name": "managed-ip", + "input-param": true, + "property": { + "type": "string" + }, + "dictionary-name": "managed-ip", + "dictionary-source": "mdsal", + "dependencies": [ + "loopback-ip" + ] + }, + { + "name": "vnf-name", + "input-param": true, + "property": { + "type": "string", + "required": true + }, + "dictionary-name": "vnf-name", + "dictionary-source": "input", + "dependencies": [] + }, + { + "name": "managed-ip1", + "input-param": true, + "property": { + "type": "string" + }, + "dictionary-name": "managed-ip1", + "dictionary-source": "mdsal", + "dependencies": [ + "loopback-ip" + ] + }, + { + "name": "loopback-ip", + "input-param": true, + "property": { + "type": "string" + }, + "dictionary-name": "loopback-ip", + "dictionary-source": "db", + "dependencies": [ + "bundle-mac", + "managed-ip1" + ] + } +] diff --git a/ms/controllerblueprints/modules/resource-dict/src/test/resources/validation/duplicate.json b/ms/controllerblueprints/modules/resource-dict/src/test/resources/validation/duplicate.json new file mode 100644 index 00000000..330324cd --- /dev/null +++ b/ms/controllerblueprints/modules/resource-dict/src/test/resources/validation/duplicate.json @@ -0,0 +1,110 @@ +[ + { + "name": "vnf-id", + "input-param": true, + "property": { + "type": "string", + "required": true + }, + "dictionary-name": "vnf-id", + "dictionary-source": "input", + "dependencies": [] + }, + { + "name": "service-instance-id", + "input-param": true, + "property": { + "type": "string", + "required": true + }, + "dictionary-name": "service-instance-id", + "dictionary-source": "input", + "dependencies": [] + }, + { + "name": "bundle-id", + "input-param": true, + "property": { + "type": "string", + "required": true + }, + "dictionary-name": "bundle-id", + "dictionary-source": "mdsal", + "dependencies": [ + "vnf-id" + ] + }, + { + "name": "bundle-ip", + "input-param": true, + "property": { + "type": "string", + "required": true + }, + "dictionary-name": "bundle-ip", + "dictionary-source": "mdsal", + "dependencies": [ + "vnf-id" + ] + }, + { + "name": "bundle-mac", + "input-param": true, + "property": { + "type": "string" + }, + "dictionary-name": "bundle-mac", + "dictionary-source": "mdsal", + "dependencies": [ + "vnf-id", + "bundle-id" + ] + }, + { + "name": "bundle-mac", + "input-param": true, + "property": { + "type": "string" + }, + "dictionary-name": "bundle-mac", + "dictionary-source": "mdsal", + "dependencies": [ + "loopback-ip" + ] + }, + { + "name": "vnf-name", + "input-param": true, + "property": { + "type": "string", + "required": true + }, + "dictionary-name": "vnf-name", + "dictionary-source": "input", + "dependencies": [] + }, + { + "name": "managed-ip1", + "input-param": true, + "property": { + "type": "string" + }, + "dictionary-name": "managed-ip1", + "dictionary-source": "mdsal", + "dependencies": [ + "loopback-ip" + ] + }, + { + "name": "loopback-ip", + "input-param": true, + "property": { + "type": "string" + }, + "dictionary-name": "loopback-ip", + "dictionary-source": "db", + "dependencies": [ + "bundle-mac" + ] + } +] diff --git a/ms/controllerblueprints/modules/resource-dict/src/test/resources/validation/success.json b/ms/controllerblueprints/modules/resource-dict/src/test/resources/validation/success.json new file mode 100644 index 00000000..3215d06d --- /dev/null +++ b/ms/controllerblueprints/modules/resource-dict/src/test/resources/validation/success.json @@ -0,0 +1,110 @@ +[ + { + "name": "vnf-id", + "input-param": true, + "property": { + "type": "string", + "required": true + }, + "dictionary-name": "vnf-id", + "dictionary-source": "input", + "dependencies": [] + }, + { + "name": "service-instance-id", + "input-param": true, + "property": { + "type": "string", + "required": true + }, + "dictionary-name": "service-instance-id", + "dictionary-source": "input", + "dependencies": [] + }, + { + "name": "bundle-id", + "input-param": true, + "property": { + "type": "string", + "required": true + }, + "dictionary-name": "bundle-id", + "dictionary-source": "mdsal", + "dependencies": [ + "vnf-id" + ] + }, + { + "name": "bundle-ip", + "input-param": true, + "property": { + "type": "string", + "required": true + }, + "dictionary-name": "bundle-ip", + "dictionary-source": "mdsal", + "dependencies": [ + "vnf-id" + ] + }, + { + "name": "bundle-mac", + "input-param": true, + "property": { + "type": "string" + }, + "dictionary-name": "bundle-mac", + "dictionary-source": "mdsal", + "dependencies": [ + "vnf-id", + "bundle-id" + ] + }, + { + "name": "managed-ip", + "input-param": true, + "property": { + "type": "string" + }, + "dictionary-name": "managed-ip", + "dictionary-source": "mdsal", + "dependencies": [ + "loopback-ip" + ] + }, + { + "name": "vnf-name", + "input-param": true, + "property": { + "type": "string", + "required": true + }, + "dictionary-name": "vnf-name", + "dictionary-source": "input", + "dependencies": [] + }, + { + "name": "managed-ip1", + "input-param": true, + "property": { + "type": "string" + }, + "dictionary-name": "managed-ip1", + "dictionary-source": "mdsal", + "dependencies": [ + "loopback-ip" + ] + }, + { + "name": "loopback-ip", + "input-param": true, + "property": { + "type": "string" + }, + "dictionary-name": "loopback-ip", + "dictionary-source": "db", + "dependencies": [ + "bundle-mac" + ] + } +] 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 ae4fed9f..c4aebe52 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 @@ -19,6 +19,7 @@ package org.onap.ccsdk.apps.controllerblueprints.service; import com.google.common.base.Preconditions; import org.apache.commons.lang3.StringUtils; +import org.jetbrains.annotations.NotNull; import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException; import org.onap.ccsdk.apps.controllerblueprints.core.data.*; import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRepoService; @@ -36,36 +37,37 @@ import java.util.Optional; * @author Brinda Santh */ @Service +@SuppressWarnings("unused") public class BluePrintRepoDBService implements BluePrintRepoService { private ModelTypeRepository modelTypeRepository; - + @SuppressWarnings("unused") public BluePrintRepoDBService(ModelTypeRepository modelTypeRepository) { this.modelTypeRepository = modelTypeRepository; } @Override - public Mono getNodeType(String nodeTypeName) throws BluePrintException { + public Mono getNodeType(@NotNull String nodeTypeName) throws BluePrintException { return getModelType(nodeTypeName, NodeType.class); } @Override - public Mono getDataType(String dataTypeName) throws BluePrintException { + public Mono getDataType(@NotNull String dataTypeName) throws BluePrintException { return getModelType(dataTypeName, DataType.class); } @Override - public Mono getArtifactType(String artifactTypeName) throws BluePrintException { + public Mono getArtifactType(@NotNull String artifactTypeName) throws BluePrintException { return getModelType(artifactTypeName, ArtifactType.class); } @Override - public Mono getRelationshipType(String relationshipTypeName) throws BluePrintException { + public Mono getRelationshipType(@NotNull String relationshipTypeName) throws BluePrintException { return getModelType(relationshipTypeName, RelationshipType.class); } @Override - public Mono getCapabilityDefinition(String capabilityDefinitionName) throws BluePrintException { + public Mono getCapabilityDefinition(@NotNull String capabilityDefinitionName) throws BluePrintException { return getModelType(capabilityDefinitionName, CapabilityDefinition.class); } @@ -73,15 +75,15 @@ public class BluePrintRepoDBService implements BluePrintRepoService { 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 getModelDefinition(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 getModelDefinitions(String modelName) throws BluePrintException { + private Mono getModelDefinition(String modelName) throws BluePrintException { String modelDefinition; Optional modelTypeDb = modelTypeRepository.findByModelName(modelName); if (modelTypeDb.isPresent()) { diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ModelTypeRepository.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ModelTypeRepository.java index 51ae752f..27823ef3 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ModelTypeRepository.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ModelTypeRepository.java @@ -37,15 +37,23 @@ public interface ModelTypeRepository extends JpaRepository { /** * This is a findByModelName method * - * @param modelName + * @param modelName Model Name * @return Optional */ Optional findByModelName(String modelName); + /** + * This is a findByModelNameIn method + * + * @param modelNames Model Names + * @return List + */ + List findByModelNameIn(List modelNames); + /** * This is a findByDerivedFrom method * - * @param derivedFrom + * @param derivedFrom Derived From * @return List */ List findByDerivedFrom(String derivedFrom); @@ -54,15 +62,16 @@ public interface ModelTypeRepository extends JpaRepository { /** * This is a findByDerivedFromIn method * - * @param derivedFroms + * @param derivedFroms Derived Froms * @return List */ + @SuppressWarnings("unused") List findByDerivedFromIn(List derivedFroms); /** * This is a findByDefinitionType method * - * @param definitionType + * @param definitionType Definition Type * @return List */ List findByDefinitionType(String definitionType); @@ -70,16 +79,17 @@ public interface ModelTypeRepository extends JpaRepository { /** * This is a findByDefinitionTypeIn method * - * @param definitionTypes + * @param definitionTypes Definition Types * @return List */ + @SuppressWarnings("unused") List findByDefinitionTypeIn(List definitionTypes); /** * This is a findByTagsContainingIgnoreCase method * - * @param tags + * @param tags Tags * @return Optional */ List findByTagsContainingIgnoreCase(String tags); @@ -88,8 +98,7 @@ public interface ModelTypeRepository extends JpaRepository { /** * This is a deleteByModelName method * - * @param modelName - * @return Optional + * @param modelName ModelName */ void deleteByModelName(String modelName); -- cgit 1.2.3-korg