-
Notifications
You must be signed in to change notification settings - Fork 172
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* Copyright (C) 2023-2023 Huawei Technologies Co., Ltd. All rights reserved. | ||
* | ||
* Licensed 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 com.huaweicloud.sermant.core.command; | ||
|
||
import com.huaweicloud.sermant.core.common.LoggerFactory; | ||
import com.huaweicloud.sermant.core.plugin.Plugin; | ||
import com.huaweicloud.sermant.core.plugin.PluginManager; | ||
import com.huaweicloud.sermant.core.plugin.agent.info.EnhanceInfoManager; | ||
import com.huaweicloud.sermant.core.utils.CollectionUtils; | ||
import com.huaweicloud.sermant.core.utils.MapUtils; | ||
|
||
import java.util.Map; | ||
import java.util.Set; | ||
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
|
||
/** | ||
* 增强信息查询命令执行器 | ||
* | ||
* @author tangle | ||
* @since 2023-11-02 | ||
*/ | ||
public class CheckEnhanceCommandExecutor implements CommandExecutor { | ||
private static final Logger LOGGER = LoggerFactory.getLogger(); | ||
|
||
@Override | ||
public void execute(String args) { | ||
LOGGER.log(Level.INFO, "========== plugins =========="); | ||
for (Map.Entry<String, Plugin> entry : PluginManager.getPluginMap().entrySet()) { | ||
LOGGER.log(Level.INFO, entry.getKey() + ":" + entry.getValue().getVersion()); | ||
} | ||
LOGGER.log(Level.INFO, "========== enhancement =========="); | ||
Map<String, Map<String, Set<String>>> enhancement = EnhanceInfoManager.getEnhancement(); | ||
if (MapUtils.isEmpty(enhancement)) { | ||
LOGGER.log(Level.INFO, "enhancement map is empty."); | ||
return; | ||
} | ||
for (Map.Entry<String, Map<String, Set<String>>> enhancemantEntry : enhancement.entrySet()) { | ||
String pluginInfo = enhancemantEntry.getKey(); | ||
Map<String, Set<String>> methodDescMap = enhancemantEntry.getValue(); | ||
if (MapUtils.isEmpty(methodDescMap)) { | ||
continue; | ||
} | ||
LOGGER.log(Level.INFO, pluginInfo); | ||
for (Map.Entry<String, Set<String>> methodDescEntry : methodDescMap.entrySet()) { | ||
String methodDesc = methodDescEntry.getKey(); | ||
Set<String> interceptorSet = methodDescEntry.getValue(); | ||
if (CollectionUtils.isEmpty(interceptorSet)) { | ||
continue; | ||
} | ||
LOGGER.log(Level.INFO, methodDesc + " " + interceptorSet); | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
/* | ||
* Copyright (C) 2023-2023 Huawei Technologies Co., Ltd. All rights reserved. | ||
* | ||
* Licensed 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 com.huaweicloud.sermant.core.plugin.agent.info; | ||
|
||
import com.huaweicloud.sermant.core.plugin.Plugin; | ||
import com.huaweicloud.sermant.core.plugin.agent.interceptor.Interceptor; | ||
import com.huaweicloud.sermant.core.utils.MapUtils; | ||
import com.huaweicloud.sermant.core.utils.StringUtils; | ||
|
||
import java.util.HashMap; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
/** | ||
* 存储增强信息的静态类 | ||
* | ||
* @author tangle | ||
* @since 2023-11-02 | ||
*/ | ||
public class EnhanceInfoManager { | ||
private static Map<String, Map<String, Set<String>>> enhancement; | ||
|
||
private EnhanceInfoManager() { | ||
} | ||
|
||
public static Map<String, Map<String, Set<String>>> getEnhancement() { | ||
return enhancement; | ||
} | ||
|
||
/** | ||
* 添加拦截器信息 | ||
* | ||
* @param interceptorList 拦截器列表 | ||
* @param plugin 插件 | ||
* @param className 类名 | ||
Check failure on line 51 in sermant-agentcore/sermant-agentcore-core/src/main/java/com/huaweicloud/sermant/core/plugin/agent/info/EnhanceInfoManager.java GitHub Actions / Checkstyle
|
||
* @param methodName 方法名 | ||
Check failure on line 52 in sermant-agentcore/sermant-agentcore-core/src/main/java/com/huaweicloud/sermant/core/plugin/agent/info/EnhanceInfoManager.java GitHub Actions / Checkstyle
|
||
*/ | ||
public static void addEnhancement(Plugin plugin, List<Interceptor> interceptorList, ClassLoader classLoader, | ||
Check failure on line 54 in sermant-agentcore/sermant-agentcore-core/src/main/java/com/huaweicloud/sermant/core/plugin/agent/info/EnhanceInfoManager.java GitHub Actions / Checkstyle
|
||
String methodDesc) { | ||
Check failure on line 55 in sermant-agentcore/sermant-agentcore-core/src/main/java/com/huaweicloud/sermant/core/plugin/agent/info/EnhanceInfoManager.java GitHub Actions / Checkstyle
|
||
if (MapUtils.isEmpty(enhancement)) { | ||
enhancement = new HashMap<>(); | ||
} | ||
String enhancementKey = combinePluginInfo(plugin); | ||
Map<String, Set<String>> methodDescMap = enhancement.computeIfAbsent(enhancementKey, key -> new HashMap<>()); | ||
if (!StringUtils.isEmpty(methodDesc)) { | ||
String methodDescKey = combineEnhanceInfo(methodDesc, classLoader); | ||
Set<String> interceptorSet = methodDescMap.computeIfAbsent(methodDescKey, key -> new HashSet<>()); | ||
for (Interceptor interceptor : interceptorList){ | ||
Check failure on line 64 in sermant-agentcore/sermant-agentcore-core/src/main/java/com/huaweicloud/sermant/core/plugin/agent/info/EnhanceInfoManager.java GitHub Actions / Checkstyle
|
||
interceptorSet.add(interceptor.getClass().getCanonicalName()); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* 卸载插件时清除该插件的增强信息 | ||
* | ||
* @param plugin 插件 | ||
*/ | ||
public static void removePluginEnhancement(Plugin plugin) { | ||
if (enhancement != null) { | ||
enhancement.remove(combinePluginInfo(plugin)); | ||
} | ||
} | ||
|
||
/** | ||
* 清理缓存的增强信息 | ||
*/ | ||
public static void clear() { | ||
if (enhancement != null) { | ||
enhancement.clear(); | ||
} | ||
} | ||
|
||
/** | ||
* 拼接插件信息 | ||
*/ | ||
private static String combinePluginInfo(Plugin plugin) { | ||
return plugin.getName() + ":" + plugin.getVersion(); | ||
} | ||
|
||
/** | ||
* 拼接增强信息 | ||
*/ | ||
private static String combineEnhanceInfo(String methodDesc, ClassLoader classLoader) { | ||
return methodDesc + "@" + classLoader; | ||
} | ||
} |