Merge "Controller Blueprints Microservice"
authorDan Timoney <dt5972@att.com>
Thu, 13 Sep 2018 20:30:39 +0000 (20:30 +0000)
committerGerrit Code Review <gerrit@onap.org>
Thu, 13 Sep 2018 20:30:39 +0000 (20:30 +0000)
13 files changed:
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
ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintEnhancerService.kt
ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/ResourceAssignmentEnhancerServiceTest.java
ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/validator/ServiceTemplateValidationTest.java

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
index cf9e96e..46709c5 100644 (file)
@@ -171,7 +171,7 @@ open class BluePrintEnhancerDefaultService(val bluePrintRepoService: BluePrintRe
     }\r
 \r
     open fun enrichNodeTypeCapabilityProperties(nodeTypeName: String, nodeType: NodeType) {\r
-        nodeType.capabilities?.forEach { capabilityDefinitionName, capabilityDefinition ->\r
+        nodeType.capabilities?.forEach { _, capabilityDefinition ->\r
             capabilityDefinition.properties?.let { properties ->\r
                 enrichPropertyDefinitions(properties)\r
             }\r
@@ -246,7 +246,7 @@ open class BluePrintEnhancerDefaultService(val bluePrintRepoService: BluePrintRe
     open fun populateNodeType(nodeTypeName: String): NodeType {\r
 \r
         val nodeType = serviceTemplate.nodeTypes?.get(nodeTypeName)\r
-                ?: bluePrintRepoService.getNodeType(nodeTypeName)?.block()\r
+                ?: bluePrintRepoService.getNodeType(nodeTypeName).block()\r
                 ?: throw BluePrintException(format("Couldn't get NodeType({}) from repo.", nodeTypeName))\r
         serviceTemplate.nodeTypes?.put(nodeTypeName, nodeType)\r
         return nodeType\r
@@ -254,7 +254,7 @@ open class BluePrintEnhancerDefaultService(val bluePrintRepoService: BluePrintRe
 \r
     open fun populateArtifactType(artifactTypeName: String): ArtifactType {\r
         val artifactType = serviceTemplate.artifactTypes?.get(artifactTypeName)\r
-                ?: bluePrintRepoService.getArtifactType(artifactTypeName)?.block()\r
+                ?: bluePrintRepoService.getArtifactType(artifactTypeName).block()\r
                 ?: throw BluePrintException(format("Couldn't get ArtifactType({}) from repo.", artifactTypeName))\r
         serviceTemplate.artifactTypes?.put(artifactTypeName, artifactType)\r
         return artifactType\r
@@ -262,7 +262,7 @@ open class BluePrintEnhancerDefaultService(val bluePrintRepoService: BluePrintRe
 \r
     open fun populateDataTypes(dataTypeName: String): DataType {\r
         val dataType = serviceTemplate.dataTypes?.get(dataTypeName)\r
-                ?: bluePrintRepoService.getDataType(dataTypeName)?.block()\r
+                ?: bluePrintRepoService.getDataType(dataTypeName).block()\r
                 ?: throw BluePrintException(format("Couldn't get DataType({}) from repo.", dataTypeName))\r
         serviceTemplate.dataTypes?.put(dataTypeName, dataType)\r
         return dataType\r
index e279ec9..a5d1e41 100644 (file)
@@ -26,9 +26,9 @@ import org.onap.ccsdk.apps.controllerblueprints.core.data.ServiceTemplate;
 import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonReactorUtils;\r
 import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils;\r
 import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment;\r
-import org.onap.ccsdk.apps.controllerblueprints.resource.dict.factory.ResourceSourceMappingFactory;\r
 import org.onap.ccsdk.apps.controllerblueprints.resource.dict.service.ResourceDefinitionFileRepoService;\r
 import org.onap.ccsdk.apps.controllerblueprints.resource.dict.service.ResourceDefinitionRepoService;\r
+import org.onap.ccsdk.apps.controllerblueprints.resource.dict.utils.ResourceDictionaryTestUtils;\r
 \r
 import java.util.List;\r
 \r
@@ -42,10 +42,8 @@ public class ResourceAssignmentEnhancerServiceTest {
 \r
     @Before\r
     public void setUp(){\r
-        ResourceSourceMappingFactory.INSTANCE.registerSourceMapping("db", "source-db");\r
-        ResourceSourceMappingFactory.INSTANCE.registerSourceMapping("input", "source-input");\r
-        ResourceSourceMappingFactory.INSTANCE.registerSourceMapping("default", "source-default");\r
-        ResourceSourceMappingFactory.INSTANCE.registerSourceMapping("mdsal", "source-rest");\r
+        // Setup dummy Source Instance Mapping\r
+        ResourceDictionaryTestUtils.setUpResourceSourceMapping();\r
     }\r
 \r
     @Test\r
index 5f34b55..26fb1d3 100644 (file)
@@ -24,6 +24,7 @@ import org.junit.Test;
 import org.onap.ccsdk.apps.controllerblueprints.core.data.ServiceTemplate;\r
 import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils;\r
 import org.onap.ccsdk.apps.controllerblueprints.resource.dict.factory.ResourceSourceMappingFactory;\r
+import org.onap.ccsdk.apps.controllerblueprints.resource.dict.utils.ResourceDictionaryTestUtils;\r
 import org.onap.ccsdk.apps.controllerblueprints.service.utils.ConfigModelUtils;\r
 import com.att.eelf.configuration.EELFLogger;\r
 import com.att.eelf.configuration.EELFManager;\r
@@ -37,10 +38,8 @@ public class ServiceTemplateValidationTest {
 \r
     @Before\r
     public void setUp(){\r
-        ResourceSourceMappingFactory.INSTANCE.registerSourceMapping("db", "source-db");\r
-        ResourceSourceMappingFactory.INSTANCE.registerSourceMapping("input", "source-input");\r
-        ResourceSourceMappingFactory.INSTANCE.registerSourceMapping("default", "source-default");\r
-        ResourceSourceMappingFactory.INSTANCE.registerSourceMapping("mdsal", "source-rest");\r
+        // Setup dummy Source Instance Mapping\r
+        ResourceDictionaryTestUtils.setUpResourceSourceMapping();\r
     }\r
 \r
     @Test\r