Statistics
| Branch: | Revision:

root / src / com / rackspacecloud / android / ViewLoadBalancerActivity.java @ fee0d4aa

History | View | Annotate | Download (20.6 kB)

1
/**
2
 * 
3
 */
4
package com.rackspacecloud.android;
5

    
6
import java.util.ArrayList;
7
import java.util.Collections;
8

    
9
import org.apache.http.HttpResponse;
10

    
11
import android.app.Activity;
12
import android.app.AlertDialog;
13
import android.app.Dialog;
14
import android.content.DialogInterface;
15
import android.content.Intent;
16
import android.graphics.Color;
17
import android.os.AsyncTask;
18
import android.os.Bundle;
19
import android.util.Log;
20
import android.util.TypedValue;
21
import android.view.Menu;
22
import android.view.MenuInflater;
23
import android.view.MenuItem;
24
import android.view.View;
25
import android.view.View.OnClickListener;
26
import android.widget.Button;
27
import android.widget.HorizontalScrollView;
28
import android.widget.LinearLayout;
29
import android.widget.TextView;
30

    
31
import com.rackspace.cloud.loadbalancer.api.client.LoadBalancer;
32
import com.rackspace.cloud.loadbalancer.api.client.LoadBalancerManager;
33
import com.rackspace.cloud.loadbalancer.api.client.Node;
34
import com.rackspace.cloud.loadbalancer.api.client.VirtualIp;
35
import com.rackspace.cloud.loadbalancer.api.client.http.LoadBalancersException;
36
import com.rackspace.cloud.servers.api.client.CloudServersException;
37
import com.rackspace.cloud.servers.api.client.http.HttpBundle;
38

    
39
public class ViewLoadBalancerActivity extends CloudActivity {
40

    
41
        private static final int EDIT_LOAD_BALANCER_CODE = 184;
42
        private static final int EDIT_NODES_CODE = 185;
43

    
44
        private LoadBalancer loadBalancer;
45
        private PollLoadBalancerTask pollLoadBalancerTask;
46

    
47
        @Override
48
        public void onCreate(Bundle savedInstanceState) {
49
                super.onCreate(savedInstanceState);
50
                loadBalancer = (LoadBalancer) this.getIntent().getExtras().get("loadBalancer");
51
                setContentView(R.layout.view_loadbalancer);
52
                restoreState(savedInstanceState);
53
        }
54

    
55
        @Override
56
        protected void onSaveInstanceState(Bundle outState) {
57
                super.onSaveInstanceState(outState);
58
                outState.putSerializable("loadBalancer", loadBalancer);
59
        }
60

    
61
        protected void restoreState(Bundle state) {
62
                super.restoreState(state);
63

    
64
                if (state != null && state.containsKey("loadBalancer") && state.getSerializable("loadBalancer") != null) {
65
                        loadBalancer = (LoadBalancer) state.getSerializable("loadBalancer");
66
                        loadLoadBalancerData();
67
                        setUpButtons();
68
                }
69
                else{
70
                        new LoadLoadBalancerTask().execute((Void[]) null);
71
                }
72
        }
73

    
74
        @Override
75
        protected void onDestroy(){
76
                super.onDestroy();
77

    
78
                //need to cancel pollLoadBalancerTask so it 
79
                //does not keep polling in a new activity
80
                if(pollLoadBalancerTask != null){
81
                        pollLoadBalancerTask.cancel(true);
82
                }
83
        }
84

    
85
        private void setupButton(int resourceId, OnClickListener onClickListener) {
86
                Button button = (Button) findViewById(resourceId);
87
                button.setOnClickListener(onClickListener);
88
        }
89

    
90
        //change the text on the button depending
91
        //on the state of Connection Logging
92
        private void setLogButtonText(){
93
                Button logs = (Button)findViewById(R.id.connection_log_button);
94
                String loggingEnabled = loadBalancer.getIsConnectionLoggingEnabled();
95
                if(loggingEnabled != null && loggingEnabled.equals("true")){
96
                        logs.setText("Disable Logs");
97
                } else {
98
                        logs.setText("Enable Logs");
99
                }
100
        }
101

    
102
        //change the text on the button depending
103
        //on the state of Session Persistence
104
        private void setSessionButtonText(){
105
                Button sessionPersistence = (Button)findViewById(R.id.session_persistence_button);
106
                //session persistence is null if it is off
107
                if(loadBalancer.getSessionPersistence() != null){
108
                        sessionPersistence.setText("Disable Session Persistence");
109
                } else {
110
                        sessionPersistence.setText("Enable Session Persistence");
111
                }
112
        }
113

    
114
        //if the load balancer state contains DELETE
115
        //then parts of it may be null, so use a different
116
        //onClick in that condition
117
        private void setUpButtons(){
118
                setupButton(R.id.edit_loadbalancer_button, new OnClickListener() {
119
                        @Override
120
                        public void onClick(View v) {
121
                                if(!loadBalancer.getStatus().contains("DELETE")){
122
                                        Intent editLoadBalancerIntent = new Intent(getContext(), EditLoadBalancerActivity.class);
123
                                        editLoadBalancerIntent.putExtra("loadBalancer", loadBalancer);
124
                                        startActivityForResult(editLoadBalancerIntent, EDIT_LOAD_BALANCER_CODE);
125
                                } else {
126
                                        showAlert(loadBalancer.getStatus(), "The load balancer cannot be updated.");
127
                                }
128
                        }
129
                });
130

    
131

    
132
                setupButton(R.id.delete_loadbalancer_button, new OnClickListener() {
133
                        @Override
134
                        public void onClick(View v) {
135
                                if(!loadBalancer.getStatus().contains("DELETE")){
136
                                        showDialog(R.id.view_server_delete_button);
137
                                } else {
138
                                        showAlert(loadBalancer.getStatus(), "The load balancer cannot be deleted.");
139
                                }
140
                        }
141

    
142
                });
143

    
144
                setupButton(R.id.edit_nodes_button, new OnClickListener() {
145
                        @Override
146
                        public void onClick(View v) {
147
                                if(!loadBalancer.getStatus().contains("DELETE")){
148
                                        Intent editLoadBalancerIntent = new Intent(getContext(), EditNodesActivity.class);
149
                                        editLoadBalancerIntent.putExtra("nodes", loadBalancer.getNodes());
150
                                        editLoadBalancerIntent.putExtra("loadBalancer", loadBalancer);
151
                                        startActivityForResult(editLoadBalancerIntent, EDIT_NODES_CODE);
152
                                } else {
153
                                        showAlert(loadBalancer.getStatus(), "The nodes cannot be edited.");
154
                                }
155
                        }
156
                });
157

    
158
                setupButton(R.id.connection_log_button, new OnClickListener() {
159
                        @Override
160
                        public void onClick(View v) {
161
                                if(!loadBalancer.getStatus().contains("DELETE")){
162
                                        showDialog(R.id.connection_log_button);        
163
                                } else {
164
                                        showAlert(loadBalancer.getStatus(), "Log settings cannot be edited.");        
165
                                }
166
                        }
167
                });
168
                setLogButtonText();
169

    
170
                setupButton(R.id.session_persistence_button, new OnClickListener() {
171
                        @Override
172
                        public void onClick(View v) {
173
                                if(!loadBalancer.getStatus().contains("DELETE")){
174
                                        if(!loadBalancer.getProtocol().equals("HTTP")){
175
                                                showAlert("Error", "Session Persistence cannot be enabled for protocols other than HTTP.");
176
                                        } else {
177
                                                showDialog(R.id.session_persistence_button);
178
                                        }
179
                                } else {
180
                                        showAlert(loadBalancer.getStatus(), "Session Persistence cannot be edited.");        
181
                                }
182
                        }
183
                });
184
                setSessionButtonText();
185
        }
186

    
187
        @Override
188
        protected Dialog onCreateDialog(int id) {
189
                switch (id) {
190
                case R.id.view_server_delete_button:
191
                        return new AlertDialog.Builder(ViewLoadBalancerActivity.this)
192
                        .setIcon(R.drawable.alert_dialog_icon)
193
                        .setTitle("Delete Load Balancer")
194
                        .setMessage("Are you sure you want to delete the load balancer?")
195
                        .setPositiveButton("Delete", new DialogInterface.OnClickListener() {
196
                                public void onClick(DialogInterface dialog, int whichButton) {
197
                                        new DeleteLoadBalancerTask().execute((Void[]) null);
198
                                }
199
                        })
200
                        .setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
201
                                public void onClick(DialogInterface dialog, int whichButton) {
202
                                        // do nothing
203
                                }
204
                        })
205
                        .create();
206
                case R.id.connection_log_button:
207
                        return new AlertDialog.Builder(ViewLoadBalancerActivity.this)
208
                        .setIcon(R.drawable.alert_dialog_icon)
209
                        .setTitle("Disable Logs")
210
                        .setMessage("Are you sure you want to disable logs for this Load Balancer?")
211
                        .setPositiveButton("Enable", new DialogInterface.OnClickListener() {
212
                                public void onClick(DialogInterface dialog, int whichButton) {
213
                                        new SetLoggingTask().execute();        
214
                                }
215
                        })
216
                        .setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
217
                                public void onClick(DialogInterface dialog, int whichButton) {
218
                                        // do nothing
219
                                }
220
                        })
