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;
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;
+ 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) {
VersionInfo versionInfo = getVersionInfo(vspId, VersionableEntityAction.Read, user);
- //
+
if (vspDetails.getOldVersion() != null && !"".equals(vspDetails.getOldVersion())) {
if (Version.valueOf(versionId).equals(versionInfo.getActiveVersion())) {
try {
@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(),
try {
validateUniqueName(VALIDATION_VSP_NAME);
} catch (Exception ignored) {
- logger.debug("",ignored);
+ logger.debug("", ignored);
return VALIDATION_VSP_ID;
}
VspDetails validationVsp = new VspDetails();
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
() + "] " +
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());
}
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;
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);