Java Code Examples for org.jclouds.ContextBuilder#endpoint()

The following examples show how to use org.jclouds.ContextBuilder#endpoint() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BlobStoreManagedLedgerOffloader.java    From pulsar with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example 2
Source File: AreWeConsistentYet.java    From are-we-consistent-yet with Apache License 2.0 6 votes vote down vote up
private static BlobStoreContext blobStoreContextFromProperties(
        Properties properties) {
    String provider = properties.getProperty(Constants.PROPERTY_PROVIDER);
    String identity = properties.getProperty(Constants.PROPERTY_IDENTITY);
    String credential = properties.getProperty(
            Constants.PROPERTY_CREDENTIAL);
    String endpoint = properties.getProperty(Constants.PROPERTY_ENDPOINT);
    if (provider == null || identity == null || credential == null) {
        System.err.println("Properties file must contain:\n" +
                Constants.PROPERTY_PROVIDER + "\n" +
                Constants.PROPERTY_IDENTITY + "\n" +
                Constants.PROPERTY_CREDENTIAL);
        System.exit(1);
    }

    ContextBuilder builder = ContextBuilder
            .newBuilder(provider)
            .credentials(identity, credential)
            .modules(ImmutableList.<Module>of(new SLF4JLoggingModule()))
            .overrides(properties);
    if (endpoint != null) {
        builder = builder.endpoint(endpoint);
    }
    return builder.build(BlobStoreContext.class);
}
 
Example 3
Source File: ObjectStoreFileStorageFactoryBean.java    From multiapps-controller with Apache License 2.0 5 votes vote down vote up
private BlobStoreContext getBlobStoreContext() {
    BlobStoreContext blobStoreContext;
    ObjectStoreServiceInfo serviceInfo = getServiceInfo();
    if (serviceInfo == null) {
        return null;
    }
    ContextBuilder contextBuilder = ContextBuilder.newBuilder(serviceInfo.getProvider())
                                                  .credentials(serviceInfo.getIdentity(), serviceInfo.getCredential());
    if (serviceInfo.getEndpoint() != null) {
        contextBuilder.endpoint(serviceInfo.getEndpoint());
    }
    blobStoreContext = contextBuilder.buildView(BlobStoreContext.class);
    return blobStoreContext;
}
 
Example 4
Source File: BlobStoreContextFactoryImpl.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Override
public BlobStoreContext newBlobStoreContext(Location location) {
    String rawProvider = checkNotNull(location.getConfig(LocationConfigKeys.CLOUD_PROVIDER), "provider must not be null");
    String provider = DeserializingJcloudsRenamesProvider.INSTANCE.applyJcloudsRenames(rawProvider);
    String identity = checkNotNull(location.getConfig(LocationConfigKeys.ACCESS_IDENTITY), "identity must not be null");
    String credential = checkNotNull(location.getConfig(LocationConfigKeys.ACCESS_CREDENTIAL), "credential must not be null");
    String endpoint = location.getConfig(CloudLocationConfig.CLOUD_ENDPOINT);

    Properties overrides = new Properties();
    // * Java 7,8 bug workaround - sockets closed by GC break the internal bookkeeping
    //   of HttpUrlConnection, leading to invalid handling of the "HTTP/1.1 100 Continue"
    //   response. Coupled with a bug when using SSL sockets reads will block
    //   indefinitely even though a read timeout is explicitly set.
    // * Java 6 ignores the header anyways as it is included in its restricted headers black list.
    // * Also there's a bug in SL object store which still expects Content-Length bytes
    //   even when it responds with a 408 timeout response, leading to incorrectly
    //   interpreting the next request (triggered by above problem).
    overrides.setProperty(Constants.PROPERTY_STRIP_EXPECT_HEADER, "true");

    // Add extra jclouds-specific configuration
    Map<String, Object> extra = Maps.filterKeys(((LocationInternal)location).config().getBag().getAllConfig(), Predicates.containsPattern("^jclouds\\."));
    if (extra.size() > 0) {
        LOG.debug("Configuring custom jclouds property overrides for {}: {}", provider, Sanitizer.sanitize(extra));
    }
    overrides.putAll(Maps.filterValues(extra, Predicates.notNull()));

    ContextBuilder contextBuilder = ContextBuilder.newBuilder(provider).credentials(identity, credential);
    contextBuilder.modules(MutableList.copyOf(getCommonModules()));
    if (!org.apache.brooklyn.util.text.Strings.isBlank(endpoint)) {
        contextBuilder.endpoint(endpoint);
    }
    contextBuilder.overrides(overrides);
    BlobStoreContext context = contextBuilder.buildView(BlobStoreContext.class);
    return context;
}
 
