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


Java Operation.Error方法代码示例

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


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

示例1: main

import com.google.api.services.compute.model.Operation; //导入方法依赖的package包/类
public static void main(String[] args) {
  try {
    httpTransport = GoogleNetHttpTransport.newTrustedTransport();

    // Authenticate using Google Application Default Credentials.
    GoogleCredential credential = GoogleCredential.getApplicationDefault();
    if (credential.createScopedRequired()) {
      List<String> scopes = new ArrayList<>();
      // Set Google Cloud Storage scope to Full Control.
      scopes.add(ComputeScopes.DEVSTORAGE_FULL_CONTROL);
      // Set Google Compute Engine scope to Read-write.
      scopes.add(ComputeScopes.COMPUTE);
      credential = credential.createScoped(scopes);
    }

    // Create Compute Engine object for listing instances.
    Compute compute =
        new Compute.Builder(httpTransport, JSON_FACTORY, credential)
            .setApplicationName(APPLICATION_NAME)
            .build();

    // List out instances, looking for the one created by this sample app.
    boolean foundOurInstance = printInstances(compute);

    Operation op;
    if (foundOurInstance) {
      op = deleteInstance(compute, SAMPLE_INSTANCE_NAME);
    } else {
      op = startInstance(compute, SAMPLE_INSTANCE_NAME);
    }

    // Call Compute Engine API operation and poll for operation completion status
    System.out.println("Waiting for operation completion...");
    Operation.Error error = blockUntilComplete(compute, op, OPERATION_TIMEOUT_MILLIS);
    if (error == null) {
      System.out.println("Success!");
    } else {
      System.out.println(error.toPrettyString());
    }
  } catch (IOException e) {
    System.err.println(e.getMessage());
  } catch (Throwable t) {
    t.printStackTrace();
  }
  System.exit(1);
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:47,代码来源:ComputeEngineSample.java

示例2: main

import com.google.api.services.compute.model.Operation; //导入方法依赖的package包/类
public static void main(String[] args) {
  try {
    httpTransport = GoogleNetHttpTransport.newTrustedTransport();

    // Authenticate using Google Application Default Credentials.
    GoogleCredential credential = GoogleCredential.getApplicationDefault();
    if (credential.createScopedRequired()) {
      List<String> scopes = new ArrayList<>();
      // Set Google Cloud Storage scope to Full Control.
      scopes.add(ComputeScopes.DEVSTORAGE_FULL_CONTROL);
      // Set Google Compute Engine scope to Read-write.
      scopes.add(ComputeScopes.COMPUTE);
      credential = credential.createScoped(scopes);
    }

    // Create Compute Engine object for listing instances.
    Compute compute = new Compute.Builder(httpTransport, JSON_FACTORY, credential)
      .setApplicationName(APPLICATION_NAME)
      .build();

    // List out instances, looking for the one created by this sample app.
    boolean foundOurInstance = printInstances(compute);

    Operation op;
    if (foundOurInstance) {
      op = deleteInstance(compute, SAMPLE_INSTANCE_NAME);
    } else {
      op = startInstance(compute, SAMPLE_INSTANCE_NAME);
    }

    // Call Compute Engine API operation and poll for operation completion status
    System.out.println("Waiting for operation completion...");
    Operation.Error error = blockUntilComplete(compute, op, OPERATION_TIMEOUT_MILLIS);
    if (error == null) {
      System.out.println("Success!");
    } else {
      System.out.println(error.toPrettyString());
    }
  } catch (IOException e) {
    System.err.println(e.getMessage());
  } catch (Throwable t) {
    t.printStackTrace();
  }
  System.exit(1);
}
 
开发者ID:googlearchive,项目名称:compute-getting-started-java,代码行数:46,代码来源:ComputeEngineSample.java


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