2017-05-20 101 views
0

這些是我的OpenShift Java客戶端代碼:Openshift V3 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("[email protected]").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" : {} 
} 

正如你看到的,Pod主機的響應,波德狀態沒有從我的OpenShift莢回答。而這裏沒有描述的更多值也丟失了。我錯過了OpenShift Java SDK的編碼過程嗎?

回答

0

以下代碼已成功執行。

IClient client = new ClientBuilder("https://api.starter-us-east-1.openshift.com") 
       .withUserName("[email protected]") 
       .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()); 
     } 
相關問題