2 * Copyright © 2017-2018 AT&T Intellectual Property.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.onap.ccsdk.apps.blueprintsprocessor.selfservice.api
19 import io.grpc.stub.StreamObserver
20 import org.apache.commons.io.FileUtils
21 import org.onap.ccsdk.apps.blueprintsprocessor.core.BluePrintCoreConfiguration
22 import org.onap.ccsdk.apps.controllerblueprints.management.api.*
23 import org.slf4j.LoggerFactory
24 import org.springframework.stereotype.Service
28 class BluePrintManagementGRPCHandler(private val bluePrintCoreConfiguration: BluePrintCoreConfiguration)
29 : BluePrintManagementServiceGrpc.BluePrintManagementServiceImplBase() {
31 private val log = LoggerFactory.getLogger(BluePrintManagementGRPCHandler::class.java)
33 override fun uploadBlueprint(request: BluePrintUploadInput, responseObserver: StreamObserver<BluePrintUploadOutput>) {
34 val response = BluePrintUploadOutput.newBuilder().setCommonHeader(request.commonHeader).build()
36 val blueprintName = request.blueprintName
37 val blueprintVersion = request.blueprintVersion
38 val filePath = "${bluePrintCoreConfiguration.archivePath}/$blueprintName/$blueprintVersion"
39 val blueprintDir = File(filePath)
41 log.info("Re-creating blueprint directory(${blueprintDir.absolutePath})")
42 FileUtils.deleteDirectory(blueprintDir)
43 FileUtils.forceMkdir(blueprintDir)
45 val file = File("${blueprintDir.absolutePath}/$blueprintName.zip")
46 log.info("Writing CBA File under :${file.absolutePath}")
48 val fileChunk = request.fileChunk
50 file.writeBytes(fileChunk.chunk.toByteArray()).apply {
51 log.info("CBA file(${file.absolutePath} written successfully")
53 } catch (e: Exception) {
54 log.error("failed to upload file ", e)
56 responseObserver.onNext(response)
57 responseObserver.onCompleted()
60 override fun removeBlueprint(request: BluePrintRemoveInput?, responseObserver: StreamObserver<BluePrintRemoveOutput>?) {