| 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 | /** |
| 26 | * |
| 27 | * @see <a href="http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-CreateSnapshot.html" |
| 28 | * /> |
| 29 | * @author Adrian Cole |
| 30 | */ |
| 31 | public class Snapshot implements Comparable<Snapshot> { |
| 32 | public static enum Status { |
| 33 | PENDING, COMPLETED, ERROR, UNRECOGNIZED; |
| 34 | public String value() { |
| 35 | return name().toLowerCase(); |
| 36 | } |
| 37 | |
| 38 | @Override |
| 39 | public String toString() { |
| 40 | return value(); |
| 41 | } |
| 42 | |
| 43 | public static Status fromValue(String status) { |
| 44 | try { |
| 45 | return valueOf(checkNotNull(status, "status").toUpperCase()); |
| 46 | } catch (IllegalArgumentException e) { |
| 47 | return UNRECOGNIZED; |
| 48 | } |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | private final String region; |
| 53 | private final String id; |
| 54 | private final String volumeId; |
| 55 | private final int volumeSize; |
| 56 | private final Status status; |
| 57 | private final Date startTime; |
| 58 | private final int progress; |
| 59 | private final String ownerId; |
| 60 | private final String description; |
| 61 | private final String ownerAlias; |
| 62 | |
| 63 | public Snapshot(String region, String id, String volumeId, int volumeSize, Status status, Date startTime, |
| 64 | int progress, String ownerId, String description, String ownerAlias) { |
| 65 | this.region = checkNotNull(region, "region"); |
| 66 | this.id = id; |
| 67 | this.volumeId = volumeId; |
| 68 | this.volumeSize = volumeSize; |
| 69 | this.status = status; |
| 70 | this.startTime = startTime; |
| 71 | this.progress = progress; |
| 72 | this.ownerId = ownerId; |
| 73 | this.description = description; |
| 74 | this.ownerAlias = ownerAlias; |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * Snapshots are tied to Regions and can only be used for volumes within the same Region. |
| 79 | */ |
| 80 | public String getRegion() { |
| 81 | return region; |
| 82 | } |
| 83 | |
| 84 | /** |
| 85 | * The ID of the snapshot. |
| 86 | */ |
| 87 | public String getId() { |
| 88 | return id; |
| 89 | } |
| 90 | |
| 91 | /** |
| 92 | * The ID of the volume. |
| 93 | */ |
| 94 | public String getVolumeId() { |
| 95 | return volumeId; |
| 96 | } |
| 97 | |
| 98 | /** |
| 99 | * The size of the volume, in GiB. |
| 100 | */ |
| 101 | public int getVolumeSize() { |
| 102 | return volumeSize; |
| 103 | } |
| 104 | |
| 105 | /** |
| 106 | * Snapshot state (e.g., pending, completed, or error) |
| 107 | */ |
| 108 | public Status getStatus() { |
| 109 | return status; |
| 110 | } |
| 111 | |
| 112 | /** |
| 113 | * Time stamp when the snapshot was initiated. |
| 114 | */ |
| 115 | public Date getStartTime() { |
| 116 | return startTime; |
| 117 | } |
| 118 | |
| 119 | /** |
| 120 | * The progress of the snapshot, in percentage. |
| 121 | */ |
| 122 | public int getProgress() { |
| 123 | return progress; |
| 124 | } |
| 125 | |
| 126 | /** |
| 127 | * AWS Access Key ID of the user who owns the snapshot. |
| 128 | */ |
| 129 | public String getOwnerId() { |
| 130 | return ownerId; |
| 131 | } |
| 132 | |
| 133 | /** |
| 134 | * Description of the snapshot. |
| 135 | */ |
| 136 | public String getDescription() { |
| 137 | return description; |
| 138 | } |
| 139 | |
| 140 | /** |
| 141 | * The AWS identity alias (e.g., "amazon", "redhat", "self", etc.) or AWS identity ID that owns |
| 142 | * the AMI. |
| 143 | */ |
| 144 | public String getOwnerAlias() { |
| 145 | return ownerAlias; |
| 146 | } |
| 147 | |
| 148 | @Override |
| 149 | public int hashCode() { |
| 150 | final int prime = 31; |
| 151 | int result = 1; |
| 152 | result = prime * result + ((description == null) ? 0 : description.hashCode()); |
| 153 | result = prime * result + ((id == null) ? 0 : id.hashCode()); |
| 154 | result = prime * result + ((ownerAlias == null) ? 0 : ownerAlias.hashCode()); |
| 155 | result = prime * result + ((ownerId == null) ? 0 : ownerId.hashCode()); |
| 156 | result = prime * result + progress; |
| 157 | result = prime * result + ((region == null) ? 0 : region.hashCode()); |
| 158 | result = prime * result + ((startTime == null) ? 0 : startTime.hashCode()); |
| 159 | result = prime * result + ((status == null) ? 0 : status.hashCode()); |
| 160 | result = prime * result + ((volumeId == null) ? 0 : volumeId.hashCode()); |
| 161 | result = prime * result + volumeSize; |
| 162 | return result; |
| 163 | } |
| 164 | |
| 165 | @Override |
| 166 | public boolean equals(Object obj) { |
| 167 | if (this == obj) |
| 168 | return true; |
| 169 | if (obj == null) |
| 170 | return false; |
| 171 | if (getClass() != obj.getClass()) |
| 172 | return false; |
| 173 | Snapshot other = (Snapshot) obj; |
| 174 | if (description == null) { |
| 175 | if (other.description != null) |
| 176 | return false; |
| 177 | } else if (!description.equals(other.description)) |
| 178 | return false; |
| 179 | if (id == null) { |
| 180 | if (other.id != null) |
| 181 | return false; |
| 182 | } else if (!id.equals(other.id)) |
| 183 | return false; |
| 184 | if (ownerAlias == null) { |
| 185 | if (other.ownerAlias != null) |
| 186 | return false; |
| 187 | } else if (!ownerAlias.equals(other.ownerAlias)) |
| 188 | return false; |
| 189 | if (ownerId == null) { |
| 190 | if (other.ownerId != null) |
| 191 | return false; |
| 192 | } else if (!ownerId.equals(other.ownerId)) |
| 193 | return false; |
| 194 | if (progress != other.progress) |
| 195 | return false; |
| 196 | if (region == null) { |
| 197 | if (other.region != null) |
| 198 | return false; |
| 199 | } else if (!region.equals(other.region)) |
| 200 | return false; |
| 201 | if (startTime == null) { |
| 202 | if (other.startTime != null) |
| 203 | return false; |
| 204 | } else if (!startTime.equals(other.startTime)) |
| 205 | return false; |
| 206 | if (status == null) { |
| 207 | if (other.status != null) |
| 208 | return false; |
| 209 | } else if (!status.equals(other.status)) |
| 210 | return false; |
| 211 | if (volumeId == null) { |
| 212 | if (other.volumeId != null) |
| 213 | return false; |
| 214 | } else if (!volumeId.equals(other.volumeId)) |
| 215 | return false; |
| 216 | if (volumeSize != other.volumeSize) |
| 217 | return false; |
| 218 | return true; |
| 219 | } |
| 220 | |
| 221 | @Override |
| 222 | public String toString() { |
| 223 | return "Snapshot [description=" + description + ", id=" + id + ", ownerAlias=" + ownerAlias + ", ownerId=" |
| 224 | + ownerId + ", progress=" + progress + ", startTime=" + startTime + ", status=" + status + ", volumeId=" |
| 225 | + volumeId + ", volumeSize=" + volumeSize + "]"; |
| 226 | } |
| 227 | |
| 228 | @Override |
| 229 | public int compareTo(Snapshot o) { |
| 230 | return startTime.compareTo(o.startTime); |
| 231 | } |
| 232 | |
| 233 | } |