当前位置: 首页 > 工具软件 > OpenStack4j > 使用案例 >

openstack4j开始使用的两个BUG

祁绪
2023-12-01

昨天使用IDEA建立了一个openstack4j的测试工程。第一次用这个框架,出现了三个问题。

问题1 连接器问题

一开始在pom文件中没加连接器,报错如下:

Exception in thread "main" org.openstack4j.api.exceptions.ConnectorNotFoundException: No OpenStack4j connector found in classpath

完善后的 pom.xml

	<properties>
        <log4j.version>1.2.17</log4j.version>
        <slf4j.version>1.7.22</slf4j.version>
        <openstack4j.version>3.3</openstack4j.version>
    </properties>
    <dependencies>
        <!-- Logging -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>jcl-over-slf4j</artifactId>
            <version>${slf4j.version}</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>${slf4j.version}</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>${slf4j.version}</version>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>${log4j.version}</version>
        </dependency>
        <!-- Logging End -->
        <!-- openstack 4j -->
        <dependency>
            <groupId>com.github.openstack4j.core</groupId>
            <artifactId>openstack4j-core</artifactId>
            <version>${openstack4j.version}</version>
        </dependency>
        <!-- 连接器 -->
        <dependency>
            <groupId>com.github.openstack4j.core.connectors</groupId>
            <artifactId>openstack4j-jersey2</artifactId>
<!--        <artifactId>openstack4j-resteasy</artifactId>-->
 <!--        <artifactId>openstack4j-okhttp</artifactId>-->
 <!--        <artifactId>openstack4j-http-connector</artifactId>-->
 <!--        <artifactId>openstack4j-httpclient</artifactId>-->
            <version>3.3</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>compile</scope>
        </dependency>
    </dependencies>

问题2 hosts文件配置问题1

我的hosts文件中controller绑定的是本地虚拟机的IP地址,没绑定远程的。我代码里面的IP是远程的。报错如下:

Exception in thread "main" ConnectionException{message=java.net.ConnectException: Connection timed out: connect, status=0}
	at org.openstack4j.connectors.jersey2.HttpExecutorServiceImpl.invoke(HttpExecutorServiceImpl.java:58)
	at org.openstack4j.connectors.jersey2.HttpExecutorServiceImpl.execute(HttpExecutorServiceImpl.java:33)
	at org.openstack4j.core.transport.internal.HttpExecutor.execute(HttpExecutor.java:51)
	at org.openstack4j.openstack.internal.BaseOpenStackService$Invocation.execute(BaseOpenStackService.java:213)
	at org.openstack4j.openstack.internal.BaseOpenStackService$Invocation.execute(BaseOpenStackService.java:207)
	at org.openstack4j.openstack.identity.v3.internal.UserServiceImpl.list(UserServiceImpl.java:131)
	at com.imut.keystone_demo.Demo_start.main(Demo_start.java:37)

问题3 hosts文件配置问题2

如果不在hosts文件中配置controller,报错如下:

Exception in thread "main" ConnectionException{message=java.net.UnknownHostException: controller, status=0}
	at org.openstack4j.connectors.jersey2.HttpExecutorServiceImpl.invoke(HttpExecutorServiceImpl.java:58)
	at org.openstack4j.connectors.jersey2.HttpExecutorServiceImpl.execute(HttpExecutorServiceImpl.java:33)
	at org.openstack4j.core.transport.internal.HttpExecutor.execute(HttpExecutor.java:51)
	at org.openstack4j.openstack.internal.BaseOpenStackService$Invocation.execute(BaseOpenStackService.java:213)
	at org.openstack4j.openstack.internal.BaseOpenStackService$Invocation.execute(BaseOpenStackService.java:207)
	at org.openstack4j.openstack.identity.v3.internal.UserServiceImpl.list(UserServiceImpl.java:131)
	at com.imut.keystone_demo.Demo_start.main(Demo_start.java:37)

总结

  • 问题1的解决方案是:在pom文件中加上连接器。
  • 问题2与问题3的解决方案一样:在hosts文件中配置正确的conroller。
 类似资料: