From c90edac236dffb7c495e266dd04991de7e8f04b7 Mon Sep 17 00:00:00 2001 From: Alexis de Talhouët Date: Mon, 25 Mar 2019 13:04:18 -0400 Subject: Migrate ccsdk/apps to ccsdk/cds MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Issue-ID: CCSDK-1177 Issue-ID: CCSDK-1178 Change-Id: I0c02702fbec52211ca367abbba72aebecee8cbaa Signed-off-by: Alexis de Talhouët --- .../modules/resource-dict/pom.xml | 4 +- .../resource/dict/ResourceDefinition.kt | 100 --------------- .../resource/dict/ResourceDictionaryConstants.kt | 40 ------ .../dict/factory/ResourceSourceMappingFactory.kt | 47 ------- .../service/ResourceAssignmentValidationService.kt | 141 --------------------- .../dict/utils/BulkResourceSequencingUtils.kt | 109 ---------------- .../resource/dict/utils/ResourceDictionaryUtils.kt | 100 --------------- .../resource/dict/ResourceDefinition.kt | 100 +++++++++++++++ .../resource/dict/ResourceDictionaryConstants.kt | 40 ++++++ .../dict/factory/ResourceSourceMappingFactory.kt | 47 +++++++ .../service/ResourceAssignmentValidationService.kt | 141 +++++++++++++++++++++ .../dict/utils/BulkResourceSequencingUtils.kt | 109 ++++++++++++++++ .../resource/dict/utils/ResourceDictionaryUtils.kt | 100 +++++++++++++++ .../resource/dict/ResourceDefinitionTest.java | 60 --------- .../factory/ResourceSourceMappingFactoryTest.java | 42 ------ .../ResourceAssignmentValidationServiceTest.kt | 66 ---------- .../utils/BulkResourceSequencingUtilsTest.java | 37 ------ .../dict/utils/ResourceDictionaryUtilsTest.java | 99 --------------- .../resource/dict/ResourceDefinitionTest.java | 60 +++++++++ .../factory/ResourceSourceMappingFactoryTest.java | 42 ++++++ .../ResourceAssignmentValidationServiceTest.kt | 66 ++++++++++ .../utils/BulkResourceSequencingUtilsTest.java | 37 ++++++ .../dict/utils/ResourceDictionaryUtilsTest.java | 99 +++++++++++++++ .../dict/utils/ResourceDictionaryTestUtils.kt | 30 ----- .../dict/utils/ResourceDictionaryTestUtils.kt | 30 +++++ 25 files changed, 873 insertions(+), 873 deletions(-) delete mode 100644 ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDefinition.kt delete mode 100644 ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDictionaryConstants.kt delete mode 100644 ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/factory/ResourceSourceMappingFactory.kt delete mode 100644 ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceAssignmentValidationService.kt delete mode 100644 ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/BulkResourceSequencingUtils.kt delete mode 100644 ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtils.kt create mode 100644 ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/resource/dict/ResourceDefinition.kt create mode 100644 ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/resource/dict/ResourceDictionaryConstants.kt create mode 100644 ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/resource/dict/factory/ResourceSourceMappingFactory.kt create mode 100644 ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/resource/dict/service/ResourceAssignmentValidationService.kt create mode 100644 ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/resource/dict/utils/BulkResourceSequencingUtils.kt create mode 100644 ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/resource/dict/utils/ResourceDictionaryUtils.kt delete mode 100644 ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDefinitionTest.java delete mode 100644 ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/factory/ResourceSourceMappingFactoryTest.java delete mode 100644 ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceAssignmentValidationServiceTest.kt delete mode 100644 ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/BulkResourceSequencingUtilsTest.java delete mode 100644 ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtilsTest.java create mode 100644 ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/cds/controllerblueprints/resource/dict/ResourceDefinitionTest.java create mode 100644 ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/cds/controllerblueprints/resource/dict/factory/ResourceSourceMappingFactoryTest.java create mode 100644 ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/cds/controllerblueprints/resource/dict/service/ResourceAssignmentValidationServiceTest.kt create mode 100644 ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/cds/controllerblueprints/resource/dict/utils/BulkResourceSequencingUtilsTest.java create mode 100644 ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/cds/controllerblueprints/resource/dict/utils/ResourceDictionaryUtilsTest.java delete mode 100644 ms/controllerblueprints/modules/resource-dict/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryTestUtils.kt create mode 100644 ms/controllerblueprints/modules/resource-dict/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/resource/dict/utils/ResourceDictionaryTestUtils.kt (limited to 'ms/controllerblueprints/modules/resource-dict') diff --git a/ms/controllerblueprints/modules/resource-dict/pom.xml b/ms/controllerblueprints/modules/resource-dict/pom.xml index 22533dbed..3f4f762b0 100644 --- a/ms/controllerblueprints/modules/resource-dict/pom.xml +++ b/ms/controllerblueprints/modules/resource-dict/pom.xml @@ -19,7 +19,7 @@ 4.0.0 - org.onap.ccsdk.apps.controllerblueprints + org.onap.ccsdk.cds.controllerblueprints modules 0.4.2-SNAPSHOT @@ -28,7 +28,7 @@ - org.onap.ccsdk.apps.controllerblueprints + org.onap.ccsdk.cds.controllerblueprints blueprint-core 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 d141ed0cb..000000000 --- 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 -} - -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? = 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 -} 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 75368684c..000000000 --- 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 876aca9f7..000000000 --- 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 = 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 cd1dd431d..000000000 --- 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): Boolean -} - -/** - * ResourceAssignmentValidationServiceImpl. - * - * @author Brinda Santh - */ -open class ResourceAssignmentValidationServiceImpl : ResourceAssignmentValidationService { - private val log: EELFLogger = EELFManager.getInstance().getLogger(ResourceAssignmentValidationServiceImpl::class.java) - - open var resourceAssignmentMap: Map = hashMapOf() - open val validationMessage = StrBuilder() - - override fun validate(resourceAssignments: List): 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) { - - 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) { - val startResourceAssignment = ResourceAssignment() - startResourceAssignment.name = "*" - - val topologySorting = TopologicalSortingUtils() - - 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): 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 cd92f42c0..000000000 --- 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): List> { - val resourceAssignmentMap: MutableMap = hashMapOf() - val sequenceBatchResourceAssignment = ArrayList>() - 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() - 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 = topologySorting.topSort()!! as MutableList - log.info("Sorted Sequenced Assignments ({})", sequencedResourceAssignments) - - var batchResourceAssignment: MutableList? = null - var batchAssignmentName: MutableList? = 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 69ee1cfd4..000000000 --- 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? { - var source: String? = null - if (MapUtils.isNotEmpty(sources)) { - source = sources.keys.stream().findFirst().get() - } - return source - } - - @JvmStatic - fun assignInputs(data: JsonNode, context: MutableMap) { - 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 { - return JacksonUtils.getListFromFile(filePath, ResourceAssignment::class.java) - ?: throw BluePrintProcessorException("couldn't get ResourceAssignment definitions for the file($filePath)") - } - - fun writeResourceDefinitionTypes(basePath: String, resourceDefinitions: List) { - val resourceDefinitionMap = resourceDefinitions.map { it.name to it }.toMap() - writeResourceDefinitionTypes(basePath, resourceDefinitionMap) - - } - - fun writeResourceDefinitionTypes(basePath: String, resourceDefinitionMap: Map) { - 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 diff --git a/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/resource/dict/ResourceDefinition.kt b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/resource/dict/ResourceDefinition.kt new file mode 100644 index 000000000..80ce72e14 --- /dev/null +++ b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/resource/dict/ResourceDefinition.kt @@ -0,0 +1,100 @@ +/* + * 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.cds.controllerblueprints.resource.dict + +import com.fasterxml.jackson.annotation.JsonFormat +import com.fasterxml.jackson.annotation.JsonProperty +import org.onap.ccsdk.cds.controllerblueprints.core.data.NodeTemplate +import org.onap.ccsdk.cds.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 +} + +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? = 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 +} diff --git a/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/resource/dict/ResourceDictionaryConstants.kt b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/resource/dict/ResourceDictionaryConstants.kt new file mode 100644 index 000000000..2921c2c3e --- /dev/null +++ b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/resource/dict/ResourceDictionaryConstants.kt @@ -0,0 +1,40 @@ +/* + * 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.cds.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/cds/controllerblueprints/resource/dict/factory/ResourceSourceMappingFactory.kt b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/resource/dict/factory/ResourceSourceMappingFactory.kt new file mode 100644 index 000000000..6f2b9bae7 --- /dev/null +++ b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/resource/dict/factory/ResourceSourceMappingFactory.kt @@ -0,0 +1,47 @@ +/* + * 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.cds.controllerblueprints.resource.dict.factory + +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException +import org.onap.ccsdk.cds.controllerblueprints.core.format +import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceSourceMapping + +/** + * ResourceSourceMappingFactory. + * + * @author Brinda Santh + */ +object ResourceSourceMappingFactory { + + private val resourceSourceMappings: MutableMap = 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/cds/controllerblueprints/resource/dict/service/ResourceAssignmentValidationService.kt b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/resource/dict/service/ResourceAssignmentValidationService.kt new file mode 100644 index 000000000..a7e87b6ea --- /dev/null +++ b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/resource/dict/service/ResourceAssignmentValidationService.kt @@ -0,0 +1,141 @@ +/* + * 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.cds.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.cds.controllerblueprints.core.BluePrintException +import org.onap.ccsdk.cds.controllerblueprints.core.utils.TopologicalSortingUtils +import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceAssignment +import java.io.Serializable + +/** + * ResourceAssignmentValidationService. + * + * @author Brinda Santh + */ +interface ResourceAssignmentValidationService : Serializable { + + @Throws(BluePrintException::class) + fun validate(resourceAssignments: List): Boolean +} + +/** + * ResourceAssignmentValidationServiceImpl. + * + * @author Brinda Santh + */ +open class ResourceAssignmentValidationServiceImpl : ResourceAssignmentValidationService { + private val log: EELFLogger = EELFManager.getInstance().getLogger(ResourceAssignmentValidationServiceImpl::class.java) + + open var resourceAssignmentMap: Map = hashMapOf() + open val validationMessage = StrBuilder() + + override fun validate(resourceAssignments: List): 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) { + + 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) { + val startResourceAssignment = ResourceAssignment() + startResourceAssignment.name = "*" + + val topologySorting = TopologicalSortingUtils() + + 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): 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/cds/controllerblueprints/resource/dict/utils/BulkResourceSequencingUtils.kt b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/resource/dict/utils/BulkResourceSequencingUtils.kt new file mode 100644 index 000000000..42bde8517 --- /dev/null +++ b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/resource/dict/utils/BulkResourceSequencingUtils.kt @@ -0,0 +1,109 @@ +/* + * 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.cds.controllerblueprints.resource.dict.utils + +import com.att.eelf.configuration.EELFLogger +import org.apache.commons.collections.CollectionUtils +import org.onap.ccsdk.cds.controllerblueprints.core.utils.TopologicalSortingUtils +import org.onap.ccsdk.cds.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): List> { + val resourceAssignmentMap: MutableMap = hashMapOf() + val sequenceBatchResourceAssignment = ArrayList>() + 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() + 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 = topologySorting.topSort()!! as MutableList + log.info("Sorted Sequenced Assignments ({})", sequencedResourceAssignments) + + var batchResourceAssignment: MutableList? = null + var batchAssignmentName: MutableList? = 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/cds/controllerblueprints/resource/dict/utils/ResourceDictionaryUtils.kt b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/resource/dict/utils/ResourceDictionaryUtils.kt new file mode 100644 index 000000000..f6159188c --- /dev/null +++ b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/resource/dict/utils/ResourceDictionaryUtils.kt @@ -0,0 +1,100 @@ +/* + * 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.cds.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.cds.controllerblueprints.core.BluePrintConstants +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException +import org.onap.ccsdk.cds.controllerblueprints.core.data.NodeTemplate +import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintFileUtils +import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils +import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceAssignment +import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceDefinition +import org.onap.ccsdk.cds.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? { + var source: String? = null + if (MapUtils.isNotEmpty(sources)) { + source = sources.keys.stream().findFirst().get() + } + return source + } + + @JvmStatic + fun assignInputs(data: JsonNode, context: MutableMap) { + 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 { + return JacksonUtils.getListFromFile(filePath, ResourceAssignment::class.java) + ?: throw BluePrintProcessorException("couldn't get ResourceAssignment definitions for the file($filePath)") + } + + fun writeResourceDefinitionTypes(basePath: String, resourceDefinitions: List) { + val resourceDefinitionMap = resourceDefinitions.map { it.name to it }.toMap() + writeResourceDefinitionTypes(basePath, resourceDefinitionMap) + + } + + fun writeResourceDefinitionTypes(basePath: String, resourceDefinitionMap: Map) { + 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 diff --git a/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDefinitionTest.java b/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDefinitionTest.java deleted file mode 100644 index d059d1ba5..000000000 --- a/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDefinitionTest.java +++ /dev/null @@ -1,60 +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; - -import org.junit.Assert; -import org.junit.Test; -import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; - -public class ResourceDefinitionTest { - private EELFLogger log = EELFManager.getInstance().getLogger(ResourceDefinitionTest.class); - private String basePath = "load/resource_dictionary"; - - @Test - public void testDictionaryDefinitionInputSource(){ - - String fileName = basePath + "/input-source.json"; - ResourceDefinition resourceDefinition = JacksonUtils.Companion.readValueFromFile(fileName, ResourceDefinition.class); - Assert.assertNotNull("Failed to populate dictionaryDefinition for input type", resourceDefinition); - } - - @Test - public void testDictionaryDefinitionDefaultSource(){ - - String fileName = basePath + "/default-source.json"; - ResourceDefinition resourceDefinition = JacksonUtils.Companion.readValueFromFile(fileName, ResourceDefinition.class); - Assert.assertNotNull("Failed to populate dictionaryDefinition for default type", resourceDefinition); - } - - @Test - public void testDictionaryDefinitionDBSource(){ - - String fileName = basePath + "/primary-db-source.json"; - ResourceDefinition resourceDefinition = JacksonUtils.Companion.readValueFromFile(fileName, ResourceDefinition.class); - Assert.assertNotNull("Failed to populate dictionaryDefinition for primary-db type", resourceDefinition); - } - - @Test - public void testDictionaryDefinitionMDSALSource(){ - String fileName = basePath + "/mdsal-source.json"; - ResourceDefinition resourceDefinition = JacksonUtils.Companion.readValueFromFile(fileName, ResourceDefinition.class); - Assert.assertNotNull("Failed to populate dictionaryDefinition for mdsal type", resourceDefinition); - } -} diff --git a/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/factory/ResourceSourceMappingFactoryTest.java b/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/factory/ResourceSourceMappingFactoryTest.java deleted file mode 100644 index 3950ae367..000000000 --- a/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/factory/ResourceSourceMappingFactoryTest.java +++ /dev/null @@ -1,42 +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.junit.Test; -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceSourceMapping; -import org.springframework.util.Assert; - -public class ResourceSourceMappingFactoryTest { - - @Test - public void testRegisterResourceMapping() { - - ResourceSourceMappingFactory.INSTANCE.registerSourceMapping("primary-db", "source-primary-db"); - ResourceSourceMappingFactory.INSTANCE.registerSourceMapping("input", "source-input"); - ResourceSourceMappingFactory.INSTANCE.registerSourceMapping("default", "source-default"); - ResourceSourceMappingFactory.INSTANCE.registerSourceMapping("primary-config-data", "source-rest"); - - String nodeTypeName = ResourceSourceMappingFactory.INSTANCE.getRegisterSourceMapping("primary-db"); - Assert.notNull(nodeTypeName, "Failed to get primary-db mapping"); - - ResourceSourceMapping resourceSourceMapping = ResourceSourceMappingFactory.INSTANCE.getRegisterSourceMapping(); - Assert.notNull(resourceSourceMapping, "Failed to get resource source mapping"); - Assert.notNull(resourceSourceMapping.getResourceSourceMappings(), "Failed to get resource source mappings"); - - } - -} diff --git a/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceAssignmentValidationServiceTest.kt b/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceAssignmentValidationServiceTest.kt deleted file mode 100644 index 8905dab60..000000000 --- a/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceAssignmentValidationServiceTest.kt +++ /dev/null @@ -1,66 +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.service - -import com.att.eelf.configuration.EELFLogger -import org.junit.Assert -import org.junit.Test -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException -import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment -import com.att.eelf.configuration.EELFManager -import org.junit.Before -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.utils.ResourceDictionaryTestUtils - -/** - * ResourceAssignmentValidationServiceTest. - * - * @author Brinda Santh - */ -class ResourceAssignmentValidationServiceTest { - private val log: EELFLogger = EELFManager.getInstance().getLogger(ResourceAssignmentValidationServiceTest::class.java) - @Before - fun setUp() { - // Setup dummy Source Instance Mapping - ResourceDictionaryTestUtils.setUpResourceSourceMapping() - } - - @Test - fun testValidateSuccess() { - log.info("**************** testValidateSuccess *****************") - val assignments = JacksonUtils.getListFromClassPathFile("validation/success.json", ResourceAssignment::class.java) - val resourceAssignmentValidator = ResourceAssignmentValidationServiceImpl() - val result = resourceAssignmentValidator.validate(assignments!!) - Assert.assertTrue("Failed to Validate", result) - } - - @Test(expected = BluePrintException::class) - fun testValidateDuplicate() { - log.info(" **************** testValidateDuplicate *****************") - val assignments = JacksonUtils.getListFromClassPathFile("validation/duplicate.json", ResourceAssignment::class.java) - val resourceAssignmentValidator = ResourceAssignmentValidationServiceImpl() - resourceAssignmentValidator.validate(assignments!!) - } - - @Test(expected = BluePrintException::class) - fun testValidateCyclic() { - log.info(" **************** testValidateCyclic *****************") - val assignments = JacksonUtils.getListFromClassPathFile("validation/cyclic.json", ResourceAssignment::class.java) - val resourceAssignmentValidator = ResourceAssignmentValidationServiceImpl() - resourceAssignmentValidator.validate(assignments!!) - } -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/BulkResourceSequencingUtilsTest.java b/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/BulkResourceSequencingUtilsTest.java deleted file mode 100644 index c1b9f5007..000000000 --- a/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/BulkResourceSequencingUtilsTest.java +++ /dev/null @@ -1,37 +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 org.junit.Assert; -import org.junit.Test; -import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils; -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment; -import java.util.List; -/** - * BulkResourceSequencingUtils. - * - * @author Brinda Santh - */ -public class BulkResourceSequencingUtilsTest { - - @Test - public void testProcess(){ - List assignments = JacksonUtils.Companion.getListFromClassPathFile("validation/success.json", ResourceAssignment.class); - Assert.assertNotNull("failed to get ResourceAssignment from validation/success.json ", assignments); - BulkResourceSequencingUtils.process(assignments); - } -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtilsTest.java b/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtilsTest.java deleted file mode 100644 index 45fc739d7..000000000 --- a/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtilsTest.java +++ /dev/null @@ -1,99 +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.utils; - - -import com.fasterxml.jackson.databind.JsonNode; -import org.junit.Assert; -import org.junit.Test; -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants; -import org.onap.ccsdk.apps.controllerblueprints.core.data.NodeTemplate; -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 com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; - -import java.util.HashMap; -import java.util.Map; -/** - * ResourceDictionaryUtilsTest. - * - * @author Brinda Santh - */ -public class ResourceDictionaryUtilsTest { - private static final EELFLogger log = EELFManager.getInstance().getLogger(ResourceDictionaryUtilsTest.class); - - @Test - public void testPopulateSourceMapping() { - - ResourceAssignment resourceAssignment = new ResourceAssignment(); - resourceAssignment.setName("sample-assignment"); - ResourceDefinition resourceDefinition = new ResourceDefinition(); - Map sources = new HashMap<>(); - resourceDefinition.setSources(sources); - // To Check Empty Source - ResourceDictionaryUtils.populateSourceMapping(resourceAssignment, resourceDefinition); - Assert.assertEquals("Expected Empty source Input, but.", ResourceDictionaryConstants.SOURCE_INPUT, resourceAssignment.getDictionarySource()); - - // To Check First Source - resourceAssignment.setDictionarySource(null); - sources.put(ResourceDictionaryConstants.SOURCE_DEFAULT, new NodeTemplate()); - ResourceDictionaryUtils.populateSourceMapping(resourceAssignment, resourceDefinition); - Assert.assertEquals("Expected First source Default, but.", ResourceDictionaryConstants.SOURCE_DEFAULT, resourceAssignment.getDictionarySource()); - - // To Check Assigned Source - resourceAssignment.setDictionarySource(ResourceDictionaryConstants.SOURCE_PROCESSOR_DB); - ResourceDictionaryUtils.populateSourceMapping(resourceAssignment, resourceDefinition); - Assert.assertEquals("Expected Assigned source DB, but.", ResourceDictionaryConstants.SOURCE_PROCESSOR_DB, resourceAssignment.getDictionarySource()); - - } - - @Test - public void testFindFirstSource() { - //To check if Empty Source - Map sources = new HashMap<>(); - String firstSource = ResourceDictionaryUtils.findFirstSource(sources); - Assert.assertNull("Source populated, which is not expected.", firstSource); - - // TO check the first Source - sources.put(ResourceDictionaryConstants.SOURCE_INPUT, new NodeTemplate()); - String inputFirstSource = ResourceDictionaryUtils.findFirstSource(sources); - Assert.assertEquals("Expected source Input, but.", ResourceDictionaryConstants.SOURCE_INPUT, inputFirstSource); - - // TO check the multiple Source - sources.put(ResourceDictionaryConstants.SOURCE_PROCESSOR_DB, new NodeTemplate()); - String multipleFirstSource = ResourceDictionaryUtils.findFirstSource(sources); - Assert.assertEquals("Expected source Input, but.", ResourceDictionaryConstants.SOURCE_INPUT, multipleFirstSource); - - } - - @Test - public void testAssignInputs() { - JsonNode data = JacksonUtils.Companion.jsonNodeFromClassPathFile("data/resource-assignment-input.json"); - Map context = new HashMap<>(); - ResourceDictionaryUtils.assignInputs(data, context); - String path = BluePrintConstants.PATH_INPUTS.concat(BluePrintConstants.PATH_DIVIDER).concat("mapValue"); - log.info("populated context {}", context); - Assert.assertTrue(String.format("failed to get variable : %s",path),context.containsKey(path)); - - } - - -} diff --git a/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/cds/controllerblueprints/resource/dict/ResourceDefinitionTest.java b/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/cds/controllerblueprints/resource/dict/ResourceDefinitionTest.java new file mode 100644 index 000000000..db949d45f --- /dev/null +++ b/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/cds/controllerblueprints/resource/dict/ResourceDefinitionTest.java @@ -0,0 +1,60 @@ +/* + * 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.cds.controllerblueprints.resource.dict; + +import org.junit.Assert; +import org.junit.Test; +import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; + +public class ResourceDefinitionTest { + private EELFLogger log = EELFManager.getInstance().getLogger(ResourceDefinitionTest.class); + private String basePath = "load/resource_dictionary"; + + @Test + public void testDictionaryDefinitionInputSource(){ + + String fileName = basePath + "/input-source.json"; + ResourceDefinition resourceDefinition = JacksonUtils.Companion.readValueFromFile(fileName, ResourceDefinition.class); + Assert.assertNotNull("Failed to populate dictionaryDefinition for input type", resourceDefinition); + } + + @Test + public void testDictionaryDefinitionDefaultSource(){ + + String fileName = basePath + "/default-source.json"; + ResourceDefinition resourceDefinition = JacksonUtils.Companion.readValueFromFile(fileName, ResourceDefinition.class); + Assert.assertNotNull("Failed to populate dictionaryDefinition for default type", resourceDefinition); + } + + @Test + public void testDictionaryDefinitionDBSource(){ + + String fileName = basePath + "/primary-db-source.json"; + ResourceDefinition resourceDefinition = JacksonUtils.Companion.readValueFromFile(fileName, ResourceDefinition.class); + Assert.assertNotNull("Failed to populate dictionaryDefinition for primary-db type", resourceDefinition); + } + + @Test + public void testDictionaryDefinitionMDSALSource(){ + String fileName = basePath + "/mdsal-source.json"; + ResourceDefinition resourceDefinition = JacksonUtils.Companion.readValueFromFile(fileName, ResourceDefinition.class); + Assert.assertNotNull("Failed to populate dictionaryDefinition for mdsal type", resourceDefinition); + } +} diff --git a/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/cds/controllerblueprints/resource/dict/factory/ResourceSourceMappingFactoryTest.java b/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/cds/controllerblueprints/resource/dict/factory/ResourceSourceMappingFactoryTest.java new file mode 100644 index 000000000..6c75f0bd8 --- /dev/null +++ b/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/cds/controllerblueprints/resource/dict/factory/ResourceSourceMappingFactoryTest.java @@ -0,0 +1,42 @@ +/* + * 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.cds.controllerblueprints.resource.dict.factory; + +import org.junit.Test; +import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceSourceMapping; +import org.springframework.util.Assert; + +public class ResourceSourceMappingFactoryTest { + + @Test + public void testRegisterResourceMapping() { + + ResourceSourceMappingFactory.INSTANCE.registerSourceMapping("primary-db", "source-primary-db"); + ResourceSourceMappingFactory.INSTANCE.registerSourceMapping("input", "source-input"); + ResourceSourceMappingFactory.INSTANCE.registerSourceMapping("default", "source-default"); + ResourceSourceMappingFactory.INSTANCE.registerSourceMapping("primary-config-data", "source-rest"); + + String nodeTypeName = ResourceSourceMappingFactory.INSTANCE.getRegisterSourceMapping("primary-db"); + Assert.notNull(nodeTypeName, "Failed to get primary-db mapping"); + + ResourceSourceMapping resourceSourceMapping = ResourceSourceMappingFactory.INSTANCE.getRegisterSourceMapping(); + Assert.notNull(resourceSourceMapping, "Failed to get resource source mapping"); + Assert.notNull(resourceSourceMapping.getResourceSourceMappings(), "Failed to get resource source mappings"); + + } + +} diff --git a/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/cds/controllerblueprints/resource/dict/service/ResourceAssignmentValidationServiceTest.kt b/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/cds/controllerblueprints/resource/dict/service/ResourceAssignmentValidationServiceTest.kt new file mode 100644 index 000000000..f21ff4093 --- /dev/null +++ b/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/cds/controllerblueprints/resource/dict/service/ResourceAssignmentValidationServiceTest.kt @@ -0,0 +1,66 @@ +/* + * 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.cds.controllerblueprints.resource.dict.service + +import com.att.eelf.configuration.EELFLogger +import org.junit.Assert +import org.junit.Test +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException +import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils +import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceAssignment +import com.att.eelf.configuration.EELFManager +import org.junit.Before +import org.onap.ccsdk.cds.controllerblueprints.resource.dict.utils.ResourceDictionaryTestUtils + +/** + * ResourceAssignmentValidationServiceTest. + * + * @author Brinda Santh + */ +class ResourceAssignmentValidationServiceTest { + private val log: EELFLogger = EELFManager.getInstance().getLogger(ResourceAssignmentValidationServiceTest::class.java) + @Before + fun setUp() { + // Setup dummy Source Instance Mapping + ResourceDictionaryTestUtils.setUpResourceSourceMapping() + } + + @Test + fun testValidateSuccess() { + log.info("**************** testValidateSuccess *****************") + val assignments = JacksonUtils.getListFromClassPathFile("validation/success.json", ResourceAssignment::class.java) + val resourceAssignmentValidator = ResourceAssignmentValidationServiceImpl() + val result = resourceAssignmentValidator.validate(assignments!!) + Assert.assertTrue("Failed to Validate", result) + } + + @Test(expected = BluePrintException::class) + fun testValidateDuplicate() { + log.info(" **************** testValidateDuplicate *****************") + val assignments = JacksonUtils.getListFromClassPathFile("validation/duplicate.json", ResourceAssignment::class.java) + val resourceAssignmentValidator = ResourceAssignmentValidationServiceImpl() + resourceAssignmentValidator.validate(assignments!!) + } + + @Test(expected = BluePrintException::class) + fun testValidateCyclic() { + log.info(" **************** testValidateCyclic *****************") + val assignments = JacksonUtils.getListFromClassPathFile("validation/cyclic.json", ResourceAssignment::class.java) + val resourceAssignmentValidator = ResourceAssignmentValidationServiceImpl() + resourceAssignmentValidator.validate(assignments!!) + } +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/cds/controllerblueprints/resource/dict/utils/BulkResourceSequencingUtilsTest.java b/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/cds/controllerblueprints/resource/dict/utils/BulkResourceSequencingUtilsTest.java new file mode 100644 index 000000000..3413868ee --- /dev/null +++ b/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/cds/controllerblueprints/resource/dict/utils/BulkResourceSequencingUtilsTest.java @@ -0,0 +1,37 @@ +/* + * 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.cds.controllerblueprints.resource.dict.utils; + +import org.junit.Assert; +import org.junit.Test; +import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils; +import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceAssignment; +import java.util.List; +/** + * BulkResourceSequencingUtils. + * + * @author Brinda Santh + */ +public class BulkResourceSequencingUtilsTest { + + @Test + public void testProcess(){ + List assignments = JacksonUtils.Companion.getListFromClassPathFile("validation/success.json", ResourceAssignment.class); + Assert.assertNotNull("failed to get ResourceAssignment from validation/success.json ", assignments); + BulkResourceSequencingUtils.process(assignments); + } +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/cds/controllerblueprints/resource/dict/utils/ResourceDictionaryUtilsTest.java b/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/cds/controllerblueprints/resource/dict/utils/ResourceDictionaryUtilsTest.java new file mode 100644 index 000000000..fccc4f5fa --- /dev/null +++ b/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/cds/controllerblueprints/resource/dict/utils/ResourceDictionaryUtilsTest.java @@ -0,0 +1,99 @@ +/* + * 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.cds.controllerblueprints.resource.dict.utils; + + +import com.fasterxml.jackson.databind.JsonNode; +import org.junit.Assert; +import org.junit.Test; +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants; +import org.onap.ccsdk.cds.controllerblueprints.core.data.NodeTemplate; +import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils; +import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceAssignment; +import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceDefinition; +import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceDictionaryConstants; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; + +import java.util.HashMap; +import java.util.Map; +/** + * ResourceDictionaryUtilsTest. + * + * @author Brinda Santh + */ +public class ResourceDictionaryUtilsTest { + private static final EELFLogger log = EELFManager.getInstance().getLogger(ResourceDictionaryUtilsTest.class); + + @Test + public void testPopulateSourceMapping() { + + ResourceAssignment resourceAssignment = new ResourceAssignment(); + resourceAssignment.setName("sample-assignment"); + ResourceDefinition resourceDefinition = new ResourceDefinition(); + Map sources = new HashMap<>(); + resourceDefinition.setSources(sources); + // To Check Empty Source + ResourceDictionaryUtils.populateSourceMapping(resourceAssignment, resourceDefinition); + Assert.assertEquals("Expected Empty source Input, but.", ResourceDictionaryConstants.SOURCE_INPUT, resourceAssignment.getDictionarySource()); + + // To Check First Source + resourceAssignment.setDictionarySource(null); + sources.put(ResourceDictionaryConstants.SOURCE_DEFAULT, new NodeTemplate()); + ResourceDictionaryUtils.populateSourceMapping(resourceAssignment, resourceDefinition); + Assert.assertEquals("Expected First source Default, but.", ResourceDictionaryConstants.SOURCE_DEFAULT, resourceAssignment.getDictionarySource()); + + // To Check Assigned Source + resourceAssignment.setDictionarySource(ResourceDictionaryConstants.SOURCE_PROCESSOR_DB); + ResourceDictionaryUtils.populateSourceMapping(resourceAssignment, resourceDefinition); + Assert.assertEquals("Expected Assigned source DB, but.", ResourceDictionaryConstants.SOURCE_PROCESSOR_DB, resourceAssignment.getDictionarySource()); + + } + + @Test + public void testFindFirstSource() { + //To check if Empty Source + Map sources = new HashMap<>(); + String firstSource = ResourceDictionaryUtils.findFirstSource(sources); + Assert.assertNull("Source populated, which is not expected.", firstSource); + + // TO check the first Source + sources.put(ResourceDictionaryConstants.SOURCE_INPUT, new NodeTemplate()); + String inputFirstSource = ResourceDictionaryUtils.findFirstSource(sources); + Assert.assertEquals("Expected source Input, but.", ResourceDictionaryConstants.SOURCE_INPUT, inputFirstSource); + + // TO check the multiple Source + sources.put(ResourceDictionaryConstants.SOURCE_PROCESSOR_DB, new NodeTemplate()); + String multipleFirstSource = ResourceDictionaryUtils.findFirstSource(sources); + Assert.assertEquals("Expected source Input, but.", ResourceDictionaryConstants.SOURCE_INPUT, multipleFirstSource); + + } + + @Test + public void testAssignInputs() { + JsonNode data = JacksonUtils.Companion.jsonNodeFromClassPathFile("data/resource-assignment-input.json"); + Map context = new HashMap<>(); + ResourceDictionaryUtils.assignInputs(data, context); + String path = BluePrintConstants.PATH_INPUTS.concat(BluePrintConstants.PATH_DIVIDER).concat("mapValue"); + log.info("populated context {}", context); + Assert.assertTrue(String.format("failed to get variable : %s",path),context.containsKey(path)); + + } + + +} diff --git a/ms/controllerblueprints/modules/resource-dict/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryTestUtils.kt b/ms/controllerblueprints/modules/resource-dict/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryTestUtils.kt deleted file mode 100644 index ed2bfc0a1..000000000 --- a/ms/controllerblueprints/modules/resource-dict/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryTestUtils.kt +++ /dev/null @@ -1,30 +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 org.onap.ccsdk.apps.controllerblueprints.resource.dict.factory.ResourceSourceMappingFactory - -object ResourceDictionaryTestUtils { - - @JvmStatic - fun setUpResourceSourceMapping() { - ResourceSourceMappingFactory.registerSourceMapping("primary-db", "source-primary-db") - ResourceSourceMappingFactory.registerSourceMapping("input", "source-input") - ResourceSourceMappingFactory.registerSourceMapping("default", "source-default") - ResourceSourceMappingFactory.registerSourceMapping("primary-config-data", "source-rest") - } -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/resource-dict/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/resource/dict/utils/ResourceDictionaryTestUtils.kt b/ms/controllerblueprints/modules/resource-dict/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/resource/dict/utils/ResourceDictionaryTestUtils.kt new file mode 100644 index 000000000..721a36a7f --- /dev/null +++ b/ms/controllerblueprints/modules/resource-dict/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/resource/dict/utils/ResourceDictionaryTestUtils.kt @@ -0,0 +1,30 @@ +/* + * 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.cds.controllerblueprints.resource.dict.utils + +import org.onap.ccsdk.cds.controllerblueprints.resource.dict.factory.ResourceSourceMappingFactory + +object ResourceDictionaryTestUtils { + + @JvmStatic + fun setUpResourceSourceMapping() { + ResourceSourceMappingFactory.registerSourceMapping("primary-db", "source-primary-db") + ResourceSourceMappingFactory.registerSourceMapping("input", "source-input") + ResourceSourceMappingFactory.registerSourceMapping("default", "source-default") + ResourceSourceMappingFactory.registerSourceMapping("primary-config-data", "source-rest") + } +} \ No newline at end of file -- cgit 1.2.3-korg