restconf resolution service
authorMuthuramalingam, Brinda Santh <brindasanth@in.ibm.com>
Fri, 15 Feb 2019 23:42:34 +0000 (18:42 -0500)
committerAlexis de Talhouët <adetalhouet89@gmail.com>
Sun, 17 Feb 2019 14:46:44 +0000 (09:46 -0500)
Change-Id: I643430d8c7fb8a29f5333297a2ca022082481dc2
Issue-ID: CCSDK-1086
Signed-off-by: Muthuramalingam, Brinda Santh <brindasanth@in.ibm.com>
ms/blueprintsprocessor/functions/pom.xml
ms/blueprintsprocessor/functions/resource-resolution/pom.xml
ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionService.kt
ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponentTest.kt
ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionServiceTest.kt
ms/blueprintsprocessor/functions/restconf-executor/pom.xml
ms/blueprintsprocessor/functions/restconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/restconf/executor/ComponentRestconfExecutor.kt
ms/blueprintsprocessor/functions/restconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/restconf/executor/RestconfComponentFunction.kt
ms/blueprintsprocessor/functions/restconf-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/restconf/executor/ComponentRestconfExecutorTest.kt
ms/blueprintsprocessor/modules/services/execution-service/pom.xml

index 503e5f0..dc1eda3 100755 (executable)
             <artifactId>execution-service</artifactId>
         </dependency>
         <!-- Test Dependencies -->
+        <dependency>
+            <groupId>io.mockk</groupId>
+            <artifactId>mockk</artifactId>
+            <scope>test</scope>
+        </dependency>
         <dependency>
             <groupId>org.powermock</groupId>
             <artifactId>powermock-api-mockito2</artifactId>
             <artifactId>kotlin-test-junit</artifactId>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>org.jetbrains.kotlinx</groupId>
+            <artifactId>kotlinx-coroutines-test</artifactId>
+            <scope>test</scope>
+        </dependency>
         <dependency>
             <groupId>io.projectreactor</groupId>
             <artifactId>reactor-test</artifactId>
index 1e15ba2..c9f4c58 100644 (file)
             <groupId>org.onap.ccsdk.apps.blueprintsprocessor.functions</groupId>
             <artifactId>python-executor</artifactId>
         </dependency>
-        <dependency>
-            <groupId>org.onap.ccsdk.apps.controllerblueprints</groupId>
-            <artifactId>blueprint-scripts</artifactId>
-        </dependency>
         <dependency>
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-starter-data-jpa</artifactId>
index ce0f060..3498552 100644 (file)
@@ -17,7 +17,6 @@
 \r
 package org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution\r
 \r
-import com.fasterxml.jackson.databind.node.JsonNodeFactory
 import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.processor.ResourceAssignmentProcessor\r
 import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.utils.ResourceAssignmentUtils\r
 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants\r
@@ -29,34 +28,43 @@ import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment
 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
- * @author Brinda Santh\r
- * 8/14/2018\r
- */\r
+interface ResourceResolutionService {
+
+    fun registeredResourceSources(): List<String>
+
+    fun resolveResources(bluePrintRuntimeService: BluePrintRuntimeService<*>, nodeTemplateName: String,
+                         artifactNames: List<String>): MutableMap<String, String>
+
+    fun resolveResources(bluePrintRuntimeService: BluePrintRuntimeService<*>, nodeTemplateName: String,
+                         artifactPrefix: String): String
+
+    fun resolveResources(bluePrintRuntimeService: BluePrintRuntimeService<*>, nodeTemplateName: String,
+                         artifactMapping: String, artifactTemplate: String?): String
+
+    fun resolveResourceAssignments(blueprintRuntimeService: BluePrintRuntimeService<*>,
+                                   resourceDictionaries: MutableMap<String, ResourceDefinition>,
+                                   resourceAssignments: MutableList<ResourceAssignment>,
+                                   identifierName: String)
+}
 \r
 @Service\r
