diff options
Diffstat (limited to 'ms/blueprintsprocessor')
19 files changed, 247 insertions, 92 deletions
diff --git a/ms/blueprintsprocessor/application/pom.xml b/ms/blueprintsprocessor/application/pom.xml index dc0e49fd7..138eecba5 100755 --- a/ms/blueprintsprocessor/application/pom.xml +++ b/ms/blueprintsprocessor/application/pom.xml @@ -24,7 +24,7 @@ <groupId>org.onap.ccsdk.cds.blueprintsprocessor</groupId> <artifactId>parent</artifactId> <version>0.7.0-SNAPSHOT</version> - <relativePath>..</relativePath> + <relativePath>../parent</relativePath> </parent> <artifactId>application</artifactId> diff --git a/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/security/BasicAuthServerInterceptor.kt b/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/security/BasicAuthServerInterceptor.kt index f821462af..a0a4ae297 100644 --- a/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/security/BasicAuthServerInterceptor.kt +++ b/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/security/BasicAuthServerInterceptor.kt @@ -49,7 +49,7 @@ class BasicAuthServerInterceptor(private val authenticationManager: Authenticati log.info("Basic Authentication Authorization header found for user: {}", username) val authRequest = UsernamePasswordAuthenticationToken(username, tokens[1]) - val authResult = authenticationManager!!.authenticate(authRequest).block() + val authResult = authenticationManager.authenticate(authRequest).block() log.info("Authentication success: {}", authResult) diff --git a/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/UatExecutor.kt b/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/UatExecutor.kt index 6678075bd..4e97460d3 100644 --- a/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/UatExecutor.kt +++ b/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/UatExecutor.kt @@ -304,6 +304,10 @@ class UatExecutor( return realAnswer } + override suspend fun <T> retry(times: Int, initialDelay: Long, delay: Long, block: suspend (Int) -> T): T { + return super.retry(times, initialDelay, delay, block) + } + fun asServiceDefinition() = ServiceDefinition(selector, expectations) diff --git a/ms/blueprintsprocessor/application/src/main/resources/application-dev.properties b/ms/blueprintsprocessor/application/src/main/resources/application-dev.properties index 485b0bfee..fc2e7f244 100755 --- a/ms/blueprintsprocessor/application/src/main/resources/application-dev.properties +++ b/ms/blueprintsprocessor/application/src/main/resources/application-dev.properties @@ -34,14 +34,10 @@ resourceSourceMappings=processor-db=source-db,input=source-input,default=source- blueprintsprocessor.blueprintDeployPath=blueprints/deploy blueprintsprocessor.blueprintArchivePath=blueprints/archive blueprintsprocessor.blueprintWorkingPath=blueprints/work + # Controller Blueprint Load Configurations -# blueprints.load.initial-data may be overridden by ENV variables -blueprintsprocessor.loadInitialData=false -blueprintsprocessor.loadBluePrint=false blueprintsprocessor.loadBluePrintPaths=./../../../components/model-catalog/blueprint-model/service-blueprint -blueprintsprocessor.loadModelType=true blueprintsprocessor.loadModeTypePaths=./../../../components/model-catalog/definition-type/starter-type -blueprintsprocessor.loadResourceDictionary=true blueprintsprocessor.loadResourceDictionaryPaths=./../../../components/model-catalog/resource-dictionary/starter-dictionary # CBA file extension diff --git a/ms/blueprintsprocessor/application/src/main/resources/application.properties b/ms/blueprintsprocessor/application/src/main/resources/application.properties index 6708dcf69..bd713080f 100755 --- a/ms/blueprintsprocessor/application/src/main/resources/application.properties +++ b/ms/blueprintsprocessor/application/src/main/resources/application.properties @@ -24,14 +24,9 @@ blueprintsprocessor.blueprintArchivePath=/opt/app/onap/blueprints/archive blueprintsprocessor.blueprintWorkingPath=/opt/app/onap/blueprints/working # Controller Blueprint Load Configurations -# blueprints.load.initial-data may be overridden by ENV variables -blueprintsprocessor.loadInitialData=false -blueprintsprocessor.loadBluePrint=false -blueprintsprocessor.loadBluePrintPaths=/opt/app/onap/model-catalog/blueprint-model/service-blueprint -blueprintsprocessor.loadModelType=false -blueprintsprocessor.loadModeTypePaths=/opt/app/onap/model-catalog/definition-type/starter-type -blueprintsprocessor.loadResourceDictionary=false -blueprintsprocessor.loadResourceDictionaryPaths=/opt/app/onap/model-catalog/resource-dictionary/starter-dictionary +blueprintsprocessor.loadBluePrintPaths=/opt/app/onap/model-catalog/blueprint-model +blueprintsprocessor.loadModeTypePaths=/opt/app/onap/model-catalog/definition-type +blueprintsprocessor.loadResourceDictionaryPaths=/opt/app/onap/model-catalog/resource-dictionary # CBA file extension controllerblueprints.loadCbaExtension=zip diff --git a/ms/blueprintsprocessor/application/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/BlueprintsAcceptanceTest.kt b/ms/blueprintsprocessor/application/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/BlueprintsAcceptanceTest.kt index 4fed0ce67..fa550d1d0 100644 --- a/ms/blueprintsprocessor/application/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/BlueprintsAcceptanceTest.kt +++ b/ms/blueprintsprocessor/application/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/BlueprintsAcceptanceTest.kt @@ -19,6 +19,7 @@ */ package org.onap.ccsdk.cds.blueprintsprocessor.uat +import kotlinx.coroutines.runBlocking import org.junit.ClassRule import org.junit.Rule import org.junit.runner.RunWith @@ -38,7 +39,7 @@ import kotlin.test.Test // See more on https://docs.spring.io/autorepo/docs/spring-framework/current/spring-framework-reference/testing.html#testcontext-junit4-rules @RunWith(Parameterized::class) class BlueprintsAcceptanceTest(@Suppress("unused") private val blueprintName: String, // readable test description - private val rootFs: FileSystem): BaseUatTest() { + private val rootFs: FileSystem) : BaseUatTest() { companion object { @@ -84,8 +85,10 @@ class BlueprintsAcceptanceTest(@Suppress("unused") private val blueprintName: St @Test fun runUat() { - val uatSpec = rootFs.getPath(UAT_SPECIFICATION_FILE).toFile().readText() - val cbaBytes = compressToBytes(rootFs.getPath("/")) - uatExecutor.execute(uatSpec, cbaBytes) + runBlocking { + val uatSpec = rootFs.getPath(UAT_SPECIFICATION_FILE).toFile().readText() + val cbaBytes = compressToBytes(rootFs.getPath("/")) + uatExecutor.execute(uatSpec, cbaBytes) + } } }
\ No newline at end of file diff --git a/ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/python/executor/ComponentRemotePythonExecutor.kt b/ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/python/executor/ComponentRemotePythonExecutor.kt index 6b1f186c9..91d51757a 100644 --- a/ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/python/executor/ComponentRemotePythonExecutor.kt +++ b/ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/python/executor/ComponentRemotePythonExecutor.kt @@ -110,35 +110,38 @@ open class ComponentRemotePythonExecutor(private val remoteScriptExecutionServic ) val prepareEnvOutput = remoteScriptExecutionService.prepareEnv(prepareEnvInput) log.info("$ATTRIBUTE_PREPARE_ENV_LOG - ${prepareEnvOutput.response}") - val logs = JacksonUtils.jsonNodeFromObject(prepareEnvOutput.response) - setAttribute(ATTRIBUTE_PREPARE_ENV_LOG, logs) - setAttribute(ATTRIBUTE_EXEC_CMD_LOG, "N/A".asJsonPrimitive()) + val logs = prepareEnvOutput.response + val logsEnv = logs.toString().asJsonPrimitive() + setAttribute(ATTRIBUTE_PREPARE_ENV_LOG, logsEnv) if (prepareEnvOutput.status != StatusType.SUCCESS) { - setNodeOutputErrors(prepareEnvOutput.status.name, logs) + setAttribute(ATTRIBUTE_EXEC_CMD_LOG, "N/A".asJsonPrimitive()) + setNodeOutputErrors(prepareEnvOutput.status.name, logsEnv) } else { - setNodeOutputProperties(prepareEnvOutput.status.name.asJsonPrimitive(), logs, "".asJsonPrimitive()) + setNodeOutputProperties(prepareEnvOutput.status.name.asJsonPrimitive(), logsEnv, "".asJsonPrimitive()) } } - // Populate command execution properties and pass it to the remote server - val properties = dynamicProperties?.returnNullIfMissing()?.rootFieldsToMap() ?: hashMapOf() - - val remoteExecutionInput = RemoteScriptExecutionInput( - requestId = processId, - remoteIdentifier = RemoteIdentifier(blueprintName = blueprintName, blueprintVersion = blueprintVersion), - command = scriptCommand, - properties = properties) - val remoteExecutionOutput = remoteScriptExecutionService.executeCommand(remoteExecutionInput) - - val logs = JacksonUtils.jsonNodeFromObject(remoteExecutionOutput.response) - if (remoteExecutionOutput.status != StatusType.SUCCESS) { - setNodeOutputErrors(remoteExecutionOutput.status.name,logs, remoteExecutionOutput.payload) - } else { - setNodeOutputProperties(remoteExecutionOutput.status.name.asJsonPrimitive(), logs, - remoteExecutionOutput.payload) + // if Env preparation was successful, then proceed with command execution in this Env + if (bluePrintRuntimeService.getBluePrintError().errors.isEmpty()) { + // Populate command execution properties and pass it to the remote server + val properties = dynamicProperties?.returnNullIfMissing()?.rootFieldsToMap() ?: hashMapOf() + + val remoteExecutionInput = RemoteScriptExecutionInput( + requestId = processId, + remoteIdentifier = RemoteIdentifier(blueprintName = blueprintName, blueprintVersion = blueprintVersion), + command = scriptCommand, + properties = properties) + val remoteExecutionOutput = remoteScriptExecutionService.executeCommand(remoteExecutionInput) + + val logs = JacksonUtils.jsonNodeFromObject(remoteExecutionOutput.response) + if (remoteExecutionOutput.status != StatusType.SUCCESS) { + setNodeOutputErrors(remoteExecutionOutput.status.name, logs, remoteExecutionOutput.payload) + } else { + setNodeOutputProperties(remoteExecutionOutput.status.name.asJsonPrimitive(), logs, + remoteExecutionOutput.payload) + } } - } catch (e: Exception) { log.error("Failed to process on remote executor", e) } finally { @@ -178,9 +181,12 @@ open class ComponentRemotePythonExecutor(private val remoteScriptExecutionServic */ private fun setNodeOutputErrors(status: String, message: JsonNode, artifacts: JsonNode = "".asJsonPrimitive() ) { setAttribute(ATTRIBUTE_EXEC_CMD_STATUS, status.asJsonPrimitive()) + log.info("Executor status : $status") setAttribute(ATTRIBUTE_EXEC_CMD_LOG, message) + log.info("Executor message : $message") setAttribute(ATTRIBUTE_RESPONSE_DATA, artifacts) + log.info("Executor artifacts: $artifacts") - addError(status, ATTRIBUTE_EXEC_CMD_LOG, message.asText()) + addError(status, ATTRIBUTE_EXEC_CMD_LOG, message.toString()) } } diff --git a/ms/blueprintsprocessor/functions/restconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/restconf/executor/RestconfExecutorExtensions.kt b/ms/blueprintsprocessor/functions/restconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/restconf/executor/RestconfExecutorExtensions.kt index 49fd025d9..11a35eede 100644 --- a/ms/blueprintsprocessor/functions/restconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/restconf/executor/RestconfExecutorExtensions.kt +++ b/ms/blueprintsprocessor/functions/restconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/restconf/executor/RestconfExecutorExtensions.kt @@ -39,19 +39,20 @@ fun AbstractScriptComponentFunction.restconfClientService(selector: String): Blu */ suspend fun AbstractScriptComponentFunction.restconfMountDevice(webClientService: BlueprintWebClientService, - deviceId: String, payload: Any) { - val headers: MutableMap<String, String> = hashMapOf() - headers["Content-Type"] = "application/xml" + deviceId: String, + payload: Any, + headers: Map<String, String> = mutableMapOf("Content-Type" to "application/xml")) { + val mountUrl = "restconf/config/network-topology:network-topology/topology/topology-netconf/node/$deviceId" log.info("sending mount request, url: $mountUrl") - webClientService.exchangeNB("PUT", mountUrl, payload, headers) + webClientService.exchangeResource("PUT", mountUrl, payload as String, headers) /** Check device has mounted */ val mountCheckUrl = "restconf/operational/network-topology:network-topology/topology/topology-netconf/node/$deviceId" val expectedResult = """"netconf-node-topology:connection-status":"connected"""" val mountCheckExecutionBlock: suspend (Int) -> String = { tryCount: Int -> - val result = webClientService.exchangeNB("GET", mountCheckUrl, "") + val result = webClientService.exchangeResource("GET", mountCheckUrl, "") if (result.body.contains(expectedResult)) { log.info("NF was mounted successfully on ODL") result.body @@ -70,13 +71,13 @@ suspend fun AbstractScriptComponentFunction.restconfMountDevice(webClientService suspend fun AbstractScriptComponentFunction.restconfApplyDeviceConfig(webClientService: BlueprintWebClientService, deviceId: String, configletResourcePath: String, configletToApply: Any, - additionalHeaders: Map<String, String>?) { + additionalHeaders: Map<String, String > = mutableMapOf("Content-Type" to "application/yang.patch+xml")) { log.debug("headers: $additionalHeaders") log.info("configuring device: $deviceId, Configlet: $configletToApply") val applyConfigUrl = "restconf/config/network-topology:network-topology/topology/topology-netconf/node/" + "$deviceId/$configletResourcePath" - val result = webClientService.exchangeNB("PATCH", applyConfigUrl, configletToApply, additionalHeaders) + val result:Any = webClientService.exchangeResource("PATCH", applyConfigUrl, configletToApply as String, additionalHeaders) log.info("Configuration application result: $result") } @@ -88,7 +89,7 @@ suspend fun AbstractScriptComponentFunction.restconfDeviceConfig(webClientServic val configPathUrl = "restconf/config/network-topology:network-topology/topology/topology-netconf/node/" + "$deviceId/$configletResourcePath" log.debug("sending GET request, url: $configPathUrl") - return webClientService.exchangeNB("GET", configPathUrl, "") + return webClientService.exchangeResource("GET", configPathUrl, "") } /** @@ -98,5 +99,5 @@ suspend fun AbstractScriptComponentFunction.restconfUnMountDevice(webClientServi deviceId: String, payload: String) { val unMountUrl = "restconf/config/network-topology:network-topology/topology/topology-netconf/node/$deviceId" log.info("sending unMount request, url: $unMountUrl") - webClientService.exchangeNB("DELETE", unMountUrl, "") + webClientService.exchangeResource("DELETE", unMountUrl, "") }
\ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/repository/BlueprintModelSearchRepository.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/repository/BlueprintModelSearchRepository.kt index 60ca1fec1..5c7a94034 100644 --- a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/repository/BlueprintModelSearchRepository.kt +++ b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/repository/BlueprintModelSearchRepository.kt @@ -18,6 +18,9 @@ package org.onap.ccsdk.cds.blueprintsprocessor.db.primary.repository import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.domain.BlueprintModelSearch +import org.springframework.data.domain.Page +import org.springframework.data.domain.PageRequest +import org.springframework.data.domain.Pageable import org.springframework.data.jpa.repository.JpaRepository import org.springframework.stereotype.Repository @@ -76,4 +79,25 @@ interface BlueprintModelSearchRepository : JpaRepository<BlueprintModelSearch, L */ fun findByUpdatedByOrTagsOrOrArtifactNameOrOrArtifactVersionOrArtifactType(updatedBy: String, tags: String, artifactName: String, artifactVersion: String, artifactType: String): List<BlueprintModelSearch> + + + /** + * This is a findby some attributes method + * + * @author Shaaban Ebrahim + * + * @param updatedBy + * @param tags + * @param artifactName + * @param artifactVersion + * @param artifactType + * @param pageRequest + * @return Page<BlueprintModelSearch> + */ + fun findByUpdatedByOrTagsOrOrArtifactNameOrOrArtifactVersionOrArtifactType(updatedBy: String, tags: String, artifactName: String, artifactVersion: String, + artifactType: String,pageRequest: Pageable): Page<BlueprintModelSearch> + + + + } diff --git a/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/BluePrintGrpcLibConfiguration.kt b/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/BluePrintGrpcLibConfiguration.kt index 0ec049a3c..c37c6263a 100644 --- a/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/BluePrintGrpcLibConfiguration.kt +++ b/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/BluePrintGrpcLibConfiguration.kt @@ -45,6 +45,8 @@ fun BluePrintDependencyService.grpcClientService(jsonNode: JsonNode): BluePrintG class GRPCLibConstants { companion object { const val SERVICE_BLUEPRINT_GRPC_LIB_PROPERTY = "blueprint-grpc-lib-property-service" + const val PROPERTY_GRPC_CLIENT_PREFIX = "blueprintsprocessor.grpcclient." + const val PROPERTY_GRPC_SERVER_PREFIX = "blueprintsprocessor.grpcserver." const val TYPE_TOKEN_AUTH = "token-auth" const val TYPE_BASIC_AUTH = "basic-auth" const val TYPE_TLS_AUTH = "tls-auth" diff --git a/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/BluePrintGrpcLibPropertyService.kt b/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/BluePrintGrpcLibPropertyService.kt index fbc9ddd86..02d5cc695 100644 --- a/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/BluePrintGrpcLibPropertyService.kt +++ b/ms/blueprintsprocessor/modules/commons/grpc-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/BluePrintGrpcLibPropertyService.kt @@ -28,6 +28,18 @@ import org.springframework.stereotype.Service @Service(GRPCLibConstants.SERVICE_BLUEPRINT_GRPC_LIB_PROPERTY) open class BluePrintGrpcLibPropertyService(private var bluePrintPropertiesService: BluePrintPropertiesService) { + fun blueprintGrpcServerService(jsonNode: JsonNode): BluePrintGrpcServerService { + val grpcServerProperties = grpcServerProperties(jsonNode) + return blueprintGrpcServerService(grpcServerProperties) + } + + fun blueprintGrpcServerService(selector: String): BluePrintGrpcServerService { + val prefix = "${GRPCLibConstants.PROPERTY_GRPC_SERVER_PREFIX}$selector" + val grpcServerProperties = grpcServerProperties(prefix) + return blueprintGrpcServerService(grpcServerProperties) + } + + /** GRPC Server Lib Property Service */ fun grpcServerProperties(jsonNode: JsonNode): GrpcServerProperties { return when (val type = jsonNode.get("type").textValue()) { @@ -67,6 +79,19 @@ open class BluePrintGrpcLibPropertyService(private var bluePrintPropertiesServic return bluePrintPropertiesService.propertyBeanType(prefix, TLSAuthGrpcServerProperties::class.java) } + private fun blueprintGrpcServerService(grpcServerProperties: GrpcServerProperties) + : BluePrintGrpcServerService { + when (grpcServerProperties) { + is TLSAuthGrpcServerProperties -> { + return TLSAuthGrpcServerService(grpcServerProperties) + } + else -> { + throw BluePrintProcessorException("couldn't get grpc client service for properties $grpcServerProperties") + } + } + } + + /** GRPC Client Lib Property Service */ fun blueprintGrpcClientService(jsonNode: JsonNode): BluePrintGrpcClientService { @@ -75,7 +100,7 @@ open class BluePrintGrpcLibPropertyService(private var bluePrintPropertiesServic } fun blueprintGrpcClientService(selector: String): BluePrintGrpcClientService { - val prefix = "blueprintsprocessor.grpcclient.$selector" + val prefix = "${GRPCLibConstants.PROPERTY_GRPC_CLIENT_PREFIX}$selector" val restClientProperties = grpcClientProperties(prefix) return blueprintGrpcClientService(restClientProperties) } diff --git a/ms/blueprintsprocessor/modules/commons/grpc-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/BluePrintGrpcLibPropertyServiceTest.kt b/ms/blueprintsprocessor/modules/commons/grpc-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/BluePrintGrpcLibPropertyServiceTest.kt index e4bfd5d7c..13432c043 100644 --- a/ms/blueprintsprocessor/modules/commons/grpc-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/BluePrintGrpcLibPropertyServiceTest.kt +++ b/ms/blueprintsprocessor/modules/commons/grpc-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/grpc/service/BluePrintGrpcLibPropertyServiceTest.kt @@ -19,6 +19,7 @@ package org.onap.ccsdk.cds.blueprintsprocessor.grpc.service import com.fasterxml.jackson.databind.JsonNode import com.fasterxml.jackson.databind.ObjectMapper +import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintPropertiesService @@ -190,5 +191,9 @@ class BluePrintGrpcLibPropertyServiceTest { val jsonProperties = bluePrintGrpcLibPropertyService .grpcServerProperties(configDsl.jsonAsJsonType()) as TLSAuthGrpcServerProperties assertNotNull(jsonProperties, "failed to create property bean from json") + + val grpcServerService = bluePrintGrpcLibPropertyService.blueprintGrpcServerService("tls-sample") + assertNotNull(grpcServerService, "failed to get grpc server service") + Assert.assertEquals(TLSAuthGrpcServerService::class.java, grpcServerService.javaClass) } }
\ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/BluePrintManagementGRPCHandler.kt b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/BluePrintManagementGRPCHandler.kt index 0f804b8b2..5f2a6dfb6 100644 --- a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/BluePrintManagementGRPCHandler.kt +++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/BluePrintManagementGRPCHandler.kt @@ -160,6 +160,29 @@ open class BluePrintManagementGRPCHandler(private val bluePrintModelHandler: Blu } } + override fun bootstrapBlueprint(request: BluePrintBootstrapInput, + responseObserver: StreamObserver<BluePrintManagementOutput>) { + runBlocking { + try { + log.info("request(${request.commonHeader.requestId}): Received bootstrap request") + val bootstrapRequest = BootstrapRequest().apply { + loadModelType = request.loadModelType + loadResourceDictionary = request.loadResourceDictionary + loadCBA = request.loadCBA + } + /** Perform bootstrap of Model Types, Resource Definitions and CBA */ + bluePrintModelHandler.bootstrapBlueprint(bootstrapRequest) + responseObserver.onNext(successStatus(request.commonHeader)) + + } catch (e: Exception) { + responseObserver.onNext(failStatus(request.commonHeader, + "request(${request.commonHeader.requestId}): Failed to bootstrap", e)) + } finally { + responseObserver.onCompleted() + } + } + } + private fun outputWithFileBytes(header: CommonHeader, byteArray: ByteArray): BluePrintManagementOutput = BluePrintManagementOutput.newBuilder() .setCommonHeader(header) diff --git a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/BlueprintModelController.kt b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/BlueprintModelController.kt index ea5023cd5..5ef50b09f 100644 --- a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/BlueprintModelController.kt +++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/BlueprintModelController.kt @@ -47,6 +47,15 @@ import reactor.core.publisher.Mono @RequestMapping("/api/v1/blueprint-model") open class BlueprintModelController(private val bluePrintModelHandler: BluePrintModelHandler) { + @PostMapping(path = arrayOf("/bootstrap"), produces = arrayOf(MediaType.APPLICATION_JSON_VALUE), + consumes = arrayOf(MediaType.APPLICATION_JSON_VALUE)) + @ResponseBody + @Throws(BluePrintException::class) + @PreAuthorize("hasRole('USER')") + fun bootstrap(@RequestBody bootstrapRequest: BootstrapRequest): Mono<Unit> = monoMdc { + bluePrintModelHandler.bootstrapBlueprint(bootstrapRequest) + } + @PostMapping("", produces = [MediaType.APPLICATION_JSON_VALUE], consumes = [MediaType.MULTIPART_FORM_DATA_VALUE]) @ResponseBody @Throws(BluePrintException::class) @@ -80,6 +89,19 @@ open class BlueprintModelController(private val bluePrintModelHandler: BluePrint } + @GetMapping("/paged/meta-data/{keyword}", produces = [MediaType.APPLICATION_JSON_VALUE]) + @ResponseBody + @PreAuthorize("hasRole('USER')") + fun allBlueprintModelMetaDataPaged(@NotNull @PathVariable(value = "keyword") keyWord: String, + @RequestParam(defaultValue = "20") limit: Int, + @RequestParam(defaultValue = "0") offset: Int, + @RequestParam(defaultValue = "DATE") sort: BlueprintSortByOption + ): Page<BlueprintModelSearch> { + val pageRequest = PageRequest.of(offset, limit, Sort.Direction.ASC, sort.columnName) + return this.bluePrintModelHandler.searchBluePrintModelsByKeyWordPaged(keyWord, pageRequest) + + } + @DeleteMapping("/{id}") @Throws(BluePrintException::class) @PreAuthorize("hasRole('USER')") diff --git a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/DesignerApiData.kt b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/DesignerApiData.kt index 5259ee1c9..346015bc4 100644 --- a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/DesignerApiData.kt +++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/DesignerApiData.kt @@ -1,5 +1,6 @@ /* * Copyright © 2019 IBM. + * Modifications Copyright © 2018-2019 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. @@ -25,6 +26,13 @@ import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceAssignment import java.io.Serializable import java.util.* + +class BootstrapRequest { + var loadModelType: Boolean = false + var loadResourceDictionary: Boolean = false + var loadCBA: Boolean = false +} + /** * ArtifactRequest.java Purpose: Provide Configuration Generator ArtifactRequest Model * diff --git a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/handler/BluePrintModelHandler.kt b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/handler/BluePrintModelHandler.kt index 19076c681..5f7eacee8 100644 --- a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/handler/BluePrintModelHandler.kt +++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/handler/BluePrintModelHandler.kt @@ -24,6 +24,8 @@ import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.domain.BlueprintModelSe import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.repository.BlueprintModelContentRepository import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.repository.BlueprintModelRepository import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.repository.BlueprintModelSearchRepository +import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.BootstrapRequest +import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.load.BluePrintDatabaseLoadService import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.utils.BluePrintEnhancerUtils import org.onap.ccsdk.cds.controllerblueprints.core.* import org.onap.ccsdk.cds.controllerblueprints.core.config.BluePrintLoadConfiguration @@ -35,6 +37,8 @@ import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintFileUtils import org.springframework.core.io.ByteArrayResource import org.springframework.core.io.Resource import org.springframework.data.domain.Page +import org.springframework.data.domain.PageRequest +import org.springframework.data.domain.Pageable import org.springframework.http.HttpHeaders import org.springframework.http.MediaType import org.springframework.http.ResponseEntity @@ -43,7 +47,6 @@ import org.springframework.stereotype.Service import org.springframework.transaction.annotation.Transactional import java.io.IOException import java.util.* -import org.springframework.data.domain.Pageable /** @@ -54,7 +57,8 @@ import org.springframework.data.domain.Pageable */ @Service -open class BluePrintModelHandler(private val blueprintsProcessorCatalogService: BluePrintCatalogService, +open class BluePrintModelHandler(private val bluePrintDatabaseLoadService: BluePrintDatabaseLoadService, + private val blueprintsProcessorCatalogService: BluePrintCatalogService, private val bluePrintLoadConfiguration: BluePrintLoadConfiguration, private val blueprintModelSearchRepository: BlueprintModelSearchRepository, private val blueprintModelRepository: BlueprintModelRepository, @@ -63,6 +67,22 @@ open class BluePrintModelHandler(private val blueprintsProcessorCatalogService: private val log = logger(BluePrintModelHandler::class) + + open suspend fun bootstrapBlueprint(bootstrapRequest: BootstrapRequest) { + log.info("Bootstrap request with type load(${bootstrapRequest.loadModelType}), " + + "resource dictionary load(${bootstrapRequest.loadResourceDictionary}) and " + + "cba load(${bootstrapRequest.loadCBA})") + if (bootstrapRequest.loadModelType) { + bluePrintDatabaseLoadService.initModelTypes() + } + if (bootstrapRequest.loadResourceDictionary) { + bluePrintDatabaseLoadService.initResourceDictionary() + } + if (bootstrapRequest.loadCBA) { + bluePrintDatabaseLoadService.initBluePrintCatalog() + } + } + /** * This is a getAllBlueprintModel method to retrieve all the BlueprintModel in Database * @@ -241,11 +261,23 @@ open class BluePrintModelHandler(private val blueprintsProcessorCatalogService: * @return List<BlueprintModelSearch> list of the controller blueprint </BlueprintModelSearch> */ open fun searchBluePrintModelsByKeyWord(keyWord: String): List<BlueprintModelSearch> { - return blueprintModelSearchRepository. - findByUpdatedByOrTagsOrOrArtifactNameOrOrArtifactVersionOrArtifactType( - keyWord,keyWord,keyWord,keyWord,keyWord) + return blueprintModelSearchRepository.findByUpdatedByOrTagsOrOrArtifactNameOrOrArtifactVersionOrArtifactType( + keyWord, keyWord, keyWord, keyWord, keyWord) + } + + + /** + * This is a searchBluePrintModelsByKeyWordPagebale method to retrieve specific BlueprintModel in Database + * where keyword equals updatedBy or tags or artifcat name or artifcat version or artifact type and pageable + * @author Shaaban Ebrahim + * @param keyWord + * + * @return List<BlueprintModelSearch> list of the controller blueprint + </BlueprintModelSearch> */ + open fun searchBluePrintModelsByKeyWordPaged(keyWord: String, pageRequest: PageRequest): Page<BlueprintModelSearch> { + return blueprintModelSearchRepository.findByUpdatedByOrTagsOrOrArtifactNameOrOrArtifactVersionOrArtifactType(keyWord, keyWord, keyWord, keyWord, keyWord, pageRequest) } - + /** * This is a deleteBlueprintModel method * diff --git a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/load/BluePrintDatabaseLoadService.kt b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/load/BluePrintDatabaseLoadService.kt index f30d156ef..31bd2c953 100644 --- a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/load/BluePrintDatabaseLoadService.kt +++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/load/BluePrintDatabaseLoadService.kt @@ -20,8 +20,6 @@ package org.onap.ccsdk.cds.blueprintsprocessor.designer.api.load import kotlinx.coroutines.runBlocking import org.onap.ccsdk.cds.controllerblueprints.core.config.BluePrintLoadConfiguration import org.slf4j.LoggerFactory -import org.springframework.boot.context.event.ApplicationReadyEvent -import org.springframework.context.event.EventListener import org.springframework.stereotype.Service @Service @@ -32,52 +30,36 @@ open class BluePrintDatabaseLoadService(private val bluePrintLoadConfiguration: private val log = LoggerFactory.getLogger(BluePrintDatabaseLoadService::class.java) - - @EventListener(ApplicationReadyEvent::class) open fun init() = runBlocking { - if (bluePrintLoadConfiguration.loadInitialData) { - initModelTypes() - initResourceDictionary() - initBluePrintCatalog() - } else { - log.info("Initial data load is disabled") - } - + initModelTypes() + initResourceDictionary() + initBluePrintCatalog() } open suspend fun initModelTypes() { - log.info("model types load configuration(${bluePrintLoadConfiguration.loadModelType}) " + - "under paths(${bluePrintLoadConfiguration.loadModeTypePaths})") + log.info("model types load from paths(${bluePrintLoadConfiguration.loadModeTypePaths})") - if (bluePrintLoadConfiguration.loadModelType) { - val paths = bluePrintLoadConfiguration.loadModeTypePaths?.split(",") - paths?.let { - modelTypeLoadService.loadPathsModelType(paths) - } + val paths = bluePrintLoadConfiguration.loadModeTypePaths?.split(",") + paths?.let { + modelTypeLoadService.loadPathsModelType(paths) } } open suspend fun initResourceDictionary() { - log.info("resource dictionary load configuration(${bluePrintLoadConfiguration.loadResourceDictionary}) " + - "under paths(${bluePrintLoadConfiguration.loadResourceDictionaryPaths})") + log.info("resource dictionary load from paths(${bluePrintLoadConfiguration.loadResourceDictionaryPaths})") - if (bluePrintLoadConfiguration.loadResourceDictionary) { - val paths = bluePrintLoadConfiguration.loadResourceDictionaryPaths?.split(",") - paths?.let { - resourceDictionaryLoadService.loadPathsResourceDictionary(paths) - } + val paths = bluePrintLoadConfiguration.loadResourceDictionaryPaths?.split(",") + paths?.let { + resourceDictionaryLoadService.loadPathsResourceDictionary(paths) } } open suspend fun initBluePrintCatalog() { - log.info("blueprint load configuration(${bluePrintLoadConfiguration.loadBluePrint}) " + - "under paths(${bluePrintLoadConfiguration.loadBluePrintPaths})") + log.info("cba load from paths(${bluePrintLoadConfiguration.loadBluePrintPaths})") - if (bluePrintLoadConfiguration.loadBluePrint) { - val paths = bluePrintLoadConfiguration.loadBluePrintPaths?.split(",") - paths?.let { - bluePrintCatalogLoadService.loadPathsBluePrintModelCatalog(paths) - } + val paths = bluePrintLoadConfiguration.loadBluePrintPaths?.split(",") + paths?.let { + bluePrintCatalogLoadService.loadPathsBluePrintModelCatalog(paths) } } }
\ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/BluePrintManagementGRPCHandlerTest.kt b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/BluePrintManagementGRPCHandlerTest.kt index 54dd46ef7..61f515017 100644 --- a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/BluePrintManagementGRPCHandlerTest.kt +++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/BluePrintManagementGRPCHandlerTest.kt @@ -68,6 +68,18 @@ class BluePrintManagementGRPCHandlerTest { } @Test + fun testBootstrap() { + val blockingStub = BluePrintManagementServiceGrpc.newBlockingStub(grpcServerRule.channel) + val id = "123_Bootstrap" + val req = createBootstrapInputRequest(id) + val bootstrapOutput = blockingStub.bootstrapBlueprint(req) + assertEquals(200, bootstrapOutput.status.code) + assertTrue(bootstrapOutput.status.message.contentEquals(BluePrintConstants.STATUS_SUCCESS), + "failed to get success status") + assertEquals(id, bootstrapOutput.commonHeader.requestId) + } + + @Test fun `test upload and download blueprint`() { val blockingStub = BluePrintManagementServiceGrpc.newBlockingStub(grpcServerRule.channel) val id = "123_upload" @@ -128,6 +140,21 @@ class BluePrintManagementGRPCHandlerTest { } } + private fun createBootstrapInputRequest(id: String): BluePrintBootstrapInput { + val commonHeader = CommonHeader + .newBuilder() + .setTimestamp("2012-04-23T18:25:43.511Z") + .setOriginatorId("System") + .setRequestId(id) + .setSubRequestId("1234-56").build() + + return BluePrintBootstrapInput.newBuilder() + .setCommonHeader(commonHeader) + .setLoadModelType(false) + .setLoadResourceDictionary(false) + .setLoadCBA(false) + .build() + } private fun createUploadInputRequest(id: String, action: String): BluePrintUploadInput { val file = normalizedFile("./src/test/resources/test-cba.zip") diff --git a/ms/blueprintsprocessor/pom.xml b/ms/blueprintsprocessor/pom.xml index 658e5c417..cf9d88885 100755 --- a/ms/blueprintsprocessor/pom.xml +++ b/ms/blueprintsprocessor/pom.xml @@ -22,7 +22,7 @@ <groupId>org.onap.ccsdk.cds</groupId> <artifactId>ms</artifactId> <version>0.7.0-SNAPSHOT</version> - <relativePath>../parent</relativePath> + <relativePath>..</relativePath> </parent> <artifactId>blueprintsprocessor</artifactId> |