Skip to content

Commit

Permalink
fix: fixed bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
YarikRevich committed Nov 28, 2024
1 parent 7be609a commit 07e43b6
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 47 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.objectstorage.dto;

import lombok.AllArgsConstructor;
import lombok.Getter;

/**
* Represents vendor object listing.
*/
@Getter
@AllArgsConstructor(staticName = "of")
public class VendorObjectListingDto {
/**
* Represent location.
*/
private String location;

/**
* Represents created at timestamp.
*/
private Long createdAt;
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.objectstorage.model.*;
import com.objectstorage.repository.*;
import com.objectstorage.repository.common.RepositoryConfigurationHelper;
import com.objectstorage.service.telemetry.TelemetryService;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;

Expand Down Expand Up @@ -44,6 +45,9 @@ public class RepositoryFacade {
@Inject
SecretRepository secretRepository;

@Inject
TelemetryService telemetryService;

/**
* Retrieves filtered content from temporate repository.
*
Expand Down Expand Up @@ -94,11 +98,17 @@ public List<ContentRetrievalProviderUnit> retrieveFilteredTemporateContent(
* @throws TemporateContentRetrievalFailureException if temporate content amount retrieval fails.
*/
public Boolean isTemporateContentPresent() throws TemporateContentRetrievalFailureException {
Integer amount;

try {
return temporateRepository.count() > 0;
amount = temporateRepository.count();
} catch (RepositoryOperationFailureException e) {
throw new TemporateContentRetrievalFailureException(e.getMessage());
}

telemetryService.setTemporateStorageFilesAmount(amount);

return amount > 0;
}

/**
Expand Down Expand Up @@ -225,8 +235,8 @@ public TemporateContentUnitDto retrieveTemporateContentByLocationProviderAndSecr
try {
temporate = temporateRepository
.findEarliestByLocationProviderAndSecret(location, provider.getId(), secret.getId());
} catch (RepositoryOperationFailureException e) {
throw new TemporateContentRemovalFailureException(e.getMessage());
} catch (RepositoryOperationFailureException ignored) {
return null;
}

return TemporateContentUnitDto.of(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,6 @@ public void process() throws BackupPeriodRetrievalFailureException {
scheduledOperationExecutorService.scheduleWithFixedDelay(() -> {
StateService.getBackupProcessorGuard().lock();

// vendorFacade.listAllObjectsFromBucket(
//
// );

// vendorFacade.listAllObjectsFromBucket().get(0).

// workspaceFacade.add

StateService.getBackupProcessorGuard().unlock();
}, 0, period, TimeUnit.MILLISECONDS);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
* Provides high-level access to ObjectStorage processor operations.
Expand Down Expand Up @@ -307,12 +308,14 @@ public byte[] downloadObject(
throw new ProcessorContentDownloadFailureException(e.getMessage());
}

try {
if (workspaceFacade.isObjectFilePresent(workspaceUnitKey, temporateContentUnit.getHash())) {
return workspaceFacade.getObjectFile(workspaceUnitKey, temporateContentUnit.getHash());
if (Objects.nonNull(temporateContentUnit)) {
try {
if (workspaceFacade.isObjectFilePresent(workspaceUnitKey, temporateContentUnit.getHash())) {
return workspaceFacade.getObjectFile(workspaceUnitKey, temporateContentUnit.getHash());
}
} catch (FileExistenceCheckFailureException | FileUnitRetrievalFailureException e) {
throw new ProcessorContentDownloadFailureException(e.getMessage());
}
} catch (FileExistenceCheckFailureException | FileUnitRetrievalFailureException e) {
throw new ProcessorContentDownloadFailureException(e.getMessage());
}

RepositoryContentUnitDto repositoryContentLocationUnitDto;
Expand Down Expand Up @@ -481,18 +484,20 @@ public void removeObject(
throw new ProcessorContentRemovalFailureException(e1.getMessage());
}

try {
if (workspaceFacade.isObjectFilePresent(workspaceUnitKey, temporateContentUnit.getHash())) {
workspaceFacade.removeObjectFile(workspaceUnitKey, temporateContentUnit.getHash());
}
} catch (FileExistenceCheckFailureException | FileRemovalFailureException e1) {
if (Objects.nonNull(temporateContentUnit)) {
try {
repositoryExecutor.rollbackTransaction();
} catch (TransactionRollbackFailureException e2) {
throw new ProcessorContentRemovalFailureException(e2.getMessage());
if (workspaceFacade.isObjectFilePresent(workspaceUnitKey, temporateContentUnit.getHash())) {
workspaceFacade.removeObjectFile(workspaceUnitKey, temporateContentUnit.getHash());
}
} catch (FileExistenceCheckFailureException | FileRemovalFailureException e1) {
try {
repositoryExecutor.rollbackTransaction();
} catch (TransactionRollbackFailureException e2) {
throw new ProcessorContentRemovalFailureException(e2.getMessage());
}

throw new ProcessorContentRemovalFailureException(e1.getMessage());
}

throw new ProcessorContentRemovalFailureException(e1.getMessage());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,24 +71,14 @@ private void configure() {
}

/**
* Increases current amount of files in ObjectStorage Temporate Storage.
* Sets current amount of files in ObjectStorage Temporate Storage.
*
* @param value given value.
*/
public void increaseTemporateStorageFilesAmount() {
public void setTemporateStorageFilesAmount(Integer value) {
if (configService.getConfig().getDiagnostics().getEnabled()) {
temporateStorageFilesAmountQueue.add(
() -> telemetryBinding.getTemporateStorageFilesAmount().set(
telemetryBinding.getTemporateStorageFilesAmount().get() + 1));
}
}

/**
* Decreases current amount of files in ObjectStorage Temporate Storage.
*/
public void decreaseTemporateStorageFilesAmount() {
if (configService.getConfig().getDiagnostics().getEnabled()) {
temporateStorageFilesAmountQueue.add(
() -> telemetryBinding.getTemporateStorageFilesAmount().set(
telemetryBinding.getTemporateStorageFilesAmount().get() - 1));
() -> telemetryBinding.getTemporateStorageFilesAmount().set(value));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,8 @@ public List<ContentRetrievalProviderUnit> listAllObjectsFromBucket(
bucketName,
credentialsFieldExternal.getRegion())
.stream()
.map(ContentRetrievalProviderUnit::of)
.map(element -> ContentRetrievalProviderUnit.of(
element.getLocation(), element.getCreatedAt()))
.toList();
}
case GCS -> {
Expand All @@ -333,7 +334,8 @@ public List<ContentRetrievalProviderUnit> listAllObjectsFromBucket(

yield gcsVendorService.listObjectsFromGCSBucket(credentials, bucketName)
.stream()
.map(ContentRetrievalProviderUnit::of)
.map(element -> ContentRetrievalProviderUnit.of(
element.getLocation(), element.getCreatedAt()))
.toList();
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.google.cloud.resourcemanager.ResourceManagerOptions;
import com.google.cloud.resourcemanager.Project;
import com.google.cloud.storage.*;
import com.objectstorage.dto.VendorObjectListingDto;
import com.objectstorage.exception.GCPCredentialsInitializationFailureException;
import com.objectstorage.exception.GCSBucketObjectUploadFailureException;
import jakarta.enterprise.context.ApplicationScoped;
Expand Down Expand Up @@ -173,7 +174,7 @@ public byte[] retrieveObjectFromGCSBucket(
* @param bucketName given name of the GCS bucket.
* @return listed objects.
*/
public List<String> listObjectsFromGCSBucket(
public List<VendorObjectListingDto> listObjectsFromGCSBucket(
Credentials credentials,
String bucketName) {
Storage storage = StorageOptions.newBuilder()
Expand All @@ -184,7 +185,9 @@ public List<String> listObjectsFromGCSBucket(
Page<Blob> blobs = storage.list(bucketName);

return StreamSupport.stream(blobs.iterateAll().spliterator(), false)
.map(element -> element.getBlobId().getName())
.map(element -> VendorObjectListingDto.of(
element.getBlobId().getName(),
element.getUpdateTimeOffsetDateTime().toEpochSecond()))
.toList();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.amazonaws.services.securitytoken.model.GetCallerIdentityRequest;
import com.amazonaws.waiters.WaiterParameters;
import com.objectstorage.dto.AWSSecretsDto;
import com.objectstorage.dto.VendorObjectListingDto;
import com.objectstorage.exception.S3BucketObjectRetrievalFailureException;
import com.objectstorage.exception.VendorOperationFailureException;
import jakarta.enterprise.context.ApplicationScoped;
Expand Down Expand Up @@ -271,7 +272,7 @@ public byte[] retrieveObjectFromS3Bucket(
* @return listed objects.
* @throws VendorOperationFailureException if vendor operation fails.
*/
public List<String> listObjectsFromS3Bucket(
public List<VendorObjectListingDto> listObjectsFromS3Bucket(
AWSCredentialsProvider awsCredentialsProvider,
String bucketName,
String region) throws VendorOperationFailureException {
Expand All @@ -285,7 +286,8 @@ public List<String> listObjectsFromS3Bucket(
return simpleStorage
.listObjects(bucketName)
.getObjectSummaries()
.stream().map(S3ObjectSummary::getKey)
.stream().map(element -> VendorObjectListingDto.of(
element.getKey(), element.getLastModified().getTime()))
.toList();
} catch (Exception e) {
throw new VendorOperationFailureException(e.getMessage());
Expand Down

0 comments on commit 07e43b6

Please sign in to comment.