本文整理汇总了Java中com.amazonaws.services.ec2.model.StartInstancesRequest.setInstanceIds方法的典型用法代码示例。如果您正苦于以下问题:Java StartInstancesRequest.setInstanceIds方法的具体用法?Java StartInstancesRequest.setInstanceIds怎么用?Java StartInstancesRequest.setInstanceIds使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.amazonaws.services.ec2.model.StartInstancesRequest
的用法示例。
在下文中一共展示了StartInstancesRequest.setInstanceIds方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: startInstance
import com.amazonaws.services.ec2.model.StartInstancesRequest; //导入方法依赖的package包/类
StartInstancesResult startInstance(InstanceRequest instanceRequest, Context context) {
AmazonEC2Async client = createEC2Client();
try {
StartInstancesRequest req = new StartInstancesRequest();
req.setInstanceIds(Arrays.asList(instanceRequest.getInstanceId()));
Future<StartInstancesResult> result = client.startInstancesAsync(req);
while (!result.isDone()) {
Thread.sleep(100);
}
return result.get();
} catch (Exception e) {
throw new RuntimeException("unexpected error has occured in the start instance request.", e);
} finally {
client.shutdown();
}
}
示例2: startInstance
import com.amazonaws.services.ec2.model.StartInstancesRequest; //导入方法依赖的package包/类
public void startInstance(AmazonEC2Client ec2Client, String instanceId) throws Exception {
StartInstancesRequest startReq = new StartInstancesRequest();
List<String> instanceIds = new ArrayList<String>();
instanceIds.add(instanceId);
startReq.setInstanceIds(instanceIds);
logger.debug("Starting EC2 instance...." + Arrays.toString(instanceIds.toArray(new String[]{})));
ec2Client.startInstances(startReq);
}
示例3: instanceStart
import com.amazonaws.services.ec2.model.StartInstancesRequest; //导入方法依赖的package包/类
/**
* http://shlomoswidler.com/2009/07/ec2-instance-life-cycle.html
*/
public void instanceStart(final String instanceId) throws Exception {
final Instance instance = findInstance(instanceId);
final InstanceStateName state = stateFrom(instance);
logger.info("start: current state=" + state);
switch (state) {
case Running:
return;
case Pending:
waitForIstanceState(instanceId, InstanceStateName.Running);
return;
case Stopped:
break;
case Stopping:
waitForIstanceState(instanceId, InstanceStateName.Stopped);
break;
case ShuttingDown:
case Terminated:
throw new IllegalStateException("start: dead instance");
default:
throw new IllegalStateException("start: unknown state");
}
final StartInstancesRequest request = new StartInstancesRequest();
request.setInstanceIds(wrapList(instanceId));
final StartInstancesResult result = amazonClient
.startInstances(request);
waitForIstanceState(instanceId, InstanceStateName.Running);
}
示例4: startInstances
import com.amazonaws.services.ec2.model.StartInstancesRequest; //导入方法依赖的package包/类
/**
* Start instances.
*
* @param instanceIds
* instances' IDs
* @return list of instances change
*/
protected final List<InstanceStateChange> startInstances(
final Collection<String> instanceIds) {
log.info("Start instances:" + toString(instanceIds));
StartInstancesRequest request = new StartInstancesRequest();
request.setInstanceIds(instanceIds);
StartInstancesResult result = amazonEC2Client.startInstances(request);
return result.getStartingInstances();
}
示例5: StartServer
import com.amazonaws.services.ec2.model.StartInstancesRequest; //导入方法依赖的package包/类
public static void StartServer(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);
StartInstancesRequest req = new StartInstancesRequest();
ArrayList<String> list = new ArrayList<String>();
list.add(serverId);
req.setInstanceIds(list);
System.out.println("Starting Instance " + serverId);
ec2.startInstances(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;
}
}