EG version upgrade to 1.3
[ealt-edge.git] / example-apps / ROBO / backup_BE / src / main / java / org / edgegallery / example_app / controller / k8sController.java
1 package org.edgegallery.example_app.controller;
2
3 import io.swagger.annotations.ApiOperation;
4 import io.swagger.annotations.ApiResponse;
5 import io.swagger.annotations.ApiResponses;
6 import javax.ws.rs.core.MediaType;
7 import org.edgegallery.example_app.model.*;
8 import io.kubernetes.client.ApiException;
9 import io.kubernetes.client.apis.CoreV1Api;
10 import io.kubernetes.client.models.*;
11 import org.checkerframework.common.reflection.qual.GetMethod;
12 import org.springframework.beans.factory.annotation.Autowired;
13 import org.springframework.http.HttpStatus;
14 import org.springframework.http.ResponseEntity;
15 import org.springframework.stereotype.Controller;
16 import org.springframework.validation.annotation.Validated;
17 import org.springframework.web.bind.annotation.*;
18 import org.edgegallery.example_app.service.podService;
19 import org.edgegallery.example_app.service.pvcService;
20 import org.edgegallery.example_app.service.deleteNamespace;
21
22
23 import java.util.ArrayList;
24 import java.util.List;
25
26 @CrossOrigin
27 @Controller
28 @RequestMapping("/v1/robo")
29 @Validated
30 public class k8sController {
31
32     @Autowired
33     EALTEdgePodsPvcs eALTEdgePodsPvcs;
34
35     @Autowired
36     pvcService PvcService;
37
38     @Autowired
39     podService PodService;
40
41     private final deleteNamespace DeleteNamespace;
42
43     @Autowired
44     public k8sController(deleteNamespace DeleteNamespace) {
45         this.DeleteNamespace = DeleteNamespace;
46     }
47
48     @GetMapping(path = "/apps-pvcs")
49     @ApiOperation(value = "get pod and pvcs tables.", response = EALTEdgePodsPvcs.class,
50             responseContainer = "List")
51     @ApiResponses(value = {
52             @ApiResponse(code = 404, message = "microservice not found", response = String.class),
53             @ApiResponse(code = 415, message = "Unprocessable " + "MicroServiceInfo Entity ",
54                     response = String.class),
55             @ApiResponse(code = 500, message = "resource grant " + "error", response = String.class)
56     })
57     public ResponseEntity<EALTEdgePodsPvcs> getAllPodPvcList() throws ApiException {
58
59         List<Pod> podlistElement;
60         podlistElement = PodService.getPodsList();
61         if (podlistElement.isEmpty()) {
62             System.out.println("Pod list is null");
63         }
64
65         List<Pvcs> pvcslistElement;
66         pvcslistElement = PvcService.getPvcsList();
67         if (pvcslistElement.isEmpty()) {
68             System.out.println("Pvcs list is null");
69         }
70
71         eALTEdgePodsPvcs.setAppsData(podlistElement);
72         eALTEdgePodsPvcs.setPvcData(pvcslistElement);
73
74         return new ResponseEntity<EALTEdgePodsPvcs>(eALTEdgePodsPvcs, HttpStatus.OK);
75     }
76
77     @GetMapping(path = "/disaster")
78     @ApiOperation(value = "delete namespace. in k8s", response = String.class,
79             responseContainer = "List")
80     @ApiResponses(value = {
81             @ApiResponse(code = 404, message = "microservice not found", response = String.class),
82             @ApiResponse(code = 415, message = "Unprocessable " + "MicroServiceInfo Entity ",
83                     response = String.class),
84             @ApiResponse(code = 500, message = "resource grant " + "error", response = String.class)
85     })
86     public ResponseEntity<String> createDisaster() throws ApiException {
87
88         DeleteNamespace.deleteNS();
89         System.out.println("k8s 1 api is ok");
90
91         return ResponseEntity.ok("success");
92     }
93 }