aboutsummaryrefslogtreecommitdiffstats
path: root/ms
diff options
context:
space:
mode:
authorMuthuramalingam, Brinda Santh <brindasanth@in.ibm.com>2019-03-20 18:27:53 -0400
committerMuthuramalingam, Brinda Santh <brindasanth@in.ibm.com>2019-03-22 11:27:18 -0400
commit663217341fafeea16541958b8b70c270e1270965 (patch)
tree012294709ff6ef4a1b6fccccecedadeb59c74496 /ms
parent2960fd72dc68665e4d518713528957ec9528907f (diff)
Improve publish api
Change-Id: I245fc765bf4e7916c36126d7a9597e9db80a1713 Issue-ID: CCSDK-1137 Signed-off-by: Muthuramalingam, Brinda Santh <brindasanth@in.ibm.com>
Diffstat (limited to 'ms')
-rw-r--r--ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintConstants.kt6
-rw-r--r--ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/FileExtensionFunctions.kt15
-rw-r--r--ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/interfaces/BluePrintEnhancer.kt5
-rw-r--r--ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintImportService.kt7
-rw-r--r--ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintParserService.kt62
-rw-r--r--ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/PropertyAssignmentService.kt2
-rw-r--r--ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintMetadataUtils.kt19
-rw-r--r--ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonReactorUtils.kt129
-rw-r--r--ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonUtils.kt23
-rw-r--r--ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/ResourceResolverUtils.kt36
-rw-r--r--ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/ServiceTemplateUtils.kt28
-rw-r--r--ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonReactorUtilsTest.kt43
-rw-r--r--ms/controllerblueprints/modules/db-resources/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/db/resources/BlueprintCatalogServiceImpl.kt4
-rw-r--r--ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/controller/BlueprintModelController.kt6
-rw-r--r--ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintEnhancerServiceImpl.kt5
-rw-r--r--ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/handler/BluePrintModelHandler.kt57
-rwxr-xr-xms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/load/ControllerBlueprintCatalogServiceImpl.kt4
-rw-r--r--ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/utils/BluePrintEnhancerUtils.kt31
-rw-r--r--ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintEnhancerServiceImplTest.kt17
-rw-r--r--ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/utils/BluePrintEnhancerUtilsTest.kt15
20 files changed, 244 insertions, 270 deletions
diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintConstants.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintConstants.kt
index e3545dff..4b578912 100644
--- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintConstants.kt
+++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintConstants.kt
@@ -33,6 +33,9 @@ object BluePrintConstants {
const val STATUS_PROCESSING: String = "processing"
const val STATUS_FAILURE: String = "failure"
+ const val FLAG_Y: String = "Y"
+ const val FLAG_N: String = "N"
+
const val TYPE_DEFAULT: String = "default"
const val DATA_TYPE_STRING: String = "string"
@@ -98,8 +101,6 @@ object BluePrintConstants {
const val MODEL_TYPE_NODE_DG = "tosca.nodes.DG"
const val MODEL_TYPE_NODE_COMPONENT = "tosca.nodes.Component"
const val MODEL_TYPE_NODE_VNF = "tosca.nodes.Vnf"
- @Deprecated("Artifacts will be attached to Node Template")
- const val MODEL_TYPE_NODE_ARTIFACT = "tosca.nodes.Artifact"
const val MODEL_TYPE_NODE_RESOURCE_SOURCE = "tosca.nodes.ResourceSource"
const val MODEL_TYPE_NODES_COMPONENT_JAVA: String = "tosca.nodes.component.Java"
@@ -141,6 +142,7 @@ object BluePrintConstants {
const val EXPRESSION_GET_NODE_OF_TYPE: String = "get_nodes_of_type"
const val PROPERTY_BLUEPRINT_PROCESS_ID: String = "blueprint-process-id"
+ const val PROPERTY_BLUEPRINT_VALID: String = "blueprint-valid"
const val PROPERTY_BLUEPRINT_BASE_PATH: String = "blueprint-basePath"
const val PROPERTY_BLUEPRINT_RUNTIME: String = "blueprint-runtime"
const val PROPERTY_BLUEPRINT_INPUTS_DATA: String = "blueprint-inputs-data"
diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/FileExtensionFunctions.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/FileExtensionFunctions.kt
index a433a31b..11553ba6 100644
--- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/FileExtensionFunctions.kt
+++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/FileExtensionFunctions.kt
@@ -20,6 +20,7 @@ import org.apache.commons.io.FileUtils
import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintArchiveUtils
import java.io.File
import java.io.InputStream
+import java.nio.file.Path
import java.nio.file.Paths
fun InputStream.toFile(path: String): File {
@@ -65,10 +66,18 @@ fun File.deCompress(targetFile: File): File {
}
fun deleteDir(path: String) {
- Paths.get(path).toFile().deleteRecursively()
+ normalizedFile(path).deleteRecursively()
}
+fun normalizedFile(path: String, vararg more: String?): File {
+ return Paths.get(path, *more).toFile().normalize()
+}
+
+fun normalizedPath(path: String, vararg more: String?): Path {
+ return Paths.get(path, *more).normalize().toAbsolutePath()
+}
-fun normalizedFile(path: String): File {
- return Paths.get(path).toFile().normalize()
+fun normalizedPathName(path: String, vararg more: String?): String {
+ return normalizedPath(path, *more).toUri().path
}
+
diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/interfaces/BluePrintEnhancer.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/interfaces/BluePrintEnhancer.kt
index f01f1262..0aa01e8f 100644
--- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/interfaces/BluePrintEnhancer.kt
+++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/interfaces/BluePrintEnhancer.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.
@@ -47,10 +48,10 @@ interface BluePrintAttributeDefinitionEnhancer : BluePrintEnhancer<AttributeDefi
interface BluePrintEnhancerService {
@Throws(BluePrintException::class)
- fun enhance(basePath: String, enrichedBasePath: String): BluePrintContext
+ suspend fun enhance(basePath: String, enrichedBasePath: String): BluePrintContext
@Throws(BluePrintException::class)
- fun enhance(basePath: String): BluePrintContext
+ suspend fun enhance(basePath: String): BluePrintContext
}
interface BluePrintTypeEnhancerService {
diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintImportService.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintImportService.kt
index 26eb19de..c524773a 100644
--- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintImportService.kt
+++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintImportService.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.
@@ -37,7 +38,7 @@ class BluePrintImportService(private val parentServiceTemplate: ServiceTemplate,
private var importServiceTemplateMap: MutableMap<String, ServiceTemplate> = hashMapOf()
- fun getImportResolvedServiceTemplate(): ServiceTemplate {
+ suspend fun getImportResolvedServiceTemplate(): ServiceTemplate {
// Populate Imported Service Templates
traverseSchema(PARENT_SERVICE_TEMPLATE, parentServiceTemplate)
@@ -48,7 +49,7 @@ class BluePrintImportService(private val parentServiceTemplate: ServiceTemplate,
return parentServiceTemplate
}
- private fun traverseSchema(key: String, serviceTemplate: ServiceTemplate) {
+ private suspend fun traverseSchema(key: String, serviceTemplate: ServiceTemplate) {
if (key != PARENT_SERVICE_TEMPLATE) {
importServiceTemplateMap[key] = serviceTemplate
}
@@ -63,7 +64,7 @@ class BluePrintImportService(private val parentServiceTemplate: ServiceTemplate,
}
}
- private fun resolveImportDefinition(importDefinition: ImportDefinition): ServiceTemplate {
+ private suspend fun resolveImportDefinition(importDefinition: ImportDefinition): ServiceTemplate {
var serviceTemplate: ServiceTemplate? = null
val file: String = importDefinition.file
val decodedSystemId: String = URLDecoder.decode(file, Charset.defaultCharset().toString())
diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintParserService.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintParserService.kt
deleted file mode 100644
index b1d67ece..00000000
--- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintParserService.kt
+++ /dev/null
@@ -1,62 +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.service
-
-import org.onap.ccsdk.apps.controllerblueprints.core.data.ServiceTemplate
-import org.onap.ccsdk.apps.controllerblueprints.core.utils.ServiceTemplateUtils
-import com.att.eelf.configuration.EELFLogger
-import com.att.eelf.configuration.EELFManager
-import java.io.File
-import java.io.Serializable
-
-/**
- *
- *
- * @author Brinda Santh
- */
-interface BluePrintParserService : Serializable {
- fun readBlueprint(content: String) : BluePrintContext
- fun readBlueprintFile(fileName: String) : BluePrintContext
- /**
- * Read Blueprint from CSAR structure Directory
- */
- fun readBlueprintFile(fileName: String, basePath : String) : BluePrintContext
-}
-
-class BluePrintParserDefaultService : BluePrintParserService {
-
- private val log: EELFLogger = EELFManager.getInstance().getLogger(this::class.toString())
-
- var basePath : String = javaClass.classLoader.getResource(".").path
-
- override fun readBlueprint(content: String): BluePrintContext {
- return BluePrintContext(ServiceTemplateUtils.getServiceTemplateFromContent(content))
- }
-
- override fun readBlueprintFile(fileName: String): BluePrintContext {
- return readBlueprintFile(fileName, basePath )
- }
-
- override fun readBlueprintFile(fileName: String, basePath : String): BluePrintContext {
- val rootFilePath: String = StringBuilder().append(basePath).append(File.separator).append(fileName).toString()
- val rootServiceTemplate : ServiceTemplate = ServiceTemplateUtils.getServiceTemplate(rootFilePath)
- // TODO("Nested Lookup Implementation based on Import files")
- return BluePrintContext(rootServiceTemplate)
- }
-
-
-}
diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/PropertyAssignmentService.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/PropertyAssignmentService.kt
index 7905b8fb..62a7b09e 100644
--- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/PropertyAssignmentService.kt
+++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/PropertyAssignmentService.kt
@@ -219,7 +219,7 @@ If Property Assignment is Expression.
if (artifactDefinition.repository != null) {
TODO()
} else if (artifactDefinition.file != null) {
- return ResourceResolverUtils.getFileContent(artifactDefinition.file!!, bluePrintBasePath)
+ return ResourceResolverUtils.getFileContent(artifactDefinition.file, bluePrintBasePath)
}
return ""
}
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 ce11d97e..8ba2e275 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
@@ -21,16 +21,17 @@ package org.onap.ccsdk.apps.controllerblueprints.core.utils
import com.att.eelf.configuration.EELFLogger
import com.att.eelf.configuration.EELFManager
import com.fasterxml.jackson.databind.JsonNode
+import kotlinx.coroutines.runBlocking
import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants
import org.onap.ccsdk.apps.controllerblueprints.core.asJsonPrimitive
import org.onap.ccsdk.apps.controllerblueprints.core.data.ToscaMetaData
+import org.onap.ccsdk.apps.controllerblueprints.core.normalizedFile
import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintContext
import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintImportService
import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService
import org.onap.ccsdk.apps.controllerblueprints.core.service.DefaultBluePrintRuntimeService
import java.io.File
import java.nio.charset.Charset
-import java.nio.file.Paths
import java.util.*
class BluePrintMetadataUtils {
@@ -73,7 +74,7 @@ class BluePrintMetadataUtils {
fun toscaMetaDataFromMetaFile(metaFilePath: String): ToscaMetaData {
val toscaMetaData = ToscaMetaData()
- val lines = Paths.get(metaFilePath).toFile().readLines(Charset.defaultCharset())
+ val lines = normalizedFile(metaFilePath).readLines(Charset.defaultCharset())
lines.forEach { line ->
if (line.contains(":")) {
val keyValue = line.split(":")
@@ -104,7 +105,8 @@ class BluePrintMetadataUtils {
return bluePrintRuntimeService
}
- 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)
@@ -115,7 +117,8 @@ class BluePrintMetadataUtils {
return bluePrintRuntimeService
}
- fun getBluePrintRuntime(id: String, blueprintBasePath: String, executionContext: MutableMap<String, JsonNode>): BluePrintRuntimeService<MutableMap<String, JsonNode>> {
+ 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 {
@@ -126,16 +129,16 @@ class BluePrintMetadataUtils {
return bluePrintRuntimeService
}
- fun getBluePrintContext(blueprintBasePath: String): BluePrintContext {
+ fun getBluePrintContext(blueprintBasePath: String): BluePrintContext = runBlocking {
val toscaMetaData: ToscaMetaData = toscaMetaData(blueprintBasePath)
log.info("Reading blueprint path($blueprintBasePath) and entry definition file (${toscaMetaData.entityDefinitions})")
- return readBlueprintFile(toscaMetaData.entityDefinitions, blueprintBasePath)
+ readBlueprintFile(toscaMetaData.entityDefinitions, blueprintBasePath)
}
- private fun getBaseEnhancementBluePrintContext(blueprintBasePath: String): BluePrintContext {
+ private suspend fun getBaseEnhancementBluePrintContext(blueprintBasePath: String): BluePrintContext {
val toscaMetaData: ToscaMetaData = toscaMetaData(blueprintBasePath)
// Clean Type files
BluePrintFileUtils.deleteBluePrintTypes(blueprintBasePath)
@@ -151,7 +154,7 @@ class BluePrintMetadataUtils {
return blueprintContext
}
- private fun readBlueprintFile(entityDefinitions: String, basePath: String): BluePrintContext {
+ private suspend fun readBlueprintFile(entityDefinitions: String, basePath: String): BluePrintContext {
val rootFilePath: String = basePath.plus(File.separator).plus(entityDefinitions)
val rootServiceTemplate = ServiceTemplateUtils.getServiceTemplate(rootFilePath)
// Recursively Import Template files
diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonReactorUtils.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonReactorUtils.kt
index 0522e1f5..45d8fd4e 100644
--- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonReactorUtils.kt
+++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonReactorUtils.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.
@@ -19,91 +20,73 @@ package org.onap.ccsdk.apps.controllerblueprints.core.utils
import com.att.eelf.configuration.EELFLogger
import com.att.eelf.configuration.EELFManager
import com.fasterxml.jackson.databind.JsonNode
-import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
-import reactor.core.publisher.Mono
-import reactor.core.publisher.toMono
+import kotlinx.coroutines.Dispatchers
+import kotlinx.coroutines.withContext
+import org.apache.commons.io.IOUtils
+import org.onap.ccsdk.apps.controllerblueprints.core.normalizedFile
+import java.io.File
+import java.nio.charset.Charset
-@Deprecated("Reactor will be replaced by coroutines by default")
-object JacksonReactorUtils {
- private val log: EELFLogger = EELFManager.getInstance().getLogger(this::class.toString())
+class JacksonReactorUtils {
+ companion object {
- @JvmStatic
- fun getContent(fileName: String): Mono<String> {
- return JacksonUtils.getContent(fileName).toMono()
- }
+ private val log: EELFLogger = EELFManager.getInstance().getLogger(this::class.toString())
- @JvmStatic
- fun getClassPathFileContent(fileName: String): Mono<String> {
- return JacksonUtils.getClassPathFileContent(fileName).toMono()
- }
+ suspend fun getContent(fileName: String): String {
+ //log.info("Reading File($fileName)")
+ return getContent(normalizedFile(fileName))
+ }
- @JvmStatic
- fun <T> readValue(content: String, valueType: Class<T>): Mono<T> {
- return Mono.just(jacksonObjectMapper().readValue(content, valueType))
- }
+ suspend fun getContent(file: File): String = withContext(Dispatchers.IO) {
+ // log.info("Reading File(${file.absolutePath})")
+ file.readText(Charsets.UTF_8)
+ }
- @JvmStatic
- fun jsonNode(content: String): Mono<JsonNode> {
- return Mono.just(jacksonObjectMapper().readTree(content))
- }
+ suspend fun getClassPathFileContent(fileName: String): String = withContext(Dispatchers.IO) {
+ //log.trace("Reading Classpath File($fileName)")
+ IOUtils.toString(JacksonUtils::class.java.classLoader
+ .getResourceAsStream(fileName), Charset.defaultCharset())
+ }
- @JvmStatic
- fun getJson(any: kotlin.Any, pretty: Boolean = false): Mono<String> {
- return Mono.just(JacksonUtils.getJson(any, pretty))
- }
+ suspend fun <T> readValueFromFile(fileName: String, valueType: Class<T>): T? {
+ val content: String = getContent(fileName)
+ return JacksonUtils.readValue(content, valueType)
+ }
- @JvmStatic
- fun <T> getListFromJson(content: String, valueType: Class<T>): Mono<List<T>> {
- val objectMapper = jacksonObjectMapper()
- val javaType = objectMapper.typeFactory.constructCollectionType(List::class.java, valueType)
- return objectMapper.readValue<List<T>>(content, javaType).toMono()
- }
+ suspend fun <T> readValueFromClassPathFile(fileName: String, valueType: Class<T>): T? {
+ val content: String = getClassPathFileContent(fileName)
+ return JacksonUtils.readValue(content, valueType)
+ }
- @JvmStatic
- fun <T> readValueFromFile(fileName: String, valueType: Class<T>): Mono<T> {
- return getContent(fileName)
- .flatMap { content ->
- readValue(content, valueType)
- }
- }
+ suspend fun jsonNodeFromClassPathFile(fileName: String): JsonNode {
+ val content: String = getClassPathFileContent(fileName)
+ return JacksonUtils.jsonNode(content)
+ }
- @JvmStatic
- fun <T> readValueFromClassPathFile(fileName: String, valueType: Class<T>): Mono<T> {
- return getClassPathFileContent(fileName)
- .flatMap { content ->
- readValue(content, valueType)
- }
- }
+ suspend fun jsonNodeFromFile(fileName: String): JsonNode {
+ val content: String = getContent(fileName)
+ return JacksonUtils.jsonNode(content)
+ }
- @JvmStatic
- fun jsonNodeFromFile(fileName: String): Mono<JsonNode> {
- return getContent(fileName)
- .flatMap { content ->
- jsonNode(content)
- }
- }
+ suspend fun <T> getListFromFile(fileName: String, valueType: Class<T>): List<T> {
+ val content: String = getContent(fileName)
+ return JacksonUtils.getListFromJson(content, valueType)
+ }
- @JvmStatic
- fun jsonNodeFromClassPathFile(fileName: String): Mono<JsonNode> {
- return getClassPathFileContent(fileName)
- .flatMap { content ->
- jsonNode(content)
- }
- }
+ suspend fun <T> getListFromClassPathFile(fileName: String, valueType: Class<T>): List<T> {
+ val content: String = getClassPathFileContent(fileName)
+ return JacksonUtils.getListFromJson(content, valueType)
+ }
- @JvmStatic
- fun <T> getListFromFile(fileName: String, valueType: Class<T>): Mono<List<T>> {
- return getContent(fileName)
- .flatMap { content ->
- getListFromJson(content, valueType)
- }
- }
+ suspend fun <T> getMapFromFile(file: File, valueType: Class<T>): MutableMap<String, T> {
+ val content: String = getContent(file)
+ return JacksonUtils.getMapFromJson(content, valueType)
+ }
+
+ suspend fun <T> getMapFromClassPathFile(fileName: String, valueType: Class<T>): MutableMap<String, T> {
+ val content: String = getClassPathFileContent(fileName)
+ return JacksonUtils.getMapFromJson(content, valueType)
+ }
- @JvmStatic
- fun <T> getListFromClassPathFile(fileName: String, valueType: Class<T>): Mono<List<T>> {
- return getClassPathFileContent(fileName)
- .flatMap { content ->
- getListFromJson(content, valueType)
- }
}
} \ No newline at end of file
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 e0341b8a..7c515984 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
@@ -21,24 +21,14 @@ import com.att.eelf.configuration.EELFManager
import com.fasterxml.jackson.annotation.JsonInclude
import com.fasterxml.jackson.databind.JsonNode
import com.fasterxml.jackson.databind.SerializationFeature
-import com.fasterxml.jackson.databind.node.ArrayNode
-import com.fasterxml.jackson.databind.node.BooleanNode
-import com.fasterxml.jackson.databind.node.DoubleNode
-import com.fasterxml.jackson.databind.node.FloatNode
-import com.fasterxml.jackson.databind.node.IntNode
-import com.fasterxml.jackson.databind.node.NullNode
-import com.fasterxml.jackson.databind.node.ObjectNode
-import com.fasterxml.jackson.databind.node.TextNode
+import com.fasterxml.jackson.databind.node.*
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.async
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.withContext
import org.apache.commons.io.IOUtils
-import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants
-import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException
-import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException
-import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintTypes
+import org.onap.ccsdk.apps.controllerblueprints.core.*
import java.io.File
import java.nio.charset.Charset
@@ -51,7 +41,7 @@ class JacksonUtils {
companion object {
private val log: EELFLogger = EELFManager.getInstance().getLogger(this::class.toString())
inline fun <reified T : Any> readValue(content: String): T =
- jacksonObjectMapper().readValue(content, T::class.java)
+ jacksonObjectMapper().readValue(content, T::class.java)
fun <T> readValue(content: String, valueType: Class<T>): T? {
return jacksonObjectMapper().readValue(content, valueType)
@@ -73,7 +63,8 @@ class JacksonUtils {
}
}
- fun getContent(fileName: String): String = getContent(File(fileName))
+
+ fun getContent(fileName: String): String = getContent(normalizedFile(fileName))
fun getContent(file: File): String = runBlocking {
async {
@@ -89,7 +80,7 @@ class JacksonUtils {
return runBlocking {
withContext(Dispatchers.Default) {
IOUtils.toString(JacksonUtils::class.java.classLoader
- .getResourceAsStream(fileName), Charset.defaultCharset())
+ .getResourceAsStream(fileName), Charset.defaultCharset())
}
}
}
@@ -189,7 +180,7 @@ class JacksonUtils {
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)")
+ ?: throw BluePrintProcessorException("failed to transform content ($properties) to type ($classType)")
}
fun checkJsonNodeValueOfType(type: String, jsonNode: JsonNode): Boolean {
diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/ResourceResolverUtils.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/ResourceResolverUtils.kt
index 965e965c..762e47fb 100644
--- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/ResourceResolverUtils.kt
+++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/ResourceResolverUtils.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.
@@ -16,14 +17,13 @@
package org.onap.ccsdk.apps.controllerblueprints.core.utils
-import org.apache.commons.io.FileUtils
-import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException
-import org.onap.ccsdk.apps.controllerblueprints.core.checkNotEmpty
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.checkNotEmpty
import java.io.File
import java.net.URL
-import java.nio.charset.Charset
+
/**
*
*
@@ -32,30 +32,30 @@ import java.nio.charset.Charset
object ResourceResolverUtils {
private val log: EELFLogger = EELFManager.getInstance().getLogger(this::class.toString())
- @JvmStatic
- fun getFileContent(filename : String, basePath : String?): String {
+ fun getFileContent(filename: String, basePath: String?): String {
log.trace("file ({}), basePath ({}) ", filename, basePath)
- try{
- var resolvedFileName : String = filename
- if(filename.startsWith("http", true)
- || filename.startsWith("https", true)){
- val givenUrl : String = URL(filename).toString()
- val systemUrl : String = File(".").toURI().toURL().toString()
+ try {
+ var resolvedFileName: String = filename
+ if (filename.startsWith("http", true)
+ || filename.startsWith("https", true)) {
+ val givenUrl: String = URL(filename).toString()
+ val systemUrl: String = File(".").toURI().toURL().toString()
log.trace("givenUrl ({}), systemUrl ({}) ", givenUrl, systemUrl)
- if(givenUrl.startsWith(systemUrl)){
+ if (givenUrl.startsWith(systemUrl)) {
}
- }else{
- if(!filename.startsWith("/")){
+ } else {
+ if (!filename.startsWith("/")) {
if (checkNotEmpty(basePath)) {
resolvedFileName = basePath.plus(File.separator).plus(filename)
- }else{
+ } else {
resolvedFileName = javaClass.classLoader.getResource(".").path.plus(filename)
}
}
}
- return FileUtils.readFileToString(File(resolvedFileName), Charset.defaultCharset())
- }catch (e : Exception){
+ //FIXME("Convert into reactive")
+ return JacksonUtils.getContent(resolvedFileName)
+ } catch (e: Exception) {
throw BluePrintException(e, "failed to file (%s), basePath (%s) ", filename, basePath)
}
}
diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/ServiceTemplateUtils.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/ServiceTemplateUtils.kt
index 93316132..28916772 100644
--- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/ServiceTemplateUtils.kt
+++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/ServiceTemplateUtils.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.
@@ -16,11 +17,8 @@
package org.onap.ccsdk.apps.controllerblueprints.core.utils
-import org.apache.commons.io.FileUtils
import org.onap.ccsdk.apps.controllerblueprints.core.data.ServiceTemplate
import org.onap.ccsdk.apps.controllerblueprints.core.data.TopologyTemplate
-import java.io.File
-import java.nio.charset.Charset
/**
*
@@ -29,14 +27,11 @@ import java.nio.charset.Charset
*/
object ServiceTemplateUtils {
- @JvmStatic
- fun getServiceTemplate(fileName: String): ServiceTemplate {
- val content: String = FileUtils.readFileToString(File(fileName), Charset.defaultCharset())
+ suspend fun getServiceTemplate(fileName: String): ServiceTemplate {
+ val content: String = JacksonReactorUtils.getContent(fileName)
return getServiceTemplateFromContent(content)
}
-
- @JvmStatic
fun getServiceTemplateFromContent(content: String): ServiceTemplate {
return JacksonUtils.readValue(content)
}
@@ -80,31 +75,34 @@ object ServiceTemplateUtils {
parentServiceTemplate.topologyTemplate = parentServiceTemplate.topologyTemplate ?: TopologyTemplate()
toMerge.topologyTemplate?.inputs?.let {
- parentServiceTemplate.topologyTemplate?.inputs = parentServiceTemplate.topologyTemplate?.inputs ?: hashMapOf()
+ parentServiceTemplate.topologyTemplate?.inputs = parentServiceTemplate.topologyTemplate?.inputs
+ ?: hashMapOf()
parentServiceTemplate.topologyTemplate?.inputs?.putAll(parentServiceTemplate.topologyTemplate?.inputs as MutableMap)
}
toMerge.topologyTemplate?.nodeTemplates?.let {
- parentServiceTemplate.topologyTemplate?.nodeTemplates = parentServiceTemplate.topologyTemplate?.nodeTemplates ?: hashMapOf()
+ parentServiceTemplate.topologyTemplate?.nodeTemplates = parentServiceTemplate.topologyTemplate?.nodeTemplates
+ ?: hashMapOf()
parentServiceTemplate.topologyTemplate?.nodeTemplates?.putAll(parentServiceTemplate.topologyTemplate?.nodeTemplates as MutableMap)
}
toMerge.topologyTemplate?.relationshipTemplates?.let {
- parentServiceTemplate.topologyTemplate?.relationshipTemplates = parentServiceTemplate.topologyTemplate?.relationshipTemplates ?: hashMapOf()
+ parentServiceTemplate.topologyTemplate?.relationshipTemplates = parentServiceTemplate.topologyTemplate?.relationshipTemplates
+ ?: hashMapOf()
parentServiceTemplate.topologyTemplate?.relationshipTemplates?.putAll(parentServiceTemplate.topologyTemplate?.relationshipTemplates as MutableMap)
}
toMerge.topologyTemplate?.policies?.let {
- parentServiceTemplate.topologyTemplate?.policies = parentServiceTemplate.topologyTemplate?.policies ?: hashMapOf()
+ parentServiceTemplate.topologyTemplate?.policies = parentServiceTemplate.topologyTemplate?.policies
+ ?: hashMapOf()
parentServiceTemplate.topologyTemplate?.policies?.putAll(parentServiceTemplate.topologyTemplate?.policies as MutableMap)
}
toMerge.topologyTemplate?.workflows?.let {
- parentServiceTemplate.topologyTemplate?.workflows = parentServiceTemplate.topologyTemplate?.workflows ?: hashMapOf()
+ parentServiceTemplate.topologyTemplate?.workflows = parentServiceTemplate.topologyTemplate?.workflows
+ ?: hashMapOf()
parentServiceTemplate.topologyTemplate?.workflows?.putAll(parentServiceTemplate.topologyTemplate?.workflows as MutableMap)
}
return parentServiceTemplate
}
-
-
} \ No newline at end of file
diff --git a/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonReactorUtilsTest.kt b/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonReactorUtilsTest.kt
new file mode 100644
index 00000000..9cf8d62a
--- /dev/null
+++ b/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonReactorUtilsTest.kt
@@ -0,0 +1,43 @@
+/*
+ * 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.core.utils
+
+import com.att.eelf.configuration.EELFLogger
+import com.att.eelf.configuration.EELFManager
+import kotlinx.coroutines.runBlocking
+import org.junit.Test
+
+class JacksonReactorUtilsTest {
+
+ private val log: EELFLogger = EELFManager.getInstance().getLogger(this::class.toString())
+
+ @Test
+ fun testJsonNodeFromClassPathFile() {
+ runBlocking {
+ val filePath = "data/default-context.json"
+ JacksonReactorUtils.jsonNodeFromClassPathFile(filePath)
+ }
+ }
+
+ @Test
+ fun testJsonNodeFromFile() {
+ runBlocking {
+ val filePath = "src/test/resources/data/default-context.json"
+ JacksonReactorUtils.jsonNodeFromFile(filePath)
+ }
+ }
+} \ No newline at end of file
diff --git a/ms/controllerblueprints/modules/db-resources/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/db/resources/BlueprintCatalogServiceImpl.kt b/ms/controllerblueprints/modules/db-resources/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/db/resources/BlueprintCatalogServiceImpl.kt
index cfde86aa..e4323152 100644
--- a/ms/controllerblueprints/modules/db-resources/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/db/resources/BlueprintCatalogServiceImpl.kt
+++ b/ms/controllerblueprints/modules/db-resources/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/db/resources/BlueprintCatalogServiceImpl.kt
@@ -1,6 +1,7 @@
/*
* Copyright © 2017-2018 AT&T Intellectual Property.
* Modifications Copyright © 2019 Bell Canada.
+ * 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.
@@ -55,13 +56,16 @@ abstract class BlueprintCatalogServiceImpl(private val blueprintValidator: BlueP
toDeleteDirectory = extractedDirectory
}
+ var valid = BluePrintConstants.FLAG_N
if (validate) {
blueprintValidator.validateBluePrints(extractedDirectory.path)
+ valid = BluePrintConstants.FLAG_Y
}
val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime(blueprintId, extractedDirectory.path)
val metadata = bluePrintRuntimeService.bluePrintContext().metadata!!
metadata[BluePrintConstants.PROPERTY_BLUEPRINT_PROCESS_ID] = blueprintId
+ metadata[BluePrintConstants.PROPERTY_BLUEPRINT_VALID] = valid
save(metadata, archivedDirectory)
diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/controller/BlueprintModelController.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/controller/BlueprintModelController.kt
index d6ce286f..4974bcd1 100644
--- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/controller/BlueprintModelController.kt
+++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/controller/BlueprintModelController.kt
@@ -95,11 +95,11 @@ open class BlueprintModelController(private val bluePrintModelHandler: BluePrint
bluePrintModelHandler.enrichBlueprint(file)
}
- @PutMapping("/publish/{id}", produces = [MediaType.APPLICATION_JSON_VALUE])
+ @PostMapping("/publish", produces = [MediaType.APPLICATION_JSON_VALUE])
@ResponseBody
@Throws(BluePrintException::class)
- fun publishBlueprintModel(@PathVariable(value = "id") id: String): BlueprintModelSearch {
- return this.bluePrintModelHandler.publishBlueprintModel(id)
+ fun publishBlueprint(@RequestPart("file") file: FilePart): BlueprintModelSearch = runBlocking {
+ bluePrintModelHandler.publishBlueprint(file)
}
@GetMapping("/search/{tags}", produces = [MediaType.APPLICATION_JSON_VALUE])
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 fb49dc46..da755d16 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
@@ -35,7 +35,7 @@ open class BluePrintEnhancerServiceImpl(private val bluePrintTypeEnhancerService
private val log: EELFLogger = EELFManager.getInstance().getLogger(BluePrintEnhancerServiceImpl::class.toString())
- override fun enhance(basePath: String, enrichedBasePath: String): BluePrintContext {
+ override suspend fun enhance(basePath: String, enrichedBasePath: String): BluePrintContext {
// Copy the Blueprint Content to Target Location
BluePrintFileUtils.copyBluePrint(basePath, enrichedBasePath)
@@ -45,7 +45,7 @@ open class BluePrintEnhancerServiceImpl(private val bluePrintTypeEnhancerService
}
@Throws(BluePrintException::class)
- override fun enhance(basePath: String): BluePrintContext {
+ override suspend fun enhance(basePath: String): BluePrintContext {
log.info("Enhancing blueprint($basePath)")
val blueprintRuntimeService = BluePrintMetadataUtils
@@ -73,7 +73,6 @@ open class BluePrintEnhancerServiceImpl(private val bluePrintTypeEnhancerService
} catch (e: Exception) {
throw e
}
-
return blueprintRuntimeService.bluePrintContext()
}
diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/handler/BluePrintModelHandler.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/handler/BluePrintModelHandler.kt
index 4239abba..11087bc5 100644
--- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/handler/BluePrintModelHandler.kt
+++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/handler/BluePrintModelHandler.kt
@@ -19,11 +19,11 @@
package org.onap.ccsdk.apps.controllerblueprints.service.handler
import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException
-import org.onap.ccsdk.apps.controllerblueprints.core.common.ApplicationConstants
import org.onap.ccsdk.apps.controllerblueprints.core.config.BluePrintLoadConfiguration
import org.onap.ccsdk.apps.controllerblueprints.core.data.ErrorCode
import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintCatalogService
import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintEnhancerService
+import org.onap.ccsdk.apps.controllerblueprints.core.normalizedPathName
import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintFileUtils
import org.onap.ccsdk.apps.controllerblueprints.service.domain.BlueprintModel
import org.onap.ccsdk.apps.controllerblueprints.service.domain.BlueprintModelSearch
@@ -95,26 +95,6 @@ open class BluePrintModelHandler(private val bluePrintCatalogService: BluePrintC
}
- /**
- * This is a publishBlueprintModel method to change the status published to YES
- *
- * @param id id
- * @return BlueprintModelSearch
- * @throws BluePrintException BluePrintException
- */
- @Throws(BluePrintException::class)
- open fun publishBlueprintModel(id: String): BlueprintModelSearch {
- val blueprintModelSearch: BlueprintModelSearch
- val dbBlueprintModel = blueprintModelSearchRepository.findById(id)
- if (dbBlueprintModel.isPresent) {
- blueprintModelSearch = dbBlueprintModel.get()
- } else {
- val msg = String.format(BLUEPRINT_MODEL_ID_FAILURE_MSG, id)
- throw BluePrintException(ErrorCode.RESOURCE_NOT_FOUND.value, msg)
- }
- blueprintModelSearch.published = ApplicationConstants.ACTIVE_Y
- return blueprintModelSearchRepository.saveAndFlush(blueprintModelSearch)
- }
/**
* This is a searchBlueprintModels method
@@ -296,9 +276,8 @@ open class BluePrintModelHandler(private val bluePrintCatalogService: BluePrintC
@Throws(BluePrintException::class)
open suspend fun enrichBlueprint(filePart: FilePart): ResponseEntity<Resource> {
val enhanceId = UUID.randomUUID().toString()
- val blueprintArchive = bluePrintLoadConfiguration.blueprintArchivePath.plus(File.separator).plus(enhanceId)
- val blueprintEnrichmentDir = bluePrintLoadConfiguration.blueprintEnrichmentPath.plus(File.separator).plus(enhanceId)
-
+ val blueprintArchive = normalizedPathName(bluePrintLoadConfiguration.blueprintArchivePath, enhanceId)
+ val blueprintEnrichmentDir = normalizedPathName(bluePrintLoadConfiguration.blueprintEnrichmentPath, enhanceId)
try {
BluePrintEnhancerUtils.decompressFilePart(filePart, blueprintArchive, blueprintEnrichmentDir)
@@ -309,7 +288,35 @@ open class BluePrintModelHandler(private val bluePrintCatalogService: BluePrintC
} catch (e: IOException) {
throw BluePrintException(ErrorCode.IO_FILE_INTERRUPT.value,
- String.format("I/O Error while uploading the CBA file: %s", e.message), e)
+ "Error in Enriching CBA: ${e.message}", e)
+ } finally {
+ BluePrintEnhancerUtils.cleanEnhancer(blueprintArchive, blueprintEnrichmentDir)
+ }
+ }
+
+ /**
+ * This is a publishBlueprintModel method to change the status published to YES
+ *
+ * @param filePart filePart
+ * @return BlueprintModelSearch
+ * @throws BluePrintException BluePrintException
+ */
+ @Throws(BluePrintException::class)
+ open suspend fun publishBlueprint(filePart: FilePart): BlueprintModelSearch {
+ val publishId = UUID.randomUUID().toString()
+ val blueprintArchive = bluePrintLoadConfiguration.blueprintArchivePath.plus(File.separator).plus(publishId)
+ val blueprintEnrichmentDir = bluePrintLoadConfiguration.blueprintEnrichmentPath.plus(File.separator).plus(publishId)
+ try {
+ val compressedFilePart = BluePrintEnhancerUtils
+ .extractCompressFilePart(filePart, blueprintArchive, blueprintEnrichmentDir)
+
+ val blueprintId = bluePrintCatalogService.saveToDatabase(compressedFilePart, true)
+
+ return blueprintModelSearchRepository.findById(blueprintId).get()
+
+ } catch (e: Exception) {
+ throw BluePrintException(ErrorCode.IO_FILE_INTERRUPT.value,
+ "Error in Publishing CBA: ${e.message}", e)
} finally {
BluePrintEnhancerUtils.cleanEnhancer(blueprintArchive, blueprintEnrichmentDir)
}
diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/load/ControllerBlueprintCatalogServiceImpl.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/load/ControllerBlueprintCatalogServiceImpl.kt
index 892cdbd5..17149e46 100755
--- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/load/ControllerBlueprintCatalogServiceImpl.kt
+++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/load/ControllerBlueprintCatalogServiceImpl.kt
@@ -1,6 +1,7 @@
/*
* Copyright © 2017-2018 AT&T Intellectual Property.
* Modifications Copyright © 2019 Bell Canada.
+ * 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.
@@ -83,7 +84,8 @@ class ControllerBlueprintCatalogServiceImpl(bluePrintValidatorService: BluePrint
val blueprintModel = BlueprintModel()
blueprintModel.id = metadata[BluePrintConstants.PROPERTY_BLUEPRINT_PROCESS_ID]
blueprintModel.artifactType = ApplicationConstants.ASDC_ARTIFACT_TYPE_SDNC_MODEL
- blueprintModel.published = ApplicationConstants.ACTIVE_N
+ blueprintModel.published = metadata[BluePrintConstants.PROPERTY_BLUEPRINT_VALID]
+ ?: BluePrintConstants.FLAG_N
blueprintModel.artifactName = artifactName
blueprintModel.artifactVersion = artifactVersion
blueprintModel.updatedBy = metadata[BluePrintConstants.METADATA_TEMPLATE_AUTHOR]
diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/utils/BluePrintEnhancerUtils.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/utils/BluePrintEnhancerUtils.kt
index 02140ebf..cf1bfb57 100644
--- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/utils/BluePrintEnhancerUtils.kt
+++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/utils/BluePrintEnhancerUtils.kt
@@ -21,12 +21,9 @@ package org.onap.ccsdk.apps.controllerblueprints.service.utils
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.reactive.awaitSingle
import kotlinx.coroutines.withContext
-import org.apache.commons.io.FileUtils
-import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException
+import org.onap.ccsdk.apps.controllerblueprints.core.*
import org.onap.ccsdk.apps.controllerblueprints.core.data.*
-import org.onap.ccsdk.apps.controllerblueprints.core.deCompress
import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintRepoService
-import org.onap.ccsdk.apps.controllerblueprints.core.reCreateDirs
import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintContext
import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintArchiveUtils
import org.springframework.core.io.ByteArrayResource
@@ -87,7 +84,7 @@ class BluePrintEnhancerUtils {
return artifactType
}
- suspend fun copyFromFilePart(filePart: FilePart, targetFile: File): File {
+ private suspend fun copyFromFilePart(filePart: FilePart, targetFile: File): File {
// Delete the Directory
targetFile.deleteRecursively()
return filePart.transferTo(targetFile)
@@ -95,20 +92,23 @@ class BluePrintEnhancerUtils {
.awaitSingle()
}
- suspend fun decompressFilePart(filePart: FilePart, archiveDir: String, enhanceDir: String): File {
+ suspend fun extractCompressFilePart(filePart: FilePart, archiveDir: String, enhanceDir: String): File {
//Recreate the Base Directories
- Paths.get(archiveDir).toFile().reCreateDirs()
- Paths.get(enhanceDir).toFile().reCreateDirs()
-
- val filePartFile = Paths.get(archiveDir, "cba.zip").toFile()
+ normalizedFile(archiveDir).reCreateDirs()
+ normalizedFile(enhanceDir).reCreateDirs()
+ val filePartFile = normalizedFile(archiveDir, "cba.zip")
// Copy the File Part to ZIP
- copyFromFilePart(filePart, filePartFile)
+ return copyFromFilePart(filePart, filePartFile)
+ }
+
+ suspend fun decompressFilePart(filePart: FilePart, archiveDir: String, enhanceDir: String): File {
+ val filePartFile = extractCompressFilePart(filePart, archiveDir, enhanceDir)
val deCompressFileName = Paths.get(enhanceDir).toUri().path
return filePartFile.deCompress(deCompressFileName)
}
suspend fun compressToFilePart(enhanceDir: String, archiveDir: String): ResponseEntity<Resource> {
- val compressedFile = Paths.get(archiveDir, "enhanced-cba.zip").toFile()
+ val compressedFile = normalizedFile(archiveDir, "enhanced-cba.zip")
BluePrintArchiveUtils.compress(Paths.get(enhanceDir).toFile(), compressedFile, true)
return prepareResourceEntity(compressedFile.name, compressedFile.readBytes())
}
@@ -121,11 +121,8 @@ class BluePrintEnhancerUtils {
}
suspend fun cleanEnhancer(archiveLocation: String, enhancementLocation: String) = withContext(Dispatchers.Default) {
- val enrichDir = File(enhancementLocation)
- FileUtils.forceDeleteOnExit(enrichDir)
-
- val archiveDir = File(archiveLocation)
- FileUtils.forceDeleteOnExit(archiveDir)
+ deleteDir(archiveLocation)
+ deleteDir(enhancementLocation)
}
/**
diff --git a/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintEnhancerServiceImplTest.kt b/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintEnhancerServiceImplTest.kt
index e0ecf039..74f225a5 100644
--- a/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintEnhancerServiceImplTest.kt
+++ b/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintEnhancerServiceImplTest.kt
@@ -91,17 +91,18 @@ class BluePrintEnhancerServiceImplTest {
}
private fun testComponentInvokeEnhancementAndValidation(basePath: String, targetDirName: String) {
+ runBlocking {
+ val targetPath = Paths.get("target", targetDirName).toUri().path
- val targetPath = Paths.get("target", targetDirName).toUri().path
-
- deleteTargetDirectory(targetPath)
+ deleteTargetDirectory(targetPath)
- val bluePrintContext = bluePrintEnhancerService.enhance(basePath, targetPath)
- Assert.assertNotNull("failed to get blueprintContext ", bluePrintContext)
+ val bluePrintContext = bluePrintEnhancerService.enhance(basePath, targetPath)
+ Assert.assertNotNull("failed to get blueprintContext ", bluePrintContext)
- // Validate the Generated BluePrints
- val valid = bluePrintValidatorService.validateBluePrints(targetPath)
- Assert.assertTrue("blueprint($basePath) validation failed ", valid)
+ // Validate the Generated BluePrints
+ val valid = bluePrintValidatorService.validateBluePrints(targetPath)
+ Assert.assertTrue("blueprint($basePath) validation failed ", valid)
+ }
}
private fun deleteTargetDirectory(targetPath: String) {
diff --git a/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/utils/BluePrintEnhancerUtilsTest.kt b/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/utils/BluePrintEnhancerUtilsTest.kt
index 2e7ca2cd..026561e1 100644
--- a/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/utils/BluePrintEnhancerUtilsTest.kt
+++ b/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/utils/BluePrintEnhancerUtilsTest.kt
@@ -20,10 +20,7 @@ import kotlinx.coroutines.runBlocking
import org.junit.After
import org.junit.Before
import org.junit.Test
-import org.onap.ccsdk.apps.controllerblueprints.core.compress
-import org.onap.ccsdk.apps.controllerblueprints.core.deleteDir
-import org.onap.ccsdk.apps.controllerblueprints.core.normalizedFile
-import org.onap.ccsdk.apps.controllerblueprints.core.reCreateDirs
+import org.onap.ccsdk.apps.controllerblueprints.core.*
import org.onap.ccsdk.apps.controllerblueprints.service.controller.mock.MockFilePart
import java.nio.file.Paths
import java.util.*
@@ -34,10 +31,9 @@ class BluePrintEnhancerUtilsTest {
private val blueprintDir = "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration"
private val blueprintArchivePath: String = "./target/blueprints/archive"
private val blueprintEnrichmentPath: String = "./target/blueprints/enrichment"
- private var zipBlueprintFileName = Paths.get(blueprintArchivePath, "test.zip").toFile().normalize().absolutePath
+ private var zipBlueprintFileName = Paths.get(blueprintArchivePath, "test.zip").normalize().toUri().path
@Before
- @Throws(Exception::class)
fun setUp() {
val archiveDir = normalizedFile(blueprintArchivePath).reCreateDirs()
assertTrue(archiveDir.exists(), "failed to create archiveDir(${archiveDir.absolutePath}")
@@ -49,20 +45,19 @@ class BluePrintEnhancerUtilsTest {
}
@After
- @Throws(Exception::class)
fun tearDown() {
deleteDir(blueprintArchivePath)
deleteDir(blueprintEnrichmentPath)
}
@Test
- fun testDecompressFilePart() {
+ fun testFilePartCompressionNDeCompression() {
val filePart = MockFilePart(zipBlueprintFileName)
runBlocking {
val enhanceId = UUID.randomUUID().toString()
- val blueprintArchiveLocation = "$blueprintArchivePath/$enhanceId"
- val blueprintEnrichmentLocation = "$blueprintEnrichmentPath/$enhanceId"
+ val blueprintArchiveLocation = normalizedPathName(blueprintArchivePath, enhanceId)
+ val blueprintEnrichmentLocation = normalizedPathName(blueprintEnrichmentPath, enhanceId)
BluePrintEnhancerUtils.decompressFilePart(filePart, blueprintArchiveLocation, blueprintEnrichmentLocation)
BluePrintEnhancerUtils.compressToFilePart(blueprintEnrichmentLocation, blueprintArchiveLocation)
}