Revision b722cab3 src/com/rackspace/cloud/loadbalancer/api/client/LoadBalancerManager.java
b/src/com/rackspace/cloud/loadbalancer/api/client/LoadBalancerManager.java | ||
---|---|---|
69 | 69 |
} |
70 | 70 |
|
71 | 71 |
private LoadBalancer getLoadBalancerById(long id, String url) throws LoadBalancersException { |
72 |
//TODO:grab from ord and combine list |
|
73 | 72 |
CustomHttpClient httpclient = new CustomHttpClient(context); |
74 |
//TODO: check for uk or us |
|
75 | 73 |
HttpGet get = new HttpGet(url + Account.getAccount().getAccountId() + "/loadbalancers/" + id); |
76 | 74 |
LoadBalancer loadBalancer = new LoadBalancer(); |
77 | 75 |
|
... | ... | |
82 | 80 |
HttpResponse resp = httpclient.execute(get); |
83 | 81 |
BasicResponseHandler responseHandler = new BasicResponseHandler(); |
84 | 82 |
String body = responseHandler.handleResponse(resp); |
85 |
Log.i("LB PARSE", body); |
|
83 |
|
|
84 |
Log.d("info", "the xml body is " + body); |
|
85 |
|
|
86 | 86 |
if (resp.getStatusLine().getStatusCode() == 200 || resp.getStatusLine().getStatusCode() == 202) { |
87 | 87 |
LoadBalancersXmlParser loadBalancersXMLParser = new LoadBalancersXmlParser(); |
88 | 88 |
SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser(); |
... | ... | |
120 | 120 |
cse.setMessage(e.getLocalizedMessage()); |
121 | 121 |
throw cse; |
122 | 122 |
} |
123 |
if(loadBalancer != null){ |
|
124 |
Log.d("info", "the name is " + loadBalancer.getName()); |
|
125 |
} |
|
126 |
else{ |
|
127 |
Log.d("info", "the lb is null"); |
|
128 |
} |
|
129 | 123 |
return loadBalancer; |
130 | 124 |
} |
131 | 125 |
|
... | ... | |
156 | 150 |
HttpResponse resp = httpclient.execute(get); |
157 | 151 |
BasicResponseHandler responseHandler = new BasicResponseHandler(); |
158 | 152 |
String body = responseHandler.handleResponse(resp); |
159 |
Log.i("LB PARSE", body); |
|
160 | 153 |
if (resp.getStatusLine().getStatusCode() == 200 || resp.getStatusLine().getStatusCode() == 202) { |
161 | 154 |
LoadBalancersXmlParser loadBalancersXMLParser = new LoadBalancersXmlParser(); |
162 | 155 |
SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser(); |
... | ... | |
213 | 206 |
throw cse; |
214 | 207 |
} |
215 | 208 |
|
216 |
Log.d("info", entity.toDetailedXML()); |
|
217 |
|
|
218 | 209 |
post.setEntity(tmp); |
219 | 210 |
|
220 | 211 |
post.addHeader("X-Auth-Token", Account.getAccount().getAuthToken()); |
... | ... | |
322 | 313 |
return bundle; |
323 | 314 |
} |
324 | 315 |
|
325 |
public HttpBundle addNodes(LoadBalancer loadBalancer, ArrayList<Node> nodes) throws CloudServersException { |
|
326 |
HttpResponse resp = null; |
|
327 |
CustomHttpClient httpclient = new CustomHttpClient(context); |
|
328 |
|
|
329 |
HttpPost post = new HttpPost(LoadBalancer.getRegionUrl(loadBalancer.getRegion()) + Account.getAccount().getAccountId() + "/loadbalancers/" + loadBalancer.getId() + "/nodes"); |
|
330 |
|
|
331 |
post.addHeader("X-Auth-Token", Account.getAccount().getAuthToken()); |
|
332 |
post.addHeader("Content-Type", "application/xml"); |
|
333 |
|
|
334 |
String xml = "<nodes xmlns=\"http://docs.openstack.org/loadbalancers/api/v1.0\"> "; |
|
335 |
for(int i = 0;i < nodes.size(); i++){ |
|
336 |
Node node = nodes.get(i); |
|
337 |
if(node.getWeight() == null){ |
|
338 |
xml += "<node address=\"" + node.getAddress() + "\" port=\"" + node.getPort() + "\" condition=\"" + node.getCondition() + "\"/>"; |
|
339 |
} |
|
340 |
else{ |
|
341 |
xml += "<node address=\"" + node.getAddress() + "\" port=\"" + node.getPort() + "\" condition=\"" + node.getCondition() + "\" weight=\"" + node.getWeight() + "\"/>"; |
|
342 |
} |
|
343 |
xml += " </nodes>"; |
|
344 |
} |
|
345 |
|
|
346 |
Log.d("info", xml); |
|
347 |
|
|
348 |
StringEntity tmp = null; |
|
349 |
try { |
|
350 |
tmp = new StringEntity(xml); |
|
351 |
} catch (UnsupportedEncodingException e) { |
|
352 |
CloudServersException cse = new CloudServersException(); |
|
353 |
cse.setMessage(e.getLocalizedMessage()); |
|
354 |
throw cse; |
|
355 |
} |
|
356 |
|
|
357 |
post.setEntity(tmp); |
|
358 |
httpclient.removeRequestInterceptorByClass(RequestExpectContinue.class); |
|
359 |
|
|
360 |
HttpBundle bundle = new HttpBundle(); |
|
361 |
bundle.setCurlRequest(post); |
|
362 |
|
|
363 |
try { |
|
364 |
resp = httpclient.execute(post); |
|
365 |
bundle.setHttpResponse(resp); |
|
366 |
} catch (ClientProtocolException e) { |
|
367 |
CloudServersException cse = new CloudServersException(); |
|
368 |
cse.setMessage(e.getLocalizedMessage()); |
|
369 |
throw cse; |
|
370 |
} catch (IOException e) { |
|
371 |
CloudServersException cse = new CloudServersException(); |
|
372 |
cse.setMessage(e.getLocalizedMessage()); |
|
373 |
throw cse; |
|
374 |
} catch (FactoryConfigurationError e) { |
|
375 |
CloudServersException cse = new CloudServersException(); |
|
376 |
cse.setMessage(e.getLocalizedMessage()); |
|
377 |
throw cse; |
|
378 |
} |
|
379 |
return bundle; |
|
380 |
} |
|
381 |
|
|
382 |
public HttpBundle modifyNode(LoadBalancer loadBalancer, Node node, String condition, String weight) throws CloudServersException { |
|
383 |
HttpResponse resp = null; |
|
384 |
CustomHttpClient httpclient = new CustomHttpClient(context); |
|
385 |
|
|
386 |
HttpPut put = new HttpPut(LoadBalancer.getRegionUrl(loadBalancer.getRegion()) + Account.getAccount().getAccountId() + "/loadbalancers/" + loadBalancer.getId() + "/nodes/" + node.getId()); |
|
387 |
|
|
388 |
put.addHeader("X-Auth-Token", Account.getAccount().getAuthToken()); |
|
389 |
put.addHeader("Content-Type", "application/xml"); |
|
390 |
|
|
391 |
String xml; |
|
392 |
//different request body if the nodes have weight |
|
393 |
if(weight != null){ |
|
394 |
xml = "<node xmlns=\"http://docs.openstack.org/loadbalancers/api/v1.0\" condition=\"" + condition.toUpperCase() + "\" weight=\"" + weight + "\"" + "/>"; |
|
395 |
Log.d("info", "went to first"); |
|
396 |
} |
|
397 |
else{ |
|
398 |
xml = "<node xmlns=\"http://docs.openstack.org/loadbalancers/api/v1.0\" condition=\"" + condition.toUpperCase() + "\"/>"; |
|
399 |
Log.d("info", "went to second"); |
|
400 |
} |
|
401 |
|
|
402 |
StringEntity tmp = null; |
|
403 |
try { |
|
404 |
tmp = new StringEntity(xml); |
|
405 |
} catch (UnsupportedEncodingException e) { |
|
406 |
CloudServersException cse = new CloudServersException(); |
|
407 |
cse.setMessage(e.getLocalizedMessage()); |
|
408 |
throw cse; |
|
409 |
} |
|
410 |
|
|
411 |
Log.d("info", xml); |
|
412 |
|
|
413 |
put.setEntity(tmp); |
|
414 |
httpclient.removeRequestInterceptorByClass(RequestExpectContinue.class); |
|
415 |
|
|
416 |
HttpBundle bundle = new HttpBundle(); |
|
417 |
bundle.setCurlRequest(put); |
|
418 |
|
|
419 |
try { |
|
420 |
resp = httpclient.execute(put); |
|
421 |
bundle.setHttpResponse(resp); |
|
422 |
} catch (ClientProtocolException e) { |
|
423 |
CloudServersException cse = new CloudServersException(); |
|
424 |
cse.setMessage(e.getLocalizedMessage()); |
|
425 |
throw cse; |
|
426 |
} catch (IOException e) { |
|
427 |
CloudServersException cse = new CloudServersException(); |
|
428 |
cse.setMessage(e.getLocalizedMessage()); |
|
429 |
throw cse; |
|
430 |
} catch (FactoryConfigurationError e) { |
|
431 |
CloudServersException cse = new CloudServersException(); |
|
432 |
cse.setMessage(e.getLocalizedMessage()); |
|
433 |
throw cse; |
|
434 |
} |
|
435 |
return bundle; |
|
436 |
} |
|
437 |
|
|
438 |
public HttpBundle removeNode(LoadBalancer loadBalancer, Node node) throws CloudServersException { |
|
439 |
HttpResponse resp = null; |
|
440 |
CustomHttpClient httpclient = new CustomHttpClient(context); |
|
441 |
|
|
442 |
HttpDelete delete = new HttpDelete(LoadBalancer.getRegionUrl(loadBalancer.getRegion()) + Account.getAccount().getAccountId() + "/loadbalancers/" + loadBalancer.getId() + "/nodes/" + node.getId()); |
|
443 |
|
|
444 |
delete.addHeader("X-Auth-Token", Account.getAccount().getAuthToken()); |
|
445 |
|
|
446 |
httpclient.removeRequestInterceptorByClass(RequestExpectContinue.class); |
|
447 |
|
|
448 |
HttpBundle bundle = new HttpBundle(); |
|
449 |
bundle.setCurlRequest(delete); |
|
450 |
|
|
451 |
try { |
|
452 |
resp = httpclient.execute(delete); |
|
453 |
bundle.setHttpResponse(resp); |
|
454 |
} catch (ClientProtocolException e) { |
|
455 |
CloudServersException cse = new CloudServersException(); |
|
456 |
cse.setMessage(e.getLocalizedMessage()); |
|
457 |
throw cse; |
|
458 |
} catch (IOException e) { |
|
459 |
CloudServersException cse = new CloudServersException(); |
|
460 |
cse.setMessage(e.getLocalizedMessage()); |
|
461 |
throw cse; |
|
462 |
} catch (FactoryConfigurationError e) { |
|
463 |
CloudServersException cse = new CloudServersException(); |
|
464 |
cse.setMessage(e.getLocalizedMessage()); |
|
465 |
throw cse; |
|
466 |
} |
|
467 |
return bundle; |
|
468 |
} |
|
316 |
|
|
469 | 317 |
} |
Also available in: Unified diff