Example 5
Source File: AzureCloudTLCInstanceParameters.java    From tlaplus with MIT License 4 votes vote down vote up
@Override
public void mungeBuilder(ContextBuilder builder) {
	builder.endpoint("https://management.core.windows.net/" + getSubscriptionId());
}
 
Example 6
Source File: AzureARMCloudTLCInstanceParameters.java    From tlaplus with MIT License 4 votes vote down vote up
@Override
public void mungeBuilder(ContextBuilder builder) {
	builder.endpoint("https://management.azure.com/subscriptions/" + getSubscriptionId());
}
 
Example 7
Source File: Main.java    From s3proxy with Apache License 2.0 4 votes vote down vote up
private static BlobStore createBlobStore(Properties properties,
        ExecutorService executorService) throws IOException {
    String provider = properties.getProperty(Constants.PROPERTY_PROVIDER);
    String identity = properties.getProperty(Constants.PROPERTY_IDENTITY);
    String credential = properties.getProperty(
            Constants.PROPERTY_CREDENTIAL);
    String endpoint = properties.getProperty(Constants.PROPERTY_ENDPOINT);
    properties.remove(Constants.PROPERTY_ENDPOINT);
    String region = properties.getProperty(
            LocationConstants.PROPERTY_REGION);

    if (provider == null) {
        System.err.println(
                "Properties file must contain: " +
                Constants.PROPERTY_PROVIDER);
        System.exit(1);
    }

    if (provider.equals("filesystem") || provider.equals("transient")) {
        // local blobstores do not require credentials
        identity = Strings.nullToEmpty(identity);
        credential = Strings.nullToEmpty(credential);
    } else if (provider.equals("google-cloud-storage")) {
        File credentialFile = new File(credential);
        if (credentialFile.exists()) {
            credential = Files.asCharSource(credentialFile,
                    StandardCharsets.UTF_8).read();
        }
        properties.remove(Constants.PROPERTY_CREDENTIAL);
    }

    if (identity == null || credential == null) {
        System.err.println(
                "Properties file must contain: " +
                Constants.PROPERTY_IDENTITY + " and " +
                Constants.PROPERTY_CREDENTIAL);
        System.exit(1);
    }

    properties.setProperty(Constants.PROPERTY_USER_AGENT,
            String.format("s3proxy/%s jclouds/%s java/%s",
                    Main.class.getPackage().getImplementationVersion(),
                    JcloudsVersion.get(),
                    System.getProperty("java.version")));

    ContextBuilder builder = ContextBuilder
            .newBuilder(provider)
            .credentials(identity, credential)
            .modules(ImmutableList.<Module>of(
                    new SLF4JLoggingModule(),
                    new ExecutorServiceModule(executorService)))
            .overrides(properties);
    if (!Strings.isNullOrEmpty(endpoint)) {
        builder = builder.endpoint(endpoint);
    }

    BlobStoreContext context = builder.build(BlobStoreContext.class);
    BlobStore blobStore;
    if (context instanceof RegionScopedBlobStoreContext &&
            region != null) {
        blobStore = ((RegionScopedBlobStoreContext) context)
                .getBlobStore(region);
    } else {
        blobStore = context.getBlobStore();
    }
    return blobStore;
}
 
