当前位置: 首页>>代码示例>>Java>>正文


Java ContextBuilder.buildView方法代码示例

本文整理汇总了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);
    }
}
 
开发者ID:hekate-io,项目名称:hekate,代码行数:18,代码来源:CloudSeedNodeProvider.java

示例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);
}
 
开发者ID:wildfly-extras,项目名称:sunstone,代码行数:23,代码来源:AbstractJCloudsCloudProvider.java

示例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]);
	
}
 
开发者ID:xLeitix,项目名称:jcloudscale,代码行数:20,代码来源:OpenStackWrapper.java

示例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;
}
 
开发者ID:SINTEF-9012,项目名称:cloudml,代码行数:26,代码来源:JCloudsConnector.java

示例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);
}
 
开发者ID:hekate-io,项目名称:hekate,代码行数:12,代码来源:CloudStoreSeedNodeProvider.java

示例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());
  }
}
 
开发者ID:openbaton,项目名称:openstack-plugin,代码行数:40,代码来源:OpenstackClient.java

示例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();
}
 
开发者ID:karamelchef,项目名称:karamel,代码行数:30,代码来源:Ec2Context.java

示例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();
}
 
开发者ID:karamelchef,项目名称:kandy,代码行数:32,代码来源:Ec2Context.java

示例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);
}
 
开发者ID:jclouds,项目名称:jclouds-examples,代码行数:36,代码来源:MainApp.java

示例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);
}
 
开发者ID:SINTEF-9012,项目名称:cloudml,代码行数:16,代码来源:OpenStackConnector.java

示例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:(");
}
 
开发者ID:openbaton,项目名称:openstack-plugin,代码行数:79,代码来源:OpenstackClient.java

示例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));
         }
      }
   }
}
 
开发者ID:infinispan,项目名称:infinispan-cachestore-cloud,代码行数:46,代码来源:CloudStore.java


注:本文中的org.jclouds.ContextBuilder.buildView方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。