Search in sources :

Example 6 with OperationStatus

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

the class E2EServiceInstancesTest method getE2EServiceInstance.

@Test
public void getE2EServiceInstance() throws IOException {
    OperationStatus status = new OperationStatus();
    status.setOperationId("operationId");
    status.setServiceId("9b9f02c0-298b-458a-bc9c-be3692e4f35e");
    wireMockServer.stubFor(get(urlPathEqualTo("/operationStatus/search/findOneByServiceIdAndOperationId")).willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).withBody(mapper.writeValueAsString(status)).withStatus(HttpStatus.SC_OK)));
    String uri = e2eServInstancesUri + "v3/9b9f02c0-298b-458a-bc9c-be3692e4f35e/operations/operationId";
    ResponseEntity<String> response = sendRequest("", uri, HttpMethod.GET);
    assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value());
}
Also used : OperationStatus(org.onap.so.db.request.beans.OperationStatus) Test(org.junit.Test)

Example 7 with OperationStatus

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

the class MsoRequestsDbAdapterImpl method updateOperationStatusBasedOnResourceStatus.

/**
 * update service operation status when a operation resource status updated <br>
 *
 * @param operStatus the resource operation status
 * @since ONAP Amsterdam Release
 */
private void updateOperationStatusBasedOnResourceStatus(ResourceOperationStatus operStatus) {
    String serviceId = operStatus.getServiceId();
    String operationId = operStatus.getOperationId();
    logger.debug("Request database - update Operation Status Based On Resource Operation Status with service Id: " + "{}, operationId: {}", serviceId, operationId);
    List<ResourceOperationStatus> lstResourceStatus = resourceOperationStatusRepository.findByServiceIdAndOperationId(serviceId, operationId);
    if (lstResourceStatus == null) {
        logger.error("Unable to retrieve resourceOperStatus Object by ServiceId: {} operationId: {}", serviceId, operationId);
        return;
    }
    // count the total progress
    int resourceCount = lstResourceStatus.size();
    int progress = 0;
    boolean isFinished = true;
    for (ResourceOperationStatus lstResourceStatu : lstResourceStatus) {
        progress = progress + Integer.valueOf(lstResourceStatu.getProgress()) / resourceCount;
        if (RequestsDbConstant.Status.PROCESSING.equals(lstResourceStatu.getStatus())) {
            isFinished = false;
        }
    }
    OperationStatus serviceOperStatus = operationStatusRepository.findOneByServiceIdAndOperationId(serviceId, operationId);
    if (serviceOperStatus == null) {
        String error = "Entity not found. Unable to retrieve OperationStatus Object ServiceId: " + serviceId + " operationId: " + operationId;
        logger.error(error);
        serviceOperStatus = new OperationStatus();
        serviceOperStatus.setOperationId(operationId);
        serviceOperStatus.setServiceId(serviceId);
    }
    progress = progress > 100 ? 100 : progress;
    serviceOperStatus.setProgress(String.valueOf(progress));
    serviceOperStatus.setOperationContent(operStatus.getStatusDescription());
    // if current resource failed. service failed.
    if (RequestsDbConstant.Status.ERROR.equals(operStatus.getStatus())) {
        serviceOperStatus.setResult(RequestsDbConstant.Status.ERROR);
        serviceOperStatus.setReason(operStatus.getStatusDescription());
    } else if (isFinished) {
        // if finished
        serviceOperStatus.setResult(RequestsDbConstant.Status.FINISHED);
        serviceOperStatus.setProgress(RequestsDbConstant.Progress.ONE_HUNDRED);
    }
    operationStatusRepository.save(serviceOperStatus);
}
Also used : ResourceOperationStatus(org.onap.so.db.request.beans.ResourceOperationStatus) ResourceOperationStatus(org.onap.so.db.request.beans.ResourceOperationStatus) OperationStatus(org.onap.so.db.request.beans.OperationStatus)

Example 8 with OperationStatus

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

the class MSORequestDBImplTest method updateServiceOperation_Not_Found.

@Test
public void updateServiceOperation_Not_Found() throws MsoRequestsDbException {
    TestAppender.events.clear();
    String serviceId = "badserviceId";
    String operationId = "operationid";
    String operation = "newOperationType";
    String userId = "NewUserId";
    String result = "NewResult";
    String operationContent = "newOperationContent";
    String progress = "Newprogress";
    String reason = "NewReason";
    OperationStatus updatedOperationStatus = new OperationStatus();
    updatedOperationStatus.setServiceId(serviceId);
    updatedOperationStatus.setOperationId(operationId);
    updatedOperationStatus.setOperation(operation);
    updatedOperationStatus.setUserId(userId);
    updatedOperationStatus.setResult(result);
    updatedOperationStatus.setProgress(progress);
    updatedOperationStatus.setReason(reason);
    updatedOperationStatus.setOperationContent(operationContent);
    dbAdapter.updateServiceOperationStatus(serviceId, operationId, operation, userId, result, operationContent, progress, reason);
    OperationStatus dbOpStatus = operationStatusRepository.findOneByServiceIdAndOperationId(serviceId, operationId);
    assertThat(dbOpStatus, sameBeanAs(updatedOperationStatus).ignoring("operateAt").ignoring("finishedAt"));
}
Also used : ResourceOperationStatus(org.onap.so.db.request.beans.ResourceOperationStatus) OperationStatus(org.onap.so.db.request.beans.OperationStatus) Test(org.junit.Test)

