@ -6,7 +6,7 @@ import java.io.IOException;
import java.net.UnknownHostException ;
import java.util.List ;
import java.util.Map ;
import java.util.Objects ;
import org.gcube.contentmanagement.blobstorage.resource.MemoryType ;
import org.gcube.contentmanagement.blobstorage.resource.MyFile ;
@ -32,10 +32,9 @@ import java.net.URI;
import software.amazon.awssdk.auth.credentials.AwsSessionCredentials ;
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider ;
import software.amazon.awssdk.regions.Region ;
import software.amazon.awssdk.services.s3.S3Client ;
import com.mongodb.MongoException ;
public class S3PluginManager extends TransportManager {
@ -47,9 +46,9 @@ public class S3PluginManager extends TransportManager {
// THE FOLLOWING FIELDS SHOULD BE RETRIEVED FROM SERVICEENDPOINT
static final String ACCESS_KEY = "UXMKEBMZBDROS5K9HREG" ;
static final String SECRET_ACCESS_KEY = "0Mqu8gmzcZ09wuqqKZwNmuS5bYC549MlZhvfgv6W" ;
Region region = Region . US_EAST _1;
final String END_POINT = "https://s3.wasabisys.com" ;
static final String bucket = "g cube-home-test-access" ;
Region region = Region . EU_NORTH _1;
// final String END_POINT = "https://s3.wasabisys.com";
static String bucket = "g 3-test1data"; // gcube-test;//"g cube-home-test-access";
@Override
@ -69,14 +68,52 @@ public class S3PluginManager extends TransportManager {
}
@Override
public void initBackend ( String [ ] server , String user, String pass , MemoryType memoryType , String [ ] dbNames ,
public void initBackend ( String [ ] server , String accessKey, String secretAccessKey , MemoryType memoryType , String [ ] dbNames ,
String writeConcern , String readConcern ) {
AwsSessionCredentials awsCreds = AwsSessionCredentials . create ( ACCESS_KEY , SECRET_ACCESS_KEY , "" ) ;
// AwsSessionCredentials awsCreds = AwsSessionCredentials.create(ACCESS_KEY, SECRET_ACCESS_KEY, "");
AwsSessionCredentials awsCreds = AwsSessionCredentials . create ( accessKey , secretAccessKey , "" ) ;
// s3 = S3Client.builder().credentialsProvider(
// StaticCredentialsProvider.create(awsCreds))
// .endpointOverride(URI.create(END_POINT)).region(region).build();
// region=Region.of(dbNames[0]);
// region=Region.of("The Netherlands");
// logger.debug("connection to region: "+region);
region = Region . of ( "eu-nl" ) ;
s3 = S3Client . builder ( ) . credentialsProvider (
StaticCredentialsProvider . create ( awsCreds ) )
. endpointOverride ( URI . create ( server [ 0 ] ) ) . region ( region ) . build ( ) ;
// without region specification
// s3 = S3Client.builder().credentialsProvider(
// StaticCredentialsProvider.create(awsCreds))
// .endpointOverride(URI.create(server[0])).build();
}
// @Override
public void initBackendzad ( String [ ] server , String accessKey , String secretAccessKey , MemoryType memoryType , String [ ] dbNames ,
String writeConcern , String readConcern ) {
region = Region . of ( "IT" ) ;
// AwsSessionCredentials awsCreds = AwsSessionCredentials.create(accessKey, secretAccessKey, "");
AwsSessionCredentials awsCreds = AwsSessionCredentials . create ( "1168063577b54b30bd35e9ed209e698e" , "e60be85b39dc4e1e816f6d922c1f2c3a" , "gAAAAABf3MQXCVgepxjLLPAaPb063qABbuMVERNoW7CrQgQpu-Phea-YG1aQEhBwbnQZqkAZMUfI3DaMbFdCPZ7sTJn2RY3hwP8y1qBQmt5oRTxJAHO01JdLcTAOtBLH7et1KPdo-AOLvuwWclYYI2nvztqeT2FhNK5irTY004tm_1pgwvuHRfE" ) ;
// s3 = S3Client.builder().region(newRegion)
// .credentialsProvider(StaticCredentialsProvider.create(awsCreds))
// .httpClientBuilder(ApacheHttpClient.builder().connectionTimeout(Duration.ofSeconds(30))
// .connectionMaxIdleTime(Duration.ofSeconds(30)).socketTimeout(Duration.ofSeconds(60)));
// s3 = s3.endpointOverride(new URI("http://xxxxxxx"));
s3 = S3Client . builder ( ) . credentialsProvider (
StaticCredentialsProvider . create ( awsCreds ) )
. endpointOverride ( URI . create ( END_POINT ) ) . region ( region ) . build ( ) ;
StaticCredentialsProvider . create ( awsCreds ) )
. endpointOverride ( URI . create ( "https://vsa-0000000e-it-momit-01.zadarazios.com:443" ) ) . region ( region ) . build ( ) ;
}
@Override
public Object get ( Download download ) throws FileNotFoundException , IOException {
@ -85,10 +122,13 @@ public class S3PluginManager extends TransportManager {
@Override
public String put ( Upload upload ) throws FileNotFoundException , IOException {
logger . info ( "put method invoked " ) ;
logger . trace ( "put method invoked " ) ;
String bucketName = Utils . convertToS3Format ( upload . getResource ( ) . getRootPath ( ) ) ;
if ( ! BucketOperator . isBucket ( s3 , bucketName ) )
BucketOperator . createBucketWaiter ( s3 , bucketName , region ) ;
File file = new File ( upload . getResource ( ) . getLocalPath ( ) ) ;
// return BucketOperator.getInstance(s3).putObject(bucket, Utils.convertToS3Format(upload.getResource().getRemotePath()), file).toString();
int hashcode = BucketOperator . getInstance ( s3 ) . putObject ( bucket , Utils . convertToS3Format ( upload . getResource ( ) . getRemotePath ( ) ) , file , upload . isReplaceOption ( ) ) . hashCode ( ) ;
int hashcode = BucketOperator . getInstance ( s3 ) . putObject ( bucket Name , Utils . convertToS3Format ( upload . getResource ( ) . getRemotePath ( ) ) , file , upload . isReplaceOption ( ) ) . hashCode ( ) ;
return hashcode + "" ;
}
@ -113,7 +153,7 @@ public class S3PluginManager extends TransportManager {
public long getSize ( String key , MyFile file ) {
logger . info ( "remoteObject identifier " + key ) ;
try {
return BucketOperator . getObjectSize ( bucket , Utils . convertToS3Format ( file . getRemotePath ( ) ) ) ;
return BucketOperator . getObjectSize ( Utils. convertToS3Format ( file . getRootPath ( ) ) , Utils . convertToS3Format ( file . getRemotePath ( ) ) ) ;
} catch ( IOException e ) {
e . printStackTrace ( ) ;
throw new RemoteBackendException ( "Problem during getSize Operation on s3 cloud storage" ) ;
@ -231,5 +271,6 @@ public class S3PluginManager extends TransportManager {
public String duplicateFile ( DuplicateFile duplicate ) {
throw new RemoteBackendException ( "method not implemented yet on s3 plugin" ) ;
}
}