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


Java ComputeService类代码示例

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


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

示例1: setUpClass

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

示例2: test

import org.jclouds.compute.ComputeService; //导入依赖的package包/类
@Test
public void test() {
    CloudProperties.getInstance().reset().load(this.getClass());
    try (DockerCloudProvider cloudProvider = (DockerCloudProvider) CloudProvider.create("provider0")) {
        final ComputeService computeService = cloudProvider.getComputeServiceContext().getComputeService();
        assertTrue("No node-group should be 'node-leak-test' before test", computeService.listNodes().stream()
                .noneMatch(cm -> "node-leak-test".equals(((NodeMetadata) cm).getGroup())));
        try {
            cloudProvider.createNode("node0").close();
            Assert.fail("Port 2468 was unexpectedly opened");
        } catch (PortOpeningException e) {
            assertTrue("No node-group should be 'node-leak-test' after test", computeService.listNodes().stream()
                    .noneMatch(cm -> "node-leak-test".equals(((NodeMetadata) cm).getGroup())));
        }
    }
}
 
开发者ID:wildfly-extras,项目名称:sunstone,代码行数:17,代码来源:NodeLeakOnBadPortsTest.java

示例3: configure

import org.jclouds.compute.ComputeService; //导入依赖的package包/类
@Override
protected void configure() {
    super.configure();
    bind(new TypeLiteral<ComputeServiceAdapter<ServerWithExternalIp, OsImage, OsImage, Datacenter>>() {
    }).to(DimensionDataCloudControllerComputeServiceAdapter.class);
    bind(ComputeService.class).to(DimensionDataCloudControllerComputeService.class);

    bind(new TypeLiteral<Function<ServerWithExternalIp, NodeMetadata>>() {
    }).to(ServerWithNatRuleToNodeMetadata.class);
    bind(new TypeLiteral<Function<OsImage, Image>>() {
    }).to(OsImageToImage.class);
    bind(new TypeLiteral<Function<OsImage, Hardware>>() {
    }).to(OsImageToHardware.class);
    bind(new TypeLiteral<Function<Datacenter, Location>>() {
    }).to(DatacenterToLocation.class);
    bind(TemplateOptions.class).to(DimensionDataCloudControllerTemplateOptions.class);
    bind(CreateNodesInGroupThenAddToSet.class).to(GetOrCreateNetworkDomainThenCreateNodes.class);
    bind(PrioritizeCredentialsFromTemplate.class).to(UseNodeCredentialsButOverrideFromTemplate.class);

    // to have the compute service adapter override default locations
    install(new LocationsFromComputeServiceAdapterModule<ServerWithExternalIp, OsImage, OsImage, Datacenter>() {
    });
}
 
开发者ID:cloudsoft,项目名称:amp-dimensiondata,代码行数:24,代码来源:DimensionDataCloudControllerComputeServiceContextModule.java

示例4: listNodesWhereImageDoesntExist

import org.jclouds.compute.ComputeService; //导入依赖的package包/类
public void listNodesWhereImageDoesntExist() throws Exception {
   enqueueRegions(DEFAULT_REGION);
   enqueueXml(DEFAULT_REGION, "/describe_instances_running-1.xml");
   enqueueXml(DEFAULT_REGION, "/availabilityZones.xml");
   enqueue(DEFAULT_REGION, new MockResponse().setBody("<DescribeImagesResponse><imagesSet></imagesSet></DescribeImagesResponse>"));
   enqueue(DEFAULT_REGION, new MockResponse().setBody("<DescribeSpotInstanceRequestsResponse><spotInstanceRequestSet></spotInstanceRequestSet></DescribeSpotInstanceRequestsResponse>"));

   ComputeService computeService = computeService();

   NodeMetadata node = Iterables.getOnlyElement(computeService.listNodesDetailsMatching(NodePredicates.all()));
   assertEquals(node.getId(), "us-east-1/i-2baa5550");

   assertPosted(DEFAULT_REGION, "Action=DescribeRegions");
   assertPosted(DEFAULT_REGION, "Action=DescribeInstances");
   assertPosted(DEFAULT_REGION, "Action=DescribeAvailabilityZones");
   assertPosted(DEFAULT_REGION, "Action=DescribeImages&ImageId.1=ami-aecd60c7");
   assertPosted(DEFAULT_REGION, "Action=DescribeSpotInstanceRequests");
}
 
