From 3b4a7eb973d0167c01a882355f24c70adf5d177a Mon Sep 17 00:00:00 2001 From: "Muthuramalingam, Brinda Santh(bs2796)" Date: Fri, 7 Dec 2018 16:37:03 -0500 Subject: [PATCH] Add GRPC Blueprint Processing API Change-Id: Id2c31e8db2b5ede6a992d923f695ce1e0e14b450 Issue-ID: CCSDK-799 Signed-off-by: Muthuramalingam, Brinda Santh(bs2796) --- .../blueprintsprocessor/BlueprintGRPCServer.java | 64 ++++++++++++++ .../blueprintsprocessor/BlueprintHttpServer.java | 57 +++++++++++++ .../src/main/resources/application.properties | 4 + .../modules/inbounds/selfservice-api/pom.xml | 64 +++++++++++--- .../selfservice/api/BluePrintCatalogServiceImpl.kt | 3 +- .../api/BluePrintManagementGRPCHandler.kt | 63 ++++++++++++++ .../api/BluePrintProcessingGRPCHandler.kt | 44 ++++++++++ .../api/BluePrintManagementGRPCHandlerTest.kt | 92 +++++++++++++++++++++ .../api/BluePrintProcessingGRPCHandlerTest.kt | 81 ++++++++++++++++++ .../src/test/resources/application-test.properties | 17 ++++ .../resources/execution-input/sample-payload.json | 10 +++ .../src/test/resources/test-cba.zip | Bin 0 -> 9189 bytes ms/blueprintsprocessor/parent/pom.xml | 10 +++ 13 files changed, 497 insertions(+), 12 deletions(-) create mode 100644 ms/blueprintsprocessor/application/src/main/java/org/onap/ccsdk/apps/blueprintsprocessor/BlueprintGRPCServer.java create mode 100644 ms/blueprintsprocessor/application/src/main/java/org/onap/ccsdk/apps/blueprintsprocessor/BlueprintHttpServer.java create mode 100644 ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/BluePrintManagementGRPCHandler.kt create mode 100644 ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/BluePrintProcessingGRPCHandler.kt create mode 100644 ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/BluePrintManagementGRPCHandlerTest.kt create mode 100644 ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/BluePrintProcessingGRPCHandlerTest.kt create mode 100644 ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/resources/application-test.properties create mode 100644 ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/resources/execution-input/sample-payload.json create mode 100644 ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/resources/test-cba.zip diff --git a/ms/blueprintsprocessor/application/src/main/java/org/onap/ccsdk/apps/blueprintsprocessor/BlueprintGRPCServer.java b/ms/blueprintsprocessor/application/src/main/java/org/onap/ccsdk/apps/blueprintsprocessor/BlueprintGRPCServer.java new file mode 100644 index 000000000..86fdccd4b --- /dev/null +++ b/ms/blueprintsprocessor/application/src/main/java/org/onap/ccsdk/apps/blueprintsprocessor/BlueprintGRPCServer.java @@ -0,0 +1,64 @@ +/* + * 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; + +import io.grpc.Server; +import io.grpc.ServerBuilder; +import org.onap.ccsdk.apps.blueprintsprocessor.selfservice.api.BluePrintManagementGRPCHandler; +import org.onap.ccsdk.apps.blueprintsprocessor.selfservice.api.BluePrintProcessingGRPCHandler; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.context.ApplicationListener; +import org.springframework.context.event.ContextRefreshedEvent; +import org.springframework.stereotype.Component; + +@ConditionalOnProperty(name = "blueprintsprocessor.grpcEnable", havingValue = "true") +@Component +public class BlueprintGRPCServer implements ApplicationListener { + + private static Logger log = LoggerFactory.getLogger(BlueprintGRPCServer.class); + + @Autowired + private BluePrintProcessingGRPCHandler bluePrintProcessingGRPCHandler; + + @Autowired + private BluePrintManagementGRPCHandler bluePrintManagementGRPCHandler; + + @Value("${blueprintsprocessor.grpcPort}") + private Integer grpcPort; + + @Override + public void onApplicationEvent(ContextRefreshedEvent event) { + try { + log.info("Starting Blueprint Processor GRPC Starting.."); + Server server = ServerBuilder + .forPort(grpcPort) + .addService(bluePrintProcessingGRPCHandler) + .addService(bluePrintManagementGRPCHandler) + .build(); + + server.start(); + log.info("Blueprint Processor GRPC server started and ready to serve on port({})...", server.getPort()); + server.awaitTermination(); + } catch (Exception e) { + e.printStackTrace(); + } + } +} diff --git a/ms/blueprintsprocessor/application/src/main/java/org/onap/ccsdk/apps/blueprintsprocessor/BlueprintHttpServer.java b/ms/blueprintsprocessor/application/src/main/java/org/onap/ccsdk/apps/blueprintsprocessor/BlueprintHttpServer.java new file mode 100644 index 000000000..b00c4627c --- /dev/null +++ b/ms/blueprintsprocessor/application/src/main/java/org/onap/ccsdk/apps/blueprintsprocessor/BlueprintHttpServer.java @@ -0,0 +1,57 @@ +/* + * 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; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.boot.web.embedded.netty.NettyReactiveWebServerFactory; +import org.springframework.boot.web.reactive.server.ReactiveWebServerFactory; +import org.springframework.boot.web.server.WebServer; +import org.springframework.http.server.reactive.HttpHandler; +import org.springframework.stereotype.Component; + +import javax.annotation.PostConstruct; +import javax.annotation.PreDestroy; + +@ConditionalOnProperty(name = "blueprintsprocessor.grpcEnable", havingValue = "true") +@Component +public class BlueprintHttpServer { + private static Logger log = LoggerFactory.getLogger(BlueprintHttpServer.class); + + @Value("${blueprintsprocessor.httpPort}") + private Integer httpPort; + + @Autowired + HttpHandler httpHandler; + + WebServer http; + + @PostConstruct + public void start() { + ReactiveWebServerFactory factory = new NettyReactiveWebServerFactory(httpPort); + this.http = factory.getWebServer(this.httpHandler); + this.http.start(); + } + + @PreDestroy + public void stop() { + this.http.stop(); + } +} diff --git a/ms/blueprintsprocessor/application/src/main/resources/application.properties b/ms/blueprintsprocessor/application/src/main/resources/application.properties index 81b997685..fa1a1e6e4 100644 --- a/ms/blueprintsprocessor/application/src/main/resources/application.properties +++ b/ms/blueprintsprocessor/application/src/main/resources/application.properties @@ -13,6 +13,10 @@ # See the License for the specific language governing permissions and # limitations under the License. # +#logging.level.web=DEBUG +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 diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/pom.xml b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/pom.xml index a4c7aaf08..f319ca412 100644 --- a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/pom.xml +++ b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/pom.xml @@ -15,17 +15,59 @@ ~ limitations under the License. --> - 4.0.0 - - org.onap.ccsdk.apps.blueprintsprocessor - inbounds - 0.4.0-SNAPSHOT - + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 + + org.onap.ccsdk.apps.blueprintsprocessor + inbounds + 0.4.0-SNAPSHOT + - selfservice-api - jar - Blueprints Processor Selfservice API - Blueprints Processor Selfservice API + selfservice-api + jar + Blueprints Processor Selfservice API + Blueprints Processor Selfservice API + + + + io.grpc + grpc-testing + + + + + + + kr.motd.maven + os-maven-plugin + 1.6.1 + + + + + org.xolstice.maven.plugins + protobuf-maven-plugin + 0.6.1 + + + com.google.protobuf:protoc:3.5.1-1:exe:${os.detected.classifier} + + grpc-java + + io.grpc:protoc-gen-grpc-java:1.16.1:exe:${os.detected.classifier} + + ./../../../../../components/model-catalog/api-definition + + + + + compile + compile-custom + + + + + + diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/BluePrintCatalogServiceImpl.kt b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/BluePrintCatalogServiceImpl.kt index 8e0678735..01c9a39e9 100644 --- a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/BluePrintCatalogServiceImpl.kt +++ b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/BluePrintCatalogServiceImpl.kt @@ -26,7 +26,8 @@ class BluePrintCatalogServiceImpl(private val bluePrintCoreConfiguration: BluePr override fun prepareBluePrint(name: String, version: String): String { //TODO("Get the Blueprint from the DB") - return bluePrintCoreConfiguration.deployPath.plus(File.separator).plus(name).plus(File.separator).plus(version) + return bluePrintCoreConfiguration.deployPath.plus(File.separator) + .plus(name).plus(File.separator).plus(version) } } \ 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/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..17191f31d --- /dev/null +++ b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/BluePrintManagementGRPCHandler.kt @@ -0,0 +1,63 @@ +/* + * 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 + +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.slf4j.LoggerFactory +import org.springframework.stereotype.Service +import java.io.File + +@Service +class BluePrintManagementGRPCHandler(private val bluePrintCoreConfiguration: BluePrintCoreConfiguration) + : BluePrintManagementServiceGrpc.BluePrintManagementServiceImplBase() { + + private val log = LoggerFactory.getLogger(BluePrintManagementGRPCHandler::class.java) + + override fun uploadBlueprint(request: BluePrintUploadInput, responseObserver: StreamObserver) { + val response = BluePrintUploadOutput.newBuilder().setCommonHeader(request.commonHeader).build() + try { + val blueprintName = request.blueprintName + val blueprintVersion = request.blueprintVersion + val filePath = "${bluePrintCoreConfiguration.archivePath}/$blueprintName/$blueprintVersion" + val blueprintDir = File(filePath) + + log.info("Re-creating blueprint directory(${blueprintDir.absolutePath})") + FileUtils.deleteDirectory(blueprintDir) + FileUtils.forceMkdir(blueprintDir) + + val file = File("${blueprintDir.absolutePath}/$blueprintName.zip") + log.info("Writing CBA File under :${file.absolutePath}") + + val fileChunk = request.fileChunk + + file.writeBytes(fileChunk.chunk.toByteArray()).apply { + log.info("CBA file(${file.absolutePath} written successfully") + } + } catch (e: Exception) { + log.error("failed to upload file ", e) + } + responseObserver.onNext(response) + responseObserver.onCompleted() + } + + override fun removeBlueprint(request: BluePrintRemoveInput?, responseObserver: StreamObserver?) { + //TODO + } +} \ 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 new file mode 100644 index 000000000..2a5983d00 --- /dev/null +++ b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/BluePrintProcessingGRPCHandler.kt @@ -0,0 +1,44 @@ +/* + * 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 + +import com.google.protobuf.util.JsonFormat +import io.grpc.stub.StreamObserver +import org.onap.ccsdk.apps.blueprintsprocessor.core.BluePrintCoreConfiguration +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.stereotype.Service + +@Service +class BluePrintProcessingGRPCHandler(private val bluePrintCoreConfiguration: BluePrintCoreConfiguration) + : BluePrintProcessingServiceGrpc.BluePrintProcessingServiceImplBase() { + private val log = LoggerFactory.getLogger(BluePrintProcessingGRPCHandler::class.java) + + override fun process(request: ExecutionServiceInput, + responseObserver: StreamObserver) { + + 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() + } +} \ 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 new file mode 100644 index 000000000..c870bf7f8 --- /dev/null +++ b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/BluePrintManagementGRPCHandlerTest.kt @@ -0,0 +1,92 @@ +/* + * 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 + +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.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.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.assertTrue + +@RunWith(SpringRunner::class) +@ContextConfiguration(classes = [BluePrintManagementGRPCHandler::class, BluePrintCoreConfiguration::class]) +@TestPropertySource(locations = ["classpath:application-test.properties"]) +class BluePrintManagementGRPCHandlerTest { + + private val log = LoggerFactory.getLogger(BluePrintProcessingGRPCHandlerTest::class.java)!! + + @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() { + FileUtils.deleteDirectory(File("./target/blueprints")) + } + + @Test + fun testFileUpload() { + val blockingStub = BluePrintManagementServiceGrpc.newBlockingStub(grpcServerRule.channel) + + val file = Paths.get("./src/test/resources/test-cba.zip").toFile() + assertTrue(file.exists(), "couldnt get file ${file.absolutePath}") + + val commonHeader = CommonHeader.newBuilder() + .setTimestamp("2012-04-23T18:25:43.511Z") + .setOriginatorId("System") + .setRequestId("1234") + .setSubRequestId("1234-56").build() + + val fileChunk = FileChunk.newBuilder().setChunk(ByteString.copyFrom(file.inputStream().readBytes())) + .build() + + val input = BluePrintUploadInput.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 new file mode 100644 index 000000000..6d5d633c9 --- /dev/null +++ b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/BluePrintProcessingGRPCHandlerTest.kt @@ -0,0 +1,81 @@ +/* + * 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 + + +import com.google.protobuf.util.JsonFormat +import io.grpc.testing.GrpcServerRule +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.core.utils.JacksonUtils +import org.onap.ccsdk.apps.controllerblueprints.processing.api.CommonHeader +import org.onap.ccsdk.apps.controllerblueprints.processing.api.BluePrintProcessingServiceGrpc +import org.onap.ccsdk.apps.controllerblueprints.processing.api.ExecutionServiceInput +import org.slf4j.LoggerFactory +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.test.context.ContextConfiguration +import org.springframework.test.context.TestPropertySource +import org.springframework.test.context.junit4.SpringRunner +import kotlin.test.BeforeTest +import kotlin.test.assertNotNull + +@RunWith(SpringRunner::class) +@ContextConfiguration(classes = [BluePrintProcessingGRPCHandler::class, BluePrintCoreConfiguration::class]) +@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 + + @BeforeTest + fun init() { + // Create a server, add service, start, and register for automatic graceful shutdown. + grpcServerRule.serviceRegistry.addService(bluePrintProcessingGRPCHandler) + } + + @Test + fun testSelfServiceGRPCHandler() { + + val blockingStub = BluePrintProcessingServiceGrpc.newBlockingStub(grpcServerRule.channel) + + 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() + + val response = blockingStub.process(input) + assertNotNull(response, "Response is null") + } + +} \ 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..edb51022f --- /dev/null +++ b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/resources/application-test.properties @@ -0,0 +1,17 @@ +# +# 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.blueprintDeployPath=./target/blueprints/deploy +blueprintsprocessor.blueprintArchivePath=./target/blueprints/archive 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/test-cba.zip b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/resources/test-cba.zip new file mode 100644 index 0000000000000000000000000000000000000000..a62d4bfbbfdb6c797e2db2c7f5d6728d1ec8d82a GIT binary patch literal 9189 zcmbVx1z1#D)b`M+qzKa8DJ3Y~F@U6W4KTzozE3h@MH2pkm~vM$AJs~AOo@jL%=Yw zBgBPU{hyYY-&&eIvf8ph1prW}0RYC|TAEqFz;0&ePjQ;tyMmz3Uo5RSs2VlR)7yA!f9X%eFh$LB^Ub|}xCgjcefTwC1nxa|Jyf zdzAF=imLkZ>Eh>`5gC#NCIe_G7288JDv>^#=gl+G8AfL9SkB<6@BvHJ`P>N_)Nv*$f4%Jsu^%OxVGw^PT*| zw40F_7AiD{$nQoT4~b(Ni&UOypkLo&oC*bR?b0UZAD?k%x3Ga{&{= zgM>{l#7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|Daz?UJ=o|ul$DoU#aZ>8}#3j ziXYJDPE!nL%O8s)V$Z&bb%1A~aO%|kkn|8vp+D{sr}EE41.3.10 1.0.1 1.16.1 + 3.6.1 1.0.0 0.3.1 26.0-jre @@ -116,6 +117,11 @@ grpc-stub ${grpc.version} + + com.google.protobuf + protobuf-java-util + ${protobuff.java.utils.version} + @@ -355,6 +361,10 @@ io.grpc grpc-stub + + com.google.protobuf + protobuf-java-util + -- 2.16.6