當前位置: 首頁>>代碼示例>>Java>>正文


Java ContextBuilder類代碼示例

本文整理匯總了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);
    }
}
 
開發者ID:hekate-io,項目名稱:hekate,代碼行數:18,代碼來源:CloudSeedNodeProvider.java

示例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);
    }
}
 
開發者ID:hekate-io,項目名稱:hekate,代碼行數:22,代碼來源:AwsCloudSeedNodeProviderTest.java

示例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;
}
 
開發者ID:wildfly-extras,項目名稱:sunstone,代碼行數:26,代碼來源:OpenstackCloudProvider.java

示例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);
}
 
開發者ID:wildfly-extras,項目名稱:sunstone,代碼行數:23,代碼來源:AbstractJCloudsCloudProvider.java

示例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);
}
 
開發者ID:pravega,項目名稱:pravega,代碼行數:25,代碼來源:S3ProxyImpl.java

示例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();
}
 
開發者ID:orange-cloudfoundry,項目名稱:db-dumper-service,代碼行數:21,代碼來源:UploadS3StreamImplTest.java

示例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());
  }
}
 
開發者ID:openbaton,項目名稱:openstack-plugin,代碼行數:20,代碼來源:OpenstackClient.java

示例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());
  }
}
 
開發者ID:openbaton,項目名稱:openstack-plugin,代碼行數:19,代碼來源:OpenstackClient.java

示例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);
}
 
開發者ID:openbaton,項目名稱:openstack-plugin,代碼行數:22,代碼來源:OpenstackTest.java

示例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;
}
 
開發者ID:karamelchef,項目名稱:karamel,代碼行數:17,代碼來源:NovaContext.java

示例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();
}
 
開發者ID:jasonrig,項目名稱:openstack-queue,代碼行數:24,代碼來源:OSConnection.java

示例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);
}
 
開發者ID:gaul,項目名稱:s3proxy,代碼行數:27,代碼來源:EventualBlobStoreTest.java

示例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);
}
 
開發者ID:strepsirrhini-army,項目名稱:chaos-lemur,代碼行數:22,代碼來源:InfrastructureConfiguration.java

示例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);
}
 
開發者ID:bouncestorage,項目名稱:bouncestorage,代碼行數:25,代碼來源:BounceApplication.java

示例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();
}
 
開發者ID:bouncestorage,項目名稱:bouncestorage,代碼行數:18,代碼來源:BounceApplicationTest.java


注:本文中的org.jclouds.ContextBuilder類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。