本文整理汇总了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);
}
}
示例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);
}
}
示例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);
}
示例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");
}
示例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);
}
示例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();
}
示例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();
}
示例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();
}
示例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;
}
示例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);
}
示例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);
}
示例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;
}
}
}
示例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;
}
示例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]);
}
示例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);
}