import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException
import org.onap.ccsdk.cds.controllerblueprints.core.asJsonNode
import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BlueprintFunctionNode
+import org.onap.ccsdk.cds.controllerblueprints.core.isNullOrMissing
import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintVelocityTemplateService
import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceAssignment
import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceDefinition
import org.slf4j.LoggerFactory
-import java.util.*
+import java.util.HashMap
abstract class ResourceAssignmentProcessor : BlueprintFunctionNode<ResourceAssignment, Boolean> {
private val log = LoggerFactory.getLogger(ResourceAssignmentProcessor::class.java)
lateinit var raRuntimeService: ResourceAssignmentRuntimeService
- lateinit var resourceDictionaries: MutableMap<String, ResourceDefinition>
+ var resourceDictionaries: MutableMap<String, ResourceDefinition> = hashMapOf()
var scriptPropertyInstances: MutableMap<String, Any> = hashMapOf()
lateinit var scriptType: String
*/
open fun <T> scriptPropertyInstanceType(name: String): T {
return scriptPropertyInstances as? T
- ?: throw BluePrintProcessorException("couldn't get script property instance ($name)")
+ ?: throw BluePrintProcessorException("couldn't get script property instance ($name)")
}
- open fun getFromInput(resourceAssignment: ResourceAssignment): JsonNode? {
- var value: JsonNode? = null
+ open fun setFromInput(resourceAssignment: ResourceAssignment): Boolean {
try {
- value = raRuntimeService.getInputValue(resourceAssignment.name)
- ResourceAssignmentUtils.setResourceDataValue(resourceAssignment, raRuntimeService, value)
+ val value = raRuntimeService.getInputValue(resourceAssignment.name)
+ if (!value.isNullOrMissing()) {
+ log.debug(
+ "For Resource:(${resourceAssignment.name}) found value:({}) in input-data.",
+ ResourceAssignmentUtils.getValueToLog(resourceAssignment.property?.metadata, value)
+ )
+ ResourceAssignmentUtils.setResourceDataValue(resourceAssignment, raRuntimeService, value)
+ return true
+ }
+ } catch (e: BluePrintProcessorException) {
+ // NoOp - couldn't find value from input
+ }
+ return false
+ }
+
+ open fun setFromInputKeyDependencies(keys: MutableList<String>, resourceAssignment: ResourceAssignment): Boolean {
+ try {
+ for (dependencyKey in keys) {
+ var value = raRuntimeService.getInputValue(dependencyKey)
+ if (!value.isNullOrMissing()) {
+ log.debug(
+ "For Resource:(${resourceAssignment.name}) found value:({}) in input-data under: ($dependencyKey).",
+ ResourceAssignmentUtils.getValueToLog(resourceAssignment.property?.metadata, value)
+ )
+ ResourceAssignmentUtils.setResourceDataValue(resourceAssignment, raRuntimeService, value)
+ return true
+ }
+ }
} catch (e: BluePrintProcessorException) {
// NoOp - couldn't find value from input
}
- return value
+ return false
}
- open fun resourceDefinition(name: String): ResourceDefinition {
- return resourceDictionaries[name]
- ?: throw BluePrintProcessorException("couldn't get resource definition for ($name)")
+ open fun resourceDefinition(name: String): ResourceDefinition? {
+ return if (resourceDictionaries.containsKey(name)) resourceDictionaries[name] else null
}
open fun resolveInputKeyMappingVariables(inputKeyMapping: Map<String, String>): Map<String, JsonNode> {
if (valueToResolve.isEmpty() || !valueToResolve.contains("$")) {
return valueToResolve
}
- //TODO("Optimize to JSON Node directly without velocity").asJsonNode().toString()
+ // TODO("Optimize to JSON Node directly without velocity").asJsonNode().toString()
return BluePrintVelocityTemplateService.generateContent(valueToResolve, keyMapping.asJsonNode().toString())
}
fun addError(error: String) {
raRuntimeService.getBluePrintError().addError(error)
}
-}
\ No newline at end of file
+}