CCSDK-3472 Maven plugin support of velocity for CBA package creation in IDE 97/128197/2
authorRudrangi Anupriya <ra00745022@techmahindra.com>
Wed, 30 Mar 2022 10:44:10 +0000 (16:14 +0530)
committerDan Timoney <dtimoney@att.com>
Fri, 1 Apr 2022 12:35:28 +0000 (12:35 +0000)
Change-Id: I873be858c44b3ca36f4e292e44a483a2af6e83f1
Signed-off-by: Rudrangi Anupriya <ra00745022@techmahindra.com>
Issue-ID: CCSDK-3472

components/model-catalog/blueprint-model/archetype-blueprint/src/main/resources/archetype-resources/Templates/base-config-data-velocity.json [new file with mode: 0644]
components/model-catalog/blueprint-model/archetype-blueprint/src/main/resources/archetype-resources/Templates/base-config-velocity-template.vtl [new file with mode: 0644]
components/model-catalog/blueprint-model/archetype-blueprint/src/main/resources/archetype-resources/Templates/default-variable-value-data.json [new file with mode: 0644]
components/model-catalog/blueprint-model/archetype-blueprint/src/main/resources/archetype-resources/Templates/default-variable-value-velocity-template.vtl [new file with mode: 0644]
components/model-catalog/blueprint-model/archetype-blueprint/src/main/resources/archetype-resources/Tests/default-variable-value-data.txt [new file with mode: 0644]
components/model-catalog/blueprint-model/archetype-blueprint/src/main/resources/archetype-resources/Tests/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BlueprintVelocityTemplateTest.kt [new file with mode: 0644]

