Package com.amazonaws.services.ec2.model

Examples of com.amazonaws.services.ec2.model.RequestSpotInstancesRequest


        //==========================================================================//
        //================= 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("0.03");
        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("ami-8c1fece5");
        launchSpecification.setInstanceType("t1.micro");

        // Add the security group to the request.
        ArrayList<String> securityGroups = new ArrayList<String>();
        securityGroups.add("GettingStartedGroup");
        launchSpecification.setSecurityGroups(securityGroups);

        // Add the launch specifications to the request.
        requestRequest.setLaunchSpecification(launchSpecification);

        // Call the RequestSpotInstance API.
        RequestSpotInstancesResult requestResult = ec2.requestSpotInstances(requestRequest);
        List<SpotInstanceRequest> requestResponses = requestResult.getSpotInstanceRequests();
View Full Code Here


        AmazonEC2 ec2 = new AmazonEC2Client(credentials);
        Region usWest2 = Region.getRegion(Regions.US_WEST_2);
        ec2.setRegion(usWest2);

        // Initializes a Spot Instance Request
        RequestSpotInstancesRequest requestRequest = new RequestSpotInstancesRequest();

        //*************************** Required Parameters Settings ************************//
        // Request 1 x t1.micro instance with a bid price of $0.03.
        requestRequest.setSpotPrice("0.03");
        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("ami-8c1fece5");
        launchSpecification.setInstanceType("t1.micro");

        // Add the security group to the request.
        ArrayList<String> securityGroups = new ArrayList<String>();
        securityGroups.add("GettingStartedGroup");
        launchSpecification.setSecurityGroups(securityGroups);

        //*************************** Bid Type Settings ************************//
        // Set the type of the bid to persistent.
        requestRequest.setType("persistent");

        //*************************** Valid From/To Settings ************************//
        // Set the valid start time to be two minutes from now.
        Calendar from = Calendar.getInstance();
        from.add(Calendar.MINUTE, 2);
        requestRequest.setValidFrom(from.getTime());

        // Set the valid end time to be two minutes and two hours from now.
        Calendar until = (Calendar) from.clone();
        until.add(Calendar.HOUR, 2);
        requestRequest.setValidUntil(until.getTime());

        //*************************** Launch Group Settings ************************//
        // Set the launch group.
        requestRequest.setLaunchGroup("ADVANCED-DEMO-LAUNCH-GROUP");

        //*************************** Availability Zone Group Settings ************************//
        // Set the availability zone group.
        requestRequest.setAvailabilityZoneGroup("ADVANCED-DEMO-AZ-GROUP");

        //*************************** Add the block device mapping ************************//

        // Goal: Setup block device mappings to ensure that we will not delete
        // the root partition on termination.

        // 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 availability zone ************************//
        // Setup the availability zone to use. Note we could retrieve the availability
        // zones using the ec2.describeAvailabilityZones() API. For this demo we will just use
        // us-east-1b.
        SpotPlacement placement = new SpotPlacement("us-east-1b");
        launchSpecification.setPlacement(placement);

        //*************************** Add the placement group ************************//
        // Setup the placement group to use with whatever name you desire.
        // For this demo we will just use "ADVANCED-DEMO-PLACEMENT-GROUP".
        // Note: We have commented this out, because we are not leveraging cc1.4xlarge or
        // cg1.4xlarge in this example.
        /*
        SpotPlacement pg = new SpotPlacement();
        pg.setGroupName("ADVANCED-DEMO-PLACEMENT-GROUP");
        launchSpecification.setPlacement(pg);
        */

        //*************************** Add the launch specification ************************//
        // Add the launch specification.
        requestRequest.setLaunchSpecification(launchSpecification);

        //============================================================================================//
        //=========================== Getting the Request ID from the Request ========================//
        //============================================================================================//

View Full Code Here

        AmazonEC2 ec2 = new AmazonEC2Client(credentials);
        Region usWest2 = Region.getRegion(Regions.US_WEST_2);
        ec2.setRegion(usWest2);

        // Initializes a Spot Instance Request
        RequestSpotInstancesRequest requestRequest = new RequestSpotInstancesRequest();

        // Request 1 x t1.micro instance with a bid price of $0.03.
        requestRequest.setSpotPrice("0.03");
        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("ami-8c1fece5");
        launchSpecification.setInstanceType("t1.micro");

        // Add the security group to the request.
        ArrayList<String> securityGroups = new ArrayList<String>();
        securityGroups.add("GettingStartedGroup");
        launchSpecification.setSecurityGroups(securityGroups);

        // Add the launch specifications to the request.
        requestRequest.setLaunchSpecification(launchSpecification);

        //============================================================================================//
        //=========================== Getting the Request ID from the Request ========================//
        //============================================================================================//
