1 package org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution
3 import com.fasterxml.jackson.databind.JsonNode
4 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException
5 import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintContext
6 import org.onap.ccsdk.cds.controllerblueprints.core.service.DefaultBluePrintRuntimeService
8 class ResourceAssignmentRuntimeService(private var id: String, private var bluePrintContext: BluePrintContext) :
9 DefaultBluePrintRuntimeService(id, bluePrintContext) {
11 private lateinit var resolutionId: String
12 private var resourceStore: MutableMap<String, JsonNode> = hashMapOf()
14 fun createUniqueId(key: String) {
15 resolutionId = "$id-$key"
18 fun cleanResourceStore() {
22 fun putResolutionStore(key: String, value: JsonNode) {
23 resourceStore[key] = value
26 fun getResolutionStore(): MutableMap<String, JsonNode> {
27 return resourceStore.mapValues { e -> e.value.deepCopy() as JsonNode }.toMutableMap()
30 fun getResolutionStore(key: String): JsonNode {
31 return resourceStore[key]
32 ?: throw BluePrintProcessorException("failed to get execution property ($key)")
35 fun checkResolutionStore(key: String): Boolean {
36 return resourceStore.containsKey(key)
39 fun getJsonNodeFromResolutionStore(key: String): JsonNode {
40 return getResolutionStore(key)
43 fun getStringFromResolutionStore(key: String): String? {
44 return getResolutionStore(key).asText()
47 fun getBooleanFromResolutionStore(key: String): Boolean? {
48 return getResolutionStore(key).asBoolean()
51 fun getIntFromResolutionStore(key: String): Int? {
52 return getResolutionStore(key).asInt()
55 fun getDoubleFromResolutionStore(key: String): Double? {
56 return getResolutionStore(key).asDouble()
59 fun putDictionaryStore(key: String, value: JsonNode) {
60 resourceStore["dictionary-$key"] = value
63 fun getDictionaryStore(key: String): JsonNode {
64 return resourceStore["dictionary-$key"]
65 ?: throw BluePrintProcessorException("failed to get execution property (dictionary-$key)")
68 fun checkDictionaryStore(key: String): Boolean {
69 return resourceStore.containsKey("dictionary-$key")
72 fun getJsonNodeFromDictionaryStore(key: String): JsonNode {
73 return getResolutionStore("dictionary-$key")
76 fun getStringFromDictionaryStore(key: String): String? {
77 return getResolutionStore("dictionary-$key").asText()
80 fun getBooleanFromDictionaryStore(key: String): Boolean? {
81 return getResolutionStore("dictionary-$key").asBoolean()
84 fun getIntFromDictionaryStore(key: String): Int? {
85 return getResolutionStore("dictionary-$key").asInt()
88 fun getDoubleFromDictionaryStore(key: String): Double? {
89 return getResolutionStore("dictionary-$key").asDouble()