| 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.cloudservers.domain; |
| 20 | |
| 21 | import java.util.Map; |
| 22 | |
| 23 | import com.google.common.collect.Maps; |
| 24 | |
| 25 | /** |
| 26 | * A server is a virtual machine instance in the Cloud Servers system. Flavor and image are |
| 27 | * requisite elements when creating a server. |
| 28 | * |
| 29 | * @author Adrian Cole |
| 30 | */ |
| 31 | public class Server { |
| 32 | private int id; |
| 33 | private String name; |
| 34 | private Map<String, String> metadata = Maps.newHashMap(); |
| 35 | private Addresses addresses; |
| 36 | private String adminPass; |
| 37 | private Integer flavorId; |
| 38 | private String hostId; |
| 39 | private Integer imageId; |
| 40 | private Integer sharedIpGroupId; |
| 41 | private Integer progress; |
| 42 | private ServerStatus status; |
| 43 | |
| 44 | public Server() { |
| 45 | } |
| 46 | |
| 47 | public Server(int id, String name) { |
| 48 | this.id = id; |
| 49 | this.name = name; |
| 50 | } |
| 51 | |
| 52 | public void setMetadata(Map<String, String> metadata) { |
| 53 | this.metadata = metadata; |
| 54 | } |
| 55 | |
| 56 | public Map<String, String> getMetadata() { |
| 57 | return metadata; |
| 58 | } |
| 59 | |
| 60 | public void setAddresses(Addresses addresses) { |
| 61 | this.addresses = addresses; |
| 62 | } |
| 63 | |
| 64 | public Addresses getAddresses() { |
| 65 | return addresses; |
| 66 | } |
| 67 | |
| 68 | public void setAdminPass(String adminPass) { |
| 69 | this.adminPass = adminPass; |
| 70 | } |
| 71 | |
| 72 | public String getAdminPass() { |
| 73 | return adminPass; |
| 74 | } |
| 75 | |
| 76 | public void setFlavorId(Integer flavorId) { |
| 77 | this.flavorId = flavorId; |
| 78 | } |
| 79 | |
| 80 | public Integer getFlavorId() { |
| 81 | return flavorId; |
| 82 | } |
| 83 | |
| 84 | public void setHostId(String hostId) { |
| 85 | this.hostId = hostId; |
| 86 | } |
| 87 | |
| 88 | /** |
| 89 | * The Cloud Servers provisioning algorithm has an anti-affinity property that attempts to spread |
| 90 | * out customer VMs across hosts. Under certain situations, VMs from the same customer may be |
| 91 | * placed on the same host. hostId represents the host your cloud server runs on and can be used |
| 92 | * to determine this scenario if it's relevant to your application. |
| 93 | * <p/> |
| 94 | * Note: hostId is unique PER ACCOUNT and is not globally unique. |
| 95 | */ |
| 96 | public String getHostId() { |
| 97 | return hostId; |
| 98 | } |
| 99 | |
| 100 | public int getId() { |
| 101 | return id; |
| 102 | } |
| 103 | |
| 104 | public void setImageId(Integer imageId) { |
| 105 | this.imageId = imageId; |
| 106 | } |
| 107 | |
| 108 | public Integer getImageId() { |
| 109 | return imageId; |
| 110 | } |
| 111 | |
| 112 | public String getName() { |
| 113 | return name; |
| 114 | } |
| 115 | |
| 116 | public void setProgress(Integer progress) { |
| 117 | this.progress = progress; |
| 118 | } |
| 119 | |
| 120 | public Integer getProgress() { |
| 121 | return progress; |
| 122 | } |
| 123 | |
| 124 | public void setSharedIpGroupId(Integer sharedIpGroupId) { |
| 125 | this.sharedIpGroupId = sharedIpGroupId; |
| 126 | } |
| 127 | |
| 128 | public Integer getSharedIpGroupId() { |
| 129 | return sharedIpGroupId; |
| 130 | } |
| 131 | |
| 132 | public void setStatus(ServerStatus status) { |
| 133 | this.status = status; |
| 134 | } |
| 135 | |
| 136 | /** |
| 137 | * Servers contain a status attribute that can be used as an indication of the current server |
| 138 | * state. Servers with an ACTIVE status are available for use. |
| 139 | */ |
| 140 | public ServerStatus getStatus() { |
| 141 | return status; |
| 142 | } |
| 143 | |
| 144 | @Override |
| 145 | public int hashCode() { |
| 146 | final int prime = 31; |
| 147 | int result = 1; |
| 148 | result = prime * result + ((addresses == null) ? 0 : addresses.hashCode()); |
| 149 | result = prime * result + ((adminPass == null) ? 0 : adminPass.hashCode()); |
| 150 | result = prime * result + ((flavorId == null) ? 0 : flavorId.hashCode()); |
| 151 | result = prime * result + ((hostId == null) ? 0 : hostId.hashCode()); |
| 152 | result = prime * result + id; |
| 153 | result = prime * result + ((imageId == null) ? 0 : imageId.hashCode()); |
| 154 | result = prime * result + ((metadata == null) ? 0 : metadata.hashCode()); |
| 155 | result = prime * result + ((name == null) ? 0 : name.hashCode()); |
| 156 | result = prime * result + ((sharedIpGroupId == null) ? 0 : sharedIpGroupId.hashCode()); |
| 157 | return result; |
| 158 | } |
| 159 | |
| 160 | @Override |
| 161 | public boolean equals(Object obj) { |
| 162 | if (this == obj) |
| 163 | return true; |
| 164 | if (obj == null) |
| 165 | return false; |
| 166 | if (getClass() != obj.getClass()) |
| 167 | return false; |
| 168 | Server other = (Server) obj; |
| 169 | if (addresses == null) { |
| 170 | if (other.addresses != null) |
| 171 | return false; |
| 172 | } else if (!addresses.equals(other.addresses)) |
| 173 | return false; |
| 174 | if (adminPass == null) { |
| 175 | if (other.adminPass != null) |
| 176 | return false; |
| 177 | } else if (!adminPass.equals(other.adminPass)) |
| 178 | return false; |
| 179 | if (flavorId == null) { |
| 180 | if (other.flavorId != null) |
| 181 | return false; |
| 182 | } else if (!flavorId.equals(other.flavorId)) |
| 183 | return false; |
| 184 | if (hostId == null) { |
| 185 | if (other.hostId != null) |
| 186 | return false; |
| 187 | } else if (!hostId.equals(other.hostId)) |
| 188 | return false; |
| 189 | if (id != other.id) |
| 190 | return false; |
| 191 | if (imageId == null) { |
| 192 | if (other.imageId != null) |
| 193 | return false; |
| 194 | } else if (!imageId.equals(other.imageId)) |
| 195 | return false; |
| 196 | if (metadata == null) { |
| 197 | if (other.metadata != null) |
| 198 | return false; |
| 199 | } else if (!metadata.equals(other.metadata)) |
| 200 | return false; |
| 201 | if (name == null) { |
| 202 | if (other.name != null) |
| 203 | return false; |
| 204 | } else if (!name.equals(other.name)) |
| 205 | return false; |
| 206 | if (sharedIpGroupId == null) { |
| 207 | if (other.sharedIpGroupId != null) |
| 208 | return false; |
| 209 | } else if (!sharedIpGroupId.equals(other.sharedIpGroupId)) |
| 210 | return false; |
| 211 | return true; |
| 212 | } |
| 213 | |
| 214 | public void setName(String name) { |
| 215 | this.name = name; |
| 216 | } |
| 217 | |
| 218 | @Override |
| 219 | public String toString() { |
| 220 | return "Server [addresses=" + addresses + ", adminPass=" + adminPass + ", flavorId=" |
| 221 | + flavorId + ", hostId=" + hostId + ", id=" + id + ", imageId=" + imageId |
| 222 | + ", metadata=" + metadata + ", name=" + name + ", sharedIpGroupId=" |
| 223 | + sharedIpGroupId + "]"; |
| 224 | } |
| 225 | |
| 226 | } |