<build>
<sourceDirectory>${project.basedir}/Scripts/kotlin</sourceDirectory>
+ <testSourceDirectory>${project.basedir}/Tests/kotlin</testSourceDirectory>
<resources>
<resource>
<directory>${project.basedir}/Environments</directory>
+++ /dev/null
-/*
- * 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.cds.blueprintsprocessor.functions.resource.resolution
-
-import org.jetbrains.kotlin.script.util.DependsOn
-import org.jetbrains.kotlin.script.util.Repository
-import kotlin.script.experimental.annotations.KotlinScript
-import kotlin.script.experimental.api.ScriptCompilationConfiguration
-import kotlin.script.experimental.api.defaultImports
-import kotlin.script.experimental.jvm.dependenciesFromCurrentContext
-import kotlin.script.experimental.jvm.jvm
-
-@KotlinScript(fileExtension = "resourceassignmentprocessor.kts",
- compilationConfiguration = ResourceAssignmentProcessorScriptConfiguration::class)
-abstract class ResourceAssignmentProcessorScript {
-
-}
-
-object ResourceAssignmentProcessorScriptConfiguration : ScriptCompilationConfiguration(
- {
- defaultImports(DependsOn::class, Repository::class)
- jvm {
- dependenciesFromCurrentContext(
- wholeClasspath = true
- )
- }
- }
-)
\ No newline at end of file
resourceAssignment.property = PropertyDefinitionBuilder(name, type, required, description).apply(block).build()
}
+ fun source(source: NodeTemplate) {
+ resourceAssignment.dictionarySourceDefinition = source
+ }
+
+ fun sourceInput(block: SourceInputNodeTemplateBuilder.() -> Unit) {
+ resourceAssignment.dictionarySourceDefinition = SourceInputNodeTemplateBuilder(dictionarySource, "")
+ .apply(block).build()
+ }
+
+ fun sourceDefault(block: SourceDefaultNodeTemplateBuilder.() -> Unit) {
+ resourceAssignment.dictionarySourceDefinition = SourceDefaultNodeTemplateBuilder(dictionarySource, "")
+ .apply(block).build()
+ }
+
+ fun sourceDb(block: SourceDbNodeTemplateBuilder.() -> Unit) {
+ resourceAssignment.dictionarySourceDefinition = SourceDbNodeTemplateBuilder(dictionarySource, "")
+ .apply(block).build()
+ }
+
+ fun sourceRest(block: SourceRestNodeTemplateBuilder.() -> Unit) {
+ resourceAssignment.dictionarySourceDefinition = SourceRestNodeTemplateBuilder(dictionarySource, "")
+ .apply(block).build()
+ }
+
+ fun sourceCapability(block: SourceCapabilityNodeTemplateBuilder.() -> Unit) {
+ resourceAssignment.dictionarySourceDefinition = SourceCapabilityNodeTemplateBuilder(dictionarySource, "")
+ .apply(block).build()
+ }
+
fun dependencies(dependencies: MutableList<String>) {
resourceAssignment.dependencies = dependencies
}
import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.db.TemplateResolutionService
import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.processor.ResourceAssignmentProcessor
import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.utils.ResourceAssignmentUtils
+import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.utils.ResourceDefinitionUtils.createResourceAssignments
import org.onap.ccsdk.cds.controllerblueprints.core.*
import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintRuntimeService
import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintTemplateService
import org.slf4j.LoggerFactory
import org.springframework.context.ApplicationContext
import org.springframework.stereotype.Service
+import java.util.*
interface ResourceResolutionService {
suspend fun resolveResources(bluePrintRuntimeService: BluePrintRuntimeService<*>, nodeTemplateName: String,
artifactPrefix: String, properties: Map<String, Any>): String
+ /** Resolve resources for all the sources defined in a particular resource Definition[resolveDefinition]
+ * with other [resourceDefinitions] dependencies for the sources [sources]
+ * Used to get the same resource values from multiple sources. **/
+ suspend fun resolveResourceDefinition(blueprintRuntimeService: BluePrintRuntimeService<*>,
+ resourceDefinitions: MutableMap<String, ResourceDefinition>,
+ resolveDefinition: String, sources: List<String>)
+ : MutableMap<String, JsonNode>
+
suspend fun resolveResourceAssignments(blueprintRuntimeService: BluePrintRuntimeService<*>,
resourceDefinitions: MutableMap<String, ResourceDefinition>,
resourceAssignments: MutableList<ResourceAssignment>,
properties: Map<String, Any>): MutableMap<String, JsonNode> {
val resourceAssignmentRuntimeService =
- ResourceAssignmentUtils.transformToRARuntimeService(bluePrintRuntimeService, artifactNames.toString())
+ ResourceAssignmentUtils.transformToRARuntimeService(bluePrintRuntimeService, artifactNames.toString())
val resolvedParams: MutableMap<String, JsonNode> = hashMapOf()
artifactNames.forEach { artifactName ->
val resolvedContent = resolveResources(resourceAssignmentRuntimeService, nodeTemplateName,
- artifactName, properties)
+ artifactName, properties)
resolvedParams[artifactName] = resolvedContent.asJsonType()
}
return resolvedContent
}
+ override suspend fun resolveResourceDefinition(blueprintRuntimeService: BluePrintRuntimeService<*>,
+ resourceDefinitions: MutableMap<String, ResourceDefinition>,
+ resolveDefinition: String, sources: List<String>)
+ : MutableMap<String, JsonNode> {
+
+ // Populate Dummy Resource Assignments
+ val resourceAssignments = createResourceAssignments(resourceDefinitions, resolveDefinition, sources)
+
+ resolveResourceAssignments(blueprintRuntimeService, resourceDefinitions, resourceAssignments,
+ UUID.randomUUID().toString(), hashMapOf())
+
+ // Get the data from Resource Assignments
+ return ResourceAssignmentUtils.generateResourceForAssignments(resourceAssignments)
+ }
+
/**
* Iterate the Batch, get the Resource Assignment, dictionary Name, Look for the Resource definition for the
* name, then get the type of the Resource Definition, Get the instance for the Resource Type and process the
val bulkSequenced = BulkResourceSequencingUtils.process(resourceAssignments)
// Check the BlueprintRuntime Service Should be ResourceAssignmentRuntimeService
- val resourceAssignmentRuntimeService = if (!(blueprintRuntimeService is ResourceAssignmentRuntimeService)) {
+ val resourceAssignmentRuntimeService = if (blueprintRuntimeService !is ResourceAssignmentRuntimeService) {
ResourceAssignmentUtils.transformToRARuntimeService(blueprintRuntimeService, artifactPrefix)
} else {
blueprintRuntimeService
import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceAssignment
import org.slf4j.LoggerFactory
import org.springframework.beans.factory.config.ConfigurableBeanFactory
-import org.springframework.context.ApplicationContext
import org.springframework.context.annotation.Scope
import org.springframework.stereotype.Service
@Service("${PREFIX_RESOURCE_RESOLUTION_PROCESSOR}source-capability")
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
-open class CapabilityResourceResolutionProcessor(private val applicationContext: ApplicationContext,
- private var componentFunctionScriptingService: ComponentFunctionScriptingService)
+open class CapabilityResourceResolutionProcessor(private var componentFunctionScriptingService: ComponentFunctionScriptingService)
: ResourceAssignmentProcessor() {
private val log = LoggerFactory.getLogger(CapabilityResourceResolutionProcessor::class.java)
override suspend fun processNB(resourceAssignment: ResourceAssignment) {
- val resourceDefinition = resourceDictionaries[resourceAssignment.dictionaryName]
- ?: throw BluePrintProcessorException("couldn't get resource definition for ${resourceAssignment.dictionaryName}")
+ val dName = resourceAssignment.dictionaryName!!
+ val dSource = resourceAssignment.dictionarySource!!
+ val resourceDefinition = resourceDefinition(resourceAssignment.dictionaryName!!)
- val resourceSource = resourceDefinition.sources[resourceAssignment.dictionarySource]
- ?: throw BluePrintProcessorException("couldn't get resource definition " +
- "${resourceAssignment.dictionaryName} source(${resourceAssignment.dictionarySource})")
+ /** Check Resource Assignment has the source definitions, If not get from Resource Definition **/
+ val resourceSource = resourceAssignment.dictionarySourceDefinition
+ ?: resourceDefinition?.sources?.get(dSource)
+ ?: throw BluePrintProcessorException("couldn't get resource definition $dName source($dSource)")
val resourceSourceProps = checkNotNull(resourceSource.properties) { "failed to get $resourceSource properties" }
/**
.scriptInstance<ResourceAssignmentProcessor>(raRuntimeService.bluePrintContext(), scriptType,
scriptClassReference)
- instanceDependencies.forEach { instanceDependency ->
- scriptPropertyInstances[instanceDependency] = applicationContext
- .getBean(instanceDependency)
- }
return scriptComponent
}
package org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.processor
import com.fasterxml.jackson.databind.node.JsonNodeFactory
-import com.fasterxml.jackson.databind.node.MissingNode
-import com.fasterxml.jackson.databind.node.NullNode
import org.onap.ccsdk.cds.blueprintsprocessor.db.BluePrintDBLibGenericService
import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.BluePrintDBLibPropertySevice
import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.PrimaryDBLibGenericService
*
* @author Kapil Singal
*/
-@Service("${PREFIX_RESOURCE_RESOLUTION_PROCESSOR}source-processor-db")
+@Service("${PREFIX_RESOURCE_RESOLUTION_PROCESSOR}source-db")
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
open class DatabaseResourceAssignmentProcessor(private val bluePrintDBLibPropertySevice: BluePrintDBLibPropertySevice,
private val primaryDBLibGenericService: PrimaryDBLibGenericService)
private val logger = LoggerFactory.getLogger(DatabaseResourceAssignmentProcessor::class.java)
override fun getName(): String {
- return "${PREFIX_RESOURCE_RESOLUTION_PROCESSOR}source-processor-db"
+ return "${PREFIX_RESOURCE_RESOLUTION_PROCESSOR}source-db"
}
override suspend fun processNB(resourceAssignment: ResourceAssignment) {
// Check if It has Input
try {
val value = raRuntimeService.getInputValue(resourceAssignment.name)
- if (value !is NullNode && value !is MissingNode) {
+ if (value.returnNullIfMissing() != null) {
logger.info("processor-db source template key (${resourceAssignment.name}) found from input and value is ($value)")
ResourceAssignmentUtils.setResourceDataValue(resourceAssignment, raRuntimeService, value)
} else {
}
private fun setValueFromDB(resourceAssignment: ResourceAssignment) {
- val dName = resourceAssignment.dictionaryName
- val dSource = resourceAssignment.dictionarySource
- val resourceDefinition = resourceDictionaries[dName]
- ?: throw BluePrintProcessorException("couldn't get resource dictionary definition for $dName")
- val resourceSource = resourceDefinition.sources[dSource]
+ val dName = resourceAssignment.dictionaryName!!
+ val dSource = resourceAssignment.dictionarySource!!
+ val resourceDefinition = resourceDefinition(dName)
+
+ /** Check Resource Assignment has the source definitions, If not get from Resource Definition **/
+ val resourceSource = resourceAssignment.dictionarySourceDefinition
+ ?: resourceDefinition?.sources?.get(dSource)
?: throw BluePrintProcessorException("couldn't get resource definition $dName source($dSource)")
val resourceSourceProperties = checkNotNull(resourceSource.properties) {
"failed to get source properties for $dName "
val row = rows[0]
val objectNode = JacksonUtils.objectMapper.createObjectNode()
for (mapping in outputKeyMapping.entries) {
- val dbColumnValue = checkNotNull(row[mapping.key])
+ val dbColumnValue = checkNotNull(row[mapping.value])
val propertyTypeForDataType = ResourceAssignmentUtils.getPropertyType(raRuntimeService, type, mapping.key)
JacksonUtils.populatePrimitiveValues(mapping.key, dbColumnValue, propertyTypeForDataType, objectNode)
}
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
return value
}
- 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> {
package org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.processor
-import com.fasterxml.jackson.databind.node.ArrayNode
import com.fasterxml.jackson.databind.node.MissingNode
import com.fasterxml.jackson.databind.node.NullNode
import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.ResourceResolutionConstants.PREFIX_RESOURCE_RESOLUTION_PROCESSOR
// Check if It has Input
val value = getFromInput(resourceAssignment)
if (value == null || value is MissingNode || value is NullNode) {
- val dName = resourceAssignment.dictionaryName
- val dSource = resourceAssignment.dictionarySource
- val resourceDefinition = resourceDictionaries[dName]
- ?: throw BluePrintProcessorException("couldn't get resource dictionary definition for $dName")
+ val dName = resourceAssignment.dictionaryName!!
+ val dSource = resourceAssignment.dictionarySource!!
+ val resourceDefinition = resourceDefinition(dName)
- val resourceSource = resourceDefinition.sources[dSource]
- ?: throw BluePrintProcessorException("couldn't get resource definition $dName source($dSource)")
+ /** Check Resource Assignment has the source definitions, If not get from Resource Definitions **/
+ val resourceSource = resourceAssignment.dictionarySourceDefinition
+ ?: resourceDefinition?.sources?.get(dSource)
+ ?: throw BluePrintProcessorException("couldn't get resource definition $dName source($dSource)")
val resourceSourceProperties =
- checkNotNull(resourceSource.properties) { "failed to get source properties for $dName " }
+ checkNotNull(resourceSource.properties) { "failed to get source properties for $dName " }
val sourceProperties =
- JacksonUtils.getInstanceFromMap(resourceSourceProperties, RestResourceSource::class.java)
+ JacksonUtils.getInstanceFromMap(resourceSourceProperties, RestResourceSource::class.java)
val path = nullToEmpty(sourceProperties.path)
val inputKeyMapping =
- checkNotNull(sourceProperties.inputKeyMapping) { "failed to get input-key-mappings for $dName under $dSource properties" }
+ checkNotNull(sourceProperties.inputKeyMapping) { "failed to get input-key-mappings for $dName under $dSource properties" }
val resolvedInputKeyMapping = resolveInputKeyMappingVariables(inputKeyMapping).toMutableMap()
// Resolving content Variables
val payload = resolveFromInputKeyMapping(nullToEmpty(sourceProperties.payload), resolvedInputKeyMapping)
val urlPath =
- resolveFromInputKeyMapping(checkNotNull(sourceProperties.urlPath), resolvedInputKeyMapping)
+ resolveFromInputKeyMapping(checkNotNull(sourceProperties.urlPath), resolvedInputKeyMapping)
val verb = resolveFromInputKeyMapping(nullToEmpty(sourceProperties.verb), resolvedInputKeyMapping)
logger.info("$dSource dictionary information : ($urlPath), ($inputKeyMapping), (${sourceProperties.outputKeyMapping})")
val outputKeyMapping = sourceProperties.outputKeyMapping
if (responseStatusCode in 200..299 && outputKeyMapping.isNullOrEmpty()) {
logger.info("AS>> outputKeyMapping==null, will not populateResource")
- }
- else if (responseStatusCode in 200..299 && !responseBody.isBlank()) {
+ } else if (responseStatusCode in 200..299 && !responseBody.isBlank()) {
populateResource(resourceAssignment, sourceProperties, responseBody, path)
} else {
val errMsg =
- "Failed to get $dSource result for dictionary name ($dName) using urlPath ($urlPath) response_code: ($responseStatusCode)"
+ "Failed to get $dSource result for dictionary name ($dName) using urlPath ($urlPath) response_code: ($responseStatusCode)"
logger.warn(errMsg)
throw BluePrintProcessorException(errMsg)
}
} catch (e: Exception) {
ResourceAssignmentUtils.setFailedResourceDataValue(resourceAssignment, e.message)
throw BluePrintProcessorException("Failed in template key ($resourceAssignment) assignments with: ${e.message}",
- e)
+ e)
}
}
outputKeyMapping.map {
val responseKeyValue = responseSingleJsonNode.get(it.key)
val propertyTypeForDataType = ResourceAssignmentUtils
- .getPropertyType(raRuntimeService, entrySchemaType, it.key)
+ .getPropertyType(raRuntimeService, entrySchemaType, it.key)
logger.info("For List Type Resource: key (${it.key}), value ($responseKeyValue), " +
"type ({$propertyTypeForDataType})")
JacksonUtils.populateJsonNodeValues(it.value,
- responseKeyValue, propertyTypeForDataType, arrayChildNode)
+ responseKeyValue, propertyTypeForDataType, arrayChildNode)
}
arrayNode.add(arrayChildNode)
}
outputKeyMapping.map {
val responseKeyValue = responseNode.get(it.key)
val propertyTypeForDataType = ResourceAssignmentUtils
- .getPropertyType(raRuntimeService, entrySchemaType, it.key)
+ .getPropertyType(raRuntimeService, entrySchemaType, it.key)
logger.info("For List Type Resource: key (${it.key}), value ($responseKeyValue), type ({$propertyTypeForDataType})")
JacksonUtils.populateJsonNodeValues(it.value, responseKeyValue, propertyTypeForDataType, objectNode)
import com.fasterxml.jackson.databind.JsonNode
import com.fasterxml.jackson.databind.ObjectMapper
-import com.fasterxml.jackson.databind.node.NullNode
import com.fasterxml.jackson.databind.node.ObjectNode
import com.fasterxml.jackson.databind.node.TextNode
import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.ResourceAssignmentRuntimeService
try {
if (resourceProp.type.isNotEmpty()) {
logger.info("Setting Resource Value ($value) for Resource Name " +
- "(${resourceAssignment.name}) of type (${resourceProp.type})")
+ "(${resourceAssignment.name}), definition(${resourceAssignment.dictionaryName}) " +
+ "of type (${resourceProp.type})")
setResourceValue(resourceAssignment, raRuntimeService, value)
resourceAssignment.updatedDate = Date()
resourceAssignment.updatedBy = BluePrintConstants.USER_SYSTEM
"Failed to populate mandatory resource resource mapping $resourceAssignment"
}
if (resourceProp.required != null && resourceProp.required!!
- && (resourceProp.value == null || resourceProp.value !is NullNode)) {
+ && (resourceProp.value == null || resourceProp.value!!.returnNullIfMissing() == null)) {
logger.error("failed to populate mandatory resource mapping ($resourceAssignment)")
throw BluePrintProcessorException("failed to populate mandatory resource mapping ($resourceAssignment)")
}
return result
}
+ @Throws(BluePrintProcessorException::class)
+ fun generateResourceForAssignments(assignments: List<ResourceAssignment>): MutableMap<String, JsonNode> {
+ val data: MutableMap<String, JsonNode> = hashMapOf()
+ assignments.forEach {
+ if (isNotEmpty(it.name) && it.property != null) {
+ val rName = it.name
+ val type = nullToEmpty(it.property?.type).toLowerCase()
+ val value = useDefaultValueIfNull(it, rName)
+ logger.trace("Generating Resource name ($rName), type ($type), value ($value)")
+ data[rName] = value
+ }
+ }
+ return data
+ }
+
private fun useDefaultValueIfNull(resourceAssignment: ResourceAssignment, resourceAssignmentName: String): JsonNode {
if (resourceAssignment.property?.value == null) {
val defaultValue = "\${$resourceAssignmentName}"
--- /dev/null
+/*
+ * 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.cds.blueprintsprocessor.functions.resource.resolution.utils
+
+import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException
+import org.onap.ccsdk.cds.controllerblueprints.core.asJsonString
+import org.onap.ccsdk.cds.controllerblueprints.core.asListOfString
+import org.onap.ccsdk.cds.controllerblueprints.core.data.PropertyDefinition
+import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
+import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceAssignment
+import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceDefinition
+
+object ResourceDefinitionUtils {
+
+ fun definitionDependencies(definition: ResourceDefinition, sources: List<String>): Set<String> {
+ val dependencies: MutableSet<String> = mutableSetOf()
+ definition.sources.forEach { (sourceName, source) ->
+ if (sources.contains(sourceName)) {
+ val keyDependenciesExists = source.properties?.containsKey("key-dependencies") ?: false
+ if (keyDependenciesExists) {
+ dependencies.addAll(source.properties!!["key-dependencies"]!!.asListOfString())
+ }
+ }
+ }
+ return dependencies
+ }
+
+ /** Create a processing resource assignments for the resource definition */
+ fun createResourceAssignments(resourceDefinitions: MutableMap<String, ResourceDefinition>,
+ resolveDefinition: String, sources: List<String>)
+ : MutableList<ResourceAssignment> {
+ /** Check if resolve definition is defined in the resource definition Map */
+ val resourceDefinition = resourceDefinitions[resolveDefinition]
+ ?: throw BluePrintProcessorException("failed to get resolve definition($resolveDefinition)")
+
+ val resourceAssignments: MutableList<ResourceAssignment> = arrayListOf()
+ /** Get the dependency property fields for the the resource definition to resolve */
+ val definitionDependencies = definitionDependencies(resourceDefinition, sources)
+ definitionDependencies.forEach { definitionDependencyName ->
+ val definitionDependency = resourceDefinitions[definitionDependencyName]
+ ?: throw BluePrintProcessorException("failed to get dependency definition($definitionDependencyName)")
+
+ val resourceAssignment = ResourceAssignment().apply {
+ name = definitionDependency.name
+ dictionaryName = definitionDependency.name
+ /** The assumption is al resource are already resolved and shall get as input source */
+ dictionarySource = "input"
+ property = definitionDependency.property
+ }
+ resourceAssignments.add(resourceAssignment)
+ }
+
+ resourceDefinition.sources.forEach { (sourceName, source) ->
+ if (sources.contains(sourceName)) {
+ val resourceAssignment = ResourceAssignment().apply {
+ name = "$sourceName:${resourceDefinition.name}"
+ dictionaryName = resourceDefinition.name
+ dictionarySource = sourceName
+ dictionarySourceDefinition = source
+ // Clone the PropertyDefinition, otherwise property value will be overridden
+ property = JacksonUtils
+ .readValue(resourceDefinition.property.asJsonString(), PropertyDefinition::class.java)
+ val keyDependenciesExists = source.properties?.containsKey("key-dependencies") ?: false
+ if (keyDependenciesExists) {
+ dependencies = source.properties!!["key-dependencies"]!!.asListOfString().toMutableList()
+ }
+ }
+ resourceAssignments.add(resourceAssignment)
+ }
+ }
+ // Populate Resource Definition's dependencies as Input Resource Assignment
+ return resourceAssignments
+ }
+}
\ No newline at end of file
package org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution
+import io.mockk.every
+import io.mockk.mockk
import kotlinx.coroutines.runBlocking
import org.junit.Assert
import org.junit.Before
import org.onap.ccsdk.cds.blueprintsprocessor.db.BluePrintDBLibConfiguration
import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.processor.*
import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.utils.ResourceAssignmentUtils
+import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants
+import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintError
+import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintTypes
+import org.onap.ccsdk.cds.controllerblueprints.core.asJsonPrimitive
import org.onap.ccsdk.cds.controllerblueprints.core.config.BluePrintLoadConfiguration
+import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintContext
import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintMetadataUtils
import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
import org.slf4j.LoggerFactory
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.autoconfigure.EnableAutoConfiguration
+import org.springframework.context.ApplicationContext
import org.springframework.context.annotation.ComponentScan
import org.springframework.test.context.ContextConfiguration
import org.springframework.test.context.TestPropertySource
fun testRegisteredSource() {
val sources = resourceResolutionService.registeredResourceSources()
assertNotNull(sources, "failed to get registered sources")
- assertTrue(sources.containsAll(arrayListOf("source-input", "source-default", "source-processor-db",
- "source-rest")), "failed to get registered sources : $sources")
+ assertTrue(sources.containsAll(arrayListOf("source-input", "source-default", "source-db",
+ "source-rest", "source-capability")), "failed to get registered sources : $sources")
}
@Test
Assert.assertNotNull("failed to create ResourceResolutionService", resourceResolutionService)
val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime("1234",
- "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration")
+ "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration")
val executionServiceInput =
- JacksonUtils.readValueFromClassPathFile("payload/requests/sample-resourceresolution-request.json",
- ExecutionServiceInput::class.java)!!
+ JacksonUtils.readValueFromClassPathFile("payload/requests/sample-resourceresolution-request.json",
+ ExecutionServiceInput::class.java)!!
val resourceAssignmentRuntimeService =
- ResourceAssignmentUtils.transformToRARuntimeService(bluePrintRuntimeService,
- "testResolveResource")
+ ResourceAssignmentUtils.transformToRARuntimeService(bluePrintRuntimeService,
+ "testResolveResource")
// Prepare Inputs
PayloadUtils.prepareInputsFromWorkflowPayload(bluePrintRuntimeService,
- executionServiceInput.payload,
- "resource-assignment")
+ executionServiceInput.payload,
+ "resource-assignment")
resourceResolutionService.resolveResources(resourceAssignmentRuntimeService,
- "resource-assignment",
- "baseconfig",
- props)
+ "resource-assignment",
+ "baseconfig",
+ props)
}
}
Assert.assertNotNull("failed to create ResourceResolutionService", resourceResolutionService)
val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime("1234",
- "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration")
+ "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration")
val executionServiceInput =
- JacksonUtils.readValueFromClassPathFile("payload/requests/sample-resourceresolution-request.json",
- ExecutionServiceInput::class.java)!!
+ JacksonUtils.readValueFromClassPathFile("payload/requests/sample-resourceresolution-request.json",
+ ExecutionServiceInput::class.java)!!
val artefactNames = listOf("baseconfig", "another")
// Prepare Inputs
PayloadUtils.prepareInputsFromWorkflowPayload(bluePrintRuntimeService,
- executionServiceInput.payload,
- "resource-assignment")
+ executionServiceInput.payload,
+ "resource-assignment")
resourceResolutionService.resolveResources(bluePrintRuntimeService,
- "resource-assignment",
- artefactNames,
- props)
+ "resource-assignment",
+ artefactNames,
+ props)
}
}
Assert.assertNotNull("failed to create ResourceResolutionService", resourceResolutionService)
val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime("1234",
- "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration")
+ "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration")
val executionServiceInput =
- JacksonUtils.readValueFromClassPathFile("payload/requests/sample-resourceresolution-request.json",
- ExecutionServiceInput::class.java)!!
+ JacksonUtils.readValueFromClassPathFile("payload/requests/sample-resourceresolution-request.json",
+ ExecutionServiceInput::class.java)!!
val resourceAssignmentRuntimeService =
- ResourceAssignmentUtils.transformToRARuntimeService(bluePrintRuntimeService,
- "testResolveResourcesWithMappingAndTemplate")
+ ResourceAssignmentUtils.transformToRARuntimeService(bluePrintRuntimeService,
+ "testResolveResourcesWithMappingAndTemplate")
val artifactPrefix = "another"
// Prepare Inputs
PayloadUtils.prepareInputsFromWorkflowPayload(bluePrintRuntimeService,
- executionServiceInput.payload,
- "resource-assignment")
+ executionServiceInput.payload,
+ "resource-assignment")
resourceResolutionService.resolveResources(resourceAssignmentRuntimeService,
- "resource-assignment",
- artifactPrefix,
- props)
+ "resource-assignment",
+ artifactPrefix,
+ props)
}
}
Assert.assertNotNull("failed to create ResourceResolutionService", resourceResolutionService)
val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime("1234",
- "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration")
+ "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration")
val executionServiceInput =
- JacksonUtils.readValueFromClassPathFile("payload/requests/sample-resourceresolution-request.json",
- ExecutionServiceInput::class.java)!!
+ JacksonUtils.readValueFromClassPathFile("payload/requests/sample-resourceresolution-request.json",
+ ExecutionServiceInput::class.java)!!
val resourceAssignmentRuntimeService =
- ResourceAssignmentUtils.transformToRARuntimeService(bluePrintRuntimeService,
- "testResolveResourcesWithMappingAndTemplate")
+ ResourceAssignmentUtils.transformToRARuntimeService(bluePrintRuntimeService,
+ "testResolveResourcesWithMappingAndTemplate")
val artifactPrefix = "another"
// Prepare Inputs
PayloadUtils.prepareInputsFromWorkflowPayload(bluePrintRuntimeService,
- executionServiceInput.payload,
- "resource-assignment")
+ executionServiceInput.payload,
+ "resource-assignment")
resourceResolutionService.resolveResources(resourceAssignmentRuntimeService,
- "resource-assignment",
- artifactPrefix,
- props)
+ "resource-assignment",
+ artifactPrefix,
+ props)
+ }
+ }
+
+ @Test
+ fun testResourceResolutionForDefinition() {
+ val resourceDefinitions = BluePrintTypes.resourceDefinitions {
+ resourceDefinition(name = "port-speed", description = "Port Speed") {
+ property(type = "string", required = true)
+ sources {
+ sourceCapability(id = "sdno", description = "SDNO Source") {
+ definedProperties {
+ type(BluePrintConstants.SCRIPT_KOTLIN)
+ scriptClassReference(MockCapabilityScriptRA::class.qualifiedName!!)
+ keyDependencies(arrayListOf("device-id"))
+ }
+ }
+ sourceDb(id = "sdnc", description = "SDNC Controller") {
+ definedProperties {
+ endpointSelector("processor-db")
+ query("SELECT PORT_SPEED FROM XXXX WHERE DEVICE_ID = :device_id")
+ inputKeyMapping {
+ map("device_id", "\$device-id")
+ }
+ keyDependencies(arrayListOf("device-id"))
+ }
+ }
+ }
+ }
+ resourceDefinition(name = "device-id", description = "Device Id") {
+ property(type = "string", required = true) {
+ sources {
+ sourceInput(id = "input", description = "Dependency Source") {}
+ }
+ }
+ }
+ }
+ runBlocking {
+ val raRuntimeService = mockk<ResourceAssignmentRuntimeService>()
+ every { raRuntimeService.bluePrintContext() } returns mockk<BluePrintContext>()
+ every { raRuntimeService.getBluePrintError() } returns BluePrintError()
+ every { raRuntimeService.setBluePrintError(any())} returns Unit
+ every { raRuntimeService.getInputValue("device-id") } returns "123456".asJsonPrimitive()
+
+ val applicationContext = mockk<ApplicationContext>()
+ every { applicationContext.getBean("rr-processor-source-capability") } returns MockCapabilityScriptRA()
+ every { applicationContext.getBean("rr-processor-source-db") } returns MockCapabilityScriptRA()
+ every { applicationContext.getBean("rr-processor-source-input") } returns MockCapabilityScriptRA()
+
+ val sources = arrayListOf<String>("sdno", "sdnc")
+
+ val resourceResolutionService = ResourceResolutionServiceImpl(applicationContext, mockk(), mockk(), mockk())
+ val resolvedResources = resourceResolutionService.resolveResourceDefinition(raRuntimeService,
+ resourceDefinitions, "port-speed", sources)
+ assertNotNull(resolvedResources, "failed to resolve the resources")
}
}
}
package org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.processor
+import io.mockk.coEvery
+import io.mockk.every
+import io.mockk.mockk
import kotlinx.coroutines.runBlocking
-import org.junit.Ignore
import org.junit.Test
import org.junit.runner.RunWith
import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.ResourceAssignmentRuntimeService
+import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.resourceAssignment
import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.ComponentFunctionScriptingService
import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.scripts.BlueprintJythonService
import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.scripts.PythonExecutorProperty
+import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintTypes
+import org.onap.ccsdk.cds.controllerblueprints.core.asJsonPrimitive
import org.onap.ccsdk.cds.controllerblueprints.core.data.PropertyDefinition
+import org.onap.ccsdk.cds.controllerblueprints.core.logger
+import org.onap.ccsdk.cds.controllerblueprints.core.scripts.BluePrintScriptsServiceImpl
+import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintContext
import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintMetadataUtils
import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceAssignment
import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceDefinition
-import org.onap.ccsdk.cds.controllerblueprints.core.scripts.BluePrintScriptsServiceImpl
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.test.context.ContextConfiguration
import org.springframework.test.context.TestPropertySource
import org.springframework.test.context.junit4.SpringRunner
+import kotlin.test.assertEquals
import kotlin.test.assertNotNull
+import kotlin.test.assertTrue
@RunWith(SpringRunner::class)
@ContextConfiguration(classes = [CapabilityResourceResolutionProcessor::class, ComponentFunctionScriptingService::class,
@Autowired
lateinit var capabilityResourceResolutionProcessor: CapabilityResourceResolutionProcessor
- @Ignore
@Test
fun `test kotlin capability`() {
runBlocking {
-
- val bluePrintContext = BluePrintMetadataUtils.getBluePrintContext(
- "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration")
-
- val resourceAssignmentRuntimeService = ResourceAssignmentRuntimeService("1234", bluePrintContext)
-
- capabilityResourceResolutionProcessor.raRuntimeService = resourceAssignmentRuntimeService
- capabilityResourceResolutionProcessor.resourceDictionaries = hashMapOf()
-
-
- val scriptPropertyInstances: MutableMap<String, Any> = mutableMapOf()
- scriptPropertyInstances["mock-service1"] = MockCapabilityService()
- scriptPropertyInstances["mock-service2"] = MockCapabilityService()
-
- val instanceDependencies: List<String> = listOf()
-
- val resourceAssignmentProcessor = capabilityResourceResolutionProcessor
- .scriptInstance("kotlin",
- "ResourceAssignmentProcessor_cba\$ScriptResourceAssignmentProcessor", instanceDependencies)
-
- assertNotNull(resourceAssignmentProcessor, "couldn't get kotlin script resource assignment processor")
-
- val resourceAssignment = ResourceAssignment().apply {
- name = "ra-name"
- dictionaryName = "ra-dict-name"
- dictionarySource = "capability"
- property = PropertyDefinition().apply {
- type = "string"
+ val componentFunctionScriptingService = mockk<ComponentFunctionScriptingService>()
+ coEvery {
+ componentFunctionScriptingService
+ .scriptInstance<ResourceAssignmentProcessor>(any(), any(), any())
+ } returns MockCapabilityScriptRA()
+
+ val raRuntimeService = mockk<ResourceAssignmentRuntimeService>()
+ every { raRuntimeService.bluePrintContext() } returns mockk<BluePrintContext>()
+
+ val capabilityResourceResolutionProcessor = CapabilityResourceResolutionProcessor(componentFunctionScriptingService)
+ capabilityResourceResolutionProcessor.raRuntimeService = raRuntimeService
+
+ val resourceAssignment = BluePrintTypes.resourceAssignment(name = "test-property", dictionaryName = "ra-dict-name",
+ dictionarySource = "capability") {
+ property("string", true, "")
+ sourceCapability {
+ definedProperties {
+ type("internal")
+ scriptClassReference(MockCapabilityScriptRA::class.qualifiedName!!)
+ keyDependencies(arrayListOf("dep-property"))
+ }
}
}
-
- val processorName = resourceAssignmentProcessor.applyNB(resourceAssignment)
- assertNotNull(processorName, "couldn't get kotlin script resource assignment processor name")
- println(processorName)
+ val status = capabilityResourceResolutionProcessor.applyNB(resourceAssignment)
+ assertTrue(status, "failed to execute capability source")
+ assertEquals("assigned-data".asJsonPrimitive(), resourceAssignment.property!!.value,
+ "assigned value miss match")
}
}
open class MockCapabilityService {
+}
+
+open class MockCapabilityScriptRA : ResourceAssignmentProcessor() {
+ val log = logger(MockCapabilityScriptRA::class)
+
+ override fun getName(): String {
+ return "MockCapabilityScriptRA"
+ }
+
+ override suspend fun processNB(executionRequest: ResourceAssignment) {
+ log.info("executing RA mock capability : ${executionRequest.name}")
+ executionRequest.property!!.value = "assigned-data".asJsonPrimitive()
+ }
+
+ override suspend fun recoverNB(runtimeException: RuntimeException, executionRequest: ResourceAssignment) {
+ TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
+ }
}
\ No newline at end of file
package org.onap.ccsdk.cds.blueprintsprocessor.db
-import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintDependencyService
import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintProperties
import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.BluePrintDBLibPropertySevice
+import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.PrimaryDBLibGenericService
+import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintDependencyService
import org.springframework.boot.context.properties.EnableConfigurationProperties
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.ComponentScan
/**
* Exposed Dependency Service by this SSH Lib Module
*/
-//TODO("right now not wired with name ")
fun BluePrintDependencyService.dbLibPropertyService(): BluePrintDBLibPropertySevice =
- instance(DBLibConstants.SERVICE_BLUEPRINT_DB_LIB_PROPERTY)
+ instance(BluePrintDBLibPropertySevice::class)
+
+fun BluePrintDependencyService.primaryDBLibGenericService(): BluePrintDBLibGenericService =
+ instance(PrimaryDBLibGenericService::class)
class DBLibConstants {
companion object {
- //TODO("right now not wired with name ")
- const val SERVICE_BLUEPRINT_DB_LIB_PROPERTY = "blueprint-db-lib-property-service"
const val PREFIX_DB_PRIMARY: String = "blueprintsprocessor.db.primary"
//list of database
const val DRIVER_MYSQL_DB = "com.mysql.jdbc.Driver"
const val DRIVER_ORACLE_DB = "oracle.jdbc.driver.OracleDriver"
const val DRIVER_POSTGRES_DB = "org.postgresql.Driver"
-
-
}
}
\ No newline at end of file
}
fun JdbcTemplate(selector: String): BluePrintDBLibGenericService {
- val prefix = "blueprintsprocessor.database.$selector"
+ val prefix = "blueprintsprocessor.db.$selector"
val dBConnetionProperties = dBDataSourceProperties(prefix)
return blueprintDBDataSourceService(dBConnetionProperties)
}
import com.fasterxml.jackson.databind.node.*
import org.apache.commons.lang3.ObjectUtils
import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
-import org.slf4j.LoggerFactory
import org.onap.ccsdk.cds.controllerblueprints.core.utils.JsonParserUtils
+import org.slf4j.LoggerFactory
import org.slf4j.helpers.MessageFormatter
import kotlin.reflect.KClass
return JacksonUtils.getListFromJsonNode(this, String::class.java)
}
+fun JsonNode.asListOfString(): List<String> {
+ check(this is ArrayNode) { "JsonNode is not of type ArrayNode" }
+ return this.asListOfString()
+}
+
fun JsonNode.returnNullIfMissing(): JsonNode? {
return if (this is NullNode || this is MissingNode) {
null
import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException
import org.springframework.context.ApplicationContext
+import kotlin.reflect.KClass
/**
* Generic Bluepring Dependency Service, which will be used mainly in scripts.
return applicationContext.getBean(type)
?: throw BluePrintProcessorException("failed to get instance($type)")
}
+
+ inline fun <reified T> instance(type: KClass<*>): T {
+ return applicationContext.getBean(type.java) as? T
+ ?: throw BluePrintProcessorException("failed to get instance($type)")
+ }
}
\ No newline at end of file
fun populatePrimitiveValues(key: String, value: Any, primitiveType: String, objectNode: ObjectNode) {
when (primitiveType.toLowerCase()) {
- BluePrintConstants.DATA_TYPE_BOOLEAN -> objectNode.put(key, (value as BooleanNode).booleanValue())
- BluePrintConstants.DATA_TYPE_INTEGER -> objectNode.put(key, (value as IntNode).intValue())
- BluePrintConstants.DATA_TYPE_FLOAT -> objectNode.put(key, (value as FloatNode).floatValue())
- BluePrintConstants.DATA_TYPE_DOUBLE -> objectNode.put(key, (value as DoubleNode).doubleValue())
- else -> objectNode.put(key, (value as TextNode).textValue())
+ BluePrintConstants.DATA_TYPE_STRING,
+ BluePrintConstants.DATA_TYPE_BOOLEAN,
+ BluePrintConstants.DATA_TYPE_INTEGER,
+ BluePrintConstants.DATA_TYPE_FLOAT,
+ BluePrintConstants.DATA_TYPE_DOUBLE,
+ BluePrintConstants.DATA_TYPE_TIMESTAMP ->
+ objectNode.set(key, value.asJsonPrimitive())
+ else -> objectNode.set(key, value.asJsonType())
}
}
@JsonProperty("dictionary-source")
var dictionarySource: String? = null
+ /** Modified Source definition, Capability Source will use for script reference changes,
+ * Rest Source will use for extra headers etc **/
+ @JsonProperty("dictionary-source-definition")
+ var dictionarySourceDefinition: NodeTemplate? = null
+
+ /** Duplicate field : Shall be used directly from Dictionary Source definition dependencies. **/
@JsonProperty("dependencies")
var dependencies: MutableList<String>? = null
package org.onap.ccsdk.cds.controllerblueprints.resource.dict.utils
import org.apache.commons.collections.CollectionUtils
+import org.onap.ccsdk.cds.controllerblueprints.core.asListOfString
import org.onap.ccsdk.cds.controllerblueprints.core.utils.TopologicalSortingUtils
import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceAssignment
import org.slf4j.LoggerFactory
-import java.util.ArrayList
+import java.util.*
+
/**
* BulkResourceSequencingUtils.
*
* @author Brinda Santh
*/
object BulkResourceSequencingUtils {
- private val log= LoggerFactory.getLogger(BulkResourceSequencingUtils::class.java)
+ private val log = LoggerFactory.getLogger(BulkResourceSequencingUtils::class.java)
@JvmStatic
fun process(resourceAssignments: MutableList<ResourceAssignment>): List<List<ResourceAssignment>> {
// Preepare Sorting Map
val topologySorting = TopologicalSortingUtils<ResourceAssignment>()
resourceAssignmentMap.forEach { _, resourceAssignment ->
- if (CollectionUtils.isNotEmpty(resourceAssignment.dependencies)) {
+ // Get the dependencies from the assignment sources, if not get from the Resource Assignment dependencies
+ if (resourceAssignment.dictionarySourceDefinition != null) {
+ val dependencies = resourceAssignment.dictionarySourceDefinition?.properties?.get("key-dependencies")?.asListOfString()
+ dependencies?.forEach { dependency ->
+ topologySorting.add(resourceAssignmentMap[dependency]!!, resourceAssignment)
+ }
+ } else if (CollectionUtils.isNotEmpty(resourceAssignment.dependencies)) {
for (dependency in resourceAssignment.dependencies!!) {
topologySorting.add(resourceAssignmentMap[dependency]!!, resourceAssignment)
}