当前位置: 首页>>代码示例>>Java>>正文


Java Region类代码示例

本文整理汇总了Java中com.amazonaws.services.s3.model.Region的典型用法代码示例。如果您正苦于以下问题:Java Region类的具体用法?Java Region怎么用?Java Region使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Region类属于com.amazonaws.services.s3.model包,在下文中一共展示了Region类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: regionForUri

import com.amazonaws.services.s3.model.Region; //导入依赖的package包/类
private String regionForUri(AmazonS3 client, AmazonS3URI uri) {
  String bucketRegion = client.getBucketLocation(uri.getBucket());
  Region region = Region.fromValue(bucketRegion);

  // S3 doesn't have a US East 1 region, US East 1 is really the region
  // US Standard. US Standard places the data in either an east coast
  // or west coast data center geographically closest to you.
  // SigV4 requires you to mention a region while signing a request
  // and for the S3's US standard endpoints the value to be used is "us-east-1"
  // US West 1 has an endpoint and so is treated as a stand alone region,
  // US East 1 doesn't and so is bundled into US Standard
  if (region.equals(Region.US_Standard)) {
    bucketRegion = "us-east-1";
  } else {
    bucketRegion = region.toString();
  }
  return bucketRegion;
}
 
开发者ID:HotelsDotCom,项目名称:circus-train,代码行数:19,代码来源:JceksAmazonS3ClientFactory.java

示例2: getCreateBucketEndpoint

import com.amazonaws.services.s3.model.Region; //导入依赖的package包/类
private URI getCreateBucketEndpoint(String requestRegion) {
    // Route to the default endpoint if they're not trying to specify a different one in the request.
    if(requestRegion == null || requestRegion.equals(clientRegion) || !clientOptions.isForceGlobalBucketAccessEnabled()) {
        return endpoint;
    }

    // If they enabled global bucket access and they're trying to create a bucket in a region different than the default
    // one specified when they created the client, it will probably fail because only us-east-1 (actually the global
    // endpoint) is capable of creating buckets outside of its region. Override the endpoint to which the request
    // is routed so that it will succeed.

    com.amazonaws.regions.Region targetRegion = com.amazonaws.regions.Region.getRegion(Regions.fromName(requestRegion));
    return new DefaultServiceEndpointBuilder(getEndpointPrefix(),
                                             clientConfiguration.getProtocol().toString()).withRegion(targetRegion)
                                                                                          .getServiceEndpoint();
}
 
开发者ID:IBM,项目名称:ibm-cos-sdk-java,代码行数:17,代码来源:AmazonS3Client.java

示例3: resolveServiceEndpoint

import com.amazonaws.services.s3.model.Region; //导入依赖的package包/类
/**
 * Specifically made package access for testing.
 * Used for internal consumption of AWS SDK.
 *
 * Tries to determine the service endpoint for the bucket name.
 * Returns the endpoint configured in the client if the region cannot be determined.
 */
URI resolveServiceEndpoint(String bucketName) {

    if (getSignerRegion() != null || isSignerOverridden()) return endpoint;

    final String regionStr = fetchRegionFromCache(bucketName);
    final com.amazonaws.regions.Region region = RegionUtils.getRegion(regionStr);

    if (region == null) {
        log.warn("Region information for "
                + regionStr
                + " is not available. Please upgrade to latest version of AWS Java SDK");
    }

    return region != null
            ? RuntimeHttpUtils.toUri(region.getServiceEndpoint(S3_SERVICE_NAME), clientConfiguration)
            : endpoint;
}
 
开发者ID:IBM,项目名称:ibm-cos-sdk-java,代码行数:25,代码来源:AmazonS3Client.java

示例4: test

