diff options
Diffstat (limited to 'ms/blueprintsprocessor')
65 files changed, 2430 insertions, 507 deletions
diff --git a/ms/blueprintsprocessor/.gitignore b/ms/blueprintsprocessor/.gitignore index f72f78ad..04f991d1 100644 --- a/ms/blueprintsprocessor/.gitignore +++ b/ms/blueprintsprocessor/.gitignore @@ -28,4 +28,5 @@ **/transaction.log **/*versionsBackup **/blackDuckHub* -**/*.jsonld
\ No newline at end of file +**/*.jsonld +/target-ide/ diff --git a/ms/blueprintsprocessor/application/etc/logback.xml b/ms/blueprintsprocessor/application/etc/logback.xml new file mode 100755 index 00000000..a97bb8c3 --- /dev/null +++ b/ms/blueprintsprocessor/application/etc/logback.xml @@ -0,0 +1,36 @@ +<!--
+ ~ Copyright © 2017-2018 AT&T Intellectual Property.
+ ~
+ ~ 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.
+ -->
+
+<configuration>
+ <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
+ <!-- encoders are assigned the type
+ ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
+ <encoder>
+ <pattern>%d{HH:mm:ss.SSS} %-5level %logger{100} - %msg%n</pattern>
+ </encoder>
+ </appender>
+
+
+ <logger name="org.springframework" level="info"/>
+ <logger name="org.springframework.web" level="info"/>
+ <logger name="org.hibernate" level="error"/>
+ <logger name="org.onap.ccsdk.apps" level="info"/>
+
+ <root level="warn">
+ <appender-ref ref="STDOUT"/>
+ </root>
+
+</configuration>
diff --git a/ms/blueprintsprocessor/application/etc/run.source b/ms/blueprintsprocessor/application/etc/run.source new file mode 100755 index 00000000..7557ab12 --- /dev/null +++ b/ms/blueprintsprocessor/application/etc/run.source @@ -0,0 +1,12 @@ +java -classpath "/etc:${APP_HOME}/lib/*:/lib/*:/src:/schema:/generated-sources:${APP_CONFIG_HOME}:${APP_HOME}" \ +-DappName=${APPLICATIONNAME} -DappVersion=${BUNDLEVERSION} \ +-DrouteOffer=${ROUTEOFFER} \ +-DVERSION_ROUTEOFFER_ENVCONTEXT=${BUNDLEVERSION}/${STICKYSELECTORKEY}/${ENVCONTEXT} \ +-DSecurityFilePath=/etc \ +-DREST_NAME_NORMALIZER_PATTERN_FILE=/etc/PatternInputs.txt \ +-Dms_name=org.onap.ccsdk.apps.blueprintsprocessor \ +-Dlogging.config=${APP_CONFIG_HOME}/logback.xml \ +-Djava.security.egd=file:/dev/./urandom \ +-DAPPNAME=${APP_NAME} -DAPPENV=${APP_ENV} -DAPPVERSION=${APP_VERSION} -DNAMESPACE=${NAMESPACE} \ +-Dspring.config.location=${APP_CONFIG_HOME}/ \ +org.onap.ccsdk.apps.blueprintsprocessor.BlueprintProcessorApplication diff --git a/ms/blueprintsprocessor/application/opt/app/onap/config/application.properties b/ms/blueprintsprocessor/application/opt/app/onap/config/application.properties new file mode 100755 index 00000000..c4880b67 --- /dev/null +++ b/ms/blueprintsprocessor/application/opt/app/onap/config/application.properties @@ -0,0 +1,36 @@ +#
+# Copyright � 2017-2018 AT&T Intellectual Property.
+# Modifications Copyright © 2019 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.
+#
+#logging.level.web=DEBUG
+
+# Web server config
+server.port=8080
+
+blueprintsprocessor.grpcEnable=false
+blueprintsprocessor.httpPort=8080
+blueprintsprocessor.grpcPort=9111
+# Blueprint Processor File Execution and Handling Properties
+blueprintsprocessor.blueprintDeployPath=/opt/app/onap/blueprints/deploy
+blueprintsprocessor.blueprintArchivePath=/opt/app/onap/blueprints/archive
+# Primary Database Configuration
+blueprintsprocessor.db.primary.url=jdbc:mysql://db:3306/sdnctl
+blueprintsprocessor.db.primary.username=sdnctl
+blueprintsprocessor.db.primary.password=sdnctl
+blueprintsprocessor.db.primary.driverClassName=org.mariadb.jdbc.Driver
+blueprintsprocessor.db.primary.hibernateHbm2ddlAuto=validate
+blueprintsprocessor.db.primary.hibernateDDLAuto=none
+blueprintsprocessor.db.primary.hibernateNamingStrategy=org.hibernate.cfg.ImprovedNamingStrategy
+blueprintsprocessor.db.primary.hibernateDialect=org.hibernate.dialect.MySQL5InnoDBDialect
\ No newline at end of file diff --git a/ms/blueprintsprocessor/application/opt/app/onap/config/logback.xml b/ms/blueprintsprocessor/application/opt/app/onap/config/logback.xml new file mode 100755 index 00000000..a97bb8c3 --- /dev/null +++ b/ms/blueprintsprocessor/application/opt/app/onap/config/logback.xml @@ -0,0 +1,36 @@ +<!--
+ ~ Copyright © 2017-2018 AT&T Intellectual Property.
+ ~
+ ~ 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.
+ -->
+
+<configuration>
+ <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
+ <!-- encoders are assigned the type
+ ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
+ <encoder>
+ <pattern>%d{HH:mm:ss.SSS} %-5level %logger{100} - %msg%n</pattern>
+ </encoder>
+ </appender>
+
+
+ <logger name="org.springframework" level="info"/>
+ <logger name="org.springframework.web" level="info"/>
+ <logger name="org.hibernate" level="error"/>
+ <logger name="org.onap.ccsdk.apps" level="info"/>
+
+ <root level="warn">
+ <appender-ref ref="STDOUT"/>
+ </root>
+
+</configuration>
diff --git a/ms/blueprintsprocessor/application/pom.xml b/ms/blueprintsprocessor/application/pom.xml index 679a8b90..06752b79 100644..100755 --- a/ms/blueprintsprocessor/application/pom.xml +++ b/ms/blueprintsprocessor/application/pom.xml @@ -3,6 +3,7 @@ ~ Copyright © 2017-2018 AT&T Intellectual Property. ~ ~ Modifications Copyright © 2018 IBM. + ~ Modifications Copyright © 2019 Bell Canada. ~ ~ Licensed under the Apache License, Version 2.0 (the "License"); ~ you may not use this file except in compliance with the License. @@ -31,6 +32,10 @@ <dependencies> <dependency> + <groupId>org.onap.ccsdk.apps.controllerblueprints</groupId> + <artifactId>core</artifactId> + </dependency> + <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> <scope>runtime</scope> @@ -69,13 +74,91 @@ <scope>test</scope> </dependency> </dependencies> - <build> + <resources> + <resource> + <!--config and resource files --> + <directory>${basedir}/etc</directory> + <targetPath>${basedir}/target/etc</targetPath> + <filtering>true</filtering> + <includes> + <include>**/*</include> + </includes> + </resource> + <resource> + <!--config and resource files --> + <directory>${basedir}/src/main/resources</directory> + <targetPath>${basedir}/target/src/main/resources</targetPath> + <filtering>true</filtering> + <includes> + <include>**/*</include> + </includes> + </resource> + <resource> + <directory>src/main/resources</directory> + <includes> + <include>**/*</include> + </includes> + <filtering>true</filtering> + </resource> + </resources> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> + <plugin> + <artifactId>maven-resources-plugin</artifactId> + <version>2.6</version> + <executions> + <execution> + <id>copy-dockerfile</id> + <goals> + <goal>copy-resources</goal> + </goals><!-- here the phase you need --> + <phase>validate</phase> + <configuration> + <outputDirectory>${basedir}/target/docker-stage</outputDirectory> + <resources> + <resource> + <directory>src/main/docker</directory> + <includes> + <include>*</include> + </includes> + <filtering>true</filtering> + </resource> + </resources> + </configuration> + </execution> + </executions> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-antrun-plugin</artifactId> + <executions> + <execution> + <id>ant-test</id> + <phase>package</phase> + <configuration> + <tasks> + <fixcrlf srcdir="${basedir}" eol="unix" includes="**/*.sh, **/*.source"/> + </tasks> + </configuration> + <goals> + <goal>run</goal> + </goals> + </execution> + </executions> + </plugin> + <plugin> + <artifactId>maven-compiler-plugin</artifactId> + <version>3.1</version> + <configuration> + <!-- <skip>${skip.compile}</skip>--> + <source>1.8</source> + <target>1.8</target> + </configuration> + </plugin> </plugins> </build> </project> diff --git a/ms/blueprintsprocessor/application/src/main/resources/application-dev.properties b/ms/blueprintsprocessor/application/src/main/resources/application-dev.properties new file mode 100755 index 00000000..6bfa2407 --- /dev/null +++ b/ms/blueprintsprocessor/application/src/main/resources/application-dev.properties @@ -0,0 +1,36 @@ +#
+# Copyright � 2017-2018 AT&T Intellectual Property.
+# Modifications Copyright © 2019 IBM, 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.
+#
+#logging.level.web=DEBUG
+
+# Web server config
+server.port=8080
+
+blueprintsprocessor.grpcEnable=false
+blueprintsprocessor.httpPort=8080
+blueprintsprocessor.grpcPort=9111
+# Blueprint Processor File Execution and Handling Properties
+blueprintsprocessor.blueprintDeployPath=/opt/app/onap/blueprints/deploy
+blueprintsprocessor.blueprintArchivePath=/opt/app/onap/blueprints/archive
+# Primary Database Configuration
+blueprintsprocessor.db.primary.url=jdbc:mysql://localhost:3306/sdnctl
+blueprintsprocessor.db.primary.username=sdnctl
+blueprintsprocessor.db.primary.password=sdnctl
+blueprintsprocessor.db.primary.driverClassName=org.mariadb.jdbc.Driver
+blueprintsprocessor.db.primary.hibernateHbm2ddlAuto=update
+blueprintsprocessor.db.primary.hibernateDDLAuto=none
+blueprintsprocessor.db.primary.hibernateNamingStrategy=org.hibernate.cfg.ImprovedNamingStrategy
+blueprintsprocessor.db.primary.hibernateDialect=org.hibernate.dialect.MySQL5InnoDBDialect
\ No newline at end of file diff --git a/ms/blueprintsprocessor/application/src/main/resources/application.properties b/ms/blueprintsprocessor/application/src/main/resources/application.properties index fa1a1e6e..62695207 100644..100755 --- a/ms/blueprintsprocessor/application/src/main/resources/application.properties +++ b/ms/blueprintsprocessor/application/src/main/resources/application.properties @@ -1,5 +1,6 @@ #
# Copyright � 2017-2018 AT&T Intellectual Property.
+# Modifications Copyright © 2019 IBM, Bell Canada.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -14,6 +15,10 @@ # limitations under the License.
#
#logging.level.web=DEBUG
+
+# Web server config
+server.port=8080
+
blueprintsprocessor.grpcEnable=false
blueprintsprocessor.httpPort=8080
blueprintsprocessor.grpcPort=9111
@@ -21,7 +26,7 @@ blueprintsprocessor.grpcPort=9111 blueprintsprocessor.blueprintDeployPath=/opt/app/onap/blueprints/deploy
blueprintsprocessor.blueprintArchivePath=/opt/app/onap/blueprints/archive
# Primary Database Configuration
-blueprintsprocessor.db.primary.url=jdbc:mysql://localhost:3306/sdnctl
+blueprintsprocessor.db.primary.url=jdbc:mysql://db:3306/sdnctl
blueprintsprocessor.db.primary.username=sdnctl
blueprintsprocessor.db.primary.password=sdnctl
blueprintsprocessor.db.primary.driverClassName=org.mariadb.jdbc.Driver
diff --git a/ms/blueprintsprocessor/application/src/test/resources/application.properties b/ms/blueprintsprocessor/application/src/test/resources/application.properties index f896ee05..d21264c0 100644 --- a/ms/blueprintsprocessor/application/src/test/resources/application.properties +++ b/ms/blueprintsprocessor/application/src/test/resources/application.properties @@ -13,6 +13,8 @@ # See the License for the specific language governing permissions and # limitations under the License. # +# Web server config +server.port=8080 # Blueprint Processor File Execution and Handling Properties blueprintsprocessor.blueprintDeployPath=/opt/app/onap/blueprints/deploy blueprintsprocessor.blueprintArchivePath=/opt/app/onap/blueprints/archive diff --git a/ms/blueprintsprocessor/distribution/pom.xml b/ms/blueprintsprocessor/distribution/pom.xml new file mode 100755 index 00000000..fb5e3c12 --- /dev/null +++ b/ms/blueprintsprocessor/distribution/pom.xml @@ -0,0 +1,196 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + ~ Copyright © 2019 IBM, 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.apps.blueprintsprocessor</groupId> + <artifactId>parent</artifactId> + <version>0.4.1-SNAPSHOT</version> + <relativePath>../parent</relativePath> + </parent> + <artifactId>distribution</artifactId> + <packaging>pom</packaging> + <name>Blueprints Processor Distribution</name> + <properties> + <assembly.id>maven</assembly.id> + <name.space>org.onap.ccsdk.apps</name.space> <!-- <name.space>${namespace}</name.space> --> + <serviceArtifactName>blueprintsprocessor</serviceArtifactName> + <image.name>onap/ccsdk-blueprintsprocessor</image.name> + <docker.buildArg.https_proxy>${https_proxy}</docker.buildArg.https_proxy> + <docker.push.phase>deploy</docker.push.phase> + <docker.verbose>true</docker.verbose> + </properties> + + <dependencies> + <dependency> + <groupId>org.onap.ccsdk.apps.blueprintsprocessor</groupId> + <artifactId>application</artifactId> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <artifactId>maven-resources-plugin</artifactId> + <version>2.6</version> + <executions> + <execution> + <id>copy-dockerfile</id> + <goals> + <goal>copy-resources</goal> + </goals><!-- here the phase you need --> + <phase>validate</phase> + <configuration> + <outputDirectory>${basedir}/target/docker-stage</outputDirectory> + <resources> + <resource> + <directory>src/main/docker</directory> + <includes> + <include>*</include> + </includes> + <filtering>true</filtering> + </resource> + </resources> + </configuration> + </execution> + </executions> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-antrun-plugin</artifactId> + <executions> + <execution> + <id>ant-test</id> + <phase>package</phase> + <configuration> + <tasks> + <fixcrlf srcdir="${basedir}" eol="unix" includes="**/*.sh, **/*.source"/> + </tasks> + </configuration> + <goals> + <goal>run</goal> + </goals> + </execution> + </executions> + </plugin> + <plugin> + <!--build the final artifact for docker deployment --> + <artifactId>maven-assembly-plugin</artifactId> + <version>3.1.0</version> + <configuration> + <!-- <skipAssembly>${skip.assembly}</skipAssembly>--> + <outputDirectory>${basedir}/target/docker-stage</outputDirectory> + <descriptors> + <descriptor>src/main/docker/distribution.xml</descriptor> + </descriptors> + <tarLongFileMode>posix</tarLongFileMode> + </configuration> + <executions> + <execution> + <id>${assembly.id}</id> + <phase>package</phase> + <goals> + <goal>single</goal> + </goals> + </execution> + </executions> + </plugin> + <plugin> + <groupId>org.codehaus.groovy.maven</groupId> + <artifactId>gmaven-plugin</artifactId> + <version>1.0</version> + <executions> + <execution> + <phase>validate</phase> + <goals> + <goal>execute</goal> + </goals> + <configuration> + <source> + println project.properties['ccsdk.project.version'] + def versionArray + if (project.properties['ccsdk.project.version'] != null ) { + versionArray = project.properties['ccsdk.project.version'].split('\\.') + } + + if (project.properties['ccsdk.project.version'].endsWith("-SNAPSHOT")) + { + project.properties['project.docker.latesttag.version']=versionArray[0] + '.' + versionArray[1] + "-STAGING-latest" + } else { + project.properties['project.docker.latesttag.version']=versionArray[0]+'.' + versionArray[1]+"-STAGING-latest" + } + + println 'New Tag for docker:' + project.properties['project.docker.latesttag.version'] + </source> + </configuration> + </execution> + </executions> + </plugin> + + </plugins> + </build> + + <profiles> + <profile> + <id>docker</id> + <build> + <plugins> + <plugin> + <groupId>io.fabric8</groupId> + <artifactId>docker-maven-plugin</artifactId> + <version>0.26.1</version> + <inherited>false</inherited> + <configuration> + <images> + <image> + <name>${image.name}</name> + <build> + <cleanup>try</cleanup> + <dockerFileDir>${basedir}/target/docker-stage</dockerFileDir> + <tags> + <tag>${project.version}</tag> + <tag>${project.version}-STAGING-${maven.build.timestamp}</tag> + <tag>${project.docker.latesttag.version}</tag> + </tags> + </build> + </image> + </images> + <verbose>true</verbose> + </configuration> + <executions> + <execution> + <id>generate-images</id> + <phase>package</phase> + <goals> + <goal>build</goal> + </goals> + </execution> + <execution> + <id>push-images</id> + <phase>${docker.push.phase}</phase> + <goals> + <goal>build</goal> + <goal>push</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> + </build> + </profile> + + </profiles> +</project>
\ No newline at end of file diff --git a/ms/blueprintsprocessor/distribution/src/main/dc/docker-compose.yaml b/ms/blueprintsprocessor/distribution/src/main/dc/docker-compose.yaml new file mode 100755 index 00000000..c0eade50 --- /dev/null +++ b/ms/blueprintsprocessor/distribution/src/main/dc/docker-compose.yaml @@ -0,0 +1,33 @@ +version: '3.3'
+
+services:
+ db:
+ image: mariadb:latest
+ container_name: ccsdk-mariadb
+ ports:
+ - "3306:3306"
+ volumes:
+ - ~/vm_mysql:/var/lib/mysql
+ restart: always
+ environment:
+ MYSQL_ROOT_PASSWORD: sdnctl
+ MYSQL_DATABASE: sdnctl
+ MYSQL_USER: sdnctl
+ MYSQL_PASSWORD: sdnctl
+ blueprints-processor:
+ depends_on:
+ - db
+ image: onap/ccsdk-blueprintsprocessor:latest
+ container_name: bp-rest
+ ports:
+ - "8000:8080"
+ restart: always
+ volumes:
+ - ~/share/vm_ms/blueprintsprocessor/config:/opt/app/onap/config
+ - ~/share/vm_ms/blueprintsprocessor/logs:/logs
+ environment:
+ APPLICATIONNAME: BlueprintsProcessor
+ BUNDLEVERSION: 1.0.0
+ APP_CONFIG_HOME: /opt/app/onap/config
+ STICKYSELECTORKEY:
+ ENVCONTEXT: dev
\ No newline at end of file diff --git a/ms/blueprintsprocessor/distribution/src/main/docker/Dockerfile b/ms/blueprintsprocessor/distribution/src/main/docker/Dockerfile new file mode 100755 index 00000000..21362329 --- /dev/null +++ b/ms/blueprintsprocessor/distribution/src/main/docker/Dockerfile @@ -0,0 +1,20 @@ +FROM anapsix/alpine-java:8_jdk + +ENV HTTP_PROXY ${HTTP_PROXY} +ENV HTTPS_PROXY ${HTTPS_PROXY} + +RUN apk add --no-cache curl + +COPY startService.sh /startService.sh +RUN chmod 777 /startService.sh && dos2unix /startService.sh + +COPY @project.build.finalName@-@assembly.id@.tar.gz /source.tar.gz + +RUN (mkdir -p /source /opt/app/onap) && (tar -xzf /source.tar.gz -C /source) \ +&& (mv /source/@project.build.finalName@ /source/app) \ +&& (cp -rf /source/app/opt/app/onap/lib /opt/app/onap/) \ +&& (cp -rf /source/app/etc /) \ +&& (cp -rf /source/app/config /) \ +&& (rm -rf /source) + +ENTRYPOINT /startService.sh
\ No newline at end of file diff --git a/ms/blueprintsprocessor/distribution/src/main/docker/distribution.xml b/ms/blueprintsprocessor/distribution/src/main/docker/distribution.xml new file mode 100755 index 00000000..b538b73b --- /dev/null +++ b/ms/blueprintsprocessor/distribution/src/main/docker/distribution.xml @@ -0,0 +1,69 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + ~ Copyright © 2018-2019 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. + --> + +<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>${assembly.id}</id> + <formats> + <format>tar.gz</format> + </formats> + <dependencySets> + <dependencySet> + <outputDirectory>/opt/app/onap/lib</outputDirectory> + <outputFileNameMapping>${artifact.groupId}-${artifact.artifactId}-${artifact.version}${dashClassifier?}.${artifact.extension}</outputFileNameMapping> + <excludes> + </excludes> + </dependencySet> + </dependencySets> + <fileSets> + <fileSet> + <directory>${project.basedir}/../application/src/main/resources</directory> + <includes> + <include>application.properties</include> + <include>logback.xml</include> + </includes> + <outputDirectory>./</outputDirectory> + <useDefaultExcludes>true</useDefaultExcludes> + </fileSet> + <fileSet> + <directory>${project.basedir}/src/main/docker</directory> + <includes> + <include>Dockerfile</include> + <include>startService.sh</include> + </includes> + <outputDirectory>./</outputDirectory> + <useDefaultExcludes>true</useDefaultExcludes> + </fileSet> + <fileSet> + <directory>${project.basedir}/../application/src/main/resources</directory> + <outputDirectory>src/main/resources</outputDirectory> + <useDefaultExcludes>true</useDefaultExcludes> + </fileSet> + <fileSet> + <directory>${project.basedir}/../application/opt/app/onap/config</directory> + <outputDirectory>./config</outputDirectory> + <useDefaultExcludes>true</useDefaultExcludes> + </fileSet> + <fileSet> + <directory>${project.basedir}/../application/etc</directory> + <outputDirectory>./etc</outputDirectory> + <useDefaultExcludes>true</useDefaultExcludes> + </fileSet> + </fileSets> +</assembly>
\ No newline at end of file diff --git a/ms/blueprintsprocessor/distribution/src/main/docker/startService.sh b/ms/blueprintsprocessor/distribution/src/main/docker/startService.sh new file mode 100755 index 00000000..79bcbc06 --- /dev/null +++ b/ms/blueprintsprocessor/distribution/src/main/docker/startService.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +nodeName=BlueprintsProcessor_1.0.0_$(cat /proc/self/cgroup | grep docker | sed s/\\//\\n/g | tail -1) + +echo "APP Config HOME : ${APP_CONFIG_HOME}" +export APP_HOME=/opt/app/onap + +cp -rf /config /opt/app/onap/ +source /etc/run.source diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/ComponentNetconfExecutorTest.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/ComponentNetconfExecutorTest.kt index 05f6a2db..a2c7344b 100644 --- a/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/ComponentNetconfExecutorTest.kt +++ b/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/ComponentNetconfExecutorTest.kt @@ -17,6 +17,7 @@ package org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor import com.fasterxml.jackson.databind.JsonNode +import com.fasterxml.jackson.databind.node.JsonNodeFactory import org.junit.Test import org.junit.runner.RunWith import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ActionIdentifiers @@ -46,6 +47,8 @@ class ComponentNetconfExecutorTest { fun testComponentNetconfExecutor() { val executionServiceInput = ExecutionServiceInput() + executionServiceInput.payload = JsonNodeFactory.instance.objectNode() + val commonHeader = CommonHeader() commonHeader.requestId = "1234" executionServiceInput.commonHeader = commonHeader diff --git a/ms/blueprintsprocessor/functions/pom.xml b/ms/blueprintsprocessor/functions/pom.xml index 2a952f88..2a952f88 100644..100755 --- a/ms/blueprintsprocessor/functions/pom.xml +++ b/ms/blueprintsprocessor/functions/pom.xml diff --git a/ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/ComponentJythonExecutor.kt b/ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/ComponentJythonExecutor.kt index 5eb40225..9e2ba0b9 100644 --- a/ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/ComponentJythonExecutor.kt +++ b/ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/ComponentJythonExecutor.kt @@ -22,7 +22,7 @@ import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceInp import org.onap.ccsdk.apps.blueprintsprocessor.functions.python.executor.utils.PythonExecutorUtils import org.onap.ccsdk.apps.blueprintsprocessor.services.execution.AbstractComponentFunction import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException -import org.onap.ccsdk.apps.controllerblueprints.core.checkNotEmptyNThrow +import org.onap.ccsdk.apps.controllerblueprints.core.checkNotEmptyOrThrow import org.onap.ccsdk.apps.controllerblueprints.core.data.OperationAssignment import org.slf4j.LoggerFactory import org.springframework.beans.factory.annotation.Autowired @@ -62,7 +62,7 @@ open class ComponentJythonExecutor(private val pythonExecutorProperty: PythonExe val content: String? = bluePrintRuntimeService.resolveNodeTemplateArtifact(nodeTemplateName, artifactName) - checkNotEmptyNThrow(content, "artifact ($artifactName) content is empty") + checkNotEmptyOrThrow(content, "artifact ($artifactName) content is empty") val pythonPath: MutableList<String> = operationAssignment.implementation?.dependencies ?: arrayListOf() pythonPath.add(blueprintBasePath) diff --git a/ms/blueprintsprocessor/functions/python-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/ComponentJythonExecutorTest.kt b/ms/blueprintsprocessor/functions/python-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/ComponentJythonExecutorTest.kt index 07591a50..83cf59c2 100644 --- a/ms/blueprintsprocessor/functions/python-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/ComponentJythonExecutorTest.kt +++ b/ms/blueprintsprocessor/functions/python-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/ComponentJythonExecutorTest.kt @@ -17,6 +17,7 @@ package org.onap.ccsdk.apps.blueprintsprocessor.functions.python.executor import com.fasterxml.jackson.databind.JsonNode +import com.fasterxml.jackson.databind.node.JsonNodeFactory import org.junit.Test import org.junit.runner.RunWith import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ActionIdentifiers @@ -26,6 +27,7 @@ import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants import org.onap.ccsdk.apps.controllerblueprints.core.asJsonNode import org.onap.ccsdk.apps.controllerblueprints.core.putJsonElement import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintMetadataUtils +import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils import org.springframework.beans.factory.annotation.Autowired import org.springframework.test.context.ContextConfiguration import org.springframework.test.context.TestPropertySource @@ -43,8 +45,10 @@ class ComponentJythonExecutorTest { @Test fun testPythonComponentInjection() { - + /* val executionServiceInput = ExecutionServiceInput() + executionServiceInput.payload = JsonNodeFactory.instance.objectNode() + val commonHeader = CommonHeader() commonHeader.requestId = "1234" executionServiceInput.commonHeader = commonHeader @@ -55,8 +59,12 @@ class ComponentJythonExecutorTest { actionIdentifiers.actionName = "activate" executionServiceInput.actionIdentifiers = actionIdentifiers + */ - val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime(commonHeader.requestId, + val executionServiceInput = JacksonUtils.readValueFromClassPathFile("payload/requests/sample-activate-request.json", + ExecutionServiceInput::class.java)!! + + val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime("1234", "./../../../../components/model-catalog/blueprint-model/starter-blueprint/baseconfiguration") val stepMetaData: MutableMap<String, JsonNode> = hashMapOf() @@ -68,6 +76,7 @@ class ComponentJythonExecutorTest { componentJythonExecutor.bluePrintRuntimeService = bluePrintRuntimeService componentJythonExecutor.stepName = "activate-jython" + componentJythonExecutor.apply(executionServiceInput) } diff --git a/ms/blueprintsprocessor/functions/python-executor/src/test/resources/requests/sample-activate-request.json b/ms/blueprintsprocessor/functions/python-executor/src/test/resources/payload/requests/sample-activate-request.json index 7142f045..7142f045 100644 --- a/ms/blueprintsprocessor/functions/python-executor/src/test/resources/requests/sample-activate-request.json +++ b/ms/blueprintsprocessor/functions/python-executor/src/test/resources/payload/requests/sample-activate-request.json diff --git a/ms/blueprintsprocessor/functions/resource-resolution/pom.xml b/ms/blueprintsprocessor/functions/resource-resolution/pom.xml index 2f08c580..925f9e33 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/pom.xml +++ b/ms/blueprintsprocessor/functions/resource-resolution/pom.xml @@ -14,7 +14,8 @@ ~ 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"> +<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.apps.blueprintsprocessor</groupId> @@ -27,4 +28,29 @@ <name>Blueprints Processor Function - Resource Resolution</name> <description>Blueprints Processor Function - Resource Resolution</description> + <dependencies> + <!--<dependency> + <groupId>org.onap.ccsdk.apps.controllerblueprints</groupId> + <artifactId>db-resources</artifactId> + <version>${project.version}</version> + </dependency>--> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-data-jpa</artifactId> + </dependency> + <dependency> + <groupId>com.h2database</groupId> + <artifactId>h2</artifactId> + </dependency> + <dependency> + <groupId>org.mariadb.jdbc</groupId> + <artifactId>mariadb-java-client</artifactId> + </dependency> + <dependency> + <groupId>org.hibernate</groupId> + <artifactId>hibernate-testing</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + </project> diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceAssignmentRuntimeService.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceAssignmentRuntimeService.kt index 9d6f4a6b..c4ae1397 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceAssignmentRuntimeService.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceAssignmentRuntimeService.kt @@ -6,53 +6,83 @@ import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintContext import org.onap.ccsdk.apps.controllerblueprints.core.service.DefaultBluePrintRuntimeService
class ResourceAssignmentRuntimeService(private var id: String, private var bluePrintContext: BluePrintContext)
- : DefaultBluePrintRuntimeService(id, bluePrintContext){
+ : DefaultBluePrintRuntimeService(id, bluePrintContext) {
- private var resourceResolutionStore: MutableMap<String, JsonNode> = hashMapOf()
+ private lateinit var resolutionId: String
+ private var resourceStore: MutableMap<String, JsonNode> = hashMapOf()
- override fun getExecutionContext(): MutableMap<String, JsonNode> {
- return resourceResolutionStore
+ fun createUniqueId(key: String) {
+ resolutionId = "$id-$key"
}
- @Suppress("UNCHECKED_CAST")
- override fun setExecutionContext(executionContext: MutableMap<String, JsonNode>) {
- this.resourceResolutionStore = executionContext
+ fun cleanResourceStore() {
+ resourceStore.clear()
}
- override fun put(key: String, value: JsonNode) {
- resourceResolutionStore[key] = value
+ fun putResolutionStore(key: String, value: JsonNode) {
+ resourceStore[key] = value
}
- override fun get(key: String): JsonNode {
- return resourceResolutionStore[key] ?: throw BluePrintProcessorException("failed to get execution property($key)")
+ fun getResolutionStore(key: String): JsonNode {
+ return resourceStore[key]
+ ?: throw BluePrintProcessorException("failed to get execution property ($key)")
}
- override fun check(key: String): Boolean {
- return resourceResolutionStore.containsKey(key)
+ fun checkResolutionStore(key: String): Boolean {
+ return resourceStore.containsKey(key)
}
- override fun cleanRuntime() {
- resourceResolutionStore.clear()
+ fun getJsonNodeFromResolutionStore(key: String): JsonNode {
+ return getResolutionStore(key)
}
- private fun getJsonNode(key: String): JsonNode {
- return get(key)
+ fun getStringFromResolutionStore(key: String): String? {
+ return getResolutionStore(key).asText()
}
- override fun getAsString(key: String): String? {
- return get(key).asText()
+ fun getBooleanFromResolutionStore(key: String): Boolean? {
+ return getResolutionStore(key).asBoolean()
}
- override fun getAsBoolean(key: String): Boolean? {
- return get(key).asBoolean()
+ fun getIntFromResolutionStore(key: String): Int? {
+ return getResolutionStore(key).asInt()
}
- override fun getAsInt(key: String): Int? {
- return get(key).asInt()
+ fun getDoubleFromResolutionStore(key: String): Double? {
+ return getResolutionStore(key).asDouble()
}
- override fun getAsDouble(key: String): Double? {
- return get(key).asDouble()
+ fun putDictionaryStore(key: String, value: JsonNode) {
+ resourceStore["dictionary-$key"] = value
+ }
+
+ fun getDictionaryStore(key: String): JsonNode {
+ return resourceStore["dictionary-$key"]
+ ?: throw BluePrintProcessorException("failed to get execution property (dictionary-$key)")
+ }
+
+ fun checkDictionaryStore(key: String): Boolean {
+ return resourceStore.containsKey("dictionary-$key")
+ }
+
+ fun getJsonNodeFromDictionaryStore(key: String): JsonNode {
+ return getResolutionStore("dictionary-$key")
+ }
+
+ fun getStringFromDictionaryStore(key: String): String? {
+ return getResolutionStore("dictionary-$key").asText()
+ }
+
+ fun getBooleanFromDictionaryStore(key: String): Boolean? {
+ return getResolutionStore("dictionary-$key").asBoolean()
+ }
+
+ fun getIntFromDictionaryStore(key: String): Int? {
+ return getResolutionStore("dictionary-$key").asInt()
+ }
+
+ fun getDoubleFromDictionaryStore(key: String): Double? {
+ return getResolutionStore("dictionary-$key").asDouble()
}
}
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionService.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionService.kt index 5a7161da..38e5c95f 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionService.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionService.kt @@ -18,6 +18,7 @@ package org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution
import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.processor.ResourceAssignmentProcessor
+import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.utils.ResourceAssignmentUtils
import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants
import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException
import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService
@@ -88,7 +89,7 @@ class ResourceResolutionService { val resourceDictionaries: MutableMap<String, ResourceDefinition> = JacksonUtils.getMapFromFile(dictionaryFile, ResourceDefinition::class.java)
?: throw BluePrintProcessorException("couldn't get Dictionary Definitions")
- executeProcessors(bluePrintRuntimeService, resourceDictionaries, resourceAssignments)
+ executeProcessors(bluePrintRuntimeService, resourceDictionaries, resourceAssignments, templateArtifactName)
// Check Template is there
val templateContent = bluePrintRuntimeService.resolveNodeTemplateArtifact(nodeTemplateName, mappingArtifactName)
@@ -107,11 +108,13 @@ class ResourceResolutionService { }
- fun executeProcessors(bluePrintRuntimeService: BluePrintRuntimeService<*>,
- resourceDictionaries: MutableMap<String, ResourceDefinition>,
- resourceAssignments: MutableList<ResourceAssignment>) {
+ private fun executeProcessors(blueprintRuntimeService: BluePrintRuntimeService<*>,
+ resourceDictionaries: MutableMap<String, ResourceDefinition>,
+ resourceAssignments: MutableList<ResourceAssignment>,
+ templateArtifactName: String) {
val bulkSequenced = BulkResourceSequencingUtils.process(resourceAssignments)
+ val resourceAssignmentRuntimeService = ResourceAssignmentUtils.transformToRARuntimeService(blueprintRuntimeService, templateArtifactName)
bulkSequenced.map { batchResourceAssignments ->
batchResourceAssignments.filter { it.name != "*" && it.name != "start" }
@@ -124,7 +127,7 @@ class ResourceResolutionService { "for resource assignment(${resourceAssignment.name})")
try {
// Set BluePrint Runtime Service
- resourceAssignmentProcessor.bluePrintRuntimeService = bluePrintRuntimeService
+ resourceAssignmentProcessor.raRuntimeService = resourceAssignmentRuntimeService
// Set Resource Dictionaries
resourceAssignmentProcessor.resourceDictionaries = resourceDictionaries
// Invoke Apply Method
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceSourceProperties.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceSourceProperties.kt index b141025d..9bad0998 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceSourceProperties.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceSourceProperties.kt @@ -33,8 +33,8 @@ open class DefaultResourceSource : ResourceSourceProperties() { open class DatabaseResourceSource : ResourceSourceProperties() { lateinit var type: String lateinit var query: String - var inputKeyMapping: MutableList<String>? = null - var outputKeyMapping: MutableList<String>? = null + var inputKeyMapping: MutableMap<String, String>? = null + var outputKeyMapping: MutableMap<String, String>? = null lateinit var keyDependencies: MutableList<String> } @@ -43,8 +43,8 @@ open class RestResourceSource : ResourceSourceProperties() { lateinit var urlPath: String lateinit var path: String lateinit var expressionType: String - var inputKeyMapping: MutableList<String>? = null - var outputKeyMapping: MutableList<String>? = null + var inputKeyMapping: MutableMap<String, String>? = null + var outputKeyMapping: MutableMap<String, String>? = null lateinit var keyDependencies: MutableList<String> } @@ -53,7 +53,7 @@ open class CapabilityResourceSource : ResourceSourceProperties() { lateinit var instanceName: String lateinit var path: String lateinit var expressionType: String - var inputKeyMapping: MutableList<String>? = null - var outputKeyMapping: MutableList<String>? = null + var inputKeyMapping: MutableMap<String, String>? = null + var outputKeyMapping: MutableMap<String, String>? = null lateinit var keyDependencies: MutableList<String> }
\ No newline at end of file diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/CapabilityResourceAssignmentProcessor.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/CapabilityResourceAssignmentProcessor.kt index 99338498..6c235599 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/CapabilityResourceAssignmentProcessor.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/CapabilityResourceAssignmentProcessor.kt @@ -18,8 +18,8 @@ package org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.pr import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.CapabilityResourceSource import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException +import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.utils.ResourceAssignmentUtils import org.springframework.beans.factory.annotation.Autowired import org.springframework.context.ApplicationContext import org.springframework.stereotype.Service @@ -40,17 +40,16 @@ open class CapabilityResourceAssignmentProcessor : ResourceAssignmentProcessor() return "resource-assignment-processor-capability" } - override fun process(executionRequest: ResourceAssignment) { + override fun process(resourceAssignment: ResourceAssignment) { - val resourceDefinition = resourceDictionaries[executionRequest.dictionaryName] - ?: throw BluePrintProcessorException("couldn't get resource definition for ${executionRequest.dictionaryName}") + val resourceDefinition = resourceDictionaries[resourceAssignment.dictionaryName] + ?: throw BluePrintProcessorException("couldn't get resource definition for ${resourceAssignment.dictionaryName}") - val resourceSource = resourceDefinition.sources[executionRequest.dictionarySource] - ?: throw BluePrintProcessorException("couldn't get resource definition ${executionRequest.dictionaryName} source(${executionRequest.dictionarySource})") + val resourceSource = resourceDefinition.sources[resourceAssignment.dictionarySource] + ?: throw BluePrintProcessorException("couldn't get resource definition ${resourceAssignment.dictionaryName} source(${resourceAssignment.dictionarySource})") - checkNotNull(resourceSource.properties) { "failed to get ${executionRequest.dictionarySource} properties" } - - val capabilityResourceSourceProperty = ResourceAssignmentUtils.transformResourceSource(resourceSource.properties!!, CapabilityResourceSource::class.java) + val resourceSourceProps = checkNotNull(resourceSource.properties) { "failed to get $resourceSource properties" } + val capabilityResourceSourceProperty = JacksonUtils.getInstanceFromMap(resourceSourceProps, CapabilityResourceSource::class.java) val instanceType = capabilityResourceSourceProperty.type val instanceName = capabilityResourceSourceProperty.instanceName @@ -74,14 +73,14 @@ open class CapabilityResourceAssignmentProcessor : ResourceAssignmentProcessor() checkNotNull(componentResourceAssignmentProcessor) { "failed to get capability resource assignment processor($instanceName)" } // Assign Current Blueprint runtime and ResourceDictionaries - componentResourceAssignmentProcessor.bluePrintRuntimeService = bluePrintRuntimeService + componentResourceAssignmentProcessor.raRuntimeService = raRuntimeService componentResourceAssignmentProcessor.resourceDictionaries = resourceDictionaries // Invoke componentResourceAssignmentProcessor - componentResourceAssignmentProcessor.apply(executionRequest) + componentResourceAssignmentProcessor.apply(resourceAssignment) } - override fun recover(runtimeException: RuntimeException, executionRequest: ResourceAssignment) { + override fun recover(runtimeException: RuntimeException, resourceAssignment: ResourceAssignment) { TODO("To Implement") } diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/DefaultResourceAssignmentProcessor.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/DefaultResourceAssignmentProcessor.kt index 1c5455fd..e389f362 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/DefaultResourceAssignmentProcessor.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/DefaultResourceAssignmentProcessor.kt @@ -17,24 +17,50 @@ package org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.processor +import com.fasterxml.jackson.databind.node.NullNode +import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.utils.ResourceAssignmentUtils +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment +import org.slf4j.LoggerFactory import org.springframework.stereotype.Service /** * DefaultResourceAssignmentProcessor * - * @author Brinda Santh + * @author Kapil Singal */ @Service("resource-assignment-processor-default") open class DefaultResourceAssignmentProcessor : ResourceAssignmentProcessor() { + private val logger = LoggerFactory.getLogger(DefaultResourceAssignmentProcessor::class.java) + override fun getName(): String { return "resource-assignment-processor-default" } - override fun process(executionRequest: ResourceAssignment) { + override fun process(resourceAssignment: ResourceAssignment) { + try { + // Check if It has Input + var value: Any? = raRuntimeService.getInputValue(resourceAssignment.name) + + // If value is null get it from default source + if (value == null || value is NullNode) { + logger.info("Looking for defaultValue as couldn't find value in input For template key (${resourceAssignment.name})") + value = resourceAssignment.property?.defaultValue + } + + logger.info("For template key (${resourceAssignment.name}) setting value as ($value)") + ResourceAssignmentUtils.setResourceDataValue(resourceAssignment, raRuntimeService, value) + + // Check the value has populated for mandatory case + ResourceAssignmentUtils.assertTemplateKeyValueNotNull(resourceAssignment) + } catch (e: Exception) { + ResourceAssignmentUtils.setFailedResourceDataValue(resourceAssignment, e.message) + throw BluePrintProcessorException("Failed in template key ($resourceAssignment) assignments with: ${e.message}", e) + } + } - override fun recover(runtimeException: RuntimeException, executionRequest: ResourceAssignment) { + override fun recover(runtimeException: RuntimeException, resourceAssignment: ResourceAssignment) { } }
\ No newline at end of file diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/InputResourceAssignmentProcessor.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/InputResourceAssignmentProcessor.kt index bd9c188a..5757de2a 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/InputResourceAssignmentProcessor.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/InputResourceAssignmentProcessor.kt @@ -17,41 +17,46 @@ package org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.processor -import org.onap.ccsdk.apps.controllerblueprints.core.* +import com.fasterxml.jackson.databind.node.NullNode +import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.utils.ResourceAssignmentUtils +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException +import org.onap.ccsdk.apps.controllerblueprints.core.checkNotEmpty import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment +import org.slf4j.LoggerFactory import org.springframework.stereotype.Service -import com.fasterxml.jackson.databind.node.NullNode -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.utils.ResourceAssignmentUtils /** * InputResourceAssignmentProcessor * - * @author Brinda Santh + * @author Kapil Singal */ @Service("resource-assignment-processor-input") open class InputResourceAssignmentProcessor : ResourceAssignmentProcessor() { + private val logger = LoggerFactory.getLogger(InputResourceAssignmentProcessor::class.java) + override fun getName(): String { return "resource-assignment-processor-input" } - override fun process(executionRequest: ResourceAssignment) { + override fun process(resourceAssignment: ResourceAssignment) { try { - if (checkNotEmpty(executionRequest.name)) { - val value = bluePrintRuntimeService!!.getInputValue(executionRequest.name) + if (checkNotEmpty(resourceAssignment.name)) { + val value = raRuntimeService.getInputValue(resourceAssignment.name) // if value is null don't call setResourceDataValue to populate the value if (value != null && value !is NullNode) { - ResourceAssignmentUtils.setResourceDataValue(executionRequest, value) + logger.info("input source template key (${resourceAssignment.name}) found from input and value is ($value)") + ResourceAssignmentUtils.setResourceDataValue(resourceAssignment, raRuntimeService, value) } } // Check the value has populated for mandatory case - ResourceAssignmentUtils.assertTemplateKeyValueNotNull(executionRequest) + ResourceAssignmentUtils.assertTemplateKeyValueNotNull(resourceAssignment) } catch (e: Exception) { - ResourceAssignmentUtils.setFailedResourceDataValue(executionRequest, e.message) - throw BluePrintProcessorException("Failed in template key ($executionRequest) assignments with : (${e.message})", e) + ResourceAssignmentUtils.setFailedResourceDataValue(resourceAssignment, e.message) + throw BluePrintProcessorException("Failed in template key ($resourceAssignment) assignments with : (${e.message})", e) } } - override fun recover(runtimeException: RuntimeException, executionRequest: ResourceAssignment) { + override fun recover(runtimeException: RuntimeException, resourceAssignment: ResourceAssignment) { } }
\ No newline at end of file diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/PrimaryDataResourceAssignmentProcessor.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/PrimaryDataResourceAssignmentProcessor.kt index ec98d09e..94271830 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/PrimaryDataResourceAssignmentProcessor.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/PrimaryDataResourceAssignmentProcessor.kt @@ -17,24 +17,147 @@ package org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.processor +import com.fasterxml.jackson.databind.node.JsonNodeFactory +import com.fasterxml.jackson.databind.node.NullNode +import org.onap.ccsdk.apps.blueprintsprocessor.db.primary.service.PrimaryDBLibGenericService +import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.DatabaseResourceSource +import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.utils.ResourceAssignmentUtils +import org.onap.ccsdk.apps.controllerblueprints.core.* +import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDictionaryConstants +import org.slf4j.LoggerFactory import org.springframework.stereotype.Service +import java.util.* /** * PrimaryDataResourceAssignmentProcessor * - * @author Brinda Santh + * @author Kapil Singal */ @Service("resource-assignment-processor-primary-db") -open class PrimaryDataResourceAssignmentProcessor : ResourceAssignmentProcessor(){ +open class PrimaryDataResourceAssignmentProcessor(private val primaryDBLibGenericService: PrimaryDBLibGenericService) + : ResourceAssignmentProcessor() { + + private val logger = LoggerFactory.getLogger(PrimaryDataResourceAssignmentProcessor::class.java) override fun getName(): String { return "resource-assignment-processor-primary-db" } - override fun process(executionRequest: ResourceAssignment) { + override fun process(resourceAssignment: ResourceAssignment) { + try { + validate(resourceAssignment) + + // Check if It has Input + val value = raRuntimeService.getInputValue(resourceAssignment.name) + if (value != null && value !is NullNode) { + logger.info("primary-db source template key (${resourceAssignment.name}) found from input and value is ($value)") + ResourceAssignmentUtils.setResourceDataValue(resourceAssignment, raRuntimeService, value) + } else { + val dName = resourceAssignment.dictionaryName + val dSource = resourceAssignment.dictionarySource + val resourceDefinition = resourceDictionaries[dName] + ?: throw BluePrintProcessorException("couldn't get resource dictionary definition for $dName") + val resourceSource = resourceDefinition.sources[dSource] + ?: throw BluePrintProcessorException("couldn't get resource definition $dName source($dSource)") + val resourceSourceProperties = checkNotNull(resourceSource.properties) { "failed to get source properties for $dName " } + val sourceProperties = JacksonUtils.getInstanceFromMap(resourceSourceProperties, DatabaseResourceSource::class.java) + + val sql = checkNotNull(sourceProperties.query) { "failed to get request query for $dName under $dSource properties" } + val inputKeyMapping = checkNotNull(sourceProperties.inputKeyMapping) { "failed to get input-key-mappings for $dName under $dSource properties" } + + logger.info("$dSource dictionary information : ($sql), ($inputKeyMapping), (${sourceProperties.outputKeyMapping})") + + val rows = primaryDBLibGenericService.query(sql, populateNamedParameter(inputKeyMapping)) + if (rows.isNullOrEmpty()) { + logger.warn("Failed to get $dSource result for dictionary name ($dName) the query ($sql)") + } else { + populateResource(resourceAssignment, sourceProperties, rows) + } + } + + // Check the value has populated for mandatory case + ResourceAssignmentUtils.assertTemplateKeyValueNotNull(resourceAssignment) + } catch (e: Exception) { + ResourceAssignmentUtils.setFailedResourceDataValue(resourceAssignment, e.message) + throw BluePrintProcessorException("Failed in template key ($resourceAssignment) assignments with: ${e.message}", e) + } + } + + @Throws(BluePrintProcessorException::class) + private fun validate(resourceAssignment: ResourceAssignment) { + checkNotEmptyOrThrow(resourceAssignment.name, "resource assignment template key is not defined") + checkNotEmptyOrThrow(resourceAssignment.dictionaryName, "resource assignment dictionary name is not defined for template key (${resourceAssignment.name})") + checkEqualsOrThrow(ResourceDictionaryConstants.SOURCE_PRIMARY_DB, resourceAssignment.dictionarySource) { + "resource assignment source is not ${ResourceDictionaryConstants.SOURCE_PRIMARY_DB} but it is ${resourceAssignment.dictionarySource}" + } + } + + private fun populateNamedParameter(inputKeyMapping: Map<String, String>): Map<String, Any> { + val namedParameters = HashMap<String, Any>() + inputKeyMapping.forEach { + val expressionValue = raRuntimeService.getDictionaryStore(it.value) + logger.trace("Reference dictionary key (${it.key}) resulted in value ($expressionValue)") + namedParameters[it.key] = expressionValue + } + logger.info("Parameter information : ({})", namedParameters) + return namedParameters + } + + @Throws(BluePrintProcessorException::class) + private fun populateResource(resourceAssignment: ResourceAssignment, sourceProperties: DatabaseResourceSource, rows: List<Map<String, Any>>) { + val dName = resourceAssignment.dictionaryName + val dSource = resourceAssignment.dictionarySource + val type = nullToEmpty(resourceAssignment.property?.type) + + val outputKeyMapping = checkNotNull(sourceProperties.outputKeyMapping) { "failed to get output-key-mappings for $dName under $dSource properties" } + logger.info("Response processing type($type)") + + // Primitive Types + when(type) { + in BluePrintTypes.validPrimitiveTypes() -> { + val dbColumnValue = rows[0][outputKeyMapping[dName]] + logger.info("For template key (${resourceAssignment.name}) setting value as ($dbColumnValue)") + ResourceAssignmentUtils.setResourceDataValue(resourceAssignment, raRuntimeService, dbColumnValue) + } + in BluePrintTypes.validCollectionTypes() -> { + val entrySchemaType = returnNotEmptyOrThrow(resourceAssignment.property?.entrySchema?.type) { "Entry schema is not defined for dictionary ($dName) info" } + var arrayNode = JsonNodeFactory.instance.arrayNode() + rows.forEach { + if (entrySchemaType in BluePrintTypes.validPrimitiveTypes()) { + val dbColumnValue = it[outputKeyMapping[dName]] + // Add Array JSON + JacksonUtils.populatePrimitiveValues(dbColumnValue!!, entrySchemaType, arrayNode) + } else { + val arrayChildNode = JsonNodeFactory.instance.objectNode() + for (mapping in outputKeyMapping.entries) { + val dbColumnValue = checkNotNull(it[mapping.key]) + val propertyTypeForDataType = ResourceAssignmentUtils.getPropertyType(raRuntimeService, entrySchemaType, mapping.key) + JacksonUtils.populatePrimitiveValues(mapping.key, dbColumnValue, propertyTypeForDataType, arrayChildNode) + } + arrayNode.add(arrayChildNode) + } + } + logger.info("For template key (${resourceAssignment.name}) setting value as ($arrayNode)") + // Set the List of Complex Values + ResourceAssignmentUtils.setResourceDataValue(resourceAssignment, raRuntimeService, arrayNode) + } + else -> { + // Complex Types + val row = rows[0] + var objectNode = JsonNodeFactory.instance.objectNode() + for (mapping in outputKeyMapping.entries) { + val dbColumnValue = checkNotNull(row[mapping.key]) + val propertyTypeForDataType = ResourceAssignmentUtils.getPropertyType(raRuntimeService, type, mapping.key) + JacksonUtils.populatePrimitiveValues(mapping.key, dbColumnValue, propertyTypeForDataType, objectNode) + } + logger.info("For template key (${resourceAssignment.name}) setting value as ($objectNode)") + ResourceAssignmentUtils.setResourceDataValue(resourceAssignment, raRuntimeService, objectNode) + } + } } - override fun recover(runtimeException: RuntimeException, executionRequest: ResourceAssignment) { + override fun recover(runtimeException: RuntimeException, resourceAssignment: ResourceAssignment) { } }
\ No newline at end of file diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/ResourceAssignmentProcessor.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/ResourceAssignmentProcessor.kt index 11cd3faa..43238a53 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/ResourceAssignmentProcessor.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/ResourceAssignmentProcessor.kt @@ -17,9 +17,9 @@ package org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.processor +import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.ResourceAssignmentRuntimeService import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BlueprintFunctionNode -import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition import org.slf4j.LoggerFactory @@ -28,14 +28,12 @@ abstract class ResourceAssignmentProcessor : BlueprintFunctionNode<ResourceAssig private val log = LoggerFactory.getLogger(ResourceAssignmentProcessor::class.java) - lateinit var bluePrintRuntimeService: BluePrintRuntimeService<*> - + lateinit var raRuntimeService: ResourceAssignmentRuntimeService lateinit var resourceDictionaries: Map<String, ResourceDefinition> - open fun resourceDefinition(name: String): ResourceDefinition { return resourceDictionaries[name] - ?: throw BluePrintProcessorException("couldn't get resource definition($name)") + ?: throw BluePrintProcessorException("couldn't get resource definition for ($name)") } override fun prepareRequest(resourceAssignment: ResourceAssignment): ResourceAssignment { diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/SimpleRestResourceAssignmentProcessor.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/SimpleRestResourceAssignmentProcessor.kt index e05261d8..f1a4dbb0 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/SimpleRestResourceAssignmentProcessor.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/SimpleRestResourceAssignmentProcessor.kt @@ -17,24 +17,146 @@ package org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.processor +import com.fasterxml.jackson.databind.node.ArrayNode +import com.fasterxml.jackson.databind.node.JsonNodeFactory +import com.fasterxml.jackson.databind.node.NullNode +import com.fasterxml.jackson.databind.node.ObjectNode +import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.RestResourceSource +import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.utils.ResourceAssignmentUtils +import org.onap.ccsdk.apps.blueprintsprocessor.rest.service.BluePrintRestLibPropertyService +import org.onap.ccsdk.apps.controllerblueprints.core.* +import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDictionaryConstants +import org.slf4j.LoggerFactory import org.springframework.stereotype.Service /** * SimpleRestResourceAssignmentProcessor * - * @author Brinda Santh + * @author Kapil Singal */ -@Service("resource-assignment-processor-mdsal") -open class SimpleRestResourceAssignmentProcessor : ResourceAssignmentProcessor() { +@Service("resource-assignment-processor-primary-config-data") +open class SimpleRestResourceAssignmentProcessor(private val blueprintRestLibPropertyService: BluePrintRestLibPropertyService) + : ResourceAssignmentProcessor() { + + private val logger = LoggerFactory.getLogger(SimpleRestResourceAssignmentProcessor::class.java) override fun getName(): String { - return "resource-assignment-processor-mdsal" + return "resource-assignment-processor-primary-config-data" } - override fun process(executionRequest: ResourceAssignment) { + override fun process(resourceAssignment: ResourceAssignment) { + try { + validate(resourceAssignment) + + // Check if It has Input + val value = raRuntimeService.getInputValue(resourceAssignment.name) + if (value != null && value !is NullNode) { + logger.info("primary-db source template key (${resourceAssignment.name}) found from input and value is ($value)") + ResourceAssignmentUtils.setResourceDataValue(resourceAssignment, raRuntimeService, value) + } else { + val dName = resourceAssignment.dictionaryName + val dSource = resourceAssignment.dictionarySource + val resourceDefinition = resourceDictionaries[dName] + ?: throw BluePrintProcessorException("couldn't get resource dictionary definition for $dName") + val resourceSource = resourceDefinition.sources[dSource] + ?: throw BluePrintProcessorException("couldn't get resource definition $dName source($dSource)") + val resourceSourceProperties = checkNotNull(resourceSource.properties) { "failed to get source properties for $dName " } + val sourceProperties = JacksonUtils.getInstanceFromMap(resourceSourceProperties, RestResourceSource::class.java) + + val urlPath = checkNotNull(sourceProperties.urlPath) { "failed to get request urlPath for $dName under $dSource properties" } + val path = nullToEmpty(sourceProperties.path) + val inputKeyMapping = checkNotNull(sourceProperties.inputKeyMapping) { "failed to get input-key-mappings for $dName under $dSource properties" } + + logger.info("$dSource dictionary information : ($urlPath), ($inputKeyMapping), (${sourceProperties.outputKeyMapping})") + + val restClientService = blueprintRestLibPropertyService.blueprintWebClientService("primary-config-data") + val response = restClientService.getResource(urlPath, String::class.java) + if (response.isNotBlank()) { + logger.warn("Failed to get $dSource result for dictionary name ($dName) using urlPath ($urlPath)") + } else { + populateResource(resourceAssignment, sourceProperties, response, path) + } + } + // Check the value has populated for mandatory case + ResourceAssignmentUtils.assertTemplateKeyValueNotNull(resourceAssignment) + } catch (e: Exception) { + ResourceAssignmentUtils.setFailedResourceDataValue(resourceAssignment, e.message) + throw BluePrintProcessorException("Failed in template key ($resourceAssignment) assignments with: ${e.message}", e) + } } - override fun recover(runtimeException: RuntimeException, executionRequest: ResourceAssignment) { + @Throws(BluePrintProcessorException::class) + private fun populateResource(resourceAssignment: ResourceAssignment, sourceProperties: RestResourceSource, restResponse: String, path: String) { + val dName = resourceAssignment.dictionaryName + val dSource = resourceAssignment.dictionarySource + val type = nullToEmpty(resourceAssignment.property?.type) + lateinit var entrySchemaType: String + + val outputKeyMapping = checkNotNull(sourceProperties.outputKeyMapping) { "failed to get output-key-mappings for $dName under $dSource properties" } + logger.info("Response processing type($type)") + + val responseNode = checkNotNull(JacksonUtils.jsonNode(restResponse).at(path)) { "Failed to find path ($path) in response ($restResponse)" } + logger.info("populating value for output mapping ($outputKeyMapping), from json ($responseNode)") + + + when (type) { + in BluePrintTypes.validPrimitiveTypes() -> { + logger.info("For template key (${resourceAssignment.name}) setting value as ($responseNode)") + ResourceAssignmentUtils.setResourceDataValue(resourceAssignment, raRuntimeService, responseNode) + } + in BluePrintTypes.validCollectionTypes() -> { + // Array Types + entrySchemaType = returnNotEmptyOrThrow(resourceAssignment.property?.entrySchema?.type) { "Entry schema is not defined for dictionary ($dName) info" } + val arrayNode = responseNode as ArrayNode + + if (entrySchemaType !in BluePrintTypes.validPrimitiveTypes()) { + val responseArrayNode = responseNode.toList() + for (responseSingleJsonNode in responseArrayNode) { + val arrayChildNode = JsonNodeFactory.instance.objectNode() + outputKeyMapping.map { + val responseKeyValue = responseSingleJsonNode.get(it.key) + val propertyTypeForDataType = ResourceAssignmentUtils.getPropertyType(raRuntimeService, entrySchemaType, it.key) + logger.info("For List Type Resource: key (${it.key}), value ($responseKeyValue), type ({$propertyTypeForDataType})") + JacksonUtils.populateJsonNodeValues(it.value, responseKeyValue, propertyTypeForDataType, arrayChildNode) + } + arrayNode.add(arrayChildNode) + } + } + logger.info("For template key (${resourceAssignment.name}) setting value as ($arrayNode)") + // Set the List of Complex Values + ResourceAssignmentUtils.setResourceDataValue(resourceAssignment, raRuntimeService, arrayNode) + } + else -> { + // Complex Types + val objectNode = responseNode as ObjectNode + outputKeyMapping.map { + val responseKeyValue = responseNode.get(it.key) + val propertyTypeForDataType = ResourceAssignmentUtils.getPropertyType(raRuntimeService, entrySchemaType, it.key) + logger.info("For List Type Resource: key (${it.key}), value ($responseKeyValue), type ({$propertyTypeForDataType})") + JacksonUtils.populateJsonNodeValues(it.value, responseKeyValue, propertyTypeForDataType, objectNode) + } + + logger.info("For template key (${resourceAssignment.name}) setting value as ($objectNode)") + // Set the List of Complex Values + ResourceAssignmentUtils.setResourceDataValue(resourceAssignment, raRuntimeService, objectNode) + } + } + } + + @Throws(BluePrintProcessorException::class) + private fun validate(resourceAssignment: ResourceAssignment) { + checkNotEmptyOrThrow(resourceAssignment.name, "resource assignment template key is not defined") + checkNotEmptyOrThrow(resourceAssignment.dictionaryName, "resource assignment dictionary name is not defined for template key (${resourceAssignment.name})") + checkEqualsOrThrow(ResourceDictionaryConstants.SOURCE_PRIMARY_CONFIG_DATA, resourceAssignment.dictionarySource) { + "resource assignment source is not ${ResourceDictionaryConstants.SOURCE_PRIMARY_CONFIG_DATA} but it is ${resourceAssignment.dictionarySource}" + } + checkNotEmptyOrThrow(resourceAssignment.dictionaryName, "resource assignment dictionary name is not defined for template key (${resourceAssignment.name})") } + + override fun recover(runtimeException: RuntimeException, resourceAssignment: ResourceAssignment) { + } + + }
\ No newline at end of file diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/utils/ResourceAssignmentUtils.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/utils/ResourceAssignmentUtils.kt new file mode 100644 index 00000000..ee8911ee --- /dev/null +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/utils/ResourceAssignmentUtils.kt @@ -0,0 +1,178 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * + * 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. + */ + +package org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.utils + +import com.att.eelf.configuration.EELFLogger +import com.att.eelf.configuration.EELFManager +import com.fasterxml.jackson.databind.JsonNode +import com.fasterxml.jackson.databind.ObjectMapper +import com.fasterxml.jackson.databind.node.NullNode +import com.fasterxml.jackson.databind.node.ObjectNode +import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.ResourceAssignmentRuntimeService +import org.onap.ccsdk.apps.controllerblueprints.core.* +import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService +import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment +import java.util.* + +class ResourceAssignmentUtils { + companion object { + + private val logger: EELFLogger = EELFManager.getInstance().getLogger(ResourceAssignmentUtils::class.toString()) + + @Synchronized + @Throws(BluePrintProcessorException::class) + fun setResourceDataValue(resourceAssignment: ResourceAssignment, raRuntimeService: ResourceAssignmentRuntimeService, value: Any?) { + + val resourceProp = checkNotNull(resourceAssignment.property) { "Failed in setting resource value for resource mapping $resourceAssignment" } + checkNotEmptyOrThrow(resourceAssignment.name, "Failed in setting resource value for resource mapping $resourceAssignment") + + if (checkNotEmpty(resourceAssignment.dictionaryName)) { + resourceAssignment.dictionaryName = resourceAssignment.name + logger.warn("Missing dictionary key, setting with template key (${resourceAssignment.name}) as dictionary key (${resourceAssignment.dictionaryName})") + } + + try { + if (checkNotEmpty(resourceProp.type)) { + val convertedValue = convertResourceValue(resourceProp.type, value) + logger.info("Setting Resource Value ($convertedValue) for Resource Name (${resourceAssignment.dictionaryName}) of type (${resourceProp.type})") + setResourceValue(resourceAssignment, raRuntimeService, convertedValue) + resourceAssignment.updatedDate = Date() + resourceAssignment.updatedBy = BluePrintConstants.USER_SYSTEM + resourceAssignment.status = BluePrintConstants.STATUS_SUCCESS + } + } catch (e: Exception) { + throw BluePrintProcessorException("Failed in setting value for template key (${resourceAssignment.name}) and " + + "dictionary key (${resourceAssignment.dictionaryName}) of type (${resourceProp.type}) with error message (${e.message})", e) + } + } + + private fun setResourceValue(resourceAssignment: ResourceAssignment, raRuntimeService: ResourceAssignmentRuntimeService, value: JsonNode) { + raRuntimeService.putResolutionStore(resourceAssignment.name, value) + raRuntimeService.putDictionaryStore(resourceAssignment.dictionaryName!!, value) + resourceAssignment.property!!.value = value + } + + private fun convertResourceValue(type: String, value: Any?): JsonNode { + + return if (value == null || value is NullNode) { + logger.info("Returning {} value from convertResourceValue", value) + NullNode.instance + } else if (BluePrintTypes.validPrimitiveTypes().contains(type) && value is String) { + JacksonUtils.convertPrimitiveResourceValue(type, value) + } else if (value is String) { + JacksonUtils.jsonNode(value) + } else { + JacksonUtils.getJsonNode(value) + } + + } + + @Synchronized + fun setFailedResourceDataValue(resourceAssignment: ResourceAssignment, message: String?) { + if (checkNotEmpty(resourceAssignment.name)) { + resourceAssignment.updatedDate = Date() + resourceAssignment.updatedBy = BluePrintConstants.USER_SYSTEM + resourceAssignment.status = BluePrintConstants.STATUS_FAILURE + resourceAssignment.message = message + } + } + + @Synchronized + @Throws(BluePrintProcessorException::class) + fun assertTemplateKeyValueNotNull(resourceAssignment: ResourceAssignment) { + val resourceProp = checkNotNull(resourceAssignment.property) { "Failed to populate mandatory resource resource mapping $resourceAssignment" } + if (resourceProp.required != null && resourceProp.required!! && (resourceProp.value == null || resourceProp.value !is NullNode)) { + logger.error("failed to populate mandatory resource mapping ($resourceAssignment)") + throw BluePrintProcessorException("failed to populate mandatory resource mapping ($resourceAssignment)") + } + } + + @Synchronized + @Throws(BluePrintProcessorException::class) + fun generateResourceDataForAssignments(assignments: List<ResourceAssignment>): String { + var result = "{}" + try { + val mapper = ObjectMapper() + val root = mapper.readTree(result) + + assignments.forEach { + if (checkNotEmpty(it.name) && it.property != null) { + val rName = it.name + val type = nullToEmpty(it.property?.type).toLowerCase() + val value = it.property?.value + logger.info("Generating Resource name ($rName), type ($type), value ($value)") + + when (value) { + null -> (root as ObjectNode).set(rName, null) + is JsonNode -> (root as ObjectNode).set(rName, value) + else -> { + when (type) { + BluePrintConstants.DATA_TYPE_TIMESTAMP -> (root as ObjectNode).put(rName, value as String) + BluePrintConstants.DATA_TYPE_STRING -> (root as ObjectNode).put(rName, value as String) + BluePrintConstants.DATA_TYPE_BOOLEAN -> (root as ObjectNode).put(rName, value as Boolean) + BluePrintConstants.DATA_TYPE_INTEGER -> (root as ObjectNode).put(rName, value as Int) + BluePrintConstants.DATA_TYPE_FLOAT -> (root as ObjectNode).put(rName, value as Float) + else -> { + if (JacksonUtils.getJsonNode(value) != null) { + (root as ObjectNode).set(rName, JacksonUtils.getJsonNode(value)) + } else { + (root as ObjectNode).set(rName, null) + } + } + } + } + } + } + } + result = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(root) + logger.info("Generated Resource Param Data ($result)") + } catch (e: Exception) { + throw BluePrintProcessorException("Resource Assignment is failed with $e.message", e) + } + + return result + } + + fun transformToRARuntimeService(blueprintRuntimeService: BluePrintRuntimeService<*>, templateArtifactName: String): ResourceAssignmentRuntimeService { + val resourceAssignmentRuntimeService = ResourceAssignmentRuntimeService(blueprintRuntimeService.id(), blueprintRuntimeService.bluePrintContext()) + resourceAssignmentRuntimeService.createUniqueId(templateArtifactName) + resourceAssignmentRuntimeService.setExecutionContext(blueprintRuntimeService.getExecutionContext() as MutableMap<String, JsonNode>) + + return resourceAssignmentRuntimeService + } + + /* + * Populate the Field property type for the Data type + */ + @Synchronized + @Throws(BluePrintProcessorException::class) + fun getPropertyType(raRuntimeService: ResourceAssignmentRuntimeService, dataTypeName: String, propertyName: String): String { + lateinit var type: String + try { + val dataTypeProps = checkNotNull(raRuntimeService.bluePrintContext().dataTypeByName(dataTypeName)?.properties) + val propertyDefinition = checkNotNull(dataTypeProps[propertyName]) + type = returnNotEmptyOrThrow(propertyDefinition.type) { "Couldn't get data type ($dataTypeName)" } + logger.trace("Data type({})'s property ({}) is ({})", dataTypeName, propertyName, type) + } catch (e: Exception) { + logger.error("couldn't get data type($dataTypeName)'s property ($propertyName), error message $e") + throw BluePrintProcessorException("${e.message}", e) + } + return type + } + } +}
\ No newline at end of file diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponentTest.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponentTest.kt index 8adde863..574d235b 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponentTest.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponentTest.kt @@ -19,23 +19,36 @@ package org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution import com.fasterxml.jackson.databind.JsonNode import org.junit.Test import org.junit.runner.RunWith +import org.onap.ccsdk.apps.blueprintsprocessor.core.BluePrintProperties +import org.onap.ccsdk.apps.blueprintsprocessor.core.BlueprintPropertyConfiguration import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceInput import org.onap.ccsdk.apps.blueprintsprocessor.core.utils.PayloadUtils +import org.onap.ccsdk.apps.blueprintsprocessor.db.BluePrintDBLibConfiguration +import org.onap.ccsdk.apps.blueprintsprocessor.db.primary.service.PrimaryDBLibGenericService import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.processor.* import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants import org.onap.ccsdk.apps.controllerblueprints.core.asJsonNode +import org.onap.ccsdk.apps.controllerblueprints.core.config.BluePrintLoadConfiguration import org.onap.ccsdk.apps.controllerblueprints.core.putJsonElement import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintMetadataUtils import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils import org.springframework.beans.factory.annotation.Autowired +import org.springframework.boot.autoconfigure.EnableAutoConfiguration +import org.springframework.context.annotation.ComponentScan import org.springframework.test.context.ContextConfiguration +import org.springframework.test.context.TestPropertySource import org.springframework.test.context.junit4.SpringRunner @RunWith(SpringRunner::class) -@ContextConfiguration(classes = [ResourceResolutionComponent::class, ResourceResolutionService::class, +@ContextConfiguration(classes = [ResourceResolutionService::class, InputResourceAssignmentProcessor::class, DefaultResourceAssignmentProcessor::class, PrimaryDataResourceAssignmentProcessor::class, SimpleRestResourceAssignmentProcessor::class, - CapabilityResourceAssignmentProcessor::class]) + CapabilityResourceAssignmentProcessor::class, PrimaryDBLibGenericService::class, + BlueprintPropertyConfiguration::class, BluePrintProperties::class, + BluePrintDBLibConfiguration::class, BluePrintLoadConfiguration::class]) +@TestPropertySource(locations = ["classpath:application-test.properties"]) +@ComponentScan(basePackages = ["org.onap.ccsdk.apps.blueprintsprocessor", "org.onap.ccsdk.apps.controllerblueprints"]) +@EnableAutoConfiguration class ResourceResolutionComponentTest { @Autowired diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionServiceTest.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionServiceTest.kt index 6c686753..ef69eb51 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionServiceTest.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionServiceTest.kt @@ -19,14 +19,22 @@ package org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith +import org.onap.ccsdk.apps.blueprintsprocessor.core.BluePrintProperties +import org.onap.ccsdk.apps.blueprintsprocessor.core.BlueprintPropertyConfiguration import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceInput import org.onap.ccsdk.apps.blueprintsprocessor.core.utils.PayloadUtils +import org.onap.ccsdk.apps.blueprintsprocessor.db.BluePrintDBLibConfiguration +import org.onap.ccsdk.apps.blueprintsprocessor.db.primary.service.PrimaryDBLibGenericService import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.processor.* +import org.onap.ccsdk.apps.controllerblueprints.core.config.BluePrintLoadConfiguration import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintMetadataUtils import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils import org.slf4j.LoggerFactory import org.springframework.beans.factory.annotation.Autowired +import org.springframework.boot.autoconfigure.EnableAutoConfiguration +import org.springframework.context.annotation.ComponentScan import org.springframework.test.context.ContextConfiguration +import org.springframework.test.context.TestPropertySource import org.springframework.test.context.junit4.SpringRunner import kotlin.test.assertNotNull import kotlin.test.assertTrue @@ -40,7 +48,12 @@ import kotlin.test.assertTrue @ContextConfiguration(classes = [ResourceResolutionService::class, InputResourceAssignmentProcessor::class, DefaultResourceAssignmentProcessor::class, PrimaryDataResourceAssignmentProcessor::class, SimpleRestResourceAssignmentProcessor::class, - CapabilityResourceAssignmentProcessor::class]) + CapabilityResourceAssignmentProcessor::class, PrimaryDBLibGenericService::class, + BlueprintPropertyConfiguration::class, BluePrintProperties::class, + BluePrintDBLibConfiguration::class, BluePrintLoadConfiguration::class]) +@TestPropertySource(locations = ["classpath:application-test.properties"]) +@ComponentScan(basePackages = ["org.onap.ccsdk.apps.blueprintsprocessor", "org.onap.ccsdk.apps.controllerblueprints"]) +@EnableAutoConfiguration class ResourceResolutionServiceTest { private val log = LoggerFactory.getLogger(ResourceResolutionServiceTest::class.java) @@ -48,12 +61,11 @@ class ResourceResolutionServiceTest { @Autowired lateinit var resourceResolutionService: ResourceResolutionService - @Test fun testRegisteredSource() { val sources = resourceResolutionService.registeredResourceSources() assertNotNull(sources, "failed to get registered sources") - assertTrue(sources.containsAll(arrayListOf("input", "default", "primary-db", "mdsal")), "failed to get registered sources") + assertTrue(sources.containsAll(arrayListOf("input", "default", "primary-db", "primary-config-data")), "failed to get registered sources") } @Test diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/application-test.properties b/ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/application-test.properties new file mode 100644 index 00000000..aed61c46 --- /dev/null +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/application-test.properties @@ -0,0 +1,32 @@ +# suppress inspection "UnusedProperty" for whole file +# +# Copyright © 2017-2018 AT&T Intellectual Property. +# +# 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. +# +blueprintsprocessor.db.primary.url=jdbc:h2:mem:testdb;DB_CLOSE_ON_EXIT=FALSE +blueprintsprocessor.db.primary.username=sa +blueprintsprocessor.db.primary.password= +blueprintsprocessor.db.primary.driverClassName=org.h2.Driver +blueprintsprocessor.db.primary.hibernateHbm2ddlAuto=create-drop +blueprintsprocessor.db.primary.hibernateDDLAuto=update +blueprintsprocessor.db.primary.hibernateNamingStrategy=org.hibernate.cfg.ImprovedNamingStrategy +blueprintsprocessor.db.primary.hibernateDialect=org.hibernate.dialect.H2Dialect +# Controller Blueprints Core Configuration +blueprintsprocessor.blueprintDeployPath=./target/blueprints/deploy +blueprintsprocessor.blueprintArchivePath=./target/blueprints/archive + +blueprintsprocessor.restclient.primary-config-data.type=basic-auth +blueprintsprocessor.restclient.primary-config-data.url=http://127.0.0.1:9111 +blueprintsprocessor.restclient.primary-config-data.userId=sampleuser +blueprintsprocessor.restclient.primary-config-data.token=sampletoken
\ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/commons/core/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/core/api/data/BlueprintProcessorData.kt b/ms/blueprintsprocessor/modules/commons/core/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/core/api/data/BlueprintProcessorData.kt index b0483dc3..41bbd1df 100644 --- a/ms/blueprintsprocessor/modules/commons/core/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/core/api/data/BlueprintProcessorData.kt +++ b/ms/blueprintsprocessor/modules/commons/core/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/core/api/data/BlueprintProcessorData.kt @@ -1,99 +1,123 @@ -/*
- * Copyright © 2017-2018 AT&T Intellectual Property.
- * Modifications Copyright © 2018 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.
- */
-
-package org.onap.ccsdk.apps.blueprintsprocessor.core.api.data
-
-import com.fasterxml.jackson.annotation.JsonFormat
-import com.fasterxml.jackson.databind.node.ObjectNode
-import io.swagger.annotations.ApiModelProperty
-import java.util.*
-
-/**
- * BlueprintProcessorData
- * @author Brinda Santh
- * DATE : 8/15/2018
- */
-
-open class ExecutionServiceInput {
- @get:ApiModelProperty(required = true)
- lateinit var commonHeader: CommonHeader
- @get:ApiModelProperty(required = true)
- lateinit var actionIdentifiers: ActionIdentifiers
- @get:ApiModelProperty(required = true)
- lateinit var payload: ObjectNode
-}
-
-open class ExecutionServiceOutput {
- @get:ApiModelProperty(required = true)
- lateinit var commonHeader: CommonHeader
- @get:ApiModelProperty(required = true)
- lateinit var actionIdentifiers: ActionIdentifiers
- @get:ApiModelProperty(required = true)
- var status: Status = Status()
- @get:ApiModelProperty(required = true)
- lateinit var payload: ObjectNode
-}
-
-open class ActionIdentifiers {
- @get:ApiModelProperty(required = false)
- lateinit var blueprintName: String
- @get:ApiModelProperty(required = false)
- lateinit var blueprintVersion: String
- @get:ApiModelProperty(required = true)
- lateinit var actionName: String
- @get:ApiModelProperty(required = true, allowableValues = "sync, async")
- lateinit var mode: String
-}
-
-open class CommonHeader {
- @get:ApiModelProperty(required = true, example = "2012-04-23T18:25:43.511Z")
- @get:JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")
- var timestamp: Date = Date()
- @get:ApiModelProperty(required = true)
- lateinit var originatorId: String
- @get:ApiModelProperty(required = true)
- lateinit var requestId: String
- @get:ApiModelProperty(required = true)
- lateinit var subRequestId: String
- @get:ApiModelProperty(required = false)
- var flags: Flags? = null
-}
-
-open class Flags {
- var isForce: Boolean = false
- @get:ApiModelProperty(value = "3600")
- var ttl: Int = 3600
-}
-
-open class Status {
- @get:ApiModelProperty(required = true)
- var code: Int = 200
- @get:ApiModelProperty(required = true)
- var eventType: String = "EVENT-ACTION-RESPONSE"
- @get:ApiModelProperty(required = true, example = "2012-04-23T18:25:43.511Z")
- @get:JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")
- var timestamp: Date = Date()
- @get:ApiModelProperty(required = false)
- var errorMessage: String? = null
- @get:ApiModelProperty(required = true)
- var message: String = "success"
-}
-
-
-
-
-
+/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 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. + */ + +package org.onap.ccsdk.apps.blueprintsprocessor.core.api.data + +import com.fasterxml.jackson.annotation.JsonFormat +import com.fasterxml.jackson.databind.node.ObjectNode +import io.swagger.annotations.ApiModelProperty +import java.util.* + +/** + * BlueprintProcessorData + * @author Brinda Santh + * DATE : 8/15/2018 + */ + +open class ExecutionServiceInput { + @get:ApiModelProperty(required = true) + lateinit var commonHeader: CommonHeader + @get:ApiModelProperty(required = true) + lateinit var actionIdentifiers: ActionIdentifiers + @get:ApiModelProperty(required = true) + lateinit var payload: ObjectNode +} + +open class ExecutionServiceOutput { + @get:ApiModelProperty(required = true) + lateinit var commonHeader: CommonHeader + @get:ApiModelProperty(required = true) + lateinit var actionIdentifiers: ActionIdentifiers + @get:ApiModelProperty(required = true) + var status: Status = Status() + @get:ApiModelProperty(required = true) + lateinit var payload: ObjectNode +} + +const val ACTION_MODE_ASYNC = "async" +const val ACTION_MODE_SYNC = "sync" + +open class ActionIdentifiers { + @get:ApiModelProperty(required = false) + lateinit var blueprintName: String + @get:ApiModelProperty(required = false) + lateinit var blueprintVersion: String + @get:ApiModelProperty(required = true) + lateinit var actionName: String + @get:ApiModelProperty(required = true, allowableValues = "sync, async") + lateinit var mode: String +} + +open class CommonHeader { + @get:ApiModelProperty(required = true, example = "2012-04-23T18:25:43.511Z") + @get:JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") + var timestamp: Date = Date() + @get:ApiModelProperty(required = true) + lateinit var originatorId: String + @get:ApiModelProperty(required = true) + lateinit var requestId: String + @get:ApiModelProperty(required = true) + lateinit var subRequestId: String + @get:ApiModelProperty(required = false) + var flags: Flags? = null +} + +open class Flags { + var isForce: Boolean = false + @get:ApiModelProperty(value = "3600") + var ttl: Int = 3600 +} + +open class Status { + @get:ApiModelProperty(required = true) + var code: Int = 200 + @get:ApiModelProperty(required = true) + var eventType: String = "EVENT-ACTION-RESPONSE" + @get:ApiModelProperty(required = true, example = "2012-04-23T18:25:43.511Z") + @get:JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") + var timestamp: Date = Date() + @get:ApiModelProperty(required = false) + var errorMessage: String? = null + @get:ApiModelProperty(required = true) + var message: String = "success" +} + +open class BluePrintManagementInput { + @get:ApiModelProperty(required = true) + lateinit var commonHeader: CommonHeader + @get:ApiModelProperty(required = false) + lateinit var blueprintName: String + @get:ApiModelProperty(required = false) + lateinit var blueprintVersion: String + @get:ApiModelProperty(required = true) + lateinit var fileChunk: FileChunk +} + +open class FileChunk { + @get:ApiModelProperty(required = true) + lateinit var chunk: ByteArray +} + +open class BluePrintManagementOutput { + @get:ApiModelProperty(required = true) + lateinit var commonHeader: CommonHeader + @get:ApiModelProperty(required = true) + var status: Status = Status() +} + + + diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/pom.xml b/ms/blueprintsprocessor/modules/commons/db-lib/pom.xml index 53c9b185..590c87f0 100644 --- a/ms/blueprintsprocessor/modules/commons/db-lib/pom.xml +++ b/ms/blueprintsprocessor/modules/commons/db-lib/pom.xml @@ -30,6 +30,10 @@ <dependencies> <dependency> <groupId>org.onap.ccsdk.apps.controllerblueprints</groupId> + <artifactId>core</artifactId> + </dependency> + <dependency> + <groupId>org.onap.ccsdk.apps.controllerblueprints</groupId> <artifactId>db-resources</artifactId> <version>${project.version}</version> </dependency> diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/BlueprintProcessorCatalogServiceImpl.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/BlueprintProcessorCatalogServiceImpl.kt index 89b7f649..dee7ae86 100755 --- a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/BlueprintProcessorCatalogServiceImpl.kt +++ b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/BlueprintProcessorCatalogServiceImpl.kt @@ -17,77 +17,98 @@ package org.onap.ccsdk.apps.blueprintsprocessor.db +import org.onap.ccsdk.apps.blueprintsprocessor.core.BluePrintCoreConfiguration import org.onap.ccsdk.apps.blueprintsprocessor.db.primary.domain.BlueprintProcessorModel import org.onap.ccsdk.apps.blueprintsprocessor.db.primary.domain.BlueprintProcessorModelContent -import org.onap.ccsdk.apps.blueprintsprocessor.db.primary.repository.BlueprintProcessorModelContentRepository import org.onap.ccsdk.apps.blueprintsprocessor.db.primary.repository.BlueprintProcessorModelRepository import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException import org.onap.ccsdk.apps.controllerblueprints.core.common.ApplicationConstants -import org.onap.ccsdk.apps.controllerblueprints.core.config.BluePrintLoadConfiguration import org.onap.ccsdk.apps.controllerblueprints.core.data.ErrorCode import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintValidatorService import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintArchiveUtils -import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintMetadataUtils import org.onap.ccsdk.apps.controllerblueprints.db.resources.BlueprintCatalogServiceImpl +import org.slf4j.LoggerFactory import org.springframework.dao.DataIntegrityViolationException import org.springframework.stereotype.Service import java.io.File import java.nio.file.Files +import java.nio.file.Path +import java.nio.file.Paths /** -Similar/Duplicate implementation in [org.onap.ccsdk.apps.controllerblueprints.service.load.ControllerBlueprintCatalogServiceImpl] + * Similar/Duplicate implementation in [org.onap.ccsdk.apps.controllerblueprints.service.load.ControllerBlueprintCatalogServiceImpl] */ @Service -class BlueprintProcessorCatalogServiceImpl(bluePrintLoadConfiguration: BluePrintLoadConfiguration, - private val bluePrintValidatorService: BluePrintValidatorService, +class BlueprintProcessorCatalogServiceImpl(bluePrintValidatorService: BluePrintValidatorService, + private val blueprintConfig: BluePrintCoreConfiguration, private val blueprintModelRepository: BlueprintProcessorModelRepository) - : BlueprintCatalogServiceImpl(bluePrintLoadConfiguration) { - - override fun saveToDataBase(extractedDirectory: File, id: String, archiveFile: File, checkValidity: Boolean?) { - var valid = false - val firstItem = BluePrintArchiveUtils.getFirstItemInDirectory(extractedDirectory) - val blueprintBaseDirectory = extractedDirectory.absolutePath + "/" + firstItem - // Validate Blueprint - val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime(id, blueprintBaseDirectory) - - // Check Validity of blueprint - if (checkValidity!!) { - valid = bluePrintValidatorService.validateBluePrints(bluePrintRuntimeService) + : BlueprintCatalogServiceImpl(bluePrintValidatorService) { + + private val log = LoggerFactory.getLogger(BlueprintProcessorCatalogServiceImpl::class.toString()) + + init { + + log.info("BlueprintProcessorCatalogServiceImpl initialized") + } + + override fun delete(name: String, version: String) = blueprintModelRepository.deleteByArtifactNameAndArtifactVersion(name, version) + + + override fun get(name: String, version: String, extract: Boolean): Path? { + var path = "${blueprintConfig.archivePath}/$name/$version.zip" + + blueprintModelRepository.findByArtifactNameAndArtifactVersion(name, version)?.also { + it.blueprintModelContent.run { + val file = File(path) + file.parentFile.mkdirs() + file.createNewFile() + file.writeBytes(this!!.content!!).let { + if (extract) { + path = "${blueprintConfig.archivePath}/$name/$version" + BluePrintArchiveUtils.deCompress(file, path) + } + return Paths.get(path) + } + } } + return null + } - if ((valid && checkValidity!!) || (!valid && !checkValidity!!)) { - val metaData = bluePrintRuntimeService.bluePrintContext().metadata!! - // FIXME("Check Duplicate for Artifact Name and Artifact Version") - val blueprintModel = BlueprintProcessorModel() - blueprintModel.id = id - blueprintModel.artifactType = ApplicationConstants.ASDC_ARTIFACT_TYPE_SDNC_MODEL - blueprintModel.published = ApplicationConstants.ACTIVE_N - blueprintModel.artifactName = metaData[BluePrintConstants.METADATA_TEMPLATE_NAME] - blueprintModel.artifactVersion = metaData[BluePrintConstants.METADATA_TEMPLATE_VERSION] - blueprintModel.updatedBy = metaData[BluePrintConstants.METADATA_TEMPLATE_AUTHOR] - blueprintModel.tags = metaData[BluePrintConstants.METADATA_TEMPLATE_TAGS] - blueprintModel.artifactDescription = "Controller Blueprint for ${blueprintModel.artifactName}:${blueprintModel.artifactVersion}" - - val blueprintModelContent = BlueprintProcessorModelContent() - blueprintModelContent.id = id // For quick access both id's are same.always have one to one mapping. - blueprintModelContent.contentType = "CBA_ZIP" - blueprintModelContent.name = "${blueprintModel.artifactName}:${blueprintModel.artifactVersion}" - blueprintModelContent.description = "(${blueprintModel.artifactName}:${blueprintModel.artifactVersion} CBA Zip Content" - blueprintModelContent.content = Files.readAllBytes(archiveFile.toPath()) - - // Set the Blueprint Model into blueprintModelContent - blueprintModelContent.blueprintModel = blueprintModel - - // Set the Blueprint Model Content into blueprintModel - blueprintModel.blueprintModelContent = blueprintModelContent - - try { - blueprintModelRepository.saveAndFlush(blueprintModel) - } catch (ex: DataIntegrityViolationException) { - throw BluePrintException(ErrorCode.CONFLICT_ADDING_RESOURCE.value, "The blueprint entry " + - "is already exist in database: ${ex.message}", ex) + override fun save(metadata: MutableMap<String, String>, archiveFile: File) { + val artifactName = metadata[BluePrintConstants.METADATA_TEMPLATE_NAME] + val artifactVersion = metadata[BluePrintConstants.METADATA_TEMPLATE_VERSION] + + log.isDebugEnabled.apply { + blueprintModelRepository.findByArtifactNameAndArtifactVersion(artifactName!!, artifactVersion!!)?.let { + log.debug("Overwriting blueprint model :$artifactName::$artifactVersion") } } + + val blueprintModel = BlueprintProcessorModel() + blueprintModel.id = metadata[BluePrintConstants.PROPERTY_BLUEPRINT_PROCESS_ID] + blueprintModel.artifactType = ApplicationConstants.ASDC_ARTIFACT_TYPE_SDNC_MODEL + blueprintModel.artifactName = artifactName + blueprintModel.artifactVersion = artifactVersion + blueprintModel.updatedBy = metadata[BluePrintConstants.METADATA_TEMPLATE_AUTHOR] + blueprintModel.tags = metadata[BluePrintConstants.METADATA_TEMPLATE_TAGS] + blueprintModel.artifactDescription = "Controller Blueprint for $artifactName:$artifactVersion" + + val blueprintModelContent = BlueprintProcessorModelContent() + blueprintModelContent.id = metadata[BluePrintConstants.PROPERTY_BLUEPRINT_PROCESS_ID] + blueprintModelContent.contentType = "CBA_ZIP" + blueprintModelContent.name = "$artifactName:$artifactVersion" + blueprintModelContent.description = "$artifactName:$artifactVersion CBA Zip Content" + blueprintModelContent.content = Files.readAllBytes(archiveFile.toPath()) + blueprintModelContent.blueprintModel = blueprintModel + + blueprintModel.blueprintModelContent = blueprintModelContent + + try { + blueprintModelRepository.saveAndFlush(blueprintModel) + } catch (ex: DataIntegrityViolationException) { + throw BluePrintException(ErrorCode.CONFLICT_ADDING_RESOURCE.value, "The blueprint entry " + + "is already exist in database: ${ex.message}", ex) + } } }
\ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/domain/BlueprintProcessorModel.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/domain/BlueprintProcessorModel.kt index 00d4830e..0935d038 100755 --- a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/domain/BlueprintProcessorModel.kt +++ b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/domain/BlueprintProcessorModel.kt @@ -40,13 +40,11 @@ import javax.persistence.TemporalType @Table(name = "BLUEPRINT_RUNTIME") @Proxy(lazy = false) class BlueprintProcessorModel : Serializable { + @Id - @Column(name = "config_model_id") + @Column(name = "blueprint_runtime_id") var id: String? = null - @Column(name = "artifact_uuid") - var artifactUUId: String? = null - @Column(name = "artifact_type") var artifactType: String? = null @@ -58,9 +56,6 @@ class BlueprintProcessorModel : Serializable { @Column(name = "artifact_description") var artifactDescription: String? = null - @Column(name = "internal_version") - var internalVersion: Int? = null - @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") @LastModifiedDate @Temporal(TemporalType.TIMESTAMP) @@ -71,10 +66,6 @@ class BlueprintProcessorModel : Serializable { @ApiModelProperty(required = true) var artifactName: String? = null - @Column(name = "published", nullable = false) - @ApiModelProperty(required = true) - var published: String? = null - @Column(name = "updated_by", nullable = false) @ApiModelProperty(required = true) var updatedBy: String? = null @@ -90,4 +81,4 @@ class BlueprintProcessorModel : Serializable { companion object { private const val serialVersionUID = 1L } -}
\ No newline at end of file +} diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/domain/BlueprintProcessorModelContent.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/domain/BlueprintProcessorModelContent.kt index d012af58..58bf8a33 100644 --- a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/domain/BlueprintProcessorModelContent.kt +++ b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/domain/BlueprintProcessorModelContent.kt @@ -40,7 +40,7 @@ import org.springframework.data.jpa.domain.support.AuditingEntityListener class BlueprintProcessorModelContent : Serializable { @Id - @Column(name = "config_model_content_id") + @Column(name = "blueprint_content_runtime_id") var id: String? = null @Column(name = "name", nullable = false) @@ -52,7 +52,7 @@ class BlueprintProcessorModelContent : Serializable { var contentType: String? = null @OneToOne - @JoinColumn(name = "config_model_id") + @JoinColumn(name = "blueprint_runtime_id") var blueprintModel: BlueprintProcessorModel? = null @Lob @@ -98,4 +98,4 @@ class BlueprintProcessorModelContent : Serializable { private const val serialVersionUID = 1L } -}
\ No newline at end of file +} diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/BlueprintProcessorCatalogServiceImplTest.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/BlueprintProcessorCatalogServiceImplTest.kt new file mode 100644 index 00000000..4c953163 --- /dev/null +++ b/ms/blueprintsprocessor/modules/commons/db-lib/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/BlueprintProcessorCatalogServiceImplTest.kt @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2019 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. + */ +package org.onap.ccsdk.apps.blueprintsprocessor.db + +import org.junit.Test +import org.junit.runner.RunWith +import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintCatalogService +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.boot.autoconfigure.EnableAutoConfiguration +import org.springframework.context.annotation.ComponentScan +import org.springframework.test.context.TestPropertySource +import org.springframework.test.context.junit4.SpringRunner +import java.io.File +import java.nio.file.Paths +import kotlin.test.assertTrue + +@RunWith(SpringRunner::class) +@EnableAutoConfiguration +@ComponentScan(basePackages = ["org.onap.ccsdk.apps.blueprintsprocessor", "org.onap.ccsdk.apps.controllerblueprints"]) +@TestPropertySource(locations = ["classpath:application-test.properties"]) +class BlueprintProcessorCatalogServiceImplTest { + + @Autowired + lateinit var blueprintCatalog: BluePrintCatalogService + + @Test + fun `test catalog service`() { + val file = Paths.get("./src/test/resources/test-cba.zip").toFile() + assertTrue(file.exists(), "couldnt get file ${file.absolutePath}") + + blueprintCatalog.saveToDatabase(file) + + blueprintCatalog.getFromDatabase("baseconfiguration", "1.0.0") + + blueprintCatalog.deleteFromDatabase("baseconfiguration", "1.0.0") + + File("./src/test/resources/baseconfiguration").deleteRecursively() + } +}
\ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/test/resources/application-test.properties b/ms/blueprintsprocessor/modules/commons/db-lib/src/test/resources/application-test.properties index 6f10626e..3ac7ec38 100644 --- a/ms/blueprintsprocessor/modules/commons/db-lib/src/test/resources/application-test.properties +++ b/ms/blueprintsprocessor/modules/commons/db-lib/src/test/resources/application-test.properties @@ -14,7 +14,7 @@ # See the License for the specific language governing permissions and # limitations under the License. # -blueprintsprocessor.db.primary.url=jdbc:h2:mem:testdb;DB_CLOSE_ON_EXIT=FALSE +blueprintsprocessor.db.primary.url=jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1 blueprintsprocessor.db.primary.username=sa blueprintsprocessor.db.primary.password= blueprintsprocessor.db.primary.driverClassName=org.h2.Driver @@ -22,7 +22,6 @@ blueprintsprocessor.db.primary.hibernateHbm2ddlAuto=create-drop blueprintsprocessor.db.primary.hibernateDDLAuto=update blueprintsprocessor.db.primary.hibernateNamingStrategy=org.hibernate.cfg.ImprovedNamingStrategy blueprintsprocessor.db.primary.hibernateDialect=org.hibernate.dialect.H2Dialect - # Controller Blueprints Core Configuration blueprintsprocessor.blueprintDeployPath=./target/blueprints/deploy -blueprintsprocessor.blueprintArchivePath=./target/blueprints/archive
\ No newline at end of file +blueprintsprocessor.blueprintArchivePath=./target/blueprints/archive diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/test/resources/test-cba.zip b/ms/blueprintsprocessor/modules/commons/db-lib/src/test/resources/test-cba.zip Binary files differnew file mode 100644 index 00000000..a62d4bfb --- /dev/null +++ b/ms/blueprintsprocessor/modules/commons/db-lib/src/test/resources/test-cba.zip diff --git a/ms/blueprintsprocessor/modules/commons/pom.xml b/ms/blueprintsprocessor/modules/commons/pom.xml index 4df89857..8d900a89 100644..100755 --- a/ms/blueprintsprocessor/modules/commons/pom.xml +++ b/ms/blueprintsprocessor/modules/commons/pom.xml @@ -2,6 +2,8 @@ <!-- ~ Copyright © 2017-2018 AT&T Intellectual Property. ~ + ~ Modifications Copyright © 2019 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 diff --git a/ms/blueprintsprocessor/modules/commons/rest-lib/pom.xml b/ms/blueprintsprocessor/modules/commons/rest-lib/pom.xml index 82e8cd73..773746b4 100644 --- a/ms/blueprintsprocessor/modules/commons/rest-lib/pom.xml +++ b/ms/blueprintsprocessor/modules/commons/rest-lib/pom.xml @@ -28,6 +28,10 @@ <description>Blueprints Processor Rest Lib</description> <dependencies> <dependency> + <groupId>org.onap.ccsdk.apps.controllerblueprints</groupId> + <artifactId>core</artifactId> + </dependency> + <dependency> <groupId>org.onap.ccsdk.apps.blueprintsprocessor</groupId> <artifactId>core</artifactId> </dependency> diff --git a/ms/blueprintsprocessor/modules/inbounds/resource-api/pom.xml b/ms/blueprintsprocessor/modules/inbounds/resource-api/pom.xml index 6395963b..dcf42c20 100644 --- a/ms/blueprintsprocessor/modules/inbounds/resource-api/pom.xml +++ b/ms/blueprintsprocessor/modules/inbounds/resource-api/pom.xml @@ -15,16 +15,16 @@ ~ 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.apps.blueprintsprocessor</groupId> - <artifactId>inbounds</artifactId> - <version>0.4.1-SNAPSHOT</version> - </parent> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.onap.ccsdk.apps.blueprintsprocessor</groupId> + <artifactId>inbounds</artifactId> + <version>0.4.1-SNAPSHOT</version> + </parent> - <artifactId>resource-api</artifactId> - <packaging>jar</packaging> - <name>Blueprints Processor Resource API</name> - <description>Blueprints Processor Resource API</description> + <artifactId>resource-api</artifactId> + <packaging>jar</packaging> + <name>Blueprints Processor Resource API</name> + <description>Blueprints Processor Resource API</description> </project> diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/pom.xml b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/pom.xml index db6fdd27..818adf9d 100644..100755 --- a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/pom.xml +++ b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/pom.xml @@ -2,6 +2,8 @@ <!-- ~ Copyright © 2017-2018 AT&T Intellectual Property. ~ + ~ Modifications Copyright © 2019 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 @@ -14,7 +16,8 @@ ~ 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"> +<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.apps.blueprintsprocessor</groupId> @@ -29,44 +32,24 @@ <dependencies> <dependency> + <groupId>org.onap.ccsdk.apps.components</groupId> + <artifactId>proto-definition</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.onap.ccsdk.apps.controllerblueprints</groupId> + <version>${project.version}</version> + <artifactId>core</artifactId> + </dependency> + <dependency> <groupId>io.grpc</groupId> <artifactId>grpc-testing</artifactId> </dependency> + <dependency> + <groupId>com.h2database</groupId> + <artifactId>h2</artifactId> + <scope>test</scope> + </dependency> </dependencies> - <build> - <extensions> - <extension> - <groupId>kr.motd.maven</groupId> - <artifactId>os-maven-plugin</artifactId> - <version>1.6.1</version> - </extension> - </extensions> - <plugins> - <plugin> - <groupId>org.xolstice.maven.plugins</groupId> - <artifactId>protobuf-maven-plugin</artifactId> - <version>0.6.1</version> - <configuration> - <protocArtifact> - com.google.protobuf:protoc:3.5.1-1:exe:${os.detected.classifier} - </protocArtifact> - <pluginId>grpc-java</pluginId> - <pluginArtifact> - io.grpc:protoc-gen-grpc-java:1.16.1:exe:${os.detected.classifier} - </pluginArtifact> - <protoSourceRoot>./../../../../../components/model-catalog/api-definition</protoSourceRoot> - </configuration> - <executions> - <execution> - <goals> - <goal>compile</goal> - <goal>compile-custom</goal> - </goals> - </execution> - </executions> - </plugin> - </plugins> - </build> - </project> diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/BluePrintManagementGRPCHandler.kt b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/BluePrintManagementGRPCHandler.kt index 17191f31..fb0bc567 100644 --- a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/BluePrintManagementGRPCHandler.kt +++ b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/BluePrintManagementGRPCHandler.kt @@ -1,5 +1,6 @@ /* * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2019 Bell Canada. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,48 +17,96 @@ package org.onap.ccsdk.apps.blueprintsprocessor.selfservice.api +import io.grpc.StatusException import io.grpc.stub.StreamObserver -import org.apache.commons.io.FileUtils import org.onap.ccsdk.apps.blueprintsprocessor.core.BluePrintCoreConfiguration -import org.onap.ccsdk.apps.controllerblueprints.management.api.* +import org.onap.ccsdk.apps.blueprintsprocessor.selfservice.api.utils.currentTimestamp +import org.onap.ccsdk.apps.controllerblueprints.common.api.CommonHeader +import org.onap.ccsdk.apps.controllerblueprints.common.api.Status +import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintCatalogService +import org.onap.ccsdk.apps.controllerblueprints.management.api.BluePrintManagementInput +import org.onap.ccsdk.apps.controllerblueprints.management.api.BluePrintManagementOutput +import org.onap.ccsdk.apps.controllerblueprints.management.api.BluePrintManagementServiceGrpc import org.slf4j.LoggerFactory import org.springframework.stereotype.Service import java.io.File @Service -class BluePrintManagementGRPCHandler(private val bluePrintCoreConfiguration: BluePrintCoreConfiguration) +class BluePrintManagementGRPCHandler(private val bluePrintCoreConfiguration: BluePrintCoreConfiguration, + private val bluePrintCatalogService: BluePrintCatalogService) : BluePrintManagementServiceGrpc.BluePrintManagementServiceImplBase() { private val log = LoggerFactory.getLogger(BluePrintManagementGRPCHandler::class.java) - override fun uploadBlueprint(request: BluePrintUploadInput, responseObserver: StreamObserver<BluePrintUploadOutput>) { - val response = BluePrintUploadOutput.newBuilder().setCommonHeader(request.commonHeader).build() + override fun uploadBlueprint(request: BluePrintManagementInput, responseObserver: StreamObserver<BluePrintManagementOutput>) { + val blueprintName = request.blueprintName + val blueprintVersion = request.blueprintVersion + val blueprint = "blueprint $blueprintName:$blueprintVersion" + + log.info("request(${request.commonHeader.requestId}): Received upload $blueprint") + + val blueprintArchivedFilePath = "${bluePrintCoreConfiguration.archivePath}/$blueprintName/$blueprintVersion/$blueprintName.zip" try { - val blueprintName = request.blueprintName - val blueprintVersion = request.blueprintVersion - val filePath = "${bluePrintCoreConfiguration.archivePath}/$blueprintName/$blueprintVersion" - val blueprintDir = File(filePath) + val blueprintArchivedFile = File(blueprintArchivedFilePath) + + saveToDisk(request, blueprintArchivedFile) + val blueprintId = bluePrintCatalogService.saveToDatabase(blueprintArchivedFile) + + File("${bluePrintCoreConfiguration.archivePath}/$blueprintName").deleteRecursively() - log.info("Re-creating blueprint directory(${blueprintDir.absolutePath})") - FileUtils.deleteDirectory(blueprintDir) - FileUtils.forceMkdir(blueprintDir) + responseObserver.onNext(successStatus("Successfully uploaded $blueprint with id($blueprintId)", request.commonHeader)) + responseObserver.onCompleted() + } catch (e: Exception) { + failStatus("request(${request.commonHeader.requestId}): Failed to upload $blueprint at path $blueprintArchivedFilePath", e) + } + } - val file = File("${blueprintDir.absolutePath}/$blueprintName.zip") - log.info("Writing CBA File under :${file.absolutePath}") + override fun removeBlueprint(request: BluePrintManagementInput, responseObserver: StreamObserver<BluePrintManagementOutput>) { + val blueprintName = request.blueprintName + val blueprintVersion = request.blueprintVersion + val blueprint = "blueprint $blueprintName:$blueprintVersion" - val fileChunk = request.fileChunk + log.info("request(${request.commonHeader.requestId}): Received delete $blueprint") - file.writeBytes(fileChunk.chunk.toByteArray()).apply { - log.info("CBA file(${file.absolutePath} written successfully") - } + try { + bluePrintCatalogService.deleteFromDatabase(blueprintName, blueprintVersion) + responseObserver.onNext(successStatus("Successfully deleted $blueprint", request.commonHeader)) + responseObserver.onCompleted() } catch (e: Exception) { - log.error("failed to upload file ", e) + failStatus("request(${request.commonHeader.requestId}): Failed to delete $blueprint", e) } - responseObserver.onNext(response) - responseObserver.onCompleted() } - override fun removeBlueprint(request: BluePrintRemoveInput?, responseObserver: StreamObserver<BluePrintRemoveOutput>?) { - //TODO + private fun saveToDisk(request: BluePrintManagementInput, blueprintDir: File) { + log.info("request(${request.commonHeader.requestId}): Writing CBA File under :${blueprintDir.absolutePath}") + if (blueprintDir.exists()) { + log.info("request(${request.commonHeader.requestId}): Re-creating blueprint directory(${blueprintDir.absolutePath})") + //FileUtils.deleteDirectory(blueprintDir.parentFile) + blueprintDir.parentFile.deleteRecursively() + } + blueprintDir.parentFile.mkdirs() + //FileUtils.forceMkdir(blueprintDir.parentFile) + blueprintDir.writeBytes(request.fileChunk.chunk.toByteArray()).apply { + log.info("request(${request.commonHeader.requestId}): CBA file(${blueprintDir.absolutePath} written successfully") + } + + } + + private fun successStatus(message: String, header: CommonHeader): BluePrintManagementOutput = + BluePrintManagementOutput.newBuilder() + .setCommonHeader(header) + .setStatus(Status.newBuilder() + .setTimestamp(currentTimestamp()) + .setMessage(message) + .setCode(200) + .build()) + .build() + + private fun failStatus(message: String, e: Exception): StatusException { + log.error(message, e) + return io.grpc.Status.INTERNAL + .withDescription(message) + .withCause(e) + .asException() } -}
\ No newline at end of file +} diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/BluePrintProcessingGRPCHandler.kt b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/BluePrintProcessingGRPCHandler.kt index 0668d3c9..453306de 100644 --- a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/BluePrintProcessingGRPCHandler.kt +++ b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/BluePrintProcessingGRPCHandler.kt @@ -16,9 +16,10 @@ package org.onap.ccsdk.apps.blueprintsprocessor.selfservice.api -import com.google.protobuf.util.JsonFormat import io.grpc.stub.StreamObserver import org.onap.ccsdk.apps.blueprintsprocessor.core.BluePrintCoreConfiguration +import org.onap.ccsdk.apps.blueprintsprocessor.selfservice.api.utils.toJava +import org.onap.ccsdk.apps.blueprintsprocessor.selfservice.api.utils.toProto import org.onap.ccsdk.apps.controllerblueprints.processing.api.BluePrintProcessingServiceGrpc import org.onap.ccsdk.apps.controllerblueprints.processing.api.ExecutionServiceInput import org.onap.ccsdk.apps.controllerblueprints.processing.api.ExecutionServiceOutput @@ -31,14 +32,29 @@ class BluePrintProcessingGRPCHandler(private val bluePrintCoreConfiguration: Blu : BluePrintProcessingServiceGrpc.BluePrintProcessingServiceImplBase() { private val log = LoggerFactory.getLogger(BluePrintProcessingGRPCHandler::class.java) - override fun process(request: ExecutionServiceInput, - responseObserver: StreamObserver<ExecutionServiceOutput>) { + override fun process(responseObserver: StreamObserver<ExecutionServiceOutput>?): StreamObserver<ExecutionServiceInput> { - //val json = JsonFormat.printer().print(request) - //log.info("Received GRPC request ${json}") - //TODO( Handle Processing Response") - val response = ExecutionServiceOutput.newBuilder().setCommonHeader(request.commonHeader).build() - responseObserver.onNext(response) - responseObserver.onCompleted() + return object : StreamObserver<ExecutionServiceInput> { + override fun onNext(executionServiceInput: ExecutionServiceInput) { + try { + val output = executionServiceHandler.process(executionServiceInput.toJava()) + .toProto(executionServiceInput.payload) + responseObserver?.onNext(output) + } catch (e: Exception) { + onError(e) + } + } + + override fun onError(error: Throwable) { + log.debug("Fail to process message", error) + responseObserver?.onError(io.grpc.Status.INTERNAL + .withDescription(error.message) + .asException()) + } + + override fun onCompleted() { + responseObserver?.onCompleted() + } + } } }
\ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/ExecutionServiceController.kt b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/ExecutionServiceController.kt index 0a67e878..e4734c44 100644 --- a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/ExecutionServiceController.kt +++ b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/ExecutionServiceController.kt @@ -21,7 +21,14 @@ import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceInp import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceOutput import org.springframework.beans.factory.annotation.Autowired import org.springframework.http.MediaType -import org.springframework.web.bind.annotation.* +import org.springframework.http.codec.multipart.FilePart +import org.springframework.web.bind.annotation.PostMapping +import org.springframework.web.bind.annotation.RequestBody +import org.springframework.web.bind.annotation.RequestMapping +import org.springframework.web.bind.annotation.RequestMethod +import org.springframework.web.bind.annotation.RequestPart +import org.springframework.web.bind.annotation.ResponseBody +import org.springframework.web.bind.annotation.RestController import reactor.core.publisher.Mono @RestController @@ -31,18 +38,26 @@ class ExecutionServiceController { @Autowired lateinit var executionServiceHandler: ExecutionServiceHandler - - @RequestMapping(path = arrayOf("/ping"), method = arrayOf(RequestMethod.GET), produces = arrayOf(MediaType.APPLICATION_JSON_VALUE)) + @RequestMapping(path = ["/ping"], method = [RequestMethod.GET], produces = [MediaType.APPLICATION_JSON_VALUE]) @ResponseBody fun ping(): Mono<String> { return Mono.just("Success") } - @RequestMapping(path = arrayOf("/process"), method = arrayOf(RequestMethod.POST), produces = arrayOf(MediaType.APPLICATION_JSON_VALUE)) + @PostMapping(path = ["/upload"], consumes = [MediaType.MULTIPART_FORM_DATA_VALUE]) + @ApiOperation(value = "Upload CBA", notes = "Takes a File and load it in the runtime database") + @ResponseBody + fun upload(@RequestPart("file") parts: Mono<FilePart>): Mono<String> { + return parts + .filter { it is FilePart } + .ofType(FilePart::class.java) + .flatMap(executionServiceHandler::upload) + } + + @RequestMapping(path = ["/process"], method = [RequestMethod.POST], produces = [MediaType.APPLICATION_JSON_VALUE]) @ApiOperation(value = "Resolve Resource Mappings", notes = "Takes the blueprint information and process as per the payload") @ResponseBody - fun process(@RequestBody executionServiceInput: ExecutionServiceInput): Mono<ExecutionServiceOutput> { - val executionServiceOutput = executionServiceHandler.process(executionServiceInput) - return Mono.just(executionServiceOutput) + fun process(@RequestBody executionServiceInput: ExecutionServiceInput): ExecutionServiceOutput { + return executionServiceHandler.process(executionServiceInput) } } diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/ExecutionServiceHandler.kt b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/ExecutionServiceHandler.kt index 69758ecf..ec605c1d 100644 --- a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/ExecutionServiceHandler.kt +++ b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/ExecutionServiceHandler.kt @@ -16,22 +16,61 @@ package org.onap.ccsdk.apps.blueprintsprocessor.selfservice.api +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.GlobalScope +import kotlinx.coroutines.launch +import org.onap.ccsdk.apps.blueprintsprocessor.core.BluePrintCoreConfiguration +import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ACTION_MODE_ASYNC +import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ACTION_MODE_SYNC import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceInput import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceOutput -import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintCatalogService +import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.Status +import org.onap.ccsdk.apps.blueprintsprocessor.selfservice.api.utils.saveCBAFile import org.onap.ccsdk.apps.blueprintsprocessor.services.workflow.BlueprintDGExecutionService +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException +import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintCatalogService +import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintFileUtils import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintMetadataUtils import org.slf4j.LoggerFactory +import org.springframework.http.codec.multipart.FilePart import org.springframework.stereotype.Service +import reactor.core.publisher.Mono @Service -class ExecutionServiceHandler(private val bluePrintCatalogService: BluePrintCatalogService, +class ExecutionServiceHandler(private val bluePrintCoreConfiguration: BluePrintCoreConfiguration, + private val bluePrintCatalogService: BluePrintCatalogService, private val blueprintDGExecutionService: BlueprintDGExecutionService) { private val log = LoggerFactory.getLogger(ExecutionServiceHandler::class.toString()) + fun upload(filePart: FilePart): Mono<String> { + try { + val archivedPath = BluePrintFileUtils.getCbaStorageDirectory(bluePrintCoreConfiguration.archivePath) + val cbaPath = saveCBAFile(filePart, archivedPath) + bluePrintCatalogService.saveToDatabase(cbaPath.toFile()).let { + return Mono.just("{\"status\": \"Successfully uploaded blueprint with id($it)\"}") + } + } catch (e: Exception) { + return Mono.error<String>(BluePrintException("Error uploading the CBA file.", e)) + } + } + fun process(executionServiceInput: ExecutionServiceInput): ExecutionServiceOutput { + return when { + executionServiceInput.actionIdentifiers.mode == ACTION_MODE_ASYNC -> { + GlobalScope.launch(Dispatchers.Default) { + // TODO post result in DMaaP + val executionServiceOutput = doProcess(executionServiceInput) + } + response(executionServiceInput) + } + executionServiceInput.actionIdentifiers.mode == ACTION_MODE_SYNC -> doProcess(executionServiceInput) + else -> response(executionServiceInput, "Failed to process request, 'actionIdentifiers.mode' not specified. Valid value are: 'sync' or 'async'.", true) + } + } + private fun doProcess(executionServiceInput: ExecutionServiceInput): ExecutionServiceOutput { val requestId = executionServiceInput.commonHeader.requestId log.info("processing request id $requestId") @@ -40,13 +79,34 @@ class ExecutionServiceHandler(private val bluePrintCatalogService: BluePrintCata val blueprintName = actionIdentifiers.blueprintName val blueprintVersion = actionIdentifiers.blueprintVersion - val basePath = bluePrintCatalogService.prepareBluePrint(blueprintName, blueprintVersion) + val basePath = bluePrintCatalogService.getFromDatabase(blueprintName, blueprintVersion) log.info("blueprint base path $basePath") - val blueprintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime(requestId, basePath) + val blueprintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime(requestId, basePath.toString()) return blueprintDGExecutionService.executeDirectedGraph(blueprintRuntimeService, executionServiceInput) } + fun response(executionServiceInput: ExecutionServiceInput, errorMessage: String = "", failure: Boolean = false): ExecutionServiceOutput { + val executionServiceOutput = ExecutionServiceOutput() + executionServiceOutput.commonHeader = executionServiceInput.commonHeader + executionServiceOutput.actionIdentifiers = executionServiceInput.actionIdentifiers + executionServiceOutput.payload = executionServiceInput.payload + + val status = Status() + status.errorMessage = errorMessage + if (failure) { + status.eventType = "EVENT-COMPONENT-FAILURE" + status.code = 500 + status.message = BluePrintConstants.STATUS_FAILURE + } else { + status.eventType = "EVENT-COMPONENT-PROCESSING" + status.code = 200 + status.message = BluePrintConstants.STATUS_PROCESSING + } + executionServiceOutput.status = status + + return executionServiceOutput + } }
\ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/utils/BluePrintMappings.kt b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/utils/BluePrintMappings.kt new file mode 100644 index 00000000..220a6fd6 --- /dev/null +++ b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/utils/BluePrintMappings.kt @@ -0,0 +1,168 @@ +/* + * Copyright (C) 2019 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. + */ +package org.onap.ccsdk.apps.blueprintsprocessor.selfservice.api.utils + +import com.fasterxml.jackson.databind.node.JsonNodeFactory +import com.fasterxml.jackson.databind.node.ObjectNode +import com.google.common.base.Strings +import com.google.protobuf.Struct +import com.google.protobuf.Value +import org.onap.ccsdk.apps.controllerblueprints.common.api.ActionIdentifiers +import org.onap.ccsdk.apps.controllerblueprints.common.api.CommonHeader +import org.onap.ccsdk.apps.controllerblueprints.common.api.Flag +import org.onap.ccsdk.apps.controllerblueprints.common.api.Status +import org.onap.ccsdk.apps.controllerblueprints.processing.api.ExecutionServiceInput +import org.onap.ccsdk.apps.controllerblueprints.processing.api.ExecutionServiceOutput +import java.text.SimpleDateFormat +import java.util.* + +private val formatter = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") + +// STRUCT + +fun Struct.toJava(): ObjectNode { + val objectNode = JsonNodeFactory.instance.objectNode() + return getNode(objectNode) +} + +fun Struct.getNode(objectNode: ObjectNode): ObjectNode { + this.fieldsMap.forEach { + when (it.value.kindCase.name) { + "BOOL_VALUE" -> objectNode.put(it.key, it.value.boolValue) + "KIND_NOT_SET" -> objectNode.put(it.key, it.value.toByteArray()) + "LIST_VALUE" -> { + val arrayNode = JsonNodeFactory.instance.arrayNode() + it.value.listValue.valuesList.forEach { arrayNode.addPOJO(it.getValue()) } + objectNode.put(it.key, arrayNode) + } + "NULL_VALUE" -> objectNode.put(it.key, JsonNodeFactory.instance.nullNode()) + "NUMBER_VALUE" -> objectNode.put(it.key, it.value.numberValue) + "STRING_VALUE" -> objectNode.put(it.key, it.value.stringValue) + "STRUCT_VALUE" -> objectNode.put(it.key, it.value.structValue.getNode(JsonNodeFactory.instance.objectNode())) + } + } + return objectNode +} + +fun Value.getValue(): Any { + return when (this.kindCase.name) { + "BOOL_VALUE" -> this.boolValue + "KIND_NOT_SET" -> this.toByteArray() + "LIST_VALUE" -> listOf(this.listValue.valuesList.forEach { it.getValue() }) + "NULL_VALUE" -> JsonNodeFactory.instance.nullNode() + "NUMBER_VALUE" -> this.numberValue + "STRING_VALUE" -> this.stringValue + "STRUCT_VALUE" -> this.structValue.getNode(JsonNodeFactory.instance.objectNode()) + else -> { + "undefined" + } + } +} + +// ACTION IDENTIFIER + +fun org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ActionIdentifiers.toProto(): ActionIdentifiers { + val actionIdentifier = ActionIdentifiers.newBuilder() + actionIdentifier.actionName = this.actionName + actionIdentifier.blueprintName = this.blueprintName + actionIdentifier.blueprintVersion = this.blueprintVersion + actionIdentifier.mode = this.mode + return actionIdentifier.build() +} + +fun ActionIdentifiers.toJava(): org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ActionIdentifiers { + val actionIdentifier = org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ActionIdentifiers() + actionIdentifier.actionName = this.actionName + actionIdentifier.blueprintName = this.blueprintName + actionIdentifier.blueprintVersion = this.blueprintVersion + actionIdentifier.mode = this.mode + return actionIdentifier +} + +// COMMON HEADER + +fun org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.CommonHeader.toProto(): CommonHeader { + val commonHeader = CommonHeader.newBuilder() + commonHeader.originatorId = this.originatorId + commonHeader.requestId = this.requestId + commonHeader.subRequestId = this.subRequestId + commonHeader.timestamp = this.timestamp.toString() + commonHeader.flag = this.flags?.toProto() + return commonHeader.build() +} + +fun CommonHeader.toJava(): org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.CommonHeader { + val commonHeader = org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.CommonHeader() + commonHeader.originatorId = this.originatorId + commonHeader.requestId = this.requestId + commonHeader.subRequestId = this.subRequestId + commonHeader.timestamp = if (!Strings.isNullOrEmpty(this.timestamp)) { + formatter.parse(this.timestamp) + } else { + Date() + } + commonHeader.flags = this.flag?.toJava() + return commonHeader +} + +// FLAG + +fun org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.Flags.toProto(): Flag { + val flag = Flag.newBuilder() + flag.isForce = this.isForce + flag.ttl = this.ttl + return flag.build() +} + +fun Flag.toJava(): org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.Flags { + val flag = org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.Flags() + flag.isForce = this.isForce + flag.ttl = this.ttl + return flag +} + +// STATUS + +fun org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.Status.toProto(): Status { + val status = Status.newBuilder() + status.code = this.code + status.errorMessage = this.errorMessage + status.message = this.message + status.timestamp = this.timestamp.toString() + status.eventType = this.eventType + return status.build() +} + +// EXECUTION INPUT + +fun ExecutionServiceInput.toJava(): org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceInput { + val executionServiceInput = org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceInput() + executionServiceInput.actionIdentifiers = this.actionIdentifiers.toJava() + executionServiceInput.commonHeader = this.commonHeader.toJava() + executionServiceInput.payload = this.payload.toJava() + return executionServiceInput +} + +// EXECUTION OUPUT + +fun org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceOutput.toProto(payload: Struct): ExecutionServiceOutput { + val executionServiceOuput = ExecutionServiceOutput.newBuilder() + executionServiceOuput.actionIdentifiers = this.actionIdentifiers.toProto() + executionServiceOuput.commonHeader = this.commonHeader.toProto() + executionServiceOuput.status = this.status.toProto() + executionServiceOuput.payload = payload + return executionServiceOuput.build() +}
\ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/utils/Utils.kt b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/utils/Utils.kt new file mode 100644 index 00000000..6d22fdab --- /dev/null +++ b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/utils/Utils.kt @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2019 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. + */ +package org.onap.ccsdk.apps.blueprintsprocessor.selfservice.api.utils + +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException +import org.springframework.http.codec.multipart.FilePart +import org.springframework.util.StringUtils +import java.io.File +import java.io.IOException +import java.nio.file.Path +import java.time.LocalDateTime +import java.time.ZoneId +import java.time.format.DateTimeFormatter +import java.util.* + + +fun currentTimestamp(): String { + val now = LocalDateTime.now(ZoneId.systemDefault()) + val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") + return formatter.format(now) +} + + +@Throws(BluePrintException::class, IOException::class) +fun saveCBAFile(filePart: FilePart, targetDirectory: Path): Path { + + val fileName = StringUtils.cleanPath(filePart.filename()) + + if (StringUtils.getFilenameExtension(fileName) != "zip") { + throw BluePrintException("Invalid file extension required ZIP") + } + + val changedFileName = UUID.randomUUID().toString() + ".zip" + + val targetLocation = targetDirectory.resolve(changedFileName) + + val file = File(targetLocation.toString()) + if (file.exists()) { + file.delete() + } + file.createNewFile() + + filePart.transferTo(file) + + return targetLocation +}
\ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/BluePrintManagementGRPCHandlerTest.kt b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/BluePrintManagementGRPCHandlerTest.kt index c870bf7f..264e2aea 100644 --- a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/BluePrintManagementGRPCHandlerTest.kt +++ b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/BluePrintManagementGRPCHandlerTest.kt @@ -1,5 +1,6 @@ /* * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2019 Bell Canada. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,34 +19,32 @@ package org.onap.ccsdk.apps.blueprintsprocessor.selfservice.api import com.google.protobuf.ByteString import io.grpc.testing.GrpcServerRule -import org.apache.commons.io.FileUtils import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith -import org.onap.ccsdk.apps.blueprintsprocessor.core.BluePrintCoreConfiguration +import org.onap.ccsdk.apps.controllerblueprints.common.api.CommonHeader +import org.onap.ccsdk.apps.controllerblueprints.management.api.BluePrintManagementInput import org.onap.ccsdk.apps.controllerblueprints.management.api.BluePrintManagementServiceGrpc -import org.onap.ccsdk.apps.controllerblueprints.management.api.BluePrintUploadInput -import org.onap.ccsdk.apps.controllerblueprints.management.api.CommonHeader import org.onap.ccsdk.apps.controllerblueprints.management.api.FileChunk -import org.slf4j.LoggerFactory import org.springframework.beans.factory.annotation.Autowired -import org.springframework.test.context.ContextConfiguration +import org.springframework.boot.autoconfigure.EnableAutoConfiguration +import org.springframework.context.annotation.ComponentScan +import org.springframework.test.annotation.DirtiesContext import org.springframework.test.context.TestPropertySource import org.springframework.test.context.junit4.SpringRunner import java.io.File -import java.nio.file.Paths import kotlin.test.AfterTest import kotlin.test.BeforeTest -import kotlin.test.assertNotNull +import kotlin.test.assertEquals import kotlin.test.assertTrue @RunWith(SpringRunner::class) -@ContextConfiguration(classes = [BluePrintManagementGRPCHandler::class, BluePrintCoreConfiguration::class]) +@EnableAutoConfiguration +@DirtiesContext +@ComponentScan(basePackages = ["org.onap.ccsdk.apps.blueprintsprocessor", "org.onap.ccsdk.apps.controllerblueprints"]) @TestPropertySource(locations = ["classpath:application-test.properties"]) class BluePrintManagementGRPCHandlerTest { - private val log = LoggerFactory.getLogger(BluePrintProcessingGRPCHandlerTest::class.java)!! - @get:Rule val grpcServerRule = GrpcServerRule().directExecutor() @@ -60,33 +59,58 @@ class BluePrintManagementGRPCHandlerTest { @AfterTest fun cleanDir() { - FileUtils.deleteDirectory(File("./target/blueprints")) + //TODO It's giving fluctuating results, need to look for another way to cleanup + // works sometimes otherwise results IO Exception + // Most probably bufferReader stream is not getting closed when cleanDir is getting invoked + File("./target/blueprints").deleteRecursively() + } + + @Test + fun `test upload blueprint`() { + val blockingStub = BluePrintManagementServiceGrpc.newBlockingStub(grpcServerRule.channel) + val id = "123_upload" + val req = createInputRequest(id) + val output = blockingStub.uploadBlueprint(req) + + assertEquals(200, output.status.code) + assertTrue(output.status.message.contains("Successfully uploaded blueprint sample:1.0.0 with id(")) + assertEquals(id, output.commonHeader.requestId) } @Test - fun testFileUpload() { + fun `test delete blueprint`() { val blockingStub = BluePrintManagementServiceGrpc.newBlockingStub(grpcServerRule.channel) + val id = "123_delete" + val req = createInputRequest(id) + + var output = blockingStub.uploadBlueprint(req) + assertEquals(200, output.status.code) + assertTrue(output.status.message.contains("Successfully uploaded blueprint sample:1.0.0 with id(")) + assertEquals(id, output.commonHeader.requestId) - val file = Paths.get("./src/test/resources/test-cba.zip").toFile() + output = blockingStub.removeBlueprint(req) + assertEquals(200, output.status.code) + } + + private fun createInputRequest(id: String): BluePrintManagementInput { + val file = File("./src/test/resources/test-cba.zip") assertTrue(file.exists(), "couldnt get file ${file.absolutePath}") - val commonHeader = CommonHeader.newBuilder() + val commonHeader = CommonHeader + .newBuilder() .setTimestamp("2012-04-23T18:25:43.511Z") .setOriginatorId("System") - .setRequestId("1234") + .setRequestId(id) .setSubRequestId("1234-56").build() val fileChunk = FileChunk.newBuilder().setChunk(ByteString.copyFrom(file.inputStream().readBytes())) .build() - val input = BluePrintUploadInput.newBuilder() + return BluePrintManagementInput.newBuilder() .setCommonHeader(commonHeader) .setBlueprintName("sample") .setBlueprintVersion("1.0.0") .setFileChunk(fileChunk) .build() - - val output = blockingStub.uploadBlueprint(input) - assertNotNull(output, "failed to get upload response") } -}
\ No newline at end of file +} diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/BluePrintProcessingGRPCHandlerTest.kt b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/BluePrintProcessingGRPCHandlerTest.kt index cd871b4a..01984b21 100644 --- a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/BluePrintProcessingGRPCHandlerTest.kt +++ b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/BluePrintProcessingGRPCHandlerTest.kt @@ -1,5 +1,6 @@ /* * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2019 Bell Canada. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,33 +19,36 @@ package org.onap.ccsdk.apps.blueprintsprocessor.selfservice.api import com.google.protobuf.util.JsonFormat +import io.grpc.stub.StreamObserver import io.grpc.testing.GrpcServerRule +import org.junit.Assert +import org.junit.Ignore import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith -import org.onap.ccsdk.apps.blueprintsprocessor.core.BluePrintCoreConfiguration -import org.onap.ccsdk.apps.blueprintsprocessor.selfservice.api.mock.MockBluePrintCatalogService -import org.onap.ccsdk.apps.blueprintsprocessor.selfservice.api.mock.MockBlueprintDGExecutionService +import org.onap.ccsdk.apps.controllerblueprints.common.api.ActionIdentifiers +import org.onap.ccsdk.apps.controllerblueprints.common.api.CommonHeader import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils import org.onap.ccsdk.apps.controllerblueprints.processing.api.BluePrintProcessingServiceGrpc -import org.onap.ccsdk.apps.controllerblueprints.processing.api.CommonHeader import org.onap.ccsdk.apps.controllerblueprints.processing.api.ExecutionServiceInput +import org.onap.ccsdk.apps.controllerblueprints.processing.api.ExecutionServiceOutput import org.slf4j.LoggerFactory import org.springframework.beans.factory.annotation.Autowired -import org.springframework.test.context.ContextConfiguration +import org.springframework.boot.autoconfigure.EnableAutoConfiguration +import org.springframework.context.annotation.ComponentScan +import org.springframework.test.annotation.DirtiesContext import org.springframework.test.context.TestPropertySource import org.springframework.test.context.junit4.SpringRunner import kotlin.test.BeforeTest -import kotlin.test.assertNotNull +@Ignore @RunWith(SpringRunner::class) -@ContextConfiguration(classes = [BluePrintProcessingGRPCHandler::class, ExecutionServiceHandler::class, - MockBlueprintDGExecutionService::class, MockBluePrintCatalogService::class, - BluePrintCoreConfiguration::class]) +@DirtiesContext +@EnableAutoConfiguration +@ComponentScan(basePackages = ["org.onap.ccsdk.apps.blueprintsprocessor", "org.onap.ccsdk.apps.controllerblueprints"]) @TestPropertySource(locations = ["classpath:application-test.properties"]) class BluePrintProcessingGRPCHandlerTest { - - private val log = LoggerFactory.getLogger(BluePrintProcessingGRPCHandlerTest::class.java)!! + private val log = LoggerFactory.getLogger(BluePrintProcessingGRPCHandlerTest::class.java) @get:Rule val grpcServerRule = GrpcServerRule().directExecutor() @@ -52,17 +56,35 @@ class BluePrintProcessingGRPCHandlerTest { @Autowired lateinit var bluePrintProcessingGRPCHandler: BluePrintProcessingGRPCHandler + lateinit var requestObs: StreamObserver<ExecutionServiceInput> + @BeforeTest fun init() { - // Create a server, add service, start, and register for automatic graceful shutdown. grpcServerRule.serviceRegistry.addService(bluePrintProcessingGRPCHandler) + + val blockingStub = BluePrintProcessingServiceGrpc.newStub(grpcServerRule.channel) + + requestObs = blockingStub.process(object : StreamObserver<ExecutionServiceOutput> { + override fun onNext(executionServiceOuput: ExecutionServiceOutput) { + log.debug("onNext {}", executionServiceOuput) + if ("1234".equals(executionServiceOuput.commonHeader.requestId)) { + Assert.assertEquals("Failed to process request, \'actionIdentifiers.mode\' not specified. Valid value are: \'sync\' or \'async\'.", executionServiceOuput.status.errorMessage) + } + } + + override fun onError(error: Throwable) { + log.debug("Fail to process message", error) + Assert.assertEquals("INTERNAL: Could not find blueprint : from database", error.message) + } + + override fun onCompleted() { + log.info("Done") + } + }) } @Test fun testSelfServiceGRPCHandler() { - - val blockingStub = BluePrintProcessingServiceGrpc.newBlockingStub(grpcServerRule.channel) - val commonHeader = CommonHeader.newBuilder() .setTimestamp("2012-04-23T18:25:43.511Z") .setOriginatorId("System") @@ -78,8 +100,25 @@ class BluePrintProcessingGRPCHandlerTest { .setPayload(payloadBuilder.build()) .build() - val response = blockingStub.process(input) - assertNotNull(response, "Response is null") + requestObs.onNext(input) + + val commonHeader2 = CommonHeader.newBuilder() + .setTimestamp("2012-04-23T18:25:43.511Z") + .setOriginatorId("System") + .setRequestId("2345") + .setSubRequestId("1234-56").build() + + val actionIdentifier = ActionIdentifiers.newBuilder().setMode("sync").build() + + val input2 = ExecutionServiceInput.newBuilder() + .setCommonHeader(commonHeader2) + .setActionIdentifiers(actionIdentifier) + .setPayload(payloadBuilder.build()) + .build() + + requestObs.onNext(input2) + + requestObs.onCompleted() } }
\ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/ExecutionServiceHandlerTest.kt b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/ExecutionServiceHandlerTest.kt index e9e10307..de120148 100644 --- a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/ExecutionServiceHandlerTest.kt +++ b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/ExecutionServiceHandlerTest.kt @@ -1,5 +1,6 @@ /* * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2019 Bell Canada. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,33 +19,70 @@ package org.onap.ccsdk.apps.blueprintsprocessor.selfservice.api import org.junit.Test import org.junit.runner.RunWith +import org.onap.ccsdk.apps.blueprintsprocessor.core.BluePrintCoreConfiguration import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceInput -import org.onap.ccsdk.apps.blueprintsprocessor.selfservice.api.mock.MockBluePrintCatalogService -import org.onap.ccsdk.apps.blueprintsprocessor.selfservice.api.mock.MockBlueprintDGExecutionService -import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintMetadataUtils +import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintCatalogService import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils import org.springframework.beans.factory.annotation.Autowired +import org.springframework.boot.test.autoconfigure.web.reactive.WebFluxTest +import org.springframework.context.annotation.ComponentScan +import org.springframework.core.io.ByteArrayResource +import org.springframework.http.client.MultipartBodyBuilder import org.springframework.test.context.ContextConfiguration +import org.springframework.test.context.TestPropertySource import org.springframework.test.context.junit4.SpringRunner +import org.springframework.test.web.reactive.server.WebTestClient +import org.springframework.web.reactive.function.BodyInserters +import java.nio.file.Files +import java.nio.file.Paths +import kotlin.test.assertTrue @RunWith(SpringRunner::class) -@ContextConfiguration(classes = [MockBluePrintCatalogService::class, - MockBlueprintDGExecutionService::class, ExecutionServiceHandler::class]) +@WebFluxTest +@ContextConfiguration(classes = [ExecutionServiceHandler::class, BluePrintCoreConfiguration::class, BluePrintCatalogService::class]) +@ComponentScan(basePackages = ["org.onap.ccsdk.apps.blueprintsprocessor", "org.onap.ccsdk.apps.controllerblueprints"]) +@TestPropertySource(locations = ["classpath:application-test.properties"]) class ExecutionServiceHandlerTest { @Autowired - lateinit var executionServiceHandler: ExecutionServiceHandler + lateinit var blueprintCatalog: BluePrintCatalogService + @Autowired + lateinit var webTestClient: WebTestClient + @Test - fun testProcess() { - val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime("1234", - "./../../../../../components/model-catalog/blueprint-model/starter-blueprint/baseconfiguration") + fun `test rest upload blueprint`() { + val file = Paths.get("./src/test/resources/test-cba.zip").toFile() + assertTrue(file.exists(), "couldnt get file ${file.absolutePath}") - val executionServiceInput = JacksonUtils.readValueFromClassPathFile("execution-input/default-input.json", ExecutionServiceInput::class.java)!! - executionServiceHandler.process(executionServiceInput) + val body = MultipartBodyBuilder().apply { + part("file", object : ByteArrayResource(Files.readAllBytes(Paths.get("./src/test/resources/test-cba.zip"))) { + override fun getFilename(): String { + return "test-cba.zip" + } + }) + }.build() + webTestClient + .post() + .uri("/api/v1/execution-service/upload") + .body(BodyInserters.fromMultipartData(body)) + .exchange() + .expectStatus().isOk } -} - + @Test + fun `test rest process`() { + val file = Paths.get("./src/test/resources/test-cba.zip").toFile() + assertTrue(file.exists(), "couldnt get file ${file.absolutePath}") + blueprintCatalog.saveToDatabase(file) + val executionServiceInput = JacksonUtils.readValueFromClassPathFile("execution-input/default-input.json", ExecutionServiceInput::class.java)!! + webTestClient + .post() + .uri("/api/v1/execution-service/process") + .body(BodyInserters.fromObject(executionServiceInput)) + .exchange() + .expectStatus().isOk + } +}
\ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/mock/Mock.kt b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/mock/Mock.kt new file mode 100644 index 00000000..c54e6176 --- /dev/null +++ b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/mock/Mock.kt @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2019 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. + */ +package org.onap.ccsdk.apps.blueprintsprocessor.selfservice.api.mock + +import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceInput +import org.onap.ccsdk.apps.blueprintsprocessor.services.execution.AbstractComponentFunction +import org.onap.ccsdk.apps.controllerblueprints.core.asJsonPrimitive +import org.slf4j.LoggerFactory +import org.springframework.context.annotation.Bean +import org.springframework.context.annotation.Configuration + +@Configuration +open class MockComponentConfiguration { + + @Bean(name = ["component-resource-assignment", "component-netconf-executor", "component-jython-executor"]) + open fun createComponentFunction(): AbstractComponentFunction { + return MockComponentFunction() + } +} + +class MockComponentFunction : AbstractComponentFunction() { + + private val log = LoggerFactory.getLogger(MockComponentFunction::class.java) + + override fun process(executionRequest: ExecutionServiceInput) { + log.info("Processing component : $operationInputs") + + bluePrintRuntimeService.setNodeTemplateAttributeValue(nodeTemplateName, + "assignment-params", "params".asJsonPrimitive()) + } + + override fun recover(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) { + log.info("Recovering component..") + } +}
\ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/mock/SelfServiceApiMocks.kt b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/mock/SelfServiceApiMocks.kt deleted file mode 100755 index 656d92f1..00000000 --- a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/mock/SelfServiceApiMocks.kt +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * - * 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. - */ - -package org.onap.ccsdk.apps.blueprintsprocessor.selfservice.api.mock - -import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceInput -import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceOutput -import org.onap.ccsdk.apps.blueprintsprocessor.services.workflow.BlueprintDGExecutionService -import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintCatalogService -import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService -import org.springframework.stereotype.Service -import kotlin.test.assertNotNull - -@Service -class MockBlueprintDGExecutionService : BlueprintDGExecutionService { - override fun executeDirectedGraph(bluePrintRuntimeService: BluePrintRuntimeService<*>, executionServiceInput: ExecutionServiceInput): ExecutionServiceOutput { - - assertNotNull(executionServiceInput, "failed to get executionServiceInput") - - val executionServiceOutput = ExecutionServiceOutput() - executionServiceOutput.commonHeader = executionServiceInput.commonHeader - return executionServiceOutput - } -} - -@Service -class MockBluePrintCatalogService : BluePrintCatalogService { - - override fun uploadToDataBase(file: String, validate : Boolean): String { - TODO("not implemented") //To change body of created functions use File | Settings | File Templates. - } - - override fun downloadFromDataBase(name: String, version: String, path: String): String { - TODO("not implemented") //To change body of created functions use File | Settings | File Templates. - } - - override fun prepareBluePrint(name: String, version: String): String { - assertNotNull(name, "failed to get blueprint Name") - assertNotNull(version, "failed to get blueprint version") - return "./../../../../../components/model-catalog/blueprint-model/starter-blueprint/baseconfiguration" - } - - override fun downloadFromDataBase(uuid: String, path: String): String { - TODO("not implemented") //To change body of created functions use File | Settings | File Templates. - } -}
\ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/utils/BluePrintMappingTests.kt b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/utils/BluePrintMappingTests.kt new file mode 100644 index 00000000..2e4ba275 --- /dev/null +++ b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/utils/BluePrintMappingTests.kt @@ -0,0 +1,172 @@ +package org.onap.ccsdk.apps.blueprintsprocessor.selfservice.api.utils + +import com.fasterxml.jackson.databind.ObjectMapper +import com.google.protobuf.ListValue +import com.google.protobuf.NullValue +import com.google.protobuf.Struct +import com.google.protobuf.Value +import com.google.protobuf.util.JsonFormat +import org.junit.Assert +import org.junit.Test +import org.junit.runner.RunWith +import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.Flags +import org.onap.ccsdk.apps.controllerblueprints.common.api.ActionIdentifiers +import org.onap.ccsdk.apps.controllerblueprints.common.api.CommonHeader +import org.onap.ccsdk.apps.controllerblueprints.common.api.Flag +import org.springframework.test.context.junit4.SpringRunner +import java.text.SimpleDateFormat + +@RunWith(SpringRunner::class) +class BluePrintMappingsTest { + + val formatter = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") + val dateString = "2019-01-16T18:25:43.511Z" + val dateForTest = formatter.parse(dateString) + + val flag = Flag.newBuilder().setIsForce(false).setTtl(1).build() + + fun createFlag(): Flags { + val flag = Flags() + flag.isForce = false + flag.ttl = 1 + return flag + } + + @Test + fun flagToJavaTest() { + val flag2 = flag.toJava() + + Assert.assertEquals(flag.isForce, flag2.isForce) + Assert.assertEquals(flag.ttl, flag2.ttl) + } + + @Test + fun flagToProtoTest() { + val flag = createFlag() + val flag2 = flag.toProto() + + Assert.assertEquals(flag.isForce, flag2.isForce) + Assert.assertEquals(flag.ttl, flag2.ttl) + } + + fun createStatus(): org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.Status { + val status = org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.Status() + status.code = 400 + status.errorMessage = "Concurrent modification exception" + status.eventType = "Update" + status.message = "Error uploading data" + status.timestamp = dateForTest + return status + } + + @Test + fun statusToProtoTest() { + val status = createStatus() + val status2 = status.toProto() + + Assert.assertEquals(status.code, status2.code) + Assert.assertEquals(status.errorMessage, status2.errorMessage) + Assert.assertEquals(status.eventType, status2.eventType) + Assert.assertEquals(status.message, status2.message) + Assert.assertEquals(status.timestamp.toString(), status2.timestamp) + } + + @Test + fun commonHeaderToJavaTest() { + val flag = Flag.newBuilder().setIsForce(true).setTtl(2).build() + + val commonHeader = CommonHeader.newBuilder().setOriginatorId("Origin").setRequestId("requestID").setSubRequestId("subRequestID").setTimestamp(dateString).setFlag(flag).build() + val commonHeader2 = commonHeader.toJava() + + Assert.assertEquals(commonHeader.originatorId, commonHeader2.originatorId) + Assert.assertEquals(commonHeader.requestId, commonHeader2.requestId) + Assert.assertEquals(commonHeader.subRequestId, commonHeader2.subRequestId) + Assert.assertEquals(commonHeader.timestamp, formatter.format(commonHeader2.timestamp)) + } + + fun createCommonHeader(): org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.CommonHeader { + val commonHeader = org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.CommonHeader() + commonHeader.flags = createFlag() + commonHeader.originatorId = "1234" + commonHeader.requestId = "2345" + commonHeader.subRequestId = "0123" + commonHeader.timestamp = dateForTest + return commonHeader + } + + @Test + fun commonHeaderToProtoTest() { + val commonHeader = createCommonHeader() + val commonHeader2 = commonHeader.toProto() + Assert.assertEquals(commonHeader.originatorId, commonHeader2.originatorId) + Assert.assertEquals(commonHeader.requestId, commonHeader2.requestId) + Assert.assertEquals(commonHeader.subRequestId, commonHeader2.subRequestId) + Assert.assertEquals(commonHeader.timestamp.toString(), commonHeader2.timestamp) + } + + @Test + fun actionIdentifierToJavaTest() { + val actionIdentifiers = ActionIdentifiers.newBuilder().setActionName("Process Action").setBlueprintName("BlueprintName").setBlueprintVersion("3.0").setMode("Execution").build() + val actionIdentifiers2 = actionIdentifiers.toJava() + + Assert.assertEquals(actionIdentifiers.actionName, actionIdentifiers2.actionName) + Assert.assertEquals(actionIdentifiers.blueprintName, actionIdentifiers2.blueprintName) + Assert.assertEquals(actionIdentifiers.blueprintVersion, actionIdentifiers2.blueprintVersion) + Assert.assertEquals(actionIdentifiers.mode, actionIdentifiers2.mode) + } + + fun createActionIdentifier(): org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ActionIdentifiers { + val ac = org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ActionIdentifiers() + ac.mode = "mode" + ac.blueprintVersion = "version" + ac.blueprintName = "name" + ac.actionName = "action" + return ac + } + + @Test + fun actionIdentifierToProtoTest() { + val actionIdentifiers = createActionIdentifier() + val actionIdentifiers2 = actionIdentifiers.toProto() + + Assert.assertEquals(actionIdentifiers.actionName, actionIdentifiers2.actionName) + Assert.assertEquals(actionIdentifiers.blueprintName, actionIdentifiers2.blueprintName) + Assert.assertEquals(actionIdentifiers.blueprintVersion, actionIdentifiers2.blueprintVersion) + Assert.assertEquals(actionIdentifiers.mode, actionIdentifiers2.mode) + } + + @Test + fun testStructToJava() { + val struct = Struct.newBuilder().putAllFields(createValues()).build() + val struct2 = struct.toJava() + + val mapper = ObjectMapper() + + Assert.assertEquals(JsonFormat.printer().print(struct).replace(" ", "").replace("\r",""), + mapper.writerWithDefaultPrettyPrinter().writeValueAsString(struct2).replace(" ", "").replace("\r","")) + } + + fun createValues(): Map<String, Value> { + val map = mutableMapOf<String, Value>() + + val boolValue = Value.newBuilder().setBoolValue(true).build() + val stringValue = Value.newBuilder().setStringValue("string").build() + val doubleValue = Value.newBuilder().setNumberValue(Double.MAX_VALUE).build() + val jsonValue = Value.newBuilder().setStringValue("{\"bblah\": \"bbblo\"}").build() + val listValue = Value.newBuilder().setListValue(ListValue.newBuilder().addValues(boolValue).addValues(boolValue).build()).build() + val nullValue = Value.newBuilder().setNullValue(NullValue.NULL_VALUE).build() + + map.put("bool", boolValue) + map.put("string", stringValue) + map.put("doublbe", doubleValue) + map.put("json", jsonValue) + map.put("list", listValue) + map.put("null", nullValue) + + val structValue = Value.newBuilder().setStructValue(Struct.newBuilder().putAllFields(map).build()).build() + + map.put("struct", structValue) + + return map + } +}
\ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/resources/application-test.properties b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/resources/application-test.properties index edb51022..8a26ee6e 100644 --- a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/resources/application-test.properties +++ b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/resources/application-test.properties @@ -13,5 +13,16 @@ # See the License for the specific language governing permissions and # limitations under the License. # +blueprintsprocessor.db.primary.url=jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1 +blueprintsprocessor.db.primary.username=sa +blueprintsprocessor.db.primary.password= +blueprintsprocessor.db.primary.driverClassName=org.h2.Driver +blueprintsprocessor.db.primary.hibernateHbm2ddlAuto=create-drop +blueprintsprocessor.db.primary.hibernateDDLAuto=update +blueprintsprocessor.db.primary.hibernateNamingStrategy=org.hibernate.cfg.ImprovedNamingStrategy +blueprintsprocessor.db.primary.hibernateDialect=org.hibernate.dialect.H2Dialect +# Controller Blueprints Core Configuration blueprintsprocessor.blueprintDeployPath=./target/blueprints/deploy blueprintsprocessor.blueprintArchivePath=./target/blueprints/archive +# executor +blueprints.processor.functions.python.executor.executionPath="./target/" diff --git a/ms/blueprintsprocessor/modules/outbounds/pom.xml b/ms/blueprintsprocessor/modules/outbounds/pom.xml index e957c881..b6c26e67 100644 --- a/ms/blueprintsprocessor/modules/outbounds/pom.xml +++ b/ms/blueprintsprocessor/modules/outbounds/pom.xml @@ -15,16 +15,16 @@ ~ 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.apps.blueprintsprocessor</groupId> - <artifactId>modules</artifactId> - <version>0.4.1-SNAPSHOT</version> - </parent> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.onap.ccsdk.apps.blueprintsprocessor</groupId> + <artifactId>modules</artifactId> + <version>0.4.1-SNAPSHOT</version> + </parent> - <artifactId>outbounds</artifactId> - <packaging>pom</packaging> - <name>Blueprints Processor Outbounds POM</name> - <description>Blueprints Processor Outbounds</description> + <artifactId>outbounds</artifactId> + <packaging>pom</packaging> + <name>Blueprints Processor Outbounds POM</name> + <description>Blueprints Processor Outbounds</description> </project> diff --git a/ms/blueprintsprocessor/modules/services/execution-service/pom.xml b/ms/blueprintsprocessor/modules/services/execution-service/pom.xml index 035f14d9..96bb09f2 100644 --- a/ms/blueprintsprocessor/modules/services/execution-service/pom.xml +++ b/ms/blueprintsprocessor/modules/services/execution-service/pom.xml @@ -29,6 +29,10 @@ <dependencies> <dependency> + <groupId>org.onap.ccsdk.apps.controllerblueprints</groupId> + <artifactId>core</artifactId> + </dependency> + <dependency> <groupId>org.onap.ccsdk.apps.blueprintsprocessor</groupId> <artifactId>core</artifactId> </dependency> diff --git a/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/execution/AbstractComponentFunction.kt b/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/execution/AbstractComponentFunction.kt index c9e147ba..f7c901df 100644 --- a/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/execution/AbstractComponentFunction.kt +++ b/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/execution/AbstractComponentFunction.kt @@ -53,17 +53,17 @@ abstract class AbstractComponentFunction : BlueprintFunctionNode<ExecutionServic return stepName
}
- override fun prepareRequest(executionServiceInput: ExecutionServiceInput): ExecutionServiceInput {
+ override fun prepareRequest(executionRequest: ExecutionServiceInput): ExecutionServiceInput { checkNotNull(bluePrintRuntimeService) { "failed to prepare blueprint runtime" }
check(stepName.isNotEmpty()) { "failed to assign step name" }
- this.executionServiceInput = executionServiceInput
+ this.executionServiceInput = executionRequest - processId = executionServiceInput.commonHeader.requestId
+ processId = executionRequest.commonHeader.requestId check(processId.isNotEmpty()) { "couldn't get process id for step($stepName)" }
- workflowName = executionServiceInput.actionIdentifiers.actionName
+ workflowName = executionRequest.actionIdentifiers.actionName check(workflowName.isNotEmpty()) { "couldn't get action name for step($stepName)" }
log.info("preparing request id($processId) for workflow($workflowName) step($stepName)")
@@ -88,12 +88,14 @@ abstract class AbstractComponentFunction : BlueprintFunctionNode<ExecutionServic this.operationInputs.putAll(operationResolvedProperties)
- return executionServiceInput
+ return executionRequest }
override fun prepareResponse(): ExecutionServiceOutput {
log.info("Preparing Response...")
executionServiceOutput.commonHeader = executionServiceInput.commonHeader
+ executionServiceOutput.actionIdentifiers = executionServiceInput.actionIdentifiers + executionServiceOutput.payload = executionServiceInput.payload // Resolve the Output Expression
val stepOutputs = bluePrintRuntimeService
diff --git a/ms/blueprintsprocessor/modules/services/pom.xml b/ms/blueprintsprocessor/modules/services/pom.xml index 8cb3c6f1..469899d0 100644..100755 --- a/ms/blueprintsprocessor/modules/services/pom.xml +++ b/ms/blueprintsprocessor/modules/services/pom.xml @@ -2,6 +2,8 @@ <!-- ~ Copyright © 2017-2018 AT&T Intellectual Property. ~ + ~ Modifications Copyright © 2019 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 diff --git a/ms/blueprintsprocessor/modules/services/workflow-service/pom.xml b/ms/blueprintsprocessor/modules/services/workflow-service/pom.xml index 6e3dade6..cc2a0e66 100644 --- a/ms/blueprintsprocessor/modules/services/workflow-service/pom.xml +++ b/ms/blueprintsprocessor/modules/services/workflow-service/pom.xml @@ -28,6 +28,10 @@ <dependencies> <dependency> + <groupId>org.onap.ccsdk.apps.controllerblueprints</groupId> + <artifactId>core</artifactId> + </dependency> + <dependency> <groupId>org.onap.ccsdk.apps.blueprintsprocessor</groupId> <artifactId>execution-service</artifactId> </dependency> diff --git a/ms/blueprintsprocessor/parent/pom.xml b/ms/blueprintsprocessor/parent/pom.xml index 401fef0a..472b466b 100644..100755 --- a/ms/blueprintsprocessor/parent/pom.xml +++ b/ms/blueprintsprocessor/parent/pom.xml @@ -3,6 +3,7 @@ ~ Copyright © 2017-2018 AT&T Intellectual Property. ~ ~ Modifications Copyright © 2018 IBM. + ~ Modifications Copyright © 2019 Bell Canada. ~ ~ Licensed under the Apache License, Version 2.0 (the "License"); ~ you may not use this file except in compliance with the License. @@ -16,7 +17,8 @@ ~ 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"> +<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.apps</groupId> @@ -29,12 +31,12 @@ <name>Blueprints Processor Parent</name> <description>Blueprints Processor Parent</description> <properties> - <spring.boot.version>2.1.1.RELEASE</spring.boot.version> - <spring.version>5.1.3.RELEASE</spring.version> - <kotlin.version>1.3.11</kotlin.version> - <kotlin.maven.version>1.3.11</kotlin.maven.version> - <kotlin.couroutines.version>1.1.0</kotlin.couroutines.version> - <grpc.version>1.17.1</grpc.version> + <spring.boot.version>2.1.2.RELEASE</spring.boot.version> + <spring.version>5.1.4.RELEASE</spring.version> + <kotlin.version>1.3.20</kotlin.version> + <kotlin.maven.version>1.3.20</kotlin.maven.version> + <kotlin.couroutines.version>1.1.1</kotlin.couroutines.version> + <grpc.version>1.18.0</grpc.version> <protobuff.java.utils.version>3.6.1</protobuff.java.utils.version> <eelf.version>1.0.0</eelf.version> <sli.version>0.4.1-SNAPSHOT</sli.version> @@ -125,14 +127,26 @@ </dependency> <dependency> <groupId>org.jetbrains.kotlin</groupId> + <artifactId>kotlin-stdlib-common</artifactId> + <version>${kotlin.version}</version> + </dependency> + <!--Use kotlin-compiler-embeddable instead koltin-compiler wrap--> + <!--guava dependency inside kotlin-compiler creating classpath issues at runtime--> + <dependency> + <groupId>org.jetbrains.kotlin</groupId> <artifactId>kotlin-scripting-jvm-host</artifactId> <version>${kotlin.version}</version> + <exclusions> + <exclusion> + <groupId>org.jetbrains.kotlin</groupId> + <artifactId>kotlin-compile</artifactId> + </exclusion> + </exclusions> </dependency> <dependency> <groupId>org.jetbrains.kotlin</groupId> <artifactId>kotlin-compiler-embeddable</artifactId> <version>${kotlin.version}</version> - <scope>runtime</scope> </dependency> <dependency> <groupId>org.jetbrains.kotlin</groupId> @@ -246,6 +260,11 @@ <!-- Application Module Dependencies --> <dependency> <groupId>org.onap.ccsdk.apps.blueprintsprocessor</groupId> + <artifactId>application</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.onap.ccsdk.apps.blueprintsprocessor</groupId> <artifactId>db-lib</artifactId> <version>${project.version}</version> </dependency> @@ -303,6 +322,11 @@ <artifactId>resource-dict</artifactId> <version>${project.version}</version> </dependency> + <dependency> + <groupId>org.onap.ccsdk.apps.controllerblueprints</groupId> + <artifactId>core</artifactId> + <version>${project.version}</version> + </dependency> <!-- Database --> <dependency> @@ -400,7 +424,19 @@ </dependency> <dependency> <groupId>org.jetbrains.kotlin</groupId> + <artifactId>kotlin-compiler-embeddable</artifactId> + </dependency> + <dependency> + <groupId>org.jetbrains.kotlin</groupId> <artifactId>kotlin-scripting-jvm-host</artifactId> + <!--Use kotlin-compiler-embeddable as koltin-compiler wrap--> + <!--guava dependency creating classpath issues at runtime--> + <exclusions> + <exclusion> + <groupId>org.jetbrains.kotlin</groupId> + <artifactId>kotlin-compiler</artifactId> + </exclusion> + </exclusions> </dependency> <!-- GRPC Dependencies --> <dependency> diff --git a/ms/blueprintsprocessor/pom.xml b/ms/blueprintsprocessor/pom.xml index df4932cd..774e177e 100644..100755 --- a/ms/blueprintsprocessor/pom.xml +++ b/ms/blueprintsprocessor/pom.xml @@ -1,6 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> <!-- ~ Copyright © 2017-2018 AT&T Intellectual Property. + ~ Modifications Copyright © 2019 Bell Canada. ~ ~ Licensed under the Apache License, Version 2.0 (the "License"); ~ you may not use this file except in compliance with the License. @@ -15,34 +16,35 @@ ~ 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.apps</groupId> - <artifactId>ccsdk-apps-ms</artifactId> - <version>0.4.1-SNAPSHOT</version> - </parent> - <artifactId>blueprintsprocessor</artifactId> - <packaging>pom</packaging> - <name>Blueprints Processor Root</name> - <description>Blueprints Processor Root</description> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.onap.ccsdk.apps</groupId> + <artifactId>ccsdk-apps-ms</artifactId> + <version>0.4.1-SNAPSHOT</version> + </parent> + <artifactId>blueprintsprocessor</artifactId> + <packaging>pom</packaging> + <name>Blueprints Processor Root</name> + <description>Blueprints Processor Root</description> - <properties> - <service.name>BlueprintsProcessor</service.name> - <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> - <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> - <maven.build.timestamp.format>yyyyMMdd'T'HHmmss'Z'</maven.build.timestamp.format> - <build.number>${maven.build.timestamp}</build.number> - <java.version>1.8</java.version> - <maven.compiler.target>1.8</maven.compiler.target> - <maven.compiler.source>1.8</maven.compiler.source> - <ccsdk.project.version>${project.version}</ccsdk.project.version> - </properties> + <properties> + <service.name>BlueprintsProcessor</service.name> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> + <maven.build.timestamp.format>yyyyMMdd'T'HHmmss'Z'</maven.build.timestamp.format> + <build.number>${maven.build.timestamp}</build.number> + <java.version>1.8</java.version> + <maven.compiler.target>1.8</maven.compiler.target> + <maven.compiler.source>1.8</maven.compiler.source> + <ccsdk.project.version>${project.version}</ccsdk.project.version> + </properties> - <modules> - <module>parent</module> - <module>modules</module> - <module>functions</module> - <module>application</module> - </modules> + <modules> + <module>parent</module> + <module>modules</module> + <module>functions</module> + <module>application</module> + <module>distribution</module> + </modules> </project> |