【发布时间】:2015-08-06 18:59:04
【问题描述】:
我想在谷歌计算引擎上启动/恢复和停止/暂停实例,但它给出“java.lang.UnsupportedOperationException”。有没有其他方法 执行这些操作?
public class Example {
public static void main(String[] args)
{
String provider = "google-compute-engine";
String identity = "****@developer.gserviceaccount.com";
String credential = "path to private key";
String groupName = "newgroup";
credential = getCredentialFromJsonKeyFile(credential);
Iterable<Module> modules = ImmutableSet.<Module> of(
new SshjSshClientModule(),
new SLF4JLoggingModule(),
new EnterpriseConfigurationModule());
ContextBuilder builder = ContextBuilder.newBuilder(provider)
.credentials(identity, credential)
.modules(modules);
ComputeService compute=builder.buildView(ComputeServiceContext.class).getComputeService();
compute.suspendNode("Instance id");
//compute.suspendNodesMatching(Predicates.<NodeMetadata> and(inGroup(groupName)));
System.out.println("suspended");
compute.getContext().close();
}
private static String getCredentialFromJsonKeyFile(String filename) {
try {
String fileContents = Files.toString(new File(filename), UTF_8);
Supplier<Credentials> credentialSupplier = new GoogleCredentialsFromJson(fileContents);
String credential = credentialSupplier.get().credential;
return credential;
} catch (IOException e) {
System.err.println("Exception reading private key from '%s': " + filename);
e.printStackTrace();
System.exit(1);
return null;
}
}
}
输出:
暂停节点(节点id)
线程“main”java.lang.UnsupportedOperationException 中的异常:GCE 不支持挂起
在 org.jclouds.googlecomputeengine.compute.GoogleComputeEngineServiceAdapter.suspendNode(GoogleComputeEngineServiceAdapter.java:251)
在 org.jclouds.compute.strategy.impl.AdaptingComputeServiceStrategies.suspendNode(AdaptingComputeServiceStrategies.java:171)
在 org.jclouds.compute.internal.BaseComputeService.suspendNode(BaseComputeService.java:503)
在 org.jclouds.examples.compute.basics.Example.main(Example.java:79)
【问题讨论】:
-
我的回答对你的问题有用吗?
标签: google-compute-engine google-cloud-platform jclouds