-
Notifications
You must be signed in to change notification settings - Fork 172
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a1308ed
commit 9992fdf
Showing
7 changed files
with
170 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
...-core/src/main/java/com/huaweicloud/sermant/core/command/CheckEnhanceCommandExecutor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* 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.EnhanceInfo; | ||
|
||
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, "========== print enhance class and method =========="); | ||
Map<String, Set<String>> enhancement = EnhanceInfo.getEnhancement(); | ||
for (Map.Entry<String, Set<String>> enhancemantEntry : enhancement.entrySet()) { | ||
Set<String> methodDescSet = enhancemantEntry.getValue(); | ||
for (String methodDesc : methodDescSet) { | ||
LOGGER.log(Level.INFO, enhancemantEntry.getKey() + " " + methodDesc); | ||
} | ||
} | ||
LOGGER.log(Level.INFO, "========== print plugin =========="); | ||
for (Map.Entry<String, Plugin> entry : PluginManager.getPluginMap().entrySet()) { | ||
LOGGER.log(Level.INFO, "[PluginName]:" + entry.getKey() + "\t[Version]:" + entry.getValue().getVersion()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
...ntcore-core/src/main/java/com/huaweicloud/sermant/core/plugin/agent/info/EnhanceInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/* | ||
* 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.utils.CollectionUtils; | ||
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.Map; | ||
import java.util.Set; | ||
|
||
/** | ||
* 存储增强信息的静态类 | ||
* | ||
* @author tangle | ||
* @since 2023-11-02 | ||
*/ | ||
public class EnhanceInfo { | ||
private static Map<String, Set<String>> enhancement; | ||
|
||
private EnhanceInfo() { | ||
} | ||
|
||
public static Map<String, Set<String>> getEnhancement() { | ||
return enhancement; | ||
} | ||
|
||
public static void setEnhancement(Map<String, Set<String>> enhancement) { | ||
EnhanceInfo.enhancement = enhancement; | ||
} | ||
|
||
/** | ||
* 添加拦截器信息 | ||
* | ||
* @param pluginName 插件名 | ||
* @param pluginVersion 插件版本 | ||
* @param className 类名 | ||
* @param methodName 方法名 | ||
*/ | ||
public static void addMethodDesc(String pluginName, String pluginVersion, String className, String methodName) { | ||
if (MapUtils.isEmpty(enhancement)) { | ||
enhancement = new HashMap<>(); | ||
} | ||
String enhancementKey = pluginName + ":" + pluginVersion; | ||
Set<String> methodDesc; | ||
if (CollectionUtils.isEmpty(enhancement.get(enhancementKey))) { | ||
methodDesc = new HashSet<>(); | ||
} else { | ||
methodDesc = enhancement.get(enhancementKey); | ||
} | ||
if (!StringUtils.isEmpty(className) && !StringUtils.isEmpty(methodName)) { | ||
methodDesc.add(className + "::" + methodName); | ||
} | ||
enhancement.put(enhancementKey, methodDesc); | ||
} | ||
|
||
/** | ||
* 卸载插件时清除该插件的增强信息 | ||
* | ||
* @param plugin 插件 | ||
*/ | ||
public static void removePluginEnhancement(Plugin plugin) { | ||
if (enhancement != null) { | ||
enhancement.remove(plugin.getName() + ":" + plugin.getVersion()); | ||
} | ||
} | ||
|
||
/** | ||
* 清理缓存的增强信息 | ||
*/ | ||
public static void clear() { | ||
if (enhancement != null) { | ||
enhancement.clear(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters