1 package org.edgegallery.example_app.controller;
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;
23 import java.util.ArrayList;
24 import java.util.List;
28 @RequestMapping("/v1/robo")
30 public class k8sController {
33 EALTEdgePodsPvcs eALTEdgePodsPvcs;
36 pvcService PvcService;
39 podService PodService;
41 private final deleteNamespace DeleteNamespace;
44 public k8sController(deleteNamespace DeleteNamespace) {
45 this.DeleteNamespace = DeleteNamespace;
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)
57 public ResponseEntity<EALTEdgePodsPvcs> getAllPodPvcList() throws ApiException {
59 List<Pod> podlistElement;
60 podlistElement = PodService.getPodsList();
61 if (podlistElement.isEmpty()) {
62 System.out.println("Pod list is null");
65 List<Pvcs> pvcslistElement;
66 pvcslistElement = PvcService.getPvcsList();
67 if (pvcslistElement.isEmpty()) {
68 System.out.println("Pvcs list is null");
71 eALTEdgePodsPvcs.setAppsData(podlistElement);
72 eALTEdgePodsPvcs.setPvcData(pvcslistElement);
74 return new ResponseEntity<EALTEdgePodsPvcs>(eALTEdgePodsPvcs, HttpStatus.OK);
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)
86 public ResponseEntity<String> createDisaster() throws ApiException {
88 DeleteNamespace.deleteNS();
89 System.out.println("k8s 1 api is ok");
91 return ResponseEntity.ok("success");