Fix VSP resubmit logic 43/17543/2
authorkaty.rotman <katy.rotman@amdocs.com>
Mon, 9 Oct 2017 08:57:18 +0000 (11:57 +0300)
committerkaty.rotman <katy.rotman@amdocs.com>
Mon, 9 Oct 2017 08:57:18 +0000 (11:57 +0300)
Issue-ID: SDC-434
Change-Id: I2472f4a35f53763136f1e7586c4df24e3af25759
Signed-off-by: katy.rotman <katy.rotman@amdocs.com>
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
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
openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/VendorSoftwareProductManager.java
openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/VendorSoftwareProductManagerImpl.java

index c51fcc4..20fe64b 100644 (file)
@@ -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;
 }
index 27d4405..4167785 100644 (file)
@@ -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<VersionedVendorSoftwareProductInfo> vspList = Objects.requireNonNull(
+        vendorSoftwareProductManager.listVsps(VersionStatus.Final.name(), user));
 
-    List<VersionedVendorSoftwareProductInfo> 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<ErrorMessage> errorList, String vspId, String auditType) {
+  private static void printAuditForErrors(List<ErrorMessage> errorList, String vspId,
+                                          String auditType) {
     errorList.forEach(errorMessage -> {
       if (errorMessage.getLevel().equals(ErrorLevel.ERROR)) {
         logger.audit(AuditMessages.AUDIT_MSG + String.format(auditType, errorMessage.getMessage(),
index 738e267..0adca1c 100644 (file)
@@ -34,7 +34,7 @@ import java.io.IOException;
 import java.util.Collection;
 import java.util.List;
 
-public interface  VendorSoftwareProductManager {
+public interface VendorSoftwareProductManager {
 
   Version checkout(String vendorSoftwareProductId, String user);
 
@@ -78,4 +78,7 @@ public interface  VendorSoftwareProductManager {
   String fetchValidationVsp(String user);
 
   Collection<ComputeEntity> getComputeByVsp(String vspId, Version version, String user);
+
+  Version healAndAdvanceFinalVersion(String vspId, VspDetails vendorSoftwareProductInfo,
+                                     String user) throws IOException;
 }
index f4015ab..0a34285 100644 (file)
@@ -634,7 +634,7 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa
     try {
       validateUniqueName(VALIDATION_VSP_NAME);
     } catch (Exception ignored) {
-      logger.debug("",ignored);
+      logger.debug("", ignored);
       return VALIDATION_VSP_ID;
     }
     VspDetails validationVsp = new VspDetails();
@@ -708,7 +708,7 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa
           vsps.add(new VersionedVendorSoftwareProductInfo(vsp, versionInfo));
         }
       } catch (RuntimeException rte) {
-        logger.debug("",rte);
+        logger.debug("", rte);
         logger.error(
             "Error trying to retrieve vsp[" + entry.getKey() + "] version[" + version.toString
                 () + "] " +
@@ -789,8 +789,7 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa
       throw new CoreException(new VendorSoftwareProductNotFoundErrorBuilder(vspId).build());
     }
     vsp.setValidationData(orchestrationTemplateDao.getValidationData(vspId, version));
-
-    if (Objects.isNull(vsp.getOnboardingOrigin())) {
+    if (Objects.isNull(vsp.getOnboardingOrigin())) { //todo should this only be done for non-Manual?
       vsp.setOnboardingOrigin(OnboardingTypesEnum.ZIP.toString());
     }
 
@@ -818,22 +817,7 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa
         autoHeal(vspId, checkoutVersion, vendorSoftwareProductInfo, user);
         return checkin(vspId, user);
       case Final:
-        Version checkoutFinalVersion = checkout(vspId, user);
-        autoHeal(vspId, checkoutFinalVersion, vendorSoftwareProductInfo, user);
-        Version checkinFinalVersion = checkin(vspId, user);
-        ValidationResponse response = submit(vspId, user);
-        if (!response.isValid()) {
-          return checkout(vspId, user);
-        }
-
-        try {
-          Version finalVersion = checkinFinalVersion.calculateNextFinal();
-          createPackage(vspId, finalVersion, user);
-          return finalVersion;
-        } catch (IOException ex) {
-          logger.debug("",ex);
-          throw new Exception(ex.getMessage());
-        }
+        return healAndAdvanceFinalVersion(vspId, vendorSoftwareProductInfo, user);
       default:
         //do nothing
         break;
@@ -841,8 +825,27 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa
     return versionInfo.getActiveVersion();
   }
 
-  @Override
+  public Version healAndAdvanceFinalVersion(String vspId, VspDetails vendorSoftwareProductInfo,
+                                            String user) throws IOException {
+
+    Version checkoutFinalVersion = checkout(vspId, user);
+    autoHeal(vspId, checkoutFinalVersion, vendorSoftwareProductInfo, user);
+    Version checkinFinalVersion = checkin(vspId, user);
+
+    ValidationResponse response = Objects.requireNonNull(submit(vspId, user),
+        "Null response not expected");
 
+    if (!response.isValid()) {
+      return checkout(vspId, user);
+    }
+
+    Version finalVersion = checkinFinalVersion.calculateNextFinal();
+    createPackage(vspId, finalVersion, user);
+    return finalVersion;
+
+  }
+
+  @Override
   public void deleteVsp(String vspId, String user) {
     mdcDataDebugMessage.debugEntryMessage("VSP id", vspId);