Skip to content

Commit 27ed006

Browse files
authored
Merge pull request #47 from zhp8341/bug_fix_optimize
新增客户端日志查看功能
2 parents 96d944c + a63b253 commit 27ed006

19 files changed

Lines changed: 164 additions & 40 deletions

File tree

docs/sql/flink_web.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ CREATE TABLE `job_run_log` (
9696
PRIMARY KEY (`id`)
9797
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='运行任务日志';
9898

99+
ALTER TABLE job_run_log add `run_ip` varchar(64) DEFAULT NULL COMMENT '任务运行所在的机器' AFTER local_log ;
100+
99101
-- ----------------------------
100102
-- Table structure for savepoint_backup
101103
-- ----------------------------

flink-streaming-web-common/src/main/java/com/flink/streaming/web/common/MessageConstants.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,6 @@ public class MessageConstants {
2828

2929
public static final String MESSAGE_009 = "没有获取到savepointPath路径目录 任务:{}";
3030

31+
public static final String MESSAGE_010 = "无法获取 user.name";
32+
3133
}

flink-streaming-web-common/src/main/java/com/flink/streaming/web/common/util/FileUtils.java

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package com.flink.streaming.web.common.util;
22

3-
import cn.hutool.core.date.DateUtil;
4-
import cn.hutool.core.lang.UUID;
53
import cn.hutool.core.util.StrUtil;
64
import com.flink.streaming.web.common.SystemConstants;
75
import com.flink.streaming.web.enums.SysErrorEnum;
@@ -13,7 +11,6 @@
1311
import java.io.File;
1412
import java.io.FileOutputStream;
1513
import java.io.OutputStreamWriter;
16-
import java.util.Date;
1714

1815
/**
1916
* @author zhuhuipei
@@ -104,18 +101,6 @@ public static void writeText(String filePath, String content, boolean isAppend)
104101
}
105102
}
106103

107-
public static String downJar(String downUrl,String sysHome){
108-
String extJarPath = sysHome + "tmp/udf_jar/" + DateUtil.formatDate(new Date()) + "/" + UUID.fastUUID();
109-
FileUtils.mkdirs(extJarPath);
110-
String fileName = System.currentTimeMillis() + "_udf.jar";
111-
String[] cmds = {"curl", "-o", extJarPath + "/" + fileName, downUrl};
112-
113-
114-
return "";
115-
116-
}
117-
118-
119104
public static void mkdirs(String path) {
120105
File dir = new File(path);
121106
if (!dir.exists()) {

flink-streaming-web-common/src/main/java/com/flink/streaming/web/common/util/IpUtil.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.flink.streaming.web.common.util;
22

3+
import com.flink.streaming.web.exceptions.BizException;
4+
import lombok.extern.slf4j.Slf4j;
35
import org.apache.commons.lang3.StringUtils;
46

57
import java.net.InetAddress;
@@ -11,6 +13,7 @@
1113
* @date 2018/7/19
1214
* @time 下午6:18
1315
*/
16+
@Slf4j
1417
public class IpUtil {
1518

1619
private static String ip;
@@ -54,9 +57,22 @@ private String getIp() {
5457
return ipAddrStr;
5558
}
5659

60+
public static String getHostName() {
61+
try {
62+
InetAddress addr = InetAddress.getLocalHost();
63+
return addr.getHostName(); //获取本机计算机名称
64+
} catch (Exception e) {
65+
log.error("getHostName is error", e);
66+
throw new BizException(e.getMessage());
67+
}
68+
69+
70+
}
71+
5772
public static void main(String[] args) {
5873
System.out.println(IpUtil.getInstance().getLocalIP());
5974
System.out.println(IpUtil.getInstance().getLocalIP());
60-
//System.out.println(IpUtil.getInstance().getLocalIP());
75+
System.out.println(getHostName());
76+
System.out.println(System.getProperty("user.name"));
6177
}
6278
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.flink.streaming.web.common.util;
2+
3+
import com.flink.streaming.web.common.MessageConstants;
4+
import com.flink.streaming.web.exceptions.BizException;
5+
import org.apache.commons.lang3.StringUtils;
6+
7+
/**
8+
* @author zhuhuipei
9+
* @Description:
10+
* @date 2021/5/5
11+
* @time 10:46
12+
*/
13+
public class LinuxInfoUtil {
14+
15+
public static String loginName(){
16+
String userName=System.getProperty("user.name");
17+
if (StringUtils.isNotEmpty(userName)){
18+
return userName;
19+
}
20+
throw new BizException(MessageConstants.MESSAGE_010);
21+
22+
}
23+
}

flink-streaming-web-common/src/main/java/com/flink/streaming/web/model/dto/JobRunLogDTO.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ public class JobRunLogDTO implements Serializable {
8080
*/
8181
private String localLog;
8282

83+
private String runIp;
84+
8385

8486
public static JobRunLog toEntity(JobRunLogDTO jobRunLogDTO) {
8587
if (jobRunLogDTO == null) {
@@ -100,6 +102,7 @@ public static JobRunLog toEntity(JobRunLogDTO jobRunLogDTO) {
100102
jobRunLog.setCreateTime(jobRunLogDTO.getCreateTime());
101103
jobRunLog.setEditTime(jobRunLogDTO.getEditTime());
102104
jobRunLog.setLocalLog(jobRunLogDTO.getLocalLog());
105+
jobRunLog.setRunIp(jobRunLogDTO.getRunIp());
103106
return jobRunLog;
104107
}
105108

@@ -123,6 +126,7 @@ public static JobRunLogDTO toDTO(JobRunLog jobRunLog) {
123126
jobRunLogDTO.setCreator(jobRunLog.getCreator());
124127
jobRunLogDTO.setEditor(jobRunLog.getEditor());
125128
jobRunLogDTO.setLocalLog(jobRunLog.getLocalLog());
129+
jobRunLogDTO.setRunIp(jobRunLog.getRunIp());
126130
return jobRunLogDTO;
127131
}
128132

flink-streaming-web-common/src/main/java/com/flink/streaming/web/model/entity/JobRunLog.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,5 +75,7 @@ public class JobRunLog implements Serializable {
7575
*/
7676
private String localLog;
7777

78+
private String runIp;
79+
7880

7981
}

flink-streaming-web-common/src/main/java/com/flink/streaming/web/model/param/UpsertJobConfigParam.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ public static JobConfigDTO toDTO(UpsertJobConfigParam upsertJobConfigParam) {
122122
jobConfigDTO.setStatus(JobConfigStatus.getJobConfigStatus(upsertJobConfigParam.getStauts()));
123123
if (StringUtils.isNotEmpty(upsertJobConfigParam.getExtJarPath())) {
124124
jobConfigDTO.setExtJarPath(upsertJobConfigParam.getExtJarPath().trim());
125+
}else{
126+
jobConfigDTO.setExtJarPath(SystemConstant.SPACE);
125127
}
126128
if (StringUtils.isNotEmpty(upsertJobConfigParam.getAlarmTypes())) {
127129
List<AlarmTypeEnum> list = new ArrayList<>();

flink-streaming-web-common/src/main/java/com/flink/streaming/web/model/vo/JobRunLogVO.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.flink.streaming.web.enums.JobStatusEnum;
55
import com.flink.streaming.web.model.dto.JobRunLogDTO;
66
import lombok.Data;
7+
import org.apache.commons.lang3.StringUtils;
78
import org.springframework.util.CollectionUtils;
89

910
import java.io.Serializable;
@@ -77,8 +78,13 @@ public class JobRunLogVO implements Serializable {
7778
*/
7879
private String localLog;
7980

81+
/**
82+
* 本地客户端日志
83+
*/
84+
private String clinetJobUrl;
8085

81-
public static JobRunLogVO toVO(JobRunLogDTO jobRunLogDTO, boolean isLocalLog) {
86+
87+
public static JobRunLogVO toVO(JobRunLogDTO jobRunLogDTO, boolean isLocalLog,Integer port) {
8288
if (jobRunLogDTO == null) {
8389
return null;
8490
}
@@ -97,6 +103,10 @@ public static JobRunLogVO toVO(JobRunLogDTO jobRunLogDTO, boolean isLocalLog) {
97103
if (isLocalLog) {
98104
jobRunLogVO.setLocalLog(jobRunLogDTO.getLocalLog());
99105
}
106+
if (port!=null && StringUtils.isNotEmpty(jobRunLogDTO.getRunIp())){
107+
jobRunLogVO.setClinetJobUrl(String.format("http://%s:%s/log/getFlinkLocalJobLog",
108+
jobRunLogDTO.getRunIp(),port));
109+
}
100110

101111
return jobRunLogVO;
102112
}
@@ -108,7 +118,7 @@ public static List<JobRunLogVO> toListVO(List<JobRunLogDTO> jobRunLogList, boole
108118
List<JobRunLogVO> list = new ArrayList<>();
109119

110120
for (JobRunLogDTO jobRunLog : jobRunLogList) {
111-
list.add(JobRunLogVO.toVO(jobRunLog, isLocalLog));
121+
list.add(JobRunLogVO.toVO(jobRunLog, isLocalLog,null));
112122
}
113123
return list;
114124

flink-streaming-web-config/src/main/java/com/flink/streaming/web/config/CustomConfig.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,7 @@ public class CustomConfig {
1616

1717
@Value("${custom.core.jar.name}")
1818
private String coreJarName;
19+
20+
@Value("${server.port}")
21+
private Integer webPort;
1922
}

0 commit comments

Comments
 (0)