| 1 | /** |
| 2 | * Licensed to jclouds, Inc. (jclouds) under one or more |
| 3 | * contributor license agreements. See the NOTICE file |
| 4 | * distributed with this work for additional information |
| 5 | * regarding copyright ownership. jclouds licenses this file |
| 6 | * to you under the Apache License, Version 2.0 (the |
| 7 | * "License"); you may not use this file except in compliance |
| 8 | * with the License. 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, |
| 13 | * software distributed under the License is distributed on an |
| 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | * KIND, either express or implied. See the License for the |
| 16 | * specific language governing permissions and limitations |
| 17 | * under the License. |
| 18 | */ |
| 19 | package org.jclouds.ec2.domain; |
| 20 | |
| 21 | import static com.google.common.base.Preconditions.checkNotNull; |
| 22 | |
| 23 | import java.util.Date; |
| 24 | |
| 25 | import org.jclouds.javax.annotation.Nullable; |
| 26 | |
| 27 | /** |
| 28 | * |
| 29 | * @see <a href="http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-ItemType-BundleInstanceTaskType.html" |
| 30 | * /> |
| 31 | * @author Adrian Cole |
| 32 | */ |
| 33 | public class BundleTask implements Comparable<BundleTask> { |
| 34 | /** |
| 35 | * {@inheritDoc} |
| 36 | */ |
| 37 | public int compareTo(BundleTask o) { |
| 38 | return (this == o) ? 0 : getBundleId().compareTo(o.getBundleId()); |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * If the task fails, a description of the error. |
| 43 | * |
| 44 | * @see <a href="http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-ItemType-BundleInstanceTaskErrorType.html" |
| 45 | * /> |
| 46 | * @author Adrian Cole |
| 47 | */ |
| 48 | public static class Error { |
| 49 | private final String code; |
| 50 | private final String message; |
| 51 | |
| 52 | public Error(String code, String message) { |
| 53 | this.code = checkNotNull(code, "code"); |
| 54 | this.message = checkNotNull(message, "message"); |
| 55 | } |
| 56 | |
| 57 | public String getCode() { |
| 58 | return code; |
| 59 | } |
| 60 | |
| 61 | public String getMessage() { |
| 62 | return message; |
| 63 | } |
| 64 | |
| 65 | @Override |
| 66 | public String toString() { |
| 67 | return "[code=" + code + ", message=" + message + "]"; |
| 68 | } |
| 69 | |
| 70 | @Override |
| 71 | public int hashCode() { |
| 72 | final int prime = 31; |
| 73 | int result = 1; |
| 74 | result = prime * result + ((code == null) ? 0 : code.hashCode()); |
| 75 | result = prime * result + ((message == null) ? 0 : message.hashCode()); |
| 76 | return result; |
| 77 | } |
| 78 | |
| 79 | @Override |
| 80 | public boolean equals(Object obj) { |
| 81 | if (this == obj) |
| 82 | return true; |
| 83 | if (obj == null) |
| 84 | return false; |
| 85 | if (getClass() != obj.getClass()) |
| 86 | return false; |
| 87 | Error other = (Error) obj; |
| 88 | if (code == null) { |
| 89 | if (other.code != null) |
| 90 | return false; |
| 91 | } else if (!code.equals(other.code)) |
| 92 | return false; |
| 93 | if (message == null) { |
| 94 | if (other.message != null) |
| 95 | return false; |
| 96 | } else if (!message.equals(other.message)) |
| 97 | return false; |
| 98 | return true; |
| 99 | } |
| 100 | |
| 101 | } |
| 102 | |
| 103 | private final String region; |
| 104 | private final String bundleId; |
| 105 | private final Error error; |
| 106 | private final String instanceId; |
| 107 | private final int progress; |
| 108 | private final Date startTime; |
| 109 | private final String state; |
| 110 | private final String bucket; |
| 111 | private final String prefix; |
| 112 | private final Date updateTime; |
| 113 | |
| 114 | public BundleTask(String region, String bundleId, @Nullable Error error, String instanceId, int progress, |
| 115 | Date startTime, String state, String bucket, String prefix, Date updateTime) { |
| 116 | this.region = checkNotNull(region, "region"); |
| 117 | this.bundleId = checkNotNull(bundleId, "bundleId"); |
| 118 | this.error = error; |
| 119 | this.instanceId = checkNotNull(instanceId, "instanceId"); |
| 120 | this.progress = checkNotNull(progress, "progress"); |
| 121 | this.startTime = checkNotNull(startTime, "startTime"); |
| 122 | this.state = checkNotNull(state, "state"); |
| 123 | this.bucket = checkNotNull(bucket, "bucket"); |
| 124 | this.prefix = checkNotNull(prefix, "prefix"); |
| 125 | this.updateTime = checkNotNull(updateTime, "updateTime"); |
| 126 | } |
| 127 | |
| 128 | @Override |
| 129 | public String toString() { |
| 130 | return "[bucket=" + bucket + ", bundleId=" + bundleId + ", error=" + error + ", instanceId=" + instanceId |
| 131 | + ", prefix=" + prefix + ", progress=" + progress + ", region=" + region + ", startTime=" + startTime |
| 132 | + ", state=" + state + ", updateTime=" + updateTime + "]"; |
| 133 | } |
| 134 | |
| 135 | @Override |
| 136 | public int hashCode() { |
| 137 | final int prime = 31; |
| 138 | int result = 1; |
| 139 | result = prime * result + ((bucket == null) ? 0 : bucket.hashCode()); |
| 140 | result = prime * result + ((bundleId == null) ? 0 : bundleId.hashCode()); |
| 141 | result = prime * result + ((error == null) ? 0 : error.hashCode()); |
| 142 | result = prime * result + ((instanceId == null) ? 0 : instanceId.hashCode()); |
| 143 | result = prime * result + ((prefix == null) ? 0 : prefix.hashCode()); |
| 144 | result = prime * result + progress; |
| 145 | result = prime * result + ((region == null) ? 0 : region.hashCode()); |
| 146 | result = prime * result + ((startTime == null) ? 0 : startTime.hashCode()); |
| 147 | result = prime * result + ((state == null) ? 0 : state.hashCode()); |
| 148 | result = prime * result + ((updateTime == null) ? 0 : updateTime.hashCode()); |
| 149 | return result; |
| 150 | } |
| 151 | |
| 152 | @Override |
| 153 | public boolean equals(Object obj) { |
| 154 | if (this == obj) |
| 155 | return true; |
| 156 | if (obj == null) |
| 157 | return false; |
| 158 | if (getClass() != obj.getClass()) |
| 159 | return false; |
| 160 | BundleTask other = (BundleTask) obj; |
| 161 | if (bucket == null) { |
| 162 | if (other.bucket != null) |
| 163 | return false; |
| 164 | } else if (!bucket.equals(other.bucket)) |
| 165 | return false; |
| 166 | if (bundleId == null) { |
| 167 | if (other.bundleId != null) |
| 168 | return false; |
| 169 | } else if (!bundleId.equals(other.bundleId)) |
| 170 | return false; |
| 171 | if (error == null) { |
| 172 | if (other.error != null) |
| 173 | return false; |
| 174 | } else if (!error.equals(other.error)) |
| 175 | return false; |
| 176 | if (instanceId == null) { |
| 177 | if (other.instanceId != null) |
| 178 | return false; |
| 179 | } else if (!instanceId.equals(other.instanceId)) |
| 180 | return false; |
| 181 | if (prefix == null) { |
| 182 | if (other.prefix != null) |
| 183 | return false; |
| 184 | } else if (!prefix.equals(other.prefix)) |
| 185 | return false; |
| 186 | if (progress != other.progress) |
| 187 | return false; |
| 188 | if (region == null) { |
| 189 | if (other.region != null) |
| 190 | return false; |
| 191 | } else if (!region.equals(other.region)) |
| 192 | return false; |
| 193 | if (startTime == null) { |
| 194 | if (other.startTime != null) |
| 195 | return false; |
| 196 | } else if (!startTime.equals(other.startTime)) |
| 197 | return false; |
| 198 | if (state == null) { |
| 199 | if (other.state != null) |
| 200 | return false; |
| 201 | } else if (!state.equals(other.state)) |
| 202 | return false; |
| 203 | if (updateTime == null) { |
| 204 | if (other.updateTime != null) |
| 205 | return false; |
| 206 | } else if (!updateTime.equals(other.updateTime)) |
| 207 | return false; |
| 208 | return true; |
| 209 | } |
| 210 | |
| 211 | /** |
| 212 | * |
| 213 | * @return region of the bundle task |
| 214 | */ |
| 215 | public String getRegion() { |
| 216 | return region; |
| 217 | } |
| 218 | |
| 219 | /** |
| 220 | * |
| 221 | * @return The bucket in which to store the AMI. You can specify a bucket |
| 222 | * that you already own or a new bucket that Amazon EC2 creates on |
| 223 | * your behalf. If you specify a bucket that belongs to someone e |
| 224 | * lse, Amazon EC2 returns an error. |
| 225 | */ |
| 226 | public String getBucket() { |
| 227 | return bucket; |
| 228 | } |
| 229 | |
| 230 | /** |
| 231 | * |
| 232 | * @return Specifies the beginning of the file name of the AMI. |
| 233 | */ |
| 234 | public String getPrefix() { |
| 235 | return prefix; |
| 236 | } |
| 237 | |
| 238 | /** |
| 239 | * |
| 240 | * @return Identifier for this task. |
| 241 | */ |
| 242 | public String getBundleId() { |
| 243 | return bundleId; |
| 244 | } |
| 245 | |
| 246 | /** |
| 247 | * |
| 248 | * @return If the task fails, a description of the error. |
| 249 | */ |
| 250 | public Error getError() { |
| 251 | return error; |
| 252 | } |
| 253 | |
| 254 | /** |
| 255 | * |
| 256 | * @return Instance associated with this bundle task |
| 257 | */ |
| 258 | public String getInstanceId() { |
| 259 | return instanceId; |
| 260 | } |
| 261 | |
| 262 | /** |
| 263 | * |
| 264 | * @return A percentage description of the progress of the task, such as 20. |
| 265 | */ |
| 266 | public int getProgress() { |
| 267 | return progress; |
| 268 | } |
| 269 | |
| 270 | /** |
| 271 | * |
| 272 | * @return The time this task started. |
| 273 | */ |
| 274 | public Date getStartTime() { |
| 275 | return startTime; |
| 276 | } |
| 277 | |
| 278 | /** |
| 279 | * |
| 280 | * @return The state of the task. |
| 281 | */ |
| 282 | public String getState() { |
| 283 | return state; |
| 284 | } |
| 285 | |
| 286 | /** |
| 287 | * |
| 288 | * @return The time of the most recent update for the task. |
| 289 | */ |
| 290 | public Date getUpdateTime() { |
| 291 | return updateTime; |
| 292 | } |
| 293 | |
| 294 | } |