From 6baabb9fb58b765a5274d313c730fd8ecec77b20 Mon Sep 17 00:00:00 2001 From: TLPC <470193496@qq.com> Date: Thu, 7 Dec 2023 09:42:17 +0800 Subject: [PATCH] =?UTF-8?q?markdown=E4=BF=AE=E6=94=B9=E3=80=81=E8=B4=9F?= =?UTF-8?q?=E8=BD=BD=E5=9D=87=E8=A1=A1=E6=8F=92=E4=BB=B6=E6=A8=A1=E5=9D=97?= =?UTF-8?q?=E7=8B=AC=E7=AB=8B=E3=80=81=E5=88=A0=E9=99=A4=E4=B8=8D=E5=BF=85?= =?UTF-8?q?=E8=A6=81=E7=9A=84=E5=8E=BB=E6=BA=90=E7=A0=81=E6=8F=92=E4=BB=B6?= =?UTF-8?q?=E5=BC=80=E5=8F=91=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: TLPC <470193496@qq.com> --- README.md | 74 ++++++- .../pom.xml | 2 +- .../resttemplate-consumer/pom.xml | 2 +- .../resttemplate/consumer/Configuration.java | 0 .../consumer/ConsumerApplication.java | 0 .../src/main/resources/application.yml | 0 .../resttemplate-provider/pom.xml | 2 +- .../provider/ProviderApplication.java | 0 .../src/main/resources/application.yml | 0 sermant-template/config/bootstrap.properties | 3 - sermant-template/config/config.properties | 37 ---- sermant-template/config/logback.xml | 63 ------ sermant-template/config/plugins.yaml | 2 - sermant-template/demo-application/pom.xml | 68 ------ .../huawei/example/demo/DemoApplication.java | 149 ------------- .../example/demo/service/DemoAnnotation.java | 34 --- .../demo/service/DemoAnnotationService.java | 58 ----- .../demo/service/DemoCheckEnableService.java | 45 ---- .../example/demo/service/DemoInterface.java | 27 --- .../example/demo/service/DemoNameService.java | 113 ---------- .../demo/service/DemoSuperTypeService.java | 71 ------- .../demo/service/DemoTraceService.java | 102 --------- .../src/main/resources/logback.xml | 20 -- sermant-template/pom.xml | 25 --- sermant-template/template/config/config.yaml | 21 -- sermant-template/template/pom.xml | 201 ------------------ .../template/template-plugin/pom.xml | 46 ---- .../demo/common/DemoBeanPropertyApi.java | 58 ----- .../example/demo/common/DemoInterfaceApi.java | 31 --- .../demo/common/DemoInterfaceImpl.java | 34 --- .../example/demo/common/DemoLogger.java | 44 ---- .../example/demo/config/DemoConfig.java | 139 ------------ .../huawei/example/demo/config/DemoPojo.java | 63 ------ .../huawei/example/demo/config/DemoType.java | 31 --- .../demo/declarer/DemoAnnotationDeclarer.java | 49 ----- .../demo/declarer/DemoBootstrapDeclarer.java | 52 ----- .../declarer/DemoCheckEnableDeclarer.java | 55 ----- .../demo/declarer/DemoNameDeclarer.java | 75 ------- .../demo/declarer/DemoNameInfixDeclarer.java | 42 ---- .../demo/declarer/DemoNamePrefixDeclarer.java | 40 ---- .../demo/declarer/DemoNameSuffixDeclarer.java | 43 ---- .../demo/declarer/DemoSuperTypeDeclarer.java | 47 ---- .../demo/declarer/DemoTraceDeclarer.java | 45 ---- .../DemoCheckEnableInterceptor.java | 47 ---- .../interceptor/DemoConfigInterceptor.java | 50 ----- .../interceptor/DemoConstInterceptor.java | 47 ---- .../interceptor/DemoFieldSetInterceptor.java | 57 ----- .../interceptor/DemoInterfaceInterceptor.java | 58 ----- .../interceptor/DemoMemberInterceptor.java | 47 ---- .../interceptor/DemoServiceInterceptor.java | 53 ----- .../interceptor/DemoStaticInterceptor.java | 47 ---- .../DemoTraceConsumerInterceptor.java | 76 ------- .../DemoTraceNormalInterceptor.java | 56 ----- .../DemoTraceProviderInterceptor.java | 76 ------- .../demo/service/DemoComplexService.java | 38 ---- .../demo/service/DemoDynaConfService.java | 55 ----- .../demo/service/DemoHeartBeatService.java | 49 ----- .../demo/service/DemoSimpleService.java | 57 ----- ....core.plugin.agent.declarer.PluginDeclarer | 8 - ...ud.sermant.core.plugin.config.PluginConfig | 1 - ....sermant.core.plugin.service.PluginService | 3 - .../template/template-service/pom.xml | 51 ----- .../demo/config/DemoServiceConfig.java | 45 ---- .../demo/service/DemoComplexServiceImpl.java | 64 ------ ...ud.sermant.core.plugin.config.PluginConfig | 1 - ....sermant.core.plugin.service.PluginService | 1 - 66 files changed, 67 insertions(+), 2933 deletions(-) rename {sermant-template/demo-register => loadbalancer-demo}/pom.xml (98%) rename {sermant-template/demo-register => loadbalancer-demo}/resttemplate-consumer/pom.xml (94%) rename {sermant-template/demo-register => loadbalancer-demo}/resttemplate-consumer/src/main/java/com/huawei/zk/resttemplate/consumer/Configuration.java (100%) rename {sermant-template/demo-register => loadbalancer-demo}/resttemplate-consumer/src/main/java/com/huawei/zk/resttemplate/consumer/ConsumerApplication.java (100%) rename {sermant-template/demo-register => loadbalancer-demo}/resttemplate-consumer/src/main/resources/application.yml (100%) rename {sermant-template/demo-register => loadbalancer-demo}/resttemplate-provider/pom.xml (94%) rename {sermant-template/demo-register => loadbalancer-demo}/resttemplate-provider/src/main/java/com/huawei/zk/resttemplate/provider/ProviderApplication.java (100%) rename {sermant-template/demo-register => loadbalancer-demo}/resttemplate-provider/src/main/resources/application.yml (100%) delete mode 100644 sermant-template/config/bootstrap.properties delete mode 100644 sermant-template/config/config.properties delete mode 100644 sermant-template/config/logback.xml delete mode 100644 sermant-template/config/plugins.yaml delete mode 100644 sermant-template/demo-application/pom.xml delete mode 100644 sermant-template/demo-application/src/main/java/com/huawei/example/demo/DemoApplication.java delete mode 100644 sermant-template/demo-application/src/main/java/com/huawei/example/demo/service/DemoAnnotation.java delete mode 100644 sermant-template/demo-application/src/main/java/com/huawei/example/demo/service/DemoAnnotationService.java delete mode 100644 sermant-template/demo-application/src/main/java/com/huawei/example/demo/service/DemoCheckEnableService.java delete mode 100644 sermant-template/demo-application/src/main/java/com/huawei/example/demo/service/DemoInterface.java delete mode 100644 sermant-template/demo-application/src/main/java/com/huawei/example/demo/service/DemoNameService.java delete mode 100644 sermant-template/demo-application/src/main/java/com/huawei/example/demo/service/DemoSuperTypeService.java delete mode 100644 sermant-template/demo-application/src/main/java/com/huawei/example/demo/service/DemoTraceService.java delete mode 100644 sermant-template/demo-application/src/main/resources/logback.xml delete mode 100644 sermant-template/pom.xml delete mode 100644 sermant-template/template/config/config.yaml delete mode 100644 sermant-template/template/pom.xml delete mode 100644 sermant-template/template/template-plugin/pom.xml delete mode 100644 sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/common/DemoBeanPropertyApi.java delete mode 100644 sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/common/DemoInterfaceApi.java delete mode 100644 sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/common/DemoInterfaceImpl.java delete mode 100644 sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/common/DemoLogger.java delete mode 100644 sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/config/DemoConfig.java delete mode 100644 sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/config/DemoPojo.java delete mode 100644 sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/config/DemoType.java delete mode 100644 sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/declarer/DemoAnnotationDeclarer.java delete mode 100644 sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/declarer/DemoBootstrapDeclarer.java delete mode 100644 sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/declarer/DemoCheckEnableDeclarer.java delete mode 100644 sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/declarer/DemoNameDeclarer.java delete mode 100644 sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/declarer/DemoNameInfixDeclarer.java delete mode 100644 sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/declarer/DemoNamePrefixDeclarer.java delete mode 100644 sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/declarer/DemoNameSuffixDeclarer.java delete mode 100644 sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/declarer/DemoSuperTypeDeclarer.java delete mode 100644 sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/declarer/DemoTraceDeclarer.java delete mode 100644 sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/interceptor/DemoCheckEnableInterceptor.java delete mode 100644 sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/interceptor/DemoConfigInterceptor.java delete mode 100644 sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/interceptor/DemoConstInterceptor.java delete mode 100644 sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/interceptor/DemoFieldSetInterceptor.java delete mode 100644 sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/interceptor/DemoInterfaceInterceptor.java delete mode 100644 sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/interceptor/DemoMemberInterceptor.java delete mode 100644 sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/interceptor/DemoServiceInterceptor.java delete mode 100644 sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/interceptor/DemoStaticInterceptor.java delete mode 100644 sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/interceptor/DemoTraceConsumerInterceptor.java delete mode 100644 sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/interceptor/DemoTraceNormalInterceptor.java delete mode 100644 sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/interceptor/DemoTraceProviderInterceptor.java delete mode 100644 sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/service/DemoComplexService.java delete mode 100644 sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/service/DemoDynaConfService.java delete mode 100644 sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/service/DemoHeartBeatService.java delete mode 100644 sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/service/DemoSimpleService.java delete mode 100644 sermant-template/template/template-plugin/src/main/resources/META-INF/services/com.huaweicloud.sermant.core.plugin.agent.declarer.PluginDeclarer delete mode 100644 sermant-template/template/template-plugin/src/main/resources/META-INF/services/com.huaweicloud.sermant.core.plugin.config.PluginConfig delete mode 100644 sermant-template/template/template-plugin/src/main/resources/META-INF/services/com.huaweicloud.sermant.core.plugin.service.PluginService delete mode 100644 sermant-template/template/template-service/pom.xml delete mode 100644 sermant-template/template/template-service/src/main/java/com/huawei/example/demo/config/DemoServiceConfig.java delete mode 100644 sermant-template/template/template-service/src/main/java/com/huawei/example/demo/service/DemoComplexServiceImpl.java delete mode 100644 sermant-template/template/template-service/src/main/resources/META-INF/services/com.huaweicloud.sermant.core.plugin.config.PluginConfig delete mode 100644 sermant-template/template/template-service/src/main/resources/META-INF/services/com.huaweicloud.sermant.core.plugin.service.PluginService diff --git a/README.md b/README.md index 5755621..40a337e 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,64 @@ -# Sermant-examples - -| 示例名称 | 插件文档 | 示例项目 | -| :---: | :---: | :---: | -|去源码插件开发模板|[去源码插件开发说明](https://github.com/huaweicloud/Sermant/blob/develop/docs/dev-guide/Sermant去源码插件开发说明.md)|[sermant-template](./sermant-template)| -|注册插件使用示例|[注册插件使用说明](https://github.com/huaweicloud/Sermant/blob/develop/docs/user-guide/registry/document.md)|[registry-demo](./registry-demo)| -|路由插件使用示例|[灰度插件说明](https://github.com/huaweicloud/Sermant/blob/develop/docs/user-guide/router/document.md)|[router-demo](./router-demo)| -|治理插件使用示例|[治理插件说明](https://github.com/huaweicloud/Sermant/tree/develop/docs/user-guide/flowcontrol/flowcontrol.md)|[flowcontrol-demo](./flowcontrol-demo)| -|优雅上下线使用示例|[优雅上下线使用说明](https://github.com/huaweicloud/Sermant/tree/develop/docs/user-guide/graceful/document.md)|[grace-demo](./grace-demo)| -|SpringBoot注册插件使用示例|[SpringBoot注册插件说明](https://github.com/huaweicloud/Sermant/tree/develop/docs/user-guide/springboot-registry/document.md)|[springboot-registry-demo](./registry-demo/springboot-registry-demo)| +# 工程介绍 + +| 示例名称 | 插件文档 | 示例项目 | +|:------------------:|:------------------------------------------------------------------------------------:|:------------------------------------------------:| +| 去源码插件开发模板 | [去源码插件开发说明](https://sermant.io/zh/document/developer-guide/) | [sermant-template](./sermant-template) | +| 动态配置插件使用示例 | [动态配置插件使用说明](https://sermant.io/zh/document/plugin/dynamic-config.html) | [flowcontrol-demo](./flowcontrol-demo) | +| 流控插件使用示例 | [流控插件使用说明](https://sermant.io/zh/document/plugin/flowcontrol.html) | [flowcontrol-demo](./flowcontrol-demo) | +| 无损上下线插件使用示例 | [无损上下线插件使用说明](https://sermant.io/zh/document/plugin/graceful.html) | [grace-demo](./grace-demo) | +| 负载均衡插件使用示例 | [负载均衡插件使用说明](https://sermant.io/zh/document/plugin/loadbalancer.html) | [loadbalancer-demo](./loadbalancer-demo) | +| 监控插件使用示例 | [监控插件使用说明](https://sermant.io/zh/document/plugin/monitor.html) | [monitor-demo](./monitor-demo) | +| 标签路由插件使用示例 | [标签路由插件使用说明](https://sermant.io/zh/document/plugin/router.html) | [router-demo](./router-demo) | +| 流量标签透传插件使用示例 | [流量标签透传插件使用说明](https://sermant.io/zh/document/plugin/tag-transmission.html) | [tag-transmission-demo](./tag-transmission-demo) | +| 注册迁移插件使用示例 | [注册迁移插件使用说明](https://sermant.io/zh/document/plugin/register-migration.html) | [registry-demo](./registry-demo) | +| SpringBoot注册插件使用示例 | [SpringBoot注册插件使用说明](https://sermant.io/zh/document/plugin/springboot-registry.html) | [registry-demo](./registry-demo) | +| 服务可见性插件使用示例 | [服务可见性插件使用说明](https://sermant.io/zh/document/plugin/visibility.html) | [visibility-demo](./visibility-demo) | +| 离群实例摘除插件使用示例 | [离群实例摘除插件使用说明](https://sermant.io/zh/document/plugin/removal.html) | [removal-demo](./removal-demo) | + +# RELEASE打包流程 + +### 步骤一:增加新demo至打包脚本 + +> **若无新增demo,忽略此步** + +在scripts/copy_jar.sh脚本中添加新demo相关命令 + +```shell +# 创建文件夹 +mkdir -p package/xxxxx-demo +# 复制jar包 +find . -type f -name "xxxxx-A.jar" -exec cp -v {} package/xxxxx-demo/ \; +find . -type f -name "xxxxx-B.jar" -exec cp -v {} package/xxxxx-demo/ \; +# 打包 +tar -czvf package/result/sermant-examples-xxxxx-demo-$*.tar.gz -C package/xxxxx-demo/ . +``` + +### 步骤二:增加新demo至流水线文件 + +> **若无新增demo,忽略此步** + +在.github/workflows/create_release.yml流水线文件中添加新demo相关命令 + +```shell +# 上传release包 ======================== +- name: Upload Release xxxxx-demo # 上传xxxxx-demo release包 +id: upload-release-asset-xxxxx +uses: actions/upload-release-asset@v1.0.2 +env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} +with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: ${{ github.workspace }}/package/result/sermant-examples-xxxxx-demo-${{ env.version }}.tar.gz + asset_name: sermant-examples-xxxxx-demo-${{ env.version }}.tar.gz + asset_content_type: application/tar +``` + +最后提交并合入上述修改 + +### 步骤三:创建新tag并推送 + +```shell +git tag vx.x.x +``` + +> 此步骤需拥有仓库直推权限 \ No newline at end of file diff --git a/sermant-template/demo-register/pom.xml b/loadbalancer-demo/pom.xml similarity index 98% rename from sermant-template/demo-register/pom.xml rename to loadbalancer-demo/pom.xml index 4a84637..9080665 100644 --- a/sermant-template/demo-register/pom.xml +++ b/loadbalancer-demo/pom.xml @@ -13,7 +13,7 @@ pom com.huaweicloud.sermant - demo-register + loadbalancer-demo 1.0.0 diff --git a/sermant-template/demo-register/resttemplate-consumer/pom.xml b/loadbalancer-demo/resttemplate-consumer/pom.xml similarity index 94% rename from sermant-template/demo-register/resttemplate-consumer/pom.xml rename to loadbalancer-demo/resttemplate-consumer/pom.xml index ce1e542..ac36a30 100644 --- a/sermant-template/demo-register/resttemplate-consumer/pom.xml +++ b/loadbalancer-demo/resttemplate-consumer/pom.xml @@ -3,7 +3,7 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - demo-register + loadbalancer-demo com.huaweicloud.sermant 1.0.0 diff --git a/sermant-template/demo-register/resttemplate-consumer/src/main/java/com/huawei/zk/resttemplate/consumer/Configuration.java b/loadbalancer-demo/resttemplate-consumer/src/main/java/com/huawei/zk/resttemplate/consumer/Configuration.java similarity index 100% rename from sermant-template/demo-register/resttemplate-consumer/src/main/java/com/huawei/zk/resttemplate/consumer/Configuration.java rename to loadbalancer-demo/resttemplate-consumer/src/main/java/com/huawei/zk/resttemplate/consumer/Configuration.java diff --git a/sermant-template/demo-register/resttemplate-consumer/src/main/java/com/huawei/zk/resttemplate/consumer/ConsumerApplication.java b/loadbalancer-demo/resttemplate-consumer/src/main/java/com/huawei/zk/resttemplate/consumer/ConsumerApplication.java similarity index 100% rename from sermant-template/demo-register/resttemplate-consumer/src/main/java/com/huawei/zk/resttemplate/consumer/ConsumerApplication.java rename to loadbalancer-demo/resttemplate-consumer/src/main/java/com/huawei/zk/resttemplate/consumer/ConsumerApplication.java diff --git a/sermant-template/demo-register/resttemplate-consumer/src/main/resources/application.yml b/loadbalancer-demo/resttemplate-consumer/src/main/resources/application.yml similarity index 100% rename from sermant-template/demo-register/resttemplate-consumer/src/main/resources/application.yml rename to loadbalancer-demo/resttemplate-consumer/src/main/resources/application.yml diff --git a/sermant-template/demo-register/resttemplate-provider/pom.xml b/loadbalancer-demo/resttemplate-provider/pom.xml similarity index 94% rename from sermant-template/demo-register/resttemplate-provider/pom.xml rename to loadbalancer-demo/resttemplate-provider/pom.xml index 7585eeb..45948e2 100644 --- a/sermant-template/demo-register/resttemplate-provider/pom.xml +++ b/loadbalancer-demo/resttemplate-provider/pom.xml @@ -3,7 +3,7 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - demo-register + loadbalancer-demo com.huaweicloud.sermant 1.0.0 diff --git a/sermant-template/demo-register/resttemplate-provider/src/main/java/com/huawei/zk/resttemplate/provider/ProviderApplication.java b/loadbalancer-demo/resttemplate-provider/src/main/java/com/huawei/zk/resttemplate/provider/ProviderApplication.java similarity index 100% rename from sermant-template/demo-register/resttemplate-provider/src/main/java/com/huawei/zk/resttemplate/provider/ProviderApplication.java rename to loadbalancer-demo/resttemplate-provider/src/main/java/com/huawei/zk/resttemplate/provider/ProviderApplication.java diff --git a/sermant-template/demo-register/resttemplate-provider/src/main/resources/application.yml b/loadbalancer-demo/resttemplate-provider/src/main/resources/application.yml similarity index 100% rename from sermant-template/demo-register/resttemplate-provider/src/main/resources/application.yml rename to loadbalancer-demo/resttemplate-provider/src/main/resources/application.yml diff --git a/sermant-template/config/bootstrap.properties b/sermant-template/config/bootstrap.properties deleted file mode 100644 index 4b6cdd5..0000000 --- a/sermant-template/config/bootstrap.properties +++ /dev/null @@ -1,3 +0,0 @@ -appName=default -appType=0 -instanceName=default \ No newline at end of file diff --git a/sermant-template/config/config.properties b/sermant-template/config/config.properties deleted file mode 100644 index 3e2ff49..0000000 --- a/sermant-template/config/config.properties +++ /dev/null @@ -1,37 +0,0 @@ -# agent config -agent.config.isEnhanceBootStrapEnable=false -agent.config.ignoredPrefixes=com.huawei.sermant,com.huaweicloud.sermant -agent.config.combineStrategy=ALL -agent.config.serviceBlackList=com.huaweicloud.sermant.implement.service.heartbeat.HeartbeatServiceImpl,com.huaweicloud.sermant.implement.service.send.NettyGatewayClient,com.huaweicloud.sermant.implement.service.tracing.TracingServiceImpl,com.huaweicloud.sermant.implement.service.dynamicconfig.BufferedDynamicConfigService -agent.config.serviceInjectList=com.huawei.discovery.service.lb.filter.NopInstanceFilter,com.huawei.discovery.service.lb.DiscoveryManager - -# adaptor config -adaptor.config.isLoadExtAgentEnable=false - -# dynamic config -dynamic.config.timeoutValue=30000 -dynamic.config.defaultGroup=sermant -dynamic.config.serverAddress=127.0.0.1:2181 -dynamic.config.dynamicConfigType=ZOOKEEPER -dynamic.config.connectRetryTimes=5 -dynamic.config.connectTimeout=1000 -dynamic.config.userName= -dynamic.config.password= -dynamic.config.privateKey= -dynamic.config.enableAuth=false - -# heartbeat config -heartbeat.interval=30000 - -#backend config -backend.nettyIp=127.0.0.1 -backend.nettyPort=6888 -backend.httpIp=127.0.0.1 -backend.httpPort=8900 - -# service meta config -service.meta.application=default -service.meta.version=1.0.0 -service.meta.project=default -service.meta.environment= -service.meta.zone= diff --git a/sermant-template/config/logback.xml b/sermant-template/config/logback.xml deleted file mode 100644 index 341b7fa..0000000 --- a/sermant-template/config/logback.xml +++ /dev/null @@ -1,63 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ERROR - ACCEPT - DENY - - - - ${log.pattern} - - - - - - - - ${log.home_dir}/app/%d{yyyy-MM-dd}/${log.app_name}-%i.log - ${log.maxHistory} - ${log.maxSize} - ${log.totalSize} - true - - - - ${log.pattern} - - - - - - - - - - - \ No newline at end of file diff --git a/sermant-template/config/plugins.yaml b/sermant-template/config/plugins.yaml deleted file mode 100644 index 7a54431..0000000 --- a/sermant-template/config/plugins.yaml +++ /dev/null @@ -1,2 +0,0 @@ -plugins: - - template \ No newline at end of file diff --git a/sermant-template/demo-application/pom.xml b/sermant-template/demo-application/pom.xml deleted file mode 100644 index 1bf00bb..0000000 --- a/sermant-template/demo-application/pom.xml +++ /dev/null @@ -1,68 +0,0 @@ - - - 4.0.0 - - com.huaweicloud.sermant - demo-application - 1.0.0 - - - - org.slf4j - slf4j-api - 1.7.30 - - - ch.qos.logback - logback-core - 1.2.6 - - - ch.qos.logback - logback-classic - 1.2.6 - - - - - ${project.artifactId} - - - org.apache.maven.plugins - maven-jar-plugin - 3.2.0 - - - - true - com.huawei.example.demo.DemoApplication - - - - - - org.apache.maven.plugins - maven-shade-plugin - 3.2.4 - - - package - - shade - - - - - - org.apache.maven.plugins - maven-compiler-plugin - - 7 - 7 - - - - - \ No newline at end of file diff --git a/sermant-template/demo-application/src/main/java/com/huawei/example/demo/DemoApplication.java b/sermant-template/demo-application/src/main/java/com/huawei/example/demo/DemoApplication.java deleted file mode 100644 index 639b9d4..0000000 --- a/sermant-template/demo-application/src/main/java/com/huawei/example/demo/DemoApplication.java +++ /dev/null @@ -1,149 +0,0 @@ -/* - * Copyright (C) 2021-2021 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.huawei.example.demo; - -import com.huawei.example.demo.service.DemoAnnotationService; -import com.huawei.example.demo.service.DemoCheckEnableService; -import com.huawei.example.demo.service.DemoNameService; -import com.huawei.example.demo.service.DemoSuperTypeService; -import com.huawei.example.demo.service.DemoTraceService; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * 示例应用 - * - * @author HapThorin - * @version 1.0.0 - * @since 2021-10-25 - */ -public class DemoApplication { - private static final Logger LOGGER = LoggerFactory.getLogger(DemoApplication.class); - - /** - * 主要方法 - * - * @param args 入参 - */ - public static void main(String[] args) { - annotationAndMethodTypeTest(); - superTypeAndMethodNameTest(); - classNameEqualsAndBaseFuncTest(); - classInfixAndAnnotationTest(); - classPrefixAndReturnTypeTest(); - classSuffixAndParamsTest(); - pluginServiceAndConfigTest(); - tracingFuncTest(); - checkDeclarerEnableTest(); - } - - /** - * 通过注解匹配类,通过方法类型匹配方法进行增强 - */ - private static void annotationAndMethodTypeTest() { - LOGGER.info("annotationAndMethodTypeTest"); - DemoAnnotationService.staticFunc(); - new DemoAnnotationService().memberFunc(); - } - - /** - * 通过超类匹配类,通过方法名匹配方法进行增强 - */ - private static void superTypeAndMethodNameTest() { - LOGGER.info("superTypeAndMethodNameTest"); - DemoSuperTypeService demoSuperTypeService = new DemoSuperTypeService(); - demoSuperTypeService.memberFunc(); - demoSuperTypeService.prefixFunc(); - demoSuperTypeService.memberInfixFunc(); - demoSuperTypeService.funcSuffix(); - } - - /** - * 通过类名精确匹配、字段设置、测试接口 - */ - private static void classNameEqualsAndBaseFuncTest() { - LOGGER.info("classNameEqualsAndBaseFuncTest"); - final DemoNameService demoNameService = new DemoNameService(); - - // 测试字段设置 - demoNameService.fieldFunc(); - demoNameService.fieldFunc(); - - // 测试接口 - DemoNameService.interfaceFunc(); - } - - /** - * 通过类名内缀匹配,通过注解匹配方法进行增强 - */ - private static void classInfixAndAnnotationTest() { - LOGGER.info("classInfixAndAnnotationTest"); - DemoNameService.annotationFunc(); - } - - /** - * 通过类名前缀匹配,通过方法返回值类型匹配方法进行增强 - */ - private static void classPrefixAndReturnTypeTest() { - LOGGER.info("classPrefixAndReturnTypeTest"); - DemoNameService.returnTypeFunc(); - } - - /** - * 通过类名后缀匹配,通过参数数量&&参数类型匹配方法进行增强 - */ - private static void classSuffixAndParamsTest() { - LOGGER.info("classSuffixAndParamsTest"); - DemoNameService.paramsCountAndTypeFunc("A", 0); - } - - /** - * 启动类增强 - */ - private static void bootstrapClassEnhanceTest() { - LOGGER.info("bootstrapClassEnhanceTest"); - - // 测试启动类增强 - Thread.getAllStackTraces(); - new Thread().setName("demo-thread-test"); - } - - /** - * 插件服务测试、插件配置测试 - */ - private static void pluginServiceAndConfigTest() { - LOGGER.info("pluginServiceAndConfigTest"); - DemoNameService.serviceFunc(); - } - - /** - * 链路追踪功能 - */ - private static void tracingFuncTest() { - LOGGER.info("tracingFuncTest"); - DemoTraceService.trace(); - } - - /** - * PluginDeclarer#isEnable()方法测试 - */ - private static void checkDeclarerEnableTest() { - LOGGER.info("checkDeclarerEnableTest"); - DemoCheckEnableService.exampleFunc(); - } -} diff --git a/sermant-template/demo-application/src/main/java/com/huawei/example/demo/service/DemoAnnotation.java b/sermant-template/demo-application/src/main/java/com/huawei/example/demo/service/DemoAnnotation.java deleted file mode 100644 index 8cf9163..0000000 --- a/sermant-template/demo-application/src/main/java/com/huawei/example/demo/service/DemoAnnotation.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (C) 2021-2021 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.huawei.example.demo.service; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * 示例注解,用于作为注解拦截的示例 - * - * @author HapThorin - * @version 1.0.0 - * @since 2021-10-25 - */ -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE, ElementType.METHOD}) -public @interface DemoAnnotation { -} diff --git a/sermant-template/demo-application/src/main/java/com/huawei/example/demo/service/DemoAnnotationService.java b/sermant-template/demo-application/src/main/java/com/huawei/example/demo/service/DemoAnnotationService.java deleted file mode 100644 index 514e993..0000000 --- a/sermant-template/demo-application/src/main/java/com/huawei/example/demo/service/DemoAnnotationService.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (C) 2021-2021 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.huawei.example.demo.service; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * 被注解修饰的示例被拦截点 - * - * @author HapThorin - * @version 1.0.0 - * @since 2021-10-25 - */ -@DemoAnnotation -public class DemoAnnotationService { - private static final Logger LOGGER = LoggerFactory.getLogger(DemoAnnotationService.class); - - /** - * 被拦截的构造函数 - */ - public DemoAnnotationService() { - LOGGER.info("DemoAnnotationService: constructor"); - } - - /** - * 被拦截的静态方法 - */ - public static void staticFunc() { - LOGGER.info("DemoAnnotationService: staticFunc"); - } - - /** - * 被拦截的实例方法 - */ - public void memberFunc() { - LOGGER.info("DemoAnnotationService: memberFunc"); - } - - @Override - public String toString() { - return getClass().getSimpleName(); - } -} diff --git a/sermant-template/demo-application/src/main/java/com/huawei/example/demo/service/DemoCheckEnableService.java b/sermant-template/demo-application/src/main/java/com/huawei/example/demo/service/DemoCheckEnableService.java deleted file mode 100644 index 565ed0d..0000000 --- a/sermant-template/demo-application/src/main/java/com/huawei/example/demo/service/DemoCheckEnableService.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (C) 2022-2022 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.huawei.example.demo.service; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * 用于测试插件内部增强开关是否生效的被拦截点 - * - * @author lilai - * @version 1.0.0 - * @since 2022-08-13 - */ -public class DemoCheckEnableService { - private static final Logger LOGGER = LoggerFactory.getLogger(DemoCheckEnableService.class); - - /** - * 被拦截的构造函数 - */ - private DemoCheckEnableService() { - LOGGER.info("DemoCheckEnableService: constructor"); - } - - /** - * 被拦截的示例方法 - */ - public static void exampleFunc() { - LOGGER.info("DemoCheckEnableService: exampleFunc"); - } -} diff --git a/sermant-template/demo-application/src/main/java/com/huawei/example/demo/service/DemoInterface.java b/sermant-template/demo-application/src/main/java/com/huawei/example/demo/service/DemoInterface.java deleted file mode 100644 index 3ce109b..0000000 --- a/sermant-template/demo-application/src/main/java/com/huawei/example/demo/service/DemoInterface.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (C) 2021-2021 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.huawei.example.demo.service; - -/** - * 示例接口,用作超类拦截的接口 - * - * @author HapThorin - * @version 1.0.0 - * @since 2021-10-25 - */ -public interface DemoInterface { -} diff --git a/sermant-template/demo-application/src/main/java/com/huawei/example/demo/service/DemoNameService.java b/sermant-template/demo-application/src/main/java/com/huawei/example/demo/service/DemoNameService.java deleted file mode 100644 index e52e25f..0000000 --- a/sermant-template/demo-application/src/main/java/com/huawei/example/demo/service/DemoNameService.java +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Copyright (C) 2021-2021 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.huawei.example.demo.service; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * 名称匹配的示例被拦截点 - * - * @author HapThorin - * @version 1.0.0 - * @since 2021-10-25 - */ -public class DemoNameService { - private static final Logger LOGGER = LoggerFactory.getLogger(DemoNameService.class); - - /** - * 被拦截的构造函数 - */ - public DemoNameService() { - LOGGER.info("DemoNameService: constructor"); - } - - /** - * 被拦截的静态方法 - */ - public static void staticFunc() { - LOGGER.info("DemoNameService: staticFunc"); - } - - /** - * 用于测试服务 - */ - public static void serviceFunc() { - LOGGER.info("DemoNameService: serviceFunc"); - } - - /** - * 用于测试统一配置 - */ - public static void configFunc() { - LOGGER.info("DemoNameService: configFunc"); - } - - /** - * 被拦截的实例方法 - */ - public void memberFunc() { - LOGGER.info("DemoNameService: memberFunc"); - } - - /** - * 用于测试字段设置 - */ - public void fieldFunc() { - LOGGER.info("DemoNameService: fieldFunc"); - } - - /** - * 用于测试接口 - */ - public static void interfaceFunc() { - LOGGER.info("DemoNameService: interfaceFunc"); - } - - /** - * 用于测试通过注解匹配方法 - */ - @DemoAnnotation - public static void annotationFunc() { - LOGGER.info("DemoNameService: annotationFunction"); - } - - /** - * 用于测试通过返回值类型匹配方方法 - * - * @return long - */ - public static long returnTypeFunc() { - LOGGER.info("DemoNameService: returnTypeFunc"); - return 0L; - } - - /** - * 用于测试参数数量和参数类型匹配 - * - * @param str - * @param x - */ - public static void paramsCountAndTypeFunc(String str, int x) { - LOGGER.info("DemoNameService: paramsCountAndTypeFunc"); - } - - @Override - public String toString() { - return getClass().getSimpleName(); - } -} diff --git a/sermant-template/demo-application/src/main/java/com/huawei/example/demo/service/DemoSuperTypeService.java b/sermant-template/demo-application/src/main/java/com/huawei/example/demo/service/DemoSuperTypeService.java deleted file mode 100644 index 5c79652..0000000 --- a/sermant-template/demo-application/src/main/java/com/huawei/example/demo/service/DemoSuperTypeService.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright (C) 2021-2021 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.huawei.example.demo.service; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * 超类拦截的示例被拦截点 - * - * @author HapThorin - * @version 1.0.0 - * @since 2021-10-25 - */ -public class DemoSuperTypeService implements DemoInterface { - private static final Logger LOGGER = LoggerFactory.getLogger(DemoSuperTypeService.class); - - /** - * 被拦截的构造函数 - */ - public DemoSuperTypeService() { - LOGGER.info("DemoSuperTypeService: constructor"); - } - - /** - * 被拦截的实例方法 - */ - public void memberFunc() { - LOGGER.info("DemoSuperTypeService: memberFunc"); - } - - /** - * 测试通过前缀匹配方法 - */ - public void prefixFunc() { - LOGGER.info("DemoSuperTypeService: prefixFunc"); - } - - /** - * 测试通过后缀匹配方法 - */ - public void funcSuffix() { - LOGGER.info("DemoSuperTypeService: funcSuffix"); - } - - /** - * 测试通过内缀匹配方法 - */ - public void memberInfixFunc() { - LOGGER.info("DemoSuperTypeService: memberInfixFunc"); - } - - @Override - public String toString() { - return getClass().getSimpleName(); - } -} diff --git a/sermant-template/demo-application/src/main/java/com/huawei/example/demo/service/DemoTraceService.java b/sermant-template/demo-application/src/main/java/com/huawei/example/demo/service/DemoTraceService.java deleted file mode 100644 index ba4bea8..0000000 --- a/sermant-template/demo-application/src/main/java/com/huawei/example/demo/service/DemoTraceService.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright (C) 2021-2021 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.huawei.example.demo.service; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.HashMap; -import java.util.Map; - -/** - * 链路功能的模拟通信示例 - * - * @author HapThorin - * @version 1.0.0 - * @since 2021-10-25 - */ -public class DemoTraceService { - private static final Logger LOGGER = LoggerFactory.getLogger(DemoTraceService.class); - - private static final ThreadLocal> END_POINT = new ThreadLocal>(); - - private DemoTraceService() { - } - - /** - * 主要方法 - */ - public static void trace() { - // 链路追踪入口跨度(根跨度场景) - provider(new HashMap()); - service(END_POINT.get()); - - // 调用进程内普通方法 - normal(); - - // 链路追踪出口跨度 - Map message = consumer(); - service(message); - - // 链路追踪入口跨度(非根跨度场景) - provider(message); - service(END_POINT.get()); - - // 调用进程内的普通方法 - normal(); - - // 链路追踪出口跨度 - service(consumer()); - } - - /** - * 模拟发送消息,直接写到ThreadLocal中 - * - * @param message 数据集 - */ - private static void provider(Map message) { - END_POINT.set(message); - } - - /** - * 模拟进程内的普通方法 - */ - private static void normal() { - } - - /** - * 模拟接收数据,直接从ThreadLocal中获取 - * - * @return 数据集 - */ - private static Map consumer() { - final Map message = END_POINT.get(); - if (message == null) { - return new HashMap<>(); - } - return message; - } - - /** - * 模拟进行业务操作,直接输出数据集,观察链路监控对数据集的操作 - * - * @param message 数据集 - */ - private static void service(Map message) { - LOGGER.info("DemoTraceService: {}", message); - } -} diff --git a/sermant-template/demo-application/src/main/resources/logback.xml b/sermant-template/demo-application/src/main/resources/logback.xml deleted file mode 100644 index d4b8dfd..0000000 --- a/sermant-template/demo-application/src/main/resources/logback.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - INFO - ACCEPT - DENY - - - - [%level] %msg%n - - - - - - - - \ No newline at end of file diff --git a/sermant-template/pom.xml b/sermant-template/pom.xml deleted file mode 100644 index d44871e..0000000 --- a/sermant-template/pom.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - com.huaweicloud.sermant.examples - sermant-examples - 1.0.0 - - 4.0.0 - - sermant-template - pom - - - template - demo-application - demo-register - - - - 8 - 8 - - \ No newline at end of file diff --git a/sermant-template/template/config/config.yaml b/sermant-template/template/config/config.yaml deleted file mode 100644 index 0ae3638..0000000 --- a/sermant-template/template/config/config.yaml +++ /dev/null @@ -1,21 +0,0 @@ -demo.test: - intField: 123456 - strField: hello world, intField = ${intField}, appName = ${appName}, user.home = ${user.home} - pojoField: - intField: 123 - strField: stringField0, intField = ${intField}, appName = ${appName}, user.home = ${user.home} - shortArr: [ 100, 101, 102 ] - longList: [ 100, 101, 102 ] - str2DemoSimplePojoMap: - str: - intField: 0 - str: stringField0 # yaml配置中,数组、List和Map中的复杂对象不支持字段别名(ConfigFieldKey),字符串不支持值转换(${}) - str1: - intField: 1 - str: stringField1 - str2: - intField: 2 - str: stringField2 - enumType: DEMO -com.huawei.example.demo.config.DemoServiceConfig: - testField: test-field-value \ No newline at end of file diff --git a/sermant-template/template/pom.xml b/sermant-template/template/pom.xml deleted file mode 100644 index bb0317b..0000000 --- a/sermant-template/template/pom.xml +++ /dev/null @@ -1,201 +0,0 @@ - - - - com.huaweicloud.sermant.examples - sermant-template - 1.0.0 - - 4.0.0 - - template - pom - - template-plugin - template-service - - - - ${pom.basedir}/.. - template - com.huaweicloud.sermant.dependencies - ${sermant.basedir}/agent/pluginPackage - undefined - ${package.plugin.dir}/${package.plugin.name}/${package.plugin.type} - ${project.version} - ../config - ${package.plugin.dir}/${package.plugin.name}/config - 8 - 8 - - - - - - org.apache.maven.plugins - maven-resources-plugin - 3.1.0 - false - - - package - - copy-resources - - - ${sermant.basedir}/agent/config - true - - - ${config.source.dir} - - bootstrap.properties - config.properties - logback.xml - plugins.yaml - - - - - - - - - org.apache.maven.plugins - maven-clean-plugin - 2.5 - false - - - agent-clean - clean - - clean - - - - - ${sermant.basedir}/agent - - - - - - - - org.apache.maven.plugins - maven-dependency-plugin - 3.3.0 - false - - - copy - package - - copy - - - - - - - com.huaweicloud.sermant - sermant-agentcore-premain - 0.7.0 - jar - false - ${sermant.basedir}/agent - sermant-agent.jar - - - com.huaweicloud.sermant - sermant-agentcore-core - 0.7.0 - jar - false - ${sermant.basedir}/agent/core - - - com.huaweicloud.sermant - sermant-agentcore-implement - 0.7.0 - jar - false - ${sermant.basedir}/agent/implement - - - - - - - - - - org.apache.maven.plugins - maven-jar-plugin - - - - ${package.plugin.name} - ${package.plugin.version} - - - - - - org.apache.maven.plugins - maven-resources-plugin - - - package - - copy-resources - - - ${config.output.dir} - true - - - ${config.source.dir} - - config.yaml - - - - - - - - - - org.apache.maven.plugins - maven-shade-plugin - - - package - - shade - - - - - ${package.output.dir}/${project.artifactId}-${project.version}.jar - - - net.bytebuddy - ${shade.common.prefix}.net.bytebuddy - - - - - - - - - - - - \ No newline at end of file diff --git a/sermant-template/template/template-plugin/pom.xml b/sermant-template/template/template-plugin/pom.xml deleted file mode 100644 index 059e552..0000000 --- a/sermant-template/template/template-plugin/pom.xml +++ /dev/null @@ -1,46 +0,0 @@ - - - - com.huaweicloud.sermant.examples - template - 1.0.0 - - 4.0.0 - - template-plugin - - - ${pom.basedir}/../.. - template - plugin - false - 8 - 8 - - - - - com.huaweicloud.sermant - sermant-agentcore-core - 0.7.0 - provided - - - javax.servlet - javax.servlet-api - 3.1.0 - provided - - - - - - - org.apache.maven.plugins - maven-shade-plugin - - - - \ No newline at end of file diff --git a/sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/common/DemoBeanPropertyApi.java b/sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/common/DemoBeanPropertyApi.java deleted file mode 100644 index ce502c8..0000000 --- a/sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/common/DemoBeanPropertyApi.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (C) 2021-2022 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.huawei.example.demo.common; - -import com.huaweicloud.sermant.core.plugin.agent.annotations.BeanPropertyFlag; - -/** - * 测试为被增强类添加JavaBean接口,增添JavaBean属性并为之设置get,set方法 - * - * @author HapThorin - * @version 1.0.0 - * @since 2022-01-22 - */ -@BeanPropertyFlag(value = "foo", type = String.class) -@BeanPropertyFlag(value = "bar", type = int.class) -public interface DemoBeanPropertyApi { - /** - * foo字段的get方法 - * - * @return foo字段值 - */ - String getFoo(); - - /** - * foo字段的set方法 - * - * @param foo foo字段值 - */ - void setFoo(String foo); - - /** - * bar字段的get方法 - * - * @return bar字段值 - */ - int getBar(); - - /** - * bar字段的set方法 - * - * @param bar bar字段值 - */ - void setBar(int bar); -} diff --git a/sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/common/DemoInterfaceApi.java b/sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/common/DemoInterfaceApi.java deleted file mode 100644 index bf716f5..0000000 --- a/sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/common/DemoInterfaceApi.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (C) 2021-2022 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.huawei.example.demo.common; - -/** - * 用于测试为被增强类添加接口,该接口使用{@link DemoInterfaceImpl}实现 - * - * @author HapThorin - * @version 1.0.0 - * @since 2022-01-22 - */ -public interface DemoInterfaceApi { - /** - * 测试方法 - */ - void foo(); -} diff --git a/sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/common/DemoInterfaceImpl.java b/sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/common/DemoInterfaceImpl.java deleted file mode 100644 index 0486f22..0000000 --- a/sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/common/DemoInterfaceImpl.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (C) 2021-2022 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.huawei.example.demo.common; - -/** - * 测试使用该类实现被增强类的{@link DemoInterfaceApi}接口 - * - * @author HapThorin - * @version 1.0.0 - * @since 2022-01-22 - */ -public class DemoInterfaceImpl implements DemoInterfaceApi { - /** - * {@inheritDoc} - */ - @Override - public void foo() { - DemoLogger.println("[DemoInterfaceImpl]-foo"); - } -} diff --git a/sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/common/DemoLogger.java b/sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/common/DemoLogger.java deleted file mode 100644 index 8fe9765..0000000 --- a/sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/common/DemoLogger.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (C) 2021-2021 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.huawei.example.demo.common; - -import com.huaweicloud.sermant.core.common.LoggerFactory; - -import java.util.logging.Logger; - -/** - * 示例插件的日志类 - * - * @author HapThorin - * @version 1.0.0 - * @since 2021-11-26 - */ -public class DemoLogger { - private static final Logger logger = LoggerFactory.getLogger(); - - private DemoLogger() { - } - - /** - * 输出日志到控制台,采用ERROR级别,否则会被屏蔽 - * - * @param message 日志信息 - */ - public static void println(String message) { - logger.severe(message); - } -} diff --git a/sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/config/DemoConfig.java b/sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/config/DemoConfig.java deleted file mode 100644 index da58072..0000000 --- a/sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/config/DemoConfig.java +++ /dev/null @@ -1,139 +0,0 @@ -/* - * Copyright (C) 2021-2021 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.huawei.example.demo.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; - -import java.util.Arrays; -import java.util.List; -import java.util.Map; - -/** - * 统一配置示例 - * - * @author HapThorin - * @version 1.0.0 - * @since 2021-10-25 - */ -@ConfigTypeKey("demo.test") // 声明前缀 -public class DemoConfig implements PluginConfig { // 有设置拦截器别名需求的继承AliaConfig,否则实现PluginConfig - - /** - * 基础类型配置(除byte和char) - * - *

