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 {
String tag = this.tag + "block";
try {

View File

@ -68,7 +68,7 @@ public abstract class BaseHttpErrorHandlerTest {
HttpCommand command = createMock(HttpCommand.class);
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();
command.setException(classEq(expected));

View File

@ -54,36 +54,35 @@ public class ParseTerremarkVCloudErrorFromHttpResponse implements HttpErrorHandl
try {
String content = parseErrorFromContentOrNull(command, response);
switch (response.getStatusCode()) {
case 400:
exception = new IllegalArgumentException(response.getMessage(), exception);
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:
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, exception);
break;
case 500:
if ((response.getMessage().indexOf("because there is a pending task running") != -1)
|| (response.getMessage().indexOf("because it is already powered off") != -1)
|| (response.getMessage().indexOf("already exists") != -1)
|| (response.getMessage().indexOf("same name exists") != -1))
exception = new IllegalStateException(response.getMessage(), exception);
break;
default:
exception = new HttpResponseException(command, response, content);
}
if (response.getMessage() != null && ((response.getMessage().indexOf("because there is a pending task running") != -1)
|| (response.getMessage().indexOf("because it is already powered off") != -1)
|| (response.getMessage().indexOf("already exists") != -1)
|| (response.getMessage().indexOf("same name exists") != -1)))
exception = new IllegalStateException(response.getMessage(), exception);
else
switch (response.getStatusCode()) {
case 400:
exception = new IllegalArgumentException(response.getMessage(), exception);
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:
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, exception);
break;
default:
exception = new HttpResponseException(command, response, content);
}
} finally {
releasePayload(response);
command.setException(exception);

View File

@ -71,49 +71,13 @@ public class ParseTerremarkVCloudErrorFromHttpResponseTest extends BaseHttpError
"", "", AuthorizationException.class);
}
//
// @Test
// 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, "because there is a pending task running",
// "because there is a pending task running", IllegalStateException.class);
// }
@Test
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,
"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
protected Class<? extends HttpErrorHandler> getHandlerClass() {
return ParseTerremarkVCloudErrorFromHttpResponse.class;