use of com.creditease.uav.profiling.handlers.dubbo.DubboServiceProfileInfo in project uavstack by uavorg.
the class DubboIT method doProfiling.
/**
* collect all ServiceBeans for later profiling
*
* @param args
*/
@SuppressWarnings("rawtypes")
public void doProfiling(Object[] args) {
InterceptContext ic = InterceptSupport.instance().getThreadLocalContext(Event.WEBCONTAINER_STARTED);
@SuppressWarnings("unchecked") Map<String, DubboServiceProfileInfo> list = (Map<String, DubboServiceProfileInfo>) ic.get(HookConstants.DUBBO_PROFILE_LIST);
if (null == list) {
list = new HashMap<String, DubboServiceProfileInfo>();
ic.put(HookConstants.DUBBO_PROFILE_LIST, list);
}
ServiceBean sb = (ServiceBean) args[0];
String serviceClass = sb.getInterface();
String serviceImplClass = sb.getRef().getClass().getName();
// the refclass is enhance by SpringCGLIB, className like "ServiceImplClass$$EnhancerBySpringCGLIB$$2a862c3d"
if (serviceImplClass.indexOf("$$") > -1) {
serviceImplClass = serviceImplClass.substring(0, serviceImplClass.indexOf("$$"));
}
String group = (sb.getGroup() == null) ? "" : sb.getGroup();
if (sb.getGroup() == null && sb.getProvider() != null && sb.getProvider().getGroup() != null) {
group = sb.getProvider().getGroup();
}
String version = (sb.getVersion() == null) ? "" : sb.getVersion();
if (sb.getVersion() == null && sb.getProvider() != null && sb.getProvider().getVersion() != null) {
version = sb.getProvider().getVersion();
}
String serviceKey = serviceClass;
if (!"".equals(group) && !"".equals(version)) {
serviceKey += ":" + group + ":" + version;
} else if (!"".equals(group) && "".equals(version)) {
serviceKey += ":" + group;
} else if ("".equals(group) && !"".equals(version)) {
serviceKey += ":none:" + version;
}
if (list.containsKey(serviceKey)) {
return;
}
DubboServiceProfileInfo dspi = new DubboServiceProfileInfo();
String dbAppId = sb.getApplication().getName();
if (sb.getApplication().getVersion() != null) {
dbAppId += "-" + sb.getApplication().getVersion();
}
dspi.setAppId(appId);
dspi.setDbAppId(dbAppId);
dspi.setServiceClass(serviceClass);
dspi.setServiceImplClass(serviceImplClass);
dspi.setGroup(group);
dspi.setVersion(version);
@SuppressWarnings("unchecked") List<URL> urlList = sb.getExportedUrls();
if (urlList != null) {
for (URL url : urlList) {
DubboServiceProfileInfo.Protocol pro = new DubboServiceProfileInfo.Protocol();
pro.setPort(url.getPort());
pro.setpName(url.getProtocol());
int pathLength = url.getPath().length();
// 长度加1为了去除反斜杠/
int interfaceLength = url.getServiceInterface().length() + 1;
String contextpath = null;
if (pathLength > interfaceLength + 1) {
contextpath = url.getPath().substring(0, pathLength - interfaceLength);
}
pro.setContextpath(contextpath);
pro.setCharset(url.getParameter("charset"));
// dubbo当前默认的序列化方式为hessian2,不知道日后会不会变,故此处不进行默认赋值
pro.setSerialization(url.getParameter("serialization"));
dspi.addProtocol(pro);
}
}
list.put(serviceKey, dspi);
}
use of com.creditease.uav.profiling.handlers.dubbo.DubboServiceProfileInfo in project uavstack by uavorg.
the class DubboProfileHandler method isDubboServiceImplCls.
/**
* check if the class is a dubboService's impl class.
*/
@SuppressWarnings("unchecked")
public static boolean isDubboServiceImplCls(String clsName, ProfileContext context) {
InterceptContext ic = context.get(InterceptContext.class);
Map<String, DubboServiceProfileInfo> list = (Map<String, DubboServiceProfileInfo>) ic.get(HookConstants.DUBBO_PROFILE_LIST);
if (list == null) {
return false;
}
for (DubboServiceProfileInfo dspi : list.values()) {
if (clsName.equals(dspi.getServiceImplClass())) {
return true;
}
}
return false;
}
use of com.creditease.uav.profiling.handlers.dubbo.DubboServiceProfileInfo in project uavstack by uavorg.
the class DubboProfileHandler method doProfiling.
@SuppressWarnings("unchecked")
@Override
public void doProfiling(ProfileElement elem, ProfileContext context) {
UAVServer.ServerVendor sv = (UAVServer.ServerVendor) UAVServer.instance().getServerInfo(CaptureConstants.INFO_APPSERVER_VENDOR);
// only support JEE Application, not support MSCP Application
if (sv == UAVServer.ServerVendor.MSCP) {
return;
}
if (!ProfileConstants.PROELEM_COMPONENT.equals(elem.getElemId())) {
return;
}
InterceptContext ic = context.get(InterceptContext.class);
if (ic == null) {
this.logger.warn("Profile:Annotation FAILs as No InterceptContext available", null);
return;
}
/**
* 1.get webappclassloader
*/
ClassLoader webappclsLoader = (ClassLoader) ic.get(InterceptConstants.WEBAPPLOADER);
if (null == webappclsLoader) {
this.logger.warn("Profile:JARS FAILs as No webappclsLoader available", null);
return;
}
Map<String, DubboServiceProfileInfo> list = (Map<String, DubboServiceProfileInfo>) ic.get(HookConstants.DUBBO_PROFILE_LIST);
if (list == null) {
return;
}
// set the instance id = simple name of the annotation class
ProfileElementInstance inst = elem.getInstance("com.alibaba.dubbo.config.spring.ServiceBean");
for (String servicekey : list.keySet()) {
DubboServiceProfileInfo dspi = list.get(servicekey);
Map<String, Object> info = new LinkedHashMap<String, Object>();
// get service class & dubbo application id
String serviceClass = dspi.getServiceClass();
info.put("dubboAppId", dspi.getDbAppId());
info.put("group", dspi.getGroup());
info.put("version", dspi.getVersion());
info.put("servcls", serviceClass);
info.put("servimplcls", dspi.getServiceImplClass());
// get protocols
Map<String, Object> protocols = new LinkedHashMap<String, Object>();
info.put("protocols", protocols);
for (DubboServiceProfileInfo.Protocol pro : dspi.getProtocols()) {
Map<String, Object> pAttrs = new LinkedHashMap<String, Object>();
addProtocolAttr(pAttrs, "port", pro.getPort());
addProtocolAttr(pAttrs, "path", pro.getContextpath());
addProtocolAttr(pAttrs, "ser", pro.getSerialization());
addProtocolAttr(pAttrs, "char", pro.getCharset());
protocols.put(pro.getpName(), pAttrs);
}
// get methods
try {
Class<?> serviceClassI = webappclsLoader.loadClass(serviceClass);
ComponentProfileHandler.getMethodInfo(serviceClassI, info);
} catch (ClassNotFoundException e) {
continue;
}
inst.setValue(servicekey, info);
}
}
Aggregations