JClouds + OpenStack: (NoSuchElementException) key [openstack-neutron] is not in the list of suppliers or apis

I am trying to integrate Apache jClouds into a Java project, so I can access the OpenStack API. The following code failed to execute:

neutronApi = ContextBuilder.newBuilder("openstack-neutron")
                    .credentials(USERNAME, API_KEY)
                    .endpoint(AUTH_URL)
                    .modules(modules)
                    .buildApi(NeutronApi.class);

With the following error message:

Java.util.NoSuchElementException: the key [openstack-neutron] is not in the list of providers or apis: {providers = [ultradns-ws], apis = [swift, swift-keystone]}

This, apparently, is a common problem, however, the proposals proposed in the jclouds solution do not resolve it. There is https://stackoverflow.com/a/166268/2126126 about there, but has no accepted answer.

A few useful points:

!

+1
3

/api id ContextBuilder, java ServiceLoader api. META-INF/services ApiMetadata ProviderMetadata.

, , ServiceLoader ?

ServiceLoader ApiMetadata. - :

NeutronApi neutron = ContextBuilder.newBuilder(new NeutronApiMetadata())
   .credentials(USERNAME, API_KEY)
   .endpoint(AUTH_URL)
   .modules(modules)
   .buildApi(NeutronApi.class);

openstack-neutron , . , , -, ServiceLoader. jclouds, , , .

+2

maven, :

<dependency>
    <groupId>org.apache.jclouds.provider</groupId>
    <artifactId>aws-ec2</artifactId>
    <version>${jclouds.version}</version>
</dependency>

:

mvn clean package

:

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

:

java -cp "target/jar-with-dependencies.jar:lib/*" YourClass
0

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


All Articles