本文整理汇总了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);
}
示例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);
}