import com.google.protobuf.util.JsonFormat
import io.grpc.stub.StreamObserver
import kotlinx.coroutines.runBlocking
-import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.handler.BlueprintModelHandler
+import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.handler.BluePrintModelHandler
import org.onap.ccsdk.cds.controllerblueprints.common.api.CommonHeader
import org.onap.ccsdk.cds.controllerblueprints.common.api.EventType
import org.onap.ccsdk.cds.controllerblueprints.common.api.Status
-import org.onap.ccsdk.cds.controllerblueprints.core.BlueprintConstants
-import org.onap.ccsdk.cds.controllerblueprints.core.BlueprintProcessorException
+import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants
+import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException
import org.onap.ccsdk.cds.controllerblueprints.core.asJsonString
import org.onap.ccsdk.cds.controllerblueprints.core.emptyTONull
import org.onap.ccsdk.cds.controllerblueprints.core.utils.currentTimestamp
-import org.onap.ccsdk.cds.controllerblueprints.management.api.BlueprintBootstrapInput
-import org.onap.ccsdk.cds.controllerblueprints.management.api.BlueprintDownloadInput
-import org.onap.ccsdk.cds.controllerblueprints.management.api.BlueprintManagementOutput
-import org.onap.ccsdk.cds.controllerblueprints.management.api.BlueprintManagementServiceGrpc
-import org.onap.ccsdk.cds.controllerblueprints.management.api.BlueprintRemoveInput
-import org.onap.ccsdk.cds.controllerblueprints.management.api.BlueprintUploadInput
+import org.onap.ccsdk.cds.controllerblueprints.management.api.BluePrintBootstrapInput
+import org.onap.ccsdk.cds.controllerblueprints.management.api.BluePrintDownloadInput
+import org.onap.ccsdk.cds.controllerblueprints.management.api.BluePrintManagementOutput
+import org.onap.ccsdk.cds.controllerblueprints.management.api.BluePrintManagementServiceGrpc
+import org.onap.ccsdk.cds.controllerblueprints.management.api.BluePrintRemoveInput
+import org.onap.ccsdk.cds.controllerblueprints.management.api.BluePrintUploadInput
import org.onap.ccsdk.cds.controllerblueprints.management.api.DownloadAction
import org.onap.ccsdk.cds.controllerblueprints.management.api.FileChunk
import org.onap.ccsdk.cds.controllerblueprints.management.api.RemoveAction
// TODO("Convert to coroutines handler")
@Service
-open class BlueprintManagementGRPCHandler(
- private val bluePrintModelHandler: BlueprintModelHandler,
+open class BluePrintManagementGRPCHandler(
+ private val bluePrintModelHandler: BluePrintModelHandler,
private val errorCatalogService: ErrorCatalogService
) :
- BlueprintManagementServiceGrpc.BlueprintManagementServiceImplBase() {
+ BluePrintManagementServiceGrpc.BluePrintManagementServiceImplBase() {
- private val log = LoggerFactory.getLogger(BlueprintManagementGRPCHandler::class.java)
+ private val log = LoggerFactory.getLogger(BluePrintManagementGRPCHandler::class.java)
@PreAuthorize("hasRole('USER')")
override fun uploadBlueprint(
- request: BlueprintUploadInput,
- responseObserver: StreamObserver<BlueprintManagementOutput>
+ request: BluePrintUploadInput,
+ responseObserver: StreamObserver<BluePrintManagementOutput>
) {
runBlocking {
failStatus(
request.commonHeader,
"Upload action($uploadAction) not implemented",
- BlueprintProcessorException("Not Implemented")
+ BluePrintProcessorException("Not Implemented")
)
)
}
failStatus(
request.commonHeader,
"Upload action($uploadAction) not implemented",
- BlueprintProcessorException("Not implemented")
+ BluePrintProcessorException("Not implemented")
)
)
}
@PreAuthorize("hasRole('USER')")
override fun downloadBlueprint(
- request: BlueprintDownloadInput,
- responseObserver: StreamObserver<BlueprintManagementOutput>
+ request: BluePrintDownloadInput,
+ responseObserver: StreamObserver<BluePrintManagementOutput>
) {
runBlocking {
val blueprintName = request.actionIdentifiers.blueprintName
failStatus(
request.commonHeader,
"Search action($searchAction) not implemented",
- BlueprintProcessorException("Not implemented")
+ BluePrintProcessorException("Not implemented")
)
)
}
@PreAuthorize("hasRole('USER')")
override fun removeBlueprint(
- request: BlueprintRemoveInput,
+ request: BluePrintRemoveInput,
responseObserver:
- StreamObserver<BlueprintManagementOutput>
+ StreamObserver<BluePrintManagementOutput>
) {
runBlocking {
failStatus(
request.commonHeader,
"Remove action($removeAction) not implemented",
- BlueprintProcessorException("Not implemented")
+ BluePrintProcessorException("Not implemented")
)
)
}
}
override fun bootstrapBlueprint(
- request: BlueprintBootstrapInput,
- responseObserver: StreamObserver<BlueprintManagementOutput>
+ request: BluePrintBootstrapInput,
+ responseObserver: StreamObserver<BluePrintManagementOutput>
) {
runBlocking {
try {
}
}
- private fun outputWithFileBytes(header: CommonHeader, byteArray: ByteArray): BlueprintManagementOutput =
- BlueprintManagementOutput.newBuilder()
+ private fun outputWithFileBytes(header: CommonHeader, byteArray: ByteArray): BluePrintManagementOutput =
+ BluePrintManagementOutput.newBuilder()
.setCommonHeader(header)
.setFileChunk(FileChunk.newBuilder().setChunk(ByteString.copyFrom(byteArray)))
.setStatus(
Status.newBuilder()
.setTimestamp(currentTimestamp())
.setEventType(EventType.EVENT_COMPONENT_EXECUTED)
- .setMessage(BlueprintConstants.STATUS_SUCCESS)
+ .setMessage(BluePrintConstants.STATUS_SUCCESS)
.setCode(200)
.build()
)
.build()
- private fun successStatus(header: CommonHeader, propertyContent: String? = null): BlueprintManagementOutput {
+ private fun successStatus(header: CommonHeader, propertyContent: String? = null): BluePrintManagementOutput {
// Populate Response Payload
- val propertiesBuilder = BlueprintManagementOutput.newBuilder().propertiesBuilder
+ val propertiesBuilder = BluePrintManagementOutput.newBuilder().propertiesBuilder
propertyContent?.let {
JsonFormat.parser().merge(propertyContent, propertiesBuilder)
}
- return BlueprintManagementOutput.newBuilder()
+ return BluePrintManagementOutput.newBuilder()
.setCommonHeader(header)
.setProperties(propertiesBuilder.build())
.setStatus(
Status.newBuilder()
.setTimestamp(currentTimestamp())
- .setMessage(BlueprintConstants.STATUS_SUCCESS)
+ .setMessage(BluePrintConstants.STATUS_SUCCESS)
.setEventType(EventType.EVENT_COMPONENT_EXECUTED)
.setCode(200)
.build()
.build()
}
- private fun failStatus(header: CommonHeader, message: String, e: Exception): BlueprintManagementOutput {
+ private fun failStatus(header: CommonHeader, message: String, e: Exception): BluePrintManagementOutput {
log.error(message, e)
- return if (e is BlueprintProcessorException) onErrorCatalog(header, message, e) else onError(header, message, e)
+ return if (e is BluePrintProcessorException) onErrorCatalog(header, message, e) else onError(header, message, e)
}
- private fun onError(header: CommonHeader, message: String, error: Exception): BlueprintManagementOutput {
+ private fun onError(header: CommonHeader, message: String, error: Exception): BluePrintManagementOutput {
val code = GrpcErrorCodes.code(ErrorCatalogCodes.GENERIC_FAILURE)
- return BlueprintManagementOutput.newBuilder()
+ return BluePrintManagementOutput.newBuilder()
.setCommonHeader(header)
.setStatus(
Status.newBuilder()
.setTimestamp(currentTimestamp())
- .setMessage(BlueprintConstants.STATUS_FAILURE)
+ .setMessage(BluePrintConstants.STATUS_FAILURE)
.setEventType(EventType.EVENT_COMPONENT_FAILURE)
.setErrorMessage("Error : $message \n Details: ${error.errorMessageOrDefault()}")
.setCode(code)
.build()
}
- private fun onErrorCatalog(header: CommonHeader, message: String, error: BlueprintProcessorException):
- BlueprintManagementOutput {
+ private fun onErrorCatalog(header: CommonHeader, message: String, error: BluePrintProcessorException):
+ BluePrintManagementOutput {
val err = if (error.protocol == "") {
error.grpc(ErrorCatalogCodes.GENERIC_FAILURE)
} else {
error.convertToGrpc()
}
val errorPayload = errorCatalogService.errorPayload(err.addErrorPayloadMessage(message))
- return BlueprintManagementOutput.newBuilder()
+ return BluePrintManagementOutput.newBuilder()
.setCommonHeader(header)
.setStatus(
Status.newBuilder()
.setTimestamp(currentTimestamp())
- .setMessage(BlueprintConstants.STATUS_FAILURE)
+ .setMessage(BluePrintConstants.STATUS_FAILURE)
.setEventType(EventType.EVENT_COMPONENT_FAILURE)
.setErrorMessage("Error : ${errorPayload.message}")
.setCode(errorPayload.code)