|
|
@@ -1,6 +1,7 @@
|
|
|
package cn.reghao.autodop.dmaster.utils.amqp;
|
|
|
|
|
|
import cn.reghao.autodop.common.dagent.machine.api.MachineOps;
|
|
|
+import cn.reghao.autodop.common.utils.DatetimeConverter;
|
|
|
import cn.reghao.autodop.common.utils.serializer.JsonConverter;
|
|
|
import cn.reghao.autodop.dmaster.cluster.entity.MachineHeartbeat;
|
|
|
import cn.reghao.autodop.dmaster.cluster.entity.MachineLog;
|
|
|
@@ -10,6 +11,9 @@ import cn.reghao.autodop.dmaster.cluster.service.crud.MachineLogCrudService;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
+import java.util.Map;
|
|
|
+import java.util.concurrent.ConcurrentHashMap;
|
|
|
+
|
|
|
/**
|
|
|
* @author reghao
|
|
|
* @date 2020-12-30 10:26:47
|
|
|
@@ -19,11 +23,12 @@ import org.springframework.stereotype.Component;
|
|
|
public class MachineDispatcher {
|
|
|
private MachineCrudService machineCrudService;
|
|
|
private MachineLogCrudService machineLogCrudService;
|
|
|
+ private Map<String, String> machineStatus;
|
|
|
|
|
|
- public MachineDispatcher(MachineCrudService machineCrudService,
|
|
|
- MachineLogCrudService machineLogCrudService) {
|
|
|
+ public MachineDispatcher(MachineCrudService machineCrudService, MachineLogCrudService machineLogCrudService) {
|
|
|
this.machineCrudService = machineCrudService;
|
|
|
this.machineLogCrudService = machineLogCrudService;
|
|
|
+ this.machineStatus = new ConcurrentHashMap<>();
|
|
|
}
|
|
|
|
|
|
public void dispatch(String ops, String payload) {
|
|
|
@@ -38,6 +43,7 @@ public class MachineDispatcher {
|
|
|
// TODO 做一些逻辑处理,判断内存和磁盘的使用量,然后存入数据库,更新数据
|
|
|
// TODO 存到 MongoDB
|
|
|
MachineHeartbeat machineHeartbeat = (MachineHeartbeat) JsonConverter.jsonToObject(payload, MachineHeartbeat.class);
|
|
|
+ setMachineStatus(machineHeartbeat);
|
|
|
log.info("来自机器的心跳...");
|
|
|
break;
|
|
|
case machineLogOps:
|
|
|
@@ -51,4 +57,14 @@ public class MachineDispatcher {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ private void setMachineStatus(MachineHeartbeat heartbeat) {
|
|
|
+ String machineId = heartbeat.getMachineId();
|
|
|
+ String heartbeatTime = DatetimeConverter.msTimestampFormat(System.currentTimeMillis());
|
|
|
+ machineStatus.put(machineId, heartbeatTime);
|
|
|
+ }
|
|
|
+
|
|
|
+ public Map<String, String> getMachineStatus() {
|
|
|
+ return this.machineStatus;
|
|
|
+ }
|
|
|
}
|