List of usage examples for com.amazonaws.services.ec2.model StopInstancesRequest StopInstancesRequest
public StopInstancesRequest()
From source file:au.edu.unsw.cse.soc.federatedcloud.deployers.aws.ec2.redmine.RedmineEC2DeploymentWrapper.java
License:Open Source License
@Override public void undeployResource(String resourceID) throws Exception { //Reading the credentials Properties properties = new Properties(); properties.load(this.getClass().getResourceAsStream("/AwsCredentials.properties")); String accessKey = properties.getProperty("accessKey"); String secretKey = properties.getProperty("secretKey-NULL"); AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey); AmazonEC2Client client = new AmazonEC2Client(credentials); StopInstancesRequest request = new StopInstancesRequest(); List<String> idList = new ArrayList<String>(); idList.add(resourceID);/* w ww .j a v a2 s .c om*/ request.setInstanceIds(idList); StopInstancesResult result = client.stopInstances(request); }
From source file:aws.example.ec2.StartStopInstance.java
License:Open Source License
public static void stopInstance(String instance_id) { final AmazonEC2 ec2 = AmazonEC2ClientBuilder.defaultClient(); DryRunSupportedRequest<StopInstancesRequest> dry_request = () -> { StopInstancesRequest request = new StopInstancesRequest().withInstanceIds(instance_id); return request.getDryRunRequest(); };//from w ww.j a va 2 s . c om DryRunResult dry_response = ec2.dryRun(dry_request); if (!dry_response.isSuccessful()) { System.out.printf("Failed dry run to stop instance %s", instance_id); throw dry_response.getDryRunResponse(); } StopInstancesRequest request = new StopInstancesRequest().withInstanceIds(instance_id); ec2.stopInstances(request); System.out.printf("Successfully stop instance %s", instance_id); }
From source file:br.unb.cic.bionimbuz.elasticity.legacy.Ec2Commands.java
License:Open Source License
public static void stopinstance() throws IOException { Ec2Commands.setup();/*from w w w . jav a 2s .c om*/ try { System.out.println("#4 Stop the Instance"); System.out.println("Enter the instance id"); instanceid = user_input.next(); //stop instance StopInstancesRequest sireq = new StopInstancesRequest().withInstanceIds(instanceid); StopInstancesResult sires = EC2.stopInstances(sireq); System.out.println("Stopping 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 w w .ja v a 2s . c om 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); }
From source file:com.ipcglobal.awscdh.config.ManageEc2.java
License:Apache License
/** * Stop all EC2 instances.//from w w w . j a va2s .c o m * * @param instances the instances * @throws Exception the exception */ public void stopAllInstances(List<Instance> instances) throws Exception { List<String> instanceIds = new ArrayList<String>(); for (Instance instance : instances) instanceIds.add(instance.getInstanceId()); log.info("Initiating Stop for " + instanceIds.size() + " instances"); StopInstancesRequest stopInstancesRequest = new StopInstancesRequest(); stopInstancesRequest.setInstanceIds(instanceIds); StopInstancesResult stopInstancesResult = ec2Client.stopInstances(stopInstancesRequest); log.info("stopInstancesResult: " + stopInstancesResult); log.info("Sleeping for 1 minute after Stop initiated"); Thread.sleep(1 * 60000L); long before = System.currentTimeMillis(); log.info("Verifying Instances Stopped - Begin"); verifyInstancesStopped(instances); log.info("Verifying Instances Stopped - Complete, elapsed=" + Utils.convertMSecsToHMmSs(System.currentTimeMillis() - before)); }
From source file:com.stfciz.aws.ec2.data.EC2InstancesManager.java
/** * * @param instanceIds//from w ww. ja v a2 s.c o m */ public void stopInstance(String[] instanceIds) { StopInstancesRequest request = new StopInstancesRequest(); request.setInstanceIds(Arrays.asList(instanceIds)); this.amazonEC2Client.stopInstances(request); }
From source file:com.vmware.photon.controller.model.adapters.awsadapter.AWSPowerService.java
License:Open Source License
private void powerOff(AmazonEC2AsyncClient client, ComputePowerRequest pr, BaseAwsContext c) { AWSPowerService powerService = this; OperationContext opContext = OperationContext.getOperationContext(); StopInstancesRequest request = new StopInstancesRequest(); request.withInstanceIds(c.child.id); client.stopInstancesAsync(request, new AsyncHandler<StopInstancesRequest, StopInstancesResult>() { @Override/*from w ww .ja va 2 s . c om*/ public void onSuccess(StopInstancesRequest request, StopInstancesResult 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 stopInstances(String... instanceIds) throws Exception { List<String> instanceIdsFiltered = getInstances(STATE_RUNNING, true, instanceIds); if (!instanceIdsFiltered.isEmpty()) { StopInstancesRequest stopInstancesRequest = new StopInstancesRequest(); stopInstancesRequest.setInstanceIds(instanceIdsFiltered); getConnection().stopInstances(stopInstancesRequest); }//w w w . ja v a 2 s .co m }
From source file:com.zotoh.cloudapi.aws.EC2Instance.java
License:Open Source License
@Override public void pause(String server) throws InternalException, CloudException { tstEStrArg("instance-id", server); _svc.getCloud().getEC2().stopInstances(new StopInstancesRequest().withInstanceIds(server)); }
From source file:de.fischer.thotti.ec2.clients.EC2Stopper.java
License:Apache License
private void prepareRequestsPerRegion(EC2RequestData<StopInstancesRequest> requestData, RegionType region) { StopInstancesRequest request = new StopInstancesRequest(); for (InstanceType server : region.getInstances()) { request.withInstanceIds(server.getInstanceID()); }/*from w w w .j a v a2 s .c o m*/ requestData.getRegion(region.getName()).addRequest(request); }