Create a CBA boilerplate by leveraging the use of maven archetypes 79/121479/4
authorkuldipr <kuldip.rai@amdocs.com>
Fri, 21 May 2021 13:17:31 +0000 (09:17 -0400)
committerKAPIL SINGAL <ks220y@att.com>
Fri, 21 May 2021 17:53:33 +0000 (17:53 +0000)
An archetype is a very simple artifact, that contains the project prototype you wish to create.
Idea here is to provide better user experience when it comes to setup, configuration and testing of CBAs.
With just one maven command 'mvn archetype:generate' use can have boilerplate cba ready to be explored, deployed and published.

Issue-ID: CCSDK-3311
Signed-off-by: kuldipr <kuldip.rai@amdocs.com>
Change-Id: Id02f641a37c8f1768226b503c4e18a3a447c05da

components/model-catalog/blueprint-model/archetype-blueprint/pom.xml [new file with mode: 0644]
components/model-catalog/blueprint-model/archetype-blueprint/src/main/resources/META-INF/maven/archetype-metadata.xml [new file with mode: 0644]
components/model-catalog/blueprint-model/archetype-blueprint/src/main/resources/archetype-resources/Definitions/test-kotlin.json [new file with mode: 0644]
components/model-catalog/blueprint-model/archetype-blueprint/src/main/resources/archetype-resources/Scripts/kotlin/ConfigDeploy.kt [new file with mode: 0644]
components/model-catalog/blueprint-model/archetype-blueprint/src/main/resources/archetype-resources/TOSCA-Metadata/TOSCA.meta [new file with mode: 0644]
components/model-catalog/blueprint-model/archetype-blueprint/src/main/resources/archetype-resources/Tests/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/ConfigDeployTest.kt [new file with mode: 0644]
components/model-catalog/blueprint-model/archetype-blueprint/src/main/resources/archetype-resources/pom.xml [new file with mode: 0644]
components/model-catalog/blueprint-model/archetype-blueprint/src/test/resources/projects/basic/archetype.properties [new file with mode: 0644]
components/model-catalog/blueprint-model/pom.xml

