List of usage examples for com.amazonaws.services.ec2.model StartInstancesRequest setInstanceIds
public void setInstanceIds(java.util.Collection<String> instanceIds)
The IDs of the instances.
From source file:br.unb.cic.bionimbuz.elasticity.legacy.Ec2Commands.java
License:Open Source License
public static void startinstance() throws IOException { Ec2Commands.setup();/* w w w . j av a2 s .c om*/ try { System.out.println("#3 Start the Instance"); System.out.println("Enter the instance id"); instanceid = user_input.next(); //start instance List<String> instancesToStart = new ArrayList<String>(); instancesToStart.add(instanceid); StartInstancesRequest startr = new StartInstancesRequest(); startr.setInstanceIds(instancesToStart); EC2.startInstances(startr); System.out.println("Starting instance " + instanceid); try { Thread.sleep(3000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println(); System.out.println("Restarting the application"); System.out.println(); // Ec2Commands.enteroption(); } catch (Exception e) { System.out.println("Give a valid input"); System.out.println(""); // Ec2Commands.enteroption(); } }
From source file:com.carrotgarden.maven.aws.ecc.CarrotElasticCompute.java
License:BSD License
/** * http://shlomoswidler.com/2009/07/ec2-instance-life-cycle.html */// w ww . ja v a 2s .c o m 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); }
From source file:com.ipcglobal.awscdh.config.ManageEc2.java
License:Apache License
/** * Start all EC2 instances.//w w w. j a v a 2s .co m * * @param instances the instances * @throws Exception the exception */ public void startAllInstances(List<Instance> instances) throws Exception { List<String> startInstanceIds = new ArrayList<String>(); for (Instance instance : instances) { if ("stopped".equals(instance.getState().getName())) startInstanceIds.add(instance.getInstanceId()); else if ("running".equals(instance.getState().getName())) ; else throw new Exception("Can't start instance " + instance.getInstanceId() + " while in state: " + instance.getState().getName()); } if (startInstanceIds.size() > 0) { log.info("Initiating Start for " + startInstanceIds.size() + " instances"); // Had strange issues trying to start all instances at once, no error messages but not all instances started // so do one at a time for (String startInstanceId : startInstanceIds) { StartInstancesRequest startInstancesRequest = new StartInstancesRequest(); startInstancesRequest.setInstanceIds(Arrays.asList(startInstanceId)); StartInstancesResult startInstancesResult = ec2Client.startInstances(startInstancesRequest); // log.info( "startInstancesResult: " + startInstancesResult ); } log.info("Sleeping for 1 minute after Start initiated"); Thread.sleep(1 * 60000L); long before = System.currentTimeMillis(); log.info("Verifying Instances Running - Begin"); verifyInstancesRunning(instances); log.info("Verifying Instances Running - Complete, elapsed=" + Utils.convertMSecsToHMmSs(System.currentTimeMillis() - before)); } else { log.info("Nothing to start, all instances already running"); } }
From source file:com.stfciz.aws.ec2.data.EC2InstancesManager.java
/** * * @param instanceIds//from w w w . j a v a 2 s.co m */ public void startInstance(String[] instanceIds) { StartInstancesRequest request = new StartInstancesRequest(); request.setInstanceIds(Arrays.asList(instanceIds)); this.amazonEC2Client.startInstances(request); }
From source file:com.yosanai.java.aws.console.DefaultAWSConnectionProvider.java
License:Open Source License
@Override public void startInstances(String... instanceIds) throws Exception { List<String> instanceIdsFiltered = getInstances(STATE_STOPPED, true, instanceIds); if (!instanceIdsFiltered.isEmpty()) { StartInstancesRequest startInstancesRequest = new StartInstancesRequest(); startInstancesRequest.setInstanceIds(instanceIdsFiltered); getConnection().startInstances(startInstancesRequest); }/*w ww . j ava2 s .c o m*/ }
From source file:jp.aws.test.ec2.EC2Instance.java
License:Apache License
/** * ?//from w ww .java2 s . c o m * * @throws Exception */ public void start(String instanceId) { ArrayList<String> instanceIds = new ArrayList<String>(); instanceIds.add(instanceId); StartInstancesRequest startInstancesRequest = new StartInstancesRequest(); startInstancesRequest.setInstanceIds(instanceIds); clientManager.ec2().startInstances(startInstancesRequest); }