fixed terremark error handling

This commit is contained in:
Adrian Cole 2010-10-31 14:41:08 -07:00
parent fc596fb5ce
commit 5385374ddb
4 changed files with 36 additions and 74 deletions

View File

@ -513,7 +513,6 @@ public abstract class BaseComputeServiceLiveTest {
} }
} }
@Test(enabled = true, dependsOnMethods = "testGet")
public void testOptionToNotBlock() throws Exception { public void testOptionToNotBlock() throws Exception {
String tag = this.tag + "block"; String tag = this.tag + "block";
try { try {

View File

@ -68,7 +68,7 @@ public abstract class BaseHttpErrorHandlerTest {
HttpCommand command = createMock(HttpCommand.class); HttpCommand command = createMock(HttpCommand.class);
HttpRequest request = new HttpRequest(method, uri); HttpRequest request = new HttpRequest(method, uri);
HttpResponse response = new HttpResponse(statusCode, null, Payloads.newStringPayload(content)); HttpResponse response = new HttpResponse(statusCode, message, Payloads.newStringPayload(content));
expect(command.getRequest()).andReturn(request).atLeastOnce(); expect(command.getRequest()).andReturn(request).atLeastOnce();
command.setException(classEq(expected)); command.setException(classEq(expected));

View File

@ -54,36 +54,35 @@ public class ParseTerremarkVCloudErrorFromHttpResponse implements HttpErrorHandl
try { try {
String content = parseErrorFromContentOrNull(command, response); String content = parseErrorFromContentOrNull(command, response);
switch (response.getStatusCode()) { if (response.getMessage() != null && ((response.getMessage().indexOf("because there is a pending task running") != -1)
case 400: || (response.getMessage().indexOf("because it is already powered off") != -1)
exception = new IllegalArgumentException(response.getMessage(), exception); || (response.getMessage().indexOf("already exists") != -1)
break; || (response.getMessage().indexOf("same name exists") != -1)))
case 401: exception = new IllegalStateException(response.getMessage(), exception);
exception = new AuthorizationException(command.getRequest(), content); else
break; switch (response.getStatusCode()) {
case 403: // TODO temporary as terremark mistakenly uses this for vApp case 400:
// not found. exception = new IllegalArgumentException(response.getMessage(), exception);
case 404: break;
String path = command.getRequest().getEndpoint().getPath(); case 401:
Matcher matcher = RESOURCE_PATTERN.matcher(path); exception = new AuthorizationException(command.getRequest(), content);
String message; break;
if (matcher.find()) { case 403: // TODO temporary as terremark mistakenly uses this for vApp
message = String.format("%s %s not found", matcher.group(1), matcher.group(2)); // not found.
} else { case 404:
message = path; String path = command.getRequest().getEndpoint().getPath();
} Matcher matcher = RESOURCE_PATTERN.matcher(path);
exception = new ResourceNotFoundException(message, exception); String message;
break; if (matcher.find()) {
case 500: message = String.format("%s %s not found", matcher.group(1), matcher.group(2));
if ((response.getMessage().indexOf("because there is a pending task running") != -1) } else {
|| (response.getMessage().indexOf("because it is already powered off") != -1) message = path;
|| (response.getMessage().indexOf("already exists") != -1) }
|| (response.getMessage().indexOf("same name exists") != -1)) exception = new ResourceNotFoundException(message, exception);
exception = new IllegalStateException(response.getMessage(), exception); break;
break; default:
default: exception = new HttpResponseException(command, response, content);
exception = new HttpResponseException(command, response, content); }
}
} finally { } finally {
releasePayload(response); releasePayload(response);
command.setException(exception); command.setException(exception);

View File

@ -71,49 +71,13 @@ public class ParseTerremarkVCloudErrorFromHttpResponseTest extends BaseHttpError
"", "", AuthorizationException.class); "", "", AuthorizationException.class);
} }
// @Test
// @Test public void testbecause_there_is_a_pending_task_runningSetsIllegalStateException() {
// public void testbecause_there_is_a_pending_task_runningSetsIllegalStateException() { assertCodeMakes("GET", URI.create("https://services.vcloudexpress.terremark.com/api/v0.8a-ext1.6/vdc/32"), 500,
// assertCodeMakes("GET", URI "because there is a pending task running", "because there is a pending task running",
// .create("https://services.vcloudexpress.terremark.com/api/v0.8a-ext1.6/vdc/32"), IllegalStateException.class);
// 500, "because there is a pending task running", }
// "because there is a pending task running", IllegalStateException.class);
// }
// case 401:
// exception = new AuthorizationException(command.getRequest(), content);
// break;
// case 403: // TODO temporary as terremark mistakenly uses this for vApp not found.
// case 404:
// if (!command.getRequest().getMethod().equals("DELETE")) {
// String path = command.getRequest().getEndpoint().getPath();
// Matcher matcher = RESOURCE_PATTERN.matcher(path);
// String message;
// if (matcher.find()) {
// message = String.format("%s %s not found", matcher.group(1), matcher.group(2));
// } else {
// message = path;
// }
// exception = new ResourceNotFoundException(message);
// }
// break;
// case 401:
// exception = new AuthorizationException(command.getRequest(), content);
// break;
// case 403: // TODO temporary as terremark mistakenly uses this for vApp not found.
// case 404:
// if (!command.getRequest().getMethod().equals("DELETE")) {
// String path = command.getRequest().getEndpoint().getPath();
// Matcher matcher = RESOURCE_PATTERN.matcher(path);
// String message;
// if (matcher.find()) {
// message = String.format("%s %s not found", matcher.group(1), matcher.group(2));
// } else {
// message = path;
// }
// exception = new ResourceNotFoundException(message);
// }
// break;
@Override @Override
protected Class<? extends HttpErrorHandler> getHandlerClass() { protected Class<? extends HttpErrorHandler> getHandlerClass() {
return ParseTerremarkVCloudErrorFromHttpResponse.class; return ParseTerremarkVCloudErrorFromHttpResponse.class;