Search in sources :

Example 1 with OperationStatus

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

the class MsoRequestsDbAdapterImpl method initServiceOperationStatus.

/**
 * Init operation status <br>
 *
 * @param serviceId
 * @param operationId
 * @param operationType
 * @param userId
 * @param result
 * @param operationContent
 * @param progress
 * @param reason
 * @throws MsoRequestsDbException
 * @since ONAP Casablanca Release
 */
@Override
@Transactional
public void initServiceOperationStatus(String serviceId, String operationId, String operationType, String userId, String result, String operationContent, String progress, String reason) throws MsoRequestsDbException {
    OperationStatus operStatus = new OperationStatus();
    operStatus.setOperationId(operationId);
    operStatus.setServiceId(serviceId);
    operStatus.setUserId(userId);
    operStatus.setOperation(operationType);
    operStatus.setReason(reason);
    operStatus.setProgress(progress);
    operStatus.setResult(result);
    operStatus.setOperationContent(operationContent);
    operStatus.setResult(result);
    operationStatusRepository.save(operStatus);
}
Also used : ResourceOperationStatus(org.onap.so.db.request.beans.ResourceOperationStatus) OperationStatus(org.onap.so.db.request.beans.OperationStatus) Transactional(javax.transaction.Transactional)

Example 2 with OperationStatus

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

the class MsoRequestsDbAdapterImpl method updateServiceOperationStatus.

/**
 * update operation status <br>
 *
 * @param serviceId
 * @param operationId
 * @param operationType
 * @param userId
 * @param result
 * @param operationContent
 * @param progress
 * @param reason
 * @throws MsoRequestsDbException
 * @since ONAP Amsterdam Release
 */
@Override
@Transactional
public void updateServiceOperationStatus(String serviceId, String operationId, String operationType, String userId, String result, String operationContent, String progress, String reason) throws MsoRequestsDbException {
    OperationStatus operStatus = operationStatusRepository.findOneByServiceIdAndOperationId(serviceId, operationId);
    if (operStatus == null) {
        String error = "Entity not found. Unable to retrieve OperationStatus Object ServiceId: " + serviceId + " operationId: " + operationId;
        logger.error(error);
        operStatus = new OperationStatus();
        operStatus.setOperationId(operationId);
        operStatus.setServiceId(serviceId);
    }
    operStatus.setUserId(userId);
    operStatus.setOperation(operationType);
    operStatus.setReason(reason);
    operStatus.setProgress(progress);
    operStatus.setResult(result);
    operStatus.setOperationContent(operationContent);
    operStatus.setResult(result);
    operationStatusRepository.save(operStatus);
}
Also used : ResourceOperationStatus(org.onap.so.db.request.beans.ResourceOperationStatus) OperationStatus(org.onap.so.db.request.beans.OperationStatus) Transactional(javax.transaction.Transactional)

Example 3 with OperationStatus

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

the class OperationStatusTest method timeStampCreated.

@Test
@Transactional
public void timeStampCreated() throws InterruptedException, NoEntityFoundException {
    final String testServiceId = "test-service-id";
    final String testOperationId = "test-operation-id";
    final OperationStatusId id = new OperationStatusId(testServiceId, testOperationId);
    OperationStatus status = new OperationStatus();
    status.setServiceId(testServiceId);
    status.setOperationId(testOperationId);
    status = repository.saveAndFlush(status);
    OperationStatus found = repository.findById(id).orElseThrow(() -> new NoEntityFoundException("Cannot Find Operation"));
    Date operateAt = found.getOperateAt();
    assertNotNull(operateAt);
    assertEquals(testServiceId, found.getServiceId());
    Date finishedAt = found.getFinishedAt();
    status.setProgress("test-progress");
    // timestamps only set to save on 1 second changes
    Thread.sleep(1000);
    repository.saveAndFlush(status);
    OperationStatus foundUpdate = repository.findById(id).orElseThrow(() -> new NoEntityFoundException("Cannot Find Operation"));
    assertEquals(operateAt.toString(), foundUpdate.getOperateAt().toString());
    assertNotNull(foundUpdate.getFinishedAt());
    assertNotEquals(finishedAt.toString(), foundUpdate.getFinishedAt().toString());
    assertEquals("test-progress", foundUpdate.getProgress());
}
Also used : OperationStatusId(org.onap.so.db.request.beans.OperationStatusId) OperationStatus(org.onap.so.db.request.beans.OperationStatus) NoEntityFoundException(org.onap.so.db.request.exceptions.NoEntityFoundException) Date(java.util.Date) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(javax.transaction.Transactional)