diff --git a/components/model-catalog/blueprint-model/archetype-blueprint/pom.xml b/components/model-catalog/blueprint-model/archetype-blueprint/pom.xml
new file mode 100644 (file)
index 0000000..a75c03f
--- /dev/null
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ Copyright © 2021 Bell Canada
+  ~
+  ~ 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.
+  -->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+
+  <groupId>org.onap.ccsdk.cds.components.cba</groupId>
+  <artifactId>archetype-blueprint</artifactId>
+  <version>1.0.0-SNAPSHOT</version>
+  <packaging>maven-archetype</packaging>
+
+  <name>Components Model Catalog - Blueprints Model - Archetype Blueprints</name>
+  <description>CDS Micro-services Archetype CBA</description>
+
+  <build>
+    <pluginManagement>
+      <plugins>
+        <plugin>
+          <artifactId>maven-archetype-plugin</artifactId>
+          <version>3.2.0</version>
+        </plugin>
+      </plugins>
+    </pluginManagement>
+    <extensions>
+      <extension>
+        <groupId>org.apache.maven.archetype</groupId>
+        <artifactId>archetype-packaging</artifactId>
+        <version>3.2.0</version>
+      </extension>
+    </extensions>
+  </build>
+</project>
diff --git a/components/model-catalog/blueprint-model/archetype-blueprint/src/main/resources/META-INF/maven/archetype-metadata.xml b/components/model-catalog/blueprint-model/archetype-blueprint/src/main/resources/META-INF/maven/archetype-metadata.xml
new file mode 100644 (file)
index 0000000..dd75677
--- /dev/null
@@ -0,0 +1,61 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ Copyright © 2021 Bell Canada
+  ~
+  ~ 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.
+  -->
+<archetype-descriptor xsi:schemaLocation="https://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.1.0 http://maven.apache.org/xsd/archetype-descriptor-1.1.0.xsd" name="archetype-blueprint"
+    xmlns="https://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.1.0"
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+  <fileSets>
+    <fileSet encoding="UTF-8">
+      <directory>Tests/kotlin</directory>
+      <includes>
+        <include>**/*.kt</include>
+      </includes>
+    </fileSet>
+    <fileSet encoding="UTF-8">
+      <directory>Definitions</directory>
+      <includes>
+        <include>**/*.json</include>
+      </includes>
+    </fileSet>
+    <fileSet encoding="UTF-8">
+      <directory>TOSCA-Metadata</directory>
+      <includes>
+        <include>**/*.meta</include>
+      </includes>
+    </fileSet>
+    <fileSet encoding="UTF-8">
+      <directory>Scripts/kotlin</directory>
+      <includes>
+        <include>**/*.kt</include>
+      </includes>
+    </fileSet>
+  </fileSets>
+  <requiredProperties>
+    <requiredProperty key="cdsUsername">
+      <defaultValue>ccsdkapps</defaultValue>
+    </requiredProperty>
+     <requiredProperty key="cdsPassword">
+      <defaultValue>ccsdkapps</defaultValue>
+    </requiredProperty>
+    <requiredProperty key="groupId">
+      <defaultValue>org.onap.ccsdk.cds.components.cba</defaultValue>
+    </requiredProperty>
+    <requiredProperty key="artifactId">
+      <defaultValue>test-cba</defaultValue>
+    </requiredProperty>
+  </requiredProperties>
+  
+</archetype-descriptor>
\ No newline at end of file
diff --git a/components/model-catalog/blueprint-model/archetype-blueprint/src/main/resources/archetype-resources/Definitions/test-kotlin.json b/components/model-catalog/blueprint-model/archetype-blueprint/src/main/resources/archetype-resources/Definitions/test-kotlin.json
new file mode 100644 (file)
index 0000000..38b3e55
--- /dev/null
@@ -0,0 +1,85 @@
+{
+  "metadata": {
+    "template_author": "Selffish",
+    "author-email": "test@bell.ca",
+    "template_name": "RT-test-kotlin",
+    "template_version": "1.0.0",
+    "template_tags": "ONAP, CDS, CBA, test"
+  },
+  "topology_template": {
+    "workflows": {
+      "netconf-kotlin": {
+        "steps": {
+          "netconf-kotlin": {
+            "description": "deploy config",
+            "target": "execute-kotlin-netconf"
+          }
+        },
+        "inputs": {
+          "netconf-host": {
+            "required": true,
+            "type": "string"
+          },
+          "netconf-timeout": {
+            "required": true,
+            "type": "string"
+          }
+        },
+        "outputs": {
+          "response-data": {
+            "type": "string",
+            "value": {
+              "get_attribute": [
+                "execute-kotlin-netconf",
+                "response-data"
+              ]
+            }
+          }
+        }
+      }
+    },
+    "node_templates": {
+      "execute-kotlin-netconf" : {
+        "type" : "component-netconf-executor",
+        "requirements" : {
+          "netconf-connection" : {
+            "capability" : "netconf",
+            "node" : "netconf-device",
+            "relationship" : "tosca.relationships.ConnectsTo"
+          }
+        },
+        "interfaces" : {
+          "ComponentNetconfExecutor" : {
+            "operations" : {
+              "process" : {
+                "inputs" : {
+                  "script-type" : "kotlin",
+                  "script-class-reference" : "org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor.ConfigDeploy",
+                  "instance-dependencies" : [ ]
+                }
+              }
+            }
+          }
+        }
+      },
+      "netconf-device": {
+        "type": "vnf-netconf-device",
+        "capabilities": {
+          "netconf": {
+            "properties": {
+              "login-key": "password",
+              "login-account": "admin",
+              "target-ip-address": {
+                "get_input": "netconf-host"
+              },
+              "port-number" : 17830,
+              "connection-time-out" : {
+                "get_input": "netconf-timeout"
+              }
+            }
+          }
+        }
+      }
+    }
+  }
+}
diff --git a/components/model-catalog/blueprint-model/archetype-blueprint/src/main/resources/archetype-resources/Scripts/kotlin/ConfigDeploy.kt b/components/model-catalog/blueprint-model/archetype-blueprint/src/main/resources/archetype-resources/Scripts/kotlin/ConfigDeploy.kt
new file mode 100644 (file)
index 0000000..f6a2bdc
--- /dev/null
@@ -0,0 +1,49 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - CCSDK
+ * ================================================================================
+ * Copyright (C) 2021 Bell Canada
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor
+
+import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput
+import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.storedContentFromResolvedArtifactNB
+import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.AbstractScriptComponentFunction
+import org.slf4j.LoggerFactory
+
+open class ConfigDeploy : AbstractScriptComponentFunction() {
+
+    private val log = LoggerFactory.getLogger(ConfigDeploy::class.java)!!
+
+    override suspend fun processNB(executionRequest: ExecutionServiceInput) {
+        val netconfDevice = netconfDevice("netconf-connection")
+        val netconfRpcService = netconfDevice.netconfRpcService
+        val session = netconfDevice.netconfSession
+
+        val payload = storedContentFromResolvedArtifactNB("my-resolution-key", "create")
+
+        session.connect()
+        netconfRpcService.lock()
+        netconfRpcService.editConfig(payload)
+        netconfRpcService.commit()
+        netconfRpcService.unLock()
+        session.disconnect()
+    }
+
+    override suspend fun recoverNB(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) {
+        log.info("Executing Recovery")
+    }
+}
diff --git a/components/model-catalog/blueprint-model/archetype-blueprint/src/main/resources/archetype-resources/TOSCA-Metadata/TOSCA.meta b/components/model-catalog/blueprint-model/archetype-blueprint/src/main/resources/archetype-resources/TOSCA-Metadata/TOSCA.meta
new file mode 100644 (file)
index 0000000..19ca83b
--- /dev/null
@@ -0,0 +1,8 @@
+TOSCA-Meta-File-Version: 1.0.0
+CSAR-Version: 1.0
+Created-By: Selffish
+Entry-Definitions: Definitions/test-kotlin.json
+Template-Tags: test, regression
+Template-Name: RT-test-kotlin
+Template-Version: 1.0.0
+Template-Type: DEFAULT
diff --git a/components/model-catalog/blueprint-model/archetype-blueprint/src/main/resources/archetype-resources/Tests/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/ConfigDeployTest.kt b/components/model-catalog/blueprint-model/archetype-blueprint/src/main/resources/archetype-resources/Tests/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/ConfigDeployTest.kt
new file mode 100644 (file)
index 0000000..f98514b
--- /dev/null
@@ -0,0 +1,88 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - CCSDK
+ * ================================================================================
+ * Copyright (C) 2021 Bell Canada
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor
+
+import io.mockk.coEvery
+import io.mockk.coVerify
+import io.mockk.every
+import io.mockk.mockk
+import io.mockk.mockkStatic
+import io.mockk.verifySequence
+import kotlinx.coroutines.runBlocking
+import org.junit.Before
+import org.junit.Test
+import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput
+import org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor.api.NetconfSession
+import org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor.core.NetconfRpcServiceImpl
+import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.storedContentFromResolvedArtifactNB
+
+class ConfigDeployTest {
+
+    private lateinit var unitUnderTest: ConfigDeploy
+    private lateinit var netconfSession: NetconfSession
+    private lateinit var netconfRpcService: NetconfRpcServiceImpl
+
+    private val payload = """
+            <configuration xmlns:junos="http://xml.juniper.net/junos/17.4R1/junos">
+            <system xmlns="http://yang.juniper.net/junos-qfx/conf/system">
+                <host-name operation="create">Test-Script</host-name>
+            </system>
+            </configuration>
+    """.trimIndent()
+
+    @Before
+    fun setup() {
+        // This will stub the extension functions
+        mockkStatic("org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.ResourceResolutionExtensionsKt")
+        mockkStatic("org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor.NetconfExecutorExtensionsKt")
+
+        unitUnderTest = ConfigDeploy()
+
+        // Mock return values
+        coEvery {
+            unitUnderTest.storedContentFromResolvedArtifactNB("my-resolution-key", "create")
+        }.returns(payload)
+
+        mockk<NetconfDevice>().let {
+            netconfSession = mockk(relaxed = true)
+            netconfRpcService = mockk(relaxed = true)
+            every { it.netconfSession }.returns(netconfSession)
+            every { it.netconfRpcService }.returns(netconfRpcService)
+            every { unitUnderTest.netconfDevice("netconf-connection") }.returns(it)
+        }
+    }
+
+    @Test
+    fun `should retrieve stored payload then connect and send to device`() {
+        runBlocking { unitUnderTest.processNB(ExecutionServiceInput()) }
+
+        coVerify {
+            unitUnderTest.storedContentFromResolvedArtifactNB("my-resolution-key", "create")
+        }
+        verifySequence {
+            netconfSession.connect()
+            netconfRpcService.lock()
+            netconfRpcService.editConfig(payload)
+            netconfRpcService.commit()
+            netconfRpcService.unLock()
+            netconfSession.disconnect()
+        }
+    }
+}
diff --git a/components/model-catalog/blueprint-model/archetype-blueprint/src/main/resources/archetype-resources/pom.xml b/components/model-catalog/blueprint-model/archetype-blueprint/src/main/resources/archetype-resources/pom.xml
new file mode 100644 (file)
index 0000000..76cf640
--- /dev/null
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ Copyright © 2021 Bell Canada
+  ~
+  ~ 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.
+  -->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>org.onap.ccsdk.cds.components.cba</groupId>
+        <artifactId>test-blueprint-kotlin-parent</artifactId>
+        <version>1.1.0-SNAPSHOT</version>
+    </parent>
+
+    <groupId>${groupId}</groupId>
+    <artifactId>${artifactId}</artifactId>
+    <packaging>pom</packaging>
+
+    <properties>
+        <!-- Properties for -Pdeploy-cba, these can be overridden if needed -->
+        <cds.username>${cdsUsername}</cds.username>
+        <cds.password>${cdsPassword}</cds.password>
+        <!--cds.protocol>http</cds.protocol>
+        <cds.host>localhost</cds.host>
+        <cds.port>8081</cds.port>
+        <cds.enrich.endpoint>api/v1/blueprint-model/enrich</cds.enrich.endpoint>
+        <cds.publish.endpoint>api/v1/blueprint-model/publish</cds.publish.endpoint>
+        -->
+    </properties>
+</project>
diff --git a/components/model-catalog/blueprint-model/archetype-blueprint/src/test/resources/projects/basic/archetype.properties b/components/model-catalog/blueprint-model/archetype-blueprint/src/test/resources/projects/basic/archetype.properties
new file mode 100644 (file)
index 0000000..95b76b4
--- /dev/null
@@ -0,0 +1,4 @@
+package=it.pkg
+version=0.1-SNAPSHOT
+groupId=archetype.it
+artifactId=basic
index 3b139b9..7e277c6 100644 (file)
@@ -32,6 +32,7 @@
     <name>Components Model Catalog - Blueprints Model</name>
 
     <modules>
+        <module>archetype-blueprint</module>
         <module>test-blueprint</module>
         <module>cba-assembly-descriptor</module>
         <module>test-blueprint-kotlin-parent</module>