use of com.aliyun.oss.OSS in project druid by druid-io.
the class OssDataSegmentPullerTest method testSimpleGetVersion.
@Test
public void testSimpleGetVersion() throws IOException {
String bucket = "bucket";
String keyPrefix = "prefix/dir/0";
OSS ossClient = EasyMock.createStrictMock(OSS.class);
final OSSObjectSummary objectSummary = new OSSObjectSummary();
objectSummary.setBucketName(bucket);
objectSummary.setKey(keyPrefix + "/renames-0.gz");
objectSummary.setLastModified(new Date(0));
final ObjectListing result = new ObjectListing();
result.getObjectSummaries().add(objectSummary);
EasyMock.expect(ossClient.listObjects(EasyMock.anyObject(ListObjectsRequest.class))).andReturn(result).once();
OssDataSegmentPuller puller = new OssDataSegmentPuller(ossClient);
EasyMock.replay(ossClient);
String version = puller.getVersion(URI.create(StringUtils.format(OssStorageDruidModule.SCHEME + "://%s/%s", bucket, objectSummary.getKey())));
EasyMock.verify(ossClient);
Assert.assertEquals(StringUtils.format("%d", new Date(0).getTime()), version);
}
use of com.aliyun.oss.OSS in project druid by druid-io.
the class OssTimestampVersionedDataFinderTest method testSimpleLatestVersion.
@Test
public void testSimpleLatestVersion() {
String bucket = "bucket";
String keyPrefix = "prefix/dir/0";
OSS client = EasyMock.createStrictMock(OSS.class);
OSSObjectSummary object0 = new OSSObjectSummary(), object1 = new OSSObjectSummary();
object0.setBucketName(bucket);
object0.setKey(keyPrefix + "/renames-0.gz");
object0.setLastModified(new Date(0));
object0.setSize(10);
object1.setBucketName(bucket);
object1.setKey(keyPrefix + "/renames-1.gz");
object1.setLastModified(new Date(1));
object1.setSize(10);
final ObjectListing result = new ObjectListing();
result.getObjectSummaries().add(object0);
result.getObjectSummaries().add(object1);
result.setTruncated(false);
EasyMock.expect(client.listObjects(EasyMock.anyObject(ListObjectsRequest.class))).andReturn(result).once();
OssTimestampVersionedDataFinder finder = new OssTimestampVersionedDataFinder(client);
Pattern pattern = Pattern.compile("renames-[0-9]*\\.gz");
EasyMock.replay(client);
URI latest = finder.getLatestVersion(URI.create(StringUtils.format("%s://%s/%s", OssStorageDruidModule.SCHEME, bucket, keyPrefix)), pattern);
EasyMock.verify(client);
URI expected = URI.create(StringUtils.format("%s://%s/%s", OssStorageDruidModule.SCHEME, bucket, object1.getKey()));
Assert.assertEquals(expected, latest);
}
use of com.aliyun.oss.OSS in project druid by druid-io.
the class OssTimestampVersionedDataFinderTest method testFindExact.
@Test
public void testFindExact() {
String bucket = "bucket";
String keyPrefix = "prefix/dir/0";
OSS ossClient = EasyMock.createStrictMock(OSS.class);
OSSObjectSummary object0 = new OSSObjectSummary();
object0.setBucketName(bucket);
object0.setKey(keyPrefix + "/renames-0.gz");
object0.setLastModified(new Date(0));
object0.setSize(10);
final ObjectListing result = new ObjectListing();
result.getObjectSummaries().add(object0);
result.setTruncated(false);
EasyMock.expect(ossClient.listObjects(EasyMock.anyObject(ListObjectsRequest.class))).andReturn(result).once();
OssTimestampVersionedDataFinder finder = new OssTimestampVersionedDataFinder(ossClient);
EasyMock.replay(ossClient);
URI latest = finder.getLatestVersion(URI.create(StringUtils.format("%s://%s/%s", OssStorageDruidModule.SCHEME, bucket, object0.getKey())), null);
EasyMock.verify(ossClient);
URI expected = URI.create(StringUtils.format("%s://%s/%s", OssStorageDruidModule.SCHEME, bucket, object0.getKey()));
Assert.assertEquals(expected, latest);
}
use of com.aliyun.oss.OSS 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.OSS 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());
}
}
Aggregations