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


Java StopInstancesRequest.setInstanceIds方法代码示例

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


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

示例1: stopInstance

import com.amazonaws.services.ec2.model.StopInstancesRequest; //导入方法依赖的package包/类
StopInstancesResult stopInstance(InstanceRequest instanceRequest, Context context) {
	AmazonEC2Async client = createEC2Client();
	try {
		StopInstancesRequest req = new StopInstancesRequest();
		req.setInstanceIds(Arrays.asList(instanceRequest.getInstanceId()));
		Future<StopInstancesResult> result = client.stopInstancesAsync(req);
		while (!result.isDone()) {
			Thread.sleep(100);
		}
		return result.get();

	} catch (Exception e) {
		throw new RuntimeException("unexpected error has occured in the stop instance request.", e);
	} finally {
		client.shutdown();
	}
}
 
开发者ID:uzresk,项目名称:aws-auto-operations-using-lambda,代码行数:18,代码来源:InstanceStopFunction.java

示例2: stopInstance

import com.amazonaws.services.ec2.model.StopInstancesRequest; //导入方法依赖的package包/类
public void stopInstance(AmazonEC2Client ec2Client, String instanceId) throws Exception {
	StopInstancesRequest stopReq = new StopInstancesRequest();
	List<String> instanceIds = new ArrayList<String>();
	instanceIds.add(instanceId);
	stopReq.setInstanceIds(instanceIds);
	logger.debug("Stopping EC2 instance...." + Arrays.toString(instanceIds.toArray(new String[]{})));
	ec2Client.stopInstances(stopReq);
}
 
开发者ID:bitsofinfo,项目名称:s3-bucket-loader,代码行数:9,代码来源:Ec2Util.java

示例3: instanceStop

import com.amazonaws.services.ec2.model.StopInstancesRequest; //导入方法依赖的package包/类
/**
 * http://shlomoswidler.com/2009/07/ec2-instance-life-cycle.html
 */
public void instanceStop(final String instanceId) throws Exception {

	final Instance instance = findInstance(instanceId);

	final InstanceStateName state = stateFrom(instance);

	logger.info("stop: current state=" + state);

	switch (state) {
	case Pending:
		waitForIstanceState(instanceId, InstanceStateName.Running);
	case Running:
		break;
	case Stopping:
		waitForIstanceState(instanceId, InstanceStateName.Stopped);
	case Stopped:
	case Terminated:
	case ShuttingDown:
		return;
	default:
		throw new IllegalStateException("start: unknown state");
	}

	final StopInstancesRequest request = new StopInstancesRequest();
	request.setInstanceIds(wrapList(instanceId));

	final StopInstancesResult result = amazonClient.stopInstances(request);

	waitForIstanceState(instanceId, InstanceStateName.Stopped);

}
 
开发者ID:jwrapper,项目名称:jwrapper-maven-plugin,代码行数:35,代码来源:CarrotElasticCompute.java

示例4: stopInstances

import com.amazonaws.services.ec2.model.StopInstancesRequest; //导入方法依赖的package包/类
/**
 * Stop instances.
 *
 * @param instanceIds
 *            instances' IDs
 * @return list of instances change
 */
protected final List<InstanceStateChange> stopInstances(
        final Collection<String> instanceIds) {
    log.info("Stop instances:" + toString(instanceIds));
    StopInstancesRequest request = new StopInstancesRequest();
    request.setInstanceIds(instanceIds);
    StopInstancesResult result = amazonEC2Client.stopInstances(request);
    return result.getStoppingInstances();
}
 
开发者ID:treelogic-swe,项目名称:aws-mock,代码行数:16,代码来源:BaseTest.java

示例5: StopServer

import com.amazonaws.services.ec2.model.StopInstancesRequest; //导入方法依赖的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.model.StopInstancesRequest.setInstanceIds方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。