我希望利用RackSpace的CloudFiles平台进行大对象存储(word文档,图像等)。遵循他们的一些指南,我发现了一个有用的代码段,看起来像应该起作用,但就我而言不起作用。

    Iterable<Module> modules = ImmutableSet.<Module> of(
            new Log4JLoggingModule());
    Properties properties = new Properties();
    properties.setProperty(LocationConstants.PROPERTY_ZONE, ZONE);
    properties.setProperty(LocationConstants.PROPERTY_REGION, "ORD");
    CloudFilesClient cloudFilesClient = ContextBuilder.newBuilder(PROVIDER)
            .credentials(username, apiKey)
            .overrides(properties)
            .modules(modules)
            .buildApi(CloudFilesClient.class);


问题是执行此代码时,它将尝试将我登录到CloudFiles的IAD(弗吉尼亚)实例中。我组织的目标是将ORD(Chicago)实例作为主要实例与我们的云托管在一起,并使用DFW作为备份环境。登录响应导致IAD实例首先返回,因此我假设JClouds正在使用该实例。浏览时,CloudFiles似乎忽略了ZONE / REGION属性。我想知道是否有任何方法可以覆盖验证返回的代码,以遍历返回的提供程序并选择要登录的提供程序。

更新:

可接受的答案通常很好,此代码段提供了更多信息:

    RestContext<CommonSwiftClient, CommonSwiftAsyncClient> swift = cloudFilesClient.unwrap();
    CommonSwiftClient client = swift.getApi();
    SwiftObject object = client.newSwiftObject();

    object.getInfo().setName(FILENAME + SUFFIX);
    object.setPayload("This is my payload."); //input stream.
    String id = client.putObject(CONTAINER, object);
    System.out.println(id);
    SwiftObject obj2 = client.getObject(CONTAINER,FILENAME + SUFFIX);
    System.out.println(obj2.getPayload());

最佳答案

我们正在开发下一版本的jclouds(1.7.1),该版本应包括对Rackspace Cloud Files和OpenStack Swift的多区域支持。同时,您也许可以使用此代码作为解决方法。

private void uploadToRackspaceRegion() {
  Iterable<Module> modules = ImmutableSet.<Module> of(new Log4JLoggingModule());
  String provider = "swift-keystone"; //Region selection is limited to swift-keystone provider
  String identity = "username";
  String credential = "password";
  String endpoint = "https://identity.api.rackspacecloud.com/v2.0/";
  String region = "ORD";

  Properties overrides = new Properties();
  overrides.setProperty(LocationConstants.PROPERTY_REGION, region);
  overrides.setProperty(Constants.PROPERTY_API_VERSION, "2");

  BlobStoreContext context = ContextBuilder.newBuilder(provider)
        .endpoint(endpoint)
        .credentials(identity, credential)
        .modules(modules)
        .overrides(overrides)
        .buildView(BlobStoreContext.class);
  RestContext<CommonSwiftClient, CommonSwiftAsyncClient> swift = context.unwrap();
  CommonSwiftClient client = swift.getApi();

  SwiftObject uploadObject = client.newSwiftObject();
  uploadObject.getInfo().setName("test.txt");
  uploadObject.setPayload("This is my payload."); //input stream.

  String eTag = client.putObject("jclouds", uploadObject);
  System.out.println("eTag = " + eTag);

  SwiftObject downloadObject = client.getObject("jclouds", "test.txt");
  System.out.println("downloadObject = " + downloadObject.getPayload());

  context.close();
}


像云文件一样使用swift。请记住,如果您需要使用Cloud Files CDN内容,则以上内容将无法解决。另外,请注意,这种处事方式最终会被弃用。

09-25 22:23