| 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.elasticstack.domain; |
| 20 | |
| 21 | import static com.google.common.base.Preconditions.checkNotNull; |
| 22 | |
| 23 | import java.util.Map; |
| 24 | import java.util.Set; |
| 25 | |
| 26 | import org.jclouds.javax.annotation.Nullable; |
| 27 | |
| 28 | |
| 29 | import com.google.common.collect.ImmutableSet; |
| 30 | |
| 31 | /** |
| 32 | * |
| 33 | * @author Adrian Cole |
| 34 | */ |
| 35 | public class DriveInfo extends Drive { |
| 36 | public static class Builder extends Drive.Builder { |
| 37 | |
| 38 | protected DriveStatus status; |
| 39 | protected String user; |
| 40 | protected Set<String> claimed = ImmutableSet.of(); |
| 41 | @Nullable |
| 42 | protected String encryptionCipher; |
| 43 | @Nullable |
| 44 | protected String imaging; |
| 45 | protected DriveMetrics metrics; |
| 46 | |
| 47 | public Builder status(DriveStatus status) { |
| 48 | this.status = status; |
| 49 | return this; |
| 50 | } |
| 51 | |
| 52 | public Builder user(String user) { |
| 53 | this.user = user; |
| 54 | return this; |
| 55 | } |
| 56 | |
| 57 | public Builder claimed(Iterable<String> claimed) { |
| 58 | this.claimed = ImmutableSet.copyOf(checkNotNull(claimed, "claimed")); |
| 59 | return this; |
| 60 | } |
| 61 | |
| 62 | public Builder imaging(String imaging) { |
| 63 | this.imaging = imaging; |
| 64 | return this; |
| 65 | } |
| 66 | |
| 67 | public Builder metrics(DriveMetrics metrics) { |
| 68 | this.metrics = metrics; |
| 69 | return this; |
| 70 | } |
| 71 | |
| 72 | public Builder encryptionCipher(String encryptionCipher) { |
| 73 | this.encryptionCipher = encryptionCipher; |
| 74 | return this; |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * {@inheritDoc} |
| 79 | */ |
| 80 | @Override |
| 81 | public Builder claimType(ClaimType claimType) { |
| 82 | return Builder.class.cast(super.claimType(claimType)); |
| 83 | } |
| 84 | |
| 85 | /** |
| 86 | * {@inheritDoc} |
| 87 | */ |
| 88 | @Override |
| 89 | public Builder readers(Iterable<String> readers) { |
| 90 | return Builder.class.cast(super.readers(readers)); |
| 91 | } |
| 92 | |
| 93 | /** |
| 94 | * {@inheritDoc} |
| 95 | */ |
| 96 | @Override |
| 97 | public Builder size(long size) { |
| 98 | return Builder.class.cast(super.size(size)); |
| 99 | } |
| 100 | |
| 101 | /** |
| 102 | * {@inheritDoc} |
| 103 | */ |
| 104 | @Override |
| 105 | public Builder uuid(String uuid) { |
| 106 | return Builder.class.cast(super.uuid(uuid)); |
| 107 | } |
| 108 | |
| 109 | /** |
| 110 | * {@inheritDoc} |
| 111 | */ |
| 112 | @Override |
| 113 | public Builder name(String name) { |
| 114 | return Builder.class.cast(super.name(name)); |
| 115 | } |
| 116 | |
| 117 | /** |
| 118 | * {@inheritDoc} |
| 119 | */ |
| 120 | @Override |
| 121 | public Builder tags(Iterable<String> tags) { |
| 122 | return Builder.class.cast(super.tags(tags)); |
| 123 | } |
| 124 | |
| 125 | /** |
| 126 | * {@inheritDoc} |
| 127 | */ |
| 128 | @Override |
| 129 | public Builder userMetadata(Map<String, String> userMetadata) { |
| 130 | return Builder.class.cast(super.userMetadata(userMetadata)); |
| 131 | } |
| 132 | |
| 133 | public static Builder fromDriveInfo(DriveInfo driveInfo) { |
| 134 | return new Builder().uuid(driveInfo.getUuid()).name(driveInfo.getName()).size(driveInfo.getSize()) |
| 135 | .claimType(driveInfo.getClaimType()).readers(driveInfo.getReaders()).tags(driveInfo.getTags()) |
| 136 | .userMetadata(driveInfo.getUserMetadata()).status(driveInfo.getStatus()).user(driveInfo.getUser()) |
| 137 | .claimed(driveInfo.getClaimed()).encryptionCipher(driveInfo.getEncryptionCipher()) |
| 138 | .imaging(driveInfo.getImaging()).metrics(driveInfo.getMetrics()); |
| 139 | } |
| 140 | |
| 141 | /** |
| 142 | * {@inheritDoc} |
| 143 | */ |
| 144 | @Override |
| 145 | public DriveInfo build() { |
| 146 | return new DriveInfo(uuid, name, size, claimType, readers, tags, userMetadata, status, user, claimed, |
| 147 | encryptionCipher, imaging, metrics); |
| 148 | } |
| 149 | |
| 150 | } |
| 151 | |
| 152 | protected final DriveStatus status; |
| 153 | protected final String user; |
| 154 | protected final Set<String> claimed; |
| 155 | @Nullable |
| 156 | protected final String encryptionCipher; |
| 157 | @Nullable |
| 158 | protected final String imaging; |
| 159 | protected final DriveMetrics metrics; |
| 160 | |
| 161 | public DriveInfo(String uuid, String name, long size, ClaimType claimType, Iterable<String> readers, |
| 162 | Iterable<String> tags, Map<String, String> userMetadata, DriveStatus status, String user, Set<String> claimed, |
| 163 | String encryptionCipher, String imaging, DriveMetrics metrics) { |
| 164 | super(uuid, name, size, claimType, readers, tags, userMetadata); |
| 165 | this.status = status; |
| 166 | this.user = user; |
| 167 | this.claimed = ImmutableSet.copyOf(checkNotNull(claimed, "claimed")); |
| 168 | this.encryptionCipher = encryptionCipher; |
| 169 | this.imaging = imaging; |
| 170 | this.metrics = checkNotNull(metrics, "metrics"); |
| 171 | } |
| 172 | |
| 173 | /** |
| 174 | * |
| 175 | * @return current status of the drive |
| 176 | */ |
| 177 | public DriveStatus getStatus() { |
| 178 | return status; |
| 179 | } |
| 180 | |
| 181 | /** |
| 182 | * |
| 183 | * @return owner of the drive |
| 184 | */ |
| 185 | public String getUser() { |
| 186 | return user; |
| 187 | } |
| 188 | |
| 189 | /** |
| 190 | * |
| 191 | * @return if drive is in use by a server, values are the server uuids |
| 192 | */ |
| 193 | public Set<String> getClaimed() { |
| 194 | return claimed; |
| 195 | } |
| 196 | |
| 197 | /** |
| 198 | * |
| 199 | * @return either 'none' or 'aes-xts-plain' (the default) |
| 200 | */ |
| 201 | @Nullable |
| 202 | public String getEncryptionCipher() { |
| 203 | return encryptionCipher; |
| 204 | } |
| 205 | |
| 206 | /** |
| 207 | * |
| 208 | * @return percentage completed of drive imaging if this is underway, or 'queued' if waiting for |
| 209 | * another imaging operation to complete first |
| 210 | */ |
| 211 | public String getImaging() { |
| 212 | return imaging; |
| 213 | } |
| 214 | |
| 215 | /** |
| 216 | * |
| 217 | * @return i/o and request metrics for read and write ops |
| 218 | */ |
| 219 | public DriveMetrics getMetrics() { |
| 220 | return metrics; |
| 221 | } |
| 222 | |
| 223 | @Override |
| 224 | public int hashCode() { |
| 225 | final int prime = 31; |
| 226 | int result = super.hashCode(); |
| 227 | result = prime * result + ((claimed == null) ? 0 : claimed.hashCode()); |
| 228 | result = prime * result + ((metrics == null) ? 0 : metrics.hashCode()); |
| 229 | result = prime * result + ((encryptionCipher == null) ? 0 : encryptionCipher.hashCode()); |
| 230 | result = prime * result + ((imaging == null) ? 0 : imaging.hashCode()); |
| 231 | result = prime * result + ((status == null) ? 0 : status.hashCode()); |
| 232 | result = prime * result + ((user == null) ? 0 : user.hashCode()); |
| 233 | return result; |
| 234 | } |
| 235 | |
| 236 | @Override |
| 237 | public boolean equals(Object obj) { |
| 238 | if (this == obj) |
| 239 | return true; |
| 240 | if (!super.equals(obj)) |
| 241 | return false; |
| 242 | if (getClass() != obj.getClass()) |
| 243 | return false; |
| 244 | DriveInfo other = (DriveInfo) obj; |
| 245 | if (claimed == null) { |
| 246 | if (other.claimed != null) |
| 247 | return false; |
| 248 | } else if (!claimed.equals(other.claimed)) |
| 249 | return false; |
| 250 | if (metrics == null) { |
| 251 | if (other.metrics != null) |
| 252 | return false; |
| 253 | } else if (!metrics.equals(other.metrics)) |
| 254 | return false; |
| 255 | if (encryptionCipher == null) { |
| 256 | if (other.encryptionCipher != null) |
| 257 | return false; |
| 258 | } else if (!encryptionCipher.equals(other.encryptionCipher)) |
| 259 | return false; |
| 260 | if (imaging == null) { |
| 261 | if (other.imaging != null) |
| 262 | return false; |
| 263 | } else if (!imaging.equals(other.imaging)) |
| 264 | return false; |
| 265 | if (status != other.status) |
| 266 | return false; |
| 267 | if (user == null) { |
| 268 | if (other.user != null) |
| 269 | return false; |
| 270 | } else if (!user.equals(other.user)) |
| 271 | return false; |
| 272 | return true; |
| 273 | } |
| 274 | |
| 275 | @Override |
| 276 | public String toString() { |
| 277 | return "[size=" + size + ", claimType=" + claimType + ", readers=" + readers + ", uuid=" + uuid + ", name=" |
| 278 | + name + ", tags=" + tags + ", userMetadata=" + userMetadata + ", status=" + status + ", user=" + user |
| 279 | + ", claimed=" + claimed + ", encryptionCipher=" + encryptionCipher + ", imaging=" + imaging |
| 280 | + ", metrics=" + metrics + "]"; |
| 281 | } |
| 282 | |
| 283 | } |