List of usage examples for com.amazonaws ClientConfiguration setProtocol
public void setProtocol(Protocol protocol)
From source file:com.ge.predix.sample.blobstore.connector.spring.BlobstoreServiceConnectorCreator.java
License:Apache License
/** * Creates the BlobStore context using S3Client * * @param serviceInfo Object Store Service Info Object * @param serviceConnectorConfig Cloud Foundry Service Connector Configuration * * @return BlobstoreService Instance of the ObjectStore Service */// w w w . jav a 2 s.c o m @Override public BlobstoreService create(BlobstoreServiceInfo serviceInfo, ServiceConnectorConfig serviceConnectorConfig) { log.info("create() invoked with serviceInfo? = " + (serviceInfo == null)); ClientConfiguration config = new ClientConfiguration(); config.setProtocol(Protocol.HTTPS); S3ClientOptions options = new S3ClientOptions(); config.setSignerOverride("S3SignerType"); BasicAWSCredentials creds = new BasicAWSCredentials(serviceInfo.getObjectStoreAccessKey(), serviceInfo.getObjectStoreSecretKey()); AmazonS3Client s3Client = new AmazonS3Client(creds, config); s3Client.setEndpoint(serviceInfo.getUrl()); s3Client.setS3ClientOptions(options); try { // Remove the Credentials from the Object Store URL URL url = new URL(serviceInfo.getUrl()); String urlWithoutCredentials = url.getProtocol() + "://" + url.getHost(); // Return BlobstoreService return new BlobstoreService(s3Client, serviceInfo.getBucket(), urlWithoutCredentials); } catch (MalformedURLException e) { log.error("create(): Couldnt parse the URL provided by VCAP_SERVICES. Exception = " + e.getMessage()); throw new RuntimeException("Blobstore URL is Invalid", e); } }
From source file:com.ge.predix.solsvc.blobstore.bootstrap.BlobstoreClientImpl.java
License:Apache License
/** * -/* www. java2 s . com*/ */ @PostConstruct public void init() { ClientConfiguration config = new ClientConfiguration(); config.setProtocol(Protocol.HTTPS); if (this.blobstoreConfig.getProxyHost() != null && !"".equals(this.blobstoreConfig.getProxyHost())) { //$NON-NLS-1$ this.log.info("Connnecting with proxy"); //$NON-NLS-1$ if (this.blobstoreConfig.getProxyHost() != null) { config.withProxyHost(this.blobstoreConfig.getProxyHost()); } if (this.blobstoreConfig.getProxyPort() != null) { config.withProxyPort(Integer.parseInt(this.blobstoreConfig.getProxyPort())); } } BasicAWSCredentials creds = new BasicAWSCredentials(this.blobstoreConfig.getAccessKey(), this.blobstoreConfig.getAccessKey()); this.s3Client = new AmazonS3Client(creds, config); this.s3Client.setEndpoint(this.blobstoreConfig.getUrl()); }
From source file:com.hpe.caf.worker.datastore.s3.S3DataStore.java
License:Apache License
public S3DataStore(final S3DataStoreConfiguration s3DataStoreConfiguration) { if (s3DataStoreConfiguration == null) { throw new ArgumentException("s3DataStoreConfiguration was null."); }//from w w w . j a va 2 s. com ClientConfiguration clientCfg = new ClientConfiguration(); if (!StringUtils.isNullOrEmpty(s3DataStoreConfiguration.getProxyHost())) { clientCfg.setProtocol(Protocol.valueOf(s3DataStoreConfiguration.getProxyProtocol())); clientCfg.setProxyHost(s3DataStoreConfiguration.getProxyHost()); clientCfg.setProxyPort(s3DataStoreConfiguration.getProxyPort()); } AWSCredentials credentials = new BasicAWSCredentials(s3DataStoreConfiguration.getAccessKey(), s3DataStoreConfiguration.getSecretKey()); bucketName = s3DataStoreConfiguration.getBucketName(); amazonS3Client = new AmazonS3Client(credentials, clientCfg); amazonS3Client.setBucketAccelerateConfiguration(new SetBucketAccelerateConfigurationRequest(bucketName, new BucketAccelerateConfiguration(BucketAccelerateStatus.Enabled))); }
From source file:com.ibm.stocator.fs.cos.COSAPIClient.java
License:Apache License
@Override public void initiate(String scheme) throws IOException, ConfigurationParseException { mCachedSparkOriginated = new HashMap<String, Boolean>(); mCachedSparkJobsStatus = new HashMap<String, Boolean>(); schemaProvided = scheme;// w ww .ja va2 s .com Properties props = ConfigurationHandler.initialize(filesystemURI, conf, scheme); // Set bucket name property int cacheSize = conf.getInt(CACHE_SIZE, GUAVA_CACHE_SIZE_DEFAULT); memoryCache = MemoryCache.getInstance(cacheSize); mBucket = props.getProperty(COS_BUCKET_PROPERTY); workingDir = new Path("/user", System.getProperty("user.name")).makeQualified(filesystemURI, getWorkingDirectory()); fModeAutomaticDelete = "true".equals(props.getProperty(FMODE_AUTOMATIC_DELETE_COS_PROPERTY, "false")); mIsV2Signer = "true".equals(props.getProperty(V2_SIGNER_TYPE_COS_PROPERTY, "false")); // Define COS client String accessKey = props.getProperty(ACCESS_KEY_COS_PROPERTY); String secretKey = props.getProperty(SECRET_KEY_COS_PROPERTY); if (accessKey == null) { throw new ConfigurationParseException("Access KEY is empty. Please provide valid access key"); } if (secretKey == null) { throw new ConfigurationParseException("Secret KEY is empty. Please provide valid secret key"); } BasicAWSCredentials creds = new BasicAWSCredentials(accessKey, secretKey); ClientConfiguration clientConf = new ClientConfiguration(); int maxThreads = Utils.getInt(conf, FS_COS, FS_ALT_KEYS, MAX_THREADS, DEFAULT_MAX_THREADS); if (maxThreads < 2) { LOG.warn(MAX_THREADS + " must be at least 2: forcing to 2."); maxThreads = 2; } int totalTasks = Utils.getInt(conf, FS_COS, FS_ALT_KEYS, MAX_TOTAL_TASKS, DEFAULT_MAX_TOTAL_TASKS); long keepAliveTime = Utils.getLong(conf, FS_COS, FS_ALT_KEYS, KEEPALIVE_TIME, DEFAULT_KEEPALIVE_TIME); threadPoolExecutor = BlockingThreadPoolExecutorService.newInstance(maxThreads, maxThreads + totalTasks, keepAliveTime, TimeUnit.SECONDS, "s3a-transfer-shared"); unboundedThreadPool = new ThreadPoolExecutor(maxThreads, Integer.MAX_VALUE, keepAliveTime, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(), BlockingThreadPoolExecutorService.newDaemonThreadFactory("s3a-transfer-unbounded")); boolean secureConnections = Utils.getBoolean(conf, FS_COS, FS_ALT_KEYS, SECURE_CONNECTIONS, DEFAULT_SECURE_CONNECTIONS); clientConf.setProtocol(secureConnections ? Protocol.HTTPS : Protocol.HTTP); String proxyHost = Utils.getTrimmed(conf, FS_COS, FS_ALT_KEYS, PROXY_HOST, ""); int proxyPort = Utils.getInt(conf, FS_COS, FS_ALT_KEYS, PROXY_PORT, -1); if (!proxyHost.isEmpty()) { clientConf.setProxyHost(proxyHost); if (proxyPort >= 0) { clientConf.setProxyPort(proxyPort); } else { if (secureConnections) { LOG.warn("Proxy host set without port. Using HTTPS default 443"); clientConf.setProxyPort(443); } else { LOG.warn("Proxy host set without port. Using HTTP default 80"); clientConf.setProxyPort(80); } } String proxyUsername = Utils.getTrimmed(conf, FS_COS, FS_ALT_KEYS, PROXY_USERNAME); String proxyPassword = Utils.getTrimmed(conf, FS_COS, FS_ALT_KEYS, PROXY_PASSWORD); if ((proxyUsername == null) != (proxyPassword == null)) { String msg = "Proxy error: " + PROXY_USERNAME + " or " + PROXY_PASSWORD + " set without the other."; LOG.error(msg); throw new IllegalArgumentException(msg); } clientConf.setProxyUsername(proxyUsername); clientConf.setProxyPassword(proxyPassword); clientConf.setProxyDomain(Utils.getTrimmed(conf, FS_COS, FS_ALT_KEYS, PROXY_DOMAIN)); clientConf.setProxyWorkstation(Utils.getTrimmed(conf, FS_COS, FS_ALT_KEYS, PROXY_WORKSTATION)); if (LOG.isDebugEnabled()) { LOG.debug( "Using proxy server {}:{} as user {} with password {} on " + "domain {} as workstation {}", clientConf.getProxyHost(), clientConf.getProxyPort(), String.valueOf(clientConf.getProxyUsername()), clientConf.getProxyPassword(), clientConf.getProxyDomain(), clientConf.getProxyWorkstation()); } } else if (proxyPort >= 0) { String msg = "Proxy error: " + PROXY_PORT + " set without " + PROXY_HOST; LOG.error(msg); throw new IllegalArgumentException(msg); } initConnectionSettings(conf, clientConf); if (mIsV2Signer) { clientConf.withSignerOverride("S3SignerType"); } mClient = new AmazonS3Client(creds, clientConf); final String serviceUrl = props.getProperty(ENDPOINT_URL_COS_PROPERTY); if (serviceUrl != null && !serviceUrl.equals(amazonDefaultEndpoint)) { mClient.setEndpoint(serviceUrl); } mClient.setS3ClientOptions(S3ClientOptions.builder().setPathStyleAccess(true).build()); // Set block size property String mBlockSizeString = props.getProperty(BLOCK_SIZE_COS_PROPERTY, "128"); mBlockSize = Long.valueOf(mBlockSizeString).longValue() * 1024 * 1024L; boolean autoCreateBucket = "true" .equalsIgnoreCase((props.getProperty(AUTO_BUCKET_CREATE_COS_PROPERTY, "false"))); partSize = Utils.getLong(conf, FS_COS, FS_ALT_KEYS, MULTIPART_SIZE, DEFAULT_MULTIPART_SIZE); multiPartThreshold = Utils.getLong(conf, FS_COS, FS_ALT_KEYS, MIN_MULTIPART_THRESHOLD, DEFAULT_MIN_MULTIPART_THRESHOLD); readAhead = Utils.getLong(conf, FS_COS, FS_ALT_KEYS, READAHEAD_RANGE, DEFAULT_READAHEAD_RANGE); LOG.debug(READAHEAD_RANGE + ":" + readAhead); inputPolicy = COSInputPolicy .getPolicy(Utils.getTrimmed(conf, FS_COS, FS_ALT_KEYS, INPUT_FADVISE, INPUT_FADV_NORMAL)); initTransferManager(); maxKeys = Utils.getInt(conf, FS_COS, FS_ALT_KEYS, MAX_PAGING_KEYS, DEFAULT_MAX_PAGING_KEYS); flatListingFlag = Utils.getBoolean(conf, FS_COS, FS_ALT_KEYS, FLAT_LISTING, DEFAULT_FLAT_LISTING); if (autoCreateBucket) { try { boolean bucketExist = mClient.doesBucketExist(mBucket); if (bucketExist) { LOG.trace("Bucket {} exists", mBucket); } else { LOG.trace("Bucket {} doesn`t exists and autocreate", mBucket); String mRegion = props.getProperty(REGION_COS_PROPERTY); if (mRegion == null) { mClient.createBucket(mBucket); } else { LOG.trace("Creating bucket {} in region {}", mBucket, mRegion); mClient.createBucket(mBucket, mRegion); } } } catch (AmazonServiceException ase) { /* * we ignore the BucketAlreadyExists exception since multiple processes or threads * might try to create the bucket in parrallel, therefore it is expected that * some will fail to create the bucket */ if (!ase.getErrorCode().equals("BucketAlreadyExists")) { LOG.error(ase.getMessage()); throw (ase); } } catch (Exception e) { LOG.error(e.getMessage()); throw (e); } } initMultipartUploads(conf); enableMultiObjectsDelete = Utils.getBoolean(conf, FS_COS, FS_ALT_KEYS, ENABLE_MULTI_DELETE, true); blockUploadEnabled = Utils.getBoolean(conf, FS_COS, FS_ALT_KEYS, FAST_UPLOAD, DEFAULT_FAST_UPLOAD); if (blockUploadEnabled) { blockOutputBuffer = Utils.getTrimmed(conf, FS_COS, FS_ALT_KEYS, FAST_UPLOAD_BUFFER, DEFAULT_FAST_UPLOAD_BUFFER); partSize = COSUtils.ensureOutputParameterInRange(MULTIPART_SIZE, partSize); blockFactory = COSDataBlocks.createFactory(this, blockOutputBuffer); blockOutputActiveBlocks = Utils.getInt(conf, FS_COS, FS_ALT_KEYS, FAST_UPLOAD_ACTIVE_BLOCKS, DEFAULT_FAST_UPLOAD_ACTIVE_BLOCKS); LOG.debug("Using COSBlockOutputStream with buffer = {}; block={};" + " queue limit={}", blockOutputBuffer, partSize, blockOutputActiveBlocks); } else { LOG.debug("Using COSOutputStream"); } }
From source file:com.netflix.iep.aws.AwsClientFactory.java
License:Apache License
ClientConfiguration createClientConfig(String name) { final Config cfg = getConfig(name, "client"); final ClientConfiguration settings = new ClientConfiguration(); // Should be the default, but just to make it explicit settings.setProtocol(Protocol.HTTPS); // Helpers/*w w w. j av a 2 s .com*/ Function<String, Long> getMillis = k -> cfg.getDuration(k, TimeUnit.MILLISECONDS); Function<String, Integer> getTimeout = k -> getMillis.apply(k).intValue(); // Typically use the defaults setIfPresent(cfg, "use-gzip", cfg::getBoolean, settings::setUseGzip); setIfPresent(cfg, "use-reaper", cfg::getBoolean, settings::setUseReaper); setIfPresent(cfg, "use-tcp-keep-alive", cfg::getBoolean, settings::setUseTcpKeepAlive); setIfPresent(cfg, "use-throttle-retries", cfg::getBoolean, settings::setUseThrottleRetries); setIfPresent(cfg, "max-connections", cfg::getInt, settings::setMaxConnections); setIfPresent(cfg, "max-error-retry", cfg::getInt, settings::setMaxErrorRetry); setIfPresent(cfg, "connection-ttl", getMillis, settings::setConnectionTTL); setIfPresent(cfg, "connection-max-idle", getMillis, settings::setConnectionMaxIdleMillis); setIfPresent(cfg, "connection-timeout", getTimeout, settings::setConnectionTimeout); setIfPresent(cfg, "socket-timeout", getTimeout, settings::setSocketTimeout); setIfPresent(cfg, "client-execution-timeout", getTimeout, settings::setClientExecutionTimeout); setIfPresent(cfg, "user-agent-prefix", cfg::getString, settings::setUserAgentPrefix); setIfPresent(cfg, "user-agent-suffix", cfg::getString, settings::setUserAgentSuffix); setIfPresent(cfg, "proxy-port", cfg::getInt, settings::setProxyPort); setIfPresent(cfg, "proxy-host", cfg::getString, settings::setProxyHost); setIfPresent(cfg, "proxy-domain", cfg::getString, settings::setProxyDomain); setIfPresent(cfg, "proxy-workstation", cfg::getString, settings::setProxyWorkstation); setIfPresent(cfg, "proxy-username", cfg::getString, settings::setProxyUsername); setIfPresent(cfg, "proxy-password", cfg::getString, settings::setProxyPassword); return settings; }
From source file:com.netflix.spinnaker.clouddriver.aws.security.AWSProxy.java
License:Apache License
public void apply(ClientConfiguration clientConfiguration) { clientConfiguration.setProxyHost(proxyHost); clientConfiguration.setProxyPort(Integer.parseInt(proxyPort)); clientConfiguration.setProxyUsername(proxyUsername); clientConfiguration.setProxyPassword(proxyPassword); Protocol awsProtocol = Protocol.HTTP; if ("HTTPS".equalsIgnoreCase(protocol)) { awsProtocol = Protocol.HTTPS;/*from w w w. ja v a 2s. c o m*/ } clientConfiguration.setProtocol(awsProtocol); if (isNTLMProxy()) { clientConfiguration.setProxyDomain(proxyDomain); clientConfiguration.setProxyWorkstation(proxyWorkstation); } }
From source file:com.neu.Spark.MainFrame.java
/** * Creates new form MainFrame/* w w w . ja va2s . c o m*/ */ public MainFrame() { initComponents(); AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey); ClientConfiguration clientConfig = new ClientConfiguration(); clientConfig.setProtocol(Protocol.HTTP); conn = new AmazonS3Client(credentials); conn.setEndpoint("s3.amazonaws.com"); }
From source file:com.noctarius.hazelcast.aws.HazelcastAwsDiscoveryStrategy.java
License:Open Source License
private AmazonEC2Client buildAmazonEC2Client() { ClientConfiguration configuration = new ClientConfiguration(); // Always set HTTPS as protocol, security first configuration.setProtocol(Protocol.HTTPS); // Configure proxy configuration configureProxy(configuration);//from www . jav a 2s. c o m // Configure authentication AWSCredentialsProvider credentialsProvider = buildCredentialsProvider(); // Create WS client AmazonEC2Client client = new AmazonEC2Client(credentialsProvider, configuration); // Configure Amazon EC2 WS endpoint configureEndpoint(client); return client; }
From source file:com.pearson.eidetic.driver.Common.java
public static ClientConfiguration setClientConfigurationSettings(ClientConfiguration clientConfiguration) { clientConfiguration.setConnectionTimeout(10000); clientConfiguration.setMaxConnections(10000); clientConfiguration.setProtocol(Protocol.HTTPS); clientConfiguration.setSocketTimeout(60000); return clientConfiguration; }
From source file:com.pearson.eidetic.driver.threads.MonitorSnapshotVolumeTime.java
public AmazonEC2Client connect(Region region, String awsAccessKey, String awsSecretKey) { AmazonEC2Client ec2Client;//from w w w .j ava 2 s . co m String endpoint = "ec2." + region.getName() + ".amazonaws.com"; AWSCredentials credentials = new BasicAWSCredentials(awsAccessKey, awsSecretKey); ClientConfiguration clientConfig = new ClientConfiguration(); clientConfig.setProtocol(Protocol.HTTPS); ec2Client = new AmazonEC2Client(credentials, clientConfig); ec2Client.setRegion(region); ec2Client.setEndpoint(endpoint); return ec2Client; }