Skip to content
This repository has been archived by the owner on May 16, 2023. It is now read-only.

Use version path parts from application configuration #596

Merged
merged 2 commits into from
Jun 17, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@
@Component
public class CwaApiStructureProvider {

public static final String VERSION_DIRECTORY = "version";
public static final String VERSION_V1 = "v1";

private final AppConfigurationStructureProvider appConfigurationStructureProvider;

private final DiagnosisKeysStructureProvider diagnosisKeysStructureProvider;
Expand All @@ -60,7 +57,8 @@ public class CwaApiStructureProvider {
*/
public Directory<WritableOnDisk> getDirectory() {
IndexDirectoryOnDisk<String> versionDirectory =
new IndexDirectoryOnDisk<>(VERSION_DIRECTORY, __ -> Set.of(VERSION_V1), Object::toString);
new IndexDirectoryOnDisk<>(distributionServiceConfig.getApi().getVersionPath(),
__ -> Set.of(distributionServiceConfig.getApi().getVersionV1()), Object::toString);

versionDirectory
.addWritableToAll(__ -> appConfigurationStructureProvider.getAppConfiguration());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

package app.coronawarn.server.services.distribution.objectstore;

import app.coronawarn.server.services.distribution.assembly.component.CwaApiStructureProvider;
import app.coronawarn.server.services.distribution.config.DistributionServiceConfig;
import app.coronawarn.server.services.distribution.objectstore.client.ObjectStoreOperationFailedException;
import app.coronawarn.server.services.distribution.objectstore.publish.LocalFile;
import app.coronawarn.server.services.distribution.objectstore.publish.PublishFileSet;
Expand All @@ -37,8 +37,7 @@
import org.springframework.stereotype.Component;

/**
* Publishes a folder on the disk to S3 while keeping the folder and file structure.<br>
* Moreover, does the following:
* Publishes a folder on the disk to S3 while keeping the folder and file structure.<br> Moreover, does the following:
* <br>
* <ul>
* <li>Publishes index files on a different route, removing the trailing "/index" part.</li>
Expand All @@ -55,29 +54,28 @@ public class S3Publisher {

private static final Logger logger = LoggerFactory.getLogger(S3Publisher.class);

/**
* The default CWA root folder, which contains all CWA related files.
*/
private static final String CWA_S3_ROOT = CwaApiStructureProvider.VERSION_DIRECTORY;

private final ObjectStoreAccess objectStoreAccess;
private final FailedObjectStoreOperationsCounter failedOperationsCounter;
private final ThreadPoolTaskExecutor executor;
private final DistributionServiceConfig distributionServiceConfig;

/**
* Creates an {@link S3Publisher} instance that attempts to publish the files at the specified location to an object
* store. Object store operations are performed through the specified {@link ObjectStoreAccess} instance.
*
* @param objectStoreAccess The {@link ObjectStoreAccess} used to communicate with the object store.
* @param failedOperationsCounter The {@link FailedObjectStoreOperationsCounter} that is used to monitor the number of
* failed operations.
* @param executor The executor that manages the upload task submission.
* @param objectStoreAccess The {@link ObjectStoreAccess} used to communicate with the object store.
* @param failedOperationsCounter The {@link FailedObjectStoreOperationsCounter} that is used to monitor the number
* of failed operations.
* @param executor The executor that manages the upload task submission.
* @param distributionServiceConfig The {@link DistributionServiceConfig} used for distribution service
* configuration.
*/
public S3Publisher(ObjectStoreAccess objectStoreAccess, FailedObjectStoreOperationsCounter failedOperationsCounter,
ThreadPoolTaskExecutor executor) {
ThreadPoolTaskExecutor executor, DistributionServiceConfig distributionServiceConfig) {
this.objectStoreAccess = objectStoreAccess;
this.failedOperationsCounter = failedOperationsCounter;
this.executor = executor;
this.distributionServiceConfig = distributionServiceConfig;
}

/**
Expand All @@ -92,7 +90,8 @@ public void publish(Path root) throws IOException {
List<LocalFile> diff;

try {
published = new PublishedFileSet(objectStoreAccess.getObjectsWithPrefix(CWA_S3_ROOT));
published = new PublishedFileSet(
objectStoreAccess.getObjectsWithPrefix(distributionServiceConfig.getApi().getVersionPath()));
diff = toPublish
.stream()
.filter(published::isNotYetPublished)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ public S3RetentionPolicy(ObjectStoreAccess objectStoreAccess, DistributionServic
* @param retentionDays the number of days, that files should be retained on S3.
*/
public void applyRetentionPolicy(int retentionDays) {
List<S3Object> diagnosisKeysObjects = objectStoreAccess.getObjectsWithPrefix("version/v1/"
List<S3Object> diagnosisKeysObjects = objectStoreAccess.getObjectsWithPrefix(api.getVersionPath() + "/"
+ api.getVersionV1() + "/"
+ api.getDiagnosisKeysPath() + "/"
+ api.getCountryPath() + "/"
+ api.getCountryGermany() + "/"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import app.coronawarn.server.services.distribution.config.DistributionServiceConfig;
import app.coronawarn.server.services.distribution.config.DistributionServiceConfig.Api;
import app.coronawarn.server.services.distribution.objectstore.client.ObjectStoreOperationFailedException;
import app.coronawarn.server.services.distribution.objectstore.client.S3Object;
import java.io.IOException;
Expand All @@ -43,12 +45,17 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.test.context.ConfigFileApplicationContextInitializer;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.core.io.ResourceLoader;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit.jupiter.SpringExtension;

@EnableConfigurationProperties(value = DistributionServiceConfig.class)
@ExtendWith(SpringExtension.class)
@ContextConfiguration(classes = {Api.class}, initializers = ConfigFileApplicationContextInitializer.class)
class S3PublisherTest {

private static final S3Object FILE_1 = new S3Object("file1.txt", "cf7fb1ca5c32adc0941c35a6f7fc5eba");
Expand All @@ -64,6 +71,9 @@ class S3PublisherTest {
@Autowired
private ResourceLoader resourceLoader;

@Autowired
private DistributionServiceConfig distributionServiceConfig;

private ThreadPoolTaskExecutor executor;
private Path publishingPath;
private S3Publisher s3Publisher;
Expand All @@ -76,7 +86,8 @@ void setup() throws IOException {
executor.setCorePoolSize(1);
executor.initialize();
executor = spy(executor);
s3Publisher = new S3Publisher(objectStoreAccess, failedObjectStoreOperationsCounter, executor);
s3Publisher = new S3Publisher(objectStoreAccess, failedObjectStoreOperationsCounter, executor,
distributionServiceConfig);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ void deleteDiagnosisKeysUpdatesFailedOperationCounter() {
private String generateFileName(LocalDate date) {
var api = distributionServiceConfig.getApi();

return "version/v1/" + api.getDiagnosisKeysPath() + "/" + api.getCountryPath() + "/"
+ api.getCountryGermany() + "/" + api.getDatePath() + "/" + date.toString() + "/hour/0";
return api.getVersionPath() + "/" + api.getVersionV1() + "/" + api.getDiagnosisKeysPath() + "/"
+ api.getCountryPath() + "/" + api.getCountryGermany() + "/" + api.getDatePath() + "/" + date.toString() + "/"
+ api.getHourPath() + "/0";
}
}