summaryrefslogtreecommitdiffstats
path: root/ms
diff options
context:
space:
mode:
authorMuthuramalingam, Brinda Santh(bs2796) <bs2796@att.com>2018-08-30 14:17:06 +0000
committerMuthuramalingam, Brinda Santh(bs2796) <bs2796@att.com>2018-08-30 14:17:06 +0000
commite0bf80ea0f864a4da8bc2d9bf6e5b19bde75af41 (patch)
treef737c89033488ace40d95d1552ba266eb4d3a9c2 /ms
parent2a7cd18ca4aaf6d050fe8740bcde53e9a214d224 (diff)
Controller Blueprints Microservice
Add Resource Seuencing validation and Optimise resource assignment validation logics Change-Id: I6f31ca5dbeb6f6aa89959b7d96fbfad25468b3a4 Issue-ID: CCSDK-416 Signed-off-by: Muthuramalingam, Brinda Santh(bs2796) <bs2796@att.com>
Diffstat (limited to 'ms')
-rw-r--r--ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonUtils.kt7
-rw-r--r--ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/validator/ResourceAssignmentValidator.java163
-rw-r--r--ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDefinition.kt15
-rw-r--r--ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceAssignmentValidationService.kt84
-rw-r--r--ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/BulkResourceSequencingUtils.kt108
-rw-r--r--ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/BulkResourceSequencingUtilsTest.java37
-rw-r--r--ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtilsTest.java6
-rw-r--r--ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ConfigModelCreateService.java39
-rw-r--r--ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceAssignmentValidationService.java29
-rw-r--r--ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ServiceTemplateService.java22
-rw-r--r--ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/validator/ServiceTemplateValidator.java47
-rw-r--r--ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/validator/ServiceTemplateValidationTest.java19
-rw-r--r--ms/controllerblueprints/modules/service/src/test/resources/enhance/enhance-template.json5
-rw-r--r--ms/controllerblueprints/modules/service/src/test/resources/enhance/enhanced-template.json2
14 files changed, 337 insertions, 246 deletions
diff --git a/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonUtils.kt b/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonUtils.kt
index c41124ed..9eef1cad 100644
--- a/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonUtils.kt
+++ b/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonUtils.kt
@@ -59,6 +59,13 @@ object JacksonUtils {
}
@JvmStatic
+ fun <T> readValueFromClassPathFile(fileName: String, valueType: Class<T>): T? {
+ val content: String = IOUtils.toString(JacksonUtils::class.java.classLoader.getResourceAsStream(fileName), Charset.defaultCharset())
+ ?: throw BluePrintException(String.format("Failed to read json file : %s", fileName))
+ return readValue(content, valueType)
+ }
+
+ @JvmStatic
fun jsonNodeFromObject(from: kotlin.Any): JsonNode = jacksonObjectMapper().convertValue(from, JsonNode::class.java)
@JvmStatic
diff --git a/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/validator/ResourceAssignmentValidator.java b/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/validator/ResourceAssignmentValidator.java
deleted file mode 100644
index c9b37c26..00000000
--- a/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/validator/ResourceAssignmentValidator.java
+++ /dev/null
@@ -1,163 +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.validator;
-
-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.ConfigModelConstant;
-import org.onap.ccsdk.apps.controllerblueprints.core.data.CapabilityAssignment;
-import org.onap.ccsdk.apps.controllerblueprints.core.data.NodeTemplate;
-import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils;
-import org.onap.ccsdk.apps.controllerblueprints.core.utils.TopologicalSortingUtils;
-import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.util.*;
-
-/**
- * ResourceAssignmentValidator.java Purpose:
- *
- * @author Brinda Santh
- */
-public class ResourceAssignmentValidator {
- private static final Logger log = LoggerFactory.getLogger(ResourceAssignmentValidator.class);
- private List<ResourceAssignment> assignments;
- private Map<String, ResourceAssignment> resourceAssignmentMap = new HashMap<>();
- private StrBuilder validationMessage = new StrBuilder();
-
- public ResourceAssignmentValidator(List<ResourceAssignment> assignments) {
- this.assignments = assignments;
- }
-
- public ResourceAssignmentValidator(NodeTemplate nodeTemplate) throws BluePrintException {
-
- if (nodeTemplate != null && nodeTemplate.getCapabilities() != null) {
- CapabilityAssignment capabilityAssignment =
- nodeTemplate.getCapabilities().get(ConfigModelConstant.CAPABILITY_PROPERTY_MAPPING);
- if (capabilityAssignment != null && capabilityAssignment.getProperties() != null) {
- Object mappingObject =
- capabilityAssignment.getProperties().get(ConfigModelConstant.CAPABILITY_PROPERTY_MAPPING);
- if (mappingObject != null) {
- String mappingContent = JacksonUtils.getJson(mappingObject);
- if (StringUtils.isNotBlank(mappingContent)) {
- this.assignments =
- JacksonUtils.getListFromJson(mappingContent, ResourceAssignment.class);
- } else {
- validationMessage
- .appendln(String.format("Failed to transform Mapping Content (%s) ", mappingContent));
- throw new BluePrintException(
- String.format("Failed to transform Mapping Content (%s) ", mappingContent));
- }
- }
- }
- }
- }
-
- /**
- * This is a validateResourceAssignment to validate the Topology Template
- *
- * @return boolean
- * @throws BluePrintException BluePrintException
- */
- public boolean validateResourceAssignment() throws BluePrintException {
- if (assignments != null && !assignments.isEmpty()) {
- validateDuplicateDictionaryKeys();
- validateCyclicDependency();
- if (validationMessage.length() > 0) {
- throw new BluePrintException("Resource Assignment Validation :" + validationMessage.toString());
- }
- }
- return true;
- }
-
- @SuppressWarnings("squid:S3776")
- private void validateDuplicateDictionaryKeys() {
- this.assignments.forEach(resourceMapping -> {
- if (resourceMapping != null) {
- if (!resourceAssignmentMap.containsKey(resourceMapping.getName())) {
- resourceAssignmentMap.put(resourceMapping.getName(), resourceMapping);
- } else {
- validationMessage.appendln(String.format("Duplicate Assignment Template Key (%s) is Present",
- resourceMapping.getName()));
- }
- }
- });
-
- if (!assignments.isEmpty()) {
- Set<String> uniqueSet = new HashSet<>();
- for (ResourceAssignment resourceAssignment : assignments) {
- if (resourceAssignment != null) {
- boolean added = uniqueSet.add(resourceAssignment.getDictionaryName());
- if (!added) {
- validationMessage.appendln(
- String.format("Duplicate Assignment Dictionary Key (%s) present with Template Key (%s)",
- resourceAssignment.getDictionaryName(), resourceAssignment.getName()));
- }
- }
- }
- }
- }
-
- private void validateCyclicDependency() {
- TopologicalSortingUtils<ResourceAssignment> topologySorting = new TopologicalSortingUtils<>();
- this.resourceAssignmentMap.forEach((mappingKey, mapping) -> {
- if (mapping != null) {
- if (mapping.getDependencies() != null && !mapping.getDependencies().isEmpty()) {
- for (String dependency : mapping.getDependencies()) {
- topologySorting.add(resourceAssignmentMap.get(dependency), mapping);
- }
- } else {
- topologySorting.add(null, mapping);
- }
- }
- });
-
- if (!topologySorting.isDag()) {
- String graph = getTopologicalGraph(topologySorting);
- validationMessage.appendln("Cyclic Dependency :" + graph);
- }
- }
-
-
- public String getTopologicalGraph(TopologicalSortingUtils<ResourceAssignment> topologySorting) {
- StringBuilder s = new StringBuilder();
- if (topologySorting != null) {
- Map<ResourceAssignment, List<ResourceAssignment>> neighbors = topologySorting.getNeighbors();
-
- neighbors.forEach((v, vs) -> {
- if (v == null) {
- s.append("\n * -> [");
- for (ResourceAssignment resourceAssignment : vs) {
- s.append("(" + resourceAssignment.getDictionaryName() + ":" + resourceAssignment.getName()
- + "),");
- }
- s.append("]");
- } else {
- s.append("\n (" + v.getDictionaryName() + ":" + v.getName() + ") -> [");
- for (ResourceAssignment resourceAssignment : vs) {
- s.append("(" + resourceAssignment.getDictionaryName() + ":" + resourceAssignment.getName()
- + "),");
- }
- s.append("]");
- }
- });
- }
- return s.toString();
- }
-}
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
index 2287c6c8..b4d68cbc 100644
--- 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
@@ -18,18 +18,19 @@ package org.onap.ccsdk.apps.controllerblueprints.resource.dict
import com.fasterxml.jackson.annotation.JsonFormat
import com.fasterxml.jackson.annotation.JsonProperty
+import org.apache.commons.lang3.builder.ToStringBuilder
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{
+open class ResourceDefinition {
@JsonProperty(value = "name", required = true)
lateinit var name: String
@JsonProperty(value = "property", required = true)
- lateinit var property : PropertyDefinition
+ lateinit var property: PropertyDefinition
var tags: String? = null
@@ -81,6 +82,16 @@ open class ResourceAssignment {
@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()
+ }
}
/**
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
index 6a78ac85..4578aca7 100644
--- 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
@@ -22,7 +22,6 @@ 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 org.onap.ccsdk.apps.controllerblueprints.resource.dict.validator.ResourceAssignmentValidator
import org.slf4j.LoggerFactory
import java.io.Serializable
@@ -43,18 +42,21 @@ interface ResourceAssignmentValidationService : Serializable {
* @author Brinda Santh
*/
open class ResourceAssignmentValidationDefaultService : ResourceAssignmentValidationService {
- private val log = LoggerFactory.getLogger(ResourceAssignmentValidator::class.java)
- open var resourceAssignments: List<ResourceAssignment> = arrayListOf()
- open var resourceAssignmentMap: MutableMap<String, ResourceAssignment> = hashMapOf()
+ private val log = LoggerFactory.getLogger(ResourceAssignmentValidationDefaultService::class.java)
+
+ open var resourceAssignmentMap: Map<String, ResourceAssignment> = hashMapOf()
open val validationMessage = StrBuilder()
override fun validate(resourceAssignments: List<ResourceAssignment>): Boolean {
- this.resourceAssignments = resourceAssignments
- validateSources(resourceAssignments)
- validateDuplicateDictionaryKeys()
- validateCyclicDependency()
- if (StringUtils.isNotBlank(validationMessage)) {
- throw BluePrintException("Resource Assignment Validation :" + validationMessage.toString())
+ try {
+ validateSources(resourceAssignments)
+ 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
}
@@ -63,40 +65,54 @@ open class ResourceAssignmentValidationDefaultService : ResourceAssignmentValida
log.info("validating resource assignment sources")
}
- open fun validateDuplicateDictionaryKeys() {
- val uniqueDictionaryKeys = hashSetOf<String>()
+ open fun validateTemplateNDictionaryKeys(resourceAssignments: List<ResourceAssignment>) {
- this.resourceAssignments.forEach { resourceAssignment ->
- // Check Duplicate Names
- if (!resourceAssignmentMap.containsKey(resourceAssignment.name)) {
- resourceAssignmentMap[resourceAssignment.name] = resourceAssignment
- } else {
- validationMessage.appendln(String.format("Duplicate Assignment Template Key (%s) is Present",
- resourceAssignment.name))
- }
- // Check duplicate Dictionary Keys
- if (!uniqueDictionaryKeys.contains(resourceAssignment.dictionaryName!!)) {
- uniqueDictionaryKeys.add(resourceAssignment.dictionaryName!!)
- } else {
- validationMessage.appendln(
- String.format("Duplicate Assignment Dictionary Key (%s) present with Template Key (%s)",
- resourceAssignment.dictionaryName, resourceAssignment.name))
- }
+ resourceAssignmentMap = resourceAssignments.map { it.name to it }.toMap()
+
+ 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))
+ }
+
+ val duplicateDictionaryKeyNames = resourceAssignments.groupBy { it.dictionaryName }
+ .filter { it.value.size > 1 }
+ .map { it.key }
+ if (duplicateDictionaryKeyNames.isNotEmpty()) {
+ validationMessage.appendln(String.format("Duplicate Assignment Dictionary Keys (%s) is Present", duplicateDictionaryKeyNames))
+ }
+
+ val dependenciesNames = resourceAssignments.mapNotNull { it.dependencies }.flatten()
+
+ log.info("Resource assignment definitions : {}", resourceAssignmentMap.keys)
+ log.info("Resource assignment Dictionary dependencies : {}", dependenciesNames)
+
+ 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() {
+ open fun validateCyclicDependency(resourceAssignments: List<ResourceAssignment>) {
val startResourceAssignment = ResourceAssignment()
startResourceAssignment.name = "*"
val topologySorting = TopologicalSortingUtils<ResourceAssignment>()
- this.resourceAssignmentMap.forEach { assignmentKey, assignment ->
- if (CollectionUtils.isNotEmpty(assignment.dependencies)) {
- for (dependency in assignment.dependencies!!) {
- topologySorting.add(resourceAssignmentMap[dependency]!!, assignment)
+
+ resourceAssignmentMap.map { it.value }.map { resourceAssignment ->
+ if (CollectionUtils.isNotEmpty(resourceAssignment.dependencies)) {
+ resourceAssignment.dependencies!!.map {
+ log.info("Topological Graph link from {} to {}", it, resourceAssignment.name)
+ topologySorting.add(resourceAssignmentMap[it]!!, resourceAssignment)
}
} else {
- topologySorting.add(startResourceAssignment, assignment)
+ topologySorting.add(startResourceAssignment, resourceAssignment)
}
}
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
new file mode 100644
index 00000000..82fbd3ac
--- /dev/null
+++ b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/BulkResourceSequencingUtils.kt
@@ -0,0 +1,108 @@
+/*
+ * 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.apache.commons.collections.CollectionUtils
+import org.onap.ccsdk.apps.controllerblueprints.core.utils.TopologicalSortingUtils
+import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment
+import org.slf4j.LoggerFactory
+import java.util.ArrayList
+/**
+ * BulkResourceSequencingUtils.
+ *
+ * @author Brinda Santh
+ */
+object BulkResourceSequencingUtils {
+ private val log = LoggerFactory.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/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
new file mode 100644
index 00000000..c7444dba
--- /dev/null
+++ b/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/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.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<ResourceAssignment> assignments = JacksonUtils.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
index 5c22f654..5ee56171 100644
--- 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
@@ -32,7 +32,11 @@ import org.slf4j.LoggerFactory;
import java.util.HashMap;
import java.util.Map;
-
+/**
+ * ResourceDictionaryUtilsTest.
+ *
+ * @author Brinda Santh
+ */
public class ResourceDictionaryUtilsTest {
private static final Logger log = LoggerFactory.getLogger(ResourceDictionaryUtilsTest.class);
diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ConfigModelCreateService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ConfigModelCreateService.java
index f5213719..9c1a045c 100644
--- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ConfigModelCreateService.java
+++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ConfigModelCreateService.java
@@ -21,6 +21,7 @@ import com.google.common.base.Preconditions;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
+import org.jetbrains.annotations.NotNull;
import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants;
import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException;
import org.onap.ccsdk.apps.controllerblueprints.core.ConfigModelConstant;
@@ -290,31 +291,29 @@ public class ConfigModelCreateService {
* @return ConfigModel
* @throws BluePrintException BluePrintException
*/
- public ConfigModel publishConfigModel(Long id) throws BluePrintException {
+ public ConfigModel publishConfigModel(@NotNull Long id) throws BluePrintException {
ConfigModel dbConfigModel = null;
- if (id != null) {
- Optional<ConfigModel> dbConfigModelOptional = configModelRepository.findById(id);
- if (dbConfigModelOptional.isPresent()) {
- dbConfigModel = dbConfigModelOptional.get();
- List<ConfigModelContent> configModelContents = dbConfigModel.getConfigModelContents();
- if (configModelContents != null && !configModelContents.isEmpty()) {
- for (ConfigModelContent configModelContent : configModelContents) {
- if (configModelContent.getContentType()
- .equals(ConfigModelConstant.MODEL_CONTENT_TYPE_TOSCA_JSON)) {
- ServiceTemplate serviceTemplate = JacksonUtils
- .readValue(configModelContent.getContent(), ServiceTemplate.class);
- if (serviceTemplate != null) {
- validateServiceTemplate(serviceTemplate);
- }
+ Optional<ConfigModel> dbConfigModelOptional = configModelRepository.findById(id);
+ if (dbConfigModelOptional.isPresent()) {
+ dbConfigModel = dbConfigModelOptional.get();
+ List<ConfigModelContent> configModelContents = dbConfigModel.getConfigModelContents();
+ if (configModelContents != null && !configModelContents.isEmpty()) {
+ for (ConfigModelContent configModelContent : configModelContents) {
+ if (configModelContent.getContentType()
+ .equals(ConfigModelConstant.MODEL_CONTENT_TYPE_TOSCA_JSON)) {
+ ServiceTemplate serviceTemplate = JacksonUtils
+ .readValue(configModelContent.getContent(), ServiceTemplate.class);
+ if (serviceTemplate != null) {
+ validateServiceTemplate(serviceTemplate);
}
}
}
- dbConfigModel.setPublished(ApplicationConstants.ACTIVE_Y);
- configModelRepository.save(dbConfigModel);
- log.info("Config model ({}) published successfully.", id);
-
}
-
+ dbConfigModel.setPublished(ApplicationConstants.ACTIVE_Y);
+ configModelRepository.save(dbConfigModel);
+ log.info("Config model ({}) published successfully.", id);
+ } else {
+ throw new BluePrintException(String.format("Couldn't get Config model for id :(%s)", id));
}
return dbConfigModel;
}
diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceAssignmentValidationService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceAssignmentValidationService.java
new file mode 100644
index 00000000..1228e2ee
--- /dev/null
+++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceAssignmentValidationService.java
@@ -0,0 +1,29 @@
+/*
+ * 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.service;
+
+import org.onap.ccsdk.apps.controllerblueprints.resource.dict.service.ResourceAssignmentValidationDefaultService;
+import org.springframework.stereotype.Service;
+/**
+ * ResourceAssignmentValidationService.
+ *
+ * @author Brinda Santh
+ */
+@Service
+public class ResourceAssignmentValidationService extends ResourceAssignmentValidationDefaultService {
+
+} \ No newline at end of file
diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ServiceTemplateService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ServiceTemplateService.java
index 70cee3c9..3e3c8e28 100644
--- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ServiceTemplateService.java
+++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ServiceTemplateService.java
@@ -20,7 +20,6 @@ import org.apache.commons.lang3.StringUtils;
import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException;
import org.onap.ccsdk.apps.controllerblueprints.core.data.ServiceTemplate;
import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment;
-import org.onap.ccsdk.apps.controllerblueprints.resource.dict.validator.ResourceAssignmentValidator;
import org.onap.ccsdk.apps.controllerblueprints.service.domain.ConfigModelContent;
import org.onap.ccsdk.apps.controllerblueprints.service.model.AutoMapResponse;
import org.onap.ccsdk.apps.controllerblueprints.service.repository.ResourceDictionaryRepository;
@@ -45,21 +44,24 @@ public class ServiceTemplateService {
private ConfigModelCreateService configModelCreateService;
private BluePrintEnhancerService bluePrintEnhancerService;
+ private ResourceAssignmentValidationService resourceAssignmentValidationService;
/**
* This is a SchemaGeneratorService constructor
*
- * @param dataDictionaryRepository dataDictionaryRepository
- * @param configModelCreateService configModelCreateService
- * @param bluePrintEnhancerService bluePrintEnhancerService
+ * @param dataDictionaryRepository dataDictionaryRepository
+ * @param configModelCreateService configModelCreateService
+ * @param bluePrintEnhancerService bluePrintEnhancerService
+ * @param resourceAssignmentValidationService resourceAssignmentValidationService
*/
public ServiceTemplateService(ResourceDictionaryRepository dataDictionaryRepository,
ConfigModelCreateService configModelCreateService,
- BluePrintEnhancerService bluePrintEnhancerService) {
+ BluePrintEnhancerService bluePrintEnhancerService,
+ ResourceAssignmentValidationService resourceAssignmentValidationService) {
this.dataDictionaryRepository = dataDictionaryRepository;
this.configModelCreateService = configModelCreateService;
this.bluePrintEnhancerService = bluePrintEnhancerService;
-
+ this.resourceAssignmentValidationService = resourceAssignmentValidationService;
}
/**
@@ -105,13 +107,7 @@ public class ServiceTemplateService {
*/
public List<ResourceAssignment> validateResourceAssignments(List<ResourceAssignment> resourceAssignments)
throws BluePrintException {
- try {
- ResourceAssignmentValidator resourceAssignmentValidator =
- new ResourceAssignmentValidator(resourceAssignments);
- resourceAssignmentValidator.validateResourceAssignment();
- } catch (BluePrintException e) {
- throw new BluePrintException(e.getMessage(), e);
- }
+ resourceAssignmentValidationService.validate(resourceAssignments);
return resourceAssignments;
}
diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/validator/ServiceTemplateValidator.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/validator/ServiceTemplateValidator.java
index 848a32f5..42adf1a3 100644
--- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/validator/ServiceTemplateValidator.java
+++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/validator/ServiceTemplateValidator.java
@@ -17,16 +17,23 @@
package org.onap.ccsdk.apps.controllerblueprints.service.validator;
import com.google.common.base.Preconditions;
+import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.NotNull;
+import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants;
import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException;
+import org.onap.ccsdk.apps.controllerblueprints.core.ConfigModelConstant;
+import org.onap.ccsdk.apps.controllerblueprints.core.data.CapabilityAssignment;
import org.onap.ccsdk.apps.controllerblueprints.core.data.NodeTemplate;
import org.onap.ccsdk.apps.controllerblueprints.core.data.ServiceTemplate;
import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintValidatorDefaultService;
import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils;
-import org.onap.ccsdk.apps.controllerblueprints.resource.dict.validator.ResourceAssignmentValidator;
+import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment;
+import org.onap.ccsdk.apps.controllerblueprints.resource.dict.service.ResourceAssignmentValidationDefaultService;
+import org.onap.ccsdk.apps.controllerblueprints.resource.dict.service.ResourceAssignmentValidationService;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
/**
@@ -62,7 +69,7 @@ public class ServiceTemplateValidator extends BluePrintValidatorDefaultService {
/**
* This is a validateServiceTemplate
*
- * @param serviceTemplate
+ * @param serviceTemplate serviceTemplate
* @return boolean
* @throws BluePrintException BluePrintException
*/
@@ -76,7 +83,7 @@ public class ServiceTemplateValidator extends BluePrintValidatorDefaultService {
/**
* This is a getMetaData to get the key information during the
*
- * @return Map<String, String>
+ * @return Map<String , String>
*/
public Map<String, String> getMetaData() {
return metaData;
@@ -104,9 +111,37 @@ public class ServiceTemplateValidator extends BluePrintValidatorDefaultService {
private void validateNodeTemplateCustom(@NotNull String nodeTemplateName, @NotNull NodeTemplate nodeTemplate)
throws BluePrintException {
String derivedFrom = getBluePrintContext().nodeTemplateNodeType(nodeTemplateName).getDerivedFrom();
- if ("tosca.nodes.Artifact".equals(derivedFrom)) {
- ResourceAssignmentValidator resourceAssignmentValidator = new ResourceAssignmentValidator(nodeTemplate);
- resourceAssignmentValidator.validateResourceAssignment();
+
+ if (BluePrintConstants.MODEL_TYPE_NODE_ARTIFACT.equals(derivedFrom)) {
+ List<ResourceAssignment> resourceAssignment = getResourceAssignments(nodeTemplate);
+ ResourceAssignmentValidationService resourceAssignmentValidationService = new ResourceAssignmentValidationDefaultService();
+ resourceAssignmentValidationService.validate(resourceAssignment);
+ }
+ }
+
+ private List<ResourceAssignment> getResourceAssignments(@NotNull NodeTemplate nodeTemplate) {
+
+ List<ResourceAssignment> resourceAssignment = null;
+
+ if (MapUtils.isNotEmpty(nodeTemplate.getCapabilities())) {
+
+ CapabilityAssignment capabilityAssignment =
+ nodeTemplate.getCapabilities().get(ConfigModelConstant.CAPABILITY_PROPERTY_MAPPING);
+ if (capabilityAssignment != null && capabilityAssignment.getProperties() != null) {
+ Object mappingObject =
+ capabilityAssignment.getProperties().get(ConfigModelConstant.CAPABILITY_PROPERTY_MAPPING);
+ if (mappingObject != null) {
+ String mappingContent = JacksonUtils.getJson(mappingObject);
+ Preconditions.checkArgument(StringUtils.isNotBlank(mappingContent),
+ String.format("Failed to get capability mapping property (%s) ", ConfigModelConstant.CAPABILITY_PROPERTY_MAPPING));
+
+ resourceAssignment = JacksonUtils.getListFromJson(mappingContent, ResourceAssignment.class);
+
+ Preconditions.checkNotNull(resourceAssignment,
+ String.format("Failed to get resource assignment info from the content (%s) ", mappingContent));
+ }
+ }
}
+ return resourceAssignment;
}
}
diff --git a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/validator/ServiceTemplateValidationTest.java b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/validator/ServiceTemplateValidationTest.java
index 0ef54452..e41e90a2 100644
--- a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/validator/ServiceTemplateValidationTest.java
+++ b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/validator/ServiceTemplateValidationTest.java
@@ -20,6 +20,8 @@ package org.onap.ccsdk.apps.controllerblueprints.service.validator;
import org.apache.commons.io.FileUtils;
import org.junit.Assert;
import org.junit.Test;
+import org.onap.ccsdk.apps.controllerblueprints.core.data.ServiceTemplate;
+import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils;
import org.onap.ccsdk.apps.controllerblueprints.service.utils.ConfigModelUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -40,9 +42,22 @@ public class ServiceTemplateValidationTest {
@Test
public void validateServiceTemplate() throws Exception {
- String file = "load/blueprints/baseconfiguration/Definitions/activation-blueprint.json";
+ validateServiceTemplate("load/blueprints/baseconfiguration/Definitions/activation-blueprint.json");
+ validateServiceTemplate("load/blueprints/vrr-test/Definitions/vrr-test.json");
+ }
+
+ //@Test
+ public void validateEnhancedServiceTemplate() throws Exception {
+ ServiceTemplate serviceTemplate = JacksonUtils
+ .readValueFromClassPathFile("enhance/enhanced-template.json", ServiceTemplate.class);
+ ServiceTemplateValidator serviceTemplateValidator = new ServiceTemplateValidator();
+ Boolean valid = serviceTemplateValidator.validateServiceTemplate(serviceTemplate);
+ Assert.assertTrue("Failed to validate blueprints", valid);
+ }
+
+ private void validateServiceTemplate(String fileName) throws Exception {
String serviceTemplateContent =
- FileUtils.readFileToString(new File(file), Charset.defaultCharset());
+ FileUtils.readFileToString(new File(fileName), Charset.defaultCharset());
ServiceTemplateValidator serviceTemplateValidator = new ServiceTemplateValidator();
serviceTemplateValidator.validateServiceTemplate(serviceTemplateContent);
Assert.assertNotNull("Failed to validate blueprints", serviceTemplateValidator);
diff --git a/ms/controllerblueprints/modules/service/src/test/resources/enhance/enhance-template.json b/ms/controllerblueprints/modules/service/src/test/resources/enhance/enhance-template.json
index a4ba930e..fedf1da2 100644
--- a/ms/controllerblueprints/modules/service/src/test/resources/enhance/enhance-template.json
+++ b/ms/controllerblueprints/modules/service/src/test/resources/enhance/enhance-template.json
@@ -232,10 +232,7 @@
"dictionary-name": "wan-aggregate-ipv4-addresses",
"dictionary-source": "mdsal",
"dependencies": [
- "service-instance-id",
- "oam-network-role",
- "oam-v4-ip-type ",
- "oam-vm-type"
+ "service-instance-id"
],
"version": 0
},
diff --git a/ms/controllerblueprints/modules/service/src/test/resources/enhance/enhanced-template.json b/ms/controllerblueprints/modules/service/src/test/resources/enhance/enhanced-template.json
index e0033096..0633c64d 100644
--- a/ms/controllerblueprints/modules/service/src/test/resources/enhance/enhanced-template.json
+++ b/ms/controllerblueprints/modules/service/src/test/resources/enhance/enhanced-template.json
@@ -738,7 +738,7 @@
"input-param" : false,
"dictionary-name" : "wan-aggregate-ipv4-addresses",
"dictionary-source" : "mdsal",
- "dependencies" : [ "service-instance-id", "oam-network-role", "oam-v4-ip-type ", "oam-vm-type" ],
+ "dependencies" : [ "service-instance-id" ],
"version" : 0
}, {
"name" : "hostname",