diff options
Diffstat (limited to 'ms')
26 files changed, 444 insertions, 167 deletions
diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/BlueprintProcessorCatalogServiceImpl.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/BlueprintProcessorCatalogServiceImpl.kt index 33d0d96d..e94bcff5 100755 --- a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/BlueprintProcessorCatalogServiceImpl.kt +++ b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/BlueprintProcessorCatalogServiceImpl.kt @@ -1,6 +1,7 @@ /* * Copyright © 2017-2018 AT&T Intellectual Property. * Modifications Copyright © 2019 Bell Canada. + * 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. @@ -40,10 +41,10 @@ import java.nio.file.Paths * Similar/Duplicate implementation in [org.onap.ccsdk.apps.controllerblueprints.service.load.ControllerBlueprintCatalogServiceImpl] */ @Service -class BlueprintProcessorCatalogServiceImpl(bluePrintValidatorService: BluePrintValidatorService, +class BlueprintProcessorCatalogServiceImpl(bluePrintRuntimeValidatorService: BluePrintValidatorService, private val blueprintConfig: BluePrintCoreConfiguration, private val blueprintModelRepository: BlueprintProcessorModelRepository) - : BlueprintCatalogServiceImpl(bluePrintValidatorService) { + : BlueprintCatalogServiceImpl(bluePrintRuntimeValidatorService) { private val log = LoggerFactory.getLogger(BlueprintProcessorCatalogServiceImpl::class.toString()) diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/test/resources/test-cba.zip b/ms/blueprintsprocessor/modules/commons/db-lib/src/test/resources/test-cba.zip Binary files differindex a62d4bfb..90748240 100644 --- a/ms/blueprintsprocessor/modules/commons/db-lib/src/test/resources/test-cba.zip +++ b/ms/blueprintsprocessor/modules/commons/db-lib/src/test/resources/test-cba.zip diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/pom.xml b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/pom.xml index 4a305358..c05b84ad 100755 --- a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/pom.xml +++ b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/pom.xml @@ -39,10 +39,13 @@ </dependency> <dependency> <groupId>org.onap.ccsdk.apps.controllerblueprints</groupId> - <version>${project.version}</version> <artifactId>blueprint-core</artifactId> </dependency> <dependency> + <groupId>org.onap.ccsdk.apps.controllerblueprints</groupId> + <artifactId>blueprint-validation</artifactId> + </dependency> + <dependency> <groupId>io.grpc</groupId> <artifactId>grpc-testing</artifactId> </dependency> diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/validation/BluePrintDesignTimeRuntimeValidatorService.kt b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/validation/BluePrintDesignTimeRuntimeValidatorService.kt new file mode 100644 index 00000000..08d2c3b5 --- /dev/null +++ b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/validation/BluePrintDesignTimeRuntimeValidatorService.kt @@ -0,0 +1,38 @@ +/* + * 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.blueprintsprocessor.selfservice.api.validation + +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException +import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintTypeValidatorService +import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService +import org.onap.ccsdk.apps.controllerblueprints.validation.BluePrintDesignTimeValidatorService +import org.springframework.stereotype.Service + +@Service +open class BluePrintRuntimeValidatorService( + private val bluePrintTypeValidatorService: BluePrintTypeValidatorService) : BluePrintDesignTimeValidatorService(bluePrintTypeValidatorService) { + + 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 + } +}
\ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/resources/test-cba.zip b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/resources/test-cba.zip Binary files differindex a62d4bfb..90748240 100644 --- a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/resources/test-cba.zip +++ b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/resources/test-cba.zip diff --git a/ms/blueprintsprocessor/parent/pom.xml b/ms/blueprintsprocessor/parent/pom.xml index ab418f47..51eae8b4 100755 --- a/ms/blueprintsprocessor/parent/pom.xml +++ b/ms/blueprintsprocessor/parent/pom.xml @@ -339,6 +339,11 @@ <artifactId>blueprint-scripts</artifactId> <version>${project.version}</version> </dependency> + <dependency> + <groupId>org.onap.ccsdk.apps.controllerblueprints</groupId> + <artifactId>blueprint-validation</artifactId> + <version>${project.version}</version> + </dependency> <!-- Database --> <dependency> diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/data/BluePrintModel.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/data/BluePrintModel.kt index 2647083f..aab4e7c7 100644 --- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/data/BluePrintModel.kt +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/data/BluePrintModel.kt @@ -118,16 +118,13 @@ or Node Template and used by orchestration engine to facilitate deployment and i class ArtifactDefinition { @get:JsonIgnore var id: String? = null - var type: String? = null - var file: String? = null + lateinit var type: String + lateinit var file: String var repository: String? = null var description: String? = null @get:JsonProperty("deploy_Path") var deployPath: String? = null var properties: MutableMap<String, JsonNode>? = null - var content: String? = null - @Deprecated("Mapping content is define by the Type") - var mappingContent: String? = null } diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/interfaces/BlueprintValidator.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/interfaces/BlueprintValidator.kt index bea790fd..a485c677 100644 --- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/interfaces/BlueprintValidator.kt +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/interfaces/BlueprintValidator.kt @@ -1,3 +1,20 @@ +/* + * 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.interfaces import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException @@ -18,6 +35,8 @@ interface BluePrintTopologyTemplateValidator : BluePrintValidator<TopologyTempla interface BluePrintArtifactTypeValidator : BluePrintValidator<ArtifactType> +interface BluePrintArtifactDefinitionValidator : BluePrintValidator<ArtifactDefinition> + interface BluePrintDataTypeValidator : BluePrintValidator<DataType> interface BluePrintNodeTypeValidator : BluePrintValidator<NodeType> @@ -45,12 +64,20 @@ interface BluePrintValidatorService { interface BluePrintTypeValidatorService { + fun <T : BluePrintValidator<*>> bluePrintValidator(referenceName: String, classType: Class<T>): T? + + fun <T : BluePrintValidator<*>> bluePrintValidators(referenceNamePrefix: String, classType: Class<T>): List<T>? + + fun <T : BluePrintValidator<*>> bluePrintValidators(classType: Class<T>): List<T>? + fun getServiceTemplateValidators(): List<BluePrintServiceTemplateValidator> fun getDataTypeValidators(): List<BluePrintDataTypeValidator> fun getArtifactTypeValidators(): List<BluePrintArtifactTypeValidator> + fun getArtifactDefinitionsValidators(): List<BluePrintArtifactDefinitionValidator> + fun getNodeTypeValidators(): List<BluePrintNodeTypeValidator> fun getTopologyTemplateValidators(): List<BluePrintTopologyTemplateValidator> @@ -73,6 +100,12 @@ interface BluePrintTypeValidatorService { doValidation(bluePrintRuntimeService, name, artifactType, validators) } + fun validateArtifactDefinition(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, + artifactDefinition: ArtifactDefinition) { + val validators = getArtifactDefinitionsValidators() + doValidation(bluePrintRuntimeService, name, artifactDefinition, validators) + } + fun validateDataType(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, dataType: DataType) { val validators = getDataTypeValidators() doValidation(bluePrintRuntimeService, name, dataType, validators) diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonUtils.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonUtils.kt index 76f3f329..1bc25005 100644 --- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonUtils.kt +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonUtils.kt @@ -19,7 +19,6 @@ package org.onap.ccsdk.apps.controllerblueprints.core.utils import com.att.eelf.configuration.EELFLogger import com.att.eelf.configuration.EELFManager import com.fasterxml.jackson.annotation.JsonInclude -import com.fasterxml.jackson.core.type.TypeReference import com.fasterxml.jackson.databind.JsonNode import com.fasterxml.jackson.databind.SerializationFeature import com.fasterxml.jackson.databind.node.ArrayNode @@ -148,22 +147,22 @@ class JacksonUtils { return objectMapper.valueToTree(any) } - fun <T> getListFromJsonNode(node: JsonNode, valueType: Class<T>): List<T>? { + fun <T> getListFromJsonNode(node: JsonNode, valueType: Class<T>): List<T> { return getListFromJson(node.toString(), valueType) } - fun <T> getListFromJson(content: String, valueType: Class<T>): List<T>? { + fun <T> getListFromJson(content: String, valueType: Class<T>): List<T> { val objectMapper = jacksonObjectMapper() val javaType = objectMapper.typeFactory.constructCollectionType(List::class.java, valueType) return objectMapper.readValue<List<T>>(content, javaType) } - fun <T> getListFromFile(fileName: String, valueType: Class<T>): List<T>? { + fun <T> getListFromFile(fileName: String, valueType: Class<T>): List<T> { val content: String = getContent(fileName) return getListFromJson(content, valueType) } - fun <T> getListFromClassPathFile(fileName: String, valueType: Class<T>): List<T>? { + fun <T> getListFromClassPathFile(fileName: String, valueType: Class<T>): List<T> { val content: String = getClassPathFileContent(fileName) return getListFromJson(content, valueType) } diff --git a/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintArtifactDefinitionValidatorImpl.kt b/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintArtifactDefinitionValidatorImpl.kt new file mode 100644 index 00000000..4ea5ab5b --- /dev/null +++ b/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintArtifactDefinitionValidatorImpl.kt @@ -0,0 +1,97 @@ +/* + * 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.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.ArtifactDefinition +import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintArtifactDefinitionValidator +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 +import org.springframework.beans.factory.config.ConfigurableBeanFactory +import org.springframework.context.annotation.Scope +import org.springframework.stereotype.Service +import java.io.File + +@Service("default-artifact-definition-validator") +@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) +open class BluePrintArtifactDefinitionValidatorImpl( + private val bluePrintTypeValidatorService: BluePrintTypeValidatorService) : BluePrintArtifactDefinitionValidator { + + private val log: EELFLogger = EELFManager.getInstance().getLogger(BluePrintArtifactDefinitionValidatorImpl::class.toString()) + + lateinit var bluePrintRuntimeService: BluePrintRuntimeService<*> + lateinit var bluePrintContext: BluePrintContext + var paths: MutableList<String> = arrayListOf() + + override fun validate(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, + artifactDefinition: ArtifactDefinition) { + + this.bluePrintRuntimeService = bluePrintRuntimeService + this.bluePrintContext = bluePrintRuntimeService.bluePrintContext() + + paths.add(name) + val type: String = artifactDefinition.type + log.info("Validation ArtifactDefinition of type {$type}") + // Check Artifact Type + checkValidArtifactType(name, type) + + val file: String = artifactDefinition.file + + val completePath = bluePrintContext.rootPath.plus(File.separator).plus(file) + + check(File(completePath).exists()) { + throw BluePrintException("couldn't file ($completePath)") + } + + // Perform Extension Validation + validateExtension("$type-artifact-definition-validator", name, artifactDefinition) + + paths.removeAt(paths.lastIndex) + } + + 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") + } + } + + private fun validateExtension(referencePrefix: String, name: String, artifactDefinition: ArtifactDefinition) { + + val customValidators = bluePrintTypeValidatorService + .bluePrintValidators(referencePrefix, BluePrintArtifactDefinitionValidator::class.java) + + customValidators?.let { + it.forEach { validator -> + validator.validate(bluePrintRuntimeService, name, artifactDefinition) + } + + } + } +}
\ No newline at end of file diff --git a/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintArtifactTypeValidatorImpl.kt b/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintArtifactTypeValidatorImpl.kt index b893c77d..4824d2e9 100644 --- a/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintArtifactTypeValidatorImpl.kt +++ b/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintArtifactTypeValidatorImpl.kt @@ -1,5 +1,6 @@ /* * 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. @@ -20,7 +21,9 @@ 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 +import org.springframework.stereotype.Service +@Service("default-artifact-type-validator") open class BluePrintArtifactTypeValidatorImpl(private val bluePrintTypeValidatorService: BluePrintTypeValidatorService) : BluePrintArtifactTypeValidator { override fun validate(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, artifactType: ArtifactType) { @@ -28,6 +31,5 @@ open class BluePrintArtifactTypeValidatorImpl(private val bluePrintTypeValidator artifactType.properties?.let { bluePrintTypeValidatorService.validatePropertyDefinitions(bluePrintRuntimeService, artifactType.properties!!) } - // TODO ("Files Present ") } }
\ No newline at end of file diff --git a/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintAttributeDefinitionValidatorImpl.kt b/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintAttributeDefinitionValidatorImpl.kt index 19e8f0bf..11dbf058 100644 --- a/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintAttributeDefinitionValidatorImpl.kt +++ b/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintAttributeDefinitionValidatorImpl.kt @@ -1,5 +1,6 @@ /* * 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. @@ -16,14 +17,72 @@ package org.onap.ccsdk.apps.controllerblueprints.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.AttributeDefinition +import org.onap.ccsdk.apps.controllerblueprints.core.format 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 +import org.springframework.beans.factory.config.ConfigurableBeanFactory +import org.springframework.context.annotation.Scope +import org.springframework.stereotype.Service +@Service("default-attribute-definition-validator") +@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) 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. + + private val log: EELFLogger = EELFManager.getInstance().getLogger(BluePrintServiceTemplateValidatorImpl::class.toString()) + + lateinit var bluePrintRuntimeService: BluePrintRuntimeService<*> + + + override fun validate(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, + attributeDefinition: AttributeDefinition) { + + log.trace("Validating AttributeDefinition($name)") + this.bluePrintRuntimeService = bluePrintRuntimeService + val dataType: String = attributeDefinition.type + + when { + BluePrintTypes.validPrimitiveTypes().contains(dataType) -> { + // Do Nothing + } + BluePrintTypes.validCollectionTypes().contains(dataType) -> { + val entrySchemaType: String = attributeDefinition.entrySchema?.type + ?: throw BluePrintException("Entry schema for DataType ($dataType) for the property ($name) not found") + 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("DataType($dataType) for the attribute($propertyName) is not valid") + } + } + + 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("Failed to get DataType($dataTypeName)'s derivedFrom($derivedFrom) definition ") + } } }
\ No newline at end of file diff --git a/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintDataTypeValidatorImpl.kt b/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintDataTypeValidatorImpl.kt index 6ee41774..1494bbc4 100644 --- a/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintDataTypeValidatorImpl.kt +++ b/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintDataTypeValidatorImpl.kt @@ -1,5 +1,6 @@ /* * 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. @@ -16,19 +17,16 @@ package org.onap.ccsdk.apps.controllerblueprints.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 +import org.springframework.stereotype.Service +@Service("default-data-type-validator") 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!!) diff --git a/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintValidatorServiceImpl.kt b/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintDesignTimeValidatorService.kt index 5620cb77..84073ff2 100644 --- a/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintValidatorServiceImpl.kt +++ b/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintDesignTimeValidatorService.kt @@ -1,5 +1,6 @@ /* * 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. @@ -23,12 +24,14 @@ import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintTypeVal 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 org.springframework.stereotype.Service import java.util.* -open class BluePrintValidatorServiceImpl(private val bluePrintTypeValidatorService: BluePrintTypeValidatorService) : BluePrintValidatorService { +@Service +open class BluePrintDesignTimeValidatorService(private val bluePrintTypeValidatorService: BluePrintTypeValidatorService) : BluePrintValidatorService { - private val log: EELFLogger = EELFManager.getInstance().getLogger(BluePrintValidatorServiceImpl::class.toString()) + private val log: EELFLogger = EELFManager.getInstance().getLogger(BluePrintDesignTimeValidatorService::class.toString()) override fun validateBluePrints(basePath: String): Boolean { diff --git a/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintNodeTemplateValidatorImpl.kt b/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintNodeTemplateValidatorImpl.kt index af0f88aa..ded1f384 100644 --- a/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintNodeTemplateValidatorImpl.kt +++ b/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintNodeTemplateValidatorImpl.kt @@ -1,5 +1,6 @@ /* * 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. @@ -29,8 +30,13 @@ 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 +import org.springframework.beans.factory.config.ConfigurableBeanFactory +import org.springframework.context.annotation.Scope +import org.springframework.stereotype.Service +@Service("default-node-template-validator") +@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) open class BluePrintNodeTemplateValidatorImpl(private val bluePrintTypeValidatorService: BluePrintTypeValidatorService) : BluePrintNodeTemplateValidator { private val log: EELFLogger = EELFManager.getInstance().getLogger(BluePrintNodeTemplateValidatorImpl::class.toString()) @@ -39,25 +45,28 @@ open class BluePrintNodeTemplateValidatorImpl(private val bluePrintTypeValidator lateinit var bluePrintContext: BluePrintContext var paths: MutableList<String> = arrayListOf() - override fun validate(bluePrintRuntimeService: BluePrintRuntimeService<*>, nodeTemplateName: String, nodeTemplate: NodeTemplate) { - log.info("Validating NodeTemplate($nodeTemplateName)") + override fun validate(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, nodeTemplate: NodeTemplate) { + log.info("Validating NodeTemplate($name)") this.bluePrintRuntimeService = bluePrintRuntimeService this.bluePrintContext = bluePrintRuntimeService.bluePrintContext() - paths.add(nodeTemplateName) + paths.add(name) val type: String = nodeTemplate.type val nodeType: NodeType = bluePrintContext.serviceTemplate.nodeTypes?.get(type) - ?: throw BluePrintException("Failed to get NodeType($type) definition for NodeTemplate($nodeTemplateName)") + ?: throw BluePrintException("Failed to get NodeType($type) definition for NodeTemplate($name)") 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.capabilities?.let { validateCapabilityAssignments(nodeType, name, nodeTemplate) } + nodeTemplate.requirements?.let { validateRequirementAssignments(nodeType, name, nodeTemplate) } + nodeTemplate.interfaces?.let { validateInterfaceAssignments(nodeType, name, nodeTemplate) } nodeTemplate.artifacts?.let { validateArtifactDefinitions(nodeTemplate.artifacts!!) } + // Perform Extension Validation + validateExtension("$type-node-template-validator", name, nodeTemplate) + paths.removeAt(paths.lastIndex) } @@ -65,16 +74,8 @@ open class BluePrintNodeTemplateValidatorImpl(private val bluePrintTypeValidator 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) + bluePrintTypeValidatorService.validateArtifactDefinition(bluePrintRuntimeService, + artifactDefinitionName, artifactDefinition) } paths.removeAt(paths.lastIndex) } @@ -239,21 +240,6 @@ open class BluePrintNodeTemplateValidatorImpl(private val bluePrintTypeValidator } - 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 @@ -295,4 +281,13 @@ open class BluePrintNodeTemplateValidatorImpl(private val bluePrintTypeValidator } } + private fun validateExtension(referencePrefix: String, name: String, nodeTemplate: NodeTemplate) { + val customValidator = bluePrintTypeValidatorService + .bluePrintValidator(referencePrefix, BluePrintNodeTemplateValidator::class.java) + + customValidator?.let { + it.validate(bluePrintRuntimeService, name, nodeTemplate) + } + } + }
\ No newline at end of file diff --git a/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintNodeTypeValidatorImpl.kt b/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintNodeTypeValidatorImpl.kt index eb2f0102..1108c1b5 100644 --- a/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintNodeTypeValidatorImpl.kt +++ b/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintNodeTypeValidatorImpl.kt @@ -1,5 +1,6 @@ /* * 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. @@ -26,8 +27,13 @@ import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintNodeTyp 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 +import org.springframework.beans.factory.config.ConfigurableBeanFactory +import org.springframework.context.annotation.Scope +import org.springframework.stereotype.Service +@Service("default-node-type-validator") +@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) open class BluePrintNodeTypeValidatorImpl(private val bluePrintTypeValidatorService: BluePrintTypeValidatorService) : BluePrintNodeTypeValidator { private val log: EELFLogger = EELFManager.getInstance().getLogger(BluePrintServiceTemplateValidatorImpl::class.toString()) @@ -52,7 +58,14 @@ open class BluePrintNodeTypeValidatorImpl(private val bluePrintTypeValidatorServ ?: throw BluePrintException("Failed to get derivedFrom NodeType($derivedFrom)'s for NodeType($nodeTypeName)") } - nodeType.properties?.let { bluePrintTypeValidatorService.validatePropertyDefinitions(bluePrintRuntimeService, nodeType.properties!!) } + nodeType.attributes?.let { + bluePrintTypeValidatorService.validateAttributeDefinitions(bluePrintRuntimeService, nodeType.attributes!!) + } + + 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!!) } diff --git a/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintPropertyDefinitionValidatorImpl.kt b/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintPropertyDefinitionValidatorImpl.kt index 2f328716..7d81ba62 100644 --- a/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintPropertyDefinitionValidatorImpl.kt +++ b/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintPropertyDefinitionValidatorImpl.kt @@ -1,5 +1,6 @@ /* * 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. @@ -25,7 +26,12 @@ 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 +import org.springframework.beans.factory.config.ConfigurableBeanFactory +import org.springframework.context.annotation.Scope +import org.springframework.stereotype.Service +@Service("default-property-definition-validator") +@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) open class BluePrintPropertyDefinitionValidatorImpl(private val bluePrintTypeValidatorService: BluePrintTypeValidatorService) : BluePrintPropertyDefinitionValidator { private val log: EELFLogger = EELFManager.getInstance().getLogger(BluePrintServiceTemplateValidatorImpl::class.toString()) diff --git a/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintServiceTemplateValidatorImpl.kt b/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintServiceTemplateValidatorImpl.kt index 8d49f291..37d3d1bd 100644 --- a/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintServiceTemplateValidatorImpl.kt +++ b/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintServiceTemplateValidatorImpl.kt @@ -26,7 +26,12 @@ 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 +import org.springframework.beans.factory.config.ConfigurableBeanFactory +import org.springframework.context.annotation.Scope +import org.springframework.stereotype.Service +@Service("default-service-template-validator") +@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) open class BluePrintServiceTemplateValidatorImpl(private val bluePrintTypeValidatorService: BluePrintTypeValidatorService) : BluePrintServiceTemplateValidator { private val log: EELFLogger = EELFManager.getInstance().getLogger(BluePrintServiceTemplateValidatorImpl::class.toString()) diff --git a/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintTopologyTemplateValidatorImpl.kt b/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintTopologyTemplateValidatorImpl.kt index 9f9ad1fa..841d86ea 100644 --- a/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintTopologyTemplateValidatorImpl.kt +++ b/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintTopologyTemplateValidatorImpl.kt @@ -1,5 +1,6 @@ /* * 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. @@ -26,7 +27,12 @@ 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 +import org.springframework.beans.factory.config.ConfigurableBeanFactory +import org.springframework.context.annotation.Scope +import org.springframework.stereotype.Service +@Service("default-topology-template-validator") +@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) open class BluePrintTopologyTemplateValidatorImpl(private val bluePrintTypeValidatorService: BluePrintTypeValidatorService) : BluePrintTopologyTemplateValidator { private val log: EELFLogger = EELFManager.getInstance().getLogger(BluePrintServiceTemplateValidatorImpl::class.toString()) diff --git a/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintTypeValidatorServiceImpl.kt b/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintTypeValidatorServiceImpl.kt index e9bfc613..d8c008ff 100644 --- a/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintTypeValidatorServiceImpl.kt +++ b/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintTypeValidatorServiceImpl.kt @@ -1,5 +1,6 @@ /* * 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. @@ -16,6 +17,7 @@ package org.onap.ccsdk.apps.controllerblueprints.validation +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.* import org.springframework.beans.factory.annotation.Autowired import org.springframework.context.ApplicationContext @@ -24,43 +26,79 @@ import org.springframework.stereotype.Service @Service class BluePrintTypeValidatorServiceImpl : BluePrintTypeValidatorService { + companion object { + const val PREFIX_DEFAULT = "default" + } + @Autowired private lateinit var context: ApplicationContext + override fun <T : BluePrintValidator<*>> bluePrintValidator(referenceName: String, classType: Class<T>): T? { + return if (context.containsBean(referenceName)) { + context.getBean(referenceName, classType) + } else { + null + } + } + + override fun <T : BluePrintValidator<*>> bluePrintValidators(referenceNamePrefix: String, classType: Class<T>): List<T>? { + return context.getBeansOfType(classType) + .filter { it.key.startsWith(referenceNamePrefix) } + .mapNotNull { it.value } + } + + override fun <T : BluePrintValidator<*>> bluePrintValidators(classType: Class<T>): List<T>? { + return context.getBeansOfType(classType).mapNotNull { it.value } + } + override fun getServiceTemplateValidators(): List<BluePrintServiceTemplateValidator> { - return context.getBeansOfType(BluePrintServiceTemplateValidator::class.java).mapNotNull { it.value } + return bluePrintValidators(PREFIX_DEFAULT, BluePrintServiceTemplateValidator::class.java) + ?: throw BluePrintProcessorException("failed to get default ServiceTemplate validators") } override fun getDataTypeValidators(): List<BluePrintDataTypeValidator> { - return context.getBeansOfType(BluePrintDataTypeValidator::class.java).mapNotNull { it.value } + return bluePrintValidators(PREFIX_DEFAULT, BluePrintDataTypeValidator::class.java) + ?: throw BluePrintProcessorException("failed to get default DataType validators") } override fun getArtifactTypeValidators(): List<BluePrintArtifactTypeValidator> { - return context.getBeansOfType(BluePrintArtifactTypeValidator::class.java).mapNotNull { it.value } + return bluePrintValidators(PREFIX_DEFAULT, BluePrintArtifactTypeValidator::class.java) + ?: throw BluePrintProcessorException("failed to get default ArtifactType validators") + } + + override fun getArtifactDefinitionsValidators(): List<BluePrintArtifactDefinitionValidator> { + return bluePrintValidators(PREFIX_DEFAULT, BluePrintArtifactDefinitionValidator::class.java) + ?: throw BluePrintProcessorException("failed to get default ArtifactDefinition validators") } override fun getNodeTypeValidators(): List<BluePrintNodeTypeValidator> { - return context.getBeansOfType(BluePrintNodeTypeValidator::class.java).mapNotNull { it.value } + return bluePrintValidators(PREFIX_DEFAULT, BluePrintNodeTypeValidator::class.java) + ?: throw BluePrintProcessorException("failed to get default NodeType validators") } override fun getTopologyTemplateValidators(): List<BluePrintTopologyTemplateValidator> { - return context.getBeansOfType(BluePrintTopologyTemplateValidator::class.java).mapNotNull { it.value } + return bluePrintValidators(PREFIX_DEFAULT, BluePrintTopologyTemplateValidator::class.java) + ?: throw BluePrintProcessorException("failed to get default TopologyTemplate validators") } override fun getNodeTemplateValidators(): List<BluePrintNodeTemplateValidator> { - return context.getBeansOfType(BluePrintNodeTemplateValidator::class.java).mapNotNull { it.value } + return bluePrintValidators(PREFIX_DEFAULT, BluePrintNodeTemplateValidator::class.java) + ?: throw BluePrintProcessorException("failed to get default NodeTemplate validators") } override fun getWorkflowValidators(): List<BluePrintWorkflowValidator> { - return context.getBeansOfType(BluePrintWorkflowValidator::class.java).mapNotNull { it.value } + return bluePrintValidators(PREFIX_DEFAULT, BluePrintWorkflowValidator::class.java) + ?: throw BluePrintProcessorException("failed to get default Workflow validators") } override fun getPropertyDefinitionValidators(): List<BluePrintPropertyDefinitionValidator> { - return context.getBeansOfType(BluePrintPropertyDefinitionValidator::class.java).mapNotNull { it.value } + return bluePrintValidators(PREFIX_DEFAULT, BluePrintPropertyDefinitionValidator::class.java) + ?: throw BluePrintProcessorException("failed to get default PropertyDefinition validators") } override fun getAttributeDefinitionValidators(): List<BluePrintAttributeDefinitionValidator> { - return context.getBeansOfType(BluePrintAttributeDefinitionValidator::class.java).mapNotNull { it.value } + return bluePrintValidators(PREFIX_DEFAULT, BluePrintAttributeDefinitionValidator::class.java) + ?: throw BluePrintProcessorException("failed to get default AttributeDefinition validators") } } diff --git a/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintValidatorDefaultService.kt b/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintValidatorDefaultService.kt deleted file mode 100644 index 8e26588b..00000000 --- a/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintValidatorDefaultService.kt +++ /dev/null @@ -1,92 +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. - */ - -@file:Suppress("unused") -package org.onap.ccsdk.apps.controllerblueprints.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 org.springframework.stereotype.Service -import java.util.* - -@Service -class BluePrintTypeValidatorDefaultService(private val bluePrintTypeValidatorService: BluePrintTypeValidatorService) - : BluePrintValidatorService { - - private val log: EELFLogger = EELFManager.getInstance().getLogger(BluePrintValidatorServiceImpl::class.toString()) - - override fun validateBluePrints(basePath: String): Boolean { - - log.info("validating blueprint($basePath)") - 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 - } -} - -// Core Validator Services - -@Service -class DefaultBluePrintServiceTemplateValidator(bluePrintTypeValidatorService: BluePrintTypeValidatorService) - : BluePrintServiceTemplateValidatorImpl(bluePrintTypeValidatorService) - -@Service -class DefaultBluePrintDataTypeValidator(bluePrintTypeValidatorService: BluePrintTypeValidatorService) - : BluePrintDataTypeValidatorImpl(bluePrintTypeValidatorService) - -@Service -class DefaultBluePrintArtifactTypeValidator(bluePrintTypeValidatorService: BluePrintTypeValidatorService) - : BluePrintArtifactTypeValidatorImpl(bluePrintTypeValidatorService) - -@Service -class DefaultBluePrintNodeTypeValidator(bluePrintTypeValidatorService: BluePrintTypeValidatorService) - : BluePrintNodeTypeValidatorImpl(bluePrintTypeValidatorService) - -@Service -class DefaultBluePrintTopologyTemplateValidator(bluePrintTypeValidatorService: BluePrintTypeValidatorService) - : BluePrintTopologyTemplateValidatorImpl(bluePrintTypeValidatorService) - -@Service -class DefaulBluePrintNodeTemplateValidator(bluePrintTypeValidatorService: BluePrintTypeValidatorService) - : BluePrintNodeTemplateValidatorImpl(bluePrintTypeValidatorService) - -@Service -class DefaultBluePrintWorkflowValidator(bluePrintTypeValidatorService: BluePrintTypeValidatorService) - : BluePrintWorkflowValidatorImpl(bluePrintTypeValidatorService) - -@Service -class DefaultBluePrintPropertyDefinitionValidator(bluePrintTypeValidatorService: BluePrintTypeValidatorService) - : BluePrintPropertyDefinitionValidatorImpl(bluePrintTypeValidatorService) - -@Service -class DefaultBluePrintAttributeDefinitionValidator(bluePrintTypeValidatorService: BluePrintTypeValidatorService) - : BluePrintAttributeDefinitionValidatorImpl(bluePrintTypeValidatorService)
\ No newline at end of file diff --git a/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintWorkflowValidatorImpl.kt b/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintWorkflowValidatorImpl.kt index 612ec691..851a7c60 100644 --- a/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintWorkflowValidatorImpl.kt +++ b/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintWorkflowValidatorImpl.kt @@ -23,7 +23,12 @@ 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 +import org.springframework.beans.factory.config.ConfigurableBeanFactory +import org.springframework.context.annotation.Scope +import org.springframework.stereotype.Service +@Service("default-workflow-validator") +@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) open class BluePrintWorkflowValidatorImpl(private val bluePrintTypeValidatorService: BluePrintTypeValidatorService) : BluePrintWorkflowValidator { private val log: EELFLogger = EELFManager.getInstance().getLogger(BluePrintServiceTemplateValidatorImpl::class.toString()) diff --git a/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/extension/ArtifactMappingResourceValidator.kt b/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/extension/ArtifactMappingResourceValidator.kt new file mode 100644 index 00000000..6fe4fa36 --- /dev/null +++ b/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/extension/ArtifactMappingResourceValidator.kt @@ -0,0 +1,48 @@ +/* + * 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.validation.extension + +import com.att.eelf.configuration.EELFLogger +import com.att.eelf.configuration.EELFManager +import org.onap.ccsdk.apps.controllerblueprints.core.data.ArtifactDefinition +import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintArtifactDefinitionValidator +import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintTypeValidatorService +import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService +import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.service.ResourceAssignmentValidationServiceImpl +import org.springframework.stereotype.Service +import java.io.File + +@Service("artifact-mapping-resource-artifact-definition-validator") +open class ArtifactMappingResourceValidator(private val bluePrintTypeValidatorService: BluePrintTypeValidatorService) + : BluePrintArtifactDefinitionValidator { + + private val log: EELFLogger = EELFManager.getInstance().getLogger(ArtifactMappingResourceValidator::class.toString()) + + override fun validate(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, + artifactDefinition: ArtifactDefinition) { + + val bluePrintContext = bluePrintRuntimeService.bluePrintContext() + val file: String = artifactDefinition.file + val completePath = bluePrintContext.rootPath.plus(File.separator).plus(file) + log.info("Validation artifact-mapping-resource($completePath)") + val resourceAssignment = JacksonUtils.getListFromFile(completePath, ResourceAssignment::class.java) + val resourceAssignmentValidationService = ResourceAssignmentValidationServiceImpl() + resourceAssignmentValidationService.validate(resourceAssignment) + } +}
\ No newline at end of file diff --git a/ms/controllerblueprints/modules/blueprint-validation/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintValidatorServiceImplTest.kt b/ms/controllerblueprints/modules/blueprint-validation/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintDesignTimeValidatorServiceTest.kt index f5d157dd..43c3e0e3 100644 --- a/ms/controllerblueprints/modules/blueprint-validation/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintValidatorServiceImplTest.kt +++ b/ms/controllerblueprints/modules/blueprint-validation/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintDesignTimeValidatorServiceTest.kt @@ -30,12 +30,12 @@ import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintMetadataUtil import kotlin.test.assertEquals import kotlin.test.assertTrue -class BluePrintValidatorServiceImplTest { +class BluePrintDesignTimeValidatorServiceTest { private val blueprintBasePath: String = ("./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration") private val bluePrintRuntime = BluePrintMetadataUtils.getBluePrintRuntime("1234", blueprintBasePath) private val mockBluePrintTypeValidatorService = MockBluePrintTypeValidatorService() - private val defaultBluePrintValidatorService = BluePrintValidatorServiceImpl(mockBluePrintTypeValidatorService) + private val defaultBluePrintValidatorService = BluePrintDesignTimeValidatorService(mockBluePrintTypeValidatorService) private val workflowValidator = BluePrintWorkflowValidatorImpl(mockBluePrintTypeValidatorService) @Test diff --git a/ms/controllerblueprints/modules/blueprint-validation/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/MockBluePrintTypeValidatorService.kt b/ms/controllerblueprints/modules/blueprint-validation/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/MockBluePrintTypeValidatorService.kt index 971099ca..65574c22 100644 --- a/ms/controllerblueprints/modules/blueprint-validation/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/MockBluePrintTypeValidatorService.kt +++ b/ms/controllerblueprints/modules/blueprint-validation/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/MockBluePrintTypeValidatorService.kt @@ -1,5 +1,6 @@ /* * 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. @@ -20,6 +21,18 @@ import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.* class MockBluePrintTypeValidatorService : BluePrintTypeValidatorService { + override fun <T : BluePrintValidator<*>> bluePrintValidator(referenceName: String, classType: Class<T>): T? { + return null + } + + override fun <T : BluePrintValidator<*>> bluePrintValidators(referenceNamePrefix: String, classType: Class<T>): List<T>? { + return null + } + + override fun <T : BluePrintValidator<*>> bluePrintValidators(classType: Class<T>): List<T>? { + return null + } + override fun getServiceTemplateValidators(): List<BluePrintServiceTemplateValidator> { return listOf(BluePrintServiceTemplateValidatorImpl(this)) } @@ -32,6 +45,10 @@ class MockBluePrintTypeValidatorService : BluePrintTypeValidatorService { return listOf(BluePrintArtifactTypeValidatorImpl(this)) } + override fun getArtifactDefinitionsValidators(): List<BluePrintArtifactDefinitionValidator> { + return listOf(BluePrintArtifactDefinitionValidatorImpl(this)) + } + override fun getNodeTypeValidators(): List<BluePrintNodeTypeValidator> { return listOf(BluePrintNodeTypeValidatorImpl(this)) } diff --git a/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintEnhancerServiceImplTest.kt b/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintEnhancerServiceImplTest.kt index 8d32413f..ccacee02 100644 --- a/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintEnhancerServiceImplTest.kt +++ b/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintEnhancerServiceImplTest.kt @@ -1,5 +1,6 @@ /* * 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. @@ -38,22 +39,22 @@ import java.nio.file.Paths class BluePrintEnhancerServiceImplTest { @Autowired - private val modelTypeLoadService: ModelTypeLoadService? = null + lateinit var modelTypeLoadService: ModelTypeLoadService @Autowired - private val resourceDictionaryLoadService: ResourceDictionaryLoadService? = null + lateinit var resourceDictionaryLoadService: ResourceDictionaryLoadService @Autowired - private val bluePrintEnhancerService: BluePrintEnhancerService? = null + lateinit var bluePrintEnhancerService: BluePrintEnhancerService @Autowired - private val bluePrintValidatorService: BluePrintValidatorService? = null + lateinit var bluePrintValidatorService: BluePrintValidatorService @Before fun init() { runBlocking { - modelTypeLoadService!!.loadPathModelType("./../../../../components/model-catalog/definition-type/starter-type") - resourceDictionaryLoadService!!.loadPathResourceDictionary("./../../../../components/model-catalog/resource-dictionary/starter-dictionary") + modelTypeLoadService.loadPathModelType("./../../../../components/model-catalog/definition-type/starter-type") + resourceDictionaryLoadService.loadPathResourceDictionary("./../../../../components/model-catalog/resource-dictionary/starter-dictionary") } } @@ -65,11 +66,11 @@ class BluePrintEnhancerServiceImplTest { val targetPath = Paths.get("target", "bp-enhance").toUri().path - val bluePrintContext = bluePrintEnhancerService!!.enhance(basePath, targetPath) + val bluePrintContext = bluePrintEnhancerService.enhance(basePath, targetPath) Assert.assertNotNull("failed to get blueprintContext ", bluePrintContext) // Validate the Generated BluePrints - val valid = bluePrintValidatorService!!.validateBluePrints(targetPath) + val valid = bluePrintValidatorService.validateBluePrints(targetPath) Assert.assertTrue("blueprint validation failed ", valid) } }
\ No newline at end of file |