Search code examples
javaopenshiftopenshift-client-tools

Openshift v3 Java client throws null


These is my OpenShift Java client code:

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

This source is executed well with no exceptions, but a few response can not be replied. Belows are the responses from my openshift v3 projects

=======================================================================
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" : {}
}

As you see, the response of Pod host, Pod status are not replied from the my OpenShift pod. And the more values which are not described here also missing. Did I miss the coding procedure of my OpenShift Java SDK?


Solution

  • The following codes are executed successfully.

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