diff --git a/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/util/IdValidateUtils.java b/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/util/IdValidateUtils.java index 1a8d632e4a0a..0e1c30e4bfde 100644 --- a/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/util/IdValidateUtils.java +++ b/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/util/IdValidateUtils.java @@ -29,7 +29,7 @@ public final class IdValidateUtils { private static final int DEFAULT_MAX_LENGTH = PinpointConstants.AGENT_NAME_MAX_LEN; -// private static final Pattern ID_PATTERN = Pattern.compile("[a-zA-Z0-9\\._\\-]{1,24}"); + // private static final Pattern ID_PATTERN = Pattern.compile("[a-zA-Z0-9\\._\\-]{1,24}"); private static final Pattern ID_PATTERN = Pattern.compile("[a-zA-Z0-9\\._\\-]+"); private IdValidateUtils() { @@ -47,21 +47,44 @@ public static boolean validateId(String id, int maxLength) { throw new IllegalArgumentException("negative maxLength:" + maxLength); } - final Matcher matcher = ID_PATTERN.matcher(id); - if (matcher.matches()) { - return checkBytesLength(id, maxLength); - } else { + if (!checkPattern(id)) { + return false; + } + if (!checkLength(id, maxLength)) { return false; } + + return true; } - private static boolean checkBytesLength(String id, int maxLength) { + public static boolean checkPattern(String id) { + final Matcher matcher = ID_PATTERN.matcher(id); + return matcher.matches(); + } + + public static boolean checkLength(String id, int maxLength) { + if (id == null) { + throw new NullPointerException("id must not be null"); + } // try encode + final int idLength = getLength(id); + if (idLength <= 0) { + return false; + } + return idLength <= maxLength; + } + + public static int getLength(String id) { + if (id == null) { + return -1; + } + final byte[] idBytes = BytesUtils.toBytes(id); - if (idBytes == null || idBytes.length == 0) { - throw new IllegalArgumentException("toBytes fail. id:" + id); + if (idBytes == null) { + // encoding fail + return -1; } - return idBytes.length <= maxLength; + return idBytes.length; } } diff --git a/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/AgentDirBaseClassPathResolver.java b/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/AgentDirBaseClassPathResolver.java new file mode 100644 index 000000000000..fdd77b386a2e --- /dev/null +++ b/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/AgentDirBaseClassPathResolver.java @@ -0,0 +1,435 @@ +/* + * Copyright 2014 NAVER Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.navercorp.pinpoint.bootstrap; + + + +import java.io.File; +import java.io.FileFilter; +import java.io.FilenameFilter; +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URL; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.jar.JarFile; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * @author emeroad + */ +public class AgentDirBaseClassPathResolver implements ClassPathResolver { + + private final BootLogger logger = BootLogger.getLogger(this.getClass().getName()); + + private static final Pattern DEFAULT_AGENT_PATTERN = Pattern.compile("pinpoint-bootstrap(-[0-9]+\\.[0-9]+\\.[0-9]+(\\-SNAPSHOT)?)?\\.jar"); + private static final Pattern DEFAULT_AGENT_COMMONS_PATTERN = Pattern.compile("pinpoint-commons(-[0-9]+\\.[0-9]+\\.[0-9]+(\\-SNAPSHOT)?)?\\.jar"); + private static final Pattern DEFAULT_AGENT_CORE_PATTERN = Pattern.compile("pinpoint-bootstrap-core(-[0-9]+\\.[0-9]+\\.[0-9]+(\\-SNAPSHOT)?)?\\.jar"); + private static final Pattern DEFAULT_AGENT_CORE_OPTIONAL_PATTERN = Pattern.compile("pinpoint-bootstrap-core-optional(-[0-9]+\\.[0-9]+\\.[0-9]+(\\-SNAPSHOT)?)?\\.jar"); + + private String classPath; + + private String agentJarName; + private String agentJarFullPath; + private String agentDirPath; + private Pattern agentPattern; + private Pattern agentCommonsPattern; + private Pattern agentCorePattern; + private Pattern agentCoreOptionalPattern; + private List fileExtensionList; + private String pinpointCommonsJar; + private String bootStrapCoreJar; + private String bootStrapCoreOptionalJar; + + private BootstrapJarFile bootstrapJarFile; + + public AgentDirBaseClassPathResolver() { + this(getClassPathFromSystemProperty()); + } + + + public AgentDirBaseClassPathResolver(String classPath) { + this.classPath = classPath; + this.agentPattern = DEFAULT_AGENT_PATTERN; + this.agentCommonsPattern = DEFAULT_AGENT_COMMONS_PATTERN; + this.agentCorePattern = DEFAULT_AGENT_CORE_PATTERN; + this.agentCoreOptionalPattern = DEFAULT_AGENT_CORE_OPTIONAL_PATTERN; + this.fileExtensionList = getDefaultFileExtensionList(); + } + + public List getDefaultFileExtensionList() { + List extensionList = new ArrayList(); + extensionList.add("jar"); + extensionList.add("xml"); + extensionList.add("properties"); + return extensionList; + } + + public AgentDirBaseClassPathResolver(String classPath, String agentPattern) { + this.classPath = classPath; + this.agentPattern = Pattern.compile(agentPattern); + this.agentCommonsPattern = DEFAULT_AGENT_COMMONS_PATTERN; + this.agentCorePattern = DEFAULT_AGENT_CORE_PATTERN; + this.agentCoreOptionalPattern = DEFAULT_AGENT_CORE_OPTIONAL_PATTERN; + this.fileExtensionList = getDefaultFileExtensionList(); + } + + @Override + public boolean verify() { + + final BootstrapJarFile bootstrapJarFile = new BootstrapJarFile(); + + // 1st find boot-strap.jar + final boolean agentJarNotFound = this.findAgentJar(); + if (!agentJarNotFound) { + logger.warn("pinpoint-bootstrap-x.x.x(-SNAPSHOT).jar not found."); + return false; + } + + // 2nd find pinpoint-commons.jar + final String pinpointCommonsJar = getPinpointCommonsJar(); + if (pinpointCommonsJar == null) { + logger.warn("pinpoint-commons-x.x.x(-SNAPSHOT).jar not found"); + return false; + } + final JarFile pinpointCommonsJarFile = getJarFile(pinpointCommonsJar); + if (pinpointCommonsJarFile == null) { + logger.warn("pinpoint-commons-x.x.x(-SNAPSHOT).jar not found"); + return false; + } + bootstrapJarFile.append(pinpointCommonsJarFile); + + // 3rd find bootstrap-core.jar + final String bootStrapCoreJar = getBootStrapCoreJar(); + if (bootStrapCoreJar == null) { + logger.warn("pinpoint-bootstrap-core-x.x.x(-SNAPSHOT).jar not found"); + return false; + } + JarFile bootStrapCoreJarFile = getJarFile(bootStrapCoreJar); + if (bootStrapCoreJarFile == null) { + logger.warn("pinpoint-bootstrap-core-x.x.x(-SNAPSHOT).jar not found"); + return false; + } + bootstrapJarFile.append(bootStrapCoreJarFile); + + // 4th find bootstrap-core-optional.jar + final String bootStrapCoreOptionalJar = getBootStrapCoreOptionalJar(); + if (bootStrapCoreOptionalJar == null) { + logger.info("pinpoint-bootstrap-core-optional-x.x.x(-SNAPSHOT).jar not found"); + } else { + JarFile bootStrapCoreOptionalJarFile = getJarFile(bootStrapCoreOptionalJar); + if (bootStrapCoreOptionalJarFile == null) { + logger.info("pinpoint-bootstrap-core-optional-x.x.x(-SNAPSHOT).jar not found"); + } else { + bootstrapJarFile.append(bootStrapCoreOptionalJarFile); + } + } + + this.bootstrapJarFile = bootstrapJarFile; + return true; + } + + public void setClassPathFromSystemProperty() { + this.classPath = getClassPathFromSystemProperty(); + } + + @Override + public BootstrapJarFile getBootstrapJarFile() { + return bootstrapJarFile; + } + + public static String getClassPathFromSystemProperty() { + return System.getProperty("java.class.path"); + } + + boolean findAgentJar() { + Matcher matcher = agentPattern.matcher(classPath); + if (!matcher.find()) { + return false; + } + this.agentJarName = parseAgentJar(matcher); + this.agentJarFullPath = parseAgentJarPath(classPath, agentJarName); + if (agentJarFullPath == null) { + return false; + } + this.agentDirPath = parseAgentDirPath(agentJarFullPath); + if (agentDirPath == null) { + return false; + } + + logger.info("Agent original-path:" + agentDirPath); + // defense alias change + this.agentDirPath = toCanonicalPath(agentDirPath); + logger.info("Agent canonical-path:" + agentDirPath); + + + this.pinpointCommonsJar = findFromBootDir("pinpoint-commons", agentCommonsPattern); + this.bootStrapCoreJar = findFromBootDir("bootStrapCore", agentCorePattern); + this.bootStrapCoreOptionalJar = findFromBootDir("bootStrapCoreOptional", agentCoreOptionalPattern); + return true; + } + + private String toCanonicalPath(String path) { + final File file = new File(path); + return toCanonicalPath(file); + } + + private String toCanonicalPath(File file) { + try { + return file.getCanonicalPath(); + } catch (IOException e) { + logger.warn(file.getPath() + " getCanonicalPath() error. Error:" + e.getMessage(), e); + return file.getAbsolutePath(); + } + } + + private String findFromBootDir(final String name, final Pattern pattern) { + String bootDirPath = agentDirPath + File.separator + "boot"; + File[] files = listFiles(name, pattern, bootDirPath); + if (files== null || files.length == 0) { + logger.info(name + " not found."); + return null; + } else if (files.length == 1) { + File file = files[0]; + return toCanonicalPath(file); + } else { + logger.info("too many " + name + " found. " + Arrays.toString(files)); + return null; + } + } + + private File[] listFiles(final String name, final Pattern pattern, String bootDirPath) { + File bootDir = new File(bootDirPath); + return bootDir.listFiles(new FilenameFilter() { + @Override + public boolean accept(File dir, String fileName) { + Matcher matcher = pattern.matcher(fileName); + if (matcher.matches()) { + + logger.info("found " + name + ". " + dir.getAbsolutePath() + File.separator + fileName); + return true; + } + return false; + } + }); + } + + @Override + public String getPinpointCommonsJar() { + return pinpointCommonsJar; + } + + @Override + public String getBootStrapCoreJar() { + return bootStrapCoreJar; + } + + @Override + public String getBootStrapCoreOptionalJar() { + return bootStrapCoreOptionalJar; + } + + private String parseAgentJar(Matcher matcher) { + int start = matcher.start(); + int end = matcher.end(); + return this.classPath.substring(start, end); + } + + @Override + public String getAgentJarName() { + return this.agentJarName; + } + + private String parseAgentJarPath(String classPath, String agentJar) { + String[] classPathList = classPath.split(File.pathSeparator); + for (String findPath : classPathList) { + boolean find = findPath.contains(agentJar); + if (find) { + return findPath; + } + } + return null; + } + + @Override + public String getAgentJarFullPath() { + return agentJarFullPath; + } + + @Override + public String getAgentLibPath() { + return this.agentDirPath + File.separator + "lib"; + } + + @Override + public String getAgentLogFilePath() { + return this.agentDirPath + File.separator + "log"; + } + + @Override + public String getAgentPluginPath() { + return this.agentDirPath + File.separator + "plugin"; + } + + @Override + public List resolveLib() { + String agentLibPath = getAgentLibPath(); + File libDir = new File(agentLibPath); + if (!libDir.exists()) { + logger.warn(agentLibPath + " not found"); + return Collections.emptyList(); + } + if (!libDir.isDirectory()) { + logger.warn(agentLibPath + " not Directory"); + return Collections.emptyList(); + } + final List jarURLList = new ArrayList(); + + final File[] findJarList = findJar(libDir); + if (findJarList != null) { + for (File file : findJarList) { + URL url = toURI(file); + if (url != null) { + jarURLList.add(url); + } + } + } + + URL agentDirUri = toURI(new File(agentLibPath)); + if (agentDirUri != null) { + jarURLList.add(agentDirUri); + } + + // hot fix. boot jars not found from classPool ?? + jarURLList.add(toURI(new File(getPinpointCommonsJar()))); + jarURLList.add(toURI(new File(getBootStrapCoreJar()))); + String bootstrapCoreOptionalJar = getBootStrapCoreOptionalJar(); + // bootstrap-core-optional jar is not required and is okay to be null + if (bootstrapCoreOptionalJar != null) { + jarURLList.add(toURI(new File(bootstrapCoreOptionalJar))); + } + + return jarURLList; + } + + @Override + public URL[] resolvePlugins() { + final File file = new File(getAgentPluginPath()); + + if (!file.exists()) { + logger.warn(file + " not found"); + return new URL[0]; + } + + if (!file.isDirectory()) { + logger.warn(file + " is not a directory"); + return new URL[0]; + } + + + final File[] jars = file.listFiles(new FilenameFilter() { + + @Override + public boolean accept(File dir, String name) { + return name.endsWith(".jar"); + } + }); + + if (jars == null || jars.length == 0) { + return new URL[0]; + } + + final URL[] urls = new URL[jars.length]; + + + for (int i = 0; i < jars.length; i++) { + try { + urls[i] = jars[i].toURI().toURL(); + } catch (MalformedURLException e) { + // TODO have to change to PinpointException AFTER moving the exception to pinpoint-common + throw new RuntimeException("Fail to load plugin jars", e); + } + } + + for (File pluginJar : jars) { + logger.info("Found plugins: " + pluginJar.getPath()); + } + + return urls; + } + + private URL toURI(File file) { + URI uri = file.toURI(); + try { + return uri.toURL(); + } catch (MalformedURLException e) { + logger.warn(file.getName() + ".toURL() failed.", e); + return null; + } + } + + private File[] findJar(File libDir) { + return libDir.listFiles(new FileFilter() { + @Override + public boolean accept(File pathname) { + String path = pathname.getName(); + for (String extension : fileExtensionList) { + if (path.lastIndexOf("." + extension) != -1) { + return true; + } + } + return false; + } + }); + } + + private String parseAgentDirPath(String agentJarFullPath) { + int index1 = agentJarFullPath.lastIndexOf("/"); + int index2 = agentJarFullPath.lastIndexOf("\\"); + int max = Math.max(index1, index2); + if (max == -1) { + return null; + } + return agentJarFullPath.substring(0, max); + } + + @Override + public String getAgentDirPath() { + return agentDirPath; + } + + @Override + public String getAgentConfigPath() { + return agentDirPath + File.separator + "pinpoint.config"; + } + + + private JarFile getJarFile(String jarFilePath) { + try { + return new JarFile(jarFilePath); + } catch (IOException ioe) { + logger.warn(jarFilePath + " file not found. Error:" + ioe.getMessage(), ioe); + return null; + } + } + + +} diff --git a/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/AgentOption.java b/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/AgentOption.java index 6ba35df73298..668d107391bd 100644 --- a/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/AgentOption.java +++ b/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/AgentOption.java @@ -29,10 +29,12 @@ */ public interface AgentOption { - String getAgentArgs(); - Instrumentation getInstrumentation(); + String getAgentId(); + + String getApplicationName(); + ProfilerConfig getProfilerConfig(); URL[] getPluginJars(); diff --git a/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/ArgsParser.java b/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/ArgsParser.java new file mode 100644 index 000000000000..4f109e5f6e13 --- /dev/null +++ b/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/ArgsParser.java @@ -0,0 +1,56 @@ +/* + * Copyright 2016 NAVER Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package com.navercorp.pinpoint.bootstrap; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import java.util.Scanner; + +/** + * @author Woonduk Kang(emeroad) + */ +public class ArgsParser { + + public Map parse(String args) { + if (args == null || args.isEmpty()) { + return Collections.emptyMap(); + } + + final Map map = new HashMap(); + + Scanner scanner = new Scanner(args); + scanner.useDelimiter("\\s*,\\s*"); + + while (scanner.hasNext()) { + String token = scanner.next(); + int assign = token.indexOf('='); + + if (assign == -1) { + map.put(token, ""); + } else { + String key = token.substring(0, assign); + String value = token.substring(assign + 1); + map.put(key, value); + } + } + scanner.close(); + return Collections.unmodifiableMap(map); + } + +} diff --git a/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/BootstrapJarFile.java b/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/BootstrapJarFile.java new file mode 100644 index 000000000000..a081264d1451 --- /dev/null +++ b/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/BootstrapJarFile.java @@ -0,0 +1,54 @@ +/* + * Copyright 2016 NAVER Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package com.navercorp.pinpoint.bootstrap; + +import java.util.ArrayList; +import java.util.List; +import java.util.jar.JarFile; + +/** + * @author Woonduk Kang(emeroad) + */ +public class BootstrapJarFile { + + private final List jarFileEntry = new ArrayList(); + + public BootstrapJarFile() { + } + + public void append(JarFile jarFile) { + if (jarFile == null) { + throw new NullPointerException("jarFile must not be null"); + } + + this.jarFileEntry.add(jarFile); + } + + public List getJarFileList() { + return jarFileEntry; + } + + public List getJarNameList() { + List bootStrapJarLIst = new ArrayList(jarFileEntry.size()); + for (JarFile jarFile : jarFileEntry) { + bootStrapJarLIst.add(jarFile.getName()); + } + return bootStrapJarLIst; + } + +} diff --git a/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/ClassPathResolver.java b/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/ClassPathResolver.java index a4d6b9171e7d..23b14ef85fee 100644 --- a/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/ClassPathResolver.java +++ b/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/ClassPathResolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 NAVER Corp. + * Copyright 2016 NAVER Corp. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -12,310 +12,44 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. + * */ package com.navercorp.pinpoint.bootstrap; - - -import java.io.File; -import java.io.FileFilter; -import java.io.FilenameFilter; -import java.net.MalformedURLException; -import java.net.URI; import java.net.URL; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; import java.util.List; -import java.util.regex.Matcher; -import java.util.regex.Pattern; /** - * @author emeroad + * @author Woonduk Kang(emeroad) */ -public class ClassPathResolver { - - private final BootLogger logger = BootLogger.getLogger(this.getClass().getName()); - - private static final Pattern DEFAULT_AGENT_PATTERN = Pattern.compile("pinpoint-bootstrap(-[0-9]+\\.[0-9]+\\.[0-9]+(\\-SNAPSHOT)?)?\\.jar"); - private static final Pattern DEFAULT_AGENT_COMMONS_PATTERN = Pattern.compile("pinpoint-commons(-[0-9]+\\.[0-9]+\\.[0-9]+(\\-SNAPSHOT)?)?\\.jar"); - private static final Pattern DEFAULT_AGENT_CORE_PATTERN = Pattern.compile("pinpoint-bootstrap-core(-[0-9]+\\.[0-9]+\\.[0-9]+(\\-SNAPSHOT)?)?\\.jar"); - private static final Pattern DEFAULT_AGENT_CORE_OPTIONAL_PATTERN = Pattern.compile("pinpoint-bootstrap-core-optional(-[0-9]+\\.[0-9]+\\.[0-9]+(\\-SNAPSHOT)?)?\\.jar"); - - private String classPath; - - private String agentJarName; - private String agentJarFullPath; - private String agentDirPath; - private Pattern agentPattern; - private Pattern agentCommonsPattern; - private Pattern agentCorePattern; - private Pattern agentCoreOptionalPattern; - private List fileExtensionList; - private String pinpointCommonsJar; - private String bootStrapCoreJar; - private String bootStrapCoreOptionalJar; - - public ClassPathResolver() { - this(getClassPathFromSystemProperty()); - } - - - public ClassPathResolver(String classPath) { - this.classPath = classPath; - this.agentPattern = DEFAULT_AGENT_PATTERN; - this.agentCommonsPattern = DEFAULT_AGENT_COMMONS_PATTERN; - this.agentCorePattern = DEFAULT_AGENT_CORE_PATTERN; - this.agentCoreOptionalPattern = DEFAULT_AGENT_CORE_OPTIONAL_PATTERN; - this.fileExtensionList = getDefaultFileExtensionList(); - } - - public List getDefaultFileExtensionList() { - List extensionList = new ArrayList(); - extensionList.add("jar"); - extensionList.add("xml"); - extensionList.add("properties"); - return extensionList; - } - - public ClassPathResolver(String classPath, String agentPattern) { - this.classPath = classPath; - this.agentPattern = Pattern.compile(agentPattern); - this.agentCommonsPattern = DEFAULT_AGENT_COMMONS_PATTERN; - this.agentCorePattern = DEFAULT_AGENT_CORE_PATTERN; - this.agentCoreOptionalPattern = DEFAULT_AGENT_CORE_OPTIONAL_PATTERN; - this.fileExtensionList = getDefaultFileExtensionList(); - } - - public void setClassPath(String classPath) { - this.classPath = classPath; - } - - public void setClassPathFromSystemProperty() { - this.classPath = getClassPathFromSystemProperty(); - } - - public static String getClassPathFromSystemProperty() { - return System.getProperty("java.class.path"); - } - - public boolean findAgentJar() { - Matcher matcher = agentPattern.matcher(classPath); - if (!matcher.find()) { - return false; - } - this.agentJarName = parseAgentJar(matcher); - this.agentJarFullPath = parseAgentJarPath(classPath, agentJarName); - if (agentJarFullPath == null) { - return false; - } - this.agentDirPath = parseAgentDirPath(agentJarFullPath); - - this.pinpointCommonsJar = findFromBootDir("pinpoint-commons", agentCommonsPattern); - this.bootStrapCoreJar = findFromBootDir("bootStrapCore", agentCorePattern); - this.bootStrapCoreOptionalJar = findFromBootDir("bootStrapCoreOptional", agentCoreOptionalPattern); - return true; - } - - private String findFromBootDir(final String name, final Pattern pattern) { - String bootDir = agentDirPath + File.separator + "boot"; - File file = new File(bootDir); - File[] files = file.listFiles(new FilenameFilter() { - @Override - public boolean accept(File dir, String fileName) { - Matcher matcher = pattern.matcher(fileName); - if (matcher.matches()) { - logger.info("found " + name + ". " + fileName); - return true; - } - return false; - } - }); - if (files== null || files.length == 0) { - logger.info(name + " not found."); - return null; - } else if (files.length == 1) { - return files[0].getAbsolutePath(); - } else { - logger.info("too many " + name + " found. " + Arrays.toString(files)); - return null; - } - } - - public String getPinpointCommonsJar() { - return pinpointCommonsJar; - } - - public String getBootStrapCoreJar() { - return bootStrapCoreJar; - } - - public String getBootStrapCoreOptionalJar() { - return bootStrapCoreOptionalJar; - } - - private String parseAgentJar(Matcher matcher) { - int start = matcher.start(); - int end = matcher.end(); - return this.classPath.substring(start, end); - } - - public String getAgentJarName() { - return this.agentJarName; - } - - private String parseAgentJarPath(String classPath, String agentJar) { - String[] classPathList = classPath.split(File.pathSeparator); - for (String findPath : classPathList) { - boolean find = findPath.contains(agentJar); - if (find) { - return findPath; - } - } - return null; - } - - public String getAgentJarFullPath() { - return agentJarFullPath; - } - - public String getAgentLibPath() { - return this.agentDirPath + File.separator + "lib"; - } - - public String getAgentLogFilePath() { - return this.agentDirPath + File.separator + "log"; - } +public interface ClassPathResolver { - public String getAgentPluginPath() { - return this.agentDirPath + File.separator + "plugin"; - } + boolean verify(); - public List resolveLib() { - String agentLibPath = getAgentLibPath(); - File libDir = new File(agentLibPath); - if (!libDir.exists()) { - logger.warn(agentLibPath + " not found"); - return Collections.emptyList(); - } - if (!libDir.isDirectory()) { - logger.warn(agentLibPath + " not Directory"); - return Collections.emptyList(); - } - final List jarURLList = new ArrayList(); + BootstrapJarFile getBootstrapJarFile(); - final File[] findJarList = findjar(libDir); - if (findJarList != null) { - for (File file : findJarList) { - URL url = toURI(file); - if (url != null) { - jarURLList.add(url); - } - } - } + String getPinpointCommonsJar(); - URL agentDirUri = toURI(new File(agentLibPath)); - if (agentDirUri != null) { - jarURLList.add(agentDirUri); - } + String getBootStrapCoreJar(); - // hot fix. boot jars not found from classPool ?? - jarURLList.add(toURI(new File(getPinpointCommonsJar()))); - jarURLList.add(toURI(new File(getBootStrapCoreJar()))); - String bootstrapCoreOptionalJar = getBootStrapCoreOptionalJar(); - // bootstrap-core-optional jar is not required and is okay to be null - if (bootstrapCoreOptionalJar != null) { - jarURLList.add(toURI(new File(bootstrapCoreOptionalJar))); - } + String getBootStrapCoreOptionalJar(); - return jarURLList; - } - - public URL[] resolvePlugins() { - final File file = new File(getAgentPluginPath()); - - if (!file.exists()) { - logger.warn(file + " not found"); - return new URL[0]; - } - - if (!file.isDirectory()) { - logger.warn(file + " is not a directory"); - return new URL[0]; - } - - - final File[] jars = file.listFiles(new FilenameFilter() { - - @Override - public boolean accept(File dir, String name) { - return name.endsWith(".jar"); - } - }); + String getAgentJarName(); - if (jars == null || jars.length == 0) { - return new URL[0]; - } - - final URL[] urls = new URL[jars.length]; - - - for (int i = 0; i < jars.length; i++) { - try { - urls[i] = jars[i].toURI().toURL(); - } catch (MalformedURLException e) { - // TODO have to change to PinpointException AFTER moving the exception to pinpoint-common - throw new RuntimeException("Fail to load plugin jars", e); - } - } - - logger.info("Found plugins: " + Arrays.deepToString(jars)); + String getAgentJarFullPath(); - return urls; - } + String getAgentLibPath(); - private URL toURI(File file) { - URI uri = file.toURI(); - try { - return uri.toURL(); - } catch (MalformedURLException e) { - logger.warn(file.getName() + ".toURL() failed. Error:" + e.getMessage(), e); - return null; - } - } + String getAgentLogFilePath(); - private File[] findjar(File libDir) { - return libDir.listFiles(new FileFilter() { - @Override - public boolean accept(File pathname) { - String path = pathname.getName(); - for (String extension : fileExtensionList) { - if (path.lastIndexOf("." + extension) != -1) { - return true; - } - } - return false; - } - }); - } + String getAgentPluginPath(); - public String parseAgentDirPath(String agentJarFullPath) { - int index1 = agentJarFullPath.lastIndexOf("/"); - int index2 = agentJarFullPath.lastIndexOf("\\"); - int max = Math.max(index1, index2); - if (max == -1) { - return null; - } - return agentJarFullPath.substring(0, max); - } + List resolveLib(); - public String getAgentDirPath() { - return agentDirPath; - } + URL[] resolvePlugins(); - public String getAgentConfigPath() { - return agentDirPath + File.separator + "pinpoint.config"; - } + String getAgentDirPath(); + String getAgentConfigPath(); } diff --git a/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/ContextClassLoaderExecuteTemplate.java b/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/ContextClassLoaderExecuteTemplate.java index c3742fde28a6..b12c8c9da212 100644 --- a/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/ContextClassLoaderExecuteTemplate.java +++ b/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/ContextClassLoaderExecuteTemplate.java @@ -49,7 +49,7 @@ public V execute(Callable callable) throws BootStrapException { } catch (BootStrapException ex){ throw ex; } catch (Exception ex) { - throw new BootStrapException("execute fail. Caused:" + ex.getMessage(), ex); + throw new BootStrapException("execute fail. Error:" + ex.getMessage(), ex); } } } diff --git a/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/DefaultAgentOption.java b/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/DefaultAgentOption.java index 3dbb78de372d..927572764243 100644 --- a/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/DefaultAgentOption.java +++ b/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/DefaultAgentOption.java @@ -18,6 +18,7 @@ import java.lang.instrument.Instrumentation; import java.net.URL; +import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -29,18 +30,28 @@ * @author emeroad */ public class DefaultAgentOption implements AgentOption { - private final String agentArgs; + private final Instrumentation instrumentation; + + private final String agentId; + private final String applicationName; + private final ProfilerConfig profilerConfig; private final URL[] pluginJars; private final List bootstrapJarPaths; private final ServiceTypeRegistryService serviceTypeRegistryService; private final AnnotationKeyRegistryService annotationKeyRegistryService; - public DefaultAgentOption(final String agentArgs, final Instrumentation instrumentation, final ProfilerConfig profilerConfig, final URL[] pluginJars, final List bootstrapJarPaths, final ServiceTypeRegistryService serviceTypeRegistryService, final AnnotationKeyRegistryService annotationKeyRegistryService) { + public DefaultAgentOption(final Instrumentation instrumentation, String agentId, String applicationName, final ProfilerConfig profilerConfig, final URL[] pluginJars, final List bootstrapJarPaths, final ServiceTypeRegistryService serviceTypeRegistryService, final AnnotationKeyRegistryService annotationKeyRegistryService) { if (instrumentation == null) { throw new NullPointerException("instrumentation must not be null"); } + if (agentId == null) { + throw new NullPointerException("agentId must not be null"); + } + if (applicationName == null) { + throw new NullPointerException("applicationName must not be null"); + } if (profilerConfig == null) { throw new NullPointerException("profilerConfig must not be null"); } @@ -53,8 +64,9 @@ public DefaultAgentOption(final String agentArgs, final Instrumentation instrume if (serviceTypeRegistryService == null) { throw new NullPointerException("serviceTypeRegistryService must not be null"); } - this.agentArgs = agentArgs; this.instrumentation = instrumentation; + this.agentId = agentId; + this.applicationName = applicationName; this.profilerConfig = profilerConfig; this.pluginJars = pluginJars; if (bootstrapJarPaths == null) { @@ -67,13 +79,18 @@ public DefaultAgentOption(final String agentArgs, final Instrumentation instrume } @Override - public String getAgentArgs() { - return this.agentArgs; + public Instrumentation getInstrumentation() { + return this.instrumentation; + } + + @Override + public String getAgentId() { + return agentId; } @Override - public Instrumentation getInstrumentation() { - return this.instrumentation; + public String getApplicationName() { + return applicationName; } @Override @@ -103,11 +120,16 @@ public AnnotationKeyRegistryService getAnnotationKeyRegistryService() { @Override public String toString() { - return "DefaultAgentOption{" + - "agentArgs='" + agentArgs + '\'' + - ", instrumentation=" + instrumentation + - ", profilerConfig=" + profilerConfig + - ", bootstrapJarPaths='" + bootstrapJarPaths + - '}'; + final StringBuilder sb = new StringBuilder("DefaultAgentOption{"); + sb.append("instrumentation=").append(instrumentation); + sb.append(", agentId='").append(agentId).append('\''); + sb.append(", applicationName='").append(applicationName).append('\''); + sb.append(", profilerConfig=").append(profilerConfig); + sb.append(", pluginJars=").append(Arrays.toString(pluginJars)); + sb.append(", bootstrapJarPaths=").append(bootstrapJarPaths); + sb.append(", serviceTypeRegistryService=").append(serviceTypeRegistryService); + sb.append(", annotationKeyRegistryService=").append(annotationKeyRegistryService); + sb.append('}'); + return sb.toString(); } } diff --git a/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/IdValidator.java b/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/IdValidator.java new file mode 100644 index 000000000000..7465b224c351 --- /dev/null +++ b/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/IdValidator.java @@ -0,0 +1,79 @@ +/* + * Copyright 2016 NAVER Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package com.navercorp.pinpoint.bootstrap; + +import com.navercorp.pinpoint.bootstrap.util.IdValidateUtils; + + +import java.util.Properties; + +/** + * @author Woonduk Kang(emeroad) + */ +public class IdValidator { + + private final BootLogger logger = BootLogger.getLogger(IdValidator.class.getName()); + + private final Properties property; + private static final int MAX_ID_LENGTH = 24; + + public IdValidator() { + this(System.getProperties()); + } + + public IdValidator(Properties property) { + if (property == null) { + throw new NullPointerException("property must not be null"); + } + this.property = property; + } + + private String getValidId(String propertyName, int maxSize) { + logger.info("check -D" + propertyName); + String value = property.getProperty(propertyName); + if (value == null){ + logger.warn("-D" + propertyName + " is null. value:null"); + return null; + } + // blanks not permitted around value + value = value.trim(); + if (value.isEmpty()) { + logger.warn("-D" + propertyName + " is empty. value:''"); + return null; + } + + if (!IdValidateUtils.validateId(value, maxSize)) { + logger.warn("invalid Id. " + propertyName + " can only contain [a-zA-Z0-9], '.', '-', '_'. maxLength:" + maxSize + " value:" + value); + return null; + } + + if (logger.isInfoEnabled()) { + logger.info("check success. -D" + propertyName + ":" + value + " length:" + IdValidateUtils.getLength(value)); + } + return value; + } + + + public String getApplicationName() { + return this.getValidId("pinpoint.applicationName", MAX_ID_LENGTH); + } + + public String getAgentId() { + return this.getValidId("pinpoint.agentId", MAX_ID_LENGTH); + } +} diff --git a/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/LoadState.java b/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/LoadState.java new file mode 100644 index 000000000000..c256e6897764 --- /dev/null +++ b/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/LoadState.java @@ -0,0 +1,40 @@ +/* + * Copyright 2016 NAVER Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package com.navercorp.pinpoint.bootstrap; + +import java.util.concurrent.atomic.AtomicBoolean; + +/** + * @author Woonduk Kang(emeroad) + */ +public class LoadState { + + private static final boolean STATE_NONE = false; + private static final boolean STATE_STARTED = true; + + private final AtomicBoolean state = new AtomicBoolean(STATE_NONE); + + // for test + boolean getState() { + return state.get(); + } + + public boolean start() { + return state.compareAndSet(STATE_NONE, STATE_STARTED); + } +} diff --git a/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/PinpointBootStrap.java b/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/PinpointBootStrap.java index 2856d0edea26..ea6975cb95ba 100644 --- a/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/PinpointBootStrap.java +++ b/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/PinpointBootStrap.java @@ -16,9 +16,9 @@ package com.navercorp.pinpoint.bootstrap; -import java.io.IOException; import java.lang.instrument.Instrumentation; -import java.util.concurrent.atomic.AtomicBoolean; +import java.util.List; +import java.util.Map; import java.util.jar.JarFile; import com.navercorp.pinpoint.ProductInfo; @@ -31,104 +31,59 @@ public class PinpointBootStrap { private static final BootLogger logger = BootLogger.getLogger(PinpointBootStrap.class.getName()); - public static final String BOOT_CLASS = "com.navercorp.pinpoint.profiler.DefaultAgent"; + private static final LoadState STATE = new LoadState(); - private static final boolean STATE_NONE = false; - private static final boolean STATE_STARTED = true; - private static final AtomicBoolean LOAD_STATE = new AtomicBoolean(STATE_NONE); public static void premain(String agentArgs, Instrumentation instrumentation) { - if (agentArgs != null) { - logger.info(ProductInfo.NAME + " agentArgs:" + agentArgs); + if (agentArgs == null) { + agentArgs = ""; } + logger.info(ProductInfo.NAME + " agentArgs:" + agentArgs); - final boolean duplicated = checkDuplicateLoadState(); - if (duplicated) { - logPinpointAgentLoadFail(); + final boolean success = STATE.start(); + if (!success) { + logger.warn("pinpoint-bootstrap already started. skipping agent loading."); return; } - - loadBootstrapCoreLib(instrumentation); - - PinpointStarter bootStrap = new PinpointStarter(agentArgs, instrumentation); - bootStrap.start(); - - } + Map agentArgsMap = argsToMap(agentArgs); - private static void loadBootstrapCoreLib(Instrumentation instrumentation) { - // 1st find boot-strap.jar - final ClassPathResolver classPathResolver = new ClassPathResolver(); - boolean agentJarNotFound = classPathResolver.findAgentJar(); - if (!agentJarNotFound) { - logger.warn("pinpoint-bootstrap-x.x.x(-SNAPSHOT).jar not found."); + final ClassPathResolver classPathResolver = new AgentDirBaseClassPathResolver(); + if (!classPathResolver.verify()) { + logger.warn("Agent Directory Verify fail. skipping agent loading."); logPinpointAgentLoadFail(); return; } - // 2nd find pinpoint-commons.jar - final String pinpointCommonsJar = classPathResolver.getPinpointCommonsJar(); - if (pinpointCommonsJar == null) { - logger.warn("pinpoint-commons-x.x.x(-SNAPSHOT).jar not found"); - logPinpointAgentLoadFail(); - return; - } - JarFile pinpointCommonsJarFile = getJarFile(pinpointCommonsJar); - if (pinpointCommonsJarFile == null) { - logger.warn("pinpoint-commons-x.x.x(-SNAPSHOT).jar not found"); - logPinpointAgentLoadFail(); - return; - } - logger.info("load pinpoint-commons-x.x.x(-SNAPSHOT).jar : " + pinpointCommonsJar); - instrumentation.appendToBootstrapClassLoaderSearch(pinpointCommonsJarFile); + BootstrapJarFile bootstrapJarFile = classPathResolver.getBootstrapJarFile(); + appendToBootstrapClassLoader(instrumentation, bootstrapJarFile); - // 3rd find bootstrap-core.jar - final String bootStrapCoreJar = classPathResolver.getBootStrapCoreJar(); - if (bootStrapCoreJar == null) { - logger.warn("pinpoint-bootstrap-core-x.x.x(-SNAPSHOT).jar not found"); - logPinpointAgentLoadFail(); - return; - } - JarFile bootStrapCoreJarFile = getJarFile(bootStrapCoreJar); - if (bootStrapCoreJarFile == null) { - logger.warn("pinpoint-bootstrap-core-x.x.x(-SNAPSHOT).jar not found"); + + PinpointStarter bootStrap = new PinpointStarter(agentArgsMap, bootstrapJarFile, classPathResolver, instrumentation); + if (!bootStrap.start()) { logPinpointAgentLoadFail(); - return; - } - logger.info("load pinpoint-bootstrap-core-x.x.x(-SNAPSHOT).jar : " + bootStrapCoreJar); - instrumentation.appendToBootstrapClassLoaderSearch(bootStrapCoreJarFile); - - // 4th find bootstrap-core-optional.jar - final String bootStrapCoreOptionalJar = classPathResolver.getBootStrapCoreOptionalJar(); - if (bootStrapCoreOptionalJar == null) { - logger.info("pinpoint-bootstrap-core-optional-x.x.x(-SNAPSHOT).jar not found"); - } else { - JarFile bootStrapCoreOptionalJarFile = getJarFile(bootStrapCoreOptionalJar); - if (bootStrapCoreOptionalJarFile == null) { - logger.info("pinpoint-bootstrap-core-optional-x.x.x(-SNAPSHOT).jar not found"); - } else { - logger.info("load pinpoint-bootstrap-core-optional-x.x.x(-SNAPSHOT).jar : " + bootStrapCoreOptionalJar); - instrumentation.appendToBootstrapClassLoaderSearch(bootStrapCoreOptionalJarFile); - } } + } - // for test - static boolean getLoadState() { - return LOAD_STATE.get(); + private static Map argsToMap(String agentArgs) { + ArgsParser argsParser = new ArgsParser(); + Map agentArgsMap = argsParser.parse(agentArgs); + if (!agentArgsMap.isEmpty()) { + logger.info("agentParameter :" + agentArgs); + } + return agentArgsMap; } - private static boolean checkDuplicateLoadState() { - final boolean startSuccess = LOAD_STATE.compareAndSet(STATE_NONE, STATE_STARTED); - if (startSuccess) { - return false; - } else { - if (logger.isWarnEnabled()) { - logger.warn("pinpoint-bootstrap already started. skipping agent loading."); - } - return true; + private static void appendToBootstrapClassLoader(Instrumentation instrumentation, BootstrapJarFile agentJarFile) { + List jarFileList = agentJarFile.getJarFileList(); + for (JarFile jarFile : jarFileList) { + logger.info("appendToBootstrapClassLoader:" + jarFile.getName()); + instrumentation.appendToBootstrapClassLoaderSearch(jarFile); } } + + private static void logPinpointAgentLoadFail() { final String errorLog = "*****************************************************************************\n" + @@ -137,13 +92,5 @@ private static void logPinpointAgentLoadFail() { System.err.println(errorLog); } - private static JarFile getJarFile(String jarFilePath) { - try { - return new JarFile(jarFilePath); - } catch (IOException ioe) { - logger.warn(jarFilePath + " file not found.", ioe); - return null; - } - } } diff --git a/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/PinpointStarter.java b/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/PinpointStarter.java index 51e6b966987d..9d0da6a26220 100644 --- a/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/PinpointStarter.java +++ b/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/PinpointStarter.java @@ -16,18 +16,12 @@ import java.lang.instrument.Instrumentation; import java.net.URL; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Scanner; import com.navercorp.pinpoint.ProductInfo; import com.navercorp.pinpoint.bootstrap.config.DefaultProfilerConfig; import com.navercorp.pinpoint.bootstrap.config.ProfilerConfig; -import com.navercorp.pinpoint.bootstrap.util.IdValidateUtils; -import com.navercorp.pinpoint.common.PinpointConstants; import com.navercorp.pinpoint.common.Version; import com.navercorp.pinpoint.common.service.AnnotationKeyRegistryService; import com.navercorp.pinpoint.common.service.DefaultAnnotationKeyRegistryService; @@ -35,7 +29,6 @@ import com.navercorp.pinpoint.common.service.DefaultTraceMetadataLoaderService; import com.navercorp.pinpoint.common.service.ServiceTypeRegistryService; import com.navercorp.pinpoint.common.service.TraceMetadataLoaderService; -import com.navercorp.pinpoint.common.util.BytesUtils; import com.navercorp.pinpoint.common.util.PinpointThreadFactory; import com.navercorp.pinpoint.common.util.SimpleProperty; import com.navercorp.pinpoint.common.util.SystemProperty; @@ -52,73 +45,47 @@ public class PinpointStarter { private final BootLogger logger = BootLogger.getLogger(PinpointStarter.class.getName()); public static final String BOOT_CLASS = "com.navercorp.pinpoint.profiler.DefaultAgent"; + public static final String PLUGIN_TEST_BOOT_CLASS = "com.navercorp.pinpoint.test.PluginTestAgent"; private SimpleProperty systemProperty = SystemProperty.INSTANCE; - private final String agentArgs; - private List bootstrapJars; - private final Map argMap; + + private final Map agentArgs; + private final BootstrapJarFile bootstrapJarFile; + private final ClassPathResolver classPathResolver; private final Instrumentation instrumentation; - public PinpointStarter(String agentArgs, Instrumentation instrumentation) { - if (agentArgs != null) { - logger.info(ProductInfo.NAME + " agentArgs:" + agentArgs); + public PinpointStarter(Map agentArgs, BootstrapJarFile bootstrapJarFile, ClassPathResolver classPathResolver, Instrumentation instrumentation) { + if (agentArgs == null) { + throw new NullPointerException("agentArgs must not be null"); + } + if (bootstrapJarFile == null) { + throw new NullPointerException("bootstrapJarFile must not be null"); + } + if (classPathResolver == null) { + throw new NullPointerException("classPathResolver must not be null"); } if (instrumentation == null) { throw new NullPointerException("instrumentation must not be null"); } - this.agentArgs = agentArgs; - this.argMap = parseAgentArgs(agentArgs); + this.bootstrapJarFile = bootstrapJarFile; + this.classPathResolver = classPathResolver; this.instrumentation = instrumentation; - this.bootstrapJars = new ArrayList(); + } - public void start() { - // 1st find boot-strap.jar - final ClassPathResolver classPathResolver = new ClassPathResolver(); - boolean agentJarNotFound = classPathResolver.findAgentJar(); - if (!agentJarNotFound) { - logger.warn("pinpoint-bootstrap-x.x.x(-SNAPSHOT).jar Fnot found."); - logPinpointAgentLoadFail(); - return; + public boolean start() { + final IdValidator idValidator = new IdValidator(); + final String agentId = idValidator.getAgentId(); + if (agentId == null) { + return false; } - - // 2nd find pinpoint-commons.jar - final String pinpointCommonsJar = classPathResolver.getPinpointCommonsJar(); - if (pinpointCommonsJar == null) { - logger.warn("pinpoint-commons-x.x.x(-SNAPSHOT).jar not found"); - logPinpointAgentLoadFail(); - return; + final String applicationName = idValidator.getApplicationName(); + if (applicationName == null) { + return false; } - this.bootstrapJars.add(pinpointCommonsJar); - // 3rd find bootstrap-core.jar - final String bootStrapCoreJar = classPathResolver.getBootStrapCoreJar(); - if (bootStrapCoreJar == null) { - logger.warn("pinpoint-bootstrap-core-x.x.x(-SNAPSHOT).jar not found"); - logPinpointAgentLoadFail(); - return; - } - this.bootstrapJars.add(bootStrapCoreJar); - - // 4th find bootstrap-core-optional.jar - final String bootStrapCoreOptionalJar = classPathResolver.getBootStrapCoreOptionalJar(); - if (bootStrapCoreOptionalJar == null) { - logger.info("pinpoint-bootstrap-core-optional-x.x.x(-SNAPSHOT).jar not found"); - } else { - this.bootstrapJars.add(bootStrapCoreOptionalJar); - } - - if (!isValidId("pinpoint.agentId", PinpointConstants.AGENT_NAME_MAX_LEN)) { - logPinpointAgentLoadFail(); - return; - } - if (!isValidId("pinpoint.applicationName", PinpointConstants.APPLICATION_NAME_MAX_LEN)) { - logPinpointAgentLoadFail(); - return; - } - URL[] pluginJars = classPathResolver.resolvePlugins(); // TODO using PLogger instead of CommonLogger @@ -129,8 +96,7 @@ public void start() { String configPath = getConfigPath(classPathResolver); if (configPath == null) { - logPinpointAgentLoadFail(); - return; + return false; } // set the path of log file as a system property @@ -145,25 +111,49 @@ public void start() { // this is the library list that must be loaded List libUrlList = resolveLib(classPathResolver); AgentClassLoader agentClassLoader = new AgentClassLoader(libUrlList.toArray(new URL[libUrlList.size()])); - String bootClass = argMap.containsKey("bootClass") ? argMap.get("bootClass") : BOOT_CLASS; + final String bootClass = getBootClass(); agentClassLoader.setBootClass(bootClass); logger.info("pinpoint agent [" + bootClass + "] starting..."); - AgentOption option = createAgentOption(agentArgs, instrumentation, profilerConfig, pluginJars, bootstrapJars, serviceTypeRegistryService, annotationKeyRegistryService); + + AgentOption option = createAgentOption(agentId, applicationName, profilerConfig, instrumentation, pluginJars, bootstrapJarFile, serviceTypeRegistryService, annotationKeyRegistryService); Agent pinpointAgent = agentClassLoader.boot(option); pinpointAgent.start(); registerShutdownHook(pinpointAgent); logger.info("pinpoint agent started normally."); } catch (Exception e) { // unexpected exception that did not be checked above - logger.warn(ProductInfo.NAME + " start failed. Error:" + e.getMessage(), e); - logPinpointAgentLoadFail(); + logger.warn(ProductInfo.NAME + " start failed.", e); + return false; } + return true; } - private AgentOption createAgentOption(String agentArgs, Instrumentation instrumentation, ProfilerConfig profilerConfig, URL[] pluginJars, List bootstrapJarPaths, ServiceTypeRegistryService serviceTypeRegistryService, AnnotationKeyRegistryService annotationKeyRegistryService) { + private String getBootClass() { + final String agentType = getAgentType().toUpperCase(); + if ("PLUGIN_TEST".equals(agentType)) { + return PLUGIN_TEST_BOOT_CLASS; + } + return BOOT_CLASS; + } - return new DefaultAgentOption(agentArgs, instrumentation, profilerConfig, pluginJars, bootstrapJarPaths, serviceTypeRegistryService, annotationKeyRegistryService); + private String getAgentType() { + String agentType = agentArgs.get("AGENT_TYPE"); + if (agentType == null) { + return "DEFAULT_AGENT"; + } + return agentType; + + } + + private AgentOption createAgentOption(String agentId, String applicationName, ProfilerConfig profilerConfig, + Instrumentation instrumentation, + URL[] pluginJars, + BootstrapJarFile bootstrapJarFile, + ServiceTypeRegistryService serviceTypeRegistryService, + AnnotationKeyRegistryService annotationKeyRegistryService) { + List bootstrapJarPaths = bootstrapJarFile.getJarNameList(); + return new DefaultAgentOption(instrumentation, agentId, applicationName, profilerConfig, pluginJars, bootstrapJarPaths, serviceTypeRegistryService, annotationKeyRegistryService); } // for test @@ -183,72 +173,6 @@ public void run() { Runtime.getRuntime().addShutdownHook(thread); } - private Map parseAgentArgs(String str) { - Map map = new HashMap(); - - if (str == null || str.isEmpty()) { - return map; - } - - Scanner scanner = new Scanner(str); - scanner.useDelimiter("\\s*,\\s*"); - - while (scanner.hasNext()) { - String token = scanner.next(); - int assign = token.indexOf('='); - - if (assign == -1) { - map.put(token, ""); - } else { - map.put(token.substring(0, assign), token.substring(assign + 1)); - } - } - scanner.close(); - return Collections.unmodifiableMap(map); - } - - private void logPinpointAgentLoadFail() throws PinpointException { - final String errorLog = - "*****************************************************************************\n" + - "* Pinpoint Agent load failure\n" + - "*****************************************************************************"; - System.err.println(errorLog); - } - - - private boolean isValidId(String propertyName, int maxSize) { - logger.info("check -D" + propertyName); - String value = systemProperty.getProperty(propertyName); - if (value == null){ - logger.warn("-D" + propertyName + " is null. value:null"); - return false; - } - // blanks not permitted around value - value = value.trim(); - if (value.isEmpty()) { - logger.warn("-D" + propertyName + " is empty. value:''"); - return false; - } - - if (!IdValidateUtils.validateId(value, maxSize)) { - logger.warn("invalid Id. " + propertyName + " can only contain [a-zA-Z0-9], '.', '-', '_'. maxLength:" + maxSize + " value:" + value); - return false; - } - if (logger.isInfoEnabled()) { - logger.info("check success. -D" + propertyName + ":" + value + " length:" + getLength(value)); - } - return true; - } - - private int getLength(String value) { - final byte[] bytes = BytesUtils.toBytes(value); - if (bytes == null) { - return 0; - } else { - return bytes.length; - } - } - private void saveLogFilePath(ClassPathResolver classPathResolver) { String agentLogFilePath = classPathResolver.getAgentLogFilePath(); @@ -289,9 +213,11 @@ private List resolveLib(ClassPathResolver classPathResolver) { String agentConfigPath = classPathResolver.getAgentConfigPath(); if (logger.isInfoEnabled()) { - logger.info("agentJarPath:" + agentJarFullPath); - logger.info("agentLibPath:" + agentLibPath); - logger.info("agent lib list:" + urlList); + logger.info("agent JarPath:" + agentJarFullPath); + logger.info("agent LibDir:" + agentLibPath); + for (URL url : urlList) { + logger.info("agent Lib:" + url); + } logger.info("agent config:" + agentConfigPath); } diff --git a/bootstrap/src/test/java/com/navercorp/pinpoint/bootstrap/AgentClassLoaderTest.java b/bootstrap/src/test/java/com/navercorp/pinpoint/bootstrap/AgentClassLoaderTest.java index 01ab1e05422a..d15f6e673176 100644 --- a/bootstrap/src/test/java/com/navercorp/pinpoint/bootstrap/AgentClassLoaderTest.java +++ b/bootstrap/src/test/java/com/navercorp/pinpoint/bootstrap/AgentClassLoaderTest.java @@ -41,7 +41,7 @@ public class AgentClassLoaderTest { public void boot() throws IOException, ClassNotFoundException { AgentClassLoader agentClassLoader = new AgentClassLoader(new URL[0]); agentClassLoader.setBootClass("com.navercorp.pinpoint.bootstrap.DummyAgent"); - AgentOption option = new DefaultAgentOption("test", new DummyInstrumentation(), new DefaultProfilerConfig(), new URL[0], null, new DefaultServiceTypeRegistryService(), new DefaultAnnotationKeyRegistryService()); + AgentOption option = new DefaultAgentOption(new DummyInstrumentation(), "testCaseAgent", "testCaseAppName", new DefaultProfilerConfig(), new URL[0], null, new DefaultServiceTypeRegistryService(), new DefaultAnnotationKeyRegistryService()); agentClassLoader.boot(option); // TODO need verification - implementation for obtaining logger changed // PLoggerBinder loggerBinder = (PLoggerBinder) agentClassLoader.initializeLoggerBinder(); diff --git a/bootstrap/src/test/java/com/navercorp/pinpoint/bootstrap/AgentDirBaseClassPathResolverTest.java b/bootstrap/src/test/java/com/navercorp/pinpoint/bootstrap/AgentDirBaseClassPathResolverTest.java new file mode 100644 index 000000000000..7fbfe0ba8703 --- /dev/null +++ b/bootstrap/src/test/java/com/navercorp/pinpoint/bootstrap/AgentDirBaseClassPathResolverTest.java @@ -0,0 +1,94 @@ +/* + * Copyright 2014 NAVER Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.navercorp.pinpoint.bootstrap; + +import com.navercorp.pinpoint.common.Version; +import org.junit.Assert; +import org.junit.Ignore; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.File; + +/** + * @author emeroad + */ +//@Ignore +public class AgentDirBaseClassPathResolverTest { + + private final Logger logger = LoggerFactory.getLogger(this.getClass()); + + // --------------------------- + // setup Agent build dir + private String agentBuildDir = "___setup Agent build dir___"; + // --------------------------- + + private String testBootStrapJar = "pinpoint-bootstrap-" + Version.VERSION + ".jar"; + private String agentBootstrapPath = agentBuildDir + File.separator + testBootStrapJar; + + @Test + public void testFindAgentJar() throws Exception { + + logger.debug("testAgentDir:{}", agentBuildDir); + logger.debug("agentBootstrapPath:{}", agentBootstrapPath); + + AgentDirBaseClassPathResolver classPathResolver = new AgentDirBaseClassPathResolver(agentBootstrapPath); + Assert.assertTrue("verify agent directory ", classPathResolver.verify()); + + boolean findAgentJar = classPathResolver.findAgentJar(); + Assert.assertTrue(findAgentJar); + + String agentJar = classPathResolver.getAgentJarName(); + Assert.assertEquals(testBootStrapJar, agentJar); + + String agentPath = classPathResolver.getAgentJarFullPath(); + Assert.assertEquals(agentBootstrapPath, agentPath); + + String agentDirPath = classPathResolver.getAgentDirPath(); + Assert.assertEquals(agentBuildDir, agentDirPath); + + String agentLibPath = classPathResolver.getAgentLibPath(); + Assert.assertEquals(agentBuildDir + File.separator + "lib", agentLibPath); + } + + + @Test + public void findAgentJar() { + logger.debug("testAgentDir:{}", agentBuildDir); + logger.debug("agentBootstrapPath:{}", agentBootstrapPath); + + findAgentJar(agentBootstrapPath); + + + findAgentJarAssertFail(agentBuildDir + File.separator + "pinpoint-bootstrap-unknown.jar"); + } + + private void findAgentJar(String path) { + AgentDirBaseClassPathResolver classPathResolver = new AgentDirBaseClassPathResolver(path); + boolean agentJar = classPathResolver.findAgentJar(); + Assert.assertTrue(agentJar); + } + + private void findAgentJarAssertFail(String path) { + AgentDirBaseClassPathResolver classPathResolver = new AgentDirBaseClassPathResolver(path); + boolean agentJar = classPathResolver.findAgentJar(); + Assert.assertFalse(agentJar); + } + +} + diff --git a/bootstrap/src/test/java/com/navercorp/pinpoint/bootstrap/ClassPathResolverTest.java b/bootstrap/src/test/java/com/navercorp/pinpoint/bootstrap/ClassPathResolverTest.java deleted file mode 100644 index 35732756211a..000000000000 --- a/bootstrap/src/test/java/com/navercorp/pinpoint/bootstrap/ClassPathResolverTest.java +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Copyright 2014 NAVER Corp. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.navercorp.pinpoint.bootstrap; - -import com.navercorp.pinpoint.bootstrap.ClassPathResolver; - -import org.junit.Assert; -import org.junit.Ignore; -import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.File; - -/** - * @author emeroad - */ -@Ignore -public class ClassPathResolverTest { - - private final Logger logger = LoggerFactory.getLogger(this.getClass()); - - - @Test - public void testFindAgentJar() throws Exception { - String path = "D:\\nhn_source\\pinpoint_project\\deploy\\apache-tomcat-6.0.35\\bin\\bootstrap.jar;D:\\nhn_source\\pinpoint_project\\deploy\\agent\\agentlib/lib/javassist-3.16.1.GA.jar;" + - "D:\\nhn_source\\pinpoint_project\\deploy\\agent\\agentlib/lib/pinpoint-commons-0.0.2.jar;;D:\\nhn_source\\pinpoint_project\\deploy\\agent\\agentlib/pinpoint-bootstrap-0.0.2.jar"; - // D:\nhn_source\pinpoint_project\deploy\agent\agentlib/pinpoint-tomcat-profiler-0.0.2.jar - ClassPathResolver classPathResolver = new ClassPathResolver(path); - boolean findAgentJar = classPathResolver.findAgentJar(); - Assert.assertTrue(findAgentJar); - - String agentJar = classPathResolver.getAgentJarName(); - Assert.assertEquals("pinpoint-bootstrap-0.0.2.jar", agentJar); - - String agentPath = classPathResolver.getAgentJarFullPath(); - Assert.assertEquals("D:\\nhn_source\\pinpoint_project\\deploy\\agent\\agentlib/pinpoint-bootstrap-0.0.2.jar", agentPath); - - String agentDirPath = classPathResolver.getAgentDirPath(); - Assert.assertEquals("D:\\nhn_source\\pinpoint_project\\deploy\\agent\\agentlib", agentDirPath ); - - String agentLibPath = classPathResolver.getAgentLibPath(); - Assert.assertEquals("D:\\nhn_source\\pinpoint_project\\deploy\\agent\\agentlib"+File.separator+ "lib", agentLibPath); - } - - @Test - public void testFindAgentSnapshotJar() throws Exception { - String path = "D:\\nhn_source\\pinpoint_project\\deploy\\apache-tomcat-6.0.35\\bin\\bootstrap.jar;D:\\nhn_source\\pinpoint_project\\deploy\\agent\\agentlib/lib/javassist-3.16.1.GA.jar;" + - "D:\\nhn_source\\pinpoint_project\\deploy\\agent\\agentlib/lib/pinpoint-commons-0.0.2.jar;;D:\\nhn_source\\pinpoint_project\\deploy\\agent\\agentlib" + - "/pinpoint-bootstrap-0.0.2-SNAPSHOT.jar"; - // D:\nhn_source\pinpoint_project\deploy\agent\agentlib/pinpoint-tomcat-profiler-0.0.2.jar - ClassPathResolver classPathResolver = new ClassPathResolver(path); - boolean findAgentJar = classPathResolver.findAgentJar(); - Assert.assertTrue(findAgentJar); - - String agentJar = classPathResolver.getAgentJarName(); - Assert.assertEquals("pinpoint-bootstrap-0.0.2-SNAPSHOT.jar", agentJar); - - String agentPath = classPathResolver.getAgentJarFullPath(); - Assert.assertEquals("D:\\nhn_source\\pinpoint_project\\deploy\\agent\\agentlib/pinpoint-bootstrap-0.0.2-SNAPSHOT.jar", agentPath); - - String agentDirPath = classPathResolver.getAgentDirPath(); - Assert.assertEquals("D:\\nhn_source\\pinpoint_project\\deploy\\agent\\agentlib", agentDirPath ); - - String agentLibPath = classPathResolver.getAgentLibPath(); - Assert.assertEquals("D:\\nhn_source\\pinpoint_project\\deploy\\agent\\agentlib"+File.separator+ "lib", agentLibPath); - } - - @Test - public void findAgentJar() { - findAgentJar("pinpoint-bootstrap-0.0.2.jar"); - findAgentJar("pinpoint-bootstrap-1.0.0.jar"); - findAgentJar("pinpoint-bootstrap-1.10.20.jar"); - findAgentJar("pinpoint-bootstrap.jar"); - - - findAgentJarAssertFail("pinpoint-bootstrap-1.a.test.jar"); - findAgentJarAssertFail("pinpointbootstrap-1.a.test.jar"); - findAgentJarAssertFail("pinpointbootstrap.jar"); - } - - private void findAgentJar(String path) { - ClassPathResolver classPathResolver = new ClassPathResolver(path); - boolean agentJar = classPathResolver.findAgentJar(); - Assert.assertTrue(agentJar); - } - - private void findAgentJarAssertFail(String path) { - ClassPathResolver classPathResolver = new ClassPathResolver(path); - boolean agentJar = classPathResolver.findAgentJar(); - Assert.assertFalse(agentJar); - } - - @Test - public void nullArray() { - String[] nullArray = null; - try { - for (String str : nullArray) { - logger.warn("null"); - } - Assert.fail(); - } catch (Exception ignored) { - } - } -} - diff --git a/bootstrap/src/test/java/com/navercorp/pinpoint/bootstrap/PinpointBootStrapTest.java b/bootstrap/src/test/java/com/navercorp/pinpoint/bootstrap/LoadStateTest.java similarity index 58% rename from bootstrap/src/test/java/com/navercorp/pinpoint/bootstrap/PinpointBootStrapTest.java rename to bootstrap/src/test/java/com/navercorp/pinpoint/bootstrap/LoadStateTest.java index 229b161c2bd1..743ef734b388 100644 --- a/bootstrap/src/test/java/com/navercorp/pinpoint/bootstrap/PinpointBootStrapTest.java +++ b/bootstrap/src/test/java/com/navercorp/pinpoint/bootstrap/LoadStateTest.java @@ -20,21 +20,18 @@ import org.junit.Test; -import com.navercorp.pinpoint.bootstrap.PinpointBootStrap; - /** * @author emeroad */ -public class PinpointBootStrapTest { +public class LoadStateTest { @Test - public void testDuplicatedLoadCheck() throws Exception { - Assert.assertFalse(PinpointBootStrap.getLoadState()); - PinpointBootStrap.premain("test", new DummyInstrumentation()); + public void testStart() throws Exception { + LoadState loadState = new LoadState(); + + Assert.assertTrue(loadState.start()); + Assert.assertTrue(loadState.getState()); - Assert.assertTrue(PinpointBootStrap.getLoadState()); + Assert.assertFalse(loadState.start()); - PinpointBootStrap.premain("test", new DummyInstrumentation()); - // is leaving a log the only way to test for duplicate loading? - // ? check } } diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/AgentInformationFactory.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/AgentInformationFactory.java index 907a59a2fbcd..3acc60419c0a 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/AgentInformationFactory.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/AgentInformationFactory.java @@ -16,63 +16,53 @@ package com.navercorp.pinpoint.profiler; +import com.navercorp.pinpoint.bootstrap.util.IdValidateUtils; import com.navercorp.pinpoint.bootstrap.util.NetworkUtils; -import com.navercorp.pinpoint.common.PinpointConstants; import com.navercorp.pinpoint.common.Version; import com.navercorp.pinpoint.common.trace.ServiceType; -import com.navercorp.pinpoint.common.util.BytesUtils; import com.navercorp.pinpoint.common.util.JvmUtils; -import com.navercorp.pinpoint.common.util.SimpleProperty; -import com.navercorp.pinpoint.common.util.SystemProperty; import com.navercorp.pinpoint.common.util.SystemPropertyKey; import com.navercorp.pinpoint.profiler.util.RuntimeMXBeanUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; /** * @author emeroad */ public class AgentInformationFactory { - private final Logger logger = LoggerFactory.getLogger(this.getClass()); - private final SimpleProperty systemProperty = SystemProperty.INSTANCE; + private final String agentId; + private final String applicationName; - public AgentInformationFactory() { + public AgentInformationFactory(String agentId, String applicationName) { + if (agentId == null) { + throw new NullPointerException("agentId must not be null"); + } + if (applicationName == null) { + throw new NullPointerException("applicationName must not be null"); + } + + this.agentId = checkId(agentId); + this.applicationName = checkId(applicationName); } public AgentInformation createAgentInformation(ServiceType serverType) { if (serverType == null) { throw new NullPointerException("serverType must not be null"); } - // For compatibility issue, use machineName as agentId when agengId is not provided. - // This could be a problem if more than one server instances run on a box. final String machineName = NetworkUtils.getHostName(); final String hostIp = NetworkUtils.getHostIp(); - final String agentId = getId("pinpoint.agentId", machineName, PinpointConstants.AGENT_NAME_MAX_LEN); - final String applicationName = getId("pinpoint.applicationName", "UnknownApplicationName", PinpointConstants.APPLICATION_NAME_MAX_LEN); final long startTime = RuntimeMXBeanUtils.getVmStartTime(); final int pid = RuntimeMXBeanUtils.getPid(); final String jvmVersion = JvmUtils.getSystemProperty(SystemPropertyKey.JAVA_VERSION); return new AgentInformation(agentId, applicationName, startTime, pid, machineName, hostIp, serverType, jvmVersion, Version.VERSION); } - private String getId(String key, String defaultValue, int maxlen) { - String value = systemProperty.getProperty(key, defaultValue); - validateId(value, key, maxlen); - return value; + private String checkId(String id) { + if (!IdValidateUtils.validateId(id)) { + throw new IllegalStateException("invalid Id=" + id); + } + return id; } - private void validateId(String id, String idName, int maxlen) { - if (id == null) { - throw new NullPointerException("id must not be null"); - } - // TODO AgengId should be validated BEFORE bootclass. - // or agent should stop when validation is failed here. - final byte[] bytes = BytesUtils.toBytes(id); - if (bytes.length > maxlen) { - logger.warn("{} is too long(1~24). value={}", idName, id); - } - } } diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/DefaultAgent.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/DefaultAgent.java index 8e05274aecfd..5ecc19d4a504 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/DefaultAgent.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/DefaultAgent.java @@ -191,7 +191,7 @@ public DefaultAgent(AgentOption agentOption, final InterceptorRegistryBinder int final ApplicationServerTypeResolver typeResolver = new ApplicationServerTypeResolver(pluginContexts, applicationServerType, profilerConfig.getApplicationTypeDetectOrder()); - final AgentInformationFactory agentInformationFactory = new AgentInformationFactory(); + final AgentInformationFactory agentInformationFactory = new AgentInformationFactory(agentOption.getAgentId(), agentOption.getApplicationName()); this.agentInformation = agentInformationFactory.createAgentInformation(typeResolver.resolve()); logger.info("agentInformation:{}", agentInformation); diff --git a/profiler/src/main/java/com/navercorp/pinpoint/test/MockAgent.java b/profiler/src/main/java/com/navercorp/pinpoint/test/MockAgent.java index 4db9680b521f..eef68eb83179 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/test/MockAgent.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/test/MockAgent.java @@ -78,7 +78,7 @@ public static MockAgent of(String configPath) { } public static MockAgent of(ProfilerConfig config) { - AgentOption agentOption = new DefaultAgentOption("", new DummyInstrumentation(), config, new URL[0], null, new DefaultServiceTypeRegistryService(), new DefaultAnnotationKeyRegistryService()); + AgentOption agentOption = new DefaultAgentOption(new DummyInstrumentation(), "mockAgent", "mockApplicationName", config, new URL[0], null, new DefaultServiceTypeRegistryService(), new DefaultAnnotationKeyRegistryService()); InterceptorRegistryBinder binder = new TestInterceptorRegistryBinder(); return new MockAgent(agentOption, binder); diff --git a/test/src/main/java/com/navercorp/pinpoint/test/plugin/PinpointPluginTestStatement.java b/test/src/main/java/com/navercorp/pinpoint/test/plugin/PinpointPluginTestStatement.java index 9d5becf1245e..47ed2b50090e 100644 --- a/test/src/main/java/com/navercorp/pinpoint/test/plugin/PinpointPluginTestStatement.java +++ b/test/src/main/java/com/navercorp/pinpoint/test/plugin/PinpointPluginTestStatement.java @@ -185,7 +185,7 @@ private List getDebugOptions() { } private String getAgent() { - return "-javaagent:" + context.getAgentJar() + "=bootClass=com.navercorp.pinpoint.test.PluginTestAgent"; + return "-javaagent:" + context.getAgentJar() + "=AGENT_TYPE=PLUGIN_TEST"; } private String getClassPathAsString() {