summaryrefslogtreecommitdiffstats
path: root/ms/blueprintsprocessor/modules/inbounds
diff options
context:
space:
mode:
Diffstat (limited to 'ms/blueprintsprocessor/modules/inbounds')
-rw-r--r--ms/blueprintsprocessor/modules/inbounds/pom.xml81
-rw-r--r--ms/blueprintsprocessor/modules/inbounds/resource-api/pom.xml30
-rw-r--r--ms/blueprintsprocessor/modules/inbounds/resource-api/src/main/java/org/onap/ccsdk/apps/blueprintsprocessor/resource/api/ResourceResolutionController.java48
-rw-r--r--ms/blueprintsprocessor/modules/inbounds/resource-api/src/test/java/org/onap/ccsdk/apps/blueprintsprocessor/resource/api/ResourceResolutionControllerTest.java22
-rwxr-xr-xms/blueprintsprocessor/modules/inbounds/selfservice-api/pom.xml64
-rw-r--r--ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/BluePrintManagementGRPCHandler.kt115
-rw-r--r--ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/BluePrintProcessingGRPCHandler.kt64
-rw-r--r--ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/ExecutionServiceController.kt67
-rw-r--r--ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/ExecutionServiceHandler.kt142
-rw-r--r--ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/utils/BluePrintMappings.kt130
-rw-r--r--ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/utils/Utils.kt59
-rw-r--r--ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/validation/BluePrintRuntimeValidatorService.kt27
-rw-r--r--ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/BluePrintManagementGRPCHandlerTest.kt116
-rw-r--r--ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/BluePrintProcessingGRPCHandlerTest.kt124
-rw-r--r--ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/ExecutionServiceHandlerTest.kt89
-rw-r--r--ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/mock/Mock.kt62
-rw-r--r--ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/utils/BluePrintMappingTests.kt132
-rw-r--r--ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/validation/BluePrintRuntimeValidatorServiceTest.kt44
-rw-r--r--ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/resources/application-test.properties32
-rw-r--r--ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/resources/execution-input/default-input.json23
-rw-r--r--ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/resources/execution-input/sample-payload.json10
-rw-r--r--ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/resources/logback.xml35
-rw-r--r--ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/resources/test-cba.zipbin0 -> 9302 bytes
23 files changed, 1516 insertions, 0 deletions
diff --git a/ms/blueprintsprocessor/modules/inbounds/pom.xml b/ms/blueprintsprocessor/modules/inbounds/pom.xml
new file mode 100644
index 000000000..060c7e42d
--- /dev/null
+++ b/ms/blueprintsprocessor/modules/inbounds/pom.xml
@@ -0,0 +1,81 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Copyright © 2017-2018 AT&T Intellectual Property.
+ ~ Modifications Copyright © 2019 IBM.
+ ~
+ ~ Licensed under the Apache License, Version 2.0 (the "License");
+ ~ you may not use this file except in compliance with the License.
+ ~ You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ -->
+<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.2-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>inbounds</artifactId>
+ <packaging>pom</packaging>
+ <name>Blueprints Processor Inbounds POM</name>
+ <description>Blueprints Processor Inbounds</description>
+
+ <modules>
+ <module>resource-api</module>
+ <module>selfservice-api</module>
+ </modules>
+ <dependencies>
+ <dependency>
+ <groupId>org.onap.ccsdk.apps.blueprintsprocessor</groupId>
+ <artifactId>workflow-service</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.onap.ccsdk.apps.blueprintsprocessor.functions</groupId>
+ <artifactId>resource-resolution</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-actuator</artifactId>
+ </dependency>
+
+ <!-- Test Dependencies -->
+ <dependency>
+ <groupId>io.mockk</groupId>
+ <artifactId>mockk</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.powermock</groupId>
+ <artifactId>powermock-api-mockito2</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-test</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.jetbrains.kotlin</groupId>
+ <artifactId>kotlin-test-junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.jetbrains.kotlinx</groupId>
+ <artifactId>kotlinx-coroutines-test</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>io.projectreactor</groupId>
+ <artifactId>reactor-test</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+</project>
diff --git a/ms/blueprintsprocessor/modules/inbounds/resource-api/pom.xml b/ms/blueprintsprocessor/modules/inbounds/resource-api/pom.xml
new file mode 100644
index 000000000..26ce4a8c7
--- /dev/null
+++ b/ms/blueprintsprocessor/modules/inbounds/resource-api/pom.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ 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.
+ -->
+<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.2-SNAPSHOT</version>
+ </parent>
+
+ <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/resource-api/src/main/java/org/onap/ccsdk/apps/blueprintsprocessor/resource/api/ResourceResolutionController.java b/ms/blueprintsprocessor/modules/inbounds/resource-api/src/main/java/org/onap/ccsdk/apps/blueprintsprocessor/resource/api/ResourceResolutionController.java
new file mode 100644
index 000000000..fb833a573
--- /dev/null
+++ b/ms/blueprintsprocessor/modules/inbounds/resource-api/src/main/java/org/onap/ccsdk/apps/blueprintsprocessor/resource/api/ResourceResolutionController.java
@@ -0,0 +1,48 @@
+/*
+ * 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.resource.api;
+
+import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.ResourceResolutionService;
+import org.springframework.http.MediaType;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.ResponseBody;
+import org.springframework.web.bind.annotation.RestController;
+import reactor.core.publisher.Mono;
+
+/**
+ * ResourceResolutionController
+ *
+ * @author Brinda Santh Date : 8/13/2018
+ */
+
+@RestController
+@RequestMapping("/api/v1/resource")
+public class ResourceResolutionController {
+
+ private ResourceResolutionService resourceResolutionService;
+
+ public ResourceResolutionController(ResourceResolutionService resourceResolutionService) {
+ this.resourceResolutionService = resourceResolutionService;
+ }
+
+ @RequestMapping(path = "/ping", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
+ public @ResponseBody
+ Mono<String> ping() {
+ return Mono.just("Success");
+ }
+}
diff --git a/ms/blueprintsprocessor/modules/inbounds/resource-api/src/test/java/org/onap/ccsdk/apps/blueprintsprocessor/resource/api/ResourceResolutionControllerTest.java b/ms/blueprintsprocessor/modules/inbounds/resource-api/src/test/java/org/onap/ccsdk/apps/blueprintsprocessor/resource/api/ResourceResolutionControllerTest.java
new file mode 100644
index 000000000..53718654c
--- /dev/null
+++ b/ms/blueprintsprocessor/modules/inbounds/resource-api/src/test/java/org/onap/ccsdk/apps/blueprintsprocessor/resource/api/ResourceResolutionControllerTest.java
@@ -0,0 +1,22 @@
+/*
+ * 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.
+ */
+
+package org.onap.ccsdk.apps.blueprintsprocessor.resource.api;
+
+// TODO
+public class ResourceResolutionControllerTest {
+
+}
diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/pom.xml b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/pom.xml
new file mode 100755
index 000000000..0c6b8e77d
--- /dev/null
+++ b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/pom.xml
@@ -0,0 +1,64 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Copyright © 2017-2018 AT&T Intellectual Property.
+ ~
+ ~ Modifications Copyright © 2019 Bell Canada.
+ ~ 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.
+ -->
+<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.2-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>selfservice-api</artifactId>
+ <packaging>jar</packaging>
+ <name>Blueprints Processor Selfservice API</name>
+ <description>Blueprints Processor Selfservice API</description>
+
+ <dependencies>
+
+ <dependency>
+ <groupId>org.springframework.security</groupId>
+ <artifactId>spring-security-core</artifactId>
+ </dependency>
+
+ <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>
+ <artifactId>blueprint-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.onap.ccsdk.apps.controllerblueprints</groupId>
+ <artifactId>blueprint-validation</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>
+
+</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
new file mode 100644
index 000000000..d689187e8
--- /dev/null
+++ b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/BluePrintManagementGRPCHandler.kt
@@ -0,0 +1,115 @@
+/*
+ * 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.
+ */
+
+package org.onap.ccsdk.apps.blueprintsprocessor.selfservice.api
+
+import io.grpc.StatusException
+import io.grpc.stub.StreamObserver
+import org.onap.ccsdk.apps.blueprintsprocessor.core.BluePrintCoreConfiguration
+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.security.access.prepost.PreAuthorize
+import org.springframework.stereotype.Service
+import java.io.File
+
+@Service
+open class BluePrintManagementGRPCHandler(private val bluePrintCoreConfiguration: BluePrintCoreConfiguration,
+ private val bluePrintCatalogService: BluePrintCatalogService)
+ : BluePrintManagementServiceGrpc.BluePrintManagementServiceImplBase() {
+
+ private val log = LoggerFactory.getLogger(BluePrintManagementGRPCHandler::class.java)
+
+ @PreAuthorize("hasRole('USER')")
+ 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 blueprintArchivedFile = File(blueprintArchivedFilePath)
+
+ saveToDisk(request, blueprintArchivedFile)
+ val blueprintId = bluePrintCatalogService.saveToDatabase(blueprintArchivedFile)
+
+ File("${bluePrintCoreConfiguration.archivePath}/$blueprintName").deleteRecursively()
+
+ 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)
+ }
+ }
+
+ @PreAuthorize("hasRole('USER')")
+ override fun removeBlueprint(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 delete $blueprint")
+
+ try {
+ bluePrintCatalogService.deleteFromDatabase(blueprintName, blueprintVersion)
+ responseObserver.onNext(successStatus("Successfully deleted $blueprint", request.commonHeader))
+ responseObserver.onCompleted()
+ } catch (e: Exception) {
+ failStatus("request(${request.commonHeader.requestId}): Failed to delete $blueprint", e)
+ }
+ }
+
+ 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()
+ }
+}
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
new file mode 100644
index 000000000..ebeda69b5
--- /dev/null
+++ b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/BluePrintProcessingGRPCHandler.kt
@@ -0,0 +1,64 @@
+/*
+ * Copyright © 2017-2018 AT&T Intellectual Property.
+ * Modifications Copyright © 2019 IBM.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.ccsdk.apps.blueprintsprocessor.selfservice.api
+
+import io.grpc.stub.StreamObserver
+import kotlinx.coroutines.runBlocking
+import org.onap.ccsdk.apps.blueprintsprocessor.core.BluePrintCoreConfiguration
+import org.onap.ccsdk.apps.blueprintsprocessor.selfservice.api.utils.toJava
+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
+import org.slf4j.LoggerFactory
+import org.springframework.security.access.prepost.PreAuthorize
+import org.springframework.stereotype.Service
+
+@Service
+open class BluePrintProcessingGRPCHandler(private val bluePrintCoreConfiguration: BluePrintCoreConfiguration,
+ private val executionServiceHandler: ExecutionServiceHandler)
+ : BluePrintProcessingServiceGrpc.BluePrintProcessingServiceImplBase() {
+ private val log = LoggerFactory.getLogger(BluePrintProcessingGRPCHandler::class.java)
+
+ @PreAuthorize("hasRole('USER')")
+ override fun process(
+ responseObserver: StreamObserver<ExecutionServiceOutput>): StreamObserver<ExecutionServiceInput> {
+
+ return object : StreamObserver<ExecutionServiceInput> {
+ override fun onNext(executionServiceInput: ExecutionServiceInput) {
+ try {
+ runBlocking {
+ executionServiceHandler.process(executionServiceInput.toJava(), responseObserver)
+ }
+ } 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() {
+ log.info("Completed")
+ }
+ }
+ }
+} \ 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
new file mode 100644
index 000000000..6e7294791
--- /dev/null
+++ b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/ExecutionServiceController.kt
@@ -0,0 +1,67 @@
+/*
+ * Copyright © 2017-2018 AT&T Intellectual Property.
+ * Modifications Copyright © 2019 IBM.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.ccsdk.apps.blueprintsprocessor.selfservice.api
+
+import io.swagger.annotations.ApiOperation
+import kotlinx.coroutines.runBlocking
+import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ACTION_MODE_ASYNC
+import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceInput
+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.http.codec.multipart.FilePart
+import org.springframework.security.access.prepost.PreAuthorize
+import org.springframework.web.bind.annotation.*
+import reactor.core.publisher.Mono
+
+@RestController
+@RequestMapping("/api/v1/execution-service")
+open class ExecutionServiceController {
+
+ @Autowired
+ lateinit var executionServiceHandler: ExecutionServiceHandler
+
+ @RequestMapping(path = ["/ping"], method = [RequestMethod.GET], produces = [MediaType.APPLICATION_JSON_VALUE])
+ @ResponseBody
+ fun ping(): String = runBlocking {
+ "Success"
+ }
+
+ @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
+ @PreAuthorize("hasRole('USER')")
+ 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
+ @PreAuthorize("hasRole('USER')")
+ fun process(@RequestBody executionServiceInput: ExecutionServiceInput): ExecutionServiceOutput = runBlocking {
+ if (executionServiceInput.actionIdentifiers.mode == ACTION_MODE_ASYNC) {
+ throw IllegalStateException("Can't process async request through the REST endpoint. Use gRPC for async processing.")
+ }
+ executionServiceHandler.doProcess(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
new file mode 100644
index 000000000..05a569cb8
--- /dev/null
+++ b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/ExecutionServiceHandler.kt
@@ -0,0 +1,142 @@
+/*
+ * Copyright © 2017-2018 AT&T Intellectual Property.
+ * Modifications Copyright © 2019 IBM.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.ccsdk.apps.blueprintsprocessor.selfservice.api
+
+import com.fasterxml.jackson.databind.node.JsonNodeFactory
+import io.grpc.stub.StreamObserver
+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.blueprintsprocessor.core.api.data.Status
+import org.onap.ccsdk.apps.blueprintsprocessor.selfservice.api.utils.saveCBAFile
+import org.onap.ccsdk.apps.blueprintsprocessor.selfservice.api.utils.toProto
+import org.onap.ccsdk.apps.controllerblueprints.common.api.EventType
+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.interfaces.BluePrintWorkflowExecutionService
+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
+import java.util.stream.Collectors
+
+@Service
+class ExecutionServiceHandler(private val bluePrintCoreConfiguration: BluePrintCoreConfiguration,
+ private val bluePrintCatalogService: BluePrintCatalogService,
+ private val bluePrintWorkflowExecutionService
+ : BluePrintWorkflowExecutionService<ExecutionServiceInput, ExecutionServiceOutput>) {
+
+ 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))
+ }
+ }
+
+ suspend fun process(executionServiceInput: ExecutionServiceInput,
+ responseObserver: StreamObserver<org.onap.ccsdk.apps.controllerblueprints.processing.api.ExecutionServiceOutput>) {
+ when {
+ executionServiceInput.actionIdentifiers.mode == ACTION_MODE_ASYNC -> {
+ GlobalScope.launch(Dispatchers.Default) {
+ val executionServiceOutput = doProcess(executionServiceInput)
+ responseObserver.onNext(executionServiceOutput.toProto())
+ responseObserver.onCompleted()
+ }
+ responseObserver.onNext(response(executionServiceInput).toProto())
+ }
+ executionServiceInput.actionIdentifiers.mode == ACTION_MODE_SYNC -> {
+ val executionServiceOutput = doProcess(executionServiceInput)
+ responseObserver.onNext(executionServiceOutput.toProto())
+ responseObserver.onCompleted()
+ }
+ else -> responseObserver.onNext(response(executionServiceInput,
+ "Failed to process request, 'actionIdentifiers.mode' not specified. Valid value are: 'sync' or 'async'.",
+ true).toProto());
+ }
+ }
+
+ suspend fun doProcess(executionServiceInput: ExecutionServiceInput): ExecutionServiceOutput {
+ val requestId = executionServiceInput.commonHeader.requestId
+ log.info("processing request id $requestId")
+
+ val actionIdentifiers = executionServiceInput.actionIdentifiers
+
+ val blueprintName = actionIdentifiers.blueprintName
+ val blueprintVersion = actionIdentifiers.blueprintVersion
+
+ val basePath = bluePrintCatalogService.getFromDatabase(blueprintName, blueprintVersion)
+ log.info("blueprint base path $basePath")
+
+ val blueprintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime(requestId, basePath.toString())
+
+ val output = bluePrintWorkflowExecutionService.executeBluePrintWorkflow(blueprintRuntimeService,
+ executionServiceInput, hashMapOf())
+
+ val errors = blueprintRuntimeService.getBluePrintError().errors
+ if (errors.isNotEmpty()) {
+ val errorMessage = errors.stream().map { it.toString() }.collect(Collectors.joining(", "))
+ setErrorStatus(errorMessage, output.status)
+ }
+
+ return output
+ }
+
+ private fun setErrorStatus(errorMessage: String, status: Status) {
+ status.errorMessage = errorMessage
+ status.eventType = EventType.EVENT_COMPONENT_FAILURE.name
+ status.code = 500
+ status.message = BluePrintConstants.STATUS_FAILURE
+ }
+
+ private fun response(executionServiceInput: ExecutionServiceInput, errorMessage: String = "",
+ failure: Boolean = false): ExecutionServiceOutput {
+ val executionServiceOutput = ExecutionServiceOutput()
+ executionServiceOutput.commonHeader = executionServiceInput.commonHeader
+ executionServiceOutput.actionIdentifiers = executionServiceInput.actionIdentifiers
+ executionServiceOutput.payload = JsonNodeFactory.instance.objectNode()
+
+ val status = Status()
+ if (failure) {
+ setErrorStatus(errorMessage, status)
+ } else {
+ status.eventType = EventType.EVENT_COMPONENT_PROCESSING.name
+ 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 000000000..c344ca00a
--- /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,130 @@
+/*
+ * 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.ObjectNode
+import com.google.common.base.Strings
+import com.google.protobuf.Struct
+import com.google.protobuf.util.JsonFormat
+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.EventType
+import org.onap.ccsdk.apps.controllerblueprints.common.api.Flag
+import org.onap.ccsdk.apps.controllerblueprints.common.api.Status
+import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils
+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'")
+
+// 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 = EventType.valueOf(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 = JacksonUtils.jsonNode(JsonFormat.printer().print(this.payload)) as ObjectNode
+ return executionServiceInput
+}
+
+// EXECUTION OUPUT
+
+fun org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceOutput.toProto(): ExecutionServiceOutput {
+ val executionServiceOuput = ExecutionServiceOutput.newBuilder()
+ executionServiceOuput.actionIdentifiers = this.actionIdentifiers.toProto()
+ executionServiceOuput.commonHeader = this.commonHeader.toProto()
+ executionServiceOuput.status = this.status.toProto()
+ val struct = Struct.newBuilder()
+ JsonFormat.parser().merge(JacksonUtils.getJson(this.payload), struct)
+ executionServiceOuput.payload = struct.build()
+ 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 000000000..6d22fdab5
--- /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/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/validation/BluePrintRuntimeValidatorService.kt b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/validation/BluePrintRuntimeValidatorService.kt
new file mode 100644
index 000000000..100bd320b
--- /dev/null
+++ b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/validation/BluePrintRuntimeValidatorService.kt
@@ -0,0 +1,27 @@
+/*
+ * 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.selfservice.api.validation
+
+import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintTypeValidatorService
+import org.onap.ccsdk.apps.controllerblueprints.validation.BluePrintDesignTimeValidatorService
+import org.onap.ccsdk.apps.controllerblueprints.validation.extension.ResourceDefinitionValidator
+import org.springframework.stereotype.Service
+
+@Service
+open class BluePrintRuntimeValidatorService(bluePrintTypeValidatorService: BluePrintTypeValidatorService,
+ resourceDefinitionValidator: ResourceDefinitionValidator)
+ : BluePrintDesignTimeValidatorService(bluePrintTypeValidatorService, resourceDefinitionValidator)
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
new file mode 100644
index 000000000..264e2aea6
--- /dev/null
+++ b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/BluePrintManagementGRPCHandlerTest.kt
@@ -0,0 +1,116 @@
+/*
+ * 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.
+ */
+
+package org.onap.ccsdk.apps.blueprintsprocessor.selfservice.api
+
+import com.google.protobuf.ByteString
+import io.grpc.testing.GrpcServerRule
+import org.junit.Rule
+import org.junit.Test
+import org.junit.runner.RunWith
+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.FileChunk
+import org.springframework.beans.factory.annotation.Autowired
+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 kotlin.test.AfterTest
+import kotlin.test.BeforeTest
+import kotlin.test.assertEquals
+import kotlin.test.assertTrue
+
+@RunWith(SpringRunner::class)
+@EnableAutoConfiguration
+@DirtiesContext
+@ComponentScan(basePackages = ["org.onap.ccsdk.apps.blueprintsprocessor", "org.onap.ccsdk.apps.controllerblueprints"])
+@TestPropertySource(locations = ["classpath:application-test.properties"])
+class BluePrintManagementGRPCHandlerTest {
+
+ @get:Rule
+ val grpcServerRule = GrpcServerRule().directExecutor()
+
+ @Autowired
+ lateinit var bluePrintManagementGRPCHandler: BluePrintManagementGRPCHandler
+
+ @BeforeTest
+ fun init() {
+ // Create a server, add service, start, and register for automatic graceful shutdown.
+ grpcServerRule.serviceRegistry.addService(bluePrintManagementGRPCHandler)
+ }
+
+ @AfterTest
+ fun cleanDir() {
+ //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 `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)
+
+ 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()
+ .setTimestamp("2012-04-23T18:25:43.511Z")
+ .setOriginatorId("System")
+ .setRequestId(id)
+ .setSubRequestId("1234-56").build()
+
+ val fileChunk = FileChunk.newBuilder().setChunk(ByteString.copyFrom(file.inputStream().readBytes()))
+ .build()
+
+ return BluePrintManagementInput.newBuilder()
+ .setCommonHeader(commonHeader)
+ .setBlueprintName("sample")
+ .setBlueprintVersion("1.0.0")
+ .setFileChunk(fileChunk)
+ .build()
+ }
+}
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
new file mode 100644
index 000000000..01984b21d
--- /dev/null
+++ b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/BluePrintProcessingGRPCHandlerTest.kt
@@ -0,0 +1,124 @@
+/*
+ * 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.
+ */
+
+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.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.ExecutionServiceInput
+import org.onap.ccsdk.apps.controllerblueprints.processing.api.ExecutionServiceOutput
+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.annotation.DirtiesContext
+import org.springframework.test.context.TestPropertySource
+import org.springframework.test.context.junit4.SpringRunner
+import kotlin.test.BeforeTest
+
+@Ignore
+@RunWith(SpringRunner::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)
+
+ @get:Rule
+ val grpcServerRule = GrpcServerRule().directExecutor()
+
+ @Autowired
+ lateinit var bluePrintProcessingGRPCHandler: BluePrintProcessingGRPCHandler
+
+ lateinit var requestObs: StreamObserver<ExecutionServiceInput>
+
+ @BeforeTest
+ fun init() {
+ 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 commonHeader = CommonHeader.newBuilder()
+ .setTimestamp("2012-04-23T18:25:43.511Z")
+ .setOriginatorId("System")
+ .setRequestId("1234")
+ .setSubRequestId("1234-56").build()
+
+ val jsonContent = JacksonUtils.getClassPathFileContent("execution-input/sample-payload.json")
+ val payloadBuilder = ExecutionServiceInput.newBuilder().payloadBuilder
+ JsonFormat.parser().merge(jsonContent, payloadBuilder)
+
+ val input = ExecutionServiceInput.newBuilder()
+ .setCommonHeader(commonHeader)
+ .setPayload(payloadBuilder.build())
+ .build()
+
+ 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
new file mode 100644
index 000000000..b730472e8
--- /dev/null
+++ b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/ExecutionServiceHandlerTest.kt
@@ -0,0 +1,89 @@
+/*
+ * 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.
+ */
+
+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.controllerblueprints.core.interfaces.BluePrintCatalogService
+import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils
+import org.springframework.beans.factory.annotation.Autowired
+import org.springframework.boot.autoconfigure.security.SecurityProperties
+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)
+@WebFluxTest
+@ContextConfiguration(classes = [ExecutionServiceHandler::class, BluePrintCoreConfiguration::class, BluePrintCatalogService::class, SecurityProperties::class])
+@ComponentScan(basePackages = ["org.onap.ccsdk.apps.blueprintsprocessor", "org.onap.ccsdk.apps.controllerblueprints"])
+@TestPropertySource(locations = ["classpath:application-test.properties"])
+class ExecutionServiceHandlerTest {
+
+ @Autowired
+ lateinit var blueprintCatalog: BluePrintCatalogService
+ @Autowired
+ lateinit var webTestClient: WebTestClient
+
+
+ @Test
+ 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 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 000000000..19c624bc0
--- /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,62 @@
+/*
+ * 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 io.mockk.mockk
+import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceInput
+import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.processor.ResourceAssignmentProcessor
+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..")
+ }
+}
+
+open class MockResourceSource {
+ @Bean(name = [
+ "rr-processor-source-input",
+ "rr-processor-source-default",
+ "rr-processor-source-primary-db",
+ "rr-processor-source-rest"])
+ open fun sourceInstance(): ResourceAssignmentProcessor {
+ return mockk<ResourceAssignmentProcessor>()
+ }
+
+} \ 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 000000000..770e4a9b3
--- /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,132 @@
+package org.onap.ccsdk.apps.blueprintsprocessor.selfservice.api.utils
+
+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.EventType
+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 = EventType.EVENT_COMPONENT_PROCESSING.name
+ 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.name)
+ 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)
+ }
+} \ 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/validation/BluePrintRuntimeValidatorServiceTest.kt b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/validation/BluePrintRuntimeValidatorServiceTest.kt
new file mode 100644
index 000000000..1cafead7f
--- /dev/null
+++ b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/validation/BluePrintRuntimeValidatorServiceTest.kt
@@ -0,0 +1,44 @@
+/*
+ * Copyright © 2019 IBM.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.ccsdk.apps.blueprintsprocessor.selfservice.api.validation
+
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.onap.ccsdk.apps.blueprintsprocessor.selfservice.api.mock.MockResourceSource
+import org.onap.ccsdk.apps.controllerblueprints.validation.BluePrintValidationConfiguration
+import org.springframework.beans.factory.annotation.Autowired
+import org.springframework.test.context.ContextConfiguration
+import org.springframework.test.context.junit4.SpringRunner
+import kotlin.test.assertNotNull
+
+@RunWith(SpringRunner::class)
+@ContextConfiguration(classes = [BluePrintRuntimeValidatorService::class,
+ BluePrintValidationConfiguration::class, MockResourceSource::class])
+class BluePrintRuntimeValidatorServiceTest {
+
+ @Autowired
+ lateinit var bluePrintRuntimeValidatorService: BluePrintRuntimeValidatorService
+
+ @Test
+ fun testBlueprintRuntimeValidation() {
+ val blueprintBasePath = "./../../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration"
+ assertNotNull(bluePrintRuntimeValidatorService, " failed to initilize bluePrintRuntimeValidatorService")
+
+ bluePrintRuntimeValidatorService.validateBluePrints(blueprintBasePath)
+
+ }
+} \ 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
new file mode 100644
index 000000000..6d8b62ff9
--- /dev/null
+++ b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/resources/application-test.properties
@@ -0,0 +1,32 @@
+#
+# 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.
+#
+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
+
+# Python executor
+blueprints.processor.functions.python.executor.executionPath=./../../../../components/scripts/python/ccsdk_blueprints
+blueprints.processor.functions.python.executor.modulePaths=./../../../../components/scripts/python/ccsdk_blueprints
diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/resources/execution-input/default-input.json b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/resources/execution-input/default-input.json
new file mode 100644
index 000000000..47ace853c
--- /dev/null
+++ b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/resources/execution-input/default-input.json
@@ -0,0 +1,23 @@
+{
+ "commonHeader": {
+ "originatorId": "System",
+ "requestId": "1234",
+ "subRequestId": "1234-12234"
+ },
+ "actionIdentifiers": {
+ "blueprintName": "baseconfiguration",
+ "blueprintVersion": "1.0.0",
+ "actionName": "activate",
+ "mode": "sync"
+ },
+ "payload": {
+ "activate-request": {
+ "activate-properties": {
+ "request-id": "1234",
+ "action-name": "activate",
+ "scope-type": "vnf-type",
+ "hostname": "localhost"
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/resources/execution-input/sample-payload.json b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/resources/execution-input/sample-payload.json
new file mode 100644
index 000000000..07046aa37
--- /dev/null
+++ b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/resources/execution-input/sample-payload.json
@@ -0,0 +1,10 @@
+{
+ "activate-request": {
+ "activate-properties": {
+ "request-id": "1234",
+ "action-name": "activate",
+ "scope-type": "vnf-type",
+ "hostname": "localhost"
+ }
+ }
+} \ No newline at end of file
diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/resources/logback.xml b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/resources/logback.xml
new file mode 100644
index 000000000..a816a06c5
--- /dev/null
+++ b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/resources/logback.xml
@@ -0,0 +1,35 @@
+<!--
+ ~ 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="warn"/>
+ <logger name="org.hibernate" level="info"/>
+ <logger name="org.onap.ccsdk.apps.blueprintsprocessor" level="info"/>
+
+ <root level="warn">
+ <appender-ref ref="STDOUT"/>
+ </root>
+
+</configuration>
diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/resources/test-cba.zip b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/resources/test-cba.zip
new file mode 100644
index 000000000..907482400
--- /dev/null
+++ b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/resources/test-cba.zip
Binary files differ