221
                        .create();
222
                case R.id.session_persistence_button:
223
                        return new AlertDialog.Builder(ViewLoadBalancerActivity.this)
224
                        .setIcon(R.drawable.alert_dialog_icon)
225
                        .setTitle("Session Persistence")
226
                        .setMessage("Are you sure you want to disable session persistence for this Load Balancer?")
227
                        .setPositiveButton("Enable", new DialogInterface.OnClickListener() {
228
                                public void onClick(DialogInterface dialog, int whichButton) {
229
                                        new SessionPersistenceTask().execute();
230
                                }
231
                        })
232
                        .setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
233
                                public void onClick(DialogInterface dialog, int whichButton) {
234
                                        // do nothing
235
                                }
236
                        })
237
                        .create();
238
                }
239
                return null;
240
        }
241

    
242
        @Override
243
        //Need to show different message depending on the state
244
        //of connection_logs/session_persistence
245
        protected void onPrepareDialog(int id, Dialog dialog){
246
                switch (id) {
247
                case R.id.connection_log_button:
248
                        String logTitle;
249
                        String logMessage;
250
                        String logButton;
251
                        if(loadBalancer.getIsConnectionLoggingEnabled().equals("true")){
252
                                logTitle = "Disable Logs";
253
                                logMessage = "Are you sure you want to disable logs for this Load Balancer?";
254
                                logButton = "Disable";
255
                        } else {
256
                                logTitle = "Enable Logs";
257
                                logMessage = "Log files will be processed every hour and stored in your Cloud Files account. " +
258
                                "Standard Cloud Files storage and transfer fees will be accessed for the use of this feature." +
259
                                "\n\nAre you sure you want to enable logs for this Load Balancer?";
260
                                logButton = "Enable";
261
                        }
262
                        ((AlertDialog)dialog).setTitle(logTitle);
263
                        ((AlertDialog)dialog).setMessage(logMessage);
264
                        Button sessionLogButton = ((AlertDialog)dialog).getButton(AlertDialog.BUTTON1);
265
                        sessionLogButton.setText(logButton);
266
                        sessionLogButton.invalidate();
267
                        break;
268
                case R.id.session_persistence_button:
269
                        String sessionMessage;
270
                        String sessionButton;
271
                        if(loadBalancer.getSessionPersistence() != null){
272
                                Log.d("info", "in sessionpersistence != null");
273
                                sessionMessage = "Are you sure you want to disable session persistence for this Load Balancer?";
274
                                sessionButton = "Disable";
275
                        } else {
276
                                Log.d("info", "in sessionpersistence == null");
277
                                sessionMessage = "Are you sure you want to enable session persistence for this Load Balancer?";
278
                                sessionButton = "Enable";
279
                        }
280
                        ((AlertDialog)dialog).setMessage(sessionMessage);
281
                        Button sessionPersistButton = ((AlertDialog)dialog).getButton(AlertDialog.BUTTON1);
282
                        sessionPersistButton.setText(sessionButton);
283
                        sessionPersistButton.invalidate();
284
                        break;
285
                }
286
        }
