List of usage examples for com.amazonaws.services.ec2.model SpotPlacement SpotPlacement
public SpotPlacement()
From source file:advanced.Requests.java
License:Open Source License
/** * The submit method will create 1 x one-time t1.micro request with a maximum bid * price of $0.03 using the Amazon Linux AMI. * /*from ww w .j a va 2s. c om*/ * Note the AMI id may change after the release of this code sample, and it is important * to use the latest. You can find the latest version by logging into the AWS Management * console, and attempting to perform a launch. You will be presented with AMI options, * one of which will be Amazon Linux. Simply use that AMI id. */ public void submitRequests() { //==========================================================================// //================= Submit a Spot Instance Request =====================// //==========================================================================// // Initializes a Spot Instance Request RequestSpotInstancesRequest requestRequest = new RequestSpotInstancesRequest(); // Request 1 x t1.micro instance with a bid price of $0.03. requestRequest.setSpotPrice(bidPrice); requestRequest.setInstanceCount(Integer.valueOf(1)); // Setup the specifications of the launch. This includes the instance type (e.g. t1.micro) // and the latest Amazon Linux AMI id available. Note, you should always use the latest // Amazon Linux AMI id or another of your choosing. LaunchSpecification launchSpecification = new LaunchSpecification(); launchSpecification.setImageId(amiID); launchSpecification.setInstanceType(instanceType); // Add the security group to the request. ArrayList<String> securityGroups = new ArrayList<String>(); securityGroups.add(securityGroup); launchSpecification.setSecurityGroups(securityGroups); // If a placement group has been set, then we will use it in the request. if (placementGroupName != null && !placementGroupName.equals("")) { // Setup the placement group to use with whatever name you desire. SpotPlacement placement = new SpotPlacement(); placement.setGroupName(placementGroupName); launchSpecification.setPlacement(placement); } // Check to see if we need to set the availability zone name. if (availabilityZoneName != null && !availabilityZoneName.equals("")) { // Setup the availability zone to use. Note we could retrieve the availability // zones using the ec2.describeAvailabilityZones() API. SpotPlacement placement = new SpotPlacement(availabilityZoneName); launchSpecification.setPlacement(placement); } if (availabilityZoneGroupName != null && !availabilityZoneGroupName.equals("")) { // Set the availability zone group. requestRequest.setAvailabilityZoneGroup(availabilityZoneGroupName); } // Check to see if we need to set the launch group. if (launchGroupName != null && !launchGroupName.equals("")) { // Set the availability launch group. requestRequest.setLaunchGroup(launchGroupName); } // Check to see if we need to set the valid from option. if (validFrom != null) { requestRequest.setValidFrom(validFrom); } // Check to see if we need to set the valid until option. if (validTo != null) { requestRequest.setValidUntil(validFrom); } // Check to see if we need to set the request type. if (requestType != null && !requestType.equals("")) { // Set the type of the bid. requestRequest.setType(requestType); } // If we should delete the EBS boot partition on termination. if (!deleteOnTermination) { // Create the block device mapping to describe the root partition. BlockDeviceMapping blockDeviceMapping = new BlockDeviceMapping(); blockDeviceMapping.setDeviceName("/dev/sda1"); // Set the delete on termination flag to false. EbsBlockDevice ebs = new EbsBlockDevice(); ebs.setDeleteOnTermination(Boolean.FALSE); blockDeviceMapping.setEbs(ebs); // Add the block device mapping to the block list. ArrayList<BlockDeviceMapping> blockList = new ArrayList<BlockDeviceMapping>(); blockList.add(blockDeviceMapping); // Set the block device mapping configuration in the launch specifications. launchSpecification.setBlockDeviceMappings(blockList); } // Add the launch specifications to the request. requestRequest.setLaunchSpecification(launchSpecification); // Call the RequestSpotInstance API. RequestSpotInstancesResult requestResult = ec2.requestSpotInstances(requestRequest); List<SpotInstanceRequest> requestResponses = requestResult.getSpotInstanceRequests(); // Setup an arraylist to collect all of the request ids we want to watch hit the running // state. spotInstanceRequestIds = new ArrayList<String>(); // Add all of the request ids to the hashset, so we can determine when they hit the // active state. for (SpotInstanceRequest requestResponse : requestResponses) { System.out.println("Created Spot Request: " + requestResponse.getSpotInstanceRequestId()); spotInstanceRequestIds.add(requestResponse.getSpotInstanceRequestId()); } }
From source file:com.norbl.cbp.ppe.Ec2Wrangler.java
License:Open Source License
private void setupClusterPlacementGroup(LaunchSpecification spec) { String clusterName;/* w w w .j a v a2 s. co m*/ if (params.clusterGroupName != null) clusterName = params.clusterGroupName; else clusterName = ConstantsEc2.CLUSTER_GROUP_DEFAULT; createClusterGroupIfNecessary(clusterName); // Placement placement = new Placement(); SpotPlacement placement = new SpotPlacement(); // Placement changed to SpotPlacement migrating from // AWS java sdk 1.1.6 -> 1.3.3 placement.setGroupName(clusterName); spec.setPlacement(placement); // /* D */ System.out.println("Ec2W: setup placement group name=" + // clusterName + " for spot"); }