Skip to content

Commit e651add

Browse files
committed
add s3 storage option
Signed-off-by: Harsh Modi <[email protected]>
1 parent 8a3b3ea commit e651add

File tree

3 files changed

+54
-2
lines changed

3 files changed

+54
-2
lines changed

filers/default/src/main/java/org/commonjava/indy/filer/def/DefaultGalleyStorageProvider.java

+18-1
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,15 @@
5656
import org.commonjava.maven.galley.transport.htcli.UploadMetadataGenTransferDecorator;
5757
import org.commonjava.storage.pathmapped.config.DefaultPathMappedStorageConfig;
5858
import org.commonjava.storage.pathmapped.config.PathMappedStorageConfig;
59+
import org.commonjava.storage.pathmapped.core.S3PhysicalStore;
5960
import org.commonjava.storage.pathmapped.pathdb.datastax.CassandraPathDB;
6061
import org.commonjava.storage.pathmapped.metrics.MeasuredPathDB;
6162
import org.commonjava.storage.pathmapped.spi.PathDB;
6263
import org.commonjava.storage.pathmapped.spi.PhysicalStore;
6364
import org.slf4j.Logger;
6465
import org.slf4j.LoggerFactory;
66+
import software.amazon.awssdk.services.s3.S3Client;
67+
import software.amazon.awssdk.services.s3.model.S3Exception;
6568

6669
import javax.annotation.PostConstruct;
6770
import javax.enterprise.context.ApplicationScoped;
@@ -236,7 +239,21 @@ protected boolean isMetricEnabled( String metricName )
236239
}
237240

238241
File legacyBaseDir = config.getLegacyStorageBasedir();
239-
PhysicalStore physicalStore = new LegacyReadonlyPhysicalStore( storeRoot, legacyBaseDir );
242+
String storageType = config.getStorageType();
243+
PhysicalStore physicalStore;
244+
if (DefaultStorageProviderConfiguration.STORAGE_NFS.equals( storageType )) {
245+
physicalStore = new LegacyReadonlyPhysicalStore( storeRoot, legacyBaseDir );
246+
} else {
247+
try {
248+
S3Client s3Client = S3Client.builder().build();
249+
String bucketName = config.getBucketName();
250+
physicalStore = new S3PhysicalStore( s3Client, bucketName );
251+
} catch ( S3Exception e ) {
252+
logger.error( "Ran into error during storage init e: ", e);
253+
throw e;
254+
}
255+
256+
}
240257

241258
logger.info( "Create cacheProviderFactory, pathDB: {}, physicalStore: {}", pathDB, physicalStore );
242259
PathMappedCacheProviderConfig cacheProviderConfig =

filers/default/src/main/java/org/commonjava/indy/filer/def/conf/DefaultStorageProviderConfiguration.java

+35
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ public class DefaultStorageProviderConfiguration
3838

3939
public static final String STORAGE_DIR = "indy.storage.dir";
4040

41+
public static final String STORAGE_S3 = "s3";
42+
43+
public static final String STORAGE_NFS = "nfs";
44+
45+
public static final String DEFAULT_STORAGE = STORAGE_NFS;
46+
4147
public static final String NFS_STORAGE_DIR = "indy.storage.nfs.dir";
4248

4349
private File storageBasedir;
@@ -46,6 +52,10 @@ public class DefaultStorageProviderConfiguration
4652

4753
private File nfsStoreBasedir;
4854

55+
private String storageType;
56+
57+
private String bucketName;
58+
4959
private boolean storageTimeoutEnabled = true;
5060

5161
private boolean physicalFileExistenceCheckEnabled = false;
@@ -220,6 +230,31 @@ public void setLegacyStorageBasedir( File legacyStorageBasedir )
220230
this.legacyStorageBasedir = legacyStorageBasedir;
221231
}
222232

233+
public String getStorageType()
234+
{
235+
if (storageType == null) {
236+
return DEFAULT_STORAGE;
237+
}
238+
return storageType;
239+
}
240+
241+
@ConfigName( "storage.type" )
242+
public void setStorageType( String storageType )
243+
{
244+
this.storageType = storageType;
245+
}
246+
247+
public String getBucketName()
248+
{
249+
return bucketName;
250+
}
251+
252+
@ConfigName( "storage.bucket.name" )
253+
public void setBucketName( String bucketName )
254+
{
255+
this.bucketName = bucketName;
256+
}
257+
223258
public boolean isStorageTimeoutEnabled()
224259
{
225260
return storageTimeoutEnabled;

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
<otelInstrumentationVersion>1.19.0-alpha</otelInstrumentationVersion>
8484
<cassandraUnitVersion>3.7.1.0</cassandraUnitVersion>
8585
<datastaxVersion>3.11.3</datastaxVersion>
86-
<pathmappedStorageVersion>2.6</pathmappedStorageVersion>
86+
<pathmappedStorageVersion>2.7-SNAPSHOT</pathmappedStorageVersion>
8787
<o11yphantVersion>1.9.1</o11yphantVersion>
8888
<swaggerVersion>1.6.6</swaggerVersion>
8989
<agroalVersion>1.16</agroalVersion>

0 commit comments

Comments
 (0)