添加@ConfigFieldKey("int-field")后,config.yaml中配置demo.test.intField或demo.test.int-field皆可

- *

如果不添加注解,config.yaml中只能配置为demo.test.intField

- */ - @ConfigFieldKey("int-field") - private int intField; - - /** - * 字符串类型配置 - */ - private String strField; - - /** - * 复杂类型配置 - */ - private DemoPojo pojoField; - - /** - * 数组类型,子类型为基础类型、字符串或枚举 - */ - private short[] shortArr; - - /** - * 集合类型,子类型为基础类型、字符串或枚举 - */ - private List longList; - - /** - * 字典类型,子类型为基础类型、字符串或枚举 - */ - @ConfigFieldKey("str2DemoSimplePojoMap") // 为属性起别名 - private Map map; - - /** - * 枚举类型 - */ - private DemoType enumType; - - public int getIntField() { - return intField; - } - - public void setIntField(int intField) { - this.intField = intField; - } - - public String getStrField() { - return strField; - } - - public void setStrField(String strField) { - this.strField = strField; - } - - public DemoPojo getPojoField() { - return pojoField; - } - - public void setPojoField(DemoPojo pojoField) { - this.pojoField = pojoField; - } - - public short[] getShortArr() { - return shortArr; - } - - public void setShortArr(short[] shortArr) { - this.shortArr = shortArr; - } - - public List getLongList() { - return longList; - } - - public void setLongList(List longList) { - this.longList = longList; - } - - public Map getMap() { - return map; - } - - public void setMap(Map map) { - this.map = map; - } - - public DemoType getEnumType() { - return enumType; - } - - public void setEnumType(DemoType enumType) { - this.enumType = enumType; - } - - @Override - public String toString() { - return "DemoConfig{" + "intField=" + intField + ", strField='" + strField + '\'' + ", pojoField=" + pojoField - + ", shortArr=" + Arrays.toString(shortArr) + ", longList=" + longList + ", map=" + map + ", enumType=" - + enumType + "} " + super.toString(); - } -} diff --git a/sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/config/DemoPojo.java b/sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/config/DemoPojo.java deleted file mode 100644 index 559fd32..0000000 --- a/sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/config/DemoPojo.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (C) 2021-2021 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.huawei.example.demo.config; - -import com.huaweicloud.sermant.core.config.common.ConfigFieldKey; - -/** - * 插件配置中的复杂对象示例 - * - * @author HapThorin - * @version 1.0.0 - * @since 2021-11-16 - */ -public class DemoPojo { - /** - * 普通属性 - */ - private int intField; - - /** - * 起别名的属性,将作为检验别名是否生效的依据 - */ - @ConfigFieldKey("strField") // 修改参数名称后缀 - private String str; - - public int getIntField() { - return intField; - } - - public void setIntField(int intField) { - this.intField = intField; - } - - public String getStr() { - return str; - } - - public void setStr(String str) { - this.str = str; - } - - @Override - public String toString() { - return "DemoPojo{" - + "intField=" + intField - + ", str='" + str + '\'' - + '}'; - } -} diff --git a/sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/config/DemoType.java b/sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/config/DemoType.java deleted file mode 100644 index e39e062..0000000 --- a/sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/config/DemoType.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (C) 2021-2021 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.huawei.example.demo.config; - -/** - * 示例枚举 - * - * @author HapThorin - * @version 1.0.0 - * @since 2021-10-25 - */ -public enum DemoType { - /** - * 示例枚举 - */ - DEMO -} diff --git a/sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/declarer/DemoAnnotationDeclarer.java b/sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/declarer/DemoAnnotationDeclarer.java deleted file mode 100644 index 53277ed..0000000 --- a/sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/declarer/DemoAnnotationDeclarer.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (C) 2021-2021 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.huawei.example.demo.declarer; - -import com.huawei.example.demo.interceptor.DemoConstInterceptor; -import com.huawei.example.demo.interceptor.DemoMemberInterceptor; -import com.huawei.example.demo.interceptor.DemoStaticInterceptor; - -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 HapThorin - * @version 1.0.0 - * @since 2021-10-25 - */ -public class DemoAnnotationDeclarer extends AbstractPluginDeclarer { - @Override - public ClassMatcher getClassMatcher() { - return ClassMatcher.isAnnotatedWith("com.huawei.example.demo.service.DemoAnnotation"); - } - - @Override - public InterceptDeclarer[] getInterceptDeclarers(ClassLoader classLoader) { - return new InterceptDeclarer[]{ - InterceptDeclarer.build(MethodMatcher.isStaticMethod(), new DemoStaticInterceptor()), - InterceptDeclarer.build(MethodMatcher.isConstructor(), new DemoConstInterceptor()), - InterceptDeclarer.build(MethodMatcher.isMemberMethod(), new DemoMemberInterceptor()) - }; - } -} diff --git a/sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/declarer/DemoBootstrapDeclarer.java b/sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/declarer/DemoBootstrapDeclarer.java deleted file mode 100644 index 90a34ab..0000000 --- a/sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/declarer/DemoBootstrapDeclarer.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (C) 2021-2021 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.huawei.example.demo.declarer; - -import com.huawei.example.demo.interceptor.DemoConstInterceptor; -import com.huawei.example.demo.interceptor.DemoMemberInterceptor; -import com.huawei.example.demo.interceptor.DemoStaticInterceptor; - -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; - -/** - * 以Thread为例测试启动类加载器加载的类的增强情况 - * - * @author HapThorin - * @version 1.0.0 - * @since 2021-10-27 - */ -public class DemoBootstrapDeclarer extends AbstractPluginDeclarer { - @Override - public ClassMatcher getClassMatcher() { - return ClassMatcher.nameEquals("java.lang.Thread"); - } - - @Override - public InterceptDeclarer[] getInterceptDeclarers(ClassLoader classLoader) { - return new InterceptDeclarer[]{ - InterceptDeclarer.build(MethodMatcher.nameEquals("getAllStackTraces"), - new DemoStaticInterceptor()), // 测试静态方法 - InterceptDeclarer.build(MethodMatcher.isConstructor().and(MethodMatcher.paramCountEquals(0)), - new DemoConstInterceptor()), // 测试无参构造函数 - InterceptDeclarer.build(MethodMatcher.nameEquals("setName"), - new DemoMemberInterceptor()), // 测试实例方法 - }; - } -} diff --git a/sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/declarer/DemoCheckEnableDeclarer.java b/sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/declarer/DemoCheckEnableDeclarer.java deleted file mode 100644 index 8b8576f..0000000 --- a/sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/declarer/DemoCheckEnableDeclarer.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (C) 2022-2022 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.huawei.example.demo.declarer; - -import com.huawei.example.demo.interceptor.DemoCheckEnableInterceptor; - -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 lilai - * @version 1.0.0 - * @since 2022-08-13 - */ -public class DemoCheckEnableDeclarer extends AbstractPluginDeclarer { - @Override - public ClassMatcher getClassMatcher() { - return ClassMatcher.nameEquals("com.huawei.example.demo.service.DemoCheckEnableService"); - } - - @Override - public InterceptDeclarer[] getInterceptDeclarers(ClassLoader classLoader) { - return new InterceptDeclarer[]{ - InterceptDeclarer.build(MethodMatcher.nameEquals("exampleFunc"), new DemoCheckEnableInterceptor()) - }; - } - - /** - * 测试插件自身按实际情况决定是否要增强声明的拦截点 - * - * @return 是否需要增强 - */ - @Override - public boolean isEnabled() { - return false; - } -} diff --git a/sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/declarer/DemoNameDeclarer.java b/sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/declarer/DemoNameDeclarer.java deleted file mode 100644 index 5066cd4..0000000 --- a/sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/declarer/DemoNameDeclarer.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (C) 2021-2021 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.huawei.example.demo.declarer; - -import com.huawei.example.demo.common.DemoBeanPropertyApi; -import com.huawei.example.demo.common.DemoInterfaceApi; -import com.huawei.example.demo.common.DemoInterfaceImpl; -import com.huawei.example.demo.interceptor.DemoConfigInterceptor; -import com.huawei.example.demo.interceptor.DemoFieldSetInterceptor; -import com.huawei.example.demo.interceptor.DemoInterfaceInterceptor; -import com.huawei.example.demo.interceptor.DemoMemberInterceptor; -import com.huawei.example.demo.interceptor.DemoServiceInterceptor; - -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.declarer.SuperTypeDeclarer; -import com.huaweicloud.sermant.core.plugin.agent.matcher.ClassMatcher; -import com.huaweicloud.sermant.core.plugin.agent.matcher.MethodMatcher; - -/** - * 通过名称定位到拦截点的增强定义,本示例处理测试构造函数、静态方法和示例方法三种拦截点外,还会测试日志功能和统一配置 - *