Example 9 with OperationStatus

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

the class MSORequestDBImplTest method updateServiceOperation.

@Test
public void updateServiceOperation() throws MsoRequestsDbException {
    String serviceId = "serviceid";
    String operationId = "operationid";
    String serviceName = "servicename";
    String operation = "newOperationType";
    String userId = "NewUserId";
    String result = "NewResult";
    String operationContent = "newOperationContent";
    String progress = "Newprogress";
    String reason = "NewReason";
    OperationStatus updatedOperationStatus = new OperationStatus();
    updatedOperationStatus.setServiceId(serviceId);
    updatedOperationStatus.setServiceName(serviceName);
    updatedOperationStatus.setOperationId(operationId);
    updatedOperationStatus.setOperation(operation);
    updatedOperationStatus.setUserId(userId);
    updatedOperationStatus.setResult(result);
    updatedOperationStatus.setProgress(progress);
    updatedOperationStatus.setReason(reason);
    updatedOperationStatus.setOperationContent(operationContent);
    dbAdapter.updateServiceOperationStatus(serviceId, operationId, operation, userId, result, operationContent, progress, reason);
    OperationStatus dbOpStatus = operationStatusRepository.findOneByServiceIdAndOperationId(serviceId, operationId);
    assertThat(dbOpStatus, sameBeanAs(updatedOperationStatus).ignoring("operateAt").ignoring("finishedAt"));
}
Also used : ResourceOperationStatus(org.onap.so.db.request.beans.ResourceOperationStatus) OperationStatus(org.onap.so.db.request.beans.OperationStatus) Test(org.junit.Test)

Example 10 with OperationStatus

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

the class RequestsDbClientTest method getOneByServiceIdAndOperationIdTest.

@Test
public void getOneByServiceIdAndOperationIdTest() {
    OperationStatus operationStatus = new OperationStatus();
    operationStatus.setProgress("IN_PROGRESS");
    operationStatus.setResult("FAILED");
    operationStatus.setServiceId(UUID.randomUUID().toString());
    operationStatus.setOperationContent("operation-content");
    operationStatus.setOperation("operation");
    operationStatus.setOperationId(UUID.randomUUID().toString());
    operationStatus.setReason("reason-test");
    operationStatus.setUserId(UUID.randomUUID().toString());
    operationStatus.setServiceName("test-service");
    requestsDbClient.save(operationStatus);
    OperationStatus operationStatusResponse = requestsDbClient.getOneByServiceIdAndOperationId(operationStatus.getServiceId(), operationStatus.getOperationId());
    verifyOperationStatus(operationStatus, operationStatusResponse);
    assertNull(requestsDbClient.getOneByServiceIdAndOperationId(UUID.randomUUID().toString(), operationStatus.getOperationId()));
}
Also used : OperationStatus(org.onap.so.db.request.beans.OperationStatus) Test(org.junit.Test)

Aggregations

OperationStatus (org.onap.so.db.request.beans.OperationStatus)10 ResourceOperationStatus (org.onap.so.db.request.beans.ResourceOperationStatus)6 Test (org.junit.Test)5 Transactional (javax.transaction.Transactional)3 ApiResponse (io.swagger.v3.oas.annotations.responses.ApiResponse)1 IOException (java.io.IOException)1 Date (java.util.Date)1 Response (javax.ws.rs.core.Response)1 CamundaResponse (org.onap.so.apihandler.camundabeans.CamundaResponse)1 GetE2EServiceInstanceResponse (org.onap.so.apihandlerinfra.e2eserviceinstancebeans.GetE2EServiceInstanceResponse)1 ApiException (org.onap.so.apihandlerinfra.exceptions.ApiException)1 BPMNFailureException (org.onap.so.apihandlerinfra.exceptions.BPMNFailureException)1 ValidateException (org.onap.so.apihandlerinfra.exceptions.ValidateException)1 OperationStatusId (org.onap.so.db.request.beans.OperationStatusId)1 NoEntityFoundException (org.onap.so.db.request.exceptions.NoEntityFoundException)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1