本文整理匯總了Java中com.amazonaws.services.ec2.AmazonEC2.stopInstances方法的典型用法代碼示例。如果您正苦於以下問題:Java AmazonEC2.stopInstances方法的具體用法?Java AmazonEC2.stopInstances怎麽用?Java AmazonEC2.stopInstances使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.amazonaws.services.ec2.AmazonEC2
的用法示例。
在下文中一共展示了AmazonEC2.stopInstances方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: stopInstance
import com.amazonaws.services.ec2.AmazonEC2; //導入方法依賴的package包/類
public static InstanceStateChange stopInstance(AmazonEC2 ec2, String instanceId) {
StopInstancesRequest stopInstancesRequest = new StopInstancesRequest().withInstanceIds(instanceId);
StopInstancesResult stopInstancesResult = ec2.stopInstances(stopInstancesRequest);
List<InstanceStateChange> instanceStateChange = stopInstancesResult.getStoppingInstances();
for (InstanceStateChange stateChange : instanceStateChange) {
return stateChange;
}
return null;
}
示例2: stop
import com.amazonaws.services.ec2.AmazonEC2; //導入方法依賴的package包/類
void stop() {
try {
AmazonEC2 ec2 = getCloud().connect();
StopInstancesRequest request = new StopInstancesRequest(
Collections.singletonList(getInstanceId()));
LOGGER.fine("Sending stop request for " + getInstanceId());
ec2.stopInstances(request);
LOGGER.info("EC2 instance stop request sent for " + getInstanceId());
toComputer().disconnect(null);
} catch (AmazonClientException e) {
Instance i = getInstance(getInstanceId(), getCloud());
LOGGER.log(Level.WARNING, "Failed to stop EC2 instance: " + getInstanceId() + " info: " + ((i != null) ? i : ""), e);
}
}
示例3: StopServer
import com.amazonaws.services.ec2.AmazonEC2; //導入方法依賴的package包/類
public static void StopServer(String keys, JSONObject endpointsAPI, String serverId)
{
String accessKey = keys.split(";")[0];
String secretKey = keys.split(";")[1];
String regionEndpoint = (String) endpointsAPI.get("amazon-regionEndpoint");
try
{
// EC2 Client for given region and credentials
AmazonEC2 ec2 = new AmazonEC2Client(new BasicAWSCredentials(accessKey, secretKey));
ec2.setEndpoint(regionEndpoint);
StopInstancesRequest req = new StopInstancesRequest();
ArrayList<String> list = new ArrayList<String>();
list.add(serverId);
req.setInstanceIds(list);
System.out.println("Stopping Instance " + serverId);
ec2.stopInstances(req);
return;
}
catch (AmazonServiceException ase)
{
System.out.println("Caught an AmazonServiceException, which means your request made it " + "to AWS, but was rejected with an error response for some reason.");
System.out.println("Error Message: " + ase.getMessage());
System.out.println("HTTP Status Code: " + ase.getStatusCode());
System.out.println("AWS Error Code: " + ase.getErrorCode());
System.out.println("Error Type: " + ase.getErrorType());
System.out.println("Request ID: " + ase.getRequestId());
return;
}
catch (AmazonClientException ace)
{
System.out.println("Caught an AmazonClientException, which means the client encountered " + "a serious internal problem while trying to communicate with AWS, " + "such as not being able to access the network.");
System.out.println("Error Message: " + ace.getMessage());
return;
}
}