Mandate Tosca.meta template name, version, type and tags.
Auto copy metadata from Tosca.meta to ServiceTemplate definitions.
Optimize Blueprint context and runtime creation from file path.
Removed attached CBA zip file in test repository dirs
Issue-ID: CCSDK-1992
Signed-off-by: Brinda Santh <bs2796@att.com>
Change-Id: I5d9d7a4599234a38d431328dbd9b74bd831e0115
CSAR-Version: 1.0
Created-By: Brinda Santh <brindasanth@in.ibm.com>
Entry-Definitions: Definitions/activation-blueprint.json
-Template-Tags: Brinda Santh, activation-blueprint
Template-Name: baseconfiguration
Template-Version: 1.0.0
+Template-Type: DEFAULT
+Template-Tags: Brinda Santh, activation-blueprint
Entry-Definitions: Definitions/capability-cli-blueprint.json
Template-Name: capability-cli
Template-Version: 1.0.0
+Template-Type: DEFAULT
Template-Tags: capability-cli-blueprint
Entry-Definitions: cba.resource.audit.ResourceAuditDefinitions.kt
Template-Name: resource-audit
Template-Version: 1.0.0
+Template-Type: KOTLIN_DSL
Template-Tags: resource-audit
\ No newline at end of file
CSAR-Version: 1.0
Created-By: Rodrigo Ottero
Entry-Definitions: Definitions/echo-test.json
-Template-Name: echo-test
+Template-Name: echo_test
Template-Version: 1.0.0
Template-Tags: echo-test
awxRemoteExecutor: ComponentRemoteAnsibleExecutor,
executionServiceInput: ExecutionServiceInput
): BluePrintRuntimeService<MutableMap<String, JsonNode>> {
- val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime(
+ val bluePrintRuntimeService = BluePrintMetadataUtils.bluePrintRuntime(
"123456-1000",
"./../../../../components/model-catalog/blueprint-model/test-blueprint/remote_ansible"
)
@Autowired
lateinit var cfgSnapshotService: ResourceConfigSnapshotService
lateinit var cfgSnapshotComponent: ComponentConfigSnapshotsExecutor
- private var bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime(
+ private var bluePrintRuntimeService = BluePrintMetadataUtils.bluePrintRuntime(
"123456-1000",
"./../../../../components/model-catalog/blueprint-model/test-blueprint/remote_scripts"
)
* Mocked input information for remote python executor.
*/
fun getMockedOutput(svc: DefaultBluePrintRuntimeService):
- ExecutionServiceInput {
+ ExecutionServiceInput {
val stepMetaData: MutableMap<String, JsonNode> = hashMapOf()
stepMetaData.putJsonElement(
"ComponentRemotePythonExecutor", "process"
)
} returns operationOutputs
- val bluePrintRuntimeService = BluePrintMetadataUtils
- .getBluePrintRuntime(
- "123456-1000",
- "./../../../../components/model-" +
- "catalog/blueprint-model/test-blueprint/" +
- "remote_scripts"
- )
+ val bluePrintRuntimeService = BluePrintMetadataUtils.bluePrintRuntime(
+ "123456-1000",
+ "./../../../../components/model-" +
+ "catalog/blueprint-model/test-blueprint/" +
+ "remote_scripts"
+ )
every {
svc.resolveNodeTemplateArtifactDefinition(
"execute-remote-python", "component-script"
*/
package org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.mock
-import io.mockk.every
+import io.mockk.coEvery
import io.mockk.mockk
import org.onap.ccsdk.cds.blueprintsprocessor.db.BluePrintDBLibGenericService
import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintValidatorService
@Bean(name = ["bluePrintRuntimeValidatorService"])
open fun bluePrintRuntimeValidatorService(): BluePrintValidatorService {
val bluePrintValidatorService = mockk<BluePrintValidatorService>()
- every { bluePrintValidatorService.validateBluePrints(any<String>()) } returns true
- every { bluePrintValidatorService.validateBluePrints(any<BluePrintRuntimeService<*>>()) } returns true
+ coEvery { bluePrintValidatorService.validateBluePrints(any<String>()) } returns true
+ coEvery { bluePrintValidatorService.validateBluePrints(any<BluePrintRuntimeService<*>>()) } returns true
return bluePrintValidatorService
}
}
import com.fasterxml.jackson.databind.node.TextNode
import io.mockk.every
import io.mockk.spyk
+import kotlinx.coroutines.runBlocking
import org.junit.Before
import org.junit.Test
import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.ResourceAssignmentRuntimeService
@Before
fun setup() {
- val bluePrintContext = BluePrintMetadataUtils.getBluePrintContext(
- "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration"
- )
+ val bluePrintContext = runBlocking {
+ BluePrintMetadataUtils.getBluePrintContext(
+ "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration"
+ )
+ }
resourceAssignmentRuntimeService = spyk(ResourceAssignmentRuntimeService("1234", bluePrintContext))
id = "ipAddress"
}
- var mapOfPropertiesIpAddress = mutableMapOf<String, PropertyDefinition>()
+ val mapOfPropertiesIpAddress = mutableMapOf<String, PropertyDefinition>()
mapOfPropertiesIpAddress["port"] = propertiesDefinition1
mapOfPropertiesIpAddress["ip"] = propertiesDefinition2
- var mapOfPropertiesHost = mutableMapOf<String, PropertyDefinition>()
+ val mapOfPropertiesHost = mutableMapOf<String, PropertyDefinition>()
mapOfPropertiesHost["name"] = propertiesDefinition3
mapOfPropertiesHost["ipAddress"] = propertiesDefinition4
const val DATA_TYPE_MAP: String = "map"
const val DATA_TYPE_JSON: String = "json"
+ const val BLUEPRINT_TYPE_DEFAULT = "DEFAULT"
+ const val BLUEPRINT_TYPE_KOTLIN_DSL = "KOTLIN_DSL"
+ const val BLUEPRINT_TYPE_GENERIC_SCRIPT = "GENERIC_SCRIPT"
+
const val SCRIPT_KOTLIN = "kotlin"
const val SCRIPT_JYTHON = "jython"
const val SCRIPT_INTERNAL = "internal"
const val METADATA_TEMPLATE_NAME = "template_name"
const val METADATA_TEMPLATE_VERSION = "template_version"
+ const val METADATA_TEMPLATE_TYPE = "template_type"
const val METADATA_TEMPLATE_AUTHOR = "template_author"
const val METADATA_TEMPLATE_TAGS = "template_tags"
const val METADATA_WORKFLOW_NAME = "workflow_name"
lateinit var csarVersion: String
lateinit var createdBy: String
lateinit var entityDefinitions: String
- var templateName: String? = null
- var templateVersion: String? = null
- var templateTags: String? = null
+ lateinit var templateName: String
+ lateinit var templateVersion: String
+ lateinit var templateTags: String
+ var templateType: String = BluePrintConstants.BLUEPRINT_TYPE_DEFAULT
}
interface BluePrintValidatorService {
@Throws(BluePrintException::class)
- fun validateBluePrints(basePath: String): Boolean
+ suspend fun validateBluePrints(basePath: String): Boolean
@Throws(BluePrintException::class)
- fun validateBluePrints(bluePrintRuntimeService: BluePrintRuntimeService<*>): Boolean
+ suspend fun validateBluePrints(bluePrintRuntimeService: BluePrintRuntimeService<*>): Boolean
}
interface BluePrintTypeValidatorService {
"\nCreated-By: <AUTHOR NAME>" +
"\nEntry-Definitions: Definitions/<BLUEPRINT_NAME>.json" +
"\nTemplate-Name: <BLUEPRINT_NAME>" +
- "\nTemplate-Tags: <BLUEPRINT_VERSION>" +
+ "\nTemplate-Version: <BLUEPRINT_VERSION>" +
+ "\nTemplate-Type: <BLUEPRINT_TYPE>" +
"\nTemplate-Tags: <TAGS>"
}
import com.fasterxml.jackson.databind.JsonNode
import kotlinx.coroutines.runBlocking
import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants
+import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException
import org.onap.ccsdk.cds.controllerblueprints.core.asJsonPrimitive
import org.onap.ccsdk.cds.controllerblueprints.core.checkNotEmpty
+import org.onap.ccsdk.cds.controllerblueprints.core.data.ServiceTemplate
import org.onap.ccsdk.cds.controllerblueprints.core.data.ToscaMetaData
import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintDefinitions
import org.onap.ccsdk.cds.controllerblueprints.core.normalizedFile
"Template-Name" -> toscaMetaData.templateName = value
"Template-Version" -> toscaMetaData.templateVersion = value
"Template-Tags" -> toscaMetaData.templateTags = value
+ "Template-Type" -> toscaMetaData.templateType = value
}
}
}
return toscaMetaData
}
- fun getBluePrintRuntime(id: String, blueprintBasePath: String):
- BluePrintRuntimeService<MutableMap<String, JsonNode>> {
+ /** Get the default blueprint runtime for [id] and [blueprintBasePath] */
+ suspend fun getBluePrintRuntime(id: String, blueprintBasePath: String):
+ BluePrintRuntimeService<MutableMap<String, JsonNode>> {
val bluePrintContext: BluePrintContext = getBluePrintContext(blueprintBasePath)
return getBluePrintRuntime(id, bluePrintContext)
}
+ /** Get the default blocking blueprint runtime api for [id] and [blueprintBasePath] used in testing */
+ fun bluePrintRuntime(id: String, blueprintBasePath: String):
+ BluePrintRuntimeService<MutableMap<String, JsonNode>> = runBlocking {
+ val bluePrintContext: BluePrintContext = getBluePrintContext(blueprintBasePath)
+ getBluePrintRuntime(id, bluePrintContext)
+ }
+
+ /** Get the default blueprint runtime from [bluePrintContext] */
fun getBluePrintRuntime(id: String, bluePrintContext: BluePrintContext):
- BluePrintRuntimeService<MutableMap<String, JsonNode>> {
+ BluePrintRuntimeService<MutableMap<String, JsonNode>> {
checkNotEmpty(bluePrintContext.rootPath) { "blueprint context root path is missing." }
checkNotEmpty(bluePrintContext.entryDefinition) { "blueprint context entry definition is missing." }
val blueprintBasePath = bluePrintContext.rootPath
val bluePrintRuntimeService = DefaultBluePrintRuntimeService(id, bluePrintContext)
- bluePrintRuntimeService.put(BluePrintConstants.PROPERTY_BLUEPRINT_BASE_PATH, blueprintBasePath.asJsonPrimitive())
+ bluePrintRuntimeService.put(
+ BluePrintConstants.PROPERTY_BLUEPRINT_BASE_PATH,
+ blueprintBasePath.asJsonPrimitive()
+ )
bluePrintRuntimeService.put(BluePrintConstants.PROPERTY_BLUEPRINT_PROCESS_ID, id.asJsonPrimitive())
return bluePrintRuntimeService
}
+ /** Get the blueprint runtime for enhancement start for [id] and [blueprintBasePath] */
suspend fun getBaseEnhancementBluePrintRuntime(id: String, blueprintBasePath: String):
- BluePrintRuntimeService<MutableMap<String, JsonNode>> {
+ BluePrintRuntimeService<MutableMap<String, JsonNode>> {
val bluePrintContext: BluePrintContext = getBaseEnhancementBluePrintContext(blueprintBasePath)
val bluePrintRuntimeService = DefaultBluePrintRuntimeService(id, bluePrintContext)
- bluePrintRuntimeService.put(BluePrintConstants.PROPERTY_BLUEPRINT_BASE_PATH, blueprintBasePath.asJsonPrimitive())
+ bluePrintRuntimeService.put(
+ BluePrintConstants.PROPERTY_BLUEPRINT_BASE_PATH,
+ blueprintBasePath.asJsonPrimitive()
+ )
bluePrintRuntimeService.put(BluePrintConstants.PROPERTY_BLUEPRINT_PROCESS_ID, id.asJsonPrimitive())
return bluePrintRuntimeService
}
- fun getBluePrintRuntime(id: String, blueprintBasePath: String, executionContext: MutableMap<String, JsonNode>):
- BluePrintRuntimeService<MutableMap<String, JsonNode>> {
+ /** Get the default blueprint runtime for enhancement start for [id], [blueprintBasePath] and [executionContext] */
+ suspend 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 {
return bluePrintRuntimeService
}
- fun getBluePrintContext(blueprintBasePath: String): BluePrintContext = runBlocking {
+ /** Get the default blueprint context for [blueprintBasePath]*/
+ suspend fun getBluePrintContext(blueprintBasePath: String): BluePrintContext {
val toscaMetaData: ToscaMetaData = toscaMetaData(blueprintBasePath)
- log.info("Reading blueprint path($blueprintBasePath) and entry definition file (${toscaMetaData.entityDefinitions})")
+ log.info(
+ "Reading blueprint type(${toscaMetaData.templateType}) path($blueprintBasePath) " +
+ "and entry definition file (${toscaMetaData.entityDefinitions})"
+ )
// If the EntryDefinition is Kotlin file, compile and get Service Template
- if (toscaMetaData.entityDefinitions.endsWith("kt")) {
- readBlueprintKotlinFile(toscaMetaData, blueprintBasePath)
- } else {
- readBlueprintFile(toscaMetaData.entityDefinitions, blueprintBasePath)
+ val bluePrintContext = when (toscaMetaData.templateType.toUpperCase()) {
+ BluePrintConstants.BLUEPRINT_TYPE_KOTLIN_DSL -> readBlueprintKotlinFile(
+ toscaMetaData,
+ blueprintBasePath
+ )
+ BluePrintConstants.BLUEPRINT_TYPE_GENERIC_SCRIPT -> readBlueprintGenericScript(
+ toscaMetaData,
+ blueprintBasePath
+ )
+ BluePrintConstants.BLUEPRINT_TYPE_DEFAULT -> readBlueprintFile(
+ toscaMetaData.entityDefinitions,
+ blueprintBasePath
+ )
+ else ->
+ throw BluePrintException(
+ "Unknown blueprint type(${toscaMetaData.templateType}), " +
+ "It should be any one of these types[${BluePrintConstants.BLUEPRINT_TYPE_KOTLIN_DSL}," +
+ "${BluePrintConstants.BLUEPRINT_TYPE_GENERIC_SCRIPT}, " +
+ "${BluePrintConstants.BLUEPRINT_TYPE_DEFAULT}]"
+ )
}
+ // Copy the metadata info
+ copyMetaInfoToServiceTemplate(toscaMetaData, bluePrintContext.serviceTemplate)
+
+ return bluePrintContext
}
private suspend fun getBaseEnhancementBluePrintContext(blueprintBasePath: String): BluePrintContext {
val toscaMetaData: ToscaMetaData = toscaMetaData(blueprintBasePath)
+
// Clean Type files
BluePrintFileUtils.deleteBluePrintTypes(blueprintBasePath)
val rootFilePath: String = blueprintBasePath.plus(File.separator).plus(toscaMetaData.entityDefinitions)
val rootServiceTemplate = ServiceTemplateUtils.getServiceTemplate(rootFilePath)
+ // Copy the metadata info
+ copyMetaInfoToServiceTemplate(toscaMetaData, rootServiceTemplate)
+
// Clean the Import Definitions
BluePrintFileUtils.cleanImportTypes(rootServiceTemplate)
return blueprintContext
}
+ /** copy metadata defined in [toscaMetaData] to [serviceTemplate] */
+ private fun copyMetaInfoToServiceTemplate(toscaMetaData: ToscaMetaData, serviceTemplate: ServiceTemplate) {
+ if (serviceTemplate.metadata == null) serviceTemplate.metadata = mutableMapOf()
+ val metadata = serviceTemplate.metadata!!
+ metadata[BluePrintConstants.METADATA_TEMPLATE_AUTHOR] = toscaMetaData.createdBy
+ metadata[BluePrintConstants.METADATA_TEMPLATE_NAME] = toscaMetaData.templateName
+ metadata[BluePrintConstants.METADATA_TEMPLATE_VERSION] = toscaMetaData.templateVersion
+ metadata[BluePrintConstants.METADATA_TEMPLATE_TAGS] = toscaMetaData.templateTags
+ metadata[BluePrintConstants.METADATA_TEMPLATE_TYPE] = toscaMetaData.templateType
+ }
+
private suspend fun readBlueprintFile(entityDefinitions: String, basePath: String): BluePrintContext {
val normalizedBasePath = normalizedPathName(basePath)
val rootFilePath = normalizedPathName(normalizedBasePath, entityDefinitions)
val rootServiceTemplate = ServiceTemplateUtils.getServiceTemplate(rootFilePath)
+
// Recursively Import Template files
val schemaImportResolverUtils = BluePrintImportService(rootServiceTemplate, normalizedBasePath)
val completeServiceTemplate = schemaImportResolverUtils.getImportResolvedServiceTemplate()
/** Reade the Service Template Definitions from the Kotlin file */
private suspend fun readBlueprintKotlinFile(toscaMetaData: ToscaMetaData, basePath: String): BluePrintContext {
- checkNotNull(toscaMetaData.templateName) { "couldn't find 'Template-Name' key in TOSCA.meta" }
- checkNotNull(toscaMetaData.templateVersion) { "couldn't find 'Template-Version' key in TOSCA.meta" }
-
val definitionClassName = toscaMetaData.entityDefinitions.removeSuffix(".kt")
val normalizedBasePath = normalizedPathName(basePath)
val bluePrintScriptsService = BluePrintScriptsServiceImpl()
val bluePrintDefinitions = bluePrintScriptsService
.scriptInstance<BluePrintDefinitions>(
- normalizedBasePath, toscaMetaData.templateName!!,
- toscaMetaData.templateVersion!!, definitionClassName, false
+ normalizedBasePath, toscaMetaData.templateName,
+ toscaMetaData.templateVersion, definitionClassName, false
)
// Get the Service Template
val serviceTemplate = bluePrintDefinitions.serviceTemplate()
blueprintContext.otherDefinitions = bluePrintDefinitions.otherDefinitions()
return blueprintContext
}
+
+ /** Reade the Service Template Definitions from the generic script types */
+ private fun readBlueprintGenericScript(toscaMetaData: ToscaMetaData, basePath: String): BluePrintContext {
+ return BluePrintContext(ServiceTemplate())
+ }
}
}
package org.onap.ccsdk.cds.controllerblueprints.core.service
import com.fasterxml.jackson.databind.ObjectMapper
+import kotlinx.coroutines.runBlocking
import org.junit.Test
import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants
import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException
@Test
fun testBluePrintContextCreation() {
- val bluePrintContext = BluePrintMetadataUtils.getBluePrintContext(blueprintBasePath)
- assertNotNull(bluePrintContext, "Failed to populate Blueprint context")
+ runBlocking {
+ val bluePrintContext = BluePrintMetadataUtils.getBluePrintContext(blueprintBasePath)
+ assertNotNull(bluePrintContext, "Failed to populate Blueprint context")
+ }
}
@Test
fun testChainedProperty() {
- val bluePrintContext = BluePrintMetadataUtils.getBluePrintContext(blueprintBasePath)
- val nodeType = bluePrintContext.nodeTypeChained("component-resource-resolution")
- assertNotNull(nodeType, "Failed to get chained node type")
- log.trace("Properties {}", JacksonUtils.getJson(nodeType, true))
+ runBlocking {
+ val bluePrintContext = BluePrintMetadataUtils.getBluePrintContext(blueprintBasePath)
+ val nodeType = bluePrintContext.nodeTypeChained("component-resource-resolution")
+ assertNotNull(nodeType, "Failed to get chained node type")
+ log.trace("Properties {}", JacksonUtils.getJson(nodeType, true))
+ }
}
@Test
)
val assignmentParams = "{\n" +
- " \"ipAddress\": \"127.0.0.1\",\n" +
- " \"hostName\": \"vnf-host\"\n" +
- " }"
+ " \"ipAddress\": \"127.0.0.1\",\n" +
+ " \"hostName\": \"vnf-host\"\n" +
+ " }"
bluePrintRuntimeService.setNodeTemplateAttributeValue(
"resource-assignment", "assignment-params",
"netconf"
)
assertNotNull(capProperties, "Failed to populate capability property values")
- assertEquals(capProperties["target-ip-address"], "127.0.0.1".asJsonPrimitive(), "Failed to populate parameter target-ip-address")
- assertEquals(capProperties["port-number"], JacksonUtils.jsonNodeFromObject(830), "Failed to populate parameter port-number")
+ assertEquals(
+ capProperties["target-ip-address"],
+ "127.0.0.1".asJsonPrimitive(),
+ "Failed to populate parameter target-ip-address"
+ )
+ assertEquals(
+ capProperties["port-number"],
+ JacksonUtils.jsonNodeFromObject(830),
+ "Failed to populate parameter port-number"
+ )
}
@Test
)
assertNotNull(inContext, "Failed to populate interface input property values")
- assertEquals(inContext["action-name"], JacksonUtils.jsonNodeFromObject("sample-action"), "Failed to populate parameter action-name")
- assertEquals(inContext["request-id"], JacksonUtils.jsonNodeFromObject("12345"), "Failed to populate parameter action-name")
+ assertEquals(
+ inContext["action-name"],
+ JacksonUtils.jsonNodeFromObject("sample-action"),
+ "Failed to populate parameter action-name"
+ )
+ assertEquals(
+ inContext["request-id"],
+ JacksonUtils.jsonNodeFromObject("12345"),
+ "Failed to populate parameter action-name"
+ )
}
@Test
val bluePrintRuntimeService = getBluePrintRuntimeService()
- bluePrintRuntimeService.setNodeTemplateAttributeValue("resource-assignment", "assignment-params", NullNode.getInstance())
+ bluePrintRuntimeService.setNodeTemplateAttributeValue(
+ "resource-assignment",
+ "assignment-params",
+ NullNode.getInstance()
+ )
bluePrintRuntimeService.resolveNodeTemplateInterfaceOperationOutputs(
"resource-assignment",
"resource-assignment",
"ResourceResolutionComponent", "process", "resource-assignment-params"
)
- assertEquals(NullNode.getInstance(), outputParams, "Failed to get operation property resource-assignment-params")
+ assertEquals(
+ NullNode.getInstance(),
+ outputParams,
+ "Failed to get operation property resource-assignment-params"
+ )
}
@Test
val keys = listOf("context1", "context2")
- val jsonValueNode = bluePrintRuntimeService.getJsonForNodeTemplateAttributeProperties("resource-assignment-ra-component", keys)
+ val jsonValueNode =
+ bluePrintRuntimeService.getJsonForNodeTemplateAttributeProperties("resource-assignment-ra-component", keys)
assertNotNull(jsonValueNode, "Failed to get Json for Node Template Context Properties")
log.info("JSON Prepared Value Context {}", jsonValueNode)
}
private fun getBluePrintRuntimeService(): BluePrintRuntimeService<MutableMap<String, JsonNode>> {
val blueprintBasePath = normalizedPathName(TestConstants.PATH_TEST_BLUEPRINTS_BASECONFIG)
- val blueprintRuntime = BluePrintMetadataUtils.getBluePrintRuntime("1234", blueprintBasePath)
+ val blueprintRuntime = BluePrintMetadataUtils.bluePrintRuntime("1234", blueprintBasePath)
val checkProcessId = blueprintRuntime.get(BluePrintConstants.PROPERTY_BLUEPRINT_PROCESS_ID)
val checkBasePath = blueprintRuntime.get(BluePrintConstants.PROPERTY_BLUEPRINT_BASE_PATH)
@BeforeTest
fun setup() {
val blueprintBasePath = TestConstants.PATH_TEST_BLUEPRINTS_BASECONFIG
- blueprintRuntime = BluePrintMetadataUtils.getBluePrintRuntime("1234", blueprintBasePath)
+ blueprintRuntime = BluePrintMetadataUtils.bluePrintRuntime("1234", blueprintBasePath)
}
@Test
@Test
fun testKotlinBluePrintContext() {
- val path = normalizedPathName("src/test/resources/compile")
- val blueprintContext = BluePrintMetadataUtils.getBluePrintContext(path)
- assertNotNull(blueprintContext, "failed to get blueprint context")
- assertNotNull(blueprintContext.serviceTemplate, "failed to get blueprint context service template")
- assertNotNull(blueprintContext.serviceTemplate, "failed to get blueprint context service template")
- assertNotNull(blueprintContext.otherDefinitions, "failed to get blueprint contextother definitions")
+ runBlocking {
+ val path = normalizedPathName("src/test/resources/compile")
+ val blueprintContext = BluePrintMetadataUtils.getBluePrintContext(path)
+ assertNotNull(blueprintContext, "failed to get blueprint context")
+ assertNotNull(blueprintContext.serviceTemplate, "failed to get blueprint context service template")
+ assertNotNull(blueprintContext.serviceTemplate, "failed to get blueprint context service template")
+ assertNotNull(blueprintContext.otherDefinitions, "failed to get blueprint contextother definitions")
- var cachePresent = BluePrintCompileCache.hasClassLoader(path)
- assertTrue(cachePresent, "failed to generate cache key ($path)")
+ var cachePresent = BluePrintCompileCache.hasClassLoader(path)
+ assertTrue(cachePresent, "failed to generate cache key ($path)")
- /** Cleaning Cache */
- BluePrintCompileCache.cleanClassLoader(path)
- cachePresent = BluePrintCompileCache.hasClassLoader(path)
- assertTrue(!cachePresent, "failed to remove cache key ($path)")
+ /** Cleaning Cache */
+ BluePrintCompileCache.cleanClassLoader(path)
+ cachePresent = BluePrintCompileCache.hasClassLoader(path)
+ assertTrue(!cachePresent, "failed to remove cache key ($path)")
+ }
}
@Test
CSAR-Version: 1.0
Created-By: Brinda Santh <brindasanth@in.ibm.com>
Entry-Definitions: cba.scripts.ActivateBlueprintDefinitions.kt
-Template-Tags: Brinda Santh, activation-blueprint
Template-Name: activate-blueprint
Template-Version: 1.0.0
+Template-Type: KOTLIN_DSL
+Template-Tags: Brinda Santh, activation-blueprint
private val log = LoggerFactory.getLogger(BluePrintDesignTimeValidatorService::class.toString())
- override fun validateBluePrints(basePath: String): Boolean {
+ override suspend fun validateBluePrints(basePath: String): Boolean {
val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime(UUID.randomUUID().toString(), basePath)
return validateBluePrints(bluePrintRuntimeService)
}
- override fun validateBluePrints(bluePrintRuntimeService: BluePrintRuntimeService<*>): Boolean {
+ override suspend fun validateBluePrints(bluePrintRuntimeService: BluePrintRuntimeService<*>): Boolean {
bluePrintTypeValidatorService.validateServiceTemplate(
bluePrintRuntimeService, "service_template",
if (resourceDefinitionFile.exists()) {
val resourceDefinitionMap = JacksonUtils.getMapFromFile(resourceDefinitionFile, ResourceDefinition::class.java)
- resourceDefinitionMap?.forEach { resourceDefinitionName, resourceDefinition ->
+ resourceDefinitionMap.forEach { resourceDefinitionName, resourceDefinition ->
resourceDefinitionValidator.validate(bluePrintRuntimeService, resourceDefinitionName, resourceDefinition)
}
}
import io.mockk.every
import io.mockk.mockk
+import kotlinx.coroutines.runBlocking
import org.junit.Test
import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintError
import org.onap.ccsdk.cds.controllerblueprints.core.data.NodeTemplate
class BluePrintDesignTimeValidatorServiceTest {
private val blueprintBasePath = "./../../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration"
- private val bluePrintRuntime = BluePrintMetadataUtils.getBluePrintRuntime("1234", blueprintBasePath)
+ private val bluePrintRuntime = BluePrintMetadataUtils.bluePrintRuntime("1234", blueprintBasePath)
private val mockBluePrintTypeValidatorService = MockBluePrintTypeValidatorService()
private val resourceDefinitionValidator = mockk<ResourceDefinitionValidator>()
- private val defaultBluePrintValidatorService = BluePrintDesignTimeValidatorService(mockBluePrintTypeValidatorService, resourceDefinitionValidator)
+ private val defaultBluePrintValidatorService =
+ BluePrintDesignTimeValidatorService(mockBluePrintTypeValidatorService, resourceDefinitionValidator)
private val workflowValidator = BluePrintWorkflowValidatorImpl(mockBluePrintTypeValidatorService)
@Test
fun testValidateOfType() {
- every { resourceDefinitionValidator.validate(bluePrintRuntime, any(), any()) } returns Unit
+ runBlocking {
+ every { resourceDefinitionValidator.validate(bluePrintRuntime, any(), any()) } returns Unit
- val valid = defaultBluePrintValidatorService.validateBluePrints(bluePrintRuntime)
- assertTrue(valid, "failed in blueprint Validation")
+ val valid = defaultBluePrintValidatorService.validateBluePrints(bluePrintRuntime)
+ assertTrue(valid, "failed in blueprint Validation")
+ }
}
@Test
assertEquals(1, bluePrintRuntime.getBluePrintError().errors.size)
assertEquals(
"Failed to validate Workflow(resource-assignment)'s step(test)'s definition : " +
- "resource-assignment/steps/test : NodeType(TestNodeType) derived from is 'tosca.nodes.TEST', " +
- "Expected 'tosca.nodes.Workflow' or 'tosca.nodes.Component'", bluePrintRuntime.getBluePrintError().errors[0]
+ "resource-assignment/steps/test : NodeType(TestNodeType) derived from is 'tosca.nodes.TEST', " +
+ "Expected 'tosca.nodes.Workflow' or 'tosca.nodes.Component'",
+ bluePrintRuntime.getBluePrintError().errors[0]
)
}
@Test
fun testValidateWorkflowSuccess() {
val workflowName = "resource-assignment"
- workflowValidator.validate(bluePrintRuntime, workflowName, bluePrintRuntime.bluePrintContext().workflowByName(workflowName))
+ workflowValidator.validate(
+ bluePrintRuntime,
+ workflowName,
+ bluePrintRuntime.bluePrintContext().workflowByName(workflowName)
+ )
}
}
import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.service.BlueprintCatalogServiceImpl
import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.service.BlueprintProcessorCatalogServiceImpl
import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants
+import org.onap.ccsdk.cds.controllerblueprints.core.compress
import org.onap.ccsdk.cds.controllerblueprints.core.deleteDir
import org.onap.ccsdk.cds.controllerblueprints.core.normalizedFile
import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintRuntimeService
@BeforeTest
fun setup() {
+
deleteDir("target", "blueprints")
- bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime(
+
+ // Create sample CBA zip
+ normalizedFile("./../../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration")
+ .compress(normalizedFile("./target/blueprints/generated-cba.zip"))
+
+ bluePrintRuntimeService = BluePrintMetadataUtils.bluePrintRuntime(
blueprintId,
"./../../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration"
)
@Test
fun `test catalog service`() {
- // TODO: I thing this test function should be remve and replace by the other one.
- runBlocking {
- // FIXME("Create ZIP from test blueprints")
- val file = normalizedFile("./src/test/resources/test-cba.zip")
+ runBlocking {
+ val file = normalizedFile("./target/blueprints/generated-cba.zip")
assertTrue(file.exists(), "couldn't get file ${file.absolutePath}")
blueprintsProcessorCatalogService.saveToDatabase("1234", file)
@Test
fun `test save function`() {
runBlocking {
- val file = normalizedFile("./src/test/resources/test-cba.zip")
+ val file = normalizedFile("./target/blueprints/generated-cba.zip")
assertTrue(file.exists(), "couldnt get file ${file.absolutePath}")
val metadata = bluePrintRuntimeService.bluePrintContext().metadata!!
metadata[BluePrintConstants.PROPERTY_BLUEPRINT_PROCESS_ID] = blueprintId
@Test
fun `test get function`() {
runBlocking {
- val file = normalizedFile("./src/test/resources/test-cba.zip")
+ val file = normalizedFile("./target/blueprints/generated-cba.zip")
assertTrue(file.exists(), "couldnt get file ${file.absolutePath}")
val metadata = bluePrintRuntimeService.bluePrintContext().metadata!!
metadata[BluePrintConstants.PROPERTY_BLUEPRINT_PROCESS_ID] = blueprintId
assertTrue(
File(
blueprintCoreConfiguration.bluePrintLoadConfiguration().blueprintArchivePath +
- "/baseconfiguration"
+ "/baseconfiguration"
).deleteRecursively(), "Couldn't get blueprint archive " +
- "${blueprintCoreConfiguration.bluePrintLoadConfiguration().blueprintArchivePath}/baseconfiguration " +
- "from data base."
+ "${blueprintCoreConfiguration.bluePrintLoadConfiguration().blueprintArchivePath}/baseconfiguration " +
+ "from data base."
)
}
*/
package org.onap.ccsdk.cds.blueprintsprocessor.db.mock
-import io.mockk.every
+import io.mockk.coEvery
import io.mockk.mockk
import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintValidatorService
import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintRuntimeService
@Bean(name = ["bluePrintRuntimeValidatorService"])
open fun bluePrintRuntimeValidatorService(): BluePrintValidatorService {
val bluePrintValidatorService = mockk<BluePrintValidatorService>()
- every { bluePrintValidatorService.validateBluePrints(any<String>()) } returns true
- every { bluePrintValidatorService.validateBluePrints(any<BluePrintRuntimeService<*>>()) } returns true
+ coEvery { bluePrintValidatorService.validateBluePrints(any<String>()) } returns true
+ coEvery { bluePrintValidatorService.validateBluePrints(any<BluePrintRuntimeService<*>>()) } returns true
return bluePrintValidatorService
}
}
import org.onap.ccsdk.cds.controllerblueprints.common.api.ActionIdentifiers
import org.onap.ccsdk.cds.controllerblueprints.common.api.CommonHeader
import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants
+import org.onap.ccsdk.cds.controllerblueprints.core.compress
import org.onap.ccsdk.cds.controllerblueprints.core.deleteDir
import org.onap.ccsdk.cds.controllerblueprints.core.normalizedFile
import org.onap.ccsdk.cds.controllerblueprints.management.api.BluePrintBootstrapInput
@BeforeTest
fun init() {
+
+ deleteDir("target", "blueprints")
+
+ // Create sample CBA zip
+ normalizedFile("./../../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration")
+ .compress(normalizedFile("./target/blueprints/generated-cba.zip"))
+
// Create a server, add service, start, and register for automatic graceful shutdown.
grpcServerRule.serviceRegistry.addService(bluePrintManagementGRPCHandler)
- deleteDir("target", "blueprints")
}
@AfterTest
val bootstrapOutput = blockingStub.bootstrapBlueprint(req)
assertEquals(200, bootstrapOutput.status.code)
assertTrue(
- bootstrapOutput.status.message.contentEquals(BluePrintConstants.STATUS_SUCCESS),
+ bootstrapOutput.status.message!!.contentEquals(BluePrintConstants.STATUS_SUCCESS),
"failed to get success status"
)
assertEquals(id, bootstrapOutput.commonHeader.requestId)
assertEquals(200, output.status.code)
assertTrue(
- output.status.message.contentEquals(BluePrintConstants.STATUS_SUCCESS),
+ output.status.message!!.contentEquals(BluePrintConstants.STATUS_SUCCESS),
"failed to get success status"
)
assertEquals(id, output.commonHeader.requestId)
val downloadOutput = blockingStub.downloadBlueprint(downloadReq)
assertEquals(200, downloadOutput.status.code)
assertTrue(
- downloadOutput.status.message.contentEquals(BluePrintConstants.STATUS_SUCCESS),
+ downloadOutput.status.message!!.contentEquals(BluePrintConstants.STATUS_SUCCESS),
"failed to get success status"
)
assertNotNull(downloadOutput.fileChunk?.chunk, "failed to get cba file chunks")
var output = blockingStub.uploadBlueprint(req)
assertEquals(200, output.status.code)
assertTrue(
- output.status.message.contentEquals(BluePrintConstants.STATUS_SUCCESS),
+ output.status.message!!.contentEquals(BluePrintConstants.STATUS_SUCCESS),
"failed to get success status"
)
assertEquals(id, output.commonHeader.requestId)
}
private fun createUploadInputRequest(id: String, action: String): BluePrintUploadInput {
- val file = normalizedFile("./src/test/resources/test-cba.zip")
+ val file = normalizedFile("./target/blueprints/generated-cba.zip")
assertTrue(file.exists(), "couldnt get file ${file.absolutePath}")
val commonHeader = CommonHeader
resourceDictionaryLoadService.loadPathsResourceDictionary(dictPaths)
testBaseConfigEnhancementAndValidation()
- testVFWEnhancementAndValidation()
testGoldenEnhancementAndValidation()
testRemoteScriptsEnhancementAndValidation()
testCapabilityCliEnhancementAndValidation()
}
}
- fun testBaseConfigEnhancementAndValidation() {
+ private fun testBaseConfigEnhancementAndValidation() {
val basePath = "./../../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration"
testComponentInvokeEnhancementAndValidation(basePath, "base-enhance")
}
- fun testVFWEnhancementAndValidation() {
- val basePath = "./../../../../../components/model-catalog/blueprint-model/service-blueprint/vFW"
- testComponentInvokeEnhancementAndValidation(basePath, "vFW-enhance")
- }
-
- fun testGoldenEnhancementAndValidation() {
+ private fun testGoldenEnhancementAndValidation() {
val basePath = "./../../../../../components/model-catalog/blueprint-model/test-blueprint/golden"
testComponentInvokeEnhancementAndValidation(basePath, "golden-enhance")
}
- fun testRemoteScriptsEnhancementAndValidation() {
+ private fun testRemoteScriptsEnhancementAndValidation() {
val basePath = "./../../../../../components/model-catalog/blueprint-model/test-blueprint/remote_scripts"
testComponentInvokeEnhancementAndValidation(basePath, "remote_scripts-enhance")
}
- fun testCapabilityCliEnhancementAndValidation() {
+ private fun testCapabilityCliEnhancementAndValidation() {
val basePath = "./../../../../../components/model-catalog/blueprint-model/test-blueprint/capability_cli"
testComponentInvokeEnhancementAndValidation(basePath, "capability_cli-enhance")
}
Assert.assertTrue("blueprint($basePath) validation failed ", valid)
// Enable this to get the enhanced zip file
- // val compressFile = normalizedFile("target/blueprints/enrichment", "$targetDirName.zip")
- // normalizedFile(targetPath).compress(compressFile)
+ // val compressFile = normalizedFile("target/blueprints/enrichment", "$targetDirName.zip")
+ // normalizedFile(targetPath).compress(compressFile)
deleteDir(targetPath)
}
import org.junit.runner.RunWith
import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintCoreConfiguration
import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput
+import org.onap.ccsdk.cds.controllerblueprints.core.compress
import org.onap.ccsdk.cds.controllerblueprints.core.deleteDir
import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintCatalogService
import org.onap.ccsdk.cds.controllerblueprints.core.normalizedFile
@BeforeTest
fun init() {
deleteDir("target", "blueprints")
+
+ // Create sample CBA zip
+ normalizedFile("./../../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration")
+ .compress(normalizedFile("./target/blueprints/generated-cba.zip"))
}
@AfterTest
}
private fun loadTestCbaFile(): File {
- val testCbaFile = normalizedFile("./src/test/resources/test-cba.zip")
+ val testCbaFile = normalizedFile("./target/blueprints/generated-cba.zip")
assertTrue(testCbaFile.exists(), "couldn't get file ${testCbaFile.absolutePath}")
return testCbaFile
}
package org.onap.ccsdk.cds.blueprintsprocessor.selfservice.api.validation
+import kotlinx.coroutines.runBlocking
import org.junit.Test
import org.junit.runner.RunWith
import org.onap.ccsdk.cds.blueprintsprocessor.selfservice.api.mock.MockResourceSource
@Test
fun testBlueprintRuntimeValidation() {
- val blueprintBasePath =
- "./../../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration"
- assertNotNull(bluePrintRuntimeValidatorService, " failed to initilize bluePrintRuntimeValidatorService")
+ runBlocking {
+ val blueprintBasePath =
+ "./../../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration"
+ assertNotNull(bluePrintRuntimeValidatorService, " failed to initilize bluePrintRuntimeValidatorService")
- bluePrintRuntimeValidatorService.validateBluePrints(blueprintBasePath)
+ bluePrintRuntimeValidatorService.validateBluePrints(blueprintBasePath)
+ }
}
}