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


Java ComputeServiceContext类代码示例

本文整理汇总了Java中org.jclouds.compute.ComputeServiceContext的典型用法代码示例。如果您正苦于以下问题:Java ComputeServiceContext类的具体用法?Java ComputeServiceContext怎么用?Java ComputeServiceContext使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ComputeServiceContext类属于org.jclouds.compute包,在下文中一共展示了ComputeServiceContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: withCompute

import org.jclouds.compute.ComputeServiceContext; //导入依赖的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: setUpClass

import org.jclouds.compute.ComputeServiceContext; //导入依赖的package包/类
@BeforeClass
public static void setUpClass() throws RunNodesException {
    Assume.assumeTrue(HekateTestProps.is("AWS_TEST_ENABLED"));

    Properties props = new Properties();

    props.setProperty(LocationConstants.PROPERTY_REGIONS, REGION);

    ContextBuilder builder = newBuilder("aws-ec2").credentials(
        ACCESS_KEY,
        SECRET_KEY
    ).overrides(props);

    ComputeService compute = builder.modules(ImmutableSet.<Module>of(new SLF4JLoggingModule()))
        .buildView(ComputeServiceContext.class)
        .getComputeService();

    for (int i = 0; i < 4; i++) {
        ensureNodeExists(i, compute);
    }
}
 
开发者ID:hekate-io,项目名称:hekate,代码行数:22,代码来源:AwsCloudSeedNodeProviderTest.java

示例3: AbstractJCloudsCloudProvider

import org.jclouds.compute.ComputeServiceContext; //导入依赖的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

示例4: DimensionDataCloudControllerComputeService

import org.jclouds.compute.ComputeServiceContext; //导入依赖的package包/类
@Inject
protected DimensionDataCloudControllerComputeService(ComputeServiceContext context, Map<String, Credentials> credentialStore,
                                                     @Memoized Supplier<Set<? extends Image>> images, @Memoized Supplier<Set<? extends Hardware>> sizes,
                                                     @Memoized Supplier<Set<? extends Location>> locations, ListNodesStrategy listNodesStrategy,
                                                     GetImageStrategy getImageStrategy, GetNodeMetadataStrategy getNodeMetadataStrategy,
                                                     CreateNodesInGroupThenAddToSet runNodesAndAddToSetStrategy, RebootNodeStrategy rebootNodeStrategy,
                                                     DestroyNodeStrategy destroyNodeStrategy, ResumeNodeStrategy startNodeStrategy,
                                                     SuspendNodeStrategy stopNodeStrategy, Provider<TemplateBuilder> templateBuilderProvider,
                                                     @Named("DEFAULT") Provider<TemplateOptions> templateOptionsProvider,
                                                     @Named(TIMEOUT_NODE_RUNNING) Predicate<AtomicReference<NodeMetadata>> nodeRunning,
                                                     @Named(TIMEOUT_NODE_TERMINATED) Predicate<AtomicReference<NodeMetadata>> nodeTerminated,
                                                     @Named(TIMEOUT_NODE_SUSPENDED) Predicate<AtomicReference<NodeMetadata>> nodeSuspended,
                                                     InitializeRunScriptOnNodeOrPlaceInBadMap.Factory initScriptRunnerFactory,
                                                     RunScriptOnNode.Factory runScriptOnNodeFactory, InitAdminAccess initAdminAccess,
                                                     PersistNodeCredentials persistNodeCredentials, Timeouts timeouts,
                                                     @Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor,
                                                     CleanupServer cleanupServer,
                                                     Optional<ImageExtension> imageExtension,
                                                     Optional<SecurityGroupExtension> securityGroupExtension) {
   super(context, credentialStore, images, sizes, locations, listNodesStrategy, getImageStrategy,
            getNodeMetadataStrategy, runNodesAndAddToSetStrategy, rebootNodeStrategy, destroyNodeStrategy,
            startNodeStrategy, stopNodeStrategy, templateBuilderProvider, templateOptionsProvider, nodeRunning,
            nodeTerminated, nodeSuspended, initScriptRunnerFactory, initAdminAccess, runScriptOnNodeFactory,
            persistNodeCredentials, timeouts, userExecutor, imageExtension, securityGroupExtension);
   this.cleanupServer = checkNotNull(cleanupServer, "cleanupServer");
}
 
