aboutsummaryrefslogtreecommitdiffstats
path: root/ms/controllerblueprints/modules/resource-dict
diff options
context:
space:
mode:
authorBrinda Santh <brindasanth@in.ibm.com>2018-08-26 22:10:50 -0400
committerBrinda Santh <brindasanth@in.ibm.com>2018-08-26 22:10:50 -0400
commit380790370ba573e0b0e0829b4fa1b38a79581a0e (patch)
tree451873185f9d51b8770342d5c55a120235787d51 /ms/controllerblueprints/modules/resource-dict
parentca395c635569bc70c16397a25dc46d7a9f0629a4 (diff)
Controller Blueprints Microservice
Add resource dictionary validation implementation services, validation repository services and Junit Test cases. Change-Id: Ia746b86b7d9098eabe5e643dcba558ef9aa7160f Issue-ID: CCSDK-487 Signed-off-by: Brinda Santh <brindasanth@in.ibm.com>
Diffstat (limited to 'ms/controllerblueprints/modules/resource-dict')
-rw-r--r--ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDictionaryConstants.java1
-rw-r--r--ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDictionaryValidationService.kt80
-rw-r--r--ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDictionaryValidationServiceTest.java42
3 files changed, 123 insertions, 0 deletions
diff --git a/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDictionaryConstants.java b/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDictionaryConstants.java
index 96ab1ee1..ddbd88bd 100644
--- a/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDictionaryConstants.java
+++ b/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDictionaryConstants.java
@@ -23,6 +23,7 @@ public class ResourceDictionaryConstants {
public static final String SOURCE_DB = "db";
public static final String SOURCE_MDSAL = "mdsal";
+ public static final String PROPERTY_TYPE = "type";
public static final String PROPERTY_INPUT_KEY_MAPPING = "input-key-mapping";
public static final String PROPERTY_OUTPUT_KEY_MAPPING = "output-key-mapping";
public static final String PROPERTY_KEY_DEPENDENCY = "key-dependency";
diff --git a/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDictionaryValidationService.kt b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDictionaryValidationService.kt
new file mode 100644
index 00000000..cef1f158
--- /dev/null
+++ b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDictionaryValidationService.kt
@@ -0,0 +1,80 @@
+/*
+ * 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.fasterxml.jackson.databind.JsonNode
+import com.google.common.base.Preconditions
+import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException
+import org.onap.ccsdk.apps.controllerblueprints.core.data.NodeTemplate
+import org.onap.ccsdk.apps.controllerblueprints.core.data.NodeType
+import org.onap.ccsdk.apps.controllerblueprints.core.data.PropertyDefinition
+import org.onap.ccsdk.apps.controllerblueprints.core.format
+import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintExpressionService
+import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRepoService
+import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition
+import org.slf4j.LoggerFactory
+import java.io.Serializable
+
+interface ResourceDictionaryValidationService : Serializable {
+
+ @Throws(BluePrintException::class)
+ fun validate(resourceDefinition: ResourceDefinition)
+
+}
+
+open class ResourceDictionaryDefaultValidationService(val bluePrintRepoService: BluePrintRepoService) : ResourceDictionaryValidationService {
+
+ private val log = LoggerFactory.getLogger(ResourceDictionaryDefaultValidationService::class.java)
+
+ override fun validate(resourceDefinition: ResourceDefinition) {
+ Preconditions.checkNotNull(resourceDefinition, "Failed to get Resource Definition")
+
+ resourceDefinition.sources.forEach { (name, nodeTemplate) ->
+ val sourceType = nodeTemplate.type
+
+ val sourceNodeType = bluePrintRepoService.getNodeType(sourceType)
+ ?: throw BluePrintException(format("Failed to get node type definition for source({})", sourceType))
+
+ // Validate Property Name, expression, values and Data Type
+ validateNodeTemplateProperties(nodeTemplate, sourceNodeType)
+ }
+ }
+
+
+ open fun validateNodeTemplateProperties(nodeTemplate: NodeTemplate, nodeType: NodeType) {
+ nodeTemplate.properties?.let { validatePropertyAssignments(nodeType.properties!!, nodeTemplate.properties!!) }
+ }
+
+
+ open fun validatePropertyAssignments(nodeTypeProperties: MutableMap<String, PropertyDefinition>,
+ properties: MutableMap<String, JsonNode>) {
+ properties.forEach { propertyName, propertyAssignment ->
+ val propertyDefinition: PropertyDefinition = nodeTypeProperties[propertyName]
+ ?: throw BluePrintException(format("failed to get definition for the property ({})", propertyName))
+ // Check and Validate if Expression Node
+ val expressionData = BluePrintExpressionService.getExpressionData(propertyAssignment)
+ if (!expressionData.isExpression) {
+ checkPropertyValue(propertyDefinition, propertyName, propertyAssignment)
+ }
+ }
+ }
+
+ open fun checkPropertyValue(propertyDefinition: PropertyDefinition, propertyName: String, jsonNode: JsonNode) {
+ //log.info("validating Property {}, name ({}) value ({})", propertyDefinition, propertyName, jsonNode)
+ //TODO
+ }
+} \ No newline at end of file
diff --git a/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDictionaryValidationServiceTest.java b/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDictionaryValidationServiceTest.java
new file mode 100644
index 00000000..6eebdb2f
--- /dev/null
+++ b/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDictionaryValidationServiceTest.java
@@ -0,0 +1,42 @@
+/*
+ * 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 org.junit.Assert;
+import org.junit.Test;
+import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRepoFileService;
+import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils;
+import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition;
+
+public class ResourceDictionaryValidationServiceTest {
+ private String basePath = "load/model_type";
+ String dictionaryPath = "load/resource_dictionary";
+
+ @Test
+ public void testValidate() throws Exception {
+ BluePrintRepoFileService bluePrintRepoFileService = new BluePrintRepoFileService(basePath);
+
+ String fileName = dictionaryPath + "/db-source.json";
+ ResourceDefinition resourceDefinition = JacksonUtils.readValueFromFile(fileName, ResourceDefinition.class);
+ Assert.assertNotNull("Failed to populate dictionaryDefinition for db type", resourceDefinition);
+
+ ResourceDictionaryValidationService resourceDictionaryValidationService =
+ new ResourceDictionaryDefaultValidationService(bluePrintRepoFileService);
+ resourceDictionaryValidationService.validate(resourceDefinition);
+
+ }
+}