- private Optional<MinIoArtifactInfo> backupPreviousVersion(final String vspId, final String versionId) {
-
- final String tempName = versionId + "--" + UUID.randomUUID().toString();
- try {
- copy(vspId, tempName, versionId);
- } catch (final Exception e) {
- LOGGER.error("Failed to copy - bucket: '{}', object: '{}'", vspId, versionId, e);
- return Optional.empty();
- }
-
- return Optional.of(new MinIoArtifactInfo(vspId, tempName));
- }
-
- private void rollback(final MinIoArtifactInfo minioObject, final String vspId, final String versionId) {
- try {
- moveFile(minioObject, vspId, versionId);
- } catch (final Exception ex) {
- LOGGER.warn("Could not rollback the backup '{}' to the original '{}'", versionId, minioObject.getObjectName(), ex);
- }
- }
-
- private void removePreviousVersion(final MinIoArtifactInfo minioObject) {
- if (minioObject == null) {
- return;
- }
- delete(minioObject);
- }
-
- private void moveFile(final MinIoArtifactInfo minioObject, final String vspId, final String versionId) {
- try {
- copy(vspId, versionId, minioObject.getObjectName());
- } catch (final Exception e) {
- LOGGER.error("Failed to copy - bucket: '{}', object: '{}'", vspId, versionId, e);
- throw new ArtifactStorageException("Failed to move", e);
- }
- delete(minioObject);
- }
-
- private void copy(final String vspId, final String versionId, final String objectName) throws Exception {
- minioClient.copyObject(
- CopyObjectArgs.builder()
- .bucket(vspId)
- .object(versionId)
- .source(CopySource.builder()
- .bucket(vspId)
- .object(objectName)
- .build())
- .build());
- }
-