本文整理汇总了Java中org.jclouds.ContextBuilder.endpoint方法的典型用法代码示例。如果您正苦于以下问题:Java ContextBuilder.endpoint方法的具体用法?Java ContextBuilder.endpoint怎么用?Java ContextBuilder.endpoint使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jclouds.ContextBuilder
的用法示例。
在下文中一共展示了ContextBuilder.endpoint方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: createContextBuilder
import org.jclouds.ContextBuilder; //导入方法依赖的package包/类
private static ContextBuilder createContextBuilder(ObjectProperties objectProperties) {
Set<Module> modules = new HashSet<>();
modules.add(new DynamicSshClientModule());
modules.add(new SocketFinderOnlyPublicInterfacesModule());
modules.add(new SLF4JLoggingModule());
Properties overrides = new Properties();
overrides.setProperty("jclouds.ssh.retry-auth", Boolean.FALSE.toString());
overrides.setProperty("jclouds.ssh.max-retries", Integer.toString(1));
ContextBuilder contextBuilder = ContextBuilder.newBuilder("openstack-nova");
String endpoint = objectProperties.getProperty(Config.CloudProvider.Openstack.ENDPOINT);
if (!Strings.isNullOrEmpty(endpoint)) {
contextBuilder.endpoint(endpoint);
}
contextBuilder
.credentials(
objectProperties.getProperty(Config.CloudProvider.Openstack.USERNAME),
objectProperties.getProperty(Config.CloudProvider.Openstack.PASSWORD)
)
.overrides(overrides)
.modules(modules);
return contextBuilder;
}
示例3: blobStoreContextFromProperties
import org.jclouds.ContextBuilder; //导入方法依赖的package包/类
private static BlobStoreContext blobStoreContextFromProperties(
Properties properties) {
String provider = properties.getProperty(Constants.PROPERTY_PROVIDER);
String identity = properties.getProperty(Constants.PROPERTY_IDENTITY);
String credential = properties.getProperty(
Constants.PROPERTY_CREDENTIAL);
String endpoint = properties.getProperty(Constants.PROPERTY_ENDPOINT);
if (provider == null || identity == null || credential == null) {
System.err.println("Properties file must contain:\n" +
Constants.PROPERTY_PROVIDER + "\n" +
Constants.PROPERTY_IDENTITY + "\n" +
Constants.PROPERTY_CREDENTIAL);
System.exit(1);
}
ContextBuilder builder = ContextBuilder
.newBuilder(provider)
.credentials(identity, credential)
.modules(ImmutableList.<Module>of(new SLF4JLoggingModule()))
.overrides(properties);
if (endpoint != null) {
builder = builder.endpoint(endpoint);
}
return builder.build(BlobStoreContext.class);
}
示例4: createContextBuilder
import org.jclouds.ContextBuilder; //导入方法依赖的package包/类
private static ContextBuilder createContextBuilder(ObjectProperties objectProperties) {
Properties properties = new Properties();
final String amiQuery = objectProperties.getProperty(Config.CloudProvider.EC2.AMI_QUERY);
if (!Strings.isNullOrEmpty(amiQuery)) {
properties.setProperty(AWSEC2Constants.PROPERTY_EC2_AMI_QUERY, amiQuery);
}
final String ec2Regions = objectProperties.getProperty(Config.CloudProvider.EC2.REGION);
if (!Strings.isNullOrEmpty(ec2Regions)) {
properties.setProperty(LocationConstants.PROPERTY_REGIONS, ec2Regions);
}
Set<Module> modules = new HashSet<>();
modules.add(new DynamicSshClientModule());
modules.add(new SocketFinderOnlyPublicInterfacesModule());
if (Boolean.parseBoolean(objectProperties.getProperty(Config.CloudProvider.EC2.LOG_EC2_OPERATIONS))) {
// TODO we should add that unconditionally, like we do in all other cloud providers!
// the reason why we don't [yet] is that the JClouds EC2 provider does some excessive logging,
// e.g. the names of all available images, and we don't want our users to have to deal with that
modules.add(new SLF4JLoggingModule());
}
final ContextBuilder contextBuilder = ContextBuilder.newBuilder("aws-ec2");
final String endpoint = objectProperties.getProperty(Config.CloudProvider.EC2.ENDPOINT);
if (!Strings.isNullOrEmpty(endpoint)) {
contextBuilder.endpoint(endpoint);
}
contextBuilder
.credentials(
objectProperties.getProperty(Config.CloudProvider.EC2.ACCESS_KEY_ID),
objectProperties.getProperty(Config.CloudProvider.EC2.SECRET_ACCESS_KEY)
)
.overrides(properties).modules(ImmutableSet.copyOf(modules));
return contextBuilder;
}
示例5: build
import org.jclouds.ContextBuilder; //导入方法依赖的package包/类
/**
* Build compute service.
*
* @return the compute service
*/
ComputeService build() {
final String cloudProvider = getOrNull(JCloudsProperties.PROVIDER);
final String endpoint = getOrNull(JCloudsProperties.ENDPOINT);
final String identity = getOrNull(JCloudsProperties.IDENTITY);
String credential = getOrNull(JCloudsProperties.CREDENTIAL);
final String credentialPath = getOrNull(JCloudsProperties.CREDENTIAL_PATH);
isNotNull(cloudProvider, "Cloud Provider");
if (credential != null && credentialPath != null) {
throw new UnsupportedOperationException("Both credential and credentialPath are set. Use only one method.");
}
if (credentialPath != null) {
credential = getCredentialFromFile(cloudProvider, credentialPath);
}
if (LOGGER.isFinestEnabled()) {
LOGGER.finest("Using CLOUD_PROVIDER: " + cloudProvider);
}
final String roleName = getOrNull(JCloudsProperties.ROLE_NAME);
ContextBuilder contextBuilder = newContextBuilder(cloudProvider, identity, credential, roleName);
if (endpoint != null) {
if (LOGGER.isFinestEnabled()) {
LOGGER.finest("Using custom endpoint: " + endpoint);
}
contextBuilder.endpoint(endpoint);
}
Properties jcloudsProperties = buildRegionZonesConfig();
buildTagConfig();
buildNodeFilter();
computeService = contextBuilder.overrides(jcloudsProperties)
.modules(ImmutableSet.of(new HazelcastLoggingModule()))
.buildView(ComputeServiceContext.class)
.getComputeService();
return computeService;
}
示例6: buildContext
import org.jclouds.ContextBuilder; //导入方法依赖的package包/类
private ContextBuilder buildContext() {
//todo ugly hack
final Properties properties = new Properties();
if (regions != null) {
properties.setProperty("jclouds.regions", regions);
}
if (requestTimeout != null) {
properties.setProperty(org.jclouds.Constants.PROPERTY_REQUEST_TIMEOUT, requestTimeout);
}
//todo duplicates code from NovaApiProvider
// loading ssh module of jclouds as it seems to be required for google,
// we are using the jschsshclient as the sshj conflicts with the overthere bouncy castle impl.
Set<Module> moduleSet = new HashSet<>();
moduleSet.addAll(overrideModules());
moduleSet.add(new JCloudsLoggingModule(loggerFactory));
ContextBuilder contextBuilder = ContextBuilder.newBuilder(cloud.api().providerName());
contextBuilder.credentials(cloud.credential().user(), cloud.credential().password())
.modules(moduleSet).overrides(overrideProperties(properties));
// setting optional endpoint, check for present first
// as builder does not allow null values...
if (cloud.endpoint().isPresent()) {
contextBuilder.endpoint(cloud.endpoint().get());
}
return contextBuilder;
}
示例7: mungeBuilder
import org.jclouds.ContextBuilder; //导入方法依赖的package包/类
@Override
public void mungeBuilder(ContextBuilder builder) {
builder.endpoint("https://management.core.windows.net/" + getSubscriptionId());
}
示例8: main
import org.jclouds.ContextBuilder; //导入方法依赖的package包/类
/**
* Main method.
* @param args
*/
public static void main(String[] args) throws Exception {
if (args.length == 1 && args[0].equals("--version")) {
System.err.println(
Main.class.getPackage().getImplementationVersion());
System.exit(0);
} else if (args.length != 2) {
System.err.println("Usage: swiftproxy --properties FILE");
System.exit(1);
}
Properties properties = new Properties();
try (InputStream is = new FileInputStream(new File(args[1]))) {
properties.load(is);
}
properties.putAll(System.getProperties());
String provider = properties.getProperty(Constants.PROPERTY_PROVIDER);
String identity = properties.getProperty(Constants.PROPERTY_IDENTITY);
String credential = properties.getProperty(Constants.PROPERTY_CREDENTIAL);
String endpoint = properties.getProperty(Constants.PROPERTY_ENDPOINT);
String proxyEndpoint = properties.getProperty(SwiftProxy.PROPERTY_ENDPOINT);
if (provider == null || identity == null || credential == null || proxyEndpoint == null) {
System.err.format("Properties file must contain:%n" +
Constants.PROPERTY_PROVIDER + "%n" +
Constants.PROPERTY_IDENTITY + "%n" +
Constants.PROPERTY_CREDENTIAL + "%n" +
SwiftProxy.PROPERTY_ENDPOINT + "%n");
System.exit(1);
}
if (provider.equals("google-cloud-storage")) {
File credentialFile = new File(credential);
if (credentialFile.exists()) {
credential = Files.toString(credentialFile,
StandardCharsets.UTF_8);
}
properties.remove(Constants.PROPERTY_CREDENTIAL);
}
ContextBuilder builder = ContextBuilder
.newBuilder(provider)
.credentials(identity, credential)
.modules(ImmutableList.<Module>of(new SLF4JLoggingModule()))
.overrides(properties);
if (endpoint != null) {
builder = builder.endpoint(endpoint);
}
BlobStoreContext context = builder.build(BlobStoreContext.class);
SwiftProxy proxy = SwiftProxy.Builder.builder()
.overrides(properties)
.endpoint(new URI(proxyEndpoint))
.build();
proxy.start();
System.out.format("Swift proxy listening on port %d%n", proxy.getPort());
Thread.currentThread().join();
}
示例9: setUp
import org.jclouds.ContextBuilder; //导入方法依赖的package包/类
@Before
public void setUp() throws Exception {
Properties s3ProxyProperties = new Properties();
InputStream is = Resources.asByteSource(Resources.getResource(
"s3proxy.conf")).openStream();
try {
s3ProxyProperties.load(is);
} finally {
is.close();
}
String provider = s3ProxyProperties.getProperty(
Constants.PROPERTY_PROVIDER);
String identity = s3ProxyProperties.getProperty(
Constants.PROPERTY_IDENTITY);
String credential = s3ProxyProperties.getProperty(
Constants.PROPERTY_CREDENTIAL);
String endpoint = s3ProxyProperties.getProperty(
Constants.PROPERTY_ENDPOINT);
String s3Identity = s3ProxyProperties.getProperty(
S3ProxyConstants.PROPERTY_IDENTITY);
String s3Credential = s3ProxyProperties.getProperty(
S3ProxyConstants.PROPERTY_CREDENTIAL);
awsCreds = new BasicAWSCredentials(s3Identity, s3Credential);
s3Endpoint = new URI(s3ProxyProperties.getProperty(
S3ProxyConstants.PROPERTY_ENDPOINT));
String keyStorePath = s3ProxyProperties.getProperty(
S3ProxyConstants.PROPERTY_KEYSTORE_PATH);
String keyStorePassword = s3ProxyProperties.getProperty(
S3ProxyConstants.PROPERTY_KEYSTORE_PASSWORD);
String virtualHost = s3ProxyProperties.getProperty(
S3ProxyConstants.PROPERTY_VIRTUAL_HOST);
ContextBuilder builder = ContextBuilder
.newBuilder(provider)
.credentials(identity, credential)
.modules(ImmutableList.<Module>of(new SLF4JLoggingModule()))
.overrides(s3ProxyProperties);
if (!Strings.isNullOrEmpty(endpoint)) {
builder.endpoint(endpoint);
}
context = builder.build(BlobStoreContext.class);
BlobStore blobStore = context.getBlobStore();
containerName = createRandomContainerName();
key = "stuff";
blobStore.createContainerInLocation(null, containerName);
S3Proxy.Builder s3ProxyBuilder = S3Proxy.builder()
.blobStore(blobStore)
.endpoint(s3Endpoint);
if (s3Identity != null || s3Credential != null) {
s3ProxyBuilder.awsAuthentication(s3Identity, s3Credential);
}
if (keyStorePath != null || keyStorePassword != null) {
s3ProxyBuilder.keyStore(
Resources.getResource(keyStorePath).toString(),
keyStorePassword);
}
if (virtualHost != null) {
s3ProxyBuilder.virtualHost(virtualHost);
}
s3Proxy = s3ProxyBuilder.build();
s3Proxy.start();
while (!s3Proxy.getState().equals(AbstractLifeCycle.STARTED)) {
Thread.sleep(1);
}
// reset endpoint to handle zero port
s3Endpoint = new URI(s3Endpoint.getScheme(), s3Endpoint.getUserInfo(),
s3Endpoint.getHost(), s3Proxy.getPort(), s3Endpoint.getPath(),
s3Endpoint.getQuery(), s3Endpoint.getFragment());
}
示例10: createBlobStore
import org.jclouds.ContextBuilder; //导入方法依赖的package包/类
private static BlobStore createBlobStore(Properties properties,
ExecutorService executorService) throws IOException {
String provider = properties.getProperty(Constants.PROPERTY_PROVIDER);
String identity = properties.getProperty(Constants.PROPERTY_IDENTITY);
String credential = properties.getProperty(
Constants.PROPERTY_CREDENTIAL);
String endpoint = properties.getProperty(Constants.PROPERTY_ENDPOINT);
properties.remove(Constants.PROPERTY_ENDPOINT);
String region = properties.getProperty(
LocationConstants.PROPERTY_REGION);
if (provider == null) {
System.err.println(
"Properties file must contain: " +
Constants.PROPERTY_PROVIDER);
System.exit(1);
}
if (provider.equals("filesystem") || provider.equals("transient")) {
// local blobstores do not require credentials
identity = Strings.nullToEmpty(identity);
credential = Strings.nullToEmpty(credential);
} else if (provider.equals("google-cloud-storage")) {
File credentialFile = new File(credential);
if (credentialFile.exists()) {
credential = Files.asCharSource(credentialFile,
StandardCharsets.UTF_8).read();
}
properties.remove(Constants.PROPERTY_CREDENTIAL);
}
if (identity == null || credential == null) {
System.err.println(
"Properties file must contain: " +
Constants.PROPERTY_IDENTITY + " and " +
Constants.PROPERTY_CREDENTIAL);
System.exit(1);
}
properties.setProperty(Constants.PROPERTY_USER_AGENT,
String.format("s3proxy/%s jclouds/%s java/%s",
Main.class.getPackage().getImplementationVersion(),
JcloudsVersion.get(),
System.getProperty("java.version")));
ContextBuilder builder = ContextBuilder
.newBuilder(provider)
.credentials(identity, credential)
.modules(ImmutableList.<Module>of(
new SLF4JLoggingModule(),
new ExecutorServiceModule(executorService)))
.overrides(properties);
if (!Strings.isNullOrEmpty(endpoint)) {
builder = builder.endpoint(endpoint);
}
BlobStoreContext context = builder.build(BlobStoreContext.class);
BlobStore blobStore = context.getBlobStore();
if (context instanceof RegionScopedBlobStoreContext &&
region != null) {
blobStore = ((RegionScopedBlobStoreContext) context)
.getBlobStore(region);
}
return blobStore;
}
示例11: 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));
}
}
}
}