开发者ID:apache,项目名称:stratos,代码行数:19,代码来源:AWSEC2ComputeServiceApiMockTest.java

示例5: buildDefaultComputeService

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

示例6: runScriptOnGroup

import org.jclouds.compute.ComputeService; //导入依赖的package包/类
private static void runScriptOnGroup(final ComputeService compute,
                                     final LoginCredentials login, final String groupName, final Statement command)
        throws RunScriptOnNodesException {
    // when you run commands, you can pass options to decide whether
    // to run it as root, supply or own credentials vs from cache,
    // and wrap in an init script vs directly invoke
    Map<? extends NodeMetadata, ExecResponse> execResponses =
            compute.runScriptOnNodesMatching(//
                    inGroup(groupName), // predicate used to select nodes
                    command, // what you actually intend to run
                    overrideLoginCredentials(login)); // use the local user & ssh key

    for (Entry<? extends NodeMetadata, ExecResponse> response : execResponses.entrySet()) {
        System.out.printf(
                "<< node %s: %s%n",
                response.getKey().getId(),
                concat(response.getKey().getPrivateAddresses(), response.getKey()
                        .getPublicAddresses())
        );
        System.out.printf("<<     %s%n", response.getValue());
    }
}
 
开发者ID:jclouds,项目名称:jclouds-examples,代码行数:23,代码来源:MainApp.java

示例7: initComputeService

import org.jclouds.compute.ComputeService; //导入依赖的package包/类
private static ComputeService initComputeService(final String provider, final String identity,
                                                 final String credential) {
    // example of specific properties, in this case optimizing image list to
    // only amazon supplied
    Properties properties = new Properties();
    long scriptTimeout = TimeUnit.MILLISECONDS.convert(20, TimeUnit.MINUTES);
    properties.setProperty(TIMEOUT_SCRIPT_COMPLETE, scriptTimeout + "");

    // example of injecting a ssh implementation
    Iterable<Module> modules =
            ImmutableSet.<Module>of(new SshjSshClientModule(), new SLF4JLoggingModule(),
                    new EnterpriseConfigurationModule());

    ContextBuilder builder =
            ContextBuilder.newBuilder(provider).credentials(identity, credential).modules(modules)
                    .overrides(properties);

    System.out.printf(">> initializing %s%n", builder.getApiMetadata());

    return builder.buildView(ComputeServiceContext.class).getComputeService();
}
 
开发者ID:jclouds,项目名称:jclouds-examples,代码行数:22,代码来源:MainApp.java

示例8: ECSComputeServiceContextImpl

import org.jclouds.compute.ComputeService; //导入依赖的package包/类
@Inject
public ECSComputeServiceContextImpl(
      @Provider Context backend,
      @Provider TypeToken<? extends Context> backendType,
      ComputeService computeService,
      Utils utils) {
   super(backend, backendType, computeService, utils);
}
 
开发者ID:aliyun-beta,项目名称:aliyun-jclouds,代码行数:9,代码来源:ECSComputeServiceContextImpl.java

示例9: configure

import org.jclouds.compute.ComputeService; //导入依赖的package包/类
@Override
protected void configure() {
   super.configure();
   bind(ECSApi.class).to(ECSApiImpl.class);
   bind(ComputeService.class).to(ECSComputeService.class);
   install(new LocationsFromComputeServiceAdapterModule<NodeMetadata, Hardware, Image, Location>() {});
}
 
开发者ID:aliyun-beta,项目名称:aliyun-jclouds,代码行数:8,代码来源:ECSComputeServiceContextModule.java

示例10: destroyNodes

import org.jclouds.compute.ComputeService; //导入依赖的package包/类
private static void destroyNodes(final ComputeServiceContext ctx, final String groupname) {
	// Destroy all workers identified by the given group
	final ComputeService computeService = ctx.getComputeService();
	if (computeService != null) {
		Set<? extends NodeMetadata> destroyed = computeService
				.destroyNodesMatching(
						Predicates.<NodeMetadata> and(not(TERMINATED),
								inGroup(groupname)));
		System.out.printf("<< destroyed nodes %s%n", destroyed);
	}
}
 
