Implement Resource Resolution Services
authorMuthuramalingam, Brinda Santh(bs2796) <bs2796@att.com>
Mon, 10 Dec 2018 22:01:38 +0000 (17:01 -0500)
committerMuthuramalingam, Brinda Santh(bs2796) <bs2796@att.com>
Mon, 10 Dec 2018 22:01:38 +0000 (17:01 -0500)
Change-Id: Ia1cf57c9fa16cb943836e3a78d4d2c9776f0e32f
Issue-ID: CCSDK-724
Signed-off-by: Muthuramalingam, Brinda Santh(bs2796) <bs2796@att.com>
16 files changed:
ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponent.kt
ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionConfiguration.kt [new file with mode: 0644]
ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionConstants.kt
ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionService.kt
ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolutionprocessor/DataBaseResourceAssignmentProcessor.kt
ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolutionprocessor/DefaultResourceAssignmentProcessor.kt
ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolutionprocessor/InputResourceAssignmentProcessor.kt
ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolutionprocessor/ResourceAssignmentProcessor.kt [new file with mode: 0644]
ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolutionprocessor/SimpleRestResourceAssignmentProcessor.kt
ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponentTest.kt [new file with mode: 0644]
ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionServiceTest.kt
ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/payload/requests/sample-resourceresolution-request.json
ms/blueprintsprocessor/modules/commons/core/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/core/api/data/BlueprintProcessorData.kt
ms/blueprintsprocessor/modules/commons/core/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/core/utils/PayloadUtils.kt [new file with mode: 0644]
ms/blueprintsprocessor/modules/inbounds/resource-api/src/main/java/org/onap/ccsdk/apps/blueprintsprocessor/resource/api/ResourceResolutionController.java
ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/execution/AbstractComponentFunction.kt

index 32696c5..e5feb25 100644 (file)
@@ -18,15 +18,34 @@ package org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution
 \r
 import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceInput\r
 import org.onap.ccsdk.apps.blueprintsprocessor.services.execution.AbstractComponentFunction\r
+import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException\r
+import org.onap.ccsdk.apps.controllerblueprints.core.asJsonNode\r
+import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils\r
+import org.springframework.beans.factory.annotation.Autowired\r
 import org.springframework.beans.factory.config.ConfigurableBeanFactory\r
+import org.springframework.context.ApplicationContext\r
 import org.springframework.context.annotation.Scope\r
 import org.springframework.stereotype.Component\r
 \r
 @Component("component-resource-resolution")\r
 @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)\r
