Search in sources :

Example 1 with OrchestrationTask

use of org.onap.so.db.request.beans.OrchestrationTask in project so by onap.

the class RequestsDbClient method createOrchestrationTask.

public OrchestrationTask createOrchestrationTask(OrchestrationTask orchestrationTask) {
    String url = UriBuilder.fromUri(getUri(orchestrationTasksURI + "/")).build().toString();
    HttpHeaders headers = getHttpHeaders();
    HttpEntity<OrchestrationTask> entity = new HttpEntity<>(orchestrationTask, headers);
    return restTemplate.exchange(url, HttpMethod.POST, entity, OrchestrationTask.class).getBody();
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) HttpEntity(org.springframework.http.HttpEntity) OrchestrationTask(org.onap.so.db.request.beans.OrchestrationTask)

Example 2 with OrchestrationTask

use of org.onap.so.db.request.beans.OrchestrationTask in project so by onap.

the class OrchestrationTasks method AbortOrchestrationTask.

@POST
@Path("/{version:[vV][4-7]}/{taskId}/abort")
@Operation(description = "Commit an Orchestrated Task", responses = @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
@Produces(MediaType.APPLICATION_JSON)
@Transactional
public Response AbortOrchestrationTask(@PathParam("taskId") String taskId, @PathParam("version") String version) {
    OrchestrationTask orchestrationTask;
    try {
        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 Commit", e);
        Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_NOT_FOUND, MsoException.ServiceException, e.getMessage(), ErrorNumbers.NO_COMMUNICATION_TO_REQUESTS_DB, null, version);
        return response;
    }
    try {
        String taskName = orchestrationTask.getName();
        Map<String, String> commitVar = new HashMap<>();
        commitVar.put("taskAction", "abort");
        JSONObject msgJson = createMessageBody(taskId, taskName, commitVar);
        camundaRequestHandler.sendCamundaMessages(msgJson);
        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 Delete", e);
        Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_INTERNAL_SERVER_ERROR, MsoException.ServiceException, e.getMessage(), ErrorNumbers.ERROR_FROM_BPEL, null, version);
        return response;
    }
}
Also used : ApiResponse(io.swagger.v3.oas.annotations.responses.ApiResponse) Response(javax.ws.rs.core.Response) JSONObject(org.json.JSONObject) HashMap(java.util.HashMap) OrchestrationTask(org.onap.so.db.request.beans.OrchestrationTask) ApiException(org.onap.so.apihandlerinfra.exceptions.ApiException) Operation(io.swagger.v3.oas.annotations.Operation) Transactional(javax.transaction.Transactional)

Example 3 with OrchestrationTask

use of org.onap.so.db.request.beans.OrchestrationTask in project so by onap.

the class OrchestrationTasks method CreateOrchestrationTask.

@POST
@Path("/{version:[vV][4-7]}/")
@Operation(description = "Create an Orchestrated Task", responses = @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
@Produces(MediaType.APPLICATION_JSON)
@Transactional
public Response CreateOrchestrationTask(String requestJson, @PathParam("version") String version) {
    try {
        OrchestrationTask orchestrationTask = mapper.readValue(requestJson, OrchestrationTask.class);
        requestsDbClient.createOrchestrationTask(orchestrationTask);
        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 Create", 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;
    }
}
Also used : ApiResponse(io.swagger.v3.oas.annotations.responses.ApiResponse) Response(javax.ws.rs.core.Response) OrchestrationTask(org.onap.so.db.request.beans.OrchestrationTask) ApiException(org.onap.so.apihandlerinfra.exceptions.ApiException) Operation(io.swagger.v3.oas.annotations.Operation) Transactional(javax.transaction.Transactional)

Example 4 with OrchestrationTask

use of org.onap.so.db.request.beans.OrchestrationTask in project so by onap.

the class OrchestrationTaskTest method timeStampCreated.

@Test
@Transactional
public void timeStampCreated() throws NoEntityFoundException {
    final String testTaskId = "test-task-id";
    final String testRequestId = "test-request-id";
    final String testTaskName = "test-task-name";
    final String testTaskStatus = "test-task-status";
    final String testIsManual = "test-is-manual";
    OrchestrationTask task = new OrchestrationTask();
    task.setTaskId(testTaskId);
    task.setRequestId(testRequestId);
    task.setName(testTaskName);
    task.setStatus(testTaskStatus);
    task.setIsManual(testIsManual);
    repository.saveAndFlush(task);
    OrchestrationTask found = repository.findById(testTaskId).orElseThrow(() -> new NoEntityFoundException("Cannot Find Task"));
    Date createdTime = found.getCreatedTime();
    assertNotNull(createdTime);
    assertEquals(testTaskId, found.getTaskId());
    assertEquals(testRequestId, found.getRequestId());
    assertEquals(testTaskName, found.getName());
    assertEquals(testTaskStatus, found.getStatus());
    assertEquals(testIsManual, found.getIsManual());
}
Also used : NoEntityFoundException(org.onap.so.db.request.exceptions.NoEntityFoundException) OrchestrationTask(org.onap.so.db.request.beans.OrchestrationTask) Date(java.util.Date) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(javax.transaction.Transactional)

Example 5 with OrchestrationTask

use of org.onap.so.db.request.beans.OrchestrationTask in project so by onap.

the class OrchestrationTasks method UpdateOrchestrationTask.

@PUT
@Path("/{version:[vV][4-7]}/{taskId}")
@Operation(description = "Update an Orchestrated Task", responses = @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
@Produces(MediaType.APPLICATION_JSON)
@Transactional
public Response UpdateOrchestrationTask(@PathParam("taskId") String taskId, String requestJson, @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 Update", e);
        Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_NOT_FOUND, MsoException.ServiceException, e.getMessage(), ErrorNumbers.NO_COMMUNICATION_TO_REQUESTS_DB, null, version);
        return response;
    }
    try {
        OrchestrationTask orchestrationTask = mapper.readValue(requestJson, OrchestrationTask.class);
        requestsDbClient.updateOrchestrationTask(taskId, orchestrationTask);
        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 Update", e);
        Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_INTERNAL_SERVER_ERROR, MsoException.ServiceException, e.getMessage(), ErrorNumbers.NO_COMMUNICATION_TO_REQUESTS_DB, null, version);
        return response;
    }
}
Also used : ApiResponse(io.swagger.v3.oas.annotations.responses.ApiResponse) Response(javax.ws.rs.core.Response) OrchestrationTask(org.onap.so.db.request.beans.OrchestrationTask) ApiException(org.onap.so.apihandlerinfra.exceptions.ApiException) Operation(io.swagger.v3.oas.annotations.Operation) Transactional(javax.transaction.Transactional)

Aggregations

OrchestrationTask (org.onap.so.db.request.beans.OrchestrationTask)7 Transactional (javax.transaction.Transactional)5 Operation (io.swagger.v3.oas.annotations.Operation)4 ApiResponse (io.swagger.v3.oas.annotations.responses.ApiResponse)4 Response (javax.ws.rs.core.Response)4 ApiException (org.onap.so.apihandlerinfra.exceptions.ApiException)4 HashMap (java.util.HashMap)2 JSONObject (org.json.JSONObject)2 HttpEntity (org.springframework.http.HttpEntity)2 HttpHeaders (org.springframework.http.HttpHeaders)2 Date (java.util.Date)1 Test (org.junit.Test)1 NoEntityFoundException (org.onap.so.db.request.exceptions.NoEntityFoundException)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1