Jelajahi Sumber

添加deployment状态查询接口

raledong 7 tahun lalu
induk
melakukan
11bc564b06

+ 2 - 2
src/main/java/nju/seec/SEECdemo/logic/api/k8s/impl/DeploymentApiImpl.java

@@ -147,8 +147,8 @@ public class DeploymentApiImpl implements DeploymentApi{
                     name,
                     namespace,
                     PRETTY_FORMAT,
-                    true,
-                    true);
+                    false,
+                    false);
             return v1Deployment == null ? null : new Deployment(v1Deployment);
         } catch (ApiException e) {
             if (e.getCode() != K8sApiException.NOT_FOUND) {

+ 12 - 6
src/main/java/nju/seec/SEECdemo/logic/api/k8s/model/DeploymentStatus.java

@@ -10,18 +10,24 @@ import lombok.Data;
 @Data
 public class DeploymentStatus {
 
-    private int availableReplicas;
-
+    /**
+     * 当前为就绪状态的容器
+     */
     private int readyReplicas;
 
+    /**
+     * 当前不可用的容器
+     */
     private int unavailableReplicas;
 
+    /**
+     * 当前为最新版本的容器
+     */
     private int updatedReplicas;
 
     public DeploymentStatus(V1DeploymentStatus deploymentStatus) {
-        this.availableReplicas = deploymentStatus.getAvailableReplicas();
-        this.readyReplicas = deploymentStatus.getReadyReplicas();
-        this.unavailableReplicas = deploymentStatus.getUnavailableReplicas();
-        this.updatedReplicas = deploymentStatus.getUpdatedReplicas();
+        this.readyReplicas = deploymentStatus.getReadyReplicas() == null ? 0 : deploymentStatus.getReadyReplicas();
+        this.unavailableReplicas = deploymentStatus.getUnavailableReplicas() == null ? 0 : deploymentStatus.getUnavailableReplicas();
+        this.updatedReplicas = deploymentStatus.getUpdatedReplicas() == null ? 0 : deploymentStatus.getUpdatedReplicas();
     }
 }

+ 33 - 13
src/test/java/nju/seec/SEECdemo/service/api/DeploymentApiImplTest.java

@@ -93,18 +93,18 @@ public class DeploymentApiImplTest {
 
         deploymentApi.createSync(deployment);
 
-        try {
-            Watch<V1Pod> watch = Watch.createWatch(watchApiClient,
-                    new CoreV1Api(watchApiClient).listNamespacedPodCall("demo2", null, null, null, null, "demo.seec.nju.cn/app=test", null, null, null, true, null, null ),
-                    new TypeToken<Watch.Response<V1Pod>>(){}.getType());
-            watch.forEach(response -> {
-                System.out.printf("%s pod : %s %s%n", response.type, response.object.getMetadata().getName(), response.object.getStatus());
-            });
-        } catch (ApiException e) {
-            System.out.println(e.getResponseBody());
-        } catch (Exception e) {
-            System.out.println(e);
-        }
+//        try {
+//            Watch<V1Pod> watch = Watch.createWatch(watchApiClient,
+//                    new CoreV1Api(watchApiClient).listNamespacedPodCall("demo2", null, null, null, null, "demo.seec.nju.cn/app=test", null, null, null, true, null, null ),
+//                    new TypeToken<Watch.Response<V1Pod>>(){}.getType());
+//            watch.forEach(response -> {
+//                System.out.printf("%s pod : %s %s%n", response.type, response.object.getMetadata().getName(), response.object.getStatus());
+//            });
+//        } catch (ApiException e) {
+//            System.out.println(e.getResponseBody());
+//        } catch (Exception e) {
+//            System.out.println(e);
+//        }
 
 
     }
@@ -126,7 +126,7 @@ public class DeploymentApiImplTest {
 
     @Test
     public void testDelete() {
-        deploymentApi.delete("demo", "test");
+        deploymentApi.delete("demo2", "test");
     }
 
     @Test
@@ -134,4 +134,24 @@ public class DeploymentApiImplTest {
         deploymentApi.deleteIfExist("demo", "test");
     }
 
+    @Test
+    public void testGet(){
+        Deployment deployment = deploymentApi.get("demo2", "test");
+        System.out.println(deployment);
+    }
+
+    @Test
+    public void testGetStatus() {
+        for (int i = 0 ; i<100 ; i++) {
+            DeploymentStatus status = deploymentApi.getStatus("demo2", "test");
+            System.out.println(status);
+            try {
+                Thread.sleep(10000);
+            } catch (InterruptedException e) {
+                e.printStackTrace();
+            }
+
+        }
+    }
+
 }