jclouds-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Avanti Ajay <avanti.a...@gmail.com>
Subject Error while running jclouds example code
Date Fri, 28 Feb 2014 07:29:15 GMT
Hi..

I have installed jclouds and devstack 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();
  }
}


But I am getting the following error : Exception:
java.lang.NoSuchMethodError thrown from the UncaughtExceptionHandler in
thread "main"

Please help..

Thank you
Avanti

Mime
View raw message