diff options
Diffstat (limited to 'ms/controllerblueprints/modules/blueprint-validation')
7 files changed, 111 insertions, 4 deletions
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 index 8072f283c..a3625e401 100644 --- 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 @@ -49,7 +49,7 @@ open class BluePrintArtifactDefinitionValidatorImpl( paths.add(name) val type: String = artifactDefinition.type - log.info("Validation ArtifactDefinition of type {$type}") + log.trace("Validation ArtifactDefinition of type {$type}") // Check Artifact Type checkValidArtifactType(name, type) diff --git a/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintDesignTimeValidatorService.kt b/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintDesignTimeValidatorService.kt index 84073ff2e..c89857742 100644 --- a/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintDesignTimeValidatorService.kt +++ b/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintDesignTimeValidatorService.kt @@ -19,17 +19,25 @@ 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.BluePrintConstants 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.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDictionaryConstants +import org.onap.ccsdk.apps.controllerblueprints.validation.extension.ResourceDefinitionValidator import org.springframework.stereotype.Service +import java.io.File import java.util.* @Service -open class BluePrintDesignTimeValidatorService(private val bluePrintTypeValidatorService: BluePrintTypeValidatorService) : BluePrintValidatorService { +open class BluePrintDesignTimeValidatorService(private val bluePrintTypeValidatorService: BluePrintTypeValidatorService, + private val resourceDefinitionValidator: ResourceDefinitionValidator) + : BluePrintValidatorService { private val log: EELFLogger = EELFManager.getInstance().getLogger(BluePrintDesignTimeValidatorService::class.toString()) @@ -43,9 +51,32 @@ open class BluePrintDesignTimeValidatorService(private val bluePrintTypeValidato bluePrintTypeValidatorService.validateServiceTemplate(bluePrintRuntimeService, "service_template", bluePrintRuntimeService.bluePrintContext().serviceTemplate) + + // Validate Resource Definitions + validateResourceDefinitions(bluePrintRuntimeService) + if (bluePrintRuntimeService.getBluePrintError().errors.size > 0) { throw BluePrintException("failed in blueprint validation : ${bluePrintRuntimeService.getBluePrintError().errors.joinToString("\n")}") } return true } + + private fun validateResourceDefinitions(bluePrintRuntimeService: BluePrintRuntimeService<*>) { + // Validate Resource Dictionary + val blueprintBasePath = bluePrintRuntimeService.bluePrintContext().rootPath + + val resourceDefinitionsPath = blueprintBasePath.plus(File.separator) + .plus(BluePrintConstants.TOSCA_DEFINITIONS_DIR).plus(File.separator) + .plus("${ResourceDictionaryConstants.PATH_RESOURCE_DEFINITION_TYPE}.json") + + val resourceDefinitionFile = File(resourceDefinitionsPath) + + if (resourceDefinitionFile.exists()) { + val resourceDefinitionMap = JacksonUtils.getMapFromFile(resourceDefinitionFile, ResourceDefinition::class.java) + + resourceDefinitionMap?.forEach { resourceDefinitionName, resourceDefinition -> + resourceDefinitionValidator.validate(bluePrintRuntimeService, resourceDefinitionName, resourceDefinition) + } + } + } } 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 7d81ba620..62a82286e 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 @@ -51,6 +51,9 @@ open class BluePrintPropertyDefinitionValidatorImpl(private val bluePrintTypeVal BluePrintTypes.validPrimitiveTypes().contains(dataType) -> { // Do Nothing } + BluePrintTypes.validComplexTypes().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)) diff --git a/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintValidationConfiguration.kt b/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintValidationConfiguration.kt new file mode 100644 index 000000000..bad147915 --- /dev/null +++ b/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintValidationConfiguration.kt @@ -0,0 +1,24 @@ +/* + * Copyright © 2019 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 org.springframework.context.annotation.ComponentScan +import org.springframework.context.annotation.Configuration + +@Configuration +@ComponentScan +open class BluePrintValidationConfiguration
\ No newline at end of file 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 index 6fe4fa36e..002dd9fbd 100644 --- 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 @@ -40,7 +40,7 @@ open class ArtifactMappingResourceValidator(private val bluePrintTypeValidatorSe 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)") + log.trace("Validation artifact-mapping-resource($completePath)") val resourceAssignment = JacksonUtils.getListFromFile(completePath, ResourceAssignment::class.java) val resourceAssignmentValidationService = ResourceAssignmentValidationServiceImpl() resourceAssignmentValidationService.validate(resourceAssignment) diff --git a/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/extension/ResourceDefinitionValidation.kt b/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/extension/ResourceDefinitionValidation.kt new file mode 100644 index 000000000..6975ec619 --- /dev/null +++ b/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/extension/ResourceDefinitionValidation.kt @@ -0,0 +1,44 @@ +/* + * Copyright © 2019 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.interfaces.BluePrintTypeValidatorService +import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintValidator +import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition +import org.springframework.beans.factory.config.ConfigurableBeanFactory +import org.springframework.context.annotation.Scope +import org.springframework.stereotype.Service + +interface ResourceDefinitionValidator : BluePrintValidator<ResourceDefinition> + +@Service +@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) +open class ResourceDefinitionValidatorImpl(private val bluePrintTypeValidatorService: BluePrintTypeValidatorService) : ResourceDefinitionValidator { + + private val log: EELFLogger = EELFManager.getInstance().getLogger(ResourceDefinitionValidatorImpl::class.java) + + override fun validate(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, + resourceDefinition: ResourceDefinition) { + log.trace("validating resource definition($name)") + resourceDefinition.sources.forEach { name, nodeTemplate -> + bluePrintTypeValidatorService.validateNodeTemplate(bluePrintRuntimeService, name, nodeTemplate) + } + } +}
\ No newline at end of file diff --git a/ms/controllerblueprints/modules/blueprint-validation/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintDesignTimeValidatorServiceTest.kt b/ms/controllerblueprints/modules/blueprint-validation/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintDesignTimeValidatorServiceTest.kt index 43c3e0e3e..3fc918e60 100644 --- a/ms/controllerblueprints/modules/blueprint-validation/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintDesignTimeValidatorServiceTest.kt +++ b/ms/controllerblueprints/modules/blueprint-validation/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintDesignTimeValidatorServiceTest.kt @@ -1,5 +1,6 @@ /* * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2019 IBM. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,6 +28,7 @@ import org.onap.ccsdk.apps.controllerblueprints.core.data.Workflow 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 org.onap.ccsdk.apps.controllerblueprints.validation.extension.ResourceDefinitionValidator import kotlin.test.assertEquals import kotlin.test.assertTrue @@ -35,11 +37,14 @@ 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 = BluePrintDesignTimeValidatorService(mockBluePrintTypeValidatorService) + private val resourceDefinitionValidator = mockk<ResourceDefinitionValidator>() + private val defaultBluePrintValidatorService = BluePrintDesignTimeValidatorService(mockBluePrintTypeValidatorService, resourceDefinitionValidator) private val workflowValidator = BluePrintWorkflowValidatorImpl(mockBluePrintTypeValidatorService) @Test fun testValidateOfType() { + every { resourceDefinitionValidator.validate(bluePrintRuntime, any(), any()) } returns Unit + val valid = defaultBluePrintValidatorService.validateBluePrints(bluePrintRuntime) assertTrue(valid, "failed in blueprint Validation") } |