Merge "Move GRPC management api to designer api."
authorDan Timoney <dtimoney@att.com>
Wed, 11 Sep 2019 19:54:09 +0000 (19:54 +0000)
committerGerrit Code Review <gerrit@onap.org>
Wed, 11 Sep 2019 19:54:09 +0000 (19:54 +0000)
18 files changed:
ms/blueprintsprocessor/application/src/main/java/org/onap/ccsdk/cds/blueprintsprocessor/BlueprintGRPCServer.java
ms/blueprintsprocessor/application/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/BlueprintsAcceptanceTest.kt
ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/BluePrintManagementGRPCHandler.kt [moved from ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/BluePrintManagementGRPCHandler.kt with 97% similarity]
ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/BlueprintModelController.kt
ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/DesignerBlueprintExceptionHandler.kt [moved from ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/ControllerBlueprintExceptionHandler.kt with 94% similarity]
ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/handler/BluePrintModelHandler.kt
ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/BluePrintManagementGRPCHandlerTest.kt [moved from ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/BluePrintManagementGRPCHandlerTest.kt with 98% similarity]
ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/BlueprintModelControllerTest.kt
ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/resources/test-cba.zip [new file with mode: 0644]
ms/blueprintsprocessor/modules/inbounds/pom.xml
ms/blueprintsprocessor/modules/inbounds/selfservice-api/pom.xml
ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/ExecutionServiceController.kt
ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/ExecutionServiceHandler.kt
ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/utils/Utils.kt
ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/ExecutionServiceControllerTest.kt
ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/ExecutionServiceHandlerTest.kt [deleted file]
ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/resources/cba-for-kafka-integration_enriched.zip [deleted file]
ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/DateUtils.kt [new file with mode: 0644]

index 5ad6ee2..9214121 100644 (file)
@@ -18,8 +18,8 @@ package org.onap.ccsdk.cds.blueprintsprocessor;
 
 import io.grpc.Server;
 import io.grpc.ServerBuilder;
+import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.BluePrintManagementGRPCHandler;
 import org.onap.ccsdk.cds.blueprintsprocessor.security.BasicAuthServerInterceptor;
-import org.onap.ccsdk.cds.blueprintsprocessor.selfservice.api.BluePrintManagementGRPCHandler;
 import org.onap.ccsdk.cds.blueprintsprocessor.selfservice.api.BluePrintProcessingGRPCHandler;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
