AWSCredentials awsCredentials = new AWSCredentials(awsAccessKey, awsSecretKey); try { S3Service s3Service = new RestS3Service(awsCredentials);
private AWSCredentials getCredentials() { AWSCredentials credentials = new AWSCredentials(accessKey, secretKey); return credentials; }
<br> public List getFilesList(String accessKey, String secretKey ,String bucketName ,String directoryPathRelativeToBucket) { List keys = new ArrayList(); org.jets3t.service.model.S3Object[] objects = new org.jets3t.service.model.S3Object[]{}; try { // Create a credentials object and service to access S3 account org.jets3t.service.security.AWSCredentials myCredentials = new org.jets3t.service.security.AWSCredentials(accessKey, secretKey); </br>
AWSCredentials credentials = new AWSCredentials(); AmazonEC2Client client = new AmazonEC2Client(credentials); CreateVolumeResult request = new CreateVolumeRequest(java.lang.Integer size, java.lang.String availabilityZone); CreateVolumeResponse volumeResponse = client.createVolume(request); AttachVolumeRequest attachRequest = new AttachVolumeRequest(volumeResponse.getVolume().getVolumeId(), java.lang.String instanceId, java.lang.String device); client.attachVolume(attachRequest);
public static boolean checkAuth(String awsAccessKey, String awsSecretKey) { AWSCredentials creds = null; try { creds = new AWSCredentials(awsAccessKey, awsSecretKey); RestS3Service s3Service = new RestS3Service(creds); s3Service.listAllBuckets(); return true; } catch (Exception e) { SDFSLogger.getLog().fatal("Unable to authenticate to AWS", e); return false; } }
public static boolean checkBucketUnique(String awsAccessKey, String awsSecretKey, String bucketName) { AWSCredentials creds = null; try { creds = new AWSCredentials(awsAccessKey, awsSecretKey); RestS3Service s3Service = new RestS3Service(creds); S3Bucket s3Bucket = s3Service.getBucket(bucketName); if (s3Bucket == null) { return true; // s3Bucket = s3Service.createBucket(bucketName); } return false; } catch (Exception e) { SDFSLogger.getLog().fatal("Unable to create aws bucket", e); return false; } }
/** * * @param awsCredentials * @param defaultContainerName * @throws StorageException */ public S3Template(final AwsCredentials awsCredentials, final String defaultContainerName) throws StorageException { this.defaultContainerName = defaultContainerName; try { s3Service = new RestS3Service(new org.jets3t.service.security.AWSCredentials(awsCredentials.getAccessKey(), awsCredentials.getSecretAccessKey())); // Next statement checks if connection works. This is sugested by jets3t documentation. s3Service.listAllBuckets(); } catch (S3ServiceException e) { throw new StorageException("Failed to prepare S3 service.", e); } }
@Override public void initialize(URI uri, Configuration conf) throws IOException { S3Credentials s3Credentials = new S3Credentials(); s3Credentials.initialize(uri, conf); try { AWSCredentials awsCredentials = new AWSCredentials(s3Credentials.getAccessKey(), s3Credentials.getSecretAccessKey()); this.s3Service = new RestS3Service(awsCredentials); } catch (S3ServiceException e) { handleException(e); } multipartEnabled = conf.getBoolean("fs.s3n.multipart.uploads.enabled", false); multipartBlockSize = Math.min( conf.getLong("fs.s3n.multipart.uploads.block.size", 64 * 1024 * 1024), MAX_PART_SIZE); multipartCopyBlockSize = Math.min( conf.getLong("fs.s3n.multipart.copy.block.size", MAX_PART_SIZE), MAX_PART_SIZE); serverSideEncryptionAlgorithm = conf.get("fs.s3n.server-side-encryption-algorithm"); bucket = new S3Bucket(uri.getHost()); }
public static void deleteBucket(String bucketName, String awsAccessKey, String awsSecretKey) { bucketName = bucketName.toLowerCase(); try { System.out.println(""); System.out.print("Deleting Bucket [" + bucketName + "]"); AWSCredentials bawsCredentials = new AWSCredentials(awsAccessKey, awsSecretKey); S3Service bs3Service = new RestS3Service(bawsCredentials); S3Object[] obj = bs3Service.listObjects(bucketName); for (int i = 0; i < obj.length; i++) { bs3Service.deleteObject(bucketName, obj[i].getKey()); System.out.print("."); } bs3Service.deleteBucket(bucketName); SDFSLogger.getLog().info("Bucket [" + bucketName + "] deleted"); System.out.println("Bucket [" + bucketName + "] deleted"); } catch (ServiceException e) { SDFSLogger.getLog() .warn("Unable to delete bucket " + bucketName, e); } }
@Override protected InputStream createData() throws IOException { RestS3Service service = null; try { service = new RestS3Service(new AWSCredentials(getAccess(), getSecret())); S3Object object = service.getObject(getBucket(), getPath()); return new ServiceInputStream(service, object.getDataInputStream()); } catch (ServiceException ex) { throw new IOException(String.format("Unable to store [%s] file!", getPath()), ex); } }
public static void deleteBucket(String bucketName, String awsAccessKey, String awsSecretKey) { try { System.out.println(""); System.out.print("Deleting Bucket [" + bucketName + "]"); AWSCredentials bawsCredentials = new AWSCredentials(awsAccessKey, awsSecretKey); S3Service bs3Service = new RestS3Service(bawsCredentials); S3Object[] obj = bs3Service.listObjects(bucketName); for (int i = 0; i < obj.length; i++) { bs3Service.deleteObject(bucketName, obj[i].getKey()); System.out.print("."); } bs3Service.deleteBucket(bucketName); SDFSLogger.getLog().info("Bucket [" + bucketName + "] deleted"); System.out.println("Bucket [" + bucketName + "] deleted"); } catch (ServiceException e) { SDFSLogger.getLog() .warn("Unable to delete bucket " + bucketName, e); } }
/** * Get S3 Service * * @return S3Service */ private S3Service getS3Service() { S3Service s3Service = null; try { s3Service = new RestS3Service(new AWSCredentials(AmazonCredential.getInstance().getAwsAccessKeyId(), AmazonCredential.getInstance().getAwsSecretAccessKey())); } catch (S3ServiceException s3ex) { xBayaEngine.getGUI().getErrorWindow().error(s3ex); } return s3Service; }
@Override public boolean isInStorage() { try { RestS3Service service = null; try { service = new RestS3Service(new AWSCredentials(getAccess(), getSecret())); service.getObjectDetails(getBucket(), getPath()); return true; } finally { if (service != null) { service.shutdown(); } } } catch (ServiceException error) { return false; } }
@Provides @LazySingleton public RestS3Service getRestS3Service(AWSCredentialsProvider provider) { if (provider.getCredentials() instanceof AWSSessionCredentials) { return new RestS3Service(new AWSSessionCredentialsAdapter(provider)); } else { return new RestS3Service(new AWSCredentials( provider.getCredentials().getAWSAccessKeyId(), provider.getCredentials().getAWSSecretKey() )); } } }
public void initialize(URI uri, Configuration conf) throws IOException { this.conf = conf; S3Credentials s3Credentials = new S3Credentials(); s3Credentials.initialize(uri, conf); try { AWSCredentials awsCredentials = new AWSCredentials(s3Credentials.getAccessKey(), s3Credentials.getSecretAccessKey()); this.s3Service = new RestS3Service(awsCredentials); } catch (S3ServiceException e) { if (e.getCause() instanceof IOException) { throw (IOException) e.getCause(); } throw new S3Exception(e); } bucket = new S3Bucket(uri.getHost()); this.bufferSize = conf.getInt("io.file.buffer.size", 4096); }
@Override public void initialize(URI uri, Configuration conf) throws IOException { this.conf = conf; S3Credentials s3Credentials = new S3Credentials(); s3Credentials.initialize(uri, conf); try { AWSCredentials awsCredentials = new AWSCredentials(s3Credentials.getAccessKey(), s3Credentials.getSecretAccessKey()); this.s3Service = new RestS3Service(awsCredentials); } catch (S3ServiceException e) { if (e.getCause() instanceof IOException) { throw (IOException) e.getCause(); } throw new S3Exception(e); } bucket = new S3Bucket(uri.getHost()); this.bufferSize = conf.getInt( S3FileSystemConfigKeys.S3_STREAM_BUFFER_SIZE_KEY, S3FileSystemConfigKeys.S3_STREAM_BUFFER_SIZE_DEFAULT ); }
public void initialize(URI uri, Configuration conf) throws IOException { S3Credentials s3Credentials = new S3Credentials(); s3Credentials.initialize(uri, conf); try { AWSCredentials awsCredentials = new AWSCredentials(s3Credentials.getAccessKey(), s3Credentials.getSecretAccessKey()); this.s3Service = new RestS3Service(awsCredentials); } catch (S3ServiceException e) { if (e.getCause() instanceof IOException) { throw (IOException) e.getCause(); } throw new S3Exception(e); } bucket = new S3Bucket(uri.getHost()); }
public void initialize(URI uri, Configuration conf) throws IOException { this.conf = conf; S3Credentials s3Credentials = new S3Credentials(); s3Credentials.initialize(uri, conf); try { AWSCredentials awsCredentials = new AWSCredentials(s3Credentials.getAccessKey(), s3Credentials.getSecretAccessKey()); this.s3Service = new RestS3Service(awsCredentials); } catch (S3ServiceException e) { if (e.getCause() instanceof IOException) { throw (IOException) e.getCause(); } throw new S3Exception(e); } bucket = new S3Bucket(uri.getHost()); createBucket(bucket.getName()); this.bufferSize = conf.getInt("io.file.buffer.size", 4096); }
public void initialize(URI uri, Configuration conf) throws IOException { S3Credentials s3Credentials = new S3Credentials(); s3Credentials.initialize(uri, conf); try { AWSCredentials awsCredentials = new AWSCredentials(s3Credentials.getAccessKey(), s3Credentials.getSecretAccessKey()); this.s3Service = new RestS3Service(awsCredentials); } catch (S3ServiceException e) { if (e.getCause() instanceof IOException) { throw (IOException) e.getCause(); } throw new S3Exception(e); } bucket = new S3Bucket(uri.getHost()); createBucket(bucket.getName()); }
private void connect() { String accessKey = getParamString("s3-access-key"); String secretKey = getParamString("s3-secret-key"); String bucket = getParamString("s3-bucket"); AWSCredentials awsCredentials = new AWSCredentials(accessKey, secretKey); S3Service s3service = new RestS3Service(awsCredentials); Jets3tProperties props = s3service.getJetS3tProperties(); String port = getParamString("s3-endpoint-http-port"); String httpsOnly = getParamString("s3-https-only"); String endpoint = getParamString("s3-endpoint"); if(port != null) props.setProperty("s3service.s3-endpoint-http-port", port); if(httpsOnly != null) props.setProperty("s3service.https-only", httpsOnly); if(endpoint != null) props.setProperty("s3service.s3-endpoint", endpoint); //props.setProperty("s3service.s3-endpoint-http-port", "10453"); //props.setProperty("s3service.https-only", "false"); //props.setProperty("s3service.s3-endpoint", "localhost"); props.setProperty("s3service.disable-dns-buckets", "true"); CredentialsProvider credentials = s3service.getCredentialsProvider(); s3service = new RestS3Service(awsCredentials, "Doradus", credentials, props); Object str_threads = getParamString("s3-threads"); int threads = str_threads == null ? 1 : Integer.parseInt(str_threads.toString()); s3_executor = Executors.newFixedThreadPool(threads); m_connection = new AmazonConnection(s3service, bucket); }