Java源码示例:org.jclouds.osgi.ProviderRegistry

示例1
private static Pair<BlobStoreLocation, BlobStore> createBlobStore(String driver,
                                                                  String region,
                                                                  String endpoint,
                                                                  Supplier<Credentials> credentials,
                                                                  int maxBlockSize) {
    Properties overrides = new Properties();
    // This property controls the number of parts being uploaded in parallel.
    overrides.setProperty("jclouds.mpu.parallel.degree", "1");
    overrides.setProperty("jclouds.mpu.parts.size", Integer.toString(maxBlockSize));
    overrides.setProperty(Constants.PROPERTY_SO_TIMEOUT, "25000");
    overrides.setProperty(Constants.PROPERTY_MAX_RETRIES, Integer.toString(100));

    ApiRegistry.registerApi(new S3ApiMetadata());
    ProviderRegistry.registerProvider(new AWSS3ProviderMetadata());
    ProviderRegistry.registerProvider(new GoogleCloudStorageProviderMetadata());

    ContextBuilder contextBuilder = ContextBuilder.newBuilder(driver);
    contextBuilder.credentialsSupplier(credentials);

    if (isS3Driver(driver) && !Strings.isNullOrEmpty(endpoint)) {
        contextBuilder.endpoint(endpoint);
        overrides.setProperty(S3Constants.PROPERTY_S3_VIRTUAL_HOST_BUCKETS, "false");
    }
    contextBuilder.overrides(overrides);
    BlobStoreContext context = contextBuilder.buildView(BlobStoreContext.class);
    BlobStore blobStore = context.getBlobStore();

    log.info("Connect to blobstore : driver: {}, region: {}, endpoint: {}",
        driver, region, endpoint);
    return Pair.of(
        BlobStoreLocation.of(region, endpoint),
        blobStore);
}
 
示例2
@Test
public void testRegisteredProvider() throws Exception {
    String id = "my-example-provider";
    assertFalse(JcloudsProviderAndApiLoader.isProvider(id));
    
    ProviderMetadata provider = new BaseProviderMetadata.Builder()
            .id(id)
            .name("My Example Provider")
            .apiMetadata(new AWSEC2ApiMetadata())
            .build();
    ProviderRegistry.registerProvider(provider);
    try {
        assertIsProvider(id);
        
        ProviderRegistry.unregisterProvider(provider);
        assertFalse(JcloudsProviderAndApiLoader.isProvider(id));
        
    } finally {
        ProviderRegistry.unregisterProvider(provider);
    }
}
 
示例3
/**
 * Initializes the BlobStore context.
 */
public void init() {
    Iterable<Module> modules = ImmutableSet.<Module>of(new SLF4JLoggingModule());

    // The metadata must be registered because the ServiceLoader does not detect
    // the META-INF/services in each api JAR under Tomcat/Spring. Fortunately,
    // the registry is static and is not really OSGi specific for this use.
    ApiRegistry.registerApi(new SwiftApiMetadata());
    ProviderRegistry.registerProvider(new AWSS3ProviderMetadata());

    context = ContextBuilder.newBuilder(provider)
            .credentials(identity, credential)
            .modules(modules)
            .buildView(BlobStoreContext.class);

    // There are some oddities with streaming larger files to the user,
    // so download to a temp file first. For now, call 100MB the threshold.
    maxBlobStreamSize = (long) serverConfigurationService.getInt("cloud.content.maxblobstream.size", 1024 * 1024 * 100);
    temporaryBlobDirectory = serverConfigurationService.getString("cloud.content.temporary.directory", null);
    
    if (temporaryBlobDirectory != null) {
        File baseDir = new File(temporaryBlobDirectory);
        if (!baseDir.exists()) {
            try {
                // Can't write into the preferred temp dir
                if (!baseDir.mkdirs()) {
                    temporaryBlobDirectory = null;
                }
            }
            catch (SecurityException se) {
                // JVM security hasn't whitelisted this dir
                temporaryBlobDirectory = null;
            }
        }
    }
}
 
示例4
public static Optional<ProviderMetadata> getProvider(String id) {
    id = DeserializingJcloudsRenamesProvider.INSTANCE.applyJcloudsRenames(id);
    if (LazyServiceLoader.INSTANCE.providers.containsKey(id)) {
        return Optional.of(LazyServiceLoader.INSTANCE.providers.get(id));
    }
    return Iterables.tryFind(ProviderRegistry.fromRegistry(), ProviderPredicates.id(id));
}
 
示例5
@Test
public void testRenamedRegisteredProvider() throws Exception {
    String newId = "my-example-provider2";
    String oldId = "my-example-provider-renamed";
    assertFalse(JcloudsProviderAndApiLoader.isProvider(newId));

    ProviderMetadata provider = new BaseProviderMetadata.Builder()
            .id(newId)
            .name("My Example Provider 2")
            .apiMetadata(new AWSEC2ApiMetadata())
            .build();
    ProviderRegistry.registerProvider(provider);
    try {
        assertIsProvider(newId);
        assertFalse(JcloudsProviderAndApiLoader.isProvider(oldId));

        DeserializingJcloudsRenamesProvider.INSTANCE.loadDeserializingMapping().put(oldId,newId);

        assertIsProvider(oldId, newId);

        ProviderRegistry.unregisterProvider(provider);
        assertFalse(JcloudsProviderAndApiLoader.isProvider(newId));
        assertFalse(JcloudsProviderAndApiLoader.isProvider(oldId));

    } finally {
        ProviderRegistry.unregisterProvider(provider);
    }
}
 
示例6
/**
 * Initializes the BlobStore context.
 */
public void init() {
    Iterable<Module> modules = ImmutableSet.<Module>of(new SLF4JLoggingModule());

    // The metadata must be registered because the ServiceLoader does not detect
    // the META-INF/services in each api JAR under Tomcat/Spring. Fortunately,
    // the registry is static and is not really OSGi specific for this use.
    ApiRegistry.registerApi(new SwiftApiMetadata());
    ProviderRegistry.registerProvider(new AWSS3ProviderMetadata());

    context = ContextBuilder.newBuilder(provider)
            .credentials(identity, credential)
            .modules(modules)
            .buildView(BlobStoreContext.class);

    // There are some oddities with streaming larger files to the user,
    // so download to a temp file first. For now, call 100MB the threshold.
    maxBlobStreamSize = (long) serverConfigurationService.getInt("cloud.content.maxblobstream.size", 1024 * 1024 * 100);
    temporaryBlobDirectory = serverConfigurationService.getString("cloud.content.temporary.directory", null);
    
    if (temporaryBlobDirectory != null) {
        File baseDir = new File(temporaryBlobDirectory);
        if (!baseDir.exists()) {
            try {
                // Can't write into the preferred temp dir
                if (!baseDir.mkdirs()) {
                    temporaryBlobDirectory = null;
                }
            }
            catch (SecurityException se) {
                // JVM security hasn't whitelisted this dir
                temporaryBlobDirectory = null;
            }
        }
    }
}