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


Java ComputeServiceContext.close方法代码示例

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


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

示例1: main

import org.jclouds.compute.ComputeServiceContext; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException, RunNodesException {
   // Get a context with docker that offers the portable ComputeService api
   ComputeServiceContext client = Utils.getComputeApiFromCarinaDirectory(args[0]);

   // Carina does not allow privileged mode containers
   DockerTemplateOptions dto = new DockerTemplateOptions();
   dto.privileged(false);

   // Use a known sshd image for demonstration purposes: sickp/apline-sshd
   Template template = client.getComputeService()
         .templateBuilder()
         .options(dto)
         .imageNameMatches("sickp/alpine-sshd")
         .build();

   // Run a couple nodes accessible via group container
   Set<? extends NodeMetadata> nodes = client.getComputeService().createNodesInGroup("jcloudscontainertest", 2, template);

   // Show the nodes
   for(NodeMetadata node : nodes) {
      System.out.println("Node: " + node.getName());
   }

   // Cleanup
   client.getComputeService().destroyNodesMatching(runningInGroup("jcloudscontainertest"));

   // Release resources
   client.close();
}
 
开发者ID:jclouds,项目名称:jclouds-examples,代码行数:30,代码来源:CreateComputeContainer.java

示例2: main

import org.jclouds.compute.ComputeServiceContext; //导入方法依赖的package包/类
public static void main(String[] args) {

      if (args.length < PARAMETERS) {
         throw new IllegalArgumentException(INVALID_SYNTAX);
      }

      // Arguments
      String accessKeyId = args[0];
      String secretKey = args[1];

      ComputeServiceContext awsEC2Context = null;
      RestContext<CloudWatchClient, CloudWatchAsyncClient> cloudWatchContext = null;

      try {
         cloudWatchContext = ContextBuilder.newBuilder(new AWSCloudWatchProviderMetadata())
                                           .credentials(accessKeyId, secretKey)
                                           .build();
         awsEC2Context = ContextBuilder.newBuilder(new AWSEC2ProviderMetadata())
                                       .credentials(accessKeyId, secretKey)
                                       .build(ComputeServiceContext.class);

         // Get all nodes
         Set<? extends ComputeMetadata> allNodes = awsEC2Context.getComputeService().listNodes();

         for (ComputeMetadata node : allNodes) {
            String nodeId = node.getProviderId();
            String region = getRegion(node.getLocation());
            MetricClient metricClient = cloudWatchContext.getApi().getMetricClientForRegion(region);
            int metricsCount = getMetricsCountForInstance(cloudWatchContext.getApi(), region, nodeId);
            double[] cpuUtilization = getCPUUtilizationStatsForInstanceOverTheLast24Hours(metricClient, nodeId);
            String cpuUtilizationHeader = "  CPU utilization statistics: ";
            DecimalFormat df = new DecimalFormat("#.##");

            System.out.println(nodeId + " CloudWatch Metrics (Past 24 hours)");
            System.out.println("  Total metrics stored: " + metricsCount);

            if (cpuUtilization == null) {
               System.out.println(cpuUtilizationHeader + "Unable to compute as there are no CPU utilization " +
                                        "metrics stored.");
            } else {
               System.out.println(cpuUtilizationHeader +
                                        df.format(cpuUtilization[0]) + "% (avg), " +
                                        df.format(cpuUtilization[1]) + "% (max), " +
                                        df.format(cpuUtilization[2]) + "% (min)");
            }
         }
      } finally {
         if (awsEC2Context != null) {
            awsEC2Context.close();
         }
         if (cloudWatchContext != null) {
            cloudWatchContext.close();
         }
      }

   }
 
开发者ID:jclouds,项目名称:jclouds-examples,代码行数:57,代码来源:MainApp.java


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