/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/Zone.java

https://github.com/gnodet/jclouds · Java · 401 lines · 282 code · 41 blank · 78 comment · 101 complexity · 6d949cdee374c5eeb2b0373eafd422d0 MD5 · raw file

  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.cloudstack.domain;
  20. import static com.google.common.base.Preconditions.checkNotNull;
  21. import java.util.List;
  22. import javax.annotation.Nullable;
  23. import com.google.common.collect.ImmutableList;
  24. import com.google.gson.annotations.SerializedName;
  25. /**
  26. *
  27. * @author Adrian Cole
  28. */
  29. public class Zone implements Comparable<Zone> {
  30. public static Builder builder() {
  31. return new Builder();
  32. }
  33. public static class Builder {
  34. private long id;
  35. private String description;
  36. private String displayText;
  37. private List<String> DNS = ImmutableList.of();
  38. private String domain;
  39. private long domainId;
  40. private String guestCIDRAddress;
  41. private List<String> internalDNS = ImmutableList.of();
  42. private String name;
  43. private NetworkType networkType;
  44. private String status;
  45. private String VLAN;
  46. private boolean securityGroupsEnabled;
  47. public Builder id(long id) {
  48. this.id = id;
  49. return this;
  50. }
  51. public Builder description(String description) {
  52. this.description = description;
  53. return this;
  54. }
  55. public Builder displayText(String displayText) {
  56. this.displayText = displayText;
  57. return this;
  58. }
  59. public Builder DNS(List<String> DNS) {
  60. this.DNS = ImmutableList.copyOf(checkNotNull(DNS, "DNS"));
  61. return this;
  62. }
  63. public Builder domain(String domain) {
  64. this.domain = domain;
  65. return this;
  66. }
  67. public Builder domainId(long domainId) {
  68. this.domainId = domainId;
  69. return this;
  70. }
  71. public Builder guestCIDRAddress(String guestCIDRAddress) {
  72. this.guestCIDRAddress = guestCIDRAddress;
  73. return this;
  74. }
  75. public Builder internalDNS(List<String> internalDNS) {
  76. this.internalDNS = ImmutableList.copyOf(checkNotNull(internalDNS, "internalDNS"));
  77. return this;
  78. }
  79. public Builder name(String name) {
  80. this.name = name;
  81. return this;
  82. }
  83. public Builder networkType(NetworkType networkType) {
  84. this.networkType = networkType;
  85. return this;
  86. }
  87. public Builder status(String status) {
  88. this.status = status;
  89. return this;
  90. }
  91. public Builder VLAN(String VLAN) {
  92. this.VLAN = VLAN;
  93. return this;
  94. }
  95. public Builder securityGroupsEnabled(boolean securityGroupsEnabled) {
  96. this.securityGroupsEnabled = securityGroupsEnabled;
  97. return this;
  98. }
  99. public Zone build() {
  100. return new Zone(id, description, displayText, DNS, domain, domainId, guestCIDRAddress, internalDNS, name,
  101. networkType, status, VLAN, securityGroupsEnabled);
  102. }
  103. }
  104. private long id;
  105. private String description;
  106. @SerializedName("displaytext")
  107. private String displayText;
  108. @SerializedName("dns1")
  109. private String DNS1;
  110. @SerializedName("dns2")
  111. private String DNS2;
  112. private String domain;
  113. @Nullable
  114. @SerializedName("domainid")
  115. private long domainId;
  116. @SerializedName("guestcidraddress")
  117. private String guestCIDRAddress;
  118. @SerializedName("internaldns1")
  119. private String internalDNS1;
  120. @SerializedName("internaldns2")
  121. private String internalDNS2;
  122. private String name;
  123. @SerializedName("networktype")
  124. private NetworkType networkType;
  125. private String status;
  126. @SerializedName("vlan")
  127. private String VLAN;
  128. @SerializedName("securitygroupsenabled")
  129. private boolean securityGroupsEnabled;
  130. /**
  131. * present only for serializer
  132. *
  133. */
  134. Zone() {
  135. }
  136. public Zone(long id, String description, String displayText, List<String> DNS, String domain, long domainId,
  137. String guestCIDRAddress, List<String> internalDNS, String name, NetworkType networkType, String status,
  138. String vLAN, boolean securityGroupsEnabled) {
  139. this.id = id;
  140. this.description = description;
  141. this.displayText = displayText;
  142. this.DNS1 = checkNotNull(DNS, "DNS").size() > 0 ? DNS.get(0) : null;
  143. this.DNS2 = DNS.size() > 1 ? DNS.get(1) : null;
  144. this.domain = domain;
  145. this.domainId = domainId;
  146. this.guestCIDRAddress = guestCIDRAddress;
  147. this.internalDNS1 = checkNotNull(internalDNS, "internalDNS").size() > 0 ? internalDNS.get(0) : null;
  148. this.internalDNS2 = internalDNS.size() > 1 ? internalDNS.get(1) : null;
  149. this.name = name;
  150. this.networkType = networkType;
  151. this.status = status;
  152. this.VLAN = vLAN;
  153. this.securityGroupsEnabled = securityGroupsEnabled;
  154. }
  155. /**
  156. *
  157. * @return Zone id
  158. */
  159. public long getId() {
  160. return id;
  161. }
  162. /**
  163. *
  164. * @return Zone description
  165. */
  166. public String getDescription() {
  167. return description;
  168. }
  169. /**
  170. *
  171. * @return the display text of the zone
  172. */
  173. public String getDisplayText() {
  174. return displayText;
  175. }
  176. /**
  177. *
  178. * @return the external DNS for the Zone
  179. */
  180. public List<String> getDNS() {
  181. ImmutableList.Builder<String> builder = ImmutableList.builder();
  182. if (DNS1 != null && !"".equals(DNS1))
  183. builder.add(DNS1);
  184. if (DNS2 != null && !"".equals(DNS2))
  185. builder.add(DNS2);
  186. return builder.build();
  187. }
  188. /**
  189. *
  190. * @return Domain name for the Vms in the zone
  191. */
  192. public String getDomain() {
  193. return domain;
  194. }
  195. /**
  196. *
  197. * @return the ID of the containing domain, null for public zones
  198. */
  199. @Nullable
  200. public long getDomainId() {
  201. return domainId;
  202. }
  203. /**
  204. *
  205. * @return the guest CIDR address for the Zone
  206. */
  207. public String getGuestCIDRAddress() {
  208. return guestCIDRAddress;
  209. }
  210. /**
  211. *
  212. * @return the internal DNS for the Zone
  213. */
  214. public List<String> getInternalDNS() {
  215. ImmutableList.Builder<String> builder = ImmutableList.builder();
  216. if (internalDNS1 != null && !"".equals(internalDNS1))
  217. builder.add(internalDNS1);
  218. if (internalDNS2 != null && !"".equals(internalDNS2))
  219. builder.add(internalDNS2);
  220. return builder.build();
  221. }
  222. /**
  223. *
  224. * @return Zone name
  225. */
  226. public String getName() {
  227. return name;
  228. }
  229. /**
  230. *
  231. * @return the network type of the zone; can be Basic or Advanced
  232. */
  233. public NetworkType getNetworkType() {
  234. return networkType;
  235. }
  236. /**
  237. *
  238. * @return
  239. */
  240. public String getStatus() {
  241. return status;
  242. }
  243. /**
  244. *
  245. * @return the vlan range of the zone
  246. */
  247. public String getVLAN() {
  248. return VLAN;
  249. }
  250. /**
  251. *
  252. * @return true if this zone has security groups enabled
  253. */
  254. public boolean isSecurityGroupsEnabled() {
  255. return securityGroupsEnabled;
  256. }
  257. @Override
  258. public int hashCode() {
  259. final int prime = 31;
  260. int result = 1;
  261. result = prime * result + ((DNS1 == null) ? 0 : DNS1.hashCode());
  262. result = prime * result + ((DNS2 == null) ? 0 : DNS2.hashCode());
  263. result = prime * result + ((VLAN == null) ? 0 : VLAN.hashCode());
  264. result = prime * result + ((description == null) ? 0 : description.hashCode());
  265. result = prime * result + ((displayText == null) ? 0 : displayText.hashCode());
  266. result = prime * result + ((domain == null) ? 0 : domain.hashCode());
  267. result = prime * result + (int) (domainId ^ (domainId >>> 32));
  268. result = prime * result + ((guestCIDRAddress == null) ? 0 : guestCIDRAddress.hashCode());
  269. result = prime * result + (int) (id ^ (id >>> 32));
  270. result = prime * result + ((internalDNS1 == null) ? 0 : internalDNS1.hashCode());
  271. result = prime * result + ((internalDNS2 == null) ? 0 : internalDNS2.hashCode());
  272. result = prime * result + ((name == null) ? 0 : name.hashCode());
  273. result = prime * result + ((networkType == null) ? 0 : networkType.hashCode());
  274. result = prime * result + (securityGroupsEnabled ? 1231 : 1237);
  275. return result;
  276. }
  277. @Override
  278. public boolean equals(Object obj) {
  279. if (this == obj)
  280. return true;
  281. if (obj == null)
  282. return false;
  283. if (getClass() != obj.getClass())
  284. return false;
  285. Zone other = (Zone) obj;
  286. if (DNS1 == null) {
  287. if (other.DNS1 != null)
  288. return false;
  289. } else if (!DNS1.equals(other.DNS1))
  290. return false;
  291. if (DNS2 == null) {
  292. if (other.DNS2 != null)
  293. return false;
  294. } else if (!DNS2.equals(other.DNS2))
  295. return false;
  296. if (VLAN == null) {
  297. if (other.VLAN != null)
  298. return false;
  299. } else if (!VLAN.equals(other.VLAN))
  300. return false;
  301. if (description == null) {
  302. if (other.description != null)
  303. return false;
  304. } else if (!description.equals(other.description))
  305. return false;
  306. if (displayText == null) {
  307. if (other.displayText != null)
  308. return false;
  309. } else if (!displayText.equals(other.displayText))
  310. return false;
  311. if (domain == null) {
  312. if (other.domain != null)
  313. return false;
  314. } else if (!domain.equals(other.domain))
  315. return false;
  316. if (domainId != other.domainId)
  317. return false;
  318. if (guestCIDRAddress == null) {
  319. if (other.guestCIDRAddress != null)
  320. return false;
  321. } else if (!guestCIDRAddress.equals(other.guestCIDRAddress))
  322. return false;
  323. if (id != other.id)
  324. return false;
  325. if (internalDNS1 == null) {
  326. if (other.internalDNS1 != null)
  327. return false;
  328. } else if (!internalDNS1.equals(other.internalDNS1))
  329. return false;
  330. if (internalDNS2 == null) {
  331. if (other.internalDNS2 != null)
  332. return false;
  333. } else if (!internalDNS2.equals(other.internalDNS2))
  334. return false;
  335. if (name == null) {
  336. if (other.name != null)
  337. return false;
  338. } else if (!name.equals(other.name))
  339. return false;
  340. if (networkType == null) {
  341. if (other.networkType != null)
  342. return false;
  343. } else if (!networkType.equals(other.networkType))
  344. return false;
  345. if (securityGroupsEnabled != other.securityGroupsEnabled)
  346. return false;
  347. return true;
  348. }
  349. @Override
  350. public String toString() {
  351. return "[id=" + id + ", status=" + status + ", name=" + name + ", description=" + description + ", displayText="
  352. + displayText + ", domain=" + domain + ", domainId=" + domainId + ", networkType=" + networkType
  353. + ", guestCIDRAddress=" + guestCIDRAddress + ", VLAN=" + VLAN + ", DNS=" + getDNS()
  354. + ", securityGroupsEnabled=" + isSecurityGroupsEnabled() + ", internalDNS=" + getInternalDNS() + "]";
  355. }
  356. @Override
  357. public int compareTo(Zone arg0) {
  358. return new Long(id).compareTo(arg0.getId());
  359. }
  360. }