Search in sources :

Example 21 with OSS

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);
}
Also used : OSSObjectSummary(com.aliyun.oss.model.OSSObjectSummary) ObjectListing(com.aliyun.oss.model.ObjectListing) OSS(com.aliyun.oss.OSS) Date(java.util.Date) Test(org.junit.Test)

Example 22 with OSS

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);
}
Also used : OSSObjectSummary(com.aliyun.oss.model.OSSObjectSummary) Pattern(java.util.regex.Pattern) ObjectListing(com.aliyun.oss.model.ObjectListing) URI(java.net.URI) OSS(com.aliyun.oss.OSS) Date(java.util.Date) Test(org.junit.Test)

Example 23 with OSS

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);
}
Also used : OSSObjectSummary(com.aliyun.oss.model.OSSObjectSummary) ObjectListing(com.aliyun.oss.model.ObjectListing) URI(java.net.URI) OSS(com.aliyun.oss.OSS) Date(java.util.Date) Test(org.junit.Test)

Example 24 with OSS

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);
}
Also used : ClientBuilderConfiguration(com.aliyun.oss.ClientBuilderConfiguration) OSS(com.aliyun.oss.OSS) OSSClientBuilder(com.aliyun.oss.OSSClientBuilder)

Example 25 with OSS

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());
    }
}
Also used : ClientBuilderConfiguration(com.aliyun.oss.ClientBuilderConfiguration) OSSObject(com.aliyun.oss.model.OSSObject) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) BucketInfo(com.aliyun.oss.model.BucketInfo) ObjectMetadata(com.aliyun.oss.model.ObjectMetadata) OSS(com.aliyun.oss.OSS) OSSClientBuilder(com.aliyun.oss.OSSClientBuilder) Ignore(org.junit.Ignore)

Aggregations

OSS (com.aliyun.oss.OSS)50 OSSClientBuilder (com.aliyun.oss.OSSClientBuilder)40 Test (org.junit.Test)24 OSSException (com.aliyun.oss.OSSException)19 ByteArrayInputStream (java.io.ByteArrayInputStream)19 ClientException (com.aliyun.oss.ClientException)17 ObjectListing (com.aliyun.oss.model.ObjectListing)10 Date (java.util.Date)10 ClientBuilderConfiguration (com.aliyun.oss.ClientBuilderConfiguration)9 OSSObjectSummary (com.aliyun.oss.model.OSSObjectSummary)9 OSSObject (com.aliyun.oss.model.OSSObject)8 Ignore (org.junit.Ignore)8 File (java.io.File)6 InputStream (java.io.InputStream)6 ArrayList (java.util.ArrayList)6 CredentialsProvider (com.aliyun.oss.common.auth.CredentialsProvider)5 PutObjectRequest (com.aliyun.oss.model.PutObjectRequest)5 Credentials (com.aliyun.oss.common.auth.Credentials)4 URI (java.net.URI)4 GetObjectRequest (com.aliyun.oss.model.GetObjectRequest)3