-class ResourceResolutionService {\r
+open class ResourceResolutionServiceImpl(private var applicationContext: ApplicationContext) :
+        ResourceResolutionService {
 \r
     private val log = LoggerFactory.getLogger(ResourceResolutionService::class.java)\r
 \r
-    @Autowired\r
-    private lateinit var applicationContext: ApplicationContext\r
-\r
-    fun registeredResourceSources(): List<String> {\r
+    override fun registeredResourceSources(): List<String> {
         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
-\r
-    fun resolveResources(bluePrintRuntimeService: BluePrintRuntimeService<*>, nodeTemplateName: String,\r
-                         artifactNames: List<String>): MutableMap<String, String> {\r
+    override fun resolveResources(bluePrintRuntimeService: BluePrintRuntimeService<*>, nodeTemplateName: String,
+                                  artifactNames: List<String>): MutableMap<String, String> {
 \r
         val resolvedParams: MutableMap<String, String> = hashMapOf()\r
         artifactNames.forEach { artifactName ->\r
@@ -66,18 +74,27 @@ class ResourceResolutionService {
         return resolvedParams\r
     }\r
 \r
+    override fun resolveResources(bluePrintRuntimeService: BluePrintRuntimeService<*>, nodeTemplateName: String,
+                                  artifactPrefix: String): String {
 \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
+        val artifactTemplate = "$artifactPrefix-template"
         // 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
+        val artifactMapping = "$artifactPrefix-mapping"
+
+        return resolveResources(bluePrintRuntimeService, nodeTemplateName, artifactMapping, artifactTemplate)
+    }
+
+\r
+    override fun resolveResources(bluePrintRuntimeService: BluePrintRuntimeService<*>, nodeTemplateName: String,
+                                  artifactMapping: String, artifactTemplate: String?): String {
+\r
+        var resolvedContent = ""
+        log.info("Resolving resource for template artifact($artifactTemplate) with resource assignment artifact($artifactMapping)")
+
+        val identifierName = artifactTemplate ?: "no-template"
+
+        val resourceAssignmentContent = bluePrintRuntimeService.resolveNodeTemplateArtifact(nodeTemplateName, artifactMapping)
 \r
         val resourceAssignments: MutableList<ResourceAssignment> = JacksonUtils.getListFromJson(resourceAssignmentContent, ResourceAssignment::class.java)\r
                 as? MutableList<ResourceAssignment>\r
@@ -92,14 +109,13 @@ class ResourceResolutionService {
                 ?: throw BluePrintProcessorException("couldn't get Dictionary Definitions")\r
 \r
         // Resolve resources
-        executeProcessors(bluePrintRuntimeService, resourceDictionaries, resourceAssignments, templateArtifactName)\r
-\r
-        // Check Template is there\r
-        val templateContent = bluePrintRuntimeService.resolveNodeTemplateArtifact(nodeTemplateName, templateArtifactName)
+        resolveResourceAssignments(bluePrintRuntimeService, resourceDictionaries, resourceAssignments, identifierName)
 \r
         val resolvedParamJsonContent = ResourceAssignmentUtils.generateResourceDataForAssignments(resourceAssignments.toList())
 \r
-        if (templateContent.isNotEmpty()) {\r
+        // Check Template is there
+        if (artifactTemplate != null) {
+            val templateContent = bluePrintRuntimeService.resolveNodeTemplateArtifact(nodeTemplateName, artifactTemplate)
             resolvedContent = BluePrintTemplateService.generateContent(templateContent, resolvedParamJsonContent)
         } else {\r
             resolvedContent = resolvedParamJsonContent\r
@@ -107,13 +123,13 @@ class ResourceResolutionService {
         return resolvedContent\r
     }\r
 \r
-    private fun executeProcessors(blueprintRuntimeService: BluePrintRuntimeService<*>,\r
-                                  resourceDictionaries: MutableMap<String, ResourceDefinition>,\r
-                                  resourceAssignments: MutableList<ResourceAssignment>,\r
-                                  templateArtifactName: String) {\r
+    override fun resolveResourceAssignments(blueprintRuntimeService: BluePrintRuntimeService<*>,
+                                            resourceDictionaries: MutableMap<String, ResourceDefinition>,
+                                            resourceAssignments: MutableList<ResourceAssignment>,
+                                            identifierName: String) {
 \r
         val bulkSequenced = BulkResourceSequencingUtils.process(resourceAssignments)\r
-        val resourceAssignmentRuntimeService = ResourceAssignmentUtils.transformToRARuntimeService(blueprintRuntimeService, templateArtifactName)\r
+        val resourceAssignmentRuntimeService = ResourceAssignmentUtils.transformToRARuntimeService(blueprintRuntimeService, identifierName)
 \r
         bulkSequenced.map { batchResourceAssignments ->\r
             batchResourceAssignments.filter { it.name != "*" && it.name != "start" }\r
index bb54fcb..fbecb55 100644 (file)
@@ -1,5 +1,6 @@
 /*
  * Copyright © 2017-2018 AT&T Intellectual Property.
+ * Modifications Copyright © 2018 IBM.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -40,7 +41,7 @@ import org.springframework.test.context.TestPropertySource
 import org.springframework.test.context.junit4.SpringRunner
 
 @RunWith(SpringRunner::class)
-@ContextConfiguration(classes = [ResourceResolutionService::class,
+@ContextConfiguration(classes = [ResourceResolutionServiceImpl::class,
     InputResourceAssignmentProcessor::class, DefaultResourceAssignmentProcessor::class,
     PrimaryDataResourceAssignmentProcessor::class, SimpleRestResourceAssignmentProcessor::class,
     CapabilityResourceAssignmentProcessor::class, PrimaryDBLibGenericService::class,
index 2f97481..d0d3a13 100644 (file)
@@ -1,5 +1,6 @@
 /*
  * Copyright © 2017-2018 AT&T Intellectual Property.
+ * Modifications Copyright © 2018 IBM.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -45,7 +46,7 @@ import kotlin.test.assertTrue
  * @author Brinda Santh DATE : 8/15/2018
  */
 @RunWith(SpringRunner::class)
-@ContextConfiguration(classes = [ResourceResolutionService::class,
+@ContextConfiguration(classes = [ResourceResolutionServiceImpl::class,
     InputResourceAssignmentProcessor::class, DefaultResourceAssignmentProcessor::class,
     PrimaryDataResourceAssignmentProcessor::class, SimpleRestResourceAssignmentProcessor::class,
     CapabilityResourceAssignmentProcessor::class, PrimaryDBLibGenericService::class,
index dea3a8a..cee90b6 100644 (file)
     <dependencies>
         <dependency>
             <groupId>org.onap.ccsdk.apps.blueprintsprocessor.functions</groupId>
-            <artifactId>python-executor</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>org.onap.ccsdk.apps.controllerblueprints</groupId>
-            <artifactId>blueprint-scripts</artifactId>
-        </dependency>
-
-        <!--Testing dependencies-->
-        <dependency>
-            <groupId>org.jetbrains.kotlin</groupId>
-            <artifactId>kotlin-test-junit</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>io.mockk</groupId>
-            <artifactId>mockk</artifactId>
+            <artifactId>resource-resolution</artifactId>
         </dependency>
     </dependencies>
 
index e91b95f..9bcc23b 100644 (file)
@@ -18,6 +18,7 @@ package org.onap.ccsdk.apps.blueprintsprocessor.functions.restconf.executor
 
 import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceInput
 import org.onap.ccsdk.apps.blueprintsprocessor.functions.python.executor.BlueprintJythonService
+import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.ResourceResolutionService
 import org.onap.ccsdk.apps.blueprintsprocessor.rest.service.BluePrintRestLibPropertyService
 import org.onap.ccsdk.apps.blueprintsprocessor.services.execution.AbstractComponentFunction
 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants
@@ -35,7 +36,8 @@ import org.springframework.stereotype.Component
 open class ComponentRestconfExecutor(private var applicationContext: ApplicationContext,
                                      private val blueprintJythonService: BlueprintJythonService,
                                      private val bluePrintScriptsService: BluePrintScriptsService,
-                                     private var bluePrintRestLibPropertyService: BluePrintRestLibPropertyService) :
+                                     private var bluePrintRestLibPropertyService: BluePrintRestLibPropertyService,
+                                     private var resourceResolutionService: ResourceResolutionService) :
         AbstractComponentFunction() {
 
     private val log = LoggerFactory.getLogger(ComponentRestconfExecutor::class.java)
@@ -68,6 +70,7 @@ open class ComponentRestconfExecutor(private var applicationContext: Application
 
         // Set the Rest Lib Property Service
         scriptComponent.bluePrintRestLibPropertyService = bluePrintRestLibPropertyService
+        scriptComponent.resourceResolutionService = resourceResolutionService
 
         scriptComponent.process(executionServiceInput)
     }
index 7b3615f..d9362af 100644 (file)
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  */
-
+@file:Suppress("unused")
 package org.onap.ccsdk.apps.blueprintsprocessor.functions.restconf.executor
 
+import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.ResourceResolutionService
 import org.onap.ccsdk.apps.blueprintsprocessor.rest.service.BluePrintRestLibPropertyService
 import org.onap.ccsdk.apps.blueprintsprocessor.rest.service.BlueprintWebClientService
 import org.onap.ccsdk.apps.blueprintsprocessor.services.execution.AbstractComponentFunction
@@ -24,10 +25,23 @@ import org.onap.ccsdk.apps.blueprintsprocessor.services.execution.AbstractCompon
 abstract class RestconfComponentFunction : AbstractComponentFunction() {
 
     lateinit var bluePrintRestLibPropertyService: BluePrintRestLibPropertyService
+    lateinit var resourceResolutionService: ResourceResolutionService
 
     fun restClientService(selector: String): BlueprintWebClientService {
         return bluePrintRestLibPropertyService.blueprintWebClientService(selector)
     }
 
+    fun generateMessage(artifactName: String): String {
+        return bluePrintRuntimeService.resolveNodeTemplateArtifact(nodeTemplateName, artifactName)
+    }
 
+    fun resolveAndGenerateMessage(artifactMapping: String, artifactTemplate: String): String {
+        return resourceResolutionService.resolveResources(bluePrintRuntimeService, nodeTemplateName,
+                artifactMapping, artifactTemplate)
+    }
+
+    fun resolveAndGenerateMessage(artifactPrefix: String): String {
+        return resourceResolutionService.resolveResources(bluePrintRuntimeService, nodeTemplateName,
+                artifactPrefix)
+    }
 }
\ No newline at end of file
index 77d4691..31bd4eb 100644 (file)
@@ -29,6 +29,7 @@ import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.CommonHeader
 import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceInput
 import org.onap.ccsdk.apps.blueprintsprocessor.functions.python.executor.BlueprintJythonService
 import org.onap.ccsdk.apps.blueprintsprocessor.functions.python.executor.PythonExecutorProperty
+import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.ResourceResolutionServiceImpl
 import org.onap.ccsdk.apps.blueprintsprocessor.rest.service.BluePrintRestLibPropertyService
 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants
 import org.onap.ccsdk.apps.controllerblueprints.core.asJsonNode
@@ -46,7 +47,8 @@ import kotlin.test.assertNotNull
 @RunWith(SpringRunner::class)
 @ContextConfiguration(classes = [RestconfExecutorConfiguration::class, ComponentRestconfExecutor::class,
     BlueprintJythonService::class, PythonExecutorProperty::class, BluePrintRestLibPropertyService::class,
-    BlueprintPropertyConfiguration::class, BluePrintProperties::class, BluePrintScriptsServiceImpl::class])
+    BlueprintPropertyConfiguration::class, BluePrintProperties::class, BluePrintScriptsServiceImpl::class,
+    ResourceResolutionServiceImpl::class])
 @TestPropertySource(properties =
 ["server.port=9111",
     "blueprintsprocessor.restconfEnabled=true",
index 19685b5..ea5f31a 100644 (file)
             <groupId>org.onap.ccsdk.apps.controllerblueprints</groupId>
             <artifactId>blueprint-core</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.onap.ccsdk.apps.controllerblueprints</groupId>
+            <artifactId>blueprint-scripts</artifactId>
+        </dependency>
         <dependency>
             <groupId>org.onap.ccsdk.apps.blueprintsprocessor</groupId>
             <artifactId>core</artifactId>