本示例直接使用名称完全匹配的方式定位,其他名称相关的定位方式有: - *

- *     1. {@link ClassMatcher#nameEquals(String)}完全匹配
- *     2. {@link ClassMatcher#nameContains} 多重匹配
- *     3. {@link ClassMatcher#namePrefixedWith(String)} 前缀匹配
- *     4. {@link ClassMatcher#nameSuffixedWith(String)} 后缀匹配
- *     5. {@link ClassMatcher#nameInfixedWith(String)} 内容包含
- *     6. {@link ClassMatcher#nameMatches(String)} 正则匹配
- * 
- * - * @author HapThorin - * @version 1.0.0 - * @since 2021-10-25 - */ -public class DemoNameDeclarer extends AbstractPluginDeclarer { - @Override - public ClassMatcher getClassMatcher() { - return ClassMatcher.nameEquals("com.huawei.example.demo.service.DemoNameService"); - } - - @Override - public InterceptDeclarer[] getInterceptDeclarers(ClassLoader classLoader) { - return new InterceptDeclarer[]{ - InterceptDeclarer.build(MethodMatcher.nameEquals("serviceFunc"), new DemoServiceInterceptor()), - InterceptDeclarer.build(MethodMatcher.nameEquals("configFunc"), new DemoConfigInterceptor()), - InterceptDeclarer.build(MethodMatcher.nameEquals("fieldFunc"), - new DemoFieldSetInterceptor(),new DemoMemberInterceptor()), - InterceptDeclarer.build(MethodMatcher.isMemberMethod().and(MethodMatcher.nameEquals("interfaceFunc")), - new DemoInterfaceInterceptor()) - }; - } - - @Override - public SuperTypeDeclarer[] getSuperTypeDeclarers() { - return new SuperTypeDeclarer[]{ - SuperTypeDeclarer.ForImplInstance.build(DemoInterfaceApi.class, new DemoInterfaceImpl()), - SuperTypeDeclarer.ForBeanProperty.build(DemoBeanPropertyApi.class) - }; - } -} diff --git a/sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/declarer/DemoNameInfixDeclarer.java b/sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/declarer/DemoNameInfixDeclarer.java deleted file mode 100644 index 7a516e0..0000000 --- a/sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/declarer/DemoNameInfixDeclarer.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (C) 2022-2022 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.huawei.example.demo.declarer; - -import com.huawei.example.demo.interceptor.DemoMemberInterceptor; - -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 luanwenfei - * @since 2022-04-07 - */ -public class DemoNameInfixDeclarer extends AbstractPluginDeclarer { - @Override - public ClassMatcher getClassMatcher() { - return ClassMatcher.nameInfixedWith("example.demo.service"); - } - - @Override - public InterceptDeclarer[] getInterceptDeclarers(ClassLoader classLoader) { - return new InterceptDeclarer[]{ - InterceptDeclarer.build(MethodMatcher.isAnnotatedWith("com.huawei.example.demo.service.DemoAnnotation"), - new DemoMemberInterceptor()) - }; - } -} diff --git a/sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/declarer/DemoNamePrefixDeclarer.java b/sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/declarer/DemoNamePrefixDeclarer.java deleted file mode 100644 index 3b742ff..0000000 --- a/sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/declarer/DemoNamePrefixDeclarer.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (C) 2022-2022 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.huawei.example.demo.declarer; - -import com.huawei.example.demo.interceptor.DemoMemberInterceptor; - -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 luanwenfei - * @since 2022-04-07 - */ -public class DemoNamePrefixDeclarer extends AbstractPluginDeclarer { - @Override - public ClassMatcher getClassMatcher() { - return ClassMatcher.namePrefixedWith("com.huawei.example.demo.service.DemoName"); - } - - @Override - public InterceptDeclarer[] getInterceptDeclarers(ClassLoader classLoader) { - return new InterceptDeclarer[] { - InterceptDeclarer.build(MethodMatcher.resultTypeEquals(long.class), new DemoMemberInterceptor())}; - } -} diff --git a/sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/declarer/DemoNameSuffixDeclarer.java b/sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/declarer/DemoNameSuffixDeclarer.java deleted file mode 100644 index 140c49e..0000000 --- a/sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/declarer/DemoNameSuffixDeclarer.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (C) 2022-2022 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.huawei.example.demo.declarer; - -import com.huawei.example.demo.interceptor.DemoMemberInterceptor; - -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 luanwenfei - * @since 2022-04-07 - */ -public class DemoNameSuffixDeclarer extends AbstractPluginDeclarer { - private static final int PARAMS_COUNT = 2; - - @Override - public ClassMatcher getClassMatcher() { - return ClassMatcher.nameSuffixedWith("DemoNameService"); - } - - @Override - public InterceptDeclarer[] getInterceptDeclarers(ClassLoader classLoader) { - return new InterceptDeclarer[] { - InterceptDeclarer.build(MethodMatcher.and(MethodMatcher.paramCountEquals(PARAMS_COUNT), - MethodMatcher.paramTypesEqual(String.class, int.class)), new DemoMemberInterceptor())}; - } -} diff --git a/sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/declarer/DemoSuperTypeDeclarer.java b/sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/declarer/DemoSuperTypeDeclarer.java deleted file mode 100644 index 829b34f..0000000 --- a/sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/declarer/DemoSuperTypeDeclarer.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (C) 2021-2021 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.huawei.example.demo.declarer; - -import com.huawei.example.demo.interceptor.DemoMemberInterceptor; - -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 HapThorin - * @version 1.0.0 - * @since 2021-10-25 - */ -public class DemoSuperTypeDeclarer extends AbstractPluginDeclarer { - @Override - public ClassMatcher getClassMatcher() { - return ClassMatcher.isExtendedFrom("com.huawei.example.demo.service.DemoInterface"); - } - - @Override - public InterceptDeclarer[] getInterceptDeclarers(ClassLoader classLoader) { - return new InterceptDeclarer[] { - InterceptDeclarer.build(MethodMatcher.nameEquals("memberFunc"), new DemoMemberInterceptor()), - InterceptDeclarer.build(MethodMatcher.nameSuffixedWith("Suffix"), new DemoMemberInterceptor()), - InterceptDeclarer.build(MethodMatcher.namePrefixedWith("prefix"), new DemoMemberInterceptor()), - InterceptDeclarer.build(MethodMatcher.nameInfixedWith("Infix"), new DemoMemberInterceptor())}; - } -} diff --git a/sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/declarer/DemoTraceDeclarer.java b/sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/declarer/DemoTraceDeclarer.java deleted file mode 100644 index 35d9e80..0000000 --- a/sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/declarer/DemoTraceDeclarer.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (C) 2021-2021 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.huawei.example.demo.declarer; - -import com.huawei.example.demo.interceptor.DemoTraceConsumerInterceptor; -import com.huawei.example.demo.interceptor.DemoTraceNormalInterceptor; -import com.huawei.example.demo.interceptor.DemoTraceProviderInterceptor; - -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 HapThorin - * @version 1.0.0 - * @since 2021-10-25 - */ -public class DemoTraceDeclarer extends AbstractPluginDeclarer { - @Override - public ClassMatcher getClassMatcher() { - return ClassMatcher.nameEquals("com.huawei.example.demo.service.DemoTraceService"); - } - - @Override - public InterceptDeclarer[] getInterceptDeclarers(ClassLoader classLoader) { - return new InterceptDeclarer[] { - InterceptDeclarer.build(MethodMatcher.nameEquals("provider"), new DemoTraceProviderInterceptor()), - InterceptDeclarer.build(MethodMatcher.nameEquals("normal"), new DemoTraceNormalInterceptor()), - InterceptDeclarer.build(MethodMatcher.nameEquals("consumer"), new DemoTraceConsumerInterceptor())}; - } -} diff --git a/sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/interceptor/DemoCheckEnableInterceptor.java b/sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/interceptor/DemoCheckEnableInterceptor.java deleted file mode 100644 index 3ebb780..0000000 --- a/sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/interceptor/DemoCheckEnableInterceptor.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (C) 2022-2022 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.huawei.example.demo.interceptor; - -import com.huawei.example.demo.common.DemoLogger; - -import com.huaweicloud.sermant.core.plugin.agent.entity.ExecuteContext; -import com.huaweicloud.sermant.core.plugin.agent.interceptor.AbstractInterceptor; - -import java.util.Locale; - -/** - * 用于测试插件内部增强开关是否生效 - * - * @author lilai - * @version 1.0.0 - * @since 2022-08-13 - */ -public class DemoCheckEnableInterceptor extends AbstractInterceptor { - @Override - public ExecuteContext before(ExecuteContext context) throws Exception { - DemoLogger.println(String.format(Locale.ROOT, "[DemoCheckEnableInterceptor]before, class: %s, method: %s.", - context.getRawCls().getName(), context.getMethod().getName())); - return context; - } - - @Override - public ExecuteContext after(ExecuteContext context) throws Exception { - DemoLogger.println(String.format(Locale.ROOT, "[DemoCheckEnableInterceptor]after, class: %s, method: %s.", - context.getRawCls().getName(), context.getMethod().getName())); - return context; - } -} diff --git a/sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/interceptor/DemoConfigInterceptor.java b/sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/interceptor/DemoConfigInterceptor.java deleted file mode 100644 index 436a96c..0000000 --- a/sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/interceptor/DemoConfigInterceptor.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (C) 2021-2021 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.huawei.example.demo.interceptor; - -import com.huawei.example.demo.common.DemoLogger; -import com.huawei.example.demo.config.DemoConfig; - -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; - -/** - * 统一配置功能的拦截器示例,在本示例中,将展示如何在插件端获取统一配置 - * - * @author HapThorin - * @version 1.0.0 - * @since 2021-10-25 - */ -public class DemoConfigInterceptor extends AbstractInterceptor { - private DemoConfig config; - - @Override - public ExecuteContext before(ExecuteContext context) throws Exception { - DemoLogger.println(context.getRawCls().getSimpleName() + ": [DemoConfigInterceptor]-before"); - config = PluginConfigManager.getPluginConfig(DemoConfig.class); - return context; - } - - @Override - public ExecuteContext after(ExecuteContext context) throws Exception { - final String clsName = context.getRawCls().getSimpleName(); - DemoLogger.println(clsName + ": " + config); - DemoLogger.println(clsName + ": [DemoConfigInterceptor]-after"); - return context; - } -} diff --git a/sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/interceptor/DemoConstInterceptor.java b/sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/interceptor/DemoConstInterceptor.java deleted file mode 100644 index 2c3283d..0000000 --- a/sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/interceptor/DemoConstInterceptor.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (C) 2021-2021 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.huawei.example.demo.interceptor; - -import com.huawei.example.demo.common.DemoLogger; - -import com.huaweicloud.sermant.core.plugin.agent.entity.ExecuteContext; -import com.huaweicloud.sermant.core.plugin.agent.interceptor.AbstractInterceptor; - -import java.util.Locale; - -/** - * 构造函数的拦截器示例,本示例将展示如何对构造函数进行增强 - * - * @author HapThorin - * @version 1.0.0 - * @since 2021-10-25 - */ -public class DemoConstInterceptor extends AbstractInterceptor { - @Override - public ExecuteContext before(ExecuteContext context) throws Exception { - DemoLogger.println(String.format(Locale.ROOT, "[DemoConstInterceptor]before, class: %s.", - context.getRawCls().getName())); - return context; - } - - @Override - public ExecuteContext after(ExecuteContext context) throws Exception { - DemoLogger.println(String.format(Locale.ROOT, "[DemoConstInterceptor]after, class: %s.", - context.getRawCls().getName())); - return context; - } -} diff --git a/sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/interceptor/DemoFieldSetInterceptor.java b/sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/interceptor/DemoFieldSetInterceptor.java deleted file mode 100644 index ca75b16..0000000 --- a/sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/interceptor/DemoFieldSetInterceptor.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (C) 2021-2022 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.huawei.example.demo.interceptor; - -import com.huawei.example.demo.common.DemoLogger; - -import com.huaweicloud.sermant.core.plugin.agent.entity.ExecuteContext; -import com.huaweicloud.sermant.core.plugin.agent.interceptor.AbstractInterceptor; - -/** - * 用于测试局部变量、成员变量和全局变量的写入和读取 - * - * @author HapThorin - * @version 1.0.0 - * @since 2022-01-22 - */ -public class DemoFieldSetInterceptor extends AbstractInterceptor { - private static final String LOCALFIELDNAME = "testLocal"; - private static final String MEMEBERFIELDNAME = "testMember"; - private static final String STATICFIELDNAME = "testStatic"; - - @Override - public ExecuteContext before(ExecuteContext context) throws Exception { - final Object localField = context.getLocalFieldValue(LOCALFIELDNAME); - final int newLocalField = localField == null ? 1 : Integer.parseInt(localField.toString()) + 1; - context.setLocalFieldValue(LOCALFIELDNAME, newLocalField); - final Object memberField = context.getMemberFieldValue(MEMEBERFIELDNAME); - final int newMemberField = memberField == null ? 1 : Integer.parseInt(memberField.toString()) + 1; - context.setMemberFieldValue(MEMEBERFIELDNAME, newMemberField); - final Object staticField = context.getStaticFieldValue(STATICFIELDNAME); - final int newStaticField = staticField == null ? 1 : Integer.parseInt(staticField.toString()) + 1; - context.setStaticFieldValue(STATICFIELDNAME, newStaticField); - return context; - } - - @Override - public ExecuteContext after(ExecuteContext context) throws Exception { - DemoLogger.println("[DemoFieldSetInterceptor]-testLocal: " + context.getLocalFieldValue(LOCALFIELDNAME)); - DemoLogger.println("[DemoFieldSetInterceptor]-testMember: " + context.getMemberFieldValue(MEMEBERFIELDNAME)); - DemoLogger.println("[DemoFieldSetInterceptor]-testStatic: " + context.getStaticFieldValue(STATICFIELDNAME)); - return context; - } -} diff --git a/sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/interceptor/DemoInterfaceInterceptor.java b/sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/interceptor/DemoInterfaceInterceptor.java deleted file mode 100644 index 610825f..0000000 --- a/sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/interceptor/DemoInterfaceInterceptor.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (C) 2021-2022 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.huawei.example.demo.interceptor; - -import com.huawei.example.demo.common.DemoBeanPropertyApi; -import com.huawei.example.demo.common.DemoInterfaceApi; -import com.huawei.example.demo.common.DemoLogger; - -import com.huaweicloud.sermant.core.plugin.agent.entity.ExecuteContext; -import com.huaweicloud.sermant.core.plugin.agent.interceptor.AbstractInterceptor; - -/** - * 用于测试对被增强类的接口实现 - * - * @author HapThorin - * @version 1.0.0 - * @since 2022-01-22 - */ -public class DemoInterfaceInterceptor extends AbstractInterceptor { - @Override - public ExecuteContext before(ExecuteContext context) throws Exception { - final Object object = context.getObject(); - if (object instanceof DemoInterfaceApi) { - ((DemoInterfaceApi) object).foo(); - } - if (object instanceof DemoBeanPropertyApi) { - final DemoBeanPropertyApi demoBeanPropertyApi = (DemoBeanPropertyApi) object; - demoBeanPropertyApi.setFoo("foo field string"); - demoBeanPropertyApi.setBar(1); - } - return context; - } - - @Override - public ExecuteContext after(ExecuteContext context) throws Exception { - final Object object = context.getObject(); - if (object instanceof DemoBeanPropertyApi) { - final DemoBeanPropertyApi demoBeanPropertyApi = (DemoBeanPropertyApi) object; - DemoLogger.println("[DemoInterfaceInterceptor]-foo: " + demoBeanPropertyApi.getFoo()); - DemoLogger.println("[DemoInterfaceInterceptor]-bar: " + demoBeanPropertyApi.getBar()); - } - return context; - } -} diff --git a/sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/interceptor/DemoMemberInterceptor.java b/sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/interceptor/DemoMemberInterceptor.java deleted file mode 100644 index bbf8c3b..0000000 --- a/sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/interceptor/DemoMemberInterceptor.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (C) 2021-2021 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.huawei.example.demo.interceptor; - -import com.huawei.example.demo.common.DemoLogger; - -import com.huaweicloud.sermant.core.plugin.agent.entity.ExecuteContext; -import com.huaweicloud.sermant.core.plugin.agent.interceptor.AbstractInterceptor; - -import java.util.Locale; - -/** - * 实例方法的拦截器示例,本示例将展示如何对实例方法进行增强 - * - * @author HapThorin - * @version 1.0.0 - * @since 2021-10-25 - */ -public class DemoMemberInterceptor extends AbstractInterceptor { - @Override - public ExecuteContext before(ExecuteContext context) throws Exception { - DemoLogger.println(String.format(Locale.ROOT, "[DemoMemberInterceptor]before, class: %s, method: %s.", - context.getRawCls().getName(), context.getMethod().getName())); - return context; - } - - @Override - public ExecuteContext after(ExecuteContext context) throws Exception { - DemoLogger.println(String.format(Locale.ROOT, "[DemoMemberInterceptor]after, class: %s, method: %s.", - context.getRawCls().getName(), context.getMethod().getName())); - return context; - } -} diff --git a/sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/interceptor/DemoServiceInterceptor.java b/sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/interceptor/DemoServiceInterceptor.java deleted file mode 100644 index fc825ee..0000000 --- a/sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/interceptor/DemoServiceInterceptor.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (C) 2021-2021 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.huawei.example.demo.interceptor; - -import com.huawei.example.demo.common.DemoLogger; -import com.huawei.example.demo.service.DemoComplexService; -import com.huawei.example.demo.service.DemoSimpleService; - -import com.huaweicloud.sermant.core.plugin.agent.entity.ExecuteContext; -import com.huaweicloud.sermant.core.plugin.agent.interceptor.AbstractInterceptor; -import com.huaweicloud.sermant.core.plugin.service.PluginServiceManager; - -/** - * 插件服务的拦截器示例,在本示例中,将展示如何在拦截器中使用插件服务 - * - * @author HapThorin - * @version 1.0.0 - * @since 2021-10-25 - */ -public class DemoServiceInterceptor extends AbstractInterceptor { - private DemoSimpleService simpleService; - private DemoComplexService complexService; - - @Override - public ExecuteContext before(ExecuteContext context) throws Exception { - DemoLogger.println(context.getRawCls().getSimpleName() + ": [DemoServiceInterceptor]-before"); - simpleService = PluginServiceManager.getPluginService(DemoSimpleService.class); - complexService = PluginServiceManager.getPluginService(DemoComplexService.class); - return context; - } - - @Override - public ExecuteContext after(ExecuteContext context) throws Exception { - DemoLogger.println(context.getRawCls().getSimpleName() + ": [DemoServiceInterceptor]-after"); - simpleService.activeFunc(); - complexService.activeFunc(); - return context; - } -} diff --git a/sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/interceptor/DemoStaticInterceptor.java b/sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/interceptor/DemoStaticInterceptor.java deleted file mode 100644 index 8201a16..0000000 --- a/sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/interceptor/DemoStaticInterceptor.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (C) 2021-2021 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.huawei.example.demo.interceptor; - -import com.huawei.example.demo.common.DemoLogger; - -import com.huaweicloud.sermant.core.plugin.agent.entity.ExecuteContext; -import com.huaweicloud.sermant.core.plugin.agent.interceptor.AbstractInterceptor; - -import java.util.Locale; - -/** - * 静态函数的拦截器示例,本示例将展示如何对静态函数进行增强 - * - * @author HapThorin - * @version 1.0.0 - * @since 2021-10-25 - */ -public class DemoStaticInterceptor extends AbstractInterceptor { - @Override - public ExecuteContext before(ExecuteContext context) throws Exception { - DemoLogger.println(String.format(Locale.ROOT, "[DemoStaticInterceptor]before, class: %s, method: %s.", - context.getRawCls().getName(), context.getMethod().getName())); - return context; - } - - @Override - public ExecuteContext after(ExecuteContext context) throws Exception { - DemoLogger.println(String.format(Locale.ROOT, "[DemoStaticInterceptor]after, class: %s, method: %s.", - context.getRawCls().getName(), context.getMethod().getName())); - return context; - } -} diff --git a/sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/interceptor/DemoTraceConsumerInterceptor.java b/sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/interceptor/DemoTraceConsumerInterceptor.java deleted file mode 100644 index e64ea04..0000000 --- a/sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/interceptor/DemoTraceConsumerInterceptor.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright (C) 2022-2022 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.huawei.example.demo.interceptor; - -import com.huawei.example.demo.common.DemoLogger; - -import com.huaweicloud.sermant.core.plugin.agent.entity.ExecuteContext; -import com.huaweicloud.sermant.core.plugin.agent.interceptor.AbstractInterceptor; -import com.huaweicloud.sermant.core.service.ServiceManager; -import com.huaweicloud.sermant.core.service.tracing.api.InjectService; -import com.huaweicloud.sermant.core.service.tracing.api.TracingService; -import com.huaweicloud.sermant.core.service.tracing.common.SpanEvent; -import com.huaweicloud.sermant.core.service.tracing.common.SpanEventContext; -import com.huaweicloud.sermant.core.service.tracing.common.TracingHeader; -import com.huaweicloud.sermant.core.service.tracing.common.TracingRequest; - -import java.util.HashMap; -import java.util.Locale; -import java.util.Optional; - -/** - * 链路监控功能的拦截器示例,本示例将展示如何在插件端使用链路监控功能 - * 该拦截器拦截consumer数据,provider数据见{@link DemoTraceProviderInterceptor} - * - * @author luanwenfei - * @version 1.0.0 - * @since 2022-03-18 - */ -public class DemoTraceConsumerInterceptor extends AbstractInterceptor { - TracingService tracingService = ServiceManager.getService(TracingService.class); - - @Override - public ExecuteContext before(ExecuteContext context) throws Exception { - return context; - } - - @Override - public ExecuteContext after(ExecuteContext context) throws Exception { - TracingRequest request = - new TracingRequest(context.getRawCls().getName(), context.getMethod().getName()); - InjectService> injectService = (spanEvent, carrier) -> { - carrier.put(TracingHeader.TRACE_ID.getValue(), spanEvent.getTraceId()); - carrier.put(TracingHeader.PARENT_SPAN_ID.getValue(), spanEvent.getSpanId()); - carrier.put(TracingHeader.SPAN_ID_PREFIX.getValue(), spanEvent.getNextSpanIdPrefix()); - }; - tracingService.onConsumerSpanStart(request, injectService, (HashMap)context.getResult()); - Optional spanEventContextOptional = tracingService.getContext(); - if (spanEventContextOptional.isPresent()) { - SpanEvent spanEvent = spanEventContextOptional.get().getSpanEvent(); - DemoLogger.println(String.format(Locale.ROOT, "ConsumerSpanEvent TraceId: %s, SpanId: %s.", - spanEvent.getTraceId(), spanEvent.getSpanId())); - } - tracingService.onSpanFinally(); - return context; - } - - @Override - public ExecuteContext onThrow(ExecuteContext context) throws Exception { - tracingService.onSpanError(context.getThrowable()); - return context; - } -} diff --git a/sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/interceptor/DemoTraceNormalInterceptor.java b/sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/interceptor/DemoTraceNormalInterceptor.java deleted file mode 100644 index 6ddad37..0000000 --- a/sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/interceptor/DemoTraceNormalInterceptor.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (C) 2022-2022 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.huawei.example.demo.interceptor; - -import com.huawei.example.demo.common.DemoLogger; - -import com.huaweicloud.sermant.core.plugin.agent.entity.ExecuteContext; -import com.huaweicloud.sermant.core.plugin.agent.interceptor.AbstractInterceptor; -import com.huaweicloud.sermant.core.service.ServiceManager; -import com.huaweicloud.sermant.core.service.tracing.api.TracingService; -import com.huaweicloud.sermant.core.service.tracing.common.SpanEvent; -import com.huaweicloud.sermant.core.service.tracing.common.SpanEventContext; -import com.huaweicloud.sermant.core.service.tracing.common.TracingRequest; - -import java.util.Locale; -import java.util.Optional; - -/** - * 链路监控功能的拦截器实例,本示例将展示如何在插件端使用链路监控功能 - * - * @author luanwenfei - * @since 2022-04-07 - */ -public class DemoTraceNormalInterceptor extends AbstractInterceptor { - TracingService tracingService = ServiceManager.getService(TracingService.class); - - @Override - public ExecuteContext before(ExecuteContext context) throws Exception { - TracingRequest request = new TracingRequest(context.getRawCls().getName(), context.getMethod().getName()); - tracingService.onNormalSpanStart(request); - return context; - } - - @Override - public ExecuteContext after(ExecuteContext context) throws Exception { - Optional spanEventContextOptional = tracingService.getContext(); - if (spanEventContextOptional.isPresent()) { - SpanEvent spanEvent = spanEventContextOptional.get().getSpanEvent(); - DemoLogger.println(String.format(Locale.ROOT, "NormalSpanEvent TraceId: %s, SpanId: %s.", - spanEvent.getTraceId(), spanEvent.getSpanId())); - } - tracingService.onSpanFinally(); - return context; - } -} diff --git a/sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/interceptor/DemoTraceProviderInterceptor.java b/sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/interceptor/DemoTraceProviderInterceptor.java deleted file mode 100644 index 1f8e463..0000000 --- a/sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/interceptor/DemoTraceProviderInterceptor.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright (C) 2022-2022 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.huawei.example.demo.interceptor; - -import com.huawei.example.demo.common.DemoLogger; - -import com.huaweicloud.sermant.core.plugin.agent.entity.ExecuteContext; -import com.huaweicloud.sermant.core.plugin.agent.interceptor.AbstractInterceptor; -import com.huaweicloud.sermant.core.service.ServiceManager; -import com.huaweicloud.sermant.core.service.tracing.api.ExtractService; -import com.huaweicloud.sermant.core.service.tracing.api.TracingService; -import com.huaweicloud.sermant.core.service.tracing.common.SpanEvent; -import com.huaweicloud.sermant.core.service.tracing.common.SpanEventContext; -import com.huaweicloud.sermant.core.service.tracing.common.TracingHeader; -import com.huaweicloud.sermant.core.service.tracing.common.TracingRequest; - -import java.util.HashMap; -import java.util.Locale; -import java.util.Optional; - -/** - * 链路监控功能的拦截器示例,本示例将展示如何在插件端使用链路监控功能 - * 该拦截器拦截provider数据,consumer数据见{@link DemoTraceConsumerInterceptor} - * - * @author luanwenfei - * @version 1.0.0 - * @since 2022-03-18 - */ -public class DemoTraceProviderInterceptor extends AbstractInterceptor { - private final TracingService tracingService = ServiceManager.getService(TracingService.class); - - @Override - public ExecuteContext before(ExecuteContext context) throws Exception { - TracingRequest request = - new TracingRequest(context.getRawCls().getName(), context.getMethod().getName()); - ExtractService> extractService = (tracingRequest, carrier) -> { - tracingRequest.setTraceId(carrier.get(TracingHeader.TRACE_ID.getValue())); - tracingRequest.setParentSpanId(carrier.get(TracingHeader.PARENT_SPAN_ID.getValue())); - tracingRequest.setSpanIdPrefix(carrier.get(TracingHeader.SPAN_ID_PREFIX.getValue())); - }; - tracingService.onProviderSpanStart(request, extractService, (HashMap)context.getArguments()[0]); - return context; - } - - @Override - public ExecuteContext after(ExecuteContext context) throws Exception { - Optional spanEventContextOptional = tracingService.getContext(); - if (spanEventContextOptional.isPresent()) { - SpanEvent spanEvent = spanEventContextOptional.get().getSpanEvent(); - DemoLogger.println(String.format(Locale.ROOT, "ProviderSpanEvent TraceId: %s, SpanId: %s.", - spanEvent.getTraceId(), spanEvent.getSpanId())); - } - tracingService.onSpanFinally(); - return context; - } - - @Override - public ExecuteContext onThrow(ExecuteContext context) throws Exception { - tracingService.onSpanError(context.getThrowable()); - return context; - } -} diff --git a/sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/service/DemoComplexService.java b/sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/service/DemoComplexService.java deleted file mode 100644 index 519b1a5..0000000 --- a/sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/service/DemoComplexService.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (C) 2021-2021 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.huawei.example.demo.service; - -import com.huaweicloud.sermant.core.plugin.service.PluginService; - -/** - * 复杂服务的接口示例 - * - * @author HapThorin - * @version 1.0.0 - * @since 2021-11-16 - */ -public interface DemoComplexService extends PluginService { - /** - * 主动调用的方法,将调用{@link DemoSimpleService#passiveFunc()}方法 - */ - void activeFunc(); - - /** - * 被动调用的方法,将被{@link DemoSimpleService#activeFunc()}方法调用 - */ - void passiveFunc(); -} diff --git a/sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/service/DemoDynaConfService.java b/sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/service/DemoDynaConfService.java deleted file mode 100644 index c17bc34..0000000 --- a/sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/service/DemoDynaConfService.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (C) 2021-2021 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.huawei.example.demo.service; - -import com.huawei.example.demo.common.DemoLogger; - -import com.huaweicloud.sermant.core.plugin.service.PluginService; -import com.huaweicloud.sermant.core.service.ServiceManager; -import com.huaweicloud.sermant.core.service.dynamicconfig.DynamicConfigService; -import com.huaweicloud.sermant.core.service.dynamicconfig.common.DynamicConfigEvent; -import com.huaweicloud.sermant.core.service.dynamicconfig.common.DynamicConfigListener; - -/** - * 动态配置示例 - * - * @author HapThorin - * @version 1.0.0 - * @since 2021-11-26 - */ -public class DemoDynaConfService implements PluginService { - private DynamicConfigService service; - - /** - * 如果是zookeeper实现,修改{@code /sermant/demo/test}的值以观察动态配置效果 - */ - @Override - public void start() { - service = ServiceManager.getService(DynamicConfigService.class); - service.addConfigListener("demo/test", "sermant", new DynamicConfigListener() { - @Override - public void process(DynamicConfigEvent event) { - DemoLogger.println("[DemoDynaConfService]-" + event.toString()); - } - }); - } - - @Override - public void stop() { - service.stop(); - } -} diff --git a/sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/service/DemoHeartBeatService.java b/sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/service/DemoHeartBeatService.java deleted file mode 100644 index 3c0f98f..0000000 --- a/sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/service/DemoHeartBeatService.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (C) 2021-2021 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.huawei.example.demo.service; - -import com.huaweicloud.sermant.core.plugin.service.PluginService; -import com.huaweicloud.sermant.core.service.ServiceManager; -import com.huaweicloud.sermant.core.service.heartbeat.api.ExtInfoProvider; -import com.huaweicloud.sermant.core.service.heartbeat.api.HeartbeatService; - -import java.util.Collections; -import java.util.Map; - -/** - * 本示例中,将展示如何在插件服务中使用心跳功能 - * - * @author HapThorin - * @version 1.0.0 - * @since 2021-10-25 - */ -public class DemoHeartBeatService implements PluginService { - @Override - public void start() { - final HeartbeatService service = ServiceManager.getService(HeartbeatService.class); - service.setExtInfo(new ExtInfoProvider() { - @Override - public Map getExtInfo() { - return Collections.singletonMap("exampleKey", "exampleValue"); - } - }); - } - - @Override - public void stop() { - } -} diff --git a/sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/service/DemoSimpleService.java b/sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/service/DemoSimpleService.java deleted file mode 100644 index d0a4dd6..0000000 --- a/sermant-template/template/template-plugin/src/main/java/com/huawei/example/demo/service/DemoSimpleService.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (C) 2021-2021 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.huawei.example.demo.service; - -import com.huawei.example.demo.common.DemoLogger; - -import com.huaweicloud.sermant.core.plugin.service.PluginService; -import com.huaweicloud.sermant.core.plugin.service.PluginServiceManager; - -/** - * 示例服务,本示例中将展示如何编写一个插件服务 - * - * @author HapThorin - * @version 1.0.0 - * @since 2021-10-25 - */ -public class DemoSimpleService implements PluginService { - @Override - public void start() { - DemoLogger.println("[DemoSimpleService]-start"); - } - - @Override - public void stop() { - DemoLogger.println("[DemoSimpleService]-stop"); - } - - /** - * 主动调用的方法,将调用{@link DemoComplexService#passiveFunc()}方法 - */ - public void activeFunc() { - DemoLogger.println("[DemoSimpleService]-activeFunc"); - final DemoComplexService service = PluginServiceManager.getPluginService(DemoComplexService.class); - service.passiveFunc(); - } - - /** - * 被动调用的方法,将被{@link DemoComplexService#activeFunc()}方法调用 - */ - public void passiveFunc() { - DemoLogger.println("[DemoSimpleService]-passiveFunc"); - } -} diff --git a/sermant-template/template/template-plugin/src/main/resources/META-INF/services/com.huaweicloud.sermant.core.plugin.agent.declarer.PluginDeclarer b/sermant-template/template/template-plugin/src/main/resources/META-INF/services/com.huaweicloud.sermant.core.plugin.agent.declarer.PluginDeclarer deleted file mode 100644 index f0ce197..0000000 --- a/sermant-template/template/template-plugin/src/main/resources/META-INF/services/com.huaweicloud.sermant.core.plugin.agent.declarer.PluginDeclarer +++ /dev/null @@ -1,8 +0,0 @@ -com.huawei.example.demo.declarer.DemoAnnotationDeclarer -com.huawei.example.demo.declarer.DemoNameDeclarer -com.huawei.example.demo.declarer.DemoSuperTypeDeclarer -com.huawei.example.demo.declarer.DemoTraceDeclarer -com.huawei.example.demo.declarer.DemoBootstrapDeclarer -com.huawei.example.demo.declarer.DemoNameInfixDeclarer -com.huawei.example.demo.declarer.DemoNamePrefixDeclarer -com.huawei.example.demo.declarer.DemoNameSuffixDeclarer \ No newline at end of file diff --git a/sermant-template/template/template-plugin/src/main/resources/META-INF/services/com.huaweicloud.sermant.core.plugin.config.PluginConfig b/sermant-template/template/template-plugin/src/main/resources/META-INF/services/com.huaweicloud.sermant.core.plugin.config.PluginConfig deleted file mode 100644 index fe60189..0000000 --- a/sermant-template/template/template-plugin/src/main/resources/META-INF/services/com.huaweicloud.sermant.core.plugin.config.PluginConfig +++ /dev/null @@ -1 +0,0 @@ -com.huawei.example.demo.config.DemoConfig \ No newline at end of file diff --git a/sermant-template/template/template-plugin/src/main/resources/META-INF/services/com.huaweicloud.sermant.core.plugin.service.PluginService b/sermant-template/template/template-plugin/src/main/resources/META-INF/services/com.huaweicloud.sermant.core.plugin.service.PluginService deleted file mode 100644 index 119dfa6..0000000 --- a/sermant-template/template/template-plugin/src/main/resources/META-INF/services/com.huaweicloud.sermant.core.plugin.service.PluginService +++ /dev/null @@ -1,3 +0,0 @@ -com.huawei.example.demo.service.DemoSimpleService -com.huawei.example.demo.service.DemoHeartBeatService -com.huawei.example.demo.service.DemoDynaConfService \ No newline at end of file diff --git a/sermant-template/template/template-service/pom.xml b/sermant-template/template/template-service/pom.xml deleted file mode 100644 index 47923f7..0000000 --- a/sermant-template/template/template-service/pom.xml +++ /dev/null @@ -1,51 +0,0 @@ - - - - com.huaweicloud.sermant.examples - template - 1.0.0 - - 4.0.0 - - template-service - - - com.huaweicloud.sermant - sermant-agentcore-core - 0.7.0 - provided - - - com.huaweicloud.sermant.examples - template-plugin - 1.0.0 - provided - - - org.slf4j - slf4j-api - 1.7.30 - provided - - - - - - ${pom.basedir}/../.. - template - service - 8 - 8 - - - - - - org.apache.maven.plugins - maven-shade-plugin - - - - \ No newline at end of file diff --git a/sermant-template/template/template-service/src/main/java/com/huawei/example/demo/config/DemoServiceConfig.java b/sermant-template/template/template-service/src/main/java/com/huawei/example/demo/config/DemoServiceConfig.java deleted file mode 100644 index 39e97da..0000000 --- a/sermant-template/template/template-service/src/main/java/com/huawei/example/demo/config/DemoServiceConfig.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (C) 2021-2021 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.huawei.example.demo.config; - -import com.huaweicloud.sermant.core.plugin.config.PluginConfig; - -/** - * 插件服务包中定义的插件配置示例,该示例较{@link com.huawei.example.demo.config.DemoConfig}较为简单 - * - * @author HapThorin - * @version 1.0.0 - * @since 2021-11-16 - */ -public class DemoServiceConfig implements PluginConfig { // 没有设定类别名的情况,将使用类的全限定名 - private String testField; - - public String getTestField() { - return testField; - } - - public void setTestField(String testField) { - this.testField = testField; - } - - @Override - public String toString() { - return "DemoServiceConfig{" + - "testField='" + testField + '\'' + - '}'; - } -} diff --git a/sermant-template/template/template-service/src/main/java/com/huawei/example/demo/service/DemoComplexServiceImpl.java b/sermant-template/template/template-service/src/main/java/com/huawei/example/demo/service/DemoComplexServiceImpl.java deleted file mode 100644 index c24440d..0000000 --- a/sermant-template/template/template-service/src/main/java/com/huawei/example/demo/service/DemoComplexServiceImpl.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (C) 2021-2021 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.huawei.example.demo.service; - -import com.huawei.example.demo.config.DemoConfig; -import com.huawei.example.demo.config.DemoServiceConfig; - -import com.huaweicloud.sermant.core.plugin.config.PluginConfigManager; -import com.huaweicloud.sermant.core.plugin.service.PluginServiceManager; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - - -/** - * 复杂服务示例实现 - * - * @author HapThorin - * @version 1.0.0 - * @since 2021-11-16 - */ -public class DemoComplexServiceImpl implements DemoComplexService { - private static final Logger LOGGER = LoggerFactory.getLogger("slf4j.test"); - - @Override - public void start() { - LOGGER.error("[DemoComplexService]-start"); - } - - @Override - public void stop() { - LOGGER.error("[DemoComplexService]-stop"); - } - - @Override - public void activeFunc() { - LOGGER.error("[DemoComplexService]-activeFunc"); - final DemoSimpleService service = PluginServiceManager.getPluginService(DemoSimpleService.class); - service.passiveFunc(); - } - - @Override - public void passiveFunc() { - LOGGER.error("[DemoComplexService]-passiveFunc"); - final DemoServiceConfig serviceConfig = PluginConfigManager.getPluginConfig(DemoServiceConfig.class); - LOGGER.error(getClass().getSimpleName() + ": " + serviceConfig); - final DemoConfig demoConfig = PluginConfigManager.getPluginConfig(DemoConfig.class); - LOGGER.error(getClass().getSimpleName() + ": " + demoConfig); - } -} diff --git a/sermant-template/template/template-service/src/main/resources/META-INF/services/com.huaweicloud.sermant.core.plugin.config.PluginConfig b/sermant-template/template/template-service/src/main/resources/META-INF/services/com.huaweicloud.sermant.core.plugin.config.PluginConfig deleted file mode 100644 index 197d5e3..0000000 --- a/sermant-template/template/template-service/src/main/resources/META-INF/services/com.huaweicloud.sermant.core.plugin.config.PluginConfig +++ /dev/null @@ -1 +0,0 @@ -com.huawei.example.demo.config.DemoServiceConfig \ No newline at end of file diff --git a/sermant-template/template/template-service/src/main/resources/META-INF/services/com.huaweicloud.sermant.core.plugin.service.PluginService b/sermant-template/template/template-service/src/main/resources/META-INF/services/com.huaweicloud.sermant.core.plugin.service.PluginService deleted file mode 100644 index 34c2f47..0000000 --- a/sermant-template/template/template-service/src/main/resources/META-INF/services/com.huaweicloud.sermant.core.plugin.service.PluginService +++ /dev/null @@ -1 +0,0 @@ -com.huawei.example.demo.service.DemoComplexServiceImpl \ No newline at end of file