Example 8
Source File: TestUtils.java    From s3proxy with Apache License 2.0 4 votes vote down vote up
static S3ProxyLaunchInfo startS3Proxy(String configFile) throws Exception {
    S3ProxyLaunchInfo info = new S3ProxyLaunchInfo();

    try (InputStream is = Resources.asByteSource(Resources.getResource(
            configFile)).openStream()) {
        info.getProperties().load(is);
    }

    String provider = info.getProperties().getProperty(
            Constants.PROPERTY_PROVIDER);
    String identity = info.getProperties().getProperty(
            Constants.PROPERTY_IDENTITY);
    String credential = info.getProperties().getProperty(
            Constants.PROPERTY_CREDENTIAL);
    if (provider.equals("google-cloud-storage")) {
        File credentialFile = new File(credential);
        if (credentialFile.exists()) {
            credential = Files.asCharSource(credentialFile,
                    StandardCharsets.UTF_8).read();
        }
        info.getProperties().remove(Constants.PROPERTY_CREDENTIAL);
    }
    String endpoint = info.getProperties().getProperty(
            Constants.PROPERTY_ENDPOINT);

    ContextBuilder builder = ContextBuilder
            .newBuilder(provider)
            .credentials(identity, credential)
            .modules(ImmutableList.<Module>of(new SLF4JLoggingModule()))
            .overrides(info.getProperties());
    if (!Strings.isNullOrEmpty(endpoint)) {
        builder.endpoint(endpoint);
    }
    BlobStoreContext context = builder.build(BlobStoreContext.class);
    info.blobStore = context.getBlobStore();

    S3Proxy.Builder s3ProxyBuilder = S3Proxy.Builder.fromProperties(
            info.getProperties());
    s3ProxyBuilder.blobStore(info.blobStore);
    info.endpoint = s3ProxyBuilder.getEndpoint();
    info.secureEndpoint = s3ProxyBuilder.getSecureEndpoint();
    info.s3Identity = s3ProxyBuilder.getIdentity();
    info.s3Credential = s3ProxyBuilder.getCredential();
    info.servicePath = s3ProxyBuilder.getServicePath();
    info.getProperties().setProperty(Constants.PROPERTY_USER_AGENT,
            String.format("s3proxy/%s jclouds/%s java/%s",
                    TestUtils.class.getPackage().getImplementationVersion(),
                    JcloudsVersion.get(),
                    System.getProperty("java.version")));

    // resolve relative path for tests
    String keyStorePath = info.getProperties().getProperty(
            S3ProxyConstants.PROPERTY_KEYSTORE_PATH);
    String keyStorePassword = info.getProperties().getProperty(
            S3ProxyConstants.PROPERTY_KEYSTORE_PASSWORD);
    if (keyStorePath != null || keyStorePassword != null) {
        s3ProxyBuilder.keyStore(
                Resources.getResource(keyStorePath).toString(),
                keyStorePassword);
    }
    info.s3Proxy = s3ProxyBuilder.build();
    info.s3Proxy.start();
    while (!info.s3Proxy.getState().equals(AbstractLifeCycle.STARTED)) {
        Thread.sleep(1);
    }

    // reset endpoint to handle zero port
    info.endpoint = new URI(info.endpoint.getScheme(),
            info.endpoint.getUserInfo(), info.endpoint.getHost(),
            info.s3Proxy.getPort(), info.endpoint.getPath(),
            info.endpoint.getQuery(), info.endpoint.getFragment());
    if (info.secureEndpoint != null) {
        info.secureEndpoint = new URI(info.secureEndpoint.getScheme(),
                info.secureEndpoint.getUserInfo(),
                info.secureEndpoint.getHost(),
                info.s3Proxy.getSecurePort(),
                info.secureEndpoint.getPath(),
                info.secureEndpoint.getQuery(),
                info.secureEndpoint.getFragment());
    }

    return info;
}