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