287

    
288
        //Displays all the load balancer data
289
        private void loadLoadBalancerData() {
290
                if(loadBalancer != null){
291
                        /*
292
                         * need to update the text on button if 
293
                         * it has changed
294
                         */
295
                        setLogButtonText();
296
                        setSessionButtonText();
297

    
298

    
299
                        TextView name = (TextView) findViewById(R.id.view_name);
300
                        name.setText(loadBalancer.getName());
301

    
302
                        TextView id = (TextView) findViewById(R.id.view_lb_id);
303
                        id.setText(loadBalancer.getId());
304

    
305
                        TextView protocol = (TextView) findViewById(R.id.view_protocol);
306
                        protocol.setText(loadBalancer.getProtocol());
307

    
308
                        TextView port = (TextView) findViewById(R.id.view_port);
309
                        port.setText(loadBalancer.getPort());
310

    
311
                        TextView algorithm = (TextView) findViewById(R.id.view_algorithm);
312
                        algorithm.setText(getPrettyAlgoName(loadBalancer.getAlgorithm()));
313

    
314
                        TextView status = (TextView) findViewById(R.id.view_status);
315
                        if (!"ACTIVE".equals(loadBalancer.getStatus())) {
316
                                status.setText(loadBalancer.getStatus());
317
                                pollLoadBalancerTask = new PollLoadBalancerTask();
318
                                pollLoadBalancerTask.execute((Void[]) null);
319
                        } else {
320
                                status.setText(loadBalancer.getStatus());
321
                        }
322

    
323
                        status.setText(loadBalancer.getStatus());
324

    
325
                        TextView connectionLogging = (TextView) findViewById(R.id.view_islogging);
326
                        String isConnectionLogging = loadBalancer.getIsConnectionLoggingEnabled();
327
                        if(isConnectionLogging != null && isConnectionLogging.equals("true")){
328
                                connectionLogging.setText("Enabled");
329
                        } else {
330
                                connectionLogging.setText("Disabled");
331
                        }
332

    
333
                        loadVirutalIpData();
334
                }
335
        }
