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.cloudsigma.domain;
20  
21  import static com.google.common.base.Preconditions.checkNotNull;
22  
23  import java.net.URI;
24  import java.util.Set;
25  
26  import javax.annotation.Nullable;
27  
28  import com.google.common.collect.ImmutableSet;
29  
30  /**
31   * 
32   * @author Adrian Cole
33   */
34  public class DriveInfo extends Drive {
35     public static class Builder extends Drive.Builder {
36  
37        protected DriveStatus status;
38        protected String user;
39        protected Set<String> claimed = ImmutableSet.of();
40        @Nullable
41        protected String encryptionCipher;
42        @Nullable
43        protected String imaging;
44        protected DriveMetrics metrics;
45        private Boolean autoexpanding;
46        private Integer bits;
47        private String description;
48        private Set<String> driveType = ImmutableSet.of();
49        private String encryptionKey;
50        private Boolean free;
51        private String installNotes;
52        private String os;
53        private DriveType type;
54        private URI url;
55  
56        public Builder status(DriveStatus status) {
57           this.status = status;
58           return this;
59        }
60  
61        public Builder user(String user) {
62           this.user = user;
63           return this;
64        }
65  
66        public Builder claimed(Iterable<String> claimed) {
67           this.claimed = ImmutableSet.copyOf(checkNotNull(claimed, "claimed"));
68           return this;
69        }
70  
71        public Builder imaging(String imaging) {
72           this.imaging = imaging;
73           return this;
74        }
75  
76        public Builder metrics(DriveMetrics metrics) {
77           this.metrics = metrics;
78           return this;
79        }
80  
81        public Builder encryptionCipher(String encryptionCipher) {
82           this.encryptionCipher = encryptionCipher;
83           return this;
84        }
85  
86        public Builder autoexpanding(Boolean autoexpanding) {
87           this.autoexpanding = autoexpanding;
88           return this;
89        }
90  
91        public Builder bits(Integer bits) {
92           this.bits = bits;
93           return this;
94        }
95  
96        public Builder description(String description) {
97           this.description = description;
98           return this;
99        }
100 
101       public Builder driveType(Iterable<String> driveType) {
102          this.driveType = ImmutableSet.copyOf(checkNotNull(driveType, "driveType"));
103          return this;
104       }
105 
106       public Builder encryptionKey(String encryptionKey) {
107          this.encryptionKey = encryptionKey;
108          return this;
109       }
110 
111       public Builder free(Boolean free) {
112          this.free = free;
113          return this;
114       }
115 
116       public Builder installNotes(String installNotes) {
117          this.installNotes = installNotes;
118          return this;
119       }
120 
121       public Builder os(String os) {
122          this.os = os;
123          return this;
124       }
125 
126       public Builder type(DriveType type) {
127          this.type = type;
128          return this;
129       }
130 
131       public Builder url(URI url) {
132          this.url = url;
133          return this;
134       }
135 
136       /**
137        * {@inheritDoc}
138        */
139       @Override
140       public Builder claimType(ClaimType claimType) {
141          return Builder.class.cast(super.claimType(claimType));
142       }
143 
144       /**
145        * {@inheritDoc}
146        */
147       @Override
148       public Builder readers(Iterable<String> readers) {
149          return Builder.class.cast(super.readers(readers));
150       }
151 
152       /**
153        * {@inheritDoc}
154        */
155       @Override
156       public Builder size(long size) {
157          return Builder.class.cast(super.size(size));
158       }
159 
160       /**
161        * {@inheritDoc}
162        */
163       @Override
164       public Builder uuid(String uuid) {
165          return Builder.class.cast(super.uuid(uuid));
166       }
167 
168       /**
169        * {@inheritDoc}
170        */
171       @Override
172       public Builder name(String name) {
173          return Builder.class.cast(super.name(name));
174       }
175 
176       /**
177        * {@inheritDoc}
178        */
179       @Override
180       public Builder use(Iterable<String> use) {
181          return Builder.class.cast(super.use(use));
182       }
183 
184       public static Builder fromDriveInfo(DriveInfo in) {
185          return new Builder().uuid(in.getUuid()).name(in.getName()).size(in.getSize()).claimType(in.getClaimType())
186                .readers(in.getReaders()).use(in.getUse()).status(in.getStatus()).user(in.getUser())
187                .claimed(in.getClaimed()).encryptionCipher(in.getEncryptionCipher()).imaging(in.getImaging())
188                .metrics(in.getMetrics()).autoexpanding(in.getAutoexpanding()).bits(in.getBits())
189                .description(in.getDescription()).encryptionKey(in.getEncryptionKey()).free(in.getFree())
190                .installNotes(in.getInstallNotes()).type(in.getType()).url(in.getUrl());
191       }
192 
193       /**
194        * {@inheritDoc}
195        */
196       @Override
197       public DriveInfo build() {
198          return new DriveInfo(uuid, name, size, claimType, readers, use, status, user, claimed, encryptionCipher,
199                imaging, metrics, autoexpanding, bits, description, driveType, encryptionKey, free, installNotes, os,
200                type, url);
201       }
202 
203    }
204 
205    protected final DriveStatus status;
206    protected final String user;
207    protected final Set<String> claimed;
208    @Nullable
209    protected final String encryptionCipher;
210    @Nullable
211    protected final String imaging;
212    protected final DriveMetrics metrics;
213    private final Boolean autoexpanding;
214    private final Integer bits;
215    private final String description;
216    private final ImmutableSet<String> driveType;
217    private final String encryptionKey;
218    private final Boolean free;
219    private final String installNotes;
220    private final String os;
221    private final DriveType type;
222    private final URI url;
223 
224    public DriveInfo(String uuid, String name, long size, ClaimType claimType, Iterable<String> readers,
225          Iterable<String> use, DriveStatus status, String user, Set<String> claimed, String encryptionCipher,
226          String imaging, DriveMetrics metrics, Boolean autoexpanding, Integer bits, String description,
227          Iterable<String> driveType, String encryptionKey, Boolean free, String installNotes, String os,
228          DriveType type, URI url) {
229       super(uuid, name, size, claimType, readers, use);
230       this.status = status;
231       this.user = user;
232       this.claimed = ImmutableSet.copyOf(checkNotNull(claimed, "claimed"));
233       this.encryptionCipher = encryptionCipher;
234       this.imaging = imaging;
235       this.metrics = checkNotNull(metrics, "metrics");
236       this.autoexpanding = autoexpanding;
237       this.bits = bits;
238       this.description = description;
239       this.driveType = ImmutableSet.copyOf(driveType);
240       this.encryptionKey = encryptionKey;
241       this.free = free;
242       this.installNotes = installNotes;
243       this.os = os;
244       this.type = type;
245       this.url = url;
246    }
247 
248    /**
249     * 
250     * @return current status of the drive
251     */
252    public DriveStatus getStatus() {
253       return status;
254    }
255 
256    /**
257     * 
258     * @return owner of the drive
259     */
260    public String getUser() {
261       return user;
262    }
263 
264    /**
265     * 
266     * @return if drive is in use by a server, values are the server uuids
267     */
268    public Set<String> getClaimed() {
269       return claimed;
270    }
271 
272    /**
273     * 
274     * @return either 'none' or 'aes-xts-plain' (the default)
275     */
276    @Nullable
277    public String getEncryptionCipher() {
278       return encryptionCipher;
279    }
280 
281    /**
282     * 
283     * @return percentage completed of drive imaging if this is underway, or 'queued' if waiting for
284     *         another imaging operation to complete first
285     */
286    public String getImaging() {
287       return imaging;
288    }
289 
290    /**
291     * 
292     * @return i/o and request metrics for read and write ops
293     */
294    public DriveMetrics getMetrics() {
295       return metrics;
296    }
297 
298    // TODO
299    public Boolean getAutoexpanding() {
300       return autoexpanding;
301    }
302 
303    // TODO
304    public Integer getBits() {
305       return bits;
306    }
307 
308    // TODO undocumented
309    public String getDescription() {
310       return description;
311    }
312 
313    // TODO
314    public Set<String> getDriveType() {
315       return driveType;
316    }
317 
318    // TODO
319    public String getEncryptionKey() {
320       return encryptionKey;
321    }
322 
323    // TODO
324    public Boolean getFree() {
325       return free;
326    }
327 
328    // TODO
329    public String getInstallNotes() {
330       return installNotes;
331    }
332 
333    // TODO
334    public String getOs() {
335       return os;
336    }
337 
338    // TODO
339    public DriveType getType() {
340       return type;
341    }
342 
343    public URI getUrl() {
344       return url;
345    }
346 
347    @Override
348    public int hashCode() {
349       final int prime = 31;
350       int result = super.hashCode();
351       result = prime * result + ((autoexpanding == null) ? 0 : autoexpanding.hashCode());
352       result = prime * result + ((bits == null) ? 0 : bits.hashCode());
353       result = prime * result + ((claimed == null) ? 0 : claimed.hashCode());
354       result = prime * result + ((description == null) ? 0 : description.hashCode());
355       result = prime * result + ((driveType == null) ? 0 : driveType.hashCode());
356       result = prime * result + ((encryptionCipher == null) ? 0 : encryptionCipher.hashCode());
357       result = prime * result + ((encryptionKey == null) ? 0 : encryptionKey.hashCode());
358       result = prime * result + ((free == null) ? 0 : free.hashCode());
359       result = prime * result + ((imaging == null) ? 0 : imaging.hashCode());
360       result = prime * result + ((installNotes == null) ? 0 : installNotes.hashCode());
361       result = prime * result + ((metrics == null) ? 0 : metrics.hashCode());
362       result = prime * result + ((os == null) ? 0 : os.hashCode());
363       result = prime * result + ((status == null) ? 0 : status.hashCode());
364       result = prime * result + ((type == null) ? 0 : type.hashCode());
365       result = prime * result + ((url == null) ? 0 : url.hashCode());
366       result = prime * result + ((user == null) ? 0 : user.hashCode());
367       return result;
368    }
369 
370    @Override
371    public boolean equals(Object obj) {
372       if (this == obj)
373          return true;
374       if (!super.equals(obj))
375          return false;
376       if (getClass() != obj.getClass())
377          return false;
378       DriveInfo other = (DriveInfo) obj;
379       if (autoexpanding == null) {
380          if (other.autoexpanding != null)
381             return false;
382       } else if (!autoexpanding.equals(other.autoexpanding))
383          return false;
384       if (bits == null) {
385          if (other.bits != null)
386             return false;
387       } else if (!bits.equals(other.bits))
388          return false;
389       if (claimed == null) {
390          if (other.claimed != null)
391             return false;
392       } else if (!claimed.equals(other.claimed))
393          return false;
394       if (description == null) {
395          if (other.description != null)
396             return false;
397       } else if (!description.equals(other.description))
398          return false;
399       if (driveType == null) {
400          if (other.driveType != null)
401             return false;
402       } else if (!driveType.equals(other.driveType))
403          return false;
404       if (encryptionCipher == null) {
405          if (other.encryptionCipher != null)
406             return false;
407       } else if (!encryptionCipher.equals(other.encryptionCipher))
408          return false;
409       if (encryptionKey == null) {
410          if (other.encryptionKey != null)
411             return false;
412       } else if (!encryptionKey.equals(other.encryptionKey))
413          return false;
414       if (free == null) {
415          if (other.free != null)
416             return false;
417       } else if (!free.equals(other.free))
418          return false;
419       if (imaging == null) {
420          if (other.imaging != null)
421             return false;
422       } else if (!imaging.equals(other.imaging))
423          return false;
424       if (installNotes == null) {
425          if (other.installNotes != null)
426             return false;
427       } else if (!installNotes.equals(other.installNotes))
428          return false;
429       if (metrics == null) {
430          if (other.metrics != null)
431             return false;
432       } else if (!metrics.equals(other.metrics))
433          return false;
434       if (os == null) {
435          if (other.os != null)
436             return false;
437       } else if (!os.equals(other.os))
438          return false;
439       if (status != other.status)
440          return false;
441       if (type != other.type)
442          return false;
443       if (url == null) {
444          if (other.url != null)
445             return false;
446       } else if (!url.equals(other.url))
447          return false;
448       if (user == null) {
449          if (other.user != null)
450             return false;
451       } else if (!user.equals(other.user))
452          return false;
453       return true;
454    }
455 
456    @Override
457    public String toString() {
458       return "[size=" + size + ", claimType=" + claimType + ", readers=" + readers + ", uuid=" + uuid + ", name="
459             + name + ", use=" + use + ", status=" + status + ", user=" + user + ", claimed=" + claimed
460             + ", encryptionCipher=" + encryptionCipher + ", imaging=" + imaging + ", metrics=" + metrics + "]";
461    }
462 
463 }