开发者ID:tlaplus,项目名称:tlaplus,代码行数:12,代码来源:CloudDistributedTLCJob.java

示例11: build

import org.jclouds.compute.ComputeService; //导入依赖的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;
}
 
开发者ID:hazelcast,项目名称:hazelcast-jclouds,代码行数:45,代码来源:ComputeServiceBuilder.java

示例12: initComputeService

import org.jclouds.compute.ComputeService; //导入依赖的package包/类
public ComputeService initComputeService(String provider, String identity, String credential) {
    Properties properties = new Properties();
    ContextBuilder builder = ContextBuilder.newBuilder(provider)
            .credentials(identity, credential)
            .overrides(properties);
    LOGGER.info(MessageFormat.format(">> initializing Compute Service {0}", builder.getApiMetadata()));
    return builder.buildView(ComputeServiceContext.class).getComputeService();
}
 
开发者ID:hazelcast,项目名称:hazelcast-jclouds,代码行数:9,代码来源:LiveComputeServiceUtil.java

示例13: test_getFilteredNodes_with_group_configured

import org.jclouds.compute.ComputeService; //导入依赖的package包/类
@Test
public void test_getFilteredNodes_with_group_configured() {
    Map<String, Comparable> properties = new HashMap<String, Comparable>();
    String groupUnderTest = "group3";
    properties.put("group", groupUnderTest);
    ComputeServiceBuilder builder = new ComputeServiceBuilder(properties);
    ComputeService mockComputeService = mock(ComputeService.class);
    builder.setComputeService(mockComputeService);

    Set<NodeMetadata> nodes = new HashSet<NodeMetadata>();
    for (int i = 0; i < 5; i++) {
        nodes.add(new NodeMetadataBuilder()
                .id(newSecureUuidString())
                .group("group" + i)
                .status(NodeMetadata.Status.RUNNING)
                .build());
    }
    nodes.add(new NodeMetadataBuilder()
            .id(newSecureUuidString())
            .group(groupUnderTest)
            .status(NodeMetadata.Status.RUNNING)
            .build());
    doReturn(nodes).when(mockComputeService).listNodesDetailsMatching(null);

    Set<NodeMetadata> result = (Set<NodeMetadata>) builder.getFilteredNodes();

    assertEquals(2, result.size());
    for (NodeMetadata node : result) {
        assertEquals(groupUnderTest, node.getGroup());
    }
}
 
开发者ID:hazelcast,项目名称:hazelcast-jclouds,代码行数:32,代码来源:ComputeServiceBuilderTest.java

示例14: test_destroy_calls_computeService_destroy

import org.jclouds.compute.ComputeService; //导入依赖的package包/类
@Test
public void test_destroy_calls_computeService_destroy() {
    ComputeServiceBuilder builder = new ComputeServiceBuilder(new HashMap<String, Comparable>());
    ComputeService mockComputeService = mock(ComputeService.class);
    ComputeServiceContext mockComputeServiceContext = mock(ComputeServiceContext.class);
    builder.setComputeService(mockComputeService);
    doReturn(mockComputeServiceContext).when(mockComputeService).getContext();
    builder.destroy();

    verify(mockComputeServiceContext).close();
}
 
开发者ID:hazelcast,项目名称:hazelcast-jclouds,代码行数:12,代码来源:ComputeServiceBuilderTest.java

示例15: test_compute_service_builder_return_correct_api_class

import org.jclouds.compute.ComputeService; //导入依赖的package包/类
@Test
public void test_compute_service_builder_return_correct_api_class() {
    Map<String, Comparable> properties = new HashMap<String, Comparable>();
    properties.put("provider", "aws-ec2");
    properties.put("identity", "id");
    properties.put("credential", "credential");
    ComputeServiceBuilder builder = new ComputeServiceBuilder(properties);
    ComputeService service = builder.build();

    assertEquals(AWSEC2ComputeService.class, service.getClass());
}
 
开发者ID:hazelcast,项目名称:hazelcast-jclouds,代码行数:12,代码来源:ComputeServiceBuilderTest.java


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