Skip to content

Commit ef268fb

Browse files
Liboyistupeacewong
andauthored
Optimize monitor module (#5216)
Co-authored-by: peacewong <[email protected]>
1 parent c0065b1 commit ef268fb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1791
-197
lines changed

linkis-extensions/linkis-et-monitor/src/main/java/org/apache/linkis/monitor/config/ListenerConfig.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
package org.apache.linkis.monitor.config;
1919

20-
import org.apache.linkis.monitor.until.HttpsUntils;
20+
import org.apache.linkis.monitor.entity.ClientSingleton;
2121
import org.apache.linkis.monitor.until.ThreadUtils;
2222
import org.apache.linkis.monitor.utils.log.LogUtils;
2323

@@ -38,7 +38,7 @@ public class ListenerConfig {
3838
private void shutdownEntrance(ContextClosedEvent event) {
3939
try {
4040
ThreadUtils.executors.shutdown();
41-
HttpsUntils.client.close();
41+
ClientSingleton.getInstance().close();
4242
} catch (IOException e) {
4343
logger.error("ListenerConfig error msg {}", e.getMessage());
4444
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.linkis.monitor.department.dao;
19+
20+
import org.apache.linkis.monitor.department.entity.UserDepartmentInfo;
21+
22+
import org.apache.ibatis.annotations.Mapper;
23+
import org.apache.ibatis.annotations.Param;
24+
25+
import org.springframework.transaction.annotation.Transactional;
26+
27+
import java.util.List;
28+
29+
@Mapper
30+
public interface UserDepartmentInfoMapper {
31+
32+
void insertUser(UserDepartmentInfo user);
33+
34+
@Transactional(rollbackFor = Exception.class)
35+
int batchInsertUsers(@Param("userDepartmentInfos") List<UserDepartmentInfo> userDepartmentInfos);
36+
37+
void updateUser(UserDepartmentInfo user);
38+
39+
UserDepartmentInfo selectUser(@Param("userName") String userName);
40+
41+
@Transactional(rollbackFor = Exception.class)
42+
void deleteUser();
43+
44+
List<UserDepartmentInfo> selectAllUsers();
45+
}
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.linkis.monitor.department.entity;
19+
20+
import java.util.Date;
21+
22+
public class UserDepartmentInfo {
23+
24+
private String clusterCode;
25+
26+
private String userType;
27+
private String userName;
28+
private String orgId;
29+
private String orgName;
30+
private String queueName;
31+
private String dbName;
32+
private String interfaceUser;
33+
private String isUnionAnalyse;
34+
private Date createTime;
35+
private String userItsmNo;
36+
37+
// 构造函数、getter和setter方法
38+
public UserDepartmentInfo(
39+
String clusterCode,
40+
String userType,
41+
String userName,
42+
String orgId,
43+
String orgName,
44+
String queueName,
45+
String dbName,
46+
String interfaceUser,
47+
String isUnionAnalyse,
48+
Date createTime,
49+
String userItsmNo) {
50+
this.clusterCode = clusterCode;
51+
this.userType = userType;
52+
this.userName = userName;
53+
this.orgId = orgId;
54+
this.orgName = orgName;
55+
this.queueName = queueName;
56+
this.dbName = dbName;
57+
this.interfaceUser = interfaceUser;
58+
this.isUnionAnalyse = isUnionAnalyse;
59+
this.createTime = createTime;
60+
this.userItsmNo = userItsmNo;
61+
}
62+
63+
public String getClusterCode() {
64+
return clusterCode;
65+
}
66+
67+
public void setClusterCode(String clusterCode) {
68+
this.clusterCode = clusterCode;
69+
}
70+
71+
public String getUserType() {
72+
return userType;
73+
}
74+
75+
public void setUserType(String userType) {
76+
this.userType = userType;
77+
}
78+
79+
public String getUserName() {
80+
return userName;
81+
}
82+
83+
public void setUserName(String userName) {
84+
this.userName = userName;
85+
}
86+
87+
public String getOrgId() {
88+
return orgId;
89+
}
90+
91+
public void setOrgId(String orgId) {
92+
this.orgId = orgId;
93+
}
94+
95+
public String getOrgName() {
96+
return orgName;
97+
}
98+
99+
public void setOrgName(String orgName) {
100+
this.orgName = orgName;
101+
}
102+
103+
public String getQueueName() {
104+
return queueName;
105+
}
106+
107+
public void setQueueName(String queueName) {
108+
this.queueName = queueName;
109+
}
110+
111+
public String getDbName() {
112+
return dbName;
113+
}
114+
115+
public void setDbName(String dbName) {
116+
this.dbName = dbName;
117+
}
118+
119+
public String getInterfaceUser() {
120+
return interfaceUser;
121+
}
122+
123+
public void setInterfaceUser(String interfaceUser) {
124+
this.interfaceUser = interfaceUser;
125+
}
126+
127+
public String getIsUnionAnalyse() {
128+
return isUnionAnalyse;
129+
}
130+
131+
public void setIsUnionAnalyse(String isUnionAnalyse) {
132+
this.isUnionAnalyse = isUnionAnalyse;
133+
}
134+
135+
public Date getCreateTime() {
136+
return createTime;
137+
}
138+
139+
public void setCreateTime(Date createTime) {
140+
this.createTime = createTime;
141+
}
142+
143+
public String getUserItsmNo() {
144+
return userItsmNo;
145+
}
146+
147+
public void setUserItsmNo(String userItsmNo) {
148+
this.userItsmNo = userItsmNo;
149+
}
150+
}
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.linkis.monitor.entity;
19+
20+
import org.apache.linkis.bml.conf.BmlConfiguration;
21+
import org.apache.linkis.common.conf.Configuration;
22+
import org.apache.linkis.httpclient.dws.authentication.TokenAuthenticationStrategy;
23+
import org.apache.linkis.httpclient.dws.config.DWSClientConfig;
24+
import org.apache.linkis.httpclient.dws.config.DWSClientConfigBuilder;
25+
import org.apache.linkis.monitor.client.MonitorHTTPClient;
26+
import org.apache.linkis.monitor.client.MonitorHTTPClientClientImpl;
27+
28+
import org.apache.commons.collections.MapUtils;
29+
import org.apache.commons.lang3.StringUtils;
30+
31+
import java.util.HashMap;
32+
import java.util.Map;
33+
import java.util.concurrent.TimeUnit;
34+
35+
public class ClientSingleton {
36+
private static MonitorHTTPClient instance;
37+
private static DWSClientConfig dwsClientConfig;
38+
39+
private ClientSingleton() {}
40+
41+
public static synchronized MonitorHTTPClient getInstance() {
42+
if (instance == null) {
43+
if (dwsClientConfig == null) {
44+
dwsClientConfig = createClientConfig(null, null); // NOSONAR
45+
}
46+
instance = new MonitorHTTPClientClientImpl(dwsClientConfig);
47+
}
48+
return instance;
49+
}
50+
51+
public static DWSClientConfig createClientConfig(String url, Map<String, Object> properties) {
52+
String realUrl = "";
53+
if (StringUtils.isBlank(url)) {
54+
realUrl = Configuration.getGateWayURL();
55+
} else {
56+
realUrl = url;
57+
}
58+
Map<String, Object> parms = new HashMap<>();
59+
if (MapUtils.isNotEmpty(properties)) {
60+
parms = properties;
61+
}
62+
int maxConnection =
63+
(int)
64+
parms.getOrDefault( // NOSONAR
65+
BmlConfiguration.CONNECTION_MAX_SIZE_SHORT_NAME(),
66+
BmlConfiguration.CONNECTION_MAX_SIZE().getValue());
67+
int connectTimeout =
68+
(int)
69+
parms.getOrDefault(
70+
BmlConfiguration.CONNECTION_TIMEOUT_SHORT_NAME(),
71+
BmlConfiguration.CONNECTION_TIMEOUT().getValue());
72+
int readTimeout =
73+
(int)
74+
parms.getOrDefault(
75+
BmlConfiguration.CONNECTION_READ_TIMEOUT_SHORT_NAME(),
76+
BmlConfiguration.CONNECTION_READ_TIMEOUT().getValue());
77+
String tokenKey =
78+
(String)
79+
parms.getOrDefault(
80+
BmlConfiguration.AUTH_TOKEN_KEY_SHORT_NAME(),
81+
BmlConfiguration.AUTH_TOKEN_KEY().getValue());
82+
String tokenValue =
83+
(String)
84+
parms.getOrDefault(
85+
BmlConfiguration.AUTH_TOKEN_VALUE_SHORT_NAME(),
86+
BmlConfiguration.AUTH_TOKEN_VALUE().getValue());
87+
88+
DWSClientConfig clientConfig =
89+
((DWSClientConfigBuilder)
90+
(DWSClientConfigBuilder.newBuilder()
91+
.addServerUrl(realUrl)
92+
.connectionTimeout(connectTimeout)
93+
.discoveryEnabled(false)
94+
.discoveryFrequency(1, TimeUnit.MINUTES)
95+
.loadbalancerEnabled(false)
96+
.maxConnectionSize(maxConnection)
97+
.retryEnabled(false)
98+
.readTimeout(readTimeout)
99+
.setAuthenticationStrategy(new TokenAuthenticationStrategy())
100+
.setAuthTokenKey(tokenKey)
101+
.setAuthTokenValue(tokenValue)))
102+
.setDWSVersion("v1")
103+
.build();
104+
105+
return clientConfig;
106+
}
107+
}

linkis-extensions/linkis-et-monitor/src/main/java/org/apache/linkis/monitor/jobhistory/QueryUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
public class QueryUtils {
2525

26-
private static DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
26+
private static DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); // NOSONAR
2727

2828
public static String dateToString(Date date) {
2929
return dateFormat.format(date);

linkis-extensions/linkis-et-monitor/src/main/java/org/apache/linkis/monitor/scheduled/EntranceTaskMonitor.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,8 @@ public void entranceTask() throws IOException {
121121
});
122122
Map<String, Object> likisData = null;
123123
try {
124-
likisData = MapUtils.getMap(HttpsUntils.getEntranceTask(null, "hadoop", null), "data");
124+
likisData =
125+
MapUtils.getMap(HttpsUntils.getEntranceTask(null, Constants.ADMIN_USER(), null), "data");
125126
logger.info("TaskMonitor hadoop response {}:", likisData);
126127
} catch (IOException e) {
127128
logger.warn("failed to get EntranceTask data");
@@ -163,7 +164,9 @@ public static void resourceSendToIms() {
163164
try {
164165
// 通过serviceInstance 获取entrance中任务数量信息
165166
Map<String, Object> entranceData =
166-
MapUtils.getMap(HttpsUntils.getEntranceTask(null, "hadoop", entranceService), "data");
167+
MapUtils.getMap(
168+
HttpsUntils.getEntranceTask(null, Constants.ADMIN_USER(), entranceService),
169+
"data");
167170
int runningTaskNumber = 0;
168171
int queuedTaskNumber = 0;
169172
int totalTaskNumber = 0;

0 commit comments

Comments
 (0)