From 575d9dc91a7419d03344997b55633d2b3c5cf53b Mon Sep 17 00:00:00 2001 From: "Muthuramalingam, Brinda Santh(bs2796)" Date: Thu, 13 Sep 2018 14:25:49 +0000 Subject: Controller Blueprints Microservice Optimise dictionary dummy data creation reusability and property usage optimisation. Change-Id: Ibbd56d514f437f29943cebc0e607becb6798e4b6 Issue-ID: CCSDK-491 Signed-off-by: Muthuramalingam, Brinda Santh(bs2796) --- .../apps/controllerblueprints/core/service/BluePrintContext.kt | 6 +++--- .../core/service/BluePrintExpressionService.kt | 2 +- .../core/service/BluePrintRuntimeService.kt | 2 +- .../core/service/BluePrintValidatorService.kt | 10 +++++----- .../controllerblueprints/core/utils/BluePrintRuntimeUtils.kt | 2 +- .../core/service/BluePrintRepoFileServiceTest.kt | 8 ++++---- 6 files changed, 15 insertions(+), 15 deletions(-) (limited to 'components/core') diff --git a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintContext.kt b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintContext.kt index 875cbea61..46da9d95a 100644 --- a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintContext.kt +++ b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintContext.kt @@ -71,7 +71,7 @@ class BluePrintContext(serviceTemplate: ServiceTemplate) { } fun nodeTypeInterface(nodeTypeName: String, interfaceName: String): InterfaceDefinition? { - return nodeTypeByName(nodeTypeName).interfaces?.values?.first() + return nodeTypeByName(nodeTypeName).interfaces?.get(interfaceName) } fun nodeTypeInterfaceOperation(nodeTypeName: String, interfaceName: String, operationName: String): OperationDefinition? { @@ -155,9 +155,9 @@ class BluePrintContext(serviceTemplate: ServiceTemplate) { } fun nodeTemplateRequirementNode(nodeTemplateName: String, requirementName: String): NodeTemplate { - val nodeTemplateName: String = nodeTemplateByName(nodeTemplateName).requirements?.get(requirementName)?.node + val requirementNodeTemplateName: String = nodeTemplateByName(nodeTemplateName).requirements?.get(requirementName)?.node ?: throw BluePrintException(String.format("failed to get node name for node template's (%s) requirement's (%s) " + nodeTemplateName, requirementName)) - return nodeTemplateByName(nodeTemplateName) + return nodeTemplateByName(requirementNodeTemplateName) } fun nodeTemplateCapabilityProperty(nodeTemplateName: String, capabilityName: String, propertyName: String): Any? { diff --git a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintExpressionService.kt b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintExpressionService.kt index 82e232d0e..6a50680e6 100644 --- a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintExpressionService.kt +++ b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintExpressionService.kt @@ -99,7 +99,7 @@ object BluePrintExpressionService { arrayNode.size() > 3 -> { reqOrCapEntityName = arrayNode[1].textValue() propertyName = arrayNode[2].textValue() - val propertyPaths: List = arrayNode.filterIndexed { index, obj -> + val propertyPaths: List = arrayNode.filterIndexed { index, _ -> index >= 3 }.map { it.textValue() } subProperty = propertyPaths.joinToString("/") diff --git a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRuntimeService.kt b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRuntimeService.kt index 1fdb6c3ce..2485abdb5 100644 --- a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRuntimeService.kt +++ b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRuntimeService.kt @@ -308,7 +308,7 @@ open class BluePrintRuntimeService(var bluePrintContext: BluePrintContext, var c open fun assignWorkflowInputs(workflowName: String, jsonNode: JsonNode) { log.info("assign workflow {} input value ({})", workflowName, jsonNode.toString()) - bluePrintContext.workflowByName(workflowName)?.inputs?.forEach { propertyName, property -> + bluePrintContext.workflowByName(workflowName)?.inputs?.forEach { propertyName, _ -> val valueNode: JsonNode = jsonNode.at(BluePrintConstants.PATH_DIVIDER + propertyName) ?: NullNode.getInstance() setWorkflowInputValue(workflowName, propertyName, valueNode) diff --git a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintValidatorService.kt b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintValidatorService.kt index 3bea59f9d..7ad38332a 100644 --- a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintValidatorService.kt +++ b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintValidatorService.kt @@ -236,7 +236,7 @@ open class BluePrintValidatorDefaultService : BluePrintValidatorService { message.appendln("---> Workflow :" + paths.joinToString(separator)) // Step Validation Start paths.add("steps") - workflow.steps?.forEach { stepName, step -> + workflow.steps?.forEach { stepName, _ -> paths.add(stepName) message.appendln("----> Steps :" + paths.joinToString(separator)) paths.removeAt(paths.lastIndex) @@ -583,10 +583,10 @@ open class BluePrintValidatorDefaultService : BluePrintValidatorService { } } - private fun checkPropertyDataType(dataType: String, propertyName: String) { + private fun checkPropertyDataType(dataTypeName: String, propertyName: String) { - val dataType = serviceTemplate.dataTypes?.get(dataType) - ?: throw BluePrintException(format("DataType ({}) for the property ({}) not found", dataType, propertyName)) + val dataType = serviceTemplate.dataTypes?.get(dataTypeName) + ?: throw BluePrintException(format("DataType ({}) for the property ({}) not found", dataTypeName, propertyName)) checkValidDataTypeDerivedFrom(propertyName, dataType.derivedFrom) @@ -596,7 +596,7 @@ open class BluePrintValidatorDefaultService : BluePrintValidatorService { if (BluePrintTypes.validPrimitiveTypes().contains(dataType) || checkDataType(dataType)) { return true } else { - throw BluePrintException(format("DataType ({}) for the property ({}) is not valid", dataType)) + throw BluePrintException(format("DataType({}) for the property({}) is not valid", dataType, propertyName)) } } diff --git a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintRuntimeUtils.kt b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintRuntimeUtils.kt index 07b819ffe..0e4c3e3e8 100644 --- a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintRuntimeUtils.kt +++ b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintRuntimeUtils.kt @@ -43,7 +43,7 @@ object BluePrintRuntimeUtils { fun assignInputs(bluePrintContext: BluePrintContext, jsonNode: JsonNode, context: MutableMap) { log.info("assignInputs from input JSON ({})", jsonNode.toString()) - bluePrintContext.inputs?.forEach { propertyName, property -> + bluePrintContext.inputs?.forEach { propertyName, _ -> val valueNode: JsonNode = jsonNode.at("/".plus(propertyName)) ?: NullNode.getInstance() val path = BluePrintConstants.PATH_INPUTS.plus(BluePrintConstants.PATH_DIVIDER).plus(propertyName) diff --git a/components/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRepoFileServiceTest.kt b/components/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRepoFileServiceTest.kt index 88aea919e..b8cfdd408 100644 --- a/components/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRepoFileServiceTest.kt +++ b/components/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRepoFileServiceTest.kt @@ -33,25 +33,25 @@ class BluePrintRepoFileServiceTest { @Test fun testGetDataType() { - val dataType = bluePrintEnhancerRepoFileService.getDataType("dt-v4-aggregate")?.block() + val dataType = bluePrintEnhancerRepoFileService.getDataType("dt-v4-aggregate").block() assertNotNull(dataType, "Failed to get DataType from repo") } @Test fun testGetNodeType() { - val nodeType = bluePrintEnhancerRepoFileService.getNodeType("component-resource-assignment")?.block() + val nodeType = bluePrintEnhancerRepoFileService.getNodeType("component-resource-assignment").block() assertNotNull(nodeType, "Failed to get NodeType from repo") } @Test fun testGetArtifactType() { - val nodeType = bluePrintEnhancerRepoFileService.getArtifactType("artifact-template-velocity")?.block() + val nodeType = bluePrintEnhancerRepoFileService.getArtifactType("artifact-template-velocity").block() assertNotNull(nodeType, "Failed to get ArtifactType from repo") } @Test(expected = FileNotFoundException::class) fun testModelNotFound() { - val dataType = bluePrintEnhancerRepoFileService.getDataType("dt-not-found")?.block() + val dataType = bluePrintEnhancerRepoFileService.getDataType("dt-not-found").block() assertNotNull(dataType, "Failed to get DataType from repo") } } \ No newline at end of file -- cgit 1.2.3-korg