Add DELETE API for OrchestrationTask 34/102134/2
authorHarry Huang <huangxiangyu5@huawei.com>
Fri, 21 Feb 2020 09:33:34 +0000 (17:33 +0800)
committerHarry Huang <huangxiangyu5@huawei.com>
Mon, 24 Feb 2020 04:42:57 +0000 (12:42 +0800)
Issue-ID: SO-2368

Add method for delete a OrchestrationTask

Change-Id: Ic0d480f8e8d05f5f2dcbdc729f2c825bc348ca32
Signed-off-by: Harry Huang <huangxiangyu5@huawei.com>
mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/OrchestrationTasks.java

index 4a591db..21129d7 100644 (file)
@@ -173,4 +173,37 @@ public class OrchestrationTasks {
         }
     }
 
+    @DELETE
+    @Path("/{version:[vV][4-7]}/{taskId}")
+    @Operation(description = "Delete an Orchestrated Task", responses = @ApiResponse(
+            content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
+    @Produces(MediaType.APPLICATION_JSON)
+    @Transactional
+    public Response DeleteOrchestrationTask(@PathParam("taskId") String taskId, @PathParam("version") String version) {
+        try {
+            OrchestrationTask orchestrationTask = requestsDbClient.getOrchestrationTask(taskId);
+        } catch (Exception e) {
+            logger.error(LoggingAnchor.FOUR, MessageEnum.APIH_DB_ACCESS_EXC.toString(), MSO_PROP_APIHANDLER_INFRA,
+                    ErrorCode.AvailabilityError.getValue(),
+                    "Exception while communciate with Request DB - Orchestration Task Delete", e);
+            Response response =
+                    msoRequest.buildServiceErrorResponse(HttpStatus.SC_NOT_FOUND, MsoException.ServiceException,
+                            e.getMessage(), ErrorNumbers.NO_COMMUNICATION_TO_REQUESTS_DB, null, version);
+            return response;
+        }
+
+        try {
+            requestsDbClient.deleteOrchestrationTask(taskId);
+            return builder.buildResponse(HttpStatus.SC_OK, null, null, version);
+        } catch (Exception e) {
+            logger.error(LoggingAnchor.FOUR, MessageEnum.APIH_DB_ACCESS_EXC.toString(), MSO_PROP_APIHANDLER_INFRA,
+                    ErrorCode.AvailabilityError.getValue(),
+                    "Exception while communciate with Request DB - Orchestration Task Delete", e);
+            Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_INTERNAL_SERVER_ERROR,
+                    MsoException.ServiceException, e.getMessage(), ErrorNumbers.COULD_NOT_WRITE_TO_REQUESTS_DB, null,
+                    version);
+            return response;
+        }
+    }
+
 }