0a05a7906593383e2d9a777250663e7d73c5ba05
[ealt-edge.git] / example-apps / ROBO / backup_BE / src / main / java / org / edgegallery / example_app / service / pvcService.java
1 package org.edgegallery.example_app.service;
2
3 import io.kubernetes.client.ApiException;
4 import io.kubernetes.client.apis.CoreV1Api;
5 import io.kubernetes.client.models.V1PersistentVolumeClaim;
6 import io.kubernetes.client.models.V1PersistentVolumeClaimList;
7
8 import java.util.ArrayList;
9 import java.util.List;
10 import org.edgegallery.example_app.model.Pvcs;
11 import org.springframework.stereotype.Service;
12
13 @Service
14 public class pvcService {
15     private Pvcs pvcsDetail;
16
17     public List<Pvcs> getPvcsList() {
18         String namespace = "default";
19         CoreV1Api api = new CoreV1Api();
20         V1PersistentVolumeClaimList list = null;
21         try {
22            /* list = api.listNamespacedPersistentVolumeClaim(namespace, null, null, null,
23                     null, null, null, null, null,
24                     null);*/
25             list = api.listPersistentVolumeClaimForAllNamespaces(null, null, null,
26                     null,null,null,null,null,null);
27         } catch (ApiException apie) {
28             System.err.println("Exception when calling CoreV1Api#listNamespacedPersistentVolumeClaim");
29             apie.printStackTrace();
30             System.exit(1);
31         }
32
33         if (list == null) {
34             System.out.println("Inside- pvcs obj is null");
35         }
36         List<Pvcs> pvcslistElement = new ArrayList<Pvcs>();
37
38         for (V1PersistentVolumeClaim item : list.getItems()) {
39             pvcsDetail = new Pvcs();
40             pvcsDetail.setNamespace(item.getMetadata().getNamespace());
41             pvcsDetail.setName(item.getMetadata().getName());
42             pvcsDetail.setStatus(item.getStatus().getPhase());
43             //pvcsDetail.setIp(item.getStatus().getPodIP());
44             //pvcsDetail.setNode(item.getSpec().getNodeName());
45             pvcsDetail.setReadiness("null");
46             pvcslistElement.add(pvcsDetail);
47         }
48
49         return pvcslistElement;
50     }
51
52 }