本文整理汇总了Java中org.jclouds.ContextBuilder类的典型用法代码示例。如果您正苦于以下问题:Java ContextBuilder类的具体用法?Java ContextBuilder怎么用?Java ContextBuilder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ContextBuilder类属于org.jclouds包,在下文中一共展示了ContextBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: setUpClass
import org.jclouds.ContextBuilder; //导入依赖的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: 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;
}
示例4: 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);
}
示例5: S3ProxyImpl
import org.jclouds.ContextBuilder; //导入依赖的package包/类
public S3ProxyImpl(String endpoint, S3Config s3Config) {
URI uri = URI.create(endpoint);
Properties properties = new Properties();
properties.setProperty("s3proxy.authorization", "none");
properties.setProperty("s3proxy.endpoint", endpoint);
properties.setProperty("jclouds.provider", "filesystem");
properties.setProperty("jclouds.filesystem.basedir", "/tmp/s3proxy");
ContextBuilder builder = ContextBuilder
.newBuilder("filesystem")
.credentials("x", "x")
.modules(ImmutableList.<Module>of(new SLF4JLoggingModule()))
.overrides(properties);
BlobStoreContext context = builder.build(BlobStoreContext.class);
BlobStore blobStore = context.getBlobStore();
s3Proxy = S3Proxy.builder().awsAuthentication(AuthenticationType.AWS_V2_OR_V4, "x", "x")
.endpoint(uri)
.keyStore("", "")
.blobStore(blobStore)
.ignoreUnknownHeaders(true)
.build();
client = new S3JerseyCopyPartClient(s3Config);
}
示例6: init
import org.jclouds.ContextBuilder; //导入依赖的package包/类
@Before
public void init() {
initMocks(this);
uploadS3Stream.retry = 5;
uploadS3Stream.s3Client = fakeS3Client;
fakeS3Client.setMakeItFailUpload(false);
fakeS3Client.setBaseFolder(baseDirectory);
fakeS3Client.setMakeItFailCompleteUpload(false);
Properties properties = new Properties();
properties.setProperty(FilesystemConstants.PROPERTY_BASEDIR, baseDirectory);
BlobStoreContext blobStoreContext = ContextBuilder.newBuilder("filesystem")
.overrides(properties)
.buildView(BlobStoreContext.class);
this.springCloudBlobStoreContext = new SpringCloudBlobStoreContext(blobStoreContext, bucketName);
uploadS3Stream.blobStoreContext = this.springCloudBlobStoreContext;
blobStoreContext.getBlobStore().createContainerInLocation(null, bucketName);
this.uploadS3Stream.setChunkSize(UploadS3StreamImpl.DEFAULT_CHUNK_SIZE);
BlobStore blobStore = springCloudBlobStoreContext.getBlobStore();
blob = blobStore.blobBuilder(fileName).build();
}
示例7: rebootServer
import org.jclouds.ContextBuilder; //导入依赖的package包/类
public void rebootServer(VimInstance vimInstance, String extId, RebootType type)
throws VimDriverException {
try {
NovaApi novaApi =
ContextBuilder.newBuilder("openstack-nova")
.endpoint(vimInstance.getAuthUrl())
.credentials(
vimInstance.getTenant() + ":" + vimInstance.getUsername(),
vimInstance.getPassword())
.modules(modules)
.overrides(overrides)
.buildApi(NovaApi.class);
ServerApi serverApi = novaApi.getServerApi(getZone(vimInstance));
serverApi.reboot(extId, type);
} catch (Exception e) {
log.error(e.getMessage(), e);
throw new VimDriverException(e.getMessage());
}
}
示例8: deleteServerById
import org.jclouds.ContextBuilder; //导入依赖的package包/类
public void deleteServerById(VimInstance vimInstance, String extId) throws VimDriverException {
try {
NovaApi novaApi =
ContextBuilder.newBuilder("openstack-nova")
.endpoint(vimInstance.getAuthUrl())
.credentials(
vimInstance.getTenant() + ":" + vimInstance.getUsername(),
vimInstance.getPassword())
.modules(modules)
.overrides(overrides)
.buildApi(NovaApi.class);
ServerApi serverApi = novaApi.getServerApi(getZone(vimInstance));
serverApi.delete(extId);
} catch (Exception e) {
log.error(e.getMessage(), e);
throw new VimDriverException(e.getMessage());
}
}
示例9: testListFlavors
import org.jclouds.ContextBuilder; //导入依赖的package包/类
@Test
public void testListFlavors() throws Exception {
List<DeploymentFlavour> flavors = openstackClient.listFlavors(vimInstance);
assertEqualsFlavors(definedFlavor, flavors.get(0));
NovaApi novaApi = mock(NovaApi.class);
PowerMockito.spy(ContextBuilder.class);
ContextBuilder contextBuilder = mock(ContextBuilder.class);
PowerMockito.doReturn(contextBuilder)
.when(ContextBuilder.class, "newBuilder", Mockito.anyString());
when(contextBuilder.endpoint(anyString())).thenReturn(contextBuilder);
when(contextBuilder.credentials(anyString(), anyString())).thenReturn(contextBuilder);
when(contextBuilder.modules(any(Iterable.class))).thenReturn(contextBuilder);
when(contextBuilder.overrides(any(Properties.class))).thenReturn(contextBuilder);
when(contextBuilder.buildApi(NovaApi.class)).thenReturn(novaApi);
FlavorApi flavorApi = mock(FlavorApi.class);
when(novaApi.getFlavorApi(anyString())).thenReturn(flavorApi);
when(flavorApi.listInDetail()).thenReturn(mock(PagedIterable.class));
when(flavorApi.listInDetail().concat()).thenThrow(new AuthorizationException());
exception.expect(VimDriverException.class);
openstackClient.listFlavors(vimInstance);
}
示例10: buildContext
import org.jclouds.ContextBuilder; //导入依赖的package包/类
public static ContextBuilder buildContext(NovaCredentials credentials) {
Properties properties = new Properties();
properties.setProperty(NovaProperties.AUTO_ALLOCATE_FLOATING_IPS, "true");
Iterable<Module> modules = ImmutableSet.<Module>of(
new SshjSshClientModule(),
new SLF4JLoggingModule(),
new EnterpriseConfigurationModule());
ContextBuilder build = ContextBuilder.newBuilder("aws-ec2")
.credentials(credentials.getAccountName(), credentials.getAccountPass())
.endpoint(credentials.getEndpoint())
.modules(modules)
.overrides(properties);
return build;
}
示例11: OSConnection
import org.jclouds.ContextBuilder; //导入依赖的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();
}
示例12: setUp
import org.jclouds.ContextBuilder; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
containerName = createRandomContainerName();
nearContext = ContextBuilder
.newBuilder("transient")
.credentials("identity", "credential")
.modules(ImmutableList.<Module>of(new SLF4JLoggingModule()))
.build(BlobStoreContext.class);
nearBlobStore = nearContext.getBlobStore();
nearBlobStore.createContainerInLocation(null, containerName);
farContext = ContextBuilder
.newBuilder("transient")
.credentials("identity", "credential")
.modules(ImmutableList.<Module>of(new SLF4JLoggingModule()))
.build(BlobStoreContext.class);
farBlobStore = farContext.getBlobStore();
farBlobStore.createContainerInLocation(null, containerName);
executorService = Executors.newScheduledThreadPool(1);
eventualBlobStore = EventualBlobStore.newEventualBlobStore(
nearBlobStore, farBlobStore, executorService, DELAY,
DELAY_UNIT, 1.0);
}
示例13: novaApi
import org.jclouds.ContextBuilder; //导入依赖的package包/类
@Bean
@ConditionalOnProperty("openstack.endpoint")
NovaApi novaApi(@Value("${openstack.endpoint}") String endpoint,
@Value("${openstack.tenant}") String tenant,
@Value("${openstack.username}") String username,
@Value("${openstack.password}") String password) {
String identity = String.format("%s:%s", tenant, username);
// see https://issues.apache.org/jira/browse/JCLOUDS-816
Properties overrides = new Properties();
overrides.put(Constants.PROPERTY_TRUST_ALL_CERTS, "true");
overrides.put(Constants.PROPERTY_RELAX_HOSTNAME, "true");
return ContextBuilder.newBuilder("openstack-nova")
.endpoint(endpoint)
.credentials(identity, password)
.modules(Collections.singleton(new SLF4JLoggingModule()))
.overrides(overrides)
.buildApi(NovaApi.class);
}
示例14: addProviderFromConfig
import org.jclouds.ContextBuilder; //导入依赖的package包/类
private void addProviderFromConfig(String prefix, String provider) {
String id = prefix.substring(prefix.lastIndexOf('.')).substring(1);
logger.info("adding provider from {} id: {}", prefix, id);
Configuration c = config.subset(prefix);
BlobStoreContext context;
try {
ContextBuilder builder = ContextBuilder.newBuilder(provider);
String identity = c.getString(Constants.PROPERTY_IDENTITY);
if (identity != null) {
builder.credentials(identity, c.getString(Constants.PROPERTY_CREDENTIAL));
}
c.addProperty(Constants.PROPERTY_STRIP_EXPECT_HEADER, "true");
context = builder.overrides(new ConfigurationPropertiesView(c))
.modules(ImmutableList.of(new SLF4JLoggingModule()))
.build(BlobStoreContext.class);
logger.info("added provider {} id {}", context.unwrap().getId(), id);
} catch (CreationException e) {
e.printStackTrace();
throw propagate(e);
}
BlobStore blobStore = new LoggingBlobStore(context.getBlobStore(), id, this);
providers.put(Integer.valueOf(id), blobStore);
}
示例15: testS3ProxyStartup
import org.jclouds.ContextBuilder; //导入依赖的package包/类
@Test
public void testS3ProxyStartup() throws Exception {
initializeDefaultProperties();
startApp();
String identity = app.getConfiguration().getString(S3ProxyConstants.PROPERTY_IDENTITY);
String credential = app.getConfiguration().getString(S3ProxyConstants.PROPERTY_CREDENTIAL);
configureBlobStore(identity, credential);
BlobStoreContext context = ContextBuilder.newBuilder("s3")
.endpoint("http://127.0.0.1:" + app.getS3ProxyPort())
.credentials(app.getConfiguration().getString(S3ProxyConstants.PROPERTY_IDENTITY),
app.getConfiguration().getString(S3ProxyConstants.PROPERTY_CREDENTIAL))
.build(BlobStoreContext.class);
BlobStore blobStore = context.getBlobStore();
PageSet<? extends StorageMetadata> res = blobStore.list();
assertThat(res).isEmpty();
}