Skip to content
Browse files

added connection throttle to load balancers, and fixed a bug on ListA…

…ccountsActivity
  • Loading branch information...
1 parent fee0d4a commit 16615abdbad1d95fff9885a5b255e10b4539f034 Adam Menz committed Aug 4, 2011
View
1 AndroidManifest.xml
@@ -139,6 +139,7 @@
<activity android:name=".AddMoreNodesActivity"></activity>
<activity android:name=".AddExternalNodeActivity"></activity>
<activity android:name=".SharedVipActivity"></activity>
+ <activity android:name=".ConnectionThrottleActivity"></activity>
View
94 res/layout/connectionthrottle.xml
@@ -0,0 +1,94 @@
+<?xml version="1.0" encoding="utf-8"?>
+<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
+ android:orientation="vertical" android:layout_width="fill_parent"
+ android:layout_height="fill_parent">
+ <LinearLayout android:layout_width="fill_parent"
+ android:layout_height="wrap_content" android:id="@+id/linearLayout1"
+ android:orientation="vertical">
+ <TextView android:layout_width="wrap_content"
+ android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceLarge"
+ android:id="@+id/textView1" android:text="Connection Throttle"
+ android:layout_marginLeft="5dip" android:layout_marginTop="5dip"></TextView>
+ <LinearLayout android:layout_width="fill_parent"
+ android:layout_height="wrap_content" android:orientation="vertical"
+ android:id="@+id/min_connections_layout">
+ <TextView android:layout_width="wrap_content"
+ android:layout_height="wrap_content" android:layout_marginLeft="5dip"
+ android:text="Min Connections" android:textAppearance="?android:attr/textAppearanceSmall"
+ android:id="@+id/textView2" android:layout_marginTop="10dip"></TextView>
+ <EditText android:layout_width="fill_parent"
+ android:layout_height="wrap_content" android:layout_marginLeft="22dip"
+ android:inputType="number" android:layout_marginRight="30dip"
+ android:id="@+id/min_connections_text" android:lines="1" android:scrollHorizontally="true"></EditText>
+ <TextView android:layout_width="wrap_content"
+ android:layout_height="wrap_content" android:layout_marginLeft="22dip"
+ android:textSize="11dip"
+ android:text="Minimum number of simultaneous connections from a single IP address before applying restrictions."
+ android:textAppearance="?android:attr/textAppearanceSmall"
+ android:id="@+id/textView3" android:layout_marginRight="30dip"></TextView>
+ </LinearLayout>
+ <LinearLayout android:layout_width="fill_parent"
+ android:orientation="vertical" android:layout_height="wrap_content"
+ android:id="@+id/max_connections_per_ip_layout">
+ <TextView android:layout_width="wrap_content"
+ android:layout_height="wrap_content" android:layout_marginLeft="5dip"
+ android:textAppearance="?android:attr/textAppearanceSmall"
+ android:id="@+id/TextView01" android:layout_marginTop="10dip"
+ android:text="Max Connections Per IP"></TextView>
+ <EditText android:layout_width="fill_parent"
+ android:layout_height="wrap_content" android:layout_marginLeft="22dip"
+ android:inputType="number" android:layout_marginRight="30dip"
+ android:id="@+id/max_connections_text" android:lines="1" android:scrollHorizontally="true"></EditText>
+ <TextView android:layout_width="wrap_content"
+ android:layout_height="wrap_content" android:layout_marginLeft="22dip"
+ android:textSize="11dip" android:textAppearance="?android:attr/textAppearanceSmall"
+ android:id="@+id/TextView02" android:layout_marginRight="30dip"
+ android:text="Maximum simultaneous connections from a single IP address."></TextView>
+ </LinearLayout>
+ <LinearLayout android:layout_width="fill_parent"
+ android:orientation="vertical" android:layout_height="wrap_content"
+ android:id="@+id/max_connection_rate_layout">
+ <TextView android:layout_width="wrap_content"
+ android:layout_height="wrap_content" android:layout_marginLeft="5dip"
+ android:textAppearance="?android:attr/textAppearanceSmall"
+ android:id="@+id/TextView04" android:layout_marginTop="10dip"
+ android:text="Max Connection Rate"></TextView>
+ <LinearLayout android:layout_width="fill_parent"
+ android:layout_height="wrap_content" android:id="@+id/linearLayout2">
+ <EditText android:layout_height="wrap_content"
+ android:layout_marginLeft="22dip" android:inputType="number"
+ android:id="@+id/max_connection_rate" android:layout_width="150dip" android:lines="1" android:scrollHorizontally="true">
+ <requestFocus></requestFocus>
+ </EditText>
+ <TextView android:layout_weight="1" android:layout_width="wrap_content"
+ android:layout_height="wrap_content" android:id="@+id/TextView03"
+ android:layout_marginRight="30dip" android:text="Connections"
+ android:textSize="15dip" android:layout_marginLeft="3dip"></TextView>
+ </LinearLayout>
+ </LinearLayout>
+ <LinearLayout android:layout_width="fill_parent"
+ android:orientation="vertical" android:layout_height="wrap_content"
+ android:id="@+id/rate_interval_layout">
+ <TextView android:layout_width="wrap_content"
+ android:layout_height="wrap_content" android:layout_marginLeft="5dip"
+ android:textAppearance="?android:attr/textAppearanceSmall"
+ android:id="@+id/TextView05" android:layout_marginTop="10dip" android:text="Rate Interval"></TextView>
+ <LinearLayout android:layout_width="fill_parent"
+ android:layout_height="wrap_content" android:id="@+id/LinearLayout01">
+ <EditText android:layout_height="wrap_content"
+ android:layout_marginLeft="22dip" android:inputType="number"
+ android:id="@+id/rate_interval" android:layout_width="150dip" android:lines="1" android:scrollHorizontally="true"></EditText>
+ <TextView android:layout_width="wrap_content"
+ android:layout_height="wrap_content" android:layout_weight="1"
+ android:layout_marginLeft="3dip" android:textSize="15dip"
+ android:id="@+id/TextView06" android:layout_marginRight="30dip"
+ android:text="Seconds"></TextView>
+ </LinearLayout>
+ </LinearLayout>
+ <LinearLayout android:layout_width="fill_parent" android:id="@+id/linearLayout3" android:gravity="center" android:layout_height="wrap_content" android:layout_marginTop="10dip">
+ <Button android:layout_height="wrap_content" android:layout_gravity="center" android:layout_width="120dip" android:layout_marginRight="5dip" android:id="@+id/enable_throttle_button" android:text="Disable Throttle" android:lines="2"></Button>
+ <Button android:id="@+id/save_throttle_button" android:layout_height="wrap_content" android:layout_gravity="center" android:layout_width="120dip" android:layout_marginLeft="5dip" android:text="Save Throttle Settings"></Button>
+ </LinearLayout>
+ </LinearLayout>
+
+</ScrollView>
View
1 res/layout/view_loadbalancer.xml
@@ -138,6 +138,7 @@
</LinearLayout>
<LinearLayout android:layout_height="fill_parent" android:layout_width="fill_parent" android:id="@+id/load_balancer_button3">
<Button android:layout_height="wrap_content" android:layout_marginLeft="20dip" android:layout_marginTop="10dip" android:layout_gravity="left" android:layout_width="130dip" android:id="@+id/session_persistence_button" android:text="Disable Session Persistence"></Button>
+ <Button android:layout_marginTop="10dip" android:layout_marginLeft="10dip" android:layout_height="wrap_content" android:layout_gravity="left" android:layout_width="130dip" android:text="Connection Throttle" android:id="@+id/connection_throttle_button"></Button>
</LinearLayout>
</LinearLayout>
</ScrollView>
View
112 src/com/rackspace/cloud/loadbalancer/api/client/ConnectionThrottleManager.java
@@ -0,0 +1,112 @@
+/**
+ *
+ */
+package com.rackspace.cloud.loadbalancer.api.client;
+
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+
+import javax.xml.parsers.FactoryConfigurationError;
+
+import org.apache.http.HttpResponse;
+import org.apache.http.client.ClientProtocolException;
+import org.apache.http.client.methods.HttpDelete;
+import org.apache.http.client.methods.HttpPut;
+import org.apache.http.entity.StringEntity;
+import org.apache.http.protocol.RequestExpectContinue;
+import android.content.Context;
+
+import com.rackspace.cloud.files.api.client.CustomHttpClient;
+import com.rackspace.cloud.servers.api.client.Account;
+import com.rackspace.cloud.servers.api.client.CloudServersException;
+import com.rackspace.cloud.servers.api.client.http.HttpBundle;
+
+public class ConnectionThrottleManager extends EntityManager {
+ private Context context;
+
+ public ConnectionThrottleManager(Context context) {
+ this.context = context;
+ }
+
+ public HttpBundle update(LoadBalancer loadBalancer, ConnectionThrottle throttle) throws CloudServersException {
+ HttpResponse resp = null;
+ CustomHttpClient httpclient = new CustomHttpClient(context);
+
+ HttpPut put = new HttpPut(LoadBalancer.getRegionUrl(loadBalancer.getRegion()) + Account.getAccount().getAccountId() + "/loadbalancers/" + loadBalancer.getId() + "/connectionthrottle");
+
+ put.addHeader("X-Auth-Token", Account.getAccount().getAuthToken());
+ put.addHeader("Content-Type", "application/xml");
+
+ String xml = "<connectionThrottle xmlns=\"http://docs.openstack.org/loadbalancers/api/v1.0\" " +
+ "minConnections=\"" + throttle.getMinConnections() + "\" " +
+ "maxConnections=\"" + throttle.getMaxConnections() + "\" " +
+ "maxConnectionRate=\"" + throttle.getMaxConnectionRate() + "\" " +
+ "rateInterval=\"" + throttle.getRateInterval() + "\" />";
+
+ StringEntity tmp = null;
+ try {
+ tmp = new StringEntity(xml);
+ } catch (UnsupportedEncodingException e) {
+ CloudServersException cse = new CloudServersException();
+ cse.setMessage(e.getLocalizedMessage());
+ throw cse;
+ }
+
+ put.setEntity(tmp);
+ httpclient.removeRequestInterceptorByClass(RequestExpectContinue.class);
+
+ HttpBundle bundle = new HttpBundle();
+ bundle.setCurlRequest(put);
+
+ try {
+ resp = httpclient.execute(put);
+ bundle.setHttpResponse(resp);
+ } catch (ClientProtocolException e) {
+ CloudServersException cse = new CloudServersException();
+ cse.setMessage(e.getLocalizedMessage());
+ throw cse;
+ } catch (IOException e) {
+ CloudServersException cse = new CloudServersException();
+ cse.setMessage(e.getLocalizedMessage());
+ throw cse;
+ } catch (FactoryConfigurationError e) {
+ CloudServersException cse = new CloudServersException();
+ cse.setMessage(e.getLocalizedMessage());
+ throw cse;
+ }
+ return bundle;
+ }
+
+ public HttpBundle delete(LoadBalancer loadBalancer) throws CloudServersException {
+ HttpResponse resp = null;
+ CustomHttpClient httpclient = new CustomHttpClient(context);
+
+ HttpDelete delete = new HttpDelete(LoadBalancer.getRegionUrl(loadBalancer.getRegion()) + Account.getAccount().getAccountId()
+ + "/loadbalancers/" + loadBalancer.getId() + "/connectionthrottle");
+ delete.addHeader("X-Auth-Token", Account.getAccount().getAuthToken());
+ delete.addHeader("Content-Type", "application/xml");
+ httpclient.removeRequestInterceptorByClass(RequestExpectContinue.class);
+
+ HttpBundle bundle = new HttpBundle();
+ bundle.setCurlRequest(delete);
+
+ try {
+ resp = httpclient.execute(delete);
+ bundle.setHttpResponse(resp);
+ } catch (ClientProtocolException e) {
+ CloudServersException cse = new CloudServersException();
+ cse.setMessage(e.getLocalizedMessage());
+ throw cse;
+ } catch (IOException e) {
+ CloudServersException cse = new CloudServersException();
+ cse.setMessage(e.getLocalizedMessage());
+ throw cse;
+ } catch (FactoryConfigurationError e) {
+ CloudServersException cse = new CloudServersException();
+ cse.setMessage(e.getLocalizedMessage());
+ throw cse;
+ }
+ return bundle;
+ }
+
+}
View
2 src/com/rackspacecloud/android/AndroidCloudApplication.java
@@ -79,7 +79,7 @@ public void setIsLoggingIn(boolean logginIn){
isLoggingIn = logginIn;
}
- public boolean isLogginIn(){
+ public boolean isLoggingIn(){
return isLoggingIn;
}
}
View
250 src/com/rackspacecloud/android/ConnectionThrottleActivity.java
@@ -0,0 +1,250 @@
+package com.rackspacecloud.android;
+
+import org.apache.http.HttpResponse;
+
+import android.app.Activity;
+import android.os.AsyncTask;
+import android.os.Bundle;
+import android.util.Log;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.widget.Button;
+import android.widget.EditText;
+
+import com.rackspace.cloud.loadbalancer.api.client.ConnectionThrottle;
+import com.rackspace.cloud.loadbalancer.api.client.ConnectionThrottleManager;
+import com.rackspace.cloud.loadbalancer.api.client.LoadBalancer;
+import com.rackspace.cloud.servers.api.client.CloudServersException;
+import com.rackspace.cloud.servers.api.client.http.HttpBundle;
+
+public class ConnectionThrottleActivity extends CloudActivity{
+
+ private LoadBalancer loadBalancer;
+ private ConnectionThrottle connectionThrottle;
+ private EditText minCons;
+ private EditText maxCons;
+ private EditText maxConRate;
+ private EditText rateInterval;
+
+ private final String ENABLE = "Enable Throttle";
+ private final String DISABLE = "Disable Throttle";
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ loadBalancer = (LoadBalancer) this.getIntent().getExtras().get("loadBalancer");
+ setContentView(R.layout.connectionthrottle);
+ restoreState(savedInstanceState);
+ }
+
+ protected void restoreState(Bundle state) {
+ super.restoreState(state);
+
+ minCons = (EditText)findViewById(R.id.min_connections_text);
+ maxCons = (EditText)findViewById(R.id.max_connections_text);
+ maxConRate = (EditText)findViewById(R.id.max_connection_rate);
+ rateInterval = (EditText)findViewById(R.id.rate_interval);
+
+ setupButtons();
+ setupText();
+ }
+
+ private void setupButtons(){
+ Button enable = (Button)findViewById(R.id.enable_throttle_button);
+ if(loadBalancer.getConnectionThrottle() == null){
+ enable.setText(ENABLE);
+ } else {
+ enable.setText(DISABLE);
+ }
+ enable.setOnClickListener(new OnClickListener() {
+ Button enable = (Button)findViewById(R.id.enable_throttle_button);
+ @Override
+ public void onClick(View v) {
+ if(enable.getText().toString().equals(ENABLE)){
+ //Turn on EditTexts
+ minCons.setEnabled(true);
+ maxCons.setEnabled(true);
+ maxConRate.setEnabled(true);
+ rateInterval.setEnabled(true);
+ enable.setText(DISABLE);
+ } else {
+ //Turn off EditTexts
+ minCons.setEnabled(false);
+ maxCons.setEnabled(false);
+ maxConRate.setEnabled(false);
+ rateInterval.setEnabled(false);
+ enable.setText(ENABLE);
+ }
+ }
+ });
+
+ Button submit = (Button)findViewById(R.id.save_throttle_button);
+ submit.setOnClickListener(new OnClickListener() {
+
+ Button enable = (Button)findViewById(R.id.enable_throttle_button);
+
+ @Override
+ public void onClick(View v) {
+
+ connectionThrottle = new ConnectionThrottle();
+ connectionThrottle.setMaxConnectionRate(maxConRate.getText().toString());
+ connectionThrottle.setMinConnections(minCons.getText().toString());
+ connectionThrottle.setMaxConnections(maxCons.getText().toString());
+ connectionThrottle.setRateInterval(rateInterval.getText().toString());
+
+ if(enable.getText().toString().equals(DISABLE)){
+ if(validText()){
+ new UpdateConnectionThrottleTask().execute();
+ }
+ } else {
+ //if there was no connection throttle before
+ //then no need to delete it
+ if(loadBalancer.getConnectionThrottle() != null){
+ new DeleteConnectionThrottleTask().execute();
+ } else {
+ finish();
+ }
+ }
+ }
+ });
+ }
+
+ private void setupText(){
+ if(loadBalancer.getConnectionThrottle() == null){
+ minCons.setEnabled(false);
+ maxCons.setEnabled(false);
+ maxConRate.setEnabled(false);
+ rateInterval.setEnabled(false);
+
+ //Set boxes to default values
+ minCons.setText("25");
+ maxCons.setText("100");
+ maxConRate.setText("25");
+ rateInterval.setText("5");
+ } else {
+ ConnectionThrottle throttle = loadBalancer.getConnectionThrottle();
+
+ //restore the current values to the boxes
+ minCons.setText(throttle.getMinConnections());
+ maxCons.setText(throttle.getMaxConnections());
+ maxConRate.setText(throttle.getMaxConnectionRate());
+ rateInterval.setText(throttle.getRateInterval());
+ }
+ }
+
+ private Boolean validText(){
+ return validEditText(maxCons, 0, 100000, "Max Connections")
+ && validEditText(minCons, 0, 1000, "Min Connections")
+ && validEditText(maxConRate, 0, 100000, "Max Connection Rate")
+ && validEditText(rateInterval, 1, 3600, "Rate Interval");
+ }
+
+ private Boolean validEditText(EditText box, int min, int max, String boxName){
+ String result = box.getText().toString();
+ if(result.equals("")){
+ showAlert("Error", "Please enter a value for " + boxName + ".");
+ return false;
+ } else {
+ try {
+ int value = Integer.parseInt(result);
+ Log.d("info", min + " <= " + value + " <= " + max);
+ if(value >= min && value <= max){
+ return true;
+ } else {
+ showAlert("Error", boxName + " must be an integer between " + min + " and " + max + " inclusive.");
+ return false;
+ }
+ } catch (NumberFormatException e) {
+ showAlert("Error", boxName + " must be an integer between " + min + " and " + max + " inclusive.");
+ return false;
+ }
+ }
+ }
+
+ public class UpdateConnectionThrottleTask extends AsyncTask<Void, Void, HttpBundle> {
+
+ private CloudServersException exception;
+
+ @Override
+ protected void onPreExecute(){
+ showDialog();
+ }
+
+ @Override
+ protected HttpBundle doInBackground(Void... arg0) {
+ HttpBundle bundle = null;
+ try {
+ bundle = (new ConnectionThrottleManager(getContext())).update(loadBalancer, connectionThrottle);
+ } catch (CloudServersException e) {
+ exception = e;
+ }
+ return bundle;
+ }
+
+ @Override
+ protected void onPostExecute(HttpBundle bundle) {
+ hideDialog();
+ HttpResponse response = bundle.getResponse();
+ if (response != null) {
+ int statusCode = response.getStatusLine().getStatusCode();
+ if (statusCode == 202) {
+ setResult(Activity.RESULT_OK);
+ finish();
+ } else {
+ CloudServersException cse = parseCloudServersException(response);
+ if ("".equals(cse.getMessage())) {
+ showError("There was a problem editing the connection throttle.", bundle);
+ } else {
+ showError("There was a problem editing the connection throttle: " + cse.getMessage(), bundle);
+ }
+ }
+ } else if (exception != null) {
+ showError("There was a problem editing the connection throttle: " + exception.getMessage(), bundle);
+ }
+ }
+ }
+
+ public class DeleteConnectionThrottleTask extends AsyncTask<Void, Void, HttpBundle> {
+
+ private CloudServersException exception;
+
+ @Override
+ protected void onPreExecute(){
+ showDialog();
+ }
+
+ @Override
+ protected HttpBundle doInBackground(Void... arg0) {
+ HttpBundle bundle = null;
+ try {
+ bundle = (new ConnectionThrottleManager(getContext())).delete(loadBalancer);
+ } catch (CloudServersException e) {
+ exception = e;
+ }
+ return bundle;
+ }
+
+ @Override
+ protected void onPostExecute(HttpBundle bundle) {
+ hideDialog();
+ HttpResponse response = bundle.getResponse();
+ if (response != null) {
+ int statusCode = response.getStatusLine().getStatusCode();
+ if (statusCode == 202) {
+ setResult(Activity.RESULT_OK);
+ finish();
+ } else {
+ CloudServersException cse = parseCloudServersException(response);
+ if ("".equals(cse.getMessage())) {
+ showError("There was a problem editing the connection throttle.", bundle);
+ } else {
+ showError("There was a problem editing the connection throttle: " + cse.getMessage(), bundle);
+ }
+ }
+ } else if (exception != null) {
+ showError("There was a problem editing the connection throttle: " + exception.getMessage(), bundle);
+ }
+ }
+ }
+
+}
View
76 src/com/rackspacecloud/android/ListAccountsActivity.java
@@ -65,6 +65,9 @@
private ProgressDialog dialog;
private Context context;
private AndroidCloudApplication app;
+ //used to track the current asynctask
+ @SuppressWarnings("rawtypes")
+ private AsyncTask task;
//need to store if the user has successfully logged in
private boolean loggedIn;
@@ -415,6 +418,8 @@ private void showDialog() {
@Override
public void onCancel(DialogInterface dialog) {
app.setIsLoggingIn(false);
+ //need to cancel the old task or we may get a double login
+ task.cancel(true);
hideDialog();
}
});
@@ -437,38 +442,44 @@ private void hideDialog() {
@Override
protected void onPreExecute(){
+ Log.d("info", "Starting authenticate");
+ task = this;
showDialog();
}
@Override
protected Boolean doInBackground(Void... arg0) {
- if(isCancelled()){
- return false;
- }
return new Boolean(Authentication.authenticate(context));
}
@Override
protected void onPostExecute(Boolean result) {
if (result.booleanValue()) {
//startActivity(tabViewIntent);
- if(app.isLogginIn()){
+ if(app.isLoggingIn()){
new LoadImagesTask().execute((Void[]) null);
} else {
hideDialog();
}
} else {
hideDialog();
- showAlert("Login Failure", "Authentication failed. Please check your User Name and API Key.");
+ if(app.isLoggingIn()){
+ showAlert("Login Failure", "Authentication failed. Please check your User Name and API Key.");
+ }
}
}
}
private class LoadImagesTask extends AsyncTask<Void, Void, ArrayList<Image>> {
@Override
+ protected void onPreExecute(){
+ Log.d("info", "Starting Images");
+ task = this;
+ }
+
+ @Override
protected ArrayList<Image> doInBackground(Void... arg0) {
- Log.d("info", "LoadImagesTask Started");
return (new ImageManager()).createList(true, context);
}
@@ -481,100 +492,111 @@ protected void onPostExecute(ArrayList<Image> result) {
imageMap.put(image.getId(), image);
}
Image.setImages(imageMap);
- if(app.isLogginIn()){
+ if(app.isLoggingIn()){
new LoadProtocolsTask().execute((Void[]) null);
} else {
hideDialog();
}
} else {
hideDialog();
- showAlert("Login Failure", "There was a problem loading server images. Please try again.");
+ if(app.isLoggingIn()){
+ showAlert("Login Failure", "There was a problem loading server images. Please try again.");
+ }
}
}
}
private class LoadProtocolsTask extends AsyncTask<Void, Void, ArrayList<Protocol>> {
@Override
+ protected void onPreExecute(){
+ Log.d("info", "Starting protcols");
+ task = this;
+ }
+
+ @Override
protected ArrayList<Protocol> doInBackground(Void... arg0) {
- Log.d("info", "LoadProtocolsTask Started");
return (new ProtocolManager()).createList(context);
}
@Override
protected void onPostExecute(ArrayList<Protocol> result) {
if (result != null && result.size() > 0) {
Protocol.setProtocols(result);
- if(app.isLogginIn()){
+ if(app.isLoggingIn()){
new LoadAlgorithmsTask().execute((Void[]) null);
} else {
hideDialog();
}
} else {
hideDialog();
- showAlert("Login Failure", "There was a problem loading load balancer protocols. Please try again.");
+ if(app.isLoggingIn()){
+ showAlert("Login Failure", "There was a problem loading load balancer protocols. Please try again.");
+ }
}
}
}
private class LoadAlgorithmsTask extends AsyncTask<Void, Void, ArrayList<Algorithm>> {
+ protected void onPreExecute(){
+ Log.d("info", "Starting algorithms");
+ task = this;
+ }
+
@Override
protected ArrayList<Algorithm> doInBackground(Void... arg0) {
- Log.d("info", "LoadAlgorithmsTask Started");
return (new AlgorithmManager()).createList(context);
}
@Override
protected void onPostExecute(ArrayList<Algorithm> result) {
if (result != null && result.size() > 0) {
Algorithm.setAlgorithms(result);
- if(app.isLogginIn()){
+ if(app.isLoggingIn()){
new LoadFlavorsTask().execute((Void[]) null);
} else {
hideDialog();
}
} else {
hideDialog();
- showAlert("Login Failure", "There was a problem loading load balancer algorithms. Please try again.");
+ if(app.isLoggingIn()){
+ showAlert("Login Failure", "There was a problem loading load balancer algorithms. Please try again.");
+ }
}
}
}
private class LoadFlavorsTask extends AsyncTask<Void, Void, ArrayList<Flavor>> {
+ protected void onPreExecute(){
+ Log.d("info", "Starting flavors");
+ task = this;
+ }
+
@Override
protected ArrayList<Flavor> doInBackground(Void... arg0) {
- Log.d("info", "LoadFlavorsTask Started");
return (new FlavorManager()).createList(true, context);
}
@Override
protected void onPostExecute(ArrayList<Flavor> result) {
- if(isCancelled()){
- return;
- }
-
if (result != null && result.size() > 0) {
TreeMap<String, Flavor> flavorMap = new TreeMap<String, Flavor>();
for (int i = 0; i < result.size(); i++) {
Flavor flavor = result.get(i);
flavorMap.put(flavor.getId(), flavor);
}
Flavor.setFlavors(flavorMap);
- if(isCancelled()){
- return;
- }
hideDialog();
- Log.d("info", "Starting TabViewIntent");
- if(app.isLogginIn()){
+ if(app.isLoggingIn()){
startActivityForResult(tabViewIntent, 187);
- } else {
- hideDialog();
}
} else {
hideDialog();
- showAlert("Login Failure", "There was a problem loading server flavors. Please try again.");
+ if(app.isLoggingIn()){
+ showAlert("Login Failure", "There was a problem loading server flavors. Please try again.");
+ }
}
}
}
View
30 src/com/rackspacecloud/android/ViewLoadBalancerActivity.java
@@ -38,8 +38,11 @@
public class ViewLoadBalancerActivity extends CloudActivity {
- private static final int EDIT_LOAD_BALANCER_CODE = 184;
- private static final int EDIT_NODES_CODE = 185;
+ private final int EDIT_LOAD_BALANCER_CODE = 184;
+ private final int EDIT_NODES_CODE = 185;
+ private final int EDIT_THROTTLE_CODE = 186;
+
+ private final String DELETED = "DELETED";
private LoadBalancer loadBalancer;
private PollLoadBalancerTask pollLoadBalancerTask;
@@ -118,7 +121,7 @@ private void setUpButtons(){
setupButton(R.id.edit_loadbalancer_button, new OnClickListener() {
@Override
public void onClick(View v) {
- if(!loadBalancer.getStatus().contains("DELETE")){
+ if(!loadBalancer.getStatus().contains(DELETED)){
Intent editLoadBalancerIntent = new Intent(getContext(), EditLoadBalancerActivity.class);
editLoadBalancerIntent.putExtra("loadBalancer", loadBalancer);
startActivityForResult(editLoadBalancerIntent, EDIT_LOAD_BALANCER_CODE);
@@ -132,7 +135,7 @@ public void onClick(View v) {
setupButton(R.id.delete_loadbalancer_button, new OnClickListener() {
@Override
public void onClick(View v) {
- if(!loadBalancer.getStatus().contains("DELETE")){
+ if(!loadBalancer.getStatus().contains(DELETED)){
showDialog(R.id.view_server_delete_button);
} else {
showAlert(loadBalancer.getStatus(), "The load balancer cannot be deleted.");
@@ -144,7 +147,7 @@ public void onClick(View v) {
setupButton(R.id.edit_nodes_button, new OnClickListener() {
@Override
public void onClick(View v) {
- if(!loadBalancer.getStatus().contains("DELETE")){
+ if(!loadBalancer.getStatus().contains(DELETED)){
Intent editLoadBalancerIntent = new Intent(getContext(), EditNodesActivity.class);
editLoadBalancerIntent.putExtra("nodes", loadBalancer.getNodes());
editLoadBalancerIntent.putExtra("loadBalancer", loadBalancer);
@@ -158,7 +161,7 @@ public void onClick(View v) {
setupButton(R.id.connection_log_button, new OnClickListener() {
@Override
public void onClick(View v) {
- if(!loadBalancer.getStatus().contains("DELETE")){
+ if(!loadBalancer.getStatus().contains(DELETED)){
showDialog(R.id.connection_log_button);
} else {
showAlert(loadBalancer.getStatus(), "Log settings cannot be edited.");
@@ -170,7 +173,7 @@ public void onClick(View v) {
setupButton(R.id.session_persistence_button, new OnClickListener() {
@Override
public void onClick(View v) {
- if(!loadBalancer.getStatus().contains("DELETE")){
+ if(!loadBalancer.getStatus().contains(DELETED)){
if(!loadBalancer.getProtocol().equals("HTTP")){
showAlert("Error", "Session Persistence cannot be enabled for protocols other than HTTP.");
} else {
@@ -182,6 +185,19 @@ public void onClick(View v) {
}
});
setSessionButtonText();
+
+ setupButton(R.id.connection_throttle_button, new OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ if(!loadBalancer.getStatus().contains(DELETED)){
+ Intent editLoadBalancerIntent = new Intent(getContext(), ConnectionThrottleActivity.class);
+ editLoadBalancerIntent.putExtra("loadBalancer", loadBalancer);
+ startActivityForResult(editLoadBalancerIntent, EDIT_THROTTLE_CODE);
+ } else {
+ showAlert(loadBalancer.getStatus(), "Connection Throttle cannot be edited.");
+ }
+ }
+ });
}
@Override

0 comments on commit 16615ab

Please sign in to comment.
Something went wrong with that request. Please try again.