diff options
author | talig <talig@amdocs.com> | 2017-10-24 20:23:35 +0300 |
---|---|---|
committer | talig <talig@amdocs.com> | 2017-10-24 20:24:07 +0300 |
commit | 26ffac7f0f508f73a1b0701bc3897d0259409a35 (patch) | |
tree | 5b77a8df02ecc1bfccb958380dec82b3d54f5934 /openecomp-be/api | |
parent | e211e63edef1b88d8f7da53f3d1f0d5fb26d1555 (diff) |
Fix VSP resubmit all impl
Change-Id: I080425eb0115712da9a3d52f24d1b513cfb58291
Issue-ID: SDC-529
Signed-off-by: talig <talig@amdocs.com>
Diffstat (limited to 'openecomp-be/api')
1 files changed, 40 insertions, 64 deletions
diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/services/VendorSoftwareProductsImpl.java b/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/services/VendorSoftwareProductsImpl.java index 9e4d3bf51b..0450244355 100644 --- a/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/services/VendorSoftwareProductsImpl.java +++ b/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/services/VendorSoftwareProductsImpl.java @@ -78,6 +78,7 @@ import java.io.IOException; import java.util.Collection; import java.util.List; import java.util.Objects; +import java.util.stream.Collectors; import static org.openecomp.sdc.logging.messages.AuditMessages.SUBMIT_VSP_ERROR; @@ -403,59 +404,30 @@ public class VendorSoftwareProductsImpl implements VendorSoftwareProducts { MDC.put(LoggerConstants.SERVICE_NAME, LoggerServiceName.Re_Submit_ALL_Final_VSPs.toString()); logger.audit(AuditMessages.AUDIT_MSG + AuditMessages.RESUBMIT_ALL_FINAL_VSPS); - List<VersionedVendorSoftwareProductInfo> vspList = Objects.requireNonNull( - vendorSoftwareProductManager.listVsps(VersionStatus.Final.name(), user)); - int skippedCounter = 0; - final int vspListSizeBefore = vspList.size(); - - for (VersionedVendorSoftwareProductInfo versionVspInfo : vspList) { - final VspDetails vspDetails = versionVspInfo.getVspDetails(); - final String vspId = vspDetails.getId(); - final Version latestFinalVersion = - getVersionInfo(vspId, VersionableEntityAction.Read, user).getLatestFinalVersion(); - - if (latestFinalVersion.getStatus().equals(VersionStatus.Locked)) { - logger.info("Skipping processing VSP name [{}]/id [{}] due to status LOCKED", vspDetails - .getName(), - vspId); - skippedCounter++; - vspList.remove(versionVspInfo); - } - } + List<VersionedVendorSoftwareProductInfo> latestFinalVsps = Objects + .requireNonNull(vendorSoftwareProductManager.listVsps(VersionStatus.Final.name(), user)); - logger.info("Removed {} VSPs out of {} from processing due to status LOCKED", skippedCounter, - vspListSizeBefore); + List<VersionedVendorSoftwareProductInfo> nonLockedLatestFinalVsps = latestFinalVsps.stream() + .filter(vsp -> + !isVspLocked(vsp.getVspDetails().getId(), vsp.getVspDetails().getName(), user)) + .collect(Collectors.toList()); + + logger.info("Removed {} VSPs out of {} from processing due to status LOCKED.\n" + + "Total number of VSPs: {}. Performing healing and resubmit for all non-Manual VSPs " + + "in submitted status.\n No need to pre-set oldVersion field", + latestFinalVsps.size() - nonLockedLatestFinalVsps.size(), latestFinalVsps.size(), + nonLockedLatestFinalVsps.size()); int healingCounter = 0; int failedCounter = 0; - int totalCounter = 0; - - - final int vspListSize = vspList.size(); - logger.info("Total number of VSPs: {}. Performing healing and " + - "resubmit for all non-Manual VSPs in submitted status.\n No need to pre-set oldVersion " + - "field", vspListSize); - - for (VersionedVendorSoftwareProductInfo versionVspInfo : vspList) { + for (int counter = 0; counter < nonLockedLatestFinalVsps.size(); counter++) { + VersionedVendorSoftwareProductInfo versionVspInfo = nonLockedLatestFinalVsps.get(counter); try { - totalCounter++; - final Version activeVersion = versionVspInfo.getVersionInfo().getActiveVersion(); final VspDetails vspDetails = versionVspInfo.getVspDetails(); - final String vspId = vspDetails.getId(); - final Version latestFinalVersion = - getVersionInfo(vspId, VersionableEntityAction.Read, user).getLatestFinalVersion(); - - final String vspName = vspDetails.getName(); - logger.info("VSP Name {}, VSP id [{}], Active Version {} , Active Version Status {}," + - "Latest Final Version {} , " + - "Latest Final Version Status {}", vspName, vspId, activeVersion - .toString(), - activeVersion.getStatus(), latestFinalVersion.toString(), - latestFinalVersion.getStatus()); - - if (Objects.nonNull(latestFinalVersion) && - (!OnboardingMethod.Manual.name().equals(vspDetails.getOnboardingMethod()))) { - reSubmit(vspDetails, user, totalCounter, vspListSize); + if (!OnboardingMethod.Manual.name().equals(vspDetails.getOnboardingMethod())) { + logger.info("Starting on healing and resubmit for VSP [{}], #{} out of total {}", + vspDetails.getName(), counter + 1, nonLockedLatestFinalVsps.size()); + reSubmit(vspDetails, user); healingCounter++; } } catch (Exception e) { @@ -464,42 +436,46 @@ public class VendorSoftwareProductsImpl implements VendorSoftwareProducts { } logger.info("Total VSPs processed {}. Completed running healing and resubmit for {} VSPs out" + - " " + - "of total # of {} submitted VSPs. Failures count during resubmitAll: {}", - totalCounter, healingCounter, vspListSize, failedCounter); - + " of total # of {} submitted VSPs. Failures count during resubmitAll: {}", + nonLockedLatestFinalVsps.size(), healingCounter, latestFinalVsps.size(), failedCounter); return Response.ok().build(); } + private boolean isVspLocked(String vspId, String vspName, String user) { + final VersionInfo versionInfo = getVersionInfo(vspId, VersionableEntityAction.Read, user); - private void reSubmit(VspDetails vspDetails, String user, int currentCount, int total) throws - Exception { + if (versionInfo.getStatus().equals(VersionStatus.Locked)) { + logger.info("VSP name [{}]/id [{}] status is LOCKED", vspName, vspId); + return true; + } + logger.info("VSP Name {}, VSP id [{}], Active Version {} , Status {}, Latest Final Version {}", + vspName, vspId, versionInfo.getActiveVersion().toString(), versionInfo.getStatus(), + versionInfo.getLatestFinalVersion().toString()); + return false; + } - final String vspId = vspDetails.getId(); - final String vspName = vspDetails.getName(); - final Version versionBefore = vspDetails.getVersion(); - Version finalVersion; - logger.info("Starting on healing and resubmit for VSP [{}], #{} out of total {}", vspName, - currentCount, total); + private void reSubmit(VspDetails vspDetails, String user) throws Exception { + final Version versionBefore = vspDetails.getVersion(); vspDetails.setOldVersion("true"); + Version finalVersion; try { finalVersion = - vendorSoftwareProductManager.healAndAdvanceFinalVersion(vspId, vspDetails, user); - + vendorSoftwareProductManager + .healAndAdvanceFinalVersion(vspDetails.getId(), vspDetails, user); } catch (Exception e) { - logger.error("Failed during resubmit, VSP [{}] , version before:{}, version after:{}, " + "status after:{}, with exception:{}", - vspName, versionBefore.toString(), vspDetails.getVersion().toString(), vspDetails + vspDetails.getName(), versionBefore.toString(), vspDetails.getVersion().toString(), + vspDetails .getVersion().getStatus().name(), e.getMessage()); throw e; } logger.info("Completed healing and resubmit for VSP [{}], version before:{}, version after:" + - " {}", vspName, versionBefore.toString(), finalVersion); + " {}", vspDetails.getName(), versionBefore.toString(), finalVersion); } private static void printAuditForErrors(List<ErrorMessage> errorList, String vspId, |