index dfa0a85..ce7434f 100644 (file)
@@ -190,7 +190,7 @@ class BlueprintsAcceptanceTest(private val blueprintName: String, private val fi
         val body = toMultiValueMap("file", getBlueprintAsResource(blueprintName))
         webTestClient
                 .post()
-                .uri("/api/v1/execution-service/upload")
+                .uri("/api/v1/blueprint-model/publish")
                 .header("Authorization", TestSecuritySettings.clientAuthToken())
                 .syncBody(body)
                 .exchange()
  * limitations under the License.
  */
 
-package org.onap.ccsdk.cds.blueprintsprocessor.selfservice.api
+package org.onap.ccsdk.cds.blueprintsprocessor.designer.api
 
 import io.grpc.StatusException
 import io.grpc.stub.StreamObserver
 import kotlinx.coroutines.runBlocking
-import org.onap.ccsdk.cds.blueprintsprocessor.selfservice.api.utils.currentTimestamp
 import org.onap.ccsdk.cds.controllerblueprints.common.api.CommonHeader
 import org.onap.ccsdk.cds.controllerblueprints.common.api.Status
 import org.onap.ccsdk.cds.controllerblueprints.core.*
@@ -29,6 +28,7 @@ import org.onap.ccsdk.cds.controllerblueprints.core.config.BluePrintLoadConfigur
 import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintCatalogService
 import org.onap.ccsdk.cds.controllerblueprints.core.scripts.BluePrintCompileCache
 import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintFileUtils
+import org.onap.ccsdk.cds.controllerblueprints.core.utils.currentTimestamp
 import org.onap.ccsdk.cds.controllerblueprints.management.api.*
 import org.slf4j.LoggerFactory
 import org.springframework.security.access.prepost.PreAuthorize
@@ -36,7 +36,6 @@ import org.springframework.stereotype.Service
 import java.io.File
 import java.util.*
 
-// TODO("move to management-api or designer-api module")
 @Service
 open class BluePrintManagementGRPCHandler(private val bluePrintLoadConfiguration: BluePrintLoadConfiguration,
                                           private val blueprintsProcessorCatalogService: BluePrintCatalogService)
index f67ed25..4d13486 100644 (file)
 
 package org.onap.ccsdk.cds.blueprintsprocessor.designer.api
 
+import io.swagger.annotations.ApiOperation
+import io.swagger.annotations.ApiParam
 import kotlinx.coroutines.runBlocking
-import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException
 import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.domain.BlueprintModelSearch
 import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.handler.BluePrintModelHandler
+import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException
 import org.springframework.core.io.Resource
 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.*
 
 /**
@@ -40,18 +43,21 @@ open class BlueprintModelController(private val bluePrintModelHandler: BluePrint
     @PostMapping("", produces = [MediaType.APPLICATION_JSON_VALUE], consumes = [MediaType.MULTIPART_FORM_DATA_VALUE])
     @ResponseBody
     @Throws(BluePrintException::class)
+    @PreAuthorize("hasRole('USER')")
     fun saveBlueprint(@RequestPart("file") filePart: FilePart): BlueprintModelSearch = runBlocking {
         bluePrintModelHandler.saveBlueprintModel(filePart)
     }
 
     @GetMapping("", produces = [MediaType.APPLICATION_JSON_VALUE])
     @ResponseBody
+    @PreAuthorize("hasRole('USER')")
     fun allBlueprintModel(): List<BlueprintModelSearch> {
         return this.bluePrintModelHandler.allBlueprintModel()
     }
 
     @DeleteMapping("/{id}")
     @Throws(BluePrintException::class)
+    @PreAuthorize("hasRole('USER')")
     fun deleteBlueprint(@PathVariable(value = "id") id: String) {
         this.bluePrintModelHandler.deleteBlueprintModel(id)
     }
@@ -59,6 +65,7 @@ open class BlueprintModelController(private val bluePrintModelHandler: BluePrint
     @GetMapping("/by-name/{name}/version/{version}", produces = [MediaType.APPLICATION_JSON_VALUE])
     @ResponseBody
     @Throws(BluePrintException::class)
+    @PreAuthorize("hasRole('USER')")
     fun getBlueprintByNameAndVersion(@PathVariable(value = "name") name: String,
                                      @PathVariable(value = "version") version: String): BlueprintModelSearch {
         return this.bluePrintModelHandler.getBlueprintModelSearchByNameAndVersion(name, version)
@@ -67,6 +74,7 @@ open class BlueprintModelController(private val bluePrintModelHandler: BluePrint
     @GetMapping("/download/by-name/{name}/version/{version}", produces = [MediaType.APPLICATION_JSON_VALUE])
     @ResponseBody
     @Throws(BluePrintException::class)
+    @PreAuthorize("hasRole('USER')")
     fun downloadBlueprintByNameAndVersion(@PathVariable(value = "name") name: String,
                                           @PathVariable(value = "version") version: String): ResponseEntity<Resource> {
         return this.bluePrintModelHandler.downloadBlueprintModelFileByNameAndVersion(name, version)
@@ -75,6 +83,7 @@ open class BlueprintModelController(private val bluePrintModelHandler: BluePrint
     @GetMapping("/{id}", produces = [MediaType.APPLICATION_JSON_VALUE])
     @ResponseBody
     @Throws(BluePrintException::class)
+    @PreAuthorize("hasRole('USER')")
     fun getBlueprintModel(@PathVariable(value = "id") id: String): BlueprintModelSearch {
         return this.bluePrintModelHandler.getBlueprintModelSearch(id)
     }
@@ -82,6 +91,7 @@ open class BlueprintModelController(private val bluePrintModelHandler: BluePrint
     @GetMapping("/download/{id}", produces = [MediaType.APPLICATION_JSON_VALUE])
     @ResponseBody
     @Throws(BluePrintException::class)
+    @PreAuthorize("hasRole('USER')")
     fun downloadBluePrint(@PathVariable(value = "id") id: String): ResponseEntity<Resource> {
         return this.bluePrintModelHandler.downloadBlueprintModelFile(id)
     }
@@ -90,6 +100,7 @@ open class BlueprintModelController(private val bluePrintModelHandler: BluePrint
             .MULTIPART_FORM_DATA_VALUE])
     @ResponseBody
     @Throws(BluePrintException::class)
+    @PreAuthorize("hasRole('USER')")
     fun enrichBlueprint(@RequestPart("file") file: FilePart): ResponseEntity<Resource> = runBlocking {
         bluePrintModelHandler.enrichBlueprint(file)
     }
@@ -97,13 +108,27 @@ open class BlueprintModelController(private val bluePrintModelHandler: BluePrint
     @PostMapping("/publish", produces = [MediaType.APPLICATION_JSON_VALUE])
     @ResponseBody
     @Throws(BluePrintException::class)
+    @PreAuthorize("hasRole('USER')")
     fun publishBlueprint(@RequestPart("file") file: FilePart): BlueprintModelSearch = runBlocking {
         bluePrintModelHandler.publishBlueprint(file)
     }
 
     @GetMapping("/search/{tags}", produces = [MediaType.APPLICATION_JSON_VALUE])
     @ResponseBody
+    @PreAuthorize("hasRole('USER')")
     fun searchBlueprintModels(@PathVariable(value = "tags") tags: String): List<BlueprintModelSearch> {
         return this.bluePrintModelHandler.searchBlueprintModels(tags)
     }
+
+    @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)
+    @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) = runBlocking {
+        bluePrintModelHandler.deleteBlueprintModel(name, version)
+    }
 }
@@ -32,10 +32,10 @@ import org.springframework.web.bind.annotation.RestControllerAdvice
  * @version 1.0
  */
 @RestControllerAdvice("org.onap.ccsdk.cds.controllerblueprints")
-open class ControllerBlueprintExceptionHandler {
+open class DesignerBlueprintExceptionHandler {
 
     companion object ControllerBlueprintExceptionHandler {
-        val LOG = LoggerFactory.getLogger(ControllerBlueprintExceptionHandler::class.java)
+        val LOG = LoggerFactory.getLogger(DesignerBlueprintExceptionHandler::class.java)
     }
 
     @ExceptionHandler
index c074573..af7b3fe 100644 (file)
@@ -18,6 +18,7 @@
 
 package org.onap.ccsdk.cds.blueprintsprocessor.designer.api.handler
 
+import kotlinx.coroutines.reactive.awaitSingle
 import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.domain.BlueprintModel
 import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.domain.BlueprintModelSearch
 import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.repository.BlueprintModelContentRepository
@@ -29,6 +30,8 @@ import org.onap.ccsdk.cds.controllerblueprints.core.config.BluePrintLoadConfigur
 import org.onap.ccsdk.cds.controllerblueprints.core.data.ErrorCode
 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.scripts.BluePrintCompileCache
+import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintFileUtils
 import org.slf4j.LoggerFactory
 import org.springframework.core.io.ByteArrayResource
 import org.springframework.core.io.Resource
@@ -50,7 +53,7 @@ import java.util.*
  */
 
 @Service
-open class BluePrintModelHandler(private val controllerBlueprintsCatalogService: BluePrintCatalogService,
+open class BluePrintModelHandler(private val blueprintsProcessorCatalogService: BluePrintCatalogService,
                                  private val bluePrintLoadConfiguration: BluePrintLoadConfiguration,
                                  private val blueprintModelSearchRepository: BlueprintModelSearchRepository,
                                  private val blueprintModelRepository: BlueprintModelRepository,
@@ -77,29 +80,19 @@ open class BluePrintModelHandler(private val controllerBlueprintsCatalogService:
     </BlueprintModelSearch> */
     @Throws(BluePrintException::class)
     open suspend fun saveBlueprintModel(filePart: FilePart): BlueprintModelSearch {
-        val saveId = UUID.randomUUID().toString()
-        val blueprintArchive = normalizedPathName(bluePrintLoadConfiguration.blueprintArchivePath, saveId)
         try {
-            //Recreate the Dir
-            normalizedFile(bluePrintLoadConfiguration.blueprintArchivePath, saveId).reCreateDirs()
-            val deCompressedFile = normalizedFile(blueprintArchive, "cba.zip")
-            // Copy the File Part to Local File
-            BluePrintEnhancerUtils.copyFromFilePart(filePart, deCompressedFile)
-            // Save the Copied file to Database
-            val blueprintId = controllerBlueprintsCatalogService.saveToDatabase(saveId, deCompressedFile, false)
+            val blueprintId = upload(filePart, false)
             // Check and Return the Saved File
             val blueprintModelSearch = blueprintModelSearchRepository.findById(blueprintId)
                     ?: throw BluePrintException(ErrorCode.RESOURCE_NOT_FOUND.value,
                             String.format(BLUEPRINT_MODEL_ID_FAILURE_MSG, blueprintId))
 
-            log.info("Save($saveId) successful for blueprint(${blueprintModelSearch.artifactName}) " +
+            log.info("Save successful for blueprint(${blueprintModelSearch.artifactName}) " +
                     "version(${blueprintModelSearch.artifactVersion})")
             return blueprintModelSearch
         } catch (e: IOException) {
             throw BluePrintException(ErrorCode.IO_FILE_INTERRUPT.value,
                     "Error in Save CBA: ${e.message}", e)
-        } finally {
-            deleteDir(blueprintArchive)
         }
     }
 
@@ -261,6 +254,10 @@ open class BluePrintModelHandler(private val controllerBlueprintsCatalogService:
         }
     }
 
+    open suspend fun deleteBlueprintModel(name: String, version: String) {
+        blueprintsProcessorCatalogService.deleteFromDatabase(name, version)
+    }
+
     /**
      * This is a CBA enrichBlueprint method
      * Save the Zip File in archive location and extract the cba content.
@@ -303,14 +300,8 @@ open class BluePrintModelHandler(private val controllerBlueprintsCatalogService:
      */
     @Throws(BluePrintException::class)
     open suspend fun publishBlueprint(filePart: FilePart): BlueprintModelSearch {
-        val publishId = UUID.randomUUID().toString()
-        val blueprintArchive = bluePrintLoadConfiguration.blueprintArchivePath.plus(File.separator).plus(publishId)
-        val blueprintWorkingDir = bluePrintLoadConfiguration.blueprintWorkingPath.plus(File.separator).plus(publishId)
         try {
-            val compressedFilePart = BluePrintEnhancerUtils
-                    .extractCompressFilePart(filePart, blueprintArchive, blueprintWorkingDir)
-
-            val blueprintId = controllerBlueprintsCatalogService.saveToDatabase(publishId, compressedFilePart, true)
+            val blueprintId = upload(filePart, true)
 
             return blueprintModelSearchRepository.findById(blueprintId)
                     ?: throw BluePrintException(ErrorCode.RESOURCE_NOT_FOUND.value,
@@ -319,11 +310,40 @@ open class BluePrintModelHandler(private val controllerBlueprintsCatalogService:
         } catch (e: Exception) {
             throw BluePrintException(ErrorCode.IO_FILE_INTERRUPT.value,
                     "Error in Publishing CBA: ${e.message}", e)
+        }
+    }
+
+    //TODO("Combine Rest and GRPC Handler")
+    suspend fun upload(filePart: FilePart, validate: Boolean): String {
+        val saveId = UUID.randomUUID().toString()
+        val blueprintArchive = normalizedPathName(bluePrintLoadConfiguration.blueprintArchivePath, saveId)
+        val blueprintWorking = normalizedPathName(bluePrintLoadConfiguration.blueprintWorkingPath, saveId)
+        try {
+            val compressedFile = normalizedFile(blueprintArchive, "cba.zip")
+            compressedFile.parentFile.reCreateNBDirs()
+            // Copy the File Part to Local File
+            copyFromFilePart(filePart, compressedFile)
+            // Save the Copied file to Database
+            return blueprintsProcessorCatalogService.saveToDatabase(saveId, compressedFile, validate)
+        } catch (e: IOException) {
+            throw BluePrintException(ErrorCode.IO_FILE_INTERRUPT.value,
+                    "Error in Upload CBA: ${e.message}", e)
         } finally {
-            BluePrintEnhancerUtils.cleanEnhancer(blueprintArchive, blueprintWorkingDir)
+            // Clean blueprint script cache
+            val cacheKey = BluePrintFileUtils
+                    .compileCacheKey(normalizedPathName(bluePrintLoadConfiguration.blueprintWorkingPath, saveId))
+            BluePrintCompileCache.cleanClassLoader(cacheKey)
+            deleteNBDir(blueprintArchive)
+            deleteNBDir(blueprintWorking)
         }
     }
 
+    private suspend fun copyFromFilePart(filePart: FilePart, targetFile: File): File {
+        return filePart.transferTo(targetFile)
+                .thenReturn(targetFile)
+                .awaitSingle()
+    }
+
     companion object {
 
         private const val BLUEPRINT_MODEL_ID_FAILURE_MSG = "failed to get blueprint model id(%s) from repo"
index 877584e..1491080 100644 (file)
@@ -176,6 +176,31 @@ class BlueprintModelControllerTest {
 
     @Test
     fun test07_publishBlueprintModel() {
+        bp = runBlocking {
+            val body = MultipartBodyBuilder().apply {
+                part("file", object : ByteArrayResource(testZipFile!!.readBytes()) {
+                    override fun getFilename(): String {
+                        return "test.zip"
+                    }
+                })
+            }.build()
+
+            val publishBP = webTestClient
+                    .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")
+            assertEquals("1.0.0", publishBP.artifactVersion, "mismatch artifact version")
+            assertEquals("Y", publishBP.published, "mismatch publish")
+            publishBP
+        }
     }
 
     @Test
@@ -196,7 +221,13 @@ class BlueprintModelControllerTest {
 
     @Test
     fun test10_deleteBluePrint() {
-        webTestClient.delete().uri("/api/v1/blueprint-model/${bp!!.id}")
+//        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()
diff --git a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/resources/test-cba.zip b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/resources/test-cba.zip
new file mode 100644 (file)
index 0000000..785ec6c
Binary files /dev/null and b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/resources/test-cba.zip differ
index cb730b0..0542fe3 100644 (file)
         <module>selfservice-api</module>
     </modules>
     <dependencies>
+        <dependency>
+            <groupId>org.springframework.security</groupId>
+            <artifactId>spring-security-core</artifactId>
+        </dependency>
         <dependency>
             <groupId>org.onap.ccsdk.cds.blueprintsprocessor</groupId>
             <artifactId>workflow-service</artifactId>
             <artifactId>kotlinx-coroutines-test</artifactId>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>io.grpc</groupId>
+            <artifactId>grpc-testing</artifactId>
+            <scope>test</scope>
+        </dependency>
         <dependency>
             <groupId>io.projectreactor</groupId>
             <artifactId>reactor-test</artifactId>
index 1431e51..7c53e1c 100755 (executable)
 
     <dependencies>
 
-        <dependency>
-            <groupId>org.springframework.security</groupId>
-            <artifactId>spring-security-core</artifactId>
-        </dependency>
-
         <dependency>
             <groupId>org.onap.ccsdk.cds.components</groupId>
             <artifactId>proto-definition</artifactId>
-            <version>${project.version}</version>
         </dependency>
 
         <dependency>
             <groupId>org.onap.ccsdk.cds.controllerblueprints</groupId>
             <artifactId>blueprint-validation</artifactId>
         </dependency>
-        <dependency>
-            <groupId>io.grpc</groupId>
-            <artifactId>grpc-testing</artifactId>
-        </dependency>
 
         <!-- For Message libraries -->
         <dependency>
index d48f0c7..4441d2b 100644 (file)
@@ -27,11 +27,9 @@ import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInpu
 import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceOutput
 import org.onap.ccsdk.cds.blueprintsprocessor.selfservice.api.utils.determineHttpStatusCode
 import org.onap.ccsdk.cds.controllerblueprints.core.asJsonPrimitive
-import org.onap.ccsdk.cds.controllerblueprints.core.asJsonType
 import org.springframework.beans.factory.annotation.Autowired
 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.*
 
@@ -53,30 +51,6 @@ open class ExecutionServiceController {
         "Success".asJsonPrimitive()
     }
 
-    @PostMapping(path = ["/upload"], consumes = [MediaType.MULTIPART_FORM_DATA_VALUE])
-    @ResponseBody
-    @PreAuthorize("hasRole('USER')")
-    @ApiOperation(value = "Upload a CBA",
-            notes = "Upload the CBA package. This will also run validation on the CBA.",
-            produces = MediaType.APPLICATION_JSON_VALUE)
-    fun upload(@ApiParam(value = "The ZIP file containing the overall CBA package.", required = true)
-               @RequestPart("file") filePart: FilePart): JsonNode = runBlocking {
-        val uploadId = executionServiceHandler.upload(filePart)
-        """{"upload-id" : "$uploadId"}""".asJsonType()
-    }
-
-    @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)
-    @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) = runBlocking {
-        executionServiceHandler.remove(name, version)
-    }
-
     @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.",
index 2f88780..20af589 100644 (file)
@@ -21,24 +21,16 @@ import io.grpc.stub.StreamObserver
 import kotlinx.coroutines.Dispatchers
 import kotlinx.coroutines.GlobalScope
 import kotlinx.coroutines.launch
-import kotlinx.coroutines.reactive.awaitSingle
 import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.*
 import org.onap.ccsdk.cds.blueprintsprocessor.selfservice.api.utils.toProto
 import org.onap.ccsdk.cds.controllerblueprints.common.api.EventType
-import org.onap.ccsdk.cds.controllerblueprints.core.*
+import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants
 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.interfaces.BluePrintCatalogService
 import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintWorkflowExecutionService
-import org.onap.ccsdk.cds.controllerblueprints.core.scripts.BluePrintCompileCache
-import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintFileUtils
 import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintMetadataUtils
 import org.slf4j.LoggerFactory
-import org.springframework.http.codec.multipart.FilePart
 import org.springframework.stereotype.Service
-import java.io.File
-import java.io.IOException
-import java.util.*
 import java.util.stream.Collectors
 
 @Service
@@ -49,37 +41,6 @@ class ExecutionServiceHandler(private val bluePrintLoadConfiguration: BluePrintL
 
     private val log = LoggerFactory.getLogger(ExecutionServiceHandler::class.toString())
 
-    //TODO("Remove from self service api and move to designer api module")
-    suspend fun upload(filePart: FilePart): String {
-        val saveId = UUID.randomUUID().toString()
-        val blueprintArchive = normalizedPathName(bluePrintLoadConfiguration.blueprintArchivePath, saveId)
-        val blueprintWorking = normalizedPathName(bluePrintLoadConfiguration.blueprintWorkingPath, saveId)
-        try {
-
-            val compressedFile = normalizedFile(blueprintArchive, "cba.zip")
-            compressedFile.parentFile.reCreateNBDirs()
-            // Copy the File Part to Local File
-            copyFromFilePart(filePart, compressedFile)
-            // Save the Copied file to Database
-            return blueprintsProcessorCatalogService.saveToDatabase(saveId, compressedFile, true)
-        } catch (e: IOException) {
-            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))
-            BluePrintCompileCache.cleanClassLoader(cacheKey)
-            deleteNBDir(blueprintArchive)
-            deleteNBDir(blueprintWorking)
-        }
-    }
-
-    //TODO("Remove from self service api and move to designer api module")
-    suspend fun remove(name: String, version: String) {
-        blueprintsProcessorCatalogService.deleteFromDatabase(name, version)
-    }
-
     suspend fun process(executionServiceInput: ExecutionServiceInput,
                         responseObserver: StreamObserver<org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceOutput>) {
         when {
@@ -97,8 +58,8 @@ class ExecutionServiceHandler(private val bluePrintLoadConfiguration: BluePrintL
                 responseObserver.onCompleted()
             }
             else -> responseObserver.onNext(response(executionServiceInput,
-                "Failed to process request, 'actionIdentifiers.mode' not specified. Valid value are: 'sync' or 'async'.",
-                true).toProto());
+                    "Failed to process request, 'actionIdentifiers.mode' not specified. Valid value are: 'sync' or 'async'.",
+                    true).toProto());
         }
     }
 
@@ -115,7 +76,7 @@ class ExecutionServiceHandler(private val bluePrintLoadConfiguration: BluePrintL
             val blueprintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime(requestId, basePath.toString())
 
             val output = bluePrintWorkflowExecutionService.executeBluePrintWorkflow(blueprintRuntimeService,
-                executionServiceInput, hashMapOf())
+                    executionServiceInput, hashMapOf())
 
             val errors = blueprintRuntimeService.getBluePrintError().errors
             if (errors.isNotEmpty()) {
@@ -129,12 +90,6 @@ class ExecutionServiceHandler(private val bluePrintLoadConfiguration: BluePrintL
         }
     }
 
-    private suspend fun copyFromFilePart(filePart: FilePart, targetFile: File): File {
-        return filePart.transferTo(targetFile)
-            .thenReturn(targetFile)
-            .awaitSingle()
-    }
-
     private fun setErrorStatus(errorMessage: String, status: Status) {
         status.errorMessage = errorMessage
         status.eventType = EventType.EVENT_COMPONENT_FAILURE.name
index 2cf1c1d..16fe36c 100644 (file)
@@ -22,20 +22,10 @@ import org.springframework.util.StringUtils
 import java.io.File
 import java.io.IOException
 import java.nio.file.Path
-import java.time.LocalDateTime
-import java.time.ZoneId
-import java.time.format.DateTimeFormatter
 import java.util.*
 
 const val INTERNAL_SERVER_ERROR_HTTP_STATUS_CODE = 500
 
-fun currentTimestamp(): String {
-    val now = LocalDateTime.now(ZoneId.systemDefault())
-    val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")
-    return formatter.format(now)
-}
-
-
 @Throws(BluePrintException::class, IOException::class)
 fun saveCBAFile(filePart: FilePart, targetDirectory: Path): Path {
 
index fc6c489..e1a498a 100644 (file)
@@ -1,5 +1,6 @@
 /*
- * Copyright © 2019 Bell Canada
+ * Copyright © 2017-2018 AT&T Intellectual Property.
+ * Modifications Copyright © 2019 Bell Canada.
  * Modifications Copyright © 2019 IBM.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  */
 package org.onap.ccsdk.cds.blueprintsprocessor.selfservice.api
 
-import kotlinx.coroutines.reactive.awaitSingle
 import kotlinx.coroutines.runBlocking
-import org.junit.After
-import org.junit.Before
+import org.junit.Test
 import org.junit.runner.RunWith
+import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintCoreConfiguration
 import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput
 import org.onap.ccsdk.cds.controllerblueprints.core.deleteDir
-import org.slf4j.LoggerFactory
+import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintCatalogService
+import org.onap.ccsdk.cds.controllerblueprints.core.normalizedFile
+import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
 import org.springframework.beans.factory.annotation.Autowired
-import org.springframework.boot.autoconfigure.EnableAutoConfiguration
 import org.springframework.boot.autoconfigure.security.SecurityProperties
 import org.springframework.boot.test.autoconfigure.web.reactive.WebFluxTest
 import org.springframework.context.annotation.ComponentScan
-import org.springframework.core.io.ByteArrayResource
-import org.springframework.http.client.MultipartBodyBuilder
-import org.springframework.test.annotation.DirtiesContext
 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.springframework.test.web.reactive.server.returnResult
 import org.springframework.web.reactive.function.BodyInserters
 import java.io.File
-import java.nio.file.Files
-import java.nio.file.Paths
-import kotlin.test.Test
+import java.util.*
+import kotlin.test.AfterTest
+import kotlin.test.BeforeTest
+import kotlin.test.assertTrue
 
 @RunWith(SpringRunner::class)
-@EnableAutoConfiguration
-@ContextConfiguration(classes = [ExecutionServiceControllerTest::class, SecurityProperties::class])
-@ComponentScan(basePackages = ["org.onap.ccsdk.cds.blueprintsprocessor", "org.onap.ccsdk.cds.controllerblueprints"])
-@TestPropertySource(locations = ["classpath:application-test.properties"])
-@DirtiesContext
 @WebFluxTest
+@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 {
 
-    private val log = LoggerFactory.getLogger(ExecutionServiceControllerTest::class.java)!!
-
+    @Autowired
+    lateinit var blueprintsProcessorCatalogService: BluePrintCatalogService
     @Autowired
     lateinit var webTestClient: WebTestClient
 
-    var event: ExecutionServiceInput? = null
-
-    @Before
-    fun setup() {
+    @BeforeTest
+    fun init() {
         deleteDir("target", "blueprints")
     }
 
-    @After
-    fun clean() {
+    @AfterTest
+    fun cleanDir() {
         deleteDir("target", "blueprints")
     }
 
     @Test
-    fun uploadBluePrint() {
+    fun `test rest process`() {
         runBlocking {
-            val body = MultipartBodyBuilder().apply {
-                part("file", object : ByteArrayResource(Files.readAllBytes(loadCbaArchive().toPath())) {
-                    override fun getFilename(): String {
-                        return "test-cba.zip"
-                    }
-                })
-            }.build()
+            blueprintsProcessorCatalogService.saveToDatabase(UUID.randomUUID().toString(), loadTestCbaFile())
+
+            val executionServiceInput = JacksonUtils
+                    .readValueFromClassPathFile("execution-input/default-input.json",
+                            ExecutionServiceInput::class.java)!!
 
             webTestClient
                     .post()
-                    .uri("/api/v1/execution-service/upload")
-                    .body(BodyInserters.fromMultipartData(body))
+                    .uri("/api/v1/execution-service/process")
+                    .body(BodyInserters.fromObject(executionServiceInput))
                     .exchange()
                     .expectStatus().isOk
-                    .returnResult<String>()
-                    .responseBody
-                    .awaitSingle()
         }
     }
 
-    private fun loadCbaArchive(): File {
-        return Paths.get("./src/test/resources/cba-for-kafka-integration_enriched.zip").toFile()
-    }
-}
+    @Test
+    fun `rest resource process should return status code 500 in case of server-side exception`() {
+        runBlocking {
+            blueprintsProcessorCatalogService.saveToDatabase(UUID.randomUUID().toString(), loadTestCbaFile())
+
+            val executionServiceInput = JacksonUtils
+                    .readValueFromClassPathFile("execution-input/faulty-input.json",
+                            ExecutionServiceInput::class.java)!!
 
+            webTestClient
+                    .post()
+                    .uri("/api/v1/execution-service/process")
+                    .body(BodyInserters.fromObject(executionServiceInput))
+                    .exchange()
+                    .expectStatus().is5xxServerError
+        }
+    }
 
+    private fun loadTestCbaFile(): File {
+        val testCbaFile = normalizedFile("./src/test/resources/test-cba.zip")
+        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
deleted file mode 100644 (file)
index a480b11..0000000
+++ /dev/null
@@ -1,139 +0,0 @@
-/*
- * Copyright © 2017-2018 AT&T Intellectual Property.
- * Modifications Copyright © 2019 Bell Canada.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onap.ccsdk.cds.blueprintsprocessor.selfservice.api
-
-import kotlinx.coroutines.reactive.awaitSingle
-import kotlinx.coroutines.runBlocking
-import org.junit.Test
-import org.junit.runner.RunWith
-import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintCoreConfiguration
-import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput
-import org.onap.ccsdk.cds.controllerblueprints.core.deleteDir
-import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintCatalogService
-import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
-import org.springframework.beans.factory.annotation.Autowired
-import org.springframework.boot.autoconfigure.security.SecurityProperties
-import org.springframework.boot.test.autoconfigure.web.reactive.WebFluxTest
-import org.springframework.context.annotation.ComponentScan
-import org.springframework.core.io.ByteArrayResource
-import org.springframework.http.client.MultipartBodyBuilder
-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.springframework.test.web.reactive.server.returnResult
-import org.springframework.web.reactive.function.BodyInserters
-import java.io.File
-import java.nio.file.Files
-import java.nio.file.Paths
-import java.util.*
-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"])
-@TestPropertySource(locations = ["classpath:application-test.properties"])
-class ExecutionServiceHandlerTest {
-
-    @Autowired
-    lateinit var blueprintsProcessorCatalogService: BluePrintCatalogService
-    @Autowired
-    lateinit var webTestClient: WebTestClient
-
-    @BeforeTest
-    fun init() {
-        deleteDir("target", "blueprints")
-    }
-
-    @AfterTest
-    fun cleanDir() {
-        deleteDir("target", "blueprints")
-    }
-
-
-    @Test
-    fun `test rest upload blueprint`() {
-        runBlocking {
-            val body = MultipartBodyBuilder().apply {
-                part("file", object : ByteArrayResource(Files.readAllBytes(loadTestCbaFile().toPath())) {
-                    override fun getFilename(): String {
-                        return "test-cba.zip"
-                    }
-                })
-            }.build()
-
-            webTestClient
-                    .post()
-                    .uri("/api/v1/execution-service/upload")
-                    .body(BodyInserters.fromMultipartData(body))
-                    .exchange()
-                    .expectStatus().isOk
-                    .returnResult<String>()
-                    .responseBody
-                    .awaitSingle()
-        }
-
-    }
-
-    @Test
-    fun `test rest process`() {
-        runBlocking {
-            blueprintsProcessorCatalogService.saveToDatabase(UUID.randomUUID().toString(), loadTestCbaFile())
-
-            val executionServiceInput = JacksonUtils
-                    .readValueFromClassPathFile("execution-input/default-input.json",
-                            ExecutionServiceInput::class.java)!!
-
-            webTestClient
-                    .post()
-                    .uri("/api/v1/execution-service/process")
-                    .body(BodyInserters.fromObject(executionServiceInput))
-                    .exchange()
-                    .expectStatus().isOk
-        }
-    }
-
-    @Test
-    fun `rest resource process should return status code 500 in case of server-side exception`() {
-        runBlocking {
-            blueprintsProcessorCatalogService.saveToDatabase(UUID.randomUUID().toString(), loadTestCbaFile())
-
-            val executionServiceInput = JacksonUtils
-                    .readValueFromClassPathFile("execution-input/faulty-input.json",
-                            ExecutionServiceInput::class.java)!!
-
-            webTestClient
-                    .post()
-                    .uri("/api/v1/execution-service/process")
-                    .body(BodyInserters.fromObject(executionServiceInput))
-                    .exchange()
-                    .expectStatus().is5xxServerError
-        }
-    }
-
-    private fun loadTestCbaFile(): File {
-        val testCbaFile = Paths.get("./src/test/resources/test-cba.zip").toFile()
-        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/resources/cba-for-kafka-integration_enriched.zip b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/resources/cba-for-kafka-integration_enriched.zip
deleted file mode 100755 (executable)
index 9581191..0000000
Binary files a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/resources/cba-for-kafka-integration_enriched.zip and /dev/null differ
diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/DateUtils.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/DateUtils.kt
new file mode 100644 (file)
index 0000000..e01ba80
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+ *  Copyright © 2019 IBM.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.onap.ccsdk.cds.controllerblueprints.core.utils
+
+import java.time.LocalDateTime
+import java.time.ZoneId
+import java.time.format.DateTimeFormatter
+
+fun currentTimestamp(): String {
+    val now = LocalDateTime.now(ZoneId.systemDefault())
+    val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")
+    return formatter.format(now)
+}