Java Code Examples for org.jclouds.ContextBuilder#buildView()
The following examples show how to use
org.jclouds.ContextBuilder#buildView() .
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 |
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: JCloudsConnector.java From cloudml with GNU Lesser General Public License v3.0 | 6 votes |
public JCloudsConnector(String provider,String login,String secretKey){ journal.log(Level.INFO, ">> Connecting to "+provider+" ..."); Properties overrides = new Properties(); if(provider.equals("aws-ec2")){ // choose only amazon images that are ebs-backed //overrides.setProperty(AWSEC2Constants.PROPERTY_EC2_AMI_OWNERS,"107378836295"); overrides.setProperty(AWSEC2Constants.PROPERTY_EC2_AMI_QUERY, "owner-id=137112412989,107378836295,099720109477;state=available;image-type=machine;root-device-type=ebs"); } overrides.setProperty(PROPERTY_CONNECTION_TIMEOUT, 0 + ""); overrides.setProperty(PROPERTY_SO_TIMEOUT, 0 + ""); overrides.setProperty(PROPERTY_REQUEST_TIMEOUT, 0 + ""); overrides.setProperty(PROPERTY_RETRY_DELAY_START, 0 + ""); Iterable<Module> modules = ImmutableSet.<Module> of( new SshjSshClientModule(), new NullLoggingModule()); ContextBuilder builder = ContextBuilder.newBuilder(provider).credentials(login, secretKey).modules(modules).overrides(overrides); journal.log(Level.INFO, ">> Authenticating ..."); computeContext=builder.buildView(ComputeServiceContext.class); ec2api=builder.buildApi(EC2Api.class); //loadBalancerCtx=builder.buildView(LoadBalancerServiceContext.class); compute=computeContext.getComputeService(); this.provider = provider; }
Example 3
Source File: ObjectStoreFileStorageFactoryBean.java From multiapps-controller with Apache License 2.0 | 5 votes |
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: Ec2Context.java From karamel with Apache License 2.0 | 5 votes |
public Ec2Context(Ec2Credentials credentials) { this.credentials = credentials; Properties properties = new Properties(); long scriptTimeout = TimeUnit.MILLISECONDS.convert(50, TimeUnit.MINUTES); properties.setProperty(TIMEOUT_SCRIPT_COMPLETE, scriptTimeout + ""); properties.setProperty(TIMEOUT_PORT_OPEN, scriptTimeout + ""); properties.setProperty(PROPERTY_CONNECTION_TIMEOUT, scriptTimeout + ""); properties.setProperty(PROPERTY_EC2_AMI_QUERY, "owner-id=137112412989;state=available;image-type=machine"); properties.setProperty(PROPERTY_EC2_CC_AMI_QUERY, ""); properties.setProperty(Constants.PROPERTY_MAX_RETRIES, Settings.JCLOUDS_PROPERTY_MAX_RETRIES + ""); properties.setProperty(Constants.PROPERTY_RETRY_DELAY_START, Settings.JCLOUDS_PROPERTY_RETRY_DELAY_START + ""); Iterable<Module> modules = ImmutableSet.<Module>of( new SshjSshClientModule(), new SLF4JLoggingModule(), new EnterpriseConfigurationModule()); ContextBuilder build = ContextBuilder.newBuilder("aws-ec2") .credentials(credentials.getAccessKey(), credentials.getSecretKey()) .modules(modules) .overrides(properties); ComputeServiceContext context = build.buildView(ComputeServiceContext.class); this.computeService = (AWSEC2ComputeService) context.getComputeService(); this.ec2api = computeService.getContext().unwrapApi(EC2Api.class); this.securityGroupApi = ec2api.getSecurityGroupApi().get(); this.keypairApi = (AWSKeyPairApi) ec2api.getKeyPairApi().get(); vmBatchSize = Settings.AWS_VM_BATCH_SIZE(); }
Example 5
Source File: BlobStoreContextFactoryImpl.java From brooklyn-server with Apache License 2.0 | 5 votes |
@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 6
Source File: OpenStackConnector.java From cloudml with GNU Lesser General Public License v3.0 | 5 votes |
public OpenStackConnector(String endPoint,String provider,String login,String secretKey){ this.endpoint=endPoint; journal.log(Level.INFO, ">> Connecting to "+provider+" ..."); Iterable<Module> modules = ImmutableSet.<Module> of( new SshjSshClientModule(), new NullLoggingModule()); ContextBuilder builder = ContextBuilder.newBuilder(provider) .endpoint(endPoint) .credentials(login, secretKey) .modules(modules); journal.log(Level.INFO, ">> Authenticating ..."); computeContext=builder.buildView(ComputeServiceContext.class); novaComputeService= computeContext.getComputeService(); serverApi=builder.buildApi(NovaApi.class); }