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