Skip to content

Commit

Permalink
Optimize monitor module
Browse files Browse the repository at this point in the history
  • Loading branch information
peacewong committed Jan 20, 2025
1 parent 8ac124b commit 233785a
Show file tree
Hide file tree
Showing 45 changed files with 1,791 additions and 197 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

package org.apache.linkis.monitor.config;

import org.apache.linkis.monitor.until.HttpsUntils;
import org.apache.linkis.monitor.entity.ClientSingleton;
import org.apache.linkis.monitor.until.ThreadUtils;
import org.apache.linkis.monitor.utils.log.LogUtils;

Expand All @@ -38,7 +38,7 @@ public class ListenerConfig {
private void shutdownEntrance(ContextClosedEvent event) {
try {
ThreadUtils.executors.shutdown();
HttpsUntils.client.close();
ClientSingleton.getInstance().close();
} catch (IOException e) {
logger.error("ListenerConfig error msg {}", e.getMessage());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.linkis.monitor.department.dao;

import org.apache.linkis.monitor.department.entity.UserDepartmentInfo;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Mapper
public interface UserDepartmentInfoMapper {

void insertUser(UserDepartmentInfo user);

@Transactional(rollbackFor = Exception.class)
int batchInsertUsers(@Param("userDepartmentInfos") List<UserDepartmentInfo> userDepartmentInfos);

void updateUser(UserDepartmentInfo user);

UserDepartmentInfo selectUser(@Param("userName") String userName);

@Transactional(rollbackFor = Exception.class)
void deleteUser();

List<UserDepartmentInfo> selectAllUsers();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.linkis.monitor.department.entity;

import java.util.Date;

public class UserDepartmentInfo {

private String clusterCode;

private String userType;
private String userName;
private String orgId;
private String orgName;
private String queueName;
private String dbName;
private String interfaceUser;
private String isUnionAnalyse;
private Date createTime;
private String userItsmNo;

// 构造函数、getter和setter方法
public UserDepartmentInfo(
String clusterCode,
String userType,
String userName,
String orgId,
String orgName,
String queueName,
String dbName,
String interfaceUser,
String isUnionAnalyse,
Date createTime,
String userItsmNo) {
this.clusterCode = clusterCode;
this.userType = userType;
this.userName = userName;
this.orgId = orgId;
this.orgName = orgName;
this.queueName = queueName;
this.dbName = dbName;
this.interfaceUser = interfaceUser;
this.isUnionAnalyse = isUnionAnalyse;
this.createTime = createTime;
this.userItsmNo = userItsmNo;
}

public String getClusterCode() {
return clusterCode;
}

public void setClusterCode(String clusterCode) {
this.clusterCode = clusterCode;
}

public String getUserType() {
return userType;
}

public void setUserType(String userType) {
this.userType = userType;
}

public String getUserName() {
return userName;
}

public void setUserName(String userName) {
this.userName = userName;
}

public String getOrgId() {
return orgId;
}

public void setOrgId(String orgId) {
this.orgId = orgId;
}

public String getOrgName() {
return orgName;
}

public void setOrgName(String orgName) {
this.orgName = orgName;
}

public String getQueueName() {
return queueName;
}

public void setQueueName(String queueName) {
this.queueName = queueName;
}

public String getDbName() {
return dbName;
}

public void setDbName(String dbName) {
this.dbName = dbName;
}

public String getInterfaceUser() {
return interfaceUser;
}

public void setInterfaceUser(String interfaceUser) {
this.interfaceUser = interfaceUser;
}

public String getIsUnionAnalyse() {
return isUnionAnalyse;
}

public void setIsUnionAnalyse(String isUnionAnalyse) {
this.isUnionAnalyse = isUnionAnalyse;
}

public Date getCreateTime() {
return createTime;
}

public void setCreateTime(Date createTime) {
this.createTime = createTime;
}

public String getUserItsmNo() {
return userItsmNo;
}

public void setUserItsmNo(String userItsmNo) {
this.userItsmNo = userItsmNo;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.linkis.monitor.entity;

import org.apache.linkis.bml.conf.BmlConfiguration;
import org.apache.linkis.common.conf.Configuration;
import org.apache.linkis.httpclient.dws.authentication.TokenAuthenticationStrategy;
import org.apache.linkis.httpclient.dws.config.DWSClientConfig;
import org.apache.linkis.httpclient.dws.config.DWSClientConfigBuilder;
import org.apache.linkis.monitor.client.MonitorHTTPClient;
import org.apache.linkis.monitor.client.MonitorHTTPClientClientImpl;

import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.StringUtils;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;

public class ClientSingleton {
private static MonitorHTTPClient instance;
private static DWSClientConfig dwsClientConfig;

private ClientSingleton() {}

public static synchronized MonitorHTTPClient getInstance() {
if (instance == null) {
if (dwsClientConfig == null) {
dwsClientConfig = createClientConfig(null, null); // NOSONAR
}
instance = new MonitorHTTPClientClientImpl(dwsClientConfig);
}
return instance;
}

public static DWSClientConfig createClientConfig(String url, Map<String, Object> properties) {
String realUrl = "";
if (StringUtils.isBlank(url)) {
realUrl = Configuration.getGateWayURL();
} else {
realUrl = url;
}
Map<String, Object> parms = new HashMap<>();
if (MapUtils.isNotEmpty(properties)) {
parms = properties;
}
int maxConnection =
(int)
parms.getOrDefault( // NOSONAR
BmlConfiguration.CONNECTION_MAX_SIZE_SHORT_NAME(),
BmlConfiguration.CONNECTION_MAX_SIZE().getValue());
int connectTimeout =
(int)
parms.getOrDefault(
BmlConfiguration.CONNECTION_TIMEOUT_SHORT_NAME(),
BmlConfiguration.CONNECTION_TIMEOUT().getValue());
int readTimeout =
(int)
parms.getOrDefault(
BmlConfiguration.CONNECTION_READ_TIMEOUT_SHORT_NAME(),
BmlConfiguration.CONNECTION_READ_TIMEOUT().getValue());
String tokenKey =
(String)
parms.getOrDefault(
BmlConfiguration.AUTH_TOKEN_KEY_SHORT_NAME(),
BmlConfiguration.AUTH_TOKEN_KEY().getValue());
String tokenValue =
(String)
parms.getOrDefault(
BmlConfiguration.AUTH_TOKEN_VALUE_SHORT_NAME(),
BmlConfiguration.AUTH_TOKEN_VALUE().getValue());

DWSClientConfig clientConfig =
((DWSClientConfigBuilder)
(DWSClientConfigBuilder.newBuilder()
.addServerUrl(realUrl)
.connectionTimeout(connectTimeout)
.discoveryEnabled(false)
.discoveryFrequency(1, TimeUnit.MINUTES)
.loadbalancerEnabled(false)
.maxConnectionSize(maxConnection)
.retryEnabled(false)
.readTimeout(readTimeout)
.setAuthenticationStrategy(new TokenAuthenticationStrategy())
.setAuthTokenKey(tokenKey)
.setAuthTokenValue(tokenValue)))
.setDWSVersion("v1")
.build();

return clientConfig;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

public class QueryUtils {

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

public static String dateToString(Date date) {
return dateFormat.format(date);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ public void entranceTask() throws IOException {
});
Map<String, Object> likisData = null;
try {
likisData = MapUtils.getMap(HttpsUntils.getEntranceTask(null, "hadoop", null), "data");
likisData =
MapUtils.getMap(HttpsUntils.getEntranceTask(null, Constants.ADMIN_USER(), null), "data");
logger.info("TaskMonitor hadoop response {}:", likisData);
} catch (IOException e) {
logger.warn("failed to get EntranceTask data");
Expand Down Expand Up @@ -163,7 +164,9 @@ public static void resourceSendToIms() {
try {
// 通过serviceInstance 获取entrance中任务数量信息
Map<String, Object> entranceData =
MapUtils.getMap(HttpsUntils.getEntranceTask(null, "hadoop", entranceService), "data");
MapUtils.getMap(
HttpsUntils.getEntranceTask(null, Constants.ADMIN_USER(), entranceService),
"data");
int runningTaskNumber = 0;
int queuedTaskNumber = 0;
int totalTaskNumber = 0;
Expand Down
Loading

0 comments on commit 233785a

Please sign in to comment.