2

Java jclouds API fails to connect to an OpenStack provider.

Exception is thrown with the following message: java.util.NoSuchElementException: apiType compute not found in catalog [].

Other APIs (python-novaclient, ruby-fog) work just fine, so the problem looks language (API)-specific.

import static com.google.common.io.Closeables.closeQuietly;

import java.io.Closeable;
import java.util.Set;

import org.jclouds.ContextBuilder;
import org.jclouds.compute.ComputeService;
import org.jclouds.compute.ComputeServiceContext;
import org.jclouds.compute.domain.ComputeMetadata;
import org.jclouds.logging.slf4j.config.SLF4JLoggingModule;
import org.jclouds.openstack.nova.v2_0.NovaApi;
import org.jclouds.openstack.nova.v2_0.NovaAsyncApi;
import org.jclouds.openstack.nova.v2_0.domain.Server;
import org.jclouds.openstack.nova.v2_0.features.ServerApi;
import org.jclouds.rest.RestContext;

import com.google.common.collect.ImmutableSet;
import com.google.inject.Module;

public class jcloudsOpenStack implements Closeable {
   private ComputeService compute;
   private RestContext nova;

   public static void main(String[] args) {
      jcloudsOpenStack jcloudOpenStack = new jcloudsOpenStack();

      try {
         jcloudOpenStack.init();
         jcloudOpenStack.listServers();
         jcloudOpenStack.close();
      }
      catch (Exception e) {
         e.printStackTrace();
      }
      finally {
         jcloudOpenStack.close();
      }
   }

   private void init() {
      Iterable modules = ImmutableSet. of(new SLF4JLoggingModule());

      String provider = "openstack-nova";
      String identity = "...";   // login name
      String password = "...";   // password

      ComputeServiceContext context = ContextBuilder.newBuilder(provider)
            .endpoint("https://UltiCloud.com:5000/v2.0/")
            .credentials(identity, password)
            .modules(modules)
            .buildView(ComputeServiceContext.class);
      compute = context.getComputeService();
      nova = context.unwrap();
   }

   private void listServers() {
      Set<? extends ComputeMetadata> nodes = compute.listNodes();
      System.out.println(nodes.size());
   }

   public void close() {
      closeQuietly(compute.getContext());
   }
}

Any help or a hint is greatly appreciated

2 Answers2

3

I got the same problem in last few days, and finally i got this resolved. you should use"username:tenantname" for parameters 'identity' of 'credentials' function. if you use "username" instead of "tenantname:username", jclouds would query tokens only instead of querying endpoint-list after token-querying, and the exception been thrown.

looks like this:

  ComputeServiceContext context = ContextBuilder.newBuilder(provider)
        .endpoint("https://UltiCloud.com:5000/v2.0/")
        .credentials("admin:admin", "123456")
        .modules(modules)
        .buildView(ComputeServiceContext.class);

not like this:

  ComputeServiceContext context = ContextBuilder.newBuilder(provider)
        .endpoint("https://UltiCloud.com:5000/v2.0/")
        .credentials("admin", "123456")
        .modules(modules)
        .buildView(ComputeServiceContext.class);

Hope this could help you guys

0

You're missing the proper dependencies to run this. It's easiest to use Maven to get them.

The bare minimum you need for the example above is the openstack-nova dependency. To get it make a file called pom.xml and copy in this code.

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <properties>
    <jclouds.version>1.7.0</jclouds.version>
  </properties>
  <groupId>org.apache.jclouds.examples</groupId>
  <artifactId>openstack-examples</artifactId>
  <version>1.0</version>
  <dependencies>
    <dependency>
      <groupId>org.apache.jclouds.api</groupId>
      <artifactId>openstack-nova</artifactId>
      <version>${jclouds.version}</version>
    </dependency>
  </dependencies>
</project>

Then run mvn dependency:copy-dependencies "-DoutputDirectory=./lib" that will download all of the dependencies you need to run your example.

Don't forget to include the lib dir in your path when you compile or run it like java -classpath ".:lib/*" jcloudsOpenStack

A more complete pom.xml file for working with all of the OpenStack services supported in jclouds follows.

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven 4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <properties>
    <jclouds.version>1.7.0</jclouds.version>
  </properties>
  <groupId>org.apache.jclouds.examples</groupId>
  <artifactId>openstack-examples</artifactId>
  <version>1.0</version>
  <dependencies>
    <!-- jclouds dependencies -->
    <dependency>
      <groupId>org.apache.jclouds.driver</groupId>
      <artifactId>jclouds-slf4j</artifactId>
      <version>${jclouds.version}</version>
    </dependency>
    <dependency>
      <groupId>org.apache.jclouds.driver</groupId>
      <artifactId>jclouds-sshj</artifactId>
      <version>${jclouds.version}</version>
    </dependency>
    <!-- OpenStack dependencies -->
    <dependency>
      <groupId>org.apache.jclouds.api</groupId>
      <artifactId>openstack-keystone</artifactId>
      <version>${jclouds.version}</version>
    </dependency>
    <dependency>
      <groupId>org.apache.jclouds.api</groupId>
      <artifactId>openstack-nova</artifactId>
      <version>${jclouds.version}</version>
    </dependency>
    <dependency>
      <groupId>org.apache.jclouds.api</groupId>
      <artifactId>swift</artifactId>
      <version>${jclouds.version}</version>
    </dependency>
    <dependency>
      <groupId>org.apache.jclouds.api</groupId>
      <artifactId>openstack-cinder</artifactId>
      <version>${jclouds.version}</version>
    </dependency>
    <dependency>
      <groupId>org.apache.jclouds.api</groupId>
      <artifactId>openstack-trove</artifactId>
      <version>${jclouds.version}</version>
    </dependency>
    <dependency>
      <groupId>org.apache.jclouds.labs</groupId>
      <artifactId>openstack-glance</artifactId>
      <version>${jclouds.version}</version>
    </dependency>
    <dependency>
      <groupId>org.apache.jclouds.labs</groupId>
      <artifactId>openstack-marconi</artifactId>
      <version>${jclouds.version}</version>
    </dependency>
    <dependency>
      <groupId>org.apache.jclouds.labs</groupId>
      <artifactId>openstack-neutron</artifactId>
      <version>${jclouds.version}</version>
    </dependency>
    <!-- 3rd party dependencies -->
    <dependency>
      <groupId>ch.qos.logback</groupId>
      <artifactId>logback-classic</artifactId>
      <version>1.0.13</version>
    </dependency>
    <dependency>
      <groupId>mysql</groupId>
      <artifactId>mysql-connector-java</artifactId>
      <version>5.1.25</version>
    </dependency>
  </dependencies>
</project>
Everett Toews
  • 10,337
  • 10
  • 44
  • 45
  • 1
    I have all these. If I had not, I would not have been able to compile the code, which I was able to do. I will check if I have everything you mentioned though, thanks. – Lukas Korous Jan 17 '14 at 09:07
  • I ran your example exactly as is against a DevStack Havana deployment of mine and it worked just fine. Hope it's working for you too. – Everett Toews Jan 17 '14 at 21:14
  • Thanks, so far it does not, but we are working on it. Good to know it works for you. – Lukas Korous Jan 18 '14 at 10:14
  • 2
    @user2436366 did you ever get this resolved? I'm using a rackspace private cloud and running into the same issue – Christopher Dancy May 22 '14 at 19:12
  • 2
    This is a common issue. Have a look at http://jclouds.apache.org/reference/troubleshooting/ to see if that helps. – Everett Toews May 23 '14 at 19:42