use of com.vip.saturn.job.console.domain.ServerBriefInfo in project Saturn by vipshop.
the class ExecutorServiceImpl method getServerBriefInfo.
private ServerBriefInfo getServerBriefInfo(String executorName, CuratorFrameworkOp curatorFrameworkOp) {
ServerBriefInfo executorInfo = new ServerBriefInfo(executorName);
String ip = curatorFrameworkOp.getData(ExecutorNodePath.getExecutorIpNodePath(executorName));
executorInfo.setServerIp(ip);
if (StringUtils.isNotBlank(ip)) {
executorInfo.setStatus(ServerStatus.ONLINE);
} else {
executorInfo.setStatus(ServerStatus.OFFLINE);
}
String restartNodePath = ExecutorNodePath.getExecutorRestartNodePath(executorName);
long restartTriggerTime = curatorFrameworkOp.getCtime(restartNodePath);
long now = System.currentTimeMillis();
long maxRestartInv = systemConfigService.getIntegerValue(SystemConfigProperties.MAX_SECONDS_FORCE_KILL_EXECUTOR, DEFAULT_MAX_SECONDS_FORCE_KILL_EXECUTOR) * 1000L;
// 如果restart结点存在,restart结点存在的时间<300s,executor状态列显示RESTARTING;
if (0 != restartTriggerTime && now - restartTriggerTime < maxRestartInv) {
executorInfo.setRestarting(true);
} else {
executorInfo.setRestarting(false);
}
// 是否已被摘流量
executorInfo.setNoTraffic(curatorFrameworkOp.checkExists(ExecutorNodePath.getExecutorNoTrafficNodePath(executorName)));
// lastBeginTime
String lastBeginTime = curatorFrameworkOp.getData(ExecutorNodePath.getExecutorNodePath(executorInfo.getExecutorName(), "lastBeginTime"));
executorInfo.setLastBeginTime(SaturnConsoleUtils.parseMillisecond2DisplayTime(lastBeginTime));
// version
executorInfo.setVersion(curatorFrameworkOp.getData(ExecutorNodePath.getExecutorVersionNodePath(executorName)));
String task = curatorFrameworkOp.getData(ExecutorNodePath.getExecutorTaskNodePath(executorName));
if (StringUtils.isNotBlank(task)) {
// 容器组
executorInfo.setGroupName(task);
// 是否容器
executorInfo.setContainer(true);
}
return executorInfo;
}
use of com.vip.saturn.job.console.domain.ServerBriefInfo in project Saturn by vipshop.
the class ServerDimensionServiceImpl method getAllServersBriefInfo.
@Override
public Map<String, Object> getAllServersBriefInfo() {
CuratorRepository.CuratorFrameworkOp curatorFrameworkOp = curatorRepository.inSessionClient();
HashMap<String, Object> model = new HashMap<String, Object>();
Map<String, ServerBriefInfo> sbfMap = new LinkedHashMap<String, ServerBriefInfo>();
List<String> jobs = new ArrayList<>();
try {
jobs = jobDimensionService.getAllUnSystemJobs(curatorFrameworkOp);
} catch (SaturnJobConsoleException e) {
log.error(e.getMessage(), e);
}
Map<String, Map<String, Integer>> jobNameExecutorNameTotalLevel = new HashMap<>();
String executorNodePath = ExecutorNodePath.getExecutorNodePath();
if (curatorFrameworkOp.checkExists(executorNodePath)) {
List<String> executors = curatorFrameworkOp.getChildren(executorNodePath);
if (!CollectionUtils.isEmpty(executors)) {
for (String executor : executors) {
ServerBriefInfo sbf = new ServerBriefInfo(executor);
String ip = curatorFrameworkOp.getData(ExecutorNodePath.getExecutorNodePath(executor, "ip"));
sbf.setServerIp(ip);
sbf.setNoTraffic(curatorFrameworkOp.checkExists(ExecutorNodePath.getExecutorNodePath(executor, "noTraffic")));
String lastBeginTime = curatorFrameworkOp.getData(ExecutorNodePath.getExecutorNodePath(sbf.getExecutorName(), "lastBeginTime"));
sbf.setLastBeginTime(null == lastBeginTime ? null : dateFormat.format(new Date(Long.parseLong(lastBeginTime))));
if (!Strings.isNullOrEmpty(ip)) {
sbf.setStatus(ServerStatus.ONLINE);
} else {
sbf.setStatus(ServerStatus.OFFLINE);
}
sbf.setVersion(curatorFrameworkOp.getData(ExecutorNodePath.getExecutorNodePath(executor, "version")));
if (!CollectionUtils.isEmpty(jobs)) {
for (String jobName : jobs) {
String serverNodePath = JobNodePath.getServerNodePath(jobName);
if (!curatorFrameworkOp.checkExists(serverNodePath)) {
continue;
}
if (Strings.isNullOrEmpty(sbf.getServerIp())) {
String serverIp = curatorFrameworkOp.getData(JobNodePath.getServerNodePath(jobName, executor, "ip"));
sbf.setServerIp(serverIp);
}
Map<String, Integer> executorNameWithTotalLevel = null;
if (jobNameExecutorNameTotalLevel.containsKey(jobName)) {
executorNameWithTotalLevel = jobNameExecutorNameTotalLevel.get(jobName);
} else {
executorNameWithTotalLevel = new LinkedHashMap<>();
jobNameExecutorNameTotalLevel.put(jobName, executorNameWithTotalLevel);
}
if (ServerStatus.ONLINE.equals(sbf.getStatus())) {
// 负荷分布图只显示online的Executor
executorNameWithTotalLevel.put(executor, 0);
}
String sharding = curatorFrameworkOp.getData(JobNodePath.getServerNodePath(jobName, executor, "sharding"));
if (!Strings.isNullOrEmpty(sharding)) {
// 如果有分片信息则前端需要屏蔽删除按钮
sbf.setHasSharding(true);
if (JobStatus.STOPPED.equals(jobDimensionService.getJobStatus(jobName))) {
// 作业状态为STOPPED的即使有残留分片也不显示该分片
continue;
}
if (ServerStatus.OFFLINE.equals(sbf.getStatus())) {
// offline的executor即使有残留分片也不显示该分片
continue;
}
// concat executorSharding
String executorSharding = jobName + ":" + sharding;
if (Strings.isNullOrEmpty(sbf.getSharding())) {
// 如果有分片信息则前端需要屏蔽删除按钮
sbf.setSharding(executorSharding);
} else {
sbf.setSharding(sbf.getSharding() + "<br/>" + executorSharding);
}
// calculate totalLoadLevel
String loadLevelNode = curatorFrameworkOp.getData(JobNodePath.getConfigNodePath(jobName, "loadLevel"));
Integer loadLevel = 1;
if (!Strings.isNullOrEmpty(loadLevelNode)) {
loadLevel = Integer.parseInt(loadLevelNode);
}
Integer totalLoadLevel = sbf.getTotalLoadLevel();
int thisJobsLoad = (sharding.split(",").length * loadLevel);
sbf.setTotalLoadLevel((sbf.getTotalLoadLevel() == null ? 0 : totalLoadLevel) + thisJobsLoad);
executorNameWithTotalLevel.put(executor, thisJobsLoad);
}
}
}
sbfMap.put(executor, sbf);
}
}
model.put("serverInfos", sbfMap.values());
model.put("jobShardLoadLevels", jobNameExecutorNameTotalLevel);
}
return model;
}
Aggregations