Jclouds with OpenStack => java.util.NoSuchElementException: apiType compute not found in directory []

Java jclouds API cannot connect to OpenStack provider.

An exception is thrown with the following message: java.util.NoSuchElementException: apiType evaluates not found in the [] directory.

Other APIs (python-novaclient, ruby-fog) work very well, so the problem seems to be language specific (API).

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 hint is appreciated.

+1
source share
2 answers

, , , . " : tenantname" " ". " " "tenantname: username", jclouds , .

:

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

:

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

, , ,

+3

. Maven, .

, , - openstack-nova. pom.xml .

<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>

mvn dependency:copy-dependencies "-DoutputDirectory=./lib", , .

lib , java -classpath ".:lib/*" jcloudsOpenStack

pom.xml OpenStack, jclouds.

<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>
0

Source: https://habr.com/ru/post/1536549/


All Articles