Issue 456: add new InsufficientResourcesException

This commit is contained in:
Adrian Cole 2011-01-29 16:15:51 -08:00
parent 4eefd0dfa1
commit 99bbdfce8a
3 changed files with 56 additions and 8 deletions

View File

@ -0,0 +1,43 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* 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);
}
}

View File

@ -28,13 +28,13 @@ import java.util.NoSuchElementException;
import org.jclouds.http.HttpResponseException; import org.jclouds.http.HttpResponseException;
import org.jclouds.rest.AuthorizationException; import org.jclouds.rest.AuthorizationException;
import org.jclouds.rest.InsufficientResourcesException;
import org.jclouds.rest.ResourceNotFoundException; import org.jclouds.rest.ResourceNotFoundException;
import com.google.common.base.Throwables; import com.google.common.base.Throwables;
import com.google.inject.ProvisionException; import com.google.inject.ProvisionException;
import com.google.inject.spi.Message; import com.google.inject.spi.Message;
/** /**
* General utilities used in jclouds code. * General utilities used in jclouds code.
* *
@ -72,7 +72,7 @@ public class Throwables2 {
} }
// Note this needs to be kept up-to-date with all top-level exceptions jclouds works against // 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, public static Exception returnFirstExceptionIfInListOrThrowStandardExceptionOrCause(Class[] exceptionTypes,
Exception exception) throws Exception { Exception exception) throws Exception {
for (Class type : exceptionTypes) { for (Class type : exceptionTypes) {
@ -83,7 +83,7 @@ public class Throwables2 {
} }
for (Class<Exception> propagatableExceptionType : new Class[] { IllegalStateException.class, for (Class<Exception> propagatableExceptionType : new Class[] { IllegalStateException.class,
UnsupportedOperationException.class, IllegalArgumentException.class, AuthorizationException.class, UnsupportedOperationException.class, IllegalArgumentException.class, AuthorizationException.class,
ResourceNotFoundException.class, HttpResponseException.class }) { ResourceNotFoundException.class, InsufficientResourcesException.class, HttpResponseException.class }) {
Throwable throwable = getFirstThrowableOfType(exception, propagatableExceptionType); Throwable throwable = getFirstThrowableOfType(exception, propagatableExceptionType);
if (throwable != null) { if (throwable != null) {
throw (Exception) throwable; throw (Exception) throwable;
@ -102,6 +102,4 @@ public class Throwables2 {
return null; return null;
} }
} }

View File

@ -30,6 +30,7 @@ import java.util.concurrent.TimeoutException;
import org.jclouds.http.HttpCommand; import org.jclouds.http.HttpCommand;
import org.jclouds.http.HttpResponseException; import org.jclouds.http.HttpResponseException;
import org.jclouds.rest.AuthorizationException; import org.jclouds.rest.AuthorizationException;
import org.jclouds.rest.InsufficientResourcesException;
import org.jclouds.rest.ResourceNotFoundException; import org.jclouds.rest.ResourceNotFoundException;
import org.testng.annotations.Test; import org.testng.annotations.Test;
@ -116,6 +117,12 @@ public class Throwables2Test {
returnFirstExceptionIfInListOrThrowStandardExceptionOrCause(new Class[] {}, new RuntimeException(e)); 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) @Test(expectedExceptions = ResourceNotFoundException.class)
public void testPropagateStandardExceptionResourceNotFoundException() throws Exception { public void testPropagateStandardExceptionResourceNotFoundException() throws Exception {
Exception e = new ResourceNotFoundException(); Exception e = new ResourceNotFoundException();