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());
}
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);
}
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"));
}
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"));
}
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()));
}
Aggregations