diff options
Diffstat (limited to 'adapters')
2 files changed, 73 insertions, 13 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); + } } diff --git a/adapters/mso-vfc-adapter/src/main/java/org/onap/so/adapters/vfc/util/RestfulUtil.java b/adapters/mso-vfc-adapter/src/main/java/org/onap/so/adapters/vfc/util/RestfulUtil.java index 1db9d9546d..bb7fa70bda 100644 --- a/adapters/mso-vfc-adapter/src/main/java/org/onap/so/adapters/vfc/util/RestfulUtil.java +++ b/adapters/mso-vfc-adapter/src/main/java/org/onap/so/adapters/vfc/util/RestfulUtil.java @@ -43,7 +43,6 @@ import org.apache.http.impl.client.HttpClientBuilder; import org.apache.http.util.EntityUtils; import org.onap.so.adapters.vfc.model.RestfulResponse; import org.onap.so.logger.MessageEnum; - import org.onap.so.logger.MsoLogger; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.env.Environment; @@ -66,8 +65,6 @@ public class RestfulUtil { */ private static final MsoLogger LOGGER = MsoLogger.getMsoLogger(MsoLogger.Catalog.RA, RestfulUtil.class); - - private static final int DEFAULT_TIME_OUT = 60000; private static final String ONAP_IP = "ONAP_IP"; @@ -82,15 +79,18 @@ public class RestfulUtil { private Environment env; public String getMsbHost() { - // MSB_IP will be set as ONAP_IP environment parameter in install flow. - String msbIp = System.getenv().get(ONAP_IP); - // if ONAP IP is not set. get it from config file. - if(null == msbIp || msbIp.isEmpty()) { - msbIp = env.getProperty("mso.msb-ip", DEFAULT_MSB_IP); - } + // MSB_IP will be set as ONAP_IP environment parameter in install flow. + String msbIp = System.getenv().get(ONAP_IP); + // if ONAP IP is not set. get it from config file. + if (null == msbIp || msbIp.isEmpty()) { + msbIp = env.getProperty("mso.msb-ip", DEFAULT_MSB_IP); + } Integer msbPort = env.getProperty("mso.msb-port", Integer.class, DEFAULT_MSB_PORT); - return UriBuilder.fromPath("").host(msbIp).port(msbPort).scheme("http").build().toString(); + String msbEndpoint = UriBuilder.fromPath("").host(msbIp).port(msbPort).scheme("http").build().toString(); + LOGGER.debug("msbEndpoint in vfc adapter: " + msbEndpoint); + + return msbEndpoint; } private RestfulUtil() { @@ -99,7 +99,7 @@ public class RestfulUtil { public RestfulResponse send(String url, String methodType, String content) { String msbUrl = getMsbHost() + url; - LOGGER.info(MessageEnum.RA_NS_EXC, "Begin to sent message " + methodType +": " + msbUrl, "org.onap.so.adapters.vfc.util.RestfulUtil",VFC_ADAPTER); + LOGGER.debug("Begin to sent message " + methodType +": " + msbUrl); HttpRequestBase method = null; HttpResponse httpResponse = null; @@ -201,12 +201,10 @@ public class RestfulUtil { private static void logError(String errMsg, Throwable t) { LOGGER.error(MessageEnum.RA_NS_EXC, VFC_ADAPTER, "", MsoLogger.ErrorCode.AvailabilityError, errMsg, t); - } private static void logError(String errMsg) { LOGGER.error(MessageEnum.RA_NS_EXC, VFC_ADAPTER, "", MsoLogger.ErrorCode.AvailabilityError, errMsg); - } private static RestfulResponse createResponse(int statusCode, String content) { |