From 4bbf560bb197d33fc4d8e37d2ad2b0f80bc79299 Mon Sep 17 00:00:00 2001 From: kuldipr Date: Fri, 21 May 2021 09:17:31 -0400 Subject: Create a CBA boilerplate by leveraging the use of maven archetypes 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 Change-Id: Id02f641a37c8f1768226b503c4e18a3a447c05da --- .../blueprint-model/archetype-blueprint/pom.xml | 45 +++++++++++ .../META-INF/maven/archetype-metadata.xml | 61 +++++++++++++++ .../Definitions/test-kotlin.json | 85 +++++++++++++++++++++ .../Scripts/kotlin/ConfigDeploy.kt | 49 ++++++++++++ .../archetype-resources/TOSCA-Metadata/TOSCA.meta | 8 ++ .../functions/netconf/executor/ConfigDeployTest.kt | 88 ++++++++++++++++++++++ .../src/main/resources/archetype-resources/pom.xml | 41 ++++++++++ .../resources/projects/basic/archetype.properties | 4 + components/model-catalog/blueprint-model/pom.xml | 1 + 9 files changed, 382 insertions(+) create mode 100644 components/model-catalog/blueprint-model/archetype-blueprint/pom.xml create mode 100644 components/model-catalog/blueprint-model/archetype-blueprint/src/main/resources/META-INF/maven/archetype-metadata.xml create mode 100644 components/model-catalog/blueprint-model/archetype-blueprint/src/main/resources/archetype-resources/Definitions/test-kotlin.json create mode 100644 components/model-catalog/blueprint-model/archetype-blueprint/src/main/resources/archetype-resources/Scripts/kotlin/ConfigDeploy.kt create mode 100644 components/model-catalog/blueprint-model/archetype-blueprint/src/main/resources/archetype-resources/TOSCA-Metadata/TOSCA.meta create mode 100644 components/model-catalog/blueprint-model/archetype-blueprint/src/main/resources/archetype-resources/Tests/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/ConfigDeployTest.kt create mode 100644 components/model-catalog/blueprint-model/archetype-blueprint/src/main/resources/archetype-resources/pom.xml create mode 100644 components/model-catalog/blueprint-model/archetype-blueprint/src/test/resources/projects/basic/archetype.properties (limited to 'components') 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 index 000000000..a75c03f0a --- /dev/null +++ b/components/model-catalog/blueprint-model/archetype-blueprint/pom.xml @@ -0,0 +1,45 @@ + + + + 4.0.0 + + org.onap.ccsdk.cds.components.cba + archetype-blueprint + 1.0.0-SNAPSHOT + maven-archetype + + Components Model Catalog - Blueprints Model - Archetype Blueprints + CDS Micro-services Archetype CBA + + + + + + maven-archetype-plugin + 3.2.0 + + + + + + org.apache.maven.archetype + archetype-packaging + 3.2.0 + + + + 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 index 000000000..dd756775f --- /dev/null +++ b/components/model-catalog/blueprint-model/archetype-blueprint/src/main/resources/META-INF/maven/archetype-metadata.xml @@ -0,0 +1,61 @@ + + + + + + Tests/kotlin + + **/*.kt + + + + Definitions + + **/*.json + + + + TOSCA-Metadata + + **/*.meta + + + + Scripts/kotlin + + **/*.kt + + + + + + ccsdkapps + + + ccsdkapps + + + org.onap.ccsdk.cds.components.cba + + + test-cba + + + + \ 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 index 000000000..38b3e554f --- /dev/null +++ b/components/model-catalog/blueprint-model/archetype-blueprint/src/main/resources/archetype-resources/Definitions/test-kotlin.json @@ -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 index 000000000..f6a2bdc46 --- /dev/null +++ b/components/model-catalog/blueprint-model/archetype-blueprint/src/main/resources/archetype-resources/Scripts/kotlin/ConfigDeploy.kt @@ -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 index 000000000..19ca83bb1 --- /dev/null +++ b/components/model-catalog/blueprint-model/archetype-blueprint/src/main/resources/archetype-resources/TOSCA-Metadata/TOSCA.meta @@ -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 index 000000000..f98514b56 --- /dev/null +++ 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 @@ -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 = """ + + + Test-Script + + + """.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().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 index 000000000..76cf640d0 --- /dev/null +++ b/components/model-catalog/blueprint-model/archetype-blueprint/src/main/resources/archetype-resources/pom.xml @@ -0,0 +1,41 @@ + + + + 4.0.0 + + + org.onap.ccsdk.cds.components.cba + test-blueprint-kotlin-parent + 1.1.0-SNAPSHOT + + + ${groupId} + ${artifactId} + pom + + + + ${cdsUsername} + ${cdsPassword} + + + 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 index 000000000..95b76b4ba --- /dev/null +++ b/components/model-catalog/blueprint-model/archetype-blueprint/src/test/resources/projects/basic/archetype.properties @@ -0,0 +1,4 @@ +package=it.pkg +version=0.1-SNAPSHOT +groupId=archetype.it +artifactId=basic diff --git a/components/model-catalog/blueprint-model/pom.xml b/components/model-catalog/blueprint-model/pom.xml index 3b139b965..7e277c618 100644 --- a/components/model-catalog/blueprint-model/pom.xml +++ b/components/model-catalog/blueprint-model/pom.xml @@ -32,6 +32,7 @@ Components Model Catalog - Blueprints Model + archetype-blueprint test-blueprint cba-assembly-descriptor test-blueprint-kotlin-parent -- cgit 1.2.3-korg