From 723cec335bf69d656c8c3e53cd9c10422121c9ca Mon Sep 17 00:00:00 2001 From: "katy.rotman" Date: Mon, 9 Oct 2017 11:57:18 +0300 Subject: Fix VSP resubmit logic Issue-ID: SDC-434 Change-Id: I2472f4a35f53763136f1e7586c4df24e3af25759 Signed-off-by: katy.rotman --- .../sdcrests/vsp/rest/VendorSoftwareProducts.java | 13 +-- .../rest/services/VendorSoftwareProductsImpl.java | 101 ++++++++++++--------- 2 files changed, 59 insertions(+), 55 deletions(-) (limited to 'openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services') 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/VendorSoftwareProducts.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/VendorSoftwareProducts.java index c51fcc452b..20fe64b88f 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/VendorSoftwareProducts.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/VendorSoftwareProducts.java @@ -209,17 +209,10 @@ public interface VendorSoftwareProducts extends VspEntities { @PUT @Path("/reSubmitAll") - @ApiOperation(value = "Performs check out, check in and submit for ALL submitted VSPs", notes + @ApiOperation(value = "Performs healing ,check out, check in and submit for Network Package " + + "Based VSPs", + notes = "Please note - only submitted VSPs will be processed") Response reSubmitAll(@NotNull(message = USER_MISSING_ERROR_MSG) @HeaderParam(USER_ID_HEADER_PARAM) String user) throws IOException; - - @PUT - @Path("/{vspId}/reSubmit") - @ApiOperation(value = "Performs check out, check in and submit for a specific Vendor Software " + - "Product") - Response reSubmit(@PathParam("vspId") String vspId, - @NotNull(message = USER_MISSING_ERROR_MSG) - @HeaderParam(USER_ID_HEADER_PARAM) String user) - throws IOException; } 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 27d4405fc7..4167785c02 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 @@ -48,7 +48,15 @@ import org.openecomp.sdc.versioning.dao.types.Version; import org.openecomp.sdc.versioning.dao.types.VersionStatus; import org.openecomp.sdc.versioning.types.VersionInfo; import org.openecomp.sdc.versioning.types.VersionableEntityAction; -import org.openecomp.sdcrests.vendorsoftwareproducts.types.*; +import org.openecomp.sdcrests.vendorsoftwareproducts.types.OnboardingMethod; +import org.openecomp.sdcrests.vendorsoftwareproducts.types.PackageInfoDto; +import org.openecomp.sdcrests.vendorsoftwareproducts.types.QuestionnaireResponseDto; +import org.openecomp.sdcrests.vendorsoftwareproducts.types.ValidationResponseDto; +import org.openecomp.sdcrests.vendorsoftwareproducts.types.VersionSoftwareProductActionRequestDto; +import org.openecomp.sdcrests.vendorsoftwareproducts.types.VspComputeDto; +import org.openecomp.sdcrests.vendorsoftwareproducts.types.VspCreationDto; +import org.openecomp.sdcrests.vendorsoftwareproducts.types.VspDescriptionDto; +import org.openecomp.sdcrests.vendorsoftwareproducts.types.VspDetailsDto; import org.openecomp.sdcrests.vsp.rest.VendorSoftwareProducts; import org.openecomp.sdcrests.vsp.rest.mapping.MapComputeEntityToVspComputeDto; import org.openecomp.sdcrests.vsp.rest.mapping.MapPackageInfoToPackageInfoDto; @@ -69,6 +77,7 @@ import java.io.File; import java.io.IOException; import java.util.Collection; import java.util.List; +import java.util.Objects; import static org.openecomp.sdc.logging.messages.AuditMessages.SUBMIT_VSP_ERROR; @@ -94,8 +103,9 @@ public class VendorSoftwareProductsImpl implements VendorSoftwareProducts { + vspDescriptionDto.getName()); VspCreationDto vspCreationDto = null; - OnboardingMethod onboardingMethod = OnboardingMethod.valueOf(vspDescriptionDto.getOnboardingMethod()); - if (onboardingMethod == null){ + OnboardingMethod onboardingMethod = + OnboardingMethod.valueOf(vspDescriptionDto.getOnboardingMethod()); + if (onboardingMethod == null) { return handleUnkownOnboardingMethod(); } switch (onboardingMethod) { @@ -155,7 +165,7 @@ public class VendorSoftwareProductsImpl implements VendorSoftwareProducts { VersionInfo versionInfo = getVersionInfo(vspId, VersionableEntityAction.Read, user); - // + if (vspDetails.getOldVersion() != null && !"".equals(vspDetails.getOldVersion())) { if (Version.valueOf(versionId).equals(versionInfo.getActiveVersion())) { try { @@ -389,67 +399,68 @@ public class VendorSoftwareProductsImpl implements VendorSoftwareProducts { @Override public Response reSubmitAll(String user) throws IOException { + MDC.put(LoggerConstants.SERVICE_NAME, LoggerServiceName.Re_Submit_ALL_Final_VSPs.toString()); logger.audit(AuditMessages.AUDIT_MSG + AuditMessages.RESUBMIT_ALL_FINAL_VSPS); + List vspList = Objects.requireNonNull( + vendorSoftwareProductManager.listVsps(VersionStatus.Final.name(), user)); - List vspList = - vendorSoftwareProductManager.listVsps(null, user); + int healingCounter = 0; + int failedCounter = 0; + + try { + + 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", vspList.size()); - for (VersionedVendorSoftwareProductInfo versionVspInfo : vspList) { - String vspId = versionVspInfo.getVspDetails().getId(); - if (versionVspInfo.getVersionInfo().getStatus().equals(VersionStatus.Final)) { + 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 != null) { - reSubmit(vspId, user); + + if (Objects.nonNull(latestFinalVersion) && + (!OnboardingMethod.Manual.name().equals(vspDetails.getOnboardingMethod()))) { + reSubmit(vspDetails, user); + healingCounter++; } } + + } catch (Exception e) { + logger.error("Failed during resubmitAll", e); + failedCounter++; + } finally { + logger.info("Finished attempted healing and resubmit for {} VSPs out " + + "of total # of {} submitted VSPs. Failure count during resubmitAll: {}", + healingCounter, vspList.size(), failedCounter); } + return Response.ok().build(); } - @Override - public Response reSubmit(String vspId, String user) - throws IOException { - MDC.put(LoggerConstants.SERVICE_NAME, LoggerServiceName.Checkout_VSP.toString()); - vendorSoftwareProductManager.checkout(vspId, user); - logger.audit(AuditMessages.AUDIT_MSG + AuditMessages.CHECK_OUT_VSP + vspId); - - MDC.put(LoggerConstants.SERVICE_NAME, LoggerServiceName.Checkin_VSP.toString()); - vendorSoftwareProductManager.checkin(vspId, user); - logger.audit(AuditMessages.AUDIT_MSG + AuditMessages.CHECK_IN_VSP + vspId); - - MDC.put(LoggerConstants.SERVICE_NAME, LoggerServiceName.Submit_VSP.toString()); - ValidationResponse validationResponse = vendorSoftwareProductManager.submit(vspId, user); - if (!validationResponse.isValid()) { - logger.audit(AuditMessages.AUDIT_MSG + AuditMessages.SUBMIT_VSP_FAIL + vspId); - logAuditErrors(vspId, validationResponse); - return Response.status(Response.Status.EXPECTATION_FAILED).entity( - new MapValidationResponseToDto() - .applyMapping(validationResponse, ValidationResponseDto.class)).build(); - } - logger.audit(AuditMessages.AUDIT_MSG + AuditMessages.SUBMIT_VSP + vspId); + private void reSubmit(VspDetails vspDetails, String user) throws IOException { + final String vspId = vspDetails.getId(); + long startTime = System.currentTimeMillis(); + logger.info("Starting on healing and resubmit for VSP id[{}]", vspId); + vspDetails.setOldVersion("true"); - return Response.ok().build(); - } + vendorSoftwareProductManager.healAndAdvanceFinalVersion(vspId, vspDetails, user); - private void logAuditErrors(String vspId, ValidationResponse validationResponse) { - if (validationResponse.getVspErrors() != null) { - validationResponse.getVspErrors().forEach(errorCode -> logger.audit(AuditMessages - .AUDIT_MSG + String.format(SUBMIT_VSP_ERROR, errorCode.message(), vspId))); - } - if (validationResponse.getUploadDataErrors() != null) { - validationResponse.getUploadDataErrors().values().forEach(errorMessages - -> VendorSoftwareProductsImpl.printAuditForErrors(errorMessages, vspId, - SUBMIT_VSP_ERROR)); - } + long endTime = System.currentTimeMillis(); + long seconds = (endTime - startTime) / 1000; + + logger.info("Completed healing and resubmit for VSP id [{}], duration: {} seconds", + vspId, seconds); } - private static void printAuditForErrors(List errorList, String vspId, String auditType) { + private static void printAuditForErrors(List errorList, String vspId, + String auditType) { errorList.forEach(errorMessage -> { if (errorMessage.getLevel().equals(ErrorLevel.ERROR)) { logger.audit(AuditMessages.AUDIT_MSG + String.format(auditType, errorMessage.getMessage(), -- cgit 1.2.3-korg