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