List of usage examples for com.amazonaws.services.ec2.model StartInstancesRequest StartInstancesRequest
public StartInstancesRequest()
From source file:aws.example.ec2.StartStopInstance.java
License:Open Source License
public static void startInstance(String instance_id) { final AmazonEC2 ec2 = AmazonEC2ClientBuilder.defaultClient(); DryRunSupportedRequest<StartInstancesRequest> dry_request = () -> { StartInstancesRequest request = new StartInstancesRequest().withInstanceIds(instance_id); return request.getDryRunRequest(); };//from www.ja va 2 s . c om DryRunResult dry_response = ec2.dryRun(dry_request); if (!dry_response.isSuccessful()) { System.out.printf("Failed dry run to start instance %s", instance_id); throw dry_response.getDryRunResponse(); } StartInstancesRequest request = new StartInstancesRequest().withInstanceIds(instance_id); ec2.startInstances(request); System.out.printf("Successfully started instance %s", instance_id); }
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 a 2s. co m*/ 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:ca.roussil.ec2instancestarter.SimpleEc2Service.java
License:Open Source License
@Override public void startInstance(String ec2InstanceId) throws InterruptedException { Instance instance = getSingleEc2InstanceById(ec2InstanceId); InstanceState state = instance.getState(); // different possible states: pending, running, shutting-down, // terminated, stopping, stopped String stateName = state.getName(); if (stateName.equalsIgnoreCase("pending")) { log.info("startInstance: instance with id= " + ec2InstanceId + " state is pending, no action was taken."); } else if (stateName.equalsIgnoreCase("running")) { log.info("startInstance: instance with id= " + ec2InstanceId + " state is running, no action was taken."); } else if (stateName.equalsIgnoreCase("shutting-down")) { log.info("startInstance: instance with id= " + ec2InstanceId + " state is shutting-down, no action was taken."); // TODO maybe we should wait for the instance to shutdown before // starting it again.. ? } else if (stateName.equalsIgnoreCase("terminated")) { log.info("startInstance: instance with id= " + ec2InstanceId + " state is terminated, no action was taken."); // TODO throw error ? } else if (stateName.equalsIgnoreCase("stopping")) { log.info("startInstance: instance with id= " + ec2InstanceId + " state is stopping, no action was taken."); // TODO maybe we should wait for the instance to stop before // starting it again.. ? what is the difference between // shutting-down and stopping ?? } else if (stateName.equalsIgnoreCase("stopped")) { log.info("startInstance: instance with id= " + ec2InstanceId + " state is stopped, the instance has been asked to start..."); StartInstancesRequest startRequest = new StartInstancesRequest().withInstanceIds(ec2InstanceId); StartInstancesResult startResult = config.getAmazonEC2Client().startInstances(startRequest); List<InstanceStateChange> stateChangeList = startResult.getStartingInstances(); waitForTransitionCompletion(stateChangeList, "running", ec2InstanceId); }/*from w w w .j a v a2 s . c om*/ }
From source file:com.carrotgarden.maven.aws.ecc.CarrotElasticCompute.java
License:BSD License
/** * http://shlomoswidler.com/2009/07/ec2-instance-life-cycle.html *///from w w w . j a va 2 s . c om 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.github.trask.sandbox.ec2.Ec2Service.java
License:Apache License
public Instance startInstance(String instanceId) { StartInstancesRequest startInstancesRequest = new StartInstancesRequest().withInstanceIds(instanceId); logger.debug("startInstance(): calling ec2.startInstances({})", instanceId); ec2.startInstances(startInstancesRequest); return getInstance(instanceId); }
From source file:com.ipcglobal.awscdh.config.ManageEc2.java
License:Apache License
/** * Start all EC2 instances.// w w w . j av a 2s. c om * * @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// w w w. ja va2s. c o m */ public void startInstance(String[] instanceIds) { StartInstancesRequest request = new StartInstancesRequest(); request.setInstanceIds(Arrays.asList(instanceIds)); this.amazonEC2Client.startInstances(request); }
From source file:com.vmware.photon.controller.model.adapters.awsadapter.AWSPowerService.java
License:Open Source License
private void powerOn(AmazonEC2AsyncClient client, ComputePowerRequest pr, BaseAwsContext c) { AWSPowerService powerService = this; OperationContext opContext = OperationContext.getOperationContext(); StartInstancesRequest request = new StartInstancesRequest(); request.withInstanceIds(c.child.id); client.startInstancesAsync(request, new AsyncHandler<StartInstancesRequest, StartInstancesResult>() { @Override// w w w . ja va 2 s. c o m public void onSuccess(StartInstancesRequest request, StartInstancesResult result) { OperationContext.restoreOperationContext(opContext); updateComputeState(pr); } @Override public void onError(Exception e) { OperationContext.restoreOperationContext(opContext); AdapterUtils.sendPatchToTask(powerService, pr.taskReference, ResourceOperationResponse.fail(pr.resourceLink(), e)); } }); }
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); }//from ww w . j a v a 2s . co m }
From source file:com.zotoh.cloudapi.aws.EC2Instance.java
License:Open Source License
@Override public void boot(String server) throws InternalException, CloudException { tstEStrArg("instance-id", server); _svc.getCloud().getEC2().startInstances(new StartInstancesRequest().withInstanceIds(server)); }