mirror of https://github.com/apache/jclouds.git
fixed terremark error handling
This commit is contained in:
parent
fc596fb5ce
commit
5385374ddb
|
@ -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 {
|
||||||
|
|
|
@ -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));
|
||||||
|
|
|
@ -54,6 +54,12 @@ public class ParseTerremarkVCloudErrorFromHttpResponse implements HttpErrorHandl
|
||||||
|
|
||||||
try {
|
try {
|
||||||
String content = parseErrorFromContentOrNull(command, response);
|
String content = parseErrorFromContentOrNull(command, response);
|
||||||
|
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()) {
|
switch (response.getStatusCode()) {
|
||||||
case 400:
|
case 400:
|
||||||
exception = new IllegalArgumentException(response.getMessage(), exception);
|
exception = new IllegalArgumentException(response.getMessage(), exception);
|
||||||
|
@ -74,13 +80,6 @@ public class ParseTerremarkVCloudErrorFromHttpResponse implements HttpErrorHandl
|
||||||
}
|
}
|
||||||
exception = new ResourceNotFoundException(message, exception);
|
exception = new ResourceNotFoundException(message, exception);
|
||||||
break;
|
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:
|
default:
|
||||||
exception = new HttpResponseException(command, response, content);
|
exception = new HttpResponseException(command, response, content);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
|
|
Loading…
Reference in New Issue