336
        
337
        private String getPrettyAlgoName(String name){
338
                if(name == null || name.length() == 0){
339
                        return "";
340
                } else {
341
                        String result = name.charAt(0) + "";
342
                        boolean previousWasSpace = false;;
343
                        for(int i = 1; i < name.length(); i++){
344
                                char curLetter = name.charAt(i);
345
                                if(curLetter == '_'){
346
                                        result += " ";
347
                                        previousWasSpace = true;
348
                                } else {
349
                                        if(previousWasSpace){
350
                                                result += Character.toUpperCase(curLetter);
351
                                        } else {
352
                                                result += Character.toLowerCase(curLetter);
353
                                        }
354
                                        previousWasSpace = false;
355
                                }
356
                        }
357
                        return result;
358
                }
359
        }
360

    
361
        private void loadVirutalIpData() {
362
                int layoutIndex = 0;
363
                LinearLayout layout = (LinearLayout) this.findViewById(R.id.vip_addresses);    
364
                layout.removeAllViews();
365
                ArrayList<VirtualIp> virtualIps = loadBalancer.getVirtualIps();
366
                //maybe null if the lb has been deleted
367
                if(virtualIps != null){
368
                        for (int i = 0; i < virtualIps.size(); i++) {
369
                                TextView tv = new TextView(this.getBaseContext());
370
                                //tv.setLayoutParams(((TextView)findViewById(R.id.view_port)).getLayoutParams()); // easy quick styling! :)
371
                                tv.setTypeface(tv.getTypeface(), 1); // 1 == bold
372
                                tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, 20);
373
                                tv.setTextColor(Color.WHITE);
374
                                tv.setText(virtualIps.get(i).getAddress());
375
                                HorizontalScrollView scroll = new HorizontalScrollView(this.getBaseContext());
376
                                scroll.setLayoutParams(((TextView)findViewById(R.id.view_port)).getLayoutParams()); // easy quick styling! :)
377
                                scroll.setScrollbarFadingEnabled(true);
378
                                scroll.addView(tv);
379
                                layout.addView(scroll, layoutIndex++);
380
                        }
381
                }
