From fb0b3dc943bca0346271e0889ff2e7dbf3c77eeb Mon Sep 17 00:00:00 2001 From: Jozsef Csongvai Date: Tue, 11 Aug 2020 16:17:55 -0400 Subject: Add test-blueprint-kotlin-parent This parent project is intended for inheritence in CBA pom.xml. It provides dependencies for testing and mocking kotlin scripts. By turning a CBA into a maven project which inherits this parent, users will be able to debug and unit test their kotlin scripts. The parent also includes a profile (-Pdeploy-cba) which will enrich and publish the CBA to a running instance of CDS, defined by properties in the CBA pom.xml. This patch also adds a common assembly descriptor for resuse in maven-assembly-plugin where it is used to package CBA into zip. Issue-ID: CCSDK-2642 Signed-off-by: Jozsef Csongvai Change-Id: I160c3c3e982ad4ed46f0704d6dc27dadfb0dfdc8 --- .../cba-assembly-descriptor/pom.xml | 11 + .../src/main/resources/assemblies/cba_zip.xml | 43 +++ components/model-catalog/blueprint-model/pom.xml | 2 + .../test-blueprint-kotlin-parent/pom.xml | 393 +++++++++++++++++++++ .../capability_cli/Distribution/cba_zip.xml | 43 --- .../test-blueprint/capability_cli/pom.xml | 13 +- .../resource-audit/Distribution/cba_zip.xml | 43 --- .../test-blueprint/resource-audit/pom.xml | 13 +- 8 files changed, 469 insertions(+), 92 deletions(-) create mode 100644 components/model-catalog/blueprint-model/cba-assembly-descriptor/pom.xml create mode 100644 components/model-catalog/blueprint-model/cba-assembly-descriptor/src/main/resources/assemblies/cba_zip.xml create mode 100644 components/model-catalog/blueprint-model/test-blueprint-kotlin-parent/pom.xml delete mode 100755 components/model-catalog/blueprint-model/test-blueprint/capability_cli/Distribution/cba_zip.xml delete mode 100755 components/model-catalog/blueprint-model/test-blueprint/resource-audit/Distribution/cba_zip.xml (limited to 'components') diff --git a/components/model-catalog/blueprint-model/cba-assembly-descriptor/pom.xml b/components/model-catalog/blueprint-model/cba-assembly-descriptor/pom.xml new file mode 100644 index 000000000..e918cc214 --- /dev/null +++ b/components/model-catalog/blueprint-model/cba-assembly-descriptor/pom.xml @@ -0,0 +1,11 @@ + + + 4.0.0 + org.onap.ccsdk.cds.blueprintsprocessor + cba-assembly-descriptor + 1.0.0-SNAPSHOT + CBA - Assembly Sescriptor + Shared assembly descriptor + \ No newline at end of file diff --git a/components/model-catalog/blueprint-model/cba-assembly-descriptor/src/main/resources/assemblies/cba_zip.xml b/components/model-catalog/blueprint-model/cba-assembly-descriptor/src/main/resources/assemblies/cba_zip.xml new file mode 100644 index 000000000..71a3c8d44 --- /dev/null +++ b/components/model-catalog/blueprint-model/cba-assembly-descriptor/src/main/resources/assemblies/cba_zip.xml @@ -0,0 +1,43 @@ + + + + + + cba + + zip + + false + + + ${project.basedir} + + Definitions/** + Distribution/** + Environments/** + Plans/** + Others/** + Scripts/** + Templates/** + TOSCA-Metadata/** + pom.xml + + + + \ No newline at end of file diff --git a/components/model-catalog/blueprint-model/pom.xml b/components/model-catalog/blueprint-model/pom.xml index 7eaeda290..1ea99fa99 100644 --- a/components/model-catalog/blueprint-model/pom.xml +++ b/components/model-catalog/blueprint-model/pom.xml @@ -35,5 +35,7 @@ test-blueprint + cba-assembly-descriptor + test-blueprint-kotlin-parent diff --git a/components/model-catalog/blueprint-model/test-blueprint-kotlin-parent/pom.xml b/components/model-catalog/blueprint-model/test-blueprint-kotlin-parent/pom.xml new file mode 100644 index 000000000..1459531ec --- /dev/null +++ b/components/model-catalog/blueprint-model/test-blueprint-kotlin-parent/pom.xml @@ -0,0 +1,393 @@ + + + + + 4.0.0 + + + org.onap.ccsdk.cds.blueprintsprocessor + cba-parent + 1.0.0-SNAPSHOT + + + test-blueprint-kotlin-parent + 1.0.0-SNAPSHOT + pom + + CBA - Test Kotlin scripts + CBA - Test Kotlin scripts + + + + org.onap.ccsdk.cds.blueprintsprocessor + execution-service + + + org.onap.ccsdk.cds.blueprintsprocessor.functions + resource-resolution + + + org.onap.ccsdk.cds.blueprintsprocessor.functions + netconf-executor + + + org.onap.ccsdk.cds.blueprintsprocessor.functions + cli-executor + + + org.onap.ccsdk.cds.blueprintsprocessor.functions + message-prioritizaion + + + org.jetbrains.kotlin + kotlin-stdlib + + + org.jetbrains.kotlin + kotlin-test-junit + test + + + org.jetbrains.kotlinx + kotlinx-coroutines-test + test + + + + junit + junit + 4.12 + test + + + io.mockk + mockk + 1.10.0 + test + + + com.squareup.okhttp3 + okhttp + 3.14.0 + + + + + ${project.basedir}/Scripts/kotlin + ${project.basedir}/Tests/kotlin + + + ${project.basedir}/Environments + + + + + maven-antrun-plugin + + + validate-kotlin + validate + + + + + + + ${format.skipValidate} + + + run + + + + + format-kotlin + process-sources + + + + + + + + ${format.skipExecute} + + + run + + + + + + org.jacoco + jacoco-maven-plugin + + + pre-unit-test + none + + + default-prepare-agent + none + + + post-unit-test + none + + + default-report + none + + + pre-integration-test + none + + + post-integration-test + none + + + default-check + none + + + + + org.apache.maven.plugins + maven-failsafe-plugin + + + default + none + + + integration-tests + none + + + + + org.jetbrains.kotlin + kotlin-maven-plugin + ${kotlin.maven.version} + + + compile + compile + + compile + + + + ${project.basedir}/Scripts/kotlin + + + + + test-compile + test-compile + + test-compile + + + + ${project.basedir}/Tests/kotlin + + + + + + + maven-surefire-plugin + + + default-test + test + + test + + + + + + org.apache.maven.plugins + maven-site-plugin + + + attach-descriptor + none + + + + + maven-checkstyle-plugin + + + check-license + none + + + check-style + none + + + + + maven-assembly-plugin + + + org.onap.ccsdk.cds.blueprintsprocessor + cba-assembly-descriptor + 1.0.0-SNAPSHOT + + + + + make-assembly + package + + single + + + + cba_zip + + + + + + + + + + + deploy-cba + + + + org.codehaus.gmaven + groovy-maven-plugin + + + com.squareup.okhttp3 + okhttp + 3.14.0 + + + commons-io + commons-io + ${commons-io-version} + + + + + deploy-cba + install + + execute + + + + import okhttp3.Credentials + import okhttp3.MediaType + import okhttp3.MultipartBody + import okhttp3.OkHttpClient + import okhttp3.Request + import okhttp3.RequestBody + import org.apache.commons.io.IOUtils + + import java.io.File + + target = "${basedir.absolutePath}/target" + userName = throwIfPropMissing('cds.username') + password = throwIfPropMissing('cds.password') + protocol = properties['cds.protocol'] ?: 'http' + host = properties['cds.host'] ?: 'localhost' + port = properties['cds.port'] ?: '8081' + + def cba = "${project.artifact.artifactId}-${project.artifact.version}-cba.zip" + def enrichedCba = "${project.artifact.artifactId}-${project.artifact.version}-enriched-cba.zip" + def enrichEndpoint = properties['cds.enrich.endpoint'] ?: 'api/v1/blueprint-model/enrich' + def publishEndpoint = properties['cds.publish.endpoint'] ?: 'api/v1/blueprint-model/publish' + + def throwIfPropMissing(prop) { + value = properties[prop] + if (!value || "".equals(value)) { + throw new RuntimeException("Property missing: $prop") + } + return value + } + + def buildRequest(endpoint, fileName) { + body = new MultipartBody.Builder() + .setType(MultipartBody.FORM) + .addFormDataPart("file", + fileName, + RequestBody.create(MediaType.parse('application/zip'), new File(target, fileName))) + .build() + + return new Request.Builder() + .url("$protocol://$host:$port/$endpoint") + .addHeader('Authorization', Credentials.basic(userName, password)) + .post(body) + .build() + } + + def logAndThrow(msg) { + if(response) { + log.error(response.body().string()) + } + throw new RuntimeException(msg) + } + + response = null + try { + def client = new OkHttpClient() + + response = client.newCall(buildRequest(enrichEndpoint, cba)).execute() + if (!response || !response.isSuccessful()) { + logAndThrow("Failed to enrich CBA") + } + + IOUtils.copy( + response.body().byteStream(), + new FileOutputStream(new File(target, enrichedCba)) + ) + log.info("Created enriched cba: $enrichedCba") + + response = client.newCall(buildRequest(publishEndpoint, enrichedCba)).execute() + if (!response || !response.isSuccessful()) { + logAndThrow("Failed to publish CBA") + } + + log.info("CBA Deployed") + log.info(response.body().string()) + } finally { + if (response) { + response.close() + } + } + + + + + + + + + + diff --git a/components/model-catalog/blueprint-model/test-blueprint/capability_cli/Distribution/cba_zip.xml b/components/model-catalog/blueprint-model/test-blueprint/capability_cli/Distribution/cba_zip.xml deleted file mode 100755 index c6c3bde71..000000000 --- a/components/model-catalog/blueprint-model/test-blueprint/capability_cli/Distribution/cba_zip.xml +++ /dev/null @@ -1,43 +0,0 @@ - - - - - - cba - - zip - - false - - - ${project.basedir} - - Definitions/** - Distribution/** - Environments/** - Plans/** - Others/** - Scripts/** - Templates/** - TOSCA-Metadata/** - pom.xml - - - - \ No newline at end of file diff --git a/components/model-catalog/blueprint-model/test-blueprint/capability_cli/pom.xml b/components/model-catalog/blueprint-model/test-blueprint/capability_cli/pom.xml index f2f51964b..c3138da4e 100644 --- a/components/model-catalog/blueprint-model/test-blueprint/capability_cli/pom.xml +++ b/components/model-catalog/blueprint-model/test-blueprint/capability_cli/pom.xml @@ -41,6 +41,13 @@ maven-assembly-plugin + + + org.onap.ccsdk.cds.blueprintsprocessor + cba-assembly-descriptor + 1.0.0-SNAPSHOT + + 3.1.0 @@ -51,9 +58,9 @@ false - - Distribution/cba_zip.xml - + + cba_zip + diff --git a/components/model-catalog/blueprint-model/test-blueprint/resource-audit/Distribution/cba_zip.xml b/components/model-catalog/blueprint-model/test-blueprint/resource-audit/Distribution/cba_zip.xml deleted file mode 100755 index c6c3bde71..000000000 --- a/components/model-catalog/blueprint-model/test-blueprint/resource-audit/Distribution/cba_zip.xml +++ /dev/null @@ -1,43 +0,0 @@ - - - - - - cba - - zip - - false - - - ${project.basedir} - - Definitions/** - Distribution/** - Environments/** - Plans/** - Others/** - Scripts/** - Templates/** - TOSCA-Metadata/** - pom.xml - - - - \ No newline at end of file diff --git a/components/model-catalog/blueprint-model/test-blueprint/resource-audit/pom.xml b/components/model-catalog/blueprint-model/test-blueprint/resource-audit/pom.xml index 21d9b8df5..3cc08222d 100644 --- a/components/model-catalog/blueprint-model/test-blueprint/resource-audit/pom.xml +++ b/components/model-catalog/blueprint-model/test-blueprint/resource-audit/pom.xml @@ -43,6 +43,13 @@ maven-assembly-plugin 3.1.0 + + + org.onap.ccsdk.cds.blueprintsprocessor + cba-assembly-descriptor + 1.0.0-SNAPSHOT + + cba @@ -52,9 +59,9 @@ false - - Distribution/cba_zip.xml - + + cba_zip + -- cgit 1.2.3-korg