jClouds + OpenStack:(NoSuchElementException)键[openstack-neutron]不在提供程序或API的列表中 [英] jClouds + OpenStack: (NoSuchElementException) key [openstack-neutron] not in the list of providers or apis

查看:133
本文介绍了jClouds + OpenStack:(NoSuchElementException)键[openstack-neutron]不在提供程序或API的列表中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将Apache jClouds集成到Java项目中,以便可以访问OpenStack API.以下代码失败:

I'm trying to integrate Apache jClouds into a Java project so I can access the OpenStack API. The following code fails:

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

显示以下错误消息:

Java.util.NoSuchElementException:键[openstack-neutron]不在提供程序或API的列表中:{providers = [ultradns-ws],apis = [swift,swift-keystone]}

这显然是一个常见问题,但是 jClouds故障排除中提供的建议不会解决它.关于此问题,有另一个StackOverflow讨论,但没有有一个可以接受的答案.

This is apparently a common problem, however the suggestions offered in jClouds troubleshooting don't resolve it. There's another StackOverflow discussion about this problem but does not have an accepted answer.

一些有用的要点:

  • 我们的Java项目使用Ant,而jClouds基于Maven.《 jClouds安装指南》 https://github.com/jclouds/jclouds 编译) .jar文件放到我的类路径的文件夹中.现在,我可以在代码中访问jClouds对象.
  • 默认的jclouds源不包括OpenStack Neutron对象.我最终在OpenStack Labs源文件中找到了这些文件( https://github.com/jclouds/jclouds- labs-openstack ).从源代码编译,将openstack-neutron-1.9.1.jar文件复制到classpath文件夹中,现在我可以访问Neutron对象了.
  • 所有在线资源都表明这是类路径/依赖关系问题.我已经验证了.classpath和build.xml文件中都提供了openstack-neutron-1.9.1.jar库.没有解决办法.
  • Our Java project uses Ant, whereas jClouds is based on Maven. The jClouds Installation Guide provides directions to install using Ant, but none of them work correctly. Instead, I compiled jClouds from source (https://github.com/jclouds/jclouds) and copied the .jar files into a folder on my classpath. Now I can access the jClouds objects in my code.
  • The default jclouds source does not include OpenStack Neutron objects. I eventually found these in the OpenStack Labs source (https://github.com/jclouds/jclouds-labs-openstack). Compiled from source, copied the openstack-neutron-1.9.1.jar file into classpath folder, now I can access Neutron objects.
  • All online sources suggest this is a classpath/dependency problem. I've verified the openstack-neutron-1.9.1.jar library is available in both my .classpath and build.xml files. No resolution.

我将不胜感激!

推荐答案

当您将提供程序/api id作为字符串传递给ContextBuilder时,java

When you pass a provider/api id as a string to the ContextBuilder, the java ServiceLoader will be used to load the api classes. It will scan the META-INF/services folder in the classpath and look for implementations of ApiMetadata and ProviderMetadata.

您可以验证您的环境中是否存在类加载问题,这些问题可能会阻止ServiceLoader正常运行?

Can you verify that in your environment there are no class loading issues that could prevent the ServiceLoader from operating normally?

作为替代方案,您可以绕过ServiceLoader查找,并直接提供具体的ApiMetadata实现.在您的情况下,它将类似于:

As an alternative, you can bypass the ServiceLoader lookup and provide directly the concrete ApiMetadata implementation. In your case it would be something like:

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

如果您的类路径中有openstack-neutron jar,则此方法应该起作用.如果确实如此,它还表明您的项目中有某些内容阻止了ServiceLoader的正常运行.它不会影响jclouds,因为它仅在创建上下文时使用它,但这是您可能要修复的问题.

If you have the openstack-neutron jar in your classpath this should work. And if it does, it also indicates that there is something in your project that is preventing the ServiceLoader from operating properly. It won't affect jclouds, as it only uses it when creating the context, but it is something you may want to fix.

这篇关于jClouds + OpenStack:(NoSuchElementException)键[openstack-neutron]不在提供程序或API的列表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