382

    
383
                loadNodeData();
384
        }
385

    
386
        private void loadNodeData() {
387
                int layoutIndex = 0; // public IPs start here
388
                LinearLayout layout = (LinearLayout) this.findViewById(R.id.node_addresses);   
389
                layout.removeAllViews();
390
                ArrayList<Node> nodeIps = loadBalancer.getNodes();
391
                if(nodeIps == null){
392
                        nodeIps = new ArrayList<Node>();
393
                }
394

    
395
                /*
396
                 * need to sort the addresses because during polling
397
                 * their order can change and the display becomes
398
                 * jumpy
399
                 */
400
                ArrayList<String> addresses = new ArrayList<String>();
401
                for(Node n : nodeIps){
402
                        addresses.add(n.getAddress());
403
                }
404

    
405
                Collections.sort(addresses);
406

    
407
                //may be null if lb has been deleted
408
                if(nodeIps != null){
409
                        for (int i = 0; i < nodeIps.size(); i++) {
410
                                TextView tv = new TextView(this.getBaseContext());
411
                                tv.setLayoutParams(((TextView)findViewById(R.id.view_port)).getLayoutParams()); // easy quick styling! :)
412
                                tv.setTypeface(tv.getTypeface(), 1); // 1 == bold
413
                                tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, 20);
414
                                tv.setTextColor(Color.WHITE);
415
                                tv.setText(addresses.get(i));
416
                                HorizontalScrollView scroll = new HorizontalScrollView(this.getBaseContext());
417
                                scroll.setLayoutParams(((TextView)findViewById(R.id.view_port)).getLayoutParams()); // easy quick styling! :)
418
                                scroll.setScrollbarFadingEnabled(true);
419
                                scroll.addView(tv);
420
                                layout.addView(scroll, layoutIndex++);
421
                        }
422
                }
423
        }
424

    
425
        //setup menu for when menu button is pressed
426
        public boolean onCreateOptionsMenu(Menu menu) {
427
                super.onCreateOptionsMenu(menu);
428
                MenuInflater inflater = getMenuInflater();
429
                inflater.inflate(R.menu.view_loadbalancer_menu, menu);
430
                return true;
431
        } 
432

    
433
        @Override 
434
        public boolean onOptionsItemSelected(MenuItem item) {
435
                switch (item.getItemId()) {
436
                case R.id.refresh_loadbalancer:
437
                        new LoadLoadBalancerTask().execute((Void[]) null);   
438
                        return true;
439
                }        
440
                return false;
441
        } 
442

    
443
        @Override
444
        //have been kicked back from another activity,
445
        //so refresh the load balancer data