Example 4 with OperationStatus

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

the class E2EServiceInstances method getE2EServiceInstance.

private Response getE2EServiceInstance(String serviceId, String operationId, String version) {
    GetE2EServiceInstanceResponse e2eServiceResponse = new GetE2EServiceInstanceResponse();
    String apiVersion = version.substring(1);
    OperationStatus operationStatus;
    try {
        operationStatus = requestsDbClient.getOneByServiceIdAndOperationId(serviceId, operationId);
    } 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 - Infra Request Lookup", e);
        Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_NOT_FOUND, MsoException.ServiceException, e.getMessage(), ErrorNumbers.NO_COMMUNICATION_TO_REQUESTS_DB, null, version);
        logger.debug(END_OF_THE_TRANSACTION + response.getEntity());
        return response;
    }
    if (operationStatus == null) {
        Response resp = msoRequest.buildServiceErrorResponse(HttpStatus.SC_NO_CONTENT, MsoException.ServiceException, "E2E serviceId " + serviceId + " is not found in DB", ErrorNumbers.SVC_DETAILED_SERVICE_ERROR, null, version);
        logger.error(LoggingAnchor.FOUR, MessageEnum.APIH_BPEL_COMMUNICATE_ERROR.toString(), MSO_PROP_APIHANDLER_INFRA, ErrorCode.BusinessProcessError.getValue(), "Null response from RequestDB when searching by serviceId");
        logger.debug(END_OF_THE_TRANSACTION + resp.getEntity());
        return resp;
    }
    e2eServiceResponse.setOperation(operationStatus);
    return builder.buildResponse(HttpStatus.SC_OK, null, e2eServiceResponse, apiVersion);
}
Also used : CamundaResponse(org.onap.so.apihandler.camundabeans.CamundaResponse) GetE2EServiceInstanceResponse(org.onap.so.apihandlerinfra.e2eserviceinstancebeans.GetE2EServiceInstanceResponse) Response(javax.ws.rs.core.Response) ApiResponse(io.swagger.v3.oas.annotations.responses.ApiResponse) OperationStatus(org.onap.so.db.request.beans.OperationStatus) GetE2EServiceInstanceResponse(org.onap.so.apihandlerinfra.e2eserviceinstancebeans.GetE2EServiceInstanceResponse) ApiException(org.onap.so.apihandlerinfra.exceptions.ApiException) BPMNFailureException(org.onap.so.apihandlerinfra.exceptions.BPMNFailureException) ValidateException(org.onap.so.apihandlerinfra.exceptions.ValidateException) IOException(java.io.IOException)

Example 5 with OperationStatus

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

the class RequestsDbClient method getOneByServiceIdAndOperationId.

public OperationStatus getOneByServiceIdAndOperationId(String serviceId, String operationId) {
    OperationStatus operationStatus = getSingleResponse(getUri(UriBuilder.fromUri(getUri(findOneByServiceIdAndOperationIdURI)).queryParam(SERVICE_ID, serviceId).queryParam(OPERATION_ID, operationId).build().toString()), OperationStatus.class);
    if (operationStatus != null) {
        operationStatus.setServiceId(serviceId);
        operationStatus.setOperationId(operationId);
    }
    return operationStatus;
}
Also used : ResourceOperationStatus(org.onap.so.db.request.beans.ResourceOperationStatus) OperationStatus(org.onap.so.db.request.beans.OperationStatus)

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