| 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.compute.domain.internal; |
| 20 | |
| 21 | import static com.google.common.base.Preconditions.checkNotNull; |
| 22 | |
| 23 | import java.net.URI; |
| 24 | import java.util.Map; |
| 25 | import java.util.Set; |
| 26 | |
| 27 | import org.jclouds.javax.annotation.Nullable; |
| 28 | |
| 29 | import org.jclouds.compute.domain.ComputeType; |
| 30 | import org.jclouds.compute.domain.Hardware; |
| 31 | import org.jclouds.compute.domain.NodeMetadata; |
| 32 | import org.jclouds.compute.domain.NodeState; |
| 33 | import org.jclouds.compute.domain.OperatingSystem; |
| 34 | import org.jclouds.domain.Credentials; |
| 35 | import org.jclouds.domain.Location; |
| 36 | |
| 37 | import com.google.common.collect.ImmutableSet; |
| 38 | |
| 39 | /** |
| 40 | * @author Adrian Cole |
| 41 | * @author Ivan Meredith |
| 42 | */ |
| 43 | public class NodeMetadataImpl extends ComputeMetadataImpl implements NodeMetadata { |
| 44 | |
| 45 | /** The serialVersionUID */ |
| 46 | private static final long serialVersionUID = 7924307572338157887L; |
| 47 | |
| 48 | private final NodeState state; |
| 49 | private final int loginPort; |
| 50 | private final Set<String> publicAddresses; |
| 51 | private final Set<String> privateAddresses; |
| 52 | @Nullable |
| 53 | private final String adminPassword; |
| 54 | @Nullable |
| 55 | private final Credentials credentials; |
| 56 | @Nullable |
| 57 | private final String group; |
| 58 | @Nullable |
| 59 | private final String imageId; |
| 60 | @Nullable |
| 61 | private final Hardware hardware; |
| 62 | @Nullable |
| 63 | private final OperatingSystem os; |
| 64 | @Nullable |
| 65 | private final String hostname; |
| 66 | |
| 67 | public NodeMetadataImpl(String providerId, String name, String id, Location location, URI uri, |
| 68 | Map<String, String> userMetadata, Set<String> tags, @Nullable String group, @Nullable Hardware hardware, |
| 69 | @Nullable String imageId, @Nullable OperatingSystem os, NodeState state, int loginPort, |
| 70 | Iterable<String> publicAddresses, Iterable<String> privateAddresses, @Nullable String adminPassword, |
| 71 | @Nullable Credentials credentials, String hostname) { |
| 72 | super(ComputeType.NODE, providerId, name, id, location, uri, userMetadata, tags); |
| 73 | this.group = group; |
| 74 | this.hardware = hardware; |
| 75 | this.imageId = imageId; |
| 76 | this.os = os; |
| 77 | this.state = checkNotNull(state, "state"); |
| 78 | this.loginPort = loginPort; |
| 79 | this.publicAddresses = ImmutableSet.copyOf(checkNotNull(publicAddresses, "publicAddresses")); |
| 80 | this.privateAddresses = ImmutableSet.copyOf(checkNotNull(privateAddresses, "privateAddresses")); |
| 81 | this.adminPassword = adminPassword; |
| 82 | this.credentials = credentials; |
| 83 | this.hostname = hostname; |
| 84 | } |
| 85 | |
| 86 | /** |
| 87 | * {@inheritDoc} |
| 88 | */ |
| 89 | @Override |
| 90 | public String getTag() { |
| 91 | return getGroup(); |
| 92 | } |
| 93 | |
| 94 | /** |
| 95 | * {@inheritDoc} |
| 96 | */ |
| 97 | @Override |
| 98 | public String getGroup() { |
| 99 | return group; |
| 100 | } |
| 101 | |
| 102 | /** |
| 103 | * {@inheritDoc} |
| 104 | */ |
| 105 | @Override |
| 106 | public Hardware getHardware() { |
| 107 | return hardware; |
| 108 | } |
| 109 | |
| 110 | /** |
| 111 | * {@inheritDoc} |
| 112 | */ |
| 113 | @Override |
| 114 | public String getAdminPassword() { |
| 115 | return adminPassword; |
| 116 | } |
| 117 | |
| 118 | /** |
| 119 | * {@inheritDoc} |
| 120 | */ |
| 121 | @Override |
| 122 | public Credentials getCredentials() { |
| 123 | return credentials; |
| 124 | } |
| 125 | |
| 126 | /** |
| 127 | * {@inheritDoc} |
| 128 | */ |
| 129 | @Override |
| 130 | public Set<String> getPublicAddresses() { |
| 131 | return publicAddresses; |
| 132 | } |
| 133 | |
| 134 | /** |
| 135 | * {@inheritDoc} |
| 136 | */ |
| 137 | @Override |
| 138 | public Set<String> getPrivateAddresses() { |
| 139 | return privateAddresses; |
| 140 | } |
| 141 | |
| 142 | /** |
| 143 | * {@inheritDoc} |
| 144 | */ |
| 145 | @Override |
| 146 | public NodeState getState() { |
| 147 | return state; |
| 148 | } |
| 149 | |
| 150 | /** |
| 151 | * {@inheritDoc} |
| 152 | */ |
| 153 | @Override |
| 154 | public int getLoginPort() { |
| 155 | return this.loginPort; |
| 156 | } |
| 157 | |
| 158 | /** |
| 159 | * {@inheritDoc} |
| 160 | */ |
| 161 | @Override |
| 162 | public String getImageId() { |
| 163 | return imageId; |
| 164 | } |
| 165 | |
| 166 | /** |
| 167 | * {@inheritDoc} |
| 168 | */ |
| 169 | @Override |
| 170 | public OperatingSystem getOperatingSystem() { |
| 171 | return os; |
| 172 | } |
| 173 | |
| 174 | /** |
| 175 | * {@inheritDoc} |
| 176 | */ |
| 177 | @Override |
| 178 | public String getHostname() { |
| 179 | return hostname; |
| 180 | } |
| 181 | |
| 182 | @Override |
| 183 | public String toString() { |
| 184 | return "[id=" + getId() + ", providerId=" + getProviderId() + ", group=" + getTag() + ", name=" + getName() |
| 185 | + ", location=" + getLocation() + ", uri=" + getUri() + ", imageId=" + getImageId() + ", os=" |
| 186 | + getOperatingSystem() + ", state=" + getState() + ", loginPort=" + getLoginPort() + ", hostname=" |
| 187 | + getHostname() + ", privateAddresses=" + privateAddresses + ", publicAddresses=" + publicAddresses |
| 188 | + ", hardware=" + getHardware() + ", loginUser=" + ((credentials != null) ? credentials.identity : null) |
| 189 | + ", userMetadata=" + getUserMetadata() + ", tags=" + tags + "]"; |
| 190 | } |
| 191 | |
| 192 | @Override |
| 193 | public int hashCode() { |
| 194 | final int prime = 31; |
| 195 | int result = super.hashCode(); |
| 196 | result = prime * result + loginPort; |
| 197 | result = prime * result + ((privateAddresses == null) ? 0 : privateAddresses.hashCode()); |
| 198 | result = prime * result + ((publicAddresses == null) ? 0 : publicAddresses.hashCode()); |
| 199 | result = prime * result + ((group == null) ? 0 : group.hashCode()); |
| 200 | result = prime * result + ((hostname == null) ? 0 : hostname.hashCode()); |
| 201 | result = prime * result + ((imageId == null) ? 0 : imageId.hashCode()); |
| 202 | result = prime * result + ((hardware == null) ? 0 : hardware.hashCode()); |
| 203 | result = prime * result + ((os == null) ? 0 : os.hashCode()); |
| 204 | result = prime * result + ((adminPassword == null) ? 0 : adminPassword.hashCode()); |
| 205 | result = prime * result + ((credentials == null) ? 0 : credentials.hashCode()); |
| 206 | return result; |
| 207 | } |
| 208 | |
| 209 | @Override |
| 210 | public boolean equals(Object obj) { |
| 211 | if (this == obj) |
| 212 | return true; |
| 213 | if (!super.equals(obj)) |
| 214 | return false; |
| 215 | if (getClass() != obj.getClass()) |
| 216 | return false; |
| 217 | NodeMetadataImpl other = (NodeMetadataImpl) obj; |
| 218 | if (loginPort != other.loginPort) |
| 219 | return false; |
| 220 | if (privateAddresses == null) { |
| 221 | if (other.privateAddresses != null) |
| 222 | return false; |
| 223 | } else if (!privateAddresses.equals(other.privateAddresses)) |
| 224 | return false; |
| 225 | if (publicAddresses == null) { |
| 226 | if (other.publicAddresses != null) |
| 227 | return false; |
| 228 | } else if (!publicAddresses.equals(other.publicAddresses)) |
| 229 | return false; |
| 230 | if (hostname == null) { |
| 231 | if (other.hostname != null) |
| 232 | return false; |
| 233 | } else if (!hostname.equals(other.hostname)) |
| 234 | return false; |
| 235 | if (group == null) { |
| 236 | if (other.group != null) |
| 237 | return false; |
| 238 | } else if (!group.equals(other.group)) |
| 239 | return false; |
| 240 | if (imageId == null) { |
| 241 | if (other.imageId != null) |
| 242 | return false; |
| 243 | } else if (!imageId.equals(other.imageId)) |
| 244 | return false; |
| 245 | if (hardware == null) { |
| 246 | if (other.hardware != null) |
| 247 | return false; |
| 248 | } else if (!hardware.equals(other.hardware)) |
| 249 | return false; |
| 250 | if (os == null) { |
| 251 | if (other.os != null) |
| 252 | return false; |
| 253 | } else if (!os.equals(other.os)) |
| 254 | return false; |
| 255 | if (adminPassword == null) { |
| 256 | if (other.adminPassword != null) |
| 257 | return false; |
| 258 | } else if (!adminPassword.equals(other.adminPassword)) |
| 259 | return false; |
| 260 | if (credentials == null) { |
| 261 | if (other.credentials != null) |
| 262 | return false; |
| 263 | } else if (!credentials.equals(other.credentials)) |
| 264 | return false; |
| 265 | return true; |
| 266 | } |
| 267 | |
| 268 | } |