-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
f0a4b3e
commit 4110e17
Showing
11 changed files
with
214 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
core/src/main/java/com/megaease/easeagent/core/info/AgentInfoFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* Copyright (c) 2021, MegaEase | ||
* 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. | ||
*/ | ||
|
||
package com.megaease.easeagent.core.info; | ||
|
||
import com.megaease.easeagent.log4j2.Logger; | ||
import com.megaease.easeagent.log4j2.LoggerFactory; | ||
import com.megaease.easeagent.plugin.bridge.AgentInfo; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.InputStreamReader; | ||
|
||
public class AgentInfoFactory { | ||
private static final Logger LOGGER = LoggerFactory.getLogger(AgentInfoFactory.class); | ||
public static final String AGENT_TYPE = "EaseAgent"; | ||
private static final String VERSION_FILE = "version.txt"; | ||
|
||
|
||
public static AgentInfo loadAgentInfo(ClassLoader classLoader) { | ||
return new AgentInfo(AGENT_TYPE, loadVersion(classLoader, VERSION_FILE)); | ||
} | ||
|
||
|
||
private static String loadVersion(ClassLoader classLoader, String file) { | ||
try (InputStream in = classLoader.getResourceAsStream(file)) { | ||
BufferedReader reader = new BufferedReader(new InputStreamReader(in)); | ||
String version = reader.readLine(); | ||
reader.close(); | ||
return version; | ||
} catch (IOException e) { | ||
LOGGER.warn("Load config file:{} by classloader:{} failure: {}", file, classLoader.toString(), e); | ||
} | ||
return ""; | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
core/src/main/java/com/megaease/easeagent/core/info/AgentInfoProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Copyright (c) 2021, MegaEase | ||
* 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. | ||
*/ | ||
|
||
package com.megaease.easeagent.core.info; | ||
|
||
import com.megaease.easeagent.core.utils.JsonUtil; | ||
import com.megaease.easeagent.httpserver.nano.AgentHttpHandler; | ||
import com.megaease.easeagent.httpserver.nano.AgentHttpHandlerProvider; | ||
import com.megaease.easeagent.httpserver.nano.AgentHttpServer; | ||
import com.megaease.easeagent.httpserver.nanohttpd.protocols.http.IHTTPSession; | ||
import com.megaease.easeagent.httpserver.nanohttpd.protocols.http.response.Response; | ||
import com.megaease.easeagent.httpserver.nanohttpd.protocols.http.response.Status; | ||
import com.megaease.easeagent.httpserver.nanohttpd.router.RouterNanoHTTPD; | ||
import com.megaease.easeagent.plugin.bean.BeanProvider; | ||
import com.megaease.easeagent.plugin.bridge.EaseAgent; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class AgentInfoProvider implements AgentHttpHandlerProvider, BeanProvider { | ||
|
||
@Override | ||
public List<AgentHttpHandler> getAgentHttpHandlers() { | ||
List<AgentHttpHandler> list = new ArrayList<>(); | ||
list.add(new AgentInfoHttpHandler()); | ||
return list; | ||
} | ||
|
||
public static class AgentInfoHttpHandler extends AgentHttpHandler { | ||
|
||
@Override | ||
public String getPath() { | ||
return "/agent-info"; | ||
} | ||
|
||
@Override | ||
public Response process(RouterNanoHTTPD.UriResource uriResource, Map<String, String> urlParams, IHTTPSession session) { | ||
return Response.newFixedLengthResponse(Status.OK, AgentHttpServer.JSON_TYPE, JsonUtil.toJson(EaseAgent.getAgentInfo())); | ||
} | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
core/src/main/resources/META-INF/services/com.megaease.easeagent.plugin.bean.BeanProvider
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
com.megaease.easeagent.core.health.HealthProvider | ||
com.megaease.easeagent.core.info.AgentInfoProvider |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
${project.version} |
35 changes: 35 additions & 0 deletions
35
core/src/test/java/com/megaease/easeagent/core/info/AgentInfoFactoryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Copyright (c) 2021, MegaEase | ||
* 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. | ||
*/ | ||
|
||
package com.megaease.easeagent.core.info; | ||
|
||
import com.megaease.easeagent.config.ConfigFactory; | ||
import com.megaease.easeagent.config.Configs; | ||
import com.megaease.easeagent.plugin.bridge.AgentInfo; | ||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
public class AgentInfoFactoryTest { | ||
|
||
@Test | ||
public void loadAgentInfo() { | ||
AgentInfo config = AgentInfoFactory.loadAgentInfo(this.getClass().getClassLoader()); | ||
assertEquals(AgentInfoFactory.AGENT_TYPE, config.getType()); | ||
assertTrue(config.getVersion().matches(".*\\d+\\.\\d+\\.\\d+.*")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
plugin-api/src/main/java/com/megaease/easeagent/plugin/bridge/AgentInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Copyright (c) 2021, MegaEase | ||
* 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. | ||
*/ | ||
|
||
package com.megaease.easeagent.plugin.bridge; | ||
|
||
public class AgentInfo { | ||
private final String type; | ||
private final String version; | ||
|
||
public AgentInfo(String type, String version) { | ||
this.type = type; | ||
this.version = version; | ||
} | ||
|
||
public String getType() { | ||
return type; | ||
} | ||
|
||
public String getVersion() { | ||
return version; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters