Openshift v3 Java客户端抛出null

时间:2017-05-20 04:23:44

标签: java openshift openshift-client-tools

这些是我的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());

此源可以很好地执行,没有例外,但无法回复一些响应。 Belows是我的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" : {}
}

如您所见,Pod主机的响应,Pod状态未从我的OpenShift pod中回复。而且这里没有描述的值也越来越少。我是否错过了OpenShift Java SDK的编码程序?

1 个答案:

答案 0 :(得分:1)

以下代码已成功执行。

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());
        }