Controller Blueprints Microservice
authorMuthuramalingam, Brinda Santh(bs2796) <bs2796@att.com>
Thu, 13 Sep 2018 14:25:49 +0000 (14:25 +0000)
committerMuthuramalingam, Brinda Santh(bs2796) <bs2796@att.com>
Thu, 13 Sep 2018 14:25:49 +0000 (14:25 +0000)
Optimise dictionary dummy data creation reusability and property usage optimisation.

Change-Id: Ibbd56d514f437f29943cebc0e607becb6798e4b6
Issue-ID: CCSDK-491
Signed-off-by: Muthuramalingam, Brinda Santh(bs2796) <bs2796@att.com>
components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintContext.kt
components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintExpressionService.kt
components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRuntimeService.kt
components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintValidatorService.kt
components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintRuntimeUtils.kt
components/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRepoFileServiceTest.kt
components/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceAssignmentValidationService.kt
components/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDefinitionValidationService.kt
components/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryTestUtils.kt [new file with mode: 0644]
components/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceAssignmentValidationServiceTest.kt

index 875cbea..46da9d9 100644 (file)
@@ -71,7 +71,7 @@ class BluePrintContext(serviceTemplate: ServiceTemplate) {
     }\r
 \r
     fun nodeTypeInterface(nodeTypeName: String, interfaceName: String): InterfaceDefinition? {\r
-        return nodeTypeByName(nodeTypeName).interfaces?.values?.first()\r
+        return nodeTypeByName(nodeTypeName).interfaces?.get(interfaceName)\r
     }\r
 \r
     fun nodeTypeInterfaceOperation(nodeTypeName: String, interfaceName: String, operationName: String): OperationDefinition? {\r
@@ -155,9 +155,9 @@ class BluePrintContext(serviceTemplate: ServiceTemplate) {
     }\r
 \r
     fun nodeTemplateRequirementNode(nodeTemplateName: String, requirementName: String): NodeTemplate {\r
-        val nodeTemplateName: String = nodeTemplateByName(nodeTemplateName).requirements?.get(requirementName)?.node\r
+        val requirementNodeTemplateName: String = nodeTemplateByName(nodeTemplateName).requirements?.get(requirementName)?.node\r
                 ?: throw BluePrintException(String.format("failed to get node name for node template's (%s) requirement's (%s) " + nodeTemplateName, requirementName))\r
-        return nodeTemplateByName(nodeTemplateName)\r
+        return nodeTemplateByName(requirementNodeTemplateName)\r
     }\r
 \r
     fun nodeTemplateCapabilityProperty(nodeTemplateName: String, capabilityName: String, propertyName: String): Any? {\r
index 82e232d..6a50680 100644 (file)
@@ -99,7 +99,7 @@ object BluePrintExpressionService {
             arrayNode.size() > 3 -> {\r
                 reqOrCapEntityName = arrayNode[1].textValue()\r
                 propertyName = arrayNode[2].textValue()\r
-                val propertyPaths: List<String> = arrayNode.filterIndexed { index, obj ->\r
+                val propertyPaths: List<String> = arrayNode.filterIndexed { index, _ ->\r
                     index >= 3\r
                 }.map { it.textValue() }\r
                 subProperty = propertyPaths.joinToString("/")\r
index 1fdb6c3..2485abd 100644 (file)
@@ -308,7 +308,7 @@ open class BluePrintRuntimeService(var bluePrintContext: BluePrintContext, var c
 \r
     open fun assignWorkflowInputs(workflowName: String, jsonNode: JsonNode) {\r
         log.info("assign workflow {} input value ({})", workflowName, jsonNode.toString())\r
-        bluePrintContext.workflowByName(workflowName)?.inputs?.forEach { propertyName, property ->\r
+        bluePrintContext.workflowByName(workflowName)?.inputs?.forEach { propertyName, _ ->\r
             val valueNode: JsonNode = jsonNode.at(BluePrintConstants.PATH_DIVIDER + propertyName)\r
                     ?: NullNode.getInstance()\r
             setWorkflowInputValue(workflowName, propertyName, valueNode)\r
index 3bea59f..7ad3833 100644 (file)
@@ -236,7 +236,7 @@ open class BluePrintValidatorDefaultService : BluePrintValidatorService {
         message.appendln("---> Workflow :" + paths.joinToString(separator))\r
         // Step Validation Start\r
         paths.add("steps")\r
-        workflow.steps?.forEach { stepName, step ->\r
+        workflow.steps?.forEach { stepName, _ ->\r
             paths.add(stepName)\r
             message.appendln("----> Steps :" + paths.joinToString(separator))\r
             paths.removeAt(paths.lastIndex)\r
@@ -583,10 +583,10 @@ open class BluePrintValidatorDefaultService : BluePrintValidatorService {
         }\r
     }\r
 \r
-    private fun checkPropertyDataType(dataType: String, propertyName: String) {\r
+    private fun checkPropertyDataType(dataTypeName: String, propertyName: String) {\r
 \r
-        val dataType = serviceTemplate.dataTypes?.get(dataType)\r
-                ?: throw BluePrintException(format("DataType ({}) for the property ({}) not found", dataType, propertyName))\r
+        val dataType = serviceTemplate.dataTypes?.get(dataTypeName)\r
+                ?: throw BluePrintException(format("DataType ({}) for the property ({}) not found", dataTypeName, propertyName))\r
 \r
         checkValidDataTypeDerivedFrom(propertyName, dataType.derivedFrom)\r
 \r
@@ -596,7 +596,7 @@ open class BluePrintValidatorDefaultService : BluePrintValidatorService {
         if (BluePrintTypes.validPrimitiveTypes().contains(dataType) || checkDataType(dataType)) {\r
             return true\r
         } else {\r
-            throw BluePrintException(format("DataType ({}) for the property ({}) is not valid", dataType))\r
+            throw BluePrintException(format("DataType({}) for the property({}) is not valid", dataType, propertyName))\r
         }\r
     }\r
 \r
index 07b819f..0e4c3e3 100644 (file)
@@ -43,7 +43,7 @@ object BluePrintRuntimeUtils {
 \r
     fun assignInputs(bluePrintContext: BluePrintContext, jsonNode: JsonNode, context: MutableMap<String, Any>) {\r
         log.info("assignInputs from input JSON ({})", jsonNode.toString())\r
-        bluePrintContext.inputs?.forEach { propertyName, property ->\r
+        bluePrintContext.inputs?.forEach { propertyName, _ ->\r
             val valueNode: JsonNode = jsonNode.at("/".plus(propertyName)) ?: NullNode.getInstance()\r
 \r
             val path = BluePrintConstants.PATH_INPUTS.plus(BluePrintConstants.PATH_DIVIDER).plus(propertyName)\r
index 88aea91..b8cfdd4 100644 (file)
@@ -33,25 +33,25 @@ class BluePrintRepoFileServiceTest {
 \r
     @Test\r
     fun testGetDataType() {\r
-        val dataType = bluePrintEnhancerRepoFileService.getDataType("dt-v4-aggregate")?.block()\r
+        val dataType = bluePrintEnhancerRepoFileService.getDataType("dt-v4-aggregate").block()\r
         assertNotNull(dataType, "Failed to get DataType from repo")\r
     }\r
 \r
     @Test\r
     fun testGetNodeType() {\r
-        val nodeType = bluePrintEnhancerRepoFileService.getNodeType("component-resource-assignment")?.block()\r
+        val nodeType = bluePrintEnhancerRepoFileService.getNodeType("component-resource-assignment").block()\r
         assertNotNull(nodeType, "Failed to get NodeType from repo")\r
     }\r
 \r
     @Test\r
     fun testGetArtifactType() {\r
-        val nodeType = bluePrintEnhancerRepoFileService.getArtifactType("artifact-template-velocity")?.block()\r
+        val nodeType = bluePrintEnhancerRepoFileService.getArtifactType("artifact-template-velocity").block()\r
         assertNotNull(nodeType, "Failed to get ArtifactType from repo")\r
     }\r
 \r
     @Test(expected = FileNotFoundException::class)\r
     fun testModelNotFound() {\r
-        val dataType = bluePrintEnhancerRepoFileService.getDataType("dt-not-found")?.block()\r
+        val dataType = bluePrintEnhancerRepoFileService.getDataType("dt-not-found").block()\r
         assertNotNull(dataType, "Failed to get DataType from repo")\r
     }\r
 }
\ No newline at end of file
index 089fce0..fc7f109 100644 (file)
@@ -67,6 +67,7 @@ open class ResourceAssignmentValidationDefaultService : ResourceAssignmentValida
 
     open fun validateSources(resourceAssignments: List<ResourceAssignment>) {
         log.info("validating resource assignment sources")
+        // Check the Resource Assignment Source(Dynamic Instance) is valid.
         resourceAssignments.forEach { resourceAssignment ->
             try {
                 ResourceSourceMappingFactory.getRegisterSourceMapping(resourceAssignment.dictionarySource!!)
@@ -80,6 +81,7 @@ open class ResourceAssignmentValidationDefaultService : ResourceAssignmentValida
 
         resourceAssignmentMap = resourceAssignments.map { it.name to it }.toMap()
 
+        // Check the Resource Assignment has Duplicate Key Names
         val duplicateKeyNames = resourceAssignments.groupBy { it.name }
                 .filter { it.value.size > 1 }
                 .map { it.key }
@@ -88,6 +90,7 @@ open class ResourceAssignmentValidationDefaultService : ResourceAssignmentValida
             validationMessage.appendln(String.format("Duplicate Assignment Template Keys (%s) is Present", duplicateKeyNames))
         }
 
+        // Check the Resource Assignment has Duplicate Dictionary Names
         val duplicateDictionaryKeyNames = resourceAssignments.groupBy { it.dictionaryName }
                 .filter { it.value.size > 1 }
                 .map { it.key }
@@ -95,8 +98,10 @@ open class ResourceAssignmentValidationDefaultService : ResourceAssignmentValida
             validationMessage.appendln(String.format("Duplicate Assignment Dictionary Keys (%s) is Present", duplicateDictionaryKeyNames))
         }
 
+        // Collect all the dependencies as a single list
         val dependenciesNames = resourceAssignments.mapNotNull { it.dependencies }.flatten()
 
+        // Check all the dependencies keys have Resource Assignment mappings.
         val notPresentDictionaries = dependenciesNames.filter { !resourceAssignmentMap.containsKey(it) }.distinct()
         if (notPresentDictionaries.isNotEmpty()) {
             validationMessage.appendln(String.format("No assignments for Dictionary Keys (%s)", notPresentDictionaries))
index 14855d4..9f45d16 100644 (file)
@@ -59,7 +59,7 @@ open class ResourceDefinitionDefaultValidationService(private val bluePrintRepoS
         resourceDefinition.sources.forEach { (name, nodeTemplate) ->
             val sourceType = nodeTemplate.type
 
-            val sourceNodeType = bluePrintRepoService.getNodeType(sourceType)?.block()
+            val sourceNodeType = bluePrintRepoService.getNodeType(sourceType).block()
                     ?: throw BluePrintException(format("Failed to get source({}) node type definition({})", name, sourceType))
 
             // Validate Property Name, expression, values and Data Type
@@ -100,7 +100,7 @@ open class ResourceDefinitionDefaultValidationService(private val bluePrintRepoS
 
             isValid = JacksonUtils.checkJsonNodeValueOfCollectionType(propertyType, propertyAssignment)
         } else {
-            bluePrintRepoService.getDataType(propertyType)
+            bluePrintRepoService.getDataType(propertyType).block()
                     ?: throw BluePrintException(format("property({}) defined of data type({}) is not in repository",
                             propertyName, propertyType))
             isValid = true
diff --git a/components/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryTestUtils.kt b/components/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryTestUtils.kt
new file mode 100644 (file)
index 0000000..bebe27d
--- /dev/null
@@ -0,0 +1,30 @@
+/*\r
+ *  Copyright © 2017-2018 AT&T Intellectual Property.\r
+ *\r
+ *  Licensed under the Apache License, Version 2.0 (the "License");\r
+ *  you may not use this file except in compliance with the License.\r
+ *  You may obtain a copy of the License at\r
+ *\r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ *  Unless required by applicable law or agreed to in writing, software\r
+ *  distributed under the License is distributed on an "AS IS" BASIS,\r
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ *  See the License for the specific language governing permissions and\r
+ *  limitations under the License.\r
+ */\r
+\r
+package org.onap.ccsdk.apps.controllerblueprints.resource.dict.utils\r
+\r
+import org.onap.ccsdk.apps.controllerblueprints.resource.dict.factory.ResourceSourceMappingFactory\r
+\r
+object ResourceDictionaryTestUtils {\r
+\r
+    @JvmStatic\r
+    fun setUpResourceSourceMapping() {\r
+        ResourceSourceMappingFactory.registerSourceMapping("db", "source-db")\r
+        ResourceSourceMappingFactory.registerSourceMapping("input", "source-input")\r
+        ResourceSourceMappingFactory.registerSourceMapping("default", "source-default")\r
+        ResourceSourceMappingFactory.registerSourceMapping("mdsal", "source-rest")\r
+    }\r
+}
\ No newline at end of file
index 6216d5b..87ebb70 100644 (file)
@@ -23,6 +23,9 @@ import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException
 import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils\r
 import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment\r
 import com.att.eelf.configuration.EELFManager\r
+import org.junit.Before\r
+import org.onap.ccsdk.apps.controllerblueprints.resource.dict.utils.ResourceDictionaryTestUtils\r
+\r
 /**\r
  * ResourceAssignmentValidationServiceTest.\r
  *\r
@@ -30,6 +33,12 @@ import com.att.eelf.configuration.EELFManager
  */\r
 class ResourceAssignmentValidationServiceTest {\r
     private val log: EELFLogger = EELFManager.getInstance().getLogger(ResourceAssignmentValidationServiceTest::class.java)\r
+    @Before\r
+    fun setUp() {\r
+        // Setup dummy Source Instance Mapping\r
+        ResourceDictionaryTestUtils.setUpResourceSourceMapping()\r
+    }\r
+\r
     @Test\r
     fun testValidateSuccess() {\r
         log.info("**************** testValidateSuccess *****************")\r