Coerce InsufficientResourcesException for CloudStack

This commit is contained in:
Andrew Bayer 2013-02-21 11:29:20 -08:00 committed by adriancole
parent 7feabaf836
commit 698db63297
2 changed files with 18 additions and 0 deletions

View File

@ -29,6 +29,7 @@ import org.jclouds.http.HttpResponse;
import org.jclouds.http.HttpResponseException;
import org.jclouds.logging.Logger;
import org.jclouds.rest.AuthorizationException;
import org.jclouds.rest.InsufficientResourcesException;
import org.jclouds.rest.ResourceNotFoundException;
import org.jclouds.util.Strings2;
@ -77,6 +78,11 @@ public class CloudStackErrorHandler implements HttpErrorHandler {
exception = new IllegalStateException(message, exception);
}
break;
case 534:
if (message.contains("Maximum number of resources of type")) {
exception = new InsufficientResourcesException(message, exception);
}
break;
case 537:
exception = new IllegalStateException(message, exception);
break;

View File

@ -31,6 +31,7 @@ import org.jclouds.http.HttpCommand;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse;
import org.jclouds.rest.AuthorizationException;
import org.jclouds.rest.InsufficientResourcesException;
import org.jclouds.rest.ResourceNotFoundException;
import org.testng.annotations.Test;
@ -94,6 +95,17 @@ public class CloudStackErrorHandlerTest {
AuthorizationException.class);
}
@Test
void test534WithMaximumResourcesMakesInsufficientResourcesException() {
assertCodeMakes(
"GET",
URI.create("http://10.26.26.155:8080/client/api?response=json&command=deployVirtualMachine&zoneid=7dbc4787-ec2f-498d-95f0-848c8c81e5da&templateid=240937c8-d695-419c-9908-5c7b2a07e6f1&serviceofferingid=c376102e-b683-4d43-b583-4eeab4627e65&displayname=bousa-4&name=bousa-4"),
534,
"",
"{ \"createipforwardingruleresponse\" : {\"errorcode\" : 534, \"errortext\" : \"Maximum number of resources of type 'volume' for account name=jarcec in domain id=1 has been exceeded.\"} }",
InsufficientResourcesException.class);
}
@Test
void test537MakesIllegalStateException() {
assertCodeMakes(