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)