當前位置: 首頁>>代碼示例>>Java>>正文


Java AmazonEC2.stopInstances方法代碼示例

本文整理匯總了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;
}
 
開發者ID:betahikaru,項目名稱:ec2-util,代碼行數:10,代碼來源:AwsEc2Client.java

示例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);
    }
}
 
開發者ID:hudson3-plugins,項目名稱:ec2-plugin,代碼行數:15,代碼來源:EC2AbstractSlave.java

示例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;
				}

}
 
開發者ID:tosca-types,項目名稱:openstack,代碼行數:43,代碼來源:AwsUtilities.java


注:本文中的com.amazonaws.services.ec2.AmazonEC2.stopInstances方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。