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