446
        public void onActivityResult(int requestCode, int resultCode, Intent data) {
447
                super.onActivityResult(requestCode, resultCode, data);
448
                if (resultCode == RESULT_OK) {
449
                        new LoadLoadBalancerTask().execute((Void[]) null);   
450
                }
451
        }
452

    
453
        // HTTP request tasks
454
        private class PollLoadBalancerTask extends AsyncTask<Void, Void, LoadBalancer> {
455

    
456
                @Override
457
                protected LoadBalancer doInBackground(Void... arg0) {
458
                        if(pollLoadBalancerTask.isCancelled()){
459
                                return null;
460
                        }
461
                        try {
462
                                loadBalancer = (new LoadBalancerManager(getContext())).getLoadBalancerById(Integer.parseInt(loadBalancer.getId()));
463
                        } catch (NumberFormatException e) {
464
                                // we're polling, so need to show exceptions
465
                        } catch (LoadBalancersException e) {
466
                                // we're polling, so need to show exceptions
467
                        }
468
                        return loadBalancer;
469
                }
470

    
471
                @Override
472
                protected void onPostExecute(LoadBalancer result) {
473
                        loadBalancer = result;
474
                        loadLoadBalancerData();
475
                }
476
        }
477

    
478
        private class LoadLoadBalancerTask extends AsyncTask<Void, Void, LoadBalancer> {
479

    
480
                private LoadBalancersException exception;
481
                private String loadBalancerId;
482

    
483
                protected void onPreExecute() {
484
                        loadBalancerId = loadBalancer.getId();
485
                        /*
486
                         * set to null, so if config change occurs
487
                         * it will be reloaded in onCreate()
488
                         */
489
                        loadBalancer = null;
490
                        showDialog();
491
                }
492

    
493
                @Override
494
                protected LoadBalancer doInBackground(Void... arg0) {
495
                        LoadBalancer result = null;
496
                        try {
497
                                result = (new LoadBalancerManager(getContext())).getLoadBalancerById(Integer.parseInt(loadBalancerId));
498
                        } catch (LoadBalancersException e) {
499
                                exception = e;
500
                        }
501
                        return result;
502
                }
503

    
504
                @Override
505
                protected void onPostExecute(LoadBalancer result) {
506
                        hideDialog();
507
                        if (exception != null) {
508
                                showAlert("Error", exception.getMessage());
509
                        }
510
                        loadBalancer = result;
511

    
512
                        setUpButtons();
513
                        loadLoadBalancerData();
514
                }
515
        } 
516

    
517
        public class DeleteLoadBalancerTask extends AsyncTask<Void, Void, HttpBundle> {
518

    
519
                private CloudServersException exception;
520

    
521
                @Override
522
                protected void onPreExecute(){
523
                        showDialog();
524
                }
525

    
526
                @Override
527
                protected HttpBundle doInBackground(Void... arg0) {
528
                        HttpBundle bundle = null;
529
                        try {
530
                                bundle = (new LoadBalancerManager(getContext())).delete(loadBalancer);
531
                        } catch (CloudServersException e) {
532
                                exception = e;
533
                        }
534
                        return bundle;
535
                }
536

    
537
                @Override
538
                protected void onPostExecute(HttpBundle bundle) {
539
                        hideDialog();
540
                        HttpResponse response = bundle.getResponse();
541
                        if (response != null) {
542
                                int statusCode = response.getStatusLine().getStatusCode();
543
                                if (statusCode == 202) {
544
                                        setResult(Activity.RESULT_OK);
545
                                        finish();
546
                                } else {
547
                                        CloudServersException cse = parseCloudServersException(response);
548
                                        if ("".equals(cse.getMessage())) {
549
                                                showError("There was a problem deleting your load balancer.", bundle);
550
                                        } else {
551
                                                showError("There was a problem deleting your load balancer: " + cse.getMessage(), bundle);
552
                                        }
553
                                }
554
                        } else if (exception != null) {
555
                                showError("There was a problem deleting your load balancer: " + exception.getMessage(), bundle);                                
556
                        }                        
557
                }
558
        }
