use of com.aliyun.oss.ClientBuilderConfiguration in project alluxio by Alluxio.
the class OSSUnderFileSystem method initializeOSSClientConfig.
/**
* Creates an OSS {@code ClientConfiguration} using an Alluxio Configuration.
*
* @return the OSS {@link ClientBuilderConfiguration}
*/
private static ClientBuilderConfiguration initializeOSSClientConfig(AlluxioConfiguration alluxioConf) {
ClientBuilderConfiguration ossClientConf = new ClientBuilderConfiguration();
ossClientConf.setConnectionTimeout((int) alluxioConf.getMs(PropertyKey.UNDERFS_OSS_CONNECT_TIMEOUT));
ossClientConf.setSocketTimeout((int) alluxioConf.getMs(PropertyKey.UNDERFS_OSS_SOCKET_TIMEOUT));
ossClientConf.setConnectionTTL(alluxioConf.getLong(PropertyKey.UNDERFS_OSS_CONNECT_TTL));
ossClientConf.setMaxConnections(alluxioConf.getInt(PropertyKey.UNDERFS_OSS_CONNECT_MAX));
return ossClientConf;
}
use of com.aliyun.oss.ClientBuilderConfiguration in project alluxio by Alluxio.
the class OSSUnderFileSystem method createInstance.
/**
* Constructs a new instance of {@link OSSUnderFileSystem}.
*
* @param uri the {@link AlluxioURI} for this UFS
* @param conf the configuration for this UFS
* @return the created {@link OSSUnderFileSystem} instance
*/
public static OSSUnderFileSystem createInstance(AlluxioURI uri, UnderFileSystemConfiguration conf) throws Exception {
String bucketName = UnderFileSystemUtils.getBucketName(uri);
Preconditions.checkArgument(conf.isSet(PropertyKey.OSS_ACCESS_KEY), "Property %s is required to connect to OSS", PropertyKey.OSS_ACCESS_KEY);
Preconditions.checkArgument(conf.isSet(PropertyKey.OSS_SECRET_KEY), "Property %s is required to connect to OSS", PropertyKey.OSS_SECRET_KEY);
Preconditions.checkArgument(conf.isSet(PropertyKey.OSS_ENDPOINT_KEY), "Property %s is required to connect to OSS", PropertyKey.OSS_ENDPOINT_KEY);
String accessId = conf.getString(PropertyKey.OSS_ACCESS_KEY);
String accessKey = conf.getString(PropertyKey.OSS_SECRET_KEY);
String endPoint = conf.getString(PropertyKey.OSS_ENDPOINT_KEY);
ClientBuilderConfiguration ossClientConf = initializeOSSClientConfig(conf);
OSS ossClient = new OSSClientBuilder().build(endPoint, accessId, accessKey, ossClientConf);
return new OSSUnderFileSystem(uri, ossClient, bucketName, conf);
}
use of com.aliyun.oss.ClientBuilderConfiguration in project aliyun-oss-java-sdk by aliyun.
the class ProxyTest method testProxy.
@Ignore
public void testProxy() {
String key = "test/test.txt";
String content = "Hello OSS.";
try {
ClientBuilderConfiguration conf = new ClientBuilderConfiguration();
conf.setProxyHost(TestConfig.PROXY_HOST);
conf.setProxyPort(TestConfig.PROXY_PORT);
conf.setProxyUsername(TestConfig.PROXY_USER);
conf.setProxyPassword(TestConfig.PROXY_PASSWORD);
OSS ossClient = new OSSClientBuilder().build(TestConfig.OSS_TEST_ENDPOINT, TestConfig.OSS_TEST_ACCESS_KEY_ID, TestConfig.OSS_TEST_ACCESS_KEY_SECRET, conf);
BucketInfo info = ossClient.getBucketInfo(bucketName);
Assert.assertEquals(info.getBucket().getName(), bucketName);
ObjectMetadata metadata = new ObjectMetadata();
metadata.setContentLength(content.getBytes().length);
ossClient.putObject(bucketName, key, new ByteArrayInputStream(content.getBytes()), metadata);
OSSObject ossObject = ossClient.getObject(bucketName, key);
InputStream inputStream = ossObject.getObjectContent();
inputStream.close();
ossClient.deleteObject(bucketName, key);
} catch (Exception e) {
Assert.fail(e.getMessage());
}
}
use of com.aliyun.oss.ClientBuilderConfiguration in project aliyun-oss-java-sdk by aliyun.
the class RequestTimeoutTest method testClientConfigIndependent.
/**
* Testing connection timeout.
*/
@Test
public void testClientConfigIndependent() throws Exception {
String key = "test-client-config-independent";
ClientBuilderConfiguration config = new ClientBuilderConfiguration();
config.setRequestTimeout(requestTimeout);
config.setRequestTimeoutEnabled(true);
config.setConnectionTimeout(1);
OSS client = new OSSClientBuilder().build(endpoint, accessId, accessKey, config);
try {
client.putObject(bucketName, key, TestUtils.genFixedLengthInputStream(1024));
Assert.fail("Put object should not be successful");
} catch (ClientException e) {
Assert.assertEquals(ClientErrorCode.CONNECTION_TIMEOUT, e.getErrorCode());
} finally {
client.shutdown();
}
}
use of com.aliyun.oss.ClientBuilderConfiguration in project aliyun-oss-java-sdk by aliyun.
the class ProxySignTest method testProxyAuth.
@Ignore
public void testProxyAuth() {
String bucketName = "sdk-test-md-1";
String key = "mingdi/test.txt";
String content = "Hello OSS.";
String proxyHost = "";
String endpoint = "";
String accessKeyId = "";
String secretAccessKey = "";
try {
ClientBuilderConfiguration conf = new ClientBuilderConfiguration();
conf.setProxyHost(proxyHost);
conf.setProxyPort(8080);
Credentials credentials = new ProxyCredentials("mingditest");
ProxyRequestSigner proxySigner = new ProxyRequestSigner(credentials);
List<RequestSigner> signerHandlers = new LinkedList<RequestSigner>();
signerHandlers.add(proxySigner);
conf.setSignerHandlers(signerHandlers);
Map<String, String> proxyHeaders = new LinkedHashMap<String, String>();
proxyHeaders.put(HEADER_PROXY_TYPE, "default");
proxyHeaders.put(HEADER_PROXY_USER, "diff_bucket_sync_test_user_1");
proxyHeaders.put(HEADER_PROXY_DEST, "cn-qingdao");
proxyHeaders.put(HEADER_PROXY_DEST_REGION, "cn-qingdao");
proxyHeaders.put(HEADER_PROXY_REAL_HOST, endpoint);
conf.setDefaultHeaders(proxyHeaders);
OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, secretAccessKey, conf);
ossClient.putObject(bucketName, key, new ByteArrayInputStream(content.getBytes()));
ossClient.getObject(bucketName, key);
ossClient.deleteObject(bucketName, key);
} catch (Throwable e) {
e.printStackTrace();
Assert.fail(e.getMessage());
}
}
Aggregations