aboutsummaryrefslogtreecommitdiffstats
path: root/ms/blueprintsprocessor/functions/resource-resolution/src/main
diff options
context:
space:
mode:
authorAlexis de Talhouët <adetalhouet89@gmail.com>2019-06-20 22:12:08 -0400
committerAlexis de Talhouët <adetalhouet89@gmail.com>2019-06-25 18:33:36 +0000
commit396b49a03e418ce7f68587c3e4444ed262325e0a (patch)
tree376b8b5ecf52c923ffe15cedbd943b9797f4eeb7 /ms/blueprintsprocessor/functions/resource-resolution/src/main
parent2e2d56dba10dc8ccc9673e969f95cfb70f9b44bc (diff)
Store resolution and expose with REST API
Change-Id: Ie1fe9c02542ccd5fbfa18f1e2d6ddb633f55c214 Issue-ID: CCSDK-1423 Signed-off-by: Alexis de Talhouët <adetalhouet89@gmail.com>
Diffstat (limited to 'ms/blueprintsprocessor/functions/resource-resolution/src/main')
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponent.kt9
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionConstants.kt2
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionService.kt138
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/ResourceResolution.kt91
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/ResourceResolutionDBService.kt128
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/ResourceResolutionRepository.kt22
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/ResourceResolutionResultRepository.kt25
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/ResourceResolutionResultService.kt2
8 files changed, 339 insertions, 78 deletions
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponent.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponent.kt
index 0bc83763a..7c2c11c06 100644
--- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponent.kt
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponent.kt
@@ -37,10 +37,15 @@ open class ResourceResolutionComponent(private val resourceResolutionService: Re
val occurrence = getOperationInput(ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_OCCURRENCE)
val key = getOptionalOperationInput(ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_KEY)
val storeResult = getOptionalOperationInput(ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_STORE_RESULT)
+ val resourceId = getOptionalOperationInput(ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOURCE_ID)
+ val resourceType = getOptionalOperationInput(ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOURCE_TYPE)
+
val properties: MutableMap<String, Any> = mutableMapOf()
- properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_STORE_RESULT] =
- storeResult?.asBoolean() ?: false
+ properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_STORE_RESULT] = storeResult?.asBoolean() ?: false
+ properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_KEY] = key?.asText() ?: ""
+ properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOURCE_ID] = resourceId?.asText() ?: ""
+ properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOURCE_TYPE] = resourceType?.asText() ?: ""
val artifactPrefixNamesNode = getOperationInput(ResourceResolutionConstants.INPUT_ARTIFACT_PREFIX_NAMES)
val artifactPrefixNames = JacksonUtils.getListFromJsonNode(artifactPrefixNamesNode, String::class.java)
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionConstants.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionConstants.kt
index 9d422f1c6..929e9e8df 100644
--- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionConstants.kt
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionConstants.kt
@@ -27,6 +27,8 @@ object ResourceResolutionConstants {
const val RESOURCE_RESOLUTION_INPUT_KEY = "resolution-key"
const val RESOURCE_RESOLUTION_INPUT_STORE_RESULT = "store-result"
const val RESOURCE_RESOLUTION_INPUT_OCCURRENCE = "occurrence"
+ const val RESOURCE_RESOLUTION_INPUT_RESOURCE_ID = "resource-id"
+ const val RESOURCE_RESOLUTION_INPUT_RESOURCE_TYPE = "resource-type"
} \ No newline at end of file
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionService.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionService.kt
index fe5906220..b1482934f 100644
--- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionService.kt
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionService.kt
@@ -20,6 +20,7 @@ package org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution
import kotlinx.coroutines.async
import kotlinx.coroutines.awaitAll
import kotlinx.coroutines.coroutineScope
+import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.db.ResourceResolutionDBService
import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.db.ResourceResolutionResultService
import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.processor.ResourceAssignmentProcessor
import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.utils.ResourceAssignmentUtils
@@ -48,27 +49,26 @@ interface ResourceResolutionService {
suspend fun resolveResources(bluePrintRuntimeService: BluePrintRuntimeService<*>, nodeTemplateName: String,
artifactPrefix: String, properties: Map<String, Any>): String
- suspend fun resolveResources(bluePrintRuntimeService: BluePrintRuntimeService<*>, nodeTemplateName: String,
- artifactMapping: String, artifactTemplate: String?): String
-
suspend fun resolveResourceAssignments(blueprintRuntimeService: BluePrintRuntimeService<*>,
resourceDefinitions: MutableMap<String, ResourceDefinition>,
resourceAssignments: MutableList<ResourceAssignment>,
- identifierName: String)
+ artifactPrefix: String,
+ properties: Map<String, Any>)
}
@Service(ResourceResolutionConstants.SERVICE_RESOURCE_RESOLUTION)
open class ResourceResolutionServiceImpl(private var applicationContext: ApplicationContext,
private var resolutionResultService: ResourceResolutionResultService,
- private var blueprintTemplateService: BluePrintTemplateService) :
- ResourceResolutionService {
+ private var blueprintTemplateService: BluePrintTemplateService,
+ private var resourceResolutionDBService: ResourceResolutionDBService) :
+ ResourceResolutionService {
private val log = LoggerFactory.getLogger(ResourceResolutionService::class.java)
override fun registeredResourceSources(): List<String> {
return applicationContext.getBeanNamesForType(ResourceAssignmentProcessor::class.java)
- .filter { it.startsWith(ResourceResolutionConstants.PREFIX_RESOURCE_RESOLUTION_PROCESSOR) }
- .map { it.substringAfter(ResourceResolutionConstants.PREFIX_RESOURCE_RESOLUTION_PROCESSOR) }
+ .filter { it.startsWith(ResourceResolutionConstants.PREFIX_RESOURCE_RESOLUTION_PROCESSOR) }
+ .map { it.substringAfter(ResourceResolutionConstants.PREFIX_RESOURCE_RESOLUTION_PROCESSOR) }
}
override suspend fun resolveFromDatabase(bluePrintRuntimeService: BluePrintRuntimeService<*>,
@@ -78,12 +78,13 @@ open class ResourceResolutionServiceImpl(private var applicationContext: Applica
}
override suspend fun resolveResources(bluePrintRuntimeService: BluePrintRuntimeService<*>, nodeTemplateName: String,
- artifactNames: List<String>, properties: Map<String, Any>): MutableMap<String, String> {
+ artifactNames: List<String>,
+ properties: Map<String, Any>): MutableMap<String, String> {
val resolvedParams: MutableMap<String, String> = hashMapOf()
artifactNames.forEach { artifactName ->
val resolvedContent = resolveResources(bluePrintRuntimeService, nodeTemplateName,
- artifactName, properties)
+ artifactName, properties)
resolvedParams[artifactName] = resolvedContent
}
return resolvedParams
@@ -97,52 +98,38 @@ open class ResourceResolutionServiceImpl(private var applicationContext: Applica
// Resource Assignment Artifact Definition Name
val artifactMapping = "$artifactPrefix-mapping"
- val result = resolveResources(bluePrintRuntimeService, nodeTemplateName,
- artifactMapping, artifactTemplate)
-
- if (properties.containsKey(ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_STORE_RESULT)
- && properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_STORE_RESULT] as Boolean) {
- resolutionResultService.write(properties, result, bluePrintRuntimeService, artifactPrefix)
- log.info("resolution saved into database successfully : ($properties)")
- }
-
- return result
- }
-
-
- override suspend fun resolveResources(bluePrintRuntimeService: BluePrintRuntimeService<*>, nodeTemplateName: String,
- artifactMapping: String, artifactTemplate: String?): String {
-
val resolvedContent: String
log.info("Resolving resource for template artifact($artifactTemplate) with resource assignment artifact($artifactMapping)")
- val identifierName = artifactTemplate ?: "no-template"
-
val resourceAssignmentContent =
- bluePrintRuntimeService.resolveNodeTemplateArtifact(nodeTemplateName, artifactMapping)
+ bluePrintRuntimeService.resolveNodeTemplateArtifact(nodeTemplateName, artifactMapping)
val resourceAssignments: MutableList<ResourceAssignment> =
- JacksonUtils.getListFromJson(resourceAssignmentContent, ResourceAssignment::class.java)
- as? MutableList<ResourceAssignment>
- ?: throw BluePrintProcessorException("couldn't get Dictionary Definitions")
+ JacksonUtils.getListFromJson(resourceAssignmentContent, ResourceAssignment::class.java)
+ as? MutableList<ResourceAssignment>
+ ?: throw BluePrintProcessorException("couldn't get Dictionary Definitions")
// Get the Resource Dictionary Name
val resourceDefinitions: MutableMap<String, ResourceDefinition> = ResourceAssignmentUtils
- .resourceDefinitions(bluePrintRuntimeService.bluePrintContext().rootPath)
+ .resourceDefinitions(bluePrintRuntimeService.bluePrintContext().rootPath)
// Resolve resources
- resolveResourceAssignments(bluePrintRuntimeService, resourceDefinitions, resourceAssignments, identifierName)
+ resolveResourceAssignments(bluePrintRuntimeService,
+ resourceDefinitions,
+ resourceAssignments,
+ artifactPrefix,
+ properties)
val resolvedParamJsonContent =
- ResourceAssignmentUtils.generateResourceDataForAssignments(resourceAssignments.toList())
+ ResourceAssignmentUtils.generateResourceDataForAssignments(resourceAssignments.toList())
- // Check Template is there
- if (artifactTemplate != null) {
- resolvedContent = blueprintTemplateService.generateContent(bluePrintRuntimeService, nodeTemplateName,
- artifactTemplate, resolvedParamJsonContent)
+ resolvedContent = blueprintTemplateService.generateContent(bluePrintRuntimeService, nodeTemplateName,
+ artifactTemplate, resolvedParamJsonContent)
- } else {
- resolvedContent = resolvedParamJsonContent
+ if (properties.containsKey(ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_STORE_RESULT)
+ && properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_STORE_RESULT] as Boolean) {
+ resolutionResultService.write(properties, resolvedContent, bluePrintRuntimeService, artifactPrefix)
+ log.info("template resolution saved into database successfully : ($properties)")
}
return resolvedContent
@@ -156,44 +143,55 @@ open class ResourceResolutionServiceImpl(private var applicationContext: Applica
override suspend fun resolveResourceAssignments(blueprintRuntimeService: BluePrintRuntimeService<*>,
resourceDefinitions: MutableMap<String, ResourceDefinition>,
resourceAssignments: MutableList<ResourceAssignment>,
- identifierName: String) {
+ artifactPrefix: String,
+ properties: Map<String, Any>) {
val bulkSequenced = BulkResourceSequencingUtils.process(resourceAssignments)
val resourceAssignmentRuntimeService =
- ResourceAssignmentUtils.transformToRARuntimeService(blueprintRuntimeService, identifierName)
+ ResourceAssignmentUtils.transformToRARuntimeService(blueprintRuntimeService, artifactPrefix)
coroutineScope {
bulkSequenced.forEach { batchResourceAssignments ->
// Execute Non Dependent Assignments in parallel ( ie asynchronously )
val deferred = batchResourceAssignments.filter { it.name != "*" && it.name != "start" }
- .map { resourceAssignment ->
- async {
- val dictionaryName = resourceAssignment.dictionaryName
- val dictionarySource = resourceAssignment.dictionarySource
- /**
- * Get the Processor name
- */
- val processorName = processorName(dictionaryName!!, dictionarySource!!, resourceDefinitions)
-
- val resourceAssignmentProcessor =
- applicationContext.getBean(processorName) as? ResourceAssignmentProcessor
- ?: throw BluePrintProcessorException("failed to get resource processor ($processorName) " +
- "for resource assignment(${resourceAssignment.name})")
- try {
- // Set BluePrint Runtime Service
- resourceAssignmentProcessor.raRuntimeService = resourceAssignmentRuntimeService
- // Set Resource Dictionaries
- resourceAssignmentProcessor.resourceDictionaries = resourceDefinitions
- // Invoke Apply Method
- resourceAssignmentProcessor.applyNB(resourceAssignment)
- // Set errors from RA
- blueprintRuntimeService.setBluePrintError(resourceAssignmentRuntimeService.getBluePrintError())
- } catch (e: RuntimeException) {
- log.error("Fail in processing ${resourceAssignment.name}", e)
- throw BluePrintProcessorException(e)
+ .map { resourceAssignment ->
+ async {
+ val dictionaryName = resourceAssignment.dictionaryName
+ val dictionarySource = resourceAssignment.dictionarySource
+ /**
+ * Get the Processor name
+ */
+ val processorName = processorName(dictionaryName!!, dictionarySource!!, resourceDefinitions)
+
+ val resourceAssignmentProcessor =
+ applicationContext.getBean(processorName) as? ResourceAssignmentProcessor
+ ?: throw BluePrintProcessorException("failed to get resource processor ($processorName) " +
+ "for resource assignment(${resourceAssignment.name})")
+ try {
+ // Set BluePrint Runtime Service
+ resourceAssignmentProcessor.raRuntimeService = resourceAssignmentRuntimeService
+ // Set Resource Dictionaries
+ resourceAssignmentProcessor.resourceDictionaries = resourceDefinitions
+ // Invoke Apply Method
+ resourceAssignmentProcessor.applyNB(resourceAssignment)
+
+ if (properties.containsKey(ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_STORE_RESULT)
+ && properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_STORE_RESULT] as Boolean) {
+ resourceResolutionDBService.write(properties,
+ blueprintRuntimeService,
+ artifactPrefix,
+ resourceAssignment)
+ log.info("resolution saved into database successfully : ($resourceAssignment)")
}
+
+ // Set errors from RA
+ blueprintRuntimeService.setBluePrintError(resourceAssignmentRuntimeService.getBluePrintError())
+ } catch (e: RuntimeException) {
+ log.error("Fail in processing ${resourceAssignment.name}", e)
+ throw BluePrintProcessorException(e)
}
}
+ }
log.debug("Resolving (${deferred.size})resources parallel.")
deferred.awaitAll()
}
@@ -217,10 +215,10 @@ open class ResourceResolutionServiceImpl(private var applicationContext: Applica
}
else -> {
val resourceDefinition = resourceDefinitions[dictionaryName]
- ?: throw BluePrintProcessorException("couldn't get resource dictionary definition for $dictionaryName")
+ ?: throw BluePrintProcessorException("couldn't get resource dictionary definition for $dictionaryName")
val resourceSource = resourceDefinition.sources[dictionarySource]
- ?: throw BluePrintProcessorException("couldn't get resource definition $dictionaryName source($dictionarySource)")
+ ?: throw BluePrintProcessorException("couldn't get resource definition $dictionaryName source($dictionarySource)")
ResourceResolutionConstants.PREFIX_RESOURCE_RESOLUTION_PROCESSOR.plus(resourceSource.type)
}
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/ResourceResolution.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/ResourceResolution.kt
new file mode 100644
index 000000000..767a1feaf
--- /dev/null
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/ResourceResolution.kt
@@ -0,0 +1,91 @@
+/*
+ * Copyright © 2019 Bell Canada
+ *
+ * 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.cds.blueprintsprocessor.functions.resource.resolution.db
+
+import com.fasterxml.jackson.annotation.JsonFormat
+import com.fasterxml.jackson.annotation.JsonProperty
+import org.hibernate.annotations.Proxy
+import org.springframework.data.annotation.LastModifiedDate
+import org.springframework.data.jpa.domain.support.AuditingEntityListener
+import java.io.Serializable
+import java.util.*
+import javax.persistence.Column
+import javax.persistence.Entity
+import javax.persistence.EntityListeners
+import javax.persistence.Id
+import javax.persistence.Lob
+import javax.persistence.Table
+import javax.persistence.Temporal
+import javax.persistence.TemporalType
+
+@EntityListeners(AuditingEntityListener::class)
+@Entity
+@Table(name = "RESOURCE_RESOLUTION")
+@Proxy(lazy = false)
+class ResourceResolution : Serializable {
+
+ @Id
+ @Column(name = "resource_resolution_id")
+ var id: String? = null
+
+ @Column(name = "resolution_key", nullable = false)
+ var resolutionKey: String? = null
+
+ @Column(name = "resource_type", nullable = false)
+ var resourceType: String? = null
+
+ @Column(name = "resource_id", nullable = false)
+ var resourceId: String? = null
+
+ @Column(name = "blueprint_name", nullable = false)
+ var blueprintName: String? = null
+
+ @Column(name = "blueprint_version", nullable = false)
+ var blueprintVersion: String? = null
+
+ @Column(name = "artifact_name", nullable = false)
+ var artifactName: String? = null
+
+ @Column(name = "status", nullable = false)
+ var status: String? = null
+
+ @Column(name = "name", nullable = false)
+ var name: String? = null
+
+ @Column(name = "dictionary_vname", nullable = false)
+ var dictionaryName: String? = null
+
+ @Column(name = "dictionary_status", nullable = false)
+ var dictionarySource: String? = null
+
+ @Column(name = "dictionary_version", nullable = false)
+ var dictionaryVersion: Int = 0
+
+ @Lob
+ @Column(name = "value", nullable = false)
+ var value: String? = null
+
+ @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")
+ @LastModifiedDate
+ @Temporal(TemporalType.TIMESTAMP)
+ @Column(name = "creation_date")
+ var createdDate = Date()
+
+ companion object {
+ private const val serialVersionUID = 1L
+ }
+} \ No newline at end of file
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/ResourceResolutionDBService.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/ResourceResolutionDBService.kt
new file mode 100644
index 000000000..81239be30
--- /dev/null
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/ResourceResolutionDBService.kt
@@ -0,0 +1,128 @@
+/*
+ * Copyright (C) 2019 Bell Canada.
+ *
+ * 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.cds.blueprintsprocessor.functions.resource.resolution.db
+
+import kotlinx.coroutines.Dispatchers
+import kotlinx.coroutines.withContext
+import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.ResourceResolutionConstants
+import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants
+import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException
+import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintRuntimeService
+import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
+import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceAssignment
+import org.slf4j.LoggerFactory
+import org.springframework.dao.DataIntegrityViolationException
+import org.springframework.stereotype.Service
+import java.util.*
+
+@Service
+class ResourceResolutionDBService(private val resourceResolutionRepository: ResourceResolutionRepository) {
+
+ private val log = LoggerFactory.getLogger(ResourceResolutionDBService::class.toString())
+
+ suspend fun readValue(blueprintName: String,
+ blueprintVersion: String,
+ artifactPrefix: String,
+ resolutionKey: String,
+ name: String): ResourceResolution = withContext(Dispatchers.IO) {
+
+ resourceResolutionRepository.findByResolutionKeyAndBlueprintNameAndBlueprintVersionAndArtifactNameAndName(
+ resolutionKey,
+ blueprintName,
+ blueprintVersion,
+ artifactPrefix,
+ name)
+ }
+
+ suspend fun readWithResolutionKey(blueprintName: String,
+ blueprintVersion: String,
+ artifactPrefix: String,
+ resolutionKey: String): List<ResourceResolution> = withContext(Dispatchers.IO) {
+
+ resourceResolutionRepository.findByResolutionKeyAndBlueprintNameAndBlueprintVersionAndArtifactName(
+ resolutionKey,
+ blueprintName,
+ blueprintVersion,
+ artifactPrefix)
+ }
+
+ suspend fun readWithResourceIdAndResourceType(blueprintName: String,
+ blueprintVersion: String,
+ resourceId: String,
+ resourceType: String): List<ResourceResolution> = withContext(Dispatchers.IO) {
+
+ resourceResolutionRepository.findByBlueprintNameAndBlueprintVersionAndResourceIdAndResourceType(
+ blueprintName,
+ blueprintVersion,
+ resourceId,
+ resourceType)
+ }
+
+ suspend fun write(properties: Map<String, Any>,
+ bluePrintRuntimeService: BluePrintRuntimeService<*>,
+ artifactPrefix: String,
+ resourceAssignment: ResourceAssignment): ResourceResolution = withContext(Dispatchers.IO) {
+
+ val metadata = bluePrintRuntimeService.bluePrintContext().metadata!!
+
+ val blueprintVersion = metadata[BluePrintConstants.METADATA_TEMPLATE_VERSION]!!
+ val blueprintName = metadata[BluePrintConstants.METADATA_TEMPLATE_NAME]!!
+ val resolutionKey =
+ properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_KEY].toString()
+ val resourceType =
+ properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOURCE_TYPE].toString()
+ val resourceId =
+ properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOURCE_ID].toString()
+
+ write(blueprintName,
+ blueprintVersion,
+ resolutionKey,
+ resourceId,
+ resourceType,
+ artifactPrefix,
+ resourceAssignment)
+ }
+
+ suspend fun write(blueprintName: String,
+ blueprintVersion: String,
+ resolutionKey: String,
+ resourceId: String,
+ resourceType: String,
+ artifactPrefix: String,
+ resourceAssignment: ResourceAssignment): ResourceResolution = withContext(Dispatchers.IO) {
+
+ val resourceResolution = ResourceResolution()
+ resourceResolution.id = UUID.randomUUID().toString()
+ resourceResolution.artifactName = artifactPrefix
+ resourceResolution.blueprintVersion = blueprintVersion
+ resourceResolution.blueprintName = blueprintName
+ resourceResolution.resolutionKey = resolutionKey
+ resourceResolution.resourceType = resourceType
+ resourceResolution.resourceId = resourceId
+ resourceResolution.value = JacksonUtils.getValue(resourceAssignment.property?.value!!).toString()
+ resourceResolution.name = resourceAssignment.name
+ resourceResolution.dictionaryName = resourceAssignment.dictionaryName
+ resourceResolution.dictionaryVersion = resourceAssignment.version
+ resourceResolution.dictionarySource = resourceAssignment.dictionarySource
+ resourceResolution.status = resourceAssignment.status
+
+ try {
+ resourceResolutionRepository.saveAndFlush(resourceResolution)
+ } catch (ex: Exception) {
+ throw BluePrintException("Failed to store resource resolution result.", ex)
+ }
+ }
+} \ No newline at end of file
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/ResourceResolutionRepository.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/ResourceResolutionRepository.kt
index 72bb4a384..d2cbf8411 100644
--- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/ResourceResolutionRepository.kt
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/ResourceResolutionRepository.kt
@@ -17,9 +17,21 @@ package org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.db
import org.springframework.data.jpa.repository.JpaRepository
-interface ResourceResolutionRepository : JpaRepository<ResourceResolutionResult, String> {
+interface ResourceResolutionRepository : JpaRepository<ResourceResolution, String> {
- fun findByResolutionKeyAndBlueprintNameAndBlueprintVersionAndArtifactName(key: String, blueprintName: String?,
- blueprintVersion: String?,
- artifactName: String): ResourceResolutionResult
-}
+ fun findByResolutionKeyAndBlueprintNameAndBlueprintVersionAndArtifactNameAndName(key: String,
+ blueprintName: String?,
+ blueprintVersion: String?,
+ artifactName: String,
+ name: String): ResourceResolution
+
+ fun findByResolutionKeyAndBlueprintNameAndBlueprintVersionAndArtifactName(resolutionKey: String,
+ blueprintName: String,
+ blueprintVersion: String,
+ artifactPrefix: String): List<ResourceResolution>
+
+ fun findByBlueprintNameAndBlueprintVersionAndResourceIdAndResourceType(blueprintName: String,
+ blueprintVersion: String,
+ resourceId: String,
+ resourceType: String): List<ResourceResolution>
+} \ No newline at end of file
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/ResourceResolutionResultRepository.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/ResourceResolutionResultRepository.kt
new file mode 100644
index 000000000..efc130a84
--- /dev/null
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/ResourceResolutionResultRepository.kt
@@ -0,0 +1,25 @@
+/*
+ * Copyright (C) 2019 Bell Canada.
+ *
+ * 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.cds.blueprintsprocessor.functions.resource.resolution.db
+
+import org.springframework.data.jpa.repository.JpaRepository
+
+interface ResourceResolutionResultRepository : JpaRepository<ResourceResolutionResult, String> {
+
+ fun findByResolutionKeyAndBlueprintNameAndBlueprintVersionAndArtifactName(key: String, blueprintName: String?,
+ blueprintVersion: String?,
+ artifactName: String): ResourceResolutionResult
+}
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/ResourceResolutionResultService.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/ResourceResolutionResultService.kt
index 3cb9dec63..ebb34ba4a 100644
--- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/ResourceResolutionResultService.kt
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/ResourceResolutionResultService.kt
@@ -27,7 +27,7 @@ import org.springframework.stereotype.Service
import java.util.*
@Service
-class ResourceResolutionResultService(private val resourceResolutionRepository: ResourceResolutionRepository) {
+class ResourceResolutionResultService(private val resourceResolutionRepository: ResourceResolutionResultRepository) {
suspend fun read(bluePrintRuntimeService: BluePrintRuntimeService<*>, artifactPrefix: String,
resolutionKey: String): String = withContext(Dispatchers.IO) {