Search in sources :

Example 1 with GoogleStorageService

use of org.jets3t.service.impl.rest.httpclient.GoogleStorageService in project alluxio by Alluxio.

the class GCSUnderFileSystem method createInstance.

/**
   * Constructs a new instance of {@link GCSUnderFileSystem}.
   *
   * @param uri the {@link AlluxioURI} for this UFS
   * @return the created {@link GCSUnderFileSystem} instance
   * @throws ServiceException when a connection to GCS could not be created
   */
public static GCSUnderFileSystem createInstance(AlluxioURI uri) throws ServiceException {
    String bucketName = uri.getHost();
    Preconditions.checkArgument(Configuration.containsKey(PropertyKey.GCS_ACCESS_KEY), "Property " + PropertyKey.GCS_ACCESS_KEY + " is required to connect to GCS");
    Preconditions.checkArgument(Configuration.containsKey(PropertyKey.GCS_SECRET_KEY), "Property " + PropertyKey.GCS_SECRET_KEY + " is required to connect to GCS");
    GSCredentials googleCredentials = new GSCredentials(Configuration.get(PropertyKey.GCS_ACCESS_KEY), Configuration.get(PropertyKey.GCS_SECRET_KEY));
    // TODO(chaomin): maybe add proxy support for GCS.
    GoogleStorageService googleStorageService = new GoogleStorageService(googleCredentials);
    String accountOwnerId = googleStorageService.getAccountOwner().getId();
    // Gets the owner from user-defined static mapping from GCS account id to Alluxio user name.
    String owner = CommonUtils.getValueFromStaticMapping(Configuration.get(PropertyKey.UNDERFS_GCS_OWNER_ID_TO_USERNAME_MAPPING), accountOwnerId);
    // If there is no user-defined mapping, use the display name.
    if (owner == null) {
        owner = googleStorageService.getAccountOwner().getDisplayName();
    }
    String accountOwner = owner == null ? accountOwnerId : owner;
    GSAccessControlList acl = googleStorageService.getBucketAcl(bucketName);
    short bucketMode = GCSUtils.translateBucketAcl(acl, accountOwnerId);
    return new GCSUnderFileSystem(uri, googleStorageService, bucketName, bucketMode, accountOwner);
}
Also used : GSCredentials(org.jets3t.service.security.GSCredentials) GoogleStorageService(org.jets3t.service.impl.rest.httpclient.GoogleStorageService) GSAccessControlList(org.jets3t.service.acl.gs.GSAccessControlList)

Aggregations

GSAccessControlList (org.jets3t.service.acl.gs.GSAccessControlList)1 GoogleStorageService (org.jets3t.service.impl.rest.httpclient.GoogleStorageService)1 GSCredentials (org.jets3t.service.security.GSCredentials)1