Statistics
| Branch: | Revision:

root / src / com / rackspace / cloud / loadbalancer / api / client / LoadBalancer.java @ 403bb53b

History | View | Annotate | Download (4.9 kB)

1 23bc5e75 Phillip Toohill
/**
2 23bc5e75 Phillip Toohill
 * 
3 23bc5e75 Phillip Toohill
 */
4 23bc5e75 Phillip Toohill
package com.rackspace.cloud.loadbalancer.api.client;
5 23bc5e75 Phillip Toohill
6 23bc5e75 Phillip Toohill
import java.util.ArrayList;
7 23bc5e75 Phillip Toohill
8 4f9d1a69 Adam Menz
import com.rackspace.cloud.servers.api.client.Account;
9 4f9d1a69 Adam Menz
10 4f9d1a69 Adam Menz
import android.util.Log;
11 4f9d1a69 Adam Menz
12 aeff0a62 Adam Menz
13 23bc5e75 Phillip Toohill
public class LoadBalancer extends Entity {
14 23bc5e75 Phillip Toohill
15 23bc5e75 Phillip Toohill
        private static final long serialVersionUID = 5994739895998309675L;
16 23bc5e75 Phillip Toohill
        private String id;
17 23bc5e75 Phillip Toohill
        private String name;
18 23bc5e75 Phillip Toohill
        private String protocol;
19 23bc5e75 Phillip Toohill
        private String port;
20 23bc5e75 Phillip Toohill
        private String algorithm;
21 23bc5e75 Phillip Toohill
        private String status;
22 23bc5e75 Phillip Toohill
        private String isConnectionLoggingEnabled;
23 23bc5e75 Phillip Toohill
        private String created;
24 23bc5e75 Phillip Toohill
        private String updated;
25 23bc5e75 Phillip Toohill
        private String sessionPersistence;
26 23bc5e75 Phillip Toohill
        private String clusterName;
27 4f9d1a69 Adam Menz
        private String virtualIpType;
28 4f9d1a69 Adam Menz
        private String region;
29 23bc5e75 Phillip Toohill
        private ConnectionThrottle connectionThrottle;
30 23bc5e75 Phillip Toohill
        private ArrayList<VirtualIp> virtualIps;
31 23bc5e75 Phillip Toohill
        private ArrayList<Node> nodes;
32 23bc5e75 Phillip Toohill
        
33 4f9d1a69 Adam Menz
        public static String getRegionUrl(String region){
34 4f9d1a69 Adam Menz
                if(region.equals("ORD")){
35 1b82ddb3 Adam Menz
                        return Account.getLoadBalancerORDUrl();
36 403bb53b Adam Menz
                } else if(region.equals("DFW")){
37 1b82ddb3 Adam Menz
                        return Account.getLoadBalancerDFWUrl();
38 403bb53b Adam Menz
                } else if(region.equals("LON")){
39 403bb53b Adam Menz
                        return Account.getLoadBalancerLONUrl();
40 403bb53b Adam Menz
                } else {
41 4f9d1a69 Adam Menz
                        return "";
42 4f9d1a69 Adam Menz
                }
43 4f9d1a69 Adam Menz
        }
44 4f9d1a69 Adam Menz
        
45 23bc5e75 Phillip Toohill
        public String getId() {
46 23bc5e75 Phillip Toohill
                return id;
47 23bc5e75 Phillip Toohill
        }
48 23bc5e75 Phillip Toohill
49 23bc5e75 Phillip Toohill
        public void setId(String id) {
50 23bc5e75 Phillip Toohill
                this.id = id;
51 23bc5e75 Phillip Toohill
        }
52 23bc5e75 Phillip Toohill
53 23bc5e75 Phillip Toohill
        public String getName() {
54 23bc5e75 Phillip Toohill
                return name;
55 23bc5e75 Phillip Toohill
        }
56 23bc5e75 Phillip Toohill
57 23bc5e75 Phillip Toohill
        public void setName(String name) {
58 23bc5e75 Phillip Toohill
                this.name = name;
59 23bc5e75 Phillip Toohill
        }
60 23bc5e75 Phillip Toohill
61 23bc5e75 Phillip Toohill
        public String getProtocol() {
62 23bc5e75 Phillip Toohill
                return protocol;
63 23bc5e75 Phillip Toohill
        }
64 23bc5e75 Phillip Toohill
65 23bc5e75 Phillip Toohill
        public void setProtocol(String protocol) {
66 b722cab3 Adam Menz
                /*
67 b722cab3 Adam Menz
                 * protocol may come in as null if the server
68 b722cab3 Adam Menz
                 * has been deleted, so need to check if not 
69 b722cab3 Adam Menz
                 * null
70 b722cab3 Adam Menz
                 */
71 b722cab3 Adam Menz
                if(protocol != null){
72 b722cab3 Adam Menz
                        this.protocol = protocol.toUpperCase();
73 b722cab3 Adam Menz
                } else {
74 b722cab3 Adam Menz
                        this.protocol = "";
75 b722cab3 Adam Menz
                }
76 23bc5e75 Phillip Toohill
        }
77 23bc5e75 Phillip Toohill
78 23bc5e75 Phillip Toohill
        public String getPort() {
79 23bc5e75 Phillip Toohill
                return port;
80 23bc5e75 Phillip Toohill
        }
81 23bc5e75 Phillip Toohill
82 23bc5e75 Phillip Toohill
        public void setPort(String port) {
83 23bc5e75 Phillip Toohill
                this.port = port;
84 23bc5e75 Phillip Toohill
        }
85 23bc5e75 Phillip Toohill
86 23bc5e75 Phillip Toohill
        public String getAlgorithm() {
87 23bc5e75 Phillip Toohill
                return algorithm;
88 23bc5e75 Phillip Toohill
        }
89 23bc5e75 Phillip Toohill
90 23bc5e75 Phillip Toohill
        public void setAlgorithm(String algorithm) {
91 23bc5e75 Phillip Toohill
                this.algorithm = algorithm;
92 23bc5e75 Phillip Toohill
        }
93 23bc5e75 Phillip Toohill
94 23bc5e75 Phillip Toohill
        public String getStatus() {
95 23bc5e75 Phillip Toohill
                return status;
96 23bc5e75 Phillip Toohill
        }
97 23bc5e75 Phillip Toohill
98 23bc5e75 Phillip Toohill
        public void setStatus(String status) {
99 23bc5e75 Phillip Toohill
                this.status = status;
100 23bc5e75 Phillip Toohill
        }
101 23bc5e75 Phillip Toohill
102 23bc5e75 Phillip Toohill
        public String getIsConnectionLoggingEnabled() {
103 23bc5e75 Phillip Toohill
                return isConnectionLoggingEnabled;
104 23bc5e75 Phillip Toohill
        }
105 23bc5e75 Phillip Toohill
106 23bc5e75 Phillip Toohill
        public void setIsConnectionLoggingEnabled(String isConnectionLoggingEnabled) {
107 23bc5e75 Phillip Toohill
                this.isConnectionLoggingEnabled = isConnectionLoggingEnabled;
108 23bc5e75 Phillip Toohill
        }
109 23bc5e75 Phillip Toohill
        
110 23bc5e75 Phillip Toohill
        public String getCreated() {
111 23bc5e75 Phillip Toohill
                return created;
112 23bc5e75 Phillip Toohill
        }
113 23bc5e75 Phillip Toohill
114 23bc5e75 Phillip Toohill
        public void setCreated(String created) {
115 23bc5e75 Phillip Toohill
                this.created = created;
116 23bc5e75 Phillip Toohill
        }
117 23bc5e75 Phillip Toohill
118 23bc5e75 Phillip Toohill
        public String getUpdated() {
119 23bc5e75 Phillip Toohill
                return updated;
120 23bc5e75 Phillip Toohill
        }
121 23bc5e75 Phillip Toohill
122 23bc5e75 Phillip Toohill
        public void setUpdated(String updated) {
123 23bc5e75 Phillip Toohill
                this.updated = updated;
124 23bc5e75 Phillip Toohill
        }
125 23bc5e75 Phillip Toohill
126 23bc5e75 Phillip Toohill
        public String getSessionPersistence() {
127 23bc5e75 Phillip Toohill
                return sessionPersistence;
128 23bc5e75 Phillip Toohill
        }
129 23bc5e75 Phillip Toohill
130 23bc5e75 Phillip Toohill
        public void setSessionPersistence(String sessionPersistence) {
131 23bc5e75 Phillip Toohill
                this.sessionPersistence = sessionPersistence;
132 23bc5e75 Phillip Toohill
        }
133 23bc5e75 Phillip Toohill
134 23bc5e75 Phillip Toohill
        public String getClusterName() {
135 23bc5e75 Phillip Toohill
                return clusterName;
136 23bc5e75 Phillip Toohill
        }
137 23bc5e75 Phillip Toohill
138 23bc5e75 Phillip Toohill
        public void setClusterName(String clusterName) {
139 23bc5e75 Phillip Toohill
                this.clusterName = clusterName;
140 23bc5e75 Phillip Toohill
        }
141 23bc5e75 Phillip Toohill
142 23bc5e75 Phillip Toohill
        public ConnectionThrottle getConnectionThrottle() {
143 23bc5e75 Phillip Toohill
                return connectionThrottle;
144 23bc5e75 Phillip Toohill
        }
145 23bc5e75 Phillip Toohill
146 23bc5e75 Phillip Toohill
        public void setConnectionThrottle(ConnectionThrottle connectionThrottle) {
147 23bc5e75 Phillip Toohill
                this.connectionThrottle = connectionThrottle;
148 23bc5e75 Phillip Toohill
        }
149 23bc5e75 Phillip Toohill
150 23bc5e75 Phillip Toohill
        public ArrayList<VirtualIp> getVirtualIps() {
151 23bc5e75 Phillip Toohill
                return virtualIps;
152 23bc5e75 Phillip Toohill
        }
153 23bc5e75 Phillip Toohill
154 23bc5e75 Phillip Toohill
        public void setVirtualIps(ArrayList<VirtualIp> virtualIps) {
155 23bc5e75 Phillip Toohill
                this.virtualIps = virtualIps;
156 23bc5e75 Phillip Toohill
        }
157 23bc5e75 Phillip Toohill
158 23bc5e75 Phillip Toohill
        public ArrayList<Node> getNodes() {
159 23bc5e75 Phillip Toohill
                return nodes;
160 23bc5e75 Phillip Toohill
        }
161 23bc5e75 Phillip Toohill
162 23bc5e75 Phillip Toohill
        public void setNodes(ArrayList<Node> nodes) {
163 23bc5e75 Phillip Toohill
                this.nodes = nodes;
164 23bc5e75 Phillip Toohill
        }
165 4f9d1a69 Adam Menz
        
166 4f9d1a69 Adam Menz
        public String getVirtualIpType(){
167 4f9d1a69 Adam Menz
                return virtualIpType;
168 4f9d1a69 Adam Menz
        }
169 4f9d1a69 Adam Menz
        
170 b722cab3 Adam Menz
        public void setVirtualIpType(String virtualIpType){
171 b722cab3 Adam Menz
                /*
172 b722cab3 Adam Menz
                 * protocol may come in as null if the server
173 b722cab3 Adam Menz
                 * has been deleted, so need to check if not 
174 b722cab3 Adam Menz
                 * null
175 b722cab3 Adam Menz
                 */
176 b722cab3 Adam Menz
                if(virtualIpType != null){
177 b722cab3 Adam Menz
                    this.virtualIpType = virtualIpType.toUpperCase();
178 b722cab3 Adam Menz
                } else {
179 b722cab3 Adam Menz
                        this.virtualIpType = "";
180 b722cab3 Adam Menz
                }
181 4f9d1a69 Adam Menz
        }
182 4f9d1a69 Adam Menz
        
183 4f9d1a69 Adam Menz
        public String getRegion(){
184 4f9d1a69 Adam Menz
                return region;
185 4f9d1a69 Adam Menz
        }
186 4f9d1a69 Adam Menz
        
187 b722cab3 Adam Menz
        public void setRegion(String region){
188 b722cab3 Adam Menz
                this.region = region;
189 4f9d1a69 Adam Menz
        }
190 23bc5e75 Phillip Toohill
191 23bc5e75 Phillip Toohill
        public static long getSerialversionuid() {
192 23bc5e75 Phillip Toohill
                return serialVersionUID;
193 23bc5e75 Phillip Toohill
        }
194 23bc5e75 Phillip Toohill
        
195 23bc5e75 Phillip Toohill
        public String toXML() {
196 23bc5e75 Phillip Toohill
                String xml = "";
197 23bc5e75 Phillip Toohill
                xml = "<loadBalancer xmlns=\"http://docs.rackspacecloud.com/loadbalancers/api/v1.0\" name=\""
198 23bc5e75 Phillip Toohill
                                + getName() + "\" id=\"" + getId() + "</loadBalancer>";
199 23bc5e75 Phillip Toohill
                return xml;
200 23bc5e75 Phillip Toohill
        }
201 4f9d1a69 Adam Menz
        
202 4f9d1a69 Adam Menz
        public String toDetailedXML(){
203 4f9d1a69 Adam Menz
                String xml = "<loadBalancer xmlns=\"http://docs.openstack.org/loadbalancers/api/v1.0\"" + 
204 4f9d1a69 Adam Menz
                                                " name=\"" + getName() + "\"" + 
205 4f9d1a69 Adam Menz
                                                " port=\"" + getPort() + "\"" + 
206 4f9d1a69 Adam Menz
                                                " protocol=\"" + getProtocol() + "\"" + 
207 4f9d1a69 Adam Menz
                                                " algorithm=\"" + getAlgorithm() + "\"" + ">" +
208 403bb53b Adam Menz
                                                " <virtualIps>";
209 403bb53b Adam Menz
                                                if(getVirtualIpType().equals("SHARED")){
210 403bb53b Adam Menz
                                                        for(VirtualIp ip : getVirtualIps()){
211 403bb53b Adam Menz
                                                        xml += "<virtualIp id=\"" + ip.getId() + "\"" +  "/>";
212 403bb53b Adam Menz
                                                        }
213 403bb53b Adam Menz
                                                } else {
214 403bb53b Adam Menz
                                                        xml += "<virtualIp type=\"" + getVirtualIpType() + "\"" +  "/>";
215 403bb53b Adam Menz
                                                }
216 403bb53b Adam Menz
                                                xml += " </virtualIps>" + 
217 4f9d1a69 Adam Menz
                                                " <nodes>";
218 4f9d1a69 Adam Menz
                                                for(Node node : getNodes()){
219 4f9d1a69 Adam Menz
                                                        xml += "<node address=\"" + node.getAddress() + "\"" +  " port=\"" + node.getPort() + "\"" + 
220 4f9d1a69 Adam Menz
                                                                        " condition=\"" + node.getCondition() + "\"" +  "/>";
221 4f9d1a69 Adam Menz
                                                }
222 4f9d1a69 Adam Menz
                                xml +=  " </nodes>" +
223 4f9d1a69 Adam Menz
                                                " </loadBalancer>";
224 4f9d1a69 Adam Menz
                Log.d("info", xml);
225 4f9d1a69 Adam Menz
                return xml;
226 4f9d1a69 Adam Menz
        }
227 23bc5e75 Phillip Toohill
}