diff options
author | Singal, Kapil (ks220y) <ks220y@att.com> | 2019-11-22 18:06:08 -0500 |
---|---|---|
committer | KAPIL SINGAL <ks220y@att.com> | 2019-11-26 21:32:38 +0000 |
commit | 341db21b2ac0a14a1ed2b8bf7930914dda054bfe (patch) | |
tree | 113bba965b06cfe3a8af3a0a527d1a41c9faf0f9 /ms/blueprintsprocessor/modules/inbounds | |
parent | d274e5fc552cf9ae25500f504f0434981cf3accf (diff) |
Formatting Code base with ktlint
No Business logic change, just the code format.
Competible with IntelliJ: https://github.com/pinterest/ktlint#option-3
To format run: mvn process-sources -P format
Issue-ID: CCSDK-1947
Signed-off-by: Singal, Kapil (ks220y) <ks220y@att.com>
Change-Id: Ic9e9209fb7023d77f434693ad5a01229f8d09331
Diffstat (limited to 'ms/blueprintsprocessor/modules/inbounds')
93 files changed, 1439 insertions, 1018 deletions
diff --git a/ms/blueprintsprocessor/modules/inbounds/configs-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/configs/api/ResourceConfigSnapshotController.kt b/ms/blueprintsprocessor/modules/inbounds/configs-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/configs/api/ResourceConfigSnapshotController.kt index eb7929509..0b18fb01f 100644 --- a/ms/blueprintsprocessor/modules/inbounds/configs-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/configs/api/ResourceConfigSnapshotController.kt +++ b/ms/blueprintsprocessor/modules/inbounds/configs-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/configs/api/ResourceConfigSnapshotController.kt @@ -27,7 +27,14 @@ import org.onap.ccsdk.cds.controllerblueprints.core.asJsonPrimitive import org.springframework.http.MediaType import org.springframework.http.ResponseEntity import org.springframework.security.access.prepost.PreAuthorize -import org.springframework.web.bind.annotation.* +import org.springframework.web.bind.annotation.PathVariable +import org.springframework.web.bind.annotation.PostMapping +import org.springframework.web.bind.annotation.RequestBody +import org.springframework.web.bind.annotation.RequestMapping +import org.springframework.web.bind.annotation.RequestMethod +import org.springframework.web.bind.annotation.RequestParam +import org.springframework.web.bind.annotation.ResponseBody +import org.springframework.web.bind.annotation.RestController /** * Exposes Resource Configuration Snapshot API to store and retrieve stored resource configurations. @@ -37,52 +44,66 @@ import org.springframework.web.bind.annotation.* */ @RestController @RequestMapping("/api/v1/configs") -@Api(value = "/api/v1/configs", - description = "Interaction with stored configurations.") +@Api( + value = "/api/v1/configs", + description = "Interaction with stored configurations." +) open class ResourceConfigSnapshotController(private val resourceConfigSnapshotService: ResourceConfigSnapshotService) { - @RequestMapping(path = ["/health-check"], + @RequestMapping( + path = ["/health-check"], method = [RequestMethod.GET], - produces = [MediaType.APPLICATION_JSON_VALUE]) + produces = [MediaType.APPLICATION_JSON_VALUE] + ) @ResponseBody @ApiOperation(value = "Health Check", hidden = true) fun ressCfgSnapshotControllerHealthCheck(): JsonNode = runBlocking { "Success".asJsonPrimitive() } - @RequestMapping(path = [""], + @RequestMapping( + path = [""], method = [RequestMethod.GET], - produces = [MediaType.TEXT_PLAIN_VALUE, MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE]) - @ApiOperation(value = "Retrieve a resource configuration snapshot.", + produces = [MediaType.TEXT_PLAIN_VALUE, MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE] + ) + @ApiOperation( + value = "Retrieve a resource configuration snapshot.", notes = "Retrieve a config snapshot, identified by its Resource Id and Type. " + - "An extra 'format' parameter can be passed to tell what content-type is expected.") + "An extra 'format' parameter can be passed to tell what content-type is expected." + ) @ResponseBody @PreAuthorize("hasRole('USER')") fun get( - @ApiParam(value = "Resource Type associated of the resource configuration snapshot.", required = false) + @ApiParam(value = "Resource Type associated of the resource configuration snapshot.", required = false) @RequestParam(value = "resourceType", required = true) resourceType: String, - @ApiParam(value = "Resource Id associated of the resource configuration snapshot.", required = false) + @ApiParam(value = "Resource Id associated of the resource configuration snapshot.", required = false) @RequestParam(value = "resourceId", required = true) resourceId: String, - @ApiParam(value = "Status of the snapshot being retrieved.", defaultValue = "RUNNING", required = false) + @ApiParam(value = "Status of the snapshot being retrieved.", defaultValue = "RUNNING", required = false) @RequestParam(value = "status", required = false, defaultValue = "RUNNING") status: String, - @ApiParam(value = "Expected format of the snapshot being retrieved.", defaultValue = MediaType.TEXT_PLAIN_VALUE, - required = false) - @RequestParam(value = "format", required = false, defaultValue = MediaType.TEXT_PLAIN_VALUE) format: String) + @ApiParam( + value = "Expected format of the snapshot being retrieved.", defaultValue = MediaType.TEXT_PLAIN_VALUE, + required = false + ) + @RequestParam(value = "format", required = false, defaultValue = MediaType.TEXT_PLAIN_VALUE) format: String + ): - : ResponseEntity<String> = runBlocking { + ResponseEntity<String> = runBlocking { var configSnapshot = "" if (resourceType.isNotEmpty() && resourceId.isNotEmpty()) { try { - configSnapshot = resourceConfigSnapshotService.findByResourceIdAndResourceTypeAndStatus(resourceId, - resourceType, ResourceConfigSnapshot.Status.valueOf(status.toUpperCase())) - } catch (ex : NoSuchElementException) { + configSnapshot = resourceConfigSnapshotService.findByResourceIdAndResourceTypeAndStatus( + resourceId, + resourceType, ResourceConfigSnapshot.Status.valueOf(status.toUpperCase()) + ) + } catch (ex: NoSuchElementException) { throw ResourceConfigSnapshotException( - "Could not find configuration snapshot entry for type $resourceType and Id $resourceId") + "Could not find configuration snapshot entry for type $resourceType and Id $resourceId" + ) } } else { throw IllegalArgumentException("Missing param. You must specify resource-id and resource-type.") @@ -97,12 +118,16 @@ open class ResourceConfigSnapshotController(private val resourceConfigSnapshotSe ResponseEntity.ok().contentType(expectedMediaType).body(configSnapshot) } - @PostMapping("/{resourceType}/{resourceId}/{status}", - produces = [MediaType.APPLICATION_JSON_VALUE]) - @ApiOperation(value = "Store a resource configuration snapshot identified by resourceId, resourceType, status.", + @PostMapping( + "/{resourceType}/{resourceId}/{status}", + produces = [MediaType.APPLICATION_JSON_VALUE] + ) + @ApiOperation( + value = "Store a resource configuration snapshot identified by resourceId, resourceType, status.", notes = "Store a resource configuration snapshot, identified by its resourceId and resourceType, " + "and optionally its status, either RUNNING or CANDIDATE.", - response = ResourceConfigSnapshot::class, produces = MediaType.APPLICATION_JSON_VALUE) + response = ResourceConfigSnapshot::class, produces = MediaType.APPLICATION_JSON_VALUE + ) @ResponseBody @PreAuthorize("hasRole('USER')") fun postWithResourceIdAndResourceType( @@ -113,11 +138,14 @@ open class ResourceConfigSnapshotController(private val resourceConfigSnapshotSe @ApiParam(value = "Status of the snapshot being retrieved.", defaultValue = "RUNNING", required = true) @PathVariable(value = "status", required = true) status: String, @ApiParam(value = "Config snapshot to store.", required = true) - @RequestBody snapshot: String): ResponseEntity<ResourceConfigSnapshot> = runBlocking { + @RequestBody snapshot: String + ): ResponseEntity<ResourceConfigSnapshot> = runBlocking { val resultStored = - resourceConfigSnapshotService.write(snapshot, resourceId, resourceType, - ResourceConfigSnapshot.Status.valueOf(status.toUpperCase())) + resourceConfigSnapshotService.write( + snapshot, resourceId, resourceType, + ResourceConfigSnapshot.Status.valueOf(status.toUpperCase()) + ) ResponseEntity.ok().body(resultStored) } diff --git a/ms/blueprintsprocessor/modules/inbounds/configs-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/configs/api/ResourceConfigSnapshotExceptionHandler.kt b/ms/blueprintsprocessor/modules/inbounds/configs-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/configs/api/ResourceConfigSnapshotExceptionHandler.kt index d21464ef5..d4c31e780 100644 --- a/ms/blueprintsprocessor/modules/inbounds/configs-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/configs/api/ResourceConfigSnapshotExceptionHandler.kt +++ b/ms/blueprintsprocessor/modules/inbounds/configs-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/configs/api/ResourceConfigSnapshotExceptionHandler.kt @@ -23,16 +23,16 @@ import com.fasterxml.jackson.annotation.JsonTypeName import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException import org.onap.ccsdk.cds.controllerblueprints.core.data.ErrorCode import org.slf4j.LoggerFactory +import org.springframework.dao.EmptyResultDataAccessException +import org.springframework.dao.IncorrectResultSizeDataAccessException import org.springframework.http.HttpStatus import org.springframework.http.ResponseEntity import org.springframework.orm.jpa.JpaObjectRetrievalFailureException -import org.springframework.dao.EmptyResultDataAccessException -import org.springframework.dao.IncorrectResultSizeDataAccessException -import org.springframework.web.server.ServerWebInputException import org.springframework.web.bind.annotation.ExceptionHandler import org.springframework.web.bind.annotation.RestControllerAdvice +import org.springframework.web.server.ServerWebInputException import java.io.Serializable -import java.util.* +import java.util.Date /** * Handle exceptions in ResourceConfigSnapshot API and provide relevant HTTP status codes and messages @@ -102,9 +102,11 @@ open class ResourceConfigSnapshotExceptionHandler { log.error(e.message) } val errorMessage = - ErrorMessage(errorCode.message(e.message!!), + ErrorMessage( + errorCode.message(e.message!!), errorCode.value, - debugMsg) + debugMsg + ) return ResponseEntity(errorMessage, HttpStatus.resolve(errorCode.httpCode)!!) } } @@ -113,6 +115,7 @@ open class ResourceConfigSnapshotExceptionHandler { @JsonTypeName("errorMessage") @JsonTypeInfo(include = JsonTypeInfo.As.WRAPPER_OBJECT, use = JsonTypeInfo.Id.NAME) class ErrorMessage(var message: String?, var code: Int?, var debugMessage: String?) : Serializable { + @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") var timestamp = Date() -}
\ No newline at end of file +} diff --git a/ms/blueprintsprocessor/modules/inbounds/configs-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/configs/api/ResourceConfigSnapshotControllerTest.kt b/ms/blueprintsprocessor/modules/inbounds/configs-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/configs/api/ResourceConfigSnapshotControllerTest.kt index 89f62812e..34c7a7c7c 100644 --- a/ms/blueprintsprocessor/modules/inbounds/configs-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/configs/api/ResourceConfigSnapshotControllerTest.kt +++ b/ms/blueprintsprocessor/modules/inbounds/configs-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/configs/api/ResourceConfigSnapshotControllerTest.kt @@ -35,8 +35,10 @@ import org.springframework.web.reactive.function.BodyInserters @RunWith(SpringRunner::class) @WebFluxTest -@ContextConfiguration(classes = [BluePrintCoreConfiguration::class, - BluePrintCatalogService::class, SecurityProperties::class]) +@ContextConfiguration( + classes = [BluePrintCoreConfiguration::class, + BluePrintCatalogService::class, SecurityProperties::class] +) @ComponentScan(basePackages = ["org.onap.ccsdk.cds.blueprintsprocessor", "org.onap.ccsdk.cds.controllerblueprints"]) @TestPropertySource(locations = ["classpath:application-test.properties"]) class ResourceConfigSnapshotControllerTest { @@ -68,24 +70,24 @@ class ResourceConfigSnapshotControllerTest { runBlocking { webTestClient - .post() - .uri("/api/v1/configs/$resourceType/$resourceId/running") - .body(BodyInserters.fromObject(snapshotData)) - .exchange() - .expectStatus().is2xxSuccessful - .expectBody() - .jsonPath("$.createdDate") - .value<String> { println(it) } + .post() + .uri("/api/v1/configs/$resourceType/$resourceId/running") + .body(BodyInserters.fromObject(snapshotData)) + .exchange() + .expectStatus().is2xxSuccessful + .expectBody() + .jsonPath("$.createdDate") + .value<String> { println(it) } webTestClient - .post() - .uri("/api/v1/configs/$resourceType/$resourceId/running") - .body(BodyInserters.fromObject(snapshotData)) - .exchange() - .expectStatus().is2xxSuccessful - .expectBody() - .jsonPath("$.createdDate") - .value<String> { println(it)} + .post() + .uri("/api/v1/configs/$resourceType/$resourceId/running") + .body(BodyInserters.fromObject(snapshotData)) + .exchange() + .expectStatus().is2xxSuccessful + .expectBody() + .jsonPath("$.createdDate") + .value<String> { println(it) } } } @@ -93,7 +95,7 @@ class ResourceConfigSnapshotControllerTest { fun `get returns requested JSON content-type`() { runBlocking { post(resourceType, "22", "RUNNING") - get("json", resourceType,"22", "RUNNING") + get("json", resourceType, "22", "RUNNING") } } @@ -122,8 +124,8 @@ class ResourceConfigSnapshotControllerTest { val arguments = "resourceId=MISSING&resourceType=PNF&status=TOTALLY_WRONG" webTestClient.get().uri("/api/v1/configs?$arguments") - .exchange() - .expectStatus().isBadRequest + .exchange() + .expectStatus().isBadRequest } } @@ -140,7 +142,7 @@ class ResourceConfigSnapshotControllerTest { } } - private fun post( resourceType: String, resourceId: String, status: String) { + private fun post(resourceType: String, resourceId: String, status: String) { webTestClient .post() .uri("/api/v1/configs/$resourceType/$resourceId/$status") @@ -150,7 +152,7 @@ class ResourceConfigSnapshotControllerTest { .expectBody() } - private fun get(expectedType : String, resourceType: String, resourceId: String, status: String) { + private fun get(expectedType: String, resourceType: String, resourceId: String, status: String) { var requestArguments = "resourceId=$resourceId&resourceType=$resourceType&status=$status" if (expectedType.isNotEmpty()) { 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 5f2a6dfb6..bca77f275 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 @@ -30,31 +30,42 @@ 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.* +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 +import org.onap.ccsdk.cds.controllerblueprints.management.api.UploadAction import org.slf4j.LoggerFactory import org.springframework.security.access.prepost.PreAuthorize import org.springframework.stereotype.Service -//TODO("Convert to coroutines handler") +// TODO("Convert to coroutines handler") @Service -open class BluePrintManagementGRPCHandler(private val bluePrintModelHandler: BluePrintModelHandler) - : BluePrintManagementServiceGrpc.BluePrintManagementServiceImplBase() { +open class BluePrintManagementGRPCHandler(private val bluePrintModelHandler: BluePrintModelHandler) : + BluePrintManagementServiceGrpc.BluePrintManagementServiceImplBase() { private val log = LoggerFactory.getLogger(BluePrintManagementGRPCHandler::class.java) @PreAuthorize("hasRole('USER')") - override fun uploadBlueprint(request: BluePrintUploadInput, responseObserver: - StreamObserver<BluePrintManagementOutput>) { + override fun uploadBlueprint( + request: BluePrintUploadInput, + responseObserver: StreamObserver<BluePrintManagementOutput> + ) { runBlocking { - //TODO("catch if request id is missing") + // TODO("catch if request id is missing") log.info("request(${request.commonHeader.requestId})") try { /** Get the file byte array */ val byteArray = request.fileChunk.chunk.toByteArray() /** Get the Upload Action */ val uploadAction = request.actionIdentifiers?.actionName.emptyTONull() - ?: UploadAction.DRAFT.toString() + ?: UploadAction.DRAFT.toString() when (uploadAction) { UploadAction.DRAFT.toString() -> { @@ -66,24 +77,36 @@ open class BluePrintManagementGRPCHandler(private val bluePrintModelHandler: Blu responseObserver.onNext(successStatus(request.commonHeader, blueprintModel.asJsonString())) } UploadAction.VALIDATE.toString() -> { - //TODO("Not Implemented") - responseObserver.onNext(failStatus(request.commonHeader, + // TODO("Not Implemented") + responseObserver.onNext( + failStatus( + request.commonHeader, "Upload action($uploadAction) not implemented", - BluePrintProcessorException("Not Implemented"))) + BluePrintProcessorException("Not Implemented") + ) + ) } UploadAction.ENRICH.toString() -> { val enrichedByteArray = bluePrintModelHandler.enrichBlueprintFileSource(byteArray) responseObserver.onNext(outputWithFileBytes(request.commonHeader, enrichedByteArray)) } else -> { - responseObserver.onNext(failStatus(request.commonHeader, + responseObserver.onNext( + failStatus( + request.commonHeader, "Upload action($uploadAction) not implemented", - BluePrintProcessorException("Not implemented"))) + BluePrintProcessorException("Not implemented") + ) + ) } } } catch (e: Exception) { - responseObserver.onNext(failStatus(request.commonHeader, - "request(${request.commonHeader.requestId}): Failed to upload CBA", e)) + responseObserver.onNext( + failStatus( + request.commonHeader, + "request(${request.commonHeader.requestId}): Failed to upload CBA", e + ) + ) } finally { responseObserver.onCompleted() } @@ -91,8 +114,10 @@ open class BluePrintManagementGRPCHandler(private val bluePrintModelHandler: Blu } @PreAuthorize("hasRole('USER')") - override fun downloadBlueprint(request: BluePrintDownloadInput, - responseObserver: StreamObserver<BluePrintManagementOutput>) { + override fun downloadBlueprint( + request: BluePrintDownloadInput, + responseObserver: StreamObserver<BluePrintManagementOutput> + ) { runBlocking { val blueprintName = request.actionIdentifiers.blueprintName val blueprintVersion = request.actionIdentifiers.blueprintVersion @@ -100,7 +125,7 @@ open class BluePrintManagementGRPCHandler(private val bluePrintModelHandler: Blu /** Get the Search Action */ val searchAction = request.actionIdentifiers?.actionName.emptyTONull() - ?: DownloadAction.SEARCH.toString() + ?: DownloadAction.SEARCH.toString() log.info("request(${request.commonHeader.requestId}): Received download $blueprint") try { @@ -110,14 +135,22 @@ open class BluePrintManagementGRPCHandler(private val bluePrintModelHandler: Blu responseObserver.onNext(outputWithFileBytes(request.commonHeader, downloadByteArray)) } else -> { - responseObserver.onNext(failStatus(request.commonHeader, + responseObserver.onNext( + failStatus( + request.commonHeader, "Search action($searchAction) not implemented", - BluePrintProcessorException("Not implemented"))) + BluePrintProcessorException("Not implemented") + ) + ) } } } catch (e: Exception) { - responseObserver.onNext(failStatus(request.commonHeader, - "request(${request.commonHeader.requestId}): Failed to delete $blueprint", e)) + responseObserver.onNext( + failStatus( + request.commonHeader, + "request(${request.commonHeader.requestId}): Failed to delete $blueprint", e + ) + ) } finally { responseObserver.onCompleted() } @@ -125,8 +158,11 @@ open class BluePrintManagementGRPCHandler(private val bluePrintModelHandler: Blu } @PreAuthorize("hasRole('USER')") - override fun removeBlueprint(request: BluePrintRemoveInput, responseObserver: - StreamObserver<BluePrintManagementOutput>) { + override fun removeBlueprint( + request: BluePrintRemoveInput, + responseObserver: + StreamObserver<BluePrintManagementOutput> + ) { runBlocking { val blueprintName = request.actionIdentifiers.blueprintName @@ -137,7 +173,7 @@ open class BluePrintManagementGRPCHandler(private val bluePrintModelHandler: Blu /** Get the Remove Action */ val removeAction = request.actionIdentifiers?.actionName.emptyTONull() - ?: RemoveAction.DEFAULT.toString() + ?: RemoveAction.DEFAULT.toString() try { when (removeAction) { @@ -146,22 +182,32 @@ open class BluePrintManagementGRPCHandler(private val bluePrintModelHandler: Blu responseObserver.onNext(successStatus(request.commonHeader)) } else -> { - responseObserver.onNext(failStatus(request.commonHeader, + responseObserver.onNext( + failStatus( + request.commonHeader, "Remove action($removeAction) not implemented", - BluePrintProcessorException("Not implemented"))) + BluePrintProcessorException("Not implemented") + ) + ) } } } catch (e: Exception) { - responseObserver.onNext(failStatus(request.commonHeader, - "request(${request.commonHeader.requestId}): Failed to delete $blueprint", e)) + responseObserver.onNext( + failStatus( + request.commonHeader, + "request(${request.commonHeader.requestId}): Failed to delete $blueprint", e + ) + ) } finally { responseObserver.onCompleted() } } } - override fun bootstrapBlueprint(request: BluePrintBootstrapInput, - responseObserver: StreamObserver<BluePrintManagementOutput>) { + override fun bootstrapBlueprint( + request: BluePrintBootstrapInput, + responseObserver: StreamObserver<BluePrintManagementOutput> + ) { runBlocking { try { log.info("request(${request.commonHeader.requestId}): Received bootstrap request") @@ -173,10 +219,13 @@ open class BluePrintManagementGRPCHandler(private val bluePrintModelHandler: Blu /** 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)) + responseObserver.onNext( + failStatus( + request.commonHeader, + "request(${request.commonHeader.requestId}): Failed to bootstrap", e + ) + ) } finally { responseObserver.onCompleted() } @@ -184,15 +233,17 @@ open class BluePrintManagementGRPCHandler(private val bluePrintModelHandler: Blu } private fun outputWithFileBytes(header: CommonHeader, byteArray: ByteArray): BluePrintManagementOutput = - BluePrintManagementOutput.newBuilder() - .setCommonHeader(header) - .setFileChunk(FileChunk.newBuilder().setChunk(ByteString.copyFrom(byteArray))) - .setStatus(Status.newBuilder() - .setTimestamp(currentTimestamp()) - .setMessage(BluePrintConstants.STATUS_SUCCESS) - .setCode(200) - .build()) + BluePrintManagementOutput.newBuilder() + .setCommonHeader(header) + .setFileChunk(FileChunk.newBuilder().setChunk(ByteString.copyFrom(byteArray))) + .setStatus( + Status.newBuilder() + .setTimestamp(currentTimestamp()) + .setMessage(BluePrintConstants.STATUS_SUCCESS) + .setCode(200) .build() + ) + .build() private fun successStatus(header: CommonHeader, propertyContent: String? = null): BluePrintManagementOutput { // Populate Response Payload @@ -201,30 +252,34 @@ open class BluePrintManagementGRPCHandler(private val bluePrintModelHandler: Blu JsonFormat.parser().merge(propertyContent, propertiesBuilder) } return BluePrintManagementOutput.newBuilder() - .setCommonHeader(header) - .setProperties(propertiesBuilder.build()) - .setStatus(Status.newBuilder() - .setTimestamp(currentTimestamp()) - .setMessage(BluePrintConstants.STATUS_SUCCESS) - .setCode(200) - .build()) - .build() + .setCommonHeader(header) + .setProperties(propertiesBuilder.build()) + .setStatus( + Status.newBuilder() + .setTimestamp(currentTimestamp()) + .setMessage(BluePrintConstants.STATUS_SUCCESS) + .setCode(200) + .build() + ) + .build() } private fun failStatus(header: CommonHeader, message: String, e: Exception): BluePrintManagementOutput { log.error(message, e) return BluePrintManagementOutput.newBuilder() - .setCommonHeader(header) - .setStatus(Status.newBuilder() - .setTimestamp(currentTimestamp()) - .setMessage(BluePrintConstants.STATUS_FAILURE) - .setErrorMessage(message) - .setCode(500) - .build()) - .build() -// return io.grpc.Status.INTERNAL -// .withDescription(message) -// .withCause(e) -// .asException() + .setCommonHeader(header) + .setStatus( + Status.newBuilder() + .setTimestamp(currentTimestamp()) + .setMessage(BluePrintConstants.STATUS_FAILURE) + .setErrorMessage(message) + .setCode(500) + .build() + ) + .build() + // return io.grpc.Status.INTERNAL + // .withDescription(message) + // .withCause(e) + // .asException() } } 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 5ef50b09f..f257157c8 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 @@ -34,7 +34,16 @@ import org.springframework.http.MediaType import org.springframework.http.ResponseEntity import org.springframework.http.codec.multipart.FilePart import org.springframework.security.access.prepost.PreAuthorize -import org.springframework.web.bind.annotation.* +import org.springframework.web.bind.annotation.DeleteMapping +import org.springframework.web.bind.annotation.GetMapping +import org.springframework.web.bind.annotation.PathVariable +import org.springframework.web.bind.annotation.PostMapping +import org.springframework.web.bind.annotation.RequestBody +import org.springframework.web.bind.annotation.RequestMapping +import org.springframework.web.bind.annotation.RequestParam +import org.springframework.web.bind.annotation.RequestPart +import org.springframework.web.bind.annotation.ResponseBody +import org.springframework.web.bind.annotation.RestController import reactor.core.publisher.Mono /** @@ -47,8 +56,10 @@ 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)) + @PostMapping( + path = arrayOf("/bootstrap"), produces = arrayOf(MediaType.APPLICATION_JSON_VALUE), + consumes = arrayOf(MediaType.APPLICATION_JSON_VALUE) + ) @ResponseBody @Throws(BluePrintException::class) @PreAuthorize("hasRole('USER')") @@ -74,9 +85,11 @@ open class BlueprintModelController(private val bluePrintModelHandler: BluePrint @GetMapping("/paged", produces = [MediaType.APPLICATION_JSON_VALUE]) @ResponseBody @PreAuthorize("hasRole('USER')") - fun allBlueprintModel(@RequestParam(defaultValue = "20") limit: Int, - @RequestParam(defaultValue = "0") offset: Int, - @RequestParam(defaultValue = "DATE") sort: BlueprintSortByOption): Page<BlueprintModelSearch> { + fun allBlueprintModel( + @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.allBlueprintModel(pageRequest) } @@ -88,18 +101,17 @@ open class BlueprintModelController(private val bluePrintModelHandler: BluePrint return this.bluePrintModelHandler.searchBluePrintModelsByKeyWord(keyWord) } - @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 + 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}") @@ -113,9 +125,11 @@ open class BlueprintModelController(private val bluePrintModelHandler: BluePrint @ResponseBody @Throws(BluePrintException::class) @PreAuthorize("hasRole('USER')") - fun getBlueprintByNameAndVersion(@PathVariable(value = "name") name: String, - @PathVariable(value = "version") version: String) - : Mono<BlueprintModelSearch> = monoMdc { + fun getBlueprintByNameAndVersion( + @PathVariable(value = "name") name: String, + @PathVariable(value = "version") version: String + ): + Mono<BlueprintModelSearch> = monoMdc { bluePrintModelHandler.getBlueprintModelSearchByNameAndVersion(name, version) } @@ -123,9 +137,11 @@ open class BlueprintModelController(private val bluePrintModelHandler: BluePrint @ResponseBody @Throws(BluePrintException::class) @PreAuthorize("hasRole('USER')") - fun downloadBlueprintByNameAndVersion(@PathVariable(value = "name") name: String, - @PathVariable(value = "version") version: String) - : Mono<ResponseEntity<Resource>> = monoMdc { + fun downloadBlueprintByNameAndVersion( + @PathVariable(value = "name") name: String, + @PathVariable(value = "version") version: String + ): + Mono<ResponseEntity<Resource>> = monoMdc { bluePrintModelHandler.downloadBlueprintModelFileByNameAndVersion(name, version) } @@ -145,8 +161,10 @@ open class BlueprintModelController(private val bluePrintModelHandler: BluePrint bluePrintModelHandler.downloadBlueprintModelFile(id) } - @PostMapping("/enrich", produces = [MediaType.APPLICATION_JSON_VALUE], consumes = [MediaType - .MULTIPART_FORM_DATA_VALUE]) + @PostMapping( + "/enrich", produces = [MediaType.APPLICATION_JSON_VALUE], consumes = [MediaType + .MULTIPART_FORM_DATA_VALUE] + ) @ResponseBody @Throws(BluePrintException::class) @PreAuthorize("hasRole('USER')") @@ -170,14 +188,18 @@ open class BlueprintModelController(private val bluePrintModelHandler: BluePrint } @DeleteMapping("/name/{name}/version/{version}") - @ApiOperation(value = "Delete a CBA", - notes = "Delete the CBA package identified by its name and version.", - produces = MediaType.APPLICATION_JSON_VALUE) + @ApiOperation( + value = "Delete a CBA", + notes = "Delete the CBA package identified by its name and version.", + produces = MediaType.APPLICATION_JSON_VALUE + ) @PreAuthorize("hasRole('USER')") - fun deleteBlueprint(@ApiParam(value = "Name of the CBA.", required = true) - @PathVariable(value = "name") name: String, - @ApiParam(value = "Version of the CBA.", required = true) - @PathVariable(value = "version") version: String) = monoMdc { + fun deleteBlueprint( + @ApiParam(value = "Name of the CBA.", required = true) + @PathVariable(value = "name") name: String, + @ApiParam(value = "Version of the CBA.", required = true) + @PathVariable(value = "version") version: String + ) = monoMdc { bluePrintModelHandler.deleteBlueprintModel(name, version) } } 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 346015bc4..d0cb67315 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 @@ -24,8 +24,7 @@ import com.fasterxml.jackson.annotation.JsonTypeName import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.domain.ResourceDictionary import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceAssignment import java.io.Serializable -import java.util.* - +import java.util.Date class BootstrapRequest { var loadModelType: Boolean = false @@ -40,15 +39,16 @@ class BootstrapRequest { * @version 1.0 */ class AutoMapResponse { + var resourceAssignments: List<ResourceAssignment>? = null var dataDictionaries: List<ResourceDictionary>? = null } - @JsonInclude(JsonInclude.Include.NON_NULL) @JsonTypeName("errorMessage") @JsonTypeInfo(include = JsonTypeInfo.As.WRAPPER_OBJECT, use = JsonTypeInfo.Id.NAME) class ErrorMessage(var message: String?, var code: Int?, var debugMessage: String?) : Serializable { + @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") var timestamp = Date() -}
\ 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/ModelTypeController.kt b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/ModelTypeController.kt index bac281356..adeb3cf89 100644 --- a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/ModelTypeController.kt +++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/ModelTypeController.kt @@ -18,11 +18,18 @@ package org.onap.ccsdk.cds.blueprintsprocessor.designer.api import kotlinx.coroutines.runBlocking +import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.domain.ModelType import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.handler.ModelTypeHandler import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException -import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.domain.ModelType import org.springframework.http.MediaType -import org.springframework.web.bind.annotation.* +import org.springframework.web.bind.annotation.DeleteMapping +import org.springframework.web.bind.annotation.GetMapping +import org.springframework.web.bind.annotation.PathVariable +import org.springframework.web.bind.annotation.PostMapping +import org.springframework.web.bind.annotation.RequestBody +import org.springframework.web.bind.annotation.RequestMapping +import org.springframework.web.bind.annotation.ResponseBody +import org.springframework.web.bind.annotation.RestController @RestController @RequestMapping(value = arrayOf("/api/v1/model-type")) @@ -55,4 +62,4 @@ open class ModelTypeController(private val modelTypeHandler: ModelTypeHandler) { fun deleteModelTypeByName(@PathVariable(value = "name") name: String) = runBlocking { modelTypeHandler.deleteByModelName(name) } -}
\ 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/ResourceDictionaryController.kt b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/ResourceDictionaryController.kt index bae890a87..562932e23 100644 --- a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/ResourceDictionaryController.kt +++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/ResourceDictionaryController.kt @@ -22,7 +22,14 @@ import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.handler.ResourceDicti import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceSourceMapping import org.springframework.http.MediaType -import org.springframework.web.bind.annotation.* +import org.springframework.web.bind.annotation.DeleteMapping +import org.springframework.web.bind.annotation.GetMapping +import org.springframework.web.bind.annotation.PathVariable +import org.springframework.web.bind.annotation.PostMapping +import org.springframework.web.bind.annotation.RequestBody +import org.springframework.web.bind.annotation.RequestMapping +import org.springframework.web.bind.annotation.ResponseBody +import org.springframework.web.bind.annotation.RestController @RestController @RequestMapping(value = ["/api/v1/dictionary"]) @@ -57,7 +64,6 @@ open class ResourceDictionaryController(private val resourceDictionaryHandler: R @ResponseBody fun searchResourceDictionaryByTags(@PathVariable(value = "tags") tags: String): List<ResourceDictionary> = runBlocking { resourceDictionaryHandler.searchResourceDictionaryByTags(tags) - } @GetMapping(path = ["/source-mapping"], produces = [MediaType.APPLICATION_JSON_VALUE]) @@ -65,5 +71,4 @@ open class ResourceDictionaryController(private val resourceDictionaryHandler: R fun getResourceSourceMapping(): ResourceSourceMapping = runBlocking { resourceDictionaryHandler.getResourceSourceMapping() } - } diff --git a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/domain/JpaJsonNodeConverter.kt b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/domain/JpaJsonNodeConverter.kt index 97c7ab6a6..4779ad340 100644 --- a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/domain/JpaJsonNodeConverter.kt +++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/domain/JpaJsonNodeConverter.kt @@ -18,7 +18,6 @@ package org.onap.ccsdk.cds.blueprintsprocessor.designer.api.domain import com.fasterxml.jackson.databind.JsonNode import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils - import javax.persistence.AttributeConverter import javax.persistence.Converter @@ -35,4 +34,4 @@ class JpaJsonNodeConverter : AttributeConverter<JsonNode, String> { override fun convertToEntityAttribute(dbData: String): JsonNode { return JacksonUtils.jsonNode(dbData) } -}
\ 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/domain/JpaResourceDefinitionConverter.kt b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/domain/JpaResourceDefinitionConverter.kt index 75cfede50..f0692cdd9 100644 --- a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/domain/JpaResourceDefinitionConverter.kt +++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/domain/JpaResourceDefinitionConverter.kt @@ -18,7 +18,6 @@ package org.onap.ccsdk.cds.blueprintsprocessor.designer.api.domain import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceDefinition - import javax.persistence.AttributeConverter import javax.persistence.Converter @@ -27,6 +26,7 @@ import javax.persistence.Converter */ @Converter class JpaResourceDefinitionConverter : AttributeConverter<ResourceDefinition, String> { + override fun convertToDatabaseColumn(resourceDefinition: ResourceDefinition): String { return JacksonUtils.getJson(resourceDefinition) } diff --git a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/domain/ModelType.kt b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/domain/ModelType.kt index a964e0416..6e277e5c8 100644 --- a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/domain/ModelType.kt +++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/domain/ModelType.kt @@ -22,8 +22,16 @@ import io.swagger.annotations.ApiModelProperty import org.springframework.data.annotation.LastModifiedDate import org.springframework.data.jpa.domain.support.AuditingEntityListener import java.io.Serializable -import java.util.* -import javax.persistence.* +import java.util.Date +import javax.persistence.Column +import javax.persistence.Convert +import javax.persistence.Entity +import javax.persistence.EntityListeners +import javax.persistence.Id +import javax.persistence.Lob +import javax.persistence.Table +import javax.persistence.Temporal +import javax.persistence.TemporalType /** * Provide ModelType Entity @@ -94,4 +102,4 @@ class ModelType : Serializable { companion object { private const val serialVersionUID = 1L } -}
\ 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/domain/ResourceDictionary.kt b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/domain/ResourceDictionary.kt index ac5ea2070..209e2bbe8 100644 --- a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/domain/ResourceDictionary.kt +++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/domain/ResourceDictionary.kt @@ -22,8 +22,16 @@ import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceDefinition import org.springframework.data.annotation.LastModifiedDate import org.springframework.data.jpa.domain.support.AuditingEntityListener import java.io.Serializable -import java.util.* -import javax.persistence.* +import java.util.Date +import javax.persistence.Column +import javax.persistence.Convert +import javax.persistence.Entity +import javax.persistence.EntityListeners +import javax.persistence.Id +import javax.persistence.Lob +import javax.persistence.Table +import javax.persistence.Temporal +import javax.persistence.TemporalType /** * Provide ResourceDictionary Entity @@ -89,6 +97,4 @@ class ResourceDictionary : Serializable { companion object { private const val serialVersionUID = 1L } - - } diff --git a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/enhancer/BluePrintArtifactDefinitionEnhancerImpl.kt b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/enhancer/BluePrintArtifactDefinitionEnhancerImpl.kt index 552339be9..f954df7ac 100644 --- a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/enhancer/BluePrintArtifactDefinitionEnhancerImpl.kt +++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/enhancer/BluePrintArtifactDefinitionEnhancerImpl.kt @@ -32,22 +32,22 @@ import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceAssignment import org.springframework.stereotype.Service @Service -open class BluePrintArtifactDefinitionEnhancerImpl(private val bluePrintRepoService: BluePrintRepoService, - private val bluePrintTypeEnhancerService: BluePrintTypeEnhancerService, - private val resourceAssignmentEnhancerService: ResourceAssignmentEnhancerService) - : BluePrintArtifactDefinitionEnhancer { +open class BluePrintArtifactDefinitionEnhancerImpl( + private val bluePrintRepoService: BluePrintRepoService, + private val bluePrintTypeEnhancerService: BluePrintTypeEnhancerService, + private val resourceAssignmentEnhancerService: ResourceAssignmentEnhancerService +) : + BluePrintArtifactDefinitionEnhancer { companion object { const val ARTIFACT_TYPE_MAPPING_SOURCE: String = "artifact-mapping-resource" } - private val log = logger(BluePrintArtifactDefinitionEnhancerImpl::class) lateinit var bluePrintRuntimeService: BluePrintRuntimeService<*> lateinit var bluePrintContext: BluePrintContext - override fun enhance(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, artifactDefinition: ArtifactDefinition) { log.info("enhancing ArtifactDefinition($name)") @@ -55,7 +55,7 @@ open class BluePrintArtifactDefinitionEnhancerImpl(private val bluePrintRepoServ this.bluePrintContext = bluePrintRuntimeService.bluePrintContext() val artifactTypeName = artifactDefinition.type - ?: throw BluePrintException("artifact type is missing for ArtifactDefinition($name)") + ?: throw BluePrintException("artifact type is missing for ArtifactDefinition($name)") // Populate Artifact Type BluePrintEnhancerUtils.populateArtifactType(bluePrintContext, bluePrintRepoService, artifactTypeName) @@ -80,7 +80,7 @@ open class BluePrintArtifactDefinitionEnhancerImpl(private val bluePrintRepoServ if (!alreadyEnhanced) { val resourceAssignments: MutableList<ResourceAssignment> = JacksonUtils.getListFromFile(artifactFilePath, ResourceAssignment::class.java) as? MutableList<ResourceAssignment> - ?: throw BluePrintProcessorException("couldn't get ResourceAssignment definitions for the file($artifactFilePath)") + ?: throw BluePrintProcessorException("couldn't get ResourceAssignment definitions for the file($artifactFilePath)") // Call Resource Assignment Enhancer resourceAssignmentEnhancerService.enhanceBluePrint(bluePrintTypeEnhancerService, bluePrintRuntimeService, resourceAssignments) @@ -88,5 +88,4 @@ open class BluePrintArtifactDefinitionEnhancerImpl(private val bluePrintRepoServ bluePrintRuntimeService.put(alreadyEnhancedKey, true.asJsonPrimitive()) } } - -}
\ 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/enhancer/BluePrintAttributeDefinitionEnhancerImpl.kt b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/enhancer/BluePrintAttributeDefinitionEnhancerImpl.kt index 0b64ed503..030fbe8ae 100644 --- a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/enhancer/BluePrintAttributeDefinitionEnhancerImpl.kt +++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/enhancer/BluePrintAttributeDefinitionEnhancerImpl.kt @@ -26,9 +26,11 @@ import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintTypeEnha import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintContext import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintRuntimeService -class BluePrintAttributeDefinitionEnhancerImpl(private val bluePrintRepoService: BluePrintRepoService, - private val bluePrintTypeEnhancerService: BluePrintTypeEnhancerService) - : BluePrintAttributeDefinitionEnhancer { +class BluePrintAttributeDefinitionEnhancerImpl( + private val bluePrintRepoService: BluePrintRepoService, + private val bluePrintTypeEnhancerService: BluePrintTypeEnhancerService +) : + BluePrintAttributeDefinitionEnhancer { lateinit var bluePrintRuntimeService: BluePrintRuntimeService<*> lateinit var bluePrintContext: BluePrintContext @@ -39,10 +41,9 @@ class BluePrintAttributeDefinitionEnhancerImpl(private val bluePrintRepoService: val propertyType = attributeDefinition.type if (BluePrintTypes.validPrimitiveTypes().contains(propertyType)) { - } else if (BluePrintTypes.validCollectionTypes().contains(propertyType)) { val entrySchema = attributeDefinition.entrySchema - ?: throw BluePrintException("Entry Schema is missing for collection property($name)") + ?: throw BluePrintException("Entry Schema is missing for collection property($name)") if (!BluePrintTypes.validPrimitiveTypes().contains(entrySchema.type)) { BluePrintEnhancerUtils.populateDataTypes(bluePrintContext, bluePrintRepoService, entrySchema.type) @@ -51,5 +52,4 @@ class BluePrintAttributeDefinitionEnhancerImpl(private val bluePrintRepoService: BluePrintEnhancerUtils.populateDataTypes(bluePrintContext, bluePrintRepoService, propertyType) } } - -}
\ 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/enhancer/BluePrintEnhancerServiceImpl.kt b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/enhancer/BluePrintEnhancerServiceImpl.kt index b4d149e16..e99f49489 100644 --- a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/enhancer/BluePrintEnhancerServiceImpl.kt +++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/enhancer/BluePrintEnhancerServiceImpl.kt @@ -26,11 +26,13 @@ import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintFileUtils import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintMetadataUtils import org.onap.ccsdk.cds.controllerblueprints.resource.dict.utils.ResourceDictionaryUtils import org.springframework.stereotype.Service -import java.util.* +import java.util.UUID @Service -open class BluePrintEnhancerServiceImpl(private val bluePrintTypeEnhancerService: BluePrintTypeEnhancerService, - private val resourceDefinitionEnhancerService: ResourceDefinitionEnhancerService) : BluePrintEnhancerService { +open class BluePrintEnhancerServiceImpl( + private val bluePrintTypeEnhancerService: BluePrintTypeEnhancerService, + private val resourceDefinitionEnhancerService: ResourceDefinitionEnhancerService +) : BluePrintEnhancerService { private val log = logger(BluePrintEnhancerServiceImpl::class) @@ -48,16 +50,20 @@ open class BluePrintEnhancerServiceImpl(private val bluePrintTypeEnhancerService log.info("Enhancing blueprint($basePath)") val blueprintRuntimeService = BluePrintMetadataUtils - .getBaseEnhancementBluePrintRuntime(UUID.randomUUID().toString(), basePath) + .getBaseEnhancementBluePrintRuntime(UUID.randomUUID().toString(), basePath) try { - bluePrintTypeEnhancerService.enhanceServiceTemplate(blueprintRuntimeService, "service_template", - blueprintRuntimeService.bluePrintContext().serviceTemplate) + bluePrintTypeEnhancerService.enhanceServiceTemplate( + blueprintRuntimeService, "service_template", + blueprintRuntimeService.bluePrintContext().serviceTemplate + ) log.info("##### Enhancing blueprint Resource Definitions") - val resourceDefinitions = resourceDefinitionEnhancerService.enhance(bluePrintTypeEnhancerService, - blueprintRuntimeService) + val resourceDefinitions = resourceDefinitionEnhancerService.enhance( + bluePrintTypeEnhancerService, + blueprintRuntimeService + ) // Write the Enhanced Blueprint Definitions BluePrintFileUtils.writeEnhancedBluePrint(blueprintRuntimeService.bluePrintContext()) @@ -68,12 +74,9 @@ open class BluePrintEnhancerServiceImpl(private val bluePrintTypeEnhancerService if (blueprintRuntimeService.getBluePrintError().errors.isNotEmpty()) { throw BluePrintException(blueprintRuntimeService.getBluePrintError().errors.toString()) } - } catch (e: Exception) { throw e } return blueprintRuntimeService.bluePrintContext() } - } - diff --git a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/enhancer/BluePrintNodeTemplateEnhancerImpl.kt b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/enhancer/BluePrintNodeTemplateEnhancerImpl.kt index 723d7bb27..6ca0b2d14 100644 --- a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/enhancer/BluePrintNodeTemplateEnhancerImpl.kt +++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/enhancer/BluePrintNodeTemplateEnhancerImpl.kt @@ -31,22 +31,22 @@ import org.springframework.stereotype.Service @Service @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) -open class BluePrintNodeTemplateEnhancerImpl(private val bluePrintRepoService: BluePrintRepoService, - private val bluePrintTypeEnhancerService: BluePrintTypeEnhancerService) - : BluePrintNodeTemplateEnhancer { +open class BluePrintNodeTemplateEnhancerImpl( + private val bluePrintRepoService: BluePrintRepoService, + private val bluePrintTypeEnhancerService: BluePrintTypeEnhancerService +) : + BluePrintNodeTemplateEnhancer { - private val log= logger(BluePrintNodeTemplateEnhancerImpl::class) + private val log = logger(BluePrintNodeTemplateEnhancerImpl::class) lateinit var bluePrintRuntimeService: BluePrintRuntimeService<*> lateinit var bluePrintContext: BluePrintContext - override fun enhance(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, nodeTemplate: NodeTemplate) { log.info("***** Enhancing NodeTemplate($name)") this.bluePrintRuntimeService = bluePrintRuntimeService this.bluePrintContext = bluePrintRuntimeService.bluePrintContext() - val nodeTypeName = nodeTemplate.type // Get NodeType from Repo and Update Service Template val nodeType = BluePrintEnhancerUtils.populateNodeType(bluePrintContext, bluePrintRepoService, nodeTypeName) @@ -54,7 +54,7 @@ open class BluePrintNodeTemplateEnhancerImpl(private val bluePrintRepoService: B // Enrich NodeType bluePrintTypeEnhancerService.enhanceNodeType(bluePrintRuntimeService, nodeTypeName, nodeType) - //Enrich Node Template Artifacts + // Enrich Node Template Artifacts enhanceNodeTemplateArtifactDefinition(name, nodeTemplate) } @@ -65,5 +65,4 @@ open class BluePrintNodeTemplateEnhancerImpl(private val bluePrintRepoService: B bluePrintTypeEnhancerService.enhanceArtifactDefinition(bluePrintRuntimeService, artifactDefinitionName, artifactDefinition) } } - -}
\ 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/enhancer/BluePrintNodeTypeEnhancerImpl.kt b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/enhancer/BluePrintNodeTypeEnhancerImpl.kt index efb695b22..d28084e40 100644 --- a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/enhancer/BluePrintNodeTypeEnhancerImpl.kt +++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/enhancer/BluePrintNodeTypeEnhancerImpl.kt @@ -34,20 +34,20 @@ import org.springframework.stereotype.Service @Service @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) -open class BluePrintNodeTypeEnhancerImpl(private val bluePrintRepoService: BluePrintRepoService, - private val bluePrintTypeEnhancerService: BluePrintTypeEnhancerService) : BluePrintNodeTypeEnhancer { +open class BluePrintNodeTypeEnhancerImpl( + private val bluePrintRepoService: BluePrintRepoService, + private val bluePrintTypeEnhancerService: BluePrintTypeEnhancerService +) : BluePrintNodeTypeEnhancer { - private val log= logger(BluePrintNodeTypeEnhancerImpl::class) + private val log = logger(BluePrintNodeTypeEnhancerImpl::class) lateinit var bluePrintRuntimeService: BluePrintRuntimeService<*> lateinit var bluePrintContext: BluePrintContext - override fun enhance(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, nodeType: NodeType) { this.bluePrintRuntimeService = bluePrintRuntimeService this.bluePrintContext = bluePrintRuntimeService.bluePrintContext() - val derivedFrom = nodeType.derivedFrom if (!BluePrintTypes.rootNodeTypes().contains(derivedFrom)) { @@ -62,15 +62,14 @@ open class BluePrintNodeTypeEnhancerImpl(private val bluePrintRepoService: BlueP // NodeType Property Definitions enrichNodeTypeProperties(name, nodeType) - //NodeType Requirement + // NodeType Requirement enrichNodeTypeRequirements(name, nodeType) - //NodeType Capability + // NodeType Capability enrichNodeTypeCapabilityProperties(name, nodeType) - //NodeType Interface + // NodeType Interface enrichNodeTypeInterfaces(name, nodeType) - } open fun enrichNodeTypeAttributes(nodeTypeName: String, nodeType: NodeType) { @@ -91,15 +90,19 @@ open class BluePrintNodeTypeEnhancerImpl(private val bluePrintRepoService: BlueP // Populate Requirement Node requirementDefinition.node?.let { requirementNodeTypeName -> // Get Requirement NodeType from Repo and Update Service Template - val requirementNodeType = BluePrintEnhancerUtils.populateNodeType(bluePrintContext, - bluePrintRepoService, requirementNodeTypeName) + val requirementNodeType = BluePrintEnhancerUtils.populateNodeType( + bluePrintContext, + bluePrintRepoService, requirementNodeTypeName + ) // Enhance Node Type enhance(bluePrintRuntimeService, requirementNodeTypeName, requirementNodeType) // Enhance Relationship Type val relationShipTypeName = requirementDefinition.relationship - ?: throw BluePrintException("couldn't get relationship name for the NodeType($nodeTypeName) " + - "Requirement($requirementName)") + ?: throw BluePrintException( + "couldn't get relationship name for the NodeType($nodeTypeName) " + + "Requirement($requirementName)" + ) enrichRelationShipType(relationShipTypeName) } } @@ -118,7 +121,6 @@ open class BluePrintNodeTypeEnhancerImpl(private val bluePrintRepoService: BlueP // Populate Node type Interface Operation log.debug("Enriching NodeType({}) Interface({})", nodeTypeName, interfaceName) populateNodeTypeInterfaceOperation(nodeTypeName, interfaceName, interfaceObj) - } } @@ -136,8 +138,11 @@ open class BluePrintNodeTypeEnhancerImpl(private val bluePrintRepoService: BlueP } } - open fun enrichNodeTypeInterfaceOperationOutputs(nodeTypeName: String, operationName: String, - operation: OperationDefinition) { + open fun enrichNodeTypeInterfaceOperationOutputs( + nodeTypeName: String, + operationName: String, + operation: OperationDefinition + ) { operation.outputs?.let { inputs -> bluePrintTypeEnhancerService.enhancePropertyDefinitions(bluePrintRuntimeService, inputs) } @@ -149,5 +154,4 @@ open class BluePrintNodeTypeEnhancerImpl(private val bluePrintRepoService: BlueP open fun enrichRelationShipType(relationshipName: String) { BluePrintEnhancerUtils.populateRelationshipType(bluePrintContext, bluePrintRepoService, relationshipName) } - -}
\ 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/enhancer/BluePrintPolicyTypeEnhancerImpl.kt b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/enhancer/BluePrintPolicyTypeEnhancerImpl.kt index 83fd403e8..212dc440d 100644 --- a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/enhancer/BluePrintPolicyTypeEnhancerImpl.kt +++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/enhancer/BluePrintPolicyTypeEnhancerImpl.kt @@ -27,17 +27,18 @@ import org.springframework.stereotype.Service @Service @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) -class BluePrintPolicyTypeEnhancerImpl(private val bluePrintRepoService: BluePrintRepoService, - private val bluePrintTypeEnhancerService: BluePrintTypeEnhancerService) - : BluePrintPolicyTypeEnhancer { +class BluePrintPolicyTypeEnhancerImpl( + private val bluePrintRepoService: BluePrintRepoService, + private val bluePrintTypeEnhancerService: BluePrintTypeEnhancerService +) : + BluePrintPolicyTypeEnhancer { lateinit var bluePrintRuntimeService: BluePrintRuntimeService<*> - override fun enhance(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, type: PolicyType) { - this.bluePrintRuntimeService = bluePrintRuntimeService + this.bluePrintRuntimeService = bluePrintRuntimeService // TODO("not implemented") //To change body of created functions use File | Settings | File Templates. } -}
\ 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/enhancer/BluePrintPropertyDefinitionEnhancerImpl.kt b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/enhancer/BluePrintPropertyDefinitionEnhancerImpl.kt index b87cf9c6b..eb7443443 100644 --- a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/enhancer/BluePrintPropertyDefinitionEnhancerImpl.kt +++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/enhancer/BluePrintPropertyDefinitionEnhancerImpl.kt @@ -32,9 +32,11 @@ import org.springframework.stereotype.Service @Service @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) -open class BluePrintPropertyDefinitionEnhancerImpl(private val bluePrintRepoService: BluePrintRepoService, - private val bluePrintTypeEnhancerService: BluePrintTypeEnhancerService) - : BluePrintPropertyDefinitionEnhancer { +open class BluePrintPropertyDefinitionEnhancerImpl( + private val bluePrintRepoService: BluePrintRepoService, + private val bluePrintTypeEnhancerService: BluePrintTypeEnhancerService +) : + BluePrintPropertyDefinitionEnhancer { lateinit var bluePrintRuntimeService: BluePrintRuntimeService<*> lateinit var bluePrintContext: BluePrintContext @@ -44,12 +46,13 @@ open class BluePrintPropertyDefinitionEnhancerImpl(private val bluePrintRepoServ this.bluePrintContext = bluePrintRuntimeService.bluePrintContext() val propertyType = propertyDefinition.type - if (BluePrintTypes.validPrimitiveTypes().contains(propertyType) - || BluePrintTypes.validComplexTypes().contains(propertyType)) { + if (BluePrintTypes.validPrimitiveTypes().contains(propertyType) || + BluePrintTypes.validComplexTypes().contains(propertyType) + ) { // Do Nothing, } else if (BluePrintTypes.validCollectionTypes().contains(propertyType)) { val entrySchema = propertyDefinition.entrySchema - ?: throw BluePrintException("Entry Schema is missing for collection property($name)") + ?: throw BluePrintException("Entry Schema is missing for collection property($name)") if (!BluePrintTypes.validPrimitiveTypes().contains(entrySchema.type)) { BluePrintEnhancerUtils.populateDataTypes(bluePrintContext, bluePrintRepoService, entrySchema.type) @@ -58,5 +61,4 @@ open class BluePrintPropertyDefinitionEnhancerImpl(private val bluePrintRepoServ BluePrintEnhancerUtils.populateDataTypes(bluePrintContext, bluePrintRepoService, propertyType) } } - -}
\ 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/enhancer/BluePrintServiceTemplateEnhancerImpl.kt b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/enhancer/BluePrintServiceTemplateEnhancerImpl.kt index 65e5ff9e1..9f4a4592a 100644 --- a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/enhancer/BluePrintServiceTemplateEnhancerImpl.kt +++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/enhancer/BluePrintServiceTemplateEnhancerImpl.kt @@ -28,10 +28,10 @@ import org.springframework.stereotype.Service @Service @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) -open class BluePrintServiceTemplateEnhancerImpl(private val bluePrintTypeEnhancerService: BluePrintTypeEnhancerService) - : BluePrintServiceTemplateEnhancer { - private val log = logger(BluePrintServiceTemplateEnhancerImpl::class) +open class BluePrintServiceTemplateEnhancerImpl(private val bluePrintTypeEnhancerService: BluePrintTypeEnhancerService) : + BluePrintServiceTemplateEnhancer { + private val log = logger(BluePrintServiceTemplateEnhancerImpl::class) lateinit var bluePrintRuntimeService: BluePrintRuntimeService<*> lateinit var bluePrintContext: BluePrintContext @@ -57,7 +57,6 @@ open class BluePrintServiceTemplateEnhancerImpl(private val bluePrintTypeEnhance bluePrintContext.serviceTemplate.policyTypes = mutableMapOf() bluePrintContext.serviceTemplate.relationshipTypes = mutableMapOf() log.info("reinitialized all type definitions") - } open fun enhanceTopologyTemplate() { @@ -65,4 +64,4 @@ open class BluePrintServiceTemplateEnhancerImpl(private val bluePrintTypeEnhance bluePrintTypeEnhancerService.enhanceTopologyTemplate(bluePrintRuntimeService, "topology_template", topologyTemplate) } } -}
\ 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/enhancer/BluePrintTopologyTemplateEnhancerImpl.kt b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/enhancer/BluePrintTopologyTemplateEnhancerImpl.kt index c22370c33..c0100fbea 100644 --- a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/enhancer/BluePrintTopologyTemplateEnhancerImpl.kt +++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/enhancer/BluePrintTopologyTemplateEnhancerImpl.kt @@ -27,8 +27,11 @@ import org.springframework.stereotype.Service @Service @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) -open class BluePrintTopologyTemplateEnhancerImpl(private val bluePrintRepoService: BluePrintRepoService, - private val bluePrintTypeEnhancerService: BluePrintTypeEnhancerService) : BluePrintTopologyTemplateEnhancer { +open class BluePrintTopologyTemplateEnhancerImpl( + private val bluePrintRepoService: BluePrintRepoService, + private val bluePrintTypeEnhancerService: BluePrintTypeEnhancerService +) : + BluePrintTopologyTemplateEnhancer { lateinit var bluePrintRuntimeService: BluePrintRuntimeService<*> @@ -57,5 +60,4 @@ open class BluePrintTopologyTemplateEnhancerImpl(private val bluePrintRepoServic bluePrintTypeEnhancerService.enhanceWorkflow(bluePrintRuntimeService, workflowName, workflow) } } - -}
\ 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/enhancer/BluePrintTypeEnhancerServiceImpl.kt b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/enhancer/BluePrintTypeEnhancerServiceImpl.kt index db361a248..5b7c6b2d0 100644 --- a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/enhancer/BluePrintTypeEnhancerServiceImpl.kt +++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/enhancer/BluePrintTypeEnhancerServiceImpl.kt @@ -16,7 +16,16 @@ package org.onap.ccsdk.cds.blueprintsprocessor.designer.api.enhancer -import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.* +import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintArtifactDefinitionEnhancer +import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintAttributeDefinitionEnhancer +import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintNodeTemplateEnhancer +import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintNodeTypeEnhancer +import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintPolicyTypeEnhancer +import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintPropertyDefinitionEnhancer +import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintServiceTemplateEnhancer +import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintTopologyTemplateEnhancer +import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintTypeEnhancerService +import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintWorkflowEnhancer import org.springframework.beans.factory.annotation.Autowired import org.springframework.context.ApplicationContext import org.springframework.stereotype.Service @@ -62,4 +71,4 @@ open class BluePrintTypeEnhancerServiceImpl : BluePrintTypeEnhancerService { override fun getAttributeDefinitionEnhancers(): List<BluePrintAttributeDefinitionEnhancer> { return context.getBeansOfType(BluePrintAttributeDefinitionEnhancer::class.java).map { it.value } } -}
\ 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/enhancer/BluePrintWorkflowEnhancerImpl.kt b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/enhancer/BluePrintWorkflowEnhancerImpl.kt index 394289ced..88127e3ca 100644 --- a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/enhancer/BluePrintWorkflowEnhancerImpl.kt +++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/enhancer/BluePrintWorkflowEnhancerImpl.kt @@ -17,13 +17,17 @@ package org.onap.ccsdk.cds.blueprintsprocessor.designer.api.enhancer -import org.onap.ccsdk.cds.controllerblueprints.core.* +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException +import org.onap.ccsdk.cds.controllerblueprints.core.asJsonPrimitive import org.onap.ccsdk.cds.controllerblueprints.core.data.DataType import org.onap.ccsdk.cds.controllerblueprints.core.data.PropertyDefinition import org.onap.ccsdk.cds.controllerblueprints.core.data.Workflow import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintRepoService import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintTypeEnhancerService import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintWorkflowEnhancer +import org.onap.ccsdk.cds.controllerblueprints.core.logger import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintContext import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintRuntimeService import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils @@ -34,11 +38,14 @@ import org.springframework.stereotype.Service @Service @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) -open class BluePrintWorkflowEnhancerImpl(private val bluePrintRepoService: BluePrintRepoService, - private val bluePrintTypeEnhancerService: BluePrintTypeEnhancerService, - private val resourceAssignmentEnhancerService: ResourceAssignmentEnhancerService) - : BluePrintWorkflowEnhancer { - private val log= logger(BluePrintWorkflowEnhancerImpl::class) +open class BluePrintWorkflowEnhancerImpl( + private val bluePrintRepoService: BluePrintRepoService, + private val bluePrintTypeEnhancerService: BluePrintTypeEnhancerService, + private val resourceAssignmentEnhancerService: ResourceAssignmentEnhancerService +) : + BluePrintWorkflowEnhancer { + + private val log = logger(BluePrintWorkflowEnhancerImpl::class) companion object { const val ARTIFACT_TYPE_MAPPING_SOURCE: String = "artifact-mapping-resource" @@ -70,8 +77,6 @@ open class BluePrintWorkflowEnhancerImpl(private val bluePrintRepoService: BlueP // Enrich Only for Resource Assignment and Dynamic Input Properties if any enhanceStepTargets(name, workflow) - - } open fun enhanceWorkflowInputs(name: String, workflow: Workflow) { @@ -102,11 +107,12 @@ open class BluePrintWorkflowEnhancerImpl(private val bluePrintRepoService: BlueP enhanceStepTargets(name, workflow, firstNodeTemplateName, true) } else -> { - throw BluePrintProcessorException("couldn't execute workflow($name) step mapped " + - "to node template($firstNodeTemplateName) derived from($derivedFrom)") + throw BluePrintProcessorException( + "couldn't execute workflow($name) step mapped " + + "to node template($firstNodeTemplateName) derived from($derivedFrom)" + ) } } - } private fun enhanceStepTargets(name: String, workflow: Workflow, nodeTemplateName: String, isDG: Boolean) { @@ -132,10 +138,10 @@ open class BluePrintWorkflowEnhancerImpl(private val bluePrintRepoService: BlueP log.info("identified workflow($name) targets($componentNodeTemplateName)") val resourceAssignmentArtifacts = bluePrintContext.nodeTemplateByName(componentNodeTemplateName) - .artifacts?.filter { + .artifacts?.filter { it.value.type == ARTIFACT_TYPE_MAPPING_SOURCE }?.map { - log.info("resource assignment artifacts(${it.key}) for NodeType(${componentNodeTemplateName})") + log.info("resource assignment artifacts(${it.key}) for NodeType($componentNodeTemplateName)") it.value.file } resourceAssignmentArtifacts @@ -162,13 +168,13 @@ open class BluePrintWorkflowEnhancerImpl(private val bluePrintRepoService: BlueP val filePath = "${bluePrintContext.rootPath}/$fileName" - log.info("enriching artifacts file(${filePath}") + log.info("enriching artifacts file($filePath") val resourceAssignmentProperties: MutableMap<String, PropertyDefinition> = hashMapOf() val resourceAssignments: MutableList<ResourceAssignment> = JacksonUtils.getListFromFile(filePath, ResourceAssignment::class.java) as? MutableList<ResourceAssignment> - ?: throw BluePrintProcessorException("couldn't get ResourceAssignment definitions for the file($filePath)") + ?: throw BluePrintProcessorException("couldn't get ResourceAssignment definitions for the file($filePath)") val alreadyEnhancedKey = "enhanced-$fileName" val alreadyEnhanced = bluePrintRuntimeService.check(alreadyEnhancedKey) @@ -215,7 +221,6 @@ open class BluePrintWorkflowEnhancerImpl(private val bluePrintRepoService: BlueP // Overwrite WorkFlow DataType bluePrintContext.serviceTemplate.dataTypes?.put(dataTypeName, dynamicDataType) - } else { log.info("dynamic dataType($dataTypeName) already present for workflow($workflowName).") } @@ -224,4 +229,4 @@ open class BluePrintWorkflowEnhancerImpl(private val bluePrintRepoService: BlueP dynamicDataType.properties?.put(propertyName, propertyDefinition) } } -}
\ 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/enhancer/ResourceAssignmentEnhancerService.kt b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/enhancer/ResourceAssignmentEnhancerService.kt index 55eb42f89..94e183405 100644 --- a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/enhancer/ResourceAssignmentEnhancerService.kt +++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/enhancer/ResourceAssignmentEnhancerService.kt @@ -16,6 +16,7 @@ package org.onap.ccsdk.cds.blueprintsprocessor.designer.api.enhancer +import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.service.ResourceDefinitionRepoService import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintTypes import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintTypeEnhancerService @@ -25,7 +26,6 @@ import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceAssignment import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceDefinition import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceDictionaryConstants import org.onap.ccsdk.cds.controllerblueprints.resource.dict.factory.ResourceSourceMappingFactory -import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.service.ResourceDefinitionRepoService import org.springframework.beans.factory.config.ConfigurableBeanFactory import org.springframework.context.annotation.Scope import org.springframework.stereotype.Service @@ -38,9 +38,11 @@ import org.springframework.stereotype.Service interface ResourceAssignmentEnhancerService { @Throws(BluePrintException::class) - fun enhanceBluePrint(bluePrintTypeEnhancerService: BluePrintTypeEnhancerService, - bluePrintRuntimeService: BluePrintRuntimeService<*>, - resourceAssignments: List<ResourceAssignment>) + fun enhanceBluePrint( + bluePrintTypeEnhancerService: BluePrintTypeEnhancerService, + bluePrintRuntimeService: BluePrintRuntimeService<*>, + resourceAssignments: List<ResourceAssignment> + ) } /** @@ -50,17 +52,20 @@ interface ResourceAssignmentEnhancerService { */ @Service @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) -open class ResourceAssignmentEnhancerServiceImpl(private val resourceDefinitionRepoService: ResourceDefinitionRepoService) - : ResourceAssignmentEnhancerService { - private val log= logger(ResourceAssignmentEnhancerServiceImpl::class) +open class ResourceAssignmentEnhancerServiceImpl(private val resourceDefinitionRepoService: ResourceDefinitionRepoService) : + ResourceAssignmentEnhancerService { + + private val log = logger(ResourceAssignmentEnhancerServiceImpl::class) /** * Get the defined source instance from the ResourceAssignment, * then get the NodeType of the Sources assigned */ - override fun enhanceBluePrint(bluePrintTypeEnhancerService: BluePrintTypeEnhancerService, - bluePrintRuntimeService: BluePrintRuntimeService<*>, - resourceAssignments: List<ResourceAssignment>) { + override fun enhanceBluePrint( + bluePrintTypeEnhancerService: BluePrintTypeEnhancerService, + bluePrintRuntimeService: BluePrintRuntimeService<*>, + resourceAssignments: List<ResourceAssignment> + ) { val uniqueSourceNodeTypeNames = hashSetOf<String>() @@ -77,14 +82,16 @@ open class ResourceAssignmentEnhancerServiceImpl(private val resourceDefinitionR // TODO("Candidate for Optimisation") if (checkResourceDefinitionNeeded(resourceAssignment)) { - bluePrintTypeEnhancerService.enhancePropertyDefinition(bluePrintRuntimeService, resourceAssignment.name, - resourceAssignment.property!!); + bluePrintTypeEnhancerService.enhancePropertyDefinition( + bluePrintRuntimeService, resourceAssignment.name, + resourceAssignment.property!! + ) // Get the Resource Definition from Repo val resourceDefinition: ResourceDefinition = getResourceDefinition(dictionaryName) val sourceNodeTemplate = resourceDefinition.sources[dictionarySource] - ?: throw BluePrintException("failed to get assigned dictionarySource($dictionarySource) from resourceDefinition($dictionaryName)") + ?: throw BluePrintException("failed to get assigned dictionarySource($dictionarySource) from resourceDefinition($dictionaryName)") // Enrich as NodeTemplate bluePrintTypeEnhancerService.enhanceNodeTemplate(bluePrintRuntimeService, dictionarySource, sourceNodeTemplate) @@ -95,16 +102,15 @@ open class ResourceAssignmentEnhancerServiceImpl(private val resourceDefinitionR val nodeType = resourceDefinitionRepoService.getNodeType(nodeTypeName) bluePrintTypeEnhancerService.enhanceNodeType(bluePrintRuntimeService, nodeTypeName, nodeType) } - } private fun checkResourceDefinitionNeeded(resourceAssignment: ResourceAssignment): Boolean { - return !((resourceAssignment.dictionarySource.equals(ResourceDictionaryConstants.SOURCE_INPUT) - || resourceAssignment.dictionarySource.equals(ResourceDictionaryConstants.SOURCE_DEFAULT)) - && BluePrintTypes.validPrimitiveOrCollectionPrimitive(resourceAssignment.property!!)) + return !((resourceAssignment.dictionarySource.equals(ResourceDictionaryConstants.SOURCE_INPUT) || + resourceAssignment.dictionarySource.equals(ResourceDictionaryConstants.SOURCE_DEFAULT)) && + BluePrintTypes.validPrimitiveOrCollectionPrimitive(resourceAssignment.property!!)) } private fun getResourceDefinition(name: String): ResourceDefinition { return resourceDefinitionRepoService.getResourceDefinition(name) } -}
\ 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/enhancer/ResourceDefinitionEnhancerService.kt b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/enhancer/ResourceDefinitionEnhancerService.kt index c018664e4..042c76805 100644 --- a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/enhancer/ResourceDefinitionEnhancerService.kt +++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/enhancer/ResourceDefinitionEnhancerService.kt @@ -20,6 +20,8 @@ package org.onap.ccsdk.cds.blueprintsprocessor.designer.api.enhancer import kotlinx.coroutines.Deferred import kotlinx.coroutines.async import kotlinx.coroutines.runBlocking +import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.service.ResourceDefinitionRepoService +import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.utils.BluePrintEnhancerUtils import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintTypeEnhancerService import org.onap.ccsdk.cds.controllerblueprints.core.logger @@ -28,20 +30,20 @@ import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintRuntimeServ import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceAssignment import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceDefinition import org.onap.ccsdk.cds.controllerblueprints.resource.dict.utils.ResourceDictionaryUtils -import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.service.ResourceDefinitionRepoService -import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.utils.BluePrintEnhancerUtils import org.springframework.stereotype.Service interface ResourceDefinitionEnhancerService { @Throws(BluePrintException::class) - fun enhance(bluePrintTypeEnhancerService: BluePrintTypeEnhancerService, - bluePrintRuntimeService: BluePrintRuntimeService<*>): List<ResourceDefinition> + fun enhance( + bluePrintTypeEnhancerService: BluePrintTypeEnhancerService, + bluePrintRuntimeService: BluePrintRuntimeService<*> + ): List<ResourceDefinition> } @Service class ResourceDefinitionEnhancerServiceImpl(private val resourceDefinitionRepoService: ResourceDefinitionRepoService) : - ResourceDefinitionEnhancerService { + ResourceDefinitionEnhancerService { private val log = logger(ResourceDefinitionEnhancerService::class) @@ -54,8 +56,10 @@ class ResourceDefinitionEnhancerServiceImpl(private val resourceDefinitionRepoSe // 2. Get all the Unique Resource assignments from all mapping files // 3. Collect the Resource Definition for Resource Assignment names from database. // 4. Create the Resource Definition under blueprint base path. - override fun enhance(bluePrintTypeEnhancerService: BluePrintTypeEnhancerService, - bluePrintRuntimeService: BluePrintRuntimeService<*>): List<ResourceDefinition> { + override fun enhance( + bluePrintTypeEnhancerService: BluePrintTypeEnhancerService, + bluePrintRuntimeService: BluePrintRuntimeService<*> + ): List<ResourceDefinition> { var resourceDefinitions: List<ResourceDefinition> = mutableListOf() @@ -82,7 +86,6 @@ class ResourceDefinitionEnhancerServiceImpl(private val resourceDefinitionRepoSe }?.mapNotNull { artifactDefinitionMap -> artifactDefinitionMap.value.file } - }?.flatten()?.distinct() } @@ -104,33 +107,34 @@ class ResourceDefinitionEnhancerServiceImpl(private val resourceDefinitionRepoSe val distinctResourceAssignments = resourceAssignments.distinctBy { it.name } generateResourceDictionary(blueprintBasePath, distinctResourceAssignments) - //log.info("distinct Resource assignment ($distinctResourceAssignments)") + // log.info("distinct Resource assignment ($distinctResourceAssignments)") } - // Read the Resource Definitions from the Database and write to type file. - private fun generateResourceDictionary(blueprintBasePath: String, resourceAssignments: List<ResourceAssignment>) - : List<ResourceDefinition> { + private fun generateResourceDictionary(blueprintBasePath: String, resourceAssignments: List<ResourceAssignment>): + List<ResourceDefinition> { val resourceKeys = resourceAssignments.mapNotNull { it.dictionaryName }.distinct().sorted() log.info("distinct resource keys ($resourceKeys)") - //TODO("Optimise DB single Query to multiple Query") + // TODO("Optimise DB single Query to multiple Query") return resourceKeys.map { resourceKey -> getResourceDefinition(resourceKey) } } - private fun enrichResourceDefinitionSources(bluePrintContext: BluePrintContext, - resourceDefinitions: List<ResourceDefinition>) { + private fun enrichResourceDefinitionSources( + bluePrintContext: BluePrintContext, + resourceDefinitions: List<ResourceDefinition> + ) { val sources = resourceDefinitions - .map { it.sources } - .map { - it.values - .map { nodeTemplate -> - nodeTemplate.type - } - } - .flatten().distinct() + .map { it.sources } + .map { + it.values + .map { nodeTemplate -> + nodeTemplate.type + } + } + .flatten().distinct() log.info("Enriching Resource Definition sources Node Template: $sources") sources.forEach { BluePrintEnhancerUtils.populateNodeType(bluePrintContext, resourceDefinitionRepoService, it) @@ -141,4 +145,4 @@ class ResourceDefinitionEnhancerServiceImpl(private val resourceDefinitionRepoSe private fun getResourceDefinition(name: String): ResourceDefinition { return resourceDefinitionRepoService.getResourceDefinition(name) } -}
\ 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/handler/BluePrintModelHandler.kt b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/handler/BluePrintModelHandler.kt index 5f7eacee8..392fa0bb4 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 @@ -27,11 +27,15 @@ import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.repository.BlueprintMod 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.BluePrintException import org.onap.ccsdk.cds.controllerblueprints.core.config.BluePrintLoadConfiguration import org.onap.ccsdk.cds.controllerblueprints.core.data.ErrorCode +import org.onap.ccsdk.cds.controllerblueprints.core.deleteNBDir import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintCatalogService import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintEnhancerService +import org.onap.ccsdk.cds.controllerblueprints.core.logger +import org.onap.ccsdk.cds.controllerblueprints.core.normalizedFile +import org.onap.ccsdk.cds.controllerblueprints.core.normalizedPathName import org.onap.ccsdk.cds.controllerblueprints.core.scripts.BluePrintCompileCache import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintFileUtils import org.springframework.core.io.ByteArrayResource @@ -46,8 +50,7 @@ import org.springframework.http.codec.multipart.FilePart import org.springframework.stereotype.Service import org.springframework.transaction.annotation.Transactional import java.io.IOException -import java.util.* - +import java.util.UUID /** * BlueprintModelHandler Purpose: Handler service to handle the request from BlurPrintModelRest @@ -57,21 +60,24 @@ import java.util.* */ @Service -open class BluePrintModelHandler(private val bluePrintDatabaseLoadService: BluePrintDatabaseLoadService, - private val blueprintsProcessorCatalogService: BluePrintCatalogService, - private val bluePrintLoadConfiguration: BluePrintLoadConfiguration, - private val blueprintModelSearchRepository: BlueprintModelSearchRepository, - private val blueprintModelRepository: BlueprintModelRepository, - private val blueprintModelContentRepository: BlueprintModelContentRepository, - private val bluePrintEnhancerService: BluePrintEnhancerService) { +open class BluePrintModelHandler( + private val bluePrintDatabaseLoadService: BluePrintDatabaseLoadService, + private val blueprintsProcessorCatalogService: BluePrintCatalogService, + private val bluePrintLoadConfiguration: BluePrintLoadConfiguration, + private val blueprintModelSearchRepository: BlueprintModelSearchRepository, + private val blueprintModelRepository: BlueprintModelRepository, + private val blueprintModelContentRepository: BlueprintModelContentRepository, + private val bluePrintEnhancerService: BluePrintEnhancerService +) { 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})") + log.info( + "Bootstrap request with type load(${bootstrapRequest.loadModelType}), " + + "resource dictionary load(${bootstrapRequest.loadResourceDictionary}) and " + + "cba load(${bootstrapRequest.loadCBA})" + ) if (bootstrapRequest.loadModelType) { bluePrintDatabaseLoadService.initModelTypes() } @@ -113,12 +119,13 @@ open class BluePrintModelHandler(private val bluePrintDatabaseLoadService: BlueP try { return upload(filePart, false) } catch (e: IOException) { - throw BluePrintException(ErrorCode.IO_FILE_INTERRUPT.value, - "Error in Save CBA: ${e.message}", e) + throw BluePrintException( + ErrorCode.IO_FILE_INTERRUPT.value, + "Error in Save CBA: ${e.message}", e + ) } } - /** * This is a searchBlueprintModels method * @@ -140,9 +147,10 @@ open class BluePrintModelHandler(private val bluePrintDatabaseLoadService: BlueP @Throws(BluePrintException::class) open fun getBlueprintModelSearchByNameAndVersion(name: String, version: String): BlueprintModelSearch { return blueprintModelSearchRepository.findByArtifactNameAndArtifactVersion(name, version) - ?: throw BluePrintException(ErrorCode.RESOURCE_NOT_FOUND.value, - String.format(BLUEPRINT_MODEL_NAME_VERSION_FAILURE_MSG, name, version)) - + ?: throw BluePrintException( + ErrorCode.RESOURCE_NOT_FOUND.value, + String.format(BLUEPRINT_MODEL_NAME_VERSION_FAILURE_MSG, name, version) + ) } /** @@ -154,15 +162,19 @@ open class BluePrintModelHandler(private val bluePrintDatabaseLoadService: BlueP * @throws BluePrintException BluePrintException </Resource> */ @Throws(BluePrintException::class) - open fun downloadBlueprintModelFileByNameAndVersion(name: String, - version: String): ResponseEntity<Resource> { + open fun downloadBlueprintModelFileByNameAndVersion( + name: String, + version: String + ): ResponseEntity<Resource> { try { val archiveByteArray = download(name, version) val fileName = "${name}_$version.zip" return prepareResourceEntity(fileName, archiveByteArray) } catch (e: BluePrintException) { - throw BluePrintException(ErrorCode.RESOURCE_NOT_FOUND.value, - String.format("Error while " + "downloading the CBA file: %s", e.message), e) + throw BluePrintException( + ErrorCode.RESOURCE_NOT_FOUND.value, + String.format("Error while " + "downloading the CBA file: %s", e.message), e + ) } } @@ -183,8 +195,10 @@ open class BluePrintModelHandler(private val bluePrintDatabaseLoadService: BlueP val fileName = "${blueprintModel.artifactName}_${blueprintModel.artifactVersion}.zip" val file = blueprintModel.blueprintModelContent?.content - ?: throw BluePrintException(ErrorCode.RESOURCE_NOT_FOUND.value, - String.format("Error while downloading the CBA file: couldn't get model content")) + ?: throw BluePrintException( + ErrorCode.RESOURCE_NOT_FOUND.value, + String.format("Error while downloading the CBA file: couldn't get model content") + ) return prepareResourceEntity(fileName, file) } @@ -193,9 +207,9 @@ open class BluePrintModelHandler(private val bluePrintDatabaseLoadService: BlueP </Resource> */ private fun prepareResourceEntity(fileName: String, file: ByteArray): ResponseEntity<Resource> { return ResponseEntity.ok() - .contentType(MediaType.parseMediaType("text/plain")) - .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"$fileName\"") - .body(ByteArrayResource(file)) + .contentType(MediaType.parseMediaType("text/plain")) + .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"$fileName\"") + .body(ByteArrayResource(file)) } /** @@ -229,7 +243,7 @@ open class BluePrintModelHandler(private val bluePrintDatabaseLoadService: BlueP @Throws(BluePrintException::class) open fun getBlueprintModelByNameAndVersion(name: String, version: String): BlueprintModel { val blueprintModel = blueprintModelRepository - .findByArtifactNameAndArtifactVersion(name, version) + .findByArtifactNameAndArtifactVersion(name, version) if (blueprintModel != null) { return blueprintModel } else { @@ -248,8 +262,10 @@ open class BluePrintModelHandler(private val bluePrintDatabaseLoadService: BlueP @Throws(BluePrintException::class) open fun getBlueprintModelSearch(id: String): BlueprintModelSearch { return blueprintModelSearchRepository.findById(id) - ?: throw BluePrintException(ErrorCode.RESOURCE_NOT_FOUND.value, - String.format(BLUEPRINT_MODEL_ID_FAILURE_MSG, id)) + ?: throw BluePrintException( + ErrorCode.RESOURCE_NOT_FOUND.value, + String.format(BLUEPRINT_MODEL_ID_FAILURE_MSG, id) + ) } /** @@ -262,10 +278,10 @@ open class BluePrintModelHandler(private val bluePrintDatabaseLoadService: BlueP </BlueprintModelSearch> */ open fun searchBluePrintModelsByKeyWord(keyWord: String): List<BlueprintModelSearch> { return blueprintModelSearchRepository.findByUpdatedByOrTagsOrOrArtifactNameOrOrArtifactVersionOrArtifactType( - keyWord, keyWord, keyWord, keyWord, keyWord) + 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 @@ -275,7 +291,14 @@ open class BluePrintModelHandler(private val bluePrintDatabaseLoadService: BlueP * @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) + return blueprintModelSearchRepository.findByUpdatedByOrTagsOrOrArtifactNameOrOrArtifactVersionOrArtifactType( + keyWord, + keyWord, + keyWord, + keyWord, + keyWord, + pageRequest + ) } /** @@ -319,8 +342,10 @@ open class BluePrintModelHandler(private val bluePrintDatabaseLoadService: BlueP val enhancedByteArray = enrichBlueprintFileSource(filePart) return BluePrintEnhancerUtils.prepareResourceEntity("enhanced-cba.zip", enhancedByteArray) } catch (e: IOException) { - throw BluePrintException(ErrorCode.IO_FILE_INTERRUPT.value, - "Error in Enriching CBA: ${e.message}", e) + throw BluePrintException( + ErrorCode.IO_FILE_INTERRUPT.value, + "Error in Enriching CBA: ${e.message}", e + ) } } @@ -336,8 +361,10 @@ open class BluePrintModelHandler(private val bluePrintDatabaseLoadService: BlueP try { return upload(filePart, true) } catch (e: Exception) { - throw BluePrintException(ErrorCode.IO_FILE_INTERRUPT.value, - "Error in Publishing CBA: ${e.message}", e) + throw BluePrintException( + ErrorCode.IO_FILE_INTERRUPT.value, + "Error in Publishing CBA: ${e.message}", e + ) } } @@ -357,16 +384,19 @@ open class BluePrintModelHandler(private val bluePrintDatabaseLoadService: BlueP val blueprintId = blueprintsProcessorCatalogService.saveToDatabase(saveId, compressedFile, validate) return blueprintModelSearchRepository.findById(blueprintId) - ?: throw BluePrintException(ErrorCode.RESOURCE_NOT_FOUND.value, - String.format(BLUEPRINT_MODEL_ID_FAILURE_MSG, blueprintId)) - + ?: throw BluePrintException( + ErrorCode.RESOURCE_NOT_FOUND.value, + String.format(BLUEPRINT_MODEL_ID_FAILURE_MSG, blueprintId) + ) } catch (e: IOException) { - throw BluePrintException(ErrorCode.IO_FILE_INTERRUPT.value, - "Error in Upload CBA: ${e.message}", e) + throw BluePrintException( + ErrorCode.IO_FILE_INTERRUPT.value, + "Error in Upload CBA: ${e.message}", e + ) } finally { // Clean blueprint script cache val cacheKey = BluePrintFileUtils - .compileCacheKey(normalizedPathName(bluePrintLoadConfiguration.blueprintWorkingPath, saveId)) + .compileCacheKey(normalizedPathName(bluePrintLoadConfiguration.blueprintWorkingPath, saveId)) BluePrintCompileCache.cleanClassLoader(cacheKey) deleteNBDir(blueprintArchive) deleteNBDir(blueprintWorking) @@ -379,11 +409,15 @@ open class BluePrintModelHandler(private val bluePrintDatabaseLoadService: BlueP try { val blueprintModel = getBlueprintModelByNameAndVersion(name, version) return blueprintModel.blueprintModelContent?.content - ?: throw BluePrintException(ErrorCode.RESOURCE_NOT_FOUND.value, - String.format("Error while downloading the CBA file: couldn't get model content")) + ?: throw BluePrintException( + ErrorCode.RESOURCE_NOT_FOUND.value, + String.format("Error while downloading the CBA file: couldn't get model content") + ) } catch (e: BluePrintException) { - throw BluePrintException(ErrorCode.RESOURCE_NOT_FOUND.value, - String.format("Error while " + "downloading the CBA file: %s", e.message), e) + throw BluePrintException( + ErrorCode.RESOURCE_NOT_FOUND.value, + String.format("Error while " + "downloading the CBA file: %s", e.message), e + ) } } @@ -396,17 +430,18 @@ open class BluePrintModelHandler(private val bluePrintDatabaseLoadService: BlueP try { when (fileSource) { is FilePart -> BluePrintEnhancerUtils - .copyFilePartToEnhanceDir(fileSource, blueprintArchive, blueprintWorkingDir) + .copyFilePartToEnhanceDir(fileSource, blueprintArchive, blueprintWorkingDir) is ByteArray -> BluePrintEnhancerUtils - .copyByteArrayToEnhanceDir(fileSource, blueprintArchive, blueprintWorkingDir) - } // Enhance the Blue Prints + .copyByteArrayToEnhanceDir(fileSource, blueprintArchive, blueprintWorkingDir) + } // Enhance the Blue Prints bluePrintEnhancerService.enhance(blueprintWorkingDir) return BluePrintEnhancerUtils.compressEnhanceDirAndReturnByteArray(blueprintWorkingDir, blueprintArchive) - } catch (e: IOException) { - throw BluePrintException(ErrorCode.IO_FILE_INTERRUPT.value, - "Error in Enriching CBA: ${e.message}", e) + throw BluePrintException( + ErrorCode.IO_FILE_INTERRUPT.value, + "Error in Enriching CBA: ${e.message}", e + ) } finally { BluePrintEnhancerUtils.cleanEnhancer(blueprintArchive, blueprintWorkingDir) } diff --git a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/handler/ModelTypeHandler.kt b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/handler/ModelTypeHandler.kt index 5c7ba275d..a364f3678 100644 --- a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/handler/ModelTypeHandler.kt +++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/handler/ModelTypeHandler.kt @@ -17,10 +17,10 @@ package org.onap.ccsdk.cds.blueprintsprocessor.designer.api.handler +import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.domain.ModelType import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.repository.ModelTypeRepository import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.utils.ModelTypeValidator import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException -import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.domain.ModelType import org.slf4j.LoggerFactory import org.springframework.stereotype.Service @@ -46,7 +46,6 @@ open class ModelTypeHandler(private val modelTypeRepository: ModelTypeRepository } } - /** * This is a searchModelTypes service * @@ -66,7 +65,7 @@ open class ModelTypeHandler(private val modelTypeRepository: ModelTypeRepository * @throws BluePrintException BluePrintException */ @Throws(BluePrintException::class) - suspend open fun saveModel(modelType: ModelType): ModelType { + open suspend fun saveModel(modelType: ModelType): ModelType { lateinit var dbModel: ModelType ModelTypeValidator.validateModelType(modelType) val dbModelType: ModelType? = modelTypeRepository.findByModelName(modelType.modelName) @@ -86,16 +85,14 @@ open class ModelTypeHandler(private val modelTypeRepository: ModelTypeRepository return dbModel } - /** * This is a deleteByModelName service * * @param modelName modelName */ - suspend open fun deleteByModelName(modelName: String) { + open suspend fun deleteByModelName(modelName: String) { check(modelName.isNotBlank()) { "Model Name Information is missing." } modelTypeRepository.deleteByModelName(modelName) - } /** @@ -119,4 +116,4 @@ open class ModelTypeHandler(private val modelTypeRepository: ModelTypeRepository check(derivedFrom.isNotBlank()) { "Model derivedFrom Information is missing." } return modelTypeRepository.findByDerivedFrom(derivedFrom) } -}
\ 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/handler/ResourceDictionaryHandler.kt b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/handler/ResourceDictionaryHandler.kt index 8ba4c7b38..af40f56ed 100644 --- a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/handler/ResourceDictionaryHandler.kt +++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/handler/ResourceDictionaryHandler.kt @@ -31,7 +31,6 @@ import org.springframework.stereotype.Service @Service class ResourceDictionaryHandler(private val resourceDictionaryRepository: ResourceDictionaryRepository) { - /** * This is a getDataDictionaryByName service * @@ -85,8 +84,8 @@ class ResourceDictionaryHandler(private val resourceDictionaryRepository: Resour val resourceDefinition = resourceDictionary.definition Preconditions.checkNotNull(resourceDefinition, "failed to get resource definition from content") // Validate the Resource Definitions - //TODO( Save Validator) - //validate(resourceDefinition) + // TODO( Save Validator) + // validate(resourceDefinition) resourceDictionary.tags = resourceDefinition.tags!! resourceDefinition.updatedBy = resourceDictionary.updatedBy @@ -137,11 +136,11 @@ class ResourceDictionaryHandler(private val resourceDictionaryRepository: Resour } private fun validateResourceDictionary(resourceDictionary: ResourceDictionary): Boolean { - checkNotEmpty(resourceDictionary.name){ "DataDictionary Definition name is missing."} + checkNotEmpty(resourceDictionary.name) { "DataDictionary Definition name is missing." } checkNotNull(resourceDictionary.definition) { "DataDictionary Definition Information is missing." } - checkNotEmpty(resourceDictionary.description){ "DataDictionary Definition Information is missing."} - checkNotEmpty(resourceDictionary.tags){ "DataDictionary Definition tags is missing."} - checkNotEmpty(resourceDictionary.updatedBy){ "DataDictionary Definition updatedBy is missing."} + checkNotEmpty(resourceDictionary.description) { "DataDictionary Definition Information is missing." } + checkNotEmpty(resourceDictionary.tags) { "DataDictionary Definition tags is missing." } + checkNotEmpty(resourceDictionary.updatedBy) { "DataDictionary Definition updatedBy is missing." } return true } -}
\ 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/load/BluePrintCatalogLoadService.kt b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/load/BluePrintCatalogLoadService.kt index 36df06909..8d209449c 100644 --- a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/load/BluePrintCatalogLoadService.kt +++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/load/BluePrintCatalogLoadService.kt @@ -25,7 +25,7 @@ import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintCatalogS import org.slf4j.LoggerFactory import org.springframework.stereotype.Service import java.io.File -import java.util.* +import java.util.UUID @Service open class BluePrintCatalogLoadService(private val controllerBlueprintsCatalogService: BluePrintCatalogService) { @@ -66,5 +66,4 @@ open class BluePrintCatalogLoadService(private val controllerBlueprintsCatalogSe errorBuilder.appendln("Couldn't load BlueprintModel(${file.name}: ${e.message}") } } - -}
\ 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/load/BluePrintDatabaseLoadService.kt b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/load/BluePrintDatabaseLoadService.kt index 31bd2c953..02d6ad3c1 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 @@ -23,10 +23,12 @@ import org.slf4j.LoggerFactory import org.springframework.stereotype.Service @Service -open class BluePrintDatabaseLoadService(private val bluePrintLoadConfiguration: BluePrintLoadConfiguration, - private val modelTypeLoadService: ModelTypeLoadService, - private val resourceDictionaryLoadService: ResourceDictionaryLoadService, - private val bluePrintCatalogLoadService: BluePrintCatalogLoadService) { +open class BluePrintDatabaseLoadService( + private val bluePrintLoadConfiguration: BluePrintLoadConfiguration, + private val modelTypeLoadService: ModelTypeLoadService, + private val resourceDictionaryLoadService: ResourceDictionaryLoadService, + private val bluePrintCatalogLoadService: BluePrintCatalogLoadService +) { private val log = LoggerFactory.getLogger(BluePrintDatabaseLoadService::class.java) @@ -62,4 +64,4 @@ open class BluePrintDatabaseLoadService(private val bluePrintLoadConfiguration: bluePrintCatalogLoadService.loadPathsBluePrintModelCatalog(paths) } } -}
\ 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/load/ModelTypeLoadService.kt b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/load/ModelTypeLoadService.kt index 9f43740aa..e96daf9f0 100644 --- a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/load/ModelTypeLoadService.kt +++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/load/ModelTypeLoadService.kt @@ -26,7 +26,11 @@ import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.domain.ModelType import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.handler.ModelTypeHandler import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException -import org.onap.ccsdk.cds.controllerblueprints.core.data.* +import org.onap.ccsdk.cds.controllerblueprints.core.data.ArtifactType +import org.onap.ccsdk.cds.controllerblueprints.core.data.DataType +import org.onap.ccsdk.cds.controllerblueprints.core.data.EntityType +import org.onap.ccsdk.cds.controllerblueprints.core.data.NodeType +import org.onap.ccsdk.cds.controllerblueprints.core.data.RelationshipType import org.onap.ccsdk.cds.controllerblueprints.core.normalizedFile import org.onap.ccsdk.cds.controllerblueprints.core.readNBText import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils @@ -108,7 +112,7 @@ open class ModelTypeLoadService(private val modelTypeHandler: ModelTypeHandler) val dataKey = FilenameUtils.getBaseName(file.name) val definitionContent = file.readNBText() val definition = JacksonUtils.readValue(definitionContent, classType) as EntityType - //checkNotNull(definition) { "failed to get data type from file : ${file.name}" } + // checkNotNull(definition) { "failed to get data type from file : ${file.name}" } val modelType = ModelType() val definitionType: String? @@ -143,4 +147,4 @@ open class ModelTypeLoadService(private val modelTypeHandler: ModelTypeHandler) errorBuilder.appendln("Couldn't load ${classType.name}(${file.name}: ${e.message}") } } -}
\ 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/load/ResourceDictionaryLoadService.kt b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/load/ResourceDictionaryLoadService.kt index 95073e99d..0350bc731 100644 --- a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/load/ResourceDictionaryLoadService.kt +++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/load/ResourceDictionaryLoadService.kt @@ -66,7 +66,6 @@ open class ResourceDictionaryLoadService(private val resourceDictionaryHandler: if (!errorBuilder.isEmpty) { log.error(errorBuilder.toString()) } - } private suspend fun loadResourceDictionary(errorBuilder: StrBuilder, file: File) { @@ -91,9 +90,8 @@ open class ResourceDictionaryLoadService(private val resourceDictionaryHandler: resourceDictionary.updatedBy = resourceDefinition.updatedBy if (StringUtils.isBlank(resourceDefinition.tags)) { - resourceDictionary.tags = (resourceDefinition.name + ", " + resourceDefinition.updatedBy - + ", " + resourceDefinition.updatedBy) - + resourceDictionary.tags = (resourceDefinition.name + ", " + resourceDefinition.updatedBy + + ", " + resourceDefinition.updatedBy) } else { resourceDictionary.tags = resourceDefinition.tags!! } @@ -107,5 +105,4 @@ open class ResourceDictionaryLoadService(private val resourceDictionaryHandler: errorBuilder.appendln("Couldn't load Resource dictionary (${file.name}: ${e.message}") } } - -}
\ 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/repository/BluePrintsReactRepository.kt b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/repository/ModelTypeReactRepository.kt index 1d69cd7cc..80aa6b49a 100644 --- a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/repository/BluePrintsReactRepository.kt +++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/repository/ModelTypeReactRepository.kt @@ -21,6 +21,7 @@ import org.springframework.stereotype.Service import reactor.core.publisher.Flux import reactor.core.publisher.Mono import reactor.core.scheduler.Schedulers + // TODO("Convert into coroutines") /** * ModelTypeReactRepository. @@ -40,37 +41,36 @@ open class ModelTypeReactRepository(private val modelTypeRepository: ModelTypeRe fun findByModelNameIn(modelNames: List<String>): Flux<ModelType> { return Flux.fromIterable(modelTypeRepository.findByModelNameIn(modelNames)) - .subscribeOn(Schedulers.elastic()) + .subscribeOn(Schedulers.elastic()) } fun findByDerivedFrom(derivedFrom: String): Flux<ModelType> { return Flux.fromIterable(modelTypeRepository.findByDerivedFrom(derivedFrom)) - .subscribeOn(Schedulers.elastic()) + .subscribeOn(Schedulers.elastic()) } fun findByDerivedFromIn(derivedFroms: List<String>): Flux<ModelType> { return Flux.fromIterable(modelTypeRepository.findByDerivedFromIn(derivedFroms)) - .subscribeOn(Schedulers.elastic()) + .subscribeOn(Schedulers.elastic()) } fun findByDefinitionType(definitionType: String): Flux<ModelType> { return Flux.fromIterable(modelTypeRepository.findByDefinitionType(definitionType)) - .subscribeOn(Schedulers.elastic()) + .subscribeOn(Schedulers.elastic()) } fun findByDefinitionTypeIn(definitionTypes: List<String>): Flux<ModelType> { return Flux.fromIterable(modelTypeRepository.findByDefinitionTypeIn(definitionTypes)) - .subscribeOn(Schedulers.elastic()) + .subscribeOn(Schedulers.elastic()) } fun findByTagsContainingIgnoreCase(tags: String): Flux<ModelType> { return Flux.fromIterable(modelTypeRepository.findByTagsContainingIgnoreCase(tags)) - .subscribeOn(Schedulers.elastic()) + .subscribeOn(Schedulers.elastic()) } fun deleteByModelName(modelName: String): Mono<Void> { modelTypeRepository.deleteByModelName(modelName) return Mono.empty() } - -}
\ 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/repository/ModelTypeRepository.kt b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/repository/ModelTypeRepository.kt index 3e36947a4..8beea7161 100644 --- a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/repository/ModelTypeRepository.kt +++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/repository/ModelTypeRepository.kt @@ -23,6 +23,7 @@ import javax.transaction.Transactional @Repository interface ModelTypeRepository : JpaRepository<ModelType, String> { + /** * This is a findByModelName method * @@ -30,6 +31,7 @@ interface ModelTypeRepository : JpaRepository<ModelType, String> { * @return Optional<ModelType> */ fun findByModelName(modelName: String): ModelType? + /** * This is a findByModelNameIn method * @@ -37,19 +39,21 @@ interface ModelTypeRepository : JpaRepository<ModelType, String> { * @return List<ModelType> */ fun findByModelNameIn(modelNames: List<String>): List<ModelType> + /** * This is a findByDerivedFrom method * * @param derivedFrom Derived From * @return List<ModelType> - */ + */ fun findByDerivedFrom(derivedFrom: String): List<ModelType> + /** * This is a findByDerivedFromIn method * * @param derivedFroms Derived Froms * @return List<ModelType> - */ + */ fun findByDerivedFromIn(derivedFroms: List<String>): List<ModelType> /** @@ -59,12 +63,13 @@ interface ModelTypeRepository : JpaRepository<ModelType, String> { * @return List<ModelType> */ fun findByDefinitionType(definitionType: String): List<ModelType> + /** * This is a findByDefinitionTypeIn method * * @param definitionTypes Definition Types * @return List<ModelType> - */ + */ fun findByDefinitionTypeIn(definitionTypes: List<String>): List<ModelType> /** diff --git a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/repository/ResourceDictionaryRepository.kt b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/repository/ResourceDictionaryRepository.kt index 68db371c6..da7893861 100644 --- a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/repository/ResourceDictionaryRepository.kt +++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/repository/ResourceDictionaryRepository.kt @@ -20,7 +20,6 @@ import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.domain.ResourceDictio import org.springframework.data.jpa.repository.JpaRepository import org.springframework.stereotype.Repository - /** * ResourceMappingRepository.java Purpose: Provide Configuration Generator ResourceMappingRepository * @@ -30,7 +29,6 @@ import org.springframework.stereotype.Repository @Repository interface ResourceDictionaryRepository : JpaRepository<ResourceDictionary, String> { - /** * This is a findByName method * @@ -61,6 +59,4 @@ interface ResourceDictionaryRepository : JpaRepository<ResourceDictionary, Strin * @param name name */ fun deleteByName(name: String) - - } diff --git a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/service/BluePrintRepoServiceImpl.kt b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/service/BluePrintRepoServiceImpl.kt index f8e6163a5..420a9fcd7 100644 --- a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/service/BluePrintRepoServiceImpl.kt +++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/service/BluePrintRepoServiceImpl.kt @@ -23,7 +23,11 @@ import org.apache.commons.lang3.StringUtils import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.repository.ModelTypeRepository import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.repository.ResourceDictionaryRepository import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException -import org.onap.ccsdk.cds.controllerblueprints.core.data.* +import org.onap.ccsdk.cds.controllerblueprints.core.data.ArtifactType +import org.onap.ccsdk.cds.controllerblueprints.core.data.CapabilityDefinition +import org.onap.ccsdk.cds.controllerblueprints.core.data.DataType +import org.onap.ccsdk.cds.controllerblueprints.core.data.NodeType +import org.onap.ccsdk.cds.controllerblueprints.core.data.RelationshipType import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintRepoService import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceDefinition @@ -36,37 +40,39 @@ interface ResourceDefinitionRepoService : BluePrintRepoService { } @Service -open class BluePrintRepoFileService(private val modelTypeRepository: ModelTypeRepository, - private val resourceDictionaryRepository: ResourceDictionaryRepository) : ResourceDefinitionRepoService { +open class BluePrintRepoFileService( + private val modelTypeRepository: ModelTypeRepository, + private val resourceDictionaryRepository: ResourceDictionaryRepository +) : ResourceDefinitionRepoService { @Throws(BluePrintException::class) override fun getNodeType(nodeTypeName: String): NodeType { return getModelType(nodeTypeName, NodeType::class.java) - ?: throw BluePrintException("couldn't get NodeType($nodeTypeName)") + ?: throw BluePrintException("couldn't get NodeType($nodeTypeName)") } @Throws(BluePrintException::class) override fun getDataType(dataTypeName: String): DataType { return getModelType(dataTypeName, DataType::class.java) - ?: throw BluePrintException("couldn't get DataType($dataTypeName)") + ?: throw BluePrintException("couldn't get DataType($dataTypeName)") } @Throws(BluePrintException::class) override fun getArtifactType(artifactTypeName: String): ArtifactType { return getModelType(artifactTypeName, ArtifactType::class.java) - ?: throw BluePrintException("couldn't get ArtifactType($artifactTypeName)") + ?: throw BluePrintException("couldn't get ArtifactType($artifactTypeName)") } @Throws(BluePrintException::class) override fun getRelationshipType(relationshipTypeName: String): RelationshipType { return getModelType(relationshipTypeName, RelationshipType::class.java) - ?: throw BluePrintException("couldn't get RelationshipType($relationshipTypeName)") + ?: throw BluePrintException("couldn't get RelationshipType($relationshipTypeName)") } @Throws(BluePrintException::class) override fun getCapabilityDefinition(capabilityDefinitionName: String): CapabilityDefinition { return getModelType(capabilityDefinitionName, CapabilityDefinition::class.java) - ?: throw BluePrintException("couldn't get CapabilityDefinition($capabilityDefinitionName)") + ?: throw BluePrintException("couldn't get CapabilityDefinition($capabilityDefinitionName)") } @Throws(BluePrintException::class) @@ -81,12 +87,16 @@ open class BluePrintRepoFileService(private val modelTypeRepository: ModelTypeRe @Throws(BluePrintException::class) private fun <T> getModelType(modelName: String, valueClass: Class<T>): T? { - Preconditions.checkArgument(StringUtils.isNotBlank(modelName), - "Failed to get model from repo, model name is missing") + Preconditions.checkArgument( + StringUtils.isNotBlank(modelName), + "Failed to get model from repo, model name is missing" + ) val modelDefinition = getModelDefinition(modelName) - Preconditions.checkNotNull(modelDefinition, - String.format("Failed to get model content for model name (%s)", modelName)) + Preconditions.checkNotNull( + modelDefinition, + String.format("Failed to get model content for model name (%s)", modelName) + ) return JacksonUtils.readValue(modelDefinition, valueClass) } @@ -102,4 +112,4 @@ open class BluePrintRepoFileService(private val modelTypeRepository: ModelTypeRe } return modelDefinition } -}
\ 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/utils/BluePrintEnhancerUtils.kt b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/utils/BluePrintEnhancerUtils.kt index c79d1b526..4d5ca36cf 100644 --- a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/utils/BluePrintEnhancerUtils.kt +++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/utils/BluePrintEnhancerUtils.kt @@ -19,12 +19,18 @@ package org.onap.ccsdk.cds.blueprintsprocessor.designer.api.utils import kotlinx.coroutines.reactive.awaitSingle -import org.onap.ccsdk.cds.controllerblueprints.core.* +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException import org.onap.ccsdk.cds.controllerblueprints.core.data.ArtifactType import org.onap.ccsdk.cds.controllerblueprints.core.data.DataType import org.onap.ccsdk.cds.controllerblueprints.core.data.NodeType import org.onap.ccsdk.cds.controllerblueprints.core.data.RelationshipType +import org.onap.ccsdk.cds.controllerblueprints.core.deCompress +import org.onap.ccsdk.cds.controllerblueprints.core.deleteNBDir import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintRepoService +import org.onap.ccsdk.cds.controllerblueprints.core.logger +import org.onap.ccsdk.cds.controllerblueprints.core.normalizedFile +import org.onap.ccsdk.cds.controllerblueprints.core.normalizedPathName +import org.onap.ccsdk.cds.controllerblueprints.core.reCreateNBDirs import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintContext import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintArchiveUtils import org.springframework.core.io.ByteArrayResource @@ -36,47 +42,57 @@ import org.springframework.http.codec.multipart.FilePart import java.io.File import java.nio.file.Paths - class BluePrintEnhancerUtils { companion object { val log = logger(BluePrintEnhancerUtils) - fun populateDataTypes(bluePrintContext: BluePrintContext, bluePrintRepoService: BluePrintRepoService, - dataTypeName: String): DataType { + fun populateDataTypes( + bluePrintContext: BluePrintContext, + bluePrintRepoService: BluePrintRepoService, + dataTypeName: String + ): DataType { val dataType = bluePrintContext.serviceTemplate.dataTypes?.get(dataTypeName) - ?: bluePrintRepoService.getDataType(dataTypeName) - ?: throw BluePrintException("couldn't get DataType($dataTypeName) from repo.") + ?: bluePrintRepoService.getDataType(dataTypeName) + ?: throw BluePrintException("couldn't get DataType($dataTypeName) from repo.") bluePrintContext.serviceTemplate.dataTypes?.put(dataTypeName, dataType) return dataType } - fun populateRelationshipType(bluePrintContext: BluePrintContext, bluePrintRepoService: BluePrintRepoService, - relationshipName: String): RelationshipType { + fun populateRelationshipType( + bluePrintContext: BluePrintContext, + bluePrintRepoService: BluePrintRepoService, + relationshipName: String + ): RelationshipType { val relationshipType = bluePrintContext.serviceTemplate.relationshipTypes?.get(relationshipName) - ?: bluePrintRepoService.getRelationshipType(relationshipName) - ?: throw BluePrintException("couldn't get RelationshipType($relationshipName) from repo.") + ?: bluePrintRepoService.getRelationshipType(relationshipName) + ?: throw BluePrintException("couldn't get RelationshipType($relationshipName) from repo.") bluePrintContext.serviceTemplate.relationshipTypes?.put(relationshipName, relationshipType) return relationshipType } - - fun populateNodeType(bluePrintContext: BluePrintContext, bluePrintRepoService: BluePrintRepoService, - nodeTypeName: String): NodeType { + fun populateNodeType( + bluePrintContext: BluePrintContext, + bluePrintRepoService: BluePrintRepoService, + nodeTypeName: String + ): NodeType { val nodeType = bluePrintContext.serviceTemplate.nodeTypes?.get(nodeTypeName) - ?: bluePrintRepoService.getNodeType(nodeTypeName) - ?: throw BluePrintException("couldn't get NodeType($nodeTypeName) from repo.") + ?: bluePrintRepoService.getNodeType(nodeTypeName) + ?: throw BluePrintException("couldn't get NodeType($nodeTypeName) from repo.") bluePrintContext.serviceTemplate.nodeTypes?.put(nodeTypeName, nodeType) return nodeType } - fun populateArtifactType(bluePrintContext: BluePrintContext, bluePrintRepoService: BluePrintRepoService, - artifactTypeName: String): ArtifactType { + fun populateArtifactType( + bluePrintContext: BluePrintContext, + bluePrintRepoService: BluePrintRepoService, + artifactTypeName: String + ): ArtifactType { val artifactType = bluePrintContext.serviceTemplate.artifactTypes?.get(artifactTypeName) - ?: bluePrintRepoService.getArtifactType(artifactTypeName) - ?: throw BluePrintException("couldn't get ArtifactType($artifactTypeName) from repo.") + ?: bluePrintRepoService.getArtifactType(artifactTypeName) + ?: throw BluePrintException("couldn't get ArtifactType($artifactTypeName) from repo.") bluePrintContext.serviceTemplate.artifactTypes?.put(artifactTypeName, artifactType) return artifactType } @@ -90,17 +106,16 @@ class BluePrintEnhancerUtils { return targetFile } - suspend fun filePartAsFile(filePart: FilePart, targetFile: File): File { // Delete the Directory targetFile.parentFile.reCreateNBDirs() return filePart.transferTo(targetFile) - .thenReturn(targetFile) - .awaitSingle() + .thenReturn(targetFile) + .awaitSingle() } private suspend fun byteArrayAsArchiveFile(byteArray: ByteArray, archiveDir: String, enhanceDir: String): File { - //Recreate the Base Directories + // Recreate the Base Directories normalizedFile(archiveDir).reCreateNBDirs() normalizedFile(enhanceDir).reCreateNBDirs() val archiveFile = normalizedFile(archiveDir, "cba.zip") @@ -109,7 +124,7 @@ class BluePrintEnhancerUtils { } private suspend fun filePartAsArchiveFile(filePart: FilePart, archiveDir: String, enhanceDir: String): File { - //Recreate the Base Directories + // Recreate the Base Directories normalizedFile(archiveDir).reCreateNBDirs() normalizedFile(enhanceDir).reCreateNBDirs() val archiveFile = normalizedFile(archiveDir, "cba.zip") @@ -132,17 +147,23 @@ class BluePrintEnhancerUtils { } /** compress [enhanceDir] to [archiveDir] and return ByteArray */ - suspend fun compressEnhanceDirAndReturnByteArray(enhanceDir: String, archiveDir: String, - outputFileName: String = "enhanced-cba.zip"): ByteArray { + suspend fun compressEnhanceDirAndReturnByteArray( + enhanceDir: String, + archiveDir: String, + outputFileName: String = "enhanced-cba.zip" + ): ByteArray { val compressedFile = normalizedFile(archiveDir, outputFileName) BluePrintArchiveUtils.compress(Paths.get(enhanceDir).toFile(), compressedFile) return compressedFile.readBytes() } /** compress [enhanceDir] to [archiveDir] and return ResponseEntity */ - suspend fun compressEnhanceDirAndReturnFilePart(enhanceDir: String, archiveDir: String, - outputFileName: String = "enhanced-cba.zip") - : ResponseEntity<Resource> { + suspend fun compressEnhanceDirAndReturnFilePart( + enhanceDir: String, + archiveDir: String, + outputFileName: String = "enhanced-cba.zip" + ): + ResponseEntity<Resource> { val compressedFile = normalizedFile(archiveDir, outputFileName) BluePrintArchiveUtils.compress(Paths.get(enhanceDir).toFile(), compressedFile) return prepareResourceEntity(compressedFile) @@ -152,12 +173,13 @@ class BluePrintEnhancerUtils { suspend fun prepareResourceEntity(file: File): ResponseEntity<Resource> { return prepareResourceEntity(file.name, file.readBytes()) } + /** convert [byteArray] to ResourceEntity with [fileName]*/ fun prepareResourceEntity(fileName: String, byteArray: ByteArray): ResponseEntity<Resource> { return ResponseEntity.ok() - .contentType(MediaType.parseMediaType("text/plain")) - .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"$fileName\"") - .body(ByteArrayResource(byteArray)) + .contentType(MediaType.parseMediaType("text/plain")) + .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"$fileName\"") + .body(ByteArrayResource(byteArray)) } suspend fun cleanEnhancer(archiveLocation: String, enhancementLocation: String) { diff --git a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/utils/SortByOptionsEnum.kt b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/utils/BlueprintSortByOption.kt index 6f5636516..92573892a 100644 --- a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/utils/SortByOptionsEnum.kt +++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/utils/BlueprintSortByOption.kt @@ -3,4 +3,4 @@ package org.onap.ccsdk.cds.blueprintsprocessor.designer.api.utils enum class BlueprintSortByOption(val columnName: String) { DATE("createdDate"), NAME("artifactName") -}
\ 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/utils/ModelTypeValidator.kt b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/utils/ModelTypeValidator.kt index 8ec0b9bab..6b9ea28f0 100644 --- a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/utils/ModelTypeValidator.kt +++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/utils/ModelTypeValidator.kt @@ -21,7 +21,11 @@ import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.domain.ModelType import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintTypes -import org.onap.ccsdk.cds.controllerblueprints.core.data.* +import org.onap.ccsdk.cds.controllerblueprints.core.data.ArtifactType +import org.onap.ccsdk.cds.controllerblueprints.core.data.CapabilityDefinition +import org.onap.ccsdk.cds.controllerblueprints.core.data.DataType +import org.onap.ccsdk.cds.controllerblueprints.core.data.NodeType +import org.onap.ccsdk.cds.controllerblueprints.core.data.RelationshipType import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils class ModelTypeValidator { @@ -38,23 +42,23 @@ class ModelTypeValidator { when (definitionType) { BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE -> { JacksonUtils.readValue(definitionContent, DataType::class.java) - ?: throw BluePrintException("Model type definition is not DataType valid content $definitionContent") + ?: throw BluePrintException("Model type definition is not DataType valid content $definitionContent") } BluePrintConstants.MODEL_DEFINITION_TYPE_NODE_TYPE -> { JacksonUtils.readValue(definitionContent, NodeType::class.java) - ?: throw BluePrintException("Model type definition is not NodeType valid content $definitionContent") + ?: throw BluePrintException("Model type definition is not NodeType valid content $definitionContent") } BluePrintConstants.MODEL_DEFINITION_TYPE_ARTIFACT_TYPE -> { JacksonUtils.readValue(definitionContent, ArtifactType::class.java) - ?: throw BluePrintException("Model type definition is not ArtifactType valid content $definitionContent") + ?: throw BluePrintException("Model type definition is not ArtifactType valid content $definitionContent") } BluePrintConstants.MODEL_DEFINITION_TYPE_CAPABILITY_TYPE -> { JacksonUtils.readValue(definitionContent, CapabilityDefinition::class.java) - ?: throw BluePrintException("Model type definition is not CapabilityDefinition valid content $definitionContent") + ?: throw BluePrintException("Model type definition is not CapabilityDefinition valid content $definitionContent") } BluePrintConstants.MODEL_DEFINITION_TYPE_RELATIONSHIP_TYPE -> { JacksonUtils.readValue(definitionContent, RelationshipType::class.java) - ?: throw BluePrintException("Model type definition is not RelationshipType valid content $definitionContent") + ?: throw BluePrintException("Model type definition is not RelationshipType valid content $definitionContent") } } return true @@ -79,5 +83,4 @@ class ModelTypeValidator { return true } } - } 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 61f515017..0938431d6 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 @@ -32,20 +32,34 @@ import org.onap.ccsdk.cds.controllerblueprints.common.api.CommonHeader import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants import org.onap.ccsdk.cds.controllerblueprints.core.deleteDir import org.onap.ccsdk.cds.controllerblueprints.core.normalizedFile -import org.onap.ccsdk.cds.controllerblueprints.management.api.* +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.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 +import org.onap.ccsdk.cds.controllerblueprints.management.api.UploadAction import org.springframework.beans.factory.annotation.Autowired import org.springframework.boot.autoconfigure.EnableAutoConfiguration import org.springframework.context.annotation.ComponentScan import org.springframework.test.annotation.DirtiesContext import org.springframework.test.context.TestPropertySource import org.springframework.test.context.junit4.SpringRunner -import kotlin.test.* +import kotlin.test.AfterTest +import kotlin.test.BeforeTest +import kotlin.test.assertEquals +import kotlin.test.assertNotNull +import kotlin.test.assertTrue @RunWith(SpringRunner::class) @EnableAutoConfiguration @DirtiesContext -@ComponentScan(basePackages = ["org.onap.ccsdk.cds.blueprintsprocessor", - "org.onap.ccsdk.cds.controllerblueprints"]) +@ComponentScan( + basePackages = ["org.onap.ccsdk.cds.blueprintsprocessor", + "org.onap.ccsdk.cds.controllerblueprints"] +) @TestPropertySource(locations = ["classpath:application-test.properties"]) class BluePrintManagementGRPCHandlerTest { @@ -74,8 +88,10 @@ class BluePrintManagementGRPCHandlerTest { 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") + assertTrue( + bootstrapOutput.status.message.contentEquals(BluePrintConstants.STATUS_SUCCESS), + "failed to get success status" + ) assertEquals(id, bootstrapOutput.commonHeader.requestId) } @@ -87,8 +103,10 @@ class BluePrintManagementGRPCHandlerTest { val output = blockingStub.uploadBlueprint(req) assertEquals(200, output.status.code) - assertTrue(output.status.message.contentEquals(BluePrintConstants.STATUS_SUCCESS), - "failed to get success status") + assertTrue( + output.status.message.contentEquals(BluePrintConstants.STATUS_SUCCESS), + "failed to get success status" + ) assertEquals(id, output.commonHeader.requestId) val downloadId = "123_download" @@ -96,8 +114,10 @@ class BluePrintManagementGRPCHandlerTest { val downloadOutput = blockingStub.downloadBlueprint(downloadReq) assertEquals(200, downloadOutput.status.code) - assertTrue(downloadOutput.status.message.contentEquals(BluePrintConstants.STATUS_SUCCESS), - "failed to get success status") + assertTrue( + downloadOutput.status.message.contentEquals(BluePrintConstants.STATUS_SUCCESS), + "failed to get success status" + ) assertNotNull(downloadOutput.fileChunk?.chunk, "failed to get cba file chunks") assertEquals(downloadId, downloadOutput.commonHeader.requestId) } @@ -110,8 +130,10 @@ class BluePrintManagementGRPCHandlerTest { var output = blockingStub.uploadBlueprint(req) assertEquals(200, output.status.code) - assertTrue(output.status.message.contentEquals(BluePrintConstants.STATUS_SUCCESS), - "failed to get success status") + assertTrue( + output.status.message.contentEquals(BluePrintConstants.STATUS_SUCCESS), + "failed to get success status" + ) assertEquals(id, output.commonHeader.requestId) val removeReq = createRemoveInputRequest(id) @@ -142,18 +164,18 @@ 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() + .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() + .setCommonHeader(commonHeader) + .setLoadModelType(false) + .setLoadResourceDictionary(false) + .setLoadCBA(false) + .build() } private fun createUploadInputRequest(id: String, action: String): BluePrintUploadInput { @@ -161,59 +183,63 @@ class BluePrintManagementGRPCHandlerTest { assertTrue(file.exists(), "couldnt get file ${file.absolutePath}") val commonHeader = CommonHeader - .newBuilder() - .setTimestamp("2012-04-23T18:25:43.511Z") - .setOriginatorId("System") - .setRequestId(id) - .setSubRequestId("1234-56").build() + .newBuilder() + .setTimestamp("2012-04-23T18:25:43.511Z") + .setOriginatorId("System") + .setRequestId(id) + .setSubRequestId("1234-56").build() val actionIdentifier = ActionIdentifiers.newBuilder() - .setActionName(action) - .setBlueprintName("sample") - .setBlueprintVersion("1.0.0") - .build() + .setActionName(action) + .setBlueprintName("sample") + .setBlueprintVersion("1.0.0") + .build() val fileChunk = FileChunk.newBuilder().setChunk(ByteString.copyFrom(file.inputStream().readBytes())) - .build() + .build() return BluePrintUploadInput.newBuilder() - .setCommonHeader(commonHeader) - .setActionIdentifiers(actionIdentifier) - .setFileChunk(fileChunk) - .build() + .setCommonHeader(commonHeader) + .setActionIdentifiers(actionIdentifier) + .setFileChunk(fileChunk) + .build() } private fun createDownloadInputRequest(id: String, action: String): BluePrintDownloadInput { val commonHeader = CommonHeader - .newBuilder() - .setTimestamp("2012-04-23T18:25:43.511Z") - .setOriginatorId("System") - .setRequestId(id) - .setSubRequestId("1234-56").build() + .newBuilder() + .setTimestamp("2012-04-23T18:25:43.511Z") + .setOriginatorId("System") + .setRequestId(id) + .setSubRequestId("1234-56").build() return BluePrintDownloadInput.newBuilder() - .setCommonHeader(commonHeader) - .setActionIdentifiers(ActionIdentifiers.newBuilder() - .setBlueprintName("baseconfiguration") - .setBlueprintVersion("1.0.0") - .setActionName(action).build()) - .build() + .setCommonHeader(commonHeader) + .setActionIdentifiers( + ActionIdentifiers.newBuilder() + .setBlueprintName("baseconfiguration") + .setBlueprintVersion("1.0.0") + .setActionName(action).build() + ) + .build() } private fun createRemoveInputRequest(id: String): BluePrintRemoveInput { val commonHeader = CommonHeader - .newBuilder() - .setTimestamp("2012-04-23T18:25:43.511Z") - .setOriginatorId("System") - .setRequestId(id) - .setSubRequestId("1234-56").build() + .newBuilder() + .setTimestamp("2012-04-23T18:25:43.511Z") + .setOriginatorId("System") + .setRequestId(id) + .setSubRequestId("1234-56").build() return BluePrintRemoveInput.newBuilder() - .setCommonHeader(commonHeader) - .setActionIdentifiers(ActionIdentifiers.newBuilder() - .setBlueprintName("sample") - .setBlueprintVersion("1.0.0") - .setActionName(RemoveAction.DEFAULT.toString()).build()) - .build() + .setCommonHeader(commonHeader) + .setActionIdentifiers( + ActionIdentifiers.newBuilder() + .setBlueprintName("sample") + .setBlueprintVersion("1.0.0") + .setActionName(RemoveAction.DEFAULT.toString()).build() + ) + .build() } } diff --git a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/BlueprintModelControllerTest.kt b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/BlueprintModelControllerTest.kt index 149acb03c..50eafd12c 100644 --- a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/BlueprintModelControllerTest.kt +++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/BlueprintModelControllerTest.kt @@ -30,8 +30,13 @@ import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintPropertiesService import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintPropertyConfiguration import org.onap.ccsdk.cds.blueprintsprocessor.db.BluePrintDBLibConfiguration import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.domain.BlueprintModelSearch -import org.onap.ccsdk.cds.controllerblueprints.core.* +import org.onap.ccsdk.cds.controllerblueprints.core.compress import org.onap.ccsdk.cds.controllerblueprints.core.config.BluePrintLoadConfiguration +import org.onap.ccsdk.cds.controllerblueprints.core.deleteDir +import org.onap.ccsdk.cds.controllerblueprints.core.logger +import org.onap.ccsdk.cds.controllerblueprints.core.normalizedFile +import org.onap.ccsdk.cds.controllerblueprints.core.normalizedPathName +import org.onap.ccsdk.cds.controllerblueprints.core.reCreateDirs import org.springframework.beans.factory.annotation.Autowired import org.springframework.boot.test.context.SpringBootTest import org.springframework.core.io.ByteArrayResource @@ -60,8 +65,10 @@ import kotlin.test.assertTrue @RunWith(SpringRunner::class) @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) -@ContextConfiguration(classes = [DesignerApiTestConfiguration::class, - BluePrintPropertyConfiguration::class, BluePrintPropertiesService::class, BluePrintDBLibConfiguration::class]) +@ContextConfiguration( + classes = [DesignerApiTestConfiguration::class, + BluePrintPropertyConfiguration::class, BluePrintPropertiesService::class, BluePrintDBLibConfiguration::class] +) @TestPropertySource(locations = ["classpath:application-test.properties"]) @FixMethodOrder(MethodSorters.NAME_ASCENDING) class BlueprintModelControllerTest { @@ -82,7 +89,6 @@ class BlueprintModelControllerTest { private var testZipFile: File? = null - @Before fun setUp() { assertNotNull(webTestClient, " Failed to create WebTestClient") @@ -121,14 +127,14 @@ class BlueprintModelControllerTest { }.build() val saveBP = webTestClient - .post() - .uri("/api/v1/blueprint-model") - .body(BodyInserters.fromMultipartData(body)) - .exchange() - .expectStatus().isOk - .returnResult<BlueprintModelSearch>() - .responseBody - .awaitSingle() + .post() + .uri("/api/v1/blueprint-model") + .body(BodyInserters.fromMultipartData(body)) + .exchange() + .expectStatus().isOk + .returnResult<BlueprintModelSearch>() + .responseBody + .awaitSingle() assertNotNull(saveBP, "failed to get response") assertEquals("baseconfiguration", saveBP.artifactName, "mismatch artifact name") @@ -141,18 +147,21 @@ class BlueprintModelControllerTest { @Test @Throws(JSONException::class) fun test02_getBluePrintByNameAndVersion() { - webTestClient(HttpMethod.GET, null, - "/api/v1/blueprint-model/by-name/${bp!!.artifactName}/version/${bp!!.artifactVersion}", - HttpStatus.OK, false) + webTestClient( + HttpMethod.GET, null, + "/api/v1/blueprint-model/by-name/${bp!!.artifactName}/version/${bp!!.artifactVersion}", + HttpStatus.OK, false + ) } - @Test @Throws(JSONException::class) fun test03_getBlueprintModel() { - webTestClient(HttpMethod.GET, null, - "/api/v1/blueprint-model/${bp!!.id}", - HttpStatus.OK, false) + webTestClient( + HttpMethod.GET, null, + "/api/v1/blueprint-model/${bp!!.id}", + HttpStatus.OK, false + ) } @Test @@ -164,9 +173,11 @@ class BlueprintModelControllerTest { @Test @Throws(JSONException::class) fun test05_downloadBluePrint() { - webTestClient(HttpMethod.GET, null, - "/api/v1/blueprint-model/download/${bp!!.id}", - HttpStatus.OK, false) + webTestClient( + HttpMethod.GET, null, + "/api/v1/blueprint-model/download/${bp!!.id}", + HttpStatus.OK, false + ) } @Test @@ -185,14 +196,14 @@ class BlueprintModelControllerTest { }.build() val publishBP = webTestClient - .post() - .uri("/api/v1/blueprint-model/publish") - .body(BodyInserters.fromMultipartData(body)) - .exchange() - .expectStatus().isOk - .returnResult<BlueprintModelSearch>() - .responseBody - .awaitSingle() + .post() + .uri("/api/v1/blueprint-model/publish") + .body(BodyInserters.fromMultipartData(body)) + .exchange() + .expectStatus().isOk + .returnResult<BlueprintModelSearch>() + .responseBody + .awaitSingle() assertNotNull(publishBP, "failed to get response") assertEquals("baseconfiguration", publishBP.artifactName, "mismatch artifact name") @@ -205,49 +216,60 @@ class BlueprintModelControllerTest { @Test @Throws(JSONException::class) fun test08_searchBlueprintModels() { - webTestClient(HttpMethod.GET, null, - "/api/v1/blueprint-model/search/${bp!!.artifactName}", - HttpStatus.OK, false) + webTestClient( + HttpMethod.GET, null, + "/api/v1/blueprint-model/search/${bp!!.artifactName}", + HttpStatus.OK, false + ) } @Test @Throws(JSONException::class) fun test09_downloadBlueprintByNameAndVersion() { - webTestClient(HttpMethod.GET, null, - "/api/v1/blueprint-model/download/by-name/${bp!!.artifactName}/version/${bp!!.artifactVersion}", - HttpStatus.OK, false) + webTestClient( + HttpMethod.GET, null, + "/api/v1/blueprint-model/download/by-name/${bp!!.artifactName}/version/${bp!!.artifactVersion}", + HttpStatus.OK, false + ) } @Test fun test10_deleteBluePrint() { -// webTestClient.delete().uri("/api/v1/blueprint-model/${bp!!.id}") -// .header("Authorization", "Basic " + Base64Utils -// .encodeToString(("ccsdkapps" + ":" + "ccsdkapps").toByteArray(UTF_8))) -// .exchange() -// .expectStatus().is2xxSuccessful + // webTestClient.delete().uri("/api/v1/blueprint-model/${bp!!.id}") + // .header("Authorization", "Basic " + Base64Utils + // .encodeToString(("ccsdkapps" + ":" + "ccsdkapps").toByteArray(UTF_8))) + // .exchange() + // .expectStatus().is2xxSuccessful webTestClient.delete().uri("/api/v1/blueprint-model/name/${bp!!.artifactName}/version/${bp!!.artifactVersion}") - .header("Authorization", "Basic " + Base64Utils - .encodeToString(("ccsdkapps" + ":" + "ccsdkapps").toByteArray(UTF_8))) - .exchange() - .expectStatus().is2xxSuccessful + .header( + "Authorization", "Basic " + Base64Utils + .encodeToString(("ccsdkapps" + ":" + "ccsdkapps").toByteArray(UTF_8)) + ) + .exchange() + .expectStatus().is2xxSuccessful } @Throws(JSONException::class) - private fun webTestClient(requestMethod: HttpMethod, body: BodyInserters.MultipartInserter?, uri: String, - expectedResponceStatus: HttpStatus, setParam: Boolean) { + private fun webTestClient( + requestMethod: HttpMethod, + body: BodyInserters.MultipartInserter?, + uri: String, + expectedResponceStatus: HttpStatus, + setParam: Boolean + ) { log.info("Requesting($uri): Method(${requestMethod.name})") webTestClient.method(requestMethod).uri(uri) - .header("Authorization", "Basic " + Base64Utils - .encodeToString(("ccsdkapps" + ":" + "ccsdkapps").toByteArray(UTF_8))) - .body(body) - .exchange() - .expectStatus().isEqualTo(expectedResponceStatus) - .expectBody() - .returnResult().responseBody!! - + .header( + "Authorization", "Basic " + Base64Utils + .encodeToString(("ccsdkapps" + ":" + "ccsdkapps").toByteArray(UTF_8)) + ) + .body(body) + .exchange() + .expectStatus().isEqualTo(expectedResponceStatus) + .expectBody() + .returnResult().responseBody!! } - -}
\ 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/DesignerApiTestConfiguration.kt b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/DesignerApiTestConfiguration.kt index 03e016b8e..4953d9cee 100644 --- a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/DesignerApiTestConfiguration.kt +++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/DesignerApiTestConfiguration.kt @@ -21,7 +21,9 @@ import org.springframework.context.annotation.ComponentScan import org.springframework.context.annotation.Configuration @Configuration -@ComponentScan(basePackages = ["org.onap.ccsdk.cds.controllerblueprints", - "org.onap.ccsdk.cds.blueprintsprocessor"]) +@ComponentScan( + basePackages = ["org.onap.ccsdk.cds.controllerblueprints", + "org.onap.ccsdk.cds.blueprintsprocessor"] +) @EnableAutoConfiguration open class DesignerApiTestConfiguration diff --git a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/ModelTypeControllerTest.kt b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/ModelTypeControllerTest.kt index 8871676d2..fd51df482 100644 --- a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/ModelTypeControllerTest.kt +++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/ModelTypeControllerTest.kt @@ -24,9 +24,9 @@ import org.junit.runners.MethodSorters import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintPropertiesService import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintPropertyConfiguration import org.onap.ccsdk.cds.blueprintsprocessor.db.BluePrintDBLibConfiguration +import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.domain.ModelType import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils -import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.domain.ModelType import org.slf4j.LoggerFactory import org.springframework.beans.factory.annotation.Autowired import org.springframework.test.annotation.Commit @@ -35,8 +35,10 @@ import org.springframework.test.context.TestPropertySource import org.springframework.test.context.junit4.SpringRunner @RunWith(SpringRunner::class) -@ContextConfiguration(classes = [DesignerApiTestConfiguration::class, - BluePrintPropertyConfiguration::class, BluePrintPropertiesService::class, BluePrintDBLibConfiguration::class]) +@ContextConfiguration( + classes = [DesignerApiTestConfiguration::class, + BluePrintPropertyConfiguration::class, BluePrintPropertiesService::class, BluePrintDBLibConfiguration::class] +) @TestPropertySource(locations = ["classpath:application-test.properties"]) @FixMethodOrder(MethodSorters.NAME_ASCENDING) class ModelTypeControllerTest { @@ -62,8 +64,8 @@ class ModelTypeControllerTest { modelType.definition = JacksonUtils.jsonNode(content) modelType.modelName = modelName modelType.version = "1.0.0" - modelType.tags = ("test-datatype ," + BluePrintConstants.MODEL_TYPE_DATATYPES_ROOT + "," - + BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE) + modelType.tags = ("test-datatype ," + BluePrintConstants.MODEL_TYPE_DATATYPES_ROOT + "," + + BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE) modelType.updatedBy = "xxxxxx@xxx.com" modelType = modelTypeController!!.saveModelType(modelType) log.info("Saved Mode {}", modelType.toString()) @@ -71,15 +73,16 @@ class ModelTypeControllerTest { Assert.assertNotNull("Failed to get Saved ModelType, Id", modelType.modelName) val dbModelType = modelTypeController!!.getModelTypeByName(modelType.modelName) - Assert.assertNotNull("Failed to query ResourceMapping for ID (" + dbModelType!!.modelName + ")", - dbModelType) + Assert.assertNotNull( + "Failed to query ResourceMapping for ID (" + dbModelType!!.modelName + ")", + dbModelType + ) // Model Update modelType.updatedBy = "bs2796@xxx.com" modelType = modelTypeController!!.saveModelType(modelType) Assert.assertNotNull("Failed to get Saved ModelType", modelType) Assert.assertEquals("Failed to get Saved getUpdatedBy ", "bs2796@xxx.com", modelType.updatedBy) - } @Test @@ -92,7 +95,6 @@ class ModelTypeControllerTest { val dbModelTypes = modelTypeController!!.searchModelTypes(tags) Assert.assertNotNull("Failed to search ResourceMapping by tags", dbModelTypes) Assert.assertTrue("Failed to search ResourceMapping by tags count", dbModelTypes.isNotEmpty()) - } @Test @@ -113,7 +115,8 @@ class ModelTypeControllerTest { @Throws(Exception::class) fun test04DeleteModelType() { log.info( - "************************ test03DeleteModelType ***********************") + "************************ test03DeleteModelType ***********************" + ) val dbResourceMapping = modelTypeController!!.getModelTypeByName(modelName) Assert.assertNotNull("Failed to get response for api call getModelByName ", dbResourceMapping) Assert.assertNotNull("Failed to get Id for api call getModelByName ", dbResourceMapping!!.modelName) diff --git a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/ResourceDictionaryControllerTest.kt b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/ResourceDictionaryControllerTest.kt index b13b1ac08..cfb16c786 100644 --- a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/ResourceDictionaryControllerTest.kt +++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/ResourceDictionaryControllerTest.kt @@ -32,8 +32,10 @@ import kotlin.test.assertNotNull @RunWith(SpringRunner::class) @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) -@ContextConfiguration(classes = [DesignerApiTestConfiguration::class, - BluePrintPropertyConfiguration::class, BluePrintPropertiesService::class, BluePrintDBLibConfiguration::class]) +@ContextConfiguration( + classes = [DesignerApiTestConfiguration::class, + BluePrintPropertyConfiguration::class, BluePrintPropertiesService::class, BluePrintDBLibConfiguration::class] +) @TestPropertySource(locations = ["classpath:application-test.properties"]) @FixMethodOrder(MethodSorters.NAME_ASCENDING) class ResourceDictionaryControllerTest { @@ -45,5 +47,4 @@ class ResourceDictionaryControllerTest { fun testResourceDictionaryControllerPresence() { assertNotNull(resourceDictionaryController, "failed to initialise ResourceDictionaryController") } - -}
\ 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/enhancer/BluePrintEnhancerServiceImplTest.kt b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/enhancer/BluePrintEnhancerServiceImplTest.kt index a5a0511f5..c8c2f0b9b 100644 --- a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/enhancer/BluePrintEnhancerServiceImplTest.kt +++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/enhancer/BluePrintEnhancerServiceImplTest.kt @@ -37,8 +37,10 @@ import org.springframework.test.context.TestPropertySource import org.springframework.test.context.junit4.SpringRunner @RunWith(SpringRunner::class) -@ContextConfiguration(classes = [DesignerApiTestConfiguration::class, - BluePrintPropertyConfiguration::class, BluePrintPropertiesService::class, BluePrintDBLibConfiguration::class]) +@ContextConfiguration( + classes = [DesignerApiTestConfiguration::class, + BluePrintPropertyConfiguration::class, BluePrintPropertiesService::class, BluePrintDBLibConfiguration::class] +) @TestPropertySource(locations = ["classpath:application-test.properties"]) class BluePrintEnhancerServiceImplTest { @@ -54,7 +56,6 @@ class BluePrintEnhancerServiceImplTest { @Autowired lateinit var bluePrintValidatorService: BluePrintValidatorService - @Test @Throws(Exception::class) fun testEnhancementAndValidation() { @@ -93,7 +94,6 @@ class BluePrintEnhancerServiceImplTest { fun testRemoteScriptsEnhancementAndValidation() { val basePath = "./../../../../../components/model-catalog/blueprint-model/test-blueprint/remote_scripts" testComponentInvokeEnhancementAndValidation(basePath, "remote_scripts-enhance") - } fun testCapabilityCliEnhancementAndValidation() { @@ -115,12 +115,10 @@ class BluePrintEnhancerServiceImplTest { Assert.assertTrue("blueprint($basePath) validation failed ", valid) // Enable this to get the enhanced zip file -// val compressFile = normalizedFile("target/blueprints/enrichment", "$targetDirName.zip") -// normalizedFile(targetPath).compress(compressFile) + // val compressFile = normalizedFile("target/blueprints/enrichment", "$targetDirName.zip") + // normalizedFile(targetPath).compress(compressFile) deleteDir(targetPath) } } - - -}
\ 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/handler/ModelTypeServiceTest.kt b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/handler/ModelTypeServiceTest.kt index 7ea845dee..fe5cd4d3e 100644 --- a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/handler/ModelTypeServiceTest.kt +++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/handler/ModelTypeServiceTest.kt @@ -26,9 +26,9 @@ import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintPropertiesService import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintPropertyConfiguration import org.onap.ccsdk.cds.blueprintsprocessor.db.BluePrintDBLibConfiguration import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.DesignerApiTestConfiguration +import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.domain.ModelType import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils -import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.domain.ModelType import org.slf4j.LoggerFactory import org.springframework.beans.factory.annotation.Autowired import org.springframework.test.annotation.Commit @@ -36,13 +36,15 @@ import org.springframework.test.context.ContextConfiguration import org.springframework.test.context.TestPropertySource import org.springframework.test.context.junit4.SpringRunner - @RunWith(SpringRunner::class) -@ContextConfiguration(classes = [DesignerApiTestConfiguration::class, - BluePrintPropertyConfiguration::class, BluePrintPropertiesService::class, BluePrintDBLibConfiguration::class]) +@ContextConfiguration( + classes = [DesignerApiTestConfiguration::class, + BluePrintPropertyConfiguration::class, BluePrintPropertiesService::class, BluePrintDBLibConfiguration::class] +) @TestPropertySource(locations = ["classpath:application-test.properties"]) @FixMethodOrder(MethodSorters.NAME_ASCENDING) class ModelTypeServiceTest { + @Autowired private val modelTypeHandler: ModelTypeHandler? = null @@ -65,8 +67,8 @@ class ModelTypeServiceTest { modelType.definition = JacksonUtils.jsonNode(content) modelType.modelName = modelName modelType.version = "1.0.0" - modelType.tags = ("test-datatype ," + BluePrintConstants.MODEL_TYPE_DATATYPES_ROOT + "," - + BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE) + modelType.tags = ("test-datatype ," + BluePrintConstants.MODEL_TYPE_DATATYPES_ROOT + "," + + BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE) modelType.updatedBy = "xxxxxx@xxx.com" modelType = modelTypeHandler!!.saveModel(modelType) log.info("Saved Mode {}", modelType.toString()) @@ -74,8 +76,10 @@ class ModelTypeServiceTest { Assert.assertNotNull("Failed to get Saved ModelType, Id", modelType.modelName) val dbModelType = modelTypeHandler.getModelTypeByName(modelType.modelName) - Assert.assertNotNull("Failed to query ResourceMapping for ID (" + dbModelType!!.modelName + ")", - dbModelType) + Assert.assertNotNull( + "Failed to query ResourceMapping for ID (" + dbModelType!!.modelName + ")", + dbModelType + ) // Model Update modelType.updatedBy = "bs2796@xxx.com" @@ -83,7 +87,6 @@ class ModelTypeServiceTest { Assert.assertNotNull("Failed to get Saved ModelType", modelType) Assert.assertEquals("Failed to get Saved getUpdatedBy ", "bs2796@xxx.com", modelType.updatedBy) } - } @Test @@ -98,7 +101,6 @@ class ModelTypeServiceTest { Assert.assertNotNull("Failed to search ResourceMapping by tags", dbModelTypes) Assert.assertTrue("Failed to search ResourceMapping by tags count", dbModelTypes.size > 0) } - } @Test @@ -118,7 +120,6 @@ class ModelTypeServiceTest { Assert.assertNotNull("Failed to find getModelTypeByDerivedFrom by tags", dbModelTypeByDerivedFroms) Assert.assertTrue("Failed to find getModelTypeByDerivedFrom by count", dbModelTypeByDerivedFroms.size > 0) } - } @Test @@ -126,7 +127,8 @@ class ModelTypeServiceTest { fun test04DeleteModelType() { runBlocking { log.info( - "************************ test03DeleteModelType ***********************") + "************************ test03DeleteModelType ***********************" + ) val dbResourceMapping = modelTypeHandler!!.getModelTypeByName(modelName) Assert.assertNotNull("Failed to get response for api call getModelByName ", dbResourceMapping) Assert.assertNotNull("Failed to get Id for api call getModelByName ", dbResourceMapping!!.modelName) @@ -134,5 +136,4 @@ class ModelTypeServiceTest { modelTypeHandler.deleteByModelName(dbResourceMapping.modelName) } } - -}
\ 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/mock/MockFilePart.kt b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/mock/MockFilePart.kt index 3165a6e2f..27949901c 100644 --- a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/mock/MockFilePart.kt +++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/mock/MockFilePart.kt @@ -30,11 +30,11 @@ import java.nio.file.Path class MockFilePart(private val fileName: String) : FilePart { val log = LoggerFactory.getLogger(MockFilePart::class.java)!! override fun content(): Flux<DataBuffer> { - TODO("not implemented") //To change body of created functions use File | Settings | File Templates. + TODO("not implemented") // To change body of created functions use File | Settings | File Templates. } override fun headers(): HttpHeaders { - TODO("not implemented") //To change body of created functions use File | Settings | File Templates. + TODO("not implemented") // To change body of created functions use File | Settings | File Templates. } override fun filename(): String { @@ -46,8 +46,8 @@ class MockFilePart(private val fileName: String) : FilePart { } override fun transferTo(path: Path): Mono<Void> { - log.info("Copying file($fileName to ${path}") + log.info("Copying file($fileName to $path") FileCopyUtils.copy(File(fileName), path.toFile()) return Mono.empty() } -}
\ 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/repository/ModelTypeReactRepositoryTest.kt b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/repository/ModelTypeReactRepositoryTest.kt index 3dfed1ccb..4b771c0a6 100644 --- a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/repository/ModelTypeReactRepositoryTest.kt +++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/repository/ModelTypeReactRepositoryTest.kt @@ -25,17 +25,17 @@ import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintPropertiesService import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintPropertyConfiguration import org.onap.ccsdk.cds.blueprintsprocessor.db.BluePrintDBLibConfiguration import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.DesignerApiTestConfiguration +import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.domain.ModelType import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants import org.onap.ccsdk.cds.controllerblueprints.core.normalizedFile import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils -import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.domain.ModelType import org.springframework.beans.factory.annotation.Autowired import org.springframework.test.annotation.Commit import org.springframework.test.context.ContextConfiguration import org.springframework.test.context.TestPropertySource import org.springframework.test.context.junit4.SpringRunner import java.nio.charset.Charset -import java.util.* +import java.util.Arrays /** * ModelTypeReactRepositoryTest. @@ -44,8 +44,10 @@ import java.util.* */ @RunWith(SpringRunner::class) -@ContextConfiguration(classes = [DesignerApiTestConfiguration::class, - BluePrintPropertyConfiguration::class, BluePrintPropertiesService::class, BluePrintDBLibConfiguration::class]) +@ContextConfiguration( + classes = [DesignerApiTestConfiguration::class, + BluePrintPropertyConfiguration::class, BluePrintPropertiesService::class, BluePrintDBLibConfiguration::class] +) @TestPropertySource(locations = ["classpath:application-test.properties"]) @FixMethodOrder(MethodSorters.NAME_ASCENDING) class ModelTypeReactRepositoryTest { @@ -59,7 +61,7 @@ class ModelTypeReactRepositoryTest { @Commit fun test01Save() { val content = normalizedFile("./src/test/resources/model_type/data_type/datatype-property.json") - .readText(Charset.defaultCharset()) + .readText(Charset.defaultCharset()) val modelType = ModelType() modelType.definitionType = BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE modelType.derivedFrom = BluePrintConstants.MODEL_TYPE_DATATYPES_ROOT @@ -67,8 +69,8 @@ class ModelTypeReactRepositoryTest { modelType.definition = JacksonUtils.jsonNode(content) modelType.modelName = modelName modelType.version = "1.0.0" - modelType.tags = ("test-datatype ," + BluePrintConstants.MODEL_TYPE_DATATYPES_ROOT + "," - + BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE) + modelType.tags = ("test-datatype ," + BluePrintConstants.MODEL_TYPE_DATATYPES_ROOT + "," + + BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE) modelType.updatedBy = "xxxxxx@xxx.com" val dbModelType = modelTypeReactRepository!!.save(modelType).block() @@ -80,7 +82,8 @@ class ModelTypeReactRepositoryTest { val dbFindByModelName = modelTypeReactRepository!!.findByModelName(modelName).block() Assert.assertNotNull("Failed to findByModelName ", dbFindByModelName) - val dbFindByDefinitionType = modelTypeReactRepository.findByDefinitionType(BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE).collectList().block() + val dbFindByDefinitionType = + modelTypeReactRepository.findByDefinitionType(BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE).collectList().block() Assert.assertNotNull("Failed to findByDefinitionType ", dbFindByDefinitionType) Assert.assertTrue("Failed to findByDefinitionType count", dbFindByDefinitionType!!.size > 0) @@ -92,11 +95,13 @@ class ModelTypeReactRepositoryTest { Assert.assertNotNull("Failed to findByModelNameIn ", dbFindByModelNameIn) Assert.assertTrue("Failed to findByModelNameIn by count", dbFindByModelNameIn!!.size > 0) - val dbFindByDefinitionTypeIn = modelTypeReactRepository.findByDefinitionTypeIn(Arrays.asList(BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE)).collectList().block() + val dbFindByDefinitionTypeIn = + modelTypeReactRepository.findByDefinitionTypeIn(Arrays.asList(BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE)).collectList().block() Assert.assertNotNull("Failed to findByDefinitionTypeIn", dbFindByDefinitionTypeIn) Assert.assertTrue("Failed to findByDefinitionTypeIn by count", dbFindByDefinitionTypeIn!!.size > 0) - val dbFindByDerivedFromIn = modelTypeReactRepository.findByDerivedFromIn(Arrays.asList(BluePrintConstants.MODEL_TYPE_DATATYPES_ROOT)).collectList().block() + val dbFindByDerivedFromIn = + modelTypeReactRepository.findByDerivedFromIn(Arrays.asList(BluePrintConstants.MODEL_TYPE_DATATYPES_ROOT)).collectList().block() Assert.assertNotNull("Failed to find findByDerivedFromIn", dbFindByDerivedFromIn) Assert.assertTrue("Failed to find findByDerivedFromIn by count", dbFindByDerivedFromIn!!.size > 0) } @@ -106,5 +111,4 @@ class ModelTypeReactRepositoryTest { fun test03Delete() { modelTypeReactRepository!!.deleteByModelName(modelName).block() } - } diff --git a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/repository/ResourceDictionaryRepositoryTest.kt b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/repository/ResourceDictionaryReactRepositoryTest.kt index 6351f6aa0..0534afa2a 100644 --- a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/repository/ResourceDictionaryRepositoryTest.kt +++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/repository/ResourceDictionaryReactRepositoryTest.kt @@ -36,8 +36,10 @@ import org.springframework.test.context.junit4.SpringRunner import org.springframework.transaction.annotation.Transactional @RunWith(SpringRunner::class) -@ContextConfiguration(classes = [DesignerApiTestConfiguration::class, - BluePrintPropertyConfiguration::class, BluePrintPropertiesService::class, BluePrintDBLibConfiguration::class]) +@ContextConfiguration( + classes = [DesignerApiTestConfiguration::class, + BluePrintPropertyConfiguration::class, BluePrintPropertiesService::class, BluePrintDBLibConfiguration::class] +) @TestPropertySource(locations = ["classpath:application-test.properties"]) @FixMethodOrder(MethodSorters.NAME_ASCENDING) class ResourceDictionaryReactRepositoryTest { @@ -51,8 +53,10 @@ class ResourceDictionaryReactRepositoryTest { @Commit fun test01Save() { val resourceDefinition = JacksonUtils - .readValueFromFile("./../../../../../components/model-catalog/resource-dictionary/starter-dictionary/sample-db-source.json", - ResourceDefinition::class.java) + .readValueFromFile( + "./../../../../../components/model-catalog/resource-dictionary/starter-dictionary/sample-db-source.json", + ResourceDefinition::class.java + ) Assert.assertNotNull("Failed to get resourceDefinition from content", resourceDefinition) resourceDefinition!!.name = sourceName diff --git a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/utils/BluePrintEnhancerUtilsTest.kt b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/utils/BluePrintEnhancerUtilsTest.kt index 10bf887f6..c644aeedd 100644 --- a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/utils/BluePrintEnhancerUtilsTest.kt +++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/utils/BluePrintEnhancerUtilsTest.kt @@ -21,8 +21,12 @@ import org.junit.After import org.junit.Before import org.junit.Test import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.mock.MockFilePart -import org.onap.ccsdk.cds.controllerblueprints.core.* -import java.util.* +import org.onap.ccsdk.cds.controllerblueprints.core.compress +import org.onap.ccsdk.cds.controllerblueprints.core.deleteDir +import org.onap.ccsdk.cds.controllerblueprints.core.normalizedFile +import org.onap.ccsdk.cds.controllerblueprints.core.normalizedPathName +import org.onap.ccsdk.cds.controllerblueprints.core.reCreateDirs +import java.util.UUID import kotlin.test.assertTrue class BluePrintEnhancerUtilsTest { @@ -30,7 +34,7 @@ class BluePrintEnhancerUtilsTest { private val blueprintDir = "./../../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration" private val blueprintArchivePath: String = "./target/blueprints/archive" private val blueprintEnrichmentPath: String = "./target/blueprints/enrichment" - private var zipBlueprintFileName = normalizedPathName(blueprintArchivePath, "test.zip") + private var zipBlueprintFileName = normalizedPathName(blueprintArchivePath, "test.zip") @Before fun setUp() { @@ -62,4 +66,3 @@ class BluePrintEnhancerUtilsTest { } } } - diff --git a/ms/blueprintsprocessor/modules/inbounds/health-api-common/pom.xml b/ms/blueprintsprocessor/modules/inbounds/health-api-common/pom.xml index 2bd6782a7..3b3fec4d1 100644 --- a/ms/blueprintsprocessor/modules/inbounds/health-api-common/pom.xml +++ b/ms/blueprintsprocessor/modules/inbounds/health-api-common/pom.xml @@ -27,7 +27,7 @@ <artifactId>health-api-common</artifactId> <packaging>jar</packaging> - <name>Blueprints Processor Health API common </name> + <name>Blueprints Processor Health API common</name> <description>checking system check health endpoints</description> <dependencies> @@ -36,7 +36,6 @@ <artifactId>rest-lib</artifactId> </dependency> - <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> diff --git a/ms/blueprintsprocessor/modules/inbounds/health-api-common/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/configuration/BasicAuthRestClientServiceConfiguration.kt b/ms/blueprintsprocessor/modules/inbounds/health-api-common/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/configuration/BasicAuthRestClientServiceConfiguration.kt index 0c6099a1a..ead1f3b78 100644 --- a/ms/blueprintsprocessor/modules/inbounds/health-api-common/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/configuration/BasicAuthRestClientServiceConfiguration.kt +++ b/ms/blueprintsprocessor/modules/inbounds/health-api-common/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/configuration/BasicAuthRestClientServiceConfiguration.kt @@ -45,5 +45,4 @@ open class BasicAuthRestClientServiceConfiguration(private val securityConfigura open fun getBasicAuthRestClientService(): BasicAuthRestClientService { return BasicAuthRestClientService(getBasicAuthRestClientProperties()) } - } diff --git a/ms/blueprintsprocessor/modules/inbounds/health-api-common/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/configuration/HealthCheckProperties.kt b/ms/blueprintsprocessor/modules/inbounds/health-api-common/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/configuration/HealthCheckProperties.kt index c63952d80..080a26e6f 100644 --- a/ms/blueprintsprocessor/modules/inbounds/health-api-common/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/configuration/HealthCheckProperties.kt +++ b/ms/blueprintsprocessor/modules/inbounds/health-api-common/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/configuration/HealthCheckProperties.kt @@ -54,7 +54,6 @@ open class HealthCheckProperties { open fun getCDSListenerServiceInformation(): List<ServiceEndpoint> { val serviceName = ServiceName.BLUEPRINT return getListOfServiceEndPoints(cdsListenerServiceMapping, serviceName) - } private fun getListOfServiceEndPoints(serviceMapping: List<String>?, serviceName: ServiceName): MutableList<ServiceEndpoint> { @@ -67,7 +66,7 @@ open class HealthCheckProperties { return serviceEndpoints } - private fun fillListOfService(serviceName: ServiceName , element: String, listOfCDSListenerServiceEndpoint: MutableList<ServiceEndpoint>) { + private fun fillListOfService(serviceName: ServiceName, element: String, listOfCDSListenerServiceEndpoint: MutableList<ServiceEndpoint>) { val serviceEndpointInfo = element.split(",/") val serviceEndpoint = getServiceEndpoint(serviceEndpointInfo) if (serviceName.equals(ServiceName.CDSLISTENER)) @@ -77,16 +76,15 @@ open class HealthCheckProperties { listOfCDSListenerServiceEndpoint.add(serviceEndpoint) } - private fun getServiceEndpoint(serviceEndpointInfo: List<String>): ServiceEndpoint { - return ServiceEndpoint(removeSpecialCharacter(serviceEndpointInfo.get(0)) - , removeSpecialCharacter(serviceEndpointInfo.get(1)) + return ServiceEndpoint( + removeSpecialCharacter(serviceEndpointInfo.get(0)), removeSpecialCharacter(serviceEndpointInfo.get(1)) ) } - private fun removeSpecialCharacter(value:String):String{ - return value.replaceFirst(",[","") - .replace("[","") - .replace("]","") + private fun removeSpecialCharacter(value: String): String { + return value.replaceFirst(",[", "") + .replace("[", "") + .replace("]", "") } } diff --git a/ms/blueprintsprocessor/modules/inbounds/health-api-common/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/configuration/SecurityEncryptionConfiguration.kt b/ms/blueprintsprocessor/modules/inbounds/health-api-common/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/configuration/SecurityEncryptionConfiguration.kt index 94021207a..8b319fc43 100644 --- a/ms/blueprintsprocessor/modules/inbounds/health-api-common/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/configuration/SecurityEncryptionConfiguration.kt +++ b/ms/blueprintsprocessor/modules/inbounds/health-api-common/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/configuration/SecurityEncryptionConfiguration.kt @@ -16,17 +16,15 @@ package org.onap.ccsdk.cds.blueprintsprocessor.healthapi.configuration - import org.apache.commons.net.util.Base64 import org.springframework.stereotype.Component -import org.springframework.stereotype.Service import javax.crypto.Cipher import javax.crypto.spec.IvParameterSpec import javax.crypto.spec.SecretKeySpec - @Component class SecurityEncryptionConfiguration { + private val key = "aesEncryptionKey" private val initVector = "encryptionIntVec" diff --git a/ms/blueprintsprocessor/modules/inbounds/health-api-common/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/domain/ApplicationHealth.kt b/ms/blueprintsprocessor/modules/inbounds/health-api-common/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/domain/ApplicationHealth.kt index f66e8774c..f6ce829c1 100644 --- a/ms/blueprintsprocessor/modules/inbounds/health-api-common/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/domain/ApplicationHealth.kt +++ b/ms/blueprintsprocessor/modules/inbounds/health-api-common/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/domain/ApplicationHealth.kt @@ -21,5 +21,3 @@ import org.springframework.boot.actuate.health.Status data class ApplicationHealth(val status: Status?, val details: Map<String, Any>?) { constructor() : this(null, HashMap()) } - - diff --git a/ms/blueprintsprocessor/modules/inbounds/health-api-common/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/domain/HealthApiResponse.kt b/ms/blueprintsprocessor/modules/inbounds/health-api-common/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/domain/HealthApiResponse.kt index 61d8120d4..285dc0878 100644 --- a/ms/blueprintsprocessor/modules/inbounds/health-api-common/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/domain/HealthApiResponse.kt +++ b/ms/blueprintsprocessor/modules/inbounds/health-api-common/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/domain/HealthApiResponse.kt @@ -16,8 +16,7 @@ package org.onap.ccsdk.cds.blueprintsprocessor.healthapi.domain - -data class HealthApiResponse(val status: HealthCheckStatus, val checks: List<ServicesCheckResponse> +data class HealthApiResponse( + val status: HealthCheckStatus, + val checks: List<ServicesCheckResponse> ) - - diff --git a/ms/blueprintsprocessor/modules/inbounds/health-api-common/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/domain/Metrics.kt b/ms/blueprintsprocessor/modules/inbounds/health-api-common/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/domain/Metrics.kt index d9f1c79d4..ceb92d1b4 100644 --- a/ms/blueprintsprocessor/modules/inbounds/health-api-common/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/domain/Metrics.kt +++ b/ms/blueprintsprocessor/modules/inbounds/health-api-common/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/domain/Metrics.kt @@ -16,7 +16,6 @@ package org.onap.ccsdk.cds.blueprintsprocessor.healthapi.domain - data class Metrics(val names: ArrayList<Any>?) { constructor() : this(ArrayList()) } diff --git a/ms/blueprintsprocessor/modules/inbounds/health-api-common/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/domain/MetricsResponse.kt b/ms/blueprintsprocessor/modules/inbounds/health-api-common/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/domain/MetricsResponse.kt index b3796c91a..f58a31e8c 100644 --- a/ms/blueprintsprocessor/modules/inbounds/health-api-common/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/domain/MetricsResponse.kt +++ b/ms/blueprintsprocessor/modules/inbounds/health-api-common/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/domain/MetricsResponse.kt @@ -16,6 +16,4 @@ package org.onap.ccsdk.cds.blueprintsprocessor.healthapi.domain -data class MetricsResponse(val maps: HashMap<String, String>) { - -} +data class MetricsResponse(val maps: HashMap<String, String>) diff --git a/ms/blueprintsprocessor/modules/inbounds/health-api-common/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/domain/ServiceEndpoint.kt b/ms/blueprintsprocessor/modules/inbounds/health-api-common/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/domain/ServiceEndpoint.kt index ce95a5c0c..badd772c4 100644 --- a/ms/blueprintsprocessor/modules/inbounds/health-api-common/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/domain/ServiceEndpoint.kt +++ b/ms/blueprintsprocessor/modules/inbounds/health-api-common/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/domain/ServiceEndpoint.kt @@ -15,5 +15,4 @@ */ package org.onap.ccsdk.cds.blueprintsprocessor.healthapi.domain - data class ServiceEndpoint(val serviceName: String, var serviceLink: String) diff --git a/ms/blueprintsprocessor/modules/inbounds/health-api-common/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/domain/ServiceName.kt b/ms/blueprintsprocessor/modules/inbounds/health-api-common/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/domain/ServiceName.kt index 1a78a5d10..3e984b3b6 100644 --- a/ms/blueprintsprocessor/modules/inbounds/health-api-common/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/domain/ServiceName.kt +++ b/ms/blueprintsprocessor/modules/inbounds/health-api-common/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/domain/ServiceName.kt @@ -17,5 +17,5 @@ package org.onap.ccsdk.cds.blueprintsprocessor.healthapi.domain enum class ServiceName(s: String) { - BLUEPRINT("Blue Print service"),CDSLISTENER("CDS Listener service") + BLUEPRINT("Blue Print service"), CDSLISTENER("CDS Listener service") } diff --git a/ms/blueprintsprocessor/modules/inbounds/health-api-common/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/domain/ServicesCheckResponse.kt b/ms/blueprintsprocessor/modules/inbounds/health-api-common/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/domain/ServicesCheckResponse.kt index 391d7f38a..908007523 100644 --- a/ms/blueprintsprocessor/modules/inbounds/health-api-common/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/domain/ServicesCheckResponse.kt +++ b/ms/blueprintsprocessor/modules/inbounds/health-api-common/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/domain/ServicesCheckResponse.kt @@ -16,7 +16,4 @@ package org.onap.ccsdk.cds.blueprintsprocessor.healthapi.domain - data class ServicesCheckResponse(val name: String, val status: HealthCheckStatus) - - diff --git a/ms/blueprintsprocessor/modules/inbounds/health-api-common/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/domain/WebClientEnpointResponse.kt b/ms/blueprintsprocessor/modules/inbounds/health-api-common/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/domain/WebClientEnpointResponse.kt index 03e864a9d..1e7e670b5 100644 --- a/ms/blueprintsprocessor/modules/inbounds/health-api-common/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/domain/WebClientEnpointResponse.kt +++ b/ms/blueprintsprocessor/modules/inbounds/health-api-common/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/domain/WebClientEnpointResponse.kt @@ -18,5 +18,4 @@ package org.onap.ccsdk.cds.blueprintsprocessor.healthapi.domain import org.onap.ccsdk.cds.blueprintsprocessor.rest.service.BlueprintWebClientService -data class WebClientEnpointResponse (val response:BlueprintWebClientService.WebClientResponse<String>?) { -} +data class WebClientEnpointResponse(val response: BlueprintWebClientService.WebClientResponse<String>?) diff --git a/ms/blueprintsprocessor/modules/inbounds/health-api-common/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/service/EndPointExecution.kt b/ms/blueprintsprocessor/modules/inbounds/health-api-common/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/service/EndPointExecution.kt index 72fa6c849..9f526251e 100644 --- a/ms/blueprintsprocessor/modules/inbounds/health-api-common/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/service/EndPointExecution.kt +++ b/ms/blueprintsprocessor/modules/inbounds/health-api-common/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/service/EndPointExecution.kt @@ -16,7 +16,6 @@ package org.onap.ccsdk.cds.blueprintsprocessor.healthapi.service - import com.fasterxml.jackson.databind.ObjectMapper import org.onap.ccsdk.cds.blueprintsprocessor.healthapi.domain.ApplicationHealth import org.onap.ccsdk.cds.blueprintsprocessor.healthapi.domain.ServiceEndpoint @@ -35,8 +34,10 @@ import org.springframework.stereotype.Service * @version 1.0 */ @Service -open class EndPointExecution(private val basicAuthRestClientService: BasicAuthRestClientService - , private val restClientProperties: BasicAuthRestClientProperties) { +open class EndPointExecution( + private val basicAuthRestClientService: BasicAuthRestClientService, + private val restClientProperties: BasicAuthRestClientProperties +) { private var logger = LoggerFactory.getLogger(EndPointExecution::class.java) @@ -46,25 +47,21 @@ open class EndPointExecution(private val basicAuthRestClientService: BasicAuthRe val result = basicAuthRestClientService.exchangeResource(HttpMethod.GET.name, "", "") if (result.status == 200) return WebClientEnpointResponse(result) - } catch (e: Exception) { logger.error("service name ${serviceEndpoint.serviceName} is down ${e.message}") } - return WebClientEnpointResponse(BlueprintWebClientService.WebClientResponse(500,"")) + return WebClientEnpointResponse(BlueprintWebClientService.WebClientResponse(500, "")) } private fun addClientPropertiesConfiguration(serviceEndpoint: ServiceEndpoint) { restClientProperties.url = serviceEndpoint.serviceLink } - open fun getHealthFromWebClientEnpointResponse(webClientEnpointResponse: WebClientEnpointResponse): ApplicationHealth? { return mappingMetricsToDTO(webClientEnpointResponse?.response?.body.toString()) - } private fun mappingMetricsToDTO(body: String): ApplicationHealth { return ObjectMapper().readValue(body, ApplicationHealth::class.java) } } - diff --git a/ms/blueprintsprocessor/modules/inbounds/health-api-common/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/service/health/AbstractHealthCheck.kt b/ms/blueprintsprocessor/modules/inbounds/health-api-common/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/service/health/AbstractHealthCheck.kt index f793754e3..6d49ebe65 100644 --- a/ms/blueprintsprocessor/modules/inbounds/health-api-common/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/service/health/AbstractHealthCheck.kt +++ b/ms/blueprintsprocessor/modules/inbounds/health-api-common/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/service/health/AbstractHealthCheck.kt @@ -16,7 +16,11 @@ package org.onap.ccsdk.cds.blueprintsprocessor.healthapi.service.health -import org.onap.ccsdk.cds.blueprintsprocessor.healthapi.domain.* +import org.onap.ccsdk.cds.blueprintsprocessor.healthapi.domain.HealthApiResponse +import org.onap.ccsdk.cds.blueprintsprocessor.healthapi.domain.HealthCheckStatus +import org.onap.ccsdk.cds.blueprintsprocessor.healthapi.domain.ServiceEndpoint +import org.onap.ccsdk.cds.blueprintsprocessor.healthapi.domain.ServicesCheckResponse +import org.onap.ccsdk.cds.blueprintsprocessor.healthapi.domain.WebClientEnpointResponse import org.onap.ccsdk.cds.blueprintsprocessor.healthapi.service.EndPointExecution import org.slf4j.LoggerFactory @@ -27,7 +31,7 @@ import org.slf4j.LoggerFactory * @author Shaaban Ebrahim * @version 1.0 */ -abstract class AbstractHealthCheck (private val endPointExecution: EndPointExecution) { +abstract class AbstractHealthCheck(private val endPointExecution: EndPointExecution) { private var logger = LoggerFactory.getLogger(BluePrintProcessorHealthCheck::class.java) @@ -45,10 +49,8 @@ abstract class AbstractHealthCheck (private val endPointExecution: EndPointExec } healthApiResponse = HealthApiResponse(systemStatus, listOfResponse) return healthApiResponse - } - private fun retrieveServiceStatus(serviceEndpoint: ServiceEndpoint): HealthCheckStatus { var serviceStatus: HealthCheckStatus = HealthCheckStatus.UP try { @@ -59,16 +61,13 @@ abstract class AbstractHealthCheck (private val endPointExecution: EndPointExec } catch (e: Exception) { logger.error("service name ${serviceEndpoint.serviceName} is down ${e.message}") serviceStatus = HealthCheckStatus.DOWN - } return serviceStatus } - open fun retrieveEndpointExecutionStatus(): HealthApiResponse { return retrieveSystemStatus(setupServiceEndpoint()) } abstract fun setupServiceEndpoint(): List<ServiceEndpoint> - } diff --git a/ms/blueprintsprocessor/modules/inbounds/health-api-common/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/service/health/BluePrintProcessorHealthCheck.kt b/ms/blueprintsprocessor/modules/inbounds/health-api-common/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/service/health/BluePrintProcessorHealthCheck.kt index d661b32b5..dddad52e2 100644 --- a/ms/blueprintsprocessor/modules/inbounds/health-api-common/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/service/health/BluePrintProcessorHealthCheck.kt +++ b/ms/blueprintsprocessor/modules/inbounds/health-api-common/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/service/health/BluePrintProcessorHealthCheck.kt @@ -28,9 +28,11 @@ import org.springframework.stereotype.Service * @version 1.0 */ @Service -open class BluePrintProcessorHealthCheck(private val endPointExecution: EndPointExecution - , private val healthCheckProperties: HealthCheckProperties) - : AbstractHealthCheck(endPointExecution) { +open class BluePrintProcessorHealthCheck( + private val endPointExecution: EndPointExecution, + private val healthCheckProperties: HealthCheckProperties +) : + AbstractHealthCheck(endPointExecution) { override fun setupServiceEndpoint(): List<ServiceEndpoint> { return healthCheckProperties.getBluePrintServiceInformation() diff --git a/ms/blueprintsprocessor/modules/inbounds/health-api-common/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/service/health/SDCListenerHealthCheck.kt b/ms/blueprintsprocessor/modules/inbounds/health-api-common/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/service/health/SDCListenerHealthCheck.kt index 0a7c5e092..aa0d4d5f2 100644 --- a/ms/blueprintsprocessor/modules/inbounds/health-api-common/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/service/health/SDCListenerHealthCheck.kt +++ b/ms/blueprintsprocessor/modules/inbounds/health-api-common/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/service/health/SDCListenerHealthCheck.kt @@ -17,14 +17,8 @@ package org.onap.ccsdk.cds.blueprintsprocessor.healthapi.service.health import org.onap.ccsdk.cds.blueprintsprocessor.healthapi.configuration.HealthCheckProperties -import org.onap.ccsdk.cds.blueprintsprocessor.healthapi.domain.HealthApiResponse -import org.onap.ccsdk.cds.blueprintsprocessor.healthapi.domain.HealthCheckStatus import org.onap.ccsdk.cds.blueprintsprocessor.healthapi.domain.ServiceEndpoint -import org.onap.ccsdk.cds.blueprintsprocessor.healthapi.domain.ServicesCheckResponse import org.onap.ccsdk.cds.blueprintsprocessor.healthapi.service.EndPointExecution -import org.onap.ccsdk.cds.blueprintsprocessor.rest.service.BlueprintWebClientService -import org.slf4j.LoggerFactory -import org.springframework.beans.factory.annotation.Autowired import org.springframework.stereotype.Service /** @@ -34,13 +28,13 @@ import org.springframework.stereotype.Service * @version 1.0 */ @Service -open class SDCListenerHealthCheck (private val endPointExecution: EndPointExecution - ,private val healthCheckProperties: HealthCheckProperties) - : AbstractHealthCheck(endPointExecution) { +open class SDCListenerHealthCheck( + private val endPointExecution: EndPointExecution, + private val healthCheckProperties: HealthCheckProperties +) : + AbstractHealthCheck(endPointExecution) { override fun setupServiceEndpoint(): List<ServiceEndpoint> { return healthCheckProperties.getCDSListenerServiceInformation() } - - } diff --git a/ms/blueprintsprocessor/modules/inbounds/health-api-common/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/HealthCheckServiceTest.kt b/ms/blueprintsprocessor/modules/inbounds/health-api-common/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/HealthCheckServiceTest.kt index c4a8d1235..e3ba72428 100644 --- a/ms/blueprintsprocessor/modules/inbounds/health-api-common/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/HealthCheckServiceTest.kt +++ b/ms/blueprintsprocessor/modules/inbounds/health-api-common/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/HealthCheckServiceTest.kt @@ -16,25 +16,18 @@ package org.onap.ccsdk.cds.blueprintsprocessor.healthapi +import org.junit.Assert import org.junit.Assert.assertEquals import org.junit.Assert.assertNotNull -import org.mockito.ArgumentMatchers.any -import org.mockito.ArgumentMatchers.eq -import org.mockito.Mockito.anyString -import org.mockito.Mockito.mock - -import java.util.Arrays -import org.junit.Assert import org.junit.Before import org.junit.Test import org.junit.runner.RunWith -import org.mockito.ArgumentMatchers import org.mockito.InjectMocks import org.mockito.Mock import org.mockito.Mockito +import org.mockito.Mockito.anyString import org.mockito.junit.MockitoJUnitRunner import org.onap.ccsdk.cds.blueprintsprocessor.healthapi.configuration.HealthCheckProperties -import org.onap.ccsdk.cds.blueprintsprocessor.healthapi.domain.HealthApiResponse import org.onap.ccsdk.cds.blueprintsprocessor.healthapi.domain.HealthCheckStatus import org.onap.ccsdk.cds.blueprintsprocessor.healthapi.domain.ServiceEndpoint import org.onap.ccsdk.cds.blueprintsprocessor.healthapi.service.EndPointExecution @@ -42,8 +35,7 @@ import org.onap.ccsdk.cds.blueprintsprocessor.healthapi.service.health.BluePrint import org.onap.ccsdk.cds.blueprintsprocessor.rest.BasicAuthRestClientProperties import org.onap.ccsdk.cds.blueprintsprocessor.rest.service.BasicAuthRestClientService import org.onap.ccsdk.cds.blueprintsprocessor.rest.service.BlueprintWebClientService -import org.onap.ccsdk.cds.blueprintsprocessor.rest.service.BlueprintWebClientService.WebClientResponse -import org.springframework.http.HttpMethod +import java.util.Arrays @RunWith(MockitoJUnitRunner::class) class HealthCheckServiceTest { @@ -62,106 +54,113 @@ class HealthCheckServiceTest { private var bluePrintProcessorHealthCheck: BluePrintProcessorHealthCheck? = null - @Before fun setup() { endPointExecution = Mockito.spy(endPointExecution!!) - Mockito.`when`(healthCheckProperties!!.getBluePrintServiceInformation()).thenReturn(Arrays.asList( + Mockito.`when`(healthCheckProperties!!.getBluePrintServiceInformation()).thenReturn( + Arrays.asList( ServiceEndpoint("Execution service ", "http://cds-blueprints-processor-http:8080/api/v1/execution-service/health-check"), - ServiceEndpoint("Resources service", "http://cds-blueprints-processor-http:8080/api/v1/resources/health-check"), ServiceEndpoint("Template service", "http://cds-blueprints-processor-http:8080/api/v1/template/health-check") - )) + ServiceEndpoint("Resources service", "http://cds-blueprints-processor-http:8080/api/v1/resources/health-check"), + ServiceEndpoint("Template service", "http://cds-blueprints-processor-http:8080/api/v1/template/health-check") + ) + ) bluePrintProcessorHealthCheck = BluePrintProcessorHealthCheck(endPointExecution!!, healthCheckProperties) } - @Test + @Test fun testSystemIsCompletelyDown() { - Mockito.`when`(basicAuthRestClientService!!.exchangeResource( - anyString(), - anyString(), - anyString())).thenThrow(RuntimeException()) + Mockito.`when`( + basicAuthRestClientService!!.exchangeResource( + anyString(), + anyString(), + anyString() + ) + ).thenThrow(RuntimeException()) val healthApiResponse = bluePrintProcessorHealthCheck!!.retrieveEndpointExecutionStatus() assertNotNull(healthApiResponse) Assert.assertEquals(HealthCheckStatus.DOWN, healthApiResponse.status) healthApiResponse.checks.forEach { serviceEndpoint -> assertNotNull(serviceEndpoint) assertEquals(HealthCheckStatus.DOWN, serviceEndpoint.status) - } - } @Test fun testSystemIsUPAndRunning() { - Mockito.`when`(basicAuthRestClientService!! - .exchangeResource( - anyString(), - anyString(), - anyString())).thenReturn(BlueprintWebClientService.WebClientResponse(200, "Success")) + Mockito.`when`( + basicAuthRestClientService!! + .exchangeResource( + anyString(), + anyString(), + anyString() + ) + ).thenReturn(BlueprintWebClientService.WebClientResponse(200, "Success")) val healthApiResponse = bluePrintProcessorHealthCheck!!.retrieveEndpointExecutionStatus() assertNotNull(healthApiResponse) assertEquals(HealthCheckStatus.UP, healthApiResponse.status) healthApiResponse.checks.forEach { serviceEndpoint -> assertNotNull(serviceEndpoint) assertEquals(HealthCheckStatus.UP, serviceEndpoint.status) - } - } @Test fun testServiceIsNotFound() { - Mockito.`when`(basicAuthRestClientService!!.exchangeResource( - anyString(), - anyString(), - anyString())).thenReturn(BlueprintWebClientService.WebClientResponse(404, "failure")) + Mockito.`when`( + basicAuthRestClientService!!.exchangeResource( + anyString(), + anyString(), + anyString() + ) + ).thenReturn(BlueprintWebClientService.WebClientResponse(404, "failure")) val healthApiResponse = bluePrintProcessorHealthCheck!!.retrieveEndpointExecutionStatus() assertNotNull(healthApiResponse) assertEquals(HealthCheckStatus.DOWN, healthApiResponse.status) healthApiResponse.checks.forEach { serviceEndpoint -> assertNotNull(serviceEndpoint) assertEquals(HealthCheckStatus.DOWN, serviceEndpoint.status) - } - } - @Test fun testServiceInternalServerError() { - Mockito.`when`(basicAuthRestClientService!!.exchangeResource( - anyString(), - anyString(), - anyString())) - .thenReturn(BlueprintWebClientService.WebClientResponse(500, "failure")) + Mockito.`when`( + basicAuthRestClientService!!.exchangeResource( + anyString(), + anyString(), + anyString() + ) + ) + .thenReturn(BlueprintWebClientService.WebClientResponse(500, "failure")) val healthApiResponse = bluePrintProcessorHealthCheck!!.retrieveEndpointExecutionStatus() assertNotNull(healthApiResponse) assertEquals(HealthCheckStatus.DOWN, healthApiResponse.status) healthApiResponse.checks.forEach { serviceEndpoint -> assertNotNull(serviceEndpoint) assertEquals(HealthCheckStatus.DOWN, serviceEndpoint.status) - } - } @Test fun testServiceIsRedirected() { - Mockito.`when`(basicAuthRestClientService!!. - exchangeResource( - anyString(), - anyString(), - anyString())) - .thenReturn(BlueprintWebClientService.WebClientResponse(300, "failure")) + Mockito.`when`( + basicAuthRestClientService!! + .exchangeResource( + anyString(), + anyString(), + anyString() + ) + ) + .thenReturn(BlueprintWebClientService.WebClientResponse(300, "failure")) val healthApiResponse = bluePrintProcessorHealthCheck!!.retrieveEndpointExecutionStatus() assertNotNull(healthApiResponse) assertEquals(HealthCheckStatus.DOWN, healthApiResponse.status) healthApiResponse.checks.forEach { serviceEndpoint -> assertNotNull(serviceEndpoint) assertEquals(HealthCheckStatus.DOWN, serviceEndpoint.status) - } } } diff --git a/ms/blueprintsprocessor/modules/inbounds/health-api-common/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/SecurityConfigurationTest.kt b/ms/blueprintsprocessor/modules/inbounds/health-api-common/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/SecurityConfigurationTest.kt index e1f7abdb7..54becbadf 100644 --- a/ms/blueprintsprocessor/modules/inbounds/health-api-common/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/SecurityConfigurationTest.kt +++ b/ms/blueprintsprocessor/modules/inbounds/health-api-common/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/SecurityConfigurationTest.kt @@ -20,7 +20,6 @@ import org.junit.Assert import org.junit.Test import org.onap.ccsdk.cds.blueprintsprocessor.healthapi.configuration.SecurityEncryptionConfiguration - class SecurityConfigurationTest { @Test diff --git a/ms/blueprintsprocessor/modules/inbounds/health-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/controller/CombinedHealth.kt b/ms/blueprintsprocessor/modules/inbounds/health-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/controller/CombinedHealth.kt index 54c85a0fc..531a275fa 100644 --- a/ms/blueprintsprocessor/modules/inbounds/health-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/controller/CombinedHealth.kt +++ b/ms/blueprintsprocessor/modules/inbounds/health-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/controller/CombinedHealth.kt @@ -35,18 +35,20 @@ import org.springframework.web.bind.annotation.RestController */ @RestController @RequestMapping("/api/v1/combinedHealth") -@Api(value = "/api/v1/combinedHealth", - description = "gather all HealthCheckResponses for HealthChecks known to the runtime") +@Api( + value = "/api/v1/combinedHealth", + description = "gather all HealthCheckResponses for HealthChecks known to the runtime" +) open class CombinedHealth(private val combinedHealthService: CombinedHealthService) { - @RequestMapping(path = [""], - method = [RequestMethod.GET], - produces = [MediaType.APPLICATION_JSON_VALUE]) + @RequestMapping( + path = [""], + method = [RequestMethod.GET], + produces = [MediaType.APPLICATION_JSON_VALUE] + ) @ResponseBody @ApiOperation(value = "Health Check", hidden = true) fun getSystemHealthCheckResponse(): ResponseEntity<List<ApplicationHealth?>> { return ResponseEntity.ok().body(combinedHealthService.getCombinedHealthCheck()) - } } - diff --git a/ms/blueprintsprocessor/modules/inbounds/health-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/controller/CombinedMetrics.kt b/ms/blueprintsprocessor/modules/inbounds/health-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/controller/CombinedMetrics.kt index 785def524..d2f02028c 100644 --- a/ms/blueprintsprocessor/modules/inbounds/health-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/controller/CombinedMetrics.kt +++ b/ms/blueprintsprocessor/modules/inbounds/health-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/controller/CombinedMetrics.kt @@ -35,18 +35,20 @@ import org.springframework.web.bind.annotation.RestController */ @RestController @RequestMapping("/api/v1/combinedMetrics") -@Api(value = "/api/v1/combinedMetrics", - description = "gather all Metrics info from BluePrint and CDSListener") +@Api( + value = "/api/v1/combinedMetrics", + description = "gather all Metrics info from BluePrint and CDSListener" +) open class CombinedMetrics(private val combinedMetricsService: CombinedMetricsService) { - @RequestMapping(path = [""], - method = [RequestMethod.GET], - produces = [MediaType.APPLICATION_JSON_VALUE]) + @RequestMapping( + path = [""], + method = [RequestMethod.GET], + produces = [MediaType.APPLICATION_JSON_VALUE] + ) @ResponseBody @ApiOperation(value = " Metrics Check", hidden = true) fun getMetricsHealthCheckResponse(): ResponseEntity<MetricsInfo?> { return ResponseEntity.ok().body(combinedMetricsService.metricsInfo) - } - } diff --git a/ms/blueprintsprocessor/modules/inbounds/health-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/service/CombinedHealthService.kt b/ms/blueprintsprocessor/modules/inbounds/health-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/service/CombinedHealthService.kt index 786048ce4..f4c3e93bf 100644 --- a/ms/blueprintsprocessor/modules/inbounds/health-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/service/CombinedHealthService.kt +++ b/ms/blueprintsprocessor/modules/inbounds/health-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/service/CombinedHealthService.kt @@ -22,7 +22,6 @@ import org.onap.ccsdk.cds.blueprintsprocessor.healthapi.domain.WebClientEnpointR import org.springframework.boot.actuate.health.Status import org.springframework.stereotype.Service - /** *Service for combined health (BluePrintProcessor and CDSListener) * @@ -30,13 +29,15 @@ import org.springframework.stereotype.Service * @version 1.0 */ @Service -open class CombinedHealthService(private val endPointExecution: EndPointExecution - , private val healthCheckProperties: HealthCheckProperties) { +open class CombinedHealthService( + private val endPointExecution: EndPointExecution, + private val healthCheckProperties: HealthCheckProperties +) { private fun setupServiceEndpoint(): List<ServiceEndpoint> { return listOf( - ServiceEndpoint("BluePrintProcessor Health Check ", healthCheckProperties.getBluePrintBaseURL() + "actuator/health") - , ServiceEndpoint("CDSListener Health Check", healthCheckProperties.getCDSListenerBaseURL() + "actuator/health") + ServiceEndpoint("BluePrintProcessor Health Check ", healthCheckProperties.getBluePrintBaseURL() + "actuator/health"), + ServiceEndpoint("CDSListener Health Check", healthCheckProperties.getCDSListenerBaseURL() + "actuator/health") ) } @@ -45,14 +46,18 @@ open class CombinedHealthService(private val endPointExecution: EndPointExecutio for (serviceEndpoint in setupServiceEndpoint().parallelStream()) { val result: WebClientEnpointResponse? = endPointExecution?.retrieveWebClientResponse(serviceEndpoint) if (result?.response != null && - result.response!!.status?.equals(200)!!) { + result.response!!.status?.equals(200)!! + ) { listOfResponse.add(endPointExecution?.getHealthFromWebClientEnpointResponse(result)) } else { - listOfResponse.add(ApplicationHealth(Status.DOWN, - hashMapOf(serviceEndpoint.serviceLink to serviceEndpoint.serviceLink))) + listOfResponse.add( + ApplicationHealth( + Status.DOWN, + hashMapOf(serviceEndpoint.serviceLink to serviceEndpoint.serviceLink) + ) + ) } } return listOfResponse } - } diff --git a/ms/blueprintsprocessor/modules/inbounds/health-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/service/CombinedMetricsService.kt b/ms/blueprintsprocessor/modules/inbounds/health-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/service/CombinedMetricsService.kt index a23c9925b..0a2e7ae24 100644 --- a/ms/blueprintsprocessor/modules/inbounds/health-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/service/CombinedMetricsService.kt +++ b/ms/blueprintsprocessor/modules/inbounds/health-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/service/CombinedMetricsService.kt @@ -16,7 +16,12 @@ package org.onap.ccsdk.cds.blueprintsprocessor.healthapi.service import org.onap.ccsdk.cds.blueprintsprocessor.healthapi.configuration.HealthCheckProperties -import org.onap.ccsdk.cds.blueprintsprocessor.healthapi.domain.* +import org.onap.ccsdk.cds.blueprintsprocessor.healthapi.domain.ActuatorCheckResponse +import org.onap.ccsdk.cds.blueprintsprocessor.healthapi.domain.HealthCheckStatus +import org.onap.ccsdk.cds.blueprintsprocessor.healthapi.domain.Metrics +import org.onap.ccsdk.cds.blueprintsprocessor.healthapi.domain.MetricsInfo +import org.onap.ccsdk.cds.blueprintsprocessor.healthapi.domain.MetricsResponse +import org.onap.ccsdk.cds.blueprintsprocessor.healthapi.domain.ServiceEndpoint import org.onap.ccsdk.cds.blueprintsprocessor.healthapi.utils.ObjectMappingUtils import org.onap.ccsdk.cds.blueprintsprocessor.rest.service.BlueprintWebClientService import org.springframework.stereotype.Service @@ -28,14 +33,16 @@ import org.springframework.stereotype.Service * @version 1.0 */ @Service -open class CombinedMetricsService(private val endPointExecution: EndPointExecution - , private val healthCheckProperties: HealthCheckProperties - , private val objectMappingUtils: ObjectMappingUtils<Metrics>) { +open class CombinedMetricsService( + private val endPointExecution: EndPointExecution, + private val healthCheckProperties: HealthCheckProperties, + private val objectMappingUtils: ObjectMappingUtils<Metrics> +) { private fun setupServiceEndpoint(): List<ServiceEndpoint> { return listOf( - ServiceEndpoint("BluePrintProcessor metrics", healthCheckProperties.getBluePrintBaseURL() + "/actuator/metrics") - , ServiceEndpoint("CDS Listener metrics", healthCheckProperties.getCDSListenerBaseURL() + "/actuator/metrics") + ServiceEndpoint("BluePrintProcessor metrics", healthCheckProperties.getBluePrintBaseURL() + "/actuator/metrics"), + ServiceEndpoint("CDS Listener metrics", healthCheckProperties.getCDSListenerBaseURL() + "/actuator/metrics") ) } @@ -46,7 +53,8 @@ open class CombinedMetricsService(private val endPointExecution: EndPointExecuti val webClientResponse = endPointExecution?.retrieveWebClientResponse(serviceEndpoint) var actuatorsHealthResponse: ActuatorCheckResponse? = null actuatorsHealthResponse = if (webClientResponse?.response != null && - webClientResponse.response!!.status?.equals(200)!!) { + webClientResponse.response!!.status?.equals(200)!! + ) { var body = gettingCustomizedBody(serviceEndpoint, webClientResponse.response!!) ActuatorCheckResponse(serviceEndpoint.serviceName, body) } else { @@ -57,7 +65,10 @@ open class CombinedMetricsService(private val endPointExecution: EndPointExecuti return MetricsInfo(containerHealthChecks) } - private fun gettingCustomizedBody(serviceEndpoint: ServiceEndpoint?, webClientResponse: BlueprintWebClientService.WebClientResponse<String>): Any { + private fun gettingCustomizedBody( + serviceEndpoint: ServiceEndpoint?, + webClientResponse: BlueprintWebClientService.WebClientResponse<String> + ): Any { var body: Any val metrics: Metrics = objectMappingUtils.getObjectFromBody(webClientResponse.body, Metrics::class.java) val mapOfMetricsInfo = HashMap<String, String>() @@ -69,4 +80,3 @@ open class CombinedMetricsService(private val endPointExecution: EndPointExecuti return body } } - diff --git a/ms/blueprintsprocessor/modules/inbounds/health-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/HealthCheckApplicationTests.kt b/ms/blueprintsprocessor/modules/inbounds/health-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/HealthCheckApplicationTests.kt index b1d629da7..5a1999ec1 100644 --- a/ms/blueprintsprocessor/modules/inbounds/health-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/HealthCheckApplicationTests.kt +++ b/ms/blueprintsprocessor/modules/inbounds/health-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/HealthCheckApplicationTests.kt @@ -16,7 +16,6 @@ package org.onap.ccsdk.cds.blueprintsprocessor.healthapi - import org.junit.Test import org.junit.runner.RunWith import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintCoreConfiguration @@ -40,8 +39,10 @@ import org.springframework.test.web.reactive.server.WebTestClient */ @RunWith(SpringRunner::class) @WebFluxTest -@ContextConfiguration(classes = [BluePrintRuntimeService::class, BluePrintCoreConfiguration::class, - BluePrintCatalogService::class, SecurityProperties::class, ComponentScriptExecutor::class]) +@ContextConfiguration( + classes = [BluePrintRuntimeService::class, BluePrintCoreConfiguration::class, + BluePrintCatalogService::class, SecurityProperties::class, ComponentScriptExecutor::class] +) @ComponentScan(basePackages = ["org.onap.ccsdk.cds.blueprintsprocessor", "org.onap.ccsdk.cds.controllerblueprints"]) @TestPropertySource(locations = ["classpath:application-test.properties"]) class HealthCheckApplicationTests { @@ -52,17 +53,14 @@ class HealthCheckApplicationTests { @Test fun testHealthApiUp() { webTestClient.get().uri("/api/v1/combinedHealth") - .exchange() - .expectStatus().is2xxSuccessful - + .exchange() + .expectStatus().is2xxSuccessful } @Test fun testMetricsApiUp() { webTestClient.get().uri("/api/v1/combinedMetrics") - .exchange() - .expectStatus().is2xxSuccessful + .exchange() + .expectStatus().is2xxSuccessful } - - } diff --git a/ms/blueprintsprocessor/modules/inbounds/pom.xml b/ms/blueprintsprocessor/modules/inbounds/pom.xml index 6dc39a7ff..81fe3af4e 100644 --- a/ms/blueprintsprocessor/modules/inbounds/pom.xml +++ b/ms/blueprintsprocessor/modules/inbounds/pom.xml @@ -53,7 +53,6 @@ <artifactId>resource-resolution</artifactId> </dependency> - <!-- Test Dependencies --> <dependency> <groupId>io.mockk</groupId> diff --git a/ms/blueprintsprocessor/modules/inbounds/resource-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/resource/api/ResourceController.kt b/ms/blueprintsprocessor/modules/inbounds/resource-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/resource/api/ResourceController.kt index 3a708a973..b49ca68ed 100644 --- a/ms/blueprintsprocessor/modules/inbounds/resource-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/resource/api/ResourceController.kt +++ b/ms/blueprintsprocessor/modules/inbounds/resource-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/resource/api/ResourceController.kt @@ -27,31 +27,43 @@ import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils import org.springframework.http.MediaType import org.springframework.http.ResponseEntity import org.springframework.security.access.prepost.PreAuthorize -import org.springframework.web.bind.annotation.* +import org.springframework.web.bind.annotation.RequestMapping +import org.springframework.web.bind.annotation.RequestMethod +import org.springframework.web.bind.annotation.RequestParam +import org.springframework.web.bind.annotation.ResponseBody +import org.springframework.web.bind.annotation.RestController @RestController @RequestMapping("/api/v1/resources") -@Api(value = "/api/v1/resources", - description = "Interaction with resolved resources.") +@Api( + value = "/api/v1/resources", + description = "Interaction with resolved resources." +) open class ResourceController(private var resourceResolutionDBService: ResourceResolutionDBService) { - @RequestMapping(path = ["/health-check"], + @RequestMapping( + path = ["/health-check"], method = [RequestMethod.GET], - produces = [MediaType.APPLICATION_JSON_VALUE]) + produces = [MediaType.APPLICATION_JSON_VALUE] + ) @ResponseBody @ApiOperation(value = "Health Check", hidden = true) fun resourceControllerHealthCheck(): JsonNode = runBlocking { JacksonUtils.getJsonNode("Success") } - @RequestMapping(path = [""], - method = [RequestMethod.GET], produces = [MediaType.APPLICATION_JSON_VALUE]) - @ApiOperation(value = "Get all resolved resources using the resolution key. ", + @RequestMapping( + path = [""], + method = [RequestMethod.GET], produces = [MediaType.APPLICATION_JSON_VALUE] + ) + @ApiOperation( + value = "Get all resolved resources using the resolution key. ", notes = "Retrieve all stored resolved resources using the blueprint name, blueprint version, " + "artifact name and the resolution-key.", response = ResourceResolution::class, responseContainer = "List", - produces = MediaType.APPLICATION_JSON_VALUE) + produces = MediaType.APPLICATION_JSON_VALUE + ) @ResponseBody @PreAuthorize("hasRole('USER')") fun getAllFromResolutionKeyOrFromResourceTypeAndId( @@ -66,8 +78,9 @@ open class ResourceController(private var resourceResolutionDBService: ResourceR @ApiParam(value = "Resource Type associated with the resolution.", required = false) @RequestParam(value = "resourceType", required = false, defaultValue = "") resourceType: String, @ApiParam(value = "Resource Id associated with the resolution.", required = false) - @RequestParam(value = "resourceId", required = false, defaultValue = "") resourceId: String) - : ResponseEntity<List<ResourceResolution>> = runBlocking { + @RequestParam(value = "resourceId", required = false, defaultValue = "") resourceId: String + ): + ResponseEntity<List<ResourceResolution>> = runBlocking { if ((resolutionKey.isNotEmpty() || artifactName.isNotEmpty()) && (resourceId.isNotEmpty() || resourceType.isNotEmpty())) { throw ResolutionException("Either retrieve resolved value using artifact name and resolution-key OR using resource-id and resource-type.") @@ -76,36 +89,46 @@ open class ResourceController(private var resourceResolutionDBService: ResourceR .body(resourceResolutionDBService.readWithResolutionKey(bpName, bpVersion, artifactName, resolutionKey)) } else if (resourceType.isNotEmpty() && resourceId.isNotEmpty()) { ResponseEntity.ok() - .body(resourceResolutionDBService.readWithResourceIdAndResourceType(bpName, - bpVersion, - resourceId, - resourceType)) + .body( + resourceResolutionDBService.readWithResourceIdAndResourceType( + bpName, + bpVersion, + resourceId, + resourceType + ) + ) } else { throw ResolutionException("Missing param. Either retrieve resolved value using artifact name and resolution-key OR using resource-id and resource-type.") } } - @RequestMapping(path = ["/resource"], + @RequestMapping( + path = ["/resource"], method = [RequestMethod.GET], - produces = [MediaType.APPLICATION_JSON_VALUE]) - @ApiOperation(value = "Fetch a resource value using resolution key.", + produces = [MediaType.APPLICATION_JSON_VALUE] + ) + @ApiOperation( + value = "Fetch a resource value using resolution key.", notes = "Retrieve a stored resource value using the blueprint metadata, artifact name, resolution-key along with the name of the resource value to retrieve.", - produces = MediaType.APPLICATION_JSON_VALUE) + produces = MediaType.APPLICATION_JSON_VALUE + ) @ResponseBody @PreAuthorize("hasRole('USER')") - fun getOneFromResolutionKey(@ApiParam(value = "Name of the CBA.", required = true) - @RequestParam(value = "bpName", required = true) bpName: String, - @ApiParam(value = "Version of the CBA.", required = true) - @RequestParam(value = "bpVersion", required = true) bpVersion: String, - @ApiParam(value = "Artifact name for which to retrieve a resolved resource.", required = true) - @RequestParam(value = "artifactName", required = true) artifactName: String, - @ApiParam(value = "Resolution Key associated with the resolution.", required = true) - @RequestParam(value = "resolutionKey", required = true) resolutionKey: String, - @ApiParam(value = "Name of the resource to retrieve.", required = true) - @RequestParam(value = "name", required = true) name: String) - : ResponseEntity<ResourceResolution> = runBlocking { + fun getOneFromResolutionKey( + @ApiParam(value = "Name of the CBA.", required = true) + @RequestParam(value = "bpName", required = true) bpName: String, + @ApiParam(value = "Version of the CBA.", required = true) + @RequestParam(value = "bpVersion", required = true) bpVersion: String, + @ApiParam(value = "Artifact name for which to retrieve a resolved resource.", required = true) + @RequestParam(value = "artifactName", required = true) artifactName: String, + @ApiParam(value = "Resolution Key associated with the resolution.", required = true) + @RequestParam(value = "resolutionKey", required = true) resolutionKey: String, + @ApiParam(value = "Name of the resource to retrieve.", required = true) + @RequestParam(value = "name", required = true) name: String + ): + ResponseEntity<ResourceResolution> = runBlocking { ResponseEntity.ok() .body(resourceResolutionDBService.readValue(bpName, bpVersion, artifactName, resolutionKey, name)) } -}
\ No newline at end of file +} diff --git a/ms/blueprintsprocessor/modules/inbounds/resource-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/resource/api/ResourceExceptionHandler.kt b/ms/blueprintsprocessor/modules/inbounds/resource-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/resource/api/ResourceExceptionHandler.kt index 42ff8016c..5d5623d4f 100644 --- a/ms/blueprintsprocessor/modules/inbounds/resource-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/resource/api/ResourceExceptionHandler.kt +++ b/ms/blueprintsprocessor/modules/inbounds/resource-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/resource/api/ResourceExceptionHandler.kt @@ -23,16 +23,16 @@ import com.fasterxml.jackson.annotation.JsonTypeName import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException import org.onap.ccsdk.cds.controllerblueprints.core.data.ErrorCode import org.slf4j.LoggerFactory +import org.springframework.dao.EmptyResultDataAccessException +import org.springframework.dao.IncorrectResultSizeDataAccessException import org.springframework.http.HttpStatus import org.springframework.http.ResponseEntity import org.springframework.orm.jpa.JpaObjectRetrievalFailureException -import org.springframework.dao.EmptyResultDataAccessException -import org.springframework.dao.IncorrectResultSizeDataAccessException -import org.springframework.web.server.ServerWebInputException import org.springframework.web.bind.annotation.ExceptionHandler import org.springframework.web.bind.annotation.RestControllerAdvice +import org.springframework.web.server.ServerWebInputException import java.io.Serializable -import java.util.* +import java.util.Date /** * Handle exceptions in Resolution API and provide relevant HTTP status codes and messages @@ -86,9 +86,11 @@ open class ResourceExceptionHandler { fun returnError(e: Exception, errorCode: ErrorCode): ResponseEntity<ErrorMessage> { log.error(e.message, e) val errorMessage = - ErrorMessage(errorCode.message(e.message!!), + ErrorMessage( + errorCode.message(e.message!!), errorCode.value, - debugMsg) + debugMsg + ) return ResponseEntity(errorMessage, HttpStatus.resolve(errorCode.httpCode)!!) } @@ -103,6 +105,7 @@ open class ResourceExceptionHandler { @JsonTypeName("errorMessage") @JsonTypeInfo(include = JsonTypeInfo.As.WRAPPER_OBJECT, use = JsonTypeInfo.Id.NAME) class ErrorMessage(var message: String?, var code: Int?, var debugMessage: String?) : Serializable { + @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") var timestamp = Date() -}
\ No newline at end of file +} diff --git a/ms/blueprintsprocessor/modules/inbounds/resource-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/resource/api/TemplateController.kt b/ms/blueprintsprocessor/modules/inbounds/resource-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/resource/api/TemplateController.kt index 93253a554..5913bde1d 100644 --- a/ms/blueprintsprocessor/modules/inbounds/resource-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/resource/api/TemplateController.kt +++ b/ms/blueprintsprocessor/modules/inbounds/resource-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/resource/api/TemplateController.kt @@ -27,7 +27,14 @@ import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils import org.springframework.http.MediaType import org.springframework.http.ResponseEntity import org.springframework.security.access.prepost.PreAuthorize -import org.springframework.web.bind.annotation.* +import org.springframework.web.bind.annotation.PathVariable +import org.springframework.web.bind.annotation.PostMapping +import org.springframework.web.bind.annotation.RequestBody +import org.springframework.web.bind.annotation.RequestMapping +import org.springframework.web.bind.annotation.RequestMethod +import org.springframework.web.bind.annotation.RequestParam +import org.springframework.web.bind.annotation.ResponseBody +import org.springframework.web.bind.annotation.RestController /** * Exposes Template Resolution API to store and retrieve rendered template results. @@ -37,26 +44,34 @@ import org.springframework.web.bind.annotation.* */ @RestController @RequestMapping("/api/v1/template") -@Api(value = "/api/v1/template", - description = "Interaction with resolved template.") +@Api( + value = "/api/v1/template", + description = "Interaction with resolved template." +) open class TemplateController(private val templateResolutionService: TemplateResolutionService) { - @RequestMapping(path = ["/health-check"], + @RequestMapping( + path = ["/health-check"], method = [RequestMethod.GET], - produces = [MediaType.APPLICATION_JSON_VALUE]) + produces = [MediaType.APPLICATION_JSON_VALUE] + ) @ResponseBody @ApiOperation(value = "Health Check", hidden = true) fun templateControllerHealthCheck(): JsonNode = runBlocking { JacksonUtils.getJsonNode("Success") } - @RequestMapping(path = [""], + @RequestMapping( + path = [""], method = [RequestMethod.GET], - produces = [MediaType.TEXT_PLAIN_VALUE, MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE]) - @ApiOperation(value = "Retrieve a resolved template.", + produces = [MediaType.TEXT_PLAIN_VALUE, MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE] + ) + @ApiOperation( + value = "Retrieve a resolved template.", notes = "Retrieve a config template for a given CBA's action, identified by its blueprint name, blueprint version, " + "artifact name and resolution key. An extra 'format' parameter can be passed to tell what content-type" + - " to expect in return") + " to expect in return" + ) @ResponseBody @PreAuthorize("hasRole('USER')") fun get( @@ -72,11 +87,14 @@ open class TemplateController(private val templateResolutionService: TemplateRes @RequestParam(value = "resourceType", required = false, defaultValue = "") resourceType: String, @ApiParam(value = "Resource Id associated with the resolution.", required = false) @RequestParam(value = "resourceId", required = false, defaultValue = "") resourceId: String, - @ApiParam(value = "Expected format of the template being retrieved.", + @ApiParam( + value = "Expected format of the template being retrieved.", defaultValue = MediaType.TEXT_PLAIN_VALUE, - required = true) - @RequestParam(value = "format", required = false, defaultValue = MediaType.TEXT_PLAIN_VALUE) format: String) - : ResponseEntity<String> = runBlocking { + required = true + ) + @RequestParam(value = "format", required = false, defaultValue = MediaType.TEXT_PLAIN_VALUE) format: String + ): + ResponseEntity<String> = runBlocking { var result = "" @@ -87,7 +105,8 @@ open class TemplateController(private val templateResolutionService: TemplateRes bpName, bpVersion, artifactName, - resolutionKey) + resolutionKey + ) } else if (resourceType.isNotEmpty() && resourceId.isNotEmpty()) { result = templateResolutionService.findByResoureIdAndResourceTypeAndBlueprintNameAndBlueprintVersionAndArtifactName( @@ -95,12 +114,12 @@ open class TemplateController(private val templateResolutionService: TemplateRes bpVersion, artifactName, resourceId, - resourceType) + resourceType + ) } else { throw ResolutionException("Missing param. Either retrieve resolved template using artifact name and resolution-key OR using resource-id and resource-type.") } - var expectedContentType = format if (expectedContentType.indexOf('/') < 0) { expectedContentType = "application/$expectedContentType" @@ -110,13 +129,14 @@ open class TemplateController(private val templateResolutionService: TemplateRes ResponseEntity.ok().contentType(expectedMediaType).body(result) } - @PostMapping("/{bpName}/{bpVersion}/{artifactName}/{resolutionKey}", produces = [MediaType.APPLICATION_JSON_VALUE]) - @ApiOperation(value = "Store a resolved template w/ resolution-key", + @ApiOperation( + value = "Store a resolved template w/ resolution-key", notes = "Store a template for a given CBA's action, identified by its blueprint name, blueprint version, " + "artifact name and resolution key.", response = TemplateResolution::class, - produces = MediaType.APPLICATION_JSON_VALUE) + produces = MediaType.APPLICATION_JSON_VALUE + ) @ResponseBody @PreAuthorize("hasRole('USER')") fun postWithResolutionKey( @@ -129,7 +149,8 @@ open class TemplateController(private val templateResolutionService: TemplateRes @ApiParam(value = "Resolution Key associated with the resolution.", required = true) @PathVariable(value = "resolutionKey") resolutionKey: String, @ApiParam(value = "Template to store.", required = true) - @RequestBody result: String): ResponseEntity<TemplateResolution> = runBlocking { + @RequestBody result: String + ): ResponseEntity<TemplateResolution> = runBlocking { val resultStored = templateResolutionService.write(bpName, bpVersion, artifactName, result, resolutionKey = resolutionKey) @@ -137,13 +158,17 @@ open class TemplateController(private val templateResolutionService: TemplateRes ResponseEntity.ok().body(resultStored) } - @PostMapping("/{bpName}/{bpVersion}/{artifactName}/{resourceType}/{resourceId}", - produces = [MediaType.APPLICATION_JSON_VALUE]) - @ApiOperation(value = "Store a resolved template w/ resourceId and resourceType", + @PostMapping( + "/{bpName}/{bpVersion}/{artifactName}/{resourceType}/{resourceId}", + produces = [MediaType.APPLICATION_JSON_VALUE] + ) + @ApiOperation( + value = "Store a resolved template w/ resourceId and resourceType", notes = "Store a template for a given CBA's action, identified by its blueprint name, blueprint version, " + "artifact name, resourceId and resourceType.", response = TemplateResolution::class, - produces = MediaType.APPLICATION_JSON_VALUE) + produces = MediaType.APPLICATION_JSON_VALUE + ) @ResponseBody @PreAuthorize("hasRole('USER')") fun postWithResourceIdAndResourceType( @@ -158,7 +183,8 @@ open class TemplateController(private val templateResolutionService: TemplateRes @ApiParam(value = "Resource Id associated with the resolution.", required = false) @PathVariable(value = "resourceId", required = true) resourceId: String, @ApiParam(value = "Template to store.", required = true) - @RequestBody result: String): ResponseEntity<TemplateResolution> = runBlocking { + @RequestBody result: String + ): ResponseEntity<TemplateResolution> = runBlocking { val resultStored = templateResolutionService.write(bpName, bpVersion, artifactName, result, resourceId = resourceId, resourceType = resourceType) diff --git a/ms/blueprintsprocessor/modules/inbounds/resource-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/resource/api/ResourceControllerTest.kt b/ms/blueprintsprocessor/modules/inbounds/resource-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/resource/api/ResourceControllerTest.kt index 85ac7bddd..60b24131f 100644 --- a/ms/blueprintsprocessor/modules/inbounds/resource-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/resource/api/ResourceControllerTest.kt +++ b/ms/blueprintsprocessor/modules/inbounds/resource-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/resource/api/ResourceControllerTest.kt @@ -22,6 +22,7 @@ import org.junit.Test import org.junit.runner.RunWith import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.db.ResourceResolution import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.db.ResourceResolutionDBService +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants import org.onap.ccsdk.cds.controllerblueprints.core.asJsonPrimitive import org.onap.ccsdk.cds.controllerblueprints.core.data.PropertyDefinition import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils @@ -35,8 +36,6 @@ import org.springframework.test.context.ContextConfiguration import org.springframework.test.context.TestPropertySource import org.springframework.test.context.junit4.SpringRunner import org.springframework.test.web.reactive.server.WebTestClient -import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants - @RunWith(SpringRunner::class) @WebFluxTest @@ -88,8 +87,10 @@ class ResourceControllerTest { .consumeWith { val json = String(it.responseBody!!) val typeFactory = JacksonUtils.objectMapper.typeFactory - val list: List<ResourceResolution> = JacksonUtils.objectMapper.readValue(json, - typeFactory.constructCollectionType(List::class.java, ResourceResolution::class.java)) + val list: List<ResourceResolution> = JacksonUtils.objectMapper.readValue( + json, + typeFactory.constructCollectionType(List::class.java, ResourceResolution::class.java) + ) Assert.assertEquals(2, list.size) assertEqual(ra1, list[0]) assertEqual(ra1, list[0]) @@ -119,8 +120,10 @@ class ResourceControllerTest { .consumeWith { val json = String(it.responseBody!!) val typeFactory = JacksonUtils.objectMapper.typeFactory - val list: List<ResourceResolution> = JacksonUtils.objectMapper.readValue(json, - typeFactory.constructCollectionType(List::class.java, ResourceResolution::class.java)) + val list: List<ResourceResolution> = JacksonUtils.objectMapper.readValue( + json, + typeFactory.constructCollectionType(List::class.java, ResourceResolution::class.java) + ) Assert.assertEquals(2, list.size) assertEqual(ra1, list[0]) assertEqual(ra1, list[0]) @@ -128,7 +131,6 @@ class ResourceControllerTest { } } - @Test fun getAllFromMissingParamTest() { runBlocking { @@ -140,8 +142,10 @@ class ResourceControllerTest { .expectBody() .consumeWith { val r = JacksonUtils.objectMapper.readValue(it.responseBody, ErrorMessage::class.java) - Assert.assertEquals("Missing param. Either retrieve resolved value using artifact name and resolution-key OR using resource-id and resource-type.", - r.message) + Assert.assertEquals( + "Missing param. Either retrieve resolved value using artifact name and resolution-key OR using resource-id and resource-type.", + r.message + ) } } } @@ -157,8 +161,10 @@ class ResourceControllerTest { .expectBody() .consumeWith { val r = JacksonUtils.objectMapper.readValue(it.responseBody, ErrorMessage::class.java) - Assert.assertEquals("Either retrieve resolved value using artifact name and resolution-key OR using resource-id and resource-type.", - r.message) + Assert.assertEquals( + "Either retrieve resolved value using artifact name and resolution-key OR using resource-id and resource-type.", + r.message + ) } } } @@ -195,15 +201,21 @@ class ResourceControllerTest { } } - private suspend fun store(resourceAssignment: ResourceAssignment, resKey: String = "", resId: String = "", - resType: String = "") { - resourceResolutionDBService.write(blueprintName, + private suspend fun store( + resourceAssignment: ResourceAssignment, + resKey: String = "", + resId: String = "", + resType: String = "" + ) { + resourceResolutionDBService.write( + blueprintName, blueprintVersion, resKey, resId, resType, templatePrefix, - resourceAssignment) + resourceAssignment + ) } private fun createRA(prefix: String): ResourceAssignment { @@ -221,8 +233,10 @@ class ResourceControllerTest { } private fun assertEqual(resourceAssignment: ResourceAssignment, resourceResolution: ResourceResolution) { - Assert.assertEquals(JacksonUtils.getValue(resourceAssignment.property?.value!!).toString(), - resourceResolution.value) + Assert.assertEquals( + JacksonUtils.getValue(resourceAssignment.property?.value!!).toString(), + resourceResolution.value + ) Assert.assertEquals(resourceAssignment.status, resourceResolution.status) Assert.assertEquals(resourceAssignment.dictionarySource, resourceResolution.dictionarySource) Assert.assertEquals(resourceAssignment.dictionaryName, resourceResolution.dictionaryName) @@ -230,6 +244,5 @@ class ResourceControllerTest { Assert.assertEquals(resourceAssignment.name, resourceResolution.name) Assert.assertEquals(blueprintVersion, resourceResolution.blueprintVersion) Assert.assertEquals(blueprintName, resourceResolution.blueprintName) - } -}
\ No newline at end of file +} diff --git a/ms/blueprintsprocessor/modules/inbounds/resource-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/resource/api/TemplateControllerTest.kt b/ms/blueprintsprocessor/modules/inbounds/resource-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/resource/api/TemplateControllerTest.kt index c3a718e11..baf0aa7c1 100644 --- a/ms/blueprintsprocessor/modules/inbounds/resource-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/resource/api/TemplateControllerTest.kt +++ b/ms/blueprintsprocessor/modules/inbounds/resource-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/resource/api/TemplateControllerTest.kt @@ -37,8 +37,10 @@ import kotlin.test.AfterTest @RunWith(SpringRunner::class) @WebFluxTest -@ContextConfiguration(classes = [BluePrintCoreConfiguration::class, - BluePrintCatalogService::class, SecurityProperties::class]) +@ContextConfiguration( + classes = [BluePrintCoreConfiguration::class, + BluePrintCatalogService::class, SecurityProperties::class] +) @ComponentScan(basePackages = ["org.onap.ccsdk.cds.blueprintsprocessor", "org.onap.ccsdk.cds.controllerblueprints"]) @TestPropertySource(locations = ["classpath:application-test.properties"]) class TemplateControllerTest { @@ -129,8 +131,10 @@ class TemplateControllerTest { webTestClient .get() - .uri("/api/v1/template?bpName=$blueprintName&bpVersion=$blueprintVersion" + - "&artifactName=$templatePrefix&resolutionKey=notFound") + .uri( + "/api/v1/template?bpName=$blueprintName&bpVersion=$blueprintVersion" + + "&artifactName=$templatePrefix&resolutionKey=notFound" + ) .exchange() .expectStatus().isNotFound } @@ -172,4 +176,4 @@ class TemplateControllerTest { .expectBody().equals(payloadDummyTemplateData) } } -}
\ No newline at end of file +} diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/BluePrintProcessingGRPCHandler.kt b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/BluePrintProcessingGRPCHandler.kt index b25acd148..305437923 100644 --- a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/BluePrintProcessingGRPCHandler.kt +++ b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/BluePrintProcessingGRPCHandler.kt @@ -31,16 +31,20 @@ import java.util.concurrent.Phaser import javax.annotation.PreDestroy @Service -open class BluePrintProcessingGRPCHandler(private val bluePrintCoreConfiguration: BluePrintCoreConfiguration, - private val executionServiceHandler: ExecutionServiceHandler) - : BluePrintProcessingServiceGrpc.BluePrintProcessingServiceImplBase() { +open class BluePrintProcessingGRPCHandler( + private val bluePrintCoreConfiguration: BluePrintCoreConfiguration, + private val executionServiceHandler: ExecutionServiceHandler +) : + BluePrintProcessingServiceGrpc.BluePrintProcessingServiceImplBase() { + private val log = LoggerFactory.getLogger(BluePrintProcessingGRPCHandler::class.java) private val ph = Phaser(1) @PreAuthorize("hasRole('USER')") override fun process( - responseObserver: StreamObserver<ExecutionServiceOutput>): StreamObserver<ExecutionServiceInput> { + responseObserver: StreamObserver<ExecutionServiceOutput> + ): StreamObserver<ExecutionServiceInput> { return object : StreamObserver<ExecutionServiceInput> { override fun onNext(executionServiceInput: ExecutionServiceInput) { @@ -51,17 +55,18 @@ open class BluePrintProcessingGRPCHandler(private val bluePrintCoreConfiguration } } catch (e: Exception) { onError(e) - } - finally { + } finally { ph.arriveAndDeregister() } } override fun onError(error: Throwable) { log.debug("Fail to process message", error) - responseObserver.onError(io.grpc.Status.INTERNAL + responseObserver.onError( + io.grpc.Status.INTERNAL .withDescription(error.message) - .asException()) + .asException() + ) } override fun onCompleted() { @@ -77,4 +82,4 @@ open class BluePrintProcessingGRPCHandler(private val bluePrintCoreConfiguration ph.arriveAndAwaitAdvance() log.info("Done waiting in $name") } -}
\ No newline at end of file +} diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/BluePrintProcessingKafkaConsumer.kt b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/BluePrintProcessingKafkaConsumer.kt index a9dda7e0c..6293f48f4 100644 --- a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/BluePrintProcessingKafkaConsumer.kt +++ b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/BluePrintProcessingKafkaConsumer.kt @@ -32,12 +32,15 @@ import org.springframework.stereotype.Service import java.util.concurrent.Phaser import javax.annotation.PreDestroy -@ConditionalOnProperty(name = ["blueprintsprocessor.messageconsumer.self-service-api.kafkaEnable"], - havingValue = "true") +@ConditionalOnProperty( + name = ["blueprintsprocessor.messageconsumer.self-service-api.kafkaEnable"], + havingValue = "true" +) @Service open class BluePrintProcessingKafkaConsumer( - private val bluePrintMessageLibPropertyService: BluePrintMessageLibPropertyService, - private val executionServiceHandler: ExecutionServiceHandler) { + private val bluePrintMessageLibPropertyService: BluePrintMessageLibPropertyService, + private val executionServiceHandler: ExecutionServiceHandler +) { val log = logger(BluePrintProcessingKafkaConsumer::class) @@ -53,13 +56,15 @@ open class BluePrintProcessingKafkaConsumer( @EventListener(ApplicationReadyEvent::class) fun setupMessageListener() = runBlocking { try { - log.info("Setting up message consumer($CONSUMER_SELECTOR) and " + - "message producer($PRODUCER_SELECTOR)...") + log.info( + "Setting up message consumer($CONSUMER_SELECTOR) and " + + "message producer($PRODUCER_SELECTOR)..." + ) /** Get the Message Consumer Service **/ blueprintMessageConsumerService = try { bluePrintMessageLibPropertyService - .blueprintMessageConsumerService(CONSUMER_SELECTOR) + .blueprintMessageConsumerService(CONSUMER_SELECTOR) } catch (e: Exception) { throw BluePrintProcessorException("failed to create consumer service ${e.message}") } @@ -67,7 +72,7 @@ open class BluePrintProcessingKafkaConsumer( /** Get the Message Producer Service **/ val blueprintMessageProducerService = try { bluePrintMessageLibPropertyService - .blueprintMessageProducerService(PRODUCER_SELECTOR) + .blueprintMessageProducerService(PRODUCER_SELECTOR) } catch (e: Exception) { throw BluePrintProcessorException("failed to create producer service ${e.message}") } @@ -83,34 +88,36 @@ open class BluePrintProcessingKafkaConsumer( log.trace("Consumed Message : $message") val executionServiceInput = message.jsonAsType<ExecutionServiceInput>() val executionServiceOutput = executionServiceHandler.doProcess(executionServiceInput) - //TODO("In future, Message publisher configuration vary with respect to request") + // TODO("In future, Message publisher configuration vary with respect to request") /** Send the response message */ blueprintMessageProducerService.sendMessage(executionServiceOutput) } catch (e: Exception) { log.error("failed in processing the consumed message : $message", e) - } - finally { + } finally { ph.arriveAndDeregister() } } } } } catch (e: Exception) { - log.error("failed to start message consumer($CONSUMER_SELECTOR) and " + - "message producer($PRODUCER_SELECTOR) ", e) + log.error( + "failed to start message consumer($CONSUMER_SELECTOR) and " + + "message producer($PRODUCER_SELECTOR) ", e + ) } } @PreDestroy fun shutdownMessageListener() = runBlocking { try { - log.info("Shutting down message consumer($CONSUMER_SELECTOR) and " + - "message producer($PRODUCER_SELECTOR)...") + log.info( + "Shutting down message consumer($CONSUMER_SELECTOR) and " + + "message producer($PRODUCER_SELECTOR)..." + ) blueprintMessageConsumerService.shutDown() ph.arriveAndAwaitAdvance() } catch (e: Exception) { log.error("failed to shutdown message listener($CONSUMER_SELECTOR)", e) } } - -}
\ No newline at end of file +} diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/ExecutionServiceController.kt b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/ExecutionServiceController.kt index 130e23ecc..02d3f2026 100644 --- a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/ExecutionServiceController.kt +++ b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/ExecutionServiceController.kt @@ -32,16 +32,23 @@ import org.springframework.beans.factory.annotation.Autowired import org.springframework.http.MediaType import org.springframework.http.ResponseEntity import org.springframework.security.access.prepost.PreAuthorize -import org.springframework.web.bind.annotation.* +import org.springframework.web.bind.annotation.RequestBody +import org.springframework.web.bind.annotation.RequestMapping +import org.springframework.web.bind.annotation.RequestMethod +import org.springframework.web.bind.annotation.ResponseBody +import org.springframework.web.bind.annotation.RestController import reactor.core.publisher.Mono import java.util.concurrent.Phaser import javax.annotation.PreDestroy @RestController @RequestMapping("/api/v1/execution-service") -@Api(value = "/api/v1/execution-service", - description = "Interaction with CBA.") +@Api( + value = "/api/v1/execution-service", + description = "Interaction with CBA." +) open class ExecutionServiceController { + val log = logger(ExecutionServiceController::class) private val ph = Phaser(1) @@ -49,9 +56,11 @@ open class ExecutionServiceController { @Autowired lateinit var executionServiceHandler: ExecutionServiceHandler - @RequestMapping(path = ["/health-check"], - method = [RequestMethod.GET], - produces = [MediaType.APPLICATION_JSON_VALUE]) + @RequestMapping( + path = ["/health-check"], + method = [RequestMethod.GET], + produces = [MediaType.APPLICATION_JSON_VALUE] + ) @ResponseBody @ApiOperation(value = "Health Check", hidden = true) fun executionServiceControllerHealthCheck() = monoMdc(Dispatchers.IO) { @@ -59,15 +68,19 @@ open class ExecutionServiceController { } @RequestMapping(path = ["/process"], method = [RequestMethod.POST], produces = [MediaType.APPLICATION_JSON_VALUE]) - @ApiOperation(value = "Execute a CBA workflow (action)", - notes = "Execute the appropriate CBA's action based on the ExecutionServiceInput object passed as input.", - produces = MediaType.APPLICATION_JSON_VALUE, - response = ExecutionServiceOutput::class) + @ApiOperation( + value = "Execute a CBA workflow (action)", + notes = "Execute the appropriate CBA's action based on the ExecutionServiceInput object passed as input.", + produces = MediaType.APPLICATION_JSON_VALUE, + response = ExecutionServiceOutput::class + ) @ResponseBody @PreAuthorize("hasRole('USER')") - fun process(@ApiParam(value = "ExecutionServiceInput payload.", required = true) - @RequestBody executionServiceInput: ExecutionServiceInput) - : Mono<ResponseEntity<ExecutionServiceOutput>> = monoMdc(Dispatchers.IO) { + fun process( + @ApiParam(value = "ExecutionServiceInput payload.", required = true) + @RequestBody executionServiceInput: ExecutionServiceInput + ): + Mono<ResponseEntity<ExecutionServiceOutput>> = monoMdc(Dispatchers.IO) { if (executionServiceInput.actionIdentifiers.mode == ACTION_MODE_ASYNC) { throw IllegalStateException("Can't process async request through the REST endpoint. Use gRPC for async processing.") @@ -87,4 +100,3 @@ open class ExecutionServiceController { log.info("Done waiting in $name") } } - diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/ExecutionServiceHandler.kt b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/ExecutionServiceHandler.kt index 356f0f7ee..9524e375e 100644 --- a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/ExecutionServiceHandler.kt +++ b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/ExecutionServiceHandler.kt @@ -21,7 +21,11 @@ import io.grpc.stub.StreamObserver import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.launch -import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.* +import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ACTION_MODE_ASYNC +import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ACTION_MODE_SYNC +import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput +import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceOutput +import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.Status import org.onap.ccsdk.cds.blueprintsprocessor.core.utils.toProto import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.AbstractServiceFunction import org.onap.ccsdk.cds.controllerblueprints.common.api.EventType @@ -36,15 +40,19 @@ import org.springframework.stereotype.Service import java.util.stream.Collectors @Service -class ExecutionServiceHandler(private val bluePrintLoadConfiguration: BluePrintLoadConfiguration, - private val blueprintsProcessorCatalogService: BluePrintCatalogService, - private val bluePrintWorkflowExecutionService - : BluePrintWorkflowExecutionService<ExecutionServiceInput, ExecutionServiceOutput>) { +class ExecutionServiceHandler( + private val bluePrintLoadConfiguration: BluePrintLoadConfiguration, + private val blueprintsProcessorCatalogService: BluePrintCatalogService, + private val bluePrintWorkflowExecutionService: + BluePrintWorkflowExecutionService<ExecutionServiceInput, ExecutionServiceOutput> +) { private val log = LoggerFactory.getLogger(ExecutionServiceHandler::class.toString()) - suspend fun process(executionServiceInput: ExecutionServiceInput, - responseObserver: StreamObserver<org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceOutput>) { + suspend fun process( + executionServiceInput: ExecutionServiceInput, + responseObserver: StreamObserver<org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceOutput> + ) { when { executionServiceInput.actionIdentifiers.mode == ACTION_MODE_ASYNC -> { GlobalScope.launch(Dispatchers.Default) { @@ -59,9 +67,13 @@ class ExecutionServiceHandler(private val bluePrintLoadConfiguration: BluePrintL responseObserver.onNext(executionServiceOutput.toProto()) responseObserver.onCompleted() } - else -> responseObserver.onNext(response(executionServiceInput, + else -> responseObserver.onNext( + response( + executionServiceInput, "Failed to process request, 'actionIdentifiers.mode' not specified. Valid value are: 'sync' or 'async'.", - true).toProto()); + true + ).toProto() + ) } } @@ -81,8 +93,10 @@ class ExecutionServiceHandler(private val bluePrintLoadConfiguration: BluePrintL val blueprintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime(requestId, basePath.toString()) - val output = bluePrintWorkflowExecutionService.executeBluePrintWorkflow(blueprintRuntimeService, - executionServiceInput, hashMapOf()) + val output = bluePrintWorkflowExecutionService.executeBluePrintWorkflow( + blueprintRuntimeService, + executionServiceInput, hashMapOf() + ) val errors = blueprintRuntimeService.getBluePrintError().errors if (errors.isNotEmpty()) { @@ -118,8 +132,11 @@ class ExecutionServiceHandler(private val bluePrintLoadConfiguration: BluePrintL status.message = BluePrintConstants.STATUS_FAILURE } - private fun response(executionServiceInput: ExecutionServiceInput, errorMessage: String = "", - failure: Boolean = false): ExecutionServiceOutput { + private fun response( + executionServiceInput: ExecutionServiceInput, + errorMessage: String = "", + failure: Boolean = false + ): ExecutionServiceOutput { val executionServiceOutput = ExecutionServiceOutput() executionServiceOutput.commonHeader = executionServiceInput.commonHeader executionServiceOutput.actionIdentifiers = executionServiceInput.actionIdentifiers @@ -138,5 +155,4 @@ class ExecutionServiceHandler(private val bluePrintLoadConfiguration: BluePrintL return executionServiceOutput } - } diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/utils/Utils.kt b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/utils/Utils.kt index 16fe36cfe..66cdbef3e 100644 --- a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/utils/Utils.kt +++ b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/utils/Utils.kt @@ -22,7 +22,7 @@ import org.springframework.util.StringUtils import java.io.File import java.io.IOException import java.nio.file.Path -import java.util.* +import java.util.UUID const val INTERNAL_SERVER_ERROR_HTTP_STATUS_CODE = 500 @@ -55,8 +55,8 @@ fun determineHttpStatusCode(statusCode: Int): HttpStatus { try { return HttpStatus.valueOf(statusCode) } catch (exception: Exception) { - //if statusCode cannot be converted to a proper HttpStatus, the resource still needs to assign a HTTP status + // if statusCode cannot be converted to a proper HttpStatus, the resource still needs to assign a HTTP status // code to the response. In this case, a 500 Internal Server Error will be returned as default. return HttpStatus.valueOf(INTERNAL_SERVER_ERROR_HTTP_STATUS_CODE) } -}
\ No newline at end of file +} diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/validation/BluePrintRuntimeValidatorService.kt b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/validation/BluePrintRuntimeValidatorService.kt index ab0d4256c..ff615536b 100644 --- a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/validation/BluePrintRuntimeValidatorService.kt +++ b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/validation/BluePrintRuntimeValidatorService.kt @@ -22,6 +22,8 @@ import org.onap.ccsdk.cds.controllerblueprints.validation.extension.ResourceDefi import org.springframework.stereotype.Service @Service("bluePrintRuntimeValidatorService") -open class BluePrintRuntimeValidatorService(bluePrintTypeValidatorService: BluePrintTypeValidatorService, - resourceDefinitionValidator: ResourceDefinitionValidator) - : BluePrintDesignTimeValidatorService(bluePrintTypeValidatorService, resourceDefinitionValidator) +open class BluePrintRuntimeValidatorService( + bluePrintTypeValidatorService: BluePrintTypeValidatorService, + resourceDefinitionValidator: ResourceDefinitionValidator +) : + BluePrintDesignTimeValidatorService(bluePrintTypeValidatorService, resourceDefinitionValidator) diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/BluePrintProcessingGRPCHandlerTest.kt b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/BluePrintProcessingGRPCHandlerTest.kt index 8bedc9628..e990c90d8 100644 --- a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/BluePrintProcessingGRPCHandlerTest.kt +++ b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/BluePrintProcessingGRPCHandlerTest.kt @@ -18,7 +18,6 @@ package org.onap.ccsdk.cds.blueprintsprocessor.selfservice.api - import com.google.protobuf.util.JsonFormat import io.grpc.stub.StreamObserver import io.grpc.testing.GrpcServerRule @@ -44,10 +43,13 @@ import kotlin.test.BeforeTest @RunWith(SpringRunner::class) @DirtiesContext @EnableAutoConfiguration -@ComponentScan(basePackages = ["org.onap.ccsdk.cds.blueprintsprocessor", - "org.onap.ccsdk.cds.controllerblueprints"]) +@ComponentScan( + basePackages = ["org.onap.ccsdk.cds.blueprintsprocessor", + "org.onap.ccsdk.cds.controllerblueprints"] +) @TestPropertySource(locations = ["classpath:application-test.properties"]) class BluePrintProcessingGRPCHandlerTest { + private val log = LoggerFactory.getLogger(BluePrintProcessingGRPCHandlerTest::class.java) @get:Rule @@ -68,7 +70,10 @@ class BluePrintProcessingGRPCHandlerTest { override fun onNext(executionServiceOuput: ExecutionServiceOutput) { log.debug("onNext {}", executionServiceOuput) if ("1234".equals(executionServiceOuput.commonHeader.requestId)) { - Assert.assertEquals("Failed to process request, \'actionIdentifiers.mode\' not specified. Valid value are: \'sync\' or \'async\'.", executionServiceOuput.status.errorMessage) + Assert.assertEquals( + "Failed to process request, \'actionIdentifiers.mode\' not specified. Valid value are: \'sync\' or \'async\'.", + executionServiceOuput.status.errorMessage + ) } } @@ -86,39 +91,38 @@ class BluePrintProcessingGRPCHandlerTest { @Test fun testSelfServiceGRPCHandler() { val commonHeader = CommonHeader.newBuilder() - .setTimestamp("2012-04-23T18:25:43.511Z") - .setOriginatorId("System") - .setRequestId("1234") - .setSubRequestId("1234-56").build() + .setTimestamp("2012-04-23T18:25:43.511Z") + .setOriginatorId("System") + .setRequestId("1234") + .setSubRequestId("1234-56").build() val jsonContent = JacksonUtils.getClassPathFileContent("execution-input/sample-payload.json") val payloadBuilder = ExecutionServiceInput.newBuilder().payloadBuilder JsonFormat.parser().merge(jsonContent, payloadBuilder) val input = ExecutionServiceInput.newBuilder() - .setCommonHeader(commonHeader) - .setPayload(payloadBuilder.build()) - .build() + .setCommonHeader(commonHeader) + .setPayload(payloadBuilder.build()) + .build() requestObs.onNext(input) val commonHeader2 = CommonHeader.newBuilder() - .setTimestamp("2012-04-23T18:25:43.511Z") - .setOriginatorId("System") - .setRequestId("2345") - .setSubRequestId("1234-56").build() + .setTimestamp("2012-04-23T18:25:43.511Z") + .setOriginatorId("System") + .setRequestId("2345") + .setSubRequestId("1234-56").build() val actionIdentifier = ActionIdentifiers.newBuilder().setMode("sync").build() val input2 = ExecutionServiceInput.newBuilder() - .setCommonHeader(commonHeader2) - .setActionIdentifiers(actionIdentifier) - .setPayload(payloadBuilder.build()) - .build() + .setCommonHeader(commonHeader2) + .setActionIdentifiers(actionIdentifier) + .setPayload(payloadBuilder.build()) + .build() requestObs.onNext(input2) requestObs.onCompleted() } - -}
\ No newline at end of file +} diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/BluePrintProcessingIntegrationTest.kt b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/BluePrintProcessingIntegrationTest.kt index 8971ebde2..b26781ad2 100644 --- a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/BluePrintProcessingIntegrationTest.kt +++ b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/BluePrintProcessingIntegrationTest.kt @@ -36,7 +36,7 @@ class BluePrintProcessingIntegrationTest { private val log = logger(BluePrintProcessingIntegrationTest::class) /** This is Integration test sample, Do not enable this test case in server build, this is for local desktop testing*/ - //@Test + // @Test fun integrationTestGrpcManagement() { runBlocking { val tokenAuthGrpcClientProperties = TokenAuthGrpcClientProperties().apply { @@ -65,26 +65,26 @@ class BluePrintProcessingIntegrationTest { }) val commonHeader = CommonHeader.newBuilder() - .setTimestamp("2012-04-23T18:25:43.511Z") - .setOriginatorId("System") - .setRequestId("1234-$it") - .setSubRequestId("1234-56").build() + .setTimestamp("2012-04-23T18:25:43.511Z") + .setOriginatorId("System") + .setRequestId("1234-$it") + .setSubRequestId("1234-56").build() val jsonContent = JacksonUtils.getClassPathFileContent("execution-input/sample-payload.json") val payloadBuilder = ExecutionServiceInput.newBuilder().payloadBuilder JsonFormat.parser().merge(jsonContent, payloadBuilder) val actionIdentifier = ActionIdentifiers.newBuilder() - .setActionName("SampleScript") - .setBlueprintName("sample-cba") - .setBlueprintVersion("1.0.0") - .build() + .setActionName("SampleScript") + .setBlueprintName("sample-cba") + .setBlueprintVersion("1.0.0") + .build() val input = ExecutionServiceInput.newBuilder() - .setCommonHeader(commonHeader) - .setActionIdentifiers(actionIdentifier) - .setPayload(payloadBuilder.build()) - .build() + .setCommonHeader(commonHeader) + .setActionIdentifiers(actionIdentifier) + .setPayload(payloadBuilder.build()) + .build() requestObs.onNext(input) requestObs.onCompleted() @@ -93,4 +93,4 @@ class BluePrintProcessingIntegrationTest { channel.shutdownNow() } } -}
\ No newline at end of file +} diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/BluePrintProcessingKafkaConsumerTest.kt b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/BluePrintProcessingKafkaConsumerTest.kt index 01199c131..f71d1b444 100644 --- a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/BluePrintProcessingKafkaConsumerTest.kt +++ b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/BluePrintProcessingKafkaConsumerTest.kt @@ -34,8 +34,10 @@ import kotlin.test.Test import kotlin.test.assertNotNull @RunWith(SpringRunner::class) -@ContextConfiguration(classes = [BluePrintMessageLibConfiguration::class, - BluePrintPropertyConfiguration::class, BluePrintPropertiesService::class]) +@ContextConfiguration( + classes = [BluePrintMessageLibConfiguration::class, + BluePrintPropertyConfiguration::class, BluePrintPropertiesService::class] +) @TestPropertySource(locations = ["classpath:application-test.properties"]) class BluePrintProcessingKafkaConsumerTest { @@ -45,15 +47,19 @@ class BluePrintProcessingKafkaConsumerTest { @Test fun testExecutionInputMessageConsumer() { runBlocking { - assertNotNull(bluePrintMessageLibPropertyService, - "failed to initialise bluePrintMessageLibPropertyService") + assertNotNull( + bluePrintMessageLibPropertyService, + "failed to initialise bluePrintMessageLibPropertyService" + ) val executionServiceHandle = mockk<ExecutionServiceHandler>() coEvery { executionServiceHandle.doProcess(any()) } returns mockk() - val bluePrintProcessingKafkaConsumer = BluePrintProcessingKafkaConsumer(bluePrintMessageLibPropertyService, - executionServiceHandle) + val bluePrintProcessingKafkaConsumer = BluePrintProcessingKafkaConsumer( + bluePrintMessageLibPropertyService, + executionServiceHandle + ) launch { bluePrintProcessingKafkaConsumer.setupMessageListener() @@ -62,5 +68,4 @@ class BluePrintProcessingKafkaConsumerTest { bluePrintProcessingKafkaConsumer.shutdownMessageListener() } } - -}
\ No newline at end of file +} diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/ExecutionServiceControllerTest.kt b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/ExecutionServiceControllerTest.kt index e1a498a6f..a6ebe9c3e 100644 --- a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/ExecutionServiceControllerTest.kt +++ b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/ExecutionServiceControllerTest.kt @@ -36,17 +36,21 @@ import org.springframework.test.context.junit4.SpringRunner import org.springframework.test.web.reactive.server.WebTestClient import org.springframework.web.reactive.function.BodyInserters import java.io.File -import java.util.* +import java.util.UUID import kotlin.test.AfterTest import kotlin.test.BeforeTest import kotlin.test.assertTrue @RunWith(SpringRunner::class) @WebFluxTest -@ContextConfiguration(classes = [ExecutionServiceHandler::class, BluePrintCoreConfiguration::class, - BluePrintCatalogService::class, SecurityProperties::class]) -@ComponentScan(basePackages = ["org.onap.ccsdk.cds.blueprintsprocessor", - "org.onap.ccsdk.cds.controllerblueprints"]) +@ContextConfiguration( + classes = [ExecutionServiceHandler::class, BluePrintCoreConfiguration::class, + BluePrintCatalogService::class, SecurityProperties::class] +) +@ComponentScan( + basePackages = ["org.onap.ccsdk.cds.blueprintsprocessor", + "org.onap.ccsdk.cds.controllerblueprints"] +) @TestPropertySource(locations = ["classpath:application-test.properties"]) class ExecutionServiceControllerTest { @@ -71,15 +75,17 @@ class ExecutionServiceControllerTest { blueprintsProcessorCatalogService.saveToDatabase(UUID.randomUUID().toString(), loadTestCbaFile()) val executionServiceInput = JacksonUtils - .readValueFromClassPathFile("execution-input/default-input.json", - ExecutionServiceInput::class.java)!! + .readValueFromClassPathFile( + "execution-input/default-input.json", + ExecutionServiceInput::class.java + )!! webTestClient - .post() - .uri("/api/v1/execution-service/process") - .body(BodyInserters.fromObject(executionServiceInput)) - .exchange() - .expectStatus().isOk + .post() + .uri("/api/v1/execution-service/process") + .body(BodyInserters.fromObject(executionServiceInput)) + .exchange() + .expectStatus().isOk } } @@ -89,15 +95,17 @@ class ExecutionServiceControllerTest { blueprintsProcessorCatalogService.saveToDatabase(UUID.randomUUID().toString(), loadTestCbaFile()) val executionServiceInput = JacksonUtils - .readValueFromClassPathFile("execution-input/faulty-input.json", - ExecutionServiceInput::class.java)!! + .readValueFromClassPathFile( + "execution-input/faulty-input.json", + ExecutionServiceInput::class.java + )!! webTestClient - .post() - .uri("/api/v1/execution-service/process") - .body(BodyInserters.fromObject(executionServiceInput)) - .exchange() - .expectStatus().is5xxServerError + .post() + .uri("/api/v1/execution-service/process") + .body(BodyInserters.fromObject(executionServiceInput)) + .exchange() + .expectStatus().is5xxServerError } } @@ -106,4 +114,4 @@ class ExecutionServiceControllerTest { assertTrue(testCbaFile.exists(), "couldn't get file ${testCbaFile.absolutePath}") return testCbaFile } -}
\ No newline at end of file +} diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/ExecutionServiceHandlerTest.kt b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/ExecutionServiceHandlerTest.kt index 293da0da6..5a44403e1 100644 --- a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/ExecutionServiceHandlerTest.kt +++ b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/ExecutionServiceHandlerTest.kt @@ -73,12 +73,12 @@ class ExecutionServiceHandlerTest { @Service("mock-service-action") class MockServiceAction : AbstractServiceFunction() { + override suspend fun processNB(executionRequest: ExecutionServiceInput) { val responsePayload = """{"answer" : "correct"}""".jsonAsJsonType() setResponsePayloadForAction(responsePayload) } override suspend fun recoverNB(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) { - } -}
\ No newline at end of file +} diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/mock/Mock.kt b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/mock/Mock.kt index 27130a7bc..9f5cc6097 100644 --- a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/mock/Mock.kt +++ b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/mock/Mock.kt @@ -41,8 +41,10 @@ class MockComponentFunction : AbstractComponentFunction() { override suspend fun processNB(executionRequest: ExecutionServiceInput) { log.info("Processing component : $operationInputs") - bluePrintRuntimeService.setNodeTemplateAttributeValue(nodeTemplateName, - "assignment-params", "params".asJsonPrimitive()) + bluePrintRuntimeService.setNodeTemplateAttributeValue( + nodeTemplateName, + "assignment-params", "params".asJsonPrimitive() + ) } override suspend fun recoverNB(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) { @@ -51,13 +53,14 @@ class MockComponentFunction : AbstractComponentFunction() { } open class MockResourceSource { - @Bean(name = [ - "rr-processor-source-input", - "rr-processor-source-default", - "rr-processor-source-db", - "rr-processor-source-rest"]) + @Bean( + name = [ + "rr-processor-source-input", + "rr-processor-source-default", + "rr-processor-source-db", + "rr-processor-source-rest"] + ) open fun sourceInstance(): ResourceAssignmentProcessor { return mockk<ResourceAssignmentProcessor>() } - } diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/utils/Utils.kt b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/utils/UtilsTest.kt index 07d8ca4e1..db2791101 100644 --- a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/utils/Utils.kt +++ b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/utils/UtilsTest.kt @@ -23,5 +23,4 @@ class UtilsTest { val nonExistentHttpStatusCode = determineHttpStatusCode(999999) assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, nonExistentHttpStatusCode) } - -}
\ No newline at end of file +} diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/validation/BluePrintRuntimeValidatorServiceTest.kt b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/validation/BluePrintRuntimeValidatorServiceTest.kt index 08da9dc28..820c4be42 100644 --- a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/validation/BluePrintRuntimeValidatorServiceTest.kt +++ b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/validation/BluePrintRuntimeValidatorServiceTest.kt @@ -26,8 +26,10 @@ import org.springframework.test.context.junit4.SpringRunner import kotlin.test.assertNotNull @RunWith(SpringRunner::class) -@ContextConfiguration(classes = [BluePrintRuntimeValidatorService::class, - BluePrintValidationConfiguration::class, MockResourceSource::class]) +@ContextConfiguration( + classes = [BluePrintRuntimeValidatorService::class, + BluePrintValidationConfiguration::class, MockResourceSource::class] +) class BluePrintRuntimeValidatorServiceTest { @Autowired @@ -39,6 +41,5 @@ class BluePrintRuntimeValidatorServiceTest { assertNotNull(bluePrintRuntimeValidatorService, " failed to initilize bluePrintRuntimeValidatorService") bluePrintRuntimeValidatorService.validateBluePrints(blueprintBasePath) - } -}
\ No newline at end of file +} |