diff options
author | Singal, Kapil (ks220y) <ks220y@att.com> | 2019-11-22 18:06:08 -0500 |
---|---|---|
committer | KAPIL SINGAL <ks220y@att.com> | 2019-11-26 21:32:38 +0000 |
commit | 341db21b2ac0a14a1ed2b8bf7930914dda054bfe (patch) | |
tree | 113bba965b06cfe3a8af3a0a527d1a41c9faf0f9 /ms/blueprintsprocessor/functions/resource-resolution/src/main | |
parent | d274e5fc552cf9ae25500f504f0434981cf3accf (diff) |
Formatting Code base with ktlint
No Business logic change, just the code format.
Competible with IntelliJ: https://github.com/pinterest/ktlint#option-3
To format run: mvn process-sources -P format
Issue-ID: CCSDK-1947
Signed-off-by: Singal, Kapil (ks220y) <ks220y@att.com>
Change-Id: Ic9e9209fb7023d77f434693ad5a01229f8d09331
Diffstat (limited to 'ms/blueprintsprocessor/functions/resource-resolution/src/main')
25 files changed, 907 insertions, 510 deletions
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceAssignmentRuntimeService.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceAssignmentRuntimeService.kt index 3a3750acb..a65ec585b 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceAssignmentRuntimeService.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceAssignmentRuntimeService.kt @@ -5,8 +5,8 @@ import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintContext import org.onap.ccsdk.cds.controllerblueprints.core.service.DefaultBluePrintRuntimeService -class ResourceAssignmentRuntimeService(private var id: String, private var bluePrintContext: BluePrintContext) - : DefaultBluePrintRuntimeService(id, bluePrintContext) { +class ResourceAssignmentRuntimeService(private var id: String, private var bluePrintContext: BluePrintContext) : + DefaultBluePrintRuntimeService(id, bluePrintContext) { private lateinit var resolutionId: String private var resourceStore: MutableMap<String, JsonNode> = hashMapOf() @@ -25,7 +25,7 @@ class ResourceAssignmentRuntimeService(private var id: String, private var blueP fun getResolutionStore(key: String): JsonNode { return resourceStore[key] - ?: throw BluePrintProcessorException("failed to get execution property ($key)") + ?: throw BluePrintProcessorException("failed to get execution property ($key)") } fun checkResolutionStore(key: String): Boolean { @@ -58,7 +58,7 @@ class ResourceAssignmentRuntimeService(private var id: String, private var blueP fun getDictionaryStore(key: String): JsonNode { return resourceStore["dictionary-$key"] - ?: throw BluePrintProcessorException("failed to get execution property (dictionary-$key)") + ?: throw BluePrintProcessorException("failed to get execution property (dictionary-$key)") } fun checkDictionaryStore(key: String): Boolean { @@ -84,5 +84,4 @@ class ResourceAssignmentRuntimeService(private var id: String, private var blueP fun getDoubleFromDictionaryStore(key: String): Double? { return getResolutionStore("dictionary-$key").asDouble() } - } diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceDefinitionDSL.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceDefinitionDSL.kt index 141bad619..7c6ba603b 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceDefinitionDSL.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceDefinitionDSL.kt @@ -24,32 +24,42 @@ import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceAssignment import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceDefinition /** Resource Definition DSL **/ -fun BluePrintTypes.resourceDefinitions(block: ResourceDefinitionsBuilder.() -> Unit) - : MutableMap<String, ResourceDefinition> { +fun BluePrintTypes.resourceDefinitions(block: ResourceDefinitionsBuilder.() -> Unit): + MutableMap<String, ResourceDefinition> { return ResourceDefinitionsBuilder().apply(block).build() } -fun BluePrintTypes.resourceDefinition(name: String, description: String, - block: ResourceDefinitionBuilder.() -> Unit): ResourceDefinition { +fun BluePrintTypes.resourceDefinition( + name: String, + description: String, + block: ResourceDefinitionBuilder.() -> Unit +): ResourceDefinition { return ResourceDefinitionBuilder(name, description).apply(block).build() } /** Resource Mapping DSL **/ -fun BluePrintTypes.resourceAssignments(block: ResourceAssignmentsBuilder.() -> Unit) - : MutableMap<String, ResourceAssignment> { +fun BluePrintTypes.resourceAssignments(block: ResourceAssignmentsBuilder.() -> Unit): + MutableMap<String, ResourceAssignment> { return ResourceAssignmentsBuilder().apply(block).build() } -fun BluePrintTypes.resourceAssignment(name: String, dictionaryName: String, dictionarySource: String, - block: ResourceAssignmentBuilder.() -> Unit): ResourceAssignment { +fun BluePrintTypes.resourceAssignment( + name: String, + dictionaryName: String, + dictionarySource: String, + block: ResourceAssignmentBuilder.() -> Unit +): ResourceAssignment { return ResourceAssignmentBuilder(name, dictionaryName, dictionarySource).apply(block).build() } class ResourceDefinitionsBuilder() { private val resourceDefinitions: MutableMap<String, ResourceDefinition> = hashMapOf() - fun resourceDefinition(name: String, description: String, - block: ResourceDefinitionBuilder.() -> Unit) { + fun resourceDefinition( + name: String, + description: String, + block: ResourceDefinitionBuilder.() -> Unit + ) { val resourceDefinition = ResourceDefinitionBuilder(name, description).apply(block).build() resourceDefinitions[resourceDefinition.name] = resourceDefinition } @@ -82,8 +92,11 @@ class ResourceDefinitionBuilder(private val name: String, private val descriptio resourceDefinition.property = PropertyDefinitionBuilder(name, type, required, description).build() } - fun property(type: String, required: Boolean, - block: PropertyDefinitionBuilder.() -> Unit) { + fun property( + type: String, + required: Boolean, + block: PropertyDefinitionBuilder.() -> Unit + ) { resourceDefinition.property = PropertyDefinitionBuilder(name, type, required, description).apply(block).build() } @@ -136,8 +149,12 @@ class ResourceDefinitionSourcesBuilder { class ResourceAssignmentsBuilder() { private val resourceAssignments: MutableMap<String, ResourceAssignment> = hashMapOf() - fun resourceAssignment(name: String, dictionaryName: String, dictionarySource: String, - block: ResourceAssignmentBuilder.() -> Unit) { + fun resourceAssignment( + name: String, + dictionaryName: String, + dictionarySource: String, + block: ResourceAssignmentBuilder.() -> Unit + ) { val resourceAssignment = ResourceAssignmentBuilder(name, dictionaryName, dictionarySource).apply(block).build() resourceAssignments[resourceAssignment.name] = resourceAssignment } @@ -151,8 +168,12 @@ class ResourceAssignmentsBuilder() { } } -class ResourceAssignmentBuilder(private val name: String, private val dictionaryName: String, - private val dictionarySource: String) { +class ResourceAssignmentBuilder( + private val name: String, + private val dictionaryName: String, + private val dictionarySource: String +) { + private val resourceAssignment = ResourceAssignment() fun inputParameter(inputParameter: Boolean) { @@ -163,8 +184,12 @@ class ResourceAssignmentBuilder(private val name: String, private val dictionary resourceAssignment.property = PropertyDefinitionBuilder(name, type, required, description).build() } - fun property(type: String, required: Boolean, description: String? = "", - block: PropertyDefinitionBuilder.() -> Unit) { + fun property( + type: String, + required: Boolean, + description: String? = "", + block: PropertyDefinitionBuilder.() -> Unit + ) { resourceAssignment.property = PropertyDefinitionBuilder(name, type, required, description).apply(block).build() } @@ -174,27 +199,27 @@ class ResourceAssignmentBuilder(private val name: String, private val dictionary fun sourceInput(block: SourceInputNodeTemplateBuilder.() -> Unit) { resourceAssignment.dictionarySourceDefinition = SourceInputNodeTemplateBuilder(dictionarySource, "") - .apply(block).build() + .apply(block).build() } fun sourceDefault(block: SourceDefaultNodeTemplateBuilder.() -> Unit) { resourceAssignment.dictionarySourceDefinition = SourceDefaultNodeTemplateBuilder(dictionarySource, "") - .apply(block).build() + .apply(block).build() } fun sourceDb(block: SourceDbNodeTemplateBuilder.() -> Unit) { resourceAssignment.dictionarySourceDefinition = SourceDbNodeTemplateBuilder(dictionarySource, "") - .apply(block).build() + .apply(block).build() } fun sourceRest(block: SourceRestNodeTemplateBuilder.() -> Unit) { resourceAssignment.dictionarySourceDefinition = SourceRestNodeTemplateBuilder(dictionarySource, "") - .apply(block).build() + .apply(block).build() } fun sourceCapability(block: SourceCapabilityNodeTemplateBuilder.() -> Unit) { resourceAssignment.dictionarySourceDefinition = SourceCapabilityNodeTemplateBuilder(dictionarySource, "") - .apply(block).build() + .apply(block).build() } fun dependencies(dependencies: MutableList<String>) { @@ -207,4 +232,4 @@ class ResourceAssignmentBuilder(private val name: String, private val dictionary resourceAssignment.dictionarySource = dictionarySource return resourceAssignment } -}
\ No newline at end of file +} diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponent.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponent.kt index 0521919aa..293f29cfc 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponent.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponent.kt @@ -32,8 +32,9 @@ import org.springframework.stereotype.Component @Component("component-resource-resolution") @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) open class ResourceResolutionComponent(private val resourceResolutionService: ResourceResolutionService) : - AbstractComponentFunction() { - companion object{ + AbstractComponentFunction() { + + companion object { const val INPUT_REQUEST_ID = "request-id" const val INPUT_RESOURCE_ID = "resource-id" const val INPUT_ACTION_NAME = "action-name" @@ -54,11 +55,14 @@ open class ResourceResolutionComponent(private val resourceResolutionService: Re override suspend fun processNB(executionRequest: ExecutionServiceInput) { val occurrence = getOptionalOperationInput(ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_OCCURRENCE)?.asInt() ?: 1 - val resolutionKey = getOptionalOperationInput(ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOLUTION_KEY)?.returnNullIfMissing()?.textValue() ?: "" + val resolutionKey = + getOptionalOperationInput(ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOLUTION_KEY)?.returnNullIfMissing()?.textValue() ?: "" val storeResult = getOptionalOperationInput(ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_STORE_RESULT)?.asBoolean() ?: false - val resourceId = getOptionalOperationInput(ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOURCE_ID)?.returnNullIfMissing()?.textValue() ?: "" + val resourceId = + getOptionalOperationInput(ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOURCE_ID)?.returnNullIfMissing()?.textValue() ?: "" - val resourceType = getOptionalOperationInput(ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOURCE_TYPE)?.returnNullIfMissing()?.textValue() ?: "" + val resourceType = + getOptionalOperationInput(ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOURCE_TYPE)?.returnNullIfMissing()?.textValue() ?: "" val properties: MutableMap<String, Any> = mutableMapOf() properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_STORE_RESULT] = storeResult @@ -69,8 +73,10 @@ open class ResourceResolutionComponent(private val resourceResolutionService: Re val jsonResponse = JsonNodeFactory.instance.objectNode() // Initialize Output Attribute to empty JSON - bluePrintRuntimeService.setNodeTemplateAttributeValue(nodeTemplateName, - ResourceResolutionConstants.OUTPUT_ASSIGNMENT_PARAMS, jsonResponse) + bluePrintRuntimeService.setNodeTemplateAttributeValue( + nodeTemplateName, + ResourceResolutionConstants.OUTPUT_ASSIGNMENT_PARAMS, jsonResponse + ) // validate inputs if we need to store the resource and template resolution. if (storeResult) { @@ -79,8 +85,10 @@ open class ResourceResolutionComponent(private val resourceResolutionService: Re } else if ((resourceType.isNotEmpty() && resourceId.isEmpty()) || (resourceType.isEmpty() && resourceId.isNotEmpty())) { throw BluePrintProcessorException("Can't proceed with the resolution: both resource-id and resource-type should be provided, one of them is missing.") } else if (resourceType.isEmpty() && resourceId.isEmpty() && resolutionKey.isEmpty()) { - throw BluePrintProcessorException("Can't proceed with the resolution: can't persist resolution without a correlation key. " + - "Either provide a resolution-key OR combination of resource-id and resource-type OR set `storeResult` to false.") + throw BluePrintProcessorException( + "Can't proceed with the resolution: can't persist resolution without a correlation key. " + + "Either provide a resolution-key OR combination of resource-id and resource-type OR set `storeResult` to false." + ) } } @@ -90,10 +98,12 @@ open class ResourceResolutionComponent(private val resourceResolutionService: Re for (j in 1..occurrence) { properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_OCCURRENCE] = j - val response = resourceResolutionService.resolveResources(bluePrintRuntimeService, - nodeTemplateName, - artifactPrefixNames, - properties) + val response = resourceResolutionService.resolveResources( + bluePrintRuntimeService, + nodeTemplateName, + artifactPrefixNames, + properties + ) // provide indexed result in output if we have multiple resolution if (occurrence != 1) { @@ -101,15 +111,16 @@ open class ResourceResolutionComponent(private val resourceResolutionService: Re } else { jsonResponse.setAll(response.asObjectNode()) } - } // Set Output Attributes with resolved value - bluePrintRuntimeService.setNodeTemplateAttributeValue(nodeTemplateName, - ResourceResolutionConstants.OUTPUT_ASSIGNMENT_PARAMS, jsonResponse) + bluePrintRuntimeService.setNodeTemplateAttributeValue( + nodeTemplateName, + ResourceResolutionConstants.OUTPUT_ASSIGNMENT_PARAMS, jsonResponse + ) } override suspend fun recoverNB(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) { bluePrintRuntimeService.getBluePrintError().addError(runtimeException.message!!) } -}
\ No newline at end of file +} diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponentDSL.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponentDSL.kt index 40ea47e33..25338c6ca 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponentDSL.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponentDSL.kt @@ -17,81 +17,118 @@ package org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution import com.fasterxml.jackson.databind.JsonNode -import org.onap.ccsdk.cds.controllerblueprints.core.* +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintTypes +import org.onap.ccsdk.cds.controllerblueprints.core.asJsonPrimitive +import org.onap.ccsdk.cds.controllerblueprints.core.asJsonString +import org.onap.ccsdk.cds.controllerblueprints.core.asJsonType import org.onap.ccsdk.cds.controllerblueprints.core.data.NodeTemplate import org.onap.ccsdk.cds.controllerblueprints.core.data.NodeType import org.onap.ccsdk.cds.controllerblueprints.core.dsl.AbstractNodeTemplateOperationImplBuilder import org.onap.ccsdk.cds.controllerblueprints.core.dsl.PropertiesAssignmentBuilder import org.onap.ccsdk.cds.controllerblueprints.core.dsl.nodeType +import org.onap.ccsdk.cds.controllerblueprints.core.jsonAsJsonType /** Component Extensions **/ fun BluePrintTypes.nodeTypeComponentResourceResolution(): NodeType { - return nodeType(id = "component-resource-resolution", version = BluePrintConstants.DEFAULT_VERSION_NUMBER, - derivedFrom = BluePrintConstants.MODEL_TYPE_NODE_COMPONENT, - description = "Resource Assignment Component") { - - attribute(ResourceResolutionComponent.ATTRIBUTE_ASSIGNMENT_PARAM, BluePrintConstants.DATA_TYPE_STRING, - true) - attribute(ResourceResolutionComponent.ATTRIBUTE_STATUS, BluePrintConstants.DATA_TYPE_STRING, - true) + return nodeType( + id = "component-resource-resolution", version = BluePrintConstants.DEFAULT_VERSION_NUMBER, + derivedFrom = BluePrintConstants.MODEL_TYPE_NODE_COMPONENT, + description = "Resource Assignment Component" + ) { + + attribute( + ResourceResolutionComponent.ATTRIBUTE_ASSIGNMENT_PARAM, BluePrintConstants.DATA_TYPE_STRING, + true + ) + attribute( + ResourceResolutionComponent.ATTRIBUTE_STATUS, BluePrintConstants.DATA_TYPE_STRING, + true + ) operation("ResourceResolutionComponent", "ResourceResolutionComponent Operation") { inputs { - property(ResourceResolutionComponent.INPUT_REQUEST_ID, BluePrintConstants.DATA_TYPE_STRING, - true, "Request Id, Unique Id for the request.") - - property(ResourceResolutionComponent.INPUT_RESOURCE_ID, BluePrintConstants.DATA_TYPE_STRING, - false, "Resource Id.") - - property(ResourceResolutionComponent.INPUT_ACTION_NAME, BluePrintConstants.DATA_TYPE_STRING, - false, "Action Name of the process") - - property(ResourceResolutionComponent.INPUT_DYNAMIC_PROPERTIES, BluePrintConstants.DATA_TYPE_JSON, - false, "Dynamic Json Content or DSL Json reference.") - - property(ResourceResolutionComponent.INPUT_RESOLUTION_KEY, BluePrintConstants.DATA_TYPE_STRING, - false, "Key for service instance related correlation.") - - property(ResourceResolutionComponent.INPUT_OCCURRENCE, BluePrintConstants.DATA_TYPE_INTEGER, - false, "Number of time to perform the resolution.") { + property( + ResourceResolutionComponent.INPUT_REQUEST_ID, BluePrintConstants.DATA_TYPE_STRING, + true, "Request Id, Unique Id for the request." + ) + + property( + ResourceResolutionComponent.INPUT_RESOURCE_ID, BluePrintConstants.DATA_TYPE_STRING, + false, "Resource Id." + ) + + property( + ResourceResolutionComponent.INPUT_ACTION_NAME, BluePrintConstants.DATA_TYPE_STRING, + false, "Action Name of the process" + ) + + property( + ResourceResolutionComponent.INPUT_DYNAMIC_PROPERTIES, BluePrintConstants.DATA_TYPE_JSON, + false, "Dynamic Json Content or DSL Json reference." + ) + + property( + ResourceResolutionComponent.INPUT_RESOLUTION_KEY, BluePrintConstants.DATA_TYPE_STRING, + false, "Key for service instance related correlation." + ) + + property( + ResourceResolutionComponent.INPUT_OCCURRENCE, BluePrintConstants.DATA_TYPE_INTEGER, + false, "Number of time to perform the resolution." + ) { defaultValue(1) } - property(ResourceResolutionComponent.INPUT_STORE_RESULT, BluePrintConstants.DATA_TYPE_BOOLEAN, - false, "Whether or not to store the output.") + property( + ResourceResolutionComponent.INPUT_STORE_RESULT, BluePrintConstants.DATA_TYPE_BOOLEAN, + false, "Whether or not to store the output." + ) - property(ResourceResolutionComponent.INPUT_RESOURCE_TYPE, BluePrintConstants.DATA_TYPE_STRING, - false, "Request type.") + property( + ResourceResolutionComponent.INPUT_RESOURCE_TYPE, BluePrintConstants.DATA_TYPE_STRING, + false, "Request type." + ) - property(ResourceResolutionComponent.INPUT_ARTIFACT_PREFIX_NAMES, BluePrintConstants.DATA_TYPE_LIST, - true, "Template , Resource Assignment Artifact Prefix names") { + property( + ResourceResolutionComponent.INPUT_ARTIFACT_PREFIX_NAMES, BluePrintConstants.DATA_TYPE_LIST, + true, "Template , Resource Assignment Artifact Prefix names" + ) { entrySchema(BluePrintConstants.DATA_TYPE_STRING) } } outputs { - property(ResourceResolutionComponent.OUTPUT_RESOURCE_ASSIGNMENT_PARAMS, BluePrintConstants.DATA_TYPE_STRING, - true, "Output Response") - property(ResourceResolutionComponent.OUTPUT_STATUS, BluePrintConstants.DATA_TYPE_STRING, - true, "Status of the Component Execution ( success or failure )") + property( + ResourceResolutionComponent.OUTPUT_RESOURCE_ASSIGNMENT_PARAMS, BluePrintConstants.DATA_TYPE_STRING, + true, "Output Response" + ) + property( + ResourceResolutionComponent.OUTPUT_STATUS, BluePrintConstants.DATA_TYPE_STRING, + true, "Status of the Component Execution ( success or failure )" + ) } } } } /** Component Builder */ -fun BluePrintTypes.nodeTemplateComponentResourceResolution(id: String, - description: String, - block: ComponentResourceResolutionNodeTemplateBuilder.() -> Unit) - : NodeTemplate { +fun BluePrintTypes.nodeTemplateComponentResourceResolution( + id: String, + description: String, + block: ComponentResourceResolutionNodeTemplateBuilder.() -> Unit +): + NodeTemplate { return ComponentResourceResolutionNodeTemplateBuilder(id, description).apply(block).build() } class ComponentResourceResolutionNodeTemplateBuilder(id: String, description: String) : - AbstractNodeTemplateOperationImplBuilder<PropertiesAssignmentBuilder, - ComponentResourceResolutionNodeTemplateBuilder.InputsBuilder, - ComponentResourceResolutionNodeTemplateBuilder.OutputsBuilder>(id, "component-script-executor", - "ComponentResourceResolution", - description) { + AbstractNodeTemplateOperationImplBuilder<PropertiesAssignmentBuilder, + ComponentResourceResolutionNodeTemplateBuilder.InputsBuilder, + ComponentResourceResolutionNodeTemplateBuilder.OutputsBuilder>( + id, "component-script-executor", + "ComponentResourceResolution", + description + ) { class InputsBuilder : PropertiesAssignmentBuilder() { @@ -146,7 +183,7 @@ class ComponentResourceResolutionNodeTemplateBuilder(id: String, description: St fun artifactPrefixNames(artifactPrefixNames: String) = artifactPrefixNames(artifactPrefixNames.jsonAsJsonType()) fun artifactPrefixNames(artifactPrefixNameList: List<String>) = - artifactPrefixNames(artifactPrefixNameList.asJsonString()) + artifactPrefixNames(artifactPrefixNameList.asJsonString()) fun artifactPrefixNames(artifactPrefixNames: JsonNode) { property(ResourceResolutionComponent.INPUT_ARTIFACT_PREFIX_NAMES, artifactPrefixNames) @@ -162,10 +199,10 @@ class ComponentResourceResolutionNodeTemplateBuilder(id: String, description: St } fun resourceAssignmentParams(resourceAssignmentParams: String) = - resourceAssignmentParams(resourceAssignmentParams.asJsonType()) + resourceAssignmentParams(resourceAssignmentParams.asJsonType()) fun resourceAssignmentParams(resourceAssignmentParams: JsonNode) { property(ResourceResolutionComponent.OUTPUT_RESOURCE_ASSIGNMENT_PARAMS, resourceAssignmentParams) } } -}
\ No newline at end of file +} diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionConfiguration.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionConfiguration.kt index 13ff0a73f..219040e6b 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionConfiguration.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionConfiguration.kt @@ -22,5 +22,3 @@ import org.springframework.context.annotation.Configuration @Configuration @ComponentScan open class ResourceResolutionConfiguration - - diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionConstants.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionConstants.kt index 537074383..0726d2871 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionConstants.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionConstants.kt @@ -19,15 +19,15 @@ package org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution object ResourceResolutionConstants { - const val SERVICE_RESOURCE_RESOLUTION = "resource-resolution-service" - const val PREFIX_RESOURCE_RESOLUTION_PROCESSOR = "rr-processor-" - const val INPUT_ARTIFACT_PREFIX_NAMES = "artifact-prefix-names" - const val OUTPUT_ASSIGNMENT_PARAMS = "assignment-params" - const val FILE_NAME_RESOURCE_DEFINITION_TYPES = "resources_definition_types.json" - const val RESOURCE_RESOLUTION_INPUT_RESOLUTION_KEY = "resolution-key" - const val RESOURCE_RESOLUTION_INPUT_STORE_RESULT = "store-result" - const val RESOURCE_RESOLUTION_INPUT_OCCURRENCE = "occurrence" - const val RESOURCE_RESOLUTION_INPUT_RESOURCE_ID = "resource-id" - const val RESOURCE_RESOLUTION_INPUT_RESOURCE_TYPE = "resource-type" - const val RESOURCE_RESOLUTION_LOG_PROTECTED_METADATA = "log-protect" -}
\ No newline at end of file + const val SERVICE_RESOURCE_RESOLUTION = "resource-resolution-service" + const val PREFIX_RESOURCE_RESOLUTION_PROCESSOR = "rr-processor-" + const val INPUT_ARTIFACT_PREFIX_NAMES = "artifact-prefix-names" + const val OUTPUT_ASSIGNMENT_PARAMS = "assignment-params" + const val FILE_NAME_RESOURCE_DEFINITION_TYPES = "resources_definition_types.json" + const val RESOURCE_RESOLUTION_INPUT_RESOLUTION_KEY = "resolution-key" + const val RESOURCE_RESOLUTION_INPUT_STORE_RESULT = "store-result" + const val RESOURCE_RESOLUTION_INPUT_OCCURRENCE = "occurrence" + const val RESOURCE_RESOLUTION_INPUT_RESOURCE_ID = "resource-id" + const val RESOURCE_RESOLUTION_INPUT_RESOURCE_TYPE = "resource-type" + const val RESOURCE_RESOLUTION_LOG_PROTECTED_METADATA = "log-protect" +} diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionExtensions.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionExtensions.kt index ab01b15b7..53ce65d0b 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionExtensions.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionExtensions.kt @@ -20,18 +20,18 @@ import kotlinx.coroutines.runBlocking import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.AbstractComponentFunction import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintDependencyService - /** * Register the Resolution module exposed dependency */ fun BluePrintDependencyService.resourceResolutionService(): ResourceResolutionService = - instance(ResourceResolutionConstants.SERVICE_RESOURCE_RESOLUTION) - + instance(ResourceResolutionConstants.SERVICE_RESOURCE_RESOLUTION) -suspend fun AbstractComponentFunction.storedContentFromResolvedArtifactNB(resolutionKey: String, - artifactName: String): String { +suspend fun AbstractComponentFunction.storedContentFromResolvedArtifactNB( + resolutionKey: String, + artifactName: String +): String { return BluePrintDependencyService.resourceResolutionService() - .resolveFromDatabase(bluePrintRuntimeService, artifactName, resolutionKey) + .resolveFromDatabase(bluePrintRuntimeService, artifactName, resolutionKey) } /** @@ -39,16 +39,15 @@ suspend fun AbstractComponentFunction.storedContentFromResolvedArtifactNB(resolu */ suspend fun AbstractComponentFunction.contentFromResolvedArtifactNB(artifactPrefix: String): String { return BluePrintDependencyService.resourceResolutionService() - .resolveResources(bluePrintRuntimeService, nodeTemplateName, artifactPrefix, mapOf()) + .resolveResources(bluePrintRuntimeService, nodeTemplateName, artifactPrefix, mapOf()) } - /** * Blocking Methods called from Jython Scripts */ -fun AbstractComponentFunction.storedContentFromResolvedArtifact(resolutionKey: String, artifactName: String) - : String = runBlocking { +fun AbstractComponentFunction.storedContentFromResolvedArtifact(resolutionKey: String, artifactName: String): + String = runBlocking { storedContentFromResolvedArtifactNB(resolutionKey, artifactName) } diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionService.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionService.kt index 28e7d395a..14e60bc95 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionService.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionService.kt @@ -27,7 +27,11 @@ import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.db.T 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.BluePrintConstants +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException +import org.onap.ccsdk.cds.controllerblueprints.core.asJsonPrimitive +import org.onap.ccsdk.cds.controllerblueprints.core.asJsonType +import org.onap.ccsdk.cds.controllerblueprints.core.checkNotEmpty import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintRuntimeService import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintTemplateService import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils @@ -37,80 +41,109 @@ import org.onap.ccsdk.cds.controllerblueprints.resource.dict.utils.BulkResourceS import org.slf4j.LoggerFactory import org.springframework.context.ApplicationContext import org.springframework.stereotype.Service -import java.util.* +import java.util.UUID interface ResourceResolutionService { fun registeredResourceSources(): List<String> - suspend fun resolveFromDatabase(bluePrintRuntimeService: BluePrintRuntimeService<*>, artifactTemplate: String, - resolutionKey: String): String - - suspend fun resolveResources(bluePrintRuntimeService: BluePrintRuntimeService<*>, nodeTemplateName: String, - artifactNames: List<String>, properties: Map<String, Any>): MutableMap<String, String> - - suspend fun resolveResources(bluePrintRuntimeService: BluePrintRuntimeService<*>, nodeTemplateName: String, - artifactPrefix: String, properties: Map<String, Any>): String + suspend fun resolveFromDatabase( + bluePrintRuntimeService: BluePrintRuntimeService<*>, + artifactTemplate: String, + resolutionKey: String + ): String + + suspend fun resolveResources( + bluePrintRuntimeService: BluePrintRuntimeService<*>, + nodeTemplateName: String, + artifactNames: List<String>, + properties: Map<String, Any> + ): MutableMap<String, String> + + 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>, - artifactPrefix: String, - properties: Map<String, Any>) + 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>, + artifactPrefix: String, + properties: Map<String, Any> + ) } @Service(ResourceResolutionConstants.SERVICE_RESOURCE_RESOLUTION) -open class ResourceResolutionServiceImpl(private var applicationContext: ApplicationContext, - private var templateResolutionDBService: TemplateResolutionService, - private var blueprintTemplateService: BluePrintTemplateService, - private var resourceResolutionDBService: ResourceResolutionDBService) : - ResourceResolutionService { +open class ResourceResolutionServiceImpl( + private var applicationContext: ApplicationContext, + private var templateResolutionDBService: TemplateResolutionService, + private var blueprintTemplateService: BluePrintTemplateService, + private var resourceResolutionDBService: ResourceResolutionDBService +) : + ResourceResolutionService { private val log = LoggerFactory.getLogger(ResourceResolutionService::class.java) override fun registeredResourceSources(): List<String> { return applicationContext.getBeanNamesForType(ResourceAssignmentProcessor::class.java) - .filter { it.startsWith(ResourceResolutionConstants.PREFIX_RESOURCE_RESOLUTION_PROCESSOR) } - .map { it.substringAfter(ResourceResolutionConstants.PREFIX_RESOURCE_RESOLUTION_PROCESSOR) } + .filter { it.startsWith(ResourceResolutionConstants.PREFIX_RESOURCE_RESOLUTION_PROCESSOR) } + .map { it.substringAfter(ResourceResolutionConstants.PREFIX_RESOURCE_RESOLUTION_PROCESSOR) } } - override suspend fun resolveFromDatabase(bluePrintRuntimeService: BluePrintRuntimeService<*>, - artifactTemplate: String, - resolutionKey: String): String { + override suspend fun resolveFromDatabase( + bluePrintRuntimeService: BluePrintRuntimeService<*>, + artifactTemplate: String, + resolutionKey: String + ): String { return templateResolutionDBService.findByResolutionKeyAndBlueprintNameAndBlueprintVersionAndArtifactName( - bluePrintRuntimeService, - artifactTemplate, - resolutionKey) + bluePrintRuntimeService, + artifactTemplate, + resolutionKey + ) } - override suspend fun resolveResources(bluePrintRuntimeService: BluePrintRuntimeService<*>, nodeTemplateName: String, - artifactNames: List<String>, - properties: Map<String, Any>): MutableMap<String, String> { + override suspend fun resolveResources( + bluePrintRuntimeService: BluePrintRuntimeService<*>, + nodeTemplateName: String, + artifactNames: List<String>, + properties: Map<String, Any> + ): MutableMap<String, String> { val resourceAssignmentRuntimeService = - ResourceAssignmentUtils.transformToRARuntimeService(bluePrintRuntimeService, artifactNames.toString()) + ResourceAssignmentUtils.transformToRARuntimeService(bluePrintRuntimeService, artifactNames.toString()) val resolvedParams: MutableMap<String, String> = hashMapOf() artifactNames.forEach { artifactName -> - val resolvedContent = resolveResources(resourceAssignmentRuntimeService, nodeTemplateName, - artifactName, properties) + val resolvedContent = resolveResources( + resourceAssignmentRuntimeService, nodeTemplateName, + artifactName, properties + ) resolvedParams[artifactName] = resolvedContent } return resolvedParams } - - override suspend fun resolveResources(bluePrintRuntimeService: BluePrintRuntimeService<*>, nodeTemplateName: String, - artifactPrefix: String, properties: Map<String, Any>): String { + override suspend fun resolveResources( + bluePrintRuntimeService: BluePrintRuntimeService<*>, + nodeTemplateName: String, + artifactPrefix: String, + properties: Map<String, Any> + ): String { // Velocity Artifact Definition Name val artifactTemplate = "$artifactPrefix-template" @@ -121,39 +154,47 @@ open class ResourceResolutionServiceImpl(private var applicationContext: Applica log.info("Resolving resource for template artifact($artifactTemplate) with resource assignment artifact($artifactMapping)") val resourceAssignmentContent = - bluePrintRuntimeService.resolveNodeTemplateArtifact(nodeTemplateName, artifactMapping) + bluePrintRuntimeService.resolveNodeTemplateArtifact(nodeTemplateName, artifactMapping) val resourceAssignments: MutableList<ResourceAssignment> = - JacksonUtils.getListFromJson(resourceAssignmentContent, ResourceAssignment::class.java) - as? MutableList<ResourceAssignment> - ?: throw BluePrintProcessorException("couldn't get Dictionary Definitions") + JacksonUtils.getListFromJson(resourceAssignmentContent, ResourceAssignment::class.java) + as? MutableList<ResourceAssignment> + ?: throw BluePrintProcessorException("couldn't get Dictionary Definitions") if (isToStore(properties)) { val existingResourceResolution = isNewResolution(bluePrintRuntimeService, properties, artifactPrefix) if (existingResourceResolution.isNotEmpty()) { - updateResourceAssignmentWithExisting(bluePrintRuntimeService as ResourceAssignmentRuntimeService, - existingResourceResolution, resourceAssignments) + updateResourceAssignmentWithExisting( + bluePrintRuntimeService as ResourceAssignmentRuntimeService, + existingResourceResolution, resourceAssignments + ) } } // Get the Resource Dictionary Name val resourceDefinitions: MutableMap<String, ResourceDefinition> = ResourceAssignmentUtils - .resourceDefinitions(bluePrintRuntimeService.bluePrintContext().rootPath) + .resourceDefinitions(bluePrintRuntimeService.bluePrintContext().rootPath) // Resolve resources - resolveResourceAssignments(bluePrintRuntimeService, - resourceDefinitions, - resourceAssignments, - artifactPrefix, - properties) + resolveResourceAssignments( + bluePrintRuntimeService, + resourceDefinitions, + resourceAssignments, + artifactPrefix, + properties + ) val resolvedParamJsonContent = - ResourceAssignmentUtils.generateResourceDataForAssignments(resourceAssignments.toList()) + ResourceAssignmentUtils.generateResourceDataForAssignments(resourceAssignments.toList()) - resolvedContent = blueprintTemplateService.generateContent(bluePrintRuntimeService, nodeTemplateName, - artifactTemplate, resolvedParamJsonContent, false, - mutableMapOf(ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_OCCURRENCE to - properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_OCCURRENCE].asJsonPrimitive())) + resolvedContent = blueprintTemplateService.generateContent( + bluePrintRuntimeService, nodeTemplateName, + artifactTemplate, resolvedParamJsonContent, false, + mutableMapOf( + ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_OCCURRENCE to + properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_OCCURRENCE].asJsonPrimitive() + ) + ) if (isToStore(properties)) { templateResolutionDBService.write(properties, resolvedContent, bluePrintRuntimeService, artifactPrefix) @@ -163,16 +204,21 @@ open class ResourceResolutionServiceImpl(private var applicationContext: Applica return resolvedContent } - override suspend fun resolveResourceDefinition(blueprintRuntimeService: BluePrintRuntimeService<*>, - resourceDefinitions: MutableMap<String, ResourceDefinition>, - resolveDefinition: String, sources: List<String>) - : MutableMap<String, JsonNode> { + 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()) + resolveResourceAssignments( + blueprintRuntimeService, resourceDefinitions, resourceAssignments, + UUID.randomUUID().toString(), hashMapOf() + ) // Get the data from Resource Assignments return ResourceAssignmentUtils.generateResourceForAssignments(resourceAssignments) @@ -183,11 +229,13 @@ open class ResourceResolutionServiceImpl(private var applicationContext: Applica * name, then get the type of the Resource Definition, Get the instance for the Resource Type and process the * request. */ - override suspend fun resolveResourceAssignments(blueprintRuntimeService: BluePrintRuntimeService<*>, - resourceDefinitions: MutableMap<String, ResourceDefinition>, - resourceAssignments: MutableList<ResourceAssignment>, - artifactPrefix: String, - properties: Map<String, Any>) { + override suspend fun resolveResourceAssignments( + blueprintRuntimeService: BluePrintRuntimeService<*>, + resourceDefinitions: MutableMap<String, ResourceDefinition>, + resourceAssignments: MutableList<ResourceAssignment>, + artifactPrefix: String, + properties: Map<String, Any> + ) { val bulkSequenced = BulkResourceSequencingUtils.process(resourceAssignments) @@ -204,56 +252,62 @@ open class ResourceResolutionServiceImpl(private var applicationContext: Applica bulkSequenced.forEach { batchResourceAssignments -> // Execute Non Dependent Assignments in parallel ( ie asynchronously ) val deferred = batchResourceAssignments - .filter { it.name != "*" && it.name != "start" } - .filter { it.status != BluePrintConstants.STATUS_SUCCESS } - .map { resourceAssignment -> - async { - val dictionaryName = resourceAssignment.dictionaryName - val dictionarySource = resourceAssignment.dictionarySource - - val processorName = processorName(dictionaryName!!, dictionarySource!!, resourceDefinitions) - - val resourceAssignmentProcessor = - applicationContext.getBean(processorName) as? ResourceAssignmentProcessor - ?: throw BluePrintProcessorException("failed to get resource processor ($processorName) " + - "for resource assignment(${resourceAssignment.name})") - try { - // Set BluePrint Runtime Service - resourceAssignmentProcessor.raRuntimeService = resourceAssignmentRuntimeService - // Set Resource Dictionaries - resourceAssignmentProcessor.resourceDictionaries = resourceDefinitions - // Invoke Apply Method - resourceAssignmentProcessor.applyNB(resourceAssignment) - - if (isToStore(properties)) { - resourceResolutionDBService.write(properties, - blueprintRuntimeService, - artifactPrefix, - resourceAssignment) - log.info("Resource resolution saved into database successfully : (${resourceAssignment.name})") - } - - // Set errors from RA - blueprintRuntimeService.setBluePrintError(resourceAssignmentRuntimeService.getBluePrintError()) - } catch (e: RuntimeException) { - log.error("Fail in processing ${resourceAssignment.name}", e) - throw BluePrintProcessorException(e) + .filter { it.name != "*" && it.name != "start" } + .filter { it.status != BluePrintConstants.STATUS_SUCCESS } + .map { resourceAssignment -> + async { + val dictionaryName = resourceAssignment.dictionaryName + val dictionarySource = resourceAssignment.dictionarySource + + val processorName = processorName(dictionaryName!!, dictionarySource!!, resourceDefinitions) + + val resourceAssignmentProcessor = + applicationContext.getBean(processorName) as? ResourceAssignmentProcessor + ?: throw BluePrintProcessorException( + "failed to get resource processor ($processorName) " + + "for resource assignment(${resourceAssignment.name})" + ) + try { + // Set BluePrint Runtime Service + resourceAssignmentProcessor.raRuntimeService = resourceAssignmentRuntimeService + // Set Resource Dictionaries + resourceAssignmentProcessor.resourceDictionaries = resourceDefinitions + // Invoke Apply Method + resourceAssignmentProcessor.applyNB(resourceAssignment) + + if (isToStore(properties)) { + resourceResolutionDBService.write( + properties, + blueprintRuntimeService, + artifactPrefix, + resourceAssignment + ) + log.info("Resource resolution saved into database successfully : (${resourceAssignment.name})") } + + // Set errors from RA + blueprintRuntimeService.setBluePrintError(resourceAssignmentRuntimeService.getBluePrintError()) + } catch (e: RuntimeException) { + log.error("Fail in processing ${resourceAssignment.name}", e) + throw BluePrintProcessorException(e) } } + } log.debug("Resolving (${deferred.size})resources parallel.") deferred.awaitAll() } } - } /** * If the Source instance is "input", then it is not mandatory to have source Resource Definition, So it can * derive the default input processor. */ - private fun processorName(dictionaryName: String, dictionarySource: String, - resourceDefinitions: MutableMap<String, ResourceDefinition>): String { + private fun processorName( + dictionaryName: String, + dictionarySource: String, + resourceDefinitions: MutableMap<String, ResourceDefinition> + ): String { val processorName: String = when (dictionarySource) { "input" -> { "${ResourceResolutionConstants.PREFIX_RESOURCE_RESOLUTION_PROCESSOR}source-input" @@ -263,10 +317,10 @@ open class ResourceResolutionServiceImpl(private var applicationContext: Applica } else -> { val resourceDefinition = resourceDefinitions[dictionaryName] - ?: throw BluePrintProcessorException("couldn't get resource dictionary definition for $dictionaryName") + ?: throw BluePrintProcessorException("couldn't get resource dictionary definition for $dictionaryName") val resourceSource = resourceDefinition.sources[dictionarySource] - ?: throw BluePrintProcessorException("couldn't get resource definition $dictionaryName source($dictionarySource)") + ?: throw BluePrintProcessorException("couldn't get resource definition $dictionaryName source($dictionarySource)") ResourceResolutionConstants.PREFIX_RESOURCE_RESOLUTION_PROCESSOR.plus(resourceSource.type) } @@ -276,19 +330,20 @@ open class ResourceResolutionServiceImpl(private var applicationContext: Applica } return processorName - } // Check whether to store or not the resolution of resource and template private fun isToStore(properties: Map<String, Any>): Boolean { - return properties.containsKey(ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_STORE_RESULT) - && properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_STORE_RESULT] as Boolean + return properties.containsKey(ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_STORE_RESULT) && + properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_STORE_RESULT] as Boolean } // Check whether resolution already exist in the database for the specified resolution-key or resourceId/resourceType - private suspend fun isNewResolution(bluePrintRuntimeService: BluePrintRuntimeService<*>, - properties: Map<String, Any>, - artifactPrefix: String): List<ResourceResolution> { + private suspend fun isNewResolution( + bluePrintRuntimeService: BluePrintRuntimeService<*>, + properties: Map<String, Any>, + artifactPrefix: String + ): List<ResourceResolution> { val occurrence = properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_OCCURRENCE] as Int val resolutionKey = properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOLUTION_KEY] as String val resourceId = properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOURCE_ID] as String @@ -296,28 +351,34 @@ open class ResourceResolutionServiceImpl(private var applicationContext: Applica if (resolutionKey.isNotEmpty()) { val existingResourceAssignments = - resourceResolutionDBService.findByBlueprintNameAndBlueprintVersionAndArtifactNameAndResolutionKeyAndOccurrence( - bluePrintRuntimeService, - resolutionKey, - occurrence, - artifactPrefix) + resourceResolutionDBService.findByBlueprintNameAndBlueprintVersionAndArtifactNameAndResolutionKeyAndOccurrence( + bluePrintRuntimeService, + resolutionKey, + occurrence, + artifactPrefix + ) if (existingResourceAssignments.isNotEmpty()) { - log.info("Resolution with resolutionKey=($resolutionKey) already exist - will resolve all resources not already resolved.", - resolutionKey) + log.info( + "Resolution with resolutionKey=($resolutionKey) already exist - will resolve all resources not already resolved.", + resolutionKey + ) } return existingResourceAssignments } else if (resourceId.isNotEmpty() && resourceType.isNotEmpty()) { val existingResourceAssignments = - resourceResolutionDBService.findByBlueprintNameAndBlueprintVersionAndArtifactNameAndResourceIdAndResourceTypeAndOccurrence( - bluePrintRuntimeService, - resourceId, - resourceType, - - occurrence, - artifactPrefix) + resourceResolutionDBService.findByBlueprintNameAndBlueprintVersionAndArtifactNameAndResourceIdAndResourceTypeAndOccurrence( + bluePrintRuntimeService, + resourceId, + resourceType, + + occurrence, + artifactPrefix + ) if (existingResourceAssignments.isNotEmpty()) { - log.info("Resolution with resourceId=($resourceId) and resourceType=($resourceType) already exist - will resolve " + - "all resources not already resolved.") + log.info( + "Resolution with resourceId=($resourceId) and resourceType=($resourceType) already exist - will resolve " + + "all resources not already resolved." + ) } return existingResourceAssignments } @@ -325,9 +386,11 @@ open class ResourceResolutionServiceImpl(private var applicationContext: Applica } // Update the resource assignment list with the status of the resource that have already been resolved - private fun updateResourceAssignmentWithExisting(raRuntimeService : ResourceAssignmentRuntimeService, - resourceResolutionList: List<ResourceResolution>, - resourceAssignmentList: MutableList<ResourceAssignment>) { + private fun updateResourceAssignmentWithExisting( + raRuntimeService: ResourceAssignmentRuntimeService, + resourceResolutionList: List<ResourceResolution>, + resourceAssignmentList: MutableList<ResourceAssignment> + ) { resourceResolutionList.forEach { resourceResolution -> if (resourceResolution.status == BluePrintConstants.STATUS_SUCCESS) { resourceAssignmentList.forEach { @@ -347,15 +410,19 @@ open class ResourceResolutionServiceImpl(private var applicationContext: Applica // Comparision between what we have in the database vs what we have to assign. private fun compareOne(resourceResolution: ResourceResolution, resourceAssignment: ResourceAssignment): Boolean { - return (resourceResolution.name == resourceAssignment.name - && resourceResolution.dictionaryName == resourceAssignment.dictionaryName - && resourceResolution.dictionarySource == resourceAssignment.dictionarySource - && resourceResolution.dictionaryVersion == resourceAssignment.version) + return (resourceResolution.name == resourceAssignment.name && + resourceResolution.dictionaryName == resourceAssignment.dictionaryName && + resourceResolution.dictionarySource == resourceAssignment.dictionarySource && + resourceResolution.dictionaryVersion == resourceAssignment.version) } - private fun exposeOccurrencePropertyInResourceAssignments(raRuntimeService: ResourceAssignmentRuntimeService, - properties: Map<String, Any>) { - raRuntimeService.putResolutionStore(ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_OCCURRENCE, - properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_OCCURRENCE].asJsonPrimitive()) + private fun exposeOccurrencePropertyInResourceAssignments( + raRuntimeService: ResourceAssignmentRuntimeService, + properties: Map<String, Any> + ) { + raRuntimeService.putResolutionStore( + ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_OCCURRENCE, + properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_OCCURRENCE].asJsonPrimitive() + ) } } diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceSourceDSL.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceSourceDSL.kt index 182f3a178..d541fe60c 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceSourceDSL.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceSourceDSL.kt @@ -18,7 +18,11 @@ package org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution import com.fasterxml.jackson.databind.JsonNode import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.ComponentScriptExecutor -import org.onap.ccsdk.cds.controllerblueprints.core.* +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintTypes +import org.onap.ccsdk.cds.controllerblueprints.core.asJsonPrimitive +import org.onap.ccsdk.cds.controllerblueprints.core.asJsonString +import org.onap.ccsdk.cds.controllerblueprints.core.asJsonType import org.onap.ccsdk.cds.controllerblueprints.core.data.NodeTemplate import org.onap.ccsdk.cds.controllerblueprints.core.data.NodeType import org.onap.ccsdk.cds.controllerblueprints.core.dsl.AbstractNodeTemplatePropertyImplBuilder @@ -27,149 +31,220 @@ import org.onap.ccsdk.cds.controllerblueprints.core.dsl.nodeType import kotlin.reflect.KClass fun BluePrintTypes.nodeTypeSourceInput(): NodeType { - return nodeType(id = "source-input", version = BluePrintConstants.DEFAULT_VERSION_NUMBER, - derivedFrom = BluePrintConstants.MODEL_TYPE_NODE_RESOURCE_SOURCE, - description = "This is Input Resource Source Node Type") {} + return nodeType( + id = "source-input", version = BluePrintConstants.DEFAULT_VERSION_NUMBER, + derivedFrom = BluePrintConstants.MODEL_TYPE_NODE_RESOURCE_SOURCE, + description = "This is Input Resource Source Node Type" + ) {} } fun BluePrintTypes.nodeTypeSourceDefault(): NodeType { - return nodeType(id = "source-default", version = BluePrintConstants.DEFAULT_VERSION_NUMBER, - derivedFrom = BluePrintConstants.MODEL_TYPE_NODE_RESOURCE_SOURCE, - description = "This is Default Resource Source Node Type") {} + return nodeType( + id = "source-default", version = BluePrintConstants.DEFAULT_VERSION_NUMBER, + derivedFrom = BluePrintConstants.MODEL_TYPE_NODE_RESOURCE_SOURCE, + description = "This is Default Resource Source Node Type" + ) {} } fun BluePrintTypes.nodeTypeSourceDb(): NodeType { - return nodeType(id = "source-db", version = BluePrintConstants.DEFAULT_VERSION_NUMBER, - derivedFrom = BluePrintConstants.MODEL_TYPE_NODE_RESOURCE_SOURCE, - description = "This is Database Resource Source Node Type") { - property("type", BluePrintConstants.DATA_TYPE_STRING, - true, "") { + return nodeType( + id = "source-db", version = BluePrintConstants.DEFAULT_VERSION_NUMBER, + derivedFrom = BluePrintConstants.MODEL_TYPE_NODE_RESOURCE_SOURCE, + description = "This is Database Resource Source Node Type" + ) { + property( + "type", BluePrintConstants.DATA_TYPE_STRING, + true, "" + ) { defaultValue("SQL".asJsonPrimitive()) constrain { validValues(arrayListOf("SQL".asJsonPrimitive(), "PLSQL".asJsonPrimitive())) } } - property("endpoint-selector", BluePrintConstants.DATA_TYPE_STRING, - false, "") - property("query", BluePrintConstants.DATA_TYPE_STRING, - true, "") - property("input-key-mapping", BluePrintConstants.DATA_TYPE_MAP, - true, "") { + property( + "endpoint-selector", BluePrintConstants.DATA_TYPE_STRING, + false, "" + ) + property( + "query", BluePrintConstants.DATA_TYPE_STRING, + true, "" + ) + property( + "input-key-mapping", BluePrintConstants.DATA_TYPE_MAP, + true, "" + ) { entrySchema(BluePrintConstants.DATA_TYPE_STRING) } - property("output-key-mapping", BluePrintConstants.DATA_TYPE_MAP, - false, "") { + property( + "output-key-mapping", BluePrintConstants.DATA_TYPE_MAP, + false, "" + ) { entrySchema(BluePrintConstants.DATA_TYPE_STRING) } - property("key-dependencies", BluePrintConstants.DATA_TYPE_LIST, - true, "Resource Resolution dependency dictionary names.") { + property( + "key-dependencies", BluePrintConstants.DATA_TYPE_LIST, + true, "Resource Resolution dependency dictionary names." + ) { entrySchema(BluePrintConstants.DATA_TYPE_STRING) } } } fun BluePrintTypes.nodeTypeSourceRest(): NodeType { - return nodeType(id = "source-rest", version = BluePrintConstants.DEFAULT_VERSION_NUMBER, - derivedFrom = BluePrintConstants.MODEL_TYPE_NODE_RESOURCE_SOURCE, - description = "This is Rest Resource Source Node Type") { - property("type", BluePrintConstants.DATA_TYPE_STRING, - true, "") { + return nodeType( + id = "source-rest", version = BluePrintConstants.DEFAULT_VERSION_NUMBER, + derivedFrom = BluePrintConstants.MODEL_TYPE_NODE_RESOURCE_SOURCE, + description = "This is Rest Resource Source Node Type" + ) { + property( + "type", BluePrintConstants.DATA_TYPE_STRING, + true, "" + ) { defaultValue("JSON".asJsonPrimitive()) constrain { validValues(arrayListOf("JSON".asJsonPrimitive(), "XML".asJsonPrimitive())) } } - property("verb", BluePrintConstants.DATA_TYPE_STRING, - true, "") { + property( + "verb", BluePrintConstants.DATA_TYPE_STRING, + true, "" + ) { defaultValue("GET".asJsonPrimitive()) constrain { - validValues(arrayListOf("GET".asJsonPrimitive(), "POST".asJsonPrimitive(), - "DELETE".asJsonPrimitive(), "PUT".asJsonPrimitive())) + validValues( + arrayListOf( + "GET".asJsonPrimitive(), "POST".asJsonPrimitive(), + "DELETE".asJsonPrimitive(), "PUT".asJsonPrimitive() + ) + ) } } - property("payload", BluePrintConstants.DATA_TYPE_STRING, - false, "") { + property( + "payload", BluePrintConstants.DATA_TYPE_STRING, + false, "" + ) { defaultValue("".asJsonPrimitive()) } - property("endpoint-selector", BluePrintConstants.DATA_TYPE_STRING, - false, "") - property("url-path", BluePrintConstants.DATA_TYPE_STRING, - true, "") - property("path", BluePrintConstants.DATA_TYPE_STRING, - true, "") - property("expression-type", BluePrintConstants.DATA_TYPE_STRING, - false, "") { + property( + "endpoint-selector", BluePrintConstants.DATA_TYPE_STRING, + false, "" + ) + property( + "url-path", BluePrintConstants.DATA_TYPE_STRING, + true, "" + ) + property( + "path", BluePrintConstants.DATA_TYPE_STRING, + true, "" + ) + property( + "expression-type", BluePrintConstants.DATA_TYPE_STRING, + false, "" + ) { defaultValue("JSON_PATH".asJsonPrimitive()) constrain { validValues(arrayListOf("JSON_PATH".asJsonPrimitive(), "JSON_POINTER".asJsonPrimitive())) } } - property("input-key-mapping", BluePrintConstants.DATA_TYPE_MAP, - true, "") { + property( + "input-key-mapping", BluePrintConstants.DATA_TYPE_MAP, + true, "" + ) { entrySchema(BluePrintConstants.DATA_TYPE_STRING) } - property("output-key-mapping", BluePrintConstants.DATA_TYPE_MAP, - false, "") { + property( + "output-key-mapping", BluePrintConstants.DATA_TYPE_MAP, + false, "" + ) { entrySchema(BluePrintConstants.DATA_TYPE_STRING) } - property("key-dependencies", BluePrintConstants.DATA_TYPE_LIST, - true, "Resource Resolution dependency dictionary names.") { + property( + "key-dependencies", BluePrintConstants.DATA_TYPE_LIST, + true, "Resource Resolution dependency dictionary names." + ) { entrySchema(BluePrintConstants.DATA_TYPE_STRING) } } } fun BluePrintTypes.nodeTypeSourceCapability(): NodeType { - return nodeType(id = "source-capability", version = BluePrintConstants.DEFAULT_VERSION_NUMBER, - derivedFrom = BluePrintConstants.MODEL_TYPE_NODE_RESOURCE_SOURCE, - description = "This is Component Resource Source Node Type") { - property(ComponentScriptExecutor.INPUT_SCRIPT_TYPE, BluePrintConstants.DATA_TYPE_STRING, - true, "Request Id, Unique Id for the request.") { + return nodeType( + id = "source-capability", version = BluePrintConstants.DEFAULT_VERSION_NUMBER, + derivedFrom = BluePrintConstants.MODEL_TYPE_NODE_RESOURCE_SOURCE, + description = "This is Component Resource Source Node Type" + ) { + property( + ComponentScriptExecutor.INPUT_SCRIPT_TYPE, BluePrintConstants.DATA_TYPE_STRING, + true, "Request Id, Unique Id for the request." + ) { defaultValue(BluePrintConstants.SCRIPT_KOTLIN) constrain { - validValues(arrayListOf(BluePrintConstants.SCRIPT_KOTLIN.asJsonPrimitive(), + validValues( + arrayListOf( + BluePrintConstants.SCRIPT_KOTLIN.asJsonPrimitive(), BluePrintConstants.SCRIPT_INTERNAL.asJsonPrimitive(), - BluePrintConstants.SCRIPT_JYTHON.asJsonPrimitive())) + BluePrintConstants.SCRIPT_JYTHON.asJsonPrimitive() + ) + ) } } - property(ComponentScriptExecutor.INPUT_SCRIPT_CLASS_REFERENCE, BluePrintConstants.DATA_TYPE_STRING, - true, "Kotlin Script class name or jython script name.") - property("key-dependencies", BluePrintConstants.DATA_TYPE_LIST, - true, "Resource Resolution dependency dictionary names.") { + property( + ComponentScriptExecutor.INPUT_SCRIPT_CLASS_REFERENCE, BluePrintConstants.DATA_TYPE_STRING, + true, "Kotlin Script class name or jython script name." + ) + property( + "key-dependencies", BluePrintConstants.DATA_TYPE_LIST, + true, "Resource Resolution dependency dictionary names." + ) { entrySchema(BluePrintConstants.DATA_TYPE_STRING) } } } /** Node Template Source Input **/ -fun BluePrintTypes.nodeTemplateSourceInput(id: String, description: String, - block: SourceInputNodeTemplateBuilder.() -> Unit): NodeTemplate { +fun BluePrintTypes.nodeTemplateSourceInput( + id: String, + description: String, + block: SourceInputNodeTemplateBuilder.() -> Unit +): NodeTemplate { return SourceInputNodeTemplateBuilder(id, description).apply(block).build() } class SourceInputNodeTemplateBuilder(id: String, description: String) : - AbstractNodeTemplatePropertyImplBuilder<PropertiesAssignmentBuilder>(id, - "source-input", description) + AbstractNodeTemplatePropertyImplBuilder<PropertiesAssignmentBuilder>( + id, + "source-input", description + ) /** Node Template Source Default **/ -fun BluePrintTypes.nodeTemplateSourceDefault(id: String, description: String, - block: SourceDefaultNodeTemplateBuilder.() -> Unit): NodeTemplate { +fun BluePrintTypes.nodeTemplateSourceDefault( + id: String, + description: String, + block: SourceDefaultNodeTemplateBuilder.() -> Unit +): NodeTemplate { return SourceDefaultNodeTemplateBuilder(id, description).apply(block).build() } class SourceDefaultNodeTemplateBuilder(id: String, description: String) : - AbstractNodeTemplatePropertyImplBuilder<PropertiesAssignmentBuilder>(id, - "source-default", description) + AbstractNodeTemplatePropertyImplBuilder<PropertiesAssignmentBuilder>( + id, + "source-default", description + ) /** Node Template Source DB **/ -fun BluePrintTypes.nodeTemplateSourceDb(id: String, description: String, - block: SourceDbNodeTemplateBuilder.() -> Unit): NodeTemplate { +fun BluePrintTypes.nodeTemplateSourceDb( + id: String, + description: String, + block: SourceDbNodeTemplateBuilder.() -> Unit +): NodeTemplate { return SourceDbNodeTemplateBuilder(id, description).apply(block).build() } class SourceDbNodeTemplateBuilder(id: String, description: String) : - AbstractNodeTemplatePropertyImplBuilder<SourceDbNodeTemplateBuilder.PropertiesBuilder>(id, - "source-db", description) { + AbstractNodeTemplatePropertyImplBuilder<SourceDbNodeTemplateBuilder.PropertiesBuilder>( + id, + "source-db", description + ) { class PropertiesBuilder : PropertiesAssignmentBuilder() { fun type(type: String) = type(type.asJsonPrimitive()) @@ -221,16 +296,20 @@ class KeyMappingBuilder() { } } - /** Node Template Source Rest **/ -fun BluePrintTypes.nodeTemplateSourceRest(id: String, description: String, - block: SourceRestNodeTemplateBuilder.() -> Unit): NodeTemplate { +fun BluePrintTypes.nodeTemplateSourceRest( + id: String, + description: String, + block: SourceRestNodeTemplateBuilder.() -> Unit +): NodeTemplate { return SourceRestNodeTemplateBuilder(id, description).apply(block).build() } class SourceRestNodeTemplateBuilder(id: String, description: String) : - AbstractNodeTemplatePropertyImplBuilder<SourceRestNodeTemplateBuilder.PropertiesBuilder>(id, - "source-rest", description) { + AbstractNodeTemplatePropertyImplBuilder<SourceRestNodeTemplateBuilder.PropertiesBuilder>( + id, + "source-rest", description + ) { class PropertiesBuilder : PropertiesAssignmentBuilder() { fun type(type: String) = type(type.asJsonPrimitive()) @@ -296,14 +375,19 @@ class SourceRestNodeTemplateBuilder(id: String, description: String) : } /** Node Template Source Rest **/ -fun BluePrintTypes.nodeTemplateSourceCapability(id: String, description: String, - block: SourceCapabilityNodeTemplateBuilder.() -> Unit): NodeTemplate { +fun BluePrintTypes.nodeTemplateSourceCapability( + id: String, + description: String, + block: SourceCapabilityNodeTemplateBuilder.() -> Unit +): NodeTemplate { return SourceCapabilityNodeTemplateBuilder(id, description).apply(block).build() } class SourceCapabilityNodeTemplateBuilder(id: String, description: String) : - AbstractNodeTemplatePropertyImplBuilder<SourceCapabilityNodeTemplateBuilder.PropertiesBuilder>(id, - "source-capability", description) { + AbstractNodeTemplatePropertyImplBuilder<SourceCapabilityNodeTemplateBuilder.PropertiesBuilder>( + id, + "source-capability", description + ) { class PropertiesBuilder : PropertiesAssignmentBuilder() { fun type(type: String) = type(type.asJsonPrimitive()) @@ -330,4 +414,4 @@ class SourceCapabilityNodeTemplateBuilder(id: String, description: String) : property("key-dependencies", keyDependencies) } } -}
\ No newline at end of file +} diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceSourceProperties.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceSourceProperties.kt index 2a0e7a443..636e81dda 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceSourceProperties.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceSourceProperties.kt @@ -78,4 +78,4 @@ open class CapabilityResourceSource : ResourceSourceProperties() { var instanceDependencies: List<String>? = null @get:JsonProperty("key-dependencies") lateinit var keyDependencies: MutableList<String> -}
\ No newline at end of file +} diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/ResourceResolution.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/ResourceResolution.kt index 781cafd97..db023acfb 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/ResourceResolution.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/ResourceResolution.kt @@ -22,8 +22,15 @@ import org.hibernate.annotations.Proxy import org.springframework.data.annotation.LastModifiedDate import org.springframework.data.jpa.domain.support.AuditingEntityListener import java.io.Serializable -import java.util.* -import javax.persistence.* +import java.util.Date +import javax.persistence.Column +import javax.persistence.Entity +import javax.persistence.EntityListeners +import javax.persistence.Id +import javax.persistence.Lob +import javax.persistence.Table +import javax.persistence.Temporal +import javax.persistence.TemporalType @EntityListeners(AuditingEntityListener::class) @Entity @@ -56,8 +63,10 @@ class ResourceResolution : Serializable { @Column(name = "status", nullable = false) var status: String? = null - @get:ApiModelProperty(value = "Resolution Key uniquely identifying the resolution of a given artifact within a CBA.", - required = true) + @get:ApiModelProperty( + value = "Resolution Key uniquely identifying the resolution of a given artifact within a CBA.", + required = true + ) @Column(name = "resolution_key", nullable = false) var resolutionKey: String? = null @@ -69,8 +78,10 @@ class ResourceResolution : Serializable { @Column(name = "resource_id", nullable = false) var resourceId: String? = null - @get:ApiModelProperty(value = "If resolution occurred multiple time, this field provides the index.", - required = true) + @get:ApiModelProperty( + value = "If resolution occurred multiple time, this field provides the index.", + required = true + ) @Column(name = "occurrence", nullable = false) var occurrence: Int = 0 @@ -78,8 +89,10 @@ class ResourceResolution : Serializable { @Column(name = "dictionary_name", nullable = false) var dictionaryName: String? = null - @get:ApiModelProperty(value = "Source associated with the data dictionary used for the resolution.", - required = true) + @get:ApiModelProperty( + value = "Source associated with the data dictionary used for the resolution.", + required = true + ) @Column(name = "dictionary_status", nullable = false) var dictionarySource: String? = null diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/ResourceResolutionDBService.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/ResourceResolutionDBService.kt index e5a13a630..f8bf7bd09 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/ResourceResolutionDBService.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/ResourceResolutionDBService.kt @@ -26,7 +26,7 @@ import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceAssignment import org.slf4j.LoggerFactory import org.springframework.dao.EmptyResultDataAccessException import org.springframework.stereotype.Service -import java.util.* +import java.util.UUID @Service class ResourceResolutionDBService(private val resourceResolutionRepository: ResourceResolutionRepository) { @@ -34,8 +34,11 @@ class ResourceResolutionDBService(private val resourceResolutionRepository: Reso private val log = LoggerFactory.getLogger(ResourceResolutionDBService::class.toString()) suspend fun findByBlueprintNameAndBlueprintVersionAndArtifactNameAndResolutionKeyAndOccurrence( - bluePrintRuntimeService: BluePrintRuntimeService<*>, key: String, - occurrence: Int, artifactPrefix: String): List<ResourceResolution> { + bluePrintRuntimeService: BluePrintRuntimeService<*>, + key: String, + occurrence: Int, + artifactPrefix: String + ): List<ResourceResolution> { return try { val metadata = bluePrintRuntimeService.bluePrintContext().metadata!! @@ -47,16 +50,20 @@ class ResourceResolutionDBService(private val resourceResolutionRepository: Reso blueprintVersion, artifactPrefix, key, - occurrence) + occurrence + ) } catch (e: EmptyResultDataAccessException) { emptyList() } } suspend fun findByBlueprintNameAndBlueprintVersionAndArtifactNameAndResourceIdAndResourceTypeAndOccurrence( - bluePrintRuntimeService: BluePrintRuntimeService<*>, resourceId: String, - resourceType: String, occurrence: Int, - artifactPrefix: String): List<ResourceResolution> { + bluePrintRuntimeService: BluePrintRuntimeService<*>, + resourceId: String, + resourceType: String, + occurrence: Int, + artifactPrefix: String + ): List<ResourceResolution> { return try { val metadata = bluePrintRuntimeService.bluePrintContext().metadata!! @@ -70,55 +77,67 @@ class ResourceResolutionDBService(private val resourceResolutionRepository: Reso artifactPrefix, resourceId, resourceType, - occurrence) + occurrence + ) } catch (e: EmptyResultDataAccessException) { emptyList() } } - suspend fun readValue(blueprintName: String, - blueprintVersion: String, - artifactPrefix: String, - resolutionKey: String, - name: String): ResourceResolution = withContext(Dispatchers.IO) { + suspend fun readValue( + blueprintName: String, + blueprintVersion: String, + artifactPrefix: String, + resolutionKey: String, + name: String + ): ResourceResolution = withContext(Dispatchers.IO) { resourceResolutionRepository.findByResolutionKeyAndBlueprintNameAndBlueprintVersionAndArtifactNameAndName( resolutionKey, blueprintName, blueprintVersion, artifactPrefix, - name) + name + ) } - suspend fun readWithResolutionKey(blueprintName: String, - blueprintVersion: String, - artifactPrefix: String, - resolutionKey: String): List<ResourceResolution> = withContext(Dispatchers.IO) { + suspend fun readWithResolutionKey( + blueprintName: String, + blueprintVersion: String, + artifactPrefix: String, + resolutionKey: String + ): List<ResourceResolution> = withContext(Dispatchers.IO) { resourceResolutionRepository.findByResolutionKeyAndBlueprintNameAndBlueprintVersionAndArtifactName( resolutionKey, blueprintName, blueprintVersion, - artifactPrefix) + artifactPrefix + ) } - suspend fun readWithResourceIdAndResourceType(blueprintName: String, - blueprintVersion: String, - resourceId: String, - resourceType: String): List<ResourceResolution> = + suspend fun readWithResourceIdAndResourceType( + blueprintName: String, + blueprintVersion: String, + resourceId: String, + resourceType: String + ): List<ResourceResolution> = withContext(Dispatchers.IO) { resourceResolutionRepository.findByBlueprintNameAndBlueprintVersionAndResourceIdAndResourceType( blueprintName, blueprintVersion, resourceId, - resourceType) + resourceType + ) } - suspend fun write(properties: Map<String, Any>, - bluePrintRuntimeService: BluePrintRuntimeService<*>, - artifactPrefix: String, - resourceAssignment: ResourceAssignment): ResourceResolution = withContext(Dispatchers.IO) { + suspend fun write( + properties: Map<String, Any>, + bluePrintRuntimeService: BluePrintRuntimeService<*>, + artifactPrefix: String, + resourceAssignment: ResourceAssignment + ): ResourceResolution = withContext(Dispatchers.IO) { val metadata = bluePrintRuntimeService.bluePrintContext().metadata!! @@ -130,24 +149,28 @@ class ResourceResolutionDBService(private val resourceResolutionRepository: Reso val resourceType = properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOURCE_TYPE] as String val occurrence = properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_OCCURRENCE] as Int - write(blueprintName, + write( + blueprintName, blueprintVersion, resolutionKey, resourceId, resourceType, artifactPrefix, resourceAssignment, - occurrence) + occurrence + ) } - suspend fun write(blueprintName: String, - blueprintVersion: String, - resolutionKey: String, - resourceId: String, - resourceType: String, - artifactPrefix: String, - resourceAssignment: ResourceAssignment, - occurrence: Int = 0): ResourceResolution = withContext(Dispatchers.IO) { + suspend fun write( + blueprintName: String, + blueprintVersion: String, + resolutionKey: String, + resourceId: String, + resourceType: String, + artifactPrefix: String, + resourceAssignment: ResourceAssignment, + occurrence: Int = 0 + ): ResourceResolution = withContext(Dispatchers.IO) { val resourceResolution = ResourceResolution() resourceResolution.id = UUID.randomUUID().toString() @@ -175,4 +198,4 @@ class ResourceResolutionDBService(private val resourceResolutionRepository: Reso throw BluePrintException("Failed to store resource resolution result.", ex) } } -}
\ No newline at end of file +} diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/ResourceResolutionRepository.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/ResourceResolutionRepository.kt index 429041e14..155270cd9 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/ResourceResolutionRepository.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/ResourceResolutionRepository.kt @@ -19,28 +19,35 @@ import org.springframework.data.jpa.repository.JpaRepository interface ResourceResolutionRepository : JpaRepository<ResourceResolution, String> { - fun findByResolutionKeyAndBlueprintNameAndBlueprintVersionAndArtifactNameAndName(key: String, - blueprintName: String?, - blueprintVersion: String?, - artifactName: String, - name: String): ResourceResolution + fun findByResolutionKeyAndBlueprintNameAndBlueprintVersionAndArtifactNameAndName( + key: String, + blueprintName: String?, + blueprintVersion: String?, + artifactName: String, + name: String + ): ResourceResolution - fun findByResolutionKeyAndBlueprintNameAndBlueprintVersionAndArtifactName(resolutionKey: String, - blueprintName: String, - blueprintVersion: String, - artifactPrefix: String): List<ResourceResolution> + fun findByResolutionKeyAndBlueprintNameAndBlueprintVersionAndArtifactName( + resolutionKey: String, + blueprintName: String, + blueprintVersion: String, + artifactPrefix: String + ): List<ResourceResolution> - fun findByBlueprintNameAndBlueprintVersionAndResourceIdAndResourceType(blueprintName: String, - blueprintVersion: String, - resourceId: String, - resourceType: String): List<ResourceResolution> + fun findByBlueprintNameAndBlueprintVersionAndResourceIdAndResourceType( + blueprintName: String, + blueprintVersion: String, + resourceId: String, + resourceType: String + ): List<ResourceResolution> fun findByBlueprintNameAndBlueprintVersionAndArtifactNameAndResolutionKeyAndOccurrence( blueprintName: String?, blueprintVersion: String?, artifactName: String, resolutionKey: String, - occurrence: Int): List<ResourceResolution> + occurrence: Int + ): List<ResourceResolution> fun findByBlueprintNameAndBlueprintVersionAndArtifactNameAndResourceIdAndResourceTypeAndOccurrence( blueprintName: String?, @@ -48,5 +55,6 @@ interface ResourceResolutionRepository : JpaRepository<ResourceResolution, Strin artifactName: String, resourceId: String, resourceType: String, - occurrence: Int): List<ResourceResolution> -}
\ No newline at end of file + occurrence: Int + ): List<ResourceResolution> +} diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/TemplateResolution.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/TemplateResolution.kt index 9d5a3f5d5..8b235925b 100755 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/TemplateResolution.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/TemplateResolution.kt @@ -22,8 +22,15 @@ import org.hibernate.annotations.Proxy import org.springframework.data.annotation.LastModifiedDate import org.springframework.data.jpa.domain.support.AuditingEntityListener import java.io.Serializable -import java.util.* -import javax.persistence.* +import java.util.Date +import javax.persistence.Column +import javax.persistence.Entity +import javax.persistence.EntityListeners +import javax.persistence.Id +import javax.persistence.Lob +import javax.persistence.Table +import javax.persistence.Temporal +import javax.persistence.TemporalType @EntityListeners(AuditingEntityListener::class) @Entity @@ -48,8 +55,10 @@ class TemplateResolution : Serializable { @Column(name = "result", nullable = false) var result: String? = null - @get:ApiModelProperty(value = "Resolution Key uniquely identifying the resolution of a given artifact within a CBA.", - required = true) + @get:ApiModelProperty( + value = "Resolution Key uniquely identifying the resolution of a given artifact within a CBA.", + required = true + ) @Column(name = "resolution_key", nullable = false) var resolutionKey: String? = null @@ -61,8 +70,10 @@ class TemplateResolution : Serializable { @Column(name = "resource_id", nullable = false) var resourceId: String? = null - @get:ApiModelProperty(value = "If resolution occurred multiple time, this field provides the index.", - required = true) + @get:ApiModelProperty( + value = "If resolution occurred multiple time, this field provides the index.", + required = true + ) @Column(name = "occurrence", nullable = false) var occurrence: Int = 1 diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/TemplateResolutionRepository.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/TemplateResolutionRepository.kt index 440663f25..610a3cfe3 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/TemplateResolutionRepository.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/TemplateResolutionRepository.kt @@ -26,14 +26,16 @@ interface TemplateResolutionRepository : JpaRepository<TemplateResolution, Strin blueprintName: String?, blueprintVersion: String?, artifactName: String, - occurrence: Int): TemplateResolution ? + occurrence: Int + ): TemplateResolution? fun findByResolutionKeyAndBlueprintNameAndBlueprintVersionAndArtifactNameAndOccurrence( key: String, blueprintName: String?, blueprintVersion: String?, artifactName: String, - occurrence: Int): TemplateResolution ? + occurrence: Int + ): TemplateResolution? @Transactional fun deleteByResourceIdAndResourceTypeAndBlueprintNameAndBlueprintVersionAndArtifactNameAndOccurrence( @@ -42,7 +44,8 @@ interface TemplateResolutionRepository : JpaRepository<TemplateResolution, Strin blueprintName: String?, blueprintVersion: String?, artifactName: String, - occurrence: Int) + occurrence: Int + ) @Transactional fun deleteByResolutionKeyAndBlueprintNameAndBlueprintVersionAndArtifactNameAndOccurrence( @@ -50,5 +53,6 @@ interface TemplateResolutionRepository : JpaRepository<TemplateResolution, Strin blueprintName: String?, blueprintVersion: String?, artifactName: String, - occurrence: Int) + occurrence: Int + ) } diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/TemplateResolutionService.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/TemplateResolutionService.kt index c64605ef0..895bc993f 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/TemplateResolutionService.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/TemplateResolutionService.kt @@ -25,7 +25,7 @@ import org.slf4j.LoggerFactory import org.springframework.dao.DataIntegrityViolationException import org.springframework.dao.EmptyResultDataAccessException import org.springframework.stereotype.Service -import java.util.* +import java.util.UUID @Service class TemplateResolutionService(private val templateResolutionRepository: TemplateResolutionRepository) { @@ -35,7 +35,8 @@ class TemplateResolutionService(private val templateResolutionRepository: Templa suspend fun findByResolutionKeyAndBlueprintNameAndBlueprintVersionAndArtifactName( bluePrintRuntimeService: BluePrintRuntimeService<*>, artifactPrefix: String, - resolutionKey: String): String = + resolutionKey: String + ): String = withContext(Dispatchers.IO) { val metadata = bluePrintRuntimeService.bluePrintContext().metadata!! @@ -43,17 +44,21 @@ class TemplateResolutionService(private val templateResolutionRepository: Templa val blueprintVersion = metadata[BluePrintConstants.METADATA_TEMPLATE_VERSION]!! val blueprintName = metadata[BluePrintConstants.METADATA_TEMPLATE_NAME]!! - findByResolutionKeyAndBlueprintNameAndBlueprintVersionAndArtifactName(blueprintName, + findByResolutionKeyAndBlueprintNameAndBlueprintVersionAndArtifactName( + blueprintName, blueprintVersion, artifactPrefix, - resolutionKey) + resolutionKey + ) } - suspend fun findByResolutionKeyAndBlueprintNameAndBlueprintVersionAndArtifactName(blueprintName: String, - blueprintVersion: String, - artifactPrefix: String, - resolutionKey: String, - occurrence: Int = 1): String = + suspend fun findByResolutionKeyAndBlueprintNameAndBlueprintVersionAndArtifactName( + blueprintName: String, + blueprintVersion: String, + artifactPrefix: String, + resolutionKey: String, + occurrence: Int = 1 + ): String = withContext(Dispatchers.IO) { templateResolutionRepository.findByResolutionKeyAndBlueprintNameAndBlueprintVersionAndArtifactNameAndOccurrence( @@ -61,15 +66,18 @@ class TemplateResolutionService(private val templateResolutionRepository: Templa blueprintName, blueprintVersion, artifactPrefix, - occurrence)?.result ?: throw EmptyResultDataAccessException(1) + occurrence + )?.result ?: throw EmptyResultDataAccessException(1) } - suspend fun findByResoureIdAndResourceTypeAndBlueprintNameAndBlueprintVersionAndArtifactName(blueprintName: String, - blueprintVersion: String, - artifactPrefix: String, - resourceId: String, - resourceType: String, - occurrence: Int = 1): String = + suspend fun findByResoureIdAndResourceTypeAndBlueprintNameAndBlueprintVersionAndArtifactName( + blueprintName: String, + blueprintVersion: String, + artifactPrefix: String, + resourceId: String, + resourceType: String, + occurrence: Int = 1 + ): String = withContext(Dispatchers.IO) { templateResolutionRepository.findByResourceIdAndResourceTypeAndBlueprintNameAndBlueprintVersionAndArtifactNameAndOccurrence( @@ -78,12 +86,16 @@ class TemplateResolutionService(private val templateResolutionRepository: Templa blueprintName, blueprintVersion, artifactPrefix, - occurrence)?.result!! + occurrence + )?.result!! } - suspend fun write(properties: Map<String, Any>, - result: String, bluePrintRuntimeService: BluePrintRuntimeService<*>, - artifactPrefix: String): TemplateResolution = withContext(Dispatchers.IO) { + suspend fun write( + properties: Map<String, Any>, + result: String, + bluePrintRuntimeService: BluePrintRuntimeService<*>, + artifactPrefix: String + ): TemplateResolution = withContext(Dispatchers.IO) { val metadata = bluePrintRuntimeService.bluePrintContext().metadata!! @@ -93,19 +105,28 @@ class TemplateResolutionService(private val templateResolutionRepository: Templa val resourceId = properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOURCE_ID] as String val resourceType = properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOURCE_TYPE] as String val occurrence = properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_OCCURRENCE] as Int - write(blueprintName, + write( + blueprintName, blueprintVersion, artifactPrefix, result, occurrence, resolutionKey, resourceId, - resourceType) + resourceType + ) } - suspend fun write(blueprintName: String, blueprintVersion: String, artifactPrefix: String, - template: String, occurrence: Int = 1, resolutionKey: String = "", resourceId: String = "", - resourceType: String = ""): TemplateResolution = + suspend fun write( + blueprintName: String, + blueprintVersion: String, + artifactPrefix: String, + template: String, + occurrence: Int = 1, + resolutionKey: String = "", + resourceId: String = "", + resourceType: String = "" + ): TemplateResolution = withContext(Dispatchers.IO) { val resourceResolutionResult = TemplateResolution() @@ -122,37 +143,49 @@ class TemplateResolutionService(private val templateResolutionRepository: Templa // Overwrite template resolution-key of resourceId/resourceType already existant if (resolutionKey.isNotEmpty()) { templateResolutionRepository.findByResolutionKeyAndBlueprintNameAndBlueprintVersionAndArtifactNameAndOccurrence( - resolutionKey, blueprintName, blueprintVersion, artifactPrefix, occurrence)?.let { - log.info("Overwriting template resolution for blueprintName=($blueprintVersion), blueprintVersion=($blueprintName), " + - "artifactName=($artifactPrefix) and resolutionKey=($resolutionKey)") + resolutionKey, blueprintName, blueprintVersion, artifactPrefix, occurrence + )?.let { + log.info( + "Overwriting template resolution for blueprintName=($blueprintVersion), blueprintVersion=($blueprintName), " + + "artifactName=($artifactPrefix) and resolutionKey=($resolutionKey)" + ) templateResolutionRepository.deleteByResolutionKeyAndBlueprintNameAndBlueprintVersionAndArtifactNameAndOccurrence( resolutionKey, blueprintName, blueprintVersion, artifactPrefix, - occurrence) + occurrence + ) } } else if (resourceId.isNotEmpty() && resourceType.isNotEmpty()) { templateResolutionRepository.findByResourceIdAndResourceTypeAndBlueprintNameAndBlueprintVersionAndArtifactNameAndOccurrence( - resourceId, resourceType, blueprintName, blueprintVersion, artifactPrefix, occurrence)?.let { - log.info("Overwriting template resolution for blueprintName=($blueprintVersion), blueprintVersion=($blueprintName), " + - "artifactName=($artifactPrefix), resourceId=($resourceId) and resourceType=($resourceType)") + resourceId, resourceType, blueprintName, blueprintVersion, artifactPrefix, occurrence + )?.let { + log.info( + "Overwriting template resolution for blueprintName=($blueprintVersion), blueprintVersion=($blueprintName), " + + "artifactName=($artifactPrefix), resourceId=($resourceId) and resourceType=($resourceType)" + ) templateResolutionRepository.deleteByResourceIdAndResourceTypeAndBlueprintNameAndBlueprintVersionAndArtifactNameAndOccurrence( resourceId, resourceType, blueprintName, blueprintVersion, artifactPrefix, - occurrence) + occurrence + ) } } try { - log.info("Writing out template_resolution result: bpName: $blueprintName bpVer $blueprintVersion resKey:$resolutionKey" + - " (resourceId: $resourceId resourceType: $resourceType) occurrence:$occurrence") + log.info( + "Writing out template_resolution result: bpName: $blueprintName bpVer $blueprintVersion resKey:$resolutionKey" + + " (resourceId: $resourceId resourceType: $resourceType) occurrence:$occurrence" + ) templateResolutionRepository.saveAndFlush(resourceResolutionResult) } catch (ex: DataIntegrityViolationException) { - log.error("Error writing out template_resolution result: bpName: $blueprintName bpVer $blueprintVersion resKey:$resolutionKey" + - " (resourceId: $resourceId resourceType: $resourceType) occurrence:$occurrence error: {}", ex.message) + log.error( + "Error writing out template_resolution result: bpName: $blueprintName bpVer $blueprintVersion resKey:$resolutionKey" + + " (resourceId: $resourceId resourceType: $resourceType) occurrence:$occurrence error: {}", ex.message + ) throw BluePrintException("Failed to store resource api result.", ex) } } diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/CapabilityResourceResolutionProcessor.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/CapabilityResourceResolutionProcessor.kt index 9867cd658..feef4c2fe 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/CapabilityResourceResolutionProcessor.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/CapabilityResourceResolutionProcessor.kt @@ -90,8 +90,8 @@ open class CapabilityResourceResolutionProcessor(private var componentFunctionSc ResourceAssignmentUtils.setFailedResourceDataValue(resourceAssignment, runtimeException.message) } - suspend fun scriptInstance(scriptType: String, scriptClassReference: String, instanceDependencies: List<String>) - : ResourceAssignmentProcessor { + suspend fun scriptInstance(scriptType: String, scriptClassReference: String, instanceDependencies: List<String>): + ResourceAssignmentProcessor { log.info( "creating resource resolution of script type($scriptType), reference name($scriptClassReference) and" + @@ -106,5 +106,4 @@ open class CapabilityResourceResolutionProcessor(private var componentFunctionSc return scriptComponent } - -}
\ No newline at end of file +} diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/DatabaseResourceAssignmentProcessor.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/DatabaseResourceAssignmentProcessor.kt index 0f5d91415..8ca0ab63f 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/DatabaseResourceAssignmentProcessor.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/DatabaseResourceAssignmentProcessor.kt @@ -18,7 +18,7 @@ package org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.processor 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.BluePrintDBLibPropertyService import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.PrimaryDBLibGenericService import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.DatabaseResourceSource import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.ResourceResolutionConstants.PREFIX_RESOURCE_RESOLUTION_PROCESSOR @@ -34,7 +34,7 @@ import org.slf4j.LoggerFactory import org.springframework.beans.factory.config.ConfigurableBeanFactory import org.springframework.context.annotation.Scope import org.springframework.stereotype.Service -import java.util.* +import java.util.HashMap /** * DatabaseResourceAssignmentProcessor @@ -44,7 +44,7 @@ import java.util.* @Service("${PREFIX_RESOURCE_RESOLUTION_PROCESSOR}source-db") @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) open class DatabaseResourceAssignmentProcessor( - private val bluePrintDBLibPropertySevice: BluePrintDBLibPropertySevice, + private val bluePrintDBLibPropertyService: BluePrintDBLibPropertyService, private val primaryDBLibGenericService: PrimaryDBLibGenericService ) : ResourceAssignmentProcessor() { @@ -91,8 +91,10 @@ open class DatabaseResourceAssignmentProcessor( "failed to get input-key-mappings for $dName under $dSource properties" } - logger.info("DatabaseResource ($dSource) dictionary information: " + - "Query:($sql), input-key-mapping:($inputKeyMapping), output-key-mapping:(${sourceProperties.outputKeyMapping})") + logger.info( + "DatabaseResource ($dSource) dictionary information: " + + "Query:($sql), input-key-mapping:($inputKeyMapping), output-key-mapping:(${sourceProperties.outputKeyMapping})" + ) val jdbcTemplate = blueprintDBLibService(sourceProperties) val rows = jdbcTemplate.query(sql, populateNamedParameter(inputKeyMapping)) @@ -106,11 +108,10 @@ open class DatabaseResourceAssignmentProcessor( private fun blueprintDBLibService(sourceProperties: DatabaseResourceSource): BluePrintDBLibGenericService { return if (isNotEmpty(sourceProperties.endpointSelector)) { val dbPropertiesJson = raRuntimeService.resolveDSLExpression(sourceProperties.endpointSelector!!) - bluePrintDBLibPropertySevice.JdbcTemplate(dbPropertiesJson) + bluePrintDBLibPropertyService.JdbcTemplate(dbPropertiesJson) } else { primaryDBLibGenericService } - } @Throws(BluePrintProcessorException::class) @@ -119,14 +120,13 @@ open class DatabaseResourceAssignmentProcessor( checkNotEmpty(resourceAssignment.dictionaryName) { "resource assignment dictionary name is not defined for template key (${resourceAssignment.name})" } - check(resourceAssignment.dictionarySource in getListOfDBSources()) - { + check(resourceAssignment.dictionarySource in getListOfDBSources()) { "resource assignment source is not ${ResourceDictionaryConstants.PROCESSOR_DB} but it is ${resourceAssignment.dictionarySource}" } } - //placeholder to get the list of DB sources. - //TODO: This will be replaced with a DB + // placeholder to get the list of DB sources. + // TODO: This will be replaced with a DB private fun getListOfDBSources(): Array<String> = arrayOf(ResourceDictionaryConstants.PROCESSOR_DB) private fun populateNamedParameter(inputKeyMapping: Map<String, String>): Map<String, Any> { diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/DefaultResourceResolutionProcessor.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/DefaultResourceResolutionProcessor.kt index 9a83b0cc0..7705c1102 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/DefaultResourceResolutionProcessor.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/DefaultResourceResolutionProcessor.kt @@ -53,10 +53,9 @@ open class DefaultResourceResolutionProcessor : ResourceAssignmentProcessor() { ResourceAssignmentUtils.setFailedResourceDataValue(resourceAssignment, e.message) throw BluePrintProcessorException("Failed in template key ($resourceAssignment) assignments with: ${e.message}", e) } - } override suspend fun recoverNB(runtimeException: RuntimeException, resourceAssignment: ResourceAssignment) { raRuntimeService.getBluePrintError().addError(runtimeException.message!!) } -}
\ No newline at end of file +} diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/InputResourceResolutionProcessor.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/InputResourceResolutionProcessor.kt index a78e7872e..f04a787db 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/InputResourceResolutionProcessor.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/InputResourceResolutionProcessor.kt @@ -17,10 +17,12 @@ package org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.processor +import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.DatabaseResourceSource import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.ResourceResolutionConstants.PREFIX_RESOURCE_RESOLUTION_PROCESSOR import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.utils.ResourceAssignmentUtils import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException import org.onap.ccsdk.cds.controllerblueprints.core.isNotEmpty +import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceAssignment import org.springframework.beans.factory.config.ConfigurableBeanFactory import org.springframework.context.annotation.Scope @@ -41,8 +43,8 @@ open class InputResourceResolutionProcessor : ResourceAssignmentProcessor() { override suspend fun processNB(resourceAssignment: ResourceAssignment) { try { - if (isNotEmpty(resourceAssignment.name)) { - setFromInput(resourceAssignment) + if (isNotEmpty(resourceAssignment.name) && !setFromInput(resourceAssignment)) { + setFromKeyDependencies(resourceAssignment) } // Check the value has populated for mandatory case ResourceAssignmentUtils.assertTemplateKeyValueNotNull(resourceAssignment) @@ -52,7 +54,30 @@ open class InputResourceResolutionProcessor : ResourceAssignmentProcessor() { } } + // usecase: where input data attribute doesn't match with resourceName, and needs an alternate mapping provided under key-dependencies. + private fun setFromKeyDependencies(resourceAssignment: ResourceAssignment) { + 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 sourceProperties = + JacksonUtils.getInstanceFromMap(resourceSourceProperties, DatabaseResourceSource::class.java) + + val keyDependency = checkNotNull(sourceProperties.keyDependencies) { + "failed to get input-key-mappings for $dName under $dSource properties" + } + // keyDependency = service-instance.service-instance-id + setFromInputKeyDependencies(keyDependency, resourceAssignment); // New API which picks arrtibute from Input + } + override suspend fun recoverNB(runtimeException: RuntimeException, resourceAssignment: ResourceAssignment) { raRuntimeService.getBluePrintError().addError(runtimeException.message!!) } -}
\ No newline at end of file +} diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/ResourceAssignmentProcessor.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/ResourceAssignmentProcessor.kt index e513170a8..454a899aa 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/ResourceAssignmentProcessor.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/ResourceAssignmentProcessor.kt @@ -22,13 +22,17 @@ import com.fasterxml.jackson.databind.JsonNode import org.apache.commons.collections.MapUtils import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.ResourceAssignmentRuntimeService import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.utils.ResourceAssignmentUtils -import org.onap.ccsdk.cds.controllerblueprints.core.* +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException +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> { @@ -52,8 +56,10 @@ abstract class ResourceAssignmentProcessor : BlueprintFunctionNode<ResourceAssig try { 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)) + log.debug( + "For Resource:(${resourceAssignment.name}) found value:({}) in input-data.", + ResourceAssignmentUtils.getValueToLog(resourceAssignment.property?.metadata, value) + ) ResourceAssignmentUtils.setResourceDataValue(resourceAssignment, raRuntimeService, value) return true } @@ -63,6 +69,25 @@ abstract class ResourceAssignmentProcessor : BlueprintFunctionNode<ResourceAssig 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 false + } + open fun resourceDefinition(name: String): ResourceDefinition? { return if (resourceDictionaries.containsKey(name)) resourceDictionaries[name] else null } @@ -83,7 +108,7 @@ abstract class ResourceAssignmentProcessor : BlueprintFunctionNode<ResourceAssig 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()) } @@ -171,4 +196,4 @@ abstract class ResourceAssignmentProcessor : BlueprintFunctionNode<ResourceAssig fun addError(error: String) { raRuntimeService.getBluePrintError().addError(error) } -}
\ No newline at end of file +} diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/RestResourceResolutionProcessor.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/RestResourceResolutionProcessor.kt index e9aa2749a..2ff5c441e 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/RestResourceResolutionProcessor.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/RestResourceResolutionProcessor.kt @@ -81,8 +81,10 @@ open class RestResourceResolutionProcessor(private val blueprintRestLibPropertyS resolveFromInputKeyMapping(checkNotNull(sourceProperties.urlPath), resolvedInputKeyMapping) val verb = resolveFromInputKeyMapping(nullToEmpty(sourceProperties.verb), resolvedInputKeyMapping) - logger.info("RestResource ($dSource) dictionary information: " + - "URL:($urlPath), input-key-mapping:($inputKeyMapping), output-key-mapping:(${sourceProperties.outputKeyMapping})") + logger.info( + "RestResource ($dSource) dictionary information: " + + "URL:($urlPath), input-key-mapping:($inputKeyMapping), output-key-mapping:(${sourceProperties.outputKeyMapping})" + ) val requestHeaders = sourceProperties.headers logger.info("$dSource dictionary information : ($urlPath), ($inputKeyMapping), (${sourceProperties.outputKeyMapping})") // Get the Rest Client Service @@ -125,8 +127,10 @@ open class RestResourceResolutionProcessor(private val blueprintRestLibPropertyS @Throws(BluePrintProcessorException::class) private fun populateResource( - resourceAssignment: ResourceAssignment, sourceProperties: RestResourceSource, - restResponse: String, path: String + resourceAssignment: ResourceAssignment, + sourceProperties: RestResourceSource, + restResponse: String, + path: String ) { val dName = resourceAssignment.dictionaryName val dSource = resourceAssignment.dictionarySource @@ -168,5 +172,4 @@ open class RestResourceResolutionProcessor(private val blueprintRestLibPropertyS override suspend fun recoverNB(runtimeException: RuntimeException, resourceAssignment: ResourceAssignment) { raRuntimeService.getBluePrintError().addError(runtimeException.message!!) } - } diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/utils/ResourceAssignmentUtils.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/utils/ResourceAssignmentUtils.kt index 688713469..b818cc2b1 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/utils/ResourceAssignmentUtils.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/utils/ResourceAssignmentUtils.kt @@ -25,14 +25,25 @@ import com.fasterxml.jackson.databind.node.ObjectNode import com.fasterxml.jackson.databind.node.TextNode import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.ResourceAssignmentRuntimeService import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.ResourceResolutionConstants -import org.onap.ccsdk.cds.controllerblueprints.core.* +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintTypes +import org.onap.ccsdk.cds.controllerblueprints.core.asJsonType +import org.onap.ccsdk.cds.controllerblueprints.core.checkFileExists +import org.onap.ccsdk.cds.controllerblueprints.core.checkNotEmpty +import org.onap.ccsdk.cds.controllerblueprints.core.isComplexType +import org.onap.ccsdk.cds.controllerblueprints.core.isNotEmpty +import org.onap.ccsdk.cds.controllerblueprints.core.isNullOrMissing +import org.onap.ccsdk.cds.controllerblueprints.core.normalizedFile +import org.onap.ccsdk.cds.controllerblueprints.core.nullToEmpty +import org.onap.ccsdk.cds.controllerblueprints.core.rootFieldsToMap import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintRuntimeService import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonReactorUtils 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.slf4j.LoggerFactory -import java.util.* +import java.util.Date class ResourceAssignmentUtils { companion object { @@ -51,7 +62,8 @@ class ResourceAssignmentUtils { @Throws(BluePrintProcessorException::class) fun setResourceDataValue( resourceAssignment: ResourceAssignment, - raRuntimeService: ResourceAssignmentRuntimeService, value: Any? + raRuntimeService: ResourceAssignmentRuntimeService, + value: Any? ) { // TODO("See if Validation is needed in future with respect to conversion and Types") return setResourceDataValue(resourceAssignment, raRuntimeService, value.asJsonType()) @@ -60,7 +72,8 @@ class ResourceAssignmentUtils { @Throws(BluePrintProcessorException::class) fun setResourceDataValue( resourceAssignment: ResourceAssignment, - raRuntimeService: ResourceAssignmentRuntimeService, value: JsonNode + raRuntimeService: ResourceAssignmentRuntimeService, + value: JsonNode ) { val resourceProp = checkNotNull(resourceAssignment.property) { "Failed in setting resource value for resource mapping $resourceAssignment" @@ -102,7 +115,8 @@ class ResourceAssignmentUtils { private fun setResourceValue( resourceAssignment: ResourceAssignment, - raRuntimeService: ResourceAssignmentRuntimeService, value: JsonNode + raRuntimeService: ResourceAssignmentRuntimeService, + value: JsonNode ) { // TODO("See if Validation is needed wrt to type before storing") raRuntimeService.putResolutionStore(resourceAssignment.name, value) @@ -211,7 +225,8 @@ class ResourceAssignmentUtils { @Throws(BluePrintProcessorException::class) fun getPropertyType( - raRuntimeService: ResourceAssignmentRuntimeService, dataTypeName: String, + raRuntimeService: ResourceAssignmentRuntimeService, + dataTypeName: String, propertyName: String ): String { lateinit var type: String @@ -231,8 +246,10 @@ class ResourceAssignmentUtils { @Throws(BluePrintProcessorException::class) fun parseResponseNode( - responseNode: JsonNode, resourceAssignment: ResourceAssignment, - raRuntimeService: ResourceAssignmentRuntimeService, outputKeyMapping: MutableMap<String, String> + responseNode: JsonNode, + resourceAssignment: ResourceAssignment, + raRuntimeService: ResourceAssignmentRuntimeService, + outputKeyMapping: MutableMap<String, String> ): JsonNode { val metadata = resourceAssignment.property!!.metadata try { @@ -297,7 +314,8 @@ class ResourceAssignmentUtils { } private fun parseResponseNodeForCollection( - responseNode: JsonNode, resourceAssignment: ResourceAssignment, + responseNode: JsonNode, + resourceAssignment: ResourceAssignment, raRuntimeService: ResourceAssignmentRuntimeService, outputKeyMapping: MutableMap<String, String> ): JsonNode { @@ -368,9 +386,11 @@ class ResourceAssignmentUtils { } private fun parseSingleElementOfArrayResponseNode( - entrySchemaType: String, outputKeyMapping: MutableMap<String, String>, + entrySchemaType: String, + outputKeyMapping: MutableMap<String, String>, raRuntimeService: ResourceAssignmentRuntimeService, - responseNode: JsonNode, metadata: MutableMap<String, String>? + responseNode: JsonNode, + metadata: MutableMap<String, String>? ): ObjectNode { val outputKeyMappingHasOnlyOneElement = checkIfOutputKeyMappingProvideOneElement(outputKeyMapping) when (entrySchemaType) { @@ -421,8 +441,10 @@ class ResourceAssignmentUtils { } private fun parseObjectResponseNode( - entrySchemaType: String, outputKeyMapping: MutableMap<String, String>, - responseArrayNode: MutableMap<String, JsonNode>, metadata: MutableMap<String, String>? + entrySchemaType: String, + outputKeyMapping: MutableMap<String, String>, + responseArrayNode: MutableMap<String, JsonNode>, + metadata: MutableMap<String, String>? ): ObjectNode { val outputKeyMappingHasOnlyOneElement = checkIfOutputKeyMappingProvideOneElement(outputKeyMapping) if (outputKeyMappingHasOnlyOneElement) { @@ -437,8 +459,12 @@ class ResourceAssignmentUtils { } private fun parseSingleElementNodeWithOneOutputKeyMapping( - responseSingleJsonNode: JsonNode, outputKeyMappingKey: - String, outputKeyMappingValue: String, type: String, metadata: MutableMap<String, String>? + responseSingleJsonNode: JsonNode, + outputKeyMappingKey: + String, + outputKeyMappingValue: String, + type: String, + metadata: MutableMap<String, String>? ): ObjectNode { val arrayChildNode = JacksonUtils.objectMapper.createObjectNode() @@ -457,7 +483,8 @@ class ResourceAssignmentUtils { private fun parseSingleElementNodeWithAllOutputKeyMapping( responseSingleJsonNode: JsonNode, outputKeyMapping: MutableMap<String, String>, - type: String, metadata: MutableMap<String, String>? + type: String, + metadata: MutableMap<String, String>? ): ObjectNode { val arrayChildNode = JacksonUtils.objectMapper.createObjectNode() outputKeyMapping.map { @@ -475,8 +502,10 @@ class ResourceAssignmentUtils { private fun parseObjectResponseNodeWithOneOutputKeyMapping( responseArrayNode: MutableMap<String, JsonNode>, - outputKeyMappingKey: String, outputKeyMappingValue: String, - type: String, metadata: MutableMap<String, String>? + outputKeyMappingKey: String, + outputKeyMappingValue: String, + type: String, + metadata: MutableMap<String, String>? ): ObjectNode { val objectNode = JacksonUtils.objectMapper.createObjectNode() val responseSingleJsonNode = responseArrayNode.filterKeys { key -> @@ -494,7 +523,8 @@ class ResourceAssignmentUtils { } private fun parseResponseNodeForComplexType( - responseNode: JsonNode, resourceAssignment: ResourceAssignment, + responseNode: JsonNode, + resourceAssignment: ResourceAssignment, raRuntimeService: ResourceAssignmentRuntimeService, outputKeyMapping: MutableMap<String, String> ): JsonNode { @@ -536,7 +566,8 @@ class ResourceAssignmentUtils { } private fun checkOutputKeyMappingAllElementsInDataTypeProperties( - dataTypeName: String, outputKeyMapping: MutableMap<String, String>, + dataTypeName: String, + outputKeyMapping: MutableMap<String, String>, raRuntimeService: ResourceAssignmentRuntimeService ): Boolean { val dataTypeProps = raRuntimeService.bluePrintContext().dataTypeByName(dataTypeName)?.properties @@ -583,4 +614,4 @@ class ResourceAssignmentUtils { return checkProtected } } -}
\ No newline at end of file +} diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/utils/ResourceDefinitionUtils.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/utils/ResourceDefinitionUtils.kt index 15a8c6c80..d3641a850 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/utils/ResourceDefinitionUtils.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/utils/ResourceDefinitionUtils.kt @@ -40,19 +40,22 @@ object ResourceDefinitionUtils { } /** Create a processing resource assignments for the resource definition */ - fun createResourceAssignments(resourceDefinitions: MutableMap<String, ResourceDefinition>, - resolveDefinition: String, sources: List<String>) - : MutableList<ResourceAssignment> { + 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)") + ?: 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)") + ?: throw BluePrintProcessorException("failed to get dependency definition($definitionDependencyName)") val resourceAssignment = ResourceAssignment().apply { name = definitionDependency.name @@ -73,7 +76,7 @@ object ResourceDefinitionUtils { dictionarySourceDefinition = source // Clone the PropertyDefinition, otherwise property value will be overridden property = JacksonUtils - .readValue(resourceDefinition.property.asJsonString(), PropertyDefinition::class.java) + .readValue(resourceDefinition.property.asJsonString(), PropertyDefinition::class.java) val keyDependenciesExists = source.properties?.containsKey("key-dependencies") ?: false if (keyDependenciesExists) { dependencies = source.properties!!["key-dependencies"]!!.asListOfString().toMutableList() @@ -85,4 +88,4 @@ object ResourceDefinitionUtils { // Populate Resource Definition's dependencies as Input Resource Assignment return resourceAssignments } -}
\ No newline at end of file +} diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/scripts/InternalRAProcessor.cba.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/scripts/SimpleRAProcessor.kt index 32f04e6a0..32f04e6a0 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/scripts/InternalRAProcessor.cba.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/scripts/SimpleRAProcessor.kt |