From b62aabac76abe92f04e0991157292c276d3d9177 Mon Sep 17 00:00:00 2001 From: Oleg Mitsura Date: Fri, 15 Jan 2021 13:49:25 -0500 Subject: PV/PVC elimination Issue-ID: CCSDK-3086 1. initial commit 2. fix accidental paste / rebased cleaned up unneeded validation call in cmd-exec upload Signed-off-by: Oleg Mitsura Change-Id: Ife5460c5be59aa8d8592d82099b27c507b08c6c6 --- .../db/primary/domain/BlueprintModelSearch.kt | 2 +- .../primary/repository/BlueprintModelRepository.kt | 12 ++++++ .../core/api/data/BlueprintRemoteProcessorData.kt | 26 ++++++++++++- .../execution/RemoteScriptExecutionService.kt | 43 ++++++++++++++++++++++ 4 files changed, 81 insertions(+), 2 deletions(-) (limited to 'ms/blueprintsprocessor/modules') diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/domain/BlueprintModelSearch.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/domain/BlueprintModelSearch.kt index 734bf3689..ba9051898 100644 --- a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/domain/BlueprintModelSearch.kt +++ b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/domain/BlueprintModelSearch.kt @@ -104,6 +104,6 @@ class BlueprintModelSearch : Serializable { companion object { - const val serialversionuid = 1L + const val serialVersionUID = 1L } } diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/repository/BlueprintModelRepository.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/repository/BlueprintModelRepository.kt index a7891f6a7..a6f0da1cc 100644 --- a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/repository/BlueprintModelRepository.kt +++ b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/repository/BlueprintModelRepository.kt @@ -20,6 +20,8 @@ package org.onap.ccsdk.cds.blueprintsprocessor.db.primary.repository import org.jetbrains.annotations.NotNull import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.domain.BlueprintModel import org.springframework.data.jpa.repository.JpaRepository +import org.springframework.data.jpa.repository.Query +import org.springframework.data.repository.query.Param import org.springframework.stereotype.Repository import java.util.Optional import javax.transaction.Transactional @@ -47,6 +49,16 @@ interface BlueprintModelRepository : JpaRepository { */ fun findByArtifactNameAndArtifactVersion(artifactName: String, artifactVersion: String): BlueprintModel? + /** + * Find the Blueprint UUID (blueprint_model_id) for a given artifactName/Version + * + * @param artifactName artifactName + * @param artifactVersion artifactVersion + * @return String? + */ + @Query("SELECT m.id FROM BlueprintModel m WHERE m.artifactName = :artifactName AND m.artifactVersion = :artifactVersion") + fun findIdByArtifactNameAndArtifactVersion(@Param("artifactName") artifactName: String, @Param("artifactVersion") artifactVersion: String): String? + /** * This is a findTopByArtifactNameOrderByArtifactIdDesc method * diff --git a/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/api/data/BlueprintRemoteProcessorData.kt b/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/api/data/BlueprintRemoteProcessorData.kt index 6baf261fb..d8baa8eaf 100644 --- a/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/api/data/BlueprintRemoteProcessorData.kt +++ b/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/api/data/BlueprintRemoteProcessorData.kt @@ -18,15 +18,39 @@ package org.onap.ccsdk.cds.blueprintsprocessor.core.api.data import com.fasterxml.jackson.databind.JsonNode +import com.google.protobuf.ByteString import java.util.Date enum class StatusType { SUCCESS, FAILURE } +/* TODO: Group fields into another struct containing originatorId, requestId, subRequestId, correlationId generally go together */ +// timeOuts are in seconds + data class RemoteIdentifier( var blueprintName: String, - var blueprintVersion: String + var blueprintVersion: String, + var blueprintUUID: String +) + +data class RemoteScriptUploadBlueprintInput( + val remoteIdentifier: RemoteIdentifier? = null, + val requestId: String, + val subRequestId: String, + val originatorId: String, + val correlationId: String? = null, + val timeOut: Long = 30, + val archiveType: String = "CBA_ZIP", + val binData: ByteString +) + +data class RemoteScriptUploadBlueprintOutput( + val requestId: String, + val subRequestId: String, + val status: StatusType = StatusType.SUCCESS, + val timestamp: Date = Date(), + val payload: JsonNode ) data class RemoteScriptExecutionInput( diff --git a/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/RemoteScriptExecutionService.kt b/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/RemoteScriptExecutionService.kt index 4f3f60110..7e3f16f39 100644 --- a/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/RemoteScriptExecutionService.kt +++ b/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/RemoteScriptExecutionService.kt @@ -24,8 +24,10 @@ import com.google.protobuf.util.JsonFormat import io.grpc.ManagedChannel import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.PrepareRemoteEnvInput import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.RemoteIdentifier +import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.RemoteScriptUploadBlueprintInput import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.RemoteScriptExecutionInput import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.RemoteScriptExecutionOutput +import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.RemoteScriptUploadBlueprintOutput import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.StatusType import org.onap.ccsdk.cds.blueprintsprocessor.grpc.service.BlueprintGrpcClientService import org.onap.ccsdk.cds.blueprintsprocessor.grpc.service.BlueprintGrpcLibPropertyService @@ -35,6 +37,8 @@ import org.onap.ccsdk.cds.controllerblueprints.command.api.ExecutionOutput import org.onap.ccsdk.cds.controllerblueprints.command.api.Identifiers import org.onap.ccsdk.cds.controllerblueprints.command.api.Packages import org.onap.ccsdk.cds.controllerblueprints.command.api.PrepareEnvInput +import org.onap.ccsdk.cds.controllerblueprints.command.api.UploadBlueprintInput +import org.onap.ccsdk.cds.controllerblueprints.command.api.UploadBlueprintOutput import org.onap.ccsdk.cds.controllerblueprints.core.jsonAsJsonType import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils import org.slf4j.LoggerFactory @@ -47,6 +51,7 @@ import java.util.concurrent.TimeUnit interface RemoteScriptExecutionService { suspend fun init(selector: Any) + suspend fun uploadBlueprint(uploadBpInput: RemoteScriptUploadBlueprintInput): RemoteScriptUploadBlueprintOutput suspend fun prepareEnv(prepareEnvInput: PrepareRemoteEnvInput): RemoteScriptExecutionOutput suspend fun executeCommand(remoteExecutionInput: RemoteScriptExecutionInput): RemoteScriptExecutionOutput suspend fun close() @@ -84,6 +89,19 @@ class GrpcRemoteScriptExecutionService(private val bluePrintGrpcLibPropertyServi } } + override suspend fun uploadBlueprint(uploadBPInput: RemoteScriptUploadBlueprintInput): RemoteScriptUploadBlueprintOutput { + val logPart = "requestId(${uploadBPInput.requestId}) subRequestId(${uploadBPInput.subRequestId}) blueprintName(${uploadBPInput.remoteIdentifier?.blueprintName}) blueprintVersion(${uploadBPInput.remoteIdentifier?.blueprintVersion}) blueprintUUID(${uploadBPInput.remoteIdentifier?.blueprintUUID})" + val grpcResponse = commandExecutorServiceGrpc + .withDeadlineAfter(uploadBPInput.timeOut * 1000, TimeUnit.MILLISECONDS) + .uploadBlueprint(uploadBPInput.asGrpcData()) + checkNotNull(grpcResponse.status) { + "failed to get GRPC upload CBA response status for $logPart" + } + val uploadBlueprinOutput = grpcResponse.asJavaData() + log.info("Received Upload CBA response status(${uploadBlueprinOutput.status}) for $logPart payload(${uploadBlueprinOutput.payload})") + return uploadBlueprinOutput + } + override suspend fun prepareEnv(prepareEnvInput: PrepareRemoteEnvInput): RemoteScriptExecutionOutput { val grpResponse = commandExecutorServiceGrpc .withDeadlineAfter(prepareEnvInput.timeOut * 1000, TimeUnit.MILLISECONDS) @@ -117,6 +135,21 @@ class GrpcRemoteScriptExecutionService(private val bluePrintGrpcLibPropertyServi channel?.shutdownNow() } + fun RemoteScriptUploadBlueprintInput.asGrpcData(): UploadBlueprintInput { + val correlationId = this.correlationId ?: this.requestId + return UploadBlueprintInput.newBuilder() + .setIdentifiers(this.remoteIdentifier!!.asGrpcData()) + .setRequestId(this.requestId) + .setSubRequestId(this.subRequestId) + .setOriginatorId(this.originatorId) + .setCorrelationId(correlationId) + .setTimestamp(Timestamp.getDefaultInstance()) + .setBinData(this.binData) + .setArchiveType(this.archiveType) + .setTimeOut(this.timeOut.toInt()) + .build() + } + fun PrepareRemoteEnvInput.asGrpcData(): PrepareEnvInput { val correlationId = this.correlationId ?: this.requestId @@ -159,6 +192,7 @@ class GrpcRemoteScriptExecutionService(private val bluePrintGrpcLibPropertyServi return Identifiers.newBuilder() .setBlueprintName(this.blueprintName) .setBlueprintVersion(this.blueprintVersion) + .setBlueprintUUID(this.blueprintUUID) .build() } @@ -176,4 +210,13 @@ class GrpcRemoteScriptExecutionService(private val bluePrintGrpcLibPropertyServi payload = payload.jsonAsJsonType() ) } + + fun UploadBlueprintOutput.asJavaData(): RemoteScriptUploadBlueprintOutput { + return RemoteScriptUploadBlueprintOutput( + requestId = this.requestId, + subRequestId = this.subRequestId, + status = StatusType.valueOf(this.status.name), + payload = payload.jsonAsJsonType() + ) + } } -- cgit 1.2.3-korg