Merge "Resource resolution should return a string"
authorDan Timoney <dtimoney@att.com>
Mon, 12 Aug 2019 13:14:12 +0000 (13:14 +0000)
committerGerrit Code Review <gerrit@onap.org>
Mon, 12 Aug 2019 13:14:12 +0000 (13:14 +0000)
1  2 
ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionService.kt

@@@ -26,7 -26,6 +26,7 @@@ import org.onap.ccsdk.cds.blueprintspro
  import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.db.TemplateResolutionService
  import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.processor.ResourceAssignmentProcessor
  import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.utils.ResourceAssignmentUtils
 +import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.utils.ResourceDefinitionUtils.createResourceAssignments
  import org.onap.ccsdk.cds.controllerblueprints.core.*
  import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintRuntimeService
  import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintTemplateService
@@@ -37,7 -36,6 +37,7 @@@ import org.onap.ccsdk.cds.controllerblu
  import org.slf4j.LoggerFactory
  import org.springframework.context.ApplicationContext
  import org.springframework.stereotype.Service
 +import java.util.*
  
  interface ResourceResolutionService {
  
                                      resolutionKey: String): String
  
      suspend fun resolveResources(bluePrintRuntimeService: BluePrintRuntimeService<*>, nodeTemplateName: String,
-                                  artifactNames: List<String>, properties: Map<String, Any>): MutableMap<String, JsonNode>
+                                  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>,
@@@ -93,17 -83,17 +93,17 @@@ open class ResourceResolutionServiceImp
  
      override suspend fun resolveResources(bluePrintRuntimeService: BluePrintRuntimeService<*>, nodeTemplateName: String,
                                            artifactNames: List<String>,
-                                           properties: Map<String, Any>): MutableMap<String, JsonNode> {
+                                           properties: Map<String, Any>): MutableMap<String, String> {
  
          val resourceAssignmentRuntimeService =
 -            ResourceAssignmentUtils.transformToRARuntimeService(bluePrintRuntimeService, artifactNames.toString())
 +                ResourceAssignmentUtils.transformToRARuntimeService(bluePrintRuntimeService, artifactNames.toString())
  
-         val resolvedParams: MutableMap<String, JsonNode> = hashMapOf()
+         val resolvedParams: MutableMap<String, String> = hashMapOf()
          artifactNames.forEach { artifactName ->
              val resolvedContent = resolveResources(resourceAssignmentRuntimeService, nodeTemplateName,
 -                artifactName, properties)
 +                    artifactName, properties)
  
-             resolvedParams[artifactName] = resolvedContent.asJsonType()
+             resolvedParams[artifactName] = resolvedContent
          }
          return resolvedParams
      }
          return resolvedContent
      }
  
 +    override suspend fun resolveResourceDefinition(blueprintRuntimeService: BluePrintRuntimeService<*>,
 +                                                   resourceDefinitions: MutableMap<String, ResourceDefinition>,
 +                                                   resolveDefinition: String, sources: List<String>)
 +            : MutableMap<String, JsonNode> {
 +
 +        // Populate Dummy Resource Assignments
 +        val resourceAssignments = createResourceAssignments(resourceDefinitions, resolveDefinition, sources)
 +
 +        resolveResourceAssignments(blueprintRuntimeService, resourceDefinitions, resourceAssignments,
 +                UUID.randomUUID().toString(), hashMapOf())
 +
 +        // Get the data from Resource Assignments
 +        return ResourceAssignmentUtils.generateResourceForAssignments(resourceAssignments)
 +    }
 +
      /**
       * Iterate the Batch, get the Resource Assignment, dictionary Name, Look for the Resource definition for the
       * name, then get the type of the Resource Definition, Get the instance for the Resource Type and process the
          val bulkSequenced = BulkResourceSequencingUtils.process(resourceAssignments)
  
          // Check the BlueprintRuntime Service Should be ResourceAssignmentRuntimeService
 -        val resourceAssignmentRuntimeService = if (!(blueprintRuntimeService is ResourceAssignmentRuntimeService)) {
 +        val resourceAssignmentRuntimeService = if (blueprintRuntimeService !is ResourceAssignmentRuntimeService) {
              ResourceAssignmentUtils.transformToRARuntimeService(blueprintRuntimeService, artifactPrefix)
          } else {
              blueprintRuntimeService