diff options
Diffstat (limited to 'ms/controllerblueprints')
28 files changed, 232 insertions, 591 deletions
diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintTypes.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintTypes.kt index b2f1b727..cf400fa7 100644 --- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintTypes.kt +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintTypes.kt @@ -98,16 +98,9 @@ object BluePrintTypes { @JvmStatic fun validPropertyTypes(): List<String> { val validTypes: MutableList<String> = arrayListOf() - validTypes.add(BluePrintConstants.DATA_TYPE_STRING) - validTypes.add(BluePrintConstants.DATA_TYPE_INTEGER) - validTypes.add(BluePrintConstants.DATA_TYPE_FLOAT) - validTypes.add(BluePrintConstants.DATA_TYPE_DOUBLE) - validTypes.add(BluePrintConstants.DATA_TYPE_BOOLEAN) - validTypes.add(BluePrintConstants.DATA_TYPE_TIMESTAMP) - validTypes.add(BluePrintConstants.DATA_TYPE_NULL) - validTypes.add(BluePrintConstants.DATA_TYPE_LIST) - validTypes.add(BluePrintConstants.DATA_TYPE_MAP) - validTypes.add(BluePrintConstants.DATA_TYPE_JSON) + validTypes.addAll(validPrimitiveTypes()) + validTypes.addAll(validComplexTypes()) + validTypes.addAll(validCollectionTypes()) return validTypes } @@ -125,6 +118,13 @@ object BluePrintTypes { } @JvmStatic + fun validComplexTypes(): List<String> { + val validTypes: MutableList<String> = arrayListOf() + validTypes.add(BluePrintConstants.DATA_TYPE_JSON) + return validTypes + } + + @JvmStatic fun validCollectionTypes(): List<String> { val validTypes: MutableList<String> = arrayListOf() validTypes.add(BluePrintConstants.DATA_TYPE_LIST) diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/factory/BluePrintValidatorFactory.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/factory/BluePrintValidatorFactory.kt deleted file mode 100644 index 687b86cd..00000000 --- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/factory/BluePrintValidatorFactory.kt +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.apps.controllerblueprints.core.factory - - -import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintValidatorDefaultService -import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintValidatorService - -/** - * - * - * @author Brinda Santh - */ - -object BluePrintValidatorFactory { - - var bluePrintValidatorServices: MutableMap<String, BluePrintValidatorService> = HashMap() - - init { - bluePrintValidatorServices[org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.TYPE_DEFAULT] = BluePrintValidatorDefaultService() - } - - fun register(key:String, bluePrintValidatorService: BluePrintValidatorService){ - bluePrintValidatorServices[key] = bluePrintValidatorService - } - - fun instance(key : String) : BluePrintValidatorService?{ - return bluePrintValidatorServices[key] - } - -}
\ No newline at end of file diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRuntimeService.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRuntimeService.kt index 80ad3f2a..c5828073 100644 --- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRuntimeService.kt +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRuntimeService.kt @@ -29,7 +29,6 @@ import org.onap.ccsdk.apps.controllerblueprints.core.data.ArtifactDefinition 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.utils.BluePrintMetadataUtils -import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils import java.io.File interface BluePrintRuntimeService<T> { @@ -234,7 +233,7 @@ open class DefaultBluePrintRuntimeService(private var id: String, private var bl } else { // Assign default value to the Operation nodeTypeProperty.defaultValue?.let { - resolvedValue = JacksonUtils.jsonNodeFromObject(nodeTypeProperty.defaultValue!!) + resolvedValue = nodeTypeProperty.defaultValue!! } } // Set for Return of method diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintValidatorService.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintValidatorService.kt index 9ee53146..06602a17 100644 --- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintValidatorService.kt +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintValidatorService.kt @@ -41,6 +41,7 @@ interface BluePrintValidatorService : Serializable { fun validateBlueprint(serviceTemplate: ServiceTemplate, properties: MutableMap<String, Any>) } +@Deprecated("Decomposed implementation moved to blueprint-validation module") open class BluePrintValidatorDefaultService : BluePrintValidatorService { val log: EELFLogger = EELFManager.getInstance().getLogger(BluePrintValidatorDefaultService::class.toString()) diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintMetadataUtils.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintMetadataUtils.kt index fa5e1647..c34a769e 100644 --- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintMetadataUtils.kt +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintMetadataUtils.kt @@ -97,12 +97,9 @@ class BluePrintMetadataUtils { val bluePrintContext: BluePrintContext = getBluePrintContext(blueprintBasePath) - val context: MutableMap<String, JsonNode> = hashMapOf() - context[BluePrintConstants.PROPERTY_BLUEPRINT_BASE_PATH] = blueprintBasePath.asJsonPrimitive() - context[BluePrintConstants.PROPERTY_BLUEPRINT_PROCESS_ID] = id.asJsonPrimitive() - val bluePrintRuntimeService = DefaultBluePrintRuntimeService(id, bluePrintContext) - bluePrintRuntimeService.setExecutionContext(context) + bluePrintRuntimeService.put(BluePrintConstants.PROPERTY_BLUEPRINT_BASE_PATH, blueprintBasePath.asJsonPrimitive()) + bluePrintRuntimeService.put(BluePrintConstants.PROPERTY_BLUEPRINT_PROCESS_ID, id.asJsonPrimitive()) return bluePrintRuntimeService } @@ -110,12 +107,10 @@ class BluePrintMetadataUtils { fun getBaseEnhancementBluePrintRuntime(id: String, blueprintBasePath: String): BluePrintRuntimeService<MutableMap<String, JsonNode>> { val bluePrintContext: BluePrintContext = getBaseEnhancementBluePrintContext(blueprintBasePath) - val context: MutableMap<String, JsonNode> = hashMapOf() - context[BluePrintConstants.PROPERTY_BLUEPRINT_BASE_PATH] = blueprintBasePath.asJsonPrimitive() - context[BluePrintConstants.PROPERTY_BLUEPRINT_PROCESS_ID] = id.asJsonPrimitive() val bluePrintRuntimeService = DefaultBluePrintRuntimeService(id, bluePrintContext) - bluePrintRuntimeService.setExecutionContext(context) + bluePrintRuntimeService.put(BluePrintConstants.PROPERTY_BLUEPRINT_BASE_PATH, blueprintBasePath.asJsonPrimitive()) + bluePrintRuntimeService.put(BluePrintConstants.PROPERTY_BLUEPRINT_PROCESS_ID, id.asJsonPrimitive()) return bluePrintRuntimeService } @@ -123,6 +118,10 @@ class BluePrintMetadataUtils { fun getBluePrintRuntime(id: String, blueprintBasePath: String, executionContext: MutableMap<String, JsonNode>): BluePrintRuntimeService<MutableMap<String, JsonNode>> { val bluePrintContext: BluePrintContext = getBluePrintContext(blueprintBasePath) val bluePrintRuntimeService = DefaultBluePrintRuntimeService(id, bluePrintContext) + executionContext.forEach{ + bluePrintRuntimeService.put(it.key,it.value) + } + bluePrintRuntimeService.setExecutionContext(executionContext) return bluePrintRuntimeService } 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 1bc25005..932f0edc 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 @@ -68,12 +68,14 @@ class JacksonUtils { } } - fun getContent(fileName: String): String = runBlocking { + fun getContent(fileName: String): String = getContent(File(fileName)) + + fun getContent(file: File): String = runBlocking { async { try { - File(fileName).readText(Charsets.UTF_8) + file.readText(Charsets.UTF_8) } catch (e: Exception) { - throw BluePrintException("couldn't get file ($fileName) content : ${e.message}") + throw BluePrintException("couldn't get file (${file.absolutePath}) content : ${e.message}") } }.await() } @@ -167,17 +169,19 @@ class JacksonUtils { return getListFromJson(content, valueType) } - fun <T> getMapFromJson(content: String, valueType: Class<T>): MutableMap<String, T>? { + fun <T> getMapFromJson(content: String, valueType: Class<T>): MutableMap<String, T> { val objectMapper = jacksonObjectMapper() val mapType = objectMapper.typeFactory.constructMapType(Map::class.java, String::class.java, valueType) return objectMapper.readValue(content, mapType) } - fun <T> getMapFromFile(fileName: String, valueType: Class<T>): MutableMap<String, T>? { - val content: String = getContent(fileName) + fun <T> getMapFromFile(file: File, valueType: Class<T>): MutableMap<String, T> { + val content: String = getContent(file) return getMapFromJson(content, valueType) } + fun <T> getMapFromFile(fileName: String, valueType: Class<T>): MutableMap<String, T> = getMapFromFile(File(fileName), valueType) + fun <T> getInstanceFromMap(properties: MutableMap<String, JsonNode>, classType: Class<T>): T { return readValue(getJson(properties), classType) ?: throw BluePrintProcessorException("failed to transform content ($properties) to type ($classType)") diff --git a/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintValidatorDefaultServiceTest.kt b/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintValidatorDefaultServiceTest.kt deleted file mode 100644 index be360d90..00000000 --- a/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintValidatorDefaultServiceTest.kt +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.apps.controllerblueprints.core.service - -import com.att.eelf.configuration.EELFLogger -import com.att.eelf.configuration.EELFManager -import org.junit.Before -import org.junit.Test -import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintMetadataUtils - -/** - * - * - * @author Brinda Santh - */ -class BluePrintValidatorDefaultServiceTest { - private val log: EELFLogger = EELFManager.getInstance().getLogger(this::class.toString()) - - @Before - fun setUp(): Unit { - - } - - @Test - fun testValidateBluePrint() { - - val blueprintBasePath: String = ("./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration") - val bluePrintContext = BluePrintMetadataUtils.getBluePrintContext(blueprintBasePath) - val properties: MutableMap<String, Any> = hashMapOf() - - val validatorService = BluePrintValidatorDefaultService() - validatorService.validateBlueprint(bluePrintContext.serviceTemplate, properties) - log.info("Validation Message {}", properties) - } -}
\ No newline at end of file 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 8072f283..a3625e40 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 84073ff2..c8985774 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 7d81ba62..62a82286 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 00000000..bad14791 --- /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 6fe4fa36..002dd9fb 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 00000000..6975ec61 --- /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 43c3e0e3..3fc918e6 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") } diff --git a/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDictionaryConstants.kt b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDictionaryConstants.kt index d33a2f04..62ed4047 100644 --- a/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDictionaryConstants.kt +++ b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDictionaryConstants.kt @@ -24,7 +24,7 @@ package org.onap.ccsdk.apps.controllerblueprints.resource.dict object ResourceDictionaryConstants { const val SOURCE_INPUT = "input" const val SOURCE_DEFAULT = "default" - const val SOURCE_PRIMARY_CONFIG_DATA = "primary-config-data" + const val SOURCE_PRIMARY_CONFIG_DATA = "rest" const val SOURCE_PRIMARY_DB = "primary-db" const val MODEL_DIR_RESOURCE_DEFINITION: String = "resource_dictionary" diff --git a/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceAssignmentValidationService.kt b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceAssignmentValidationService.kt index d71fbbf8..b35bca74 100644 --- a/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceAssignmentValidationService.kt +++ b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceAssignmentValidationService.kt @@ -23,10 +23,8 @@ import org.apache.commons.collections.CollectionUtils import org.apache.commons.lang3.StringUtils import org.apache.commons.lang3.text.StrBuilder import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException -import org.onap.ccsdk.apps.controllerblueprints.core.format import org.onap.ccsdk.apps.controllerblueprints.core.utils.TopologicalSortingUtils import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.factory.ResourceSourceMappingFactory import java.io.Serializable /** @@ -53,7 +51,6 @@ open class ResourceAssignmentValidationServiceImpl : ResourceAssignmentValidatio override fun validate(resourceAssignments: List<ResourceAssignment>): Boolean { try { - validateSources(resourceAssignments) validateTemplateNDictionaryKeys(resourceAssignments) validateCyclicDependency(resourceAssignments) if (StringUtils.isNotBlank(validationMessage)) { @@ -65,17 +62,6 @@ open class ResourceAssignmentValidationServiceImpl : ResourceAssignmentValidatio return true } - open fun validateSources(resourceAssignments: List<ResourceAssignment>) { - log.info("validating resource assignment sources") - // Check the Resource Assignment Source(Dynamic Instance) is valid. - resourceAssignments.forEach { resourceAssignment -> - try { - ResourceSourceMappingFactory.getRegisterSourceMapping(resourceAssignment.dictionarySource!!) - } catch (e: BluePrintException) { - validationMessage.appendln(e.message + format(" for resource assignment({})", resourceAssignment.name)) - } - } - } open fun validateTemplateNDictionaryKeys(resourceAssignments: List<ResourceAssignment>) { @@ -121,7 +107,7 @@ open class ResourceAssignmentValidationServiceImpl : ResourceAssignmentValidatio resourceAssignmentMap.map { it.value }.map { resourceAssignment -> if (CollectionUtils.isNotEmpty(resourceAssignment.dependencies)) { resourceAssignment.dependencies!!.map { - log.info("Topological Graph link from {} to {}", it, resourceAssignment.name) + log.trace("Topological Graph link from {} to {}", it, resourceAssignment.name) topologySorting.add(resourceAssignmentMap[it]!!, resourceAssignment) } } else { diff --git a/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDefinitionValidationService.kt b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDefinitionValidationService.kt deleted file mode 100644 index 9541a7b8..00000000 --- a/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDefinitionValidationService.kt +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Copyright © 2018 IBM. - * Modifications 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.resource.dict.service - -import com.att.eelf.configuration.EELFLogger -import com.att.eelf.configuration.EELFManager -import com.fasterxml.jackson.databind.JsonNode -import com.google.common.base.Preconditions -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintTypes -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.PropertyDefinition -import org.onap.ccsdk.apps.controllerblueprints.core.format -import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintRepoService -import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintExpressionService -import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition -import java.io.Serializable - -/** - * ResourceDefinitionValidationService. - * - * @author Brinda Santh - */ -interface ResourceDefinitionValidationService : Serializable { - - @Throws(BluePrintException::class) - fun validate(resourceDefinition: ResourceDefinition) - -} - -/** - * ResourceDefinitionValidationService. - * - * @author Brinda Santh - */ -open class ResourceDefinitionValidationServiceImpl(private val bluePrintRepoService: BluePrintRepoService) : ResourceDefinitionValidationService { - - private val log: EELFLogger = EELFManager.getInstance().getLogger(ResourceDefinitionValidationService::class.java) - - override fun validate(resourceDefinition: ResourceDefinition) { - Preconditions.checkNotNull(resourceDefinition, "Failed to get Resource Definition") - log.trace("Validating Resource Dictionary Definition {}", resourceDefinition.name) - - resourceDefinition.sources.forEach { name, nodeTemplate -> - val sourceType = nodeTemplate.type - - val sourceNodeType = bluePrintRepoService.getNodeType(sourceType) - - // Validate Property Name, expression, values and Data Type - validateNodeTemplateProperties(nodeTemplate, sourceNodeType) - } - } - - - open fun validateNodeTemplateProperties(nodeTemplate: NodeTemplate, nodeType: NodeType) { - nodeTemplate.properties?.let { validatePropertyAssignments(nodeType.properties!!, nodeTemplate.properties!!) } - } - - - open fun validatePropertyAssignments(nodeTypeProperties: MutableMap<String, PropertyDefinition>, - properties: MutableMap<String, JsonNode>) { - properties.forEach { propertyName, propertyAssignment -> - val propertyDefinition: PropertyDefinition = nodeTypeProperties[propertyName] - ?: throw BluePrintException(format("failed to get definition for the property ({})", propertyName)) - // Check and Validate if Expression Node - val expressionData = BluePrintExpressionService.getExpressionData(propertyAssignment) - if (!expressionData.isExpression) { - checkPropertyValue(propertyDefinition, propertyName, propertyAssignment) - } else { - throw BluePrintException(format("property({}) of expression ({}) is not supported", - propertyName, propertyAssignment)) - } - } - } - - open fun checkPropertyValue(propertyDefinition: PropertyDefinition, propertyName: String, 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)) { - - isValid = JacksonUtils.checkJsonNodeValueOfCollectionType(propertyType, propertyAssignment) - } else { - bluePrintRepoService.getDataType(propertyType) - isValid = true - } - - check(isValid) { - throw BluePrintException(format("property({}) defined of type({}) is not compatable with the value ({})", - propertyName, propertyType, propertyAssignment)) - } - } -}
\ No newline at end of file diff --git a/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtils.kt b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtils.kt index 1aeda0ba..69ee1cfd 100644 --- a/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtils.kt +++ b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtils.kt @@ -85,6 +85,12 @@ object ResourceDictionaryUtils { ?: throw BluePrintProcessorException("couldn't get ResourceAssignment definitions for the file($filePath)") } + fun writeResourceDefinitionTypes(basePath: String, resourceDefinitions: List<ResourceDefinition>) { + val resourceDefinitionMap = resourceDefinitions.map { it.name to it }.toMap() + writeResourceDefinitionTypes(basePath, resourceDefinitionMap) + + } + fun writeResourceDefinitionTypes(basePath: String, resourceDefinitionMap: Map<String, ResourceDefinition>) { val typePath = basePath.plus(File.separator).plus(BluePrintConstants.TOSCA_DEFINITIONS_DIR) .plus(File.separator).plus("${ResourceDictionaryConstants.PATH_RESOURCE_DEFINITION_TYPE}.json") diff --git a/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDefinitionValidationServiceTest.java b/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDefinitionValidationServiceTest.java deleted file mode 100644 index 7f040b2e..00000000 --- a/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDefinitionValidationServiceTest.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * 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.resource.dict.service; - -import org.junit.Assert; -import org.junit.Test; -import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRepoFileService; -import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils; -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition; - -public class ResourceDefinitionValidationServiceTest { - private String basePath = "load/model_type"; - private String dictionaryPath = "load/resource_dictionary"; - private BluePrintRepoFileService bluePrintRepoFileService = new BluePrintRepoFileService(basePath); - - @Test - public void testValidateSource() throws Exception { - - String inputFileName = dictionaryPath + "/input-source.json"; - testValidate(inputFileName); - - String dbFileName = dictionaryPath + "/primary-db-source.json"; - testValidate(dbFileName); - - String defaultFileName = dictionaryPath + "/default-source.json"; - testValidate(defaultFileName); - - String restFileName = dictionaryPath + "/mdsal-source.json"; - testValidate(restFileName); - } - - private void testValidate(String fileName) throws Exception { - - ResourceDefinition resourceDefinition = JacksonUtils.Companion.readValueFromFile(fileName, ResourceDefinition.class); - Assert.assertNotNull("Failed to populate dictionaryDefinition for type", resourceDefinition); - - ResourceDefinitionValidationService resourceDictionaryValidationService = - new ResourceDefinitionValidationServiceImpl(bluePrintRepoFileService); - resourceDictionaryValidationService.validate(resourceDefinition); - Assert.assertNotNull(String.format("Failed to populate dictionaryDefinition for : %s", fileName), resourceDefinition); - } -} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/validator/ResourceDictionaryValidator.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/validator/ResourceDictionaryValidator.java deleted file mode 100644 index 57330d90..00000000 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/validator/ResourceDictionaryValidator.java +++ /dev/null @@ -1,60 +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.service.validator;
-
-import com.google.common.base.Preconditions;
-import org.apache.commons.lang3.StringUtils;
-import org.onap.ccsdk.apps.controllerblueprints.service.domain.ResourceDictionary;
-
-/**
- * ResourceDictionaryValidator.java Purpose: Provide Validation Service for Model Type Resource
- * Dictionary Validator
- *
- * @author Brinda Santh
- * @version 1.0
- */
-public class ResourceDictionaryValidator {
-
- private ResourceDictionaryValidator() {}
-
- /**
- * This is a validateResourceDictionary method
- *
- * @param resourceDictionary
- * @return boolean
- *
- */
- public static boolean validateResourceDictionary(ResourceDictionary resourceDictionary) {
-
- Preconditions.checkNotNull(resourceDictionary,"ResourceDictionary Information is missing." );
-
- Preconditions.checkArgument( StringUtils.isNotBlank(resourceDictionary.getName()),
- "DataDictionary Alias Name Information is missing.");
- Preconditions.checkNotNull( resourceDictionary.getDefinition(),
- "DataDictionary Definition Information is missing.");
- Preconditions.checkArgument( StringUtils.isNotBlank(resourceDictionary.getDescription()),
- "DataDictionary Description Information is missing.");
- Preconditions.checkArgument( StringUtils.isNotBlank(resourceDictionary.getTags()),
- "DataDictionary Tags Information is missing.");
- Preconditions.checkArgument( StringUtils.isNotBlank(resourceDictionary.getUpdatedBy()),
- "DataDictionary Updated By Information is missing.");
- return true;
-
- }
-
-}
diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/validator/ServiceTemplateValidator.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/validator/ServiceTemplateValidator.java deleted file mode 100644 index 5d15e087..00000000 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/validator/ServiceTemplateValidator.java +++ /dev/null @@ -1,147 +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.service.validator;
-
-import com.google.common.base.Preconditions;
-import org.apache.commons.collections.MapUtils;
-import org.apache.commons.lang3.StringUtils;
-import org.jetbrains.annotations.NotNull;
-import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants;
-import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException;
-import org.onap.ccsdk.apps.controllerblueprints.core.ConfigModelConstant;
-import org.onap.ccsdk.apps.controllerblueprints.core.data.CapabilityAssignment;
-import org.onap.ccsdk.apps.controllerblueprints.core.data.NodeTemplate;
-import org.onap.ccsdk.apps.controllerblueprints.core.data.ServiceTemplate;
-import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintValidatorDefaultService;
-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.ResourceAssignmentValidationService;
-import org.onap.ccsdk.apps.controllerblueprints.resource.dict.service.ResourceAssignmentValidationServiceImpl;
-
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-/**
- * ServiceTemplateValidator.java Purpose: Provide Configuration Generator ServiceTemplateValidator
- *
- * @author Brinda Santh
- * @version 1.0
- */
-
-public class ServiceTemplateValidator extends BluePrintValidatorDefaultService {
-
- StringBuilder message = new StringBuilder();
- private Map<String, String> metaData = new HashMap<>();
-
- /**
- * This is a validateServiceTemplate
- *
- * @param serviceTemplateContent serviceTemplateContent
- * @return boolean
- * @throws BluePrintException BluePrintException
- */
- public boolean validateServiceTemplate(String serviceTemplateContent) throws BluePrintException {
- if (StringUtils.isNotBlank(serviceTemplateContent)) {
- ServiceTemplate serviceTemplate =
- JacksonUtils.Companion.readValue(serviceTemplateContent, ServiceTemplate.class);
- return validateServiceTemplate(serviceTemplate);
- } else {
- throw new BluePrintException(
- "Service Template Content is (" + serviceTemplateContent + ") not Defined.");
- }
- }
-
- /**
- * This is a validateServiceTemplate
- *
- * @param serviceTemplate serviceTemplate
- * @return boolean
- * @throws BluePrintException BluePrintException
- */
- @SuppressWarnings("squid:S00112")
- public boolean validateServiceTemplate(ServiceTemplate serviceTemplate) throws BluePrintException {
- Map<String, Object> properties = new HashMap<>();
- super.validateBlueprint(serviceTemplate, properties);
- return true;
- }
-
- /**
- * This is a getMetaData to get the key information during the
- *
- * @return Map<String , String>
- */
- public Map<String, String> getMetaData() {
- return metaData;
- }
-
- @Override
- public void validateMetadata(@NotNull Map<String, String> metaDataMap) throws BluePrintException {
-
- Preconditions.checkNotNull(serviceTemplate.getMetadata(), "Service Template Metadata Information is missing.");
- super.validateMetadata(metaDataMap);
-
- this.metaData.putAll(serviceTemplate.getMetadata());
- }
-
-
- @Override
- public void validateNodeTemplate(@NotNull String nodeTemplateName, @NotNull NodeTemplate nodeTemplate)
- throws BluePrintException {
- super.validateNodeTemplate(nodeTemplateName, nodeTemplate);
- validateNodeTemplateCustom(nodeTemplateName, nodeTemplate);
-
- }
-
- @Deprecated()
- private void validateNodeTemplateCustom(@NotNull String nodeTemplateName, @NotNull NodeTemplate nodeTemplate)
- throws BluePrintException {
- String derivedFrom = getBluePrintContext().nodeTemplateNodeType(nodeTemplateName).getDerivedFrom();
-
- if (BluePrintConstants.MODEL_TYPE_NODE_ARTIFACT.equals(derivedFrom)) {
- List<ResourceAssignment> resourceAssignment = getResourceAssignments(nodeTemplate);
- ResourceAssignmentValidationService resourceAssignmentValidationService = new ResourceAssignmentValidationServiceImpl();
- resourceAssignmentValidationService.validate(resourceAssignment);
- }
- }
-
- private List<ResourceAssignment> getResourceAssignments(@NotNull NodeTemplate nodeTemplate) {
-
- List<ResourceAssignment> resourceAssignment = null;
-
- if (MapUtils.isNotEmpty(nodeTemplate.getCapabilities())) {
-
- CapabilityAssignment capabilityAssignment =
- nodeTemplate.getCapabilities().get(ConfigModelConstant.CAPABILITY_PROPERTY_MAPPING);
- if (capabilityAssignment != null && capabilityAssignment.getProperties() != null) {
- Object mappingObject =
- capabilityAssignment.getProperties().get(ConfigModelConstant.CAPABILITY_PROPERTY_MAPPING);
- if (mappingObject != null) {
- String mappingContent = JacksonUtils.Companion.getJson(mappingObject);
- Preconditions.checkArgument(StringUtils.isNotBlank(mappingContent),
- String.format("Failed to get capability mapping property (%s) ", ConfigModelConstant.CAPABILITY_PROPERTY_MAPPING));
-
- resourceAssignment = JacksonUtils.Companion.getListFromJson(mappingContent, ResourceAssignment.class);
-
- Preconditions.checkNotNull(resourceAssignment,
- String.format("Failed to get resource assignment info from the content (%s) ", mappingContent));
- }
- }
- }
- return resourceAssignment;
- }
-}
diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/BluePrintRepoServiceImpl.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/BluePrintRepoServiceImpl.kt index f856b9ef..88589eb7 100644 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/BluePrintRepoServiceImpl.kt +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/BluePrintRepoServiceImpl.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. @@ -24,21 +25,10 @@ import org.onap.ccsdk.apps.controllerblueprints.core.data.* import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintRepoService 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.service.ResourceAssignmentValidationServiceImpl -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.service.ResourceDefinitionValidationServiceImpl import org.onap.ccsdk.apps.controllerblueprints.service.repository.ModelTypeRepository import org.onap.ccsdk.apps.controllerblueprints.service.repository.ResourceDictionaryRepository import org.springframework.stereotype.Service -// Resource Dictionary Validation Services - -@Service -class DefaultResourceAssignmentValidationService : ResourceAssignmentValidationServiceImpl() - -@Service -class DefalutResourceDefinitionValidationService(bluePrintRepoService: BluePrintRepoService) - : ResourceDefinitionValidationServiceImpl(bluePrintRepoService) - interface ResourceDefinitionRepoService : BluePrintRepoService { @Throws(BluePrintException::class) diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintEnhancerServiceImpl.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintEnhancerServiceImpl.kt index 63171de6..fb49dc46 100644 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintEnhancerServiceImpl.kt +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintEnhancerServiceImpl.kt @@ -23,9 +23,9 @@ import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintEnhancerService
import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintTypeEnhancerService
import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintContext
-import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService
import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintFileUtils
import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintMetadataUtils
+import org.onap.ccsdk.apps.controllerblueprints.resource.dict.utils.ResourceDictionaryUtils
import org.springframework.stereotype.Service
import java.util.*
@@ -56,11 +56,15 @@ open class BluePrintEnhancerServiceImpl(private val bluePrintTypeEnhancerService bluePrintTypeEnhancerService.enhanceServiceTemplate(blueprintRuntimeService, "service_template",
blueprintRuntimeService.bluePrintContext().serviceTemplate)
+ log.info("##### Enhancing blueprint Resource Definitions")
+ val resourceDefinitions = resourceDefinitionEnhancerService.enhance(bluePrintTypeEnhancerService,
+ blueprintRuntimeService)
+
// Write the Enhanced Blueprint Definitions
BluePrintFileUtils.writeEnhancedBluePrint(blueprintRuntimeService.bluePrintContext())
- // Enhance Resource Dictionary
- enhanceResourceDefinition(blueprintRuntimeService)
+ // Write the Enhanced Blueprint Resource Definitions
+ ResourceDictionaryUtils.writeResourceDefinitionTypes(basePath, resourceDefinitions)
if (blueprintRuntimeService.getBluePrintError().errors.isNotEmpty()) {
throw BluePrintException(blueprintRuntimeService.getBluePrintError().errors.toString())
@@ -73,10 +77,5 @@ open class BluePrintEnhancerServiceImpl(private val bluePrintTypeEnhancerService return blueprintRuntimeService.bluePrintContext()
}
- private fun enhanceResourceDefinition(blueprintRuntimeService: BluePrintRuntimeService<*>) {
- log.info("##### Enhancing blueprint Resource Definitions")
- resourceDefinitionEnhancerService.enhance(blueprintRuntimeService)
- }
-
}
diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintNodeTemplateEnhancerImpl.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintNodeTemplateEnhancerImpl.kt index fb6c06af..0765f903 100644 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintNodeTemplateEnhancerImpl.kt +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintNodeTemplateEnhancerImpl.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. @@ -18,15 +19,13 @@ package org.onap.ccsdk.apps.controllerblueprints.service.enhancer 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.NodeType -import org.onap.ccsdk.apps.controllerblueprints.core.format import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintNodeTemplateEnhancer import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintRepoService import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintTypeEnhancerService import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintContext import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService +import org.onap.ccsdk.apps.controllerblueprints.service.utils.BluePrintEnhancerUtils import org.springframework.beans.factory.config.ConfigurableBeanFactory import org.springframework.context.annotation.Scope import org.springframework.stereotype.Service @@ -51,7 +50,7 @@ open class BluePrintNodeTemplateEnhancerImpl(private val bluePrintRepoService: B val nodeTypeName = nodeTemplate.type // Get NodeType from Repo and Update Service Template - val nodeType = populateNodeType(nodeTypeName) + val nodeType = BluePrintEnhancerUtils.populateNodeType(bluePrintContext, bluePrintRepoService, nodeTypeName) // Enrich NodeType bluePrintTypeEnhancerService.enhanceNodeType(bluePrintRuntimeService, nodeTypeName, nodeType) @@ -60,16 +59,6 @@ open class BluePrintNodeTemplateEnhancerImpl(private val bluePrintRepoService: B enhanceNodeTemplateArtifactDefinition(name, nodeTemplate) } - - open fun populateNodeType(nodeTypeName: String): NodeType { - - val nodeType = bluePrintContext.serviceTemplate.nodeTypes?.get(nodeTypeName) - ?: bluePrintRepoService.getNodeType(nodeTypeName) - ?: throw BluePrintException(format("Couldn't get NodeType({}) from repo.", nodeTypeName)) - bluePrintContext.serviceTemplate.nodeTypes?.put(nodeTypeName, nodeType) - return nodeType - } - open fun enhanceNodeTemplateArtifactDefinition(nodeTemplateName: String, nodeTemplate: NodeTemplate) { nodeTemplate.artifacts?.forEach { artifactDefinitionName, artifactDefinition -> diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintPropertyDefinitionEnhancerImpl.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintPropertyDefinitionEnhancerImpl.kt index 1ae558fa..1675e8cd 100644 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintPropertyDefinitionEnhancerImpl.kt +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintPropertyDefinitionEnhancerImpl.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. @@ -43,8 +44,9 @@ open class BluePrintPropertyDefinitionEnhancerImpl(private val bluePrintRepoServ this.bluePrintContext = bluePrintRuntimeService.bluePrintContext() val propertyType = propertyDefinition.type - if (BluePrintTypes.validPrimitiveTypes().contains(propertyType)) { - + if (BluePrintTypes.validPrimitiveTypes().contains(propertyType) + || BluePrintTypes.validComplexTypes().contains(propertyType)) { + // Do Nothing, } else if (BluePrintTypes.validCollectionTypes().contains(propertyType)) { val entrySchema = propertyDefinition.entrySchema ?: throw BluePrintException("Entry Schema is missing for collection property($name)") diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/ResourceDefinitionEnhancerService.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/ResourceDefinitionEnhancerService.kt index 43eb019e..6171687f 100644 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/ResourceDefinitionEnhancerService.kt +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/ResourceDefinitionEnhancerService.kt @@ -23,18 +23,21 @@ import kotlinx.coroutines.Deferred import kotlinx.coroutines.async import kotlinx.coroutines.runBlocking import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException +import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintTypeEnhancerService import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintContext import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition import org.onap.ccsdk.apps.controllerblueprints.resource.dict.utils.ResourceDictionaryUtils import org.onap.ccsdk.apps.controllerblueprints.service.ResourceDefinitionRepoService +import org.onap.ccsdk.apps.controllerblueprints.service.utils.BluePrintEnhancerUtils import org.springframework.stereotype.Service interface ResourceDefinitionEnhancerService { @Throws(BluePrintException::class) - fun enhance(bluePrintRuntimeService: BluePrintRuntimeService<*>) + fun enhance(bluePrintTypeEnhancerService: BluePrintTypeEnhancerService, + bluePrintRuntimeService: BluePrintRuntimeService<*>): List<ResourceDefinition> } @Service @@ -45,7 +48,6 @@ class ResourceDefinitionEnhancerServiceImpl(private val resourceDefinitionRepoSe companion object { const val ARTIFACT_TYPE_MAPPING_SOURCE: String = "artifact-mapping-resource" - const val PROPERTY_DEPENDENCY_NODE_TEMPLATES = "dependency-node-templates" } // Enhance the Resource Definition @@ -53,15 +55,21 @@ class ResourceDefinitionEnhancerServiceImpl(private val resourceDefinitionRepoSe // 2. Get all the Unique Resource assignments from all mapping files // 3. Collect the Resource Definition for Resource Assignment names from database. // 4. Create the Resource Definition under blueprint base path. - override fun enhance(bluePrintRuntimeService: BluePrintRuntimeService<*>) { + override fun enhance(bluePrintTypeEnhancerService: BluePrintTypeEnhancerService, + bluePrintRuntimeService: BluePrintRuntimeService<*>): List<ResourceDefinition> { + + var resourceDefinitions: List<ResourceDefinition> = mutableListOf() val blueprintContext = bluePrintRuntimeService.bluePrintContext() val mappingFiles = getAllResourceMappingFiles(blueprintContext) log.info("resources assignment files ($mappingFiles)") if (mappingFiles != null) { - getResourceDefinition(blueprintContext, mappingFiles) + resourceDefinitions = getResourceDefinition(blueprintContext, mappingFiles) + // Enriching Resource Definition Sources + enrichResourceDefinitionSources(bluePrintRuntimeService.bluePrintContext(), resourceDefinitions) } + return resourceDefinitions } // Get all the Mapping files from all node templates. @@ -80,42 +88,54 @@ class ResourceDefinitionEnhancerServiceImpl(private val resourceDefinitionRepoSe } // Convert file content to ResourceAssignments asynchronously - private fun getResourceDefinition(blueprintContext: BluePrintContext, files: List<String>) { - runBlocking { - val blueprintBasePath = blueprintContext.rootPath - val deferredResourceAssignments = mutableListOf<Deferred<List<ResourceAssignment>>>() - for (file in files) { - log.info("processing file ($file)") - deferredResourceAssignments += async { - ResourceDictionaryUtils.getResourceAssignmentFromFile("$blueprintBasePath/$file") - } - } - - val resourceAssignments = mutableListOf<ResourceAssignment>() - for (deferredResourceAssignment in deferredResourceAssignments) { - resourceAssignments.addAll(deferredResourceAssignment.await()) + private fun getResourceDefinition(blueprintContext: BluePrintContext, files: List<String>) = runBlocking { + val blueprintBasePath = blueprintContext.rootPath + val deferredResourceAssignments = mutableListOf<Deferred<List<ResourceAssignment>>>() + for (file in files) { + log.info("processing file ($file)") + deferredResourceAssignments += async { + ResourceDictionaryUtils.getResourceAssignmentFromFile("$blueprintBasePath/$file") } + } - val distinctResourceAssignments = resourceAssignments.distinctBy { it.name } - generateResourceDictionaryFile(blueprintBasePath, distinctResourceAssignments) - //log.info("distinct Resource assignment ($distinctResourceAssignments)") + val resourceAssignments = mutableListOf<ResourceAssignment>() + for (deferredResourceAssignment in deferredResourceAssignments) { + resourceAssignments.addAll(deferredResourceAssignment.await()) } + + val distinctResourceAssignments = resourceAssignments.distinctBy { it.name } + generateResourceDictionary(blueprintBasePath, distinctResourceAssignments) + //log.info("distinct Resource assignment ($distinctResourceAssignments)") } + // Read the Resource Definitions from the Database and write to type file. - private fun generateResourceDictionaryFile(blueprintBasePath: String, resourceAssignments: List<ResourceAssignment>) { + private fun generateResourceDictionary(blueprintBasePath: String, resourceAssignments: List<ResourceAssignment>) + : List<ResourceDefinition> { val resourceKeys = resourceAssignments.mapNotNull { it.dictionaryName }.distinct().sorted() log.info("distinct resource keys ($resourceKeys)") //TODO("Optimise DB single Query to multiple Query") - // Collect the Resource Definition from database and convert to map to save in file - val resourceDefinitionMap = resourceKeys.map { resourceKey -> + return resourceKeys.map { resourceKey -> getResourceDefinition(resourceKey) - }.map { it.name to it }.toMap() + } + } - // Recreate the Resource Definition File - ResourceDictionaryUtils.writeResourceDefinitionTypes(blueprintBasePath, resourceDefinitionMap) - log.info("resource definition file created successfully") + private fun enrichResourceDefinitionSources(bluePrintContext: BluePrintContext, + resourceDefinitions: List<ResourceDefinition>) { + val sources = resourceDefinitions + .map { it.sources } + .map { + it.values + .map { nodeTemplate -> + nodeTemplate.type + } + } + .flatten().distinct() + log.info("Enriching Resource Definition sources Node Template: $sources") + sources.forEach { + BluePrintEnhancerUtils.populateNodeType(bluePrintContext, resourceDefinitionRepoService, it) + } } // Get the Resource Definition from Database diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/handler/ResourceDictionaryHandler.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/handler/ResourceDictionaryHandler.kt index c2493148..ec7d8aeb 100644 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/handler/ResourceDictionaryHandler.kt +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/handler/ResourceDictionaryHandler.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. @@ -20,17 +21,15 @@ import com.google.common.base.Preconditions import org.apache.commons.collections.CollectionUtils import org.apache.commons.lang3.StringUtils import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException +import org.onap.ccsdk.apps.controllerblueprints.core.checkNotEmptyOrThrow import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceSourceMapping import org.onap.ccsdk.apps.controllerblueprints.resource.dict.factory.ResourceSourceMappingFactory -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.service.ResourceDefinitionValidationService import org.onap.ccsdk.apps.controllerblueprints.service.domain.ResourceDictionary import org.onap.ccsdk.apps.controllerblueprints.service.repository.ResourceDictionaryRepository -import org.onap.ccsdk.apps.controllerblueprints.service.validator.ResourceDictionaryValidator import org.springframework.stereotype.Service @Service -class ResourceDictionaryHandler(private val resourceDictionaryRepository: ResourceDictionaryRepository, - private val resourceDictionaryValidationService: ResourceDefinitionValidationService) { +class ResourceDictionaryHandler(private val resourceDictionaryRepository: ResourceDictionaryRepository) { /** @@ -86,7 +85,8 @@ class ResourceDictionaryHandler(private val resourceDictionaryRepository: Resour val resourceDefinition = resourceDictionary.definition Preconditions.checkNotNull(resourceDefinition, "failed to get resource definition from content") // Validate the Resource Definitions - resourceDictionaryValidationService.validate(resourceDefinition) + //TODO( Save Validator) + //validate(resourceDefinition) resourceDictionary.tags = resourceDefinition.tags resourceDefinition.updatedBy = resourceDictionary.updatedBy @@ -98,7 +98,7 @@ class ResourceDictionaryHandler(private val resourceDictionaryRepository: Resour resourceDictionary.entrySchema = propertyDefinition.entrySchema!!.type } - ResourceDictionaryValidator.validateResourceDictionary(resourceDictionary) + validateResourceDictionary(resourceDictionary) val dbResourceDictionaryData = resourceDictionaryRepository.findByName(resourceDictionary.name) if (dbResourceDictionaryData.isPresent) { @@ -135,4 +135,14 @@ class ResourceDictionaryHandler(private val resourceDictionaryRepository: Resour fun getResourceSourceMapping(): ResourceSourceMapping { return ResourceSourceMappingFactory.getRegisterSourceMapping() } + + private fun validateResourceDictionary(resourceDictionary: ResourceDictionary): Boolean { + checkNotEmptyOrThrow(resourceDictionary.name, "DataDictionary Definition name is missing.") + checkNotNull(resourceDictionary.definition) { "DataDictionary Definition Information is missing." } + checkNotEmptyOrThrow(resourceDictionary.description, "DataDictionary Definition Information is missing.") + checkNotEmptyOrThrow(resourceDictionary.tags, "DataDictionary Definition tags is missing.") + checkNotEmptyOrThrow(resourceDictionary.updatedBy, "DataDictionary Definition updatedBy is missing.") + return true + + } }
\ No newline at end of file diff --git a/ms/controllerblueprints/parent/pom.xml b/ms/controllerblueprints/parent/pom.xml index ea7b4e40..f59effc4 100644 --- a/ms/controllerblueprints/parent/pom.xml +++ b/ms/controllerblueprints/parent/pom.xml @@ -30,10 +30,10 @@ <packaging>pom</packaging> <properties> <kotlin.compiler.jvmTarget>1.8</kotlin.compiler.jvmTarget> - <spring.boot.version>2.1.2.RELEASE</spring.boot.version> - <spring.version>5.1.4.RELEASE</spring.version> - <kotlin.version>1.3.20</kotlin.version> - <kotlin.maven.version>1.3.20</kotlin.maven.version> + <spring.boot.version>2.1.3.RELEASE</spring.boot.version> + <spring.version>5.1.5.RELEASE</spring.version> + <kotlin.version>1.3.21</kotlin.version> + <kotlin.maven.version>1.3.21</kotlin.maven.version> <kotlin.couroutines.version>1.1.1</kotlin.couroutines.version> <grpc.version>1.18.0</grpc.version> <protobuff.java.utils.version>3.6.1</protobuff.java.utils.version> |