aboutsummaryrefslogtreecommitdiffstats
path: root/components/core
diff options
context:
space:
mode:
authorMuthuramalingam, Brinda Santh(bs2796) <bs2796@att.com>2018-12-14 12:30:51 -0500
committerMuthuramalingam, Brinda Santh(bs2796) <bs2796@att.com>2018-12-14 12:30:51 -0500
commit72066bf5f27870a6bd009b920452a77d57fd8af3 (patch)
treef6cf183de1215efe205a42ffeccdfc189e94408b /components/core
parent776d17ace2d674f3e9f5685a7a005ce4b7b91ed3 (diff)
Add blueprint artifact definition enrichment.
Change-Id: I3b03a1f76472ce6b44929457a42805d281950ff7 Issue-ID: CCSDK-839 Signed-off-by: Muthuramalingam, Brinda Santh(bs2796) <bs2796@att.com>
Diffstat (limited to 'components/core')
-rw-r--r--components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/interfaces/BluePrintEnhancer.kt9
-rw-r--r--components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRuntimeService.kt7
-rw-r--r--components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintArchiveUtils.kt12
-rw-r--r--components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonReactorUtils.kt1
-rw-r--r--components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonUtils.kt12
-rw-r--r--components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/validation/BluePrintNodeTemplateValidatorImpl.kt2
-rw-r--r--components/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRepoFileServiceTest.kt4
-rw-r--r--components/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonReactorUtilsTest.kt5
8 files changed, 43 insertions, 9 deletions
diff --git a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/interfaces/BluePrintEnhancer.kt b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/interfaces/BluePrintEnhancer.kt
index f6659e7d..f01f1262 100644
--- a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/interfaces/BluePrintEnhancer.kt
+++ b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/interfaces/BluePrintEnhancer.kt
@@ -35,6 +35,8 @@ interface BluePrintNodeTemplateEnhancer : BluePrintEnhancer<NodeTemplate>
interface BluePrintNodeTypeEnhancer : BluePrintEnhancer<NodeType>
+interface BluePrintArtifactDefinitionEnhancer : BluePrintEnhancer<ArtifactDefinition>
+
interface BluePrintPolicyTypeEnhancer : BluePrintEnhancer<PolicyType>
interface BluePrintPropertyDefinitionEnhancer : BluePrintEnhancer<PropertyDefinition>
@@ -63,6 +65,8 @@ interface BluePrintTypeEnhancerService {
fun getNodeTypeEnhancers(): List<BluePrintNodeTypeEnhancer>
+ fun getArtifactDefinitionEnhancers(): List<BluePrintArtifactDefinitionEnhancer>
+
fun getPolicyTypeEnhancers(): List<BluePrintPolicyTypeEnhancer>
fun getPropertyDefinitionEnhancers(): List<BluePrintPropertyDefinitionEnhancer>
@@ -94,6 +98,11 @@ interface BluePrintTypeEnhancerService {
doEnhancement(bluePrintRuntimeService, name, nodeType, enhancers)
}
+ fun enhanceArtifactDefinition(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, artifactDefinition: ArtifactDefinition) {
+ val enhancers = getArtifactDefinitionEnhancers()
+ doEnhancement(bluePrintRuntimeService, name, artifactDefinition, enhancers)
+ }
+
fun enhancePolicyType(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, policyType: PolicyType) {
val enhancers = getPolicyTypeEnhancers()
doEnhancement(bluePrintRuntimeService, name, policyType, enhancers)
diff --git a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRuntimeService.kt b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRuntimeService.kt
index cf518bd1..5540047c 100644
--- a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRuntimeService.kt
+++ b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRuntimeService.kt
@@ -46,6 +46,8 @@ interface BluePrintRuntimeService<T> {
fun get(key: String): JsonNode?
+ fun check(key: String): Boolean
+
fun cleanRuntime()
fun getAsString(key: String): String?
@@ -114,6 +116,7 @@ interface BluePrintRuntimeService<T> {
open class DefaultBluePrintRuntimeService(private var id: String, private var bluePrintContext: BluePrintContext)
: BluePrintRuntimeService<MutableMap<String, JsonNode>> {
+ @Transient
private val log: EELFLogger = EELFManager.getInstance().getLogger(BluePrintRuntimeService::class.toString())
private var store: MutableMap<String, JsonNode> = hashMapOf()
@@ -145,6 +148,10 @@ open class DefaultBluePrintRuntimeService(private var id: String, private var bl
return store[key] ?: throw BluePrintProcessorException("failed to get execution property($key)")
}
+ override fun check(key: String): Boolean {
+ return store.containsKey(key)
+ }
+
override fun cleanRuntime() {
store.clear()
}
diff --git a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintArchiveUtils.kt b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintArchiveUtils.kt
index f02524ff..c1ab4fc6 100644
--- a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintArchiveUtils.kt
+++ b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintArchiveUtils.kt
@@ -16,9 +16,12 @@
package org.onap.ccsdk.apps.controllerblueprints.core.utils
+import kotlinx.coroutines.async
+import kotlinx.coroutines.runBlocking
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry
import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream
import org.apache.commons.io.IOUtils
+import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException
import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException
import java.io.*
import java.nio.charset.Charset
@@ -28,6 +31,15 @@ class BluePrintArchiveUtils {
companion object {
+ fun getFileContent(fileName: String): String = runBlocking {
+ async {
+ try {
+ File(fileName).readText(Charsets.UTF_8)
+ } catch (e: Exception) {
+ throw BluePrintException("couldn't find file($fileName)")
+ }
+ }.await()
+ }
fun compress(source: String, destination: String, absolute: Boolean): Boolean {
val rootDir = File(source)
diff --git a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonReactorUtils.kt b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonReactorUtils.kt
index 0ed90170..e3c2a710 100644
--- a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonReactorUtils.kt
+++ b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonReactorUtils.kt
@@ -23,6 +23,7 @@ import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import reactor.core.publisher.Mono
import reactor.core.publisher.toMono
+@Deprecated("Reactor will be replaced by coroutines by default")
object JacksonReactorUtils {
private val log: EELFLogger = EELFManager.getInstance().getLogger(this::class.toString())
diff --git a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonUtils.kt b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonUtils.kt
index be23172a..01874455 100644
--- a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonUtils.kt
+++ b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonUtils.kt
@@ -25,10 +25,12 @@ import com.fasterxml.jackson.databind.JsonNode
import com.fasterxml.jackson.databind.SerializationFeature
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.BluePrintTypes
import java.io.File
import java.nio.charset.Charset
@@ -55,12 +57,14 @@ object JacksonUtils {
}
@JvmStatic
- fun getContent(fileName: String): String {
- return runBlocking {
- withContext(Dispatchers.Default) {
+ fun getContent(fileName: String): String = runBlocking {
+ async {
+ try {
File(fileName).readText(Charsets.UTF_8)
+ } catch (e: Exception) {
+ throw BluePrintException("couldn't get file ($fileName) content : ${e.message}")
}
- }
+ }.await()
}
@JvmStatic
diff --git a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/validation/BluePrintNodeTemplateValidatorImpl.kt b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/validation/BluePrintNodeTemplateValidatorImpl.kt
index 1449e63d..0ed87f81 100644
--- a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/validation/BluePrintNodeTemplateValidatorImpl.kt
+++ b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/validation/BluePrintNodeTemplateValidatorImpl.kt
@@ -242,7 +242,7 @@ open class BluePrintNodeTemplateValidatorImpl(private val bluePrintTypeValidator
open fun checkValidArtifactType(artifactDefinitionName: String, artifactTypeName: String) {
val artifactType = bluePrintContext.serviceTemplate.artifactTypes?.get(artifactTypeName)
- ?: throw BluePrintException("failed to artifactType($artifactTypeName) for ArtifactDefinition($artifactDefinitionName)")
+ ?: throw BluePrintException("failed to get artifactType($artifactTypeName) for ArtifactDefinition($artifactDefinitionName)")
checkValidArtifactTypeDerivedFrom(artifactTypeName, artifactType.derivedFrom)
}
diff --git a/components/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRepoFileServiceTest.kt b/components/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRepoFileServiceTest.kt
index f7ffc394..9348a237 100644
--- a/components/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRepoFileServiceTest.kt
+++ b/components/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRepoFileServiceTest.kt
@@ -18,7 +18,7 @@
package org.onap.ccsdk.apps.controllerblueprints.core.service
import org.junit.Test
-import java.io.FileNotFoundException
+import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException
import kotlin.test.assertNotNull
/**
@@ -49,7 +49,7 @@ class BluePrintRepoFileServiceTest {
assertNotNull(nodeType, "Failed to get ArtifactType from repo")
}
- @Test(expected = FileNotFoundException::class)
+ @Test(expected = BluePrintException::class)
fun testModelNotFound() {
val dataType = bluePrintRepoFileService.getDataType("dt-not-found")
assertNotNull(dataType, "Failed to get DataType from repo")
diff --git a/components/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonReactorUtilsTest.kt b/components/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonReactorUtilsTest.kt
index be76593d..ad55c776 100644
--- a/components/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonReactorUtilsTest.kt
+++ b/components/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonReactorUtilsTest.kt
@@ -19,11 +19,12 @@ package org.onap.ccsdk.apps.controllerblueprints.core.utils
import com.att.eelf.configuration.EELFLogger
import com.att.eelf.configuration.EELFManager
import org.junit.Test
+import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException
import org.onap.ccsdk.apps.controllerblueprints.core.data.ServiceTemplate
-import java.io.FileNotFoundException
import kotlin.test.assertEquals
import kotlin.test.assertNotNull
+@Deprecated("Reactor will be replacecd by coroutines by default.")
class JacksonReactorUtilsTest {
private val log: EELFLogger = EELFManager.getInstance().getLogger(this::class.toString())
@Test
@@ -43,7 +44,7 @@ class JacksonReactorUtilsTest {
assertNotNull(jsonContent, "Failed to get json Node")
}
- @Test(expected = FileNotFoundException::class)
+ @Test(expected = BluePrintException::class)
fun testReadValuesFailure() {
JacksonReactorUtils.jsonNodeFromFile("load/blueprints/not-found.json")
.block()