Merge pull request #64 from emeroad/master

fix indent tab to space
This commit is contained in:
Woonduk Kang
2015-01-02 20:52:38 +09:00
427 changed files with 14796 additions and 14796 deletions
@@ -25,25 +25,25 @@ import java.util.logging.Logger;
*/
public class LoggingInterceptor implements StaticAroundInterceptor, SimpleAroundInterceptor {
private final Logger logger;
private final Logger logger;
public LoggingInterceptor(String loggerName) {
this.logger = Logger.getLogger(loggerName);
}
public LoggingInterceptor(String loggerName) {
this.logger = Logger.getLogger(loggerName);
}
@Override
public void before(Object target, String className, String methodName, String parameterDescription, Object[] args) {
if (logger.isLoggable(Level.FINE)) {
logger.fine("before " + defaultString(target) + " " + className + "." + methodName + parameterDescription + " args:" + Arrays.toString(args));
}
}
@Override
public void before(Object target, String className, String methodName, String parameterDescription, Object[] args) {
if (logger.isLoggable(Level.FINE)) {
logger.fine("before " + defaultString(target) + " " + className + "." + methodName + parameterDescription + " args:" + Arrays.toString(args));
}
}
@Override
public void after(Object target, String className, String methodName, String parameterDescription, Object[] args, Object result, Throwable throwable) {
if (logger.isLoggable(Level.FINE)) {
logger.fine("after " + defaultString(target) + " " + className + "." + methodName + parameterDescription + " args:" + Arrays.toString(args) + " result:" + result + " Throwable:" + throwable);
}
}
@Override
public void after(Object target, String className, String methodName, String parameterDescription, Object[] args, Object result, Throwable throwable) {
if (logger.isLoggable(Level.FINE)) {
logger.fine("after " + defaultString(target) + " " + className + "." + methodName + parameterDescription + " args:" + Arrays.toString(args) + " result:" + result + " Throwable:" + throwable);
}
}
@Override
public void before(Object target, Object[] args) {
@@ -25,53 +25,53 @@ import java.util.List;
*/
public class ExcludeUrlFilter implements Filter<String> {
private final List<String> excludeUrlList;
private final List<String> excludeUrlList;
public ExcludeUrlFilter(String excludeFormat) {
this(excludeFormat, ",");
}
public ExcludeUrlFilter(String excludeFormat) {
this(excludeFormat, ",");
}
public ExcludeUrlFilter(String excludeFormat, String separator) {
if (isEmpty(excludeFormat)) {
this.excludeUrlList = Collections.emptyList();
return;
}
final String[] split = excludeFormat.split(separator);
final List<String> buildList = new ArrayList<String>();
for (String value : split) {
if (isEmpty(value)) {
continue;
}
value = value.trim();
if (value.isEmpty()) {
continue;
}
buildList.add(value);
}
public ExcludeUrlFilter(String excludeFormat, String separator) {
if (isEmpty(excludeFormat)) {
this.excludeUrlList = Collections.emptyList();
return;
}
final String[] split = excludeFormat.split(separator);
final List<String> buildList = new ArrayList<String>();
for (String value : split) {
if (isEmpty(value)) {
continue;
}
value = value.trim();
if (value.isEmpty()) {
continue;
}
buildList.add(value);
}
this.excludeUrlList = buildList;
}
this.excludeUrlList = buildList;
}
private boolean isEmpty(String string) {
return string == null || string.isEmpty();
}
private boolean isEmpty(String string) {
return string == null || string.isEmpty();
}
@Override
public boolean filter(String requestURI) {
for (String excludeUrl : this.excludeUrlList) {
if (excludeUrl.equals(requestURI)) {
return FILTERED;
}
}
return false;
}
@Override
public boolean filter(String requestURI) {
for (String excludeUrl : this.excludeUrlList) {
if (excludeUrl.equals(requestURI)) {
return FILTERED;
}
}
return false;
}
@Override
public String toString() {
final StringBuilder sb = new StringBuilder("ExcludeUrlFilter{");
sb.append("excludeUrlList=").append(excludeUrlList);
sb.append('}');
return sb.toString();
}
@Override
public String toString() {
final StringBuilder sb = new StringBuilder("ExcludeUrlFilter{");
sb.append("excludeUrlList=").append(excludeUrlList);
sb.append('}');
return sb.toString();
}
}
@@ -20,7 +20,7 @@ package com.navercorp.pinpoint.bootstrap.config;
* @author emeroad
*/
public interface Filter<T> {
public static final boolean FILTERED = true;
public static final boolean FILTERED = true;
boolean filter(T value);
boolean filter(T value);
}
@@ -26,135 +26,135 @@ import com.navercorp.pinpoint.bootstrap.util.SimpleSamplerFactory;
*/
public class HttpDumpConfig {
public static HttpDumpConfig getDefault() {
HttpDumpConfig config = new HttpDumpConfig();
public static HttpDumpConfig getDefault() {
HttpDumpConfig config = new HttpDumpConfig();
config.setDumpCookie(false);
config.setCookieDumpType(DumpType.EXCEPTION);
config.setCookieSampler(SimpleSamplerFactory.createSampler(false, 1));
config.setCookieDumpSize(128);
config.setDumpCookie(false);
config.setCookieDumpType(DumpType.EXCEPTION);
config.setCookieSampler(SimpleSamplerFactory.createSampler(false, 1));
config.setCookieDumpSize(128);
config.setDumpEntity(false);
config.setEntityDumpType(DumpType.EXCEPTION);
config.setEntitySampler(SimpleSamplerFactory.createSampler(false, 1));
config.setEntityDumpSize(128);
config.setDumpEntity(false);
config.setEntityDumpType(DumpType.EXCEPTION);
config.setEntitySampler(SimpleSamplerFactory.createSampler(false, 1));
config.setEntityDumpSize(128);
config.setDumpParam(false);
config.setParamDumpType(DumpType.EXCEPTION);
config.setParamSampler(SimpleSamplerFactory.createSampler(false, 1));
config.setParamDumpSize(128);
config.setDumpParam(false);
config.setParamDumpType(DumpType.EXCEPTION);
config.setParamSampler(SimpleSamplerFactory.createSampler(false, 1));
config.setParamDumpSize(128);
return config;
}
return config;
}
private boolean dumpCookie = false;
private DumpType cookieDumpType = DumpType.EXCEPTION;
private SimpleSampler cookieSampler;
private int cookieDumpSize;
private boolean dumpCookie = false;
private DumpType cookieDumpType = DumpType.EXCEPTION;
private SimpleSampler cookieSampler;
private int cookieDumpSize;
private boolean dumpEntity;
private DumpType entityDumpType;
private SimpleSampler entitySampler;
private int entityDumpSize;
private boolean dumpEntity;
private DumpType entityDumpType;
private SimpleSampler entitySampler;
private int entityDumpSize;
private boolean dumpParam;
private DumpType paramDumpType;
private SimpleSampler paramSampler;
private int paramDumpSize;
private boolean dumpParam;
private DumpType paramDumpType;
private SimpleSampler paramSampler;
private int paramDumpSize;
public boolean isDumpCookie() {
return dumpCookie;
}
public boolean isDumpCookie() {
return dumpCookie;
}
public void setDumpCookie(boolean dumpCookie) {
this.dumpCookie = dumpCookie;
}
public void setDumpCookie(boolean dumpCookie) {
this.dumpCookie = dumpCookie;
}
public DumpType getCookieDumpType() {
return cookieDumpType;
}
public DumpType getCookieDumpType() {
return cookieDumpType;
}
public void setCookieDumpType(DumpType cookieDumpType) {
this.cookieDumpType = cookieDumpType;
}
public void setCookieDumpType(DumpType cookieDumpType) {
this.cookieDumpType = cookieDumpType;
}
public SimpleSampler getCookieSampler() {
return cookieSampler;
}
public SimpleSampler getCookieSampler() {
return cookieSampler;
}
public void setCookieSampler(SimpleSampler cookieSampler) {
this.cookieSampler = cookieSampler;
}
public void setCookieSampler(SimpleSampler cookieSampler) {
this.cookieSampler = cookieSampler;
}
public int getCookieDumpSize() {
return cookieDumpSize;
}
public int getCookieDumpSize() {
return cookieDumpSize;
}
public void setCookieDumpSize(int cookieDumpSize) {
this.cookieDumpSize = cookieDumpSize;
}
public void setCookieDumpSize(int cookieDumpSize) {
this.cookieDumpSize = cookieDumpSize;
}
public boolean isDumpEntity() {
return dumpEntity;
}
public boolean isDumpEntity() {
return dumpEntity;
}
public void setDumpEntity(boolean dumpEntity) {
this.dumpEntity = dumpEntity;
}
public void setDumpEntity(boolean dumpEntity) {
this.dumpEntity = dumpEntity;
}
public DumpType getEntityDumpType() {
return entityDumpType;
}
public DumpType getEntityDumpType() {
return entityDumpType;
}
public void setEntityDumpType(DumpType entityDumpType) {
this.entityDumpType = entityDumpType;
}
public void setEntityDumpType(DumpType entityDumpType) {
this.entityDumpType = entityDumpType;
}
public SimpleSampler getEntitySampler() {
return entitySampler;
}
public SimpleSampler getEntitySampler() {
return entitySampler;
}
public void setEntitySampler(SimpleSampler entitySampler) {
this.entitySampler = entitySampler;
}
public void setEntitySampler(SimpleSampler entitySampler) {
this.entitySampler = entitySampler;
}
public int getEntityDumpSize() {
return entityDumpSize;
}
public int getEntityDumpSize() {
return entityDumpSize;
}
public void setEntityDumpSize(int entityDumpSize) {
this.entityDumpSize = entityDumpSize;
}
public void setEntityDumpSize(int entityDumpSize) {
this.entityDumpSize = entityDumpSize;
}
public boolean isDumpParam() {
return dumpParam;
}
public boolean isDumpParam() {
return dumpParam;
}
public void setDumpParam(boolean dumpParam) {
this.dumpParam = dumpParam;
}
public void setDumpParam(boolean dumpParam) {
this.dumpParam = dumpParam;
}
public DumpType getParamDumpType() {
return paramDumpType;
}
public DumpType getParamDumpType() {
return paramDumpType;
}
public void setParamDumpType(DumpType paramDumpType) {
this.paramDumpType = paramDumpType;
}
public void setParamDumpType(DumpType paramDumpType) {
this.paramDumpType = paramDumpType;
}
public SimpleSampler getParamSampler() {
return paramSampler;
}
public SimpleSampler getParamSampler() {
return paramSampler;
}
public void setParamSampler(SimpleSampler paramSampler) {
this.paramSampler = paramSampler;
}
public void setParamSampler(SimpleSampler paramSampler) {
this.paramSampler = paramSampler;
}
public int getParamDumpSize() {
return paramDumpSize;
}
public int getParamDumpSize() {
return paramDumpSize;
}
public void setParamDumpSize(int paramDumpSize) {
this.paramDumpSize = paramDumpSize;
}
public void setParamDumpSize(int paramDumpSize) {
this.paramDumpSize = paramDumpSize;
}
}
@@ -24,52 +24,52 @@ import java.util.Set;
*/
public class ProfilableClassFilter implements Filter<String> {
private final Set<String> profileInclude = new HashSet<String>();
private final Set<String> profileIncludeSub = new HashSet<String>();
private final Set<String> profileInclude = new HashSet<String>();
private final Set<String> profileIncludeSub = new HashSet<String>();
public ProfilableClassFilter(String profilableClass) {
if (profilableClass == null || profilableClass.isEmpty()) {
return;
}
String[] className = profilableClass.split(",");
for (String str : className) {
if (str.endsWith(".*")) {
this.profileIncludeSub.add(str.substring(0, str.length() - 2).replace('.', '/') + "/");
} else {
String replace = str.trim().replace('.', '/');
this.profileInclude.add(replace);
}
}
}
public ProfilableClassFilter(String profilableClass) {
if (profilableClass == null || profilableClass.isEmpty()) {
return;
}
String[] className = profilableClass.split(",");
for (String str : className) {
if (str.endsWith(".*")) {
this.profileIncludeSub.add(str.substring(0, str.length() - 2).replace('.', '/') + "/");
} else {
String replace = str.trim().replace('.', '/');
this.profileInclude.add(replace);
}
}
}
/**
* TODO remove this. Added this method to test the "call stack view" on a test server
*
* @param className
* @return
*/
@Override
public boolean filter(String className) {
if (profileInclude.contains(className)) {
return true;
} else {
final String packageName = className.substring(0, className.lastIndexOf("/") + 1);
for (String pkg : profileIncludeSub) {
if (packageName.startsWith(pkg)) {
return true;
}
}
}
return false;
}
/**
* TODO remove this. Added this method to test the "call stack view" on a test server
*
* @param className
* @return
*/
@Override
public boolean filter(String className) {
if (profileInclude.contains(className)) {
return true;
} else {
final String packageName = className.substring(0, className.lastIndexOf("/") + 1);
for (String pkg : profileIncludeSub) {
if (packageName.startsWith(pkg)) {
return true;
}
}
}
return false;
}
@Override
public String toString() {
final StringBuilder sb = new StringBuilder("ProfilableClassFilter{");
sb.append("profileInclude=").append(profileInclude);
sb.append(", profileIncludeSub=").append(profileIncludeSub);
sb.append('}');
return sb.toString();
}
@Override
public String toString() {
final StringBuilder sb = new StringBuilder("ProfilableClassFilter{");
sb.append("profileInclude=").append(profileInclude);
sb.append(", profileIncludeSub=").append(profileIncludeSub);
sb.append('}');
return sb.toString();
}
}
@@ -20,8 +20,8 @@ package com.navercorp.pinpoint.bootstrap.config;
* @author emeroad
*/
public class SkipFilter<T> implements Filter<T> {
@Override
public boolean filter(T value) {
return false;
}
@Override
public boolean filter(T value) {
return false;
}
}
@@ -28,78 +28,78 @@ import java.util.Map;
*/
public enum Header {
HTTP_TRACE_ID("Pinpoint-TraceID"),
HTTP_SPAN_ID("Pinpoint-SpanID"),
HTTP_PARENT_SPAN_ID("Pinpoint-pSpanID"),
HTTP_SAMPLED("Pinpoint-Sampled"),
HTTP_FLAGS("Pinpoint-Flags"),
HTTP_PARENT_APPLICATION_NAME("Pinpoint-pAppName"),
HTTP_PARENT_APPLICATION_TYPE("Pinpoint-pAppType");
HTTP_TRACE_ID("Pinpoint-TraceID"),
HTTP_SPAN_ID("Pinpoint-SpanID"),
HTTP_PARENT_SPAN_ID("Pinpoint-pSpanID"),
HTTP_SAMPLED("Pinpoint-Sampled"),
HTTP_FLAGS("Pinpoint-Flags"),
HTTP_PARENT_APPLICATION_NAME("Pinpoint-pAppName"),
HTTP_PARENT_APPLICATION_TYPE("Pinpoint-pAppType");
private String name;
private String name;
Header(String name) {
this.name = name;
}
Header(String name) {
this.name = name;
}
public String toString() {
return name;
}
public String toString() {
return name;
}
private static final Map<String, Header> NAME_SET = createMap();
private static final Map<String, Header> NAME_SET = createMap();
private static Map<String, Header> createMap() {
Header[] headerList = values();
Map<String, Header> map = new HashMap<String, Header>();
for (Header header : headerList) {
map.put(header.name, header);
}
return map;
}
private static Map<String, Header> createMap() {
Header[] headerList = values();
Map<String, Header> map = new HashMap<String, Header>();
for (Header header : headerList) {
map.put(header.name, header);
}
return map;
}
public static Header getHeader(String name) {
if (name == null) {
return null;
}
if (!startWithPinpointHeader(name)) {
return null;
}
return NAME_SET.get(name);
}
public static Header getHeader(String name) {
if (name == null) {
return null;
}
if (!startWithPinpointHeader(name)) {
return null;
}
return NAME_SET.get(name);
}
public static boolean hasHeader(String name) {
return getHeader(name) != null;
}
public static boolean hasHeader(String name) {
return getHeader(name) != null;
}
public static Enumeration getHeaders(String name) {
if (name == null) {
return null;
}
final Header header = getHeader(name);
if (header == null) {
return null;
}
// if pinpoint header
return new EmptyEnumeration();
}
public static Enumeration getHeaders(String name) {
if (name == null) {
return null;
}
final Header header = getHeader(name);
if (header == null) {
return null;
}
// if pinpoint header
return new EmptyEnumeration();
}
public static Enumeration filteredHeaderNames(final Enumeration enumeration) {
return new DelegateEnumeration(enumeration, FILTER);
}
public static Enumeration filteredHeaderNames(final Enumeration enumeration) {
return new DelegateEnumeration(enumeration, FILTER);
}
private static DelegateEnumeration.Filter FILTER = new DelegateEnumeration.Filter() {
@Override
public boolean filter(Object o) {
if (o instanceof String) {
return hasHeader((String )o);
}
return false;
}
};
private static DelegateEnumeration.Filter FILTER = new DelegateEnumeration.Filter() {
@Override
public boolean filter(Object o) {
if (o instanceof String) {
return hasHeader((String )o);
}
return false;
}
};
private static boolean startWithPinpointHeader(String name) {
return name.startsWith("Pinpoint-");
}
private static boolean startWithPinpointHeader(String name) {
return name.startsWith("Pinpoint-");
}
}
@@ -22,20 +22,20 @@ package com.navercorp.pinpoint.bootstrap.instrument;
*/
public class InstrumentException extends Exception {
private static final long serialVersionUID = 7594176009977030312L;
private static final long serialVersionUID = 7594176009977030312L;
public InstrumentException() {
}
public InstrumentException() {
}
public InstrumentException(String message) {
super(message);
}
public InstrumentException(String message) {
super(message);
}
public InstrumentException(String message, Throwable cause) {
super(message, cause);
}
public InstrumentException(String message, Throwable cause) {
super(message, cause);
}
public InstrumentException(Throwable cause) {
super(cause);
}
public InstrumentException(Throwable cause) {
super(cause);
}
}
@@ -22,9 +22,9 @@ package com.navercorp.pinpoint.bootstrap.instrument;
*/
public class NotFoundInstrumentException extends InstrumentException {
private static final long serialVersionUID = -9079014055408569735L;
private static final long serialVersionUID = -9079014055408569735L;
public NotFoundInstrumentException() {
public NotFoundInstrumentException() {
}
public NotFoundInstrumentException(String message) {
@@ -20,5 +20,5 @@ package com.navercorp.pinpoint.bootstrap.instrument;
* @author emeroad
*/
public enum Type {
around(), before(), after()
around(), before(), after()
}
@@ -20,23 +20,23 @@ package com.navercorp.pinpoint.bootstrap.interceptor;
* @author emeroad
*/
public interface MethodDescriptor {
String getMethodName();
String getMethodName();
String getClassName();
String getClassName();
String[] getParameterTypes();
String[] getParameterTypes();
String[] getParameterVariableName();
String[] getParameterVariableName();
String getParameterDescriptor();
String getParameterDescriptor();
int getLineNumber();
int getLineNumber();
String getFullName();
String getFullName();
void setApiId(int apiId);
void setApiId(int apiId);
int getApiId();
int getApiId();
String getApiDescriptor();
String getApiDescriptor();
}
@@ -34,17 +34,17 @@ public final class InterceptorUtils {
public static String exceptionToString(Throwable ex) {
if (ex != null) {
StringBuilder sb = new StringBuilder(128);
sb.append(ex.toString()).append("\n");
if (ex != null) {
StringBuilder sb = new StringBuilder(128);
sb.append(ex.toString()).append("\n");
Writer writer = new StringWriter();
PrintWriter printWriter = new PrintWriter(writer);
Writer writer = new StringWriter();
PrintWriter printWriter = new PrintWriter(writer);
ex.printStackTrace(printWriter);
sb.append(writer.toString());
sb.append(writer.toString());
return sb.toString();
}
return null;
}
return sb.toString();
}
return null;
}
}
@@ -29,26 +29,26 @@ import org.junit.Test;
*/
public class ValidIdCheckerTest {
private final Pattern p = Pattern.compile("[^a-zA-Z0-9._(\\-)]");
private final Pattern p = Pattern.compile("[^a-zA-Z0-9._(\\-)]");
@Test
public void checkValidId() {
Assert.assertFalse(p.matcher("PINPOINT123").find());
Assert.assertFalse(p.matcher("P1NPOINT").find());
Assert.assertFalse(p.matcher("1PNPOINT").find());
Assert.assertFalse(p.matcher("P1NPOINT.DEV").find());
Assert.assertFalse(p.matcher("P1NPOINT..DEV").find());
Assert.assertFalse(p.matcher("P1N.POINT.DEV").find());
Assert.assertFalse(p.matcher("P1NPOINT-DEV").find());
Assert.assertFalse(p.matcher("P1NPOINT_DEV").find());
Assert.assertFalse(p.matcher("P1N_POINT_DEV").find());
}
@Test
public void checkValidId() {
Assert.assertFalse(p.matcher("PINPOINT123").find());
Assert.assertFalse(p.matcher("P1NPOINT").find());
Assert.assertFalse(p.matcher("1PNPOINT").find());
Assert.assertFalse(p.matcher("P1NPOINT.DEV").find());
Assert.assertFalse(p.matcher("P1NPOINT..DEV").find());
Assert.assertFalse(p.matcher("P1N.POINT.DEV").find());
Assert.assertFalse(p.matcher("P1NPOINT-DEV").find());
Assert.assertFalse(p.matcher("P1NPOINT_DEV").find());
Assert.assertFalse(p.matcher("P1N_POINT_DEV").find());
}
@Test
public void checkInvalidId() {
Assert.assertTrue(p.matcher("P1NPOINT가").find()); //include Korean character for test
Assert.assertTrue(p.matcher("P1NPOINT ").find());
Assert.assertTrue(p.matcher("P1NPOINT+").find());
Assert.assertTrue(p.matcher("PINPO+INT").find());
}
@Test
public void checkInvalidId() {
Assert.assertTrue(p.matcher("P1NPOINT가").find()); //include Korean character for test
Assert.assertTrue(p.matcher("P1NPOINT ").find());
Assert.assertTrue(p.matcher("P1NPOINT+").find());
Assert.assertTrue(p.matcher("PINPO+INT").find());
}
}
@@ -27,40 +27,40 @@ import static org.junit.Assert.*;
public class ExcludeUrlFilterTest {
@Test
public void testFilter() throws Exception {
Filter<String> filter = new ExcludeUrlFilter("/monitor/l7check.html, test/l4check.html");
@Test
public void testFilter() throws Exception {
Filter<String> filter = new ExcludeUrlFilter("/monitor/l7check.html, test/l4check.html");
assertFilter(filter);
}
assertFilter(filter);
}
@Test
public void testFilter_InvalidExcludeURL() throws Exception {
Filter<String> filter = new ExcludeUrlFilter("/monitor/l7check.html, test/l4check.html, ,,");
@Test
public void testFilter_InvalidExcludeURL() throws Exception {
Filter<String> filter = new ExcludeUrlFilter("/monitor/l7check.html, test/l4check.html, ,,");
assertFilter(filter);
}
assertFilter(filter);
}
@Test
public void testFilter_emptyExcludeURL() throws Exception {
Filter<String> filter = new ExcludeUrlFilter("");
@Test
public void testFilter_emptyExcludeURL() throws Exception {
Filter<String> filter = new ExcludeUrlFilter("");
Assert.assertFalse(filter.filter("/monitor/l7check.html"));
Assert.assertFalse(filter.filter("test/l4check.html"));
Assert.assertFalse(filter.filter("/monitor/l7check.html"));
Assert.assertFalse(filter.filter("test/l4check.html"));
Assert.assertFalse(filter.filter("test/"));
Assert.assertFalse(filter.filter("test/l4check.htm"));
}
Assert.assertFalse(filter.filter("test/"));
Assert.assertFalse(filter.filter("test/l4check.htm"));
}
private void assertFilter(Filter<String> filter) {
Assert.assertTrue(filter.filter("/monitor/l7check.html"));
Assert.assertTrue(filter.filter("test/l4check.html"));
private void assertFilter(Filter<String> filter) {
Assert.assertTrue(filter.filter("/monitor/l7check.html"));
Assert.assertTrue(filter.filter("test/l4check.html"));
Assert.assertFalse(filter.filter("test/"));
Assert.assertFalse(filter.filter("test/l4check.htm"));
}
Assert.assertFalse(filter.filter("test/"));
Assert.assertFalse(filter.filter("test/l4check.htm"));
}
@@ -26,34 +26,34 @@ import java.io.IOException;
public class ProfilableClassFilterTest {
@Test
public void testIsProfilableClassWithNoConfiguration() throws IOException {
ProfilableClassFilter filter = new ProfilableClassFilter("com.navercorp.pinpoint.testweb.controller.*,com.navercorp.pinpoint.testweb.MyClass");
@Test
public void testIsProfilableClassWithNoConfiguration() throws IOException {
ProfilableClassFilter filter = new ProfilableClassFilter("com.navercorp.pinpoint.testweb.controller.*,com.navercorp.pinpoint.testweb.MyClass");
Assert.assertFalse(filter.filter("com/navercorp/pinpoint/testweb/controllers/MyController"));
Assert.assertFalse(filter.filter("net/spider/king/wang/Jjang"));
Assert.assertFalse(filter.filter("com/navercorp/pinpoint/testweb2/controller/MyController"));
Assert.assertFalse(filter.filter("com/navercorp/pinpoint/testweb2/MyClass"));
}
Assert.assertFalse(filter.filter("com/navercorp/pinpoint/testweb/controllers/MyController"));
Assert.assertFalse(filter.filter("net/spider/king/wang/Jjang"));
Assert.assertFalse(filter.filter("com/navercorp/pinpoint/testweb2/controller/MyController"));
Assert.assertFalse(filter.filter("com/navercorp/pinpoint/testweb2/MyClass"));
}
/**
* <pre>
* configuration is
* profile.package.include=com.navercorp.pinpoint.testweb.controller.*,com.navercorp.pinpoint.testweb.MyClass
* </pre>
*
* @throws IOException
*/
@Test
public void testIsProfilableClass() throws IOException {
ProfilableClassFilter filter = new ProfilableClassFilter("com.navercorp.pinpoint.testweb.controller.*,com.navercorp.pinpoint.testweb.MyClass");
/**
* <pre>
* configuration is
* profile.package.include=com.navercorp.pinpoint.testweb.controller.*,com.navercorp.pinpoint.testweb.MyClass
* </pre>
*
* @throws IOException
*/
@Test
public void testIsProfilableClass() throws IOException {
ProfilableClassFilter filter = new ProfilableClassFilter("com.navercorp.pinpoint.testweb.controller.*,com.navercorp.pinpoint.testweb.MyClass");
Assert.assertTrue(filter.filter("com/navercorp/pinpoint/testweb/MyClass"));
Assert.assertTrue(filter.filter("com/navercorp/pinpoint/testweb/controller/MyController"));
Assert.assertTrue(filter.filter("com/navercorp/pinpoint/testweb/controller/customcontroller/MyCustomController"));
Assert.assertTrue(filter.filter("com/navercorp/pinpoint/testweb/MyClass"));
Assert.assertTrue(filter.filter("com/navercorp/pinpoint/testweb/controller/MyController"));
Assert.assertTrue(filter.filter("com/navercorp/pinpoint/testweb/controller/customcontroller/MyCustomController"));
Assert.assertFalse(filter.filter("com/navercorp/pinpoint/testweb/MyUnknownClass"));
Assert.assertFalse(filter.filter("com/navercorp/pinpoint/testweb/controller2/MyController"));
}
Assert.assertFalse(filter.filter("com/navercorp/pinpoint/testweb/MyUnknownClass"));
Assert.assertFalse(filter.filter("com/navercorp/pinpoint/testweb/controller2/MyController"));
}
}
@@ -35,12 +35,12 @@ public class ProfilerConfigTest {
private final Logger logger = LoggerFactory.getLogger(this.getClass());
@Test
public void defaultProfilableClassFilter() throws IOException {
ProfilerConfig profilerConfig = new ProfilerConfig();
Filter<String> profilableClassFilter = profilerConfig.getProfilableClassFilter();
Assert.assertFalse(profilableClassFilter.filter("net/spider/king/wang/Jjang"));
}
@Test
public void defaultProfilableClassFilter() throws IOException {
ProfilerConfig profilerConfig = new ProfilerConfig();
Filter<String> profilableClassFilter = profilerConfig.getProfilableClassFilter();
Assert.assertFalse(profilableClassFilter.filter("net/spider/king/wang/Jjang"));
}
@Test
public void readProperty() throws IOException {
@@ -145,15 +145,15 @@ public class MockTraceContext implements TraceContext {
}
@Override
public void recordAcceptResponseTime(String parentApplicationName, short parentApplicationType, int elapsedTime) {
}
@Override
public void recordAcceptResponseTime(String parentApplicationName, short parentApplicationType, int elapsedTime) {
@Override
public void recordUserAcceptResponseTime(int elapsedTime) {
}
}
@Override
public void recordUserAcceptResponseTime(int elapsedTime) {
}
@Override
public ServerMetaDataHolder getServerMetaDataHolder() {
@@ -23,12 +23,12 @@ import com.navercorp.pinpoint.collector.config.CollectorConfiguration;
*/
public abstract class AbstractClusterService implements ClusterService {
protected final CollectorConfiguration config;
protected final ClusterPointRouter clusterPointRouter;
protected final CollectorConfiguration config;
protected final ClusterPointRouter clusterPointRouter;
public AbstractClusterService(CollectorConfiguration config, ClusterPointRouter clusterPointRouter) {
this.config = config;
this.clusterPointRouter = clusterPointRouter;
}
public AbstractClusterService(CollectorConfiguration config, ClusterPointRouter clusterPointRouter) {
this.config = config;
this.clusterPointRouter = clusterPointRouter;
}
}
@@ -32,64 +32,64 @@ import com.navercorp.pinpoint.rpc.util.MapUtils;
*/
public class ChannelContextClusterPoint implements TargetClusterPoint {
private final ChannelContext channelContext;
private final SocketChannel socketChannel;
private final ChannelContext channelContext;
private final SocketChannel socketChannel;
private final String applicationName;
private final String agentId;
private final long startTimeStamp;
private final String applicationName;
private final String agentId;
private final long startTimeStamp;
private final String version;
private final String version;
public ChannelContextClusterPoint(ChannelContext channelContext) {
AssertUtils.assertNotNull(channelContext, "ChannelContext may not be null.");
this.channelContext = channelContext;
public ChannelContextClusterPoint(ChannelContext channelContext) {
AssertUtils.assertNotNull(channelContext, "ChannelContext may not be null.");
this.channelContext = channelContext;
this.socketChannel = channelContext.getSocketChannel();
AssertUtils.assertNotNull(socketChannel, "SocketChannel may not be null.");
this.socketChannel = channelContext.getSocketChannel();
AssertUtils.assertNotNull(socketChannel, "SocketChannel may not be null.");
Map<Object, Object> properties = channelContext.getChannelProperties();
this.version = MapUtils.getString(properties, AgentHandshakePropertyType.VERSION.getName());
AssertUtils.assertTrue(!StringUtils.isBlank(version), "Version may not be null or empty.");
Map<Object, Object> properties = channelContext.getChannelProperties();
this.version = MapUtils.getString(properties, AgentHandshakePropertyType.VERSION.getName());
AssertUtils.assertTrue(!StringUtils.isBlank(version), "Version may not be null or empty.");
this.applicationName = MapUtils.getString(properties, AgentHandshakePropertyType.APPLICATION_NAME.getName());
AssertUtils.assertTrue(!StringUtils.isBlank(applicationName), "ApplicationName may not be null or empty.");
this.applicationName = MapUtils.getString(properties, AgentHandshakePropertyType.APPLICATION_NAME.getName());
AssertUtils.assertTrue(!StringUtils.isBlank(applicationName), "ApplicationName may not be null or empty.");
this.agentId = MapUtils.getString(properties, AgentHandshakePropertyType.AGENT_ID.getName());
AssertUtils.assertTrue(!StringUtils.isBlank(agentId), "AgentId may not be null or empty.");
this.agentId = MapUtils.getString(properties, AgentHandshakePropertyType.AGENT_ID.getName());
AssertUtils.assertTrue(!StringUtils.isBlank(agentId), "AgentId may not be null or empty.");
this.startTimeStamp = MapUtils.getLong(properties, AgentHandshakePropertyType.START_TIMESTAMP.getName());
AssertUtils.assertTrue(startTimeStamp > 0, "StartTimeStamp is must greater than zero.");
}
this.startTimeStamp = MapUtils.getLong(properties, AgentHandshakePropertyType.START_TIMESTAMP.getName());
AssertUtils.assertTrue(startTimeStamp > 0, "StartTimeStamp is must greater than zero.");
}
@Override
public void send(byte[] data) {
socketChannel.sendMessage(data);
}
@Override
public void send(byte[] data) {
socketChannel.sendMessage(data);
}
@Override
public Future request(byte[] data) {
return socketChannel.sendRequestMessage(data);
}
@Override
public Future request(byte[] data) {
return socketChannel.sendRequestMessage(data);
}
@Override
public String getApplicationName() {
return applicationName;
}
@Override
public String getApplicationName() {
return applicationName;
}
@Override
public String getAgentId() {
return agentId;
}
@Override
public String getAgentId() {
return agentId;
}
public long getStartTimeStamp() {
return startTimeStamp;
}
public long getStartTimeStamp() {
return startTimeStamp;
}
@Override
public String gerVersion() {
return version;
}
@Override
public String gerVersion() {
return version;
}
public ChannelContext getChannelContext() {
return channelContext;
@@ -112,21 +112,21 @@ public class ChannelContextClusterPoint implements TargetClusterPoint {
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof ChannelContextClusterPoint)) {
return false;
}
if (!(obj instanceof ChannelContextClusterPoint)) {
return false;
}
if (this.getChannelContext() == ((ChannelContextClusterPoint) obj).getChannelContext()) {
return true;
}
if (this.getChannelContext() == ((ChannelContextClusterPoint) obj).getChannelContext()) {
return true;
}
return false;
}
return false;
}
}
@@ -20,8 +20,8 @@ import java.net.InetSocketAddress;
public interface Cluster {
void connectPointIfAbsent(InetSocketAddress address);
void connectPointIfAbsent(InetSocketAddress address);
void disconnectPoint(InetSocketAddress address);
void disconnectPoint(InetSocketAddress address);
}
@@ -20,8 +20,8 @@ import com.navercorp.pinpoint.rpc.Future;
public interface ClusterPoint {
void send(byte[] data);
void send(byte[] data);
Future request(byte[] data);
Future request(byte[] data);
}
@@ -20,6 +20,6 @@ import java.util.List;
public interface ClusterPointLocator<T extends ClusterPoint> {
List<T> getClusterPointList();
List<T> getClusterPointList();
}
@@ -25,36 +25,36 @@ import org.slf4j.LoggerFactory;
public class ClusterPointRepository<T extends ClusterPoint> implements ClusterPointLocator<T> {
private final Logger logger = LoggerFactory.getLogger(this.getClass());
private final Logger logger = LoggerFactory.getLogger(this.getClass());
private final CopyOnWriteArrayList<T> clusterPointRepository = new CopyOnWriteArrayList<T>();
public boolean addClusterPoint(T clusterPoint) {
boolean isAdd = clusterPointRepository.addIfAbsent(clusterPoint);
if (!isAdd) {
logger.warn("Already registered ClusterPoint({}).", clusterPoint);
}
return isAdd;
}
public boolean removeClusterPoint(T clusterPoint) {
boolean isRemove = clusterPointRepository.remove(clusterPoint);
if (!isRemove) {
logger.warn("Already unregistered or not registered ClusterPoint({}).", clusterPoint);
}
return isRemove;
}
public List<T> getClusterPointList() {
return new ArrayList<T>(clusterPointRepository);
}
public void clear() {
}
private final CopyOnWriteArrayList<T> clusterPointRepository = new CopyOnWriteArrayList<T>();
public boolean addClusterPoint(T clusterPoint) {
boolean isAdd = clusterPointRepository.addIfAbsent(clusterPoint);
if (!isAdd) {
logger.warn("Already registered ClusterPoint({}).", clusterPoint);
}
return isAdd;
}
public boolean removeClusterPoint(T clusterPoint) {
boolean isRemove = clusterPointRepository.remove(clusterPoint);
if (!isRemove) {
logger.warn("Already unregistered or not registered ClusterPoint({}).", clusterPoint);
}
return isRemove;
}
public List<T> getClusterPointList() {
return new ArrayList<T>(clusterPointRepository);
}
public void clear() {
}
}
@@ -22,9 +22,9 @@ package com.navercorp.pinpoint.collector.cluster;
*/
public interface ClusterService {
void setUp() throws Exception;
void tearDown() throws Exception;
boolean isEnable();
void setUp() throws Exception;
void tearDown() throws Exception;
boolean isEnable();
}
@@ -18,12 +18,12 @@ package com.navercorp.pinpoint.collector.cluster;
public interface TargetClusterPoint extends ClusterPoint {
String getApplicationName();
String getApplicationName();
String getAgentId();
String getAgentId();
long getStartTimeStamp();
long getStartTimeStamp();
String gerVersion();
String gerVersion();
}
@@ -37,14 +37,14 @@ import com.navercorp.pinpoint.rpc.stream.ServerStreamChannelMessageListener;
*/
public class WebCluster implements Cluster {
private final Logger logger = LoggerFactory.getLogger(this.getClass());
private final PinpointSocketFactory factory;
private final Logger logger = LoggerFactory.getLogger(this.getClass());
private final PinpointSocketFactory factory;
private final Map<InetSocketAddress, PinpointSocket> clusterRepository = new HashMap<InetSocketAddress, PinpointSocket>();
private final Map<InetSocketAddress, PinpointSocket> clusterRepository = new HashMap<InetSocketAddress, PinpointSocket>();
public WebCluster(String id, MessageListener messageListener) {
this(id, messageListener, DisabledServerStreamChannelMessageListener.INSTANCE);
}
public WebCluster(String id, MessageListener messageListener) {
this(id, messageListener, DisabledServerStreamChannelMessageListener.INSTANCE);
}
public WebCluster(String id, MessageListener messageListener, ServerStreamChannelMessageListener serverStreamChannelMessageListener) {
this.factory = new PinpointSocketFactory();
@@ -58,68 +58,68 @@ public class WebCluster implements Cluster {
factory.setProperties(properties);
}
// Not safe for use by multiple threads.
public void connectPointIfAbsent(InetSocketAddress address) {
logger.info("localhost -> {} connect started.", address);
if (clusterRepository.containsKey(address)) {
logger.info("localhost -> {} already connected.", address);
return;
}
PinpointSocket socket = createPinpointSocket(address);
clusterRepository.put(address, socket);
logger.info("localhost -> {} connect completed.", address);
}
// Not safe for use by multiple threads.
public void connectPointIfAbsent(InetSocketAddress address) {
logger.info("localhost -> {} connect started.", address);
// Not safe for use by multiple threads.
public void disconnectPoint(InetSocketAddress address) {
logger.info("localhost -> {} disconnect started.", address);
if (clusterRepository.containsKey(address)) {
logger.info("localhost -> {} already connected.", address);
return;
}
PinpointSocket socket = clusterRepository.remove(address);
if (socket != null) {
socket.close();
logger.info("localhost -> {} disconnect completed.", address);
} else {
logger.info("localhost -> {} already disconnected.", address);
}
}
PinpointSocket socket = createPinpointSocket(address);
clusterRepository.put(address, socket);
private PinpointSocket createPinpointSocket(InetSocketAddress address) {
String host = address.getHostName();
int port = address.getPort();
logger.info("localhost -> {} connect completed.", address);
}
PinpointSocket socket = null;
for (int i = 0; i < 3; i++) {
try {
socket = factory.connect(host, port);
logger.info("tcp connect success:{}/{}", host, port);
return socket;
} catch (PinpointSocketException e) {
logger.warn("tcp connect fail:{}/{} try reconnect, retryCount:{}", host, port, i);
}
}
logger.warn("change background tcp connect mode {}/{} ", host, port);
socket = factory.scheduledConnect(host, port);
// Not safe for use by multiple threads.
public void disconnectPoint(InetSocketAddress address) {
logger.info("localhost -> {} disconnect started.", address);
return socket;
}
PinpointSocket socket = clusterRepository.remove(address);
if (socket != null) {
socket.close();
logger.info("localhost -> {} disconnect completed.", address);
} else {
logger.info("localhost -> {} already disconnected.", address);
}
}
public List<InetSocketAddress> getWebClusterList() {
return new ArrayList<InetSocketAddress>(clusterRepository.keySet());
}
public void close() {
for (PinpointSocket socket : clusterRepository.values()) {
if (socket != null) {
socket.close();
}
}
if (factory != null) {
factory.release();
}
}
private PinpointSocket createPinpointSocket(InetSocketAddress address) {
String host = address.getHostName();
int port = address.getPort();
PinpointSocket socket = null;
for (int i = 0; i < 3; i++) {
try {
socket = factory.connect(host, port);
logger.info("tcp connect success:{}/{}", host, port);
return socket;
} catch (PinpointSocketException e) {
logger.warn("tcp connect fail:{}/{} try reconnect, retryCount:{}", host, port, i);
}
}
logger.warn("change background tcp connect mode {}/{} ", host, port);
socket = factory.scheduledConnect(host, port);
return socket;
}
public List<InetSocketAddress> getWebClusterList() {
return new ArrayList<InetSocketAddress>(clusterRepository.keySet());
}
public void close() {
for (PinpointSocket socket : clusterRepository.values()) {
if (socket != null) {
socket.close();
}
}
if (factory != null) {
factory.release();
}
}
}
@@ -18,12 +18,12 @@ package com.navercorp.pinpoint.collector.cluster;
public enum WorkerState {
NEW,
INITIALIZING,
STARTED,
DESTROYING,
STOPPED,
ILLEGAL_STATE
NEW,
INITIALIZING,
STARTED,
DESTROYING,
STOPPED,
ILLEGAL_STATE
}
@@ -19,43 +19,43 @@ package com.navercorp.pinpoint.collector.cluster;
import java.util.concurrent.atomic.AtomicReference;
public class WorkerStateContext {
private final AtomicReference<WorkerState> currentState = new AtomicReference<WorkerState>();
public WorkerStateContext() {
currentState.set(WorkerState.NEW);
}
public WorkerState getCurrentState() {
return currentState.get();
}
public boolean changeStateInitializing() {
return currentState.compareAndSet(WorkerState.NEW, WorkerState.INITIALIZING);
}
public boolean changeStateStarted() {
return currentState.compareAndSet(WorkerState.INITIALIZING, WorkerState.STARTED);
}
private final AtomicReference<WorkerState> currentState = new AtomicReference<WorkerState>();
public boolean changeStateDestroying() {
return currentState.compareAndSet(WorkerState.STARTED, WorkerState.DESTROYING);
}
public WorkerStateContext() {
currentState.set(WorkerState.NEW);
}
public boolean changeStateStopped() {
return currentState.compareAndSet(WorkerState.DESTROYING, WorkerState.STOPPED);
}
public boolean changeStateIllegal() {
currentState.set(WorkerState.ILLEGAL_STATE);
return true;
}
public WorkerState getCurrentState() {
return currentState.get();
}
public boolean isStarted() {
if (currentState.get() == WorkerState.STARTED) {
return true;
} else {
return false;
}
}
public boolean changeStateInitializing() {
return currentState.compareAndSet(WorkerState.NEW, WorkerState.INITIALIZING);
}
public boolean changeStateStarted() {
return currentState.compareAndSet(WorkerState.INITIALIZING, WorkerState.STARTED);
}
public boolean changeStateDestroying() {
return currentState.compareAndSet(WorkerState.STARTED, WorkerState.DESTROYING);
}
public boolean changeStateStopped() {
return currentState.compareAndSet(WorkerState.DESTROYING, WorkerState.STOPPED);
}
public boolean changeStateIllegal() {
currentState.set(WorkerState.ILLEGAL_STATE);
return true;
}
public boolean isStarted() {
if (currentState.get() == WorkerState.STARTED) {
return true;
} else {
return false;
}
}
}
@@ -23,26 +23,26 @@ import org.slf4j.LoggerFactory;
public class DefaultRouteFilterChain<T extends RouteEvent> implements RouteFilterChain<T> {
private final Logger logger = LoggerFactory.getLogger(this.getClass());
private final CopyOnWriteArrayList<RouteFilter<T>> filterList = new CopyOnWriteArrayList<RouteFilter<T>>();
@Override
public void addLast(RouteFilter<T> filter) {
filterList.add(filter);
}
private final Logger logger = LoggerFactory.getLogger(this.getClass());
private final CopyOnWriteArrayList<RouteFilter<T>> filterList = new CopyOnWriteArrayList<RouteFilter<T>>();
@Override
public void addLast(RouteFilter<T> filter) {
filterList.add(filter);
}
@Override
public void doEvent(T event) {
for (RouteFilter<T> filter : filterList) {
try {
filter.doEvent(event);
} catch (Exception e) {
if (logger.isWarnEnabled()) {
logger.warn(filter.getClass().getSimpleName() + " filter occured exception. Error:" + e.getMessage() + ".", e);
}
}
}
}
@Override
public void doEvent(T event) {
for (RouteFilter<T> filter : filterList) {
try {
filter.doEvent(event);
} catch (Exception e) {
if (logger.isWarnEnabled()) {
logger.warn(filter.getClass().getSimpleName() + " filter occured exception. Error:" + e.getMessage() + ".", e);
}
}
}
}
}
@@ -31,64 +31,64 @@ import com.navercorp.pinpoint.thrift.io.TCommandTypeVersion;
*/
public class DefaultRouteHandler extends AbstractRouteHandler<RequestEvent> {
private final Logger logger = LoggerFactory.getLogger(this.getClass());
private final Logger logger = LoggerFactory.getLogger(this.getClass());
private final RouteFilterChain<RequestEvent> requestFilterChain;
private final RouteFilterChain<ResponseEvent> responseFilterChain;
private final RouteFilterChain<RequestEvent> requestFilterChain;
private final RouteFilterChain<ResponseEvent> responseFilterChain;
public DefaultRouteHandler(ClusterPointLocator<TargetClusterPoint> targetClusterPointLocator) {
super(targetClusterPointLocator);
public DefaultRouteHandler(ClusterPointLocator<TargetClusterPoint> targetClusterPointLocator) {
super(targetClusterPointLocator);
this.requestFilterChain = new DefaultRouteFilterChain<RequestEvent>();
this.responseFilterChain = new DefaultRouteFilterChain<ResponseEvent>();
}
this.requestFilterChain = new DefaultRouteFilterChain<RequestEvent>();
this.responseFilterChain = new DefaultRouteFilterChain<ResponseEvent>();
}
@Override
public void addRequestFilter(RouteFilter<RequestEvent> filter) {
this.requestFilterChain.addLast(filter);
}
@Override
public void addRequestFilter(RouteFilter<RequestEvent> filter) {
this.requestFilterChain.addLast(filter);
}
@Override
public void addResponseFilter(RouteFilter<ResponseEvent> filter) {
this.responseFilterChain.addLast(filter);
}
@Override
public void addResponseFilter(RouteFilter<ResponseEvent> filter) {
this.responseFilterChain.addLast(filter);
}
@Override
public RouteResult onRoute(RequestEvent event) {
requestFilterChain.doEvent(event);
@Override
public RouteResult onRoute(RequestEvent event) {
requestFilterChain.doEvent(event);
RouteResult routeResult = onRoute0(event);
RouteResult routeResult = onRoute0(event);
responseFilterChain.doEvent(new ResponseEvent(event, event.getRequestId(), routeResult));
responseFilterChain.doEvent(new ResponseEvent(event, event.getRequestId(), routeResult));
return routeResult;
}
return routeResult;
}
private RouteResult onRoute0(RequestEvent event) {
TBase requestObject = event.getRequestObject();
if (requestObject == null) {
return new RouteResult(RouteStatus.BAD_REQUEST);
}
private RouteResult onRoute0(RequestEvent event) {
TBase requestObject = event.getRequestObject();
if (requestObject == null) {
return new RouteResult(RouteStatus.BAD_REQUEST);
}
TargetClusterPoint clusterPoint = findClusterPoint(event.getDeliveryCommand());
if (clusterPoint == null) {
return new RouteResult(RouteStatus.NOT_FOUND);
}
TargetClusterPoint clusterPoint = findClusterPoint(event.getDeliveryCommand());
if (clusterPoint == null) {
return new RouteResult(RouteStatus.NOT_FOUND);
}
TCommandTypeVersion commandVersion = TCommandTypeVersion.getVersion(clusterPoint.gerVersion());
if (!commandVersion.isSupportCommand(requestObject)) {
return new RouteResult(RouteStatus.NOT_ACCEPTABLE);
}
TCommandTypeVersion commandVersion = TCommandTypeVersion.getVersion(clusterPoint.gerVersion());
if (!commandVersion.isSupportCommand(requestObject)) {
return new RouteResult(RouteStatus.NOT_ACCEPTABLE);
}
Future<ResponseMessage> future = clusterPoint.request(event.getDeliveryCommand().getPayload());
future.await();
ResponseMessage responseMessage = future.getResult();
Future<ResponseMessage> future = clusterPoint.request(event.getDeliveryCommand().getPayload());
future.await();
ResponseMessage responseMessage = future.getResult();
if (responseMessage == null) {
return new RouteResult(RouteStatus.AGENT_TIMEOUT);
}
if (responseMessage == null) {
return new RouteResult(RouteStatus.AGENT_TIMEOUT);
}
return new RouteResult(RouteStatus.OK, responseMessage);
}
return new RouteResult(RouteStatus.OK, responseMessage);
}
}
@@ -24,45 +24,45 @@ import org.slf4j.LoggerFactory;
*/
public class LoggingFilter {
private final Logger logger = LoggerFactory.getLogger(this.getClass());
private final Logger logger = LoggerFactory.getLogger(this.getClass());
class RequestFilter implements RouteFilter<RequestEvent> {
class RequestFilter implements RouteFilter<RequestEvent> {
@Override
public void doEvent(RequestEvent event) {
logger.warn("{} doEvent {}.", this.getClass().getSimpleName(), event);
}
@Override
public void doEvent(RequestEvent event) {
logger.warn("{} doEvent {}.", this.getClass().getSimpleName(), event);
}
}
class StreamCreateFilter implements RouteFilter<StreamEvent> {
}
class StreamCreateFilter implements RouteFilter<StreamEvent> {
@Override
public void doEvent(StreamEvent event) {
logger.warn("{} doEvent {}.", this.getClass().getSimpleName(), event);
}
}
class ResponseFilter implements RouteFilter<ResponseEvent> {
}
@Override
public void doEvent(ResponseEvent event) {
logger.warn("{} doEvent {}.", this.getClass().getSimpleName(), event);
}
class ResponseFilter implements RouteFilter<ResponseEvent> {
}
@Override
public void doEvent(ResponseEvent event) {
logger.warn("{} doEvent {}.", this.getClass().getSimpleName(), event);
}
public RequestFilter getRequestFilter() {
return new RequestFilter();
}
public StreamCreateFilter getStreamCreateFilter() {
return new StreamCreateFilter();
}
}
public ResponseFilter getResponseFilter() {
return new ResponseFilter();
}
public RequestFilter getRequestFilter() {
return new RequestFilter();
}
public StreamCreateFilter getStreamCreateFilter() {
return new StreamCreateFilter();
}
public ResponseFilter getResponseFilter() {
return new ResponseFilter();
}
}
@@ -27,29 +27,29 @@ public class ResponseEvent extends DefaultRouteEvent {
private final int requestId;
private final RouteResult routeResult;
private final RouteResult routeResult;
public ResponseEvent(RouteEvent routeEvent, int requestId, RouteResult routeResult) {
this(routeEvent.getDeliveryCommand(), routeEvent.getSourceChannel(), requestId, routeResult);
}
public ResponseEvent(RouteEvent routeEvent, int requestId, RouteResult routeResult) {
this(routeEvent.getDeliveryCommand(), routeEvent.getSourceChannel(), requestId, routeResult);
}
public ResponseEvent(TCommandTransfer deliveryCommand, Channel sourceChannel, int requestId, RouteResult routeResult) {
super(deliveryCommand, sourceChannel);
this.requestId = requestId;
this.routeResult = routeResult;
}
public ResponseEvent(TCommandTransfer deliveryCommand, Channel sourceChannel, int requestId, RouteResult routeResult) {
super(deliveryCommand, sourceChannel);
this.requestId = requestId;
this.routeResult = routeResult;
}
public int getRequestId() {
return requestId;
}
public RouteResult getRouteResult() {
return routeResult;
}
@Override
public String toString() {
return routeResult;
}
@Override
public String toString() {
final StringBuilder sb = new StringBuilder();
sb.append(this.getClass().getSimpleName());
sb.append("{");
@@ -62,6 +62,6 @@ public class ResponseEvent extends DefaultRouteEvent {
sb.append('}');
return sb.toString();
}
}
}
@@ -25,8 +25,8 @@ import com.navercorp.pinpoint.thrift.dto.command.TCommandTransfer;
*/
public interface RouteEvent {
TCommandTransfer getDeliveryCommand();
Channel getSourceChannel();
TCommandTransfer getDeliveryCommand();
Channel getSourceChannel();
}
@@ -18,6 +18,6 @@ package com.navercorp.pinpoint.collector.cluster.route;
public interface RouteFilter<T extends RouteEvent> {
void doEvent(T event);
void doEvent(T event);
}
@@ -18,8 +18,8 @@ package com.navercorp.pinpoint.collector.cluster.route;
public interface RouteFilterChain<T extends RouteEvent> {
void addLast(RouteFilter<T> filter);
void doEvent(T event);
void addLast(RouteFilter<T> filter);
void doEvent(T event);
}
@@ -22,10 +22,10 @@ package com.navercorp.pinpoint.collector.cluster.route;
*/
public interface RouteHandler<T extends RouteEvent> {
void addRequestFilter(RouteFilter<T> filter);
void addResponseFilter(RouteFilter<ResponseEvent> filter);
RouteResult onRoute(T event);
void addRequestFilter(RouteFilter<T> filter);
void addResponseFilter(RouteFilter<ResponseEvent> filter);
RouteResult onRoute(T event);
}
@@ -23,30 +23,30 @@ import com.navercorp.pinpoint.rpc.ResponseMessage;
*/
public class RouteResult {
private final RouteStatus status;
private final ResponseMessage responseMessage;
private final RouteStatus status;
private final ResponseMessage responseMessage;
public RouteResult(RouteStatus status) {
this(status, null);
}
public RouteResult(RouteStatus status) {
this(status, null);
}
public RouteResult(RouteStatus status, ResponseMessage responseMessage) {
this.status = status;
this.responseMessage = responseMessage;
}
public RouteResult(RouteStatus status, ResponseMessage responseMessage) {
this.status = status;
this.responseMessage = responseMessage;
}
public RouteStatus getStatus() {
return status;
}
public RouteStatus getStatus() {
return status;
}
public ResponseMessage getResponseMessage() {
return responseMessage;
}
public ResponseMessage getResponseMessage() {
return responseMessage;
}
@Override
public String toString() {
return status.toString();
}
@Override
public String toString() {
return status.toString();
}
}
@@ -21,41 +21,41 @@ package com.navercorp.pinpoint.collector.cluster.route;
*/
public enum RouteStatus {
OK(0, "OK"),
OK(0, "OK"),
BAD_REQUEST(400, "Bad Request"),
BAD_REQUEST(400, "Bad Request"),
NOT_FOUND(404, " Target Route Agent Not Found."),
NOT_FOUND(404, " Target Route Agent Not Found."),
NOT_ACCEPTABLE(406, "Target Route Agent Not Acceptable."),
NOT_ACCEPTABLE_UNKNOWN(450, "Target Route Agent Not Acceptable."),
NOT_ACCEPTABLE(406, "Target Route Agent Not Acceptable."),
NOT_ACCEPTABLE_UNKNOWN(450, "Target Route Agent Not Acceptable."),
NOT_ACCEPTABLE_COMMAND(451, "Target Route Agent Not Acceptable command."),
NOT_ACCEPTABLE_AGENT_TYPE(452, "Target Route Agent Not Acceptable agent type.."),
AGENT_TIMEOUT(504, "Target Route Agent Timeout"),
CLOSED(606, "Target Route Agent Closed.");
private final int value;
AGENT_TIMEOUT(504, "Target Route Agent Timeout"),
private final String reasonPhrase;
CLOSED(606, "Target Route Agent Closed.");
private RouteStatus(int value, String reasonPhrase) {
this.value = value;
this.reasonPhrase = reasonPhrase;
}
private final int value;
public int getValue() {
return value;
}
private final String reasonPhrase;
public String getReasonPhrase() {
return reasonPhrase;
}
@Override
public String toString() {
private RouteStatus(int value, String reasonPhrase) {
this.value = value;
this.reasonPhrase = reasonPhrase;
}
public int getValue() {
return value;
}
public String getReasonPhrase() {
return reasonPhrase;
}
@Override
public String toString() {
final StringBuilder sb = new StringBuilder();
sb.append(this.getClass().getSimpleName());
sb.append("{");
@@ -63,6 +63,6 @@ public enum RouteStatus {
sb.append("message=").append(getReasonPhrase());
sb.append('}');
return sb.toString();
}
}
}
@@ -43,212 +43,212 @@ import com.navercorp.pinpoint.collector.cluster.zookeeper.exception.UnknownExcep
*/
public class ZookeeperClient {
private final Logger logger = LoggerFactory.getLogger(this.getClass());
private final Logger logger = LoggerFactory.getLogger(this.getClass());
// Zookeeper clients are thread-safe
private final ZooKeeper zookeeper;
private final AtomicBoolean clientState = new AtomicBoolean(true);
private final ZookeeperEventWatcher watcher;
// Zookeeper clients are thread-safe
private final ZooKeeper zookeeper;
private final AtomicBoolean clientState = new AtomicBoolean(true);
public ZookeeperClient(String hostPort, int sessionTimeout, ZookeeperEventWatcher watcher) throws KeeperException, IOException, InterruptedException {
this.watcher = watcher;
zookeeper = new ZooKeeper(hostPort, sessionTimeout, this.watcher); // server
}
/**
* do not create the final node in the given path.
*
* @throws PinpointZookeeperException
* @throws InterruptedException
*/
public void createPath(String path) throws PinpointZookeeperException, InterruptedException {
createPath(path, false);
}
private final ZookeeperEventWatcher watcher;
public void createPath(String path, boolean createEndNode) throws PinpointZookeeperException, InterruptedException {
checkState();
public ZookeeperClient(String hostPort, int sessionTimeout, ZookeeperEventWatcher watcher) throws KeeperException, IOException, InterruptedException {
this.watcher = watcher;
zookeeper = new ZooKeeper(hostPort, sessionTimeout, this.watcher); // server
}
int pos = 1;
do {
pos = path.indexOf('/', pos + 1);
/**
* do not create the final node in the given path.
*
* @throws PinpointZookeeperException
* @throws InterruptedException
*/
public void createPath(String path) throws PinpointZookeeperException, InterruptedException {
createPath(path, false);
}
if (pos == -1) {
pos = path.length();
}
public void createPath(String path, boolean createEndNode) throws PinpointZookeeperException, InterruptedException {
checkState();
try {
if (pos == path.length()) {
if (!createEndNode) {
return;
}
}
String subPath = path.substring(0, pos);
if (zookeeper.exists(subPath, false) != null) {
continue;
}
int pos = 1;
do {
pos = path.indexOf('/', pos + 1);
zookeeper.create(subPath, new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
} catch (KeeperException exception) {
if (exception.code() != Code.NODEEXISTS) {
handleException(exception);
}
}
if (pos == -1) {
pos = path.length();
}
} while (pos < path.length());
}
try {
if (pos == path.length()) {
if (!createEndNode) {
return;
}
}
public String createNode(String znodePath, byte[] data) throws PinpointZookeeperException, InterruptedException {
checkState();
String subPath = path.substring(0, pos);
if (zookeeper.exists(subPath, false) != null) {
continue;
}
try {
if (zookeeper.exists(znodePath, false) != null) {
return znodePath;
}
zookeeper.create(subPath, new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
} catch (KeeperException exception) {
if (exception.code() != Code.NODEEXISTS) {
handleException(exception);
}
}
String pathName = zookeeper.create(znodePath, data, Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL);
return pathName;
} catch (KeeperException exception) {
handleException(exception);
}
return znodePath;
}
public byte[] getData(String path) throws PinpointZookeeperException, InterruptedException {
checkState();
} while (pos < path.length());
}
try {
return zookeeper.getData(path, false, null);
} catch (KeeperException exception) {
handleException(exception);
}
throw new UnknownException("UnknownException.");
}
public String createNode(String znodePath, byte[] data) throws PinpointZookeeperException, InterruptedException {
checkState();
public void setData(String path, byte[] data) throws PinpointZookeeperException, InterruptedException {
checkState();
try {
if (zookeeper.exists(znodePath, false) != null) {
return znodePath;
}
try {
if (zookeeper.exists(path, false) == null) {
return;
}
String pathName = zookeeper.create(znodePath, data, Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL);
return pathName;
} catch (KeeperException exception) {
handleException(exception);
}
return znodePath;
}
zookeeper.setData(path, data, -1);
} catch (KeeperException exception) {
handleException(exception);
}
}
public void delete(String path) throws PinpointZookeeperException, InterruptedException {
checkState();
public byte[] getData(String path) throws PinpointZookeeperException, InterruptedException {
checkState();
try {
zookeeper.delete(path, -1);
} catch (KeeperException exception) {
if (exception.code() != Code.NONODE) {
handleException(exception);
}
}
}
try {
return zookeeper.getData(path, false, null);
} catch (KeeperException exception) {
handleException(exception);
}
public boolean exists(String path) throws PinpointZookeeperException, InterruptedException {
checkState();
throw new UnknownException("UnknownException.");
}
try {
Stat stat = zookeeper.exists(path, false);
if (stat == null) {
return false;
}
} catch (KeeperException exception) {
if (exception.code() != Code.NODEEXISTS) {
handleException(exception);
}
}
return true;
}
public void setData(String path, byte[] data) throws PinpointZookeeperException, InterruptedException {
checkState();
private void checkState() throws PinpointZookeeperException {
if (!isConnected()) {
throw new ConnectionException("instance must be connected.");
}
}
try {
if (zookeeper.exists(path, false) == null) {
return;
}
public boolean isConnected() {
if (!watcher.isConnected() || !clientState.get()) {
return false;
}
return true;
}
public List<String> getChildrenNode(String path, boolean watch) throws PinpointZookeeperException, InterruptedException {
checkState();
zookeeper.setData(path, data, -1);
} catch (KeeperException exception) {
handleException(exception);
}
}
try {
List<String> childNodeList = zookeeper.getChildren(path, watch, null);
logger.info("ChildNode List = {}", childNodeList);
return childNodeList;
} catch (KeeperException exception) {
if (exception.code() != Code.NONODE) {
handleException(exception);
}
}
return Collections.emptyList();
}
// public byte[] getData(String path) throws KeeperException, InterruptedException {
// checkState();
public void delete(String path) throws PinpointZookeeperException, InterruptedException {
checkState();
try {
zookeeper.delete(path, -1);
} catch (KeeperException exception) {
if (exception.code() != Code.NONODE) {
handleException(exception);
}
}
}
public boolean exists(String path) throws PinpointZookeeperException, InterruptedException {
checkState();
try {
Stat stat = zookeeper.exists(path, false);
if (stat == null) {
return false;
}
} catch (KeeperException exception) {
if (exception.code() != Code.NODEEXISTS) {
handleException(exception);
}
}
return true;
}
private void checkState() throws PinpointZookeeperException {
if (!isConnected()) {
throw new ConnectionException("instance must be connected.");
}
}
public boolean isConnected() {
if (!watcher.isConnected() || !clientState.get()) {
return false;
}
return true;
}
public List<String> getChildrenNode(String path, boolean watch) throws PinpointZookeeperException, InterruptedException {
checkState();
try {
List<String> childNodeList = zookeeper.getChildren(path, watch, null);
logger.info("ChildNode List = {}", childNodeList);
return childNodeList;
} catch (KeeperException exception) {
if (exception.code() != Code.NONODE) {
handleException(exception);
}
}
return Collections.emptyList();
}
// public byte[] getData(String path) throws KeeperException, InterruptedException {
// checkState();
//
// return zookeeper.getData(path, false, null);
// }
// return zookeeper.getData(path, false, null);
// }
//
// public List<String> getChildrenNode(String path) throws KeeperException, InterruptedException {
// checkState();
// public List<String> getChildrenNode(String path) throws KeeperException, InterruptedException {
// checkState();
//
// List<String> childNodeList = zookeeper.getChildren(path, false);
// logger.info("ChildNode List = {}", childNodeList);
// return childNodeList;
// }
// List<String> childNodeList = zookeeper.getChildren(path, false);
// logger.info("ChildNode List = {}", childNodeList);
// return childNodeList;
// }
private void handleException(KeeperException keeperException) throws PinpointZookeeperException {
switch (keeperException.code()) {
case CONNECTIONLOSS:
case SESSIONEXPIRED:
throw new ConnectionException(keeperException.getMessage(), keeperException);
case AUTHFAILED:
case INVALIDACL:
case NOAUTH:
throw new AuthException(keeperException.getMessage(), keeperException);
case BADARGUMENTS:
case BADVERSION:
case NOCHILDRENFOREPHEMERALS:
case NOTEMPTY:
case NODEEXISTS:
throw new BadOperationException(keeperException.getMessage(), keeperException);
case NONODE:
throw new NoNodeException(keeperException.getMessage(), keeperException);
case OPERATIONTIMEOUT:
throw new TimeoutException(keeperException.getMessage(), keeperException);
default:
throw new UnknownException(keeperException.getMessage(), keeperException);
}
}
public void close() {
if (clientState.compareAndSet(true, false)) {
if (zookeeper != null) {
try {
zookeeper.close();
} catch (InterruptedException ignore) {
logger.info("Interrupted zookeeper.close(). Caused:" + ignore.getMessage(), ignore);
private void handleException(KeeperException keeperException) throws PinpointZookeeperException {
switch (keeperException.code()) {
case CONNECTIONLOSS:
case SESSIONEXPIRED:
throw new ConnectionException(keeperException.getMessage(), keeperException);
case AUTHFAILED:
case INVALIDACL:
case NOAUTH:
throw new AuthException(keeperException.getMessage(), keeperException);
case BADARGUMENTS:
case BADVERSION:
case NOCHILDRENFOREPHEMERALS:
case NOTEMPTY:
case NODEEXISTS:
throw new BadOperationException(keeperException.getMessage(), keeperException);
case NONODE:
throw new NoNodeException(keeperException.getMessage(), keeperException);
case OPERATIONTIMEOUT:
throw new TimeoutException(keeperException.getMessage(), keeperException);
default:
throw new UnknownException(keeperException.getMessage(), keeperException);
}
}
public void close() {
if (clientState.compareAndSet(true, false)) {
if (zookeeper != null) {
try {
zookeeper.close();
} catch (InterruptedException ignore) {
logger.info("Interrupted zookeeper.close(). Caused:" + ignore.getMessage(), ignore);
Thread.currentThread().interrupt();
}
}
}
}
}
}
}
}
}
@@ -46,187 +46,187 @@ import com.navercorp.pinpoint.rpc.server.SocketChannelStateChangeEventListener;
*/
public class ZookeeperClusterService extends AbstractClusterService {
private static final String PINPOINT_CLUSTER_PATH = "/pinpoint-cluster";
private static final String PINPOINT_WEB_CLUSTER_PATH = PINPOINT_CLUSTER_PATH + "/web";
private static final String PINPOINT_PROFILER_CLUSTER_PATH = PINPOINT_CLUSTER_PATH + "/profiler";
private static final String PINPOINT_CLUSTER_PATH = "/pinpoint-cluster";
private static final String PINPOINT_WEB_CLUSTER_PATH = PINPOINT_CLUSTER_PATH + "/web";
private static final String PINPOINT_PROFILER_CLUSTER_PATH = PINPOINT_CLUSTER_PATH + "/profiler";
private final Logger logger = LoggerFactory.getLogger(this.getClass());
private final Logger logger = LoggerFactory.getLogger(this.getClass());
// represented as pid@hostname (identifiers may overlap for services hosted on localhost if pids are identical)
// shouldn't be too big of a problem, but will change to MAC or IP if it becomes problematic.
private final String serverIdentifier = CollectorUtils.getServerIdentifier();
// represented as pid@hostname (identifiers may overlap for services hosted on localhost if pids are identical)
// shouldn't be too big of a problem, but will change to MAC or IP if it becomes problematic.
private final String serverIdentifier = CollectorUtils.getServerIdentifier();
private final WebCluster webCluster;
private final WorkerStateContext serviceState;
private final WebCluster webCluster;
private ZookeeperClient client;
private final WorkerStateContext serviceState;
// WebClusterManager checks Zookeeper for the Web data, and manages collector -> web connections.
private ZookeeperWebClusterManager webClusterManager;
// ProfilerClusterManager detects/manages profiler -> collector connections, and saves their information in Zookeeper.
private ZookeeperClient client;
// WebClusterManager checks Zookeeper for the Web data, and manages collector -> web connections.
private ZookeeperWebClusterManager webClusterManager;
// ProfilerClusterManager detects/manages profiler -> collector connections, and saves their information in Zookeeper.
private ZookeeperProfilerClusterManager profilerClusterManager;
public ZookeeperClusterService(CollectorConfiguration config, ClusterPointRouter clusterPointRouter) {
super(config, clusterPointRouter);
this.serviceState = new WorkerStateContext();
this.webCluster = new WebCluster(serverIdentifier, clusterPointRouter, clusterPointRouter);
}
public ZookeeperClusterService(CollectorConfiguration config, ClusterPointRouter clusterPointRouter) {
super(config, clusterPointRouter);
this.serviceState = new WorkerStateContext();
this.webCluster = new WebCluster(serverIdentifier, clusterPointRouter, clusterPointRouter);
}
@PostConstruct
@Override
public void setUp() throws KeeperException, IOException, InterruptedException {
if (!config.isClusterEnable()) {
logger.info("pinpoint-collector cluster disable.");
return;
}
switch (this.serviceState.getCurrentState()) {
case NEW:
if (this.serviceState.changeStateInitializing()) {
logger.info("{} initialization started.", this.getClass().getSimpleName());
ClusterManagerWatcher watcher = new ClusterManagerWatcher();
this.client = new ZookeeperClient(config.getClusterAddress(), config.getClusterSessionTimeout(), watcher);
this.profilerClusterManager = new ZookeeperProfilerClusterManager(client, serverIdentifier, clusterPointRouter.getTargetClusterPointRepository());
this.profilerClusterManager.start();
this.webClusterManager = new ZookeeperWebClusterManager(client, PINPOINT_WEB_CLUSTER_PATH, serverIdentifier, webCluster);
this.webClusterManager.start();
this.serviceState.changeStateStarted();
logger.info("{} initialization completed.", this.getClass().getSimpleName());
if (client.isConnected()) {
WatcherEvent watcherEvent = new WatcherEvent(EventType.None.getIntValue(), KeeperState.SyncConnected.getIntValue(), "");
WatchedEvent event = new WatchedEvent(watcherEvent);
watcher.process(event);
}
}
break;
case INITIALIZING:
logger.info("{} already initializing.", this.getClass().getSimpleName());
break;
case STARTED:
logger.info("{} already started.", this.getClass().getSimpleName());
break;
case DESTROYING:
throw new IllegalStateException("Already destroying.");
case STOPPED:
throw new IllegalStateException("Already stopped.");
case ILLEGAL_STATE:
throw new IllegalStateException("Invalid State.");
}
}
@PostConstruct
@Override
public void setUp() throws KeeperException, IOException, InterruptedException {
if (!config.isClusterEnable()) {
logger.info("pinpoint-collector cluster disable.");
return;
}
@PreDestroy
@Override
public void tearDown() {
if (!config.isClusterEnable()) {
logger.info("pinpoint-collector cluster disable.");
return;
}
switch (this.serviceState.getCurrentState()) {
case NEW:
if (this.serviceState.changeStateInitializing()) {
logger.info("{} initialization started.", this.getClass().getSimpleName());
if (!(this.serviceState.changeStateDestroying())) {
WorkerState state = this.serviceState.getCurrentState();
logger.info("{} already {}.", this.getClass().getSimpleName(), state.toString());
return;
}
ClusterManagerWatcher watcher = new ClusterManagerWatcher();
this.client = new ZookeeperClient(config.getClusterAddress(), config.getClusterSessionTimeout(), watcher);
logger.info("{} destroying started.", this.getClass().getSimpleName());
this.profilerClusterManager = new ZookeeperProfilerClusterManager(client, serverIdentifier, clusterPointRouter.getTargetClusterPointRepository());
this.profilerClusterManager.start();
if (this.profilerClusterManager != null) {
profilerClusterManager.stop();
}
this.webClusterManager = new ZookeeperWebClusterManager(client, PINPOINT_WEB_CLUSTER_PATH, serverIdentifier, webCluster);
this.webClusterManager.start();
if (this.webClusterManager != null) {
webClusterManager.stop();
}
if (client != null) {
client.close();
}
this.serviceState.changeStateStarted();
logger.info("{} initialization completed.", this.getClass().getSimpleName());
if (webCluster != null) {
webCluster.close();
}
this.serviceState.changeStateStopped();
logger.info("{} destroying completed.", this.getClass().getSimpleName());
}
@Override
public boolean isEnable() {
return config.isClusterEnable();
}
public SocketChannelStateChangeEventListener getChannelStateChangeEventListener() {
return profilerClusterManager;
}
public ZookeeperProfilerClusterManager getProfilerClusterManager() {
return profilerClusterManager;
}
public ZookeeperWebClusterManager getWebClusterManager() {
return webClusterManager;
}
if (client.isConnected()) {
WatcherEvent watcherEvent = new WatcherEvent(EventType.None.getIntValue(), KeeperState.SyncConnected.getIntValue(), "");
WatchedEvent event = new WatchedEvent(watcherEvent);
class ClusterManagerWatcher implements ZookeeperEventWatcher {
watcher.process(event);
}
}
break;
case INITIALIZING:
logger.info("{} already initializing.", this.getClass().getSimpleName());
break;
case STARTED:
logger.info("{} already started.", this.getClass().getSimpleName());
break;
case DESTROYING:
throw new IllegalStateException("Already destroying.");
case STOPPED:
throw new IllegalStateException("Already stopped.");
case ILLEGAL_STATE:
throw new IllegalStateException("Invalid State.");
}
}
private final AtomicBoolean connected = new AtomicBoolean(false);
@PreDestroy
@Override
public void tearDown() {
if (!config.isClusterEnable()) {
logger.info("pinpoint-collector cluster disable.");
return;
}
@Override
public void process(WatchedEvent event) {
logger.debug("Process Zookeeper Event({})", event);
KeeperState state = event.getState();
EventType eventType = event.getType();
if (!(this.serviceState.changeStateDestroying())) {
WorkerState state = this.serviceState.getCurrentState();
// ephemeral node is removed on disconnect event (leave node management exclusively to zookeeper)
if (ZookeeperUtils.isDisconnectedEvent(state, eventType)) {
connected.compareAndSet(true, false);
return;
}
logger.info("{} already {}.", this.getClass().getSimpleName(), state.toString());
return;
}
// on connect/reconnect event
if (ZookeeperUtils.isConnectedEvent(state, eventType)) {
// could already be connected (failure to compareAndSet doesn't really matter)
boolean changed = connected.compareAndSet(false, true);
}
logger.info("{} destroying started.", this.getClass().getSimpleName());
if (serviceState.isStarted() && connected.get()) {
if (this.profilerClusterManager != null) {
profilerClusterManager.stop();
}
// duplicate event possible - but the logic does not change
if (ZookeeperUtils.isConnectedEvent(state, eventType)) {
List<ChannelContext> currentChannelContextList = profilerClusterManager.getRegisteredChannelContextList();
for (ChannelContext channelContext : currentChannelContextList) {
profilerClusterManager.eventPerformed(channelContext, channelContext.getCurrentStateCode());
}
if (this.webClusterManager != null) {
webClusterManager.stop();
}
webClusterManager.handleAndRegisterWatcher(PINPOINT_WEB_CLUSTER_PATH);
} else if (eventType == EventType.NodeChildrenChanged) {
String path = event.getPath();
if (client != null) {
client.close();
}
if (PINPOINT_WEB_CLUSTER_PATH.equals(path)) {
webClusterManager.handleAndRegisterWatcher(path);
} else {
logger.warn("Unknown Path ChildrenChanged {}.", path);
}
if (webCluster != null) {
webCluster.close();
}
}
}
}
this.serviceState.changeStateStopped();
logger.info("{} destroying completed.", this.getClass().getSimpleName());
}
@Override
public boolean isConnected() {
return connected.get();
}
@Override
public boolean isEnable() {
return config.isClusterEnable();
}
public SocketChannelStateChangeEventListener getChannelStateChangeEventListener() {
return profilerClusterManager;
}
public ZookeeperProfilerClusterManager getProfilerClusterManager() {
return profilerClusterManager;
}
public ZookeeperWebClusterManager getWebClusterManager() {
return webClusterManager;
}
class ClusterManagerWatcher implements ZookeeperEventWatcher {
private final AtomicBoolean connected = new AtomicBoolean(false);
@Override
public void process(WatchedEvent event) {
logger.debug("Process Zookeeper Event({})", event);
KeeperState state = event.getState();
EventType eventType = event.getType();
// ephemeral node is removed on disconnect event (leave node management exclusively to zookeeper)
if (ZookeeperUtils.isDisconnectedEvent(state, eventType)) {
connected.compareAndSet(true, false);
return;
}
// on connect/reconnect event
if (ZookeeperUtils.isConnectedEvent(state, eventType)) {
// could already be connected (failure to compareAndSet doesn't really matter)
boolean changed = connected.compareAndSet(false, true);
}
if (serviceState.isStarted() && connected.get()) {
// duplicate event possible - but the logic does not change
if (ZookeeperUtils.isConnectedEvent(state, eventType)) {
List<ChannelContext> currentChannelContextList = profilerClusterManager.getRegisteredChannelContextList();
for (ChannelContext channelContext : currentChannelContextList) {
profilerClusterManager.eventPerformed(channelContext, channelContext.getCurrentStateCode());
}
webClusterManager.handleAndRegisterWatcher(PINPOINT_WEB_CLUSTER_PATH);
} else if (eventType == EventType.NodeChildrenChanged) {
String path = event.getPath();
if (PINPOINT_WEB_CLUSTER_PATH.equals(path)) {
webClusterManager.handleAndRegisterWatcher(path);
} else {
logger.warn("Unknown Path ChildrenChanged {}.", path);
}
}
}
}
@Override
public boolean isConnected() {
return connected.get();
}
}
}
}
@@ -23,6 +23,6 @@ import org.apache.zookeeper.Watcher;
*/
public interface ZookeeperEventWatcher extends Watcher {
boolean isConnected();
boolean isConnected();
}
@@ -51,397 +51,397 @@ import com.navercorp.pinpoint.rpc.util.MapUtils;
*/
public class ZookeeperLatestJobWorker implements Runnable {
private static final Charset charset = Charset.forName("UTF-8");
private static final Charset charset = Charset.forName("UTF-8");
private static final String PINPOINT_CLUSTER_PATH = "/pinpoint-cluster";
private static final String PINPOINT_COLLECTOR_CLUSTER_PATH = PINPOINT_CLUSTER_PATH + "/collector";
private static final String PINPOINT_CLUSTER_PATH = "/pinpoint-cluster";
private static final String PINPOINT_COLLECTOR_CLUSTER_PATH = PINPOINT_CLUSTER_PATH + "/collector";
private static final String PATH_SEPRATOR = "/";
private static final String PROFILER_SEPERATOR = "\r\n";
private static final String PATH_SEPRATOR = "/";
private static final String PROFILER_SEPERATOR = "\r\n";
private final Logger logger = LoggerFactory.getLogger(this.getClass());
private final Logger logger = LoggerFactory.getLogger(this.getClass());
private final Object lock = new Object();
private final Object lock = new Object();
private final WorkerStateContext workerState;
private final Thread workerThread;
private final WorkerStateContext workerState;
private final Thread workerThread;
private final String collectorUniqPath;
private final ZookeeperClient zookeeperClient;
private final String collectorUniqPath;
private final ConcurrentHashMap<ChannelContext, Job> latestJobRepository = new ConcurrentHashMap<ChannelContext, Job>();
private final ZookeeperClient zookeeperClient;
// Storage for managing ChannelContexts received by Worker
private final CopyOnWriteArrayList<ChannelContext> channelContextRepository = new CopyOnWriteArrayList<ChannelContext>();
private final ConcurrentHashMap<ChannelContext, Job> latestJobRepository = new ConcurrentHashMap<ChannelContext, Job>();
private final BlockingQueue<Job> leakJobQueue = new LinkedBlockingQueue<Job>();
// Storage for managing ChannelContexts received by Worker
private final CopyOnWriteArrayList<ChannelContext> channelContextRepository = new CopyOnWriteArrayList<ChannelContext>();
public ZookeeperLatestJobWorker(ZookeeperClient zookeeperClient, String serverIdentifier) {
this.zookeeperClient = zookeeperClient;
private final BlockingQueue<Job> leakJobQueue = new LinkedBlockingQueue<Job>();
this.workerState = new WorkerStateContext();
public ZookeeperLatestJobWorker(ZookeeperClient zookeeperClient, String serverIdentifier) {
this.zookeeperClient = zookeeperClient;
this.collectorUniqPath = bindingPathAndZnode(PINPOINT_COLLECTOR_CLUSTER_PATH, serverIdentifier);
final ThreadFactory threadFactory = new PinpointThreadFactory(this.getClass().getSimpleName(), true);
this.workerThread = threadFactory.newThread(this);
}
this.workerState = new WorkerStateContext();
public void start() {
switch (this.workerState.getCurrentState()) {
case NEW:
if (this.workerState.changeStateInitializing()) {
logger.info("{} initialization started.", this.getClass().getSimpleName());
workerState.changeStateStarted();
this.collectorUniqPath = bindingPathAndZnode(PINPOINT_COLLECTOR_CLUSTER_PATH, serverIdentifier);
this.workerThread.start();
logger.info("{} initialization completed.", this.getClass().getSimpleName());
final ThreadFactory threadFactory = new PinpointThreadFactory(this.getClass().getSimpleName(), true);
this.workerThread = threadFactory.newThread(this);
}
break;
}
case INITIALIZING:
logger.info("{} already initializing.", this.getClass().getSimpleName());
break;
case STARTED:
logger.info("{} already started.", this.getClass().getSimpleName());
break;
case DESTROYING:
throw new IllegalStateException("Already destroying.");
case STOPPED:
throw new IllegalStateException("Already stopped.");
case ILLEGAL_STATE:
throw new IllegalStateException("Invalid State.");
}
}
public void start() {
switch (this.workerState.getCurrentState()) {
case NEW:
if (this.workerState.changeStateInitializing()) {
logger.info("{} initialization started.", this.getClass().getSimpleName());
workerState.changeStateStarted();
public void stop() {
if (!(this.workerState.changeStateDestroying())) {
WorkerState state = this.workerState.getCurrentState();
this.workerThread.start();
logger.info("{} initialization completed.", this.getClass().getSimpleName());
logger.info("{} already {}.", this.getClass().getSimpleName(), state.toString());
return;
}
break;
}
case INITIALIZING:
logger.info("{} already initializing.", this.getClass().getSimpleName());
break;
case STARTED:
logger.info("{} already started.", this.getClass().getSimpleName());
break;
case DESTROYING:
throw new IllegalStateException("Already destroying.");
case STOPPED:
throw new IllegalStateException("Already stopped.");
case ILLEGAL_STATE:
throw new IllegalStateException("Invalid State.");
}
}
logger.info("{} destorying started.", this.getClass().getSimpleName());
boolean interrupted = false;
while (this.workerThread.isAlive()) {
this.workerThread.interrupt();
try {
this.workerThread.join(100L);
} catch (InterruptedException e) {
interrupted = true;
}
}
public void stop() {
if (!(this.workerState.changeStateDestroying())) {
WorkerState state = this.workerState.getCurrentState();
this.workerState.changeStateStopped();
logger.info("{} destorying completed.", this.getClass().getSimpleName());
}
logger.info("{} already {}.", this.getClass().getSimpleName(), state.toString());
return;
}
@Override
public void run() {
logger.info("{} destorying started.", this.getClass().getSimpleName());
boolean interrupted = false;
while (this.workerThread.isAlive()) {
this.workerThread.interrupt();
try {
this.workerThread.join(100L);
} catch (InterruptedException e) {
interrupted = true;
}
}
// Things to consider
// spinlock possible when events are not deleted
// may lead to ChannelContext leak when events are left unresolved
while (workerState.isStarted()) {
boolean eventCreated = await(60000, 200);
if (!workerState.isStarted()) {
break;
}
this.workerState.changeStateStopped();
logger.info("{} destorying completed.", this.getClass().getSimpleName());
}
// handle events
// check and handle ChannelContext leak if events are not triggered
if (eventCreated) {
// to avoid ConcurrentModificationException
Iterator<ChannelContext> keyIterator = getLatestJobRepositoryKeyIterator();
@Override
public void run() {
while (keyIterator.hasNext()) {
ChannelContext channelContext = keyIterator.next();
Job job = getJob(channelContext);
if (job == null) {
continue;
}
logger.info("Worker execute job({}).", job);
if (job instanceof UpdateJob) {
handleUpdate((UpdateJob) job);
} else if (job instanceof DeleteJob) {
handleDelete((DeleteJob) job);
}
}
} else {
// take care of leaked jobs - jobs may leak due to timing mismatch while deleting jobs
logger.debug("LeakDetector Start.");
// Things to consider
// spinlock possible when events are not deleted
// may lead to ChannelContext leak when events are left unresolved
while (workerState.isStarted()) {
boolean eventCreated = await(60000, 200);
if (!workerState.isStarted()) {
break;
}
while (true) {
Job job = leakJobQueue.poll();
if (job == null) {
break;
}
// handle events
// check and handle ChannelContext leak if events are not triggered
if (eventCreated) {
// to avoid ConcurrentModificationException
Iterator<ChannelContext> keyIterator = getLatestJobRepositoryKeyIterator();
if (job instanceof UpdateJob) {
putRetryJob(new UpdateJob(job.getChannelContext(), 1, ((UpdateJob) job).getContents()));
}
}
while (keyIterator.hasNext()) {
ChannelContext channelContext = keyIterator.next();
Job job = getJob(channelContext);
if (job == null) {
continue;
}
for (ChannelContext channelContext : channelContextRepository) {
if (PinpointServerSocketStateCode.isFinished(channelContext.getCurrentStateCode())) {
logger.info("LeakDetector Find Leak ChannelContext={}.", channelContext);
putJob(new DeleteJob(channelContext));
}
}
logger.info("Worker execute job({}).", job);
}
}
if (job instanceof UpdateJob) {
handleUpdate((UpdateJob) job);
} else if (job instanceof DeleteJob) {
handleDelete((DeleteJob) job);
}
}
} else {
// take care of leaked jobs - jobs may leak due to timing mismatch while deleting jobs
logger.debug("LeakDetector Start.");
logger.info("{} stopped", this.getClass().getSimpleName());
}
while (true) {
Job job = leakJobQueue.poll();
if (job == null) {
break;
}
public boolean handleUpdate(UpdateJob job) {
ChannelContext channelContext = job.getChannelContext();
if (job instanceof UpdateJob) {
putRetryJob(new UpdateJob(job.getChannelContext(), 1, ((UpdateJob) job).getContents()));
}
}
PinpointServerSocketStateCode code = channelContext.getCurrentStateCode();
if (PinpointServerSocketStateCode.isFinished(code)) {
putJob(new DeleteJob(channelContext));
return false;
}
for (ChannelContext channelContext : channelContextRepository) {
if (PinpointServerSocketStateCode.isFinished(channelContext.getCurrentStateCode())) {
logger.info("LeakDetector Find Leak ChannelContext={}.", channelContext);
putJob(new DeleteJob(channelContext));
}
}
try {
String addContents = createProfilerContents(channelContext);
}
}
if (zookeeperClient.exists(collectorUniqPath)) {
byte[] contents = zookeeperClient.getData(collectorUniqPath);
String data = addIfAbsentContents(new String(contents, charset), addContents);
zookeeperClient.setData(collectorUniqPath, data.getBytes(charset));
} else {
zookeeperClient.createPath(collectorUniqPath);
// should return error even if NODE exists if the data is important
zookeeperClient.createNode(collectorUniqPath, addContents.getBytes(charset));
}
return true;
} catch (Exception e) {
logger.warn(e.getMessage(), e);
if (e instanceof TimeoutException) {
putRetryJob(job);
}
}
logger.info("{} stopped", this.getClass().getSimpleName());
}
return false;
}
public boolean handleUpdate(UpdateJob job) {
ChannelContext channelContext = job.getChannelContext();
public boolean handleDelete(Job job) {
ChannelContext channelContext = job.getChannelContext();
PinpointServerSocketStateCode code = channelContext.getCurrentStateCode();
if (PinpointServerSocketStateCode.isFinished(code)) {
putJob(new DeleteJob(channelContext));
return false;
}
try {
if (zookeeperClient.exists(collectorUniqPath)) {
byte[] contents = zookeeperClient.getData(collectorUniqPath);
String removeContents = createProfilerContents(channelContext);
String data = removeIfExistContents(new String(contents, charset), removeContents);
zookeeperClient.setData(collectorUniqPath, data.getBytes(charset));
}
channelContextRepository.remove(channelContext);
return true;
} catch (Exception e) {
logger.warn(e.getMessage(), e);
if (e instanceof TimeoutException) {
putRetryJob(job);
}
}
try {
String addContents = createProfilerContents(channelContext);
return false;
}
if (zookeeperClient.exists(collectorUniqPath)) {
byte[] contents = zookeeperClient.getData(collectorUniqPath);
public byte[] getClusterData() {
try {
return zookeeperClient.getData(collectorUniqPath);
} catch (Exception e) {
logger.warn(e.getMessage(), e);
}
String data = addIfAbsentContents(new String(contents, charset), addContents);
zookeeperClient.setData(collectorUniqPath, data.getBytes(charset));
} else {
zookeeperClient.createPath(collectorUniqPath);
return null;
}
// should return error even if NODE exists if the data is important
zookeeperClient.createNode(collectorUniqPath, addContents.getBytes(charset));
}
return true;
} catch (Exception e) {
logger.warn(e.getMessage(), e);
if (e instanceof TimeoutException) {
putRetryJob(job);
}
}
public List<ChannelContext> getRegisteredChannelContextList() {
return new ArrayList<ChannelContext>(channelContextRepository);
}
/**
* Waits for events to trigger for a given time.
*
* @param waitTimeMillis total time to wait for events to trigger in milliseconds
* @param waitUnitTimeMillis time to wait for each wait attempt in milliseconds
* @return true if event triggered, false otherwise
*/
private boolean await(long waitTimeMillis, long waitUnitTimeMillis) {
synchronized (lock) {
long waitTime = waitTimeMillis;
long waitUnitTime = waitUnitTimeMillis;
if (waitTimeMillis < 1000) {
waitTime = 1000;
}
if (waitUnitTimeMillis < 100) {
waitUnitTime = 100;
}
return false;
}
long startTimeMillis = System.currentTimeMillis();
public boolean handleDelete(Job job) {
ChannelContext channelContext = job.getChannelContext();
while (latestJobRepository.size() == 0 && !isOverWaitTime(waitTime, startTimeMillis) && workerState.isStarted()) {
try {
lock.wait(waitUnitTime);
} catch (InterruptedException ignore) {
try {
if (zookeeperClient.exists(collectorUniqPath)) {
byte[] contents = zookeeperClient.getData(collectorUniqPath);
String removeContents = createProfilerContents(channelContext);
String data = removeIfExistContents(new String(contents, charset), removeContents);
zookeeperClient.setData(collectorUniqPath, data.getBytes(charset));
}
channelContextRepository.remove(channelContext);
return true;
} catch (Exception e) {
logger.warn(e.getMessage(), e);
if (e instanceof TimeoutException) {
putRetryJob(job);
}
}
return false;
}
public byte[] getClusterData() {
try {
return zookeeperClient.getData(collectorUniqPath);
} catch (Exception e) {
logger.warn(e.getMessage(), e);
}
return null;
}
public List<ChannelContext> getRegisteredChannelContextList() {
return new ArrayList<ChannelContext>(channelContextRepository);
}
/**
* Waits for events to trigger for a given time.
*
* @param waitTimeMillis total time to wait for events to trigger in milliseconds
* @param waitUnitTimeMillis time to wait for each wait attempt in milliseconds
* @return true if event triggered, false otherwise
*/
private boolean await(long waitTimeMillis, long waitUnitTimeMillis) {
synchronized (lock) {
long waitTime = waitTimeMillis;
long waitUnitTime = waitUnitTimeMillis;
if (waitTimeMillis < 1000) {
waitTime = 1000;
}
if (waitUnitTimeMillis < 100) {
waitUnitTime = 100;
}
long startTimeMillis = System.currentTimeMillis();
while (latestJobRepository.size() == 0 && !isOverWaitTime(waitTime, startTimeMillis) && workerState.isStarted()) {
try {
lock.wait(waitUnitTime);
} catch (InterruptedException ignore) {
// Thread.currentThread().interrupt();
// TODO check Interrupted state
}
}
}
}
if (isOverWaitTime(waitTime, startTimeMillis)) {
return false;
}
if (isOverWaitTime(waitTime, startTimeMillis)) {
return false;
}
return true;
}
}
return true;
}
}
private boolean isOverWaitTime(long waitTimeMillis, long startTimeMillis) {
return waitTimeMillis < (System.currentTimeMillis() - startTimeMillis);
}
private boolean isOverWaitTime(long waitTimeMillis, long startTimeMillis) {
return waitTimeMillis < (System.currentTimeMillis() - startTimeMillis);
}
private Iterator<ChannelContext> getLatestJobRepositoryKeyIterator() {
synchronized (lock) {
return latestJobRepository.keySet().iterator();
}
}
private Iterator<ChannelContext> getLatestJobRepositoryKeyIterator() {
synchronized (lock) {
return latestJobRepository.keySet().iterator();
}
}
// must be invoked within a Runnable only
private Job getJob(ChannelContext channelContext) {
synchronized (lock) {
Job job = latestJobRepository.remove(channelContext);
return job;
}
}
// must be invoked within a Runnable only
private Job getJob(ChannelContext channelContext) {
synchronized (lock) {
Job job = latestJobRepository.remove(channelContext);
return job;
}
}
public void putJob(Job job) {
ChannelContext channelContext = job.getChannelContext();
if (!checkRequiredProperties(channelContext)) {
return;
}
synchronized (lock) {
channelContextRepository.addIfAbsent(channelContext);
latestJobRepository.put(channelContext, job);
lock.notifyAll();
}
}
private void putRetryJob(Job job) {
job.incrementCurrentRetryCount();
public void putJob(Job job) {
ChannelContext channelContext = job.getChannelContext();
if (!checkRequiredProperties(channelContext)) {
return;
}
if (job.getMaxRetryCount() < job.getCurrentRetryCount()) {
if (logger.isInfoEnabled()) {
logger.warn("Leak Job Queue Register Job={}.", job);
}
leakJobQueue.add(job);
return;
}
ChannelContext channelContext = job.getChannelContext();
synchronized (lock) {
channelContextRepository.addIfAbsent(channelContext);
latestJobRepository.put(channelContext, job);
lock.notifyAll();
}
}
synchronized (lock) {
latestJobRepository.putIfAbsent(channelContext, job);
lock.notifyAll();
}
}
private void putRetryJob(Job job) {
job.incrementCurrentRetryCount();
private String bindingPathAndZnode(String path, String znodeName) {
StringBuilder fullPath = new StringBuilder();
if (job.getMaxRetryCount() < job.getCurrentRetryCount()) {
if (logger.isInfoEnabled()) {
logger.warn("Leak Job Queue Register Job={}.", job);
}
leakJobQueue.add(job);
return;
}
fullPath.append(path);
if (!path.endsWith(PATH_SEPRATOR)) {
fullPath.append(PATH_SEPRATOR);
}
fullPath.append(znodeName);
ChannelContext channelContext = job.getChannelContext();
return fullPath.toString();
}
synchronized (lock) {
latestJobRepository.putIfAbsent(channelContext, job);
lock.notifyAll();
}
}
private boolean checkRequiredProperties(ChannelContext channelContext) {
Map<Object, Object> agentProperties = channelContext.getChannelProperties();
final String applicationName = MapUtils.getString(agentProperties, AgentHandshakePropertyType.APPLICATION_NAME.getName());
final String agentId = MapUtils.getString(agentProperties, AgentHandshakePropertyType.AGENT_ID.getName());
final Long startTimeStampe = MapUtils.getLong(agentProperties, AgentHandshakePropertyType.START_TIMESTAMP.getName());
if (StringUtils.isBlank(applicationName) || StringUtils.isBlank(agentId) || startTimeStampe == null || startTimeStampe <= 0) {
logger.warn("ApplicationName({}) and AgnetId({}) and startTimeStampe({}) may not be null.", applicationName, agentId);
return false;
}
return true;
}
private String createProfilerContents(ChannelContext channelContext) {
StringBuilder profilerContents = new StringBuilder();
Map<Object, Object> agentProperties = channelContext.getChannelProperties();
final String applicationName = MapUtils.getString(agentProperties, AgentHandshakePropertyType.APPLICATION_NAME.getName());
final String agentId = MapUtils.getString(agentProperties, AgentHandshakePropertyType.AGENT_ID.getName());
final Long startTimeStampe = MapUtils.getLong(agentProperties, AgentHandshakePropertyType.START_TIMESTAMP.getName());
if (StringUtils.isBlank(applicationName) || StringUtils.isBlank(agentId) || startTimeStampe == null || startTimeStampe <= 0) {
logger.warn("ApplicationName({}) and AgnetId({}) and startTimeStampe({}) may not be null.", applicationName, agentId);
return StringUtils.EMPTY;
}
profilerContents.append(applicationName);
profilerContents.append(":");
profilerContents.append(agentId);
profilerContents.append(":");
profilerContents.append(startTimeStampe);
return profilerContents.toString();
}
private String bindingPathAndZnode(String path, String znodeName) {
StringBuilder fullPath = new StringBuilder();
private String addIfAbsentContents(String contents, String addContents) {
String[] allContents = contents.split(PROFILER_SEPERATOR);
for (String eachContent : allContents) {
if (StringUtils.equals(eachContent.trim(), addContents.trim())) {
return contents;
}
}
return contents + PROFILER_SEPERATOR + addContents;
}
private String removeIfExistContents(String contents, String removeContents) {
StringBuilder newContents = new StringBuilder(contents.length());
String[] allContents = contents.split(PROFILER_SEPERATOR);
fullPath.append(path);
if (!path.endsWith(PATH_SEPRATOR)) {
fullPath.append(PATH_SEPRATOR);
}
fullPath.append(znodeName);
Iterator<String> stringIterator = Arrays.asList(allContents).iterator();
while (stringIterator.hasNext()) {
String eachContent = stringIterator.next();
if (StringUtils.isBlank(eachContent)) {
continue;
}
if (!StringUtils.equals(eachContent.trim(), removeContents.trim())) {
newContents.append(eachContent);
return fullPath.toString();
}
if (stringIterator.hasNext()) {
newContents.append(PROFILER_SEPERATOR);
}
}
}
private boolean checkRequiredProperties(ChannelContext channelContext) {
Map<Object, Object> agentProperties = channelContext.getChannelProperties();
final String applicationName = MapUtils.getString(agentProperties, AgentHandshakePropertyType.APPLICATION_NAME.getName());
final String agentId = MapUtils.getString(agentProperties, AgentHandshakePropertyType.AGENT_ID.getName());
final Long startTimeStampe = MapUtils.getLong(agentProperties, AgentHandshakePropertyType.START_TIMESTAMP.getName());
if (StringUtils.isBlank(applicationName) || StringUtils.isBlank(agentId) || startTimeStampe == null || startTimeStampe <= 0) {
logger.warn("ApplicationName({}) and AgnetId({}) and startTimeStampe({}) may not be null.", applicationName, agentId);
return false;
}
return true;
}
private String createProfilerContents(ChannelContext channelContext) {
StringBuilder profilerContents = new StringBuilder();
Map<Object, Object> agentProperties = channelContext.getChannelProperties();
final String applicationName = MapUtils.getString(agentProperties, AgentHandshakePropertyType.APPLICATION_NAME.getName());
final String agentId = MapUtils.getString(agentProperties, AgentHandshakePropertyType.AGENT_ID.getName());
final Long startTimeStampe = MapUtils.getLong(agentProperties, AgentHandshakePropertyType.START_TIMESTAMP.getName());
if (StringUtils.isBlank(applicationName) || StringUtils.isBlank(agentId) || startTimeStampe == null || startTimeStampe <= 0) {
logger.warn("ApplicationName({}) and AgnetId({}) and startTimeStampe({}) may not be null.", applicationName, agentId);
return StringUtils.EMPTY;
}
profilerContents.append(applicationName);
profilerContents.append(":");
profilerContents.append(agentId);
profilerContents.append(":");
profilerContents.append(startTimeStampe);
return profilerContents.toString();
}
private String addIfAbsentContents(String contents, String addContents) {
String[] allContents = contents.split(PROFILER_SEPERATOR);
for (String eachContent : allContents) {
if (StringUtils.equals(eachContent.trim(), addContents.trim())) {
return contents;
}
}
return contents + PROFILER_SEPERATOR + addContents;
}
private String removeIfExistContents(String contents, String removeContents) {
StringBuilder newContents = new StringBuilder(contents.length());
String[] allContents = contents.split(PROFILER_SEPERATOR);
Iterator<String> stringIterator = Arrays.asList(allContents).iterator();
while (stringIterator.hasNext()) {
String eachContent = stringIterator.next();
if (StringUtils.isBlank(eachContent)) {
continue;
}
if (!StringUtils.equals(eachContent.trim(), removeContents.trim())) {
newContents.append(eachContent);
if (stringIterator.hasNext()) {
newContents.append(PROFILER_SEPERATOR);
}
}
}
return newContents.toString();
}
return newContents.toString();
}
}
@@ -43,137 +43,137 @@ import com.navercorp.pinpoint.rpc.util.MapUtils;
*/
public class ZookeeperProfilerClusterManager implements SocketChannelStateChangeEventListener {
private static final Charset charset = Charset.forName("UTF-8");
private static final Charset charset = Charset.forName("UTF-8");
private static final String PROFILER_SEPERATOR = "\r\n";
private static final String PROFILER_SEPERATOR = "\r\n";
private final Logger logger = LoggerFactory.getLogger(this.getClass());
private final Logger logger = LoggerFactory.getLogger(this.getClass());
private final ZookeeperLatestJobWorker worker;
private final ZookeeperLatestJobWorker worker;
private final WorkerStateContext workerState;
private final WorkerStateContext workerState;
private final ClusterPointRepository profileCluster;
private final ClusterPointRepository profileCluster;
// keep it simple - register on RUN, remove on FINISHED, skip otherwise
// should only be instantiated when cluster is enabled.
public ZookeeperProfilerClusterManager(ZookeeperClient client, String serverIdentifier, ClusterPointRepository profileCluster) {
this.workerState = new WorkerStateContext();
this.profileCluster = profileCluster;
this.worker = new ZookeeperLatestJobWorker(client, serverIdentifier);
}
// keep it simple - register on RUN, remove on FINISHED, skip otherwise
// should only be instantiated when cluster is enabled.
public ZookeeperProfilerClusterManager(ZookeeperClient client, String serverIdentifier, ClusterPointRepository profileCluster) {
this.workerState = new WorkerStateContext();
this.profileCluster = profileCluster;
public void start() {
switch (this.workerState.getCurrentState()) {
case NEW:
if (this.workerState.changeStateInitializing()) {
logger.info("{} initialization started.", this.getClass().getSimpleName());
if (worker != null) {
worker.start();
}
workerState.changeStateStarted();
logger.info("{} initialization completed.", this.getClass().getSimpleName());
break;
}
case INITIALIZING:
logger.info("{} already initializing.", this.getClass().getSimpleName());
break;
case STARTED:
logger.info("{} already started.", this.getClass().getSimpleName());
break;
case DESTROYING:
throw new IllegalStateException("Already destroying.");
case STOPPED:
throw new IllegalStateException("Already stopped.");
case ILLEGAL_STATE:
throw new IllegalStateException("Invalid State.");
}
}
public void stop() {
if (!(this.workerState.changeStateDestroying())) {
WorkerState state = this.workerState.getCurrentState();
logger.info("{} already {}.", this.getClass().getSimpleName(), state.toString());
return;
}
this.worker = new ZookeeperLatestJobWorker(client, serverIdentifier);
}
logger.info("{} destorying started.", this.getClass().getSimpleName());
public void start() {
switch (this.workerState.getCurrentState()) {
case NEW:
if (this.workerState.changeStateInitializing()) {
logger.info("{} initialization started.", this.getClass().getSimpleName());
if (worker != null) {
worker.stop();
}
if (worker != null) {
worker.start();
}
this.workerState.changeStateStopped();
logger.info("{} destorying completed.", this.getClass().getSimpleName());
}
@Override
public void eventPerformed(ChannelContext channelContext, PinpointServerSocketStateCode stateCode) {
if (workerState.isStarted()) {
logger.info("eventPerformed ChannelContext={}, State={}", channelContext, stateCode);
workerState.changeStateStarted();
logger.info("{} initialization completed.", this.getClass().getSimpleName());
Map agentProperties = channelContext.getChannelProperties();
// skip when applicationName and agentId is unknown
if (skipAgent(agentProperties)) {
return;
}
if (PinpointServerSocketStateCode.RUN_DUPLEX_COMMUNICATION == stateCode) {
UpdateJob job = new UpdateJob(channelContext, new byte[0]);
worker.putJob(job);
profileCluster.addClusterPoint(new ChannelContextClusterPoint(channelContext));
} else if (PinpointServerSocketStateCode.isFinished(stateCode)) {
DeleteJob job = new DeleteJob(channelContext);
worker.putJob(job);
break;
}
case INITIALIZING:
logger.info("{} already initializing.", this.getClass().getSimpleName());
break;
case STARTED:
logger.info("{} already started.", this.getClass().getSimpleName());
break;
case DESTROYING:
throw new IllegalStateException("Already destroying.");
case STOPPED:
throw new IllegalStateException("Already stopped.");
case ILLEGAL_STATE:
throw new IllegalStateException("Invalid State.");
}
}
profileCluster.removeClusterPoint(new ChannelContextClusterPoint(channelContext));
}
} else {
WorkerState state = this.workerState.getCurrentState();
logger.info("{} invalid state {}.", this.getClass().getSimpleName(), state.toString());
return;
}
}
public List<String> getClusterData() {
byte[] contents = worker.getClusterData();
if (contents == null) {
return Collections.emptyList();
}
public void stop() {
if (!(this.workerState.changeStateDestroying())) {
WorkerState state = this.workerState.getCurrentState();
List<String> result = new ArrayList<String>();
logger.info("{} already {}.", this.getClass().getSimpleName(), state.toString());
return;
}
String clusterData = new String(contents, charset);
String[] allClusterData = clusterData.split(PROFILER_SEPERATOR);
for (String eachClusterData : allClusterData) {
if (!StringUtils.isBlank(eachClusterData)) {
result.add(eachClusterData);
}
}
return result;
}
public List<ChannelContext> getRegisteredChannelContextList() {
return worker.getRegisteredChannelContextList();
}
logger.info("{} destorying started.", this.getClass().getSimpleName());
private boolean skipAgent(Map<Object, Object> agentProperties) {
String applicationName = MapUtils.getString(agentProperties, AgentHandshakePropertyType.APPLICATION_NAME.getName());
String agentId = MapUtils.getString(agentProperties, AgentHandshakePropertyType.AGENT_ID.getName());
if (worker != null) {
worker.stop();
}
if (StringUtils.isBlank(applicationName) || StringUtils.isBlank(agentId)) {
return true;
}
this.workerState.changeStateStopped();
logger.info("{} destorying completed.", this.getClass().getSimpleName());
}
return false;
}
@Override
public void eventPerformed(ChannelContext channelContext, PinpointServerSocketStateCode stateCode) {
if (workerState.isStarted()) {
logger.info("eventPerformed ChannelContext={}, State={}", channelContext, stateCode);
Map agentProperties = channelContext.getChannelProperties();
// skip when applicationName and agentId is unknown
if (skipAgent(agentProperties)) {
return;
}
if (PinpointServerSocketStateCode.RUN_DUPLEX_COMMUNICATION == stateCode) {
UpdateJob job = new UpdateJob(channelContext, new byte[0]);
worker.putJob(job);
profileCluster.addClusterPoint(new ChannelContextClusterPoint(channelContext));
} else if (PinpointServerSocketStateCode.isFinished(stateCode)) {
DeleteJob job = new DeleteJob(channelContext);
worker.putJob(job);
profileCluster.removeClusterPoint(new ChannelContextClusterPoint(channelContext));
}
} else {
WorkerState state = this.workerState.getCurrentState();
logger.info("{} invalid state {}.", this.getClass().getSimpleName(), state.toString());
return;
}
}
public List<String> getClusterData() {
byte[] contents = worker.getClusterData();
if (contents == null) {
return Collections.emptyList();
}
List<String> result = new ArrayList<String>();
String clusterData = new String(contents, charset);
String[] allClusterData = clusterData.split(PROFILER_SEPERATOR);
for (String eachClusterData : allClusterData) {
if (!StringUtils.isBlank(eachClusterData)) {
result.add(eachClusterData);
}
}
return result;
}
public List<ChannelContext> getRegisteredChannelContextList() {
return worker.getRegisteredChannelContextList();
}
private boolean skipAgent(Map<Object, Object> agentProperties) {
String applicationName = MapUtils.getString(agentProperties, AgentHandshakePropertyType.APPLICATION_NAME.getName());
String agentId = MapUtils.getString(agentProperties, AgentHandshakePropertyType.AGENT_ID.getName());
if (StringUtils.isBlank(applicationName) || StringUtils.isBlank(agentId)) {
return true;
}
return false;
}
}
@@ -26,38 +26,38 @@ import org.apache.zookeeper.Watcher.Event.KeeperState;
public final class ZookeeperUtils {
// would be a good idea to move to commons-hbase (if implemented) in the future
private ZookeeperUtils() {
}
private ZookeeperUtils() {
}
public static boolean isConnectedEvent(WatchedEvent event) {
KeeperState state = event.getState();
EventType eventType = event.getType();
public static boolean isConnectedEvent(WatchedEvent event) {
KeeperState state = event.getState();
EventType eventType = event.getType();
return isConnectedEvent(state, eventType);
}
return isConnectedEvent(state, eventType);
}
public static boolean isConnectedEvent(KeeperState state, EventType eventType) {
if ((state == KeeperState.SyncConnected || state == KeeperState.NoSyncConnected) && eventType == EventType.None) {
return true;
} else {
return false;
}
}
public static boolean isConnectedEvent(KeeperState state, EventType eventType) {
if ((state == KeeperState.SyncConnected || state == KeeperState.NoSyncConnected) && eventType == EventType.None) {
return true;
} else {
return false;
}
}
public static boolean isDisconnectedEvent(WatchedEvent event) {
KeeperState state = event.getState();
EventType eventType = event.getType();
return isDisconnectedEvent(state, eventType);
}
public static boolean isDisconnectedEvent(WatchedEvent event) {
KeeperState state = event.getState();
EventType eventType = event.getType();
return isDisconnectedEvent(state, eventType);
}
public static boolean isDisconnectedEvent(KeeperState state, EventType eventType) {
if ((state == KeeperState.Disconnected || state == KeeperState.Expired) && eventType == eventType.None) {
return true;
} else {
return false;
}
}
public static boolean isDisconnectedEvent(KeeperState state, EventType eventType) {
if ((state == KeeperState.Disconnected || state == KeeperState.Expired) && eventType == eventType.None) {
return true;
} else {
return false;
}
}
}
@@ -40,76 +40,76 @@ import com.navercorp.pinpoint.common.util.PinpointThreadFactory;
public class ZookeeperWebClusterManager implements Runnable {
// it is okay for the collector to retry indefinitely, as long as RETRY_INTERVAL is set reasonably
private static final int DEFAULT_RETRY_INTERVAL = 60000;
private static final int DEFAULT_RETRY_INTERVAL = 60000;
private final Logger logger = LoggerFactory.getLogger(this.getClass());
private final Logger logger = LoggerFactory.getLogger(this.getClass());
private final GetAndRegisterTask getAndRegisterTask = new GetAndRegisterTask();
private final StopTask stopTask = new StopTask();
private final GetAndRegisterTask getAndRegisterTask = new GetAndRegisterTask();
private final StopTask stopTask = new StopTask();
private final ZookeeperClient client;
private final WebCluster webCluster;
private final String zNodePath;
private final ZookeeperClient client;
private final WebCluster webCluster;
private final String zNodePath;
private final AtomicBoolean retryMode = new AtomicBoolean(false);
private final AtomicBoolean retryMode = new AtomicBoolean(false);
private final BlockingQueue<Task> queue = new LinkedBlockingQueue<Task>(1);
private final BlockingQueue<Task> queue = new LinkedBlockingQueue<Task>(1);
private final WorkerStateContext workerState;
private final Thread workerThread;
private final WorkerStateContext workerState;
private final Thread workerThread;
// private final Timer timer;
// private final Timer timer;
// Register Worker + Job
// synchronize current status with Zookeeper when an event(job) is triggered.
// (the number of events does not matter as long as a single event is triggered - subsequent events may be ignored)
public ZookeeperWebClusterManager(ZookeeperClient client, String zookeeperClusterPath, String serverIdentifier, WebCluster webCluster) {
this.client = client;
// Register Worker + Job
// synchronize current status with Zookeeper when an event(job) is triggered.
// (the number of events does not matter as long as a single event is triggered - subsequent events may be ignored)
public ZookeeperWebClusterManager(ZookeeperClient client, String zookeeperClusterPath, String serverIdentifier, WebCluster webCluster) {
this.client = client;
this.webCluster = webCluster;
this.zNodePath = zookeeperClusterPath;
this.webCluster = webCluster;
this.zNodePath = zookeeperClusterPath;
this.workerState = new WorkerStateContext();
this.workerState = new WorkerStateContext();
final ThreadFactory threadFactory = new PinpointThreadFactory(this.getClass().getSimpleName(), true);
this.workerThread = threadFactory.newThread(this);
}
final ThreadFactory threadFactory = new PinpointThreadFactory(this.getClass().getSimpleName(), true);
this.workerThread = threadFactory.newThread(this);
}
public void start() {
switch (this.workerState.getCurrentState()) {
case NEW:
if (this.workerState.changeStateInitializing()) {
logger.info("{} initialization started.", this.getClass().getSimpleName());
this.workerThread.start();
workerState.changeStateStarted();
logger.info("{} initialization completed.", this.getClass().getSimpleName());
break;
}
case INITIALIZING:
logger.info("{} already initializing.", this.getClass().getSimpleName());
break;
case STARTED:
logger.info("{} already started.", this.getClass().getSimpleName());
break;
case DESTROYING:
throw new IllegalStateException("Already destroying.");
case STOPPED:
throw new IllegalStateException("Already stopped.");
case ILLEGAL_STATE:
throw new IllegalStateException("Invalid State.");
}
}
public void start() {
switch (this.workerState.getCurrentState()) {
case NEW:
if (this.workerState.changeStateInitializing()) {
logger.info("{} initialization started.", this.getClass().getSimpleName());
this.workerThread.start();
public void stop() {
if (!(this.workerState.changeStateDestroying())) {
WorkerState state = this.workerState.getCurrentState();
logger.info("{} already {}.", this.getClass().getSimpleName(), state.toString());
return;
}
workerState.changeStateStarted();
logger.info("{} initialization completed.", this.getClass().getSimpleName());
break;
}
case INITIALIZING:
logger.info("{} already initializing.", this.getClass().getSimpleName());
break;
case STARTED:
logger.info("{} already started.", this.getClass().getSimpleName());
break;
case DESTROYING:
throw new IllegalStateException("Already destroying.");
case STOPPED:
throw new IllegalStateException("Already stopped.");
case ILLEGAL_STATE:
throw new IllegalStateException("Invalid State.");
}
}
logger.info("{} destorying started.", this.getClass().getSimpleName());
public void stop() {
if (!(this.workerState.changeStateDestroying())) {
WorkerState state = this.workerState.getCurrentState();
logger.info("{} already {}.", this.getClass().getSimpleName(), state.toString());
return;
}
logger.info("{} destorying started.", this.getClass().getSimpleName());
final boolean stopOffer = queue.offer(stopTask);
if (!stopOffer) {
@@ -117,119 +117,119 @@ public class ZookeeperWebClusterManager implements Runnable {
}
boolean interrupted = false;
while (this.workerThread.isAlive()) {
this.workerThread.interrupt();
try {
this.workerThread.join(100L);
} catch (InterruptedException e) {
interrupted = true;
}
}
while (this.workerThread.isAlive()) {
this.workerThread.interrupt();
try {
this.workerThread.join(100L);
} catch (InterruptedException e) {
interrupted = true;
}
}
this.workerState.changeStateStopped();
logger.info("{} destorying completed.", this.getClass().getSimpleName());
}
this.workerState.changeStateStopped();
logger.info("{} destorying completed.", this.getClass().getSimpleName());
}
public void handleAndRegisterWatcher(String path) {
if (workerState.isStarted()) {
if (zNodePath.equals(path)) {
final boolean offerSuccess = queue.offer(getAndRegisterTask);
if (!offerSuccess) {
logger.info("Message Queue is Full.");
}
} else {
logger.info("Invald Path {}.", path);
}
} else {
WorkerState state = this.workerState.getCurrentState();
logger.info("{} invalid state {}.", this.getClass().getSimpleName(), state.toString());
}
}
public void handleAndRegisterWatcher(String path) {
if (workerState.isStarted()) {
if (zNodePath.equals(path)) {
final boolean offerSuccess = queue.offer(getAndRegisterTask);
if (!offerSuccess) {
logger.info("Message Queue is Full.");
}
} else {
logger.info("Invald Path {}.", path);
}
} else {
WorkerState state = this.workerState.getCurrentState();
logger.info("{} invalid state {}.", this.getClass().getSimpleName(), state.toString());
}
}
@Override
public void run() {
// if the node does not exist, create a node and retry.
// retry on timeout as well.
while (workerState.isStarted()) {
Task task = null;
@Override
public void run() {
// if the node does not exist, create a node and retry.
// retry on timeout as well.
while (workerState.isStarted()) {
Task task = null;
try {
task = queue.poll(DEFAULT_RETRY_INTERVAL, TimeUnit.MILLISECONDS);
} catch (InterruptedException e) {
logger.debug(e.getMessage(), e);
}
try {
task = queue.poll(DEFAULT_RETRY_INTERVAL, TimeUnit.MILLISECONDS);
} catch (InterruptedException e) {
logger.debug(e.getMessage(), e);
}
if (!workerState.isStarted()) {
break;
}
if (!workerState.isStarted()) {
break;
}
if (task == null) {
if (retryMode.get()) {
boolean success = getAndRegisterTask.handleAndRegisterWatcher0();
if (success) {
retryMode.compareAndSet(true, false);
}
}
} else if (task instanceof GetAndRegisterTask) {
boolean success = ((GetAndRegisterTask) task).handleAndRegisterWatcher0();
if (!success) {
retryMode.compareAndSet(false, true);
}
} else if (task instanceof StopTask) {
break;
}
}
if (task == null) {
if (retryMode.get()) {
boolean success = getAndRegisterTask.handleAndRegisterWatcher0();
if (success) {
retryMode.compareAndSet(true, false);
}
}
} else if (task instanceof GetAndRegisterTask) {
boolean success = ((GetAndRegisterTask) task).handleAndRegisterWatcher0();
if (!success) {
retryMode.compareAndSet(false, true);
}
} else if (task instanceof StopTask) {
break;
}
}
logger.info("{} stopped", this.getClass().getSimpleName());
}
logger.info("{} stopped", this.getClass().getSimpleName());
}
interface Task {
interface Task {
}
}
class GetAndRegisterTask implements Task {
class GetAndRegisterTask implements Task {
private boolean handleAndRegisterWatcher0() {
boolean needNotRetry = false;
try {
private boolean handleAndRegisterWatcher0() {
boolean needNotRetry = false;
try {
if (!client.exists(zNodePath)) {
client.createPath(zNodePath, true);
}
if (!client.exists(zNodePath)) {
client.createPath(zNodePath, true);
}
List<String> childNodeList = client.getChildrenNode(zNodePath, true);
List<InetSocketAddress> clusterAddressList = NetUtils.toInetSocketAddressLIst(childNodeList);
List<String> childNodeList = client.getChildrenNode(zNodePath, true);
List<InetSocketAddress> clusterAddressList = NetUtils.toInetSocketAddressLIst(childNodeList);
List<InetSocketAddress> addressList = webCluster.getWebClusterList();
List<InetSocketAddress> addressList = webCluster.getWebClusterList();
logger.info("Handle register and remove Task. Current Address List = {}, Cluster Address List = {}", addressList, clusterAddressList);
for (InetSocketAddress clusterAddress : clusterAddressList) {
if (!addressList.contains(clusterAddress)) {
webCluster.connectPointIfAbsent(clusterAddress);
}
}
logger.info("Handle register and remove Task. Current Address List = {}, Cluster Address List = {}", addressList, clusterAddressList);
for (InetSocketAddress address : addressList) {
if (!clusterAddressList.contains(address)) {
webCluster.disconnectPoint(address);
}
}
for (InetSocketAddress clusterAddress : clusterAddressList) {
if (!addressList.contains(clusterAddress)) {
webCluster.connectPointIfAbsent(clusterAddress);
}
}
needNotRetry = true;
return needNotRetry;
} catch (Exception e) {
if (!(e instanceof ConnectionException)) {
needNotRetry = true;
}
}
for (InetSocketAddress address : addressList) {
if (!clusterAddressList.contains(address)) {
webCluster.disconnectPoint(address);
}
}
return needNotRetry;
}
}
needNotRetry = true;
return needNotRetry;
} catch (Exception e) {
if (!(e instanceof ConnectionException)) {
needNotRetry = true;
}
}
static class StopTask implements Task {
return needNotRetry;
}
}
}
static class StopTask implements Task {
}
}
@@ -21,19 +21,19 @@ package com.navercorp.pinpoint.collector.cluster.zookeeper.exception;
*/
public class AuthException extends PinpointZookeeperException {
public AuthException() {
}
public AuthException() {
}
public AuthException(String message) {
super(message);
}
public AuthException(String message) {
super(message);
}
public AuthException(String message, Throwable cause) {
super(message, cause);
}
public AuthException(String message, Throwable cause) {
super(message, cause);
}
public AuthException(Throwable cause) {
super(cause);
}
public AuthException(Throwable cause) {
super(cause);
}
}
@@ -21,19 +21,19 @@ package com.navercorp.pinpoint.collector.cluster.zookeeper.exception;
*/
public class BadOperationException extends PinpointZookeeperException {
public BadOperationException() {
}
public BadOperationException() {
}
public BadOperationException(String message) {
super(message);
}
public BadOperationException(String message) {
super(message);
}
public BadOperationException(String message, Throwable cause) {
super(message, cause);
}
public BadOperationException(String message, Throwable cause) {
super(message, cause);
}
public BadOperationException(Throwable cause) {
super(cause);
}
public BadOperationException(Throwable cause) {
super(cause);
}
}
@@ -21,19 +21,19 @@ package com.navercorp.pinpoint.collector.cluster.zookeeper.exception;
*/
public class ConnectionException extends PinpointZookeeperException {
public ConnectionException() {
}
public ConnectionException() {
}
public ConnectionException(String message) {
super(message);
}
public ConnectionException(String message) {
super(message);
}
public ConnectionException(String message, Throwable cause) {
super(message, cause);
}
public ConnectionException(String message, Throwable cause) {
super(message, cause);
}
public ConnectionException(Throwable cause) {
super(cause);
}
public ConnectionException(Throwable cause) {
super(cause);
}
}
@@ -20,20 +20,20 @@ package com.navercorp.pinpoint.collector.cluster.zookeeper.exception;
* @author koo.taejin
*/
public class PinpointZookeeperException extends Exception {
public PinpointZookeeperException() {
}
public PinpointZookeeperException(String message) {
super(message);
}
public PinpointZookeeperException() {
}
public PinpointZookeeperException(String message, Throwable cause) {
super(message, cause);
}
public PinpointZookeeperException(String message) {
super(message);
}
public PinpointZookeeperException(Throwable cause) {
super(cause);
}
public PinpointZookeeperException(String message, Throwable cause) {
super(message, cause);
}
public PinpointZookeeperException(Throwable cause) {
super(cause);
}
}
@@ -21,19 +21,19 @@ package com.navercorp.pinpoint.collector.cluster.zookeeper.exception;
*/
public class TimeoutException extends PinpointZookeeperException {
public TimeoutException() {
}
public TimeoutException() {
}
public TimeoutException(String message) {
super(message);
}
public TimeoutException(String message) {
super(message);
}
public TimeoutException(String message, Throwable cause) {
super(message, cause);
}
public TimeoutException(String message, Throwable cause) {
super(message, cause);
}
public TimeoutException(Throwable cause) {
super(cause);
}
public TimeoutException(Throwable cause) {
super(cause);
}
}
@@ -21,19 +21,19 @@ package com.navercorp.pinpoint.collector.cluster.zookeeper.exception;
*/
public class UnknownException extends PinpointZookeeperException {
public UnknownException() {
}
public UnknownException() {
}
public UnknownException(String message) {
super(message);
}
public UnknownException(String message) {
super(message);
}
public UnknownException(String message, Throwable cause) {
super(message, cause);
}
public UnknownException(String message, Throwable cause) {
super(message, cause);
}
public UnknownException(Throwable cause) {
super(cause);
}
public UnknownException(Throwable cause) {
super(cause);
}
}
@@ -22,50 +22,50 @@ import com.navercorp.pinpoint.rpc.server.ChannelContext;
public class AbstractJob implements Job {
private final ChannelContext channelContext;
private final int maxCount;
private final AtomicInteger currentCount;
private final ChannelContext channelContext;
public AbstractJob(ChannelContext channelContext) {
this(channelContext, 3);
}
private final int maxCount;
private final AtomicInteger currentCount;
public AbstractJob(ChannelContext channelContext, int maxCount) {
this.channelContext = channelContext;
this.maxCount = maxCount;
this.currentCount = new AtomicInteger(0);
}
@Override
public ChannelContext getChannelContext() {
return channelContext;
}
@Override
public int getMaxRetryCount() {
return maxCount;
}
public AbstractJob(ChannelContext channelContext) {
this(channelContext, 3);
}
@Override
public int getCurrentRetryCount() {
return currentCount.get();
}
@Override
public void incrementCurrentRetryCount() {
currentCount.incrementAndGet();
}
@Override
public String toString() {
StringBuilder buffer = new StringBuilder();
buffer.append(this.getClass().getSimpleName());
buffer.append(", ChannelContext=").append(channelContext);
buffer.append(", Retry=").append(currentCount.get()).append("/").append(maxCount);
return buffer.toString();
}
public AbstractJob(ChannelContext channelContext, int maxCount) {
this.channelContext = channelContext;
this.maxCount = maxCount;
this.currentCount = new AtomicInteger(0);
}
@Override
public ChannelContext getChannelContext() {
return channelContext;
}
@Override
public int getMaxRetryCount() {
return maxCount;
}
@Override
public int getCurrentRetryCount() {
return currentCount.get();
}
@Override
public void incrementCurrentRetryCount() {
currentCount.incrementAndGet();
}
@Override
public String toString() {
StringBuilder buffer = new StringBuilder();
buffer.append(this.getClass().getSimpleName());
buffer.append(", ChannelContext=").append(channelContext);
buffer.append(", Retry=").append(currentCount.get()).append("/").append(maxCount);
return buffer.toString();
}
}
@@ -23,8 +23,8 @@ import com.navercorp.pinpoint.rpc.server.ChannelContext;
*/
public class DeleteJob extends AbstractJob {
public DeleteJob(ChannelContext channelContext) {
super(channelContext);
}
public DeleteJob(ChannelContext channelContext) {
super(channelContext);
}
}
@@ -23,13 +23,13 @@ import com.navercorp.pinpoint.rpc.server.ChannelContext;
*/
public interface Job {
ChannelContext getChannelContext();
int getMaxRetryCount();
int getCurrentRetryCount();
void incrementCurrentRetryCount();
ChannelContext getChannelContext();
int getMaxRetryCount();
int getCurrentRetryCount();
void incrementCurrentRetryCount();
}
@@ -23,20 +23,20 @@ import com.navercorp.pinpoint.rpc.server.ChannelContext;
*/
public class UpdateJob extends AbstractJob {
private final byte[] contents;
public UpdateJob(ChannelContext channelContext, byte[] contents) {
super(channelContext);
this.contents = contents;
}
public UpdateJob(ChannelContext channelContext, int maxRetryCount, byte[] contents) {
super(channelContext, maxRetryCount);
this.contents = contents;
}
private final byte[] contents;
public byte[] getContents() {
return contents;
}
public UpdateJob(ChannelContext channelContext, byte[] contents) {
super(channelContext);
this.contents = contents;
}
public UpdateJob(ChannelContext channelContext, int maxRetryCount, byte[] contents) {
super(channelContext, maxRetryCount);
this.contents = contents;
}
public byte[] getContents() {
return contents;
}
}
@@ -35,7 +35,7 @@ public class CollectorConfiguration implements InitializingBean {
private final Logger logger = LoggerFactory.getLogger(this.getClass());
// cluster.zookeeper.address=dev.zk.pinpoint.navercorp.com
// cluster.zookeeper.sessiontimeout=3000
// cluster.zookeeper.sessiontimeout=3000
private static final String CONFIG_FILE_NAME = "pinpoint-collector.properties";
private static final String DEFAULT_LISTEN_IP = "0.0.0.0";
@@ -103,11 +103,11 @@ public class CollectorConfiguration implements InitializingBean {
}
public int getUdpSpanListenPort() {
return udpSpanListenPort;
}
return udpSpanListenPort;
}
public int getUdpSpanWorkerThread() {
public int getUdpSpanWorkerThread() {
return udpSpanWorkerThread;
}
@@ -131,29 +131,29 @@ public class CollectorConfiguration implements InitializingBean {
this.udpSpanSocketReceiveBufferSize = udpSpanSocketReceiveBufferSize;
}
public boolean isClusterEnable() {
return clusterEnable;
}
public boolean isClusterEnable() {
return clusterEnable;
}
public void setClusterEnable(boolean clusterEnable) {
this.clusterEnable = clusterEnable;
}
public void setClusterEnable(boolean clusterEnable) {
this.clusterEnable = clusterEnable;
}
public String getClusterAddress() {
return clusterAddress;
}
public String getClusterAddress() {
return clusterAddress;
}
public void setClusterAddress(String clusterAddress) {
this.clusterAddress = clusterAddress;
}
public int getClusterSessionTimeout() {
return clusterSessionTimeout;
}
public void setClusterAddress(String clusterAddress) {
this.clusterAddress = clusterAddress;
}
public void setClusterSessionTimeout(int clusterSessionTimeout) {
this.clusterSessionTimeout = clusterSessionTimeout;
}
public int getClusterSessionTimeout() {
return clusterSessionTimeout;
}
public void setClusterSessionTimeout(int clusterSessionTimeout) {
this.clusterSessionTimeout = clusterSessionTimeout;
}
public void readConfigFile() {
@@ -226,7 +226,7 @@ public class CollectorConfiguration implements InitializingBean {
}
private boolean readBoolen(Properties properties, String propertyName) {
final String value = properties.getProperty(propertyName);
final String value = properties.getProperty(propertyName);
// if a default value will be needed afterwards, may match string value instead of Utils.
// for now stay unmodified because of no need.
@@ -21,7 +21,7 @@ package com.navercorp.pinpoint.collector.dao;
*/
@Deprecated
public interface AgentIdApplicationIndexDao {
void insert(String agentId, String applicationName);
void insert(String agentId, String applicationName);
String selectApplicationName(String agentId);
String selectApplicationName(String agentId);
}
@@ -22,5 +22,5 @@ import com.navercorp.pinpoint.thrift.dto.TSpan;
* @author emeroad
*/
public interface ApplicationTraceIndexDao {
void insert(TSpan span);
void insert(TSpan span);
}
@@ -35,14 +35,14 @@ import com.navercorp.pinpoint.common.util.PinpointThreadFactory;
*/
public class AutoFlusher {
private final Logger logger = LoggerFactory.getLogger(this.getClass());
private final Logger logger = LoggerFactory.getLogger(this.getClass());
private ScheduledExecutorService executor;
private ScheduledExecutorService executor;
private long flushPeriod = 1000;
@Autowired
private List<CachedStatisticsDao> cachedStatisticsDaoList;
@Autowired
private List<CachedStatisticsDao> cachedStatisticsDaoList;
public long getFlushPeriod() {
return flushPeriod;
@@ -53,54 +53,54 @@ public class AutoFlusher {
}
private static final class Worker implements Runnable {
private final Logger logger = LoggerFactory.getLogger(this.getClass());
private final CachedStatisticsDao dao;
private final Logger logger = LoggerFactory.getLogger(this.getClass());
private final CachedStatisticsDao dao;
public Worker(CachedStatisticsDao dao) {
this.dao = dao;
}
public Worker(CachedStatisticsDao dao) {
this.dao = dao;
}
@Override
public void run() {
try {
dao.flushAll();
} catch (Throwable th) {
logger.error("AutoFlusherWorker failed. Caused:{}", th.getMessage(), th);
}
}
}
@Override
public void run() {
try {
dao.flushAll();
} catch (Throwable th) {
logger.error("AutoFlusherWorker failed. Caused:{}", th.getMessage(), th);
}
}
}
public void initialize() {
if (cachedStatisticsDaoList == null || cachedStatisticsDaoList.isEmpty()) {
return;
}
public void initialize() {
if (cachedStatisticsDaoList == null || cachedStatisticsDaoList.isEmpty()) {
return;
}
ThreadFactory threadFactory = PinpointThreadFactory.createThreadFactory(this.getClass().getSimpleName());
executor = Executors.newScheduledThreadPool(cachedStatisticsDaoList.size(), threadFactory);
for (CachedStatisticsDao dao : cachedStatisticsDaoList) {
executor.scheduleAtFixedRate(new Worker(dao), 0L, flushPeriod, TimeUnit.MILLISECONDS);
}
logger.info("Auto flusher initialized.");
}
ThreadFactory threadFactory = PinpointThreadFactory.createThreadFactory(this.getClass().getSimpleName());
executor = Executors.newScheduledThreadPool(cachedStatisticsDaoList.size(), threadFactory);
for (CachedStatisticsDao dao : cachedStatisticsDaoList) {
executor.scheduleAtFixedRate(new Worker(dao), 0L, flushPeriod, TimeUnit.MILLISECONDS);
}
logger.info("Auto flusher initialized.");
}
public void shutdown() {
logger.info("Shutdown auto flusher.");
shutdownExecutor();
for (CachedStatisticsDao dao : cachedStatisticsDaoList) {
dao.flushAll();
}
}
public void shutdown() {
logger.info("Shutdown auto flusher.");
shutdownExecutor();
for (CachedStatisticsDao dao : cachedStatisticsDaoList) {
dao.flushAll();
}
}
private void shutdownExecutor() {
executor.shutdown();
try {
executor.awaitTermination(3000 + flushPeriod, TimeUnit.MILLISECONDS);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
private void shutdownExecutor() {
executor.shutdown();
try {
executor.awaitTermination(3000 + flushPeriod, TimeUnit.MILLISECONDS);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
public void setCachedStatisticsDaoList(List<CachedStatisticsDao> cachedStatisticsDaoList) {
this.cachedStatisticsDaoList = cachedStatisticsDaoList;
}
public void setCachedStatisticsDaoList(List<CachedStatisticsDao> cachedStatisticsDaoList) {
this.cachedStatisticsDaoList = cachedStatisticsDaoList;
}
}
@@ -22,5 +22,5 @@ package com.navercorp.pinpoint.collector.dao;
*
*/
public interface CachedStatisticsDao {
void flushAll();
void flushAll();
}
@@ -22,5 +22,5 @@ package com.navercorp.pinpoint.collector.dao;
*
*/
public interface HostApplicationMapDao {
void insert(String host, String bindApplicationName, short bindServiceType, String parentApplicationName, short parentServiceType);
void insert(String host, String bindApplicationName, short bindServiceType, String parentApplicationName, short parentServiceType);
}
@@ -22,5 +22,5 @@ package com.navercorp.pinpoint.collector.dao;
* @author emeroad
*/
public interface MapStatisticsCalleeDao extends CachedStatisticsDao {
void update(String calleeApplicationName, short calleeServiceType, String callerApplicationName, short callerServiceType, String callerHost, int elapsed, boolean isError);
void update(String calleeApplicationName, short calleeServiceType, String callerApplicationName, short callerServiceType, String callerHost, int elapsed, boolean isError);
}
@@ -22,5 +22,5 @@ package com.navercorp.pinpoint.collector.dao;
* @author emeroad
*/
public interface MapStatisticsCallerDao extends CachedStatisticsDao {
void update(String callerApplicationName, short callerServiceType, String callerAgentId, String calleeApplicationName, short calleeServiceType, String calleeHost, int elapsed, boolean isError);
void update(String callerApplicationName, short callerServiceType, String callerAgentId, String calleeApplicationName, short calleeServiceType, String calleeHost, int elapsed, boolean isError);
}
@@ -40,15 +40,15 @@ import org.springframework.stereotype.Repository;
@Deprecated
public class HbaseAgentIdApplicationIndexDao implements AgentIdApplicationIndexDao {
@Autowired
private HbaseOperations2 hbaseTemplate;
@Autowired
private HbaseOperations2 hbaseTemplate;
@Autowired
@Qualifier("applicationNameMapper")
private RowMapper<String> applicationNameMapper;
@Autowired
@Qualifier("applicationNameMapper")
private RowMapper<String> applicationNameMapper;
@Override
public void insert(String agentId, String applicationName) {
@Override
public void insert(String agentId, String applicationName) {
if (agentId == null) {
throw new NullPointerException("agentId must not be null");
}
@@ -57,23 +57,23 @@ public class HbaseAgentIdApplicationIndexDao implements AgentIdApplicationIndexD
}
byte[] agentIdByte = Bytes.toBytes(agentId);
byte[] appNameByte = Bytes.toBytes(applicationName);
byte[] appNameByte = Bytes.toBytes(applicationName);
Put put = new Put(agentIdByte);
put.add(AGENTID_APPLICATION_INDEX_CF_APPLICATION, appNameByte, appNameByte);
Put put = new Put(agentIdByte);
put.add(AGENTID_APPLICATION_INDEX_CF_APPLICATION, appNameByte, appNameByte);
hbaseTemplate.put(AGENTID_APPLICATION_INDEX, put);
}
hbaseTemplate.put(AGENTID_APPLICATION_INDEX, put);
}
@Override
public String selectApplicationName(String agentId) {
@Override
public String selectApplicationName(String agentId) {
if (agentId == null) {
throw new NullPointerException("agentId must not be null");
}
byte[] rowKey = Bytes.toBytes(agentId);
Get get = new Get(rowKey);
get.addFamily(AGENTID_APPLICATION_INDEX_CF_APPLICATION);
Get get = new Get(rowKey);
get.addFamily(AGENTID_APPLICATION_INDEX_CF_APPLICATION);
return hbaseTemplate.get(AGENTID_APPLICATION_INDEX, get, applicationNameMapper);
}
return hbaseTemplate.get(AGENTID_APPLICATION_INDEX, get, applicationNameMapper);
}
}
@@ -41,45 +41,45 @@ import org.springframework.stereotype.Repository;
@Repository
public class HbaseAgentInfoDao implements AgentInfoDao {
private final Logger logger = LoggerFactory.getLogger(this.getClass());
private final Logger logger = LoggerFactory.getLogger(this.getClass());
@Autowired
private HbaseOperations2 hbaseTemplate;
@Autowired
@Qualifier("agentInfoBoMapper")
private ThriftBoMapper<AgentInfoBo, TAgentInfo> agentInfoBoMapper;
@Autowired
private HbaseOperations2 hbaseTemplate;
@Autowired
@Qualifier("agentInfoBoMapper")
private ThriftBoMapper<AgentInfoBo, TAgentInfo> agentInfoBoMapper;
@Autowired
@Qualifier("serverMetaDataBoMapper")
private ThriftBoMapper<ServerMetaDataBo, TServerMetaData> serverMetaDataBoMapper;
@Override
public void insert(TAgentInfo agentInfo) {
@Override
public void insert(TAgentInfo agentInfo) {
if (agentInfo == null) {
throw new NullPointerException("agentInfo must not be null");
}
if (logger.isDebugEnabled()) {
logger.debug("insert agent info. {}", agentInfo);
}
logger.debug("insert agent info. {}", agentInfo);
}
byte[] agentId = Bytes.toBytes(agentInfo.getAgentId());
long reverseKey = TimeUtils.reverseTimeMillis(agentInfo.getStartTimestamp());
byte[] rowKey = RowKeyUtils.concatFixedByteAndLong(agentId, HBaseTables.AGENT_NAME_MAX_LEN, reverseKey);
Put put = new Put(rowKey);
byte[] agentId = Bytes.toBytes(agentInfo.getAgentId());
long reverseKey = TimeUtils.reverseTimeMillis(agentInfo.getStartTimestamp());
byte[] rowKey = RowKeyUtils.concatFixedByteAndLong(agentId, HBaseTables.AGENT_NAME_MAX_LEN, reverseKey);
Put put = new Put(rowKey);
// should add additional agent informations. for now added only starttime for sqlMetaData
AgentInfoBo agentInfoBo = this.agentInfoBoMapper.map(agentInfo);
byte[] agentInfoBoValue = agentInfoBo.writeValue();
put.add(HBaseTables.AGENTINFO_CF_INFO, HBaseTables.AGENTINFO_CF_INFO_IDENTIFIER, agentInfoBoValue);
if (agentInfo.isSetServerMetaData()) {
ServerMetaDataBo serverMetaDataBo = this.serverMetaDataBoMapper.map(agentInfo.getServerMetaData());
byte[] serverMetaDataBoValue = serverMetaDataBo.writeValue();
put.add(HBaseTables.AGENTINFO_CF_INFO, HBaseTables.AGENTINFO_CF_INFO_SERVER_META_DATA, serverMetaDataBoValue);
}
hbaseTemplate.put(HBaseTables.AGENTINFO, put);
}
// should add additional agent informations. for now added only starttime for sqlMetaData
AgentInfoBo agentInfoBo = this.agentInfoBoMapper.map(agentInfo);
byte[] agentInfoBoValue = agentInfoBo.writeValue();
put.add(HBaseTables.AGENTINFO_CF_INFO, HBaseTables.AGENTINFO_CF_INFO_IDENTIFIER, agentInfoBoValue);
if (agentInfo.isSetServerMetaData()) {
ServerMetaDataBo serverMetaDataBo = this.serverMetaDataBoMapper.map(agentInfo.getServerMetaData());
byte[] serverMetaDataBoValue = serverMetaDataBo.writeValue();
put.add(HBaseTables.AGENTINFO_CF_INFO, HBaseTables.AGENTINFO_CF_INFO_SERVER_META_DATA, serverMetaDataBoValue);
}
hbaseTemplate.put(HBaseTables.AGENTINFO, put);
}
}
@@ -41,8 +41,8 @@ import org.springframework.stereotype.Repository;
@Repository
public class HbaseApplicationTraceIndexDao implements ApplicationTraceIndexDao {
@Autowired
private HbaseOperations2 hbaseTemplate;
@Autowired
private HbaseOperations2 hbaseTemplate;
@Autowired
private AcceptedTimeService acceptedTimeService;
@@ -51,8 +51,8 @@ public class HbaseApplicationTraceIndexDao implements ApplicationTraceIndexDao {
@Qualifier("applicationTraceIndexDistributor")
private AbstractRowKeyDistributor rowKeyDistributor;
@Override
public void insert(final TSpan span) {
@Override
public void insert(final TSpan span) {
if (span == null) {
throw new NullPointerException("span must not be null");
}
@@ -69,27 +69,27 @@ public class HbaseApplicationTraceIndexDao implements ApplicationTraceIndexDao {
put.add(APPLICATION_TRACE_INDEX_CF_TRACE, makeQualifier(span) , acceptedTime, value);
hbaseTemplate.put(APPLICATION_TRACE_INDEX, put);
}
hbaseTemplate.put(APPLICATION_TRACE_INDEX, put);
}
private byte[] makeQualifier(final TSpan span) {
boolean useIndexedQualifier = false;
byte[] qualifier;
private byte[] makeQualifier(final TSpan span) {
boolean useIndexedQualifier = false;
byte[] qualifier;
if (useIndexedQualifier) {
final Buffer columnName = new AutomaticBuffer(16);
// FIXME putVar not used in order to utilize hbase column prefix filter
columnName.put(span.getElapsed());
columnName.put(SpanUtils.getVarTransactionId(span));
qualifier = columnName.getBuffer();
} else {
// OLD
// byte[] transactionId = SpanUtils.getTransactionId(span);
qualifier = SpanUtils.getVarTransactionId(span);
}
return qualifier;
}
if (useIndexedQualifier) {
final Buffer columnName = new AutomaticBuffer(16);
// FIXME putVar not used in order to utilize hbase column prefix filter
columnName.put(span.getElapsed());
columnName.put(SpanUtils.getVarTransactionId(span));
qualifier = columnName.getBuffer();
} else {
// OLD
// byte[] transactionId = SpanUtils.getTransactionId(span);
qualifier = SpanUtils.getVarTransactionId(span);
}
return qualifier;
}
private byte[] crateRowKey(TSpan span, long acceptedTime) {
// distribute key evenly
byte[] applicationTraceIndexRowKey = SpanUtils.getApplicationTraceIndexRowKey(span.getApplicationName(), acceptedTime);
@@ -41,13 +41,13 @@ import org.springframework.stereotype.Repository;
@Repository
public class HbaseHostApplicationMapDao implements HostApplicationMapDao {
private final Logger logger = LoggerFactory.getLogger(this.getClass());
private final Logger logger = LoggerFactory.getLogger(this.getClass());
@Autowired
private HbaseOperations2 hbaseTemplate;
@Autowired
private HbaseOperations2 hbaseTemplate;
@Autowired
private AcceptedTimeService acceptedTimeService;
@Autowired
private AcceptedTimeService acceptedTimeService;
@Autowired
private TimeSlot timeSlot;
@@ -60,8 +60,8 @@ public class HbaseHostApplicationMapDao implements HostApplicationMapDao {
private final AtomicLongUpdateMap<CacheKey> updater = new AtomicLongUpdateMap<CacheKey>();
@Override
public void insert(String host, String bindApplicationName, short bindServiceType, String parentApplicationName, short parentServiceType) {
@Override
public void insert(String host, String bindApplicationName, short bindServiceType, String parentApplicationName, short parentServiceType) {
if (host == null) {
throw new NullPointerException("host must not be null");
}
@@ -76,7 +76,7 @@ public class HbaseHostApplicationMapDao implements HostApplicationMapDao {
if (needUpdate) {
insertHostVer2(host, bindApplicationName, bindServiceType, statisticsRowSlot, parentApplicationName, parentServiceType);
}
}
}
private long getSlotTime() {
@@ -95,7 +95,7 @@ public class HbaseHostApplicationMapDao implements HostApplicationMapDao {
// TODO should consider to add bellow codes again later.
//String parentAgentId = null;
//final byte[] rowKey = createRowKey(parentApplicationName, parentServiceType, statisticsRowSlot, parentAgentId);
final byte[] rowKey = createRowKey(parentApplicationName, parentServiceType, statisticsRowSlot, null);
final byte[] rowKey = createRowKey(parentApplicationName, parentServiceType, statisticsRowSlot, null);
byte[] columnName = createColumnName(host, bindApplicationName, bindServiceType);
@@ -46,13 +46,13 @@ import static com.navercorp.pinpoint.common.hbase.HBaseTables.*;
@Repository
public class HbaseMapResponseTimeDao implements MapResponseTimeDao {
private final Logger logger = LoggerFactory.getLogger(this.getClass());
private final Logger logger = LoggerFactory.getLogger(this.getClass());
@Autowired
private HbaseOperations2 hbaseTemplate;
@Autowired
private HbaseOperations2 hbaseTemplate;
@Autowired
private AcceptedTimeService acceptedTimeService;
@Autowired
private AcceptedTimeService acceptedTimeService;
@Autowired
private TimeSlot timeSlot;
@@ -61,17 +61,17 @@ public class HbaseMapResponseTimeDao implements MapResponseTimeDao {
@Qualifier("selfMerge")
private RowKeyMerge rowKeyMerge;
private final boolean useBulk;
private final boolean useBulk;
private final ConcurrentCounterMap<RowInfo> counter = new ConcurrentCounterMap<RowInfo>();
public HbaseMapResponseTimeDao() {
public HbaseMapResponseTimeDao() {
this(true);
}
}
public HbaseMapResponseTimeDao(boolean useBulk) {
this.useBulk = useBulk;
}
public HbaseMapResponseTimeDao(boolean useBulk) {
this.useBulk = useBulk;
}
@Override
public void received(String applicationName, short applicationServiceType, String agentId, int elapsed, boolean isError) {
@@ -82,29 +82,29 @@ public class HbaseMapResponseTimeDao implements MapResponseTimeDao {
throw new NullPointerException("agentId must not be null");
}
if (logger.isDebugEnabled()) {
logger.debug("[Received] {} ({})[{}]",
if (logger.isDebugEnabled()) {
logger.debug("[Received] {} ({})[{}]",
applicationName, ServiceType.findServiceType(applicationServiceType), agentId);
}
}
// make row key. rowkey is me
final long acceptedTime = acceptedTimeService.getAcceptedTime();
final long rowTimeSlot = timeSlot.getTimeSlot(acceptedTime);
final long acceptedTime = acceptedTimeService.getAcceptedTime();
final long rowTimeSlot = timeSlot.getTimeSlot(acceptedTime);
final RowKey selfRowKey = new CallRowKey(applicationName, applicationServiceType, rowTimeSlot);
final short slotNumber = ApplicationMapStatisticsUtils.getSlotNumber(applicationServiceType, elapsed, isError);
final ColumnName selfColumnName = new ResponseColumnName(agentId, slotNumber);
if (useBulk) {
if (useBulk) {
RowInfo rowInfo = new DefaultRowInfo(selfRowKey, selfColumnName);
this.counter.increment(rowInfo, 1L);
} else {
} else {
final byte[] rowKey = selfRowKey.getRowKey();
// column name is the name of caller app.
byte[] columnName = selfColumnName.getColumnName();
increment(rowKey, columnName, 1L);
}
}
}
private void increment(byte[] rowKey, byte[] columnName, long increment) {
if (rowKey == null) {
@@ -117,11 +117,11 @@ public class HbaseMapResponseTimeDao implements MapResponseTimeDao {
}
@Override
public void flushAll() {
if (!useBulk) {
throw new IllegalStateException("useBulk is " + useBulk);
}
@Override
public void flushAll() {
if (!useBulk) {
throw new IllegalStateException("useBulk is " + useBulk);
}
// update statistics by rowkey and column for now. need to update it by rowkey later.
Map<RowInfo,ConcurrentCounterMap.LongAdder> remove = this.counter.remove();
@@ -133,5 +133,5 @@ public class HbaseMapResponseTimeDao implements MapResponseTimeDao {
hbaseTemplate.increment(MAP_STATISTICS_SELF, merge);
}
}
}
}
@@ -47,13 +47,13 @@ import java.util.Map;
@Repository
public class HbaseMapStatisticsCalleeDao implements MapStatisticsCalleeDao {
private final Logger logger = LoggerFactory.getLogger(this.getClass());
private final Logger logger = LoggerFactory.getLogger(this.getClass());
@Autowired
private HbaseOperations2 hbaseTemplate;
@Autowired
private HbaseOperations2 hbaseTemplate;
@Autowired
private AcceptedTimeService acceptedTimeService;
@Autowired
private AcceptedTimeService acceptedTimeService;
@Autowired
private TimeSlot timeSlot;
@@ -62,21 +62,21 @@ public class HbaseMapStatisticsCalleeDao implements MapStatisticsCalleeDao {
@Qualifier("calleeMerge")
private RowKeyMerge rowKeyMerge;
private final boolean useBulk;
private final boolean useBulk;
private final ConcurrentCounterMap<RowInfo> counter = new ConcurrentCounterMap<RowInfo>();
public HbaseMapStatisticsCalleeDao() {
public HbaseMapStatisticsCalleeDao() {
this(true);
}
}
public HbaseMapStatisticsCalleeDao(boolean useBulk) {
this.useBulk = useBulk;
}
public HbaseMapStatisticsCalleeDao(boolean useBulk) {
this.useBulk = useBulk;
}
@Override
public void update(String calleeApplicationName, short calleeServiceType, String callerApplicationName, short callerServiceType, String callerHost, int elapsed, boolean isError) {
public void update(String calleeApplicationName, short calleeServiceType, String callerApplicationName, short callerServiceType, String callerHost, int elapsed, boolean isError) {
if (callerApplicationName == null) {
throw new NullPointerException("callerApplicationName must not be null");
}
@@ -88,31 +88,31 @@ public class HbaseMapStatisticsCalleeDao implements MapStatisticsCalleeDao {
logger.debug("[Callee] {} ({}) <- {} ({})[{}]",
calleeApplicationName, ServiceType.findServiceType(calleeServiceType),
callerApplicationName, ServiceType.findServiceType(callerServiceType), callerHost);
}
}
// there may be no endpoint in case of httpclient
callerHost = StringUtils.defaultString(callerHost);
callerHost = StringUtils.defaultString(callerHost);
// make row key. rowkey is me
final long acceptedTime = acceptedTimeService.getAcceptedTime();
final long rowTimeSlot = timeSlot.getTimeSlot(acceptedTime);
// make row key. rowkey is me
final long acceptedTime = acceptedTimeService.getAcceptedTime();
final long rowTimeSlot = timeSlot.getTimeSlot(acceptedTime);
final RowKey calleeRowKey = new CallRowKey(calleeApplicationName, calleeServiceType, rowTimeSlot);
final short callerSlotNumber = ApplicationMapStatisticsUtils.getSlotNumber(callerServiceType, elapsed, isError);
final ColumnName callerColumnName = new CallerColumnName(callerServiceType, callerApplicationName, callerHost, callerSlotNumber);
if (useBulk) {
if (useBulk) {
RowInfo rowInfo = new DefaultRowInfo(calleeRowKey, callerColumnName);
counter.increment(rowInfo, 1L);
} else {
} else {
final byte[] rowKey = calleeRowKey.getRowKey();
// column name is the name of caller app.
byte[] columnName = callerColumnName.getColumnName();
increment(rowKey, columnName, 1L);
}
}
}
@@ -127,10 +127,10 @@ public class HbaseMapStatisticsCalleeDao implements MapStatisticsCalleeDao {
}
@Override
public void flushAll() {
if (!useBulk) {
throw new IllegalStateException();
}
public void flushAll() {
if (!useBulk) {
throw new IllegalStateException();
}
Map<RowInfo, ConcurrentCounterMap.LongAdder> remove = this.counter.remove();
List<Increment> merge = rowKeyMerge.createBulkIncrement(remove);
@@ -47,13 +47,13 @@ import java.util.Map;
@Repository
public class HbaseMapStatisticsCallerDao implements MapStatisticsCallerDao {
private final Logger logger = LoggerFactory.getLogger(this.getClass());
private final Logger logger = LoggerFactory.getLogger(this.getClass());
@Autowired
private HbaseOperations2 hbaseTemplate;
@Autowired
private HbaseOperations2 hbaseTemplate;
@Autowired
private AcceptedTimeService acceptedTimeService;
@Autowired
private AcceptedTimeService acceptedTimeService;
@Autowired
@Qualifier("callerMerge")
@@ -62,20 +62,20 @@ public class HbaseMapStatisticsCallerDao implements MapStatisticsCallerDao {
@Autowired
private TimeSlot timeSlot;
private final boolean useBulk;
private final boolean useBulk;
private final ConcurrentCounterMap<RowInfo> counter = new ConcurrentCounterMap<RowInfo>();
public HbaseMapStatisticsCallerDao() {
public HbaseMapStatisticsCallerDao() {
this(true);
}
}
public HbaseMapStatisticsCallerDao(boolean useBulk) {
this.useBulk = useBulk;
}
public HbaseMapStatisticsCallerDao(boolean useBulk) {
this.useBulk = useBulk;
}
@Override
public void update(String callerApplicationName, short callerServiceType, String callerAgentid, String calleeApplicationName, short calleeServiceType, String calleeHost, int elapsed, boolean isError) {
public void update(String callerApplicationName, short callerServiceType, String callerAgentid, String calleeApplicationName, short calleeServiceType, String calleeHost, int elapsed, boolean isError) {
if (callerApplicationName == null) {
throw new NullPointerException("callerApplicationName must not be null");
}
@@ -83,32 +83,32 @@ public class HbaseMapStatisticsCallerDao implements MapStatisticsCallerDao {
throw new NullPointerException("calleeApplicationName must not be null");
}
if (logger.isDebugEnabled()) {
logger.debug("[Caller] {} ({}) {} -> {} ({})[{}]",
if (logger.isDebugEnabled()) {
logger.debug("[Caller] {} ({}) {} -> {} ({})[{}]",
callerApplicationName, ServiceType.findServiceType(callerServiceType), callerAgentid,
calleeApplicationName, ServiceType.findServiceType(calleeServiceType), calleeHost);
}
}
// there may be no endpoint in case of httpclient
calleeHost = StringUtils.defaultString(calleeHost);
// make row key. rowkey is me
final long acceptedTime = acceptedTimeService.getAcceptedTime();
final long rowTimeSlot = timeSlot.getTimeSlot(acceptedTime);
final long acceptedTime = acceptedTimeService.getAcceptedTime();
final long rowTimeSlot = timeSlot.getTimeSlot(acceptedTime);
final RowKey callerRowKey = new CallRowKey(callerApplicationName, callerServiceType, rowTimeSlot);
final short calleeSlotNumber = ApplicationMapStatisticsUtils.getSlotNumber(calleeServiceType, elapsed, isError);
final ColumnName calleeColumnName = new CalleeColumnName(callerAgentid, calleeServiceType, calleeApplicationName, calleeHost, calleeSlotNumber);
if (useBulk) {
if (useBulk) {
RowInfo rowInfo = new DefaultRowInfo(callerRowKey, calleeColumnName);
this.counter.increment(rowInfo, 1L);
} else {
} else {
final byte[] rowKey = callerRowKey.getRowKey();
// column name is the name of caller app.
byte[] columnName = calleeColumnName.getColumnName();
increment(rowKey, columnName, 1L);
}
}
}
private void increment(byte[] rowKey, byte[] columnName, long increment) {
if (rowKey == null) {
@@ -121,11 +121,11 @@ public class HbaseMapStatisticsCallerDao implements MapStatisticsCallerDao {
}
@Override
public void flushAll() {
if (!useBulk) {
throw new IllegalStateException();
}
@Override
public void flushAll() {
if (!useBulk) {
throw new IllegalStateException();
}
// update statistics by rowkey and column for now. need to update it by rowkey later.
Map<RowInfo,ConcurrentCounterMap.LongAdder> remove = this.counter.remove();
List<Increment> merge = rowKeyMerge.createBulkIncrement(remove);
@@ -136,5 +136,5 @@ public class HbaseMapStatisticsCallerDao implements MapStatisticsCallerDao {
hbaseTemplate.increment(MAP_STATISTICS_CALLEE, merge);
}
}
}
}
@@ -34,48 +34,48 @@ import com.navercorp.pinpoint.thrift.dto.TResult;
@Service("agentInfoHandler")
public class AgentInfoHandler implements SimpleHandler, RequestResponseHandler {
private final Logger logger = LoggerFactory.getLogger(AgentInfoHandler.class.getName());
private final Logger logger = LoggerFactory.getLogger(AgentInfoHandler.class.getName());
@Autowired
private AgentInfoDao agentInfoDao;
@Autowired
private AgentInfoDao agentInfoDao;
@Autowired
private ApplicationIndexDao applicationIndexDao;
@Autowired
private ApplicationIndexDao applicationIndexDao;
public void handleSimple(TBase<?, ?> tbase) {
handleRequest(tbase);
}
@Override
public TBase<?, ?> handleRequest(TBase<?, ?> tbase) {
if (!(tbase instanceof TAgentInfo)) {
logger.warn("invalid tbase:{}", tbase);
// it happens to return null not only at this BO(Business Object) but also at other BOs.
public void handleSimple(TBase<?, ?> tbase) {
handleRequest(tbase);
}
return null;
}
@Override
public TBase<?, ?> handleRequest(TBase<?, ?> tbase) {
if (!(tbase instanceof TAgentInfo)) {
logger.warn("invalid tbase:{}", tbase);
// it happens to return null not only at this BO(Business Object) but also at other BOs.
try {
TAgentInfo agentInfo = (TAgentInfo) tbase;
return null;
}
logger.debug("Received AgentInfo={}", agentInfo);
try {
TAgentInfo agentInfo = (TAgentInfo) tbase;
// agent info
agentInfoDao.insert(agentInfo);
logger.debug("Received AgentInfo={}", agentInfo);
// for querying agentid using applicationname
applicationIndexDao.insert(agentInfo);
return new TResult(true);
// agent info
agentInfoDao.insert(agentInfo);
// for querying agentid using applicationname
applicationIndexDao.insert(agentInfo);
return new TResult(true);
// for querying applicationname using agentid
// agentIdApplicationIndexDao.insert(agentInfo.getAgentId(), agentInfo.getApplicationName());
} catch (Exception e) {
logger.warn("AgentInfo handle error. Caused:{}", e.getMessage(), e);
TResult result = new TResult(false);
result.setMessage(e.getMessage());
return result;
}
}
// for querying applicationname using agentid
// agentIdApplicationIndexDao.insert(agentInfo.getAgentId(), agentInfo.getApplicationName());
} catch (Exception e) {
logger.warn("AgentInfo handle error. Caused:{}", e.getMessage(), e);
TResult result = new TResult(false);
result.setMessage(e.getMessage());
return result;
}
}
}
@@ -32,24 +32,24 @@ import org.springframework.stereotype.Service;
@Service
public class ApiMetaDataHandler implements RequestResponseHandler {
private final Logger logger = LoggerFactory.getLogger(getClass());
private final Logger logger = LoggerFactory.getLogger(getClass());
@Autowired
private ApiMetaDataDao sqlMetaDataDao;
@Autowired
private ApiMetaDataDao sqlMetaDataDao;
@Override
public TBase<?, ?> handleRequest(TBase<?, ?> tbase) {
if (!(tbase instanceof TApiMetaData)) {
logger.error("invalid tbase:{}", tbase);
return null;
}
TApiMetaData apiMetaData = (TApiMetaData) tbase;
@Override
public TBase<?, ?> handleRequest(TBase<?, ?> tbase) {
if (!(tbase instanceof TApiMetaData)) {
logger.error("invalid tbase:{}", tbase);
return null;
}
// Because api meta data is important , logging it at info level.
if (logger.isInfoEnabled()) {
logger.info("Received ApiMetaData={}", apiMetaData);
}
TApiMetaData apiMetaData = (TApiMetaData) tbase;
// Because api meta data is important , logging it at info level.
if (logger.isInfoEnabled()) {
logger.info("Received ApiMetaData={}", apiMetaData);
}
try {
sqlMetaDataDao.insert(apiMetaData);
@@ -60,5 +60,5 @@ public class ApiMetaDataHandler implements RequestResponseHandler {
return result;
}
return new TResult(true);
}
}
}
@@ -23,7 +23,7 @@ import org.apache.thrift.TBase;
* @author koo.taejin
*/
public interface Handler {
void handle(TBase<?, ?> tbase, byte[] packet, int offset, int length);
}
@@ -25,7 +25,7 @@ import org.springframework.stereotype.Service;
*/
@Service
public interface RequestResponseHandler {
TBase<?, ?> handleRequest(TBase<?, ?> tbase);
}
@@ -23,7 +23,7 @@ import org.apache.thrift.TBase;
* @author koo.taejin
*/
public interface SimpleHandler {
void handleSimple(TBase<?, ?> tbase);
}
@@ -37,57 +37,57 @@ import org.springframework.stereotype.Service;
@Service
public class SpanChunkHandler implements SimpleHandler {
private final Logger logger = LoggerFactory.getLogger(getClass());
private final Logger logger = LoggerFactory.getLogger(getClass());
@Autowired
private TracesDao traceDao;
@Autowired
private TracesDao traceDao;
@Autowired
private StatisticsHandler statisticsHandler;
@Autowired
private StatisticsHandler statisticsHandler;
@Override
public void handleSimple(TBase<?, ?> tbase) {
@Override
public void handleSimple(TBase<?, ?> tbase) {
if (!(tbase instanceof TSpanChunk)) {
throw new IllegalArgumentException("unexpected tbase:" + tbase + " expected:" + this.getClass().getName());
}
if (!(tbase instanceof TSpanChunk)) {
throw new IllegalArgumentException("unexpected tbase:" + tbase + " expected:" + this.getClass().getName());
}
try {
TSpanChunk spanChunk = (TSpanChunk) tbase;
try {
TSpanChunk spanChunk = (TSpanChunk) tbase;
if (logger.isDebugEnabled()) {
logger.debug("Received SpanChunk={}", spanChunk);
}
if (logger.isDebugEnabled()) {
logger.debug("Received SpanChunk={}", spanChunk);
}
traceDao.insertSpanChunk(spanChunk);
traceDao.insertSpanChunk(spanChunk);
List<TSpanEvent> spanEventList = spanChunk.getSpanEventList();
if (spanEventList != null) {
logger.debug("SpanChunk Size:{}", spanEventList.size());
// TODO need to batch update later.
for (TSpanEvent spanEvent : spanEventList) {
final ServiceType serviceType = ServiceType.findServiceType(spanEvent.getServiceType());
List<TSpanEvent> spanEventList = spanChunk.getSpanEventList();
if (spanEventList != null) {
logger.debug("SpanChunk Size:{}", spanEventList.size());
// TODO need to batch update later.
for (TSpanEvent spanEvent : spanEventList) {
final ServiceType serviceType = ServiceType.findServiceType(spanEvent.getServiceType());
if (!serviceType.isRecordStatistics()) {
continue;
}
if (!serviceType.isRecordStatistics()) {
continue;
}
// if terminal update statistics
final int elapsed = spanEvent.getEndElapsed();
final boolean hasException = SpanEventUtils.hasException(spanEvent);
// if terminal update statistics
final int elapsed = spanEvent.getEndElapsed();
final boolean hasException = SpanEventUtils.hasException(spanEvent);
/**
* save information to draw a server map based on statistics
*/
// save the information of caller (the spanevent that span called)
statisticsHandler.updateCaller(spanChunk.getApplicationName(), spanChunk.getServiceType(), spanChunk.getAgentId(), spanEvent.getDestinationId(), serviceType.getCode(), spanEvent.getEndPoint(), elapsed, hasException);
/**
* save information to draw a server map based on statistics
*/
// save the information of caller (the spanevent that span called)
statisticsHandler.updateCaller(spanChunk.getApplicationName(), spanChunk.getServiceType(), spanChunk.getAgentId(), spanEvent.getDestinationId(), serviceType.getCode(), spanEvent.getEndPoint(), elapsed, hasException);
// save the information of callee (the span that called spanevent)
statisticsHandler.updateCallee(spanEvent.getDestinationId(), spanEvent.getServiceType(), spanChunk.getApplicationName(), spanChunk.getServiceType(), spanChunk.getEndPoint(), elapsed, hasException);
}
}
} catch (Exception e) {
logger.warn("SpanChunk handle error Caused:{}", e.getMessage(), e);
}
}
// save the information of callee (the span that called spanevent)
statisticsHandler.updateCallee(spanEvent.getDestinationId(), spanEvent.getServiceType(), spanChunk.getApplicationName(), spanChunk.getServiceType(), spanChunk.getEndPoint(), elapsed, hasException);
}
}
} catch (Exception e) {
logger.warn("SpanChunk handle error Caused:{}", e.getMessage(), e);
}
}
}
@@ -41,43 +41,43 @@ import org.springframework.stereotype.Service;
@Service
public class SpanHandler implements SimpleHandler {
private final Logger logger = LoggerFactory.getLogger(getClass());
private final Logger logger = LoggerFactory.getLogger(getClass());
@Autowired
private TracesDao traceDao;
@Autowired
private TracesDao traceDao;
@Autowired
private ApplicationTraceIndexDao applicationTraceIndexDao;
@Autowired
private ApplicationTraceIndexDao applicationTraceIndexDao;
@Autowired
private StatisticsHandler statisticsHandler;
@Autowired
private StatisticsHandler statisticsHandler;
@Autowired
private HostApplicationMapDao hostApplicationMapDao;
@Autowired
private HostApplicationMapDao hostApplicationMapDao;
public void handleSimple(TBase<?, ?> tbase) {
public void handleSimple(TBase<?, ?> tbase) {
if (!(tbase instanceof TSpan)) {
throw new IllegalArgumentException("unexpected tbase:" + tbase + " expected:" + this.getClass().getName());
}
if (!(tbase instanceof TSpan)) {
throw new IllegalArgumentException("unexpected tbase:" + tbase + " expected:" + this.getClass().getName());
}
try {
final TSpan span = (TSpan) tbase;
if (logger.isDebugEnabled()) {
logger.debug("Received SPAN={}", span);
}
try {
final TSpan span = (TSpan) tbase;
if (logger.isDebugEnabled()) {
logger.debug("Received SPAN={}", span);
}
traceDao.insert(span);
applicationTraceIndexDao.insert(span);
applicationTraceIndexDao.insert(span);
// insert statistics info for server map
insertAcceptorHost(span);
insertSpanStat(span);
insertSpanEventStat(span);
} catch (Exception e) {
logger.warn("Span handle error. Caused:{}. Span:{}",e.getMessage(), tbase, e);
}
}
} catch (Exception e) {
logger.warn("Span handle error. Caused:{}. Span:{}",e.getMessage(), tbase, e);
}
}
private void insertSpanStat(TSpan span) {
// TODO consider to change span.isSetErr();
@@ -31,24 +31,24 @@ import org.springframework.stereotype.Service;
*/
@Service
public class SqlMetaDataHandler implements RequestResponseHandler {
private final Logger logger = LoggerFactory.getLogger(getClass());
private final Logger logger = LoggerFactory.getLogger(getClass());
@Autowired
private SqlMetaDataDao sqlMetaDataDao;
@Autowired
private SqlMetaDataDao sqlMetaDataDao;
@Override
public TBase<?, ?> handleRequest(TBase<?, ?> tbase) {
if (!(tbase instanceof TSqlMetaData)) {
logger.error("invalid tbase:{}", tbase);
return null;
}
TSqlMetaData sqlMetaData = (TSqlMetaData) tbase;
if (logger.isInfoEnabled()) {
logger.info("Received SqlMetaData:{}", sqlMetaData);
}
@Override
public TBase<?, ?> handleRequest(TBase<?, ?> tbase) {
if (!(tbase instanceof TSqlMetaData)) {
logger.error("invalid tbase:{}", tbase);
return null;
}
TSqlMetaData sqlMetaData = (TSqlMetaData) tbase;
if (logger.isInfoEnabled()) {
logger.info("Received SqlMetaData:{}", sqlMetaData);
}
try {
sqlMetaDataDao.insert(sqlMetaData);
@@ -59,5 +59,5 @@ public class SqlMetaDataHandler implements RequestResponseHandler {
return result;
}
return new TResult(true);
}
}
}
@@ -31,11 +31,11 @@ import org.springframework.stereotype.Service;
@Service
public class StatisticsHandler {
@Autowired
private MapStatisticsCalleeDao mapStatisticsCalleeDao;
@Autowired
private MapStatisticsCalleeDao mapStatisticsCalleeDao;
@Autowired
private MapStatisticsCallerDao mapStatisticsCallerDao;
@Autowired
private MapStatisticsCallerDao mapStatisticsCallerDao;
@Autowired
private MapResponseTimeDao mapResponseTimeDao;
@@ -54,9 +54,9 @@ public class StatisticsHandler {
* @param elapsed
* @param isError
*/
public void updateCaller(String callerApplicationName, short callerServiceType, String callerAgentId, String calleeApplicationName, short calleeServiceType, String calleeHost, int elapsed, boolean isError) {
mapStatisticsCallerDao.update(callerApplicationName, callerServiceType, callerAgentId, calleeApplicationName, calleeServiceType, calleeHost, elapsed, isError);
}
public void updateCaller(String callerApplicationName, short callerServiceType, String callerAgentId, String calleeApplicationName, short calleeServiceType, String calleeHost, int elapsed, boolean isError) {
mapStatisticsCallerDao.update(callerApplicationName, callerServiceType, callerAgentId, calleeApplicationName, calleeServiceType, calleeHost, elapsed, isError);
}
/**
* Calling MySQL from Tomcat generates the following message for the callee(MySQL) :<br/>
@@ -72,9 +72,9 @@ public class StatisticsHandler {
* @param elapsed
* @param isError
*/
public void updateCallee(String calleeApplicationName, short calleeServiceType, String callerApplicationName, short callerServiceType, String callerHost, int elapsed, boolean isError) {
mapStatisticsCalleeDao.update(calleeApplicationName, calleeServiceType, callerApplicationName, callerServiceType, callerHost, elapsed, isError);
}
public void updateCallee(String calleeApplicationName, short calleeServiceType, String callerApplicationName, short callerServiceType, String callerHost, int elapsed, boolean isError) {
mapStatisticsCalleeDao.update(calleeApplicationName, calleeServiceType, callerApplicationName, callerServiceType, callerHost, elapsed, isError);
}
public void updateResponseTime(String applicationName, short serviceType, String agentId, int elapsed, boolean isError) {
mapResponseTimeDao.received(applicationName, serviceType, agentId, elapsed, isError);
@@ -32,23 +32,23 @@ import org.springframework.stereotype.Service;
@Service
public class StringMetaDataHandler implements RequestResponseHandler {
private final Logger logger = LoggerFactory.getLogger(getClass());
private final Logger logger = LoggerFactory.getLogger(getClass());
@Autowired
private StringMetaDataDao stringMetaDataDao;
@Autowired
private StringMetaDataDao stringMetaDataDao;
@Override
public TBase<?, ?> handleRequest(TBase<?, ?> tbase) {
if (!(tbase instanceof TStringMetaData)) {
logger.error("invalid tbase:{}", tbase);
return null;
}
TStringMetaData stringMetaData = (TStringMetaData) tbase;
// because api data is important, logging it at info level
if (logger.isInfoEnabled()) {
logger.info("Received StringMetaData={}", stringMetaData);
}
@Override
public TBase<?, ?> handleRequest(TBase<?, ?> tbase) {
if (!(tbase instanceof TStringMetaData)) {
logger.error("invalid tbase:{}", tbase);
return null;
}
TStringMetaData stringMetaData = (TStringMetaData) tbase;
// because api data is important, logging it at info level
if (logger.isInfoEnabled()) {
logger.info("Received StringMetaData={}", stringMetaData);
}
try {
stringMetaDataDao.insert(stringMetaData);
@@ -59,5 +59,5 @@ public class StringMetaDataHandler implements RequestResponseHandler {
return result;
}
return new TResult(true);
}
}
}
@@ -26,24 +26,24 @@ import org.springframework.stereotype.Component;
@Component
@Deprecated
public class ApplicationNameMapper implements RowMapper<String> {
@Override
public String mapRow(Result result, int rowNum) throws Exception {
@Override
public String mapRow(Result result, int rowNum) throws Exception {
if (result.isEmpty()) {
return null;
}
KeyValue[] raw = result.raw();
KeyValue[] raw = result.raw();
if (raw.length == 0) {
return null;
}
if (raw.length == 0) {
return null;
}
String[] ret = new String[raw.length];
int index = 0;
String[] ret = new String[raw.length];
int index = 0;
for (KeyValue kv : raw) {
ret[index++] = BytesUtils.toString(kv.getQualifier());
}
for (KeyValue kv : raw) {
ret[index++] = BytesUtils.toString(kv.getQualifier());
}
return ret[0];
}
return ret[0];
}
}
@@ -20,7 +20,7 @@ package com.navercorp.pinpoint.collector.receiver;
* @author emeroad
*/
public interface DataReceiver {
void start();
void start();
void shutdown();
void shutdown();
}
@@ -24,10 +24,10 @@ import org.apache.thrift.TBase;
*/
public interface DispatchHandler {
// Separating Send and Request. That dose not be satisfied but try to change that later.
void dispatchSendMessage(TBase<?, ?> tBase, byte[] packet, int offset, int length);
// Separating Send and Request. That dose not be satisfied but try to change that later.
void dispatchSendMessage(TBase<?, ?> tBase, byte[] packet, int offset, int length);
TBase dispatchRequestMessage(TBase<?, ?> tBase, byte[] packet, int offset, int length);
TBase dispatchRequestMessage(TBase<?, ?> tBase, byte[] packet, int offset, int length);
}
@@ -67,7 +67,7 @@ public class TcpDispatchHandler extends AbstractDispatchHandler {
return stringMetaDataHandler;
}
if (tBase instanceof TAgentInfo) {
return agentInfoHandler;
return agentInfoHandler;
}
return null;
}
@@ -25,52 +25,52 @@ import com.navercorp.pinpoint.rpc.util.ClassUtils;
*/
public enum AgentHandshakePropertyType {
SUPPORT_SERVER("supportServer", Boolean.class),
SUPPORT_SERVER("supportServer", Boolean.class),
HOSTNAME("hostName", String.class),
IP("ip", String.class),
AGENT_ID("agentId", String.class),
APPLICATION_NAME("applicationName", String.class),
SERVICE_TYPE("serviceType", Integer.class),
PID("pid", Integer.class),
VERSION("version", String.class),
START_TIMESTAMP("startTimestamp", Long.class);
HOSTNAME("hostName", String.class),
IP("ip", String.class),
AGENT_ID("agentId", String.class),
APPLICATION_NAME("applicationName", String.class),
SERVICE_TYPE("serviceType", Integer.class),
PID("pid", Integer.class),
VERSION("version", String.class),
START_TIMESTAMP("startTimestamp", Long.class);
private final String name;
private final Class clazzType;
private AgentHandshakePropertyType(String name, Class clazzType) {
this.name = name;
this.clazzType = clazzType;
}
public String getName() {
return name;
}
public Class getClazzType() {
return clazzType;
}
public static boolean hasAllType(Map<Object, Object> properties) {
for (AgentHandshakePropertyType type : AgentHandshakePropertyType.values()) {
Object value = properties.get(type.getName());
if (type == SUPPORT_SERVER) {
continue;
}
private final String name;
private final Class clazzType;
if (value == null) {
return false;
}
if (!ClassUtils.isAssignable(value.getClass(), type.getClazzType())) {
return false;
}
}
return true;
}
private AgentHandshakePropertyType(String name, Class clazzType) {
this.name = name;
this.clazzType = clazzType;
}
public String getName() {
return name;
}
public Class getClazzType() {
return clazzType;
}
public static boolean hasAllType(Map<Object, Object> properties) {
for (AgentHandshakePropertyType type : AgentHandshakePropertyType.values()) {
Object value = properties.get(type.getName());
if (type == SUPPORT_SERVER) {
continue;
}
if (value == null) {
return false;
}
if (!ClassUtils.isAssignable(value.getClass(), type.getClazzType())) {
return false;
}
}
return true;
}
}
@@ -68,10 +68,10 @@ import com.navercorp.pinpoint.thrift.util.SerializationUtils;
*/
public class TCPReceiver {
private final Logger logger = LoggerFactory.getLogger(TCPReceiver.class);
private final Logger logger = LoggerFactory.getLogger(TCPReceiver.class);
private final ThreadFactory THREAD_FACTORY = new PinpointThreadFactory("Pinpoint-TCP-Worker");
private final PinpointServerSocket pinpointServerSocket;
private final PinpointServerSocket pinpointServerSocket;
private final DispatchHandler dispatchHandler;
private final String bindAddress;
private final int port;
@@ -90,7 +90,7 @@ public class TCPReceiver {
public TCPReceiver(DispatchHandler dispatchHandler, String bindAddress, int port) {
this(dispatchHandler, bindAddress, port, null);
this(dispatchHandler, bindAddress, port, null);
}
public TCPReceiver(DispatchHandler dispatchHandler, String bindAddress, int port, ZookeeperClusterService service) {
@@ -102,43 +102,43 @@ public class TCPReceiver {
}
if (service == null || !service.isEnable()) {
this.pinpointServerSocket = new PinpointServerSocket();
this.pinpointServerSocket = new PinpointServerSocket();
} else {
this.pinpointServerSocket = new PinpointServerSocket(service.getChannelStateChangeEventListener());
this.pinpointServerSocket = new PinpointServerSocket(service.getChannelStateChangeEventListener());
}
this.dispatchHandler = dispatchHandler;
this.bindAddress = bindAddress;
this.port = port;
}
}
private void setL4TcpChannel(PinpointServerSocket pinpointServerSocket) {
if (l4ipList == null) {
return;
}
try {
List<InetAddress> inetAddressList = new ArrayList<InetAddress>();
for (int i = 0; i < l4ipList.size(); i++) {
String l4Ip = l4ipList.get(i);
if (StringUtils.isBlank(l4Ip)) {
continue;
}
InetAddress address = InetAddress.getByName(l4Ip);
if (address != null) {
inetAddressList.add(address);
}
List<InetAddress> inetAddressList = new ArrayList<InetAddress>();
for (int i = 0; i < l4ipList.size(); i++) {
String l4Ip = l4ipList.get(i);
if (StringUtils.isBlank(l4Ip)) {
continue;
}
InetAddress address = InetAddress.getByName(l4Ip);
if (address != null) {
inetAddressList.add(address);
}
}
InetAddress[] inetAddressArray = new InetAddress[inetAddressList.size()];
pinpointServerSocket.setIgnoreAddressList(inetAddressList.toArray(inetAddressArray));
InetAddress[] inetAddressArray = new InetAddress[inetAddressList.size()];
pinpointServerSocket.setIgnoreAddressList(inetAddressList.toArray(inetAddressArray));
} catch (UnknownHostException e) {
logger.warn("l4ipList error {}", l4ipList, e);
}
}
@PostConstruct
public void start() {
public void start() {
setL4TcpChannel(pinpointServerSocket);
// take care when attaching message handlers as events are generated from the IO thread.
// pass them to a separate queue and handle them in a different thread.
@@ -155,27 +155,27 @@ public class TCPReceiver {
@Override
public HandshakeResponseCode handleHandshake(Map properties) {
if (properties == null) {
return HandshakeResponseType.ProtocolError.PROTOCOL_ERROR;
}
boolean hasAllType = AgentHandshakePropertyType.hasAllType(properties);
if (!hasAllType) {
return HandshakeResponseType.PropertyError.PROPERTY_ERROR;
}
boolean supportServer = MapUtils.getBoolean(properties, AgentHandshakePropertyType.SUPPORT_SERVER.getName(), true);
if (supportServer) {
return HandshakeResponseType.Success.DUPLEX_COMMUNICATION;
} else {
if (properties == null) {
return HandshakeResponseType.ProtocolError.PROTOCOL_ERROR;
}
boolean hasAllType = AgentHandshakePropertyType.hasAllType(properties);
if (!hasAllType) {
return HandshakeResponseType.PropertyError.PROPERTY_ERROR;
}
boolean supportServer = MapUtils.getBoolean(properties, AgentHandshakePropertyType.SUPPORT_SERVER.getName(), true);
if (supportServer) {
return HandshakeResponseType.Success.DUPLEX_COMMUNICATION;
} else {
return HandshakeResponseType.Success.SIMPLEX_COMMUNICATION;
}
}
}
});
this.pinpointServerSocket.bind(bindAddress, port);
}
}
private void receive(SendPacket sendPacket, SocketChannel channel) {
try {
@@ -211,7 +211,7 @@ public class TCPReceiver {
@Override
public void run() {
try {
TBase<?, ?> tBase = SerializationUtils.deserialize(bytes, deserializerFactory);
TBase<?, ?> tBase = SerializationUtils.deserialize(bytes, deserializerFactory);
dispatchHandler.dispatchSendMessage(tBase, bytes, Header.HEADER_SIZE, bytes.length);
} catch (TException e) {
if (logger.isWarnEnabled()) {
@@ -251,7 +251,7 @@ public class TCPReceiver {
byte[] bytes = requestPacket.getPayload();
SocketAddress remoteAddress = socketChannel.getRemoteAddress();
try {
TBase<?, ?> tBase = SerializationUtils.deserialize(bytes, deserializerFactory);
TBase<?, ?> tBase = SerializationUtils.deserialize(bytes, deserializerFactory);
if (tBase instanceof L4Packet) {
if (logger.isDebugEnabled()) {
L4Packet packet = (L4Packet) tBase;
@@ -261,7 +261,7 @@ public class TCPReceiver {
}
TBase result = dispatchHandler.dispatchRequestMessage(tBase, bytes, Header.HEADER_SIZE, bytes.length);
if (result != null) {
byte[] resultBytes = SerializationUtils.serialize(result, serializerFactory);
byte[] resultBytes = SerializationUtils.serialize(result, serializerFactory);
socketChannel.sendResponseMessage(requestPacket, resultBytes);
}
} catch (TException e) {
@@ -152,7 +152,7 @@ public abstract class AbstractUDPReceiver implements DataReceiver {
try {
worker.execute(getPacketDispatcher(this, packet));
} catch (RejectedExecutionException ree) {
rejectedCounter.inc();
rejectedCounter.inc();
final int error = rejectedExecutionCount.incrementAndGet();
final int mod = 100;
if ((error % mod) == 0) {
@@ -23,14 +23,14 @@ import java.lang.management.ManagementFactory;
*/
public final class CollectorUtils {
private CollectorUtils() {
}
private CollectorUtils() {
}
public static String getServerIdentifier() {
public static String getServerIdentifier() {
// if the return value is not unique, it will be changed to MAC address or IP address.
// It means that the return value has format of "pid@hostname" (it is possible to be duplicate for "localhost")
return ManagementFactory.getRuntimeMXBean().getName();
}
// if the return value is not unique, it will be changed to MAC address or IP address.
// It means that the return value has format of "pid@hostname" (it is possible to be duplicate for "localhost")
return ManagementFactory.getRuntimeMXBean().getName();
}
}
@@ -31,42 +31,42 @@ import com.navercorp.pinpoint.common.buffer.OffsetFixedBuffer;
*/
public class HbaseApplicationTrraceIndexColumnTest {
@Test
public void indexedColumnName() {
final int elapsed = 1234;
final String agentId = "agentId";
final long agentStartTime = 1234567890L;
final long transactionSequence = 1234567890L;
@Test
public void indexedColumnName() {
final int elapsed = 1234;
final String agentId = "agentId";
final long agentStartTime = 1234567890L;
final long transactionSequence = 1234567890L;
// final Buffer buffer= new AutomaticBuffer(32);
// buffer.putPrefixedString(agentId);
// buffer.putSVar(transactionId.getAgentStartTime());
// buffer.putVar(transactionId.getTransactionSequence());
// return buffer.getBuffer();
// final Buffer buffer= new AutomaticBuffer(32);
// buffer.putPrefixedString(agentId);
// buffer.putSVar(transactionId.getAgentStartTime());
// buffer.putVar(transactionId.getTransactionSequence());
// return buffer.getBuffer();
final Buffer originalBuffer = new AutomaticBuffer(16);
originalBuffer.putVar(elapsed);
originalBuffer.putPrefixedString(agentId);
originalBuffer.putSVar(agentStartTime);
originalBuffer.putVar(transactionSequence);
final Buffer originalBuffer = new AutomaticBuffer(16);
originalBuffer.putVar(elapsed);
originalBuffer.putPrefixedString(agentId);
originalBuffer.putSVar(agentStartTime);
originalBuffer.putVar(transactionSequence);
byte[] source = originalBuffer.getBuffer();
byte[] source = originalBuffer.getBuffer();
final Buffer fetched = new OffsetFixedBuffer(source, 0);
final Buffer fetched = new OffsetFixedBuffer(source, 0);
Assert.assertEquals(elapsed, fetched.readVarInt());
Assert.assertEquals(agentId, fetched.readPrefixedString());
Assert.assertEquals(agentStartTime, fetched.readSVarLong());
Assert.assertEquals(transactionSequence, fetched.readVarLong());
}
Assert.assertEquals(elapsed, fetched.readVarInt());
Assert.assertEquals(agentId, fetched.readPrefixedString());
Assert.assertEquals(agentStartTime, fetched.readSVarLong());
Assert.assertEquals(transactionSequence, fetched.readVarLong());
}
@Test
public void indexColumnName2() {
final int elapsed = 1234;
final byte[] bytes = "thisisbytes".getBytes();
@Test
public void indexColumnName2() {
final int elapsed = 1234;
final byte[] bytes = "thisisbytes".getBytes();
final Buffer columnName = new AutomaticBuffer(16);
columnName.put(elapsed);
columnName.putPrefixedBytes(bytes);
}
final Buffer columnName = new AutomaticBuffer(16);
columnName.put(elapsed);
columnName.putPrefixedBytes(bytes);
}
}
@@ -59,8 +59,8 @@ public class NettyUdpReceiverTest {
latch.await();
} catch (InterruptedException e) {
}
logger.debug("server-shutdown");
udpServer.shutdown();
logger.debug("server-shutdown");
udpServer.shutdown();
}
});
thread.start();
@@ -96,7 +96,7 @@ public class NettyUdpReceiverTest {
so.send(datagramPacket);
Thread.sleep(10);
}
so.close();
so.close();
}
private ConnectionlessBootstrap createUdpServer() {
@@ -39,26 +39,26 @@ public class UDPReceiverTest {
@Test
@Ignore
public void startStop() {
try {
DataReceiver receiver = new BaseUDPReceiver("test", new DispatchHandler() {
public void startStop() {
try {
DataReceiver receiver = new BaseUDPReceiver("test", new DispatchHandler() {
@Override
public void dispatchSendMessage(TBase<?, ?> tBase, byte[] packet, int offset, int length) {
}
@Override
public TBase dispatchRequestMessage(TBase<?, ?> tBase, byte[] packet, int offset, int length) {
// TODO Auto-generated method stub
return null;
}
@Override
public TBase dispatchRequestMessage(TBase<?, ?> tBase, byte[] packet, int offset, int length) {
// TODO Auto-generated method stub
return null;
}
}, "127.0.0.1", 10999, 1024, 1, 10);
} catch (Exception e) {
e.printStackTrace();
Assert.fail(e.getMessage());
}
}
} catch (Exception e) {
e.printStackTrace();
Assert.fail(e.getMessage());
}
}
@Test
public void hostNullCheck() {
@@ -44,7 +44,7 @@ public class HistogramSchema {
// Should use the reference of FAST_SCHEMA, NORMAL created internally
private HistogramSchema(int typeCode, short fast, String fastName, short normal, String normalName, short slow, String slowName, String verySlowName, String errorName) {
this.typeCode = typeCode;
this.typeCode = typeCode;
this.fastSlot = new HistogramSlot(fast, SlotType.FAST, fastName);
this.normalSlot = new HistogramSlot(normal, SlotType.NORMAL, normalName);
this.slowSlot = new HistogramSlot(slow, SlotType.SLOW, slowName);
@@ -117,26 +117,26 @@ public class HistogramSchema {
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + typeCode;
return result;
}
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + typeCode;
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
HistogramSchema other = (HistogramSchema) obj;
if (typeCode != other.typeCode)
return false;
return true;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
HistogramSchema other = (HistogramSchema) obj;
if (typeCode != other.typeCode)
return false;
return true;
}
@Override
public String toString() {
@@ -36,8 +36,8 @@ public enum ServiceType {
// Undefined Service Code
UNDEFINED((short) -1, "UNDEFINED", TERMINAL, !RECORD_STATISTICS, !INCLUDE_DESTINATION, NORMAL_SCHEMA),
UNDEFINED((short) -1, "UNDEFINED", TERMINAL, !RECORD_STATISTICS, !INCLUDE_DESTINATION, NORMAL_SCHEMA),
// Callee node that agent hasn't been installed
UNKNOWN((short) 1, "UNKNOWN", !TERMINAL, RECORD_STATISTICS, !INCLUDE_DESTINATION, NORMAL_SCHEMA),
@@ -111,8 +111,8 @@ public enum ServiceType {
HTTP_CLIENT((short) 9050, "HTTP_CLIENT", !TERMINAL, RECORD_STATISTICS, !INCLUDE_DESTINATION, NORMAL_SCHEMA),
HTTP_CLIENT_INTERNAL((short) 9051, "HTTP_CLIENT", !TERMINAL, !RECORD_STATISTICS, !INCLUDE_DESTINATION, NORMAL_SCHEMA),
JDK_HTTPURLCONNECTOR((short) 9055, "JDK_HTTPCONNECTOR", !TERMINAL, RECORD_STATISTICS, !INCLUDE_DESTINATION, NORMAL_SCHEMA),
NPC_CLIENT((short) 9060, "NPC_CLIENT", !TERMINAL, RECORD_STATISTICS, !INCLUDE_DESTINATION, NORMAL_SCHEMA),
NIMM_CLIENT((short) 9070, "NIMM_CLIENT", !TERMINAL, RECORD_STATISTICS, !INCLUDE_DESTINATION, NORMAL_SCHEMA);
NPC_CLIENT((short) 9060, "NPC_CLIENT", !TERMINAL, RECORD_STATISTICS, !INCLUDE_DESTINATION, NORMAL_SCHEMA),
NIMM_CLIENT((short) 9070, "NIMM_CLIENT", !TERMINAL, RECORD_STATISTICS, !INCLUDE_DESTINATION, NORMAL_SCHEMA);
public static final short WAS_START_INDEX = 1000;
public static final short WAS_END_INDEX = 2000;
@@ -146,7 +146,7 @@ public enum ServiceType {
}
public boolean isInternalMethod() {
return this == INTERNAL_METHOD;
return this == INTERNAL_METHOD;
}
public boolean isRpcClient() {
@@ -162,14 +162,14 @@ public enum ServiceType {
return recordStatistics;
}
public boolean isUnknown() {
return this == ServiceType.UNKNOWN; // || this == ServiceType.UNKNOWN_CLOUD;
}
public boolean isUnknown() {
return this == ServiceType.UNKNOWN; // || this == ServiceType.UNKNOWN_CLOUD;
}
// return true when the service type is USER or can not be identified
public boolean isUser() {
return this == ServiceType.USER;
return this == ServiceType.USER;
}
public short getCode() {
@@ -192,9 +192,9 @@ public enum ServiceType {
return histogramSchema;
}
public boolean isWas() {
return isWas(this.code);
}
public boolean isWas() {
return isWas(this.code);
}
public static boolean isWas(final short code) {
return code >= WAS_START_INDEX && code < WAS_END_INDEX;
@@ -209,7 +209,7 @@ public enum ServiceType {
ServiceType serviceType = CODE_LOOKUP_TABLE.get(code);
if (serviceType == null) {
return UNDEFINED;
//return UNKNOWN;
//return UNKNOWN;
}
return serviceType;
}
@@ -22,7 +22,7 @@ package com.navercorp.pinpoint.common;
*
*/
public class ServiceTypeConstants {
public static final boolean TERMINAL = true;
public static final boolean RECORD_STATISTICS = true;
public static final boolean INCLUDE_DESTINATION = true;
public static final boolean TERMINAL = true;
public static final boolean RECORD_STATISTICS = true;
public static final boolean INCLUDE_DESTINATION = true;
}
@@ -18,5 +18,5 @@ package com.navercorp.pinpoint.common;
public enum SlotType {
FAST, NORMAL, SLOW, VERY_SLOW, ERROR
FAST, NORMAL, SLOW, VERY_SLOW, ERROR
}
@@ -24,11 +24,11 @@ import com.navercorp.pinpoint.common.ServiceType;
* @author emeroad
*/
public interface Span {
ServiceType getServiceType();
ServiceType getServiceType();
String getRpc();
String getRpc();
String getEndPoint();
List<AnnotationBo> getAnnotationBoList();
String getEndPoint();
List<AnnotationBo> getAnnotationBoList();
}
@@ -149,9 +149,9 @@ public class SpanBo implements com.navercorp.pinpoint.common.bo.Span {
this.version = (byte) (version & 0xFF);
}
public String getTransactionId() {
public String getTransactionId() {
return TransactionIdUtils.formatString(traceAgentId, traceAgentStartTime, traceTransactionSequence);
}
}
public String getAgentId() {
return agentId;
@@ -312,22 +312,22 @@ public class SpanBo implements com.navercorp.pinpoint.common.bo.Span {
}
public int getErrCode() {
return errCode;
}
return errCode;
}
public void setErrCode(int errCode) {
this.errCode = errCode;
}
public void setErrCode(int errCode) {
this.errCode = errCode;
}
public String getRemoteAddr() {
return remoteAddr;
}
return remoteAddr;
}
public void setRemoteAddr(String remoteAddr) {
this.remoteAddr = remoteAddr;
}
public void setRemoteAddr(String remoteAddr) {
this.remoteAddr = remoteAddr;
}
public long getCollectorAcceptTime() {
public long getCollectorAcceptTime() {
return collectorAcceptTime;
}
@@ -336,7 +336,7 @@ public class SpanBo implements com.navercorp.pinpoint.common.bo.Span {
}
public boolean isRoot() {
return -1L == parentSpanId;
return -1L == parentSpanId;
}
public boolean hasException() {
@@ -31,36 +31,36 @@ import com.navercorp.pinpoint.thrift.dto.*;
* @author emeroad
*/
public class SpanEventBo implements Span {
private static final int VERSION_SIZE = 1;
private static final int VERSION_SIZE = 1;
// version 0 means that the type of prefix's size is int
private byte version = 0;
private byte version = 0;
private String agentId;
private String agentId;
private String applicationId;
private long agentStartTime;
private String traceAgentId;
private long traceAgentStartTime;
private long traceTransactionSequence;
private long traceAgentStartTime;
private long traceTransactionSequence;
private long spanId;
private short sequence;
private long spanId;
private short sequence;
private int startElapsed;
private int endElapsed;
private int startElapsed;
private int endElapsed;
private String rpc;
private ServiceType serviceType;
private String rpc;
private ServiceType serviceType;
private String destinationId;
private String endPoint;
private String endPoint;
private int apiId;
private List<AnnotationBo> annotationBoList;
private List<AnnotationBo> annotationBoList;
private int depth = -1;
private long nextSpanId = -1;
private int depth = -1;
private long nextSpanId = -1;
private boolean hasException;
private int exceptionId;
@@ -70,10 +70,10 @@ public class SpanEventBo implements Span {
private String exceptionClass;
public SpanEventBo() {
}
public SpanEventBo() {
}
public SpanEventBo(TSpan tSpan, TSpanEvent tSpanEvent) {
public SpanEventBo(TSpan tSpan, TSpanEvent tSpanEvent) {
if (tSpan == null) {
throw new NullPointerException("tSpan must not be null");
}
@@ -93,30 +93,30 @@ public class SpanEventBo implements Span {
this.traceAgentStartTime = transactionId.getAgentStartTime();
this.traceTransactionSequence = transactionId.getTransactionSequence();
this.spanId = tSpan.getSpanId();
this.sequence = tSpanEvent.getSequence();
this.spanId = tSpan.getSpanId();
this.sequence = tSpanEvent.getSequence();
this.startElapsed = tSpanEvent.getStartElapsed();
this.endElapsed = tSpanEvent.getEndElapsed();
this.startElapsed = tSpanEvent.getStartElapsed();
this.endElapsed = tSpanEvent.getEndElapsed();
this.rpc = tSpanEvent.getRpc();
this.serviceType = ServiceType.findServiceType(tSpanEvent.getServiceType());
this.rpc = tSpanEvent.getRpc();
this.serviceType = ServiceType.findServiceType(tSpanEvent.getServiceType());
this.destinationId = tSpanEvent.getDestinationId();
this.endPoint = tSpanEvent.getEndPoint();
this.apiId = tSpanEvent.getApiId();
if (tSpanEvent.isSetDepth()) {
this.depth = tSpanEvent.getDepth();
}
if (tSpanEvent.isSetDepth()) {
this.depth = tSpanEvent.getDepth();
}
if (tSpanEvent.isSetNextSpanId()) {
this.nextSpanId = tSpanEvent.getNextSpanId();
}
if (tSpanEvent.isSetNextSpanId()) {
this.nextSpanId = tSpanEvent.getNextSpanId();
}
setAnnotationBoList(tSpanEvent.getAnnotations());
setAnnotationBoList(tSpanEvent.getAnnotations());
final TIntStringValue exceptionInfo = tSpanEvent.getExceptionInfo();
if (exceptionInfo != null) {
@@ -124,9 +124,9 @@ public class SpanEventBo implements Span {
this.exceptionId = exceptionInfo.getIntValue();
this.exceptionMessage = exceptionInfo.getStringValue();
}
}
}
public SpanEventBo(TSpanChunk spanChunk, TSpanEvent spanEvent) {
public SpanEventBo(TSpanChunk spanChunk, TSpanEvent spanEvent) {
if (spanChunk == null) {
throw new NullPointerException("spanChunk must not be null");
}
@@ -146,29 +146,29 @@ public class SpanEventBo implements Span {
this.traceAgentStartTime = transactionId.getAgentStartTime();
this.traceTransactionSequence = transactionId.getTransactionSequence();
this.spanId = spanChunk.getSpanId();
this.sequence = spanEvent.getSequence();
this.spanId = spanChunk.getSpanId();
this.sequence = spanEvent.getSequence();
this.startElapsed = spanEvent.getStartElapsed();
this.endElapsed = spanEvent.getEndElapsed();
this.startElapsed = spanEvent.getStartElapsed();
this.endElapsed = spanEvent.getEndElapsed();
this.rpc = spanEvent.getRpc();
this.serviceType = ServiceType.findServiceType(spanEvent.getServiceType());
this.rpc = spanEvent.getRpc();
this.serviceType = ServiceType.findServiceType(spanEvent.getServiceType());
this.destinationId = spanEvent.getDestinationId();
this.endPoint = spanEvent.getEndPoint();
this.endPoint = spanEvent.getEndPoint();
this.apiId = spanEvent.getApiId();
if (spanEvent.isSetDepth()) {
this.depth = spanEvent.getDepth();
}
if (spanEvent.isSetNextSpanId()) {
this.nextSpanId = spanEvent.getNextSpanId();
}
setAnnotationBoList(spanEvent.getAnnotations());
if (spanEvent.isSetDepth()) {
this.depth = spanEvent.getDepth();
}
if (spanEvent.isSetNextSpanId()) {
this.nextSpanId = spanEvent.getNextSpanId();
}
setAnnotationBoList(spanEvent.getAnnotations());
final TIntStringValue exceptionInfo = spanEvent.getExceptionInfo();
if (exceptionInfo != null) {
@@ -176,25 +176,25 @@ public class SpanEventBo implements Span {
this.exceptionId = exceptionInfo.getIntValue();
this.exceptionMessage = exceptionInfo.getStringValue();
}
}
}
public byte getVersion() {
return version;
}
public byte getVersion() {
return version;
}
public void setVersion(byte version) {
this.version = version;
}
public void setVersion(byte version) {
this.version = version;
}
public String getAgentId() {
return agentId;
}
public String getAgentId() {
return agentId;
}
public void setAgentId(String agentId) {
this.agentId = agentId;
}
public void setAgentId(String agentId) {
this.agentId = agentId;
}
public long getAgentStartTime() {
return this.agentStartTime;
@@ -213,76 +213,76 @@ public class SpanEventBo implements Span {
}
public long getTraceAgentStartTime() {
return traceAgentStartTime;
}
return traceAgentStartTime;
}
public void setTraceAgentStartTime(long traceAgentStartTime) {
this.traceAgentStartTime = traceAgentStartTime;
}
public void setTraceAgentStartTime(long traceAgentStartTime) {
this.traceAgentStartTime = traceAgentStartTime;
}
public long getTraceTransactionSequence() {
return traceTransactionSequence;
}
public long getTraceTransactionSequence() {
return traceTransactionSequence;
}
public void setTraceTransactionSequence(long traceTransactionSequence) {
this.traceTransactionSequence = traceTransactionSequence;
}
public void setTraceTransactionSequence(long traceTransactionSequence) {
this.traceTransactionSequence = traceTransactionSequence;
}
public void setSpanId(long spanId) {
this.spanId = spanId;
}
public void setSpanId(long spanId) {
this.spanId = spanId;
}
public long getSpanId() {
return this.spanId;
}
public long getSpanId() {
return this.spanId;
}
public short getSequence() {
return sequence;
}
public short getSequence() {
return sequence;
}
public void setSequence(short sequence) {
this.sequence = sequence;
}
public void setSequence(short sequence) {
this.sequence = sequence;
}
public int getStartElapsed() {
return startElapsed;
}
public int getStartElapsed() {
return startElapsed;
}
public void setStartElapsed(int startElapsed) {
this.startElapsed = startElapsed;
}
public void setStartElapsed(int startElapsed) {
this.startElapsed = startElapsed;
}
public int getEndElapsed() {
return endElapsed;
}
public int getEndElapsed() {
return endElapsed;
}
public void setEndElapsed(int endElapsed) {
this.endElapsed = endElapsed;
}
public void setEndElapsed(int endElapsed) {
this.endElapsed = endElapsed;
}
public String getRpc() {
return rpc;
}
public String getRpc() {
return rpc;
}
public void setRpc(String rpc) {
this.rpc = rpc;
}
public void setRpc(String rpc) {
this.rpc = rpc;
}
public ServiceType getServiceType() {
return serviceType;
}
public ServiceType getServiceType() {
return serviceType;
}
public void setServiceType(ServiceType serviceType) {
this.serviceType = serviceType;
}
public void setServiceType(ServiceType serviceType) {
this.serviceType = serviceType;
}
public String getEndPoint() {
return endPoint;
}
public String getEndPoint() {
return endPoint;
}
public void setEndPoint(String endPoint) {
this.endPoint = endPoint;
}
public void setEndPoint(String endPoint) {
this.endPoint = endPoint;
}
public int getApiId() {
return apiId;
@@ -302,35 +302,35 @@ public class SpanEventBo implements Span {
public List<AnnotationBo> getAnnotationBoList() {
return annotationBoList;
}
return annotationBoList;
}
public int getDepth() {
return depth;
}
public int getDepth() {
return depth;
}
public void setDepth(int depth) {
this.depth = depth;
}
public void setDepth(int depth) {
this.depth = depth;
}
public long getNextSpanId() {
return nextSpanId;
}
public long getNextSpanId() {
return nextSpanId;
}
public void setNextSpanId(long nextSpanId) {
this.nextSpanId = nextSpanId;
}
public void setNextSpanId(long nextSpanId) {
this.nextSpanId = nextSpanId;
}
private void setAnnotationBoList(List<TAnnotation> annotations) {
private void setAnnotationBoList(List<TAnnotation> annotations) {
if (annotations == null) {
return;
}
List<AnnotationBo> boList = new ArrayList<AnnotationBo>(annotations.size());
for (TAnnotation ano : annotations) {
boList.add(new AnnotationBo(ano));
}
this.annotationBoList = boList;
}
List<AnnotationBo> boList = new ArrayList<AnnotationBo>(annotations.size());
for (TAnnotation ano : annotations) {
boList.add(new AnnotationBo(ano));
}
this.annotationBoList = boList;
}
public boolean hasException() {
return hasException;
@@ -400,52 +400,52 @@ public class SpanEventBo implements Span {
private void writeAnnotation(Buffer buffer) {
AnnotationBoList annotationBo = new AnnotationBoList(this.annotationBoList);
annotationBo.writeValue(buffer);
}
}
public int readValue(byte[] bytes, int offset) {
public int readValue(byte[] bytes, int offset) {
final Buffer buffer = new OffsetFixedBuffer(bytes, offset);
this.version = buffer.readByte();
this.version = buffer.readByte();
// this.mostTraceID = buffer.readLong();
// this.leastTraceID = buffer.readLong();
// this.mostTraceID = buffer.readLong();
// this.leastTraceID = buffer.readLong();
this.agentId = buffer.readPrefixedString();
this.agentId = buffer.readPrefixedString();
this.applicationId = buffer.readPrefixedString();
this.agentStartTime = buffer.readVarLong();
this.startElapsed = buffer.readVarInt();
this.endElapsed = buffer.readVarInt();
this.startElapsed = buffer.readVarInt();
this.endElapsed = buffer.readVarInt();
// don't need to get sequence because it can be got at Qualifier
// this.sequence = buffer.readShort();
// this.sequence = buffer.readShort();
this.rpc = buffer.readPrefixedString();
this.serviceType = ServiceType.findServiceType(buffer.readShort());
this.endPoint = buffer.readPrefixedString();
this.rpc = buffer.readPrefixedString();
this.serviceType = ServiceType.findServiceType(buffer.readShort());
this.endPoint = buffer.readPrefixedString();
this.destinationId = buffer.readPrefixedString();
this.apiId = buffer.readSVarInt();
this.depth = buffer.readSVarInt();
this.nextSpanId = buffer.readLong();
this.depth = buffer.readSVarInt();
this.nextSpanId = buffer.readLong();
this.hasException = buffer.readBoolean();
if (hasException) {
this.exceptionId = buffer.readSVarInt();
this.exceptionMessage = buffer.readPrefixedString();
}
this.annotationBoList = readAnnotation(buffer);
return buffer.getOffset();
}
private List<AnnotationBo> readAnnotation(Buffer buffer) {
this.annotationBoList = readAnnotation(buffer);
return buffer.getOffset();
}
private List<AnnotationBo> readAnnotation(Buffer buffer) {
AnnotationBoList annotationBoList = new AnnotationBoList();
annotationBoList.readValue(buffer);
return annotationBoList.getAnnotationBoList();
}
return annotationBoList.getAnnotationBoList();
}
@Override
public String toString() {
@@ -436,20 +436,20 @@ public class HbaseTemplate2 extends HbaseTemplate implements HbaseOperations2, I
});
}
public <T> List<T> find(String tableName, final Scan scan, final AbstractRowKeyDistributor rowKeyDistributor, int limit, final RowMapper<T> action, final LimitEventHandler limitEventHandler) {
final LimitRowMapperResultsExtractor<T> resultsExtractor = new LimitRowMapperResultsExtractor<T>(action, limit, limitEventHandler);
return execute(tableName, new TableCallback<List<T>>() {
@Override
public List<T> doInTable(HTableInterface htable) throws Throwable {
final ResultScanner scanner = createDistributeScanner(htable, scan, rowKeyDistributor);
try {
return resultsExtractor.extractData(scanner);
} finally {
scanner.close();
}
}
});
}
public <T> List<T> find(String tableName, final Scan scan, final AbstractRowKeyDistributor rowKeyDistributor, int limit, final RowMapper<T> action, final LimitEventHandler limitEventHandler) {
final LimitRowMapperResultsExtractor<T> resultsExtractor = new LimitRowMapperResultsExtractor<T>(action, limit, limitEventHandler);
return execute(tableName, new TableCallback<List<T>>() {
@Override
public List<T> doInTable(HTableInterface htable) throws Throwable {
final ResultScanner scanner = createDistributeScanner(htable, scan, rowKeyDistributor);
try {
return resultsExtractor.extractData(scanner);
} finally {
scanner.close();
}
}
});
}
@Override
@@ -47,7 +47,7 @@ public class LimitRowMapperResultsExtractor<T> implements ResultsExtractor<List<
this.limit = limit;
}
/**
/**
* Create a new RowMapperResultSetExtractor.
*
* @param rowMapper the RowMapper which creates an object for each row
@@ -70,31 +70,31 @@ public class LimitRowMapperResultsExtractor<T> implements ResultsExtractor<List<
}
public List<T> extractData(ResultScanner results) throws Exception {
final List<T> rs = new ArrayList<T>();
int rowNum = 0;
final List<T> rs = new ArrayList<T>();
int rowNum = 0;
Result lastResult = null;
for (Result result : results) {
for (Result result : results) {
final T t = this.rowMapper.mapRow(result, rowNum);
lastResult = result;
if (t instanceof Collection) {
rowNum += ((Collection<?>) t).size();
} else if (t instanceof Map) {
rowNum += ((Map<?, ?>) t).size();
} else if (t == null) {
// empty
} else if (t.getClass().isArray()) {
rowNum += Array.getLength(t);
} else {
rowNum++;
}
rs.add(t);
if (rowNum >= limit) {
break;
}
}
if (t instanceof Collection) {
rowNum += ((Collection<?>) t).size();
} else if (t instanceof Map) {
rowNum += ((Map<?, ?>) t).size();
} else if (t == null) {
// empty
} else if (t.getClass().isArray()) {
rowNum += Array.getLength(t);
} else {
rowNum++;
}
rs.add(t);
if (rowNum >= limit) {
break;
}
}
eventHandler.handleLastResult(lastResult);
return rs;
}
return rs;
}
}

Some files were not shown because too many files have changed in this diff Show More