mirror of https://github.com/apache/jclouds.git
workaround for error handling on deltacloud
This commit is contained in:
parent
eb4a8393fb
commit
12d927f40d
|
@ -50,10 +50,8 @@
|
||||||
</repositories>
|
</repositories>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<!-- when instances are hung, open a ticket and add here -->
|
|
||||||
<jclouds.compute.blacklist-nodes>trmkrun-ccc,test.trmk-924</jclouds.compute.blacklist-nodes>
|
|
||||||
<test.deltacloud.endpoint>http://localhost:3001/api</test.deltacloud.endpoint>
|
<test.deltacloud.endpoint>http://localhost:3001/api</test.deltacloud.endpoint>
|
||||||
<test.deltacloud.apiversion>0.1.2</test.deltacloud.apiversion>
|
<test.deltacloud.apiversion>0.3.0</test.deltacloud.apiversion>
|
||||||
<test.deltacloud.identity>mockuser</test.deltacloud.identity>
|
<test.deltacloud.identity>mockuser</test.deltacloud.identity>
|
||||||
<test.deltacloud.credential>mockpassword</test.deltacloud.credential>
|
<test.deltacloud.credential>mockpassword</test.deltacloud.credential>
|
||||||
</properties>
|
</properties>
|
||||||
|
@ -127,10 +125,6 @@
|
||||||
<name>test.deltacloud.credential</name>
|
<name>test.deltacloud.credential</name>
|
||||||
<value>${test.deltacloud.credential}</value>
|
<value>${test.deltacloud.credential}</value>
|
||||||
</property>
|
</property>
|
||||||
<property>
|
|
||||||
<name>jclouds.compute.blacklist-nodes</name>
|
|
||||||
<value>${jclouds.compute.blacklist-nodes}</value>
|
|
||||||
</property>
|
|
||||||
</systemProperties>
|
</systemProperties>
|
||||||
</configuration>
|
</configuration>
|
||||||
</execution>
|
</execution>
|
||||||
|
|
|
@ -34,7 +34,7 @@ public class DeltacloudPropertiesBuilder extends PropertiesBuilder {
|
||||||
@Override
|
@Override
|
||||||
protected Properties defaultProperties() {
|
protected Properties defaultProperties() {
|
||||||
Properties properties = super.defaultProperties();
|
Properties properties = super.defaultProperties();
|
||||||
properties.setProperty(PROPERTY_API_VERSION, "0.1.2");
|
properties.setProperty(PROPERTY_API_VERSION, "0.3.0");
|
||||||
return properties;
|
return properties;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -50,28 +50,32 @@ public class DeltacloudErrorHandler implements HttpErrorHandler {
|
||||||
// it is important to always read fully and close streams
|
// it is important to always read fully and close streams
|
||||||
String message = parseMessage(response);
|
String message = parseMessage(response);
|
||||||
Exception exception = message != null ? new HttpResponseException(command, response, message)
|
Exception exception = message != null ? new HttpResponseException(command, response, message)
|
||||||
: new HttpResponseException(command, response);
|
: new HttpResponseException(command, response);
|
||||||
try {
|
try {
|
||||||
message = message != null ? message : String.format("%s -> %s", command.getCurrentRequest().getRequestLine(),
|
message = message != null ? message : String.format("%s -> %s", command.getCurrentRequest().getRequestLine(),
|
||||||
response.getStatusLine());
|
response.getStatusLine());
|
||||||
switch (response.getStatusCode()) {
|
if (message.indexOf("ItemNotFound") != -1) {
|
||||||
case 400:
|
exception = new ResourceNotFoundException(message, exception);
|
||||||
exception = new IllegalArgumentException(message, exception);
|
} else {
|
||||||
break;
|
switch (response.getStatusCode()) {
|
||||||
case 401:
|
case 400:
|
||||||
exception = new AuthorizationException(message, exception);
|
exception = new IllegalArgumentException(message, exception);
|
||||||
break;
|
break;
|
||||||
case 404:
|
case 401:
|
||||||
if (!command.getCurrentRequest().getMethod().equals("DELETE")) {
|
exception = new AuthorizationException(message, exception);
|
||||||
exception = new ResourceNotFoundException(message, exception);
|
break;
|
||||||
|
case 404:
|
||||||
|
if (!command.getCurrentRequest().getMethod().equals("DELETE")) {
|
||||||
|
exception = new ResourceNotFoundException(message, exception);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 405:
|
||||||
|
exception = new IllegalArgumentException(message, exception);
|
||||||
|
break;
|
||||||
|
case 409:
|
||||||
|
exception = new IllegalStateException(message, exception);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
case 405:
|
|
||||||
exception = new IllegalArgumentException(message, exception);
|
|
||||||
break;
|
|
||||||
case 409:
|
|
||||||
exception = new IllegalStateException(message, exception);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
if (response.getPayload() != null)
|
if (response.getPayload() != null)
|
||||||
|
|
|
@ -49,25 +49,31 @@ public class DeltacloudErrorHandlerTest {
|
||||||
@Test
|
@Test
|
||||||
public void test400MakesIllegalArgumentException() {
|
public void test400MakesIllegalArgumentException() {
|
||||||
assertCodeMakes("GET", URI.create("https://deltacloud.com/foo"), 400, "", "Bad Request",
|
assertCodeMakes("GET", URI.create("https://deltacloud.com/foo"), 400, "", "Bad Request",
|
||||||
IllegalArgumentException.class);
|
IllegalArgumentException.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test401MakesAuthorizationException() {
|
public void test401MakesAuthorizationException() {
|
||||||
assertCodeMakes("GET", URI.create("https://deltacloud.com/foo"), 401, "", "Unauthorized",
|
assertCodeMakes("GET", URI.create("https://deltacloud.com/foo"), 401, "", "Unauthorized",
|
||||||
AuthorizationException.class);
|
AuthorizationException.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test404MakesResourceNotFoundException() {
|
public void test404MakesResourceNotFoundException() {
|
||||||
assertCodeMakes("GET", URI.create("https://deltacloud.com/foo"), 404, "", "Not Found",
|
assertCodeMakes("GET", URI.create("https://deltacloud.com/foo"), 404, "", "Not Found",
|
||||||
ResourceNotFoundException.class);
|
ResourceNotFoundException.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testItemNotFoundMakesResourceNotFoundException() {
|
||||||
|
assertCodeMakes("GET", URI.create("https://deltacloud.com/foo"), 500, "", "ItemNotFound",
|
||||||
|
ResourceNotFoundException.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test405MakesIllegalArgumentException() {
|
public void test405MakesIllegalArgumentException() {
|
||||||
assertCodeMakes("GET", URI.create("https://deltacloud.com/foo"), 405, "", "Method Not Allowed",
|
assertCodeMakes("GET", URI.create("https://deltacloud.com/foo"), 405, "", "Method Not Allowed",
|
||||||
IllegalArgumentException.class);
|
IllegalArgumentException.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -76,19 +82,19 @@ public class DeltacloudErrorHandlerTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void assertCodeMakes(String method, URI uri, int statusCode, String message, String content,
|
private void assertCodeMakes(String method, URI uri, int statusCode, String message, String content,
|
||||||
Class<? extends Exception> expected) {
|
Class<? extends Exception> expected) {
|
||||||
assertCodeMakes(method, uri, statusCode, message, "text/xml", content, expected);
|
assertCodeMakes(method, uri, statusCode, message, "text/xml", content, expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void assertCodeMakes(String method, URI uri, int statusCode, String message, String contentType,
|
private void assertCodeMakes(String method, URI uri, int statusCode, String message, String contentType,
|
||||||
String content, Class<? extends Exception> expected) {
|
String content, Class<? extends Exception> expected) {
|
||||||
|
|
||||||
DeltacloudErrorHandler function = Guice.createInjector().getInstance(DeltacloudErrorHandler.class);
|
DeltacloudErrorHandler function = Guice.createInjector().getInstance(DeltacloudErrorHandler.class);
|
||||||
|
|
||||||
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, message, Payloads.newInputStreamPayload(Strings2
|
HttpResponse response = new HttpResponse(statusCode, message, Payloads.newInputStreamPayload(Strings2
|
||||||
.toInputStream(content)));
|
.toInputStream(content)));
|
||||||
response.getPayload().getContentMetadata().setContentType(contentType);
|
response.getPayload().getContentMetadata().setContentType(contentType);
|
||||||
|
|
||||||
expect(command.getCurrentRequest()).andReturn(request).atLeastOnce();
|
expect(command.getCurrentRequest()).andReturn(request).atLeastOnce();
|
||||||
|
|
Loading…
Reference in New Issue