aboutsummaryrefslogtreecommitdiffstats
path: root/ms/controllerblueprints/modules/resource-dict/src/main
diff options
context:
space:
mode:
authorAlexis de Talhouët <adetalhouet89@gmail.com>2019-03-26 09:49:13 -0400
committerAlexis de Talhouët <adetalhouet89@gmail.com>2019-03-26 09:49:13 -0400
commit72d22a4339db09824d46746dacbba1e141763dc0 (patch)
tree7fbfea4b81afca0bc0c95e5d4b810f236f4dea29 /ms/controllerblueprints/modules/resource-dict/src/main
parentef6983b670796becfa66c69075c1829e8f9aef4b (diff)
Migrate ccdsk/apps to ccsdk/cds
Change-Id: I020a2ccec4e691717f888e8bd2afec91a7c4e987 Issue-ID: CCSDK-1178 Signed-off-by: Alexis de Talhouët <adetalhouet89@gmail.com>
Diffstat (limited to 'ms/controllerblueprints/modules/resource-dict/src/main')
-rw-r--r--ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDefinition.kt100
-rw-r--r--ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDictionaryConstants.kt40
-rw-r--r--ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/factory/ResourceSourceMappingFactory.kt47
-rw-r--r--ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceAssignmentValidationService.kt141
-rw-r--r--ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/BulkResourceSequencingUtils.kt109
-rw-r--r--ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtils.kt100
6 files changed, 0 insertions, 537 deletions
diff --git a/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDefinition.kt b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDefinition.kt
deleted file mode 100644
index d141ed0c..00000000
--- a/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDefinition.kt
+++ /dev/null
@@ -1,100 +0,0 @@
-/*
- * 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.controllerblueprints.resource.dict
-
-import com.fasterxml.jackson.annotation.JsonFormat
-import com.fasterxml.jackson.annotation.JsonProperty
-import org.onap.ccsdk.apps.controllerblueprints.core.data.NodeTemplate
-import org.onap.ccsdk.apps.controllerblueprints.core.data.PropertyDefinition
-import java.io.Serializable
-import java.util.*
-
-open class ResourceDefinition {
-
- @JsonProperty(value = "name", required = true)
- lateinit var name: String
-
- @JsonProperty(value = "property", required = true)
- lateinit var property: PropertyDefinition
-
- var tags: String? = null
-
- @JsonProperty(value = "updated-by")
- lateinit var updatedBy: String
-
- @JsonProperty(value = "sources", required = true)
- lateinit var sources: MutableMap<String, NodeTemplate>
-}
-
-open class ResourceAssignment {
-
- @JsonProperty(value = "name", required = true)
- lateinit var name: String
-
- @JsonProperty(value = "property")
- var property: PropertyDefinition? = null
-
- @JsonProperty("input-param")
- var inputParameter: Boolean = false
-
- @JsonProperty("dictionary-name")
- var dictionaryName: String? = null
-
- @JsonProperty("dictionary-source")
- var dictionarySource: String? = null
-
- @JsonProperty("dependencies")
- var dependencies: MutableList<String>? = null
-
- @JsonProperty("version")
- var version: Int = 0
-
- @JsonProperty("status")
- var status: String? = null
-
- @JsonProperty("message")
- var message: String? = null
-
- @JsonProperty("updated-date")
- @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")
- var updatedDate: Date? = null
-
- @JsonProperty("updated-by")
- var updatedBy: String? = null
-
- override fun toString(): String {
- return StringBuilder()
- .append("[")
- .append("name=", name)
- .append(", dictionaryName=", dictionaryName)
- .append(", dictionarySource=", dictionarySource)
- .append("]")
- .toString()
- }
-}
-
-/**
- * Interface for Source Definitions (ex Input Source,
- * Default Source, Database Source, Rest Sources, etc)
- */
-interface ResourceSource : Serializable
-
-
-open class ResourceSourceMapping {
- lateinit var resourceSourceMappings: MutableMap<String, String>
-}
diff --git a/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDictionaryConstants.kt b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDictionaryConstants.kt
deleted file mode 100644
index 75368684..00000000
--- a/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDictionaryConstants.kt
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * 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.
- * 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.controllerblueprints.resource.dict
-
-/**
- * ResourceDictionaryConstants
- *
- * @author Brinda Santh
- */
-object ResourceDictionaryConstants {
- const val SOURCE_INPUT = "input"
- const val SOURCE_DEFAULT = "default"
- //const val SOURCE_PRIMARY_CONFIG_DATA = "rest"
- const val SOURCE_PROCESSOR_DB = "processor-db"
- const val SOURCE_PRIMARY_CONFIG_DATA = "primary-config-data"
- const val SOURCE_PRIMARY_DB = "primary-db"
-
- const val MODEL_DIR_RESOURCE_DEFINITION: String = "resource_dictionary"
-
- const val PROPERTY_TYPE = "type"
- const val PROPERTY_INPUT_KEY_MAPPING = "input-key-mapping"
- const val PROPERTY_OUTPUT_KEY_MAPPING = "output-key-mapping"
- const val PROPERTY_KEY_DEPENDENCIES = "key-dependencies"
-
- const val PATH_RESOURCE_DEFINITION_TYPE = "resources_definition_types"
-} \ No newline at end of file
diff --git a/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/factory/ResourceSourceMappingFactory.kt b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/factory/ResourceSourceMappingFactory.kt
deleted file mode 100644
index 876aca9f..00000000
--- a/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/factory/ResourceSourceMappingFactory.kt
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * 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.controllerblueprints.resource.dict.factory
-
-import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException
-import org.onap.ccsdk.apps.controllerblueprints.core.format
-import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceSourceMapping
-
-/**
- * ResourceSourceMappingFactory.
- *
- * @author Brinda Santh
- */
-object ResourceSourceMappingFactory {
-
- private val resourceSourceMappings: MutableMap<String, String> = hashMapOf()
-
- fun registerSourceMapping(sourceInstance: String, nodeTypeName: String) {
- resourceSourceMappings[sourceInstance] = nodeTypeName
- }
-
- fun getRegisterSourceMapping(sourceInstance: String): String {
- return resourceSourceMappings[sourceInstance]
- ?: throw BluePrintException(format("failed to get source({}) mapping", sourceInstance))
- }
-
- fun getRegisterSourceMapping(): ResourceSourceMapping {
- val resourceSourceMapping = ResourceSourceMapping()
- resourceSourceMapping.resourceSourceMappings = resourceSourceMappings
- return resourceSourceMapping
- }
-}
-
diff --git a/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceAssignmentValidationService.kt b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceAssignmentValidationService.kt
deleted file mode 100644
index cd1dd431..00000000
--- a/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceAssignmentValidationService.kt
+++ /dev/null
@@ -1,141 +0,0 @@
-/*
- * 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.
- * 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.controllerblueprints.resource.dict.service
-
-import com.att.eelf.configuration.EELFLogger
-import com.att.eelf.configuration.EELFManager
-import org.apache.commons.collections.CollectionUtils
-import org.apache.commons.lang3.StringUtils
-import org.apache.commons.lang3.text.StrBuilder
-import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException
-import org.onap.ccsdk.apps.controllerblueprints.core.utils.TopologicalSortingUtils
-import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment
-import java.io.Serializable
-
-/**
- * ResourceAssignmentValidationService.
- *
- * @author Brinda Santh
- */
-interface ResourceAssignmentValidationService : Serializable {
-
- @Throws(BluePrintException::class)
- fun validate(resourceAssignments: List<ResourceAssignment>): Boolean
-}
-
-/**
- * ResourceAssignmentValidationServiceImpl.
- *
- * @author Brinda Santh
- */
-open class ResourceAssignmentValidationServiceImpl : ResourceAssignmentValidationService {
- private val log: EELFLogger = EELFManager.getInstance().getLogger(ResourceAssignmentValidationServiceImpl::class.java)
-
- open var resourceAssignmentMap: Map<String, ResourceAssignment> = hashMapOf()
- open val validationMessage = StrBuilder()
-
- override fun validate(resourceAssignments: List<ResourceAssignment>): Boolean {
- try {
- validateTemplateNDictionaryKeys(resourceAssignments)
- validateCyclicDependency(resourceAssignments)
- if (StringUtils.isNotBlank(validationMessage)) {
- throw BluePrintException("Resource Assignment Validation Failure")
- }
- } catch (e: Exception) {
- throw BluePrintException("Resource Assignment Validation :" + validationMessage.toString(), e)
- }
- return true
- }
-
-
- open fun validateTemplateNDictionaryKeys(resourceAssignments: List<ResourceAssignment>) {
-
- resourceAssignmentMap = resourceAssignments.map { it.name to it }.toMap()
-
- // Check the Resource Assignment has Duplicate Key Names
- val duplicateKeyNames = resourceAssignments.groupBy { it.name }
- .filter { it.value.size > 1 }
- .map { it.key }
-
- if (duplicateKeyNames.isNotEmpty()) {
- validationMessage.appendln(String.format("Duplicate Assignment Template Keys (%s) is Present", duplicateKeyNames))
- }
-
- // Collect all the dependencies as a single list
- val dependenciesNames = resourceAssignments.mapNotNull { it.dependencies }.flatten()
-
- // Check all the dependencies keys have Resource Assignment mappings.
- val notPresentDictionaries = dependenciesNames.filter { !resourceAssignmentMap.containsKey(it) }.distinct()
- if (notPresentDictionaries.isNotEmpty()) {
- validationMessage.appendln(String.format("No assignments for Dictionary Keys (%s)", notPresentDictionaries))
- }
-
- if (StringUtils.isNotBlank(validationMessage)) {
- throw BluePrintException("Resource Assignment Validation Failure")
- }
- }
-
- open fun validateCyclicDependency(resourceAssignments: List<ResourceAssignment>) {
- val startResourceAssignment = ResourceAssignment()
- startResourceAssignment.name = "*"
-
- val topologySorting = TopologicalSortingUtils<ResourceAssignment>()
-
- resourceAssignmentMap.map { it.value }.map { resourceAssignment ->
- if (CollectionUtils.isNotEmpty(resourceAssignment.dependencies)) {
- resourceAssignment.dependencies!!.map {
- log.trace("Topological Graph link from {} to {}", it, resourceAssignment.name)
- topologySorting.add(resourceAssignmentMap[it]!!, resourceAssignment)
- }
- } else {
- topologySorting.add(startResourceAssignment, resourceAssignment)
- }
- }
-
- if (!topologySorting.isDag) {
- val graph = getTopologicalGraph(topologySorting)
- validationMessage.appendln("Cyclic Dependency :$graph")
- }
- }
-
- open fun getTopologicalGraph(topologySorting: TopologicalSortingUtils<ResourceAssignment>): String {
- val s = StringBuilder()
- val neighbors = topologySorting.getNeighbors()
-
- neighbors.forEach { v, vs ->
- if (v.name == "*") {
- s.append("\n * -> [")
- for (resourceAssignment in vs) {
- s.append("(" + resourceAssignment.dictionaryName + ":" + resourceAssignment.name
- + "),")
- }
- s.append("]")
- } else {
- s.append("\n (" + v.dictionaryName + ":" + v.name + ") -> [")
- for (resourceAssignment in vs) {
- s.append("(" + resourceAssignment.dictionaryName + ":" + resourceAssignment.name
- + "),")
- }
- s.append("]")
- }
- }
- return s.toString()
- }
-
-
-} \ No newline at end of file
diff --git a/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/BulkResourceSequencingUtils.kt b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/BulkResourceSequencingUtils.kt
deleted file mode 100644
index cd92f42c..00000000
--- a/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/BulkResourceSequencingUtils.kt
+++ /dev/null
@@ -1,109 +0,0 @@
-/*
- * 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.controllerblueprints.resource.dict.utils
-
-import com.att.eelf.configuration.EELFLogger
-import org.apache.commons.collections.CollectionUtils
-import org.onap.ccsdk.apps.controllerblueprints.core.utils.TopologicalSortingUtils
-import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment
-import com.att.eelf.configuration.EELFManager
-import java.util.ArrayList
-/**
- * BulkResourceSequencingUtils.
- *
- * @author Brinda Santh
- */
-object BulkResourceSequencingUtils {
- private val log: EELFLogger = EELFManager.getInstance().getLogger(BulkResourceSequencingUtils::class.java)
-
- @JvmStatic
- fun process(resourceAssignments: MutableList<ResourceAssignment>): List<List<ResourceAssignment>> {
- val resourceAssignmentMap: MutableMap<String, ResourceAssignment> = hashMapOf()
- val sequenceBatchResourceAssignment = ArrayList<List<ResourceAssignment>>()
- log.info("Assignments ({})", resourceAssignments)
- // Prepare Map
- resourceAssignments.forEach { resourceAssignment ->
- log.trace("Processing Key ({})", resourceAssignment.name)
- resourceAssignmentMap.put(resourceAssignment.name, resourceAssignment)
- }
-
- val startResourceAssignment = ResourceAssignment()
- startResourceAssignment.name = "*"
-
- // Preepare Sorting Map
- val topologySorting = TopologicalSortingUtils<ResourceAssignment>()
- resourceAssignmentMap.forEach { _, resourceAssignment ->
- if (CollectionUtils.isNotEmpty(resourceAssignment.dependencies)) {
- for (dependency in resourceAssignment.dependencies!!) {
- topologySorting.add(resourceAssignmentMap[dependency]!!, resourceAssignment)
- }
- } else {
- topologySorting.add(startResourceAssignment, resourceAssignment)
- }
- }
-
- val sequencedResourceAssignments: MutableList<ResourceAssignment> = topologySorting.topSort()!! as MutableList<ResourceAssignment>
- log.info("Sorted Sequenced Assignments ({})", sequencedResourceAssignments)
-
- var batchResourceAssignment: MutableList<ResourceAssignment>? = null
- var batchAssignmentName: MutableList<String>? = null
-
- // Prepare Sorting
- sequencedResourceAssignments.forEachIndexed { index, resourceAssignment ->
-
- var previousResourceAssignment: ResourceAssignment? = null
-
- if (index > 0) {
- previousResourceAssignment = sequencedResourceAssignments[index - 1]
- }
-
- var dependencyPresence = false
- if (batchAssignmentName != null && resourceAssignment.dependencies != null) {
- dependencyPresence = CollectionUtils.containsAny(batchAssignmentName, resourceAssignment.dependencies)
- }
-
- log.trace("({}) -> Checking ({}), with ({}), result ({})", resourceAssignment.name,
- batchAssignmentName, resourceAssignment.dependencies, dependencyPresence)
-
- if (previousResourceAssignment != null && resourceAssignment.dictionarySource != null
- && resourceAssignment.dictionarySource!!.equals(previousResourceAssignment.dictionarySource, true)
- && !dependencyPresence) {
- batchResourceAssignment!!.add(resourceAssignment)
- batchAssignmentName!!.add(resourceAssignment.name)
- } else {
- if (batchResourceAssignment != null) {
- sequenceBatchResourceAssignment.add(batchResourceAssignment!!)
- log.trace("Created old Set ({})", batchAssignmentName)
- }
- batchResourceAssignment = arrayListOf()
- batchResourceAssignment!!.add(resourceAssignment)
-
- batchAssignmentName = arrayListOf()
- batchAssignmentName!!.add(resourceAssignment.name)
- }
-
- if (index == sequencedResourceAssignments.size - 1) {
- log.trace("Created old Set ({})", batchAssignmentName)
- sequenceBatchResourceAssignment.add(batchResourceAssignment!!)
- }
- }
- log.info("Batched Sequence : ({})", sequenceBatchResourceAssignment)
-
- return sequenceBatchResourceAssignment
- }
-
-} \ No newline at end of file
diff --git a/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtils.kt b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtils.kt
deleted file mode 100644
index 69ee1cfd..00000000
--- a/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtils.kt
+++ /dev/null
@@ -1,100 +0,0 @@
-/*
- * 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.
- * 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.controllerblueprints.resource.dict.utils
-
-import com.att.eelf.configuration.EELFLogger
-import com.att.eelf.configuration.EELFManager
-import com.fasterxml.jackson.databind.JsonNode
-import com.fasterxml.jackson.databind.node.NullNode
-import org.apache.commons.collections.MapUtils
-import org.apache.commons.lang3.StringUtils
-import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants
-import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException
-import org.onap.ccsdk.apps.controllerblueprints.core.data.NodeTemplate
-import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintFileUtils
-import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils
-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.ResourceDictionaryConstants
-import java.io.File
-
-
-object ResourceDictionaryUtils {
- private val log: EELFLogger = EELFManager.getInstance().getLogger(ResourceDictionaryUtils::class.java)
-
- @JvmStatic
- fun populateSourceMapping(resourceAssignment: ResourceAssignment,
- resourceDefinition: ResourceDefinition) {
-
- if (StringUtils.isBlank(resourceAssignment.dictionarySource)) {
-
- if (MapUtils.isNotEmpty(resourceDefinition.sources)) {
- val source = findFirstSource(resourceDefinition.sources)
-
- // Populate and Assign First Source
- if (StringUtils.isNotBlank(source)) {
- // Set Dictionary Source
- resourceAssignment.dictionarySource = source
- } else {
- resourceAssignment.dictionarySource = ResourceDictionaryConstants.SOURCE_INPUT
- }
- log.info("auto map resourceAssignment : {}", resourceAssignment)
- } else {
- resourceAssignment.dictionarySource = ResourceDictionaryConstants.SOURCE_INPUT
- }
- }
- }
-
- @JvmStatic
- fun findFirstSource(sources: Map<String, NodeTemplate>): String? {
- var source: String? = null
- if (MapUtils.isNotEmpty(sources)) {
- source = sources.keys.stream().findFirst().get()
- }
- return source
- }
-
- @JvmStatic
- fun assignInputs(data: JsonNode, context: MutableMap<String, Any>) {
- log.trace("assignInputs from input JSON ({})", data.toString())
- data.fields().forEach { field ->
- val valueNode: JsonNode = data.at("/".plus(field.key)) ?: NullNode.getInstance()
-
- val path = BluePrintConstants.PATH_INPUTS.plus(BluePrintConstants.PATH_DIVIDER).plus(field.key)
- log.trace("setting path ({}), values ({})", path, valueNode)
- context[path] = valueNode
- }
- }
-
- fun getResourceAssignmentFromFile(filePath: String): List<ResourceAssignment> {
- return JacksonUtils.getListFromFile(filePath, ResourceAssignment::class.java)
- ?: throw BluePrintProcessorException("couldn't get ResourceAssignment definitions for the file($filePath)")
- }
-
- fun writeResourceDefinitionTypes(basePath: String, resourceDefinitions: List<ResourceDefinition>) {
- val resourceDefinitionMap = resourceDefinitions.map { it.name to it }.toMap()
- writeResourceDefinitionTypes(basePath, resourceDefinitionMap)
-
- }
-
- fun writeResourceDefinitionTypes(basePath: String, resourceDefinitionMap: Map<String, ResourceDefinition>) {
- val typePath = basePath.plus(File.separator).plus(BluePrintConstants.TOSCA_DEFINITIONS_DIR)
- .plus(File.separator).plus("${ResourceDictionaryConstants.PATH_RESOURCE_DEFINITION_TYPE}.json")
- val resourceDefinitionContent = JacksonUtils.getJson(resourceDefinitionMap.toSortedMap(), true)
- BluePrintFileUtils.writeDefinitionFile(typePath, resourceDefinitionContent)
- }
-} \ No newline at end of file