2 * Copyright IBM Corporation, 2013. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.controller.samples.loadbalancer.entities;
10 import java.util.ArrayList;
12 import javax.xml.bind.annotation.XmlAccessType;
13 import javax.xml.bind.annotation.XmlAccessorType;
14 import javax.xml.bind.annotation.XmlElement;
15 import javax.xml.bind.annotation.XmlRootElement;
18 * This class represents the pool of hosts among which incoming traffic
19 * will be load balanced. Each pool will load balance the traffic among its pool members
20 * based on the loadbalancing policy set for the pool.
21 * Currently, the pool supports two load balancing policies:
22 * 1. Round Robin Policy{@link org.opendaylight.controller.samples.loadbalancer.policies.RoundRobinLBPolicy}
23 * 2. Random Policy {@link org.opendaylight.controller.samples.loadbalancer.policies.RandomLBPolicy}
25 * NOTE: After creation of the pool, user can't update (change) its load balancing policy.
26 * NOTE: Each Pool should have a unique name.
29 @XmlRootElement(name="pool")
30 @XmlAccessorType(XmlAccessType.NONE)
34 * Unique name of the pool
40 * Associated load balancing policy
42 @XmlElement(name="lbmethod")
43 private String lbMethod;
46 * Status of the pool (active/inactive)
49 private String status;
52 * List of all the VIPs using this pool for load balancing their traffic - more than
53 * one VIP can be mapped to each pool.
56 private ArrayList<VIP> vips = new ArrayList<VIP>();
59 * List of all the pool members used for load balancing the traffic
62 private ArrayList<PoolMember> members = new ArrayList<PoolMember>();
65 * Private constructor used for JAXB mapping
67 @SuppressWarnings("unused")
71 * Getter/ Setter methods
74 public Pool(String name,
77 this.lbMethod = lbMethod;
83 public String getName() {
88 * @param name the name to set
90 public void setName(String name) {
95 * @return the lbMethod
97 public String getLbMethod() {
102 * @param lbMethod the lbMethod to set
104 public void setLbMethod(String lbMethod) {
105 this.lbMethod = lbMethod;
111 public String getStatus() {
116 * @param status the status to set
118 public void setStatus(String status) {
119 this.status = status;
125 public ArrayList<VIP> getAllVip() {
130 * @param vip the vip to set
132 public void setVips(ArrayList<VIP> vips) {
137 * @return the members
139 public ArrayList<PoolMember> getAllMembers() {
144 * @param members the members to set
146 public void setMembers(ArrayList<PoolMember> members) {
147 this.members = members;
151 * Add new VIP to the VIP list
152 * @param vip new VIP to add
154 public void addVIP(VIP vip){
159 * Remove VIP with given name from the VIP list of the pool
160 * @param name Name of the VIP
161 * @return true If VIP was using this pool and removed
162 * false IF VIP is not using this pool
164 public boolean removeVIP(String name){
165 for(VIP vip: this.vips){
166 if(vip.getName().equals(name)){
167 this.vips.remove(vip);
175 * Check if the given pool member is part of this pool
176 * @param pm Search for this pool member
177 * @return true If pool member is attached to this pool
180 public boolean poolMemberExists(PoolMember pm){
181 return this.members.contains(pm);
185 * Returns the pool member with the given name
186 * @param name Search for this pool member
187 * @return PoolMember If pool member is attached to this pool
190 public PoolMember getMember(String name){
192 for(PoolMember pm: this.members){
193 if(pm.getName().equals(name)){
201 * Add new pool member to the pool
202 * @param pm Add this new pool
204 public void addMember(PoolMember pm){
205 this.members.add(pm);
209 * Remove pool member from the pool list
210 * @param name Remove this pool member
211 * @return true If pool member was attached to this pool and successfully removed
212 * false If pool member is not attached to this pool
214 public boolean removeMember(String name){
215 for(PoolMember pm: this.members){
216 if(pm.getName().equals(name)){
217 this.members.remove(pm);
225 * @see java.lang.Object#hashCode()
228 public int hashCode() {
229 final int prime = 31;
231 result = prime * result+ ((lbMethod == null) ? 0 : lbMethod.hashCode());
232 result = prime * result + ((name == null) ? 0 : name.hashCode());
237 * @see java.lang.Object#equals(java.lang.Object)
240 public boolean equals(Object obj) {
247 if (!(obj instanceof Pool)) {
250 Pool other = (Pool) obj;
251 if (lbMethod == null) {
252 if (other.lbMethod != null) {
255 }else if (!lbMethod.equals(other.lbMethod)) {
259 if (other.name != null) {
262 }else if (!name.equals(other.name)) {
269 * @see java.lang.Object#toString()
272 public String toString() {
273 return "Pool [name=" + name + ", lbMethod=" + lbMethod + ", status="
274 + status + ", vips=" + vips + ", members=" + members + "]";