diff --git a/core/src/main/java/org/jclouds/rest/InsufficientResourcesException.java b/core/src/main/java/org/jclouds/rest/InsufficientResourcesException.java new file mode 100644 index 0000000000..32ab424460 --- /dev/null +++ b/core/src/main/java/org/jclouds/rest/InsufficientResourcesException.java @@ -0,0 +1,43 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.rest; + +/** + * Thrown when there is a quota or otherwise limit preventing the operation from occurring. + * + * @author Adrian Cole + */ +public class InsufficientResourcesException extends RuntimeException { + + /** The serialVersionUID */ + private static final long serialVersionUID = -2272965726680821281L; + + public InsufficientResourcesException() { + super(); + } + + public InsufficientResourcesException(String arg0, Throwable arg1) { + super(arg0, arg1); + } + + public InsufficientResourcesException(Throwable arg0) { + super(arg0); + } +} diff --git a/core/src/main/java/org/jclouds/util/Throwables2.java b/core/src/main/java/org/jclouds/util/Throwables2.java index d9cc364bb2..1327234c46 100644 --- a/core/src/main/java/org/jclouds/util/Throwables2.java +++ b/core/src/main/java/org/jclouds/util/Throwables2.java @@ -28,13 +28,13 @@ import java.util.NoSuchElementException; import org.jclouds.http.HttpResponseException; import org.jclouds.rest.AuthorizationException; +import org.jclouds.rest.InsufficientResourcesException; import org.jclouds.rest.ResourceNotFoundException; import com.google.common.base.Throwables; import com.google.inject.ProvisionException; import com.google.inject.spi.Message; - /** * General utilities used in jclouds code. * @@ -72,9 +72,9 @@ public class Throwables2 { } // Note this needs to be kept up-to-date with all top-level exceptions jclouds works against - @SuppressWarnings({ "unchecked", "rawtypes" }) + @SuppressWarnings( { "unchecked", "rawtypes" }) public static Exception returnFirstExceptionIfInListOrThrowStandardExceptionOrCause(Class[] exceptionTypes, - Exception exception) throws Exception { + Exception exception) throws Exception { for (Class type : exceptionTypes) { Throwable throwable = getFirstThrowableOfType(exception, type); if (throwable != null) { @@ -82,8 +82,8 @@ public class Throwables2 { } } for (Class propagatableExceptionType : new Class[] { IllegalStateException.class, - UnsupportedOperationException.class, IllegalArgumentException.class, AuthorizationException.class, - ResourceNotFoundException.class, HttpResponseException.class }) { + UnsupportedOperationException.class, IllegalArgumentException.class, AuthorizationException.class, + ResourceNotFoundException.class, InsufficientResourcesException.class, HttpResponseException.class }) { Throwable throwable = getFirstThrowableOfType(exception, propagatableExceptionType); if (throwable != null) { throw (Exception) throwable; @@ -101,7 +101,5 @@ public class Throwables2 { assert false : "exception should have propogated " + e; return null; } - - } diff --git a/core/src/test/java/org/jclouds/util/Throwables2Test.java b/core/src/test/java/org/jclouds/util/Throwables2Test.java index ab54c99202..8a8e2992ed 100644 --- a/core/src/test/java/org/jclouds/util/Throwables2Test.java +++ b/core/src/test/java/org/jclouds/util/Throwables2Test.java @@ -30,6 +30,7 @@ import java.util.concurrent.TimeoutException; import org.jclouds.http.HttpCommand; import org.jclouds.http.HttpResponseException; import org.jclouds.rest.AuthorizationException; +import org.jclouds.rest.InsufficientResourcesException; import org.jclouds.rest.ResourceNotFoundException; import org.testng.annotations.Test; @@ -115,7 +116,13 @@ public class Throwables2Test { Exception e = new AuthorizationException(); returnFirstExceptionIfInListOrThrowStandardExceptionOrCause(new Class[] {}, new RuntimeException(e)); } - + + @Test(expectedExceptions = InsufficientResourcesException.class) + public void testPropagateStandardExceptionInsufficientResourcesException() throws Exception { + Exception e = new InsufficientResourcesException(); + returnFirstExceptionIfInListOrThrowStandardExceptionOrCause(new Class[] {}, new RuntimeException(e)); + } + @Test(expectedExceptions = ResourceNotFoundException.class) public void testPropagateStandardExceptionResourceNotFoundException() throws Exception { Exception e = new ResourceNotFoundException();