本文整理匯總了Java中org.jclouds.ContextBuilder.buildView方法的典型用法代碼示例。如果您正苦於以下問題:Java ContextBuilder.buildView方法的具體用法?Java ContextBuilder.buildView怎麽用?Java ContextBuilder.buildView使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.jclouds.ContextBuilder
的用法示例。
在下文中一共展示了ContextBuilder.buildView方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: withCompute
import org.jclouds.ContextBuilder; //導入方法依賴的package包/類
private <T> T withCompute(ComputeTask<T> task) throws HekateException {
ContextBuilder builder = ContextBuilder.newBuilder(provider)
.credentialsSupplier(credentials::get)
.modules(ImmutableSet.<Module>of(new SLF4JLoggingModule()));
if (!properties.isEmpty()) {
builder.overrides(properties);
}
if (endpoint != null && !endpoint.trim().isEmpty()) {
builder.endpoint(endpoint.trim());
}
try (ComputeServiceContext ctx = builder.buildView(ComputeServiceContext.class)) {
return task.execute(ctx);
}
}
示例2: AbstractJCloudsCloudProvider
import org.jclouds.ContextBuilder; //導入方法依賴的package包/類
/**
* Constructor which takes name and map of overrides.
*
* @param name provider name (must not be {@code null})
* @param overrides configuration overrides (may be {@code null})
* @throws NullPointerException when {@code name} is {@code null}
*/
public AbstractJCloudsCloudProvider(String name, CloudProviderType cloudProviderType, Map<String, String> overrides,
Function<ObjectProperties, ContextBuilder> contextBuilderCreator) {
Objects.requireNonNull(name, "Cloud provider name has to be provided.");
this.cloudProviderType = cloudProviderType;
this.objectProperties = new ObjectProperties(ObjectType.CLOUD_PROVIDER, name, overrides);
LOGGER.debug("Creating {} ComputeServiceContext", cloudProviderType.getHumanReadableName());
ContextBuilder contextBuilder = contextBuilderCreator.apply(objectProperties);
// TODO the following builds a Guice injector twice, which is wasteful
this.guiceInjector = contextBuilder.buildInjector();
this.socketFinder = guiceInjector.getInstance(OpenSocketFinder.class);
this.computeServiceContext = contextBuilder.buildView(ComputeServiceContext.class);
LOGGER.info("Started {} cloud provider '{}'", cloudProviderType.getHumanReadableName(), name);
}
示例3: OpenStackWrapper
import org.jclouds.ContextBuilder; //導入方法依賴的package包/類
@SuppressWarnings("deprecation")
OpenStackWrapper(OpenstackCloudPlatformConfiguration config)
{
this.config = config;
this.log = JCloudScaleConfiguration.getLogger(this);
String identity = config.getTenantName()+":"+config.getLogin();
ContextBuilder builder = ContextBuilder.newBuilder(NOVA_PROVIDER)
.credentials(identity, config.getPassword())
.endpoint(config.getIdentityPublicURL());
context = builder.buildView(ComputeServiceContext.class);
nova = context.unwrap();
openstack = nova.getApi().getServerApiForZone(nova.getApi().getConfiguredZones().toArray(new String[0])[0]);
floatingIp = nova.getApi().getFloatingIPExtensionForZone(nova.getApi().getConfiguredZones().toArray(new String[0])[0]).get();
flavors = nova.getApi().getFlavorApiForZone(nova.getApi().getConfiguredZones().toArray(new String[0])[0]);
images = nova.getApi().getImageApiForZone(nova.getApi().getConfiguredZones().toArray(new String[0])[0]);
}
示例4: JCloudsConnector
import org.jclouds.ContextBuilder; //導入方法依賴的package包/類
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;
}
示例5: createContext
import org.jclouds.ContextBuilder; //導入方法依賴的package包/類
private BlobStoreContext createContext() {
ContextBuilder builder = ContextBuilder.newBuilder(provider)
.credentialsSupplier(credentials::get)
.modules(ImmutableSet.<Module>of(new SLF4JLoggingModule()));
if (!properties.isEmpty()) {
builder.overrides(properties);
}
return builder.buildView(BlobStoreContext.class);
}
示例6: getTenantId
import org.jclouds.ContextBuilder; //導入方法依賴的package包/類
public String getTenantId(VimInstance vimInstance) throws VimDriverException {
log.debug(
"Finding TenantID for Tenant with name: "
+ vimInstance.getTenant()
+ " on VimInstance with name: "
+ vimInstance.getName());
try {
ContextBuilder contextBuilder =
ContextBuilder.newBuilder("openstack-nova")
.credentials(vimInstance.getUsername(), vimInstance.getPassword())
.endpoint(vimInstance.getAuthUrl());
ComputeServiceContext context = contextBuilder.buildView(ComputeServiceContext.class);
Function<Credentials, Access> auth =
context
.utils()
.injector()
.getInstance(Key.get(new TypeLiteral<Function<Credentials, Access>>() {}));
//Get Access and all information
Access access =
auth.apply(
new Credentials.Builder<Credentials>()
.identity(vimInstance.getTenant() + ":" + vimInstance.getUsername())
.credential(vimInstance.getPassword())
.build());
//Get Tenant ID of user
String tenant_id = access.getToken().getTenant().get().getId();
log.info(
"Found TenantID for Tenant with name: "
+ vimInstance.getTenant()
+ " on VimInstance with name: "
+ vimInstance.getName()
+ " -> TenantID: "
+ tenant_id);
return tenant_id;
} catch (Exception e) {
log.error(e.getMessage(), e);
throw new VimDriverException(e.getMessage());
}
}
示例7: Ec2Context
import org.jclouds.ContextBuilder; //導入方法依賴的package包/類
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();
}
示例8: Ec2Context
import org.jclouds.ContextBuilder; //導入方法依賴的package包/類
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.aWSEC2Api = computeService.getContext().unwrapApi(AWSEC2Api.class);
this.securityGroupApi = ec2api.getSecurityGroupApi().get();
this.keypairApi = (AWSKeyPairApi) ec2api.getKeyPairApi().get();
this.spotInstanceApi = (SpotInstanceApi) aWSEC2Api.getSpotInstanceApi().get();
this.configuredRegions = aWSEC2Api.getConfiguredRegions();
}
示例9: initController
import org.jclouds.ContextBuilder; //導入方法依賴的package包/類
private static MinecraftController initController(String provider, String identity, String credential, String group) {
Properties properties = new Properties();
properties.setProperty("minecraft.port", "25565");
properties.setProperty("minecraft.group", group);
properties.setProperty("minecraft.ms", "1024");
properties.setProperty("minecraft.mx", "1024");
properties.setProperty("minecraft.url",
"https://s3.amazonaws.com/MinecraftDownload/launcher/minecraft_server.jar");
if ("aws-ec2".equals(provider)) {
// since minecraft download is in s3 on us-east, lowest latency is from
// there
properties.setProperty(PROPERTY_REGIONS, "us-east-1");
properties.setProperty("jclouds.ec2.ami-query", "owner-id=137112412989;state=available;image-type=machine");
properties.setProperty("jclouds.ec2.cc-ami-query", "");
}
// example of injecting a ssh implementation
Iterable<Module> modules = ImmutableSet.<Module> of(
new SshjSshClientModule(),
new SLF4JLoggingModule(),
new EnterpriseConfigurationModule(),
// This is extended stuff you might inject!!
new ConfigureMinecraftDaemon());
ContextBuilder builder = ContextBuilder.newBuilder(provider)
.credentials(identity, credential)
.modules(modules)
.overrides(properties);
System.out.printf(">> initializing %s%n", builder.getApiMetadata());
ComputeServiceContext context = builder.buildView(ComputeServiceContext.class);
context.utils().eventBus().register(ScriptLogger.INSTANCE);
return context.utils().injector().getInstance(MinecraftController.class);
}
示例10: OpenStackConnector
import org.jclouds.ContextBuilder; //導入方法依賴的package包/類
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);
}
示例11: findFloatingIpId
import org.jclouds.ContextBuilder; //導入方法依賴的package包/類
private String findFloatingIpId(String floatingIp, VimInstance vimInstance)
throws VimDriverException, IOException {
URI endpoint = null;
ContextBuilder contextBuilder =
ContextBuilder.newBuilder("openstack-nova")
.credentials(vimInstance.getUsername(), vimInstance.getPassword())
.endpoint(vimInstance.getAuthUrl());
ComputeServiceContext context = contextBuilder.buildView(ComputeServiceContext.class);
Function<Credentials, Access> auth =
context
.utils()
.injector()
.getInstance(Key.get(new TypeLiteral<Function<Credentials, Access>>() {}));
Access access =
auth.apply(
new Credentials.Builder<Credentials>()
.identity(vimInstance.getTenant() + ":" + vimInstance.getUsername())
.credential(vimInstance.getPassword())
.build());
log.debug("listing FloatingIPs: finding endpoint");
for (org.jclouds.openstack.keystone.v2_0.domain.Service service : access) {
if (service.getName().equals("neutron")) {
for (Endpoint end : service) {
endpoint = end.getPublicURL();
break;
}
break;
}
}
HttpURLConnection connection = null;
URL url = new URL(endpoint + "/v2.0/floatingips.json");
connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.setDoOutput(true);
connection.setRequestProperty("Accept", "application/json");
connection.setRequestProperty("Content-Type", "application/json");
connection.setRequestProperty("User-Agent", "python-neutronclient");
connection.setRequestProperty("X-Auth-Token", access.getToken().getId());
InputStream is = connection.getInputStream();
BufferedReader rd = new BufferedReader(new InputStreamReader(is));
StringBuilder response = new StringBuilder(); // or StringBuffer if not Java 5+
String line;
while ((line = rd.readLine()) != null) {
response.append(line);
response.append('\r');
}
rd.close();
//Parse json to object
log.debug("Associating FloatingIP: Response of final request is: " + response.toString());
JsonObject res =
new GsonBuilder()
.setPrettyPrinting()
.create()
.fromJson(response.toString(), JsonObject.class);
if (res.has("floatingips")) {
for (JsonElement element : res.get("floatingips").getAsJsonArray()) {
log.debug("FloatingIp is: " + element.getAsJsonObject());
String floating_ip_address =
element.getAsJsonObject().get("floating_ip_address").getAsString();
log.debug("found ip: " + floating_ip_address);
log.debug(floating_ip_address + " == " + floatingIp);
if (floating_ip_address.equals(floatingIp)) {
return element.getAsJsonObject().get("id").getAsString();
}
}
} else {
log.warn("Was not possible through Openstack ReST api to retreive all the FloatingIP");
}
throw new VimDriverException(
"looking for a floating ip id of a not existing floating ip. Sorry for that, we can't really implement very "
+ "well:(");
}
示例12: start
import org.jclouds.ContextBuilder; //導入方法依賴的package包/類
@Override
public void start() {
key2StringMapper = Util.getInstance(configuration.key2StringMapper(), initializationContext.getCache()
.getAdvancedCache().getClassLoader());
key2StringMapper.setMarshaller(initializationContext.getMarshaller());
ContextBuilder contextBuilder = ContextBuilder.newBuilder(configuration.provider()).credentials(configuration.identity(), configuration.credential());
if(configuration.overrides() != null)
contextBuilder.overrides(configuration.overrides());
if(configuration.endpoint() != null && !configuration.endpoint().isEmpty())
contextBuilder.endpoint(configuration.endpoint());
blobStoreContext = contextBuilder.buildView(BlobStoreContext.class);
blobStore = blobStoreContext.getBlobStore();
String cacheName = configuration.normalizeCacheNames() ?
initializationContext.getCache().getName().replaceAll("[^a-zA-Z0-9-]", "-")
: initializationContext.getCache().getName();
containerName = String.format("%s-%s", configuration.container(), cacheName);
if (!blobStore.containerExists(containerName)) {
Location location = null;
if (configuration.location() != null ) {
location = new LocationBuilder()
.scope(LocationScope.REGION)
.id(configuration.location())
.description(String.format("Infinispan cache store for %s", containerName))
.build();
}
blobStore.createContainerInLocation(location, containerName);
//make sure container is created
if(!blobStore.containerExists(containerName)) {
try {
log.waitingForContainer();
TimeUnit.SECONDS.sleep(10);
} catch (InterruptedException e) {
throw new PersistenceException(String.format("Aborted when creating blob container %s", containerName));
}
if(!blobStore.containerExists(containerName)) {
throw new PersistenceException(String.format("Unable to create blob container %s", containerName));
}
}
}
}