View Javadoc

1   /**
2    *
3    * Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
4    *
5    * ====================================================================
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   * http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   * ====================================================================
18   */
19  package org.jclouds.aws.ec2.options;
20  
21  import static com.google.common.base.Preconditions.checkNotNull;
22  
23  import java.util.Date;
24  
25  import org.jclouds.date.DateService;
26  import org.jclouds.date.internal.SimpleDateFormatDateService;
27  import org.jclouds.ec2.domain.InstanceType;
28  import org.jclouds.ec2.options.internal.BaseEC2RequestOptions;
29  
30  /**
31   * Contains options supported in the Form API for the DescribeSpotPriceHistory operation. <h2>
32   * Usage</h2> The recommended way to instantiate a DescribeSpotPriceHistoryOptions object is to
33   * statically import DescribeSpotPriceHistoryOptions.Builder.* and invoke a static creation method
34   * followed by an instance mutator (if needed):
35   * <p/>
36   * <code>
37   * import static org.jclouds.aws.ec2.options.DescribeSpotPriceHistoryOptions.Builder.*
38   * <p/>
39   * AWSEC2Client client = // get connection
40   * history = client.getSpotInstanceServices().describeSpotPriceHistoryInRegion(from(yesterday).instanceType("m1.small"));
41   * <code>
42   * 
43   * @author Adrian Cole
44   * @see <a href=
45   *      "http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/index.html?ApiReference-form-DescribeSpotPriceHistory.html"
46   *      />
47   */
48  public class DescribeSpotPriceHistoryOptions extends BaseEC2RequestOptions {
49     public static final DescribeSpotPriceHistoryOptions NONE = new DescribeSpotPriceHistoryOptions();
50     private static final DateService service = new SimpleDateFormatDateService();
51  
52     /**
53      * Start date and time of the Spot Instance price history data.
54      */
55     public DescribeSpotPriceHistoryOptions from(Date start) {
56        formParameters.put("StartTime", service.iso8601DateFormat(checkNotNull(start, "start")));
57        return this;
58     }
59  
60     /**
61      * End date and time of the Spot Instance price history data.
62      */
63     public DescribeSpotPriceHistoryOptions to(Date end) {
64        formParameters.put("EndTime", service.iso8601DateFormat(checkNotNull(end, "end")));
65        return this;
66     }
67  
68     /**
69      * Specifies the instance type to return.
70      */
71     public DescribeSpotPriceHistoryOptions instanceType(String type) {
72        formParameters.put("InstanceType.1", checkNotNull(type, "type"));
73        return this;
74     }
75  
76     /**
77      * The description of the AMI.
78      */
79     public DescribeSpotPriceHistoryOptions productDescription(String description) {
80        formParameters.put("ProductDescription", checkNotNull(description, "description"));
81        return this;
82     }
83  
84     public static class Builder {
85        /**
86         * @see DescribeSpotPriceHistoryOptions#from
87         */
88        public static DescribeSpotPriceHistoryOptions from(Date start) {
89           DescribeSpotPriceHistoryOptions options = new DescribeSpotPriceHistoryOptions();
90           return options.from(start);
91        }
92  
93        /**
94         * @see DescribeSpotPriceHistoryOptions#to
95         */
96        public static DescribeSpotPriceHistoryOptions to(Date end) {
97           DescribeSpotPriceHistoryOptions options = new DescribeSpotPriceHistoryOptions();
98           return options.to(end);
99        }
100 
101       /**
102        * @see DescribeSpotPriceHistoryOptions#instanceType(InstanceType)
103        */
104       public static DescribeSpotPriceHistoryOptions instanceType(String instanceType) {
105          DescribeSpotPriceHistoryOptions options = new DescribeSpotPriceHistoryOptions();
106          return options.instanceType(instanceType);
107       }
108 
109       /**
110        * @see DescribeSpotPriceHistoryOptions#productDescription(String)
111        */
112       public static DescribeSpotPriceHistoryOptions productDescription(String description) {
113          DescribeSpotPriceHistoryOptions options = new DescribeSpotPriceHistoryOptions();
114          return options.productDescription(description);
115       }
116 
117    }
118 }