Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions multiapps-controller-persistence/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,8 @@
<artifactId>aws-s3</artifactId>
</dependency>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-storage-blob</artifactId>
</dependency>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-core-http-okhttp</artifactId>
<groupId>org.apache.jclouds.provider</groupId>
<artifactId>azureblob</artifactId>
</dependency>
<dependency>
<groupId>org.apache.jclouds</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@
requires transitive org.cloudfoundry.multiapps.controller.api;

requires aliyun.sdk.oss;
requires com.azure.core;
requires com.azure.core.http.okhttp;
requires com.azure.storage.blob;
requires com.fasterxml.jackson.annotation;
requires com.fasterxml.jackson.databind;
requires com.google.auth;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ public final class Messages {

// ERROR log messages:
public static final String UPLOAD_STREAM_FAILED_TO_CLOSE = "Cannot close file upload stream";
public static final String CANNOT_PARSE_CONTAINER_URI_OF_OBJECT_STORE = "Cannot parse container_uri of object store";
public static final String MISSING_CONTAINER_URI_IN_THE_CREDENTIALS = "Missing container url in the credentials";

// WARN log messages:
public static final String COULD_NOT_CLOSE_RESULT_SET = "Could not close result set.";
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
package org.cloudfoundry.multiapps.controller.persistence.services;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.channels.Channels;
import java.text.MessageFormat;
import java.time.Duration;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Base64;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Predicate;
import java.util.stream.Collectors;

import com.google.api.gax.retrying.RetrySettings;
import com.google.auth.Credentials;
import com.google.auth.oauth2.GoogleCredentials;
Expand All @@ -13,32 +28,21 @@
import com.google.cloud.storage.StorageRetryStrategy;
import org.cloudfoundry.multiapps.controller.persistence.Messages;
import org.cloudfoundry.multiapps.controller.persistence.model.FileEntry;
import org.cloudfoundry.multiapps.controller.persistence.util.ObjectStoreConstants;
import org.cloudfoundry.multiapps.controller.persistence.util.ObjectStoreFilter;
import org.cloudfoundry.multiapps.controller.persistence.util.ObjectStoreMapper;
import org.springframework.http.MediaType;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.channels.Channels;
import java.text.MessageFormat;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Base64;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.function.Predicate;
import java.util.stream.Collectors;

public class GcpObjectStoreFileStorage implements FileStorage {

private final String bucketName;
private final Storage storage;
private static final String BASE_64_ENCODED_PRIVATE_KEY_DATA = "base64EncodedPrivateKeyData";
private static final String BUCKET = "bucket";
private static final int OBJECT_STORE_MAX_ATTEMPTS_CONFIG = 6;
private static final double OBJECT_STORE_RETRY_DELAY_MULTIPLIER_CONFIG = 2.0;
private static final Duration OBJECT_STORE_TOTAL_TIMEOUT_CONFIG_IN_MINUTES = Duration.ofMinutes(10);
private static final Duration OBJECT_STORE_MAX_RETRY_DELAY_CONFIG_IN_SECONDS = Duration.ofSeconds(10);
private static final Duration OBJECT_STORE_INITIAL_RETRY_DELAY_CONFIG_IN_MILLIS = Duration.ofMillis(250);
private static final String BASE_64_ENCODED_PRIVATE_KEY_DATA = "base64EncodedPrivateKeyData";

public GcpObjectStoreFileStorage(Map<String, Object> credentials) {
this.bucketName = (String) credentials.get(BUCKET);
Expand All @@ -51,12 +55,11 @@ protected Storage createObjectStoreStorage(Map<String, Object> credentials) {
.setStorageRetryStrategy(StorageRetryStrategy.getUniformStorageRetryStrategy())
.setRetrySettings(
RetrySettings.newBuilder()
.setMaxAttempts(ObjectStoreConstants.OBJECT_STORE_MAX_ATTEMPTS_CONFIG)
.setTotalTimeoutDuration(ObjectStoreConstants.OBJECT_STORE_TOTAL_TIMEOUT_CONFIG_IN_MINUTES)
.setMaxRetryDelayDuration(ObjectStoreConstants.OBJECT_STORE_MAX_RETRY_DELAY_CONFIG_IN_SECONDS)
.setInitialRetryDelayDuration(
ObjectStoreConstants.OBJECT_STORE_INITIAL_RETRY_DELAY_CONFIG_IN_MILLIS)
.setRetryDelayMultiplier(ObjectStoreConstants.OBJECT_STORE_RETRY_DELAY_MULTIPLIER_CONFIG)
.setMaxAttempts(OBJECT_STORE_MAX_ATTEMPTS_CONFIG)
.setTotalTimeoutDuration(OBJECT_STORE_TOTAL_TIMEOUT_CONFIG_IN_MINUTES)
.setMaxRetryDelayDuration(OBJECT_STORE_MAX_RETRY_DELAY_CONFIG_IN_SECONDS)
.setInitialRetryDelayDuration(OBJECT_STORE_INITIAL_RETRY_DELAY_CONFIG_IN_MILLIS)
.setRetryDelayMultiplier(OBJECT_STORE_RETRY_DELAY_MULTIPLIER_CONFIG)
.build())
.build()
.getService();
Expand Down Expand Up @@ -105,24 +108,6 @@ public List<FileEntry> getFileEntriesWithoutContent(List<FileEntry> fileEntries)
.toList();
}

@Override
public List<FileEntry> getExistingFileEntries(List<FileEntry> fileEntries) {
if (fileEntries.isEmpty()) {
return List.of();
}
List<BlobId> blobIds = fileEntries.stream()
.map(fileEntry -> BlobId.of(bucketName, fileEntry.getId()))
.toList();
List<Blob> blobs = storage.get(blobIds);
Set<String> existingBlobNames = blobs.stream()
.filter(Objects::nonNull)
.map(Blob::getName)
.collect(Collectors.toSet());
return fileEntries.stream()
.filter(fileEntry -> existingBlobNames.contains(fileEntry.getId()))
.toList();
}

@Override
public void deleteFile(String id, String space) {
deleteFileWithGeneration(id);
Expand Down

This file was deleted.

Loading
Loading