-
Notifications
You must be signed in to change notification settings - Fork 172
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
应用部署在发行版tomcat的支持 #1532
base: develop
Are you sure you want to change the base?
应用部署在发行版tomcat的支持 #1532
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package io.sermant.core.plugin.agent.enhance; | ||
Check failure on line 1 in sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/plugin/agent/enhance/AbstractClassLoaderInterceptor.java GitHub Actions / Checkstyle
|
||
|
||
import io.sermant.core.config.ConfigManager; | ||
import io.sermant.core.plugin.agent.interceptor.Interceptor; | ||
import io.sermant.core.service.inject.config.InjectConfig; | ||
|
||
import java.util.Set; | ||
|
||
/** | ||
* ClassLoader 增强抽象类 | ||
* | ||
* @author Yaxx19 | ||
* @since 2024-06-04 | ||
*/ | ||
public abstract class AbstractClassLoaderInterceptor implements Interceptor { | ||
|
||
private final Set<String> essentialPackage; | ||
|
||
/** | ||
* constructor | ||
*/ | ||
public AbstractClassLoaderInterceptor() { | ||
essentialPackage = ConfigManager.getConfig(InjectConfig.class).getEssentialPackage(); | ||
} | ||
|
||
protected boolean isSermantClass(String name) { | ||
Check failure on line 26 in sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/plugin/agent/enhance/AbstractClassLoaderInterceptor.java GitHub Actions / Checkstyle
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add Javadoc comment for isSermantClass and isSermantResource |
||
for (String prefix : essentialPackage) { | ||
if (name.startsWith(prefix)) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
protected boolean isSermantResource(String path) { | ||
Check failure on line 35 in sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/plugin/agent/enhance/AbstractClassLoaderInterceptor.java GitHub Actions / Checkstyle
|
||
String name = path.replace('/', '.'); | ||
for (String prefix : essentialPackage) { | ||
if (name.startsWith(prefix)) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package io.sermant.core.plugin.agent.enhance; | ||
Check failure on line 1 in sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/plugin/agent/enhance/WebappClassLoaderDeclarer.java GitHub Actions / Checkstyle
|
||
|
||
import io.sermant.core.plugin.agent.declarer.AbstractPluginDeclarer; | ||
import io.sermant.core.plugin.agent.declarer.InterceptDeclarer; | ||
import io.sermant.core.plugin.agent.matcher.ClassMatcher; | ||
import io.sermant.core.plugin.agent.matcher.MethodMatcher; | ||
|
||
/** | ||
* 发行版Tomcat ClassLoader 增强 | ||
* | ||
* @author Yaxx19 | ||
* @since 2024-06-04 | ||
*/ | ||
public class WebappClassLoaderDeclarer extends AbstractPluginDeclarer { | ||
|
||
private static final String TOMCAT_CLASS_LOADER = "org.apache.catalina.loader.WebappClassLoaderBase"; | ||
|
||
@Override | ||
public ClassMatcher getClassMatcher() { | ||
return ClassMatcher.nameEquals(TOMCAT_CLASS_LOADER); | ||
} | ||
|
||
@Override | ||
public InterceptDeclarer[] getInterceptDeclarers(ClassLoader classLoader) { | ||
return new InterceptDeclarer[] { | ||
InterceptDeclarer.build(MethodMatcher.nameEquals("loadClass"), | ||
new ClassLoaderLoadClassInterceptor()), | ||
InterceptDeclarer.build(MethodMatcher.nameEquals("getResourceAsStream"), | ||
new WebappClassLoaderGetResourceAsStreamInterceptor())}; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package io.sermant.core.plugin.agent.enhance; | ||
Check failure on line 1 in sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/plugin/agent/enhance/WebappClassLoaderGetResourceAsStreamInterceptor.java GitHub Actions / Checkstyle
|
||
|
||
import io.sermant.core.classloader.ClassLoaderManager; | ||
import io.sermant.core.common.LoggerFactory; | ||
import io.sermant.core.plugin.agent.entity.ExecuteContext; | ||
|
||
import java.net.URL; | ||
import java.util.Optional; | ||
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
|
||
/** | ||
* 发行版Tomcat ClassLoader getResourceAsStream 增强 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i hope all comments could be in english, As well as PR description and commit message |
||
* | ||
* @author Yaxx19 | ||
* @since 2024-06-04 | ||
*/ | ||
public class WebappClassLoaderGetResourceAsStreamInterceptor extends AbstractClassLoaderInterceptor { | ||
private static final Logger LOGGER = LoggerFactory.getLogger(); | ||
|
||
@Override | ||
public ExecuteContext before(ExecuteContext context) throws Exception { | ||
return context; | ||
} | ||
|
||
@Override | ||
public ExecuteContext after(ExecuteContext context) throws Exception { | ||
if (context.getResult() != null) { | ||
return context; | ||
} | ||
|
||
String path = (String) context.getArguments()[0]; | ||
if (isSermantResource(path)) { | ||
Optional<URL> url = ClassLoaderManager.getPluginClassFinder().findSermantResource(path); | ||
if (!url.isPresent()) { | ||
LOGGER.log(Level.WARNING, "Can not get resource stream [{0}] by sermant.And then find by {1}. ", | ||
new Object[]{path, context.getObject()}); | ||
} else { | ||
context.changeResult(url.get().openStream()); | ||
LOGGER.log(Level.INFO, "Get resource stream: {0} successfully by sermant.", path); | ||
} | ||
} | ||
return context; | ||
} | ||
|
||
@Override | ||
public ExecuteContext onThrow(ExecuteContext context) throws Exception { | ||
return context; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add copy right and licence for all new class files. You can refer to https://github.com/sermant-io/Sermant/blob/6b2582d346fef1ad358c1b408697b1c8749d6ff7/sermant-backend/src/main/java/io/sermant/backend/handler/config/ServiceRegistryPluginHandler.java