summaryrefslogtreecommitdiffstats
path: root/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
diff options
context:
space:
mode:
Diffstat (limited to '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')
-rw-r--r--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/OrchestrationTemplateCandidateImpl.java9
-rw-r--r--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/OrchestrationTemplateCandidateUploadManager.java20
-rw-r--r--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/OrchestrationTemplateCandidateUploadManagerImpl.java78
3 files changed, 94 insertions, 13 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/OrchestrationTemplateCandidateImpl.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/OrchestrationTemplateCandidateImpl.java
index 1477ce1414..6615447c6f 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/OrchestrationTemplateCandidateImpl.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/OrchestrationTemplateCandidateImpl.java
@@ -152,6 +152,8 @@ public class OrchestrationTemplateCandidateImpl implements OrchestrationTemplate
fileToUploadBytes = fileToUpload.getObject(byte[].class);
}
+
+ vspUploadStatus = orchestrationTemplateCandidateUploadManager.putUploadInValidation(vspId, versionId, user);
final var onboardingPackageProcessor =
new OnboardingPackageProcessor(filename, fileToUploadBytes, new CnfPackageValidator(), artifactInfo);
final ErrorMessage[] errorMessages = onboardingPackageProcessor.getErrorMessages().toArray(new ErrorMessage[0]);
@@ -166,13 +168,14 @@ public class OrchestrationTemplateCandidateImpl implements OrchestrationTemplate
}
final var version = new Version(versionId);
final var vspDetails = vendorSoftwareProductManager.getVsp(vspId, version);
+ vspUploadStatus = orchestrationTemplateCandidateUploadManager.putUploadInProcessing(vspId, versionId, user);
response = processOnboardPackage(onboardPackageInfo, vspDetails, errorMessages);
final UploadFileResponseDto entity = (UploadFileResponseDto) response.getEntity();
if (artifactStorageManager.isEnabled()) {
- if (!entity.getErrors().isEmpty()) {
- artifactStorageManager.delete(artifactInfo);
- } else {
+ if (entity.getErrors().isEmpty()) {
artifactStorageManager.put(vspId, versionId + ".reduced", new ByteArrayInputStream(fileToUploadBytes));
+ } else {
+ artifactStorageManager.delete(artifactInfo);
}
}
orchestrationTemplateCandidateUploadManager
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/OrchestrationTemplateCandidateUploadManager.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/OrchestrationTemplateCandidateUploadManager.java
index 0f33580099..c4b3e2ef9b 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/OrchestrationTemplateCandidateUploadManager.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/OrchestrationTemplateCandidateUploadManager.java
@@ -52,6 +52,26 @@ public interface OrchestrationTemplateCandidateUploadManager {
final String user);
/**
+ * Updates the upload status to a validation state.
+ *
+ * @param vspId the Vendor Software Product id
+ * @param vspVersionId the Vendor Software Product version id
+ * @param user the current user
+ * @return the updated upload status
+ */
+ VspUploadStatusDto putUploadInValidation(final String vspId, final String vspVersionId, final String user);
+
+ /**
+ * Updates the upload status to a processing state.
+ *
+ * @param vspId the Vendor Software Product id
+ * @param vspVersionId the Vendor Software Product version id
+ * @param user the current user
+ * @return the updated upload status
+ */
+ VspUploadStatusDto putUploadInProcessing(String vspId, String vspVersionId, String user);
+
+ /**
* Finds the latest upload status for a given Vendor Software Product version.
*
* @param vspId the Vendor Software Product id
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/OrchestrationTemplateCandidateUploadManagerImpl.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/OrchestrationTemplateCandidateUploadManagerImpl.java
index d7cfe041c2..df280bd20f 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/OrchestrationTemplateCandidateUploadManagerImpl.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/OrchestrationTemplateCandidateUploadManagerImpl.java
@@ -21,9 +21,13 @@
package org.openecomp.sdcrests.vsp.rest.services;
+import static org.openecomp.sdcrests.vsp.rest.exception.OrchestrationTemplateCandidateUploadManagerExceptionSupplier.alreadyInStatusBeingUpdated;
import static org.openecomp.sdcrests.vsp.rest.exception.OrchestrationTemplateCandidateUploadManagerExceptionSupplier.couldNotCreateLock;
import static org.openecomp.sdcrests.vsp.rest.exception.OrchestrationTemplateCandidateUploadManagerExceptionSupplier.couldNotFindLock;
+import static org.openecomp.sdcrests.vsp.rest.exception.OrchestrationTemplateCandidateUploadManagerExceptionSupplier.couldNotFindStatus;
import static org.openecomp.sdcrests.vsp.rest.exception.OrchestrationTemplateCandidateUploadManagerExceptionSupplier.couldNotUpdateLock;
+import static org.openecomp.sdcrests.vsp.rest.exception.OrchestrationTemplateCandidateUploadManagerExceptionSupplier.couldNotUpdateStatus;
+import static org.openecomp.sdcrests.vsp.rest.exception.OrchestrationTemplateCandidateUploadManagerExceptionSupplier.invalidCompletionStatus;
import static org.openecomp.sdcrests.vsp.rest.exception.OrchestrationTemplateCandidateUploadManagerExceptionSupplier.uploadAlreadyFinished;
import static org.openecomp.sdcrests.vsp.rest.exception.OrchestrationTemplateCandidateUploadManagerExceptionSupplier.vspUploadAlreadyInProgress;
@@ -58,28 +62,31 @@ public class OrchestrationTemplateCandidateUploadManagerImpl implements Orchestr
private static final Logger LOGGER = LoggerFactory.getLogger(OrchestrationTemplateCandidateUploadManagerImpl.class);
- private final VspUploadStatusRecordDao uploadManagerDao;
+ private final VspUploadStatusRecordDao vspUploadStatusRecordDao;
private final VspUploadStatusRecordMapper vspUploadStatusRecordMapper;
private final VendorSoftwareProductManager vendorSoftwareProductManager;
private final Lock startUploadLock;
+ private final Lock updateStatusLock;
@Autowired
public OrchestrationTemplateCandidateUploadManagerImpl(
- @Qualifier("vsp-upload-status-record-dao-impl") final VspUploadStatusRecordDao uploadManagerDao) {
+ @Qualifier("vsp-upload-status-record-dao-impl") final VspUploadStatusRecordDao vspUploadStatusRecordDao) {
- this.uploadManagerDao = uploadManagerDao;
+ this.vspUploadStatusRecordDao = vspUploadStatusRecordDao;
this.vendorSoftwareProductManager = VspManagerFactory.getInstance().createInterface();
this.vspUploadStatusRecordMapper = new VspUploadStatusRecordMapper();
startUploadLock = new ReentrantLock();
+ updateStatusLock = new ReentrantLock();
}
//for tests purpose
- OrchestrationTemplateCandidateUploadManagerImpl(final VspUploadStatusRecordDao uploadManagerDao,
+ OrchestrationTemplateCandidateUploadManagerImpl(final VspUploadStatusRecordDao vspUploadStatusRecordDao,
final VendorSoftwareProductManager vendorSoftwareProductManager) {
- this.uploadManagerDao = uploadManagerDao;
+ this.vspUploadStatusRecordDao = vspUploadStatusRecordDao;
this.vendorSoftwareProductManager = vendorSoftwareProductManager;
this.vspUploadStatusRecordMapper = new VspUploadStatusRecordMapper();
startUploadLock = new ReentrantLock();
+ updateStatusLock = new ReentrantLock();
}
@Override
@@ -90,7 +97,7 @@ public class OrchestrationTemplateCandidateUploadManagerImpl implements Orchestr
final VspUploadStatusRecord vspUploadStatusRecord;
startUploadLock.lock();
try {
- final List<VspUploadStatusRecord> uploadInProgressList = uploadManagerDao.findAllInProgress(vspId, vspVersionId);
+ final List<VspUploadStatusRecord> uploadInProgressList = vspUploadStatusRecordDao.findAllInProgress(vspId, vspVersionId);
if (!uploadInProgressList.isEmpty()) {
throw vspUploadAlreadyInProgress(vspId, vspVersionId).get();
}
@@ -102,7 +109,7 @@ public class OrchestrationTemplateCandidateUploadManagerImpl implements Orchestr
vspUploadStatusRecord.setLockId(UUID.randomUUID());
vspUploadStatusRecord.setCreated(new Date());
- uploadManagerDao.create(vspUploadStatusRecord);
+ vspUploadStatusRecordDao.create(vspUploadStatusRecord);
LOGGER.debug("Upload lock '{}' created for VSP id '{}', version '{}'", vspUploadStatusRecord.getLockId(), vspId, vspVersionId);
} catch (final CoreException e) {
throw e;
@@ -116,6 +123,57 @@ public class OrchestrationTemplateCandidateUploadManagerImpl implements Orchestr
}
@Override
+ public VspUploadStatusDto putUploadInValidation(final String vspId, final String vspVersionId, final String user) {
+ return updateToNotFinalStatus(vspId, vspVersionId, VspUploadStatus.VALIDATING, user);
+ }
+
+ @Override
+ public VspUploadStatusDto putUploadInProcessing(final String vspId, final String vspVersionId, final String user) {
+ return updateToNotFinalStatus(vspId, vspVersionId, VspUploadStatus.PROCESSING, user);
+ }
+
+ private VspUploadStatusDto updateToNotFinalStatus(final String vspId, final String vspVersionId, final VspUploadStatus status, final String user) {
+ LOGGER.debug("Updating upload status to '{}' for VSP id '{}', version '{}', triggered by user '{}'", status, vspId, vspVersionId, user);
+ if (status.isCompleteStatus()) {
+ throw invalidCompletionStatus(status).get();
+ }
+ updateStatusLock.lock();
+ try {
+ final Optional<VspUploadStatusRecord> vspUploadStatusRecordOptional = vspUploadStatusRecordDao.findLatest(vspId, vspVersionId);
+ if (vspUploadStatusRecordOptional.isEmpty()) {
+ throw couldNotFindStatus(vspId, vspVersionId).get();
+ }
+
+ final VspUploadStatusRecord vspUploadStatusRecord = vspUploadStatusRecordOptional.get();
+ final VspUploadStatus currentStatus = vspUploadStatusRecord.getStatus();
+ if (currentStatus == status) {
+ throw alreadyInStatusBeingUpdated(vspId, vspVersionId, status).get();
+ }
+ return updateStatus(vspUploadStatusRecord, status);
+ } finally {
+ updateStatusLock.unlock();
+ }
+ }
+
+ private VspUploadStatusDto updateStatus(final VspUploadStatusRecord vspUploadStatusRecord, final VspUploadStatus status) {
+ final VspUploadStatus currentStatus = vspUploadStatusRecord.getStatus();
+ vspUploadStatusRecord.setStatus(status);
+ vspUploadStatusRecord.setUpdated(new Date());
+
+ final String vspId = vspUploadStatusRecord.getVspId();
+ final String vspVersionId = vspUploadStatusRecord.getVspVersionId();
+ try {
+ vspUploadStatusRecordDao.update(vspUploadStatusRecord);
+ LOGGER.debug("Upload lock '{}' status updated from '{}' to '{}' for VSP id '{}', version '{}'",
+ vspUploadStatusRecord.getLockId(), currentStatus, status, vspId, vspVersionId);
+ } catch (final Exception e) {
+ throw couldNotUpdateStatus(vspId, vspVersionId, status, e).get();
+ }
+
+ return vspUploadStatusRecordMapper.applyMapping(vspUploadStatusRecord, VspUploadStatusDto.class);
+ }
+
+ @Override
public VspUploadStatusDto putUploadAsFinished(final String vspId, final String vspVersionId, final UUID lockId, final VspUploadStatus completionStatus,
final String user) {
@@ -123,7 +181,7 @@ public class OrchestrationTemplateCandidateUploadManagerImpl implements Orchestr
throw OrchestrationTemplateCandidateUploadManagerExceptionSupplier.invalidCompleteStatus(completionStatus).get();
}
final Optional<VspUploadStatusRecord> vspUploadStatusOptional =
- uploadManagerDao.findByVspIdAndVersionIdAndLockId(vspId, vspVersionId, lockId);
+ vspUploadStatusRecordDao.findByVspIdAndVersionIdAndLockId(vspId, vspVersionId, lockId);
if (vspUploadStatusOptional.isEmpty()) {
throw couldNotFindLock(lockId, vspId, vspVersionId).get();
}
@@ -138,7 +196,7 @@ public class OrchestrationTemplateCandidateUploadManagerImpl implements Orchestr
vspUploadStatusRecord.setIsComplete(true);
try {
- uploadManagerDao.update(vspUploadStatusRecord);
+ vspUploadStatusRecordDao.update(vspUploadStatusRecord);
LOGGER.debug("Upload complete for VSP '{}', version '{}', lock '{}'",
vspUploadStatusRecord.getLockId(), vspUploadStatusRecord.getVspId(), vspUploadStatusRecord.getVspVersionId());
} catch (final Exception e) {
@@ -160,7 +218,7 @@ public class OrchestrationTemplateCandidateUploadManagerImpl implements Orchestr
public Optional<VspUploadStatusDto> findLatestStatus(final String vspId, final String vspVersionId, final String user) {
checkVspExists(vspId, vspVersionId);
- final Optional<VspUploadStatusRecord> vspUploadStatus = uploadManagerDao.findLatest(vspId, vspVersionId);
+ final Optional<VspUploadStatusRecord> vspUploadStatus = vspUploadStatusRecordDao.findLatest(vspId, vspVersionId);
if (vspUploadStatus.isEmpty()) {
return Optional.empty();
}