root / src / com / rackspacecloud / android / ViewServerActivity.java @ 48601850
History | View | Annotate | Download (24.6 kB)
1 |
/**
|
---|---|
2 |
*
|
3 |
*/
|
4 |
package com.rackspacecloud.android; |
5 |
|
6 |
import java.util.Arrays; |
7 |
import java.util.Iterator; |
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.view.Menu; |
20 |
import android.view.MenuInflater; |
21 |
import android.view.MenuItem; |
22 |
import android.view.View; |
23 |
import android.view.View.OnClickListener; |
24 |
import android.widget.Button; |
25 |
import android.widget.EditText; |
26 |
import android.widget.LinearLayout; |
27 |
import android.widget.TextView; |
28 |
|
29 |
import com.rackspace.cloud.android.R; |
30 |
import com.rackspace.cloud.servers.api.client.CloudServersException; |
31 |
import com.rackspace.cloud.servers.api.client.Flavor; |
32 |
import com.rackspace.cloud.servers.api.client.Image; |
33 |
import com.rackspace.cloud.servers.api.client.ImageManager; |
34 |
import com.rackspace.cloud.servers.api.client.Server; |
35 |
import com.rackspace.cloud.servers.api.client.ServerManager; |
36 |
import com.rackspace.cloud.servers.api.client.http.HttpBundle; |
37 |
|
38 |
/**
|
39 |
* @author Mike Mayo - mike.mayo@rackspace.com - twitter.com/greenisus
|
40 |
*
|
41 |
*/
|
42 |
public class ViewServerActivity extends CloudActivity { |
43 |
|
44 |
private Server server;
|
45 |
private boolean ipAddressesLoaded; // to prevent polling from loading tons of duplicates |
46 |
private Flavor[] flavors; |
47 |
private String[] flavorNames; |
48 |
private String selectedFlavorId; |
49 |
private String modifiedServerName; |
50 |
private Image[] images; |
51 |
private String[] imageNames; |
52 |
private String selectedImageId; |
53 |
private boolean isPolling; |
54 |
private PollServerTask pollServerTask;
|
55 |
private boolean canPoll; |
56 |
private boolean noAskForConfirm; |
57 |
private Image image; |
58 |
|
59 |
/** Called when the activity is first created. */
|
60 |
@Override
|
61 |
public void onCreate(Bundle savedInstanceState) { |
62 |
super.onCreate(savedInstanceState);
|
63 |
trackPageView(GoogleAnalytics.PAGE_SERVER); |
64 |
server = (Server) this.getIntent().getExtras().get("server"); |
65 |
//if an old image it wont be on the image list
|
66 |
//so you have to fetch it manually
|
67 |
if(server.getImage().getName() == null){ |
68 |
GetImageTask getImageTask = new GetImageTask();
|
69 |
getImageTask.execute((Void[]) null); |
70 |
} |
71 |
setContentView(R.layout.viewserver); |
72 |
restoreState(savedInstanceState); |
73 |
} |
74 |
|
75 |
@Override
|
76 |
protected void onSaveInstanceState(Bundle outState) { |
77 |
super.onSaveInstanceState(outState);
|
78 |
outState.putSerializable("server", server);
|
79 |
outState.putBoolean("noAskForConfirm", noAskForConfirm);
|
80 |
if(pollServerTask != null && isPolling){ |
81 |
pollServerTask.cancel(true);
|
82 |
} |
83 |
outState.putBoolean("wasPolling", isPolling);
|
84 |
} |
85 |
|
86 |
protected void restoreState(Bundle state) { |
87 |
super.restoreState(state);
|
88 |
if(state != null && state.containsKey("noAskForConfirm")){ |
89 |
noAskForConfirm = state.getBoolean("noAskForConfirm");
|
90 |
} |
91 |
if(state != null && state.containsKey("wasPolling") && state.getBoolean("wasPolling") == true){ |
92 |
pollServerTask = new PollServerTask();
|
93 |
pollServerTask.execute((Void[]) null); |
94 |
} |
95 |
if (server == null && state != null && state.containsKey("server")) { |
96 |
server = (Server) state.getSerializable("server");
|
97 |
//imageLoaded = state.getBoolean("imageLoaded");
|
98 |
} |
99 |
canPoll = true;
|
100 |
loadServerData(); |
101 |
setupButtons(); |
102 |
loadFlavors(); |
103 |
loadImages(); |
104 |
} |
105 |
|
106 |
/*
|
107 |
* need to manage the polling task
|
108 |
* if the activity is stopped
|
109 |
*/
|
110 |
@Override
|
111 |
public void onStop(){ |
112 |
super.onStop();
|
113 |
if(pollServerTask != null && isPolling){ |
114 |
pollServerTask.cancel(true);
|
115 |
isPolling = true;
|
116 |
} |
117 |
canPoll = false;
|
118 |
|
119 |
} |
120 |
|
121 |
/*
|
122 |
* restart the pollingtask
|
123 |
* if it was running before
|
124 |
*
|
125 |
*/
|
126 |
@Override
|
127 |
public void onStart(){ |
128 |
super.onStart();
|
129 |
if(isPolling){
|
130 |
pollServerTask = new PollServerTask();
|
131 |
pollServerTask.execute((Void[]) null); |
132 |
} |
133 |
canPoll = true;
|
134 |
|
135 |
} |
136 |
|
137 |
private void loadServerData() { |
138 |
if(server != null){ |
139 |
|
140 |
TextView name = (TextView) findViewById(R.id.view_server_name); |
141 |
name.setText(server.getName()); |
142 |
|
143 |
TextView os = (TextView) findViewById(R.id.view_server_os); |
144 |
if(server.getImage().getName() == null){ |
145 |
if(image != null){ |
146 |
os.setText(image.getName()); |
147 |
} |
148 |
} else {
|
149 |
os.setText(server.getImage().getName()); |
150 |
} |
151 |
|
152 |
TextView memory = (TextView) findViewById(R.id.view_server_memory); |
153 |
memory.setText(server.getFlavor().getRam() + " MB");
|
154 |
|
155 |
TextView disk = (TextView) findViewById(R.id.view_server_disk); |
156 |
disk.setText(server.getFlavor().getDisk() + " GB");
|
157 |
|
158 |
TextView status = (TextView) findViewById(R.id.view_server_status); |
159 |
|
160 |
if(noAskForConfirm == false){ |
161 |
if(status.getText().toString().contains("VERIFY_RESIZE")){ |
162 |
//show the confimresizeactivity
|
163 |
noAskForConfirm = true;
|
164 |
Intent viewIntent = new Intent(getApplicationContext(), ConfirmResizeActivity.class);
|
165 |
viewIntent.putExtra("server", server);
|
166 |
startActivity(viewIntent); |
167 |
} |
168 |
} |
169 |
|
170 |
// show status and possibly the progress, with polling
|
171 |
if (!"ACTIVE".equals(server.getStatus())) { |
172 |
status.setText(server.getStatus() + " - " + server.getProgress() + "%"); |
173 |
pollServerTask = new PollServerTask();
|
174 |
pollServerTask.execute((Void[]) null); |
175 |
} else {
|
176 |
status.setText(server.getStatus()); |
177 |
} |
178 |
|
179 |
if (!ipAddressesLoaded) {
|
180 |
// public IPs
|
181 |
int layoutIndex = 12; // public IPs start here |
182 |
LinearLayout layout = (LinearLayout) this.findViewById(R.id.view_server_layout);
|
183 |
String publicIps[] = server.getPublicIpAddresses(); |
184 |
for (int i = 0; i < publicIps.length; i++) { |
185 |
TextView tv = new TextView(this.getBaseContext()); |
186 |
tv.setLayoutParams(os.getLayoutParams()); // easy quick styling! :)
|
187 |
tv.setTypeface(tv.getTypeface(), 1); // 1 == bold |
188 |
tv.setTextSize(os.getTextSize()); |
189 |
tv.setGravity(os.getGravity()); |
190 |
tv.setTextColor(Color.WHITE);
|
191 |
tv.setText(publicIps[i]); |
192 |
layout.addView(tv, layoutIndex++); |
193 |
} |
194 |
|
195 |
// private IPs
|
196 |
layoutIndex++; // skip over the Private IPs label
|
197 |
String privateIps[] = server.getPrivateIpAddresses(); |
198 |
for (int i = 0; i < privateIps.length; i++) { |
199 |
TextView tv = new TextView(this.getBaseContext()); |
200 |
tv.setLayoutParams(os.getLayoutParams()); // easy quick styling! :)
|
201 |
tv.setTypeface(tv.getTypeface(), 1); // 1 == bold |
202 |
tv.setTextSize(os.getTextSize()); |
203 |
tv.setGravity(os.getGravity()); |
204 |
tv.setTextColor(Color.WHITE);
|
205 |
tv.setText(privateIps[i]); |
206 |
layout.addView(tv, layoutIndex++); |
207 |
} |
208 |
ipAddressesLoaded = true;
|
209 |
} |
210 |
} |
211 |
|
212 |
//loadImage();
|
213 |
} |
214 |
|
215 |
private void loadFlavors() { |
216 |
flavorNames = new String[Flavor.getFlavors().size()]; |
217 |
flavors = new Flavor[Flavor.getFlavors().size()];
|
218 |
|
219 |
Iterator<Flavor> iter = Flavor.getFlavors().values().iterator();
|
220 |
int i = 0; |
221 |
while (iter.hasNext()) {
|
222 |
Flavor flavor = iter.next(); |
223 |
flavors[i] = flavor; |
224 |
flavorNames[i] = flavor.getName() + ", " + flavor.getDisk() + " GB disk"; |
225 |
i++; |
226 |
} |
227 |
selectedFlavorId = flavors[0].getId();
|
228 |
} |
229 |
|
230 |
private void loadImages() { |
231 |
imageNames = new String[Image.getImages().size()]; |
232 |
images = new Image[Image.getImages().size()]; |
233 |
|
234 |
Iterator<Image> iter = Image.getImages().values().iterator(); |
235 |
int i = 0; |
236 |
while (iter.hasNext()) {
|
237 |
Image image = iter.next();
|
238 |
images[i] = image; |
239 |
imageNames[i] = image.getName(); |
240 |
i++; |
241 |
} |
242 |
//sort arrays so they display nicely in the spinner
|
243 |
Arrays.sort(images);
|
244 |
Arrays.sort(imageNames);
|
245 |
selectedImageId = images[0].getId();
|
246 |
|
247 |
} |
248 |
|
249 |
private void setupButton(int resourceId, OnClickListener onClickListener) { |
250 |
Button button = (Button) findViewById(resourceId); |
251 |
button.setOnClickListener(onClickListener); |
252 |
} |
253 |
|
254 |
private void setupButtons() { |
255 |
setupButton(R.id.view_server_soft_reboot_button, new OnClickListener() {
|
256 |
public void onClick(View v) { |
257 |
showDialog(R.id.view_server_soft_reboot_button); |
258 |
} |
259 |
}); |
260 |
|
261 |
setupButton(R.id.view_server_hard_reboot_button, new OnClickListener() {
|
262 |
public void onClick(View v) { |
263 |
showDialog(R.id.view_server_hard_reboot_button); |
264 |
} |
265 |
}); |
266 |
|
267 |
setupButton(R.id.view_server_resize_button, new OnClickListener() {
|
268 |
public void onClick(View v) { |
269 |
showDialog(R.id.view_server_resize_button); |
270 |
} |
271 |
}); |
272 |
|
273 |
setupButton(R.id.view_server_delete_button, new OnClickListener() {
|
274 |
public void onClick(View v) { |
275 |
showDialog(R.id.view_server_delete_button); |
276 |
} |
277 |
}); |
278 |
|
279 |
setupButton(R.id.view_server_rename_button, new OnClickListener() {
|
280 |
public void onClick(View v) { |
281 |
showDialog(R.id.view_server_rename_button); |
282 |
} |
283 |
}); |
284 |
|
285 |
setupButton(R.id.view_server_rebuild_button, new OnClickListener() {
|
286 |
public void onClick(View v) { |
287 |
showDialog(R.id.view_server_rebuild_button); |
288 |
} |
289 |
}); |
290 |
|
291 |
|
292 |
setupButton(R.id.view_server_backup_button, new OnClickListener() {
|
293 |
public void onClick(View v) { |
294 |
Intent viewIntent = new Intent(v.getContext(), BackupServerActivity.class);
|
295 |
viewIntent.putExtra("server", server);
|
296 |
startActivity(viewIntent); |
297 |
} |
298 |
}); |
299 |
|
300 |
setupButton(R.id.view_server_password_button, new OnClickListener() {
|
301 |
public void onClick(View v) { |
302 |
Intent viewIntent = new Intent(v.getContext(), PasswordServerActivity.class);
|
303 |
viewIntent.putExtra("server", server);
|
304 |
startActivity(viewIntent); |
305 |
} |
306 |
}); |
307 |
|
308 |
setupButton(R.id.view_server_ping_button, new OnClickListener() {
|
309 |
public void onClick(View v) { |
310 |
trackEvent(GoogleAnalytics.CATEGORY_SERVER, GoogleAnalytics.EVENT_PING, "", -1); |
311 |
|
312 |
//ping the first public ip
|
313 |
Intent viewIntent = new Intent(v.getContext(), PingServerActivity.class);
|
314 |
viewIntent.putExtra("ipAddress", server.getPublicIpAddresses()[0]); |
315 |
startActivity(viewIntent); |
316 |
|
317 |
|
318 |
} |
319 |
}); |
320 |
|
321 |
} |
322 |
|
323 |
/**
|
324 |
* @return the server
|
325 |
*/
|
326 |
public Server getServer() {
|
327 |
return server;
|
328 |
} |
329 |
|
330 |
/**
|
331 |
* @param server the server to set
|
332 |
*/
|
333 |
public void setServer(Server server) { |
334 |
this.server = server;
|
335 |
} |
336 |
|
337 |
//setup menu for when menu button is pressed
|
338 |
public boolean onCreateOptionsMenu(Menu menu) { |
339 |
super.onCreateOptionsMenu(menu);
|
340 |
MenuInflater inflater = getMenuInflater(); |
341 |
inflater.inflate(R.menu.view_server_activity_menu, menu); |
342 |
return true; |
343 |
} |
344 |
|
345 |
@Override
|
346 |
//in options menu, when add account is selected go to add account activity
|
347 |
public boolean onOptionsItemSelected(MenuItem item) { |
348 |
switch (item.getItemId()) {
|
349 |
case R.id.refresh_server:
|
350 |
loadServerData(); |
351 |
return true; |
352 |
} |
353 |
return false; |
354 |
} |
355 |
|
356 |
@Override
|
357 |
protected Dialog onCreateDialog(int id) { |
358 |
if(server == null){ |
359 |
return new AlertDialog.Builder(ViewServerActivity.this) |
360 |
.setIcon(R.drawable.alert_dialog_icon) |
361 |
.setTitle("Error")
|
362 |
.setMessage("Server is Busy")
|
363 |
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { |
364 |
public void onClick(DialogInterface dialog, int whichButton) { |
365 |
// User clicked Cancel so do some stuff
|
366 |
} |
367 |
}) |
368 |
.create(); |
369 |
} |
370 |
else{
|
371 |
switch (id) {
|
372 |
case R.id.view_server_soft_reboot_button:
|
373 |
return new AlertDialog.Builder(ViewServerActivity.this) |
374 |
.setIcon(R.drawable.alert_dialog_icon) |
375 |
.setTitle("Soft Reboot")
|
376 |
.setMessage("Are you sure you want to perform a soft reboot?")
|
377 |
.setPositiveButton("Reboot Server", new DialogInterface.OnClickListener() { |
378 |
public void onClick(DialogInterface dialog, int whichButton) { |
379 |
trackEvent(GoogleAnalytics.CATEGORY_SERVER, GoogleAnalytics.EVENT_REBOOT, "", -1); |
380 |
new SoftRebootServerTask().execute((Void[]) null); |
381 |
} |
382 |
}) |
383 |
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { |
384 |
public void onClick(DialogInterface dialog, int whichButton) { |
385 |
// User clicked Cancel so do some stuff
|
386 |
} |
387 |
}) |
388 |
.create(); |
389 |
case R.id.view_server_hard_reboot_button:
|
390 |
return new AlertDialog.Builder(ViewServerActivity.this) |
391 |
.setIcon(R.drawable.alert_dialog_icon) |
392 |
.setTitle("Hard Reboot")
|
393 |
.setMessage("Are you sure you want to perform a hard reboot?")
|
394 |
.setPositiveButton("Reboot Server", new DialogInterface.OnClickListener() { |
395 |
public void onClick(DialogInterface dialog, int whichButton) { |
396 |
trackEvent(GoogleAnalytics.CATEGORY_SERVER, GoogleAnalytics.EVENT_REBOOT, "", -1); |
397 |
new HardRebootServerTask().execute((Void[]) null); |
398 |
} |
399 |
}) |
400 |
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { |
401 |
public void onClick(DialogInterface dialog, int whichButton) { |
402 |
// User clicked Cancel so do some stuff
|
403 |
} |
404 |
}) |
405 |
.create(); |
406 |
case R.id.view_server_resize_button:
|
407 |
return new AlertDialog.Builder(ViewServerActivity.this) |
408 |
.setItems(flavorNames, new ResizeClickListener())
|
409 |
.setIcon(R.drawable.alert_dialog_icon) |
410 |
.setTitle("Resize Server")
|
411 |
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { |
412 |
public void onClick(DialogInterface dialog, int whichButton) { |
413 |
// User clicked Cancel so do some stuff
|
414 |
} |
415 |
}) |
416 |
.create(); |
417 |
case R.id.view_server_delete_button:
|
418 |
return new AlertDialog.Builder(ViewServerActivity.this) |
419 |
.setIcon(R.drawable.alert_dialog_icon) |
420 |
.setTitle("Delete Server")
|
421 |
.setMessage("Are you sure you want to delete this server? This operation cannot be undone and all backups will be deleted.")
|
422 |
.setPositiveButton("Delete Server", new DialogInterface.OnClickListener() { |
423 |
public void onClick(DialogInterface dialog, int whichButton) { |
424 |
trackEvent(GoogleAnalytics.CATEGORY_SERVER, GoogleAnalytics.EVENT_DELETE, "", -1); |
425 |
new DeleteServerTask().execute((Void[]) null); |
426 |
} |
427 |
}) |
428 |
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { |
429 |
public void onClick(DialogInterface dialog, int whichButton) { |
430 |
// User clicked Cancel so do some stuff
|
431 |
} |
432 |
}) |
433 |
.create(); |
434 |
case R.id.view_server_rename_button:
|
435 |
final EditText input = new EditText(this); |
436 |
input.setText(server.getName()); |
437 |
return new AlertDialog.Builder(ViewServerActivity.this) |
438 |
.setIcon(R.drawable.alert_dialog_icon) |
439 |
.setView(input) |
440 |
.setTitle("Rename")
|
441 |
.setMessage("Enter new name for server: ")
|
442 |
.setPositiveButton("Rename", new DialogInterface.OnClickListener() { |
443 |
public void onClick(DialogInterface dialog, int whichButton) { |
444 |
trackEvent(GoogleAnalytics.CATEGORY_SERVER, GoogleAnalytics.EVENT_RENAME, "", -1); |
445 |
modifiedServerName = input.getText().toString(); |
446 |
new RenameServerTask().execute((Void[]) null); |
447 |
} |
448 |
}) |
449 |
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { |
450 |
public void onClick(DialogInterface dialog, int whichButton) { |
451 |
// User clicked Cancel so do some stuff
|
452 |
} |
453 |
}) |
454 |
.create(); |
455 |
case R.id.view_server_rebuild_button:
|
456 |
return new AlertDialog.Builder(ViewServerActivity.this) |
457 |
.setItems(imageNames, new RebuildClickListener())
|
458 |
.setIcon(R.drawable.alert_dialog_icon) |
459 |
.setTitle("Rebuild Server")
|
460 |
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { |
461 |
public void onClick(DialogInterface dialog, int whichButton) { |
462 |
// User clicked Cancel so do some stuff
|
463 |
} |
464 |
}) |
465 |
.create(); |
466 |
} |
467 |
} |
468 |
return new AlertDialog.Builder(ViewServerActivity.this) |
469 |
.setIcon(R.drawable.alert_dialog_icon) |
470 |
.setTitle("Error")
|
471 |
.setMessage("Server is Busy")
|
472 |
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { |
473 |
public void onClick(DialogInterface dialog, int whichButton) { |
474 |
// User clicked Cancel so do some stuff
|
475 |
} |
476 |
}) |
477 |
.create(); |
478 |
} |
479 |
|
480 |
private class ResizeClickListener implements android.content.DialogInterface.OnClickListener { |
481 |
|
482 |
public void onClick(DialogInterface dialog, int which) { |
483 |
trackEvent(GoogleAnalytics.CATEGORY_SERVER, GoogleAnalytics.EVENT_RESIZE, "", -1); |
484 |
selectedFlavorId = which + 1 + ""; |
485 |
new ResizeServerTask().execute((Void[]) null); |
486 |
} |
487 |
|
488 |
} |
489 |
|
490 |
private class RebuildClickListener implements android.content.DialogInterface.OnClickListener { |
491 |
|
492 |
public void onClick(DialogInterface dialog, int which) { |
493 |
trackEvent(GoogleAnalytics.CATEGORY_SERVER, GoogleAnalytics.EVENT_REBUILD, "", -1); |
494 |
selectedImageId = images[which].getId() + "";
|
495 |
new RebuildServerTask().execute((Void[]) null); |
496 |
} |
497 |
|
498 |
} |
499 |
|
500 |
// HTTP request tasks
|
501 |
|
502 |
private class PollServerTask extends AsyncTask<Void, Void, Server> { |
503 |
|
504 |
private Server tempServer;
|
505 |
|
506 |
@Override
|
507 |
protected void onPreExecute(){ |
508 |
isPolling = true;
|
509 |
} |
510 |
|
511 |
@Override
|
512 |
protected Server doInBackground(Void... arg0) { |
513 |
if(isCancelled() || !canPoll){
|
514 |
return null; |
515 |
} |
516 |
try {
|
517 |
tempServer = (new ServerManager()).find(Integer.parseInt(server.getId()), getContext()); |
518 |
} catch (NumberFormatException e) { |
519 |
// we're polling, so need to show exceptions
|
520 |
} catch (CloudServersException e) {
|
521 |
// we're polling, so need to show exceptions
|
522 |
} |
523 |
return tempServer;
|
524 |
} |
525 |
|
526 |
@Override
|
527 |
protected void onPostExecute(Server result) { |
528 |
server = result; |
529 |
if(server != null){ |
530 |
loadServerData(); |
531 |
} |
532 |
isPolling = false;
|
533 |
} |
534 |
|
535 |
@Override
|
536 |
protected void onCancelled (){ |
537 |
isPolling = false;
|
538 |
} |
539 |
|
540 |
} |
541 |
|
542 |
private class GetImageTask extends AsyncTask<Void, Void, Image> { |
543 |
|
544 |
private Image tempImage; |
545 |
|
546 |
@Override
|
547 |
protected Image doInBackground(Void... arg0) { |
548 |
try {
|
549 |
tempImage = (new ImageManager()).getImageDetails(Integer.parseInt(server.getImageId()), getContext()); |
550 |
} catch (NumberFormatException e) { |
551 |
|
552 |
} |
553 |
return tempImage;
|
554 |
} |
555 |
|
556 |
@Override
|
557 |
protected void onPostExecute(Image result) { |
558 |
image = result; |
559 |
loadServerData(); |
560 |
} |
561 |
|
562 |
} |
563 |
|
564 |
private class SoftRebootServerTask extends AsyncTask<Void, Void, HttpBundle> { |
565 |
|
566 |
private CloudServersException exception;
|
567 |
|
568 |
@Override
|
569 |
//let user know their process has started
|
570 |
protected void onPreExecute(){ |
571 |
showToast("Reboot process has begun");
|
572 |
} |
573 |
|
574 |
@Override
|
575 |
protected HttpBundle doInBackground(Void... arg0) { |
576 |
HttpBundle bundle = null;
|
577 |
try {
|
578 |
bundle = (new ServerManager()).reboot(server, ServerManager.SOFT_REBOOT, getContext());
|
579 |
} catch (CloudServersException e) {
|
580 |
exception = e; |
581 |
} |
582 |
return bundle;
|
583 |
} |
584 |
|
585 |
@Override
|
586 |
protected void onPostExecute(HttpBundle bundle) { |
587 |
HttpResponse response = bundle.getResponse(); |
588 |
if (response != null) { |
589 |
int statusCode = response.getStatusLine().getStatusCode();
|
590 |
if(statusCode == 202){ showToast("Reboot successful"); } |
591 |
if (statusCode != 202) { |
592 |
CloudServersException cse = parseCloudServersException(response); |
593 |
if ("".equals(cse.getMessage())) { |
594 |
showError("There was a problem rebooting your server.", bundle);
|
595 |
} else {
|
596 |
showError("There was a problem rebooting your server: " + cse.getMessage(), bundle);
|
597 |
} |
598 |
} |
599 |
} else if (exception != null) { |
600 |
showError("There was a problem rebooting your server: " + exception.getMessage(), bundle);
|
601 |
|
602 |
} |
603 |
} |
604 |
} |
605 |
|
606 |
private class HardRebootServerTask extends AsyncTask<Void, Void, HttpBundle> { |
607 |
|
608 |
private CloudServersException exception;
|
609 |
|
610 |
@Override
|
611 |
//let user know their process has started
|
612 |
protected void onPreExecute(){ |
613 |
showToast("Reboot process has begun");
|
614 |
} |
615 |
|
616 |
@Override
|
617 |
protected HttpBundle doInBackground(Void... arg0) { |
618 |
HttpBundle bundle = null;
|
619 |
try {
|
620 |
bundle = (new ServerManager()).reboot(server, ServerManager.HARD_REBOOT, getContext());
|
621 |
} catch (CloudServersException e) {
|
622 |
exception = e; |
623 |
} |
624 |
return bundle;
|
625 |
} |
626 |
|
627 |
@Override
|
628 |
protected void onPostExecute(HttpBundle bundle) { |
629 |
HttpResponse response = bundle.getResponse(); |
630 |
if (response != null) { |
631 |
int statusCode = response.getStatusLine().getStatusCode();
|
632 |
if(statusCode == 202){ showToast("Reboot successful"); } |
633 |
if (statusCode != 202) { |
634 |
CloudServersException cse = parseCloudServersException(response); |
635 |
if ("".equals(cse.getMessage())) { |
636 |
showError("There was a problem rebooting your server.", bundle);
|
637 |
} else {
|
638 |
showError("There was a problem rebooting your server: " + cse.getMessage(), bundle);
|
639 |
} |
640 |
} |
641 |
} else if (exception != null) { |
642 |
showError("There was a problem rebooting your server: " + exception.getMessage(), bundle);
|
643 |
|
644 |
} |
645 |
} |
646 |
} |
647 |
|
648 |
private class ResizeServerTask extends AsyncTask<Void, Void, HttpBundle> { |
649 |
|
650 |
private CloudServersException exception;
|
651 |
|
652 |
@Override
|
653 |
protected void onPreExecute(){ |
654 |
showToast("Resize process has begun, please confirm your resize after process finishes.");
|
655 |
} |
656 |
|
657 |
@Override
|
658 |
protected HttpBundle doInBackground(Void... arg0) { |
659 |
HttpBundle bundle = null;
|
660 |
try {
|
661 |
bundle = (new ServerManager()).resize(server, Integer.parseInt(selectedFlavorId), getContext()); |
662 |
} catch (CloudServersException e) {
|
663 |
exception = e; |
664 |
} |
665 |
return bundle;
|
666 |
} |
667 |
|
668 |
@Override
|
669 |
protected void onPostExecute(HttpBundle bundle) { |
670 |
HttpResponse response = bundle.getResponse(); |
671 |
if (response != null) { |
672 |
int statusCode = response.getStatusLine().getStatusCode();
|
673 |
if (statusCode == 202) { |
674 |
pollServerTask = new PollServerTask();
|
675 |
pollServerTask.execute((Void[]) null); |
676 |
} else {
|
677 |
CloudServersException cse = parseCloudServersException(response); |
678 |
if ("".equals(cse.getMessage())) { |
679 |
showError("There was a problem resizing your server.", bundle);
|
680 |
} else {
|
681 |
showError("There was a problem resizing your server: " + cse.getMessage(), bundle);
|
682 |
} |
683 |
} |
684 |
} else if (exception != null) { |
685 |
showError("There was a problem resizing your server: " + exception.getMessage(), bundle);
|
686 |
|
687 |
} |
688 |
|
689 |
} |
690 |
} |
691 |
|
692 |
|
693 |
public class DeleteServerTask extends AsyncTask<Void, Void, HttpBundle> { |
694 |
|
695 |
private CloudServersException exception;
|
696 |
|
697 |
@Override
|
698 |
//let user know their process has started
|
699 |
protected void onPreExecute(){ |
700 |
showToast("Delete process has begun");
|
701 |
} |
702 |
@Override
|
703 |
protected HttpBundle doInBackground(Void... arg0) { |
704 |
HttpBundle bundle = null;
|
705 |
try {
|
706 |
bundle = (new ServerManager()).delete(server, getContext());
|
707 |
} catch (CloudServersException e) {
|
708 |
exception = e; |
709 |
} |
710 |
return bundle;
|
711 |
} |
712 |
|
713 |
@Override
|
714 |
protected void onPostExecute(HttpBundle bundle) { |
715 |
HttpResponse response = bundle.getResponse(); |
716 |
if (response != null) { |
717 |
int statusCode = response.getStatusLine().getStatusCode();
|
718 |
if (statusCode == 202) { |
719 |
showToast("Delete successful");
|
720 |
setResult(Activity.RESULT_OK); |
721 |
finish(); |
722 |
} else {
|
723 |
CloudServersException cse = parseCloudServersException(response); |
724 |
if ("".equals(cse.getMessage())) { |
725 |
showError("There was a problem deleting your server.", bundle);
|
726 |
} else {
|
727 |
showError("There was a problem deleting your server: " + cse.getMessage(), bundle);
|
728 |
} |
729 |
} |
730 |
} else if (exception != null) { |
731 |
showError("There was a problem deleting your server: " + exception.getMessage(), bundle);
|
732 |
} |
733 |
} |
734 |
} |
735 |
|
736 |
private class RenameServerTask extends AsyncTask<Void, Void, HttpBundle> { |
737 |
|
738 |
private CloudServersException exception;
|
739 |
|
740 |
@Override
|
741 |
//let user know their process has started
|
742 |
protected void onPreExecute(){ |
743 |
showToast("Rename process has begun.");
|
744 |
} |
745 |
|
746 |
@Override
|
747 |
protected HttpBundle doInBackground(Void... arg0) { |
748 |
HttpBundle bundle = null;
|
749 |
try {
|
750 |
bundle = (new ServerManager()).rename(server, modifiedServerName, getContext());
|
751 |
} catch (CloudServersException e) {
|
752 |
exception = e; |
753 |
} |
754 |
return bundle;
|
755 |
} |
756 |
|
757 |
@Override
|
758 |
protected void onPostExecute(HttpBundle bundle) { |
759 |
HttpResponse response = bundle.getResponse(); |
760 |
if (response != null) { |
761 |
int statusCode = response.getStatusLine().getStatusCode();
|
762 |
if (statusCode == 204) { |
763 |
showToast("Rename successful");
|
764 |
pollServerTask = new PollServerTask();
|
765 |
pollServerTask.execute((Void[]) null); |
766 |
} else {
|
767 |
CloudServersException cse = parseCloudServersException(response); |
768 |
if ("".equals(cse.getMessage())) { |
769 |
showError("There was a problem renaming your server.", bundle);
|
770 |
} else {
|
771 |
showError("There was a problem renaming your server: " + cse.getMessage(), bundle);
|
772 |
} |
773 |
} |
774 |
} |
775 |
else if (exception != null) { |
776 |
showError("There was a problem renaming your server: " + exception.getMessage(), bundle);
|
777 |
} |
778 |
} |
779 |
|
780 |
} |
781 |
|
782 |
private class RebuildServerTask extends AsyncTask<Void, Void, HttpBundle> { |
783 |
|
784 |
private CloudServersException exception;
|
785 |
|
786 |
@Override
|
787 |
protected void onPreExecute(){ |
788 |
showToast("Rebuild process has begun");
|
789 |
} |
790 |
|
791 |
@Override
|
792 |
protected HttpBundle doInBackground(Void... arg0) { |
793 |
HttpBundle bundle = null;
|
794 |
try {
|
795 |
bundle = (new ServerManager()).rebuild(server, Integer.parseInt(selectedImageId), getContext()); |
796 |
} catch (CloudServersException e) {
|
797 |
exception = e; |
798 |
} |
799 |
return bundle;
|
800 |
} |
801 |
|
802 |
@Override
|
803 |
protected void onPostExecute(HttpBundle bundle) { |
804 |
HttpResponse response = bundle.getResponse(); |
805 |
if (response != null) { |
806 |
int statusCode = response.getStatusLine().getStatusCode();
|
807 |
if (statusCode == 202) { |
808 |
pollServerTask = new PollServerTask();
|
809 |
pollServerTask.execute((Void[]) null); |
810 |
} else {
|
811 |
CloudServersException cse = parseCloudServersException(response); |
812 |
if ("".equals(cse.getMessage())) { |
813 |
showError("There was a problem rebuilding your server.", bundle);
|
814 |
} else {
|
815 |
showError("There was a problem rebuilding your server: " + cse.getMessage(), bundle);
|
816 |
} |
817 |
} |
818 |
} else if (exception != null) { |
819 |
showError("There was a problem rebuilding your server: " + exception.getMessage(), bundle);
|
820 |
} |
821 |
|
822 |
} |
823 |
} |
824 |
|
825 |
|
826 |
} |