diff --git a/components/model-catalog/blueprint-model/archetype-blueprint/src/main/resources/archetype-resources/Templates/base-config-data-velocity.json b/components/model-catalog/blueprint-model/archetype-blueprint/src/main/resources/archetype-resources/Templates/base-config-data-velocity.json
new file mode 100644 (file)
index 0000000..2acc6fc
--- /dev/null
@@ -0,0 +1,36 @@
+{
+       "node0_hostname": "sdnc-host",
+       "node0_backup_router_address": "2001:1890:1253::192:168:100:1",
+       "servers": [
+               "Server1",
+               "Server2",
+               "Server3"
+       ],
+       "tacplus-servers": [
+               {
+                       "tacplus-server-name": "tacplus-server-name1",
+                       "tacplus-server-source-address": "enc-dsdsasa1"
+               },
+               {
+                       "tacplus-server-name": "tacplus-server-name2",
+                       "tacplus-server-source-address": "enc-dsdsasa2"
+               }
+       ],
+       "classes": [
+               {
+                       "name": "superuser-class",
+                       "idle-timeout": 5,
+                       "permissions": "all"
+               },
+               {
+                       "name": "tacacs-adv-class",
+                       "idle-timeout": 5
+               },
+               {
+                       "name": "tacacs-base-class",
+                       "idle-timeout": 5
+               }
+       ],
+       "system-password": "teamops-system-password",
+       "root-password": "teamops-root-password"
+}
diff --git a/components/model-catalog/blueprint-model/archetype-blueprint/src/main/resources/archetype-resources/Templates/base-config-velocity-template.vtl b/components/model-catalog/blueprint-model/archetype-blueprint/src/main/resources/archetype-resources/Templates/base-config-velocity-template.vtl
new file mode 100644 (file)
index 0000000..f7b1269
--- /dev/null
@@ -0,0 +1,61 @@
+<configuration xmlns="http://xml.juniper.net/xnm/1.1/xnm"
+xmlns:a="http://xml.juniper.net/junos/15.1X49/junos">
+       <version>15.1X49-D50.3</version>        
+       <groups>
+               <name>node0</name>
+               <system>
+               #foreach($server in ${servers})
+                       <server-host-name>$StringUtils.upperCase("$server")</server-host-name>
+               #end
+               </system>
+               <system>
+                       <host-name>${node0_hostname}</host-name>
+                       <backup-router>
+                               <address>${node0_backup_router_address}</address>
+                               <destination>$node0_backup_router_address</destination>
+                       </backup-router>
+                       #foreach($tacplus-server in ${tacplus-servers})
+                       <tacplus-server>
+                               <name>$tacplus-server.tacplus-server-name</name>
+                               <source-address>$tacplus-server.tacplus-server-source-address</source-address>
+                       </tacplus-server>
+                       #end
+                       <login>
+                               <message>ONAP information assets</message>
+                               #foreach($class in ${classes})
+                               <class>
+                                       <name>$class.name</name>
+                                       <idle-timeout>$class.idle-timeout</idle-timeout>
+                                       #if ($class.permissions)
+                                       <permissions>$class.permissions</permissions>
+                                       #end
+                               </class>
+                               #end    
+                               <user>
+                                       <name>readonly</name>
+                                       <full-name>Read Only Account Access</full-name>
+                                       <uid>1001</uid>
+                                       <class>tacacs-base-class</class>
+                               </user>
+                               <user>
+                                       <name>readwrite</name>
+                                       <full-name>Read - Write Account Access</full-name>
+                                       <uid>1002</uid>
+                                       <class>tacacs-adv-class</class>
+                                       <authentication>
+                                               <encrypted-password>${system-password}</encrypted-password>
+                                       </authentication>
+                               </user>
+                               <user>
+                                       <name>readwrite</name>
+                                       <full-name>Emergency Access Only</full-name>
+                                       <uid>1000</uid>
+                                       <class>superuser-class</class>
+                                       <authentication>
+                                               <encrypted-password>${root-password}</encrypted-password>
+                                       </authentication>
+                               </user>
+                       </login>
+               </system>               
+       </groups>       
+</configuration>
\ No newline at end of file
diff --git a/components/model-catalog/blueprint-model/archetype-blueprint/src/main/resources/archetype-resources/Templates/default-variable-value-data.json b/components/model-catalog/blueprint-model/archetype-blueprint/src/main/resources/archetype-resources/Templates/default-variable-value-data.json
new file mode 100644 (file)
index 0000000..46e793a
--- /dev/null
@@ -0,0 +1,3 @@
+{
+   "node0_hostname": "sample-hostname"
+}
diff --git a/components/model-catalog/blueprint-model/archetype-blueprint/src/main/resources/archetype-resources/Templates/default-variable-value-velocity-template.vtl b/components/model-catalog/blueprint-model/archetype-blueprint/src/main/resources/archetype-resources/Templates/default-variable-value-velocity-template.vtl
new file mode 100644 (file)
index 0000000..ce2458e
--- /dev/null
@@ -0,0 +1,2 @@
+$node0_hostname
+${node0_backup_router_address}
\ No newline at end of file
diff --git a/components/model-catalog/blueprint-model/archetype-blueprint/src/main/resources/archetype-resources/Tests/default-variable-value-data.txt b/components/model-catalog/blueprint-model/archetype-blueprint/src/main/resources/archetype-resources/Tests/default-variable-value-data.txt
new file mode 100644 (file)
index 0000000..f2359e8
--- /dev/null
@@ -0,0 +1,2 @@
+sample-hostname
+${node0_backup_router_address}
\ No newline at end of file
diff --git a/components/model-catalog/blueprint-model/archetype-blueprint/src/main/resources/archetype-resources/Tests/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BlueprintVelocityTemplateTest.kt b/components/model-catalog/blueprint-model/archetype-blueprint/src/main/resources/archetype-resources/Tests/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BlueprintVelocityTemplateTest.kt
new file mode 100644 (file)
index 0000000..56d23a2
--- /dev/null
@@ -0,0 +1,72 @@
+/*-\r
+ * ============LICENSE_START=======================================================\r
+ * ONAP - CCSDK\r
+ * ================================================================================\r
+ * Copyright (C) 2022 Tech Mahindra\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
+ * ============LICENSE_END=========================================================\r
+ */\r
+package org.onap.ccsdk.cds.controllerblueprints.core.service\r
+\r
+import kotlinx.coroutines.runBlocking\r
+import org.junit.Test\r
+import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintVelocityTemplateService\r
+import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils\r
+import kotlin.test.BeforeTest\r
+import java.io.File\r
+import java.util.*\r
+import kotlin.test.assertEquals\r
+import kotlin.test.assertNotNull\r
+\r
+\r
+class BlueprintVelocityTemplateTest {\r
+    private val velocityHome = System.getenv("velocity_path")\r
+\r
+\r
+    @BeforeTest\r
+    fun setup() {\r
+        val properties = Properties()\r
+        properties["file.resource.loader.path"] = velocityHome\r
+    }\r
+    @Test\r
+    fun testVelocityGeneratedContent() {\r
+        runBlocking {\r
+            val template = JacksonUtils.getContent("Templates/base-config-velocity-template.vtl")\r
+            val json = JacksonUtils.getContent("Templates/base-config-data-velocity.json")\r
+            val content = BluePrintVelocityTemplateService.generateContent(template, json)\r
+            assertNotNull(content, "failed to generate content for velocity template")\r
+        }\r
+    }\r
+    @Test\r
+    fun `no value variable should evaluate to default value - standalone template mesh test`() {\r
+        runBlocking {\r
+            val template = JacksonUtils.getContent("Templates/default-variable-value-velocity-template.vtl")\r
+            val json = JacksonUtils.getContent("Templates/default-variable-value-data.json")\r
+            val content = BluePrintVelocityTemplateService.generateContent(template, json)\r
+            val expected = "sample-hostname\n\${node0_backup_router_address}"\r
+            assertEquals(expected, content, "No value variable should use default value")\r
+        }\r
+    }\r
+    @Test\r
+    fun `Expected value variable from file`() {\r
+        runBlocking {\r
+            val template = JacksonUtils.getContent("Templates/default-variable-value-velocity-template.vtl")\r
+            val json = JacksonUtils.getContent("Templates/default-variable-value-data.json")\r
+            val content = BluePrintVelocityTemplateService.generateContent(template, json)\r
+            val expected = File("Tests/kotlin/default-variable-value-data.txt").readText()\r
+            assertEquals(expected, content, "expected value variable from file")\r
+        }\r
+\r
+    }\r
+}
\ No newline at end of file