开发者ID:cloudsoft,项目名称:amp-dimensiondata,代码行数:27,代码来源:DimensionDataCloudControllerComputeService.java

示例5: CloudServersUnicastHostsProvider

import org.jclouds.compute.ComputeServiceContext; //导入依赖的package包/类
@Inject
public CloudServersUnicastHostsProvider(Settings settings, TransportService transportService, ComputeServiceContext context) {
    super(settings);
    this.transportService = transportService;
    this.context = context;

    this.bindAnyGroup = componentSettings.getAsBoolean("any_group", true);
    this.groups = ImmutableSet.copyOf(componentSettings.getAsArray("groups"));

    this.tags = ImmutableSet.copyOf(componentSettings.getAsArray("tags"));

    this.region = settings.get("rackspace.region", "ORD");

    this.privateIp = componentSettings.getAsBoolean("private_address", true);

    logger.debug("using tags [{}], groups [{}] with any_group [{}]", tags, groups, bindAnyGroup);
}
 
开发者ID:jlinn,项目名称:elasticsearch-cloud-rackspace,代码行数:18,代码来源:CloudServersUnicastHostsProvider.java

示例6: OSConnection

import org.jclouds.compute.ComputeServiceContext; //导入依赖的package包/类
/**
 * Establishes a connection the OpenStack with the given credentials
 * 
 * @param credentials
 * @param endpointURL e.g. https://keystone.rc.nectar.org.au:5000/v2.0/
 */
public OSConnection(OSCredentials credentials, String endpointURL) {
	Iterable<Module> modules = ImmutableSet.<Module>of(new SLF4JLoggingModule(),
			new JschSshClientModule());

       String provider = "openstack-nova";
       String identity = credentials.getTenantId()+":"+credentials.getUserName();
       String credential = credentials.getPassword();

       ContextBuilder contextBuilder = ContextBuilder.newBuilder(provider)
               .endpoint(endpointURL)
               .credentials(identity, credential)
               .modules(modules);
       
       novaApi = contextBuilder.buildApi(NovaApi.class);
       computeService = contextBuilder.buildView(ComputeServiceContext.class).getComputeService();
       DEFAULT_ZONE = novaApi.getConfiguredZones().iterator().next();
}
 
开发者ID:jasonrig,项目名称:openstack-queue,代码行数:24,代码来源:OSConnection.java

示例7: JCloudsSecurityGroupExtension

import org.jclouds.compute.ComputeServiceContext; //导入依赖的package包/类
@Inject
public JCloudsSecurityGroupExtension(JCloudsViewFactory jCloudsViewFactory,
    OneWayConverter<org.jclouds.compute.domain.SecurityGroup, SecurityGroup> securityGroupConverter,
    OneWayConverter<Location, org.jclouds.domain.Location> locationConverter,
    GetStrategy<String, Location> locationGetStrategy) {

  checkNotNull(locationGetStrategy, "locationGetStrategy is null");
  this.locationGetStrategy = locationGetStrategy;

  checkNotNull(locationConverter);
  this.locationConverter = locationConverter;

  checkNotNull(securityGroupConverter);
  this.securityGroupConverter = securityGroupConverter;

  checkNotNull(jCloudsViewFactory);

  final ComputeServiceContext computeServiceContext =
      jCloudsViewFactory.buildJCloudsView(ComputeServiceContext.class);
  final Optional<org.jclouds.compute.extensions.SecurityGroupExtension> optional =
      computeServiceContext.getComputeService().getSecurityGroupExtension();
  checkState(optional.isPresent(), "security group extension not present.");

  this.securityGroupExtension = optional.get();

}
 