-open class ResourceResolutionComponent : AbstractComponentFunction() {\r
+open class ResourceResolutionComponent(private val resourceResolutionService: ResourceResolutionService) : AbstractComponentFunction() {\r
+\r
+    @Autowired\r
+    private lateinit var applicationContext: ApplicationContext\r
+\r
     override fun process(executionRequest: ExecutionServiceInput) {\r
-        TODO("not implemented") //To change body of created functions use File | Settings | File Templates.\r
+\r
+        val artifactPrefixNamesNode = getOperationInput(ResourceResolutionConstants.INPUT_ARTIFACT_PREFIX_NAMES)\r
+\r
+        val artifactPrefixNames = JacksonUtils.getListFromJsonNode(artifactPrefixNamesNode, String::class.java)\r
+                ?: throw BluePrintProcessorException("coundn't transform ${artifactPrefixNamesNode.asText()} to string array")\r
+\r
+        val resolvedParamContents = resourceResolutionService.resolveResources(bluePrintRuntimeService!!, nodeTemplateName, artifactPrefixNames)\r
+\r
+        // Set Output Attributes\r
+        bluePrintRuntimeService!!.setNodeTemplateAttributeValue(nodeTemplateName,\r
+                ResourceResolutionConstants.OUTPUT_ASSIGNMENT_PARAMS, resolvedParamContents.asJsonNode())\r
     }\r
 \r
     override fun recover(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) {\r
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionConfiguration.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionConfiguration.kt
new file mode 100644 (file)
index 0000000..4c24ac6
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+ * Copyright © 2017-2018 AT&T Intellectual Property.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution
+
+import org.springframework.context.annotation.ComponentScan
+import org.springframework.context.annotation.Configuration
+
+@Configuration
+@ComponentScan
+open class ResourceResolutionConfiguration
+
+
index aea3313..3211d6e 100644 (file)
@@ -19,6 +19,9 @@ package org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution
 class ResourceResolutionConstants {
     companion object {
         const val PREFIX_RESOURCE_ASSIGNMENT_PROCESSOR = "resource-assignment-processor-"
+        const val INPUT_ARTIFACT_PREFIX_NAMES = "artifact-prefix-names"
+        const val OUTPUT_ASSIGNMENT_PARAMS = "assignment-params"
+        const val FILE_NAME_RESOURCE_DICTIONARY_TYPES = "resources_dictionary_types.json"
     }
 
 }
\ No newline at end of file
index 2b76b78..c3cf009 100644 (file)
 \r
 package org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution\r
 \r
-import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ResourceResolutionInput\r
-import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ResourceResolutionOutput\r
-import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.Status\r
+import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolutionprocessor.ResourceAssignmentProcessor\r
+import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants\r
 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException\r
+import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService\r
+import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils\r
 import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment\r
-import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignmentProcessor\r
+import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition\r
 import org.onap.ccsdk.apps.controllerblueprints.resource.dict.utils.BulkResourceSequencingUtils\r
+import org.slf4j.LoggerFactory\r
 import org.springframework.beans.factory.annotation.Autowired\r
 import org.springframework.context.ApplicationContext\r
 import org.springframework.stereotype.Service\r
+import java.io.File\r
 \r
 /**\r
  * ResourceResolutionService\r
@@ -37,33 +40,76 @@ import org.springframework.stereotype.Service
 @Service\r
 class ResourceResolutionService {\r
 \r
+    private val log = LoggerFactory.getLogger(ResourceResolutionService::class.java)\r
 \r
     @Autowired\r
     private lateinit var applicationContext: ApplicationContext\r
 \r
-    fun resolveResource(resourceResolutionInput: ResourceResolutionInput): ResourceResolutionOutput {\r
-        val resourceResolutionOutput = ResourceResolutionOutput()\r
-        resourceResolutionOutput.actionIdentifiers = resourceResolutionInput.actionIdentifiers\r
-        resourceResolutionOutput.commonHeader = resourceResolutionInput.commonHeader\r
-        resourceResolutionOutput.resourceAssignments = resourceResolutionInput.resourceAssignments\r
+    fun registeredResourceSources(): List<String> {\r
+        return applicationContext.getBeanNamesForType(ResourceAssignmentProcessor::class.java)\r
+                .filter { it.startsWith(ResourceResolutionConstants.PREFIX_RESOURCE_ASSIGNMENT_PROCESSOR) }\r
+                .map { it.substringAfter(ResourceResolutionConstants.PREFIX_RESOURCE_ASSIGNMENT_PROCESSOR) }\r
+    }\r
 \r
-        process(resourceResolutionOutput.resourceAssignments)\r
 \r
-        val status = Status()\r
-        status.code = 200\r
-        status.message = "Success"\r
-        resourceResolutionOutput.status = status\r
+    fun resolveResources(bluePrintRuntimeService: BluePrintRuntimeService<*>, nodeTemplateName: String,\r
+                         artifactNames: List<String>): MutableMap<String, String> {\r
 \r
-        return resourceResolutionOutput\r
+        val resolvedParams: MutableMap<String, String> = hashMapOf()\r
+        artifactNames.forEach { artifactName ->\r
+            val resolvedContent = resolveResources(bluePrintRuntimeService, nodeTemplateName, artifactName)\r
+            resolvedParams[artifactName] = resolvedContent\r
+        }\r
+        return resolvedParams\r
     }\r
 \r
-    fun registeredResourceSources(): List<String> {\r
-        return applicationContext.getBeanNamesForType(ResourceAssignmentProcessor::class.java)\r
-                .filter { it.startsWith(ResourceResolutionConstants.PREFIX_RESOURCE_ASSIGNMENT_PROCESSOR) }\r
-                .map { it.substringAfter(ResourceResolutionConstants.PREFIX_RESOURCE_ASSIGNMENT_PROCESSOR) }\r
+\r
+    fun resolveResources(bluePrintRuntimeService: BluePrintRuntimeService<*>, nodeTemplateName: String, artifactName: String): String {\r
+\r
+        var resolvedContent = ""\r
+        // Velocity Artifact Definition Name\r
+        val templateArtifactName = "$artifactName-template"\r
+        // Resource Assignment Artifact Definition Name\r
+        val mappingArtifactName = "$artifactName-mapping"\r
+\r
+        log.info("Resolving resource for template artifact($templateArtifactName) with resource assignment artifact($mappingArtifactName)")\r
+\r
+        val resourceAssignmentContent = bluePrintRuntimeService.resolveNodeTemplateArtifact(nodeTemplateName, mappingArtifactName)\r
+\r
+        val resourceAssignments: MutableList<ResourceAssignment> = JacksonUtils.getListFromJson(resourceAssignmentContent, ResourceAssignment::class.java)\r
+                as? MutableList<ResourceAssignment>\r
+                ?: throw BluePrintProcessorException("couldn't get Dictionary Definitions")\r
+\r
+        // Get the Resource Dictionary Name\r
+        val dictionaryFile = bluePrintRuntimeService.bluePrintContext().rootPath.plus(File.separator)\r
+                .plus(BluePrintConstants.TOSCA_DEFINITIONS_DIR).plus(File.separator)\r
+                .plus(ResourceResolutionConstants.FILE_NAME_RESOURCE_DICTIONARY_TYPES)\r
+\r
+        val resourceDictionaries: MutableMap<String, ResourceDefinition> = JacksonUtils.getMapFromFile(dictionaryFile, ResourceDefinition::class.java)\r
+                ?: throw BluePrintProcessorException("couldn't get Dictionary Definitions")\r
+\r
+        executeProcessors(bluePrintRuntimeService, resourceDictionaries, resourceAssignments)\r
+\r
+        // Check Template is there\r
+        val templateContent = bluePrintRuntimeService.resolveNodeTemplateArtifact(nodeTemplateName, mappingArtifactName)\r
+\r
+        // TODO ("Generate Param JSON from Resource Assignment")\r
+        val resolvedParamJsonContent = "{}"\r
+\r
+        if (templateContent.isNotEmpty()) {\r
+            // TODO ( "Mash Data and Content")\r
+            resolvedContent = "Mashed Content"\r
+\r
+        } else {\r
+            resolvedContent = resolvedParamJsonContent\r
+        }\r
+        return resolvedContent\r
     }\r
 \r
-    fun process(resourceAssignments: MutableList<ResourceAssignment>) {\r
+\r
+    fun executeProcessors(bluePrintRuntimeService: BluePrintRuntimeService<*>,\r
+                          resourceDictionaries: MutableMap<String, ResourceDefinition>,\r
+                          resourceAssignments: MutableList<ResourceAssignment>) {\r
 \r
         val bulkSequenced = BulkResourceSequencingUtils.process(resourceAssignments)\r
 \r
@@ -77,6 +123,10 @@ class ResourceResolutionService {
                                 ?: throw BluePrintProcessorException("failed to get resource processor for instance name($processorInstanceName) " +\r
                                         "for resource assignment(${resourceAssignment.name})")\r
                         try {\r
+                            // Set BluePrint Runtime Service\r
+                            resourceAssignmentProcessor.bluePrintRuntimeService = bluePrintRuntimeService\r
+                            // Set Resource Dictionaries\r
+                            resourceAssignmentProcessor.resourceDictionaries = resourceDictionaries\r
                             // Invoke Apply Method\r
                             resourceAssignmentProcessor.apply(resourceAssignment)\r
                         } catch (e: RuntimeException) {\r
@@ -86,4 +136,5 @@ class ResourceResolutionService {
                     }\r
         }\r
     }\r
+\r
 }\r
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolutionprocessor/ResourceAssignmentProcessor.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolutionprocessor/ResourceAssignmentProcessor.kt
new file mode 100644 (file)
index 0000000..2b19c8b
--- /dev/null
@@ -0,0 +1,61 @@
+/*
+ *  Copyright © 2018 IBM.
+ *  Modifications Copyright © 2017-2018 AT&T Intellectual Property.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolutionprocessor
+
+import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException
+import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BlueprintFunctionNode
+import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService
+import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment
+import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition
+import org.slf4j.LoggerFactory
+
+abstract class ResourceAssignmentProcessor : BlueprintFunctionNode<ResourceAssignment, ResourceAssignment> {
+
+    private val log = LoggerFactory.getLogger(ResourceAssignmentProcessor::class.java)
+
+    var bluePrintRuntimeService: BluePrintRuntimeService<*>? = null
+
+    var resourceDictionaries: Map<String, ResourceDefinition> = hashMapOf()
+
+
+    open fun resourceDefinition(name: String): ResourceDefinition {
+        return resourceDictionaries.get(name)
+                ?: throw BluePrintProcessorException("couldn't get resource definition($name)")
+    }
+
+    override fun prepareRequest(resourceAssignment: ResourceAssignment): ResourceAssignment {
+        log.info("prepareRequest for ${resourceAssignment.name}, dictionary(${resourceAssignment.dictionaryName})," +
+                "source(${resourceAssignment.dictionarySource})")
+        return resourceAssignment
+    }
+
+    override fun prepareResponse(): ResourceAssignment {
+        log.info("Preparing Response...")
+        return ResourceAssignment()
+    }
+
+    override fun apply(executionServiceInput: ResourceAssignment): ResourceAssignment {
+        prepareRequest(executionServiceInput)
+        process(executionServiceInput)
+        return prepareResponse()
+    }
+
+    override abstract fun process(executionRequest: ResourceAssignment)
+
+    override abstract fun recover(runtimeException: RuntimeException, executionRequest: ResourceAssignment)
+}
\ No newline at end of file
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponentTest.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponentTest.kt
new file mode 100644 (file)
index 0000000..57217d0
--- /dev/null
@@ -0,0 +1,68 @@
+/*
+ * Copyright © 2017-2018 AT&T Intellectual Property.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution
+
+import com.fasterxml.jackson.databind.JsonNode
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceInput
+import org.onap.ccsdk.apps.blueprintsprocessor.core.utils.PayloadUtils
+import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolutionprocessor.DataBaseResourceAssignmentProcessor
+import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolutionprocessor.DefaultResourceAssignmentProcessor
+import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolutionprocessor.InputResourceAssignmentProcessor
+import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolutionprocessor.SimpleRestResourceAssignmentProcessor
+import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants
+import org.onap.ccsdk.apps.controllerblueprints.core.asJsonNode
+import org.onap.ccsdk.apps.controllerblueprints.core.putJsonElement
+import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintMetadataUtils
+import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils
+import org.springframework.beans.factory.annotation.Autowired
+import org.springframework.test.context.ContextConfiguration
+import org.springframework.test.context.junit4.SpringRunner
+
+@RunWith(SpringRunner::class)
+@ContextConfiguration(classes = [ResourceResolutionComponent::class, ResourceResolutionService::class,
+    InputResourceAssignmentProcessor::class, DefaultResourceAssignmentProcessor::class,
+    DataBaseResourceAssignmentProcessor::class, SimpleRestResourceAssignmentProcessor::class])
+class ResourceResolutionComponentTest {
+
+    @Autowired
+    lateinit var resourceResolutionComponent: ResourceResolutionComponent
+
+    @Test
+    fun testProcess() {
+
+        val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime("1234",
+                "./../../../../components/model-catalog/blueprint-model/starter-blueprint/baseconfiguration")
+
+        val executionServiceInput = JacksonUtils.readValueFromClassPathFile("payload/requests/sample-resourceresolution-request.json",
+                ExecutionServiceInput::class.java)!!
+
+        // Prepare Inputs
+        PayloadUtils.prepareInputsFromWorkflowPayload(bluePrintRuntimeService, executionServiceInput.payload, "resource-assignment")
+
+        val stepMetaData: MutableMap<String, JsonNode> = hashMapOf()
+        stepMetaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_NODE_TEMPLATE, "resource-assignment")
+        stepMetaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_INTERFACE, "ResourceAssignmentComponent")
+        stepMetaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_OPERATION, "process")
+        bluePrintRuntimeService.put("resource-assignment-step-inputs", stepMetaData.asJsonNode())
+
+        resourceResolutionComponent.bluePrintRuntimeService = bluePrintRuntimeService
+        resourceResolutionComponent.stepName = "resource-assignment"
+        resourceResolutionComponent.apply(executionServiceInput)
+    }
+}
\ No newline at end of file
index 238d1b0..df56007 100644 (file)
 
 package org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution
 
-import com.fasterxml.jackson.databind.node.ObjectNode
-import org.apache.commons.collections.CollectionUtils
-import org.apache.commons.io.FileUtils
 import org.junit.Assert
 import org.junit.Test
 import org.junit.runner.RunWith
-import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ResourceResolutionInput
 import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolutionprocessor.DataBaseResourceAssignmentProcessor
 import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolutionprocessor.DefaultResourceAssignmentProcessor
 import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolutionprocessor.InputResourceAssignmentProcessor
 import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolutionprocessor.SimpleRestResourceAssignmentProcessor
-import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils
-import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment
+import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintMetadataUtils
 import org.slf4j.LoggerFactory
 import org.springframework.beans.factory.annotation.Autowired
 import org.springframework.test.context.ContextConfiguration
 import org.springframework.test.context.junit4.SpringRunner
-import java.io.File
-import java.nio.charset.Charset
 import kotlin.test.assertNotNull
 import kotlin.test.assertTrue
 
@@ -68,26 +61,10 @@ class ResourceResolutionServiceTest {
 
         Assert.assertNotNull("failed to create ResourceResolutionService", resourceResolutionService)
 
-        val resourceResolutionInputContent = FileUtils.readFileToString(
-                File("src/test/resources/payload/requests/sample-resourceresolution-request.json"), Charset.defaultCharset())
+        val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime("1234",
+                "./../../../../components/model-catalog/blueprint-model/starter-blueprint/baseconfiguration")
 
-        val resourceResolutionInput = JacksonUtils.readValue(resourceResolutionInputContent, ResourceResolutionInput::class.java)
-        Assert.assertNotNull("failed to populate resourceResolutionInput request ", resourceResolutionInput)
-
-        val resourceAssignmentContent = FileUtils.readFileToString(
-                File("src/test/resources/mapping/db/resource-assignments-simple.json"), Charset.defaultCharset())
-        val batchResourceAssignment = JacksonUtils.getListFromJson(resourceAssignmentContent, ResourceAssignment::class.java)
-
-        Assert.assertTrue("failed to create ResourceAssignment from file", CollectionUtils.isNotEmpty(batchResourceAssignment))
-        resourceResolutionInput!!.resourceAssignments = batchResourceAssignment as MutableList<ResourceAssignment>
-
-        val inputContent = JacksonUtils.jsonNodeFromFile("src/test/resources/payload/inputs/input.json") as ObjectNode
-        Assert.assertNotNull("failed to populate input payload ", inputContent)
-        resourceResolutionInput.payload = inputContent
-        log.info("ResourceResolutionInput : {}", JacksonUtils.getJson(resourceResolutionInput, true))
-
-        val resourceResolutionOutput = resourceResolutionService.resolveResource(resourceResolutionInput)
-        Assert.assertNotNull("failed to populate output", resourceResolutionOutput)
+        resourceResolutionService.resolveResources(bluePrintRuntimeService, "resource-assignment", "baseconfig")
 
     }
 
index e8830a8..7889a7e 100644 (file)
     "timestamp": "2012-04-23T18:25:43.511Z"\r
   },\r
   "payload": {\r
-  },\r
-  "resourceAssignments": [\r
-  ]\r
+    "resource-assignment-request": {\r
+      "resource-assignment-properties": {\r
+        "request-id": "1234",\r
+        "action-name": "assign-activate",\r
+        "scope-type": "vnf-type",\r
+        "hostname": "localhost"\r
+      }\r
+    }\r
+  }\r
 }\r
index 3cad627..b0483dc 100644 (file)
@@ -20,7 +20,6 @@ package org.onap.ccsdk.apps.blueprintsprocessor.core.api.data
 import com.fasterxml.jackson.annotation.JsonFormat\r
 import com.fasterxml.jackson.databind.node.ObjectNode\r
 import io.swagger.annotations.ApiModelProperty\r
-import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment\r
 import java.util.*\r
 \r
 /**\r
@@ -29,28 +28,6 @@ import java.util.*
  * DATE : 8/15/2018\r
  */\r
 \r
-open class ResourceResolutionInput {\r
-    @get:ApiModelProperty(required = true)\r
-    lateinit var commonHeader: CommonHeader\r
-    @get:ApiModelProperty(required = true)\r
-    lateinit var actionIdentifiers: ActionIdentifiers\r
-    @get:ApiModelProperty(required = true)\r
-    lateinit var resourceAssignments: MutableList<ResourceAssignment>\r
-    @get:ApiModelProperty(required = true)\r
-    lateinit var payload: ObjectNode\r
-}\r
-\r
-open class ResourceResolutionOutput {\r
-    @get:ApiModelProperty(required = true)\r
-    lateinit var commonHeader: CommonHeader\r
-    @get:ApiModelProperty(required = true)\r
-    lateinit var actionIdentifiers: ActionIdentifiers\r
-    @get:ApiModelProperty(required = true)\r
-    lateinit var status: Status\r
-    @get:ApiModelProperty(required = true)\r
-    lateinit var resourceAssignments: MutableList<ResourceAssignment>\r
-}\r
-\r
 open class ExecutionServiceInput {\r
     @get:ApiModelProperty(required = true)\r
     lateinit var commonHeader: CommonHeader\r
diff --git a/ms/blueprintsprocessor/modules/commons/core/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/core/utils/PayloadUtils.kt b/ms/blueprintsprocessor/modules/commons/core/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/core/utils/PayloadUtils.kt
new file mode 100644 (file)
index 0000000..31dca33
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * Copyright © 2017-2018 AT&T Intellectual Property.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.ccsdk.apps.blueprintsprocessor.core.utils
+
+import com.fasterxml.jackson.databind.JsonNode
+import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants
+import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService
+
+
+class PayloadUtils {
+
+    companion object {
+
+        fun prepareInputsFromWorkflowPayload(bluePrintRuntimeService: BluePrintRuntimeService<*>, payload: JsonNode, workflowName: String) {
+            val input = payload.get("$workflowName-request")
+            bluePrintRuntimeService.assignWorkflowInputs(workflowName, input)
+        }
+
+        fun prepareDynamicInputsFromWorkflowPayload(bluePrintRuntimeService: BluePrintRuntimeService<*>, payload: JsonNode, workflowName: String) {
+            val input = payload.get("$workflowName-request")
+            val propertyFields = input.get("$workflowName-properties")
+            prepareDynamicInputsFromComponentPayload(bluePrintRuntimeService, propertyFields)
+        }
+
+        fun prepareDynamicInputsFromComponentPayload(bluePrintRuntimeService: BluePrintRuntimeService<*>, payload: JsonNode) {
+            payload.fields().forEach { property ->
+                val path = StringBuilder(BluePrintConstants.PATH_INPUTS)
+                        .append(BluePrintConstants.PATH_DIVIDER).append(property.key).toString()
+                bluePrintRuntimeService.put(path, property.value)
+            }
+        }
+    }
+}
\ No newline at end of file
index 0f3b4a8..fb833a5 100644 (file)
 \r
 package org.onap.ccsdk.apps.blueprintsprocessor.resource.api;\r
 \r
-import io.swagger.annotations.ApiOperation;\r
-import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ResourceResolutionInput;\r
-import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ResourceResolutionOutput;\r
 import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.ResourceResolutionService;\r
 import org.springframework.http.MediaType;\r
-import org.springframework.web.bind.annotation.*;\r
+import org.springframework.web.bind.annotation.RequestMapping;\r
+import org.springframework.web.bind.annotation.RequestMethod;\r
+import org.springframework.web.bind.annotation.ResponseBody;\r
+import org.springframework.web.bind.annotation.RestController;\r
 import reactor.core.publisher.Mono;\r
 \r
 /**\r
@@ -45,12 +45,4 @@ public class ResourceResolutionController {
     Mono<String> ping() {\r
         return Mono.just("Success");\r
     }\r
-\r
-    @RequestMapping(path = "/resolve-mapping", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)\r
-    @ApiOperation(value = "Resolve Resource Mappings",\r
-            notes = "Also returns a link to retrieve all students with rel - all-students")\r
-    public @ResponseBody\r
-    Mono<ResourceResolutionOutput> resolveResource(@RequestBody ResourceResolutionInput resourceResolutionInput) {\r
-        return Mono.just(resourceResolutionService.resolveResource(resourceResolutionInput));\r
-    }\r
 }\r
index c6ce465..87a925f 100644 (file)
@@ -19,11 +19,11 @@ package org.onap.ccsdk.apps.blueprintsprocessor.services.execution
 \r
 import com.fasterxml.jackson.databind.JsonNode\r
 import com.fasterxml.jackson.databind.node.JsonNodeFactory\r
-import com.fasterxml.jackson.databind.node.NullNode\r
 import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceInput\r
 import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceOutput\r
 import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.Status\r
 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants\r
+import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException\r
 import org.onap.ccsdk.apps.controllerblueprints.core.asJsonNode\r
 import org.onap.ccsdk.apps.controllerblueprints.core.getAsString\r
 import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BlueprintFunctionNode\r
@@ -118,6 +118,7 @@ abstract class AbstractComponentFunction : BlueprintFunctionNode<ExecutionServic
     }\r
 \r
     fun getOperationInput(key: String): JsonNode {\r
-        return operationInputs[key] ?: NullNode.instance\r
+        return operationInputs[key]\r
+                ?: throw BluePrintProcessorException("couldn't get the operation input($key) value.")\r
     }\r
 }
\ No newline at end of file