559

    
560

    
561
        private class SetLoggingTask extends AsyncTask<Void, Void, HttpBundle> {
562

    
563
                private CloudServersException exception;
564

    
565
                @Override
566
                protected void onPreExecute(){
567
                        showDialog();
568
                }
569

    
570
                @Override
571
                protected HttpBundle doInBackground(Void... arg0) {
572
                        HttpBundle bundle = null;        
573
                        try {
574
                                bundle = (new LoadBalancerManager(getContext())).setLogging(loadBalancer, !Boolean.valueOf(loadBalancer.getIsConnectionLoggingEnabled()));
575
                        } catch (CloudServersException e) {
576
                                exception = e;
577
                        }
578
                        return bundle;
579
                }
580

    
581
                @Override
582
                protected void onPostExecute(HttpBundle bundle) {
583
                        hideDialog();
584
                        HttpResponse response = bundle.getResponse();
585
                        if (response != null) {
586
                                int statusCode = response.getStatusLine().getStatusCode();                        
587
                                if (statusCode == 202 || statusCode == 204) {
588
                                        pollLoadBalancerTask = new PollLoadBalancerTask();
589
                                        pollLoadBalancerTask.execute((Void[]) null);
590
                                } else {                                        
591
                                        CloudServersException cse = parseCloudServersException(response);
592
                                        if ("".equals(cse.getMessage())) {
593
                                                showError("There was a problem changing your log settings.", bundle);
594
                                        } else {
595
                                                showError("There was a problem changing your log settings: " + cse.getMessage(), bundle);
596
                                        }                                        
597
                                }
598
                        } else if (exception != null) {
599
                                showError("There was a problem changing your log settings: " + exception.getMessage(), bundle);
600

    
601
                        }
602

    
603
                }
604
        }
605

    
606
        private class SessionPersistenceTask extends AsyncTask<Void, Void, HttpBundle> {
607

    
608
                private CloudServersException exception;
609

    
610
                @Override
611
                protected void onPreExecute(){
612
                        showDialog();
613
                }
614

    
615
                @Override
616
                protected HttpBundle doInBackground(Void... arg0) {
617
                        HttpBundle bundle = null;        
618
                        try {
619
                                String currentSetting = loadBalancer.getSessionPersistence();
620
                                if(currentSetting == null){
621
                                        bundle = (new LoadBalancerManager(getContext())).setSessionPersistence(loadBalancer, "HTTP_COOKIE");
622
                                } else {
623
                                        bundle = (new LoadBalancerManager(getContext())).disableSessionPersistence(loadBalancer);
624
                                }
625
                        } catch (CloudServersException e) {
626
                                exception = e;
627
                        }
628
                        return bundle;
629
                }
630

    
631
                @Override
632
                protected void onPostExecute(HttpBundle bundle) {
633
                        hideDialog();
634
                        HttpResponse response = bundle.getResponse();
635
                        if (response != null) {
636
                                int statusCode = response.getStatusLine().getStatusCode();                        
637
                                if (statusCode == 202 || statusCode == 200) {
638
                                        pollLoadBalancerTask = new PollLoadBalancerTask();
639
                                        pollLoadBalancerTask.execute((Void[]) null);
640
                                } else {                                        
641
                                        CloudServersException cse = parseCloudServersException(response);
642
                                        if ("".equals(cse.getMessage())) {
643
                                                showError("There was a problem changing your session persistence settings.", bundle);
644
                                        } else {
645
                                                showError("There was a problem changing your session persistence settings: " + cse.getMessage(), bundle);
646
                                        }                                        
647
                                }
648
                        } else if (exception != null) {
649
                                showError("There was a problem changing your session persistence settings: " + exception.getMessage(), bundle);
650

    
651
                        }
652

    
653
                }
654
        }
655

    
656

    
657
}