开发者ID:cloudiator,项目名称:sword,代码行数:27,代码来源:JCloudsSecurityGroupExtension.java

示例8: buildDefaultComputeService

import org.jclouds.compute.ComputeServiceContext; //导入依赖的package包/类
public static ComputeService buildDefaultComputeService(IaasProvider iaasProvider) {

        Properties properties = new Properties();

        // load properties
        for (Map.Entry<String, String> entry : iaasProvider.getProperties().entrySet()) {
            properties.put(entry.getKey(), entry.getValue());
        }

        // set modules
        Iterable<Module> modules =
                ImmutableSet.<Module>of(new SshjSshClientModule(), new SLF4JLoggingModule(),
                        new EnterpriseConfigurationModule());

        // build context
        ContextBuilder builder =
                ContextBuilder.newBuilder(iaasProvider.getProvider())
                        .credentials(iaasProvider.getIdentity(), iaasProvider.getCredential()).modules(modules)
                        .overrides(properties);

        return builder.buildView(ComputeServiceContext.class).getComputeService();
    }
 
开发者ID:apache,项目名称:stratos,代码行数:23,代码来源:ComputeServiceBuilderUtil.java

示例9: createKeyPairFromPublicKey

import org.jclouds.compute.ComputeServiceContext; //导入依赖的package包/类
@Override
public boolean createKeyPairFromPublicKey(String region, String keyPairName, String publicKey) {

    IaasProvider iaasInfo = getIaasProvider();
    ComputeServiceContext context = iaasInfo.getComputeService().getContext();
    CloudStackApi cloudStackApi = context.unwrapApi(CloudStackApi.class);
    SshKeyPair sshKeyPair = cloudStackApi.getSSHKeyPairApi().createSSHKeyPair(keyPairName);

    if (sshKeyPair != null) {

        iaasInfo.getTemplate().getOptions().as(CloudStackTemplateOptions.class)
                .keyPair(sshKeyPair.getName());

        log.info("A key-pair is created successfully - Key Pair Name: " + sshKeyPair.getName());
        return true;
    }
    log.error("Key-pair is unable to create");
    return false;
}
 
开发者ID:apache,项目名称:stratos,代码行数:20,代码来源:CloudStackIaas.java

示例10: isValidZone

import org.jclouds.compute.ComputeServiceContext; //导入依赖的package包/类
@Override
public boolean isValidZone(String region, String zone) throws InvalidZoneException {

    IaasProvider iaasInfo = getIaasProvider();
    ComputeServiceContext context = iaasInfo.getComputeService().getContext();
    CloudStackApi cloudStackApi = context.unwrapApi(CloudStackApi.class);
    ListZonesOptions listZonesOptions = new ListZonesOptions();
    listZonesOptions.available(true);
    Set<Zone> zoneSet = cloudStackApi.getZoneApi().listZones(listZonesOptions);

    for (org.jclouds.cloudstack.domain.Zone configuredZone : zoneSet) {
        if (configuredZone.getName().equalsIgnoreCase(zone)) {
            return true;
        }
    }
    String msg = "Invalid zone: " + zone + " in the iaas: " + iaasInfo.getType();
    log.error(msg);
    throw new InvalidZoneException(msg);
}
 
开发者ID:apache,项目名称:stratos,代码行数:20,代码来源:CloudStackIaas.java

示例11: deleteVolume

