|
|
@@ -1,21 +1,10 @@
|
|
|
package cn.reghao.autodop.dmaster.app.service;
|
|
|
|
|
|
-import cn.reghao.autodop.common.message.AsyncMsg;
|
|
|
-import cn.reghao.autodop.common.message.MessageType;
|
|
|
-import cn.reghao.autodop.common.message.ops.AppOps;
|
|
|
-import cn.reghao.autodop.common.msg.rpc.dto.app.AppIdParam;
|
|
|
-import cn.reghao.autodop.common.mqtt.DefaultMqttClient;
|
|
|
-import cn.reghao.jdkutil.serializer.JsonConverter;
|
|
|
import cn.reghao.autodop.dmaster.app.model.constant.StatusOps;
|
|
|
-import cn.reghao.autodop.dmaster.app.db.query.config.AppConfigQuery;
|
|
|
import cn.reghao.autodop.dmaster.app.model.po.AppRunning;
|
|
|
import cn.reghao.autodop.dmaster.app.model.po.config.AppConfig;
|
|
|
import cn.reghao.autodop.common.dagent.app.log.LogFile;
|
|
|
-import cn.reghao.autodop.dmaster.app.db.repository.AppRunningRepository;
|
|
|
-import org.eclipse.paho.client.mqttv3.MqttException;
|
|
|
-import org.springframework.stereotype.Service;
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
|
|
|
/**
|
|
|
@@ -24,117 +13,12 @@ import java.util.List;
|
|
|
* @author reghao
|
|
|
* @date 2019-11-27 11:30:28
|
|
|
*/
|
|
|
-@Service
|
|
|
-public class AppStatusService {
|
|
|
- private DefaultMqttClient mqttClient;
|
|
|
- private AppRunningRepository runningRepository;
|
|
|
- private AppConfigQuery appConfigQuery;
|
|
|
-
|
|
|
- public AppStatusService(DefaultMqttClient mqttClient, AppRunningRepository runningRepository, AppConfigQuery appConfigQuery) {
|
|
|
- this.mqttClient = mqttClient;
|
|
|
- this.runningRepository = runningRepository;
|
|
|
- this.appConfigQuery = appConfigQuery;
|
|
|
- }
|
|
|
-
|
|
|
- public void changeStatus(String appId, String machineId, StatusOps statusOps) {
|
|
|
- AppConfig app = appConfigQuery.findByAppId(appId);
|
|
|
- switch (statusOps) {
|
|
|
- case restart:
|
|
|
- setAppStatus(app, machineId, AppOps.appRestart);
|
|
|
- break;
|
|
|
- case stop:
|
|
|
- setAppStatus(app, machineId, AppOps.appStop);
|
|
|
- break;
|
|
|
- case start:
|
|
|
- setAppStatus(app, machineId, AppOps.appStart);
|
|
|
- break;
|
|
|
- default:
|
|
|
- ;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private void setAppStatus(AppConfig app, String machineId, AppOps appOps) {
|
|
|
- AppIdParam appIdParam = new AppIdParam(app.getPackerConfig().getType(), app.getAppId());
|
|
|
- AsyncMsg asyncMsg = new AsyncMsg();
|
|
|
- asyncMsg.setMachineId(machineId);
|
|
|
- asyncMsg.setSendTime(System.currentTimeMillis());
|
|
|
- asyncMsg.setType(MessageType.appType.name());
|
|
|
- asyncMsg.setOps(appOps.name());
|
|
|
- asyncMsg.setPayload(JsonConverter.objectToJson(appIdParam));
|
|
|
-
|
|
|
- String topic = "dagent/" + machineId;
|
|
|
- // TODO 获取应用状态
|
|
|
- /*try {
|
|
|
- mqttClient.pubWithResult(topic, 1, asyncMsg);
|
|
|
- } catch (MqttException e) {
|
|
|
- e.printStackTrace();
|
|
|
- }*/
|
|
|
- }
|
|
|
-
|
|
|
- public void refreshAppStatus() {
|
|
|
- List<AppRunning> appRunnings = runningRepository.findAll();
|
|
|
- appRunnings.forEach(appRunning -> {
|
|
|
- String appId = appRunning.getAppId();
|
|
|
- AppConfig app = appConfigQuery.findByAppId(appId);
|
|
|
- String machineId = appRunning.getMachineId();
|
|
|
- getStatus(app, machineId);
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- public void refreshAppStatus(String appId) {
|
|
|
- List<AppRunning> appRunnings = runningRepository.findByAppId(appId);
|
|
|
- }
|
|
|
-
|
|
|
- public void refreshAppStatus(AppRunning appRunning) {
|
|
|
- String appId = appRunning.getAppId();
|
|
|
- AppConfig app = appConfigQuery.findByAppId(appId);
|
|
|
- String machineId = appRunning.getMachineId();
|
|
|
- getStatus(app, machineId);
|
|
|
- }
|
|
|
-
|
|
|
- public void getStatus(AppConfig app, String machineId) {
|
|
|
- AppIdParam appIdParam = new AppIdParam(app.getPackerConfig().getType(), app.getAppId());
|
|
|
- AsyncMsg asyncMsg = new AsyncMsg();
|
|
|
- asyncMsg.setMachineId(machineId);
|
|
|
- asyncMsg.setSendTime(System.currentTimeMillis());
|
|
|
- asyncMsg.setType(MessageType.appType.name());
|
|
|
- asyncMsg.setOps(AppOps.appStatus.name());
|
|
|
- asyncMsg.setPayload(JsonConverter.objectToJson(appIdParam));
|
|
|
-
|
|
|
- String topic = "dagent/" + machineId;
|
|
|
- // TODO 获取应用状态
|
|
|
- /*try {
|
|
|
- mqttClient.pubWithResult(topic, 1, asyncMsg);
|
|
|
- } catch (MqttException e) {
|
|
|
- e.printStackTrace();
|
|
|
- }*/
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 获取应用日志文件列表
|
|
|
- *
|
|
|
- * @param
|
|
|
- * @return
|
|
|
- * @date 2021-02-26 上午8:23
|
|
|
- */
|
|
|
- public List<LogFile> logFiles(String appId, String machineId) {
|
|
|
- AppConfig app = appConfigQuery.findByAppId(appId);
|
|
|
- return null;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 获取应用日志内容
|
|
|
- *
|
|
|
- * @param
|
|
|
- * @return
|
|
|
- * @date 2021-02-26 上午8:23
|
|
|
- */
|
|
|
- public List<String> logContent(String appId, String logType, String logLevel, String machineId, String logFile) {
|
|
|
- AppConfig app = appConfigQuery.findByAppId(appId);
|
|
|
- return null;
|
|
|
- }
|
|
|
-
|
|
|
- private List<String> getAppLog(String appId, String logType, String logLevel, String machineId, String logFile) {
|
|
|
- return new ArrayList<>();
|
|
|
- }
|
|
|
+public interface AppStatusService {
|
|
|
+ void changeStatus(String appId, String machineId, StatusOps statusOps);
|
|
|
+ void refreshAppStatus();
|
|
|
+ void refreshAppStatus(String appId);
|
|
|
+ void refreshAppStatus(AppRunning appRunning);
|
|
|
+ void getStatus(AppConfig app, String machineId);
|
|
|
+ List<LogFile> logFiles(String appId, String machineId);
|
|
|
+ List<String> logContent(String appId, String logType, String logLevel, String machineId, String logFile);
|
|
|
}
|