diff options
5 files changed, 49 insertions, 17 deletions
diff --git a/.gitignore b/.gitignore index 53cb42dfe..5dbd1d403 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ # Logs logs *.log +*.log.* npm-debug.log* yarn-debug.log* yarn-error.log* diff --git a/ms/blueprintsprocessor/application/src/main/resources/logback.xml b/ms/blueprintsprocessor/application/src/main/resources/logback.xml index a6caf92fd..e0bd7ca80 100644 --- a/ms/blueprintsprocessor/application/src/main/resources/logback.xml +++ b/ms/blueprintsprocessor/application/src/main/resources/logback.xml @@ -19,7 +19,7 @@ <!-- encoders are assigned the type
ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
<encoder>
- <pattern>%d{HH:mm:ss.SSS} %-5level %logger{50} - %msg%n</pattern>
+ <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern>
</encoder>
</appender>
diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/BlueprintProcessorCatalogServiceImpl.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/BlueprintProcessorCatalogServiceImpl.kt index 3234c9a3c..79f74e5dc 100755 --- a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/BlueprintProcessorCatalogServiceImpl.kt +++ b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/BlueprintProcessorCatalogServiceImpl.kt @@ -26,13 +26,11 @@ import org.onap.ccsdk.cds.controllerblueprints.core.common.ApplicationConstants import org.onap.ccsdk.cds.controllerblueprints.core.config.BluePrintPathConfiguration import org.onap.ccsdk.cds.controllerblueprints.core.data.ErrorCode import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintValidatorService -import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintArchiveUtils import org.onap.ccsdk.cds.controllerblueprints.db.resources.BlueprintCatalogServiceImpl import org.slf4j.LoggerFactory import org.springframework.dao.DataIntegrityViolationException import org.springframework.stereotype.Service import java.io.File -import java.nio.file.Files import java.nio.file.Path import java.util.* @@ -55,34 +53,54 @@ class BlueprintProcessorCatalogServiceImpl(bluePrintRuntimeValidatorService: Blu override suspend fun delete(name: String, version: String) { // Cleaning Deployed Blueprint deleteNBDir(bluePrintPathConfiguration.blueprintDeployPath, name, version) + log.info("removed cba file name($name), version($version) from deploy location") // Cleaning Data Base blueprintModelRepository .deleteByArtifactNameAndArtifactVersion(name, version) + log.info("removed cba file name($name), version($version) from database") } override suspend fun get(name: String, version: String, extract: Boolean): Path? { - val getId = UUID.randomUUID().toString() - var path = "${bluePrintPathConfiguration.blueprintArchivePath}/$getId/cba.zip" + val deployFile = normalizedFile(bluePrintPathConfiguration.blueprintDeployPath, name, version) + val cbaFile = normalizedFile(bluePrintPathConfiguration.blueprintArchivePath, + UUID.randomUUID().toString(), "cba.zip") - // TODO("Check first location for the file", If not get from database") + if (extract && deployFile.exists()) { + log.info("cba file name($name), version($version) already present(${deployFile.absolutePath})") + } else { + deployFile.reCreateNBDirs() + cbaFile.parentFile.reCreateNBDirs() - blueprintModelRepository.findByArtifactNameAndArtifactVersion(name, version)?.also { - it.blueprintModelContent.run { - val file = normalizedFile(path) - file.parentFile.reCreateDirs() + try { + log.info("getting cba file name($name), version($version) from db") + blueprintModelRepository.findByArtifactNameAndArtifactVersion(name, version)?.also { + it.blueprintModelContent.run { - file.writeBytes(this!!.content!!).let { - if (extract) { - path = "${bluePrintPathConfiguration.blueprintDeployPath}/$name/$version" - BluePrintArchiveUtils.deCompress(file, path) + cbaFile.writeBytes(this!!.content!!) + cbaFile.deCompress(deployFile) + log.info("cba file name($name), version($version) saved in (${deployFile.absolutePath})") } - return normalizedPath(path) } + + check(deployFile.exists() && deployFile.list().isNotEmpty()) { + throw BluePrintProcessorException("file check failed") + } + } catch (e: Exception) { + deleteNBDir(deployFile.absolutePath) + throw BluePrintProcessorException("failed to get get cba file name($name), version($version) from db" + + " : ${e.message}") + } finally { + deleteNBDir(cbaFile.parentFile.absolutePath) } } - return null + + return if (extract) { + deployFile.toPath() + } else { + cbaFile.toPath() + } } override suspend fun save(metadata: MutableMap<String, String>, archiveFile: File) { @@ -112,7 +130,7 @@ class BlueprintProcessorCatalogServiceImpl(bluePrintRuntimeValidatorService: Blu blueprintModelContent.contentType = "CBA_ZIP" blueprintModelContent.name = "$artifactName:$artifactVersion" blueprintModelContent.description = "$artifactName:$artifactVersion CBA Zip Content" - blueprintModelContent.content = Files.readAllBytes(archiveFile.toPath()) + blueprintModelContent.content = archiveFile.readBytes() blueprintModelContent.blueprintModel = blueprintModel blueprintModel.blueprintModelContent = blueprintModelContent 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 41e78e518..7cbc89583 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 @@ -22,6 +22,7 @@ import kotlinx.coroutines.runBlocking import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ACTION_MODE_ASYNC 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.controllerblueprints.core.BluePrintException import org.springframework.beans.factory.annotation.Autowired import org.springframework.http.MediaType import org.springframework.http.codec.multipart.FilePart @@ -49,6 +50,14 @@ open class ExecutionServiceController { executionServiceHandler.upload(filePart) } + @DeleteMapping("/name/{name}/version/{version}") + @Throws(BluePrintException::class) + @PreAuthorize("hasRole('USER')") + fun deleteBlueprint(@PathVariable(value = "name") name: String, + @PathVariable(value = "version") version: String) = runBlocking { + executionServiceHandler.remove(name, version) + } + @RequestMapping(path = ["/process"], method = [RequestMethod.POST], produces = [MediaType.APPLICATION_JSON_VALUE]) @ApiOperation(value = "Resolve Resource Mappings", notes = "Takes the blueprint information and process as per the payload") 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 0120a8f33..274346917 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 @@ -69,6 +69,10 @@ class ExecutionServiceHandler(private val bluePrintPathConfiguration: BluePrintP } } + suspend fun remove(name: String, version: String) { + bluePrintCatalogService.deleteFromDatabase(name, version) + } + suspend fun process(executionServiceInput: ExecutionServiceInput, responseObserver: StreamObserver<org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceOutput>) { when { |