import org.jclouds.compute.ComputeServiceContext; //导入依赖的package包/类
@Override
public void deleteVolume(String volumeId) {
    IaasProvider iaasInfo = getIaasProvider();
    ComputeServiceContext context = iaasInfo.getComputeService().getContext();
    String region = ComputeServiceBuilderUtil.extractRegion(iaasInfo);
    if (region == null) {
        log.fatal("Cannot delete the volume [id]: " + volumeId + " of the [region] : " + region + " of Iaas : "
                + iaasInfo);
        return;
    }
    ElasticBlockStoreApi blockStoreApi = context.unwrapApi(AWSEC2Api.class).getElasticBlockStoreApiForRegion(region)
            .get();
    blockStoreApi.deleteVolumeInRegion(region, volumeId);
    log.info("Deletion of Volume [id]: " + volumeId + " was successful. [region] : " + region + " of Iaas : "
            + iaasInfo);
}
 
开发者ID:apache,项目名称:stratos,代码行数:17,代码来源:EC2Iaas.java

示例12: releaseAddress

import org.jclouds.compute.ComputeServiceContext; //导入依赖的package包/类
@Override
public void releaseAddress(String ip) {

    ComputeServiceContext context = iaasProvider.getComputeService().getContext();
    String region = ComputeServiceBuilderUtil.extractRegion(iaasProvider);

    NovaApi novaApi = context.unwrapApi(NovaApi.class);
    FloatingIPApi floatingIPApi = novaApi.getFloatingIPExtensionForZone(region).get();

    for (FloatingIP floatingIP : floatingIPApi.list()) {
        if (floatingIP.getIp().equals(ip)) {
            floatingIPApi.delete(floatingIP.getId());
            break;
        }
    }
}
 
开发者ID:apache,项目名称:stratos,代码行数:17,代码来源:NovaNetworkingApi.java

示例13: createKeyPairFromPublicKey

import org.jclouds.compute.ComputeServiceContext; //导入依赖的package包/类
@Override
public synchronized boolean createKeyPairFromPublicKey(String region, String keyPairName, String publicKey) {
    IaasProvider iaasInfo = getIaasProvider();
    String openstackNovaMsg = " Openstack-nova. Region: " + region + " - Name: ";
    ComputeServiceContext context = iaasInfo.getComputeService().getContext();
    NovaApi novaApi = context.unwrapApi(NovaApi.class);
    KeyPairApi api = novaApi.getKeyPairExtensionForZone(region).get();
    KeyPair keyPair = api.createWithPublicKey(keyPairName, publicKey);
    if (keyPair != null) {
        iaasInfo.getTemplate().getOptions().as(NovaTemplateOptions.class).keyPairName(keyPair.getName());
        log.info(SUCCESSFUL_LOG_LINE + openstackNovaMsg + keyPair.getName());
        return true;
    }
    log.error(FAILED_LOG_LINE + openstackNovaMsg);
    return false;
}
 
开发者ID:apache,项目名称:stratos,代码行数:17,代码来源:OpenstackIaas.java

示例14: OpenStackWrapper

import org.jclouds.compute.ComputeServiceContext; //导入依赖的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

示例15: getComputeApiFromCarinaDirectory

import org.jclouds.compute.ComputeServiceContext; //导入依赖的package包/类
public static ComputeServiceContext getComputeApiFromCarinaDirectory(String path) throws IOException {
   // docker.ps1 contains the endpoint
   String endpoint = "https://" +
         Files.readFirstLine(new File(joinPath(path, "docker.ps1")),
               Charset.forName("UTF-8")).split("=")[1].replace("\"", "").substring(6);

   // enable logging and sshj
   Iterable<Module> modules = ImmutableSet.<Module> of(new SLF4JLoggingModule(), new SshjSshClientModule());
   Properties overrides = new Properties();

   // disable certificate checking for Carina
   overrides.setProperty("jclouds.trust-all-certs", "true");

   return ContextBuilder.newBuilder("docker")
         .credentials(joinPath(path, "cert.pem"), joinPath(path, "key.pem"))
         .modules(modules)
         .overrides(overrides)
         .endpoint(endpoint)
         .buildView(ComputeServiceContext.class);
}
 
开发者ID:jclouds,项目名称:jclouds-examples,代码行数:21,代码来源:Utils.java


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