Merge "Controller Blueprints Microservice"
authorDan Timoney <dt5972@att.com>
Fri, 24 Aug 2018 19:32:51 +0000 (19:32 +0000)
committerGerrit Code Review <gerrit@onap.org>
Fri, 24 Aug 2018 19:32:51 +0000 (19:32 +0000)
ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintValidatorService.kt
ms/controllerblueprints/modules/service/load/blueprints/vrr-test/Definitions/vrr-test.json
ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/validator/ServiceTemplateValidator.java
ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/common/SchemaGeneratorServiceTest.java
ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/common/ServiceTemplateValidationTest.java [deleted file]
ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/validator/ServiceTemplateValidationTest.java [new file with mode: 0644]
ms/controllerblueprints/modules/service/src/test/resources/enhance/enhance-template.json
ms/controllerblueprints/modules/service/src/test/resources/enhance/enhanced-template.json

index 2383a65..973e3de 100644 (file)
@@ -47,7 +47,7 @@ open class BluePrintValidatorDefaultService : BluePrintValidatorService {
     lateinit var serviceTemplate: ServiceTemplate\r
     lateinit var properties: MutableMap<String, Any>\r
     var message: StringBuilder = StringBuilder()\r
-    val seperator: String = "/"\r
+    private val separator: String = BluePrintConstants.PATH_DIVIDER\r
     var paths: MutableList<String> = arrayListOf()\r
 \r
     @Throws(BluePrintException::class)\r
@@ -68,22 +68,27 @@ open class BluePrintValidatorDefaultService : BluePrintValidatorService {
             serviceTemplate.nodeTypes?.let { validateNodeTypes(serviceTemplate.nodeTypes!!) }\r
             serviceTemplate.topologyTemplate?.let { validateTopologyTemplate(serviceTemplate.topologyTemplate!!) }\r
         } catch (e: Exception) {\r
-            logger.error("validation failed in the path : {}", paths.joinToString(seperator), e)\r
+            logger.error("validation failed in the path : {}", paths.joinToString(separator), e)\r
             logger.error("validation trace message :{} ", message)\r
             throw BluePrintException(e,\r
                     format("failed to validate blueprint on path ({}) with message {}"\r
-                            , paths.joinToString(seperator), e.message))\r
+                            , paths.joinToString(separator), e.message))\r
         }\r
     }\r
 \r
     @Throws(BluePrintException::class)\r
     open fun validateMetadata(metaDataMap: MutableMap<String, String>) {\r
         paths.add("metadata")\r
-        Preconditions.checkArgument(StringUtils.isNotBlank(metaDataMap[BluePrintConstants.METADATA_TEMPLATE_NAME]), "failed to get template name metadata")\r
-        Preconditions.checkArgument(StringUtils.isNotBlank(metaDataMap[BluePrintConstants.METADATA_TEMPLATE_VERSION]), "failed to get template version metadata")\r
-        Preconditions.checkArgument(StringUtils.isNotBlank(metaDataMap[BluePrintConstants.METADATA_TEMPLATE_TAGS]), "failed to get template tags metadata")\r
-        Preconditions.checkArgument(StringUtils.isNotBlank(metaDataMap[BluePrintConstants.METADATA_TEMPLATE_AUTHOR]), "failed to get template author metadata")\r
-        Preconditions.checkArgument(StringUtils.isNotBlank(metaDataMap[BluePrintConstants.METADATA_USER_GROUPS]), "failed to get user groups metadata")\r
+\r
+        val templateName = metaDataMap[BluePrintConstants.METADATA_TEMPLATE_NAME]\r
+        val templateVersion = metaDataMap[BluePrintConstants.METADATA_TEMPLATE_VERSION]\r
+        val templateTags = metaDataMap[BluePrintConstants.METADATA_TEMPLATE_TAGS]\r
+        val templateAuthor = metaDataMap[BluePrintConstants.METADATA_TEMPLATE_AUTHOR]\r
+\r
+        Preconditions.checkArgument(StringUtils.isNotBlank(templateName), "failed to get template name metadata")\r
+        Preconditions.checkArgument(StringUtils.isNotBlank(templateVersion), "failed to get template version metadata")\r
+        Preconditions.checkArgument(StringUtils.isNotBlank(templateTags), "failed to get template tags metadata")\r
+        Preconditions.checkArgument(StringUtils.isNotBlank(templateAuthor), "failed to get template author metadata")\r
         paths.removeAt(paths.lastIndex)\r
     }\r
 \r
