const val MODEL_CONTENT_TYPE_SCHEMA: String = "SCHEMA"\r
\r
const val PATH_DIVIDER: String = "/"\r
+ const val PATH_SERVICE_TEMPLATE: String = "service_template"\r
+ const val PATH_TOPOLOGY_TEMPLATE: String = "topology_template"\r
+ const val PATH_METADATA: String = "metadata"\r
+ const val PATH_NODE_TYPES: String = "node_types"\r
+ const val PATH_ARTIFACT_TYPES: String = "artifact_types"\r
+ const val PATH_DATA_TYPES: String = "data_types"\r
const val PATH_INPUTS: String = "inputs"\r
const val PATH_NODE_WORKFLOWS: String = "workflows"\r
const val PATH_NODE_TEMPLATES: String = "node_templates"\r
interface BluePrintValidatorService {
@Throws(BluePrintException::class)
- fun validateBluePrints(bluePrintContext: BluePrintContext, properties: MutableMap<String, Any>)
+ fun validateBluePrints(bluePrintContext: BluePrintContext, properties: MutableMap<String, Any>) : Boolean
}
// Recursively Import Template files\r
val schemaImportResolverUtils = BluePrintImportService(rootServiceTemplate, basePath)\r
val completeServiceTemplate = schemaImportResolverUtils.getImportResolvedServiceTemplate()\r
- return BluePrintContext(completeServiceTemplate)\r
+ val blueprintContext = BluePrintContext(completeServiceTemplate)\r
+ blueprintContext.rootPath = basePath\r
+ return blueprintContext\r
}\r
}
\ No newline at end of file
artifactType.properties?.let {
bluePrintTypeValidatorService.validatePropertyDefinitions(bluePrintContext, error, artifactType.properties!!)
}
+ // TODO ("Files Present ")
}
}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright © 2017-2018 AT&T Intellectual Property.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.ccsdk.apps.controllerblueprints.core.validation
+
+import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintValidationError
+import org.onap.ccsdk.apps.controllerblueprints.core.data.AttributeDefinition
+import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintAttributeDefinitionValidator
+import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintTypeValidatorService
+import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintContext
+
+class BluePrintAttributeDefinitionValidatorImpl(private val bluePrintTypeValidatorService: BluePrintTypeValidatorService) : BluePrintAttributeDefinitionValidator {
+
+ override fun validate(bluePrintContext: BluePrintContext, error: BluePrintValidationError, name: String, type: AttributeDefinition) {
+ //TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
+ }
+}
\ No newline at end of file
package org.onap.ccsdk.apps.controllerblueprints.core.validation
+import com.att.eelf.configuration.EELFLogger
+import com.att.eelf.configuration.EELFManager
import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintValidationError
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.service.BluePrintContext
open class BluePrintDataTypeValidatorImpl(private val bluePrintTypeValidatorService: BluePrintTypeValidatorService) : BluePrintDataTypeValidator {
+ private val log: EELFLogger = EELFManager.getInstance().getLogger(BluePrintDataTypeValidatorImpl::class.toString())
override fun validate(bluePrintContext: BluePrintContext, error: BluePrintValidationError, name: String, dataType: DataType) {
+ log.trace("Validating DataType($name)")
+
dataType.properties?.let {
bluePrintTypeValidatorService.validatePropertyDefinitions(bluePrintContext, error, dataType.properties!!)
var paths: MutableList<String> = arrayListOf()
override fun validate(bluePrintContext: BluePrintContext, error: BluePrintValidationError, nodeTemplateName: String, nodeTemplate: NodeTemplate) {
+ log.trace("Validating NodeTemplate($nodeTemplateName)")
+ this.bluePrintContext = bluePrintContext
+ this.error = error
paths.add(nodeTemplateName)
val nodeType: NodeType = bluePrintContext.serviceTemplate.nodeTypes?.get(type)
?: throw BluePrintException("Failed to get NodeType($type) definition for NodeTemplate($nodeTemplateName)")
- nodeTemplate.artifacts?.let { validateArtifactDefinitions(nodeTemplate.artifacts!!) }
nodeTemplate.properties?.let { validatePropertyAssignments(nodeType.properties!!, nodeTemplate.properties!!) }
nodeTemplate.capabilities?.let { validateCapabilityAssignments(nodeType, nodeTemplateName, nodeTemplate) }
nodeTemplate.requirements?.let { validateRequirementAssignments(nodeType, nodeTemplateName, nodeTemplate) }
nodeTemplate.interfaces?.let { validateInterfaceAssignments(nodeType, nodeTemplateName, nodeTemplate) }
+ nodeTemplate.artifacts?.let { validateArtifactDefinitions(nodeTemplate.artifacts!!) }
paths.removeAt(paths.lastIndex)
}
var paths: MutableList<String> = arrayListOf()
override fun validate(bluePrintContext: BluePrintContext, error: BluePrintValidationError, nodeTypeName: String, nodeType: NodeType) {
-
+ log.trace("Validating NodeType($nodeTypeName)")
this.bluePrintContext = bluePrintContext
this.error = error
+
paths.add(nodeTypeName)
val derivedFrom: String = nodeType.derivedFrom
package org.onap.ccsdk.apps.controllerblueprints.core.validation
+import com.att.eelf.configuration.EELFLogger
+import com.att.eelf.configuration.EELFManager
import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException
import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintTypes
import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintValidationError
open class BluePrintPropertyDefinitionValidatorImpl(private val bluePrintTypeValidatorService: BluePrintTypeValidatorService) : BluePrintPropertyDefinitionValidator {
+ private val log: EELFLogger = EELFManager.getInstance().getLogger(BluePrintServiceTemplateValidatorImpl::class.toString())
+
var bluePrintContext: BluePrintContext? = null
var error: BluePrintValidationError? = null
this.bluePrintContext = bluePrintContext
this.error = error
+ log.trace("Validating PropertyDefinition($name)")
+
val dataType: String = propertyDefinition.type
when {
import com.google.common.base.Preconditions
import org.apache.commons.lang3.StringUtils
import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants
-import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException
import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintValidationError
import org.onap.ccsdk.apps.controllerblueprints.core.data.*
import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintServiceTemplateValidator
var bluePrintContext: BluePrintContext? = null
var error: BluePrintValidationError? = null
+ var paths: MutableList<String> = arrayListOf()
override fun validate(bluePrintContext: BluePrintContext, error: BluePrintValidationError, name: String, serviceTemplate: ServiceTemplate) {
- log.info("Validating Service Template..")
+ log.trace("Validating Service Template..")
try {
this.bluePrintContext = bluePrintContext
this.error = error
serviceTemplate.nodeTypes?.let { validateNodeTypes(serviceTemplate.nodeTypes!!) }
serviceTemplate.topologyTemplate?.let { validateTopologyTemplate(serviceTemplate.topologyTemplate!!) }
} catch (e: Exception) {
- throw BluePrintException(e, "failed to validate blueprint with message ${e.message}")
+ error.addError(BluePrintConstants.PATH_SERVICE_TEMPLATE, paths.joinToString(BluePrintConstants.PATH_DIVIDER), e.message!!)
}
}
fun validateMetadata(metaDataMap: MutableMap<String, String>) {
+ paths.add(BluePrintConstants.PATH_METADATA)
+
val templateName = metaDataMap[BluePrintConstants.METADATA_TEMPLATE_NAME]
val templateVersion = metaDataMap[BluePrintConstants.METADATA_TEMPLATE_VERSION]
val templateTags = metaDataMap[BluePrintConstants.METADATA_TEMPLATE_TAGS]
Preconditions.checkArgument(StringUtils.isNotBlank(templateVersion), "failed to get template version metadata")
Preconditions.checkArgument(StringUtils.isNotBlank(templateTags), "failed to get template tags metadata")
Preconditions.checkArgument(StringUtils.isNotBlank(templateAuthor), "failed to get template author metadata")
+
+ paths.removeAt(paths.lastIndex)
}
fun validateDataTypes(dataTypes: MutableMap<String, DataType>) {
+
+ paths.add(BluePrintConstants.PATH_DATA_TYPES)
dataTypes.forEach { dataTypeName, dataType ->
// Validate Single Data Type
bluePrintTypeValidatorService.validateDataType(bluePrintContext!!, error!!, dataTypeName, dataType)
}
+ paths.removeAt(paths.lastIndex)
}
fun validateArtifactTypes(artifactTypes: MutableMap<String, ArtifactType>) {
+ paths.add(BluePrintConstants.PATH_ARTIFACT_TYPES)
artifactTypes.forEach { artifactName, artifactType ->
// Validate Single Artifact Type
bluePrintTypeValidatorService.validateArtifactType(bluePrintContext!!, error!!, artifactName, artifactType)
}
+ paths.removeAt(paths.lastIndex)
}
fun validateNodeTypes(nodeTypes: MutableMap<String, NodeType>) {
+ paths.add(BluePrintConstants.PATH_NODE_TYPES)
nodeTypes.forEach { nodeTypeName, nodeType ->
// Validate Single Node Type
bluePrintTypeValidatorService.validateNodeType(bluePrintContext!!, error!!, nodeTypeName, nodeType)
}
+ paths.removeAt(paths.lastIndex)
}
fun validateTopologyTemplate(topologyTemplate: TopologyTemplate) {
+ paths.add(BluePrintConstants.PATH_TOPOLOGY_TEMPLATE)
bluePrintTypeValidatorService.validateTopologyTemplate(bluePrintContext!!, error!!, "topologyTemplate", topologyTemplate)
+ paths.removeAt(paths.lastIndex)
}
}
\ No newline at end of file
package org.onap.ccsdk.apps.controllerblueprints.core.validation
+import com.att.eelf.configuration.EELFLogger
+import com.att.eelf.configuration.EELFManager
import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException
import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintValidationError
import org.onap.ccsdk.apps.controllerblueprints.core.data.NodeTemplate
open class BluePrintTopologyTemplateValidatorImpl(private val bluePrintTypeValidatorService: BluePrintTypeValidatorService) : BluePrintTopologyTemplateValidator {
+ private val log: EELFLogger = EELFManager.getInstance().getLogger(BluePrintServiceTemplateValidatorImpl::class.toString())
+
var bluePrintContext: BluePrintContext? = null
var error: BluePrintValidationError? = null
override fun validate(bluePrintContext: BluePrintContext, error: BluePrintValidationError, name: String, topologyTemplate: TopologyTemplate) {
+ log.trace("Validating Topology Template..")
this.bluePrintContext = bluePrintContext
+ this.error = error
+
// Validate Inputs
topologyTemplate.inputs?.let { validateInputs(topologyTemplate.inputs!!) }
// Validate Node Templates
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.BluePrintValidationError
import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintTypeValidatorService
import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintValidatorService
private val log: EELFLogger = EELFManager.getInstance().getLogger(BluePrintValidatorServiceImpl::class.toString())
- override fun validateBluePrints(bluePrintContext: BluePrintContext, properties: MutableMap<String, Any>) {
- log.info("Validation blueprints...")
+ override fun validateBluePrints(bluePrintContext: BluePrintContext, properties: MutableMap<String, Any>): Boolean {
val error = BluePrintValidationError()
bluePrintTypeValidatorService.validateServiceTemplate(bluePrintContext, error, "default", bluePrintContext.serviceTemplate)
+ if (error.errors.size > 0) {
+ throw BluePrintException("failed in blueprint validation : ${error.errors.joinToString("\n")}")
+ }
+ return true
}
}
package org.onap.ccsdk.apps.controllerblueprints.core.validation
+import com.att.eelf.configuration.EELFLogger
+import com.att.eelf.configuration.EELFManager
+import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants
import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintValidationError
import org.onap.ccsdk.apps.controllerblueprints.core.data.Workflow
import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintTypeValidatorService
open class BluePrintWorkflowValidatorImpl(private val bluePrintTypeValidatorService: BluePrintTypeValidatorService) : BluePrintWorkflowValidator {
- override fun validate(bluePrintContext: BluePrintContext, error: BluePrintValidationError, name: String, type: Workflow) {
- TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
+ private val log: EELFLogger = EELFManager.getInstance().getLogger(BluePrintServiceTemplateValidatorImpl::class.toString())
+ var bluePrintContext: BluePrintContext? = null
+ var error: BluePrintValidationError? = null
+ var paths: MutableList<String> = arrayListOf()
+
+ override fun validate(bluePrintContext: BluePrintContext, error: BluePrintValidationError, workflowName: String, workflow: Workflow) {
+ log.info("Validating Workflow($workflowName)")
+
+ this.bluePrintContext = bluePrintContext
+ this.error = error
+
+ paths.add(workflowName)
+ paths.joinToString(BluePrintConstants.PATH_DIVIDER)
+
+ // Step Validation Start
+ paths.add("steps")
+ workflow.steps?.forEach { stepName, _ ->
+ paths.add(stepName)
+ paths.joinToString(BluePrintConstants.PATH_DIVIDER)
+ // TODO("Step Validation")
+ paths.removeAt(paths.lastIndex)
+ }
+ paths.removeAt(paths.lastIndex)
+ // Step Validation Ends
+ paths.removeAt(paths.lastIndex)
}
}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright © 2017-2018 AT&T Intellectual Property.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.ccsdk.apps.controllerblueprints.core.mock
+
+import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.*
+import org.onap.ccsdk.apps.controllerblueprints.core.validation.*
+
+class MockBluePrintTypeValidatorService : BluePrintTypeValidatorService {
+
+ override fun getServiceTemplateValidators(): List<BluePrintServiceTemplateValidator> {
+ return listOf(BluePrintServiceTemplateValidatorImpl(this))
+ }
+
+ override fun getDataTypeValidators(): List<BluePrintDataTypeValidator> {
+ return listOf(BluePrintDataTypeValidatorImpl(this))
+ }
+
+ override fun getArtifactTypeValidators(): List<BluePrintArtifactTypeValidator> {
+ return listOf(BluePrintArtifactTypeValidatorImpl(this))
+ }
+
+ override fun getNodeTypeValidators(): List<BluePrintNodeTypeValidator> {
+ return listOf(BluePrintNodeTypeValidatorImpl(this))
+ }
+
+ override fun getTopologyTemplateValidators(): List<BluePrintTopologyTemplateValidator> {
+ return listOf(BluePrintTopologyTemplateValidatorImpl(this))
+ }
+
+ override fun getNodeTemplateValidators(): List<BluePrintNodeTemplateValidator> {
+ return listOf(BluePrintNodeTemplateValidatorImpl(this))
+ }
+
+ override fun getWorkflowValidators(): List<BluePrintWorkflowValidator> {
+ return listOf(BluePrintWorkflowValidatorImpl(this))
+ }
+
+ override fun getPropertyDefinitionValidators(): List<BluePrintPropertyDefinitionValidator> {
+ return listOf(BluePrintPropertyDefinitionValidatorImpl(this))
+ }
+
+ override fun getAttributeDefinitionValidators(): List<BluePrintAttributeDefinitionValidator> {
+ return listOf(BluePrintAttributeDefinitionValidatorImpl(this))
+ }
+}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright © 2017-2018 AT&T Intellectual Property.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.ccsdk.apps.controllerblueprints.core.validation
+
+import org.junit.Test
+import org.onap.ccsdk.apps.controllerblueprints.core.mock.MockBluePrintTypeValidatorService
+import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintMetadataUtils
+import kotlin.test.assertTrue
+
+class BluePrintValidatorServiceImplTest {
+
+ val blueprintBasePath: String = ("./../model-catalog/blueprint-model/starter-blueprint/baseconfiguration")
+
+
+ @Test
+ fun testValidateOfType() {
+ val bluePrintContext = BluePrintMetadataUtils.getBluePrintContext(blueprintBasePath)
+
+ val mockBluePrintTypeValidatorService = MockBluePrintTypeValidatorService()
+
+ val defaultBluePrintValidatorService = BluePrintValidatorServiceImpl(mockBluePrintTypeValidatorService)
+
+ val valid = defaultBluePrintValidatorService.validateBluePrints(bluePrintContext, hashMapOf())
+
+ assertTrue(valid, "failed in blueprint Validation")
+
+ }
+}
+