Revision 1a79c76b
b/res/layout/addaccessrule.xml | ||
---|---|---|
17 | 17 |
<EditText android:layout_width="fill_parent" android:layout_above="@+id/add_text_file_buttons" |
18 | 18 |
android:layout_below="@+id/file_contents_view" |
19 | 19 |
android:layout_marginLeft="22dip" android:layout_marginRight="30dip" |
20 |
android:gravity="top" android:id="@+id/rule_address" android:layout_height="100dip"></EditText>
|
|
20 |
android:gravity="top" android:layout_height="100dip" android:id="@+id/rule_address"></EditText>
|
|
21 | 21 |
<TextView android:layout_height="wrap_content" android:id="@+id/textView3" |
22 | 22 |
android:layout_marginRight="30dip" android:textSize="11dip" |
23 | 23 |
android:layout_width="wrap_content" android:layout_marginLeft="22dip" android:text="Enter IP addresses or networks in CIDR notation; separate multiple entries with commas. The network 0.0.0.0/0 can be used to create a rule for all traffic."></TextView> |
b/src/com/rackspace/cloud/loadbalancer/api/client/LoadBalancerManager.java | ||
---|---|---|
93 | 93 |
BasicResponseHandler responseHandler = new BasicResponseHandler(); |
94 | 94 |
String body = responseHandler.handleResponse(resp); |
95 | 95 |
|
96 |
Log.d("info", "the xml body is " + body); |
|
97 |
|
|
98 | 96 |
if (resp.getStatusLine().getStatusCode() == 200 || resp.getStatusLine().getStatusCode() == 202) { |
99 | 97 |
LoadBalancersXmlParser loadBalancersXMLParser = new LoadBalancersXmlParser(); |
100 | 98 |
SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser(); |
b/src/com/rackspace/cloud/servers/api/client/Backup.java | ||
---|---|---|
1 | 1 |
package com.rackspace.cloud.servers.api.client; |
2 | 2 |
|
3 |
public class Backup { |
|
3 |
import java.io.Serializable; |
|
4 |
|
|
5 |
import android.util.Log; |
|
6 |
|
|
7 |
public class Backup implements Serializable { |
|
4 | 8 |
|
9 |
/** |
|
10 |
* |
|
11 |
*/ |
|
12 |
private static final long serialVersionUID = 4827357903187247384L; |
|
13 |
|
|
5 | 14 |
private static final String[] weeklyBackupValues = {"DISABLED", "SUNDAY", "MONDAY", |
6 | 15 |
"TUESDAY", "WEDNESDAY", "THURSDAY", "FRIDAY", "SATURDAY"}; |
7 | 16 |
|
... | ... | |
9 | 18 |
"H_0800_1000", "H_1000_1200", "H_1200_1400", "H_1400_1600", "H_1600_1800", "H_1800_2000", |
10 | 19 |
"H_2000_2200", "H_2200_0000"}; |
11 | 20 |
|
21 |
private boolean enabled; |
|
22 |
private String weekly; |
|
23 |
private String daily; |
|
24 |
|
|
12 | 25 |
public static String getWeeklyValue(int i){ |
13 | 26 |
return weeklyBackupValues[i]; |
14 | 27 |
} |
... | ... | |
16 | 29 |
public static String getDailyValue(int i){ |
17 | 30 |
return dailyBackupValues[i]; |
18 | 31 |
} |
32 |
|
|
33 |
public boolean getEnable(){ |
|
34 |
return enabled; |
|
35 |
} |
|
36 |
|
|
37 |
public void setEnabled(boolean enabled){ |
|
38 |
this.enabled = enabled; |
|
39 |
} |
|
40 |
|
|
41 |
public String getWeekly(){ |
|
42 |
return weekly; |
|
43 |
} |
|
44 |
|
|
45 |
public void setWeekly(String weekly){ |
|
46 |
this.weekly = weekly; |
|
47 |
} |
|
48 |
|
|
49 |
public static int getWeeklyIndex(String day){ |
|
50 |
for(int i = 0; i < weeklyBackupValues.length; i++){ |
|
51 |
if(weeklyBackupValues[i].equals(day)){ |
|
52 |
return i; |
|
53 |
} |
|
54 |
} |
|
55 |
return 0; |
|
56 |
} |
|
57 |
|
|
58 |
public String getDaily(){ |
|
59 |
return daily; |
|
60 |
} |
|
61 |
|
|
62 |
public void setDaily(String daily){ |
|
63 |
this.daily = daily; |
|
64 |
} |
|
65 |
|
|
66 |
public static int getDailyIndex(String hour){ |
|
67 |
for(int i = 0; i < dailyBackupValues.length; i++){ |
|
68 |
if(dailyBackupValues[i].equals(hour)){ |
|
69 |
return i; |
|
70 |
} |
|
71 |
} |
|
72 |
return 0; |
|
73 |
} |
|
74 |
|
|
19 | 75 |
|
20 | 76 |
} |
b/src/com/rackspace/cloud/servers/api/client/BackupManager.java | ||
---|---|---|
1 |
/** |
|
2 |
* |
|
3 |
*/ |
|
4 |
package com.rackspace.cloud.servers.api.client; |
|
5 |
|
|
6 |
import java.io.IOException; |
|
7 |
import java.io.StringReader; |
|
8 |
|
|
9 |
import javax.xml.parsers.FactoryConfigurationError; |
|
10 |
import javax.xml.parsers.ParserConfigurationException; |
|
11 |
import javax.xml.parsers.SAXParser; |
|
12 |
import javax.xml.parsers.SAXParserFactory; |
|
13 |
|
|
14 |
import org.apache.http.HttpResponse; |
|
15 |
import org.apache.http.client.ClientProtocolException; |
|
16 |
import org.apache.http.client.methods.HttpGet; |
|
17 |
import org.apache.http.impl.client.BasicResponseHandler; |
|
18 |
import org.xml.sax.InputSource; |
|
19 |
import org.xml.sax.SAXException; |
|
20 |
import org.xml.sax.XMLReader; |
|
21 |
|
|
22 |
import android.content.Context; |
|
23 |
|
|
24 |
import com.rackspace.cloud.files.api.client.CustomHttpClient; |
|
25 |
import com.rackspace.cloud.servers.api.client.parsers.BackupXMLParser; |
|
26 |
import com.rackspace.cloud.servers.api.client.parsers.CloudServersFaultXMLParser; |
|
27 |
|
|
28 |
public class BackupManager extends EntityManager { |
|
29 |
|
|
30 |
public Backup getBackup(Server server, Context context) throws CloudServersException { |
|
31 |
|
|
32 |
CustomHttpClient httpclient = new CustomHttpClient(context); |
|
33 |
HttpGet get = new HttpGet(Account.getAccount().getServerUrl() + "/servers/" + server.getId() + "/backup_schedule/.xml" + cacheBuster()); |
|
34 |
Backup backup = new Backup(); |
|
35 |
get.addHeader("X-Auth-Token", Account.getAccount().getAuthToken()); |
|
36 |
|
|
37 |
try { |
|
38 |
HttpResponse resp = httpclient.execute(get); |
|
39 |
BasicResponseHandler responseHandler = new BasicResponseHandler(); |
|
40 |
String body = responseHandler.handleResponse(resp); |
|
41 |
|
|
42 |
if (resp.getStatusLine().getStatusCode() == 200 || resp.getStatusLine().getStatusCode() == 203) { |
|
43 |
BackupXMLParser backupXMLParser = new BackupXMLParser(); |
|
44 |
SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser(); |
|
45 |
XMLReader xmlReader = saxParser.getXMLReader(); |
|
46 |
xmlReader.setContentHandler(backupXMLParser); |
|
47 |
xmlReader.parse(new InputSource(new StringReader(body))); |
|
48 |
backup = backupXMLParser.getBackup(); |
|
49 |
} else { |
|
50 |
CloudServersFaultXMLParser parser = new CloudServersFaultXMLParser(); |
|
51 |
SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser(); |
|
52 |
XMLReader xmlReader = saxParser.getXMLReader(); |
|
53 |
xmlReader.setContentHandler(parser); |
|
54 |
xmlReader.parse(new InputSource(new StringReader(body))); |
|
55 |
CloudServersException cse = parser.getException(); |
|
56 |
throw cse; |
|
57 |
} |
|
58 |
} catch (ClientProtocolException e) { |
|
59 |
CloudServersException cse = new CloudServersException(); |
|
60 |
cse.setMessage(e.getLocalizedMessage()); |
|
61 |
throw cse; |
|
62 |
} catch (IOException e) { |
|
63 |
CloudServersException cse = new CloudServersException(); |
|
64 |
cse.setMessage(e.getLocalizedMessage()); |
|
65 |
throw cse; |
|
66 |
} catch (ParserConfigurationException e) { |
|
67 |
CloudServersException cse = new CloudServersException(); |
|
68 |
cse.setMessage(e.getLocalizedMessage()); |
|
69 |
throw cse; |
|
70 |
} catch (SAXException e) { |
|
71 |
CloudServersException cse = new CloudServersException(); |
|
72 |
cse.setMessage(e.getLocalizedMessage()); |
|
73 |
throw cse; |
|
74 |
} catch (FactoryConfigurationError e) { |
|
75 |
CloudServersException cse = new CloudServersException(); |
|
76 |
cse.setMessage(e.getLocalizedMessage()); |
|
77 |
throw cse; |
|
78 |
} |
|
79 |
|
|
80 |
|
|
81 |
return backup; |
|
82 |
} |
|
83 |
|
|
84 |
|
|
85 |
} |
b/src/com/rackspace/cloud/servers/api/client/FlavorManager.java | ||
---|---|---|
37 | 37 |
ArrayList<Flavor> flavors = new ArrayList<Flavor>(); |
38 | 38 |
|
39 | 39 |
get.addHeader("X-Auth-Token", Account.getAccount().getAuthToken()); |
40 |
|
|
40 | 41 |
try { |
41 | 42 |
HttpResponse resp = httpclient.execute(get); |
42 | 43 |
BasicResponseHandler responseHandler = new BasicResponseHandler(); |
b/src/com/rackspace/cloud/servers/api/client/ServerManager.java | ||
---|---|---|
27 | 27 |
import org.xml.sax.XMLReader; |
28 | 28 |
|
29 | 29 |
import android.content.Context; |
30 |
|
|
30 | 31 |
import com.rackspace.cloud.files.api.client.CustomHttpClient; |
31 | 32 |
import com.rackspace.cloud.servers.api.client.http.HttpBundle; |
32 | 33 |
import com.rackspace.cloud.servers.api.client.parsers.CloudServersFaultXMLParser; |
... | ... | |
496 | 497 |
|
497 | 498 |
StringEntity tmp = null; |
498 | 499 |
try { |
499 |
tmp = new StringEntity("<backupSchedule xmlns=\"http://docs.rackspacecloud.com/servers/api/v1.0\" enabled=\"" + enabled + "\" " + |
|
500 |
"weekly=\"" + weeklyValue + "\" daily=\"" + dailyValue + "\"/>"); |
|
501 |
|
|
500 |
tmp = new StringEntity("<?xml version=\"1.0\" encoding=\"UTF-8\"?> <backupSchedule xmlns=\"http://docs.rackspacecloud.com/servers/api/v1.0\" enabled=\"" + enabled + "\" " + |
|
501 |
"weekly=\"" + weeklyValue + "\" daily=\"" + dailyValue + "\"/>"); |
|
502 | 502 |
} catch (UnsupportedEncodingException e) { |
503 | 503 |
CloudServersException cse = new CloudServersException(); |
504 | 504 |
cse.setMessage(e.getLocalizedMessage()); |
b/src/com/rackspace/cloud/servers/api/client/parsers/BackupXMLParser.java | ||
---|---|---|
1 |
/** |
|
2 |
* |
|
3 |
*/ |
|
4 |
package com.rackspace.cloud.servers.api.client.parsers; |
|
5 |
|
|
6 |
import org.xml.sax.Attributes; |
|
7 |
import org.xml.sax.helpers.DefaultHandler; |
|
8 |
|
|
9 |
import android.util.Log; |
|
10 |
|
|
11 |
import com.rackspace.cloud.servers.api.client.Backup; |
|
12 |
|
|
13 |
public class BackupXMLParser extends DefaultHandler { |
|
14 |
|
|
15 |
private Backup backup; |
|
16 |
private StringBuffer currentData; |
|
17 |
|
|
18 |
public void startDocument() { |
|
19 |
} |
|
20 |
|
|
21 |
public void endDocument() { |
|
22 |
} |
|
23 |
|
|
24 |
public void startElement(String uri, String name, String qName, Attributes atts) { |
|
25 |
currentData = new StringBuffer(); |
|
26 |
if("backupSchedule".equals(name)){ |
|
27 |
backup = new Backup(); |
|
28 |
backup.setEnabled(Boolean.valueOf(atts.getValue("enabled"))); |
|
29 |
backup.setWeekly(atts.getValue("weekly")); |
|
30 |
backup.setDaily(atts.getValue("daily")); |
|
31 |
} |
|
32 |
} |
|
33 |
|
|
34 |
public void characters(char ch[], int start, int length) { |
|
35 |
Log.d("Rackspace-Cloud", "Characters: \""); |
|
36 |
for (int i = start; i < start + length; i++) { |
|
37 |
switch (ch[i]) { |
|
38 |
case '\\': |
|
39 |
Log.d("Rackspace-Cloud", "\\\\"); |
|
40 |
break; |
|
41 |
case '"': |
|
42 |
Log.d("Rackspace-Cloud", "\\\""); |
|
43 |
break; |
|
44 |
case '\n': |
|
45 |
Log.d("Rackspace-Cloud", "\\n"); |
|
46 |
break; |
|
47 |
case '\r': |
|
48 |
Log.d("Rackspace-Cloud", "\\r"); |
|
49 |
break; |
|
50 |
case '\t': |
|
51 |
Log.d("Rackspace-Cloud", "\\t"); |
|
52 |
break; |
|
53 |
default: |
|
54 |
Log.d("Rackspace-Cloud", String.valueOf(ch[i])); |
|
55 |
break; |
|
56 |
} |
|
57 |
} |
|
58 |
Log.d("Rackspace-Cloud", "\"\n"); |
|
59 |
|
|
60 |
|
|
61 |
for (int i = start; i < (start + length); i++) { |
|
62 |
currentData.append(ch[i]); |
|
63 |
} |
|
64 |
} |
|
65 |
|
|
66 |
public Backup getBackup() { |
|
67 |
return backup; |
|
68 |
} |
|
69 |
|
|
70 |
} |
b/src/com/rackspacecloud/android/AddAccessRuleActivity.java | ||
---|---|---|
1 | 1 |
package com.rackspacecloud.android; |
2 | 2 |
|
3 | 3 |
import java.util.ArrayList; |
4 |
import java.util.Arrays; |
|
4 | 5 |
import java.util.regex.Matcher; |
5 | 6 |
import java.util.regex.Pattern; |
6 | 7 |
|
... | ... | |
33 | 34 |
private LoadBalancer loadBalancer; |
34 | 35 |
private String selectedAction; |
35 | 36 |
private String selectedAddresses; |
36 |
private NetworkItem networkItem; |
|
37 | 37 |
|
38 | 38 |
@Override |
39 | 39 |
public void onCreate(Bundle savedInstanceState) { |
... | ... | |
97 | 97 |
Button addRule = (Button)findViewById(R.id.add_rule_button); |
98 | 98 |
addRule.setOnClickListener(new OnClickListener() { |
99 | 99 |
|
100 |
@SuppressWarnings("unchecked") |
|
100 | 101 |
@Override |
101 | 102 |
public void onClick(View v) { |
102 | 103 |
if(!validAddress(selectedAddresses)){ |
... | ... | |
119 | 120 |
} |
120 | 121 |
|
121 | 122 |
//basic ip validation just checks that the string |
122 |
//is only composed of letters, numbers, ., : |
|
123 |
//is only composed of letters, numbers, ., : and ,
|
|
123 | 124 |
private static boolean validAddress(String address){ |
124 |
//Enter regex |
|
125 |
if(address != null){ |
|
125 |
//if just white space return false; |
|
126 |
//check regex |
|
127 |
if(address != null && !address.trim().equals("")){ |
|
126 | 128 |
Pattern pattern = Pattern.compile("[a-zA-Z0-9.:/, ]+"); |
127 | 129 |
Matcher match = pattern.matcher(address); |
128 | 130 |
return match.matches(); |
... | ... | |
132 | 134 |
} |
133 | 135 |
|
134 | 136 |
private Boolean validAction(String action){ |
135 |
return action != null; |
|
137 |
return action != null && Arrays.asList(ACTIONS).contains(action);
|
|
136 | 138 |
} |
137 | 139 |
|
138 | 140 |
private class AddNetworkItemTask extends AsyncTask<ArrayList<NetworkItem>, Void, HttpBundle> { |
b/src/com/rackspacecloud/android/BackupServerActivity.java | ||
---|---|---|
3 | 3 |
import org.apache.http.HttpResponse; |
4 | 4 |
|
5 | 5 |
import com.rackspace.cloud.servers.api.client.Backup; |
6 |
import com.rackspace.cloud.servers.api.client.BackupManager; |
|
6 | 7 |
import com.rackspace.cloud.servers.api.client.CloudServersException; |
7 | 8 |
import com.rackspace.cloud.servers.api.client.Server; |
8 | 9 |
import com.rackspace.cloud.servers.api.client.ServerManager; |
... | ... | |
10 | 11 |
|
11 | 12 |
import android.os.AsyncTask; |
12 | 13 |
import android.os.Bundle; |
14 |
import android.util.Log; |
|
13 | 15 |
import android.view.View; |
14 | 16 |
import android.view.View.OnClickListener; |
15 | 17 |
import android.widget.AdapterView; |
... | ... | |
20 | 22 |
import android.widget.Spinner; |
21 | 23 |
|
22 | 24 |
public class BackupServerActivity extends CloudActivity implements OnItemSelectedListener, OnClickListener { |
23 |
|
|
25 |
|
|
24 | 26 |
private Server server; |
27 |
private Backup backup; |
|
25 | 28 |
private Spinner weeklyBackupSpinner; |
26 | 29 |
private Spinner dailyBackupSpinner; |
27 | 30 |
private CheckBox enableCheckBox; |
28 | 31 |
private String selectedWeeklyBackup; |
29 | 32 |
private String selectedDailyBackup; |
30 |
|
|
33 |
|
|
31 | 34 |
/** Called when the activity is first created. */ |
32 |
@Override
|
|
33 |
public void onCreate(Bundle savedInstanceState) {
|
|
34 |
super.onCreate(savedInstanceState);
|
|
35 |
restoreState(savedInstanceState);
|
|
36 |
}
|
|
37 |
|
|
38 |
protected void restoreState(Bundle state){
|
|
35 |
@Override
|
|
36 |
public void onCreate(Bundle savedInstanceState) {
|
|
37 |
super.onCreate(savedInstanceState);
|
|
38 |
restoreState(savedInstanceState);
|
|
39 |
}
|
|
40 |
|
|
41 |
protected void restoreState(Bundle state){
|
|
39 | 42 |
super.restoreState(state); |
40 | 43 |
server = (Server) this.getIntent().getExtras().get("server"); |
41 |
setContentView(R.layout.viewbackup); |
|
42 |
setupSpinners(); |
|
43 |
setupButtons(); |
|
44 |
setupCheckBox(); |
|
44 |
setContentView(R.layout.viewbackup); |
|
45 |
setupSpinners(); |
|
46 |
setupButtons(); |
|
47 |
setupCheckBox(); |
|
48 |
|
|
49 |
if(state != null && state.containsKey("backup")){ |
|
50 |
backup = (Backup)state.getSerializable("backup"); |
|
51 |
if(backup == null){ |
|
52 |
loadData(); |
|
53 |
} else { |
|
54 |
displayData(); |
|
55 |
} |
|
56 |
} else { |
|
57 |
loadData(); |
|
58 |
} |
|
59 |
} |
|
60 |
|
|
61 |
@Override |
|
62 |
protected void onSaveInstanceState(Bundle state){ |
|
63 |
state.putSerializable("backup", backup); |
|
64 |
} |
|
65 |
|
|
66 |
private void setupSpinners(){ |
|
67 |
weeklyBackupSpinner = (Spinner) findViewById(R.id.weekly_backup_spinner); |
|
68 |
ArrayAdapter<CharSequence> weeklyAdapter = ArrayAdapter.createFromResource(this, R.array.weeklyBackupValues, android.R.layout.simple_spinner_item); |
|
69 |
weeklyAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); |
|
70 |
weeklyBackupSpinner.setAdapter(weeklyAdapter); |
|
71 |
weeklyBackupSpinner.setOnItemSelectedListener(this); |
|
72 |
|
|
73 |
|
|
74 |
dailyBackupSpinner = (Spinner) findViewById(R.id.daily_backup_spinner); |
|
75 |
ArrayAdapter<CharSequence> dailyAdapter = ArrayAdapter.createFromResource(this, R.array.dailyBackupValues, android.R.layout.simple_spinner_item); |
|
76 |
dailyAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); |
|
77 |
dailyBackupSpinner.setAdapter(dailyAdapter); |
|
78 |
dailyBackupSpinner.setOnItemSelectedListener(this); |
|
45 | 79 |
} |
46 | 80 |
|
47 |
private void setupSpinners(){ |
|
48 |
weeklyBackupSpinner = (Spinner) findViewById(R.id.weekly_backup_spinner); |
|
49 |
ArrayAdapter<CharSequence> weeklyAdapter = ArrayAdapter.createFromResource(this, R.array.weeklyBackupValues, android.R.layout.simple_spinner_item); |
|
50 |
weeklyAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); |
|
51 |
weeklyBackupSpinner.setAdapter(weeklyAdapter); |
|
52 |
weeklyBackupSpinner.setOnItemSelectedListener(this); |
|
53 |
|
|
54 |
|
|
55 |
dailyBackupSpinner = (Spinner) findViewById(R.id.daily_backup_spinner); |
|
56 |
ArrayAdapter<CharSequence> dailyAdapter = ArrayAdapter.createFromResource(this, R.array.dailyBackupValues, android.R.layout.simple_spinner_item); |
|
57 |
dailyAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); |
|
58 |
dailyBackupSpinner.setAdapter(dailyAdapter); |
|
59 |
dailyBackupSpinner.setOnItemSelectedListener(this); |
|
60 |
} |
|
61 |
|
|
62 | 81 |
private void setupButtons() { |
63 | 82 |
Button update = (Button) findViewById(R.id.backup_update_button); |
64 | 83 |
update.setOnClickListener(this); |
65 | 84 |
} |
66 |
|
|
85 |
|
|
67 | 86 |
private void setupCheckBox(){ |
68 | 87 |
enableCheckBox = (CheckBox) findViewById(R.id.enable_backup_checkbox); |
69 | 88 |
} |
70 |
|
|
89 |
|
|
90 |
private void displayData(){ |
|
91 |
if(backup != null){ |
|
92 |
enableCheckBox.setChecked(backup.getEnable()); |
|
93 |
|
|
94 |
if(backup.getWeekly() != null){ |
|
95 |
weeklyBackupSpinner.setSelection(Backup.getWeeklyIndex(backup.getWeekly())); |
|
96 |
} |
|
97 |
|
|
98 |
if(backup.getDaily() != null){ |
|
99 |
dailyBackupSpinner.setSelection(Backup.getDailyIndex(backup.getDaily())); |
|
100 |
} |
|
101 |
} |
|
102 |
} |
|
103 |
|
|
71 | 104 |
public void onClick(View v) { |
72 | 105 |
/* |
73 | 106 |
* server maybe null if another task is |
... | ... | |
94 | 127 |
public void onNothingSelected(AdapterView<?> parent) { |
95 | 128 |
//do nothing |
96 | 129 |
} |
97 |
|
|
130 |
|
|
131 |
private void loadData(){ |
|
132 |
new GetBackUpTask().execute((Void[]) null); |
|
133 |
} |
|
134 |
|
|
135 |
private class GetBackUpTask extends AsyncTask<Void, Void, Backup> { |
|
136 |
|
|
137 |
private CloudServersException exception; |
|
138 |
|
|
139 |
@Override |
|
140 |
//let user know their process has started |
|
141 |
protected void onPreExecute(){ |
|
142 |
showDialog(); |
|
143 |
} |
|
144 |
|
|
145 |
@Override |
|
146 |
protected Backup doInBackground(Void... arg0) { |
|
147 |
try { |
|
148 |
return (new BackupManager()).getBackup(server, getContext()); |
|
149 |
} catch (CloudServersException e) { |
|
150 |
exception = e; |
|
151 |
} |
|
152 |
return null; |
|
153 |
} |
|
154 |
|
|
155 |
@Override |
|
156 |
protected void onPostExecute(Backup result) { |
|
157 |
hideDialog(); |
|
158 |
if (exception != null) { |
|
159 |
showAlert("Error", exception.getMessage()); |
|
160 |
} else { |
|
161 |
backup = new Backup(); |
|
162 |
backup.setEnabled(result.getEnable()); |
|
163 |
backup.setWeekly(result.getWeekly()); |
|
164 |
backup.setDaily(result.getDaily()); |
|
165 |
displayData(); |
|
166 |
} |
|
167 |
} |
|
168 |
} |
|
169 |
|
|
98 | 170 |
private class BackupServerTask extends AsyncTask<Void, Void, HttpBundle> { |
99 |
|
|
171 |
|
|
100 | 172 |
private CloudServersException exception; |
101 |
|
|
173 |
|
|
102 | 174 |
@Override |
103 | 175 |
//let user know their process has started |
104 | 176 |
protected void onPreExecute(){ |
105 | 177 |
showToast("Changing backup schedule process has begun"); |
106 | 178 |
} |
107 |
|
|
179 |
|
|
108 | 180 |
@Override |
109 | 181 |
protected HttpBundle doInBackground(Void... arg0) { |
110 | 182 |
HttpBundle bundle = null; |
... | ... | |
115 | 187 |
} |
116 | 188 |
return bundle; |
117 | 189 |
} |
118 |
|
|
190 |
|
|
119 | 191 |
@Override |
120 | 192 |
protected void onPostExecute(HttpBundle bundle) { |
121 | 193 |
HttpResponse response = bundle.getResponse(); |
... | ... | |
135 | 207 |
} |
136 | 208 |
} else if (exception != null) { |
137 | 209 |
showError("There was a problem changing the backup schedule: " + exception.getMessage(), bundle); |
138 |
|
|
210 |
|
|
139 | 211 |
} |
140 | 212 |
} |
141 |
}
|
|
213 |
}
|
|
142 | 214 |
} |
b/src/com/rackspacecloud/android/ConnectionThrottleActivity.java | ||
---|---|---|
18 | 18 |
import com.rackspace.cloud.servers.api.client.http.HttpBundle; |
19 | 19 |
|
20 | 20 |
public class ConnectionThrottleActivity extends CloudActivity{ |
21 |
|
|
21 |
|
|
22 | 22 |
private LoadBalancer loadBalancer; |
23 | 23 |
private ConnectionThrottle connectionThrottle; |
24 | 24 |
private EditText minCons; |
25 | 25 |
private EditText maxCons; |
26 | 26 |
private EditText maxConRate; |
27 | 27 |
private EditText rateInterval; |
28 |
|
|
28 |
|
|
29 | 29 |
private final String ENABLE = "Enable Throttle"; |
30 | 30 |
private final String DISABLE = "Disable Throttle"; |
31 |
|
|
31 |
|
|
32 | 32 |
@Override |
33 | 33 |
public void onCreate(Bundle savedInstanceState) { |
34 | 34 |
super.onCreate(savedInstanceState); |
... | ... | |
37 | 37 |
restoreState(savedInstanceState); |
38 | 38 |
} |
39 | 39 |
|
40 |
@Override |
|
41 |
protected void onSaveInstanceState(Bundle outState) { |
|
42 |
super.onSaveInstanceState(outState); |
|
43 |
outState.putSerializable("loadBalancer", loadBalancer); |
|
44 |
} |
|
45 |
|
|
46 |
|
|
40 | 47 |
protected void restoreState(Bundle state) { |
41 | 48 |
super.restoreState(state); |
42 | 49 |
|
50 |
if(state != null && state.containsKey("loadBalancer")){ |
|
51 |
loadBalancer = (LoadBalancer)state.getSerializable("loadBalancer"); |
|
52 |
} |
|
43 | 53 |
minCons = (EditText)findViewById(R.id.min_connections_text); |
44 | 54 |
maxCons = (EditText)findViewById(R.id.max_connections_text); |
45 | 55 |
maxConRate = (EditText)findViewById(R.id.max_connection_rate); |
46 | 56 |
rateInterval = (EditText)findViewById(R.id.rate_interval); |
47 |
|
|
57 |
|
|
48 | 58 |
setupButtons(); |
49 | 59 |
setupText(); |
50 | 60 |
} |
51 |
|
|
61 |
|
|
52 | 62 |
private void setupButtons(){ |
53 | 63 |
Button enable = (Button)findViewById(R.id.enable_throttle_button); |
54 | 64 |
if(loadBalancer.getConnectionThrottle() == null){ |
... | ... | |
61 | 71 |
@Override |
62 | 72 |
public void onClick(View v) { |
63 | 73 |
if(enable.getText().toString().equals(ENABLE)){ |
74 |
ConnectionThrottle connectionThrottle = new ConnectionThrottle(); |
|
75 |
connectionThrottle.setMinConnections("25"); |
|
76 |
connectionThrottle.setMaxConnections("100"); |
|
77 |
connectionThrottle.setMaxConnectionRate("25"); |
|
78 |
connectionThrottle.setRateInterval("5"); |
|
79 |
|
|
80 |
loadBalancer.setConnectionThrottle(connectionThrottle); |
|
64 | 81 |
//Turn on EditTexts |
65 | 82 |
minCons.setEnabled(true); |
66 | 83 |
maxCons.setEnabled(true); |
... | ... | |
68 | 85 |
rateInterval.setEnabled(true); |
69 | 86 |
enable.setText(DISABLE); |
70 | 87 |
} else { |
88 |
loadBalancer.setConnectionThrottle(null); |
|
71 | 89 |
//Turn off EditTexts |
72 | 90 |
minCons.setEnabled(false); |
73 | 91 |
maxCons.setEnabled(false); |
... | ... | |
80 | 98 |
|
81 | 99 |
Button submit = (Button)findViewById(R.id.save_throttle_button); |
82 | 100 |
submit.setOnClickListener(new OnClickListener() { |
83 |
|
|
101 |
|
|
84 | 102 |
Button enable = (Button)findViewById(R.id.enable_throttle_button); |
85 |
|
|
103 |
|
|
86 | 104 |
@Override |
87 | 105 |
public void onClick(View v) { |
88 |
|
|
106 |
|
|
89 | 107 |
connectionThrottle = new ConnectionThrottle(); |
90 | 108 |
connectionThrottle.setMaxConnectionRate(maxConRate.getText().toString()); |
91 | 109 |
connectionThrottle.setMinConnections(minCons.getText().toString()); |
92 | 110 |
connectionThrottle.setMaxConnections(maxCons.getText().toString()); |
93 | 111 |
connectionThrottle.setRateInterval(rateInterval.getText().toString()); |
94 |
|
|
112 |
|
|
95 | 113 |
if(enable.getText().toString().equals(DISABLE)){ |
96 | 114 |
if(validText()){ |
97 | 115 |
new UpdateConnectionThrottleTask().execute(); |
... | ... | |
108 | 126 |
} |
109 | 127 |
}); |
110 | 128 |
} |
111 |
|
|
129 |
|
|
112 | 130 |
private void setupText(){ |
113 | 131 |
if(loadBalancer.getConnectionThrottle() == null){ |
114 | 132 |
minCons.setEnabled(false); |
115 | 133 |
maxCons.setEnabled(false); |
116 | 134 |
maxConRate.setEnabled(false); |
117 | 135 |
rateInterval.setEnabled(false); |
118 |
|
|
136 |
|
|
119 | 137 |
//Set boxes to default values |
120 | 138 |
minCons.setText("25"); |
121 | 139 |
maxCons.setText("100"); |
... | ... | |
123 | 141 |
rateInterval.setText("5"); |
124 | 142 |
} else { |
125 | 143 |
ConnectionThrottle throttle = loadBalancer.getConnectionThrottle(); |
126 |
|
|
144 |
|
|
127 | 145 |
//restore the current values to the boxes |
128 | 146 |
minCons.setText(throttle.getMinConnections()); |
129 | 147 |
maxCons.setText(throttle.getMaxConnections()); |
... | ... | |
131 | 149 |
rateInterval.setText(throttle.getRateInterval()); |
132 | 150 |
} |
133 | 151 |
} |
134 |
|
|
152 |
|
|
135 | 153 |
private Boolean validText(){ |
136 | 154 |
return validEditText(maxCons, 0, 100000, "Max Connections") |
137 |
&& validEditText(minCons, 0, 1000, "Min Connections")
|
|
138 |
&& validEditText(maxConRate, 0, 100000, "Max Connection Rate")
|
|
139 |
&& validEditText(rateInterval, 1, 3600, "Rate Interval");
|
|
155 |
&& validEditText(minCons, 0, 1000, "Min Connections") |
|
156 |
&& validEditText(maxConRate, 0, 100000, "Max Connection Rate") |
|
157 |
&& validEditText(rateInterval, 1, 3600, "Rate Interval"); |
|
140 | 158 |
} |
141 |
|
|
159 |
|
|
142 | 160 |
private Boolean validEditText(EditText box, int min, int max, String boxName){ |
143 | 161 |
String result = box.getText().toString(); |
144 | 162 |
if(result.equals("")){ |
... | ... | |
160 | 178 |
} |
161 | 179 |
} |
162 | 180 |
} |
163 |
|
|
181 |
|
|
164 | 182 |
public class UpdateConnectionThrottleTask extends AsyncTask<Void, Void, HttpBundle> { |
165 | 183 |
|
166 | 184 |
private CloudServersException exception; |
... | ... | |
203 | 221 |
} |
204 | 222 |
} |
205 | 223 |
} |
206 |
|
|
224 |
|
|
207 | 225 |
public class DeleteConnectionThrottleTask extends AsyncTask<Void, Void, HttpBundle> { |
208 | 226 |
|
209 | 227 |
private CloudServersException exception; |
Also available in: Unified diff