@@ -92,7 +97,7 @@ open class BluePrintValidatorDefaultService : BluePrintValidatorService {
         paths.add("artifact_types")\r
         artifactTypes.forEach { artifactName, artifactType ->\r
             paths.add(artifactName)\r
-            message.appendln("--> Artifact Type :" + paths.joinToString(seperator))\r
+            message.appendln("--> Artifact Type :" + paths.joinToString(separator))\r
             artifactType.properties?.let { validatePropertyDefinitions(artifactType.properties!!) }\r
             paths.removeAt(paths.lastIndex)\r
         }\r
@@ -104,7 +109,7 @@ open class BluePrintValidatorDefaultService : BluePrintValidatorService {
         paths.add("dataTypes")\r
         dataTypes.forEach { dataTypeName, dataType ->\r
             paths.add(dataTypeName)\r
-            message.appendln("--> Data Type :" + paths.joinToString(seperator))\r
+            message.appendln("--> Data Type :" + paths.joinToString(separator))\r
             dataType.properties?.let { validatePropertyDefinitions(dataType.properties!!) }\r
             paths.removeAt(paths.lastIndex)\r
         }\r
@@ -124,7 +129,7 @@ open class BluePrintValidatorDefaultService : BluePrintValidatorService {
     @Throws(BluePrintException::class)\r
     open fun validateNodeType(nodeTypeName: String, nodeType: NodeType) {\r
         paths.add(nodeTypeName)\r
-        message.appendln("--> Node Type :" + paths.joinToString(seperator))\r
+        message.appendln("--> Node Type :" + paths.joinToString(separator))\r
         val derivedFrom: String = nodeType.derivedFrom\r
         //Check Derived From\r
         checkValidNodeTypesDerivedFrom(derivedFrom)\r
@@ -147,7 +152,7 @@ open class BluePrintValidatorDefaultService : BluePrintValidatorService {
     @Throws(BluePrintException::class)\r
     open fun validateInputs(inputs: MutableMap<String, PropertyDefinition>) {\r
         paths.add("inputs")\r
-        message.appendln("---> Input :" + paths.joinToString(seperator))\r
+        message.appendln("---> Input :" + paths.joinToString(separator))\r
         validatePropertyDefinitions(inputs)\r
         paths.removeAt(paths.lastIndex)\r
     }\r
@@ -164,7 +169,7 @@ open class BluePrintValidatorDefaultService : BluePrintValidatorService {
     @Throws(BluePrintException::class)\r
     open fun validateNodeTemplate(nodeTemplateName : String, nodeTemplate: NodeTemplate) {\r
         paths.add(nodeTemplateName)\r
-        message.appendln("---> Node Template :" + paths.joinToString(seperator))\r
+        message.appendln("---> Node Template :" + paths.joinToString(separator))\r
         val type: String = nodeTemplate.type\r
 \r
         val nodeType: NodeType = serviceTemplate.nodeTypes?.get(type)\r
@@ -192,12 +197,12 @@ open class BluePrintValidatorDefaultService : BluePrintValidatorService {
     @Throws(BluePrintException::class)\r
     open fun validateWorkFlow(workflowName:String, workflow: Workflow) {\r
         paths.add(workflowName)\r
-        message.appendln("---> Workflow :" + paths.joinToString(seperator))\r
+        message.appendln("---> Workflow :" + paths.joinToString(separator))\r
         // Step Validation Start\r
         paths.add("steps")\r
         workflow.steps?.forEach { stepName, step ->\r
             paths.add(stepName)\r
-            message.appendln("----> Steps :" + paths.joinToString(seperator))\r
+            message.appendln("----> Steps :" + paths.joinToString(separator))\r
             paths.removeAt(paths.lastIndex)\r
         }\r
         paths.removeAt(paths.lastIndex)\r
@@ -220,7 +225,7 @@ open class BluePrintValidatorDefaultService : BluePrintValidatorService {
             } else {\r
                 checkPropertyDataType(dataType, propertyName)\r
             }\r
-            message.appendln("property " + paths.joinToString(seperator) + " of type " + dataType)\r
+            message.appendln("property " + paths.joinToString(separator) + " of type " + dataType)\r
             paths.removeAt(paths.lastIndex)\r
         }\r
         paths.removeAt(paths.lastIndex)\r
@@ -245,7 +250,7 @@ open class BluePrintValidatorDefaultService : BluePrintValidatorService {
         paths.add("artifacts")\r
         artifacts.forEach { artifactName, artifactDefinition ->\r
             paths.add(artifactName)\r
-            message.appendln("Validating artifact " + paths.joinToString(seperator))\r
+            message.appendln("Validating artifact " + paths.joinToString(separator))\r
             val type: String = artifactDefinition.type\r
                     ?: throw BluePrintException("type is missing for artifact definition :" + artifactName)\r
             // Check Artifact Type\r
@@ -279,7 +284,7 @@ open class BluePrintValidatorDefaultService : BluePrintValidatorService {
         paths.add("interfaces")\r
         interfaces.forEach { interfaceName, interfaceDefinition ->\r
             paths.add(interfaceName)\r
-            message.appendln("Validating : " + paths.joinToString(seperator))\r
+            message.appendln("Validating : " + paths.joinToString(separator))\r
             interfaceDefinition.operations?.let { validateOperationDefinitions(interfaceDefinition.operations!!) }\r
             paths.removeAt(paths.lastIndex)\r
         }\r
@@ -291,7 +296,7 @@ open class BluePrintValidatorDefaultService : BluePrintValidatorService {
         paths.add("operations")\r
         operations.forEach { opertaionName, operationDefinition ->\r
             paths.add(opertaionName)\r
-            message.appendln("Validating : " + paths.joinToString(seperator))\r
+            message.appendln("Validating : " + paths.joinToString(separator))\r
             operationDefinition.implementation?.let { validateImplementation(operationDefinition.implementation!!) }\r
             operationDefinition.inputs?.let { validatePropertyDefinitions(operationDefinition.inputs!!) }\r
             operationDefinition.outputs?.let { validatePropertyDefinitions(operationDefinition.outputs!!) }\r
index 626329a..d71dd20 100644 (file)
@@ -3,6 +3,7 @@
     "template_author": "Brinda Santh ( bs2796@onap.com )",\r
     "template_name": "vrr-test",\r
     "template_version": "1.0.0",\r
+    "template_tags" : "brinda, VRR",\r
     "release": "201802",\r
     "service-type": "AVPN",\r
     "vnf-type": "VRR"\r
index ea46f3a..430401b 100644 (file)
@@ -77,7 +77,7 @@ public class ServiceTemplateValidator extends BluePrintValidatorDefaultService {
     /**\r
      * This is a getMetaData to get the key information during the\r
      *\r
-     * @return Map<String                                                                                                                                                                                                                                                               ,\r
+     * @return Map<String                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               ,\r
                        *       String>\r
      */\r
     public Map<String, String> getMetaData() {\r
@@ -88,18 +88,9 @@ public class ServiceTemplateValidator extends BluePrintValidatorDefaultService {
     public void validateMetadata(@NotNull Map<String, String> metaDataMap) throws BluePrintException {\r
 \r
         Preconditions.checkNotNull(serviceTemplate.getMetadata(), "Service Template Metadata Information is missing.");\r
+        super.validateMetadata(metaDataMap);\r
 \r
         this.metaData.putAll(serviceTemplate.getMetadata());\r
-\r
-        String author = serviceTemplate.getMetadata().get(BluePrintConstants.METADATA_TEMPLATE_AUTHOR);\r
-        String serviceTemplateName =\r
-                serviceTemplate.getMetadata().get(BluePrintConstants.METADATA_TEMPLATE_NAME);\r
-        String serviceTemplateVersion =\r
-                serviceTemplate.getMetadata().get(BluePrintConstants.METADATA_TEMPLATE_VERSION);\r
-\r
-        Preconditions.checkArgument(StringUtils.isNotBlank(author), "Template Metadata (author) Information is missing.");\r
-        Preconditions.checkArgument(StringUtils.isNotBlank(serviceTemplateName), "Template Metadata (service-template-name) Information is missing.");\r
-        Preconditions.checkArgument(StringUtils.isNotBlank(serviceTemplateVersion), "Template Metadata (service-template-version) Information is missing.");\r
     }\r
 \r
 \r
index 50e94df..f846e9a 100644 (file)
@@ -32,7 +32,7 @@ import java.nio.charset.Charset;
 @FixMethodOrder(MethodSorters.NAME_ASCENDING)\r
 public class SchemaGeneratorServiceTest {\r
 \r
-    private static Logger log = LoggerFactory.getLogger(ServiceTemplateValidationTest.class);\r
+    private static Logger log = LoggerFactory.getLogger(SchemaGeneratorServiceTest.class);\r
 \r
     @Test\r
     public void test01GenerateSwaggerData() throws Exception {\r
diff --git a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/common/ServiceTemplateValidationTest.java b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/common/ServiceTemplateValidationTest.java
deleted file mode 100644 (file)
index af309e2..0000000
+++ /dev/null
@@ -1,56 +0,0 @@
-/*\r
- * Copyright © 2017-2018 AT&T Intellectual Property.\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- *     http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-package org.onap.ccsdk.apps.controllerblueprints.service.common;\r
-\r
-\r
-import org.apache.commons.io.IOUtils;\r
-import org.junit.Assert;\r
-import org.junit.Test;\r
-import org.onap.ccsdk.apps.controllerblueprints.service.utils.ConfigModelUtils;\r
-import org.onap.ccsdk.apps.controllerblueprints.service.validator.ServiceTemplateValidator;\r
-import org.slf4j.Logger;\r
-import org.slf4j.LoggerFactory;\r
-\r
-import java.nio.charset.Charset;\r
-import java.util.List;\r
-\r
-public class ServiceTemplateValidationTest {\r
-    private static Logger log = LoggerFactory.getLogger(ServiceTemplateValidationTest.class);\r
-\r
-    @Test\r
-    public void testBluePrintDirs(){\r
-        List<String> dirs = ConfigModelUtils.getBlueprintNames("load/blueprints");\r
-        Assert.assertNotNull("Failed to get blueprint directories", dirs );\r
-        Assert.assertEquals("Failed to get actual directories",2, dirs.size() );\r
-    }\r
-\r
-    // @Test\r
-    public void validateServiceTemplate() {\r
-        try {\r
-            String file = "load/service_template/vrr-201806-test/service-template.json";\r
-            String serviceTemplateContent =\r
-                    IOUtils.toString(ServiceTemplateValidationTest.class.getClassLoader().getResourceAsStream(file),\r
-                            Charset.defaultCharset());\r
-            ServiceTemplateValidator serviceTemplateValidator = new ServiceTemplateValidator();\r
-            serviceTemplateValidator.validateServiceTemplate(serviceTemplateContent);\r
-            log.info("Validated Service Template " + serviceTemplateValidator.getMetaData());\r
-\r
-        } catch (Exception e) {\r
-            e.printStackTrace();\r
-        }\r
-    }\r
-}\r
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
new file mode 100644 (file)
index 0000000..557c6dd
--- /dev/null
@@ -0,0 +1,51 @@
+/*\r
+ *  Copyright © 2017-2018 AT&T Intellectual Property.\r
+ *\r
+ *  Licensed under the Apache License, Version 2.0 (the "License");\r
+ *  you may not use this file except in compliance with the License.\r
+ *  You may obtain a copy of the License at\r
+ *\r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ *  Unless required by applicable law or agreed to in writing, software\r
+ *  distributed under the License is distributed on an "AS IS" BASIS,\r
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ *  See the License for the specific language governing permissions and\r
+ *  limitations under the License.\r
+ */\r
+\r
+package org.onap.ccsdk.apps.controllerblueprints.service.validator;\r
+\r
+\r
+import org.apache.commons.io.FileUtils;\r
+import org.apache.commons.io.IOUtils;\r
+import org.junit.Assert;\r
+import org.junit.Test;\r
+import org.onap.ccsdk.apps.controllerblueprints.service.utils.ConfigModelUtils;\r
+import org.slf4j.Logger;\r
+import org.slf4j.LoggerFactory;\r
+\r
+import java.io.File;\r
+import java.nio.charset.Charset;\r
+import java.util.List;\r
+\r
+public class ServiceTemplateValidationTest {\r
+    private static Logger log = LoggerFactory.getLogger(ServiceTemplateValidationTest.class);\r
+\r
+    @Test\r
+    public void testBluePrintDirs() {\r
+        List<String> dirs = ConfigModelUtils.getBlueprintNames("load/blueprints");\r
+        Assert.assertNotNull("Failed to get blueprint directories", dirs);\r
+        Assert.assertEquals("Failed to get actual directories", 2, dirs.size());\r
+    }\r
+\r
+    @Test\r
+    public void validateServiceTemplate() throws Exception {\r
+        String file = "load/blueprints/baseconfiguration/Definitions/activation-blueprint.json";\r
+        String serviceTemplateContent =\r
+                FileUtils.readFileToString(new File(file), Charset.defaultCharset());\r
+        ServiceTemplateValidator serviceTemplateValidator = new ServiceTemplateValidator();\r
+        serviceTemplateValidator.validateServiceTemplate(serviceTemplateContent);\r
+        Assert.assertNotNull("Failed to validate blueprints", serviceTemplateValidator);\r
+    }\r
+}\r
index 8b4fd9d..a4ba930 100644 (file)
@@ -3,6 +3,7 @@
     "template_author": "Brinda Santh",\r
     "template_name": "enhance-template",\r
     "template_version": "1.0.0",\r
+    "template_tags": "brinda, VPE",\r
     "service-type": "Sample Service",\r
     "release": "1806",\r
     "vnf-type": "VPE"\r
index 18f4992..e003309 100644 (file)
@@ -3,6 +3,7 @@
     "template_author" : "Brinda Santh",\r
     "template_name" : "enhance-template",\r
     "template_version" : "1.0.0",\r
+    "template_tags" : "brinda, VPE",\r
     "service-type" : "Sample Service",\r
     "release" : "1806",\r
     "vnf-type" : "VPE"\r