diff --git a/.github/actions/scenarios/agentcore/agentmain/action.yml b/.github/actions/scenarios/agentcore/agentmain/action.yml new file mode 100644 index 0000000000..d4ae261166 --- /dev/null +++ b/.github/actions/scenarios/agentcore/agentmain/action.yml @@ -0,0 +1,66 @@ +name: "Agent-core Agentmain Startup Test" +description: "Auto test for agent-core agentmain startup" +runs: + using: "composite" + steps: + - name: entry + uses: ./.github/actions/common/entry + with: + log-dir: ./logs/agentcore-test/agentmain + - name: compile AgentLoader + shell: bash + run: | + cp sermant-integration-tests/scripts/AgentLoader.java ./ + javac -classpath ./:${{ env.JAVA_HOME}}/lib/tools.jar AgentLoader.java + - name: (install agent) modify plugins file + shell: bash + run: | + sed -i '/dynamic-test-first-plugin/d' sermant-agent-${{ env.sermantVersion }}/agent/config/plugins.yaml + sed -i '/dynamic-test-second-plugin/d' sermant-agent-${{ env.sermantVersion }}/agent/config/plugins.yaml + sed -i '/dynamic-test-third-plugin/d' sermant-agent-${{ env.sermantVersion }}/agent/config/plugins.yaml + sed -i '/plugins:/a \ - dynamic-test-first-plugin' sermant-agent-${{ env.sermantVersion }}/agent/config/plugins.yaml + sed -i '/ active:/a \ - dynamic-test-second-plugin' sermant-agent-${{ env.sermantVersion }}/agent/config/plugins.yaml + sed -i '/ passive:/a \ - dynamic-test-third-plugin' sermant-agent-${{ env.sermantVersion }}/agent/config/plugins.yaml + - name: start backend with memory + shell: bash + run: | + nohup java -jar sermant-agent-${{ env.sermantVersion }}/server/sermant/sermant-backend-${{ env.sermantVersion }}.jar & + - name: start applications + shell: bash + env: + dynamic.config.serverAddress: 127.0.0.1:2181 + dynamic.config.dynamicConfigType: ZOOKEEPER + service.meta.project: TestAgentCore + run: | + nohup java -jar \ + sermant-agent-${{ env.sermantVersion }}/agent/agentcore-test-application-1.0.0-jar-with-dependencies.jar > ${{ env.logDir + }}/agentcore-test.log 2>&1 & + - name: waiting for agentcore services start + shell: bash + run: | + bash ./sermant-integration-tests/scripts/checkService.sh http://127.0.0.1:8915/ping 120 + bash ./sermant-integration-tests/scripts/checkService.sh http://127.0.0.1:8900/sermant/event/webhooks 120 + - name: (install agent) dynamic install agent + shell: bash + run: java -classpath ./:${{ env.JAVA_HOME}}/lib/tools.jar AgentLoader sermant-agent-${{ env.sermantVersion }}/agent/sermant-agent.jar + - name: Sleep for 5 Seconds + shell: bash + run: sleep 5 + - name: test agentmain startup + shell: bash + run: mvn test -Dagentcore.test.type=AGENTMAIN_STARTUP --file sermant-integration-tests/agentcore-test/agentcore-integration-test/pom.xml + - name: exit + if: always() + uses: ./.github/actions/common/exit + with: + processor-keyword: agentcore + - name: if failure then upload error log + uses: actions/upload-artifact@v3 + if: ${{ failure() || cancelled() }} + with: + name: agentcore-test-agentmain-logs + path: | + ./*.log + ./logs/** + if-no-files-found: warn + retention-days: 2 diff --git a/.github/actions/scenarios/agentcore/common/action.yml b/.github/actions/scenarios/agentcore/common/action.yml new file mode 100644 index 0000000000..6f7b47e4e7 --- /dev/null +++ b/.github/actions/scenarios/agentcore/common/action.yml @@ -0,0 +1,45 @@ +name: "Agent-core Common Test" +description: "Auto test for agent-core common" +runs: + using: "composite" + steps: + - name: entry + uses: ./.github/actions/common/entry + with: + log-dir: ./logs/agentcore-test/common + - name: modify config + shell: bash + run: | + sed -i 's/service\.meta\.application=default/service.meta.application=testApplication/' sermant-agent-${{ env.sermantVersion }}/agent/config/config.properties + - name: start applications + shell: bash + env: + dynamic.config.serverAddress: 127.0.0.1:2181 + dynamic.config.dynamicConfigType: ZOOKEEPER + service.meta.project: TestAgentCore + run: | + nohup java -javaagent:sermant-agent-${{ env.sermantVersion }}/agent/sermant-agent.jar -jar \ + sermant-agent-${{ env.sermantVersion }}/agent/agentcore-test-application-1.0.0-jar-with-dependencies.jar > ${{ env.logDir + }}/agentcore-test.log 2>&1 & + - name: waiting for agentcore services start + shell: bash + run: | + bash ./sermant-integration-tests/scripts/checkService.sh http://127.0.0.1:8915/ping 120 + - name: agentcore test config load start + shell: bash + run: mvn test -Dagentcore.test.type=CONFIG_LOAD --file sermant-integration-tests/agentcore-test/agentcore-integration-test/pom.xml + - name: exit + if: always() + uses: ./.github/actions/common/exit + with: + processor-keyword: agentcore + - name: if failure then upload error log + uses: actions/upload-artifact@v3 + if: ${{ failure() || cancelled() }} + with: + name: agentcore-test-common-logs + path: | + ./*.log + ./logs/** + if-no-files-found: warn + retention-days: 2 diff --git a/.github/actions/scenarios/agentcore/agentcore-common/action.yml b/.github/actions/scenarios/agentcore/dynamic-config/action.yml similarity index 83% rename from .github/actions/scenarios/agentcore/agentcore-common/action.yml rename to .github/actions/scenarios/agentcore/dynamic-config/action.yml index c2415fcb0e..ed7f005d58 100644 --- a/.github/actions/scenarios/agentcore/agentcore-common/action.yml +++ b/.github/actions/scenarios/agentcore/dynamic-config/action.yml @@ -1,5 +1,5 @@ -name: "Agent-core Common Test" -description: "Auto test for agent-core common, include nacos dynamic config" +name: "Dynamic Config Test" +description: "Auto test for dynamic config" runs: using: "composite" steps: @@ -10,8 +10,8 @@ runs: - name: start applications shell: bash env: - dynamic.config.serverAddress: 127.0.0.1:8848 - dynamic.config.dynamicConfigType: NACOS + dynamic.config.serverAddress: ${{ matrix.serviceAddress }} + dynamic.config.dynamicConfigType: ${{ matrix.dynamicConfigType }} service.meta.project: TestAgentCore run: | nohup java -javaagent:sermant-agent-${{ env.sermantVersion }}/agent/sermant-agent.jar -jar \ @@ -33,7 +33,7 @@ runs: uses: actions/upload-artifact@v3 if: ${{ failure() || cancelled() }} with: - name: agentcore-test-logs + name: agentcore-test-dynamic-config-logs path: | ./*.log ./logs/** diff --git a/.github/actions/scenarios/agentcore/dynamic/action.yml b/.github/actions/scenarios/agentcore/dynamic/action.yml index e63c39ca96..db009ef43e 100644 --- a/.github/actions/scenarios/agentcore/dynamic/action.yml +++ b/.github/actions/scenarios/agentcore/dynamic/action.yml @@ -84,7 +84,7 @@ runs: uses: actions/upload-artifact@v3 if: ${{ failure() || cancelled() }} with: - name: agentcore-test-logs + name: agentcore-test-dynamic-logs path: | ./*.log ./logs/** diff --git a/.github/actions/scenarios/agentcore/premain/action.yml b/.github/actions/scenarios/agentcore/premain/action.yml new file mode 100644 index 0000000000..927aeb013d --- /dev/null +++ b/.github/actions/scenarios/agentcore/premain/action.yml @@ -0,0 +1,53 @@ +name: "Agent-core Premain Startup Test" +description: "Auto test for agent-core premain startup" +runs: + using: "composite" + steps: + - name: entry + uses: ./.github/actions/common/entry + with: + log-dir: ./logs/agentcore-test/premain + - name: (install agent) modify plugins file + shell: bash + run: | + sed -i '/dynamic-test-first-plugin/d' sermant-agent-${{ env.sermantVersion }}/agent/config/plugins.yaml + sed -i '/dynamic-test-second-plugin/d' sermant-agent-${{ env.sermantVersion }}/agent/config/plugins.yaml + sed -i '/plugins:/a \ - dynamic-test-first-plugin' sermant-agent-${{ env.sermantVersion }}/agent/config/plugins.yaml + sed -i '/ active:/a \ - dynamic-test-second-plugin' sermant-agent-${{ env.sermantVersion }}/agent/config/plugins.yaml + - name: start backend with memory + shell: bash + run: | + nohup java -jar sermant-agent-${{ env.sermantVersion }}/server/sermant/sermant-backend-${{ env.sermantVersion }}.jar & + - name: start applications + shell: bash + env: + dynamic.config.serverAddress: 127.0.0.1:2181 + dynamic.config.dynamicConfigType: ZOOKEEPER + service.meta.project: TestAgentCore + run: | + nohup java -javaagent:sermant-agent-${{ env.sermantVersion }}/agent/sermant-agent.jar -jar \ + sermant-agent-${{ env.sermantVersion }}/agent/agentcore-test-application-1.0.0-jar-with-dependencies.jar > ${{ env.logDir + }}/agentcore-test.log 2>&1 & + - name: waiting for agentcore services start + shell: bash + run: | + bash ./sermant-integration-tests/scripts/checkService.sh http://127.0.0.1:8915/ping 120 + bash ./sermant-integration-tests/scripts/checkService.sh http://127.0.0.1:8900/sermant/event/webhooks 120 + - name: test premain startup + shell: bash + run: mvn test -Dagentcore.test.type=PREMAIN_STARTUP --file sermant-integration-tests/agentcore-test/agentcore-integration-test/pom.xml + - name: exit + if: always() + uses: ./.github/actions/common/exit + with: + processor-keyword: agentcore + - name: if failure then upload error log + uses: actions/upload-artifact@v3 + if: ${{ failure() || cancelled() }} + with: + name: agentcore-test-premain-logs + path: | + ./*.log + ./logs/** + if-no-files-found: warn + retention-days: 2 diff --git a/.github/workflows/agentcore_integration_test.yml b/.github/workflows/agentcore_integration_test.yml index d391540ef2..bcd09d0824 100644 --- a/.github/workflows/agentcore_integration_test.yml +++ b/.github/workflows/agentcore_integration_test.yml @@ -79,15 +79,18 @@ jobs: mkdir -p sermant-agent-${{ env.sermantVersion }}/agent/pluginPackage/agentcore-test-plugin/plugin mkdir -p sermant-agent-${{ env.sermantVersion }}/agent/pluginPackage/dynamic-test-first-plugin/plugin mkdir -p sermant-agent-${{ env.sermantVersion }}/agent/pluginPackage/dynamic-test-second-plugin/plugin + mkdir -p sermant-agent-${{ env.sermantVersion }}/agent/pluginPackage/dynamic-test-third-plugin/plugin cp ./sermant-integration-tests/agentcore-test/agentcore-test-plugin/target/agentcore-test-plugin-1.0.0.jar sermant-agent-${{ env.sermantVersion }}/agent/pluginPackage/agentcore-test-plugin/plugin/ + cp -r ./sermant-integration-tests/agentcore-test/config sermant-agent-${{ env.sermantVersion }}/agent/pluginPackage/agentcore-test-plugin/ cp ./sermant-integration-tests/agentcore-test/dynamic-test-first-plugin/target/dynamic-test-first-plugin-1.0.0.jar sermant-agent-${{ env.sermantVersion }}/agent/pluginPackage/dynamic-test-first-plugin/plugin/ cp ./sermant-integration-tests/agentcore-test/dynamic-test-second-plugin/target/dynamic-test-second-plugin-1.0.0.jar sermant-agent-${{ env.sermantVersion }}/agent/pluginPackage/dynamic-test-second-plugin/plugin/ + cp ./sermant-integration-tests/agentcore-test/dynamic-test-third-plugin/target/dynamic-test-third-plugin-1.0.0.jar sermant-agent-${{ env.sermantVersion }}/agent/pluginPackage/dynamic-test-third-plugin/plugin/ cp ./sermant-integration-tests/agentcore-test/agentcore-test-application/target/agentcore-test-application-1.0.0-jar-with-dependencies.jar sermant-agent-${{ env.sermantVersion }}/agent/ sed -i '/plugins:/a \ - agentcore-test-plugin' sermant-agent-${{ env.sermantVersion }}/agent/config/plugins.yaml test-for-agentcore-common: name: Test for agentcore common runs-on: ubuntu-latest - needs: [ build-agent-and-cache, download-midwares-and-cache ] + needs: [build-agent-and-cache, download-midwares-and-cache] steps: - uses: actions/checkout@v3 with: @@ -98,7 +101,30 @@ jobs: - name: common operations uses: ./.github/actions/common/agentcore - name: start agentcore common test - uses: ./.github/actions/scenarios/agentcore/agentcore-common + uses: ./.github/actions/scenarios/agentcore/common + test-for-agentcore-dynamic-config: + name: Test for agentcore dynamic config + runs-on: ubuntu-latest + needs: [build-agent-and-cache, download-midwares-and-cache] + strategy: + matrix: + include: + - serviceAddress: "127.0.0.1:8848" + dynamicConfigType: "NACOS" + - serviceAddress: "127.0.0.1:2181" + dynamicConfigType: "ZOOKEEPER" + fail-fast: false + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 100 + - name: set java version to environment + run: | + echo "javaVersion=8" >> $GITHUB_ENV + - name: common operations + uses: ./.github/actions/common/agentcore + - name: test dynamic config for ${{ matrix.dynamicConfigType }} + uses: ./.github/actions/scenarios/agentcore/dynamic-config test-for-agentcore-dynamic: name: Test for agentcore dynamic runs-on: ubuntu-latest @@ -114,5 +140,36 @@ jobs: uses: ./.github/actions/common/agentcore - name: start dynamic test uses: ./.github/actions/scenarios/agentcore/dynamic + test-for-agentcore-premain-startup: + name: Test for agentcore premain startup + runs-on: ubuntu-latest + needs: [build-agent-and-cache, download-midwares-and-cache] + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 100 + - name: set java version to environment + run: | + echo "javaVersion=8" >> $GITHUB_ENV + - name: common operations + uses: ./.github/actions/common/agentcore + - name: start dynamic test + uses: ./.github/actions/scenarios/agentcore/premain + test-for-agentcore-agentmain-startup: + name: Test for agentcore agentmain startup + runs-on: ubuntu-latest + needs: [build-agent-and-cache, download-midwares-and-cache] + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 100 + - name: set java version to environment + run: | + echo "javaVersion=8" >> $GITHUB_ENV + - name: common operations + uses: ./.github/actions/common/agentcore + - name: start dynamic test + uses: ./.github/actions/scenarios/agentcore/agentmain + diff --git a/sermant-integration-tests/agentcore-test/agentcore-integration-test/src/test/java/com/huaweicloud/agentcore/test/request/RequestTest.java b/sermant-integration-tests/agentcore-test/agentcore-integration-test/src/test/java/com/huaweicloud/agentcore/test/request/RequestTest.java index 5dd1e6b33e..7be01ea3e0 100644 --- a/sermant-integration-tests/agentcore-test/agentcore-integration-test/src/test/java/com/huaweicloud/agentcore/test/request/RequestTest.java +++ b/sermant-integration-tests/agentcore-test/agentcore-integration-test/src/test/java/com/huaweicloud/agentcore/test/request/RequestTest.java @@ -16,10 +16,12 @@ package com.huaweicloud.agentcore.test.request; +import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.condition.EnabledIfSystemProperty; import org.junit.jupiter.api.Test; import java.io.IOException; +import java.util.Map; /** * 请求测试类,采用http请求调用方式测试 @@ -72,4 +74,46 @@ public void testReInstallPlugin() throws IOException { public void testInstallPlugin() throws IOException { RequestUtils.testRequest("http://127.0.0.1:8915/testInstallPlugin"); } + + /** + * agentmain启动测试方法 + */ + @Test + @EnabledIfSystemProperty(named = "agentcore.test.type", matches = "AGENTMAIN_STARTUP") + public void testAgentmainStartup() throws IOException { + RequestUtils.testRequest("http://127.0.0.1:8915/testAgentmainStartup"); + } + + /** + * premain启动测试方法 + */ + @Test + @EnabledIfSystemProperty(named = "agentcore.test.type", matches = "PREMAIN_STARTUP") + public void testPremainStartup() throws IOException { + RequestUtils.testRequest("http://127.0.0.1:8915/testPremainStartup"); + } + + /** + * 启动后backend的appType和service字段设置测试方法 + */ + @Test + @EnabledIfSystemProperty(named = "agentcore.test.type", matches = "PREMAIN_STARTUP|AGENTMAIN_STARTUP") + public void testBackend() throws IOException { + Map resultMap = RequestUtils.analyzingRequestBackend( + "http://127.0.0.1:8900/sermant/getPluginsInfo"); + Assertions.assertNotNull(resultMap, "getPluginsInfo result is null"); + Assertions.assertTrue(resultMap.containsKey("appType"), "the result does not contain appType"); + Assertions.assertTrue(resultMap.containsKey("service"), "the result does not contain service"); + Assertions.assertEquals("default", resultMap.getOrDefault("appType", ""), "the value of appType is wrong"); + Assertions.assertEquals("default", resultMap.getOrDefault("service", ""), "the value of service is wrong"); + } + + /** + * 配置加载测试方法 + */ + @Test + @EnabledIfSystemProperty(named = "agentcore.test.type", matches = "CONFIG_LOAD") + public void testCoreAndPluginConfigLoad() throws IOException { + RequestUtils.testRequest("http://127.0.0.1:8915/testCoreAndPluginConfigLoad"); + } } diff --git a/sermant-integration-tests/agentcore-test/agentcore-integration-test/src/test/java/com/huaweicloud/agentcore/test/request/RequestUtils.java b/sermant-integration-tests/agentcore-test/agentcore-integration-test/src/test/java/com/huaweicloud/agentcore/test/request/RequestUtils.java index 4cf8b8e572..0cedf54967 100644 --- a/sermant-integration-tests/agentcore-test/agentcore-integration-test/src/test/java/com/huaweicloud/agentcore/test/request/RequestUtils.java +++ b/sermant-integration-tests/agentcore-test/agentcore-integration-test/src/test/java/com/huaweicloud/agentcore/test/request/RequestUtils.java @@ -50,12 +50,33 @@ private RequestUtils() { * @param url 测试请求接口的url */ public static void testRequest(String url) throws IOException { + Map resultMap = convertHttpEntityToMap(getResponse(url)); + for (Map.Entry entry : resultMap.entrySet()) { + Assertions.assertTrue((boolean) entry.getValue(), entry.getKey()); + } + } + + /** + * 对于backend的reponse解析 + * + * @param url 测试请求接口的url + */ + public static Map analyzingRequestBackend(String url) throws IOException { + String resultStr = getResponse(url); + resultStr = resultStr.substring(1, resultStr.length() - 1); + return convertHttpEntityToMap(resultStr); + } + + /** + * 获取请求结果 + * + * @param url 测试请求接口的url + * @return 请求结果Map + */ + public static String getResponse(String url) throws IOException { String response = doGet(url); Assertions.assertNotEquals("", response, url + " Request Error. "); - Map resultMap = convertHttpEntityToMap(response); - for (Map.Entry entry : resultMap.entrySet()) { - Assertions.assertTrue(entry.getValue(), entry.getKey()); - } + return response; } /** @@ -90,11 +111,11 @@ private static String doGet(String url) { * @param response JSON数据 * @return map数据 */ - private static Map convertHttpEntityToMap(String response) throws IOException { - Map result = new HashMap<>(); + private static Map convertHttpEntityToMap(String response) throws IOException { + Map result = new HashMap<>(); JSONObject jsonObject = JSONObject.parseObject(response); for (String key : jsonObject.keySet()) { - result.put(key, jsonObject.getBooleanValue(key)); + result.put(key, jsonObject.get(key)); } return result; } diff --git a/sermant-integration-tests/agentcore-test/agentcore-test-application/src/main/java/com/huaweicloud/agentcore/test/application/controller/TestController.java b/sermant-integration-tests/agentcore-test/agentcore-test-application/src/main/java/com/huaweicloud/agentcore/test/application/controller/TestController.java index bdee14a0da..d258241131 100644 --- a/sermant-integration-tests/agentcore-test/agentcore-test-application/src/main/java/com/huaweicloud/agentcore/test/application/controller/TestController.java +++ b/sermant-integration-tests/agentcore-test/agentcore-test-application/src/main/java/com/huaweicloud/agentcore/test/application/controller/TestController.java @@ -16,8 +16,10 @@ package com.huaweicloud.agentcore.test.application.controller; +import com.huaweicloud.agentcore.test.application.results.ConfigResults; import com.huaweicloud.agentcore.test.application.results.DynamicConfigResults; import com.huaweicloud.agentcore.test.application.results.DynamicResults; +import com.huaweicloud.agentcore.test.application.tests.configload.CoreAndPluginConfigLoadTest; import com.huaweicloud.agentcore.test.application.tests.dynamic.DynamicTest; import com.huaweicloud.agentcore.test.application.tests.dynamicconfig.DynamicConfigTest; @@ -124,6 +126,59 @@ public String testReInstallAgent() { return jsonObject.toJSONString(); } + /** + * 测试premain启动 + * + * @return 测试结果 + */ + public String testPremainStartup() { + Map resultMap = new HashMap<>(); + DynamicTest dynamicTest = new DynamicTest(); + dynamicTest.testPremainStartup(); + resultMap.put(DynamicResults.PREMAIN_STATIC_PLUGIN_INTERCEPTOR_SUCCESS.name(), + DynamicResults.PREMAIN_STATIC_PLUGIN_INTERCEPTOR_SUCCESS.getResult()); + resultMap.put(DynamicResults.PREMAIN_DYNAMIC_PLUGIN_INTERCEPTOR_FAILURE.name(), + DynamicResults.PREMAIN_DYNAMIC_PLUGIN_INTERCEPTOR_FAILURE.getResult()); + JSONObject jsonObject = new JSONObject(resultMap); + return jsonObject.toJSONString(); + } + + /** + * 测试agentmain启动 + * + * @return 测试结果 + */ + public String testAgentmainStartup() { + Map resultMap = new HashMap<>(); + DynamicTest dynamicTest = new DynamicTest(); + dynamicTest.testAgentmainStartup(); + resultMap.put(DynamicResults.AGENTMAIN_STATIC_PLUGIN_INTERCEPTOR_FAILURE.name(), + DynamicResults.AGENTMAIN_STATIC_PLUGIN_INTERCEPTOR_FAILURE.getResult()); + resultMap.put(DynamicResults.AGENTMAIN_ACTIVE_PLUGIN_INTERCEPTOR_SUCCESS.name(), + DynamicResults.AGENTMAIN_ACTIVE_PLUGIN_INTERCEPTOR_SUCCESS.getResult()); + resultMap.put(DynamicResults.AGENTMAIN_PASSIVE_PLUGIN_INTERCEPTOR_FAILURE.name(), + DynamicResults.AGENTMAIN_PASSIVE_PLUGIN_INTERCEPTOR_FAILURE.getResult()); + JSONObject jsonObject = new JSONObject(resultMap); + return jsonObject.toJSONString(); + } + + /** + * 测试配置加载功能 + * + * @return 测试结果 + */ + public String testCoreAndPluginConfigLoad() { + Map resultMap = new HashMap<>(); + CoreAndPluginConfigLoadTest configTest = new CoreAndPluginConfigLoadTest(); + configTest.testCoreAndPluginConfigLoad(); + resultMap.put(ConfigResults.PLUGIN_CONFIG_LOADED_SUCCESS.name(), + ConfigResults.PLUGIN_CONFIG_LOADED_SUCCESS.getResult()); + resultMap.put(ConfigResults.CORE_CONFIG_LOADED_SUCCESS.name(), + ConfigResults.CORE_CONFIG_LOADED_SUCCESS.getResult()); + JSONObject jsonObject = new JSONObject(resultMap); + return jsonObject.toJSONString(); + } + private String buildExceptionKey(Exception e) { return "Unexpected exception occurs: " + e.getMessage(); } diff --git a/sermant-integration-tests/agentcore-test/agentcore-test-application/src/main/java/com/huaweicloud/agentcore/test/application/results/ConfigResults.java b/sermant-integration-tests/agentcore-test/agentcore-test-application/src/main/java/com/huaweicloud/agentcore/test/application/results/ConfigResults.java new file mode 100644 index 0000000000..1692ccdf9b --- /dev/null +++ b/sermant-integration-tests/agentcore-test/agentcore-test-application/src/main/java/com/huaweicloud/agentcore/test/application/results/ConfigResults.java @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2023-2023 Huawei Technologies Co., Ltd. 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.huaweicloud.agentcore.test.application.results; + +/** + * 核心配置和插件配置加载测试用例结果 + * + * @author tangle + * @since 2023-10-09 + */ +public enum ConfigResults { + /** + * 插件配置加载 + */ + PLUGIN_CONFIG_LOADED_SUCCESS("Test load plugin config."), + + /** + * 核心配置加载 + */ + CORE_CONFIG_LOADED_SUCCESS("Test load core config."); + + /** + * 用例描述 + */ + private String description; + + /** + * 测试结果标识 + */ + private boolean result; + + /** + * 构造函数 + * + * @param description 用例描述 + */ + ConfigResults(String description) { + this.description = description; + this.result = false; + } + + public boolean getResult() { + return result; + } + + public void setResult(boolean result) { + this.result = result; + } + + public String getDescription() { + return description; + } +} diff --git a/sermant-integration-tests/agentcore-test/agentcore-test-application/src/main/java/com/huaweicloud/agentcore/test/application/results/DynamicResults.java b/sermant-integration-tests/agentcore-test/agentcore-test-application/src/main/java/com/huaweicloud/agentcore/test/application/results/DynamicResults.java index 819fd9bd39..f9f03429b5 100644 --- a/sermant-integration-tests/agentcore-test/agentcore-test-application/src/main/java/com/huaweicloud/agentcore/test/application/results/DynamicResults.java +++ b/sermant-integration-tests/agentcore-test/agentcore-test-application/src/main/java/com/huaweicloud/agentcore/test/application/results/DynamicResults.java @@ -51,7 +51,32 @@ public enum DynamicResults { /** * 再次安装AGENT,插件生效 */ - DYNAMIC_REINSTALL_AGENT_PLUGIN_SUCCESS("Test dynamic reinstall agent, plugin success."); + DYNAMIC_REINSTALL_AGENT_PLUGIN_SUCCESS("Test dynamic reinstall agent, plugin success."), + + /** + * premain启动,静态插件生效 + */ + PREMAIN_STATIC_PLUGIN_INTERCEPTOR_SUCCESS("Test premain startup, static plugin success."), + + /** + * premain启动,动态插件失效 + */ + PREMAIN_DYNAMIC_PLUGIN_INTERCEPTOR_FAILURE("Test premain startup, dynamic plugin failure."), + + /** + * agentmain启动,静态插件失效 + */ + AGENTMAIN_STATIC_PLUGIN_INTERCEPTOR_FAILURE("Test agentmain startup, static plugin failure."), + + /** + * agentmain启动,active插件生效 + */ + AGENTMAIN_ACTIVE_PLUGIN_INTERCEPTOR_SUCCESS("Test agentmain startup, active plugin success."), + + /** + * agentmain启动,passive插件失效 + */ + AGENTMAIN_PASSIVE_PLUGIN_INTERCEPTOR_FAILURE("Test agentmain startup, passive plugin failure."); /** * 用例描述 diff --git a/sermant-integration-tests/agentcore-test/agentcore-test-application/src/main/java/com/huaweicloud/agentcore/test/application/router/ControllerHandler.java b/sermant-integration-tests/agentcore-test/agentcore-test-application/src/main/java/com/huaweicloud/agentcore/test/application/router/ControllerHandler.java index 8374d2c3b8..e06207a838 100644 --- a/sermant-integration-tests/agentcore-test/agentcore-test-application/src/main/java/com/huaweicloud/agentcore/test/application/router/ControllerHandler.java +++ b/sermant-integration-tests/agentcore-test/agentcore-test-application/src/main/java/com/huaweicloud/agentcore/test/application/router/ControllerHandler.java @@ -91,6 +91,12 @@ private String setResponse(HttpExchange exchange) { return testController.testUninstallAgent(); case RouterPath.REQUEST_PATH_REINSTALL_AGENT: return testController.testReInstallAgent(); + case RouterPath.REQUEST_PATH_PREMAIN_STARTUP: + return testController.testPremainStartup(); + case RouterPath.REQUEST_PATH_AGENTMAIN_STARTUP: + return testController.testAgentmainStartup(); + case RouterPath.REQUEST_PATH_CORE_AND_PLUGIN_CONFIG_LOAD: + return testController.testCoreAndPluginConfigLoad(); default: return REQUEST_URL_NOT_FOUND; } diff --git a/sermant-integration-tests/agentcore-test/agentcore-test-application/src/main/java/com/huaweicloud/agentcore/test/application/router/RouterPath.java b/sermant-integration-tests/agentcore-test/agentcore-test-application/src/main/java/com/huaweicloud/agentcore/test/application/router/RouterPath.java index cbf7c109b5..673b2bde98 100644 --- a/sermant-integration-tests/agentcore-test/agentcore-test-application/src/main/java/com/huaweicloud/agentcore/test/application/router/RouterPath.java +++ b/sermant-integration-tests/agentcore-test/agentcore-test-application/src/main/java/com/huaweicloud/agentcore/test/application/router/RouterPath.java @@ -53,6 +53,21 @@ public class RouterPath { */ public static final String REQUEST_PATH_REINSTALL_AGENT = "/testReInstallAgent"; + /** + * 测试premain启动请求地址 + */ + public static final String REQUEST_PATH_PREMAIN_STARTUP = "/testPremainStartup"; + + /** + * 测试agentmain启动请求地址 + */ + public static final String REQUEST_PATH_AGENTMAIN_STARTUP = "/testAgentmainStartup"; + + /** + * 测试配置加载功能 + */ + public static final String REQUEST_PATH_CORE_AND_PLUGIN_CONFIG_LOAD = "/testCoreAndPluginConfigLoad"; + private RouterPath() { } } diff --git a/sermant-integration-tests/agentcore-test/agentcore-test-application/src/main/java/com/huaweicloud/agentcore/test/application/tests/configload/CoreAndPluginConfigLoadTest.java b/sermant-integration-tests/agentcore-test/agentcore-test-application/src/main/java/com/huaweicloud/agentcore/test/application/tests/configload/CoreAndPluginConfigLoadTest.java new file mode 100644 index 0000000000..d04635f690 --- /dev/null +++ b/sermant-integration-tests/agentcore-test/agentcore-test-application/src/main/java/com/huaweicloud/agentcore/test/application/tests/configload/CoreAndPluginConfigLoadTest.java @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2023-2023 Huawei Technologies Co., Ltd. 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.huaweicloud.agentcore.test.application.tests.configload; + +import com.huaweicloud.agentcore.test.application.results.ConfigResults; + +/** + * 核心配置和插件配置加载测试类 + * + * @author tangle + * @since 2023-10-09 + */ +public class CoreAndPluginConfigLoadTest { + /** + * 测试配置加载功能 + */ + public void testCoreAndPluginConfigLoad() { + boolean[] result = checkConfig(false, false); + ConfigResults.PLUGIN_CONFIG_LOADED_SUCCESS.setResult(result[0]); + ConfigResults.CORE_CONFIG_LOADED_SUCCESS.setResult(result[1]); + } + + /** + * 测试插件的增强拦截方法 + * + * @param pluginConfigFlag 插件配置增强flag + * @param coreConfigFlag 核心配置增强flag + * @return 增强结果数组 + */ + private boolean[] checkConfig(boolean pluginConfigFlag, boolean coreConfigFlag) { + return new boolean[]{pluginConfigFlag, coreConfigFlag}; + } +} diff --git a/sermant-integration-tests/agentcore-test/agentcore-test-application/src/main/java/com/huaweicloud/agentcore/test/application/tests/dynamic/DynamicTest.java b/sermant-integration-tests/agentcore-test/agentcore-test-application/src/main/java/com/huaweicloud/agentcore/test/application/tests/dynamic/DynamicTest.java index a599cc0a2b..80181be080 100644 --- a/sermant-integration-tests/agentcore-test/agentcore-test-application/src/main/java/com/huaweicloud/agentcore/test/application/tests/dynamic/DynamicTest.java +++ b/sermant-integration-tests/agentcore-test/agentcore-test-application/src/main/java/com/huaweicloud/agentcore/test/application/tests/dynamic/DynamicTest.java @@ -25,6 +25,12 @@ * @since 2023-09-08 */ public class DynamicTest { + /** + * 测试的boolean数组下标,对应着三个插件的拦截修改变量 + */ + private static final int FIRST_PLUGIN_ENHANCE_INDEX = 0; + private static final int SECOND_PLUGIN_ENHANCE_INDEX = 1; + private static final int THIRD_PLUGIN_ENHANCE_INDEX = 2; /** * 用于测试插件反射修改的回执结果:监听成功 */ @@ -38,8 +44,8 @@ public static void setServiceCloseSuccess(boolean flag) { * 测试动态安装插件 */ public void testInstallPlugin() { - boolean[] result = repeatEnhance(false, false); - if (result[0] && result[1]) { + boolean[] result = repeatEnhance(false, false, false); + if (result[FIRST_PLUGIN_ENHANCE_INDEX] && result[SECOND_PLUGIN_ENHANCE_INDEX]) { DynamicResults.DYNAMIC_INSTALL_PLUGIN_REPEAT_ENHANCE.setResult(true); } } @@ -48,11 +54,11 @@ public void testInstallPlugin() { * 测试动态卸载插件 */ public void testUninstallPlugin() { - boolean[] result = repeatEnhance(false, false); - if (!result[0]) { + boolean[] result = repeatEnhance(false, false, false); + if (!result[FIRST_PLUGIN_ENHANCE_INDEX]) { DynamicResults.DYNAMIC_UNINSTALL_PLUGIN_INTERCEPTOR_FAILURE.setResult(true); } - if (result[1]) { + if (result[SECOND_PLUGIN_ENHANCE_INDEX]) { DynamicResults.DYNAMIC_UNINSTALL_REPEAT_ENHANCE.setResult(true); } } @@ -61,8 +67,8 @@ public void testUninstallPlugin() { * 测试动态卸载Agent */ public void testUninstallAgent() { - boolean[] result = repeatEnhance(false, false); - if (!result[0] && !result[1]) { + boolean[] result = repeatEnhance(false, false, false); + if (!result[FIRST_PLUGIN_ENHANCE_INDEX] && !result[SECOND_PLUGIN_ENHANCE_INDEX]) { DynamicResults.DYNAMIC_UNINSTALL_AGENT_PLUGIN_FAILURE.setResult(true); } } @@ -71,20 +77,50 @@ public void testUninstallAgent() { * 测试动态重装Agent */ public void testReInstallAgent() { - boolean[] result = repeatEnhance(false, false); - if (result[0] && result[1]) { + boolean[] result = repeatEnhance(false, false, false); + if (result[FIRST_PLUGIN_ENHANCE_INDEX] && result[SECOND_PLUGIN_ENHANCE_INDEX]) { DynamicResults.DYNAMIC_REINSTALL_AGENT_PLUGIN_SUCCESS.setResult(true); } } + /** + * 测试premain启动 + */ + public void testPremainStartup() { + boolean[] result = repeatEnhance(false, false, false); + if (result[FIRST_PLUGIN_ENHANCE_INDEX]) { + DynamicResults.PREMAIN_STATIC_PLUGIN_INTERCEPTOR_SUCCESS.setResult(true); + } + if (!result[SECOND_PLUGIN_ENHANCE_INDEX]) { + DynamicResults.PREMAIN_DYNAMIC_PLUGIN_INTERCEPTOR_FAILURE.setResult(true); + } + } + + /** + * 测试agentmain启动 + */ + public void testAgentmainStartup() { + boolean[] result = repeatEnhance(false, false, false); + if (!result[FIRST_PLUGIN_ENHANCE_INDEX]) { + DynamicResults.AGENTMAIN_STATIC_PLUGIN_INTERCEPTOR_FAILURE.setResult(true); + } + if (result[SECOND_PLUGIN_ENHANCE_INDEX]) { + DynamicResults.AGENTMAIN_ACTIVE_PLUGIN_INTERCEPTOR_SUCCESS.setResult(true); + } + if (!result[THIRD_PLUGIN_ENHANCE_INDEX]) { + DynamicResults.AGENTMAIN_PASSIVE_PLUGIN_INTERCEPTOR_FAILURE.setResult(true); + } + } + /** * 测试插件的增强拦截方法 * * @param firstEnhanceFlag first-plugin的增强flag * @param secondEnhanceFlag second-plugin的增强flag + * @param thirdEnhanceFlag second-plugin的增强flag * @return 增强结果数组 */ - private boolean[] repeatEnhance(boolean firstEnhanceFlag, boolean secondEnhanceFlag) { - return new boolean[]{firstEnhanceFlag, secondEnhanceFlag}; + private boolean[] repeatEnhance(boolean firstEnhanceFlag, boolean secondEnhanceFlag, boolean thirdEnhanceFlag) { + return new boolean[]{firstEnhanceFlag, secondEnhanceFlag, thirdEnhanceFlag}; } } diff --git a/sermant-integration-tests/agentcore-test/agentcore-test-plugin/src/main/java/com/huaweicloud/agentcore/tests/plugin/config/TestConfig.java b/sermant-integration-tests/agentcore-test/agentcore-test-plugin/src/main/java/com/huaweicloud/agentcore/tests/plugin/config/TestConfig.java new file mode 100644 index 0000000000..5615031321 --- /dev/null +++ b/sermant-integration-tests/agentcore-test/agentcore-test-plugin/src/main/java/com/huaweicloud/agentcore/tests/plugin/config/TestConfig.java @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2023-2023 Huawei Technologies Co., Ltd. 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.huaweicloud.agentcore.tests.plugin.config; + +import com.huaweicloud.sermant.core.config.common.ConfigFieldKey; +import com.huaweicloud.sermant.core.config.common.ConfigTypeKey; +import com.huaweicloud.sermant.core.plugin.config.PluginConfig; + +/** + * 测试配置 + * + * @author tangle + * @since 2023-10-09 + */ +@ConfigTypeKey("configload.config") +public class TestConfig implements PluginConfig { + @ConfigFieldKey("test-config-value") + private String testConfigValue; + + public String getTestConfigValue() { + return testConfigValue; + } + + public void setTestConfigValue(String testConfigValue) { + this.testConfigValue = testConfigValue; + } +} + diff --git a/sermant-integration-tests/agentcore-test/agentcore-test-plugin/src/main/java/com/huaweicloud/agentcore/tests/plugin/declarer/configload/TestConfigLoadDeclarer.java b/sermant-integration-tests/agentcore-test/agentcore-test-plugin/src/main/java/com/huaweicloud/agentcore/tests/plugin/declarer/configload/TestConfigLoadDeclarer.java new file mode 100644 index 0000000000..3e917d1397 --- /dev/null +++ b/sermant-integration-tests/agentcore-test/agentcore-test-plugin/src/main/java/com/huaweicloud/agentcore/tests/plugin/declarer/configload/TestConfigLoadDeclarer.java @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2023-2023 Huawei Technologies Co., Ltd. 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.huaweicloud.agentcore.tests.plugin.declarer.configload; + +import com.huaweicloud.agentcore.tests.plugin.interceptor.configload.ConfigLoadInterceptor; +import com.huaweicloud.sermant.core.plugin.agent.declarer.AbstractPluginDeclarer; +import com.huaweicloud.sermant.core.plugin.agent.declarer.InterceptDeclarer; +import com.huaweicloud.sermant.core.plugin.agent.matcher.ClassMatcher; +import com.huaweicloud.sermant.core.plugin.agent.matcher.MethodMatcher; + +/** + * 测试核心配置和插件配置加载 + * + * @author tangle + * @since 2023-10-09 + */ +public class TestConfigLoadDeclarer extends AbstractPluginDeclarer { + @Override + public ClassMatcher getClassMatcher() { + return ClassMatcher.nameEquals( + "com.huaweicloud.agentcore.test.application.tests.configload.CoreAndPluginConfigLoadTest"); + } + + @Override + public InterceptDeclarer[] getInterceptDeclarers(ClassLoader classLoader) { + return new InterceptDeclarer[]{ + InterceptDeclarer.build(MethodMatcher.nameEquals("checkConfig"), new ConfigLoadInterceptor())}; + } +} diff --git a/sermant-integration-tests/agentcore-test/agentcore-test-plugin/src/main/java/com/huaweicloud/agentcore/tests/plugin/interceptor/configload/ConfigLoadInterceptor.java b/sermant-integration-tests/agentcore-test/agentcore-test-plugin/src/main/java/com/huaweicloud/agentcore/tests/plugin/interceptor/configload/ConfigLoadInterceptor.java new file mode 100644 index 0000000000..2f8ff8e9db --- /dev/null +++ b/sermant-integration-tests/agentcore-test/agentcore-test-plugin/src/main/java/com/huaweicloud/agentcore/tests/plugin/interceptor/configload/ConfigLoadInterceptor.java @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2023-2023 Huawei Technologies Co., Ltd. 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.huaweicloud.agentcore.tests.plugin.interceptor.configload; + +import com.huaweicloud.agentcore.tests.plugin.config.TestConfig; +import com.huaweicloud.agentcore.tests.plugin.constants.TestConstants; +import com.huaweicloud.sermant.core.common.LoggerFactory; +import com.huaweicloud.sermant.core.config.ConfigManager; +import com.huaweicloud.sermant.core.plugin.agent.entity.ExecuteContext; +import com.huaweicloud.sermant.core.plugin.agent.interceptor.AbstractInterceptor; +import com.huaweicloud.sermant.core.plugin.config.PluginConfigManager; +import com.huaweicloud.sermant.core.plugin.config.ServiceMeta; +import com.huaweicloud.sermant.core.utils.StringUtils; + +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * 配置获取拦截器 + * + * @author tangle + * @since 2023-10-09 + */ +public class ConfigLoadInterceptor extends AbstractInterceptor { + private static final Logger LOGGER = LoggerFactory.getLogger(); + + private final ServiceMeta serviceMeta = ConfigManager.getConfig(ServiceMeta.class); + + @Override + public ExecuteContext before(ExecuteContext context) { + String pluginConfigValue = PluginConfigManager.getPluginConfig(TestConfig.class).getTestConfigValue(); + if (!StringUtils.isEmpty(pluginConfigValue) && "test-config-value".equals(pluginConfigValue)) { + context.getArguments()[TestConstants.PARAM_INDEX_0] = true; + } + String coreConfigValue = serviceMeta.getApplication(); + if (!StringUtils.isEmpty(coreConfigValue) && "testApplication".equals(coreConfigValue)) { + context.getArguments()[TestConstants.PARAM_INDEX_1] = true; + } + LOGGER.log(Level.INFO, + "Test config load, core config 'service.meta.application' is {0}, " + + "plugin config 'test-config-value' is {1}", + new String[]{coreConfigValue, pluginConfigValue}); + return context; + } + + @Override + public ExecuteContext after(ExecuteContext context) { + return context; + } +} diff --git a/sermant-integration-tests/agentcore-test/agentcore-test-plugin/src/main/resources/META-INF/services/com.huaweicloud.sermant.core.plugin.agent.declarer.PluginDeclarer b/sermant-integration-tests/agentcore-test/agentcore-test-plugin/src/main/resources/META-INF/services/com.huaweicloud.sermant.core.plugin.agent.declarer.PluginDeclarer index ac0499a46b..8d7c63a894 100644 --- a/sermant-integration-tests/agentcore-test/agentcore-test-plugin/src/main/resources/META-INF/services/com.huaweicloud.sermant.core.plugin.agent.declarer.PluginDeclarer +++ b/sermant-integration-tests/agentcore-test/agentcore-test-plugin/src/main/resources/META-INF/services/com.huaweicloud.sermant.core.plugin.agent.declarer.PluginDeclarer @@ -1 +1,2 @@ -com.huaweicloud.agentcore.tests.plugin.declarer.dynamicconfig.TestDynamicConfigDeclarer \ No newline at end of file +com.huaweicloud.agentcore.tests.plugin.declarer.dynamicconfig.TestDynamicConfigDeclarer +com.huaweicloud.agentcore.tests.plugin.declarer.configload.TestConfigLoadDeclarer \ No newline at end of file diff --git a/sermant-integration-tests/agentcore-test/agentcore-test-plugin/src/main/resources/META-INF/services/com.huaweicloud.sermant.core.plugin.config.PluginConfig b/sermant-integration-tests/agentcore-test/agentcore-test-plugin/src/main/resources/META-INF/services/com.huaweicloud.sermant.core.plugin.config.PluginConfig new file mode 100644 index 0000000000..ad9e30ed26 --- /dev/null +++ b/sermant-integration-tests/agentcore-test/agentcore-test-plugin/src/main/resources/META-INF/services/com.huaweicloud.sermant.core.plugin.config.PluginConfig @@ -0,0 +1 @@ +com.huaweicloud.agentcore.tests.plugin.config.TestConfig \ No newline at end of file diff --git a/sermant-integration-tests/agentcore-test/config/config.yaml b/sermant-integration-tests/agentcore-test/config/config.yaml new file mode 100644 index 0000000000..3c3126e856 --- /dev/null +++ b/sermant-integration-tests/agentcore-test/config/config.yaml @@ -0,0 +1,4 @@ +# 测试插件的config +configload.config: + # 测试配置值 + test-config-value: "test-config-value" \ No newline at end of file diff --git a/sermant-integration-tests/agentcore-test/dynamic-test-third-plugin/pom.xml b/sermant-integration-tests/agentcore-test/dynamic-test-third-plugin/pom.xml new file mode 100644 index 0000000000..4cb1b80b00 --- /dev/null +++ b/sermant-integration-tests/agentcore-test/dynamic-test-third-plugin/pom.xml @@ -0,0 +1,47 @@ + + + agentcore-test + com.huaweicloud.sermant + 1.0.0 + + 4.0.0 + dynamic-test-third-plugin + + + ${project.artifactId} + ${project.version} + 8 + 8 + plugin + + + + + com.huaweicloud.sermant + sermant-agentcore-core + provided + + + + + + + org.apache.maven.plugins + maven-shade-plugin + + + org.apache.maven.plugins + maven-jar-plugin + + + + ${package.plugin.name} + ${package.plugin.version} + + + + + + + diff --git a/sermant-integration-tests/agentcore-test/dynamic-test-third-plugin/src/main/java/com/huaweicloud/dynamic/test/third/plugin/declarer/TestDynamicDeclarer.java b/sermant-integration-tests/agentcore-test/dynamic-test-third-plugin/src/main/java/com/huaweicloud/dynamic/test/third/plugin/declarer/TestDynamicDeclarer.java new file mode 100644 index 0000000000..4f20aada3d --- /dev/null +++ b/sermant-integration-tests/agentcore-test/dynamic-test-third-plugin/src/main/java/com/huaweicloud/dynamic/test/third/plugin/declarer/TestDynamicDeclarer.java @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2023-2023 Huawei Technologies Co., Ltd. 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.huaweicloud.dynamic.test.third.plugin.declarer; + +import com.huaweicloud.dynamic.test.third.plugin.interceptor.RepeatEnhanceInterceptor; +import com.huaweicloud.sermant.core.plugin.agent.declarer.AbstractPluginDeclarer; +import com.huaweicloud.sermant.core.plugin.agent.declarer.InterceptDeclarer; +import com.huaweicloud.sermant.core.plugin.agent.matcher.ClassMatcher; +import com.huaweicloud.sermant.core.plugin.agent.matcher.MethodMatcher; + +/** + * 动态安装卸载测试third插件的增强类 + * + * @author tangle + * @since 2023-09-27 + */ +public class TestDynamicDeclarer extends AbstractPluginDeclarer { + @Override + public ClassMatcher getClassMatcher() { + return ClassMatcher.nameEquals( + "com.huaweicloud.agentcore.test.application.tests.dynamic.DynamicTest"); + } + + @Override + public InterceptDeclarer[] getInterceptDeclarers(ClassLoader classLoader) { + return new InterceptDeclarer[]{ + InterceptDeclarer.build(MethodMatcher.nameEquals("repeatEnhance"), new RepeatEnhanceInterceptor()) + }; + } +} diff --git a/sermant-integration-tests/agentcore-test/dynamic-test-third-plugin/src/main/java/com/huaweicloud/dynamic/test/third/plugin/interceptor/RepeatEnhanceInterceptor.java b/sermant-integration-tests/agentcore-test/dynamic-test-third-plugin/src/main/java/com/huaweicloud/dynamic/test/third/plugin/interceptor/RepeatEnhanceInterceptor.java new file mode 100644 index 0000000000..99944ed898 --- /dev/null +++ b/sermant-integration-tests/agentcore-test/dynamic-test-third-plugin/src/main/java/com/huaweicloud/dynamic/test/third/plugin/interceptor/RepeatEnhanceInterceptor.java @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2023-2023 Huawei Technologies Co., Ltd. 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.huaweicloud.dynamic.test.third.plugin.interceptor; + +import com.huaweicloud.sermant.core.common.LoggerFactory; +import com.huaweicloud.sermant.core.plugin.agent.entity.ExecuteContext; +import com.huaweicloud.sermant.core.plugin.agent.interceptor.AbstractInterceptor; + +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * 动态安装卸载测试third插件的拦截器 + * + * @author tangle + * @since 2023-09-27 + */ +public class RepeatEnhanceInterceptor extends AbstractInterceptor { + /** + * third测试插件增强参数下标 + */ + private static final int ARGS_INDEX = 2; + + private static final Logger LOGGER = LoggerFactory.getLogger(); + + @Override + public ExecuteContext before(ExecuteContext context) { + context.getArguments()[ARGS_INDEX] = true; + LOGGER.log(Level.INFO, "Test repeat enhance, third plugin enhance success"); + return context; + } + + @Override + public ExecuteContext after(ExecuteContext context) { + return context; + } +} diff --git a/sermant-integration-tests/agentcore-test/dynamic-test-third-plugin/src/main/resources/META-INF/services/com.huaweicloud.sermant.core.plugin.agent.declarer.PluginDeclarer b/sermant-integration-tests/agentcore-test/dynamic-test-third-plugin/src/main/resources/META-INF/services/com.huaweicloud.sermant.core.plugin.agent.declarer.PluginDeclarer new file mode 100644 index 0000000000..6354000a0d --- /dev/null +++ b/sermant-integration-tests/agentcore-test/dynamic-test-third-plugin/src/main/resources/META-INF/services/com.huaweicloud.sermant.core.plugin.agent.declarer.PluginDeclarer @@ -0,0 +1 @@ +com.huaweicloud.dynamic.test.third.plugin.declarer.TestDynamicDeclarer \ No newline at end of file diff --git a/sermant-integration-tests/agentcore-test/pom.xml b/sermant-integration-tests/agentcore-test/pom.xml index 3e1260c60d..6e6686b25b 100644 --- a/sermant-integration-tests/agentcore-test/pom.xml +++ b/sermant-integration-tests/agentcore-test/pom.xml @@ -17,6 +17,7 @@ agentcore-test-application dynamic-test-first-plugin dynamic-test-second-plugin + dynamic-test-third-plugin @@ -45,6 +46,7 @@ agentcore-test-application dynamic-test-first-plugin dynamic-test-second-plugin + dynamic-test-third-plugin