Skip to content

Commit

Permalink
add s3 storage option
Browse files Browse the repository at this point in the history
Signed-off-by: Harsh Modi <hmodi@redhat.com>
  • Loading branch information
hjmodi committed Mar 5, 2024
1 parent 835694c commit 8356547
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 5 deletions.
21 changes: 20 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<path-mapped-storage.version>2.6</path-mapped-storage.version>
<path-mapped-storage.version>2.7-SNAPSHOT</path-mapped-storage.version>
<toolchains-plugin.version>3.0.0</toolchains-plugin.version>
<cassandra-maven-plugin.version>3.8</cassandra-maven-plugin.version>
<!--<cassandra-unit.version>3.7.1.0</cassandra-unit.version>-->
Expand All @@ -51,6 +51,17 @@
<skipTests>false</skipTests>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.quarkus.platform</groupId>
<artifactId>quarkus-amazon-services-bom</artifactId>
<version>3.6.4</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
Expand Down Expand Up @@ -145,6 +156,14 @@
<artifactId>indy-security</artifactId>
<version>${indysecurity.verison}</version>
</dependency>
<dependency>
<groupId>io.quarkiverse.amazonservices</groupId>
<artifactId>quarkus-amazon-s3</artifactId>
</dependency>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>url-connection-client</artifactId>
</dependency>

<!-- for unit test -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,21 @@

import io.quarkus.runtime.Startup;
import io.smallrye.config.ConfigMapping;
import io.smallrye.config.WithDefault;
import io.smallrye.config.WithName;

import jakarta.enterprise.context.ApplicationScoped;

import java.io.File;

@Startup
@ConfigMapping( prefix = "storage" )
@ApplicationScoped
public interface StorageServiceConfig
{
String STORAGE_S3 = "s3";

String STORAGE_NFS = "nfs";

@WithName( "baseDir" )
File baseDir();

Expand All @@ -35,4 +40,12 @@ public interface StorageServiceConfig

@WithName( "removableFilesystemPattern" )
String removableFilesystemPattern();

@WithName( "type" )
@WithDefault( STORAGE_NFS )
String type();

@WithName( "bucket.name" )
@WithDefault( "" )
String bucketName();
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@
import org.commonjava.storage.pathmapped.config.PathMappedStorageConfig;
import org.commonjava.storage.pathmapped.core.FileBasedPhysicalStore;
import org.commonjava.storage.pathmapped.core.PathMappedFileManager;
import org.commonjava.storage.pathmapped.core.S3PhysicalStore;
import org.commonjava.storage.pathmapped.pathdb.datastax.CassandraPathDB;
import org.commonjava.storage.pathmapped.spi.PathDB;
import org.commonjava.storage.pathmapped.spi.PhysicalStore;
import software.amazon.awssdk.services.s3.S3Client;

import jakarta.enterprise.context.ApplicationScoped;
import jakarta.enterprise.inject.Produces;
Expand All @@ -42,6 +44,9 @@ public class FileManagerProducer
@Inject
StorageServiceConfig storageConfig;

@Inject
S3Client s3Client;

@Produces
public PathMappedFileManager getFileManager()
{
Expand All @@ -55,10 +60,19 @@ public PathMappedFileManager getFileManager()
PathMappedStorageConfig config = new DefaultPathMappedStorageConfig( props );

PathDB pathDB = new CassandraPathDB( config );
PhysicalStore physicalStore = new FileBasedPhysicalStore( storageConfig.baseDir() );
PhysicalStore physicalStore;
String storageType = storageConfig.type();

if ( StorageServiceConfig.STORAGE_S3.equals( storageType ) )
{
physicalStore = new FileBasedPhysicalStore( storageConfig.baseDir() );
}
else
{
physicalStore = new S3PhysicalStore( s3Client, storageConfig.bucketName() );
}

PathMappedFileManager fileManager = new PathMappedFileManager( config, pathDB, physicalStore );
return fileManager;
return new PathMappedFileManager( config, pathDB, physicalStore );
}

}
6 changes: 6 additions & 0 deletions src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ quarkus:
max-backup-index: 5
max-file-size: 10M

devservices:
enabled: false

swagger-ui:
always-include: true

Expand All @@ -67,6 +70,9 @@ storage:
baseDir: "/tmp"
readonly: false
removableFilesystemPattern: ".+:(remote|group):.+"
type: s3
bucket:
name: test

"%dev":
quarkus:
Expand Down

0 comments on commit 8356547

Please sign in to comment.