import kotlinx.coroutines.runBlocking
import org.apache.commons.io.FileUtils
import org.apache.commons.lang3.StringUtils
-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.data.ErrorCode
import org.onap.ccsdk.cds.controllerblueprints.core.data.ImportDefinition
import org.onap.ccsdk.cds.controllerblueprints.core.data.ServiceTemplate
import org.onap.ccsdk.cds.controllerblueprints.core.normalizedFile
import org.onap.ccsdk.cds.controllerblueprints.core.normalizedPathName
-import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintContext
+import org.onap.ccsdk.cds.controllerblueprints.core.service.BlueprintContext
import org.slf4j.LoggerFactory
import java.io.File
import java.io.FileFilter
import java.nio.file.Paths
import java.nio.file.StandardOpenOption
-class BluePrintFileUtils {
+class BlueprintFileUtils {
companion object {
const val COMPILED_JAR_SUFFIX = "cba-kts.jar"
private val log = LoggerFactory.getLogger(this::class.toString())
- fun createEmptyBluePrint(basePath: String) {
+ fun createEmptyBlueprint(basePath: String) {
val blueprintDir = File(basePath)
FileUtils.deleteDirectory(blueprintDir)
Files.createDirectories(blueprintDir.toPath())
- val metaDataDir = File(blueprintDir.absolutePath.plus(File.separator).plus(BluePrintConstants.TOSCA_METADATA_DIR))
+ val metaDataDir = File(blueprintDir.absolutePath.plus(File.separator).plus(BlueprintConstants.TOSCA_METADATA_DIR))
Files.createDirectories(metaDataDir.toPath())
val metaFile = File(
blueprintDir.absolutePath.plus(File.separator).plus(
- BluePrintConstants
+ BlueprintConstants
.TOSCA_METADATA_ENTRY_DEFINITION_FILE
)
)
Files.write(metaFile.toPath(), getMetaDataContent().toByteArray(), StandardOpenOption.CREATE_NEW)
- val definitionsDir = File(blueprintDir.absolutePath.plus(File.separator).plus(BluePrintConstants.TOSCA_DEFINITIONS_DIR))
+ val definitionsDir = File(blueprintDir.absolutePath.plus(File.separator).plus(BlueprintConstants.TOSCA_DEFINITIONS_DIR))
Files.createDirectories(definitionsDir.toPath())
- val scriptsDir = File(blueprintDir.absolutePath.plus(File.separator).plus(BluePrintConstants.TOSCA_SCRIPTS_DIR))
+ val scriptsDir = File(blueprintDir.absolutePath.plus(File.separator).plus(BlueprintConstants.TOSCA_SCRIPTS_DIR))
Files.createDirectories(scriptsDir.toPath())
- val plansDir = File(blueprintDir.absolutePath.plus(File.separator).plus(BluePrintConstants.TOSCA_PLANS_DIR))
+ val plansDir = File(blueprintDir.absolutePath.plus(File.separator).plus(BlueprintConstants.TOSCA_PLANS_DIR))
Files.createDirectories(plansDir.toPath())
- val templatesDir = File(blueprintDir.absolutePath.plus(File.separator).plus(BluePrintConstants.TOSCA_TEMPLATES_DIR))
+ val templatesDir = File(blueprintDir.absolutePath.plus(File.separator).plus(BlueprintConstants.TOSCA_TEMPLATES_DIR))
Files.createDirectories(templatesDir.toPath())
}
- fun copyBluePrint(sourcePath: String, targetPath: String) {
+ fun copyBlueprint(sourcePath: String, targetPath: String) {
val sourceFile = File(sourcePath)
val targetFile = File(targetPath)
sourceFile.copyRecursively(targetFile, true)
}
- fun deleteBluePrintTypes(basePath: String) {
- val definitionPath = basePath.plus(File.separator).plus(BluePrintConstants.TOSCA_DEFINITIONS_DIR)
+ fun deleteBlueprintTypes(basePath: String) {
+ val definitionPath = basePath.plus(File.separator).plus(BlueprintConstants.TOSCA_DEFINITIONS_DIR)
log.info("deleting definition types under : $definitionPath")
val definitionDir = File(definitionPath)
}
}
- fun writeEnhancedBluePrint(blueprintContext: BluePrintContext) {
+ fun writeEnhancedBlueprint(blueprintContext: BlueprintContext) {
// Write Blueprint Types
- writeBluePrintTypes(blueprintContext)
+ writeBlueprintTypes(blueprintContext)
// Re Populate the Imports
populateDefaultImports(blueprintContext)
// Rewrite the Entry Definition Files
writeEntryDefinitionFile(blueprintContext)
}
- fun writeBluePrintTypes(blueprintContext: BluePrintContext) {
+ fun writeBlueprintTypes(blueprintContext: BlueprintContext) {
val basePath = blueprintContext.rootPath
- val definitionPath = basePath.plus(File.separator).plus(BluePrintConstants.TOSCA_DEFINITIONS_DIR)
+ val definitionPath = basePath.plus(File.separator).plus(BlueprintConstants.TOSCA_DEFINITIONS_DIR)
val definitionDir = File(definitionPath)
check(definitionDir.exists()) {
- throw BluePrintException(
+ throw BlueprintException(
ErrorCode.BLUEPRINT_PATH_MISSING.value,
"couldn't get definition file under " +
"path(${definitionDir.absolutePath})"
}
blueprintContext.serviceTemplate.dataTypes?.let {
- val dataTypesContent = JacksonUtils.getWrappedJson(BluePrintConstants.PATH_DATA_TYPES, it.toSortedMap(), true)
- writeTypeFile(definitionDir.absolutePath, BluePrintConstants.PATH_DATA_TYPES, dataTypesContent)
+ val dataTypesContent = JacksonUtils.getWrappedJson(BlueprintConstants.PATH_DATA_TYPES, it.toSortedMap(), true)
+ writeTypeFile(definitionDir.absolutePath, BlueprintConstants.PATH_DATA_TYPES, dataTypesContent)
}
blueprintContext.serviceTemplate.relationshipTypes?.let {
- val nodeTypesContent = JacksonUtils.getWrappedJson(BluePrintConstants.PATH_RELATIONSHIP_TYPES, it.toSortedMap(), true)
- writeTypeFile(definitionDir.absolutePath, BluePrintConstants.PATH_RELATIONSHIP_TYPES, nodeTypesContent)
+ val nodeTypesContent = JacksonUtils.getWrappedJson(BlueprintConstants.PATH_RELATIONSHIP_TYPES, it.toSortedMap(), true)
+ writeTypeFile(definitionDir.absolutePath, BlueprintConstants.PATH_RELATIONSHIP_TYPES, nodeTypesContent)
}
blueprintContext.serviceTemplate.artifactTypes?.let {
- val artifactTypesContent = JacksonUtils.getWrappedJson(BluePrintConstants.PATH_ARTIFACT_TYPES, it.toSortedMap(), true)
- writeTypeFile(definitionDir.absolutePath, BluePrintConstants.PATH_ARTIFACT_TYPES, artifactTypesContent)
+ val artifactTypesContent = JacksonUtils.getWrappedJson(BlueprintConstants.PATH_ARTIFACT_TYPES, it.toSortedMap(), true)
+ writeTypeFile(definitionDir.absolutePath, BlueprintConstants.PATH_ARTIFACT_TYPES, artifactTypesContent)
}
blueprintContext.serviceTemplate.nodeTypes?.let {
- val nodeTypesContent = JacksonUtils.getWrappedJson(BluePrintConstants.PATH_NODE_TYPES, it.toSortedMap(), true)
- writeTypeFile(definitionDir.absolutePath, BluePrintConstants.PATH_NODE_TYPES, nodeTypesContent)
+ val nodeTypesContent = JacksonUtils.getWrappedJson(BlueprintConstants.PATH_NODE_TYPES, it.toSortedMap(), true)
+ writeTypeFile(definitionDir.absolutePath, BlueprintConstants.PATH_NODE_TYPES, nodeTypesContent)
}
blueprintContext.serviceTemplate.policyTypes?.let {
- val nodeTypesContent = JacksonUtils.getWrappedJson(BluePrintConstants.PATH_POLICY_TYPES, it.toSortedMap(), true)
- writeTypeFile(definitionDir.absolutePath, BluePrintConstants.PATH_POLICY_TYPES, nodeTypesContent)
+ val nodeTypesContent = JacksonUtils.getWrappedJson(BlueprintConstants.PATH_POLICY_TYPES, it.toSortedMap(), true)
+ writeTypeFile(definitionDir.absolutePath, BlueprintConstants.PATH_POLICY_TYPES, nodeTypesContent)
}
}
- private fun populateDefaultImports(blueprintContext: BluePrintContext) {
+ private fun populateDefaultImports(blueprintContext: BlueprintContext) {
// Get the Default Types
val types = arrayListOf(
- BluePrintConstants.PATH_DATA_TYPES, BluePrintConstants.PATH_RELATIONSHIP_TYPES,
- BluePrintConstants.PATH_ARTIFACT_TYPES, BluePrintConstants.PATH_NODE_TYPES,
- BluePrintConstants.PATH_POLICY_TYPES
+ BlueprintConstants.PATH_DATA_TYPES, BlueprintConstants.PATH_RELATIONSHIP_TYPES,
+ BlueprintConstants.PATH_ARTIFACT_TYPES, BlueprintConstants.PATH_NODE_TYPES,
+ BlueprintConstants.PATH_POLICY_TYPES
)
// Clean Type Imports
val imports = mutableListOf<ImportDefinition>()
types.forEach { typeName ->
val import = ImportDefinition()
- import.file = BluePrintConstants.TOSCA_DEFINITIONS_DIR.plus("/$typeName.json")
+ import.file = BlueprintConstants.TOSCA_DEFINITIONS_DIR.plus("/$typeName.json")
imports.add(import)
}
}
/**
- * Re Generate the Blueprint Service Template Definition file based on BluePrint Context.
+ * Re Generate the Blueprint Service Template Definition file based on Blueprint Context.
*/
- private fun writeEntryDefinitionFile(blueprintContext: BluePrintContext) {
+ private fun writeEntryDefinitionFile(blueprintContext: BlueprintContext) {
val absoluteEntryDefinitionFile = blueprintContext.rootPath.plus(File.separator).plus(blueprintContext.entryDefinition)
Files.write(definitionFile.toPath(), content.toByteArray(), StandardOpenOption.CREATE_NEW)
check(definitionFile.exists()) {
- throw BluePrintException(
+ throw BlueprintException(
ErrorCode.BLUEPRINT_WRITING_FAIL.value,
"couldn't write definition file under " +
"path(${definitionFile.absolutePath})"
Files.write(typeFile.toPath(), content.toByteArray(), StandardOpenOption.CREATE_NEW)
check(typeFile.exists()) {
- throw BluePrintException(
+ throw BlueprintException(
ErrorCode.BLUEPRINT_WRITING_FAIL.value,
"couldn't write $type.json file under " +
"path(${typeFile.absolutePath})"
"\nTemplate-Tags: <TAGS>"
}
- fun getBluePrintFile(fileName: String, targetPath: Path): File {
+ fun getBlueprintFile(fileName: String, targetPath: Path): File {
val filePath = targetPath.resolve(fileName).toString()
val file = File(filePath)
check(file.exists()) {
- throw BluePrintException(
+ throw BlueprintException(
ErrorCode.BLUEPRINT_PATH_MISSING.value,
"couldn't get definition file under " +
"path(${file.absolutePath})"
fun getCbaStorageDirectory(path: String): Path {
check(StringUtils.isNotBlank(path)) {
- throw BluePrintException(
+ throw BlueprintException(
ErrorCode.BLUEPRINT_PATH_MISSING.value,
"couldn't get " +
"Blueprint folder under path($path)"
fun compileJarFilePathName(basePath: String, artifactName: String, artifactVersion: String): String {
return normalizedPathName(
- basePath, BluePrintConstants.TOSCA_SCRIPTS_KOTLIN_DIR,
+ basePath, BlueprintConstants.TOSCA_SCRIPTS_KOTLIN_DIR,
compileJarFileName(artifactName, artifactVersion)
)
}