aboutsummaryrefslogtreecommitdiffstats
path: root/mso-api-handlers/mso-api-handler-infra/src/main
diff options
context:
space:
mode:
authorHarry Huang <huangxiangyu5@huawei.com>2020-02-17 15:56:06 +0800
committerHarry Huang <huangxiangyu5@huawei.com>2020-02-19 16:12:04 +0800
commit23041847536124df4b8b60f9e1df7ab5a4887daf (patch)
treeafb1cf48e49781c5fca2fba88f28eb36ae79c58d /mso-api-handlers/mso-api-handler-infra/src/main
parent493477ef59ce12d082683f188e0253fe2d34bdff (diff)
Add Get API for OrchestrationTask
Issue-ID: SO-2368 Add methods for get all orchestrationTask and get an specific one by querying id. Change-Id: I9fb444def7640a4d70357681637a924cf546314b Signed-off-by: Harry Huang <huangxiangyu5@huawei.com>
Diffstat (limited to 'mso-api-handlers/mso-api-handler-infra/src/main')
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/OrchestrationTasks.java119
1 files changed, 119 insertions, 0 deletions
diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/OrchestrationTasks.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/OrchestrationTasks.java
new file mode 100644
index 0000000000..7961cb0886
--- /dev/null
+++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/OrchestrationTasks.java
@@ -0,0 +1,119 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2019 Huawei Technologies Co., Ltd. All rights reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.so.apihandlerinfra;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import io.swagger.v3.oas.annotations.OpenAPIDefinition;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.info.Info;
+import io.swagger.v3.oas.annotations.media.ArraySchema;
+import io.swagger.v3.oas.annotations.media.Content;
+import io.swagger.v3.oas.annotations.media.Schema;
+import io.swagger.v3.oas.annotations.responses.ApiResponse;
+import org.apache.http.HttpStatus;
+import org.json.JSONObject;
+import org.onap.so.apihandler.common.ErrorNumbers;
+import org.onap.so.apihandler.common.ResponseBuilder;
+import org.onap.so.apihandlerinfra.exceptions.ApiException;
+import org.onap.so.db.request.beans.OrchestrationTask;
+import org.onap.so.db.request.client.RequestsDbClient;
+import org.onap.so.logger.ErrorCode;
+import org.onap.so.logger.LoggingAnchor;
+import org.onap.so.logger.MessageEnum;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+import javax.transaction.Transactional;
+import javax.ws.rs.*;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import static org.onap.so.apihandlerinfra.Constants.MSO_PROP_APIHANDLER_INFRA;
+
+@Path("/onap/so/infra/orchestrationTasks")
+@OpenAPIDefinition(
+ info = @Info(title = "onap/so/infra/orchestrationTasks", description = "API Requests for Orchestration Task"))
+@Component
+public class OrchestrationTasks {
+
+ private static Logger logger = LoggerFactory.getLogger(OrchestrationTasks.class);
+
+ @Autowired
+ private MsoRequest msoRequest;
+
+ @Autowired
+ private CamundaRequestHandler camundaRequestHandler;
+
+ @Autowired
+ private RequestsDbClient requestsDbClient;
+
+ @Autowired
+ private ResponseBuilder builder;
+
+ private ObjectMapper mapper = new ObjectMapper();
+
+ @GET
+ @Path("/{version:[vV][4-7]}/")
+ @Operation(description = "Find All Orchestrated Task", responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
+ @Produces(MediaType.APPLICATION_JSON)
+ @Transactional
+ public Response getAllOrchestrationTasks(@QueryParam("status") String status,
+ @PathParam("version") String version) {
+ List<OrchestrationTask> orchestrationTaskList = requestsDbClient.getAllOrchestrationTasks();
+ if (status != null && !status.isEmpty()) {
+ for (Iterator<OrchestrationTask> it = orchestrationTaskList.iterator(); it.hasNext();) {
+ OrchestrationTask task = it.next();
+ if (!status.equals(task.getStatus())) {
+ it.remove();
+ }
+ }
+ }
+ return builder.buildResponse(HttpStatus.SC_OK, null, orchestrationTaskList, version);
+ }
+
+ @GET
+ @Path("/{version:[vV][4-7]}/{taskId}")
+ @Operation(description = "Find Orchestrated Task for a given TaskId", responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
+ @Produces(MediaType.APPLICATION_JSON)
+ @Transactional
+ public Response getOrchestrationTask(@PathParam("taskId") String taskId, @PathParam("version") String version)
+ throws ApiException {
+ try {
+ OrchestrationTask orchestrationTask = requestsDbClient.getOrchestrationTask(taskId);
+ return builder.buildResponse(HttpStatus.SC_OK, null, orchestrationTask, 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 Lookup", e);
+ Response response =
+ msoRequest.buildServiceErrorResponse(HttpStatus.SC_NOT_FOUND, MsoException.ServiceException,
+ e.getMessage(), ErrorNumbers.NO_COMMUNICATION_TO_REQUESTS_DB, null, version);
+ return response;
+ }
+ }
+
+}