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