diff options
author | Muthuramalingam, Brinda Santh <brindasanth@in.ibm.com> | 2019-02-07 16:25:50 -0500 |
---|---|---|
committer | Muthuramalingam, Brinda Santh <brindasanth@in.ibm.com> | 2019-02-07 16:25:50 -0500 |
commit | 062292d9826d32eaed3d3699a74dfbed12b68f9d (patch) | |
tree | 1ca95906b97f78de022c6a4a8540cbc9063b028b /ms/controllerblueprints/modules/blueprint-core | |
parent | 03fde837e1eb307cc0a17dda5161f1215c6159ad (diff) |
Refactor blueprint validation module
Change-Id: I93fc6e552a46a4a4796bfbddb7054a9febee878f
Issue-ID: CCSDK-1047
Signed-off-by: Muthuramalingam, Brinda Santh <brindasanth@in.ibm.com>
Diffstat (limited to 'ms/controllerblueprints/modules/blueprint-core')
12 files changed, 0 insertions, 1097 deletions
diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/validation/BluePrintArtifactTypeValidatorImpl.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/validation/BluePrintArtifactTypeValidatorImpl.kt deleted file mode 100644 index e383588ee..000000000 --- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/validation/BluePrintArtifactTypeValidatorImpl.kt +++ /dev/null @@ -1,33 +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.validation - -import org.onap.ccsdk.apps.controllerblueprints.core.data.ArtifactType -import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintArtifactTypeValidator -import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintTypeValidatorService -import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService - -open class BluePrintArtifactTypeValidatorImpl(private val bluePrintTypeValidatorService: BluePrintTypeValidatorService) : BluePrintArtifactTypeValidator { - - override fun validate(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, artifactType: ArtifactType) { - - artifactType.properties?.let { - bluePrintTypeValidatorService.validatePropertyDefinitions(bluePrintRuntimeService, artifactType.properties!!) - } - // TODO ("Files Present ") - } -}
\ No newline at end of file diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/validation/BluePrintAttributeDefinitionValidatorImpl.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/validation/BluePrintAttributeDefinitionValidatorImpl.kt deleted file mode 100644 index 53a27b53d..000000000 --- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/validation/BluePrintAttributeDefinitionValidatorImpl.kt +++ /dev/null @@ -1,29 +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.validation - -import org.onap.ccsdk.apps.controllerblueprints.core.data.AttributeDefinition -import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintAttributeDefinitionValidator -import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintTypeValidatorService -import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService - -open class BluePrintAttributeDefinitionValidatorImpl(private val bluePrintTypeValidatorService: BluePrintTypeValidatorService) : BluePrintAttributeDefinitionValidator { - - override fun validate(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, type: AttributeDefinition) { - //TODO("not implemented") //To change body of created functions use File | Settings | File Templates. - } -}
\ No newline at end of file diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/validation/BluePrintDataTypeValidatorImpl.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/validation/BluePrintDataTypeValidatorImpl.kt deleted file mode 100644 index 980302bf9..000000000 --- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/validation/BluePrintDataTypeValidatorImpl.kt +++ /dev/null @@ -1,37 +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.validation - -import com.att.eelf.configuration.EELFLogger -import com.att.eelf.configuration.EELFManager -import org.onap.ccsdk.apps.controllerblueprints.core.data.DataType -import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintDataTypeValidator -import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintTypeValidatorService -import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService - -open class BluePrintDataTypeValidatorImpl(private val bluePrintTypeValidatorService: BluePrintTypeValidatorService) : BluePrintDataTypeValidator { - private val log: EELFLogger = EELFManager.getInstance().getLogger(BluePrintDataTypeValidatorImpl::class.toString()) - - override fun validate(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, dataType: DataType) { - log.trace("Validating DataType($name)") - - dataType.properties?.let { - - bluePrintTypeValidatorService.validatePropertyDefinitions(bluePrintRuntimeService, dataType.properties!!) - } - } -}
\ No newline at end of file diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/validation/BluePrintNodeTemplateValidatorImpl.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/validation/BluePrintNodeTemplateValidatorImpl.kt deleted file mode 100644 index 0ed87f813..000000000 --- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/validation/BluePrintNodeTemplateValidatorImpl.kt +++ /dev/null @@ -1,298 +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.validation - -import com.att.eelf.configuration.EELFLogger -import com.att.eelf.configuration.EELFManager -import com.fasterxml.jackson.databind.JsonNode -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 org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintNodeTemplateValidator -import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintTypeValidatorService -import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintContext -import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintExpressionService -import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService -import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils - - -open class BluePrintNodeTemplateValidatorImpl(private val bluePrintTypeValidatorService: BluePrintTypeValidatorService) : BluePrintNodeTemplateValidator { - - private val log: EELFLogger = EELFManager.getInstance().getLogger(BluePrintNodeTemplateValidatorImpl::class.toString()) - - lateinit var bluePrintRuntimeService: BluePrintRuntimeService<*> - lateinit var bluePrintContext: BluePrintContext - var paths: MutableList<String> = arrayListOf() - - override fun validate(bluePrintRuntimeService: BluePrintRuntimeService<*>, nodeTemplateName: String, nodeTemplate: NodeTemplate) { - log.info("Validating NodeTemplate($nodeTemplateName)") - - this.bluePrintRuntimeService = bluePrintRuntimeService - this.bluePrintContext = bluePrintRuntimeService.bluePrintContext() - - paths.add(nodeTemplateName) - - val type: String = nodeTemplate.type - - val nodeType: NodeType = bluePrintContext.serviceTemplate.nodeTypes?.get(type) - ?: throw BluePrintException("Failed to get NodeType($type) definition for NodeTemplate($nodeTemplateName)") - - nodeTemplate.properties?.let { validatePropertyAssignments(nodeType.properties!!, nodeTemplate.properties!!) } - nodeTemplate.capabilities?.let { validateCapabilityAssignments(nodeType, nodeTemplateName, nodeTemplate) } - nodeTemplate.requirements?.let { validateRequirementAssignments(nodeType, nodeTemplateName, nodeTemplate) } - nodeTemplate.interfaces?.let { validateInterfaceAssignments(nodeType, nodeTemplateName, nodeTemplate) } - nodeTemplate.artifacts?.let { validateArtifactDefinitions(nodeTemplate.artifacts!!) } - - paths.removeAt(paths.lastIndex) - } - - @Throws(BluePrintException::class) - open fun validateArtifactDefinitions(artifacts: MutableMap<String, ArtifactDefinition>) { - paths.add("artifacts") - artifacts.forEach { artifactDefinitionName, artifactDefinition -> - paths.add(artifactDefinitionName) - val type: String = artifactDefinition.type - ?: throw BluePrintException("type is missing for ArtifactDefinition$artifactDefinitionName)") - // Check Artifact Type - checkValidArtifactType(artifactDefinitionName, type) - - val file: String = artifactDefinition.file - ?: throw BluePrintException("file is missing for ArtifactDefinition($artifactDefinitionName)") - - paths.removeAt(paths.lastIndex) - } - paths.removeAt(paths.lastIndex) - } - - - @Throws(BluePrintException::class) - open fun validatePropertyAssignments(nodeTypeProperties: MutableMap<String, PropertyDefinition>, - properties: MutableMap<String, JsonNode>) { - properties.forEach { propertyName, propertyAssignment -> - val propertyDefinition: PropertyDefinition = nodeTypeProperties[propertyName] - ?: throw BluePrintException("failed to get definition for the property ($propertyName)") - - validatePropertyAssignment(propertyName, propertyDefinition, propertyAssignment) - - } - } - - @Throws(BluePrintException::class) - open fun validatePropertyAssignment(propertyName: String, propertyDefinition: PropertyDefinition, - propertyAssignment: JsonNode) { - // Check and Validate if Expression Node - val expressionData = BluePrintExpressionService.getExpressionData(propertyAssignment) - if (!expressionData.isExpression) { - checkPropertyValue(propertyName, propertyDefinition, propertyAssignment) - } - } - - @Throws(BluePrintException::class) - open fun validateCapabilityAssignments(nodeType: NodeType, nodeTemplateName: String, nodeTemplate: NodeTemplate) { - val capabilities = nodeTemplate.capabilities - paths.add("capabilities") - capabilities?.forEach { capabilityName, capabilityAssignment -> - paths.add(capabilityName) - - val capabilityDefinition = nodeType.capabilities?.get(capabilityName) - ?: throw BluePrintException("Failed to get NodeTemplate($nodeTemplateName) capability definition ($capabilityName) " + - "from NodeType(${nodeTemplate.type})") - - validateCapabilityAssignment(nodeTemplateName, capabilityName, capabilityDefinition, capabilityAssignment) - - paths.removeAt(paths.lastIndex) - } - paths.removeAt(paths.lastIndex) - } - - @Throws(BluePrintException::class) - open fun validateCapabilityAssignment(nodeTemplateName: String, capabilityName: String, - capabilityDefinition: CapabilityDefinition, capabilityAssignment: CapabilityAssignment) { - - capabilityAssignment.properties?.let { validatePropertyAssignments(capabilityDefinition.properties!!, capabilityAssignment.properties!!) } - - } - - @Throws(BluePrintException::class) - open fun validateRequirementAssignments(nodeType: NodeType, nodeTemplateName: String, nodeTemplate: NodeTemplate) { - val requirements = nodeTemplate.requirements - paths.add("requirements") - requirements?.forEach { requirementName, requirementAssignment -> - paths.add(requirementName) - val requirementDefinition = nodeType.requirements?.get(requirementName) - ?: throw BluePrintException("Failed to get NodeTemplate($nodeTemplateName) requirement definition ($requirementName) from" + - " NodeType(${nodeTemplate.type})") - // Validate Requirement Assignment - validateRequirementAssignment(nodeTemplateName, requirementName, requirementDefinition, requirementAssignment) - paths.removeAt(paths.lastIndex) - } - paths.removeAt(paths.lastIndex) - - } - - @Throws(BluePrintException::class) - open fun validateRequirementAssignment(nodeTemplateName: String, requirementAssignmentName: String, - requirementDefinition: RequirementDefinition, requirementAssignment: RequirementAssignment) { - log.info("Validating NodeTemplate({}) requirement assignment ({}) ", nodeTemplateName, requirementAssignmentName) - val requirementNodeTemplateName = requirementAssignment.node!! - val capabilityName = requirementAssignment.capability - val relationship = requirementAssignment.relationship!! - - check(BluePrintTypes.validRelationShipDerivedFroms.contains(relationship)) { - throw BluePrintException("Failed to get relationship type ($relationship) for NodeTemplate($nodeTemplateName)'s requirement($requirementAssignmentName)") - } - - val relationShipNodeTemplate = bluePrintContext.serviceTemplate.topologyTemplate?.nodeTemplates?.get(requirementNodeTemplateName) - ?: throw BluePrintException("Failed to get requirement NodeTemplate($requirementNodeTemplateName)'s " + - "for NodeTemplate($nodeTemplateName) requirement($requirementAssignmentName)") - - relationShipNodeTemplate.capabilities?.get(capabilityName) - ?: throw BluePrintException("Failed to get requirement NodeTemplate($requirementNodeTemplateName)'s " + - "capability($capabilityName) for NodeTemplate ($nodeTemplateName)'s requirement($requirementAssignmentName)") - - - } - - @Throws(BluePrintException::class) - open fun validateInterfaceAssignments(nodeType: NodeType, nodeTemplateName: String, nodeTemplate: NodeTemplate) { - - val interfaces = nodeTemplate.interfaces - paths.add("interfaces") - interfaces?.forEach { interfaceAssignmentName, interfaceAssignment -> - paths.add(interfaceAssignmentName) - val interfaceDefinition = nodeType.interfaces?.get(interfaceAssignmentName) - ?: throw BluePrintException("Failed to get NodeTemplate($nodeTemplateName) interface definition ($interfaceAssignmentName) from" + - " NodeType(${nodeTemplate.type})") - - validateInterfaceAssignment(nodeTemplateName, interfaceAssignmentName, interfaceDefinition, - interfaceAssignment) - paths.removeAt(paths.lastIndex) - } - paths.removeAt(paths.lastIndex) - - - } - - @Throws(BluePrintException::class) - open fun validateInterfaceAssignment(nodeTemplateName: String, interfaceAssignmentName: String, - interfaceDefinition: InterfaceDefinition, - interfaceAssignment: InterfaceAssignment) { - - val operations = interfaceAssignment.operations - operations?.let { - validateInterfaceOperationsAssignment(nodeTemplateName, interfaceAssignmentName, interfaceDefinition, - interfaceAssignment) - } - - } - - @Throws(BluePrintException::class) - open fun validateInterfaceOperationsAssignment(nodeTemplateName: String, interfaceAssignmentName: String, - interfaceDefinition: InterfaceDefinition, - interfaceAssignment: InterfaceAssignment) { - - val operations = interfaceAssignment.operations - operations?.let { - it.forEach { operationAssignmentName, operationAssignments -> - - val operationDefinition = interfaceDefinition.operations?.get(operationAssignmentName) - ?: throw BluePrintException("Failed to get NodeTemplate($nodeTemplateName) operation definition ($operationAssignmentName)") - - log.info("Validation NodeTemplate($nodeTemplateName) Interface($interfaceAssignmentName) Operation ($operationAssignmentName)") - - val inputs = operationAssignments.inputs - val outputs = operationAssignments.outputs - - inputs?.forEach { propertyName, propertyAssignment -> - val propertyDefinition = operationDefinition.inputs?.get(propertyName) - ?: throw BluePrintException("Failed to get NodeTemplate($nodeTemplateName) operation " + - "definition ($operationAssignmentName) property definition($propertyName)") - // Check the property values with property definition - validatePropertyAssignment(propertyName, propertyDefinition, propertyAssignment) - } - - outputs?.forEach { propertyName, propertyAssignment -> - val propertyDefinition = operationDefinition.outputs?.get(propertyName) - ?: throw BluePrintException("Failed to get NodeTemplate($nodeTemplateName) operation definition ($operationAssignmentName) " + - "output property definition($propertyName)") - // Check the property values with property definition - validatePropertyAssignment(propertyName, propertyDefinition, propertyAssignment) - } - - } - } - - } - - open fun checkValidArtifactType(artifactDefinitionName: String, artifactTypeName: String) { - - val artifactType = bluePrintContext.serviceTemplate.artifactTypes?.get(artifactTypeName) - ?: throw BluePrintException("failed to get artifactType($artifactTypeName) for ArtifactDefinition($artifactDefinitionName)") - - checkValidArtifactTypeDerivedFrom(artifactTypeName, artifactType.derivedFrom) - } - - @Throws(BluePrintException::class) - open fun checkValidArtifactTypeDerivedFrom(artifactTypeName: String, derivedFrom: String) { - check(BluePrintTypes.validArtifactTypeDerivedFroms.contains(derivedFrom)) { - throw BluePrintException("failed to get artifactType($artifactTypeName)'s derivedFrom($derivedFrom) definition") - } - } - - open fun checkPropertyValue(propertyName: String, propertyDefinition: PropertyDefinition, propertyAssignment: JsonNode) { - val propertyType = propertyDefinition.type - val isValid: Boolean - - if (BluePrintTypes.validPrimitiveTypes().contains(propertyType)) { - isValid = JacksonUtils.checkJsonNodeValueOfPrimitiveType(propertyType, propertyAssignment) - - } else if (BluePrintTypes.validCollectionTypes().contains(propertyType)) { - - val entrySchemaType = propertyDefinition.entrySchema?.type - ?: throw BluePrintException(format("Failed to get EntrySchema type for the collection property ({})", propertyName)) - - if (!BluePrintTypes.validPropertyTypes().contains(entrySchemaType)) { - checkPropertyDataType(entrySchemaType, propertyName) - } - isValid = JacksonUtils.checkJsonNodeValueOfCollectionType(propertyType, propertyAssignment) - } else { - checkPropertyDataType(propertyType, propertyName) - isValid = true - } - - check(isValid) { - throw BluePrintException("property(propertyName) defined of type(propertyType) is not comptable with the value (propertyAssignment)") - } - } - - private fun checkPropertyDataType(dataTypeName: String, propertyName: String) { - - val dataType = bluePrintContext.serviceTemplate.dataTypes?.get(dataTypeName) - ?: throw BluePrintException("DataType ($dataTypeName) for the property ($propertyName) not found") - - checkValidDataTypeDerivedFrom(propertyName, dataType.derivedFrom) - - } - - private fun checkValidDataTypeDerivedFrom(dataTypeName: String, derivedFrom: String) { - check(BluePrintTypes.validDataTypeDerivedFroms.contains(derivedFrom)) { - throw BluePrintException("Failed to get DataType($dataTypeName)'s derivedFrom($derivedFrom) definition ") - } - } - -}
\ No newline at end of file diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/validation/BluePrintNodeTypeValidatorImpl.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/validation/BluePrintNodeTypeValidatorImpl.kt deleted file mode 100644 index 1077f347e..000000000 --- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/validation/BluePrintNodeTypeValidatorImpl.kt +++ /dev/null @@ -1,155 +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.validation - -import com.att.eelf.configuration.EELFLogger -import com.att.eelf.configuration.EELFManager -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintTypes -import org.onap.ccsdk.apps.controllerblueprints.core.checkNotEmptyOrThrow -import org.onap.ccsdk.apps.controllerblueprints.core.data.* -import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintNodeTypeValidator -import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintTypeValidatorService -import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintContext -import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService - - -open class BluePrintNodeTypeValidatorImpl(private val bluePrintTypeValidatorService: BluePrintTypeValidatorService) : BluePrintNodeTypeValidator { - - private val log: EELFLogger = EELFManager.getInstance().getLogger(BluePrintServiceTemplateValidatorImpl::class.toString()) - - lateinit var bluePrintRuntimeService: BluePrintRuntimeService<*> - lateinit var bluePrintContext: BluePrintContext - var paths: MutableList<String> = arrayListOf() - - override fun validate(bluePrintRuntimeService: BluePrintRuntimeService<*>, nodeTypeName: String, nodeType: NodeType) { - log.trace("Validating NodeType($nodeTypeName)") - this.bluePrintRuntimeService = bluePrintRuntimeService - this.bluePrintContext = bluePrintRuntimeService.bluePrintContext() - - paths.add(nodeTypeName) - - val derivedFrom: String = nodeType.derivedFrom - //Check Derived From - checkValidNodeTypesDerivedFrom(nodeTypeName, derivedFrom) - - if (!BluePrintTypes.rootNodeTypes().contains(derivedFrom)) { - bluePrintContext.serviceTemplate.nodeTypes?.get(derivedFrom) - ?: throw BluePrintException("Failed to get derivedFrom NodeType($derivedFrom)'s for NodeType($nodeTypeName)") - } - - nodeType.properties?.let { bluePrintTypeValidatorService.validatePropertyDefinitions(bluePrintRuntimeService, nodeType.properties!!) } - nodeType.capabilities?.let { validateCapabilityDefinitions(nodeTypeName, nodeType) } - nodeType.requirements?.let { validateRequirementDefinitions(nodeTypeName, nodeType) } - nodeType.interfaces?.let { validateInterfaceDefinitions(nodeType.interfaces!!) } - - paths.removeAt(paths.lastIndex) - } - - fun checkValidNodeTypesDerivedFrom(nodeTypeName: String, derivedFrom: String) { - check(BluePrintTypes.validNodeTypeDerivedFroms.contains(derivedFrom)) { - throw BluePrintException("Failed to get node type ($nodeTypeName)'s derivedFrom($derivedFrom) definition ") - } - } - - open fun validateCapabilityDefinitions(nodeTypeName: String, nodeType: NodeType) { - val capabilities = nodeType.capabilities - paths.add("capabilities") - capabilities?.forEach { capabilityName, capabilityDefinition -> - paths.add(capabilityName) - - validateCapabilityDefinition(nodeTypeName, nodeType, capabilityName, capabilityDefinition) - - paths.removeAt(paths.lastIndex) - } - paths.removeAt(paths.lastIndex) - } - - open fun validateCapabilityDefinition(nodeTypeName: String, nodeType: NodeType, capabilityName: String, - capabilityDefinition: CapabilityDefinition) { - val capabilityType = capabilityDefinition.type - check(BluePrintTypes.validCapabilityTypes.contains(capabilityType)) { - throw BluePrintException("failed to get CapabilityType($capabilityType) for NodeType($nodeTypeName)") - } - } - - open fun validateRequirementDefinitions(nodeName: String, nodeType: NodeType) { - paths.add("requirements") - val requirements = nodeType.requirements - - requirements?.forEach { requirementDefinitionName, requirementDefinition -> - paths.add(requirementDefinitionName) - validateRequirementDefinition(nodeName, nodeType, requirementDefinitionName, requirementDefinition) - paths.removeAt(paths.lastIndex) - } - paths.removeAt(paths.lastIndex) - } - - open fun validateRequirementDefinition(nodeTypeName: String, nodeType: NodeType, requirementDefinitionName: String, - requirementDefinition: RequirementDefinition) { - - log.info("validating NodeType({}) RequirementDefinition ({}) ", nodeTypeName, requirementDefinitionName) - val requirementNodeTypeName = requirementDefinition.node!! - val capabilityName = requirementDefinition.capability - val relationship = requirementDefinition.relationship!! - - check(BluePrintTypes.validRelationShipDerivedFroms.contains(relationship)) { - throw BluePrintException("failed to get relationship($relationship) for NodeType($nodeTypeName)'s requirement($requirementDefinitionName)") - } - - val relationShipNodeType = bluePrintContext.serviceTemplate.nodeTypes?.get(requirementNodeTypeName) - ?: throw BluePrintException("failed to get requirement NodeType($requirementNodeTypeName)'s for requirement($requirementDefinitionName) ") - - relationShipNodeType.capabilities?.get(capabilityName) - ?: throw BluePrintException("failed to get requirement NodeType($requirementNodeTypeName)'s " + - "capability($nodeTypeName) for NodeType ($capabilityName)'s requirement($requirementDefinitionName) ") - - } - - open fun validateInterfaceDefinitions(interfaces: MutableMap<String, InterfaceDefinition>) { - paths.add("interfaces") - interfaces.forEach { interfaceName, interfaceDefinition -> - paths.add(interfaceName) - interfaceDefinition.operations?.let { validateOperationDefinitions(interfaceDefinition.operations!!) } - paths.removeAt(paths.lastIndex) - } - paths.removeAt(paths.lastIndex) - } - - open fun validateOperationDefinitions(operations: MutableMap<String, OperationDefinition>) { - paths.add("operations") - operations.forEach { opertaionName, operationDefinition -> - paths.add(opertaionName) - operationDefinition.implementation?.let { validateImplementation(operationDefinition.implementation!!) } - - operationDefinition.inputs?.let { - bluePrintTypeValidatorService.validatePropertyDefinitions(bluePrintRuntimeService, operationDefinition.inputs!!) - } - - operationDefinition.outputs?.let { - bluePrintTypeValidatorService.validatePropertyDefinitions(bluePrintRuntimeService, operationDefinition.outputs!!) - } - paths.removeAt(paths.lastIndex) - } - paths.removeAt(paths.lastIndex) - } - - open fun validateImplementation(implementation: Implementation) { - checkNotEmptyOrThrow(implementation.primary) - } - -}
\ No newline at end of file diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/validation/BluePrintPropertyDefinitionValidatorImpl.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/validation/BluePrintPropertyDefinitionValidatorImpl.kt deleted file mode 100644 index ca156190c..000000000 --- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/validation/BluePrintPropertyDefinitionValidatorImpl.kt +++ /dev/null @@ -1,83 +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.validation - -import com.att.eelf.configuration.EELFLogger -import com.att.eelf.configuration.EELFManager -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintTypes -import org.onap.ccsdk.apps.controllerblueprints.core.data.PropertyDefinition -import org.onap.ccsdk.apps.controllerblueprints.core.format -import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintPropertyDefinitionValidator -import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintTypeValidatorService -import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService - -open class BluePrintPropertyDefinitionValidatorImpl(private val bluePrintTypeValidatorService: BluePrintTypeValidatorService) : BluePrintPropertyDefinitionValidator { - - private val log: EELFLogger = EELFManager.getInstance().getLogger(BluePrintServiceTemplateValidatorImpl::class.toString()) - - lateinit var bluePrintRuntimeService: BluePrintRuntimeService<*> - - - override fun validate(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, propertyDefinition: PropertyDefinition) { - this.bluePrintRuntimeService = bluePrintRuntimeService - - - log.trace("Validating PropertyDefinition($name)") - - val dataType: String = propertyDefinition.type - - when { - BluePrintTypes.validPrimitiveTypes().contains(dataType) -> { - // Do Nothing - } - BluePrintTypes.validCollectionTypes().contains(dataType) -> { - val entrySchemaType: String = propertyDefinition.entrySchema?.type - ?: throw BluePrintException(format("Entry schema for DataType ({}) for the property ({}) not found", dataType, name)) - checkPrimitiveOrComplex(entrySchemaType, name) - } - else -> checkPropertyDataType(dataType, name) - } - } - - - private fun checkPrimitiveOrComplex(dataType: String, propertyName: String): Boolean { - if (BluePrintTypes.validPrimitiveTypes().contains(dataType) || checkDataType(dataType)) { - return true - } else { - throw BluePrintException(format("DataType({}) for the property({}) is not valid", dataType, propertyName)) - } - } - - private fun checkPropertyDataType(dataTypeName: String, propertyName: String) { - - val dataType = bluePrintRuntimeService.bluePrintContext().serviceTemplate.dataTypes?.get(dataTypeName) - ?: throw BluePrintException(format("DataType ({}) for the property ({}) not found", dataTypeName, propertyName)) - - checkValidDataTypeDerivedFrom(propertyName, dataType.derivedFrom) - } - - private fun checkDataType(key: String): Boolean { - return bluePrintRuntimeService.bluePrintContext().serviceTemplate.dataTypes?.containsKey(key) ?: false - } - - open fun checkValidDataTypeDerivedFrom(dataTypeName: String, derivedFrom: String) { - check(BluePrintTypes.validDataTypeDerivedFroms.contains(derivedFrom)) { - throw BluePrintException(format("Failed to get DataType({})'s derivedFrom({}) definition ", dataTypeName, derivedFrom)) - } - } -}
\ No newline at end of file diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/validation/BluePrintServiceTemplateValidatorImpl.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/validation/BluePrintServiceTemplateValidatorImpl.kt deleted file mode 100644 index 61159cf8b..000000000 --- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/validation/BluePrintServiceTemplateValidatorImpl.kt +++ /dev/null @@ -1,107 +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.validation - -import com.att.eelf.configuration.EELFLogger -import com.att.eelf.configuration.EELFManager -import com.google.common.base.Preconditions -import org.apache.commons.lang3.StringUtils -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintError -import org.onap.ccsdk.apps.controllerblueprints.core.data.* -import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintServiceTemplateValidator -import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintTypeValidatorService -import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService - -open class BluePrintServiceTemplateValidatorImpl(private val bluePrintTypeValidatorService: BluePrintTypeValidatorService) : BluePrintServiceTemplateValidator { - - private val log: EELFLogger = EELFManager.getInstance().getLogger(BluePrintServiceTemplateValidatorImpl::class.toString()) - - lateinit var bluePrintRuntimeService: BluePrintRuntimeService<*> - lateinit var error: BluePrintError - - var paths: MutableList<String> = arrayListOf() - - override fun validate(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, serviceTemplate: ServiceTemplate) { - log.trace("Validating Service Template..") - try { - this.bluePrintRuntimeService = bluePrintRuntimeService - this.error = bluePrintRuntimeService.getBluePrintError() - - serviceTemplate.metadata?.let { validateMetadata(serviceTemplate.metadata!!) } - serviceTemplate.dataTypes?.let { validateDataTypes(serviceTemplate.dataTypes!!) } - serviceTemplate.artifactTypes?.let { validateArtifactTypes(serviceTemplate.artifactTypes!!) } - serviceTemplate.nodeTypes?.let { validateNodeTypes(serviceTemplate.nodeTypes!!) } - serviceTemplate.topologyTemplate?.let { validateTopologyTemplate(serviceTemplate.topologyTemplate!!) } - } catch (e: Exception) { - log.error("failed in blueprint service template validation", e) - error.addError(BluePrintConstants.PATH_SERVICE_TEMPLATE, paths.joinToString(BluePrintConstants.PATH_DIVIDER), e.message!!) - } - } - - fun validateMetadata(metaDataMap: MutableMap<String, String>) { - - paths.add(BluePrintConstants.PATH_METADATA) - - val templateName = metaDataMap[BluePrintConstants.METADATA_TEMPLATE_NAME] - val templateVersion = metaDataMap[BluePrintConstants.METADATA_TEMPLATE_VERSION] - val templateTags = metaDataMap[BluePrintConstants.METADATA_TEMPLATE_TAGS] - val templateAuthor = metaDataMap[BluePrintConstants.METADATA_TEMPLATE_AUTHOR] - - Preconditions.checkArgument(StringUtils.isNotBlank(templateName), "failed to get template name metadata") - Preconditions.checkArgument(StringUtils.isNotBlank(templateVersion), "failed to get template version metadata") - Preconditions.checkArgument(StringUtils.isNotBlank(templateTags), "failed to get template tags metadata") - Preconditions.checkArgument(StringUtils.isNotBlank(templateAuthor), "failed to get template author metadata") - - paths.removeAt(paths.lastIndex) - } - - - fun validateDataTypes(dataTypes: MutableMap<String, DataType>) { - - paths.add(BluePrintConstants.PATH_DATA_TYPES) - dataTypes.forEach { dataTypeName, dataType -> - // Validate Single Data Type - bluePrintTypeValidatorService.validateDataType(bluePrintRuntimeService, dataTypeName, dataType) - } - paths.removeAt(paths.lastIndex) - } - - fun validateArtifactTypes(artifactTypes: MutableMap<String, ArtifactType>) { - paths.add(BluePrintConstants.PATH_ARTIFACT_TYPES) - artifactTypes.forEach { artifactName, artifactType -> - // Validate Single Artifact Type - bluePrintTypeValidatorService.validateArtifactType(bluePrintRuntimeService, artifactName, artifactType) - } - paths.removeAt(paths.lastIndex) - } - - fun validateNodeTypes(nodeTypes: MutableMap<String, NodeType>) { - paths.add(BluePrintConstants.PATH_NODE_TYPES) - nodeTypes.forEach { nodeTypeName, nodeType -> - // Validate Single Node Type - bluePrintTypeValidatorService.validateNodeType(bluePrintRuntimeService, nodeTypeName, nodeType) - } - paths.removeAt(paths.lastIndex) - } - - fun validateTopologyTemplate(topologyTemplate: TopologyTemplate) { - paths.add(BluePrintConstants.PATH_TOPOLOGY_TEMPLATE) - bluePrintTypeValidatorService.validateTopologyTemplate(bluePrintRuntimeService, "topologyTemplate", topologyTemplate) - paths.removeAt(paths.lastIndex) - } -}
\ No newline at end of file diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/validation/BluePrintTopologyTemplateValidatorImpl.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/validation/BluePrintTopologyTemplateValidatorImpl.kt deleted file mode 100644 index b87666d2d..000000000 --- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/validation/BluePrintTopologyTemplateValidatorImpl.kt +++ /dev/null @@ -1,72 +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.validation - -import com.att.eelf.configuration.EELFLogger -import com.att.eelf.configuration.EELFManager -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException -import org.onap.ccsdk.apps.controllerblueprints.core.data.NodeTemplate -import org.onap.ccsdk.apps.controllerblueprints.core.data.PropertyDefinition -import org.onap.ccsdk.apps.controllerblueprints.core.data.TopologyTemplate -import org.onap.ccsdk.apps.controllerblueprints.core.data.Workflow -import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintTopologyTemplateValidator -import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintTypeValidatorService -import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService - -open class BluePrintTopologyTemplateValidatorImpl(private val bluePrintTypeValidatorService: BluePrintTypeValidatorService) : BluePrintTopologyTemplateValidator { - - private val log: EELFLogger = EELFManager.getInstance().getLogger(BluePrintServiceTemplateValidatorImpl::class.toString()) - - lateinit var bluePrintRuntimeService: BluePrintRuntimeService<*> - - override fun validate(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, topologyTemplate: TopologyTemplate) { - log.trace("Validating Topology Template..") - this.bluePrintRuntimeService = bluePrintRuntimeService - - // Validate Inputs - topologyTemplate.inputs?.let { validateInputs(topologyTemplate.inputs!!) } - // Validate Node Templates - topologyTemplate.nodeTemplates?.let { validateNodeTemplates(topologyTemplate.nodeTemplates!!) } - // Validate Workflow - topologyTemplate.workflows?.let { validateWorkflows(topologyTemplate.workflows!!) } - } - - @Throws(BluePrintException::class) - fun validateInputs(inputs: MutableMap<String, PropertyDefinition>) { - bluePrintTypeValidatorService.validatePropertyDefinitions(bluePrintRuntimeService, inputs) - } - - - @Throws(BluePrintException::class) - fun validateNodeTemplates(nodeTemplates: MutableMap<String, NodeTemplate>) { - - nodeTemplates.forEach { nodeTemplateName, nodeTemplate -> - // Validate Single Node Template - bluePrintTypeValidatorService.validateNodeTemplate(bluePrintRuntimeService, nodeTemplateName, nodeTemplate) - } - } - - @Throws(BluePrintException::class) - open fun validateWorkflows(workflows: MutableMap<String, Workflow>) { - - workflows.forEach { workflowName, workflow -> - // Validate Single workflow - bluePrintTypeValidatorService.validateWorkflow(bluePrintRuntimeService, workflowName, workflow) - } - } - -}
\ No newline at end of file diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/validation/BluePrintValidatorServiceImpl.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/validation/BluePrintValidatorServiceImpl.kt deleted file mode 100644 index 4f68342eb..000000000 --- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/validation/BluePrintValidatorServiceImpl.kt +++ /dev/null @@ -1,48 +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.validation - -import com.att.eelf.configuration.EELFLogger -import com.att.eelf.configuration.EELFManager -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException -import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintTypeValidatorService -import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintValidatorService -import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService -import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintMetadataUtils -import java.util.* - - -open class BluePrintValidatorServiceImpl(private val bluePrintTypeValidatorService: BluePrintTypeValidatorService) : BluePrintValidatorService { - - private val log: EELFLogger = EELFManager.getInstance().getLogger(BluePrintValidatorServiceImpl::class.toString()) - - override fun validateBluePrints(basePath: String): Boolean { - - val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime(UUID.randomUUID().toString(), basePath) - return validateBluePrints(bluePrintRuntimeService) - } - - override fun validateBluePrints(bluePrintRuntimeService: BluePrintRuntimeService<*>): Boolean { - - bluePrintTypeValidatorService.validateServiceTemplate(bluePrintRuntimeService, "service_template", - bluePrintRuntimeService.bluePrintContext().serviceTemplate) - if (bluePrintRuntimeService.getBluePrintError().errors.size > 0) { - throw BluePrintException("failed in blueprint validation : ${bluePrintRuntimeService.getBluePrintError().errors.joinToString("\n")}") - } - return true - } -} diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/validation/BluePrintWorkflowValidatorImpl.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/validation/BluePrintWorkflowValidatorImpl.kt deleted file mode 100644 index 61918fbc9..000000000 --- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/validation/BluePrintWorkflowValidatorImpl.kt +++ /dev/null @@ -1,76 +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.validation - -import com.att.eelf.configuration.EELFLogger -import com.att.eelf.configuration.EELFManager -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants -import org.onap.ccsdk.apps.controllerblueprints.core.data.Workflow -import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintTypeValidatorService -import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintWorkflowValidator -import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService - -open class BluePrintWorkflowValidatorImpl(private val bluePrintTypeValidatorService: BluePrintTypeValidatorService) : BluePrintWorkflowValidator { - - private val log: EELFLogger = EELFManager.getInstance().getLogger(BluePrintServiceTemplateValidatorImpl::class.toString()) - lateinit var bluePrintRuntimeService: BluePrintRuntimeService<*> - - var paths: MutableList<String> = arrayListOf() - - override fun validate(bluePrintRuntimeService: BluePrintRuntimeService<*>, workflowName: String, workflow: Workflow) { - log.info("Validating Workflow($workflowName)") - - this.bluePrintRuntimeService = bluePrintRuntimeService - - - paths.add(workflowName) - paths.joinToString(BluePrintConstants.PATH_DIVIDER) - - // Step Validation Start - paths.add("steps") - workflow.steps?.forEach { stepName, step -> - paths.add(stepName) - paths.joinToString(BluePrintConstants.PATH_DIVIDER) - - // Validate target - step.target?.let { - try { - val nodeTemplate = bluePrintRuntimeService.bluePrintContext().nodeTemplateByName(it) - - val nodeTypeDerivedFrom = bluePrintRuntimeService.bluePrintContext().nodeTemplateNodeType(it).derivedFrom - - check(nodeTypeDerivedFrom == BluePrintConstants.MODEL_TYPE_NODE_DG) { - "NodeType(${nodeTemplate.type}) derived from is '$nodeTypeDerivedFrom', Expected is " + - "'${BluePrintConstants.MODEL_TYPE_NODE_DG}'" - } - } catch (e: Exception) { - bluePrintRuntimeService.getBluePrintError() - .addError("Failed to validate Workflow($workflowName)'s step($stepName)'s " + - "definition", paths.joinToString(BluePrintConstants.PATH_DIVIDER), e.message!!) - } - } - paths.removeAt(paths.lastIndex) - } - paths.removeAt(paths.lastIndex) - // Step Validation Ends - paths.removeAt(paths.lastIndex) - - workflow.inputs?.let { - bluePrintTypeValidatorService.validatePropertyDefinitions(bluePrintRuntimeService, workflow.inputs!!) - } - } -}
\ No newline at end of file diff --git a/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/mock/MockBluePrintTypeValidatorService.kt b/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/mock/MockBluePrintTypeValidatorService.kt deleted file mode 100644 index 4c174f92e..000000000 --- a/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/mock/MockBluePrintTypeValidatorService.kt +++ /dev/null @@ -1,59 +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.mock - -import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.* -import org.onap.ccsdk.apps.controllerblueprints.core.validation.* - -class MockBluePrintTypeValidatorService : BluePrintTypeValidatorService { - - override fun getServiceTemplateValidators(): List<BluePrintServiceTemplateValidator> { - return listOf(BluePrintServiceTemplateValidatorImpl(this)) - } - - override fun getDataTypeValidators(): List<BluePrintDataTypeValidator> { - return listOf(BluePrintDataTypeValidatorImpl(this)) - } - - override fun getArtifactTypeValidators(): List<BluePrintArtifactTypeValidator> { - return listOf(BluePrintArtifactTypeValidatorImpl(this)) - } - - override fun getNodeTypeValidators(): List<BluePrintNodeTypeValidator> { - return listOf(BluePrintNodeTypeValidatorImpl(this)) - } - - override fun getTopologyTemplateValidators(): List<BluePrintTopologyTemplateValidator> { - return listOf(BluePrintTopologyTemplateValidatorImpl(this)) - } - - override fun getNodeTemplateValidators(): List<BluePrintNodeTemplateValidator> { - return listOf(BluePrintNodeTemplateValidatorImpl(this)) - } - - override fun getWorkflowValidators(): List<BluePrintWorkflowValidator> { - return listOf(BluePrintWorkflowValidatorImpl(this)) - } - - override fun getPropertyDefinitionValidators(): List<BluePrintPropertyDefinitionValidator> { - return listOf(BluePrintPropertyDefinitionValidatorImpl(this)) - } - - override fun getAttributeDefinitionValidators(): List<BluePrintAttributeDefinitionValidator> { - return listOf(BluePrintAttributeDefinitionValidatorImpl(this)) - } -}
\ No newline at end of file diff --git a/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/validation/BluePrintValidatorServiceImplTest.kt b/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/validation/BluePrintValidatorServiceImplTest.kt deleted file mode 100644 index cfcbd9b2f..000000000 --- a/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/validation/BluePrintValidatorServiceImplTest.kt +++ /dev/null @@ -1,100 +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.validation - -import io.mockk.every -import io.mockk.mockk -import org.junit.Test -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintError -import org.onap.ccsdk.apps.controllerblueprints.core.data.NodeTemplate -import org.onap.ccsdk.apps.controllerblueprints.core.data.NodeType -import org.onap.ccsdk.apps.controllerblueprints.core.data.Step -import org.onap.ccsdk.apps.controllerblueprints.core.data.Workflow -import org.onap.ccsdk.apps.controllerblueprints.core.mock.MockBluePrintTypeValidatorService -import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintContext -import org.onap.ccsdk.apps.controllerblueprints.core.service.DefaultBluePrintRuntimeService -import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintMetadataUtils -import kotlin.test.assertEquals -import kotlin.test.assertTrue - -class BluePrintValidatorServiceImplTest { - - private val blueprintBasePath: String = ("./../../../../components/model-catalog/blueprint-model/starter-blueprint/baseconfiguration") - private val bluePrintRuntime = BluePrintMetadataUtils.getBluePrintRuntime("1234", blueprintBasePath) - private val mockBluePrintTypeValidatorService = MockBluePrintTypeValidatorService() - private val defaultBluePrintValidatorService = BluePrintValidatorServiceImpl(mockBluePrintTypeValidatorService) - private val workflowValidator = BluePrintWorkflowValidatorImpl(mockBluePrintTypeValidatorService) - - @Test - fun testValidateOfType() { - val valid = defaultBluePrintValidatorService.validateBluePrints(bluePrintRuntime) - assertTrue(valid, "failed in blueprint Validation") - } - - @Test - fun testValidateWorkflowFailToFoundNodeTemplate() { - val workflowName = "resource-assignment" - - val step = Step() - step.target = "TestCaseFailNoNodeTemplate" - val workflow = Workflow() - workflow.steps = mutableMapOf("test" to step) - workflowValidator.validate(bluePrintRuntime, workflowName, workflow) - - assertEquals(1, bluePrintRuntime.getBluePrintError().errors.size) - assertEquals("Failed to validate Workflow(resource-assignment)'s step(test)'s definition : resource-assignment/steps/test : could't get node template for the name(TestCaseFailNoNodeTemplate)", bluePrintRuntime.getBluePrintError().errors[0]) - } - - @Test - fun testValidateWorkflowFailNodeTemplateNotDgGeneric() { - val workflowName = "resource-assignment" - val nodeTemplateName = "resource-assignment-process" - - val nodeTemplate = mockk<NodeTemplate>() - every { nodeTemplate.type } returns "TestNodeType" - - val nodeType = mockk<NodeType>() - every { nodeType.derivedFrom } returns "tosca.nodes.TEST" - - val blueprintContext = mockk<BluePrintContext>() - every { blueprintContext.nodeTemplateByName(nodeTemplateName) } returns nodeTemplate - every { blueprintContext.nodeTemplateNodeType(nodeTemplateName) } returns nodeType - - val bluePrintRuntime = mockk<DefaultBluePrintRuntimeService>("1234") - - every { bluePrintRuntime.getBluePrintError() } returns BluePrintError() - every { bluePrintRuntime.bluePrintContext() } returns blueprintContext - - val step = Step() - step.target = nodeTemplateName - val workflow = Workflow() - workflow.steps = mutableMapOf("test" to step) - workflowValidator.validate(bluePrintRuntime, workflowName, workflow) - - assertEquals(1, bluePrintRuntime.getBluePrintError().errors.size) - assertEquals("Failed to validate Workflow(resource-assignment)'s step(test)'s definition : resource-assignment/steps/test : NodeType(TestNodeType) derived from is 'tosca.nodes.TEST', Expected is 'tosca.nodes.DG'", bluePrintRuntime.getBluePrintError().errors[0]) - } - - @Test - fun testValidateWorkflowSuccess() { - val workflowName = "resource-assignment" - workflowValidator.validate(bluePrintRuntime, workflowName, bluePrintRuntime.bluePrintContext().workflowByName(workflowName)) - } - -} - |