root / src / com / rackspacecloud / android / ViewLoadBalancerActivity.java @ 01340459
History | View | Annotate | Download (19.4 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.LinearLayout; |
28 |
import android.widget.TextView; |
29 |
|
30 |
import com.rackspace.cloud.loadbalancer.api.client.LoadBalancer; |
31 |
import com.rackspace.cloud.loadbalancer.api.client.LoadBalancerManager; |
32 |
import com.rackspace.cloud.loadbalancer.api.client.Node; |
33 |
import com.rackspace.cloud.loadbalancer.api.client.VirtualIp; |
34 |
import com.rackspace.cloud.loadbalancer.api.client.http.LoadBalancersException; |
35 |
import com.rackspace.cloud.servers.api.client.CloudServersException; |
36 |
import com.rackspace.cloud.servers.api.client.http.HttpBundle; |
37 |
|
38 |
public class ViewLoadBalancerActivity extends CloudActivity { |
39 |
|
40 |
private static final int EDIT_LOAD_BALANCER_CODE = 184; |
41 |
private static final int EDIT_NODES_CODE = 185; |
42 |
|
43 |
private LoadBalancer loadBalancer;
|
44 |
private PollLoadBalancerTask pollLoadBalancerTask;
|
45 |
|
46 |
@Override
|
47 |
public void onCreate(Bundle savedInstanceState) { |
48 |
super.onCreate(savedInstanceState);
|
49 |
loadBalancer = (LoadBalancer) this.getIntent().getExtras().get("loadBalancer"); |
50 |
setContentView(R.layout.view_loadbalancer); |
51 |
restoreState(savedInstanceState); |
52 |
} |
53 |
|
54 |
@Override
|
55 |
protected void onSaveInstanceState(Bundle outState) { |
56 |
super.onSaveInstanceState(outState);
|
57 |
outState.putSerializable("loadBalancer", loadBalancer);
|
58 |
} |
59 |
|
60 |
protected void restoreState(Bundle state) { |
61 |
super.restoreState(state);
|
62 |
|
63 |
if (state != null && state.containsKey("loadBalancer") && state.getSerializable("loadBalancer") != null) { |
64 |
loadBalancer = (LoadBalancer) state.getSerializable("loadBalancer");
|
65 |
loadLoadBalancerData(); |
66 |
setUpButtons(); |
67 |
} |
68 |
else{
|
69 |
new LoadLoadBalancerTask().execute((Void[]) null); |
70 |
} |
71 |
} |
72 |
|
73 |
@Override
|
74 |
protected void onDestroy(){ |
75 |
super.onDestroy();
|
76 |
|
77 |
//need to cancel pollLoadBalancerTask so it
|
78 |
//does not keep polling in a new activity
|
79 |
if(pollLoadBalancerTask != null){ |
80 |
pollLoadBalancerTask.cancel(true);
|
81 |
} |
82 |
} |
83 |
|
84 |
private void setupButton(int resourceId, OnClickListener onClickListener) { |
85 |
Button button = (Button) findViewById(resourceId); |
86 |
button.setOnClickListener(onClickListener); |
87 |
} |
88 |
|
89 |
//change the text on the button depending
|
90 |
//on the state of Connection Logging
|
91 |
private void setLogButtonText(){ |
92 |
Button logs = (Button)findViewById(R.id.connection_log_button); |
93 |
String loggingEnabled = loadBalancer.getIsConnectionLoggingEnabled();
|
94 |
if(loggingEnabled != null && loggingEnabled.equals("true")){ |
95 |
logs.setText("Disable Logs");
|
96 |
} else {
|
97 |
logs.setText("Enable Logs");
|
98 |
} |
99 |
} |
100 |
|
101 |
//change the text on the button depending
|
102 |
//on the state of Session Persistence
|
103 |
private void setSessionButtonText(){ |
104 |
Button sessionPersistence = (Button)findViewById(R.id.session_persistence_button); |
105 |
//session persistence is null if it is off
|
106 |
if(loadBalancer.getSessionPersistence() != null){ |
107 |
sessionPersistence.setText("Disable Session Persistence");
|
108 |
} else {
|
109 |
sessionPersistence.setText("Enable Session Persistence");
|
110 |
} |
111 |
} |
112 |
|
113 |
//if the load balancer state contains DELETE
|
114 |
//then parts of it may be null, so use a different
|
115 |
//onClick in that condition
|
116 |
private void setUpButtons(){ |
117 |
setupButton(R.id.edit_loadbalancer_button, new OnClickListener() {
|
118 |
@Override
|
119 |
public void onClick(View v) { |
120 |
if(!loadBalancer.getStatus().contains("DELETE")){ |
121 |
Intent editLoadBalancerIntent = new Intent(getContext(), EditLoadBalancerActivity.class);
|
122 |
editLoadBalancerIntent.putExtra("loadBalancer", loadBalancer);
|
123 |
startActivityForResult(editLoadBalancerIntent, EDIT_LOAD_BALANCER_CODE); |
124 |
} else {
|
125 |
showAlert(loadBalancer.getStatus(), "The load balancer cannot be updated");
|
126 |
} |
127 |
} |
128 |
}); |
129 |
|
130 |
|
131 |
setupButton(R.id.delete_loadbalancer_button, new OnClickListener() {
|
132 |
@Override
|
133 |
public void onClick(View v) { |
134 |
if(!loadBalancer.getStatus().contains("DELETE")){ |
135 |
showDialog(R.id.view_server_delete_button); |
136 |
} else {
|
137 |
showAlert(loadBalancer.getStatus(), "The load balancer cannot be deleted");
|
138 |
} |
139 |
} |
140 |
|
141 |
}); |
142 |
|
143 |
setupButton(R.id.edit_nodes_button, new OnClickListener() {
|
144 |
@Override
|
145 |
public void onClick(View v) { |
146 |
if(!loadBalancer.getStatus().contains("DELETE")){ |
147 |
Intent editLoadBalancerIntent = new Intent(getContext(), EditNodesActivity.class);
|
148 |
editLoadBalancerIntent.putExtra("nodes", loadBalancer.getNodes());
|
149 |
editLoadBalancerIntent.putExtra("loadBalancer", loadBalancer);
|
150 |
startActivityForResult(editLoadBalancerIntent, EDIT_NODES_CODE); |
151 |
} else {
|
152 |
showAlert(loadBalancer.getStatus(), "The nodes cannot be edited");
|
153 |
} |
154 |
} |
155 |
}); |
156 |
|
157 |
setupButton(R.id.connection_log_button, new OnClickListener() {
|
158 |
@Override
|
159 |
public void onClick(View v) { |
160 |
if(!loadBalancer.getStatus().contains("DELETE")){ |
161 |
showDialog(R.id.connection_log_button); |
162 |
} else {
|
163 |
showAlert(loadBalancer.getStatus(), "Log settings cannot be edited.");
|
164 |
} |
165 |
} |
166 |
}); |
167 |
setLogButtonText(); |
168 |
|
169 |
setupButton(R.id.session_persistence_button, new OnClickListener() {
|
170 |
@Override
|
171 |
public void onClick(View v) { |
172 |
if(!loadBalancer.getStatus().contains("DELETE")){ |
173 |
if(!loadBalancer.getProtocol().equals("HTTP")){ |
174 |
showAlert("Error", "Session Persistence cannot be enabled for protocols other than HTTP."); |
175 |
} else {
|
176 |
showDialog(R.id.session_persistence_button); |
177 |
} |
178 |
} else {
|
179 |
showAlert(loadBalancer.getStatus(), "Session Persistence cannot be edited.");
|
180 |
} |
181 |
} |
182 |
}); |
183 |
setSessionButtonText(); |
184 |
} |
185 |
|
186 |
@Override
|
187 |
protected Dialog onCreateDialog(int id) { |
188 |
switch (id) {
|
189 |
case R.id.view_server_delete_button:
|
190 |
return new AlertDialog.Builder(ViewLoadBalancerActivity.this) |
191 |
.setIcon(R.drawable.alert_dialog_icon) |
192 |
.setTitle("Delete Load Balancer")
|
193 |
.setMessage("Are you sure you want to delete the load balancer?")
|
194 |
.setPositiveButton("Delete", new DialogInterface.OnClickListener() { |
195 |
public void onClick(DialogInterface dialog, int whichButton) { |
196 |
new DeleteLoadBalancerTask().execute((Void[]) null); |
197 |
} |
198 |
}) |
199 |
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { |
200 |
public void onClick(DialogInterface dialog, int whichButton) { |
201 |
// do nothing
|
202 |
} |
203 |
}) |
204 |
.create(); |
205 |
case R.id.connection_log_button:
|
206 |
return new AlertDialog.Builder(ViewLoadBalancerActivity.this) |
207 |
.setIcon(R.drawable.alert_dialog_icon) |
208 |
.setTitle("Disable Logs")
|
209 |
.setMessage("Are you sure you want to disable logs for this Load Balancer?")
|
210 |
.setPositiveButton("Enable", new DialogInterface.OnClickListener() { |
211 |
public void onClick(DialogInterface dialog, int whichButton) { |
212 |
new SetLoggingTask().execute();
|
213 |
} |
214 |
}) |
215 |
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { |
216 |
public void onClick(DialogInterface dialog, int whichButton) { |
217 |
// do nothing
|
218 |
} |
219 |
}) |
220 |
.create(); |
221 |
case R.id.session_persistence_button:
|
222 |
return new AlertDialog.Builder(ViewLoadBalancerActivity.this) |
223 |
.setIcon(R.drawable.alert_dialog_icon) |
224 |
.setTitle("Session Persistence")
|
225 |
.setMessage("Are you sure you want to disable session persistence for this Load Balancer?")
|
226 |
.setPositiveButton("Enable", new DialogInterface.OnClickListener() { |
227 |
public void onClick(DialogInterface dialog, int whichButton) { |
228 |
new SessionPersistenceTask().execute();
|
229 |
} |
230 |
}) |
231 |
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { |
232 |
public void onClick(DialogInterface dialog, int whichButton) { |
233 |
// do nothing
|
234 |
} |
235 |
}) |
236 |
.create(); |
237 |
} |
238 |
return null; |
239 |
} |
240 |
|
241 |
@Override
|
242 |
//Need to show different message depending on the state
|
243 |
//of connection_logs/session_persistence
|
244 |
protected void onPrepareDialog(int id, Dialog dialog){ |
245 |
switch (id) {
|
246 |
case R.id.connection_log_button:
|
247 |
String logTitle;
|
248 |
String logMessage;
|
249 |
String logButton;
|
250 |
if(loadBalancer.getIsConnectionLoggingEnabled().equals("true")){ |
251 |
logTitle = "Disable Logs";
|
252 |
logMessage = "Are you sure you want to disable logs for this Load Balancer?";
|
253 |
logButton = "Disable";
|
254 |
} else {
|
255 |
logTitle = "Enable Logs";
|
256 |
logMessage = "Log files will be processed every hour and stored in your Cloud Files account. " +
|
257 |
"Standard Cloud Files storage and transfer fees will be accessed for the use of this feature." +
|
258 |
"\n\nAre you sure you want to enable logs for this Load Balancer?";
|
259 |
logButton = "Enable";
|
260 |
} |
261 |
((AlertDialog)dialog).setTitle(logTitle); |
262 |
((AlertDialog)dialog).setMessage(logMessage); |
263 |
Button sessionLogButton = ((AlertDialog)dialog).getButton(AlertDialog.BUTTON1);
|
264 |
sessionLogButton.setText(logButton); |
265 |
sessionLogButton.invalidate(); |
266 |
break;
|
267 |
case R.id.session_persistence_button:
|
268 |
String sessionMessage;
|
269 |
String sessionButton;
|
270 |
if(loadBalancer.getSessionPersistence() != null){ |
271 |
Log.d("info", "in sessionpersistence != null"); |
272 |
sessionMessage = "Are you sure you want to disable session persistence for this Load Balancer?";
|
273 |
sessionButton = "Disable";
|
274 |
} else {
|
275 |
Log.d("info", "in sessionpersistence == null"); |
276 |
sessionMessage = "Are you sure you want to enable session persistence for this Load Balancer?";
|
277 |
sessionButton = "Enable";
|
278 |
} |
279 |
((AlertDialog)dialog).setMessage(sessionMessage); |
280 |
Button sessionPersistButton = ((AlertDialog)dialog).getButton(AlertDialog.BUTTON1);
|
281 |
sessionPersistButton.setText(sessionButton); |
282 |
sessionPersistButton.invalidate(); |
283 |
break;
|
284 |
} |
285 |
} |
286 |
|
287 |
//Displays all the load balancer data
|
288 |
private void loadLoadBalancerData() { |
289 |
if(loadBalancer != null){ |
290 |
/*
|
291 |
* need to update the text on button if
|
292 |
* it has changed
|
293 |
*/
|
294 |
setLogButtonText(); |
295 |
setSessionButtonText(); |
296 |
|
297 |
|
298 |
TextView name = (TextView) findViewById(R.id.view_name); |
299 |
name.setText(loadBalancer.getName()); |
300 |
|
301 |
TextView id = (TextView) findViewById(R.id.view_lb_id); |
302 |
id.setText(loadBalancer.getId()); |
303 |
|
304 |
TextView protocol = (TextView) findViewById(R.id.view_protocol); |
305 |
protocol.setText(loadBalancer.getProtocol()); |
306 |
|
307 |
TextView port = (TextView) findViewById(R.id.view_port); |
308 |
port.setText(loadBalancer.getPort()); |
309 |
|
310 |
TextView algorithm = (TextView) findViewById(R.id.view_algorithm); |
311 |
algorithm.setText(loadBalancer.getAlgorithm()); |
312 |
|
313 |
TextView status = (TextView) findViewById(R.id.view_status); |
314 |
if (!"ACTIVE".equals(loadBalancer.getStatus())) { |
315 |
status.setText(loadBalancer.getStatus()); |
316 |
pollLoadBalancerTask = new PollLoadBalancerTask();
|
317 |
pollLoadBalancerTask.execute((Void[]) null); |
318 |
} else {
|
319 |
status.setText(loadBalancer.getStatus()); |
320 |
} |
321 |
|
322 |
status.setText(loadBalancer.getStatus()); |
323 |
|
324 |
TextView connectionLogging = (TextView) findViewById(R.id.view_islogging); |
325 |
String isConnectionLogging = loadBalancer.getIsConnectionLoggingEnabled();
|
326 |
if(isConnectionLogging != null && isConnectionLogging.equals("true")){ |
327 |
connectionLogging.setText("Enabled");
|
328 |
} else {
|
329 |
connectionLogging.setText("Disabled");
|
330 |
} |
331 |
|
332 |
loadVirutalIpData(); |
333 |
} |
334 |
} |
335 |
|
336 |
private void loadVirutalIpData() { |
337 |
int layoutIndex = 0; |
338 |
LinearLayout layout = (LinearLayout) this.findViewById(R.id.vip_addresses);
|
339 |
layout.removeAllViews(); |
340 |
ArrayList<VirtualIp> virtualIps = loadBalancer.getVirtualIps();
|
341 |
//maybe null if the lb has been deleted
|
342 |
if(virtualIps != null){ |
343 |
for (int i = 0; i < virtualIps.size(); i++) { |
344 |
TextView tv = new TextView(this.getBaseContext()); |
345 |
tv.setLayoutParams(((TextView)findViewById(R.id.view_port)).getLayoutParams()); // easy quick styling! :)
|
346 |
tv.setTypeface(tv.getTypeface(), 1); // 1 == bold |
347 |
tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, 20);
|
348 |
tv.setTextColor(Color.WHITE);
|
349 |
tv.setText(virtualIps.get(i).getAddress()); |
350 |
layout.addView(tv, layoutIndex++); |
351 |
} |
352 |
} |
353 |
|
354 |
loadNodeData(); |
355 |
} |
356 |
|
357 |
private void loadNodeData() { |
358 |
int layoutIndex = 0; // public IPs start here |
359 |
LinearLayout layout = (LinearLayout) this.findViewById(R.id.node_addresses);
|
360 |
layout.removeAllViews(); |
361 |
ArrayList<Node> nodeIps = loadBalancer.getNodes();
|
362 |
if(nodeIps == null){ |
363 |
nodeIps = new ArrayList<Node>(); |
364 |
} |
365 |
|
366 |
/*
|
367 |
* need to sort the addresses because during polling
|
368 |
* their order can change and the display becomes
|
369 |
* jumpy
|
370 |
*/
|
371 |
ArrayList<String> addresses = new ArrayList<String>(); |
372 |
for(Node n : nodeIps){
|
373 |
addresses.add(n.getAddress()); |
374 |
} |
375 |
|
376 |
Collections.sort(addresses);
|
377 |
|
378 |
//may be null if lb has been deleted
|
379 |
if(nodeIps != null){ |
380 |
for (int i = 0; i < nodeIps.size(); i++) { |
381 |
TextView tv = new TextView(this.getBaseContext()); |
382 |
tv.setLayoutParams(((TextView)findViewById(R.id.view_port)).getLayoutParams()); // easy quick styling! :)
|
383 |
tv.setTypeface(tv.getTypeface(), 1); // 1 == bold |
384 |
tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, 20);
|
385 |
tv.setTextColor(Color.WHITE);
|
386 |
tv.setText(addresses.get(i)); |
387 |
layout.addView(tv, layoutIndex++); |
388 |
} |
389 |
} |
390 |
} |
391 |
|
392 |
//setup menu for when menu button is pressed
|
393 |
public boolean onCreateOptionsMenu(Menu menu) { |
394 |
super.onCreateOptionsMenu(menu);
|
395 |
MenuInflater inflater = getMenuInflater(); |
396 |
inflater.inflate(R.menu.view_loadbalancer_menu, menu); |
397 |
return true; |
398 |
} |
399 |
|
400 |
@Override
|
401 |
public boolean onOptionsItemSelected(MenuItem item) { |
402 |
switch (item.getItemId()) {
|
403 |
case R.id.refresh_loadbalancer:
|
404 |
new LoadLoadBalancerTask().execute((Void[]) null); |
405 |
return true; |
406 |
} |
407 |
return false; |
408 |
} |
409 |
|
410 |
@Override
|
411 |
//have been kicked back from another activity,
|
412 |
//so refresh the load balancer data
|
413 |
public void onActivityResult(int requestCode, int resultCode, Intent data) { |
414 |
super.onActivityResult(requestCode, resultCode, data);
|
415 |
if (resultCode == RESULT_OK) {
|
416 |
new LoadLoadBalancerTask().execute((Void[]) null); |
417 |
} |
418 |
} |
419 |
|
420 |
// HTTP request tasks
|
421 |
private class PollLoadBalancerTask extends AsyncTask<Void, Void, LoadBalancer> { |
422 |
|
423 |
@Override
|
424 |
protected LoadBalancer doInBackground(Void... arg0) { |
425 |
if(pollLoadBalancerTask.isCancelled()){
|
426 |
return null; |
427 |
} |
428 |
try {
|
429 |
loadBalancer = (new LoadBalancerManager(getContext())).getLoadBalancerById(Integer.parseInt(loadBalancer.getId())); |
430 |
} catch (NumberFormatException e) { |
431 |
// we're polling, so need to show exceptions
|
432 |
} catch (LoadBalancersException e) {
|
433 |
// we're polling, so need to show exceptions
|
434 |
} |
435 |
return loadBalancer;
|
436 |
} |
437 |
|
438 |
@Override
|
439 |
protected void onPostExecute(LoadBalancer result) { |
440 |
loadBalancer = result; |
441 |
loadLoadBalancerData(); |
442 |
} |
443 |
} |
444 |
|
445 |
private class LoadLoadBalancerTask extends AsyncTask<Void, Void, LoadBalancer> { |
446 |
|
447 |
private LoadBalancersException exception;
|
448 |
private String loadBalancerId; |
449 |
|
450 |
protected void onPreExecute() { |
451 |
loadBalancerId = loadBalancer.getId(); |
452 |
/*
|
453 |
* set to null, so if config change occurs
|
454 |
* it will be reloaded in onCreate()
|
455 |
*/
|
456 |
loadBalancer = null;
|
457 |
showDialog(); |
458 |
} |
459 |
|
460 |
@Override
|
461 |
protected LoadBalancer doInBackground(Void... arg0) { |
462 |
LoadBalancer result = null;
|
463 |
try {
|
464 |
result = (new LoadBalancerManager(getContext())).getLoadBalancerById(Integer.parseInt(loadBalancerId)); |
465 |
} catch (LoadBalancersException e) {
|
466 |
exception = e; |
467 |
} |
468 |
return result;
|
469 |
} |
470 |
|
471 |
@Override
|
472 |
protected void onPostExecute(LoadBalancer result) { |
473 |
hideDialog(); |
474 |
if (exception != null) { |
475 |
showAlert("Error", exception.getMessage());
|
476 |
} |
477 |
loadBalancer = result; |
478 |
|
479 |
setUpButtons(); |
480 |
loadLoadBalancerData(); |
481 |
} |
482 |
} |
483 |
|
484 |
public class DeleteLoadBalancerTask extends AsyncTask<Void, Void, HttpBundle> { |
485 |
|
486 |
private CloudServersException exception;
|
487 |
|
488 |
@Override
|
489 |
protected void onPreExecute(){ |
490 |
showDialog(); |
491 |
} |
492 |
|
493 |
@Override
|
494 |
protected HttpBundle doInBackground(Void... arg0) { |
495 |
HttpBundle bundle = null;
|
496 |
try {
|
497 |
bundle = (new LoadBalancerManager(getContext())).delete(loadBalancer);
|
498 |
} catch (CloudServersException e) {
|
499 |
exception = e; |
500 |
} |
501 |
return bundle;
|
502 |
} |
503 |
|
504 |
@Override
|
505 |
protected void onPostExecute(HttpBundle bundle) { |
506 |
hideDialog(); |
507 |
HttpResponse response = bundle.getResponse(); |
508 |
if (response != null) { |
509 |
int statusCode = response.getStatusLine().getStatusCode();
|
510 |
if (statusCode == 202) { |
511 |
setResult(Activity.RESULT_OK); |
512 |
finish(); |
513 |
} else {
|
514 |
CloudServersException cse = parseCloudServersException(response); |
515 |
if ("".equals(cse.getMessage())) { |
516 |
showError("There was a problem deleting your load balancer.", bundle);
|
517 |
} else {
|
518 |
showError("There was a problem deleting your load balancer: " + cse.getMessage(), bundle);
|
519 |
} |
520 |
} |
521 |
} else if (exception != null) { |
522 |
showError("There was a problem deleting your load balancer: " + exception.getMessage(), bundle);
|
523 |
} |
524 |
} |
525 |
} |
526 |
|
527 |
|
528 |
private class SetLoggingTask extends AsyncTask<Void, Void, HttpBundle> { |
529 |
|
530 |
private CloudServersException exception;
|
531 |
|
532 |
@Override
|
533 |
protected void onPreExecute(){ |
534 |
showDialog(); |
535 |
} |
536 |
|
537 |
@Override
|
538 |
protected HttpBundle doInBackground(Void... arg0) { |
539 |
HttpBundle bundle = null;
|
540 |
try {
|
541 |
bundle = (new LoadBalancerManager(context)).setLogging(loadBalancer, !Boolean.valueOf(loadBalancer.getIsConnectionLoggingEnabled())); |
542 |
} catch (CloudServersException e) {
|
543 |
exception = e; |
544 |
} |
545 |
return bundle;
|
546 |
} |
547 |
|
548 |
@Override
|
549 |
protected void onPostExecute(HttpBundle bundle) { |
550 |
hideDialog(); |
551 |
HttpResponse response = bundle.getResponse(); |
552 |
if (response != null) { |
553 |
int statusCode = response.getStatusLine().getStatusCode();
|
554 |
if (statusCode == 202 || statusCode == 204) { |
555 |
pollLoadBalancerTask = new PollLoadBalancerTask();
|
556 |
pollLoadBalancerTask.execute((Void[]) null); |
557 |
} else {
|
558 |
CloudServersException cse = parseCloudServersException(response); |
559 |
if ("".equals(cse.getMessage())) { |
560 |
showError("There was a problem changing your log settings.", bundle);
|
561 |
} else {
|
562 |
showError("There was a problem changing your log settings: " + cse.getMessage(), bundle);
|
563 |
} |
564 |
} |
565 |
} else if (exception != null) { |
566 |
showError("There was a problem changing your log settings: " + exception.getMessage(), bundle);
|
567 |
|
568 |
} |
569 |
|
570 |
} |
571 |
} |
572 |
|
573 |
private class SessionPersistenceTask extends AsyncTask<Void, Void, HttpBundle> { |
574 |
|
575 |
private CloudServersException exception;
|
576 |
|
577 |
@Override
|
578 |
protected void onPreExecute(){ |
579 |
showDialog(); |
580 |
} |
581 |
|
582 |
@Override
|
583 |
protected HttpBundle doInBackground(Void... arg0) { |
584 |
HttpBundle bundle = null;
|
585 |
try {
|
586 |
String currentSetting = loadBalancer.getSessionPersistence();
|
587 |
if(currentSetting == null){ |
588 |
bundle = (new LoadBalancerManager(context)).setSessionPersistence(loadBalancer, "HTTP_COOKIE"); |
589 |
} else {
|
590 |
bundle = (new LoadBalancerManager(context)).disableSessionPersistence(loadBalancer);
|
591 |
} |
592 |
} catch (CloudServersException e) {
|
593 |
exception = e; |
594 |
} |
595 |
return bundle;
|
596 |
} |
597 |
|
598 |
@Override
|
599 |
protected void onPostExecute(HttpBundle bundle) { |
600 |
hideDialog(); |
601 |
HttpResponse response = bundle.getResponse(); |
602 |
if (response != null) { |
603 |
int statusCode = response.getStatusLine().getStatusCode();
|
604 |
if (statusCode == 202 || statusCode == 200) { |
605 |
pollLoadBalancerTask = new PollLoadBalancerTask();
|
606 |
pollLoadBalancerTask.execute((Void[]) null); |
607 |
} else {
|
608 |
CloudServersException cse = parseCloudServersException(response); |
609 |
if ("".equals(cse.getMessage())) { |
610 |
showError("There was a problem changing your session persistence settings.", bundle);
|
611 |
} else {
|
612 |
showError("There was a problem changing your session persistence settings: " + cse.getMessage(), bundle);
|
613 |
} |
614 |
} |
615 |
} else if (exception != null) { |
616 |
showError("There was a problem changing your session persistence settings: " + exception.getMessage(), bundle);
|
617 |
|
618 |
} |
619 |
|
620 |
} |
621 |
} |
622 |
|
623 |
|
624 |
} |