| 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.byon; |
| 20 | |
| 21 | import java.net.URI; |
| 22 | import java.util.HashSet; |
| 23 | import java.util.Set; |
| 24 | |
| 25 | import com.google.common.base.Objects; |
| 26 | import com.google.common.collect.ImmutableSet; |
| 27 | |
| 28 | /** |
| 29 | * |
| 30 | * @author Adrian Cole |
| 31 | */ |
| 32 | public class Node { |
| 33 | public static Builder builder() { |
| 34 | return new Builder(); |
| 35 | } |
| 36 | |
| 37 | public static class Builder { |
| 38 | private String id; |
| 39 | private String name; |
| 40 | private String description; |
| 41 | private String hostname; |
| 42 | private String locationId; |
| 43 | private String osArch; |
| 44 | private String osFamily; |
| 45 | private String osDescription; |
| 46 | private String osVersion; |
| 47 | private boolean os64Bit; |
| 48 | private int loginPort = 22; |
| 49 | private String group; |
| 50 | private Set<String> tags = ImmutableSet.of(); |
| 51 | private String username; |
| 52 | private String credential; |
| 53 | private URI credentialUrl; |
| 54 | private String sudoPassword; |
| 55 | |
| 56 | public Builder id(String id) { |
| 57 | this.id = id; |
| 58 | return this; |
| 59 | } |
| 60 | |
| 61 | public Builder name(String name) { |
| 62 | this.name = name; |
| 63 | return this; |
| 64 | } |
| 65 | |
| 66 | public Builder description(String description) { |
| 67 | this.description = description; |
| 68 | return this; |
| 69 | } |
| 70 | |
| 71 | public Builder hostname(String hostname) { |
| 72 | this.hostname = hostname; |
| 73 | return this; |
| 74 | } |
| 75 | |
| 76 | public Builder loginPort(int loginPort) { |
| 77 | this.loginPort = loginPort; |
| 78 | return this; |
| 79 | } |
| 80 | |
| 81 | public Builder locationId(String locationId) { |
| 82 | this.locationId = locationId; |
| 83 | return this; |
| 84 | } |
| 85 | |
| 86 | public Builder osArch(String osArch) { |
| 87 | this.osArch = osArch; |
| 88 | return this; |
| 89 | } |
| 90 | |
| 91 | public Builder osFamily(String osFamily) { |
| 92 | this.osFamily = osFamily; |
| 93 | return this; |
| 94 | } |
| 95 | |
| 96 | public Builder osDescription(String osDescription) { |
| 97 | this.osDescription = osDescription; |
| 98 | return this; |
| 99 | } |
| 100 | |
| 101 | public Builder osVersion(String osVersion) { |
| 102 | this.osVersion = osVersion; |
| 103 | return this; |
| 104 | } |
| 105 | |
| 106 | public Builder os64Bit(boolean os64Bit) { |
| 107 | this.os64Bit = os64Bit; |
| 108 | return this; |
| 109 | } |
| 110 | |
| 111 | public Builder group(String group) { |
| 112 | this.group = group; |
| 113 | return this; |
| 114 | } |
| 115 | |
| 116 | public Builder tags(Iterable<String> tags) { |
| 117 | this.tags = ImmutableSet.copyOf(tags); |
| 118 | return this; |
| 119 | } |
| 120 | |
| 121 | public Builder username(String username) { |
| 122 | this.username = username; |
| 123 | return this; |
| 124 | } |
| 125 | |
| 126 | public Builder credential(String credential) { |
| 127 | this.credential = credential; |
| 128 | return this; |
| 129 | } |
| 130 | |
| 131 | public Builder credentialUrl(URI credentialUrl) { |
| 132 | this.credentialUrl = credentialUrl; |
| 133 | return this; |
| 134 | } |
| 135 | |
| 136 | public Builder sudoPassword(String sudoPassword) { |
| 137 | this.sudoPassword = sudoPassword; |
| 138 | return this; |
| 139 | } |
| 140 | |
| 141 | public Node build() { |
| 142 | return new Node(id, name, description, hostname, locationId, osArch, osFamily, osDescription, osVersion, |
| 143 | os64Bit, loginPort, group, tags, username, credential, credentialUrl, sudoPassword); |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | public Node(String id, String name, String description, String hostname, String locationId, String osArch, |
| 148 | String osFamily, String osDescription, String osVersion, boolean os64Bit, int loginPort, String group, |
| 149 | Iterable<String> tags, String username, String credential, URI credentialUrl, String sudoPassword) { |
| 150 | this.id = id; |
| 151 | this.name = name; |
| 152 | this.description = description; |
| 153 | this.hostname = hostname; |
| 154 | this.locationId = locationId; |
| 155 | this.osArch = osArch; |
| 156 | this.osFamily = osFamily; |
| 157 | this.osDescription = osDescription; |
| 158 | this.osVersion = osVersion; |
| 159 | this.os64Bit = os64Bit; |
| 160 | this.loginPort = loginPort; |
| 161 | this.group = group; |
| 162 | this.tags = ImmutableSet.copyOf(tags); |
| 163 | this.username = username; |
| 164 | this.credential = credential; |
| 165 | this.credentialUrl = credentialUrl; |
| 166 | this.sudoPassword = sudoPassword; |
| 167 | } |
| 168 | |
| 169 | private final String id; |
| 170 | private final String name; |
| 171 | private final String description; |
| 172 | private final String hostname; |
| 173 | private final String locationId; |
| 174 | private final String osArch; |
| 175 | private final String osFamily; |
| 176 | private final String osDescription; |
| 177 | private final String osVersion; |
| 178 | private final int loginPort; |
| 179 | private final boolean os64Bit; |
| 180 | private final String group; |
| 181 | private final Set<String> tags; |
| 182 | private final String username; |
| 183 | private final String credential; |
| 184 | private final URI credentialUrl; |
| 185 | private final String sudoPassword; |
| 186 | |
| 187 | public String getId() { |
| 188 | return id; |
| 189 | } |
| 190 | |
| 191 | public String getLocationId() { |
| 192 | return locationId; |
| 193 | } |
| 194 | |
| 195 | public String getName() { |
| 196 | return name; |
| 197 | } |
| 198 | |
| 199 | public String getDescription() { |
| 200 | return description; |
| 201 | } |
| 202 | |
| 203 | public String getGroup() { |
| 204 | return group; |
| 205 | } |
| 206 | |
| 207 | public String getHostname() { |
| 208 | return hostname; |
| 209 | } |
| 210 | |
| 211 | public String getOsArch() { |
| 212 | return osArch; |
| 213 | } |
| 214 | |
| 215 | public String getOsFamily() { |
| 216 | return osFamily; |
| 217 | } |
| 218 | |
| 219 | public String getOsDescription() { |
| 220 | return osDescription; |
| 221 | } |
| 222 | |
| 223 | public String getOsVersion() { |
| 224 | return osVersion; |
| 225 | } |
| 226 | |
| 227 | public boolean isOs64Bit() { |
| 228 | return os64Bit; |
| 229 | } |
| 230 | |
| 231 | public int getLoginPort() { |
| 232 | return loginPort; |
| 233 | } |
| 234 | |
| 235 | public Set<String> getTags() { |
| 236 | Set<String> tagSet = new HashSet<String>(); |
| 237 | for (String tag : tags) |
| 238 | tagSet.add(tag); |
| 239 | return tagSet; |
| 240 | } |
| 241 | |
| 242 | public String getUsername() { |
| 243 | return username; |
| 244 | } |
| 245 | |
| 246 | public String getCredential() { |
| 247 | return credential; |
| 248 | } |
| 249 | |
| 250 | public URI getCredentialUrl() { |
| 251 | return credentialUrl; |
| 252 | } |
| 253 | |
| 254 | public String getSudoPassword() { |
| 255 | return sudoPassword; |
| 256 | } |
| 257 | |
| 258 | @Override |
| 259 | public int hashCode() { |
| 260 | return Objects.hashCode(id); |
| 261 | } |
| 262 | |
| 263 | @Override |
| 264 | public boolean equals(Object that) { |
| 265 | if (that == null) |
| 266 | return false; |
| 267 | return Objects.equal(this.toString(), that.toString()); |
| 268 | } |
| 269 | |
| 270 | @Override |
| 271 | public String toString() { |
| 272 | return Objects.toStringHelper(this).add("id", id).add("name", name).add("description", description).add( |
| 273 | "locationId", locationId).add("hostname", hostname).add("osArch", osArch).add("osFamily", osFamily).add( |
| 274 | "osDescription", osDescription).add("osVersion", osVersion).add("os64Bit", os64Bit).add("group", group) |
| 275 | .add("loginPort", loginPort).add("tags", tags).add("username", username).add("hasCredential", |
| 276 | credential != null || credentialUrl != null).add("hasSudoPassword", sudoPassword != null) |
| 277 | .toString(); |
| 278 | } |
| 279 | |
| 280 | } |