From b359a833a6355e110a1be13096e751d86a6c6d15 Mon Sep 17 00:00:00 2001 From: "Muthuramalingam, Brinda Santh" Date: Fri, 15 Feb 2019 18:42:34 -0500 Subject: restconf resolution service Change-Id: I643430d8c7fb8a29f5333297a2ca022082481dc2 Issue-ID: CCSDK-1086 Signed-off-by: Muthuramalingam, Brinda Santh --- ms/blueprintsprocessor/functions/pom.xml | 10 +++ .../functions/resource-resolution/pom.xml | 4 -- .../resolution/ResourceResolutionService.kt | 84 +++++++++++++--------- .../resolution/ResourceResolutionComponentTest.kt | 3 +- .../resolution/ResourceResolutionServiceTest.kt | 3 +- .../functions/restconf-executor/pom.xml | 16 +---- .../restconf/executor/ComponentRestconfExecutor.kt | 5 +- .../restconf/executor/RestconfComponentFunction.kt | 16 ++++- .../executor/ComponentRestconfExecutorTest.kt | 4 +- .../modules/services/execution-service/pom.xml | 4 ++ 10 files changed, 91 insertions(+), 58 deletions(-) diff --git a/ms/blueprintsprocessor/functions/pom.xml b/ms/blueprintsprocessor/functions/pom.xml index 503e5f0b9..dc1eda361 100755 --- a/ms/blueprintsprocessor/functions/pom.xml +++ b/ms/blueprintsprocessor/functions/pom.xml @@ -40,6 +40,11 @@ execution-service + + io.mockk + mockk + test + org.powermock powermock-api-mockito2 @@ -55,6 +60,11 @@ kotlin-test-junit test + + org.jetbrains.kotlinx + kotlinx-coroutines-test + test + io.projectreactor reactor-test diff --git a/ms/blueprintsprocessor/functions/resource-resolution/pom.xml b/ms/blueprintsprocessor/functions/resource-resolution/pom.xml index 1e15ba274..c9f4c5885 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/pom.xml +++ b/ms/blueprintsprocessor/functions/resource-resolution/pom.xml @@ -38,10 +38,6 @@ org.onap.ccsdk.apps.blueprintsprocessor.functions python-executor - - org.onap.ccsdk.apps.controllerblueprints - blueprint-scripts - org.springframework.boot spring-boot-starter-data-jpa diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionService.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionService.kt index ce0f060ee..349855270 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionService.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionService.kt @@ -17,7 +17,6 @@ package org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution -import com.fasterxml.jackson.databind.node.JsonNodeFactory import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.processor.ResourceAssignmentProcessor import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.utils.ResourceAssignmentUtils import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants @@ -29,34 +28,43 @@ import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition import org.onap.ccsdk.apps.controllerblueprints.resource.dict.utils.BulkResourceSequencingUtils import org.slf4j.LoggerFactory -import org.springframework.beans.factory.annotation.Autowired import org.springframework.context.ApplicationContext import org.springframework.stereotype.Service import java.io.File -/** - * ResourceResolutionService - * @author Brinda Santh - * 8/14/2018 - */ +interface ResourceResolutionService { + + fun registeredResourceSources(): List + + fun resolveResources(bluePrintRuntimeService: BluePrintRuntimeService<*>, nodeTemplateName: String, + artifactNames: List): MutableMap + + 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, + resourceAssignments: MutableList, + identifierName: String) +} @Service -class ResourceResolutionService { +open class ResourceResolutionServiceImpl(private var applicationContext: ApplicationContext) : + ResourceResolutionService { private val log = LoggerFactory.getLogger(ResourceResolutionService::class.java) - @Autowired - private lateinit var applicationContext: ApplicationContext - - fun registeredResourceSources(): List { + override fun registeredResourceSources(): List { return applicationContext.getBeanNamesForType(ResourceAssignmentProcessor::class.java) .filter { it.startsWith(ResourceResolutionConstants.PREFIX_RESOURCE_ASSIGNMENT_PROCESSOR) } .map { it.substringAfter(ResourceResolutionConstants.PREFIX_RESOURCE_ASSIGNMENT_PROCESSOR) } } - - fun resolveResources(bluePrintRuntimeService: BluePrintRuntimeService<*>, nodeTemplateName: String, - artifactNames: List): MutableMap { + override fun resolveResources(bluePrintRuntimeService: BluePrintRuntimeService<*>, nodeTemplateName: String, + artifactNames: List): MutableMap { val resolvedParams: MutableMap = hashMapOf() artifactNames.forEach { artifactName -> @@ -66,18 +74,27 @@ class ResourceResolutionService { return resolvedParams } + override fun resolveResources(bluePrintRuntimeService: BluePrintRuntimeService<*>, nodeTemplateName: String, + artifactPrefix: String): String { - fun resolveResources(bluePrintRuntimeService: BluePrintRuntimeService<*>, nodeTemplateName: String, artifactName: String): String { - - var resolvedContent = "" // Velocity Artifact Definition Name - val templateArtifactName = "$artifactName-template" + val artifactTemplate = "$artifactPrefix-template" // Resource Assignment Artifact Definition Name - val mappingArtifactName = "$artifactName-mapping" - - log.info("Resolving resource for template artifact($templateArtifactName) with resource assignment artifact($mappingArtifactName)") - - val resourceAssignmentContent = bluePrintRuntimeService.resolveNodeTemplateArtifact(nodeTemplateName, mappingArtifactName) + val artifactMapping = "$artifactPrefix-mapping" + + return resolveResources(bluePrintRuntimeService, nodeTemplateName, artifactMapping, artifactTemplate) + } + + + override fun resolveResources(bluePrintRuntimeService: BluePrintRuntimeService<*>, nodeTemplateName: String, + artifactMapping: String, artifactTemplate: String?): String { + + 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) val resourceAssignments: MutableList = JacksonUtils.getListFromJson(resourceAssignmentContent, ResourceAssignment::class.java) as? MutableList @@ -92,14 +109,13 @@ class ResourceResolutionService { ?: throw BluePrintProcessorException("couldn't get Dictionary Definitions") // Resolve resources - executeProcessors(bluePrintRuntimeService, resourceDictionaries, resourceAssignments, templateArtifactName) - - // Check Template is there - val templateContent = bluePrintRuntimeService.resolveNodeTemplateArtifact(nodeTemplateName, templateArtifactName) + resolveResourceAssignments(bluePrintRuntimeService, resourceDictionaries, resourceAssignments, identifierName) val resolvedParamJsonContent = ResourceAssignmentUtils.generateResourceDataForAssignments(resourceAssignments.toList()) - if (templateContent.isNotEmpty()) { + // Check Template is there + if (artifactTemplate != null) { + val templateContent = bluePrintRuntimeService.resolveNodeTemplateArtifact(nodeTemplateName, artifactTemplate) resolvedContent = BluePrintTemplateService.generateContent(templateContent, resolvedParamJsonContent) } else { resolvedContent = resolvedParamJsonContent @@ -107,13 +123,13 @@ class ResourceResolutionService { return resolvedContent } - private fun executeProcessors(blueprintRuntimeService: BluePrintRuntimeService<*>, - resourceDictionaries: MutableMap, - resourceAssignments: MutableList, - templateArtifactName: String) { + override fun resolveResourceAssignments(blueprintRuntimeService: BluePrintRuntimeService<*>, + resourceDictionaries: MutableMap, + resourceAssignments: MutableList, + identifierName: String) { val bulkSequenced = BulkResourceSequencingUtils.process(resourceAssignments) - val resourceAssignmentRuntimeService = ResourceAssignmentUtils.transformToRARuntimeService(blueprintRuntimeService, templateArtifactName) + val resourceAssignmentRuntimeService = ResourceAssignmentUtils.transformToRARuntimeService(blueprintRuntimeService, identifierName) bulkSequenced.map { batchResourceAssignments -> batchResourceAssignments.filter { it.name != "*" && it.name != "start" } 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 index bb54fcb36..fbecb55c3 100644 --- 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 @@ -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, diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionServiceTest.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionServiceTest.kt index 2f974812e..d0d3a13fe 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionServiceTest.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionServiceTest.kt @@ -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, diff --git a/ms/blueprintsprocessor/functions/restconf-executor/pom.xml b/ms/blueprintsprocessor/functions/restconf-executor/pom.xml index dea3a8af3..cee90b6e6 100644 --- a/ms/blueprintsprocessor/functions/restconf-executor/pom.xml +++ b/ms/blueprintsprocessor/functions/restconf-executor/pom.xml @@ -32,21 +32,7 @@ org.onap.ccsdk.apps.blueprintsprocessor.functions - python-executor - - - org.onap.ccsdk.apps.controllerblueprints - blueprint-scripts - - - - - org.jetbrains.kotlin - kotlin-test-junit - - - io.mockk - mockk + resource-resolution diff --git a/ms/blueprintsprocessor/functions/restconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/restconf/executor/ComponentRestconfExecutor.kt b/ms/blueprintsprocessor/functions/restconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/restconf/executor/ComponentRestconfExecutor.kt index e91b95ff2..9bcc23b64 100644 --- a/ms/blueprintsprocessor/functions/restconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/restconf/executor/ComponentRestconfExecutor.kt +++ b/ms/blueprintsprocessor/functions/restconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/restconf/executor/ComponentRestconfExecutor.kt @@ -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) } diff --git a/ms/blueprintsprocessor/functions/restconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/restconf/executor/RestconfComponentFunction.kt b/ms/blueprintsprocessor/functions/restconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/restconf/executor/RestconfComponentFunction.kt index 7b3615fe3..d9362af83 100644 --- a/ms/blueprintsprocessor/functions/restconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/restconf/executor/RestconfComponentFunction.kt +++ b/ms/blueprintsprocessor/functions/restconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/restconf/executor/RestconfComponentFunction.kt @@ -13,9 +13,10 @@ * 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 diff --git a/ms/blueprintsprocessor/functions/restconf-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/restconf/executor/ComponentRestconfExecutorTest.kt b/ms/blueprintsprocessor/functions/restconf-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/restconf/executor/ComponentRestconfExecutorTest.kt index 77d469165..31bd4eb70 100644 --- a/ms/blueprintsprocessor/functions/restconf-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/restconf/executor/ComponentRestconfExecutorTest.kt +++ b/ms/blueprintsprocessor/functions/restconf-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/restconf/executor/ComponentRestconfExecutorTest.kt @@ -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", diff --git a/ms/blueprintsprocessor/modules/services/execution-service/pom.xml b/ms/blueprintsprocessor/modules/services/execution-service/pom.xml index 19685b524..ea5f31a36 100644 --- a/ms/blueprintsprocessor/modules/services/execution-service/pom.xml +++ b/ms/blueprintsprocessor/modules/services/execution-service/pom.xml @@ -33,6 +33,10 @@ org.onap.ccsdk.apps.controllerblueprints blueprint-core + + org.onap.ccsdk.apps.controllerblueprints + blueprint-scripts + org.onap.ccsdk.apps.blueprintsprocessor core -- cgit 1.2.3-korg