From d082ba55645cd4765c0189c591db2f2e8f654520 Mon Sep 17 00:00:00 2001 From: "Muthuramalingam, Brinda Santh(bs2796)" Date: Thu, 13 Sep 2018 00:20:34 +0000 Subject: Controller Blueprints Microservice Add resource assignment enhancement and validation to blueprint validation and enhancement. Change-Id: I547760012e7014cfbb7a1e3a1d8ffb77edc9b6a2 Issue-ID: CCSDK-562 Signed-off-by: Muthuramalingam, Brinda Santh(bs2796) --- .../controllerblueprints/core/BluePrintTypes.kt | 10 + .../core/factory/BluePrintEnhancerFactory.kt | 45 ---- .../core/service/BluePrintEnhancerService.kt | 271 --------------------- .../core/service/BluePrintRepoService.kt | 20 +- .../core/service/BluePrintEnhancerServiceTest.kt | 41 ---- 5 files changed, 20 insertions(+), 367 deletions(-) delete mode 100644 components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/factory/BluePrintEnhancerFactory.kt delete mode 100644 components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintEnhancerService.kt delete mode 100644 components/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintEnhancerServiceTest.kt (limited to 'components/core') diff --git a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintTypes.kt b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintTypes.kt index e25b3eea9..a971898d3 100644 --- a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintTypes.kt +++ b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintTypes.kt @@ -16,6 +16,8 @@ package org.onap.ccsdk.apps.controllerblueprints.core +import org.onap.ccsdk.apps.controllerblueprints.core.data.PropertyDefinition + /** * * @@ -104,6 +106,7 @@ object BluePrintTypes { validTypes.add(BluePrintConstants.DATA_TYPE_TIMESTAMP) validTypes.add(BluePrintConstants.DATA_TYPE_NULL) validTypes.add(BluePrintConstants.DATA_TYPE_LIST) + validTypes.add(BluePrintConstants.DATA_TYPE_MAP) return validTypes } @@ -127,6 +130,13 @@ object BluePrintTypes { return validTypes } + @JvmStatic + fun validPrimitiveOrCollectionPrimitive(propertyDefinition: PropertyDefinition): Boolean { + val entrySchema = propertyDefinition.entrySchema?.type ?: BluePrintConstants.DATA_TYPE_NULL + return BluePrintTypes.validPropertyTypes().contains(propertyDefinition.type) + && BluePrintTypes.validPrimitiveTypes().contains(entrySchema) + } + @JvmStatic fun validCommands(): List { return listOf(BluePrintConstants.EXPRESSION_GET_INPUT, diff --git a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/factory/BluePrintEnhancerFactory.kt b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/factory/BluePrintEnhancerFactory.kt deleted file mode 100644 index d796597be..000000000 --- a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/factory/BluePrintEnhancerFactory.kt +++ /dev/null @@ -1,45 +0,0 @@ -/* - * 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.core.factory - -import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintEnhancerService -import com.att.eelf.configuration.EELFLogger -import com.att.eelf.configuration.EELFManager - - -/** - * BluePrintEnhancerFactory - * @author Brinda Santh - * - */ - -object BluePrintEnhancerFactory { - private val log: EELFLogger = EELFManager.getInstance().getLogger(this::class.toString()) - - var bluePrintEnhancerServices: MutableMap = HashMap() - - fun register(key: String, bluePrintEnhancerService: BluePrintEnhancerService) { - bluePrintEnhancerServices[key] = bluePrintEnhancerService - } - - /** - * Called by clients to get a Blueprint Parser for the Blueprint parser type - */ - fun instance(key: String): BluePrintEnhancerService? { - return bluePrintEnhancerServices.get(key) - } -} diff --git a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintEnhancerService.kt b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintEnhancerService.kt deleted file mode 100644 index b125c594c..000000000 --- a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintEnhancerService.kt +++ /dev/null @@ -1,271 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * 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.core.service - -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintTypes -import org.onap.ccsdk.apps.controllerblueprints.core.data.* -import org.onap.ccsdk.apps.controllerblueprints.core.format -import com.att.eelf.configuration.EELFLogger -import com.att.eelf.configuration.EELFManager -import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonReactorUtils -import java.io.Serializable - -/** - * BluePrintEnhancerService - * @author Brinda Santh - * - */ -interface BluePrintEnhancerService : Serializable { - - @Throws(BluePrintException::class) - fun enhance(content: String): ServiceTemplate - - /** - * Read Blueprint from CSAR structure Directory - */ - @Throws(BluePrintException::class) - fun enhance(fileName: String, basePath: String): ServiceTemplate - - @Throws(BluePrintException::class) - fun enhance(serviceTemplate: ServiceTemplate): ServiceTemplate - - @Throws(BluePrintException::class) - fun enrichNodeTemplate(nodeTemplateName: String, nodeTemplate: NodeTemplate) - - @Throws(BluePrintException::class) - fun enrichNodeType(nodeTypeName: String, nodeType: NodeType) - - @Throws(BluePrintException::class) - fun enrichPropertyDefinition(propertyName: String, propertyDefinition: PropertyDefinition) -} - -open class BluePrintEnhancerDefaultService(val bluePrintRepoService: BluePrintRepoService) : BluePrintEnhancerService { - - private val log: EELFLogger = EELFManager.getInstance().getLogger(BluePrintEnhancerDefaultService::class.toString()) - - lateinit var serviceTemplate: ServiceTemplate - - @Throws(BluePrintException::class) - override fun enhance(content: String): ServiceTemplate { - return JacksonReactorUtils.readValueFromFile(content, ServiceTemplate::class.java).map { serviceTemplate -> - enhance(serviceTemplate!!) - }.block()!! - } - - @Throws(BluePrintException::class) - override fun enhance(fileName: String, basePath: String): ServiceTemplate { - TODO("not implemented") //To change body of created functions use File | Settings | File Templates. - } - - @Throws(BluePrintException::class) - override fun enhance(serviceTemplate: ServiceTemplate): ServiceTemplate { - this.serviceTemplate = serviceTemplate - initialCleanUp() - enrichTopologyTemplate(serviceTemplate) - - // log.info("Enriched Blueprint :\n {}", JacksonUtils.getJson(serviceTemplate, true)) - return this.serviceTemplate - } - - open fun initialCleanUp() { - serviceTemplate.artifactTypes?.clear() - serviceTemplate.nodeTypes?.clear() - serviceTemplate.dataTypes?.clear() - - serviceTemplate.artifactTypes = HashMap() - serviceTemplate.nodeTypes = HashMap() - serviceTemplate.dataTypes = HashMap() - - } - - @Throws(BluePrintException::class) - open fun enrichTopologyTemplate(serviceTemplate: ServiceTemplate) { - serviceTemplate.topologyTemplate?.let { topologyTemplate -> - enrichTopologyTemplateInputs(topologyTemplate) - enrichTopologyTemplateNodeTemplates(topologyTemplate) - } - } - - @Throws(BluePrintException::class) - open fun enrichTopologyTemplateInputs(topologyTemplate: TopologyTemplate) { - topologyTemplate.inputs?.let { inputs -> - enrichPropertyDefinitions(inputs) - } - } - - open fun enrichTopologyTemplateNodeTemplates(topologyTemplate: TopologyTemplate) { - topologyTemplate.nodeTemplates?.forEach { nodeTemplateName, nodeTemplate -> - enrichNodeTemplate(nodeTemplateName, nodeTemplate) - } - } - - @Throws(BluePrintException::class) - override fun enrichNodeTemplate(nodeTemplateName: String, nodeTemplate: NodeTemplate) { - val nodeTypeName = nodeTemplate.type - // Get NodeType from Repo and Update Service Template - val nodeType = populateNodeType(nodeTypeName) - - // Enrich NodeType - enrichNodeType(nodeTypeName, nodeType) - - //Enrich Node Template Artifacts - enrichNodeTemplateArtifactDefinition(nodeTemplateName, nodeTemplate) - } - - @Throws(BluePrintException::class) - override fun enrichNodeType(nodeTypeName: String, nodeType: NodeType) { - log.debug("Enriching NodeType({})", nodeTypeName) - val derivedFrom = nodeType.derivedFrom - - if (!BluePrintTypes.rootNodeTypes().contains(derivedFrom)) { - val derivedFromNodeType = populateNodeType(nodeTypeName) - // Enrich NodeType - enrichNodeType(derivedFrom, derivedFromNodeType) - } - - // NodeType Property Definitions - enrichNodeTypeProperties(nodeTypeName, nodeType) - - //NodeType Requirement - enrichNodeTypeRequirements(nodeTypeName, nodeType) - - //NodeType Capability - enrichNodeTypeCapabilityProperties(nodeTypeName, nodeType) - - //NodeType Interface - enrichNodeTypeInterfaces(nodeTypeName, nodeType) - } - - open fun enrichNodeTypeProperties(nodeTypeName: String, nodeType: NodeType) { - nodeType.properties?.let { enrichPropertyDefinitions(nodeType.properties!!) } - } - - open fun enrichNodeTypeRequirements(nodeTypeName: String, nodeType: NodeType) { - - nodeType.requirements?.forEach { _, requirementDefinition -> - // Populate Requirement Node - requirementDefinition.node?.let { requirementNodeTypeName -> - // Get Requirement NodeType from Repo and Update Service Template - val requirementNodeType = populateNodeType(requirementNodeTypeName) - - enrichNodeType(requirementNodeTypeName, requirementNodeType) - } - } - } - - open fun enrichNodeTypeCapabilityProperties(nodeTypeName: String, nodeType: NodeType) { - nodeType.capabilities?.forEach { capabilityDefinitionName, capabilityDefinition -> - capabilityDefinition.properties?.let { properties -> - enrichPropertyDefinitions(properties) - } - } - } - - open fun enrichNodeTypeInterfaces(nodeTypeName: String, nodeType: NodeType) { - nodeType.interfaces?.forEach { interfaceName, interfaceObj -> - // Populate Node type Interface Operation - log.debug("Enriching NodeType({}) Interface({})", nodeTypeName, interfaceName) - populateNodeTypeInterfaceOperation(nodeTypeName, interfaceName, interfaceObj) - - } - } - - open fun populateNodeTypeInterfaceOperation(nodeTypeName: String, interfaceName: String, interfaceObj: InterfaceDefinition) { - - interfaceObj.operations?.forEach { operationName, operation -> - enrichNodeTypeInterfaceOperationInputs(nodeTypeName, operationName, operation) - enrichNodeTypeInterfaceOperationOputputs(nodeTypeName, operationName, operation) - } - } - - open fun enrichNodeTypeInterfaceOperationInputs(nodeTypeName: String, operationName: String, operation: OperationDefinition) { - operation.inputs?.let { inputs -> - enrichPropertyDefinitions(inputs) - } - } - - open fun enrichNodeTypeInterfaceOperationOputputs(nodeTypeName: String, operationName: String, operation: OperationDefinition) { - operation.outputs?.let { inputs -> - enrichPropertyDefinitions(inputs) - } - } - - open fun enrichPropertyDefinitions(properties: MutableMap) { - - properties.forEach { propertyName, propertyDefinition -> - enrichPropertyDefinition(propertyName, propertyDefinition) - } - } - - @Throws(BluePrintException::class) - override fun enrichPropertyDefinition(propertyName: String, propertyDefinition: PropertyDefinition) { - val propertyType = propertyDefinition.type - if (BluePrintTypes.validPrimitiveTypes().contains(propertyType)) { - - } else if (BluePrintTypes.validCollectionTypes().contains(propertyType)) { - val entrySchema = propertyDefinition.entrySchema - ?: throw BluePrintException(format("Entry Schema is missing for collection property : {}", propertyName)) - - if (!BluePrintTypes.validPrimitiveTypes().contains(entrySchema.type)) { - populateDataTypes(entrySchema.type) - } - } else { - populateDataTypes(propertyType) - } - - } - - open fun enrichNodeTemplateArtifactDefinition(nodeTemplateName: String, nodeTemplate: NodeTemplate) { - - nodeTemplate.artifacts?.forEach { artifactDefinitionName, artifactDefinition -> - val artifactTypeName = artifactDefinition.type - ?: throw BluePrintException(format("Artifact type is missing for NodeTemplate({}) artifact({})", nodeTemplateName, artifactDefinitionName)) - - // Populate Artifact Type - populateArtifactType(artifactTypeName) - } - } - - open fun populateNodeType(nodeTypeName: String): NodeType { - - val nodeType = serviceTemplate.nodeTypes?.get(nodeTypeName) - ?: 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 = serviceTemplate.artifactTypes?.get(artifactTypeName) - ?: 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 = serviceTemplate.dataTypes?.get(dataTypeName) - ?: bluePrintRepoService.getDataType(dataTypeName)?.block() - ?: throw BluePrintException(format("Couldn't get DataType({}) from repo.", dataTypeName)) - serviceTemplate.dataTypes?.put(dataTypeName, dataType) - return dataType - } - -} - diff --git a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRepoService.kt b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRepoService.kt index a7c14adfe..dec7a50df 100644 --- a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRepoService.kt +++ b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRepoService.kt @@ -35,19 +35,19 @@ import java.io.Serializable interface BluePrintRepoService : Serializable { @Throws(BluePrintException::class) - fun getNodeType(nodeTypeName: String): Mono? + fun getNodeType(nodeTypeName: String): Mono @Throws(BluePrintException::class) - fun getDataType(dataTypeName: String): Mono? + fun getDataType(dataTypeName: String): Mono @Throws(BluePrintException::class) - fun getArtifactType(artifactTypeName: String): Mono? + fun getArtifactType(artifactTypeName: String): Mono @Throws(BluePrintException::class) - fun getRelationshipType(relationshipTypeName: String): Mono? + fun getRelationshipType(relationshipTypeName: String): Mono @Throws(BluePrintException::class) - fun getCapabilityDefinition(capabilityDefinitionName: String): Mono? + fun getCapabilityDefinition(capabilityDefinitionName: String): Mono } @@ -63,30 +63,30 @@ open class BluePrintRepoFileService(modelTypePath: String) : BluePrintRepoServic private val relationshipTypePath = modelTypePath.plus(BluePrintConstants.PATH_DIVIDER).plus(BluePrintConstants.MODEL_DEFINITION_TYPE_RELATIONSHIP_TYPE) private val extension = ".json" - override fun getDataType(dataTypeName: String): Mono? { + override fun getDataType(dataTypeName: String): Mono { val fileName = dataTypePath.plus(BluePrintConstants.PATH_DIVIDER) .plus(dataTypeName).plus(extension) return getModelType(fileName, DataType::class.java) } - override fun getNodeType(nodeTypeName: String): Mono? { + override fun getNodeType(nodeTypeName: String): Mono { val fileName = nodeTypePath.plus(BluePrintConstants.PATH_DIVIDER).plus(nodeTypeName).plus(extension) return getModelType(fileName, NodeType::class.java) } - override fun getArtifactType(artifactTypeName: String): Mono? { + override fun getArtifactType(artifactTypeName: String): Mono { val fileName = artifactTypePath.plus(BluePrintConstants.PATH_DIVIDER) .plus(artifactTypeName).plus(extension) return getModelType(fileName, ArtifactType::class.java) } - override fun getRelationshipType(relationshipTypeName: String): Mono? { + override fun getRelationshipType(relationshipTypeName: String): Mono { val fileName = relationshipTypePath.plus(BluePrintConstants.PATH_DIVIDER) .plus(relationshipTypeName).plus(extension) return getModelType(fileName, RelationshipType::class.java) } - override fun getCapabilityDefinition(capabilityDefinitionName: String): Mono? { + override fun getCapabilityDefinition(capabilityDefinitionName: String): Mono { val fileName = capabilityTypePath.plus(BluePrintConstants.PATH_DIVIDER) .plus(capabilityDefinitionName).plus(extension) return getModelType(fileName, CapabilityDefinition::class.java) diff --git a/components/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintEnhancerServiceTest.kt b/components/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintEnhancerServiceTest.kt deleted file mode 100644 index 8e6d5efdf..000000000 --- a/components/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintEnhancerServiceTest.kt +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * 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.core.service - -import org.junit.Test -import org.onap.ccsdk.apps.controllerblueprints.core.utils.ServiceTemplateUtils - -/** - * BluePrintEnhancerServiceTest - * @author Brinda Santh - * - */ - -class BluePrintEnhancerServiceTest { - val basePath = "load/model_type" - - @Test - fun testEnrichBlueprint() { - val bluePrintEnhancerRepoFileService = BluePrintRepoFileService(basePath) - val bluePrintEnhancerService: BluePrintEnhancerService = BluePrintEnhancerDefaultService(bluePrintEnhancerRepoFileService) - - val serviceTemplate = ServiceTemplateUtils.getServiceTemplate("load/blueprints/simple-baseconfig/Definitions/simple-baseconfig.json") - bluePrintEnhancerService.enhance(serviceTemplate) - - } -} \ No newline at end of file -- cgit 1.2.3-korg