diff options
14 files changed, 753 insertions, 55 deletions
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..5a2432953 --- /dev/null +++ b/components/model-catalog/blueprint-model/cba-assembly-descriptor/pom.xml @@ -0,0 +1,27 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + ~ Copyright © 2020 AT&T. + ~ + ~ 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.blueprintsprocessor</groupId> + <artifactId>cba-assembly-descriptor</artifactId> + <version>1.0.0-SNAPSHOT</version> + + <name>CBA - Assembly Sescriptor</name> + <description>Shared assembly descriptor</description> +</project>
\ No newline at end of file diff --git a/components/model-catalog/blueprint-model/test-blueprint/capability_cli/Distribution/cba_zip.xml b/components/model-catalog/blueprint-model/cba-assembly-descriptor/src/main/resources/assemblies/cba_zip.xml index c6c3bde71..c6c3bde71 100755..100644 --- a/components/model-catalog/blueprint-model/test-blueprint/capability_cli/Distribution/cba_zip.xml +++ b/components/model-catalog/blueprint-model/cba-assembly-descriptor/src/main/resources/assemblies/cba_zip.xml 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 @@ <modules> <module>test-blueprint</module> + <module>cba-assembly-descriptor</module> + <module>test-blueprint-kotlin-parent</module> </modules> </project> 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..de321f86f --- /dev/null +++ b/components/model-catalog/blueprint-model/test-blueprint-kotlin-parent/pom.xml @@ -0,0 +1,393 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + ~ Copyright © 2020 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.cba</groupId> + <artifactId>blueprint-model</artifactId> + <version>1.0.0-SNAPSHOT</version> + </parent> + + <artifactId>test-blueprint-kotlin-parent</artifactId> + <version>1.0.0-SNAPSHOT</version> + <packaging>pom</packaging> + + <name>CBA - Test Kotlin scripts</name> + <description>CBA - Test Kotlin scripts</description> + + <dependencies> + <dependency> + <groupId>org.onap.ccsdk.cds.blueprintsprocessor</groupId> + <artifactId>execution-service</artifactId> + </dependency> + <dependency> + <groupId>org.onap.ccsdk.cds.blueprintsprocessor.functions</groupId> + <artifactId>resource-resolution</artifactId> + </dependency> + <dependency> + <groupId>org.onap.ccsdk.cds.blueprintsprocessor.functions</groupId> + <artifactId>netconf-executor</artifactId> + </dependency> + <dependency> + <groupId>org.onap.ccsdk.cds.blueprintsprocessor.functions</groupId> + <artifactId>cli-executor</artifactId> + </dependency> + <dependency> + <groupId>org.onap.ccsdk.cds.blueprintsprocessor.functions</groupId> + <artifactId>message-prioritizaion</artifactId> + </dependency> + <dependency> + <groupId>org.jetbrains.kotlin</groupId> + <artifactId>kotlin-stdlib</artifactId> + </dependency> + <dependency> + <groupId>org.jetbrains.kotlin</groupId> + <artifactId>kotlin-test-junit</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.jetbrains.kotlinx</groupId> + <artifactId>kotlinx-coroutines-test</artifactId> + <scope>test</scope> + </dependency> + + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>4.12</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>io.mockk</groupId> + <artifactId>mockk</artifactId> + <version>1.10.0</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>com.squareup.okhttp3</groupId> + <artifactId>okhttp</artifactId> + <version>3.14.0</version> + </dependency> + </dependencies> + + <build> + <sourceDirectory>${project.basedir}/Scripts/kotlin</sourceDirectory> + <testSourceDirectory>${project.basedir}/Tests/kotlin</testSourceDirectory> + <resources> + <resource> + <directory>${project.basedir}/Environments</directory> + </resource> + </resources> + <plugins> + <plugin> + <artifactId>maven-antrun-plugin</artifactId> + <executions> + <execution> + <id>validate-kotlin</id> + <phase>validate</phase> + <configuration> + <target name="ktlint"> + <java taskname="ktlint" dir="${project.basedir}" fork="true" failonerror="true" classname="com.pinterest.ktlint.Main" classpathref="maven.plugin.classpath"> + <arg value="Scripts/kotlin/**/*.kt"/> + </java> + </target> + <skip>${format.skipValidate}</skip> + </configuration> + <goals> + <goal>run</goal> + </goals> + </execution> + <execution> + <!-- Built-in formatter So that you wouldn't have to fix all style violations by hand.--> + <id>format-kotlin</id> + <phase>process-sources</phase> + <configuration> + <target name="ktlint"> + <java taskname="ktlint" dir="${project.basedir}" fork="true" failonerror="true" classname="com.pinterest.ktlint.Main" classpathref="maven.plugin.classpath"> + <arg value="-F"/> + <arg value="Scripts/kotlin/**/*.kt"/> + </java> + </target> + <skip>${format.skipExecute}</skip> + </configuration> + <goals> + <goal>run</goal> + </goals> + </execution> + </executions> + </plugin> + <plugin> + <groupId>org.jacoco</groupId> + <artifactId>jacoco-maven-plugin</artifactId> + <executions> + <execution> + <id>pre-unit-test</id> + <phase>none</phase> + </execution> + <execution> + <id>default-prepare-agent</id> + <phase>none</phase> + </execution> + <execution> + <id>post-unit-test</id> + <phase>none</phase> + </execution> + <execution> + <id>default-report</id> + <phase>none</phase> + </execution> + <execution> + <id>pre-integration-test</id> + <phase>none</phase> + </execution> + <execution> + <id>post-integration-test</id> + <phase>none</phase> + </execution> + <execution> + <id>default-check</id> + <phase>none</phase> + </execution> + </executions> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-failsafe-plugin</artifactId> + <executions> + <execution> + <id>default</id> + <phase>none</phase> + </execution> + <execution> + <id>integration-tests</id> + <phase>none</phase> + </execution> + </executions> + </plugin> + <plugin> + <groupId>org.jetbrains.kotlin</groupId> + <artifactId>kotlin-maven-plugin</artifactId> + <version>${kotlin.maven.version}</version> + <executions> + <execution> + <id>compile</id> + <phase>compile</phase> + <goals> + <goal>compile</goal> + </goals> + <configuration> + <sourceDirs> + <sourceDir>${project.basedir}/Scripts/kotlin</sourceDir> + </sourceDirs> + </configuration> + </execution> + <execution> + <id>test-compile</id> + <phase>test-compile</phase> + <goals> + <goal>test-compile</goal> + </goals> + <configuration> + <sourceDirs> + <sourceDir>${project.basedir}/Tests/kotlin</sourceDir> + </sourceDirs> + </configuration> + </execution> + </executions> + </plugin> + <plugin> + <artifactId>maven-surefire-plugin</artifactId> + <executions> + <execution> + <id>default-test</id> + <phase>test</phase> + <goals> + <goal>test</goal> + </goals> + </execution> + </executions> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-site-plugin</artifactId> + <executions> + <execution> + <id>attach-descriptor</id> + <phase>none</phase> + </execution> + </executions> + </plugin> + <plugin> + <artifactId>maven-checkstyle-plugin</artifactId> + <executions> + <execution> + <id>check-license</id> + <phase>none</phase> + </execution> + <execution> + <id>check-style</id> + <phase>none</phase> + </execution> + </executions> + </plugin> + <plugin> + <artifactId>maven-assembly-plugin</artifactId> + <dependencies> + <dependency> + <groupId>org.onap.ccsdk.cds.blueprintsprocessor</groupId> + <artifactId>cba-assembly-descriptor</artifactId> + <version>1.0.0-SNAPSHOT</version> + </dependency> + </dependencies> + <executions> + <execution> + <id>make-assembly</id> + <phase>package</phase> + <goals> + <goal>single</goal> + </goals> + <configuration> + <descriptorRefs> + <descriptorRef>cba_zip</descriptorRef> + </descriptorRefs> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + </build> + + <profiles> + <profile> + <id>deploy-cba</id> + <build> + <plugins> + <plugin> + <groupId>org.codehaus.gmaven</groupId> + <artifactId>groovy-maven-plugin</artifactId> + <dependencies> + <dependency> + <groupId>com.squareup.okhttp3</groupId> + <artifactId>okhttp</artifactId> + <version>3.14.0</version> + </dependency> + <dependency> + <groupId>commons-io</groupId> + <artifactId>commons-io</artifactId> + <version>${commons-io-version}</version> + </dependency> + </dependencies> + <executions> + <execution> + <id>deploy-cba</id> + <phase>install</phase> + <goals> + <goal>execute</goal> + </goals> + <configuration> + <source> + 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() + } + } + </source> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + </build> + </profile> + </profiles> +</project> 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 @@ <plugins> <plugin> <artifactId>maven-assembly-plugin</artifactId> + <dependencies> + <dependency> + <groupId>org.onap.ccsdk.cds.blueprintsprocessor</groupId> + <artifactId>cba-assembly-descriptor</artifactId> + <version>1.0.0-SNAPSHOT</version> + </dependency> + </dependencies> <version>3.1.0</version> <executions> <execution> @@ -51,9 +58,9 @@ </goals> <configuration> <appendAssemblyId>false</appendAssemblyId> - <descriptors> - <descriptor>Distribution/cba_zip.xml</descriptor> - </descriptors> + <descriptorRefs> + <descriptorRef>cba_zip</descriptorRef> + </descriptorRefs> </configuration> </execution> </executions> 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 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - ~ Copyright © 2019 IBM. - ~ - ~ 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. - --> - -<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.0.0" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.0.0 http://maven.apache.org/xsd/assembly-2.0.0.xsd"> - <!-- create a tar.gz file containing the projects dependencies --> - <id>cba</id> - <formats> - <format>zip</format> - </formats> - <includeBaseDirectory>false</includeBaseDirectory> - <fileSets> - <fileSet> - <directory>${project.basedir}</directory> - <includes> - <include>Definitions/**</include> - <include>Distribution/**</include> - <include>Environments/**</include> - <include>Plans/**</include> - <include>Others/**</include> - <include>Scripts/**</include> - <include>Templates/**</include> - <include>TOSCA-Metadata/**</include> - <include>pom.xml</include> - </includes> - </fileSet> - </fileSets> -</assembly>
\ 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 @@ <plugin> <artifactId>maven-assembly-plugin</artifactId> <version>3.1.0</version> + <dependencies> + <dependency> + <groupId>org.onap.ccsdk.cds.blueprintsprocessor</groupId> + <artifactId>cba-assembly-descriptor</artifactId> + <version>1.0.0-SNAPSHOT</version> + </dependency> + </dependencies> <executions> <execution> <id>cba</id> @@ -52,9 +59,9 @@ </goals> <configuration> <appendAssemblyId>false</appendAssemblyId> - <descriptors> - <descriptor>Distribution/cba_zip.xml</descriptor> - </descriptors> + <descriptorRefs> + <descriptorRef>cba_zip</descriptorRef> + </descriptorRefs> </configuration> </execution> </executions> diff --git a/docs/modelingconcepts/cba.rst b/docs/modelingconcepts/cba.rst index a400ef614..72034d008 100644 --- a/docs/modelingconcepts/cba.rst +++ b/docs/modelingconcepts/cba.rst @@ -13,7 +13,9 @@ The **C**\ ontroller **B**\ lueprint **A**\ rchive is the overall service design The CBA is **.zip** file, comprised of the following folder structure, the files may vary: -.. code-block:: +.. code-block language is required for ReadTheDocs to render code-blocks. Python set as default. + +.. code-block:: python ├── Definitions │ ├── blueprint.json Overall TOSCA service template (worfklow + node_template) diff --git a/ms/blueprintsprocessor/functions/config-snapshots/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/config/snapshots/db/ResourceConfigSnapshotRepository.kt b/ms/blueprintsprocessor/functions/config-snapshots/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/config/snapshots/db/ResourceConfigSnapshotRepository.kt index e1806438b..6806ad665 100644 --- a/ms/blueprintsprocessor/functions/config-snapshots/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/config/snapshots/db/ResourceConfigSnapshotRepository.kt +++ b/ms/blueprintsprocessor/functions/config-snapshots/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/config/snapshots/db/ResourceConfigSnapshotRepository.kt @@ -40,4 +40,60 @@ interface ResourceConfigSnapshotRepository : JpaRepository<ResourceConfigSnapsho resourceType: String, status: ResourceConfigSnapshot.Status ) + + /** + * Finds all ResourceConfigSnapshot for a given resourceId and status as search criterias, + * ordering the resulting list in reverse chronological order. + * + * @param resourceId a resource identifier, e.g. CLLI1234555 + * @param status RUNNING or CANDIDATE + * + * @return A list of entries are found returns a list of ConfigSnapshot. + * If no entries are found, this method returns an empty list. + */ + fun findByResourceIdAndStatusOrderByCreatedDateDesc( + resourceId: String, + status: ResourceConfigSnapshot.Status + ): List<ResourceConfigSnapshot>? + + /** + * Finds all ResourceConfigSnapshot for a given resourceId, + * ordering the resulting list in reverse chronological order. + * + * @param resourceId a resource identifier, e.g. CLLI1234555 + * + * @return A list of entries are found returns a list of ConfigSnapshot. + * If no entries are found, this method returns an empty list. + */ + fun findByResourceIdOrderByCreatedDateDesc( + resourceId: String + ): List<ResourceConfigSnapshot>? + + /** + * Finds all ResourceConfigSnapshot for a given resourceType and status as search criterias, + * ordering the resulting list in reverse chronological order. + * + * @param resourceType a resource type name, e.g full_config + * @param status RUNNING or CANDIDATE + * + * @return A list of entries are found returns a list of ConfigSnapshot. + * If no entries are found, this method returns an empty list. + */ + fun findByResourceTypeAndStatusOrderByCreatedDateDesc( + resourceType: String, + status: ResourceConfigSnapshot.Status + ): List<ResourceConfigSnapshot>? + + /** + * Finds all ResourceConfigSnapshot for a given resourceType, + * ordering the resulting list in reverse chronological order. + * + * @param resourceType a resource type name, e.g full_config + * + * @return A list of entries are found returns a list of ConfigSnapshot. + * If no entries are found, this method returns an empty list. + */ + fun findByResourceTypeOrderByCreatedDateDesc( + resourceType: String + ): List<ResourceConfigSnapshot>? } diff --git a/ms/blueprintsprocessor/functions/config-snapshots/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/config/snapshots/db/ResourceConfigSnapshotService.kt b/ms/blueprintsprocessor/functions/config-snapshots/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/config/snapshots/db/ResourceConfigSnapshotService.kt index 9260b79e8..2383f2c64 100644 --- a/ms/blueprintsprocessor/functions/config-snapshots/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/config/snapshots/db/ResourceConfigSnapshotService.kt +++ b/ms/blueprintsprocessor/functions/config-snapshots/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/config/snapshots/db/ResourceConfigSnapshotService.kt @@ -36,6 +36,36 @@ open class ResourceConfigSnapshotService(private val resourceConfigSnapshotRepos private val log = LoggerFactory.getLogger(ResourceConfigSnapshotService::class.toString()) + suspend fun findAllByResourceIdForStatus( + resourceId: String, + status: ResourceConfigSnapshot.Status + ): List<ResourceConfigSnapshot>? = + withContext(Dispatchers.IO) { + resourceConfigSnapshotRepository.findByResourceIdAndStatusOrderByCreatedDateDesc(resourceId, status) + } + + suspend fun findAllByResourceId( + resourceId: String + ): List<ResourceConfigSnapshot>? = + withContext(Dispatchers.IO) { + resourceConfigSnapshotRepository.findByResourceIdOrderByCreatedDateDesc(resourceId) + } + + suspend fun findAllByResourceTypeForStatus( + resourceType: String, + status: ResourceConfigSnapshot.Status + ): List<ResourceConfigSnapshot>? = + withContext(Dispatchers.IO) { + resourceConfigSnapshotRepository.findByResourceTypeAndStatusOrderByCreatedDateDesc(resourceType, status) + } + + suspend fun findAllByResourceType( + resourceType: String + ): List<ResourceConfigSnapshot>? = + withContext(Dispatchers.IO) { + resourceConfigSnapshotRepository.findByResourceTypeOrderByCreatedDateDesc(resourceType) + } + suspend fun findByResourceIdAndResourceTypeAndStatus( resourceId: String, resourceType: String, diff --git a/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/data/BluePrintModel.kt b/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/data/BluePrintModel.kt index 24901257e..8968ce3ef 100644 --- a/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/data/BluePrintModel.kt +++ b/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/data/BluePrintModel.kt @@ -162,6 +162,8 @@ class PropertyDefinition { var description: String? = null var required: Boolean? = null lateinit var type: String + @get:JsonProperty("input-param") + var inputparam: Boolean? = null @get:JsonProperty("default") var defaultValue: JsonNode? = null var status: String? = null diff --git a/ms/blueprintsprocessor/modules/inbounds/configs-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/configs/api/ResourceConfigSnapshotController.kt b/ms/blueprintsprocessor/modules/inbounds/configs-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/configs/api/ResourceConfigSnapshotController.kt index 2a5f4c3ea..05f43c151 100644 --- a/ms/blueprintsprocessor/modules/inbounds/configs-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/configs/api/ResourceConfigSnapshotController.kt +++ b/ms/blueprintsprocessor/modules/inbounds/configs-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/configs/api/ResourceConfigSnapshotController.kt @@ -53,6 +53,8 @@ import org.springframework.web.bind.annotation.RestController ) open class ResourceConfigSnapshotController(private val resourceConfigSnapshotService: ResourceConfigSnapshotService) { + private val JSON_MIME_TYPE = "application/json" + @RequestMapping( path = ["/health-check"], method = [RequestMethod.GET], @@ -157,4 +159,84 @@ open class ResourceConfigSnapshotController(private val resourceConfigSnapshotSe ResponseEntity.ok().body(resultStored) } + + @RequestMapping( + path = ["/allByID"], + method = [RequestMethod.GET], + produces = [MediaType.APPLICATION_JSON_VALUE] + ) + @ApiOperation( + value = "Retrieve all resource configuration snapshots identified by a given resource_id", + notes = "Retrieve all config snapshots, identified by its Resource Id, ordered by most recently created/modified date. " + ) + @ResponseBody + @PreAuthorize("hasRole('USER')") + fun getAllByID( + @ApiParam(value = "Resource Id associated of the resource configuration snapshots.", required = false) + @RequestParam(value = "resourceId", required = true) resourceId: String, + @ApiParam(value = "Status of the snapshot being retrieved.", defaultValue = "ANY", required = false) + @RequestParam(value = "status", required = false, defaultValue = "ANY") status: String + ): ResponseEntity<List<ResourceConfigSnapshot>?> = runBlocking { + var configSnapshots: List<ResourceConfigSnapshot>? + + try { + if (status == "ANY") { + configSnapshots = resourceConfigSnapshotService.findAllByResourceId(resourceId) + } else { + configSnapshots = resourceConfigSnapshotService.findAllByResourceIdForStatus( + resourceId, ResourceConfigSnapshot.Status.valueOf(status.toUpperCase())) + } + } catch (ex: NoSuchElementException) { + throw httpProcessorException(ErrorCatalogCodes.RESOURCE_NOT_FOUND, ConfigsApiDomains.CONFIGS_API, + "Could not find configuration snapshot entry for ID $resourceId", + ex.errorCauseOrDefault()) + } catch (ex: Exception) { + throw httpProcessorException(ErrorCatalogCodes.INVALID_REQUEST_FORMAT, ConfigsApiDomains.CONFIGS_API, + "Unexpected error while finding configuration snapshot entries for ID $resourceId", + ex.errorCauseOrDefault()) + } + + val expectedMediaType: MediaType = MediaType.valueOf(JSON_MIME_TYPE) + ResponseEntity.ok().contentType(expectedMediaType).body(configSnapshots) + } + + @RequestMapping( + path = ["allByType"], + method = [RequestMethod.GET], + produces = [MediaType.APPLICATION_JSON_VALUE] + ) + @ApiOperation( + value = "Retrieve all resource configuration snapshots for a given resource type.", + notes = "Retrieve all config snapshots matching a specified Resource Type, ordered by most recently created/modified date. " + ) + @ResponseBody + @PreAuthorize("hasRole('USER')") + fun getAllByType( + @ApiParam(value = "Resource Type associated of the resource configuration snapshot.", required = false) + @RequestParam(value = "resourceType", required = true) resourceType: String, + @ApiParam(value = "Status of the snapshot being retrieved.", defaultValue = "ANY", required = false) + @RequestParam(value = "status", required = false, defaultValue = "ANY") status: String + ): ResponseEntity<List<ResourceConfigSnapshot>?> = runBlocking { + var configSnapshots: List<ResourceConfigSnapshot>? + + try { + if (status == "ANY") { + configSnapshots = resourceConfigSnapshotService.findAllByResourceType(resourceType) + } else { + configSnapshots = resourceConfigSnapshotService.findAllByResourceTypeForStatus( + resourceType, ResourceConfigSnapshot.Status.valueOf(status.toUpperCase())) + } + } catch (ex: NoSuchElementException) { + throw httpProcessorException(ErrorCatalogCodes.RESOURCE_NOT_FOUND, ConfigsApiDomains.CONFIGS_API, + "Could not find configuration snapshot entry for ID $resourceType", + ex.errorCauseOrDefault()) + } catch (ex: Exception) { + throw httpProcessorException(ErrorCatalogCodes.INVALID_REQUEST_FORMAT, ConfigsApiDomains.CONFIGS_API, + "Unexpected error while finding configuration snapshot entries for type $resourceType", + ex.errorCauseOrDefault()) + } + + val expectedMediaType: MediaType = MediaType.valueOf(JSON_MIME_TYPE) + ResponseEntity.ok().contentType(expectedMediaType).body(configSnapshots) + } } diff --git a/ms/blueprintsprocessor/modules/inbounds/configs-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/configs/api/ResourceConfigSnapshotControllerTest.kt b/ms/blueprintsprocessor/modules/inbounds/configs-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/configs/api/ResourceConfigSnapshotControllerTest.kt index b54d92bb0..e2fa5ca44 100644 --- a/ms/blueprintsprocessor/modules/inbounds/configs-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/configs/api/ResourceConfigSnapshotControllerTest.kt +++ b/ms/blueprintsprocessor/modules/inbounds/configs-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/configs/api/ResourceConfigSnapshotControllerTest.kt @@ -140,6 +140,112 @@ class ResourceConfigSnapshotControllerTest { } } + @Test + fun `getAllByID returns 200 if entries found`() { + runBlocking { + post(resourceType, "3", "RUNNING") + post(resourceType, "2", "RUNNING") + post(resourceType, resourceId, "RUNNING") + + webTestClient + .get() + .uri("/api/v1/configs/allByID?resourceId=$resourceId") + .exchange() + .expectStatus().is2xxSuccessful + .expectBody() + .jsonPath("$.length()") + .isEqualTo(1) + } + } + + @Test + fun `getAllByID with CANDIDATE status returns 200 if entries found`() { + runBlocking { + post(resourceType, "3", "RUNNING") + post(resourceType, "2", "RUNNING") + post(resourceType, resourceId, "CANDIDATE") + + webTestClient + .get() + .uri("/api/v1/configs/allByID?resourceId=$resourceId&status=CANDIDATE") + .exchange() + .expectStatus().is2xxSuccessful + .expectBody() + .jsonPath("$.length()") + .isEqualTo(1) + } + } + + @Test + fun `getAllByID returns 400 error if missing parameter`() { + runBlocking { + + webTestClient + .get() + .uri("/api/v1/configs/allByID") + .exchange() + .expectStatus().is4xxClientError + .expectBody() + } + } + + @Test + fun `getAllByID returns 400 error if wrong status parameter`() { + runBlocking { + + webTestClient + .get() + .uri("/api/v1/configs/allByID?resourceId=$resourceId&status=NOTGOOD") + .exchange() + .expectStatus().is4xxClientError + .expectBody() + } + } + + @Test + fun `getAllByType returns 200 if entries found`() { + runBlocking { + post(resourceType, "3", "RUNNING") + post(resourceType + "DIFF", "2", "RUNNING") + post(resourceType, "1", "RUNNING") + + webTestClient + .get() + .uri("/api/v1/configs/allByType?resourceType=$resourceType") + .exchange() + .expectStatus().is2xxSuccessful + .expectBody() + .jsonPath("$.length()") + .isEqualTo(3) + } + } + + @Test + fun `getAllByType returns 400 error if missing parameter`() { + runBlocking { + + webTestClient + .get() + .uri("/api/v1/configs/allByType") + .exchange() + .expectStatus().is4xxClientError + .expectBody() + } + } + + @Test + fun `getAllByType returns 400 error if wrong status parameter`() { + runBlocking { + + webTestClient + .get() + .uri("/api/v1/configs/allByType?resourceType=$resourceType&status=NOTGOOD") + .exchange() + .expectStatus().is4xxClientError + .expectBody() + } + } + private fun post(resourceType: String, resourceId: String, status: String) { webTestClient .post() diff --git a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/handler/BluePrintModelHandler.kt b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/handler/BluePrintModelHandler.kt index b94b21252..3140abfb3 100644 --- a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/handler/BluePrintModelHandler.kt +++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/handler/BluePrintModelHandler.kt @@ -49,6 +49,8 @@ import org.onap.ccsdk.cds.controllerblueprints.core.scripts.BluePrintCompileCach import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintContext import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintFileUtils import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintMetadataUtils +import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils +import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceAssignment import org.onap.ccsdk.cds.error.catalog.core.ErrorCatalogCodes import org.onap.ccsdk.cds.error.catalog.core.utils.errorCauseOrDefault import org.onap.ccsdk.cds.error.catalog.core.utils.errorMessageOrDefault @@ -63,6 +65,7 @@ import org.springframework.http.ResponseEntity import org.springframework.http.codec.multipart.FilePart import org.springframework.stereotype.Service import org.springframework.transaction.annotation.Transactional +import java.io.File import java.io.IOException import java.util.UUID @@ -121,30 +124,54 @@ open class BluePrintModelHandler( workFlowData.workFlowName = req.workflowName workFlowData.inputs = workFlow.inputs workFlowData.outputs = workFlow.outputs + wfRes.workFlowData = workFlowData if (workFlow.inputs != null) { for ((k, v) in workFlow.inputs!!) { - addPropertyInfo(v, blueprintContext, wfRes) + addPropertyInfo(k, v, blueprintContext, wfRes) } } if (workFlow.outputs != null) { for ((k, v) in workFlow.outputs!!) { - addPropertyInfo(v, blueprintContext, wfRes) + addPropertyInfo(k, v, blueprintContext, wfRes) } } - wfRes.workFlowData = workFlowData return wfRes } - private fun addPropertyInfo(prop: PropertyDefinition, ctx: BluePrintContext, res: WorkFlowSpecResponse) { + private fun addPropertyInfo(propName: String, prop: PropertyDefinition, ctx: BluePrintContext, res: WorkFlowSpecResponse) { + updatePropertyInfo(propName, prop, ctx, res) addDataType(prop.type, ctx, res) if (prop.entrySchema != null && prop.entrySchema!!.type != null) { addDataType(prop.entrySchema!!.type, ctx, res) } } + private fun updatePropertyInfo(name: String, prop: PropertyDefinition, ctx: BluePrintContext, res: WorkFlowSpecResponse) { + if (prop.inputparam == null || prop.inputparam == false) { + var workflow = ctx.workflowByName(res.workFlowData.workFlowName) + for ((k, v) in workflow.steps!!) { + var arts = ctx.nodeTemplateArtifacts(v.target!!) + if (arts != null) { + for ((k, v) in arts.entries!!) { + if (v.type == "artifact-mapping-resource") { + val file: String = v.file + val completePath = ctx.rootPath.plus(File.separator).plus(file) + val resourceAssignment = JacksonUtils.getListFromFile(completePath, ResourceAssignment::class.java) + for (res in resourceAssignment) { + if (res.name == name && res.inputParameter) { + prop.inputparam = true + return + } + } + } + } + } + } + } + } private fun addDataType(name: String, ctx: BluePrintContext, res: WorkFlowSpecResponse) { var data = ctx.dataTypeByName(name) if (data != null) { @@ -156,7 +183,7 @@ open class BluePrintModelHandler( private fun addParentDataType(data: DataType, ctx: BluePrintContext, res: WorkFlowSpecResponse) { if (data.properties != null) { for ((k, v) in data.properties!!) { - addPropertyInfo(v, ctx, res) + addPropertyInfo(k, v, ctx, res) } } } |