diff options
author | Yulian Han <elaine.hanyulian@huawei.com> | 2018-11-29 19:32:31 +0800 |
---|---|---|
committer | Yulian Han <elaine.hanyulian@huawei.com> | 2018-11-29 19:32:31 +0800 |
commit | eea9276879c723444c7eaf95ada94ce057d7f6ab (patch) | |
tree | f351e65c83d8276cbd1689b1efcfe80f78ef297f /adapters/mso-requests-db-adapter/src/main/java | |
parent | 0a9ca68c09d8250cb62e94a45aacc7e52133ff00 (diff) |
vfc adapter authentication bug fix
update OperationStatus Based On ResourceStatus
add Authorization header to get csar from db
Change-Id: Idaa55084f5ecb0dd3636c232cebc14fa5f064414
Issue-ID: SO-1256
Signed-off-by: Yulian Han <elaine.hanyulian@huawei.com>
Diffstat (limited to 'adapters/mso-requests-db-adapter/src/main/java')
-rw-r--r-- | adapters/mso-requests-db-adapter/src/main/java/org/onap/so/adapters/requestsdb/MsoRequestsDbAdapterImpl.java | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/adapters/mso-requests-db-adapter/src/main/java/org/onap/so/adapters/requestsdb/MsoRequestsDbAdapterImpl.java b/adapters/mso-requests-db-adapter/src/main/java/org/onap/so/adapters/requestsdb/MsoRequestsDbAdapterImpl.java index c8ea1652f7..893156ce7d 100644 --- a/adapters/mso-requests-db-adapter/src/main/java/org/onap/so/adapters/requestsdb/MsoRequestsDbAdapterImpl.java +++ b/adapters/mso-requests-db-adapter/src/main/java/org/onap/so/adapters/requestsdb/MsoRequestsDbAdapterImpl.java @@ -23,6 +23,8 @@ package org.onap.so.adapters.requestsdb; import java.sql.Timestamp; +import java.util.List; + import javax.jws.WebService; import javax.transaction.Transactional; import org.onap.so.adapters.requestsdb.exceptions.MsoRequestsDbException; @@ -304,5 +306,65 @@ public class MsoRequestsDbAdapterImpl implements MsoRequestsDbAdapter { resStatus.setErrorCode(errorCode); resStatus.setStatusDescription(statusDescription); resourceOperationStatusRepository.save(resStatus); + + updateOperationStatusBasedOnResourceStatus(resStatus); } + + /** + * 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:" + + serviceId + ", operationId:" + operationId); + + List<ResourceOperationStatus> lstResourceStatus = resourceOperationStatusRepository.findByServiceIdAndOperationId(serviceId, operationId); + if (lstResourceStatus == null) { + logger.error("Unable to retrieve resourceOperStatus Object by ServiceId: " + serviceId + " operationId: " + 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); + } } |