[ server ] [ execution ]- optimize some controller - 1
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package io.wdd.rpc.controller;
|
||||
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.wdd.common.beans.response.R;
|
||||
import io.wdd.rpc.execute.result.BuildStreamReader;
|
||||
import io.wdd.rpc.execute.service.CoreExecutionService;
|
||||
@@ -17,7 +19,8 @@ import static io.wdd.rpc.execute.result.RedisStreamReaderConfig.AGENT_STATUS_RED
|
||||
import static io.wdd.rpc.execute.result.RedisStreamReaderConfig.COMMAND_RESULT_REDIS_STREAM_LISTENER_CONTAINER;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("octopus/server/executor")
|
||||
@RequestMapping("/octopus/server/executor")
|
||||
@Api("Agent执行命令的Controller")
|
||||
public class ExecutionController {
|
||||
|
||||
@Resource
|
||||
@@ -37,9 +40,16 @@ public class ExecutionController {
|
||||
String streamKey = "";
|
||||
|
||||
if (StringUtils.isEmpty(type)) {
|
||||
streamKey = coreExecutionService.SendCommandToAgent(topicName, commandList);
|
||||
streamKey = coreExecutionService.SendCommandToAgent(
|
||||
topicName,
|
||||
commandList
|
||||
);
|
||||
} else {
|
||||
streamKey = coreExecutionService.SendCommandToAgent(topicName, type, commandList);
|
||||
streamKey = coreExecutionService.SendCommandToAgent(
|
||||
topicName,
|
||||
type,
|
||||
commandList
|
||||
);
|
||||
}
|
||||
|
||||
return R.ok(streamKey);
|
||||
@@ -50,7 +60,10 @@ public class ExecutionController {
|
||||
@RequestParam(value = "streamKey") String streamKey
|
||||
) {
|
||||
|
||||
buildStreamReader.registerStreamReader(COMMAND_RESULT_REDIS_STREAM_LISTENER_CONTAINER , streamKey);
|
||||
buildStreamReader.registerStreamReader(
|
||||
COMMAND_RESULT_REDIS_STREAM_LISTENER_CONTAINER,
|
||||
streamKey
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -59,18 +72,58 @@ public class ExecutionController {
|
||||
@RequestParam(value = "streamKey") String streamKey
|
||||
) {
|
||||
|
||||
buildStreamReader.registerStreamReader(AGENT_STATUS_REDIS_STREAM_LISTENER_CONTAINER , streamKey);
|
||||
buildStreamReader.registerStreamReader(
|
||||
AGENT_STATUS_REDIS_STREAM_LISTENER_CONTAINER,
|
||||
streamKey
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/agentUpdate")
|
||||
public void AgentUpdate(
|
||||
// auth required
|
||||
@PostMapping("/AgentUpdate")
|
||||
@ApiOperation("控制Agent升级的接口")
|
||||
public R<String> AgentUpdate(
|
||||
@RequestParam(value = "agentTopicName") String agentTopicName
|
||||
) {
|
||||
|
||||
return R.ok(
|
||||
coreExecutionService
|
||||
.SendCommandToAgent(
|
||||
agentTopicName,
|
||||
"AgentUpdate",
|
||||
null
|
||||
));
|
||||
}
|
||||
|
||||
@PostMapping("/AgentReboot")
|
||||
@ApiOperation("控制Agent重启的接口")
|
||||
public R<String> AgentReboot(
|
||||
@RequestParam(value = "agentTopicName") String agentTopicName
|
||||
) {
|
||||
|
||||
return R.ok(
|
||||
coreExecutionService
|
||||
.SendCommandToAgent(
|
||||
agentTopicName,
|
||||
"AgentRestart",
|
||||
null
|
||||
));
|
||||
}
|
||||
|
||||
@PostMapping("/AgentShutdown")
|
||||
@ApiOperation("控制Agent关闭的接口")
|
||||
public R<String> AgentShutdown(
|
||||
@RequestParam(value = "agentTopicName") String agentTopicName
|
||||
) {
|
||||
|
||||
return R.ok(
|
||||
coreExecutionService
|
||||
.SendCommandToAgent(
|
||||
agentTopicName,
|
||||
"AgentShutdown",
|
||||
null
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,75 +0,0 @@
|
||||
package io.wdd.rpc.controller;
|
||||
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import io.swagger.annotations.*;
|
||||
import io.wdd.rpc.scheduler.config.UpdateJobBean;
|
||||
import io.wdd.rpc.scheduler.service.OctopusQuartzService;
|
||||
import org.quartz.JobDataMap;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@Api(value = "quartz增删改查相关API")
|
||||
@RequestMapping(value = "/quartz")
|
||||
public class QuartzCRUDController {
|
||||
|
||||
@Autowired
|
||||
OctopusQuartzService octopusQuartzService;
|
||||
|
||||
// @ApiOperation(value = "使用quartz添加job")
|
||||
// @RequestMapping(value = "/addJob/{jobUUID}", method = RequestMethod.POST)
|
||||
// public void addQuartzJob(@ApiParam(name = "jobUUID") @PathVariable("jobUUID") String jobUUID, @ApiParam(name = "JobXXXBean") @RequestBody JobXXXBean jobXXXBean) {
|
||||
//
|
||||
// if (jobXXXBean.getOpenBean() != null) {
|
||||
// JobDataMap jobDataMap = new JobDataMap();
|
||||
// jobDataMap.put("key01", jobXXXBean.getKey01());
|
||||
// jobDataMap.put("key02", jobXXXBean.getKey02());
|
||||
// jobDataMap.put("key03", jobXXXBean.getKey03());
|
||||
// jobDataMap.put("jobTimeCron", jobXXXBean.getJobTimeCron());
|
||||
// jobDataMap.put("key04", jobXXXBean.getKey04());
|
||||
// octopusQuartzService.addJob(Job1.class, jobUUID, jobUUID, jobXXXBean.getJobTimeCron(), jobDataMap);
|
||||
// } else {
|
||||
// throw new BadRequestException("参数错误");
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
@ApiOperation(value = "使用quartz查询所有job")
|
||||
@RequestMapping(value = "/queryAllJob", method = RequestMethod.GET)
|
||||
public List<Map<String, Object>> queryAllQuartzJob() {
|
||||
|
||||
List<Map<String, Object>> list = octopusQuartzService.queryAllJob();
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
@ApiOperation(value = "使用quartz查询所有运行job")
|
||||
@RequestMapping(value = "/queryRunJob", method = RequestMethod.GET)
|
||||
public List<Map<String, Object>> queryRunQuartzJob() {
|
||||
|
||||
List<Map<String, Object>> list = octopusQuartzService.queryRunJob();
|
||||
return list;
|
||||
}
|
||||
|
||||
@ApiOperation(value = "使用quartz删除job")
|
||||
@RequestMapping(value = "/deleteJob/{jobUUID}", method = RequestMethod.DELETE)
|
||||
public void deleteJob(@ApiParam(name = "jobUUID") @PathVariable("jobUUID") String jobUUID) {
|
||||
|
||||
octopusQuartzService.deleteJob(jobUUID, jobUUID);
|
||||
}
|
||||
|
||||
|
||||
@ApiOperation(value = "使用quartz修改job的cron时间")
|
||||
@RequestMapping(value = "/updateJob/{jobUUID}", method = RequestMethod.PUT)
|
||||
public void deleteJob(@ApiParam(name = "jobUUID") @PathVariable("jobUUID") String jobUUID, @ApiParam(name = "jobCronTime") @RequestBody UpdateJobBean updateJobBean) {
|
||||
|
||||
octopusQuartzService.updateJob(jobUUID, jobUUID, updateJobBean.getJobCronTime());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
package io.wdd.rpc.controller;
|
||||
|
||||
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
import io.wdd.common.beans.response.R;
|
||||
import io.wdd.rpc.scheduler.config.UpdateJobBean;
|
||||
import io.wdd.rpc.scheduler.service.QuartzSchedulerService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@Api(value = "定时任务控制中心的Controller")
|
||||
@RequestMapping(value = "/octopus/server/scheduler")
|
||||
public class SchedulerController {
|
||||
|
||||
@Autowired
|
||||
QuartzSchedulerService octopusQuartzService;
|
||||
|
||||
|
||||
@ApiOperation(value = "查询所有job")
|
||||
@GetMapping(value = "/queryAllJob")
|
||||
public R<List<Map<String, Object>>> queryAllQuartzJob() {
|
||||
|
||||
return R.ok(octopusQuartzService.queryAllJob());
|
||||
}
|
||||
|
||||
|
||||
@ApiOperation(value = "查询所有运行job")
|
||||
@PostMapping(value = "/queryRunJob")
|
||||
public R<List<Map<String, Object>>> queryRunQuartzJob() {
|
||||
|
||||
return R.ok(octopusQuartzService.queryRunJob());
|
||||
}
|
||||
|
||||
@ApiOperation(value = "删除一个job")
|
||||
@PostMapping(value = "/deleteJob/{jobName}")
|
||||
public R<String> deleteJob(
|
||||
@ApiParam(name = "jobName") @RequestParam("jobName") String jobName
|
||||
) {
|
||||
|
||||
boolean deleteJob = octopusQuartzService.deleteJob(
|
||||
jobName,
|
||||
jobName
|
||||
);
|
||||
String result = String.format(
|
||||
"删除任务[ %s ]结果为 [ %s ]",
|
||||
jobName,
|
||||
deleteJob
|
||||
);
|
||||
|
||||
if (deleteJob) {
|
||||
return R.ok(result);
|
||||
} else {
|
||||
return R.failed(result);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ApiOperation(value = "修改job的cron时间")
|
||||
@PostMapping(value = "/updateJob/{jobName}")
|
||||
public void deleteJob(
|
||||
@ApiParam(name = "jobName") @PathVariable("jobName") String jobName, @ApiParam(name = "jobCronTime") @RequestBody UpdateJobBean updateJobBean
|
||||
) {
|
||||
|
||||
octopusQuartzService.updateJob(
|
||||
jobName,
|
||||
jobName,
|
||||
updateJobBean.getJobCronTime()
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
package io.wdd.rpc.controller;
|
||||
|
||||
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.wdd.common.beans.response.R;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import static io.wdd.rpc.status.MonitorAllAgentStatus.ALL_AGENT_HEALTHY_STATUS_MAP;
|
||||
import static io.wdd.rpc.status.MonitorAllAgentStatus.HEALTHY_STATUS_AGENT_LIST_MAP;
|
||||
|
||||
@RestController
|
||||
@Api("Agent运行状态Controller")
|
||||
@RequestMapping("/octopus/server/status")
|
||||
public class StatusController {
|
||||
|
||||
|
||||
@ApiOperation("获取所有Agent的运行状态")
|
||||
@GetMapping("/agentStatus")
|
||||
public R<Map> GetAllAgentHealthyStatus(){
|
||||
|
||||
return R.ok(ALL_AGENT_HEALTHY_STATUS_MAP);
|
||||
}
|
||||
|
||||
@ApiOperation("获取 状态-Agent Map")
|
||||
@GetMapping("/statusAgent")
|
||||
public R<Map> GetHealthyStatusAgentList(){
|
||||
|
||||
return R.ok(HEALTHY_STATUS_AGENT_LIST_MAP);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user