| 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 | /** |
| 24 | * |
| 25 | * @author Adrian Cole |
| 26 | */ |
| 27 | public abstract class Device { |
| 28 | public static abstract class Builder { |
| 29 | protected String uuid; |
| 30 | protected MediaType mediaType = MediaType.DISK; |
| 31 | |
| 32 | public Builder mediaType(MediaType mediaType) { |
| 33 | this.mediaType = mediaType; |
| 34 | return this; |
| 35 | } |
| 36 | |
| 37 | public Builder uuid(String uuid) { |
| 38 | this.uuid = uuid; |
| 39 | return this; |
| 40 | } |
| 41 | |
| 42 | public abstract Device build(); |
| 43 | } |
| 44 | |
| 45 | protected final String driveUuid; |
| 46 | protected final MediaType mediaType; |
| 47 | |
| 48 | public Device(String driveUuid, MediaType mediaType) { |
| 49 | this.driveUuid = checkNotNull(driveUuid, "driveUuid"); |
| 50 | this.mediaType = checkNotNull(mediaType, "mediaType"); |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * id generated based on the device bus, unit, and/or index numbers; |
| 55 | */ |
| 56 | public abstract String getId(); |
| 57 | |
| 58 | /** |
| 59 | * |
| 60 | * @return Drive UUID to connect as specified device. |
| 61 | */ |
| 62 | public String getDriveUuid() { |
| 63 | return driveUuid; |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * |
| 68 | * @return set to 'cdrom' to simulate a cdrom, set to 'disk' or leave unset to simulate a hard |
| 69 | * disk. |
| 70 | */ |
| 71 | public MediaType getMediaType() { |
| 72 | return mediaType; |
| 73 | } |
| 74 | |
| 75 | @Override |
| 76 | public int hashCode() { |
| 77 | final int prime = 31; |
| 78 | int result = 1; |
| 79 | result = prime * result + ((driveUuid == null) ? 0 : driveUuid.hashCode()); |
| 80 | result = prime * result + ((mediaType == null) ? 0 : mediaType.hashCode()); |
| 81 | return result; |
| 82 | } |
| 83 | |
| 84 | @Override |
| 85 | public boolean equals(Object obj) { |
| 86 | if (this == obj) |
| 87 | return true; |
| 88 | if (obj == null) |
| 89 | return false; |
| 90 | if (getClass() != obj.getClass()) |
| 91 | return false; |
| 92 | Device other = (Device) obj; |
| 93 | if (driveUuid == null) { |
| 94 | if (other.driveUuid != null) |
| 95 | return false; |
| 96 | } else if (!driveUuid.equals(other.driveUuid)) |
| 97 | return false; |
| 98 | if (mediaType != other.mediaType) |
| 99 | return false; |
| 100 | return true; |
| 101 | } |
| 102 | |
| 103 | @Override |
| 104 | public String toString() { |
| 105 | return "[driveUuid=" + driveUuid + ", mediaType=" + mediaType + "]"; |
| 106 | } |
| 107 | } |