2 * Copyright © 2017-2018 AT&T Intellectual Property.
3 * Modifications Copyright © 2018-2019 IBM, Bell Canada
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
18 package org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution
20 import com.fasterxml.jackson.databind.JsonNode
21 import kotlinx.coroutines.async
22 import kotlinx.coroutines.awaitAll
23 import kotlinx.coroutines.coroutineScope
24 import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.db.ResourceResolution
25 import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.db.ResourceResolutionDBService
26 import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.db.TemplateResolutionService
27 import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.processor.ResourceAssignmentProcessor
28 import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.utils.ResourceAssignmentUtils
29 import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.utils.ResourceDefinitionUtils.createResourceAssignments
30 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants
31 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException
32 import org.onap.ccsdk.cds.controllerblueprints.core.asJsonNode
33 import org.onap.ccsdk.cds.controllerblueprints.core.asJsonPrimitive
34 import org.onap.ccsdk.cds.controllerblueprints.core.asJsonType
35 import org.onap.ccsdk.cds.controllerblueprints.core.checkNotEmpty
36 import org.onap.ccsdk.cds.controllerblueprints.core.common.ApplicationConstants.LOG_REDACTED
37 import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintRuntimeService
38 import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintTemplateService
39 import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
40 import org.onap.ccsdk.cds.controllerblueprints.core.utils.PropertyDefinitionUtils.Companion.hasLogProtect
41 import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceAssignment
42 import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceDefinition
43 import org.onap.ccsdk.cds.controllerblueprints.resource.dict.utils.BulkResourceSequencingUtils
44 import org.slf4j.LoggerFactory
45 import org.springframework.context.ApplicationContext
46 import org.springframework.stereotype.Service
49 data class ResourceResolutionResult(
50 val templateMap: MutableMap<String, String>,
51 val assignmentMap: MutableMap<String, JsonNode>
54 interface ResourceResolutionService {
56 fun registeredResourceSources(): List<String>
58 suspend fun resolveFromDatabase(
59 bluePrintRuntimeService: BluePrintRuntimeService<*>,
60 artifactTemplate: String,
64 suspend fun resolveResolutionKeysFromDatabase(
65 bluePrintRuntimeService: BluePrintRuntimeService<*>,
66 artifactTemplate: String
69 suspend fun resolveArtifactNamesAndResolutionKeysFromDatabase(
70 bluePrintRuntimeService: BluePrintRuntimeService<*>
71 ): Map<String, List<String>>
73 suspend fun resolveResources(
74 bluePrintRuntimeService: BluePrintRuntimeService<*>,
75 nodeTemplateName: String,
76 artifactNames: List<String>,
77 properties: Map<String, Any>,
79 ): ResourceResolutionResult
81 suspend fun resolveResources(
82 bluePrintRuntimeService: BluePrintRuntimeService<*>,
83 nodeTemplateName: String,
84 artifactPrefix: String,
85 properties: Map<String, Any>
86 ): Pair<String, MutableList<ResourceAssignment>>
88 /** Resolve resources for all the sources defined in a particular resource Definition[resolveDefinition]
89 * with other [resourceDefinitions] dependencies for the sources [sources]
90 * Used to get the same resource values from multiple sources. **/
91 suspend fun resolveResourceDefinition(
92 blueprintRuntimeService: BluePrintRuntimeService<*>,
93 resourceDefinitions: MutableMap<String, ResourceDefinition>,
94 resolveDefinition: String,
97 MutableMap<String, JsonNode>
99 suspend fun resolveResourceAssignments(
100 blueprintRuntimeService: BluePrintRuntimeService<*>,
101 resourceDefinitions: MutableMap<String, ResourceDefinition>,
102 resourceAssignments: MutableList<ResourceAssignment>,
103 artifactPrefix: String,
104 properties: Map<String, Any>
108 @Service(ResourceResolutionConstants.SERVICE_RESOURCE_RESOLUTION)
109 open class ResourceResolutionServiceImpl(
110 private var applicationContext: ApplicationContext,
111 private var templateResolutionDBService: TemplateResolutionService,
112 private var blueprintTemplateService: BluePrintTemplateService,
113 private var resourceResolutionDBService: ResourceResolutionDBService
115 ResourceResolutionService {
117 private val log = LoggerFactory.getLogger(ResourceResolutionService::class.java)
119 override fun registeredResourceSources(): List<String> {
120 return applicationContext.getBeanNamesForType(ResourceAssignmentProcessor::class.java)
121 .filter { it.startsWith(ResourceResolutionConstants.PREFIX_RESOURCE_RESOLUTION_PROCESSOR) }
122 .map { it.substringAfter(ResourceResolutionConstants.PREFIX_RESOURCE_RESOLUTION_PROCESSOR) }
125 override suspend fun resolveFromDatabase(
126 bluePrintRuntimeService: BluePrintRuntimeService<*>,
127 artifactTemplate: String,
128 resolutionKey: String
130 return templateResolutionDBService.findByResolutionKeyAndBlueprintNameAndBlueprintVersionAndArtifactName(
131 bluePrintRuntimeService,
137 override suspend fun resolveResolutionKeysFromDatabase(
138 bluePrintRuntimeService: BluePrintRuntimeService<*>,
139 artifactTemplate: String
141 return templateResolutionDBService.findResolutionKeysByBlueprintNameAndBlueprintVersionAndArtifactName(
142 bluePrintRuntimeService,
147 override suspend fun resolveArtifactNamesAndResolutionKeysFromDatabase(
148 bluePrintRuntimeService: BluePrintRuntimeService<*>
149 ): Map<String, List<String>> {
150 return templateResolutionDBService.findArtifactNamesAndResolutionKeysByBlueprintNameAndBlueprintVersion(
151 bluePrintRuntimeService
155 override suspend fun resolveResources(
156 bluePrintRuntimeService: BluePrintRuntimeService<*>,
157 nodeTemplateName: String,
158 artifactNames: List<String>,
159 properties: Map<String, Any>,
161 ): ResourceResolutionResult {
163 val resourceAssignmentRuntimeService =
164 ResourceAssignmentUtils.transformToRARuntimeService(bluePrintRuntimeService, artifactNames.toString())
166 val templateMap: MutableMap<String, String> = hashMapOf()
167 val assignmentMap: MutableMap<String, JsonNode> = hashMapOf()
168 artifactNames.forEach { artifactName ->
169 val (resolvedStringContent, resourceAssignmentList) = resolveResources(
170 resourceAssignmentRuntimeService, nodeTemplateName,
171 artifactName, properties
173 val resolvedJsonContent = resourceAssignmentList
174 .associateBy({ it.name }, { it.property?.value })
177 templateMap[artifactName] = resolvedStringContent
178 assignmentMap[artifactName] = resolvedJsonContent
180 val failedResolution = resourceAssignmentList.filter { it.status != "success" && it.property?.required == true }.map { it.name }
181 if (failedResolution.isNotEmpty()) {
182 val errorMessages = mutableListOf("Failed to resolve required values: $failedResolution").apply {
183 this.addAll(resourceAssignmentRuntimeService.getBluePrintError().allErrors())
185 bluePrintRuntimeService.getBluePrintError().addErrors(stepName, errorMessages)
188 return ResourceResolutionResult(templateMap, assignmentMap)
191 override suspend fun resolveResources(
192 bluePrintRuntimeService: BluePrintRuntimeService<*>,
193 nodeTemplateName: String,
194 artifactPrefix: String,
195 properties: Map<String, Any>
196 ): Pair<String, MutableList<ResourceAssignment>> {
198 // Template Artifact Definition Name
199 val artifactTemplate = "$artifactPrefix-template"
200 // Resource Assignment Artifact Definition Name
201 val artifactMapping = "$artifactPrefix-mapping"
202 val forceResolution = isForceResolution(properties)
204 val propertiesMutableMap = properties.toMutableMap()
205 log.info("Resolving resource with resource assignment artifact($artifactMapping)")
207 val resourceAssignmentContent =
208 bluePrintRuntimeService.resolveNodeTemplateArtifact(nodeTemplateName, artifactMapping)
210 val resourceAssignments: MutableList<ResourceAssignment> =
211 JacksonUtils.getListFromJson(resourceAssignmentContent, ResourceAssignment::class.java)
212 as? MutableList<ResourceAssignment>
213 ?: throw BluePrintProcessorException("couldn't get Dictionary Definitions")
215 if (isToStore(properties)) {
216 val alwaysPerformNewResolution = properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_OCCURRENCE] as Int <= 0
217 val existingResourceResolution = if (alwaysPerformNewResolution) {
218 val occurrence = findNextOccurrence(bluePrintRuntimeService, properties, artifactPrefix)
219 log.info("Always perform new resolutions - next occurrence: $occurrence")
220 propertiesMutableMap[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_OCCURRENCE] = occurrence
221 // If resolution has already been performed previously then may need to update some assignments
222 val resourceAssignmentFilteredMap: Map<String, ResourceAssignment> =
223 resourceAssignments.filter { it.maxOccurrence != null && it.maxOccurrence!! in 1 until occurrence }
224 .associateBy { it.name }
225 if (occurrence > 1 && resourceAssignmentFilteredMap.isNotEmpty())
226 updateResourceAssignmentByOccurrence(
227 bluePrintRuntimeService as ResourceAssignmentRuntimeService,
228 propertiesMutableMap,
230 resourceAssignmentFilteredMap as MutableMap<String, ResourceAssignment>
232 // we may be performing new resolution for some resources, simply pass an empty list.
235 isNewResolution(bluePrintRuntimeService, properties, artifactPrefix)
237 if (existingResourceResolution.isNotEmpty()) {
238 if (forceResolution) {
239 resourceResolutionDBService.deleteResourceResolutionList(existingResourceResolution)
240 log.info("Force resolution is enabled - will resolve all resources.")
242 updateResourceAssignmentWithExisting(
243 bluePrintRuntimeService as ResourceAssignmentRuntimeService,
244 existingResourceResolution, resourceAssignments
246 log.info("Force resolution is disabled - will resolve all resources not already resolved.")
251 // Get the Resource Dictionary Name
252 val resourceDefinitions: MutableMap<String, ResourceDefinition> = ResourceAssignmentUtils
253 .resourceDefinitions(bluePrintRuntimeService.bluePrintContext().rootPath)
256 resolveResourceAssignments(
257 bluePrintRuntimeService,
264 val resolutionSummary = properties.getOrDefault(
265 ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOLUTION_SUMMARY,
269 val resolvedParamJsonContent =
270 ResourceAssignmentUtils.generateResourceDataForAssignments(resourceAssignments.toList())
271 val artifactTemplateDefinition =
272 bluePrintRuntimeService.bluePrintContext().checkNodeTemplateArtifact(nodeTemplateName, artifactTemplate)
274 val resolvedContent = when {
275 artifactTemplateDefinition != null -> {
276 blueprintTemplateService.generateContent(
277 bluePrintRuntimeService, nodeTemplateName,
278 artifactTemplate, resolvedParamJsonContent, false,
280 ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_OCCURRENCE to
281 properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_OCCURRENCE]
286 resolutionSummary -> {
287 ResourceAssignmentUtils.generateResolutionSummaryData(resourceAssignments, resourceDefinitions)
290 resolvedParamJsonContent
294 if (isToStore(properties)) {
295 templateResolutionDBService.write(propertiesMutableMap, resolvedContent, bluePrintRuntimeService, artifactPrefix)
296 log.info("Template resolution saved into database successfully : ($properties)")
299 return Pair(resolvedContent, resourceAssignments)
302 override suspend fun resolveResourceDefinition(
303 blueprintRuntimeService: BluePrintRuntimeService<*>,
304 resourceDefinitions: MutableMap<String, ResourceDefinition>,
305 resolveDefinition: String,
306 sources: List<String>
307 ): MutableMap<String, JsonNode> {
309 // Populate Dummy Resource Assignments
310 val resourceAssignments = createResourceAssignments(resourceDefinitions, resolveDefinition, sources)
312 resolveResourceAssignments(
313 blueprintRuntimeService, resourceDefinitions, resourceAssignments,
314 UUID.randomUUID().toString(), hashMapOf()
317 // Get the data from Resource Assignments
318 return ResourceAssignmentUtils.generateResourceForAssignments(resourceAssignments)
322 * Iterate the Batch, get the Resource Assignment, dictionary Name, Look for the Resource definition for the
323 * name, then get the type of the Resource Definition, Get the instance for the Resource Type and process the
326 override suspend fun resolveResourceAssignments(
327 blueprintRuntimeService: BluePrintRuntimeService<*>,
328 resourceDefinitions: MutableMap<String, ResourceDefinition>,
329 resourceAssignments: MutableList<ResourceAssignment>,
330 artifactPrefix: String,
331 properties: Map<String, Any>
334 val bulkSequenced = BulkResourceSequencingUtils.process(resourceAssignments)
336 // Check the BlueprintRuntime Service Should be ResourceAssignmentRuntimeService
337 val resourceAssignmentRuntimeService = if (blueprintRuntimeService !is ResourceAssignmentRuntimeService) {
338 ResourceAssignmentUtils.transformToRARuntimeService(blueprintRuntimeService, artifactPrefix)
340 blueprintRuntimeService
343 exposeOccurrencePropertyInResourceAssignments(resourceAssignmentRuntimeService, properties)
346 bulkSequenced.forEach { batchResourceAssignments ->
347 // Execute Non Dependent Assignments in parallel ( ie asynchronously )
348 val deferred = batchResourceAssignments
349 .filter { it.name != "*" && it.name != "start" }
350 .filter { it.status != BluePrintConstants.STATUS_SUCCESS }
351 .map { resourceAssignment ->
353 val dictionaryName = resourceAssignment.dictionaryName
354 val dictionarySource = resourceAssignment.dictionarySource
356 val processorName = processorName(dictionaryName!!, dictionarySource!!, resourceDefinitions)
358 val resourceAssignmentProcessor =
359 applicationContext.getBean(processorName) as? ResourceAssignmentProcessor
360 ?: throw BluePrintProcessorException(
361 "failed to get resource processor ($processorName) " +
362 "for resource assignment(${resourceAssignment.name})"
365 // Set BluePrint Runtime Service
366 resourceAssignmentProcessor.raRuntimeService = resourceAssignmentRuntimeService
367 // Set Resource Dictionaries
368 resourceAssignmentProcessor.resourceDictionaries = resourceDefinitions
370 resourceAssignmentProcessor.resourceAssignments = resourceAssignments
372 // Invoke Apply Method
373 resourceAssignmentProcessor.applyNB(resourceAssignment)
375 if (isToStore(properties)) {
376 resourceResolutionDBService.write(
378 blueprintRuntimeService,
382 log.info("Resource resolution saved into database successfully : (${resourceAssignment.name})")
385 // Set errors from RA
386 blueprintRuntimeService.setBluePrintError(resourceAssignmentRuntimeService.getBluePrintError())
387 } catch (e: RuntimeException) {
388 log.error("Fail in processing ${resourceAssignment.name}", e)
389 throw BluePrintProcessorException(e)
393 log.debug("Resolving (${deferred.size})resources parallel.")
400 * If the Source instance is "input", then it is not mandatory to have source Resource Definition, So it can
401 * derive the default input processor.
403 private fun processorName(
404 dictionaryName: String,
405 dictionarySource: String,
406 resourceDefinitions: MutableMap<String, ResourceDefinition>
408 val processorName: String = when (dictionarySource) {
410 "${ResourceResolutionConstants.PREFIX_RESOURCE_RESOLUTION_PROCESSOR}source-input"
413 "${ResourceResolutionConstants.PREFIX_RESOURCE_RESOLUTION_PROCESSOR}source-default"
416 val resourceDefinition = resourceDefinitions[dictionaryName]
417 ?: throw BluePrintProcessorException("couldn't get resource dictionary definition for $dictionaryName")
419 val resourceSource = resourceDefinition.sources[dictionarySource]
420 ?: throw BluePrintProcessorException("couldn't get resource definition $dictionaryName source($dictionarySource)")
422 ResourceResolutionConstants.PREFIX_RESOURCE_RESOLUTION_PROCESSOR.plus(resourceSource.type)
425 checkNotEmpty(processorName) {
426 "couldn't get processor name for resource dictionary definition($dictionaryName) source($dictionarySource)"
432 // Check whether to store or not the resolution of resource and template
433 private fun isToStore(properties: Map<String, Any>): Boolean {
434 return properties.containsKey(ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_STORE_RESULT) &&
435 properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_STORE_RESULT] as Boolean
438 private fun isForceResolution(properties: Map<String, Any>): Boolean =
439 properties.containsKey(ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_FORCE_RESOLUTION) &&
440 properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_FORCE_RESOLUTION] as Boolean
442 // Check whether resolution already exist in the database for the specified resolution-key or resourceId/resourceType
443 private suspend fun isNewResolution(
444 bluePrintRuntimeService: BluePrintRuntimeService<*>,
445 properties: Map<String, Any>,
446 artifactPrefix: String
447 ): List<ResourceResolution> {
448 val occurrence = properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_OCCURRENCE] as Int
449 val resolutionKey = properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOLUTION_KEY] as String
450 val resourceId = properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOURCE_ID] as String
451 val resourceType = properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOURCE_TYPE] as String
453 if (resolutionKey.isNotEmpty()) {
454 val existingResourceAssignments =
455 resourceResolutionDBService.findByBlueprintNameAndBlueprintVersionAndArtifactNameAndResolutionKeyAndOccurrence(
456 bluePrintRuntimeService,
461 if (existingResourceAssignments.isNotEmpty()) {
463 "Resolution with resolutionKey=($resolutionKey) already exist",
467 return existingResourceAssignments
468 } else if (resourceId.isNotEmpty() && resourceType.isNotEmpty()) {
469 val existingResourceAssignments =
470 resourceResolutionDBService.findByBlueprintNameAndBlueprintVersionAndArtifactNameAndResourceIdAndResourceTypeAndOccurrence(
471 bluePrintRuntimeService,
478 if (existingResourceAssignments.isNotEmpty()) {
480 "Resolution with resourceId=($resourceId) and resourceType=($resourceType) already exist"
483 return existingResourceAssignments
488 // Update the resource assignment list with the status of the resource that have already been resolved
489 private fun updateResourceAssignmentWithExisting(
490 raRuntimeService: ResourceAssignmentRuntimeService,
491 resourceResolutionList: List<ResourceResolution>,
492 resourceAssignmentList: MutableList<ResourceAssignment>
494 resourceResolutionList.forEach { resourceResolution ->
495 if (resourceResolution.status == BluePrintConstants.STATUS_SUCCESS) {
496 resourceAssignmentList.forEach {
497 if (compareOne(resourceResolution, it)) {
499 "Resource ({}) already resolved: value=({})", it.name,
500 if (hasLogProtect(it.property)) LOG_REDACTED else resourceResolution.value
503 // Make sure to recreate value as per the defined type.
504 val value = resourceResolution.value!!.asJsonType(it.property!!.type)
505 it.property!!.value = value
506 it.status = resourceResolution.status
507 ResourceAssignmentUtils.setResourceDataValue(it, raRuntimeService, value)
515 * Utility to update the resourceAssignments with existing resolutions if maxOccurrence is defined on it.
517 private suspend fun updateResourceAssignmentByOccurrence(
518 raRuntimeService: ResourceAssignmentRuntimeService,
519 properties: Map<String, Any>,
520 artifactPrefix: String,
521 resourceAssignmentFilteredMap: MutableMap<String, ResourceAssignment>
523 val resourceResolutionMap =
524 getResourceResolutionByLastOccurrence(raRuntimeService, properties, artifactPrefix).associateBy { it.name }
526 resourceAssignmentFilteredMap
528 resourceResolutionMap.containsKey(it.key) && compareOne(
529 resourceResolutionMap[it.key]!!,
533 .forEach { raMapEntry ->
534 val resourceResolution = resourceResolutionMap[raMapEntry.key]
535 val resourceAssignment = raMapEntry.value
537 resourceResolution?.value?.let {
538 val value = it.asJsonType(resourceAssignment.property!!.type)
539 resourceAssignment.property!!.value = value
540 ResourceAssignmentUtils.setResourceDataValue(
546 resourceAssignment.status = resourceResolution?.status
547 resourceResolutionDBService.write(
557 * Utility to find resource resolution based on occurrence.
559 private suspend fun getResourceResolutionByLastOccurrence(
560 bluePrintRuntimeService: BluePrintRuntimeService<*>,
561 properties: Map<String, Any>,
562 artifactPrefix: String
563 ): List<ResourceResolution> {
565 val resolutionKey = properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOLUTION_KEY] as String
566 val resourceId = properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOURCE_ID] as String
567 val resourceType = properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOURCE_TYPE] as String
569 // This should not happen since the request has already been validated but worth to check it here as well.
570 if (resourceType.isEmpty() && resourceId.isEmpty() && resolutionKey.isEmpty()) {
571 throw BluePrintProcessorException(
572 "Can't proceed to get last occurrence: " +
573 "Either provide a resolution-key OR combination of resource-id and resource-type"
576 val metadata = bluePrintRuntimeService.bluePrintContext().metadata!!
577 val blueprintVersion = metadata[BluePrintConstants.METADATA_TEMPLATE_VERSION]!!
578 val blueprintName = metadata[BluePrintConstants.METADATA_TEMPLATE_NAME]!!
580 return if (resolutionKey.isNotEmpty()) {
581 resourceResolutionDBService.findLastNOccurrences(
587 ).takeIf { it.isNotEmpty() }?.values?.first() ?: emptyList()
589 resourceResolutionDBService.findLastNOccurrences(
596 ).takeIf { it.isNotEmpty() }?.values?.first() ?: emptyList()
600 // Comparison between what we have in the database vs what we have to assign.
601 private fun compareOne(resourceResolution: ResourceResolution, resourceAssignment: ResourceAssignment): Boolean {
603 resourceResolution.name == resourceAssignment.name &&
604 resourceResolution.dictionaryName == resourceAssignment.dictionaryName &&
605 resourceResolution.dictionarySource == resourceAssignment.dictionarySource &&
606 resourceResolution.dictionaryVersion == resourceAssignment.version
610 private fun exposeOccurrencePropertyInResourceAssignments(
611 raRuntimeService: ResourceAssignmentRuntimeService,
612 properties: Map<String, Any>
614 raRuntimeService.putResolutionStore(
615 ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_OCCURRENCE,
616 properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_OCCURRENCE].asJsonPrimitive()
621 * This method returns 'occurrence' required to persist new resource resolution.
623 * @param bluePrintRuntimeService
625 * @param artifactPrefix
627 private suspend fun findNextOccurrence(
628 bluePrintRuntimeService: BluePrintRuntimeService<*>,
629 properties: Map<String, Any>,
630 artifactPrefix: String
632 val metadata = bluePrintRuntimeService.bluePrintContext().metadata!!
633 val blueprintVersion = metadata[BluePrintConstants.METADATA_TEMPLATE_VERSION]!!
634 val blueprintName = metadata[BluePrintConstants.METADATA_TEMPLATE_NAME]!!
635 val resolutionKey = properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOLUTION_KEY] as String
636 val resourceId = properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOURCE_ID] as String
637 val resourceType = properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOURCE_TYPE] as String
639 // This should not happen since the request has already been validated but worth to check it here as well.
640 if (resourceType.isEmpty() && resourceId.isEmpty() && resolutionKey.isEmpty()) {
641 throw BluePrintProcessorException(
642 "Can't proceed to get next occurrence: " +
643 "Either provide a resolution-key OR combination of resource-id and resource-type"
647 if (resolutionKey.isNotEmpty()) {
648 return resourceResolutionDBService.findNextOccurrenceByResolutionKeyAndBlueprintNameAndBlueprintVersionAndArtifactName(
655 return resourceResolutionDBService.findNextOccurrenceByBlueprintNameAndBlueprintVersionAndResourceIdAndResourceType(