Statistics
| Branch: | Revision:

root / src / com / rackspace / cloud / servers / api / client / Account.java @ 403bb53b

History | View | Annotate | Download (5.4 kB)

1
/**
2
 * 
3
 */
4
package com.rackspace.cloud.servers.api.client;
5

    
6
import com.rackspace.cloud.utils.StringUtils;
7
import com.rackspacecloud.android.Preferences;
8

    
9

    
10

    
11
/**
12
 * @author Mike Mayo - mike.mayo@rackspace.com - twitter.com/greenisus
13
 *
14
 */
15
public class Account implements java.io.Serializable{
16
        
17
        /**
18
         * 
19
         */
20
        private static final long serialVersionUID = 2180740077014156769L;
21
        private String username;
22
        private String apiKey;
23
        private String accountId;
24
        private String authServer;
25
        private String loadBalancerUKUrl;
26
        private String[] loadBalancerRegions;
27
        private static String loadBalancerDFWUrl;
28
        private static String loadBalancerORDUrl;
29
        private static String loadBalancerLONUrl;
30
        private transient String authToken;
31
        private transient String serverUrl;
32
        private transient String storageUrl;
33
        private transient String storageToken;
34
        private transient String cdnManagementUrl;
35
        private transient static Account currentAccount;
36

    
37
        
38
        public static Account getAccount(){
39
                return currentAccount;
40
        }
41
        
42
        public static void setAccount(Account account){
43
                Account.currentAccount = account;
44
        }
45
        
46
        /**
47
         * @return the serverUrl
48
         */
49
        public String getServerUrl() {
50
                return serverUrl;
51
        }
52

    
53
        /**
54
         * @param serverUrl the serverUrl to set
55
         */
56
        public void setServerUrl(String serverUrl) {
57
                this.serverUrl = serverUrl;
58
        }
59

    
60
        /**
61
         * @return the storageUrl
62
         */
63
        public String getStorageUrl() {
64
                return storageUrl;
65
        }
66
        /**
67
         * @return the storageToken
68
         */
69
        public String getStorageToken() {
70
                return storageToken;
71
        }
72
        /**
73
         * @param storageUrl the storageUrl to set
74
         */
75
        public void setStorageUrl(String storageUrl) {
76
                this.storageUrl = storageUrl;
77
        }
78

    
79
        /**
80
         * @return the cdnManagementUrl
81
         */
82
        public String getCdnManagementUrl() {
83
                return cdnManagementUrl;
84
        }
85

    
86
        /**
87
         * @param cdnManagementUrl the cdnManagementUrl to set
88
         */
89
        public void setCdnManagementUrl(String cdnManagementUrl) {
90
                this.cdnManagementUrl = cdnManagementUrl;
91
        }
92

    
93
        /**
94
         * @return the authToken
95
         */
96
        public String getAuthToken() {
97
                return authToken;
98
        }
99

    
100
        /**
101
         * @param authToken the authToken to set
102
         */
103
        public void setAuthToken(String authToken) {
104
                this.authToken = authToken;
105
        }
106

    
107
        /**
108
         * @return the authToken
109
         */
110
        public String getAuthServer() {
111
                return authServer;
112
        }
113

    
114
        /**
115
         * @param authToken the authToken to set
116
         */
117
        public void setAuthServer(String authServer) {
118
                this.authServer = authServer;
119
                
120
                /*
121
                 * the auth server used determines which regions
122
                 * can be used for load balancers, so set available
123
                 * regions here.
124
                 */
125
                if(authServer.equals(Preferences.COUNTRY_UK_AUTH_SERVER)){
126
                        setLoadBalancerRegions(Preferences.UK_REGIONS);
127
                } else if (authServer.equals(Preferences.COUNTRY_US_AUTH_SERVER)){
128
                        setLoadBalancerRegions(Preferences.US_REGIONS);
129
                } else {
130
                        setLoadBalancerRegions(new String[0]);
131
                }
132
        }
133
        
134
        //auth v1.1 should return loadbalancer endpoints and return account id ....
135
        public String getAccountId() {
136
                String delemiter = "v1.0/";
137
                int indexToReturn = 1;
138
                accountId = StringUtils.splitByDelemiter(getServerUrl(), delemiter, indexToReturn);
139
                return accountId;
140
        }
141

    
142
        /**
143
         * @return the loadBalancerDFWUrl
144
         */
145
        public static String getLoadBalancerDFWUrl() {
146
                loadBalancerDFWUrl = "https://dfw.loadbalancers.api.rackspacecloud.com/v1.0/";
147
                return loadBalancerDFWUrl;
148
        }
149

    
150
        /**
151
         * @param loadBalancerDFWUrl the loadBalancerDFWUrl to set
152
         */
153
        public static void setLoadBalancerDFWUrl(String dfwUrl) {
154
                loadBalancerDFWUrl = dfwUrl;
155
        }
156

    
157
        /**
158
         * @return the loadBalancerORDUrl
159
         */
160
        public static String getLoadBalancerORDUrl() {
161
                loadBalancerORDUrl = "https://ord.loadbalancers.api.rackspacecloud.com/v1.0/";
162
                return loadBalancerORDUrl;
163
        }
164

    
165
        /**
166
         * @param loadBalancerORDUrl the loadBalancerORDUrl to set
167
         */
168
        public static void setLoadBalancerORDUrl(String ordUrl) {
169
                loadBalancerORDUrl = ordUrl;
170
        }
171
        
172
        /**
173
         * @return the loadBalancerLONUrl
174
         */
175
        public static String getLoadBalancerLONUrl() {
176
                loadBalancerLONUrl = "https://lon.loadbalancers.api.rackspacecloud.com/v1.0/";
177
                return loadBalancerLONUrl;
178
        }
179

    
180
        /**
181
         * @param loadBalancerLONUrl the loadBalancerORDUrl to set
182
         */
183
        public static void setLoadBalancerLONUrl(String lonUrl) {
184
                loadBalancerLONUrl = lonUrl;
185
        }
186

    
187
        /**
188
         * @return the loadBalancerUKUrl
189
         */
190
        public String getLoadBalancerUKUrl() {
191
                loadBalancerUKUrl = "https://lon.loadbalancers.api.rackspacecloud.com/v1.0/";
192
                return loadBalancerUKUrl;
193
        }
194

    
195
        /**
196
         * @param loadBalancerUKUrl the loadBalancerUKUrl to set
197
         */
198
        public void setLoadBalancerUKUrl(String loadBalancerUKUrl) {
199
                this.loadBalancerUKUrl = loadBalancerUKUrl;
200
        }
201

    
202
        /**
203
         * @return the username
204
         */
205
        public String getUsername() {
206
                return username;
207
        }
208
        
209
        /**
210
         * @param username the username to set
211
         */
212
        public void setUsername(String username) {
213
                this.username = username;
214
        }
215
        
216
        /**
217
         * @return the apiKey
218
         */
219
        public String getApiKey() {
220
                return apiKey;
221
        }
222
        
223
        /**
224
         * @param apiKey the apiKey to set
225
         */
226
        public void setApiKey(String apiKey) {
227
                this.apiKey = apiKey;
228
        }
229
   /**
230
    */
231
        public void setStorageToken(String storageToken) {
232
                this.storageToken = storageToken;
233
        }
234
        
235
        /**
236
         * @return the load balancer regions
237
         */
238
        public String[] getLoadBalancerRegions() {
239
                return loadBalancerRegions;
240
        }
241
        
242
        /**
243
         * @param loadBalancerRegions the load 
244
         * balancer regions to set
245
         */
246
        public void setLoadBalancerRegions(String[] loadBalancerRegions) {
247
                this.loadBalancerRegions = new String[loadBalancerRegions.length];
248
                for(int i = 0 ; i < loadBalancerRegions.length; i++){
249
                        this.loadBalancerRegions[i] = loadBalancerRegions[i];
250
                }
251
        }
252
        
253
}
254