Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
阿信在这里
SkyWalking
提交
eb507496
S
SkyWalking
项目概览
阿信在这里
/
SkyWalking
与 Fork 源项目一致
Fork自
山不在高_有仙则灵 / SkyWalking
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
SkyWalking
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
eb507496
编写于
10月 14, 2017
作者:
wu-sheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Reoragnize the startup procedure.
上级
b3125f88
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
268 addition
and
71 deletion
+268
-71
apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/boot/AgentPackageNotFoundException.java
...ng/apm/agent/core/boot/AgentPackageNotFoundException.java
+28
-0
apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/boot/AgentPackagePath.java
.../org/skywalking/apm/agent/core/boot/AgentPackagePath.java
+71
-0
apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/conf/ConfigNotFoundException.java
...ywalking/apm/agent/core/conf/ConfigNotFoundException.java
+32
-0
apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/conf/SnifferConfigInitializer.java
...walking/apm/agent/core/conf/SnifferConfigInitializer.java
+18
-67
apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/PluginBootstrap.java
...org/skywalking/apm/agent/core/plugin/PluginBootstrap.java
+6
-1
apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/loader/PluginClassLoader.java
...lking/apm/agent/core/plugin/loader/PluginClassLoader.java
+104
-0
apm-sniffer/apm-agent/src/main/java/org/skywalking/apm/agent/SkyWalkingAgent.java
...c/main/java/org/skywalking/apm/agent/SkyWalkingAgent.java
+9
-3
未找到文件。
apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/boot/AgentPackageNotFoundException.java
0 → 100644
浏览文件 @
eb507496
/*
* Copyright 2017, OpenSkywalking Organization All rights reserved.
*
* 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.
*
* Project repository: https://github.com/OpenSkywalking/skywalking
*/
package
org.skywalking.apm.agent.core.boot
;
/**
* @author wusheng
*/
public
class
AgentPackageNotFoundException
extends
Exception
{
public
AgentPackageNotFoundException
(
String
message
)
{
super
(
message
);
}
}
apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/boot/AgentPackagePath.java
0 → 100644
浏览文件 @
eb507496
/*
* Copyright 2017, OpenSkywalking Organization All rights reserved.
*
* 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.
*
* Project repository: https://github.com/OpenSkywalking/skywalking
*/
package
org.skywalking.apm.agent.core.boot
;
import
java.io.File
;
import
java.net.MalformedURLException
;
import
java.net.URL
;
import
org.skywalking.apm.agent.core.logging.SystemOutWriter
;
import
org.skywalking.apm.logging.ILog
;
import
org.skywalking.apm.logging.LogManager
;
/**
* @author wusheng
*/
public
class
AgentPackagePath
{
private
static
final
ILog
logger
=
LogManager
.
getLogger
(
AgentPackagePath
.
class
);
private
static
File
AGENT_PACKAGE_PATH
;
public
static
File
getPath
()
throws
AgentPackageNotFoundException
{
if
(
AGENT_PACKAGE_PATH
==
null
)
{
AGENT_PACKAGE_PATH
=
findPath
();
}
return
AGENT_PACKAGE_PATH
;
}
private
static
File
findPath
()
throws
AgentPackageNotFoundException
{
String
classResourcePath
=
AgentPackagePath
.
class
.
getName
().
replaceAll
(
"\\."
,
"/"
)
+
".class"
;
URL
resource
=
AgentPackagePath
.
class
.
getClassLoader
().
getSystemClassLoader
().
getResource
(
classResourcePath
);
if
(
resource
!=
null
)
{
String
urlString
=
resource
.
toString
();
SystemOutWriter
.
INSTANCE
.
write
(
urlString
);
logger
.
debug
(
urlString
);
urlString
=
urlString
.
substring
(
urlString
.
indexOf
(
"file:"
),
urlString
.
indexOf
(
'!'
));
File
agentJarFile
=
null
;
try
{
agentJarFile
=
new
File
(
new
URL
(
urlString
).
getFile
());
}
catch
(
MalformedURLException
e
)
{
SystemOutWriter
.
INSTANCE
.
write
(
"Can not locate agent jar file by url:"
+
urlString
);
logger
.
error
(
e
,
"Can not locate agent jar file by url: {}"
,
urlString
);
}
if
(
agentJarFile
.
exists
())
{
return
agentJarFile
.
getParentFile
();
}
}
SystemOutWriter
.
INSTANCE
.
write
(
"Can not locate agent jar file."
);
logger
.
info
(
"Can not locate agent jar file."
);
throw
new
AgentPackageNotFoundException
(
"Can not locate agent jar file."
);
}
}
apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/conf/ConfigNotFoundException.java
0 → 100644
浏览文件 @
eb507496
/*
* Copyright 2017, OpenSkywalking Organization All rights reserved.
*
* 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.
*
* Project repository: https://github.com/OpenSkywalking/skywalking
*/
package
org.skywalking.apm.agent.core.conf
;
/**
* @author wusheng
*/
public
class
ConfigNotFoundException
extends
Exception
{
public
ConfigNotFoundException
(
String
message
,
Throwable
cause
)
{
super
(
message
,
cause
);
}
public
ConfigNotFoundException
(
String
message
)
{
super
(
message
);
}
}
apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/conf/SnifferConfigInitializer.java
浏览文件 @
eb507496
...
...
@@ -22,9 +22,9 @@ import java.io.File;
import
java.io.FileInputStream
;
import
java.io.FileNotFoundException
;
import
java.io.InputStream
;
import
java.net.MalformedURLException
;
import
java.net.URL
;
import
java.util.Properties
;
import
org.skywalking.apm.agent.core.boot.AgentPackageNotFoundException
;
import
org.skywalking.apm.agent.core.boot.AgentPackagePath
;
import
org.skywalking.apm.logging.ILog
;
import
org.skywalking.apm.logging.LogManager
;
import
org.skywalking.apm.util.ConfigInitializer
;
...
...
@@ -52,32 +52,17 @@ public class SnifferConfigInitializer {
* 1. applicationCode. "-DapplicationCode=" or {@link Config.Agent#APPLICATION_CODE}
* 2. servers. "-Dservers=" or {@link Config.Collector#SERVERS}
*/
public
static
void
initialize
()
{
public
static
void
initialize
()
throws
ConfigNotFoundException
,
AgentPackageNotFoundException
{
InputStream
configFileStream
;
configFileStream
=
loadConfig
BySystemProperty
();
configFileStream
=
loadConfig
FromAgentFolder
();
if
(
configFileStream
==
null
)
{
configFileStream
=
SnifferConfigInitializer
.
class
.
getResourceAsStream
(
CONFIG_FILE_NAME
);
if
(
configFileStream
==
null
)
{
logger
.
info
(
"No config file found, according system property '-Dconfig'."
);
configFileStream
=
loadConfigFromAgentFolder
();
}
else
{
logger
.
info
(
"{} file found in class path."
,
CONFIG_FILE_NAME
);
}
}
if
(
configFileStream
==
null
)
{
logger
.
info
(
"No {} found, sky-walking is going to run in default config."
,
CONFIG_FILE_NAME
);
}
else
{
try
{
Properties
properties
=
new
Properties
();
properties
.
load
(
configFileStream
);
ConfigInitializer
.
initialize
(
properties
,
Config
.
class
);
}
catch
(
Exception
e
)
{
logger
.
error
(
"Failed to read the config file, sky-walking is going to run in default config."
,
e
);
}
try
{
Properties
properties
=
new
Properties
();
properties
.
load
(
configFileStream
);
ConfigInitializer
.
initialize
(
properties
,
Config
.
class
);
}
catch
(
Exception
e
)
{
logger
.
error
(
"Failed to read the config file, sky-walking is going to run in default config."
,
e
);
}
String
applicationCode
=
System
.
getProperty
(
"applicationCode"
);
...
...
@@ -131,50 +116,16 @@ public class SnifferConfigInitializer {
*
* @return the config file {@link InputStream}, or null if not needEnhance.
*/
private
static
InputStream
loadConfigFromAgentFolder
()
{
String
agentBasePath
=
initAgentBasePath
();
if
(!
StringUtil
.
isEmpty
(
agentBasePath
))
{
File
configFile
=
new
File
(
agentBasePath
,
CONFIG_FILE_NAME
);
if
(
configFile
.
exists
()
&&
configFile
.
isFile
())
{
try
{
logger
.
info
(
"{} file found in agent folder."
,
CONFIG_FILE_NAME
);
return
new
FileInputStream
(
configFile
);
}
catch
(
FileNotFoundException
e
)
{
logger
.
error
(
e
,
"Fail to load {} in path {}, according auto-agent-folder mechanism."
,
CONFIG_FILE_NAME
,
agentBasePath
);
}
}
}
logger
.
info
(
"No {} file found in agent folder."
,
CONFIG_FILE_NAME
);
return
null
;
}
/**
* Try to allocate the skywalking-agent.jar
* Some config files or output resources are from this path.
*
* @return he path, where the skywalking-agent.jar is
*/
private
static
String
initAgentBasePath
()
{
String
classResourcePath
=
SnifferConfigInitializer
.
class
.
getName
().
replaceAll
(
"\\."
,
"/"
)
+
".class"
;
URL
resource
=
SnifferConfigInitializer
.
class
.
getClassLoader
().
getSystemClassLoader
().
getResource
(
classResourcePath
);
if
(
resource
!=
null
)
{
String
urlString
=
resource
.
toString
();
logger
.
debug
(
urlString
);
urlString
=
urlString
.
substring
(
urlString
.
indexOf
(
"file:"
),
urlString
.
indexOf
(
'!'
));
File
agentJarFile
=
null
;
private
static
InputStream
loadConfigFromAgentFolder
()
throws
AgentPackageNotFoundException
,
ConfigNotFoundException
{
File
configFile
=
new
File
(
AgentPackagePath
.
getPath
(),
CONFIG_FILE_NAME
);
if
(
configFile
.
exists
()
&&
configFile
.
isFile
())
{
try
{
agentJarFile
=
new
File
(
new
URL
(
urlString
).
getFile
());
}
catch
(
MalformedURLException
e
)
{
logger
.
error
(
e
,
"Can not locate agent jar file by url:"
,
urlString
);
}
if
(
agentJarFile
.
exists
())
{
return
agentJarFile
.
getParentFile
().
getAbsolutePath
();
logger
.
info
(
"{} file found in agent folder."
,
CONFIG_FILE_NAME
);
return
new
FileInputStream
(
configFile
);
}
catch
(
FileNotFoundException
e
)
{
throw
new
ConfigNotFoundException
(
"Fail to load agent.config"
,
e
);
}
}
logger
.
info
(
"Can not locate agent jar file."
);
return
null
;
throw
new
ConfigNotFoundException
(
"Fail to load agent.config"
);
}
}
apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/PluginBootstrap.java
浏览文件 @
eb507496
...
...
@@ -21,6 +21,9 @@ package org.skywalking.apm.agent.core.plugin;
import
java.net.URL
;
import
java.util.ArrayList
;
import
java.util.List
;
import
org.skywalking.apm.agent.core.boot.AgentPackageNotFoundException
;
import
org.skywalking.apm.agent.core.boot.AgentPackagePath
;
import
org.skywalking.apm.agent.core.plugin.loader.PluginClassLoader
;
import
org.skywalking.apm.logging.ILog
;
import
org.skywalking.apm.logging.LogManager
;
...
...
@@ -39,7 +42,9 @@ public class PluginBootstrap {
*
* @return plugin definition list.
*/
public
List
<
AbstractClassEnhancePluginDefine
>
loadPlugins
()
{
public
List
<
AbstractClassEnhancePluginDefine
>
loadPlugins
()
throws
AgentPackageNotFoundException
{
PluginClassLoader
.
initAndGet
(
AgentPackagePath
.
getPath
());
PluginResourcesResolver
resolver
=
new
PluginResourcesResolver
();
List
<
URL
>
resources
=
resolver
.
getResources
();
...
...
apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/plugin/loader/PluginClassLoader.java
0 → 100644
浏览文件 @
eb507496
/*
* Copyright 2017, OpenSkywalking Organization All rights reserved.
*
* 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.
*
* Project repository: https://github.com/OpenSkywalking/skywalking
*/
package
org.skywalking.apm.agent.core.plugin.loader
;
import
java.io.File
;
import
java.io.FilenameFilter
;
import
java.io.IOException
;
import
java.net.URL
;
import
java.util.LinkedList
;
import
java.util.List
;
import
java.util.concurrent.locks.ReentrantLock
;
import
java.util.jar.JarFile
;
import
org.skywalking.apm.logging.ILog
;
import
org.skywalking.apm.logging.LogManager
;
/**
* The <code>PluginClassLoader</code> represents a classloader,
* which is in charge of finding plugins and interceptors.
*
* @author wusheng
*/
public
class
PluginClassLoader
extends
ClassLoader
{
private
static
final
ILog
logger
=
LogManager
.
getLogger
(
PluginClassLoader
.
class
);
private
static
PluginClassLoader
LOADER
;
private
List
<
File
>
classpath
;
private
List
<
JarFile
>
allJars
;
private
ReentrantLock
jarScanLock
=
new
ReentrantLock
();
public
static
PluginClassLoader
get
()
{
return
LOADER
;
}
public
static
PluginClassLoader
initAndGet
(
File
agentDictionary
)
{
LOADER
=
new
PluginClassLoader
(
agentDictionary
);
return
get
();
}
private
PluginClassLoader
(
File
agentDictionary
)
{
super
(
PluginClassLoader
.
class
.
getClassLoader
());
classpath
=
new
LinkedList
<
File
>();
classpath
.
add
(
new
File
(
agentDictionary
,
"plugins"
));
classpath
.
add
(
new
File
(
agentDictionary
,
"activations"
));
}
@Override
protected
Class
<?>
findClass
(
String
name
)
throws
ClassNotFoundException
{
throw
new
ClassNotFoundException
(
name
);
}
@Override
protected
URL
findResource
(
String
name
)
{
getAllJars
();
throw
new
RuntimeException
(
""
);
}
private
List
<
JarFile
>
getAllJars
()
{
if
(
allJars
==
null
)
{
jarScanLock
.
lock
();
try
{
if
(
allJars
==
null
)
{
allJars
=
new
LinkedList
<
JarFile
>();
for
(
File
path
:
classpath
)
{
if
(
path
.
exists
()
&&
path
.
isDirectory
())
{
String
[]
jarFileNames
=
path
.
list
(
new
FilenameFilter
()
{
@Override
public
boolean
accept
(
File
dir
,
String
name
)
{
return
name
.
endsWith
(
".jar"
);
}
});
for
(
String
fileName
:
jarFileNames
)
{
try
{
JarFile
jar
=
new
JarFile
(
fileName
);
allJars
.
add
(
jar
);
}
catch
(
IOException
e
)
{
logger
.
error
(
e
,
"{} jar file can't be resolved"
,
fileName
);
}
}
}
}
}
}
finally
{
jarScanLock
.
unlock
();
}
}
return
allJars
;
}
}
apm-sniffer/apm-agent/src/main/java/org/skywalking/apm/agent/SkyWalkingAgent.java
浏览文件 @
eb507496
...
...
@@ -58,11 +58,17 @@ public class SkyWalkingAgent {
* @throws PluginException
*/
public
static
void
premain
(
String
agentArgs
,
Instrumentation
instrumentation
)
throws
PluginException
{
SnifferConfigInitializer
.
initialize
();
final
PluginFinder
pluginFinder
;
try
{
SnifferConfigInitializer
.
initialize
();
final
PluginFinder
pluginFinder
=
new
PluginFinder
(
new
PluginBootstrap
().
loadPlugins
());
pluginFinder
=
new
PluginFinder
(
new
PluginBootstrap
().
loadPlugins
());
ServiceManager
.
INSTANCE
.
boot
();
ServiceManager
.
INSTANCE
.
boot
();
}
catch
(
Exception
e
)
{
logger
.
error
(
e
,
"skywalking agent shutdown."
);
return
;
}
Runtime
.
getRuntime
().
addShutdownHook
(
new
Thread
(
new
Runnable
()
{
@Override
public
void
run
()
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录