use of com.usthe.common.entity.job.Configmap in project hertzbeat by dromara.
the class MonitorServiceImpl method enableManageMonitors.
@Override
public void enableManageMonitors(HashSet<Long> ids) {
// Update monitoring status Add corresponding monitoring periodic task
// 更新监控状态 新增对应的监控周期性任务
List<Monitor> unManagedMonitors = monitorDao.findMonitorsByIdIn(ids).stream().filter(monitor -> monitor.getStatus() == CommonConstants.UN_MANAGE_CODE && monitor.getJobId() != null).peek(monitor -> monitor.setStatus(CommonConstants.AVAILABLE_CODE)).collect(Collectors.toList());
if (!unManagedMonitors.isEmpty()) {
monitorDao.saveAll(unManagedMonitors);
for (Monitor monitor : unManagedMonitors) {
// Construct the collection task Job entity
// 构造采集任务Job实体
Job appDefine = appService.getAppDefine(monitor.getApp());
appDefine.setMonitorId(monitor.getId());
appDefine.setInterval(monitor.getIntervals());
appDefine.setCyclic(true);
appDefine.setTimestamp(System.currentTimeMillis());
List<Param> params = paramDao.findParamsByMonitorId(monitor.getId());
List<Configmap> configmaps = params.stream().map(param -> new Configmap(param.getField(), param.getValue(), param.getType())).collect(Collectors.toList());
appDefine.setConfigmap(configmaps);
// Issue collection tasks 下发采集任务
collectJobService.addAsyncCollectJob(appDefine);
}
}
}
use of com.usthe.common.entity.job.Configmap in project hertzbeat by dromara.
the class JobSchedulerInit method run.
@Override
public void run(String... args) throws Exception {
// 读取数据库已经添加应用 构造采集任务
List<Monitor> monitors = monitorDao.findMonitorsByStatusNotInAndAndJobIdNotNull(Arrays.asList((byte) 0, (byte) 4));
for (Monitor monitor : monitors) {
try {
// 构造采集任务Job实体
Job appDefine = appService.getAppDefine(monitor.getApp());
// todo 这里暂时是深拷贝处理
appDefine = GsonUtil.fromJson(GsonUtil.toJson(appDefine), Job.class);
appDefine.setId(monitor.getJobId());
appDefine.setMonitorId(monitor.getId());
appDefine.setInterval(monitor.getIntervals());
appDefine.setCyclic(true);
appDefine.setTimestamp(System.currentTimeMillis());
List<Param> params = paramDao.findParamsByMonitorId(monitor.getId());
List<Configmap> configmaps = params.stream().map(param -> new Configmap(param.getField(), param.getValue(), param.getType())).collect(Collectors.toList());
appDefine.setConfigmap(configmaps);
// 下发采集任务
collectJobService.addAsyncCollectJob(appDefine);
} catch (Exception e) {
log.error("init monitor job: {} error,continue next monitor", monitor, e);
}
}
}
Aggregations