import com.amazonaws.services.s3.model.Region; //导入依赖的package包/类
@Test
@Override
public void test() throws Exception {
	for (int i = 1; i <= 2; i++) {
		Message<?> received = this.messageCollector.forChannel(this.channels.output())
				.poll(10, TimeUnit.SECONDS);
		assertNotNull(received);
		assertThat(received, hasPayload(new File(this.config.getLocalDir(), i + ".test")));
	}

	assertEquals(2, this.config.getLocalDir().list().length);

	AWSCredentialsProvider awsCredentialsProvider =
			TestUtils.getPropertyValue(this.amazonS3, "awsCredentialsProvider", AWSCredentialsProvider.class);

	AWSCredentials credentials = awsCredentialsProvider.getCredentials();
	assertEquals(AWS_ACCESS_KEY, credentials.getAWSAccessKeyId());
	assertEquals(AWS_SECRET_KEY, credentials.getAWSSecretKey());

	assertEquals(Region.US_GovCloud, this.amazonS3.getRegion());
	assertEquals(new URI("https://s3-us-gov-west-1.amazonaws.com"),
			TestUtils.getPropertyValue(this.amazonS3, "endpoint"));
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-stream-app-starters,代码行数:24,代码来源:AmazonS3SourceMockTests.java

示例5: createBucket

import com.amazonaws.services.s3.model.Region; //导入依赖的package包/类
/**
 * Create an amazon bucket in the specified region
 * @param bucket - The s3 bucket name
 * @param region - The S3 region the bucket should be created in
 * @param accessList - The access control list settings for the bucket
 */
public void createBucket(final String bucket, 
			final Region region, 
			final CannedAccessControlList cannedACL, 
			final AccessControlList accessList){

	
	final CreateBucketRequest request = new CreateBucketRequest(bucket, region);
	if(cannedACL!=null){
		request.withCannedAcl(cannedACL);
	}
	if(accessList!=null){
		request.withAccessControlList(accessList);	
	}
	this.client.createBucket(request);
}
 
开发者ID:shagwood,项目名称:micro-genie,代码行数:22,代码来源:S3Admin.java

示例6: createBucketForInstance

import com.amazonaws.services.s3.model.Region; //导入依赖的package包/类
public Bucket createBucketForInstance(String instanceId, ServiceDefinition service, String planId,
        String organizationGuid, String spaceGuid) {
    String bucketName = getBucketNameForInstance(instanceId);
    logger.info("Creating bucket '{}' for serviceInstanceId '{}'", bucketName, instanceId);
    Bucket bucket = s3.createBucket(bucketName, Region.fromValue(region));

    // TODO allow for additional, custom tagging options
    BucketTaggingConfiguration bucketTaggingConfiguration = new BucketTaggingConfiguration();
    TagSet tagSet = new TagSet();
    tagSet.setTag("serviceInstanceId", instanceId);
    tagSet.setTag("serviceDefinitionId", service.getId());
    tagSet.setTag("planId", planId);
    tagSet.setTag("organizationGuid", organizationGuid);
    tagSet.setTag("spaceGuid", spaceGuid);
    bucketTaggingConfiguration.withTagSets(tagSet);
    s3.setBucketTaggingConfiguration(bucket.getName(), bucketTaggingConfiguration);

    return bucket;
}
 
开发者ID:cloudfoundry-community,项目名称:s3-cf-service-broker,代码行数:20,代码来源:S3.java

示例7: newGlobalInstance

import com.amazonaws.services.s3.model.Region; //导入依赖的package包/类
private AmazonS3 newGlobalInstance(S3S3CopierOptions s3s3CopierOptions) {
  HadoopAWSCredentialProviderChain credentialsChain = getCredentialsProviderChain();
  AmazonS3ClientBuilder builder = AmazonS3ClientBuilder
      .standard()
      .withForceGlobalBucketAccessEnabled(Boolean.TRUE)
      .withCredentials(credentialsChain);
  URI s3Endpoint = s3s3CopierOptions.getS3Endpoint();
  if (s3Endpoint != null) {
    EndpointConfiguration endpointConfiguration = new EndpointConfiguration(s3Endpoint.toString(),
        Region.US_Standard.getFirstRegionId());
    builder.withEndpointConfiguration(endpointConfiguration);
  }
  return builder.build();
}
 
开发者ID:HotelsDotCom,项目名称:circus-train,代码行数:15,代码来源:JceksAmazonS3ClientFactory.java

示例8: validate

import com.amazonaws.services.s3.model.Region; //导入依赖的package包/类
@Override
public void validate(String name, String value) throws ParameterException {
  try {
    Region.fromValue(value);
  } catch (IllegalArgumentException e) {
    throw new ParameterException("Parameter " + name + " is not a valid AWS region (found " + value + ")", e);
  }
}
 
开发者ID:HotelsDotCom,项目名称:circus-train,代码行数:9,代码来源:RegionValidator.java

示例9: typical

import com.amazonaws.services.s3.model.Region; //导入依赖的package包/类
@Test
public void typical() {
  Configuration conf = new Configuration();
  conf.set(ConfigurationVariable.REGION.getName(), "eu-west-1");
  conf.setInt(ConfigurationVariable.UPLOAD_RETRY_COUNT.getName(), 7);
  conf.setLong(ConfigurationVariable.UPLOAD_RETRY_DELAY_MS.getName(), 333L);
  AmazonS3 client = factory.newInstance(conf);
  assertThat(client, is(instanceOf(AmazonS3Client.class)));
  assertThat(client.getRegion(), is(Region.EU_Ireland));
}
 
开发者ID:HotelsDotCom,项目名称:circus-train,代码行数:11,代码来源:AwsS3ClientFactoryTest.java

示例10: setup

import com.amazonaws.services.s3.model.Region; //导入依赖的package包/类
@Before
public void setup() {
  EndpointConfiguration endpoint =
      new EndpointConfiguration(UNIT_STACK_URL + ":" + SNS_PORT, Region.EU_Frankfurt.name());
  AWSCredentials credentials = new BasicAWSCredentials("key", "secret");
  AWSCredentialsProvider credentialsProvider = new AWSStaticCredentialsProvider(credentials);

  sns = AmazonSNSAsyncClientBuilder.standard().withEndpointConfiguration(endpoint)
      .withCredentials(credentialsProvider).build();
}
 
开发者ID:daflockinger,项目名称:unitstack,代码行数:11,代码来源:MockSnsTest.java

示例11: setRegion

import com.amazonaws.services.s3.model.Region; //导入依赖的package包/类
/**
 * @deprecated use {@link AmazonS3ClientBuilder#setRegion(String)}
 */
@Override
@Deprecated
public synchronized void setRegion(com.amazonaws.regions.Region region) {
    super.setRegion(region);
    /*
     * We need to preserve the user provided region. This is because the
     * region might be mapped to a global s3 endpoint (e.g. when the client
     * is in accelerate mode), in which case we won't be able to extract the
     * region back from the endpoint during request signing phase.
     */
    clientRegion = region.getName();
}
 
开发者ID:IBM,项目名称:ibm-cos-sdk-java,代码行数:16,代码来源:AmazonS3Client.java

示例12: getRegion

import com.amazonaws.services.s3.model.Region; //导入依赖的package包/类
@Override
public synchronized Region getRegion() {
    String authority = super.endpoint.getAuthority();
    if (Constants.S3_HOSTNAME.equals(authority)) {
        return Region.US_Standard;
    } else {
        Matcher m = Region.S3_REGIONAL_ENDPOINT_PATTERN.matcher(authority);
        if (m.matches()) {
            return Region.fromValue(m.group(1));
        } else {
            throw new IllegalStateException(
                "S3 client with invalid S3 endpoint configured: " + authority);
        }
    }
}
 
开发者ID:IBM,项目名称:ibm-cos-sdk-java,代码行数:16,代码来源:AmazonS3Client.java

示例13: getRegionName

import com.amazonaws.services.s3.model.Region; //导入依赖的package包/类
@Override
public String getRegionName() {
    String authority = super.endpoint.getAuthority();
    if(Constants.S3_HOSTNAME.equals(authority)) {
        return "us-east-1";
    }
    Matcher m = Region.S3_REGIONAL_ENDPOINT_PATTERN.matcher(authority);
    try {
        m.matches();
        return RegionUtils.getRegion(m.group(1)).getName();
    } catch (Exception e) {
        throw new IllegalStateException("No valid region has been specified. Unable to return region name", e);
    }
}
 
开发者ID:IBM,项目名称:ibm-cos-sdk-java,代码行数:15,代码来源:AmazonS3Client.java

示例14: addBucketFSEntry

import com.amazonaws.services.s3.model.Region; //导入依赖的package包/类
/**
 * To reuse code for accountbased and external buckets
 * @param s3
 * @param parentConf
 * @param bucketName
 * @throws IOException
 */
private FileSystem addBucketFSEntry(AmazonS3 s3, Configuration parentConf, String bucketName) throws AmazonS3Exception, IOException {
  final String bucketRegion = s3.getBucketLocation(bucketName);
  final String projectedBucketEndPoint = "s3." + bucketRegion + ".amazonaws.com";
  String regionEndPoint = projectedBucketEndPoint;
  try {
    Region region = Region.fromValue(bucketRegion);
    com.amazonaws.regions.Region awsRegion = region.toAWSRegion();
    if (awsRegion != null) {
      regionEndPoint = awsRegion.getServiceEndpoint("s3");
    }
  } catch (IllegalArgumentException iae) {
    // try heuristic mapping if not found
    regionEndPoint = projectedBucketEndPoint;
    logger.warn("Unknown or unmapped region {} for bucket {}. Will use following fs.s3a.endpoint: {}",
      bucketRegion, bucketName, regionEndPoint);
  }
  // it could be null because no mapping from Region to aws region or there is no such region is the map of endpoints
  // not sure if latter is possible
  if (regionEndPoint == null) {
    logger.error("Could not get AWSRegion for bucket {}. Will use following fs.s3a.endpoint: " + "{} ",
      bucketName, projectedBucketEndPoint);
  }
  String location = S3_URI_SCHEMA + bucketName + "/";
  Configuration bucketConf = new Configuration(parentConf);
  bucketConf.set(ENDPOINT, (regionEndPoint != null) ? regionEndPoint : projectedBucketEndPoint);
  FileSystem.setDefaultUri(bucketConf, new Path(location).toUri());
  return FileSystem.get(bucketConf);
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:36,代码来源:S3FileSystem.java

示例15: getTeamAvatarAWSS3BucketRegion

import com.amazonaws.services.s3.model.Region; //导入依赖的package包/类
public Region getTeamAvatarAWSS3BucketRegion() {
    if (!isTeamAvatarUsingAWSS3()) {
        throw new UnsupportedOperationException("Team avatar is not using AWS S3");
    }
    if (teamAvatarAWSS3BucketRegion != null) {
        return teamAvatarAWSS3BucketRegion;
    }
    if (globalAWSS3Region != null) {
        return globalAWSS3Region;
    }

    throw new RuntimeException("Missing aws.global.s3.bucket.regionId or aws.teamAvatar.s3.bucket.regionId in");
}
 
开发者ID:judgels,项目名称:uriel,代码行数:14,代码来源:UrielProperties.java


注:本文中的com.amazonaws.services.s3.model.Region类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。