You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@jclouds.apache.org by Avanti Ajay <av...@gmail.com> on 2014/02/28 06:32:48 UTC
Error in running Jclouds example.
Hi..
I have installed devstack and I also jclouds and I am trying to run the
following code :
import java.util.Set;
import java.lang.Thread.UncaughtExceptionHandler;
import org.jclouds.ContextBuilder;
import org.jclouds.compute.ComputeService;
import org.jclouds.compute.ComputeServiceContext;
import org.jclouds.openstack.nova.v2_0.features.ImageApi;
import org.jclouds.openstack.nova.v2_0.domain.Image;
import org.jclouds.rest.RestContext;
import org.jclouds.openstack.nova.v2_0.NovaApi;
import org.jclouds.openstack.nova.v2_0.NovaAsyncApi;
import org.jclouds.logging.slf4j.config.SLF4JLoggingModule;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.FluentIterable;
import com.google.inject.Module;
public class JCloudsOpenStack {
private ComputeService compute;
private RestContext<NovaApi, NovaAsyncApi> nova;
private Set<String> zones;
public static void main(String[] args) {
JCloudsOpenStack jCloudsOpenStack = new JCloudsOpenStack();
jCloudsOpenStack.init();
jCloudsOpenStack.listImages();
jCloudsOpenStack.close();
}
private void init() {
Thread.setDefaultUncaughtExceptionHandler(new
UncaughtExceptionHandler() {
public void uncaughtException(Thread t, Throwable e) {
if (compute != null) close();
e.printStackTrace();
System.exit(1);
}
});
Iterable<Module> modules = ImmutableSet.<Module> of(
new SLF4JLoggingModule());
String provider = "openstack-nova";
String identity = "admin:admin"; // tenantName:userName
String password = "ashwini";
ComputeServiceContext context = ContextBuilder.newBuilder(provider)
.credentials(identity, password)
.endpoint("http://172.16.32.87:5000/v2.0/")
.modules(modules)
.buildView(ComputeServiceContext.class);
compute = context.getComputeService();
nova = context.unwrap();
zones = nova.getApi().getConfiguredZones();
}
private void listImages() {
for (String zone: zones) {
ImageApi imageApi = nova.getApi().getImageApiForZone(zone);
System.out.println("Calling listImages for " + zone + ":");
FluentIterable<? extends Image> images =
imageApi.listInDetail().concat();
for (Image image: images) {
System.out.println("\t" + image);
}
}
}
private void close() {
compute.getContext().close();
}
}
I am getting the following error : Exception: java.lang.NoSuchMethodError
thrown from the UncaughtExceptionHandler in thread "main"
Please help..
Thank you
Avanti
Re: Error in running Jclouds example.
Posted by Aled Sage <al...@gmail.com>.
Hi Avanti,
I've replied to your similar e-mail on user@jclouds.apache.org (entitled
"Error while running jclouds example code"). Let's discuss there, rather
than on the dev mailing list.
Aled
p.s. if you really need to post to both user@ and dev@ (which is seldom
the case), then can you use send a single e-mail with both in the "to"
list so that it's easier for folk to see what has been answered, and
what has not.
On 28/02/2014 05:32, Avanti Ajay wrote:
> Hi..
>
> I have installed devstack and I also jclouds and I am trying to run the
> following code :
>
> import java.util.Set;
> import java.lang.Thread.UncaughtExceptionHandler;
>
> import org.jclouds.ContextBuilder;
> import org.jclouds.compute.ComputeService;
> import org.jclouds.compute.ComputeServiceContext;
> import org.jclouds.openstack.nova.v2_0.features.ImageApi;
> import org.jclouds.openstack.nova.v2_0.domain.Image;
> import org.jclouds.rest.RestContext;
> import org.jclouds.openstack.nova.v2_0.NovaApi;
> import org.jclouds.openstack.nova.v2_0.NovaAsyncApi;
> import org.jclouds.logging.slf4j.config.SLF4JLoggingModule;
>
> import com.google.common.collect.ImmutableSet;
> import com.google.common.collect.FluentIterable;
> import com.google.inject.Module;
>
> public class JCloudsOpenStack {
> private ComputeService compute;
> private RestContext<NovaApi, NovaAsyncApi> nova;
> private Set<String> zones;
>
> public static void main(String[] args) {
> JCloudsOpenStack jCloudsOpenStack = new JCloudsOpenStack();
> jCloudsOpenStack.init();
> jCloudsOpenStack.listImages();
> jCloudsOpenStack.close();
> }
>
> private void init() {
> Thread.setDefaultUncaughtExceptionHandler(new
> UncaughtExceptionHandler() {
>
>
> public void uncaughtException(Thread t, Throwable e) {
> if (compute != null) close();
> e.printStackTrace();
> System.exit(1);
> }
> });
>
> Iterable<Module> modules = ImmutableSet.<Module> of(
> new SLF4JLoggingModule());
>
> String provider = "openstack-nova";
> String identity = "admin:admin"; // tenantName:userName
> String password = "ashwini";
>
> ComputeServiceContext context = ContextBuilder.newBuilder(provider)
> .credentials(identity, password)
> .endpoint("http://172.16.32.87:5000/v2.0/")
> .modules(modules)
> .buildView(ComputeServiceContext.class);
> compute = context.getComputeService();
> nova = context.unwrap();
> zones = nova.getApi().getConfiguredZones();
> }
>
> private void listImages() {
> for (String zone: zones) {
> ImageApi imageApi = nova.getApi().getImageApiForZone(zone);
>
> System.out.println("Calling listImages for " + zone + ":");
>
> FluentIterable<? extends Image> images =
> imageApi.listInDetail().concat();
>
> for (Image image: images) {
> System.out.println("\t" + image);
> }
> }
> }
> private void close() {
> compute.getContext().close();
> }
> }
>
> I am getting the following error : Exception: java.lang.NoSuchMethodError
> thrown from the UncaughtExceptionHandler in thread "main"
>
> Please help..
>
> Thank you
> Avanti
>