View Full Code Here

        //==========================================================================//
        //================= 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();
View Full Code Here

                .withImageId(imageId)
                .withBlockDeviceMappings(blockDeviceMappings)
                .withSecurityGroups(Lists.newArrayList(securityGroupName))
                .withUserData(Base64.encodeBytes(userData.getBytes(Charsets.UTF_8)));

            return new RequestSpotInstancesRequest()
                .withSpotPrice(spotPrice)
                .withLaunchSpecification(ls)
                .withLaunchGroup(businessKey)
                .withInstanceCount(pool.getExpectedSize())
                .withType(SpotInstanceType.OneTime)
View Full Code Here

                LOG.info("The describe call has not returned anything yet, waiting 20s and retrying.");
                Uninterruptibles.sleepUninterruptibly(20, TimeUnit.SECONDS);
            }
        }

        final RequestSpotInstancesRequest request = createSpotInstancesRequest(pool, execution);
        execution.setVariable(ProcessVariables.SPOT_REQUESTS_SENT, true);
        RequestSpotInstancesResult requestResult = client.requestSpotInstances(request);
        List<String> spotInstanceRequestIds = collectSpotInstanceRequestIds(requestResult.getSpotInstanceRequests());

        execution.setVariable(ProcessVariables.SPOT_INSTANCE_REQUEST_IDS, spotInstanceRequestIds);
View Full Code Here

        }

        // Request -> Query string marshalling for RequestSpotInstancesRequest is a little tricky since
        // the query string params follow a different form than the XML responses, so we manually set the parameters here.
        else if (originalRequest instanceof RequestSpotInstancesRequest) {
            RequestSpotInstancesRequest requestSpotInstancesRequest = (RequestSpotInstancesRequest)originalRequest;
            int count = 1;
            for (GroupIdentifier group : requestSpotInstancesRequest.getLaunchSpecification().getAllSecurityGroups()) {
                if (group.getGroupId() != null) {
                    request.addParameter("LaunchSpecification.SecurityGroupId." + count++, group.getGroupId());
                }
            }
View Full Code Here

        }

        // Request -> Query string marshalling for RequestSpotInstancesRequest is a little tricky since
        // the query string params follow a different form than the XML responses, so we manually set the parameters here.
        else if (originalRequest instanceof RequestSpotInstancesRequest) {
            RequestSpotInstancesRequest requestSpotInstancesRequest = (RequestSpotInstancesRequest)originalRequest;

            // Marshall the security groups specified only by name
            int groupNameCount = 1;
            for (String groupName : requestSpotInstancesRequest.getLaunchSpecification().getSecurityGroups()) {
                request.addParameter("LaunchSpecification.SecurityGroup." + groupNameCount++, groupName);
            }

            // Then loop through the GroupIdentifier objects and marshall any specified IDs
            // and any additional group names
            int groupIdCount = 1;
            for (GroupIdentifier group : requestSpotInstancesRequest.getLaunchSpecification().getAllSecurityGroups()) {
                if (group.getGroupId() != null) {
                    request.addParameter("LaunchSpecification.SecurityGroupId." + groupIdCount++, group.getGroupId());
                }

                if (group.getGroupName() != null) {
View Full Code Here

      }

      // Request -> Query string marshalling for RequestSpotInstancesRequest is a little tricky since
      // the query string params follow a different form than the XML responses, so we manually set the parameters here.
      else if (originalRequest instanceof RequestSpotInstancesRequest) {
          RequestSpotInstancesRequest requestSpotInstancesRequest = (RequestSpotInstancesRequest)originalRequest;
          int count = 1;
          for (GroupIdentifier group : requestSpotInstancesRequest.getLaunchSpecification().getAllSecurityGroups()) {
              if (group.getGroupId() != null) {
                  request.addParameter("LaunchSpecification.SecurityGroupId." + count++, group.getGroupId());
              }
          }
View Full Code Here

      }

      // Request -> Query string marshalling for RequestSpotInstancesRequest is a little tricky since
      // the query string params follow a different form than the XML responses, so we manually set the parameters here.
      else if (originalRequest instanceof RequestSpotInstancesRequest) {
          RequestSpotInstancesRequest requestSpotInstancesRequest = (RequestSpotInstancesRequest)originalRequest;
          int count = 1;
          for (GroupIdentifier group : requestSpotInstancesRequest.getLaunchSpecification().getAllSecurityGroups()) {
              if (group.getGroupId() != null) {
                  request.addParameter("LaunchSpecification.SecurityGroupId." + count++, group.getGroupId());
              }
          }
View Full Code Here

TOP

Related Classes of com.amazonaws.services.ec2.model.RequestSpotInstancesRequest

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.