回答

0

jclouds沒有爲此提供直接機制。相反,你可以打電話BlobStore.list,比較容器名稱,然後消耗StorageMetadata.getLocation

for (StorageMetadata resourceMd : blobStore.list()) { 
    if (containerName.equals(resourceMd.getName())) { 
     System.out.println(resourceMd.getLocation().getId()); 
    } 
} 
2

您可以遍歷Rackspace區域以獲取Cloud Files端點,然後您可以查詢每個端點以查看容器是否存在。像下面這樣:

package org.jclouds.examples.rackspace.cloudfiles; 

import static org.jclouds.examples.rackspace.cloudfiles.Constants.PROVIDER; 

import java.io.IOException; import java.util.Set; 

import org.jclouds.ContextBuilder; 
import org.jclouds.openstack.swift.v1.blobstore.RegionScopedBlobStoreContext; 
import org.jclouds.blobstore.BlobStore; 

public class GetRegion{ 
    private final RegionScopedBlobStoreContext ctx; 
    private final String YOUR_CONTAINER = "YOUR_CONTAINER_HERE"; 
    public static void main(String[] args) throws IOException { 
    GetRegion getRegion = new GetRegion(args[0], args[1]); 
    try { 
     getRegion.getRegion(); 
    } 
    catch (Exception e) { 
     e.printStackTrace(); 
    } 
    } 

    public GetRegion(String username, String apiKey) { 
    ctx = ContextBuilder.newBuilder(PROVIDER) 
      .credentials(username, apiKey) 
      .buildView(RegionScopedBlobStoreContext.class); 
    } 

    private void getRegion() { 
    Set<String> regions = ctx.configuredRegions(); 
    for(String region:regions){ 
     BlobStore store = ctx.blobStoreInRegion(region); 
     if(store.containerExists(YOUR_CONTAINER)) { 
     System.out.format("Container is in %s region\n", region); 
     } 
    } 
    } 
} 

要運行,將「YOUR_CONTAINER_HERE」與容器的名稱,並通過您的Rackspace公司的用戶名和API密鑰作爲命令行參數(或者硬編碼他們在「ARGS [ 0]'和'args [1]')。

+0

這種方法需要一個電話,每區BlobStore.containerExists。 –

相關問題