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