\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
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
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
?: 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
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
* 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
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