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