-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAgentApiController.java
60 lines (51 loc) · 1.96 KB
/
AgentApiController.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package org.benchmarker.bmagent.controller;
import java.util.Map;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.benchmarker.bmagent.schedule.SchedulerStatus;
import org.benchmarker.bmagent.service.IScheduledTaskService;
import org.benchmarker.bmagent.service.ISseManageService;
import org.benchmarker.bmcommon.dto.TemplateInfo;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
@RestController
@RequiredArgsConstructor
@RequestMapping("/api")
@Slf4j
public class AgentApiController {
private final ISseManageService sseManageService;
private final IScheduledTaskService scheduledTaskService;
/**
* support sse for the given id
*
* @param templateId Long
* @param action String
* @return SseEmitter
*/
@PostMapping("/templates/{template_id}")
public SseEmitter startSSE(@PathVariable("template_id") Long templateId,
@RequestParam("action") String action, @RequestBody TemplateInfo templateInfo) {
if (action.equals("start")) {
return sseManageService.start(templateId, templateInfo);
} else {
sseManageService.stop(templateId);
return null;
}
}
/**
* Get the status of all schedulers
*
* @return Map of scheduler id, status
*/
@GetMapping("/status")
public ResponseEntity<Map<Long, SchedulerStatus>> getSchedulersStatus() {
return ResponseEntity.ok(scheduledTaskService.getStatus());
}
}