Openshift v3 Java 客户端抛出空值
Openshift v3 Java client throws null
这些是我的 OpenShift Java 客户端代码:
public class JavaClient {
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
IClient client = new ClientBuilder("https://api.starter-xx-xxx-1.openshift.com").withUserName("aaa@bbb.com").withPassword("password").build();
client.getAuthorizationContext().setToken("oqW-8xm8in6QcEaQXt........");
System.out.println("=======================================================================");
System.out.println(client.getOpenShiftAPIVersion() + ", " + client.getServerReadyStatus());
System.out.println("\n========================Openshift Project====================================");
IProject project = (IProject)client.getResourceFactory().stub(ResourceKind.PROJECT, "josephproject-openshift");
System.out.println("Openshift API version : " + project.getApiVersion() +", Project namespace : " + project.getNamespace() + ", Project name : " + project.getName());
System.out.println("\n========================Openshift Pods==============================");
IPod podWildfly = (IPod)client.getResourceFactory().stub(ResourceKind.POD, project.getName(), project.getNamespace());
System.out.println("Pod version : " + podWildfly.getApiVersion() + ",\n Pod Kind : " + podWildfly.getKind() + ",\n Pod Host : " + podWildfly.getHost()+ ", Pod Name \n : " + podWildfly.getName()
+ "\n, Pod state : " + podWildfly.getStatus() + "\n" + podWildfly.toJson());
这个源码执行的很好,没有异常,但是有几个回复无法回复。
以下是我的 openshift v3 项目的回复
=======================================================================
v1, ok
========================Openshift Project====================================
Openshift API version : v1, Project namespace : josephproject-openshift, Project name : josephproject-openshift
========================Openshift Pods==============================
Pod version : v1,
Pod kind : Pod,
Pod Host : ,
Pod Name : josephproject-openshift,
Pod status :
{
"apiVersion" : "v1",
"kind" : "Pod",
"metadata" : {
"name" : "josephproject-openshift",
"namespace" : "josephproject-openshift"
},
"status" : {}
}
如您所见,我的 OpenShift pod 没有回复 Pod 主机的响应、Pod 状态。并且此处未描述的更多值也缺失。我错过了我的 OpenShift Java SDK 的编码过程吗?
以下代码执行成功
IClient client = new ClientBuilder("https://api.starter-us-east-1.openshift.com")
.withUserName("aaa@bbb.com")
.withPassword("password")
.build();
client.getAuthorizationContext().setToken("oqW-8xm8in6QcEaQXtM2ZEQ");
System.out.println("=======================================================================");
System.out.println(client.getOpenShiftAPIVersion() + ", " + client.getServerReadyStatus());
System.out.println("\n========================Openshift Project====================================");
IProject project = (IProject)client.getResourceFactory().stub(ResourceKind.PROJECT, "josephproject-openshift");
System.out.println("Openshift API version : " + project.getApiVersion()
+", Project namespace : " + project.getNamespace() + ", Project name : " + project.getName());
System.out.println("\n========================Openshift Pods==============================");
List<IPod> pods = client.list(ResourceKind.POD, "josephproject-openshift");
//IPod pod = (IPod) pods.stream().filter(p->p.getName().startsWith("docker-registry")).findFirst().orElse(null);
for(IPod pod : pods) {
System.out.println(pod.getName());
System.out.println("Pod Host : " + pod.getHost() + ", Pod Namespace : " + pod.getNamespace()
+ " ,Pod Creation Time :" + pod.getCreationTimeStamp());
System.out.println("Pod Status : " + pod.getStatus() + "\n" + pod.toJson());
}
这些是我的 OpenShift Java 客户端代码:
public class JavaClient {
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
IClient client = new ClientBuilder("https://api.starter-xx-xxx-1.openshift.com").withUserName("aaa@bbb.com").withPassword("password").build();
client.getAuthorizationContext().setToken("oqW-8xm8in6QcEaQXt........");
System.out.println("=======================================================================");
System.out.println(client.getOpenShiftAPIVersion() + ", " + client.getServerReadyStatus());
System.out.println("\n========================Openshift Project====================================");
IProject project = (IProject)client.getResourceFactory().stub(ResourceKind.PROJECT, "josephproject-openshift");
System.out.println("Openshift API version : " + project.getApiVersion() +", Project namespace : " + project.getNamespace() + ", Project name : " + project.getName());
System.out.println("\n========================Openshift Pods==============================");
IPod podWildfly = (IPod)client.getResourceFactory().stub(ResourceKind.POD, project.getName(), project.getNamespace());
System.out.println("Pod version : " + podWildfly.getApiVersion() + ",\n Pod Kind : " + podWildfly.getKind() + ",\n Pod Host : " + podWildfly.getHost()+ ", Pod Name \n : " + podWildfly.getName()
+ "\n, Pod state : " + podWildfly.getStatus() + "\n" + podWildfly.toJson());
这个源码执行的很好,没有异常,但是有几个回复无法回复。 以下是我的 openshift v3 项目的回复
=======================================================================
v1, ok
========================Openshift Project====================================
Openshift API version : v1, Project namespace : josephproject-openshift, Project name : josephproject-openshift
========================Openshift Pods==============================
Pod version : v1,
Pod kind : Pod,
Pod Host : ,
Pod Name : josephproject-openshift,
Pod status :
{
"apiVersion" : "v1",
"kind" : "Pod",
"metadata" : {
"name" : "josephproject-openshift",
"namespace" : "josephproject-openshift"
},
"status" : {}
}
如您所见,我的 OpenShift pod 没有回复 Pod 主机的响应、Pod 状态。并且此处未描述的更多值也缺失。我错过了我的 OpenShift Java SDK 的编码过程吗?
以下代码执行成功
IClient client = new ClientBuilder("https://api.starter-us-east-1.openshift.com")
.withUserName("aaa@bbb.com")
.withPassword("password")
.build();
client.getAuthorizationContext().setToken("oqW-8xm8in6QcEaQXtM2ZEQ");
System.out.println("=======================================================================");
System.out.println(client.getOpenShiftAPIVersion() + ", " + client.getServerReadyStatus());
System.out.println("\n========================Openshift Project====================================");
IProject project = (IProject)client.getResourceFactory().stub(ResourceKind.PROJECT, "josephproject-openshift");
System.out.println("Openshift API version : " + project.getApiVersion()
+", Project namespace : " + project.getNamespace() + ", Project name : " + project.getName());
System.out.println("\n========================Openshift Pods==============================");
List<IPod> pods = client.list(ResourceKind.POD, "josephproject-openshift");
//IPod pod = (IPod) pods.stream().filter(p->p.getName().startsWith("docker-registry")).findFirst().orElse(null);
for(IPod pod : pods) {
System.out.println(pod.getName());
System.out.println("Pod Host : " + pod.getHost() + ", Pod Namespace : " + pod.getNamespace()
+ " ,Pod Creation Time :" + pod.getCreationTimeStamp());
System.out.println("Pod Status : " + pod.getStatus() + "\n" + pod.toJson());
}