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.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.interfaces.BluePrintDefinitions
import org.onap.ccsdk.cds.controllerblueprints.core.normalizedFile
import org.onap.ccsdk.cds.controllerblueprints.core.normalizedPathName
import org.onap.ccsdk.cds.controllerblueprints.core.readNBLines
-import org.onap.ccsdk.cds.controllerblueprints.core.scripts.BlueprintScriptsServiceImpl
-import org.onap.ccsdk.cds.controllerblueprints.core.service.BlueprintContext
-import org.onap.ccsdk.cds.controllerblueprints.core.service.BlueprintImportService
-import org.onap.ccsdk.cds.controllerblueprints.core.service.BlueprintRuntimeService
-import org.onap.ccsdk.cds.controllerblueprints.core.service.DefaultBlueprintRuntimeService
+import org.onap.ccsdk.cds.controllerblueprints.core.scripts.BluePrintScriptsServiceImpl
+import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintContext
+import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintImportService
+import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintRuntimeService
+import org.onap.ccsdk.cds.controllerblueprints.core.service.DefaultBluePrintRuntimeService
import org.slf4j.LoggerFactory
import java.io.File
import java.util.Properties
-class BlueprintMetadataUtils {
+class BluePrintMetadataUtils {
companion object {
private val log = LoggerFactory.getLogger(this::class.toString())
suspend fun toscaMetaData(basePath: String): ToscaMetaData {
- val toscaMetaPath = basePath.plus(BlueprintConstants.PATH_DIVIDER)
- .plus(BlueprintConstants.TOSCA_METADATA_ENTRY_DEFINITION_FILE)
+ val toscaMetaPath = basePath.plus(BluePrintConstants.PATH_DIVIDER)
+ .plus(BluePrintConstants.TOSCA_METADATA_ENTRY_DEFINITION_FILE)
return toscaMetaDataFromMetaFile(toscaMetaPath)
}
suspend fun entryDefinitionFile(basePath: String): String {
- val toscaMetaPath = basePath.plus(BlueprintConstants.PATH_DIVIDER)
- .plus(BlueprintConstants.TOSCA_METADATA_ENTRY_DEFINITION_FILE)
+ val toscaMetaPath = basePath.plus(BluePrintConstants.PATH_DIVIDER)
+ .plus(BluePrintConstants.TOSCA_METADATA_ENTRY_DEFINITION_FILE)
return toscaMetaDataFromMetaFile(toscaMetaPath).entityDefinitions
}
fun bluePrintEnvProperties(basePath: String): Properties {
val blueprintsEnvFilePath = basePath.plus(File.separator)
- .plus(BlueprintConstants.TOSCA_ENVIRONMENTS_DIR)
+ .plus(BluePrintConstants.TOSCA_ENVIRONMENTS_DIR)
return environmentFileProperties(blueprintsEnvFilePath)
}
}
/** 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)
+ 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)
+ 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>> {
+ fun getBluePrintRuntime(id: String, bluePrintContext: BluePrintContext):
+ 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)
+ val bluePrintRuntimeService = DefaultBluePrintRuntimeService(id, bluePrintContext)
bluePrintRuntimeService.put(
- BlueprintConstants.PROPERTY_BLUEPRINT_BASE_PATH,
+ BluePrintConstants.PROPERTY_BLUEPRINT_BASE_PATH,
blueprintBasePath.asJsonPrimitive()
)
- bluePrintRuntimeService.put(BlueprintConstants.PROPERTY_BLUEPRINT_PROCESS_ID, id.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>> {
+ suspend fun getBaseEnhancementBluePrintRuntime(id: String, blueprintBasePath: String):
+ BluePrintRuntimeService<MutableMap<String, JsonNode>> {
- val bluePrintContext: BlueprintContext = getBaseEnhancementBlueprintContext(blueprintBasePath)
+ val bluePrintContext: BluePrintContext = getBaseEnhancementBluePrintContext(blueprintBasePath)
- val bluePrintRuntimeService = DefaultBlueprintRuntimeService(id, bluePrintContext)
+ val bluePrintRuntimeService = DefaultBluePrintRuntimeService(id, bluePrintContext)
bluePrintRuntimeService.put(
- BlueprintConstants.PROPERTY_BLUEPRINT_BASE_PATH,
+ BluePrintConstants.PROPERTY_BLUEPRINT_BASE_PATH,
blueprintBasePath.asJsonPrimitive()
)
- bluePrintRuntimeService.put(BlueprintConstants.PROPERTY_BLUEPRINT_PROCESS_ID, id.asJsonPrimitive())
+ bluePrintRuntimeService.put(BluePrintConstants.PROPERTY_BLUEPRINT_PROCESS_ID, id.asJsonPrimitive())
return bluePrintRuntimeService
}
/** Get the default blueprint runtime for enhancement start for [id], [blueprintBasePath] and [executionContext] */
- suspend fun getBlueprintRuntime(
+ 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)
+ BluePrintRuntimeService<MutableMap<String, JsonNode>> {
+ val bluePrintContext: BluePrintContext = getBluePrintContext(blueprintBasePath)
+ val bluePrintRuntimeService = DefaultBluePrintRuntimeService(id, bluePrintContext)
executionContext.forEach {
bluePrintRuntimeService.put(it.key, it.value)
}
}
/** Get the default blueprint context for [blueprintBasePath]*/
- suspend fun getBlueprintContext(blueprintBasePath: String): BlueprintContext {
+ suspend fun getBluePrintContext(blueprintBasePath: String): BluePrintContext {
val toscaMetaData: ToscaMetaData = toscaMetaData(blueprintBasePath)
// If the EntryDefinition is Kotlin file, compile and get Service Template
val bluePrintContext = when (toscaMetaData.templateType.toUpperCase()) {
- BlueprintConstants.BLUEPRINT_TYPE_KOTLIN_DSL -> readBlueprintKotlinFile(
+ BluePrintConstants.BLUEPRINT_TYPE_KOTLIN_DSL -> readBlueprintKotlinFile(
toscaMetaData,
blueprintBasePath
)
- BlueprintConstants.BLUEPRINT_TYPE_GENERIC_SCRIPT -> readBlueprintGenericScript(
+ BluePrintConstants.BLUEPRINT_TYPE_GENERIC_SCRIPT -> readBlueprintGenericScript(
toscaMetaData,
blueprintBasePath
)
- BlueprintConstants.BLUEPRINT_TYPE_DEFAULT -> readBlueprintFile(
+ BluePrintConstants.BLUEPRINT_TYPE_DEFAULT -> readBlueprintFile(
toscaMetaData.entityDefinitions,
blueprintBasePath
)
else ->
- throw BlueprintException(
+ 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}]"
+ "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
return bluePrintContext
}
- private suspend fun getBaseEnhancementBlueprintContext(blueprintBasePath: String): BlueprintContext {
+ private suspend fun getBaseEnhancementBluePrintContext(blueprintBasePath: String): BluePrintContext {
val toscaMetaData: ToscaMetaData = toscaMetaData(blueprintBasePath)
// Clean Type files
- BlueprintFileUtils.deleteBlueprintTypes(blueprintBasePath)
+ BluePrintFileUtils.deleteBluePrintTypes(blueprintBasePath)
val rootFilePath: String = blueprintBasePath.plus(File.separator).plus(toscaMetaData.entityDefinitions)
val rootServiceTemplate = ServiceTemplateUtils.getServiceTemplate(rootFilePath)
copyMetaInfoToServiceTemplate(toscaMetaData, rootServiceTemplate)
// Clean the Import Definitions
- BlueprintFileUtils.cleanImportTypes(rootServiceTemplate)
+ BluePrintFileUtils.cleanImportTypes(rootServiceTemplate)
- val blueprintContext = BlueprintContext(rootServiceTemplate)
+ val blueprintContext = BluePrintContext(rootServiceTemplate)
blueprintContext.rootPath = blueprintBasePath
blueprintContext.entryDefinition = toscaMetaData.entityDefinitions
return blueprintContext
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
+ 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 {
+ 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 schemaImportResolverUtils = BluePrintImportService(rootServiceTemplate, normalizedBasePath)
val completeServiceTemplate = schemaImportResolverUtils.getImportResolvedServiceTemplate()
- val blueprintContext = BlueprintContext(completeServiceTemplate)
+ val blueprintContext = BluePrintContext(completeServiceTemplate)
blueprintContext.rootPath = normalizedBasePath
blueprintContext.entryDefinition = entityDefinitions
return blueprintContext
}
/** Reade the Service Template Definitions from the Kotlin file */
- private suspend fun readBlueprintKotlinFile(toscaMetaData: ToscaMetaData, basePath: String): BlueprintContext {
+ private suspend fun readBlueprintKotlinFile(toscaMetaData: ToscaMetaData, basePath: String): BluePrintContext {
val definitionClassName = toscaMetaData.entityDefinitions.removeSuffix(".kt")
val normalizedBasePath = normalizedPathName(basePath)
- val bluePrintScriptsService = BlueprintScriptsServiceImpl()
+ val bluePrintScriptsService = BluePrintScriptsServiceImpl()
val bluePrintDefinitions = bluePrintScriptsService
- .scriptInstance<BlueprintDefinitions>(
+ .scriptInstance<BluePrintDefinitions>(
normalizedBasePath, toscaMetaData.templateName,
toscaMetaData.templateVersion, definitionClassName, false
)
val serviceTemplate = bluePrintDefinitions.serviceTemplate()
// Clean the Default type import Definitions
- BlueprintFileUtils.cleanImportTypes(serviceTemplate)
+ BluePrintFileUtils.cleanImportTypes(serviceTemplate)
- val blueprintContext = BlueprintContext(serviceTemplate)
+ val blueprintContext = BluePrintContext(serviceTemplate)
blueprintContext.rootPath = normalizedBasePath
blueprintContext.entryDefinition = toscaMetaData.entityDefinitions
blueprintContext.otherDefinitions = bluePrintDefinitions.otherDefinitions()
}
/** Reade the Service Template Definitions from the generic script types */
- private fun readBlueprintGenericScript(toscaMetaData: ToscaMetaData, basePath: String): BlueprintContext {
- return BlueprintContext(ServiceTemplate())
+ private fun readBlueprintGenericScript(toscaMetaData: ToscaMetaData, basePath: String): BluePrintContext {
+ return BluePrintContext(ServiceTemplate())
}
}
}