mirror of https://github.com/apache/jclouds.git
throw root exception for login failures, not provisioningexception
This commit is contained in:
parent
be59ba5e5e
commit
f4f32e07e0
|
@ -54,6 +54,7 @@ import org.jclouds.http.HttpResponseException;
|
||||||
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
|
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
|
||||||
import org.jclouds.predicates.RetryablePredicate;
|
import org.jclouds.predicates.RetryablePredicate;
|
||||||
import org.jclouds.predicates.SocketOpen;
|
import org.jclouds.predicates.SocketOpen;
|
||||||
|
import org.jclouds.rest.AuthorizationException;
|
||||||
import org.jclouds.ssh.ExecResponse;
|
import org.jclouds.ssh.ExecResponse;
|
||||||
import org.jclouds.ssh.SshClient;
|
import org.jclouds.ssh.SshClient;
|
||||||
import org.jclouds.ssh.SshException;
|
import org.jclouds.ssh.SshException;
|
||||||
|
@ -146,6 +147,12 @@ public abstract class BaseComputeServiceLiveTest {
|
||||||
|
|
||||||
abstract protected Module getSshModule();
|
abstract protected Module getSshModule();
|
||||||
|
|
||||||
|
@Test(enabled = true, expectedExceptions = AuthorizationException.class)
|
||||||
|
public void testCorrectAuthException() throws Exception {
|
||||||
|
new ComputeServiceContextFactory().createContext(service, "MOMMA", "MIA").close();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(enabled = true, dependsOnMethods = "testCorrectAuthException")
|
||||||
public void testImagesCache() throws Exception {
|
public void testImagesCache() throws Exception {
|
||||||
client.getImages();
|
client.getImages();
|
||||||
long time = System.currentTimeMillis();
|
long time = System.currentTimeMillis();
|
||||||
|
|
|
@ -29,11 +29,14 @@ import javax.inject.Inject;
|
||||||
|
|
||||||
import org.jclouds.PropertiesBuilder;
|
import org.jclouds.PropertiesBuilder;
|
||||||
import org.jclouds.domain.Credentials;
|
import org.jclouds.domain.Credentials;
|
||||||
|
import org.jclouds.util.Utils;
|
||||||
|
|
||||||
|
import com.google.common.base.Throwables;
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
import com.google.common.io.Resources;
|
import com.google.common.io.Resources;
|
||||||
import com.google.inject.Module;
|
import com.google.inject.Module;
|
||||||
|
import com.google.inject.ProvisionException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper class to instantiate {@code RestContext} instances. "blobstore.properties"
|
* Helper class to instantiate {@code RestContext} instances. "blobstore.properties"
|
||||||
|
@ -175,8 +178,15 @@ public abstract class RestContextFactory<T, B extends RestContextBuilder<?, ?>>
|
||||||
B contextBuilder = (B) contextBuilderClass.getConstructor(Properties.class).newInstance(
|
B contextBuilder = (B) contextBuilderClass.getConstructor(Properties.class).newInstance(
|
||||||
builder.build()).withModules(Iterables.toArray(modules, Module.class));
|
builder.build()).withModules(Iterables.toArray(modules, Module.class));
|
||||||
return build(contextBuilder);
|
return build(contextBuilder);
|
||||||
|
} catch (ProvisionException e) {
|
||||||
|
Throwable throwable = Utils.firstRootCauseOrOriginalException(e);
|
||||||
|
Throwables.propagate(throwable);
|
||||||
|
assert false : "exception should have propogated " + e;
|
||||||
|
return null;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException("error instantiating " + contextBuilderClassName, e);
|
Throwables.propagate(Throwables.getRootCause(e));
|
||||||
|
assert false : "exception should have propogated " + e;
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -45,6 +45,8 @@ import com.google.common.collect.ImmutableSet;
|
||||||
import com.google.common.io.ByteStreams;
|
import com.google.common.io.ByteStreams;
|
||||||
import com.google.common.io.Closeables;
|
import com.google.common.io.Closeables;
|
||||||
import com.google.common.io.OutputSupplier;
|
import com.google.common.io.OutputSupplier;
|
||||||
|
import com.google.inject.ProvisionException;
|
||||||
|
import com.google.inject.spi.Message;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* General utilities used in jclouds code.
|
* General utilities used in jclouds code.
|
||||||
|
@ -67,6 +69,16 @@ public class Utils {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Throwable firstRootCauseOrOriginalException(ProvisionException e) {
|
||||||
|
for (Message message : e.getErrorMessages()) {
|
||||||
|
Throwable cause = Throwables.getRootCause(message.getCause());
|
||||||
|
if (cause instanceof ProvisionException)
|
||||||
|
return firstRootCauseOrOriginalException(ProvisionException.class.cast(cause));
|
||||||
|
return cause;
|
||||||
|
}
|
||||||
|
return e;
|
||||||
|
}
|
||||||
|
|
||||||
public static String replaceTokens(String value, Collection<Entry<String, String>> tokenValues) {
|
public static String replaceTokens(String value, Collection<Entry<String, String>> tokenValues) {
|
||||||
for (Entry<String, String> tokenValue : tokenValues) {
|
for (Entry<String, String> tokenValue : tokenValues) {
|
||||||
value = replaceAll(value, TOKEN_TO_PATTERN.get(tokenValue.getKey()), tokenValue.getValue());
|
value = replaceAll(value, TOKEN_TO_PATTERN.get(tokenValue.getKey()), tokenValue.getValue());
|
||||||
|
|
|
@ -18,13 +18,19 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.util;
|
package org.jclouds.util;
|
||||||
|
|
||||||
|
import static org.easymock.classextension.EasyMock.createMock;
|
||||||
import static org.testng.Assert.assertEquals;
|
import static org.testng.Assert.assertEquals;
|
||||||
|
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
|
|
||||||
|
import org.jclouds.rest.AuthorizationException;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
import com.google.common.collect.ImmutableSet;
|
||||||
|
import com.google.inject.ProvisionException;
|
||||||
|
import com.google.inject.internal.ImmutableList;
|
||||||
|
import com.google.inject.spi.Message;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
|
@ -32,6 +38,13 @@ import com.google.common.collect.ImmutableMap;
|
||||||
@Test(groups = "unit", testName = "jclouds.UtilsTest")
|
@Test(groups = "unit", testName = "jclouds.UtilsTest")
|
||||||
public class UtilsTest {
|
public class UtilsTest {
|
||||||
|
|
||||||
|
public void testGetCause() {
|
||||||
|
AuthorizationException aex = createMock(AuthorizationException.class);
|
||||||
|
Message message = new Message(ImmutableList.of(), "test", aex);
|
||||||
|
ProvisionException pex = new ProvisionException(ImmutableSet.of(message));
|
||||||
|
assertEquals(Utils.firstRootCauseOrOriginalException(pex), aex);
|
||||||
|
}
|
||||||
|
|
||||||
public void testReplaceTokens() throws UnsupportedEncodingException {
|
public void testReplaceTokens() throws UnsupportedEncodingException {
|
||||||
assertEquals(Utils.replaceTokens("hello {where}", ImmutableMap.of("where", "world")),
|
assertEquals(Utils.replaceTokens("hello {where}", ImmutableMap.of("where", "world")),
|
||||||
"hello world");
|
"hello world");
|
||||||
|
|
Loading…
Reference in New Issue