Skip to content

Commit

Permalink
Merge pull request #1704 from daizhenyu/develop-dynamic-plugin-path
Browse files Browse the repository at this point in the history
dynamic plugins support custom paths
  • Loading branch information
Sherlockhan authored Dec 26, 2024
2 parents ff41cc7 + 81d013c commit 9575185
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@

package io.sermant.core.command;

import io.sermant.core.common.CommonConstant;
import io.sermant.core.utils.StringUtils;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

Expand Down Expand Up @@ -61,4 +65,26 @@ public static String getAgentArg(String key) {
public static Map<String, String> getAgentArgsMap() {
return AGENT_ARGS;
}

/**
* get dynamic plugin path
*
* @return dynamic plugin path
*/
public static String getDynamicPluginPackagePath() {
String agentFilePath = AGENT_ARGS.get(CommonConstant.AGENT_FILE_KEY);
if (StringUtils.isEmpty(agentFilePath)) {
return StringUtils.EMPTY;
}
return agentFilePath + File.separatorChar + "pluginPackage";
}

/**
* get dynamic agent path
*
* @return dynamic agent path
*/
public static String getAgentPath() {
return AGENT_ARGS.get(CommonConstant.AGENT_PATH_KEY);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package io.sermant.core.plugin;

import io.sermant.core.classloader.ClassLoaderManager;
import io.sermant.core.command.DynamicAgentArgsManager;
import io.sermant.core.common.BootArgsIndexer;
import io.sermant.core.common.LoggerFactory;
import io.sermant.core.event.collector.FrameworkEventCollector;
Expand All @@ -33,6 +34,7 @@
import io.sermant.core.plugin.config.PluginConfigManager;
import io.sermant.core.plugin.service.PluginServiceManager;
import io.sermant.core.utils.CollectionUtils;
import io.sermant.core.utils.StringUtils;

import java.io.File;
import java.io.FileFilter;
Expand Down Expand Up @@ -163,7 +165,11 @@ public static void initPlugins(Set<String> pluginNames, boolean isDynamic) {
}
final String pluginPackage;
try {
pluginPackage = BootArgsIndexer.getPluginPackageDir().getCanonicalPath();
if (isDynamic) {
pluginPackage = getDynamicPluginPackagePath();
} else {
pluginPackage = getStaticPluginPackagePath();
}
} catch (IOException ioException) {
String names = pluginNames.stream().map(String::valueOf).collect(Collectors.joining(", "));
LOGGER.log(Level.SEVERE, "[INSTALL-PLUGINS] [{0}] Resolve plugin package failed.", names);
Expand Down Expand Up @@ -414,4 +420,20 @@ private interface JarFileConsumer {
*/
void consume(JarFile jarFile);
}

private static String getStaticPluginPackagePath() throws IOException {
return BootArgsIndexer.getPluginPackageDir().getCanonicalPath();
}

private static String getDynamicPluginPackagePath() throws IOException {
String dynamicPluginPath = DynamicAgentArgsManager.getDynamicPluginPackagePath();
if (!StringUtils.isEmpty(dynamicPluginPath)) {
return dynamicPluginPath;
}
String agentPath = DynamicAgentArgsManager.getAgentPath();
if (!StringUtils.isEmpty(agentPath)) {
return agentPath + File.separatorChar + "pluginPackage";
}
return BootArgsIndexer.getPluginPackageDir().getCanonicalPath();
}
}

0 comments on commit 9575185

Please sign in to comment.