Skip to content

Commit

Permalink
添加HTTP Server service, 支持对外提供HTTP API能力
Browse files Browse the repository at this point in the history
Signed-off-by: zwmagic <[email protected]>
  • Loading branch information
zwmagic committed Feb 4, 2024
1 parent fb7ef3d commit 303be05
Show file tree
Hide file tree
Showing 28 changed files with 1,828 additions and 59 deletions.
108 changes: 55 additions & 53 deletions sermant-agentcore/sermant-agentcore-config/config/config.properties
Original file line number Diff line number Diff line change
@@ -1,98 +1,100 @@
#=============================字节码增强配置==============================
# 字节码增强重转换开关, 开启则可以支持对已加载的类通过重转换进行字节码增强, 默认值为true
#=============================\u5B57\u8282\u7801\u589E\u5F3A\u914D\u7F6E==============================
# \u5B57\u8282\u7801\u589E\u5F3A\u91CD\u8F6C\u6362\u5F00\u5173, \u5F00\u542F\u5219\u53EF\u4EE5\u652F\u6301\u5BF9\u5DF2\u52A0\u8F7D\u7684\u7C7B\u901A\u8FC7\u91CD\u8F6C\u6362\u8FDB\u884C\u5B57\u8282\u7801\u589E\u5F3A, \u9ED8\u8BA4\u503C\u4E3Atrue
agent.config.isReTransformEnable=true
# 字节码增强日志输出开关, 开启则会将字节码增强相关日志输出到日志文件, 默认值为false
# \u5B57\u8282\u7801\u589E\u5F3A\u65E5\u5FD7\u8F93\u51FA\u5F00\u5173, \u5F00\u542F\u5219\u4F1A\u5C06\u5B57\u8282\u7801\u589E\u5F3A\u76F8\u5173\u65E5\u5FD7\u8F93\u51FA\u5230\u65E5\u5FD7\u6587\u4EF6, \u9ED8\u8BA4\u503C\u4E3Afalse
agent.config.isShowEnhanceLog=false
# 被增强类字节码输出开关, 开启则会将增强后的字节码以文件的形式进行输出, 默认值为false
# \u88AB\u589E\u5F3A\u7C7B\u5B57\u8282\u7801\u8F93\u51FA\u5F00\u5173, \u5F00\u542F\u5219\u4F1A\u5C06\u589E\u5F3A\u540E\u7684\u5B57\u8282\u7801\u4EE5\u6587\u4EF6\u7684\u5F62\u5F0F\u8FDB\u884C\u8F93\u51FA, \u9ED8\u8BA4\u503C\u4E3Afalse
agent.config.isOutputEnhancedClasses=false
# 被增强类字节码输出位置配置, 配置后会将增强后的字节码以文件的形式输出到该配置指定目录, 不配置则默认为agent/enhancedClasses
# \u88AB\u589E\u5F3A\u7C7B\u5B57\u8282\u7801\u8F93\u51FA\u4F4D\u7F6E\u914D\u7F6E, \u914D\u7F6E\u540E\u4F1A\u5C06\u589E\u5F3A\u540E\u7684\u5B57\u8282\u7801\u4EE5\u6587\u4EF6\u7684\u5F62\u5F0F\u8F93\u51FA\u5230\u8BE5\u914D\u7F6E\u6307\u5B9A\u76EE\u5F55, \u4E0D\u914D\u7F6E\u5219\u9ED8\u8BA4\u4E3Aagent/enhancedClasses
agent.config.enhancedClassesOutputPath=
# 拦截器执行时使用线程上下文类加载器辅助加载宿主服务类的开关, 开启则会在拦截器执行中通过线程上下文类加载器辅助加载宿主类, 用于服务治理逻辑使用, 默认值为true
# \u62E6\u622A\u5668\u6267\u884C\u65F6\u4F7F\u7528\u7EBF\u7A0B\u4E0A\u4E0B\u6587\u7C7B\u52A0\u8F7D\u5668\u8F85\u52A9\u52A0\u8F7D\u5BBF\u4E3B\u670D\u52A1\u7C7B\u7684\u5F00\u5173, \u5F00\u542F\u5219\u4F1A\u5728\u62E6\u622A\u5668\u6267\u884C\u4E2D\u901A\u8FC7\u7EBF\u7A0B\u4E0A\u4E0B\u6587\u7C7B\u52A0\u8F7D\u5668\u8F85\u52A9\u52A0\u8F7D\u5BBF\u4E3B\u7C7B, \u7528\u4E8E\u670D\u52A1\u6CBB\u7406\u903B\u8F91\u4F7F\u7528, \u9ED8\u8BA4\u503C\u4E3Atrue
agent.config.useContextLoader=true
# 字节码增强时对类进行查找时需忽略的类的前缀列表, 如果某些类不希望被字节码增强, 则可以通过该配置项进行配置
# \u5B57\u8282\u7801\u589E\u5F3A\u65F6\u5BF9\u7C7B\u8FDB\u884C\u67E5\u627E\u65F6\u9700\u5FFD\u7565\u7684\u7C7B\u7684\u524D\u7F00\u5217\u8868, \u5982\u679C\u67D0\u4E9B\u7C7B\u4E0D\u5E0C\u671B\u88AB\u5B57\u8282\u7801\u589E\u5F3A, \u5219\u53EF\u4EE5\u901A\u8FC7\u8BE5\u914D\u7F6E\u9879\u8FDB\u884C\u914D\u7F6E
agent.config.ignoredPrefixes=com.huawei.sermant,com.huaweicloud.sermant
# 字节码增强时对类进行查找时需要忽略的接口的列表, 如果某些接口的全部实现类都不希望被字节码增强, 则可以通过该配置项进行配置
# \u5B57\u8282\u7801\u589E\u5F3A\u65F6\u5BF9\u7C7B\u8FDB\u884C\u67E5\u627E\u65F6\u9700\u8981\u5FFD\u7565\u7684\u63A5\u53E3\u7684\u5217\u8868, \u5982\u679C\u67D0\u4E9B\u63A5\u53E3\u7684\u5168\u90E8\u5B9E\u73B0\u7C7B\u90FD\u4E0D\u5E0C\u671B\u88AB\u5B57\u8282\u7801\u589E\u5F3A, \u5219\u53EF\u4EE5\u901A\u8FC7\u8BE5\u914D\u7F6E\u9879\u8FDB\u884C\u914D\u7F6E
agent.config.ignoredInterfaces=org.springframework.cglib.proxy.Factory
# 指定插件服务中允许被字节码增强的类(插件服务中的类默认不允许被字节码增强)
# \u6307\u5B9A\u63D2\u4EF6\u670D\u52A1\u4E2D\u5141\u8BB8\u88AB\u5B57\u8282\u7801\u589E\u5F3A\u7684\u7C7B\uFF08\u63D2\u4EF6\u670D\u52A1\u4E2D\u7684\u7C7B\u9ED8\u8BA4\u4E0D\u5141\u8BB8\u88AB\u5B57\u8282\u7801\u589E\u5F3A\uFF09
agent.config.serviceInjectList=com.huawei.discovery.service.lb.filter.NopInstanceFilter,com.huawei.discovery.service.lb.DiscoveryManager,com.huawei.discovery.service.util.ApplyUtil,com.huawei.discovery.service.lb.cache.InstanceCacheManager
#============================= 核心服务配置 =============================#
# 心跳服务开关
#============================= \u6838\u5FC3\u670D\u52A1\u914D\u7F6E =============================#
# \u5FC3\u8DF3\u670D\u52A1\u5F00\u5173
agent.service.heartbeat.enable=false
# 统一网关服务开关
# \u7EDF\u4E00\u7F51\u5173\u670D\u52A1\u5F00\u5173
agent.service.gateway.enable=false
# 链路标记服务开关
# \u94FE\u8DEF\u6807\u8BB0\u670D\u52A1\u5F00\u5173
agent.service.tracing.enable=false
# Spring注入服务开关
# Spring\u6CE8\u5165\u670D\u52A1\u5F00\u5173
agent.service.inject.enable=true
# 动态配置服务开关
# \u52A8\u6001\u914D\u7F6E\u670D\u52A1\u5F00\u5173
agent.service.dynamic.config.enable=true
#============================= 事件系统配置 =============================#
# 事件系统开关
# HTTP Server\u670D\u52A1\u5F00\u5173
agent.service.httpserver.enable=false
#============================= \u4E8B\u4EF6\u7CFB\u7EDF\u914D\u7F6E =============================#
# \u4E8B\u4EF6\u7CFB\u7EDF\u5F00\u5173
event.enable=false
# Warn级别日志事件上报开关
# Warn\u7EA7\u522B\u65E5\u5FD7\u4E8B\u4EF6\u4E0A\u62A5\u5F00\u5173
event.offerWarnLog=false
# Error级别日志事件上报开关
# Error\u7EA7\u522B\u65E5\u5FD7\u4E8B\u4EF6\u4E0A\u62A5\u5F00\u5173
event.offerErrorLog=false
# 事件发送间隔时间, 指定事件向Sermant Backend发送的间隔时间(ms)
# \u4E8B\u4EF6\u53D1\u9001\u95F4\u9694\u65F6\u95F4, \u6307\u5B9A\u4E8B\u4EF6\u5411Sermant Backend\u53D1\u9001\u7684\u95F4\u9694\u65F6\u95F4\uFF08ms\uFF09
event.sendInterval=30000
# 指定相同事件记录时间间隔, 在一定时间内重复事件压缩(ms)
# \u6307\u5B9A\u76F8\u540C\u4E8B\u4EF6\u8BB0\u5F55\u65F6\u95F4\u95F4\u9694, \u5728\u4E00\u5B9A\u65F6\u95F4\u5185\u91CD\u590D\u4E8B\u4EF6\u538B\u7F29\uFF08ms\uFF09
event.offerInterval=300000
# 内部事件通知开关
# \u5185\u90E8\u4E8B\u4EF6\u901A\u77E5\u5F00\u5173
notification.enable=false
#=============================动态配置服务配置=============================#
# 指定配置读取超时时间(ms)
#=============================\u52A8\u6001\u914D\u7F6E\u670D\u52A1\u914D\u7F6E=============================#
# \u6307\u5B9A\u914D\u7F6E\u8BFB\u53D6\u8D85\u65F6\u65F6\u95F4\uFF08ms\uFF09
dynamic.config.timeoutValue=30000
# 指定配置的默认组
# \u6307\u5B9A\u914D\u7F6E\u7684\u9ED8\u8BA4\u7EC4
dynamic.config.defaultGroup=sermant
# 指定配置中心的服务端地址
# \u6307\u5B9A\u914D\u7F6E\u4E2D\u5FC3\u7684\u670D\u52A1\u7AEF\u5730\u5740
dynamic.config.serverAddress=127.0.0.1:2181
# 指定动态配置中心类型, 取值范围为NOP(无实现)、ZOOKEEPER、KIE、NACOS
# \u6307\u5B9A\u52A8\u6001\u914D\u7F6E\u4E2D\u5FC3\u7C7B\u578B, \u53D6\u503C\u8303\u56F4\u4E3ANOP(\u65E0\u5B9E\u73B0)\u3001ZOOKEEPER\u3001KIE\u3001NACOS
dynamic.config.dynamicConfigType=ZOOKEEPER
# 指定在启动Sermant时的配置中心的重连次数
# \u6307\u5B9A\u5728\u542F\u52A8Sermant\u65F6\u7684\u914D\u7F6E\u4E2D\u5FC3\u7684\u91CD\u8FDE\u6B21\u6570
dynamic.config.connectRetryTimes=5
# 指定在启动Sermant时连接配置中心的超时时间(ms)
# \u6307\u5B9A\u5728\u542F\u52A8Sermant\u65F6\u8FDE\u63A5\u914D\u7F6E\u4E2D\u5FC3\u7684\u8D85\u65F6\u65F6\u95F4\uFF08ms\uFF09
dynamic.config.connectTimeout=1000
# 指定是否开启配置中心授权, 开启后需验证用户名密码
# \u6307\u5B9A\u662F\u5426\u5F00\u542F\u914D\u7F6E\u4E2D\u5FC3\u6388\u6743, \u5F00\u542F\u540E\u9700\u9A8C\u8BC1\u7528\u6237\u540D\u5BC6\u7801
dynamic.config.enableAuth=false
# 指定连接动态配置中心时的用户名
# \u6307\u5B9A\u8FDE\u63A5\u52A8\u6001\u914D\u7F6E\u4E2D\u5FC3\u65F6\u7684\u7528\u6237\u540D
dynamic.config.userName=
# 指定连接动态配置中心时的密码
# \u6307\u5B9A\u8FDE\u63A5\u52A8\u6001\u914D\u7F6E\u4E2D\u5FC3\u65F6\u7684\u5BC6\u7801
dynamic.config.password=
# 指定为用户名和密码进行加解密的密钥
# \u6307\u5B9A\u4E3A\u7528\u6237\u540D\u548C\u5BC6\u7801\u8FDB\u884C\u52A0\u89E3\u5BC6\u7684\u5BC6\u94A5
dynamic.config.privateKey=
# 指定获取配置的请求超时时间(ms)
# \u6307\u5B9A\u83B7\u53D6\u914D\u7F6E\u7684\u8BF7\u6C42\u8D85\u65F6\u65F6\u95F4\uFF08ms\uFF09
dynamic.config.requestTimeout=3000
#=============================心跳服务配置===============================#
# 指定心跳时间间隔(ms)
#=============================\u5FC3\u8DF3\u670D\u52A1\u914D\u7F6E===============================#
# \u6307\u5B9A\u5FC3\u8DF3\u65F6\u95F4\u95F4\u9694\uFF08ms\uFF09
heartbeat.interval=30000
#=============================Spring注入服务配置=========================#
# Spring注入服务所需依赖的包
#=============================Spring\u6CE8\u5165\u670D\u52A1\u914D\u7F6E=========================#
# Spring\u6CE8\u5165\u670D\u52A1\u6240\u9700\u4F9D\u8D56\u7684\u5305
inject.essentialPackage=com.huawei.sermant,com.huaweicloud.sermant,com.huawei.dynamic.config,com.huawei.flowcontrol,com.huaweicloud.loadbalancer,com.huawei.monitor,com.huawei.dubbo.registry,com.huawei.registry,com.huaweicloud.visibility,com.huawei.discovery
#=============================统一网关配置===============================#
# 指定统一网关对接的Netty服务端IP
#=============================\u7EDF\u4E00\u7F51\u5173\u914D\u7F6E===============================#
# \u6307\u5B9A\u7EDF\u4E00\u7F51\u5173\u5BF9\u63A5\u7684Netty\u670D\u52A1\u7AEFIP
gateway.nettyIp=127.0.0.1
# 指定统一网关对接的Netty服务端端口
# \u6307\u5B9A\u7EDF\u4E00\u7F51\u5173\u5BF9\u63A5\u7684Netty\u670D\u52A1\u7AEF\u7AEF\u53E3
gateway.nettyPort=6888
# 指定统一网关对接的Netty服务端连接超时时间(ms)
# \u6307\u5B9A\u7EDF\u4E00\u7F51\u5173\u5BF9\u63A5\u7684Netty\u670D\u52A1\u7AEF\u8FDE\u63A5\u8D85\u65F6\u65F6\u95F4\uFF08ms\uFF09
gateway.nettyConnectTimeout=5000
# 指定统一网关对接的Netty客户端读写等待时间(ms)
# \u6307\u5B9A\u7EDF\u4E00\u7F51\u5173\u5BF9\u63A5\u7684Netty\u5BA2\u6237\u7AEF\u8BFB\u5199\u7B49\u5F85\u65F6\u95F4\uFF08ms\uFF09
gateway.nettyWriteAndReadWaitTime=60000
# 指定统一网关数据向服务端发送的间隔时间(s)
# \u6307\u5B9A\u7EDF\u4E00\u7F51\u5173\u6570\u636E\u5411\u670D\u52A1\u7AEF\u53D1\u9001\u7684\u95F4\u9694\u65F6\u95F4\uFF08s\uFF09
gateway.sendInternalTime=10
# 指定统一网关重连退避算法初始连接间隔(s)
# \u6307\u5B9A\u7EDF\u4E00\u7F51\u5173\u91CD\u8FDE\u9000\u907F\u7B97\u6CD5\u521D\u59CB\u8FDE\u63A5\u95F4\u9694\uFF08s\uFF09
gateway.initReconnectInternalTime=5
# 指定统一网关重连退避算法最大连接间隔(s)
# \u6307\u5B9A\u7EDF\u4E00\u7F51\u5173\u91CD\u8FDE\u9000\u907F\u7B97\u6CD5\u6700\u5927\u8FDE\u63A5\u95F4\u9694\uFF08s\uFF09
gateway.maxReconnectInternalTime=180
#=============================元数据配置================================#
# 指定服务名
#=============================\u5143\u6570\u636E\u914D\u7F6E================================#
# \u6307\u5B9A\u670D\u52A1\u540D
service.meta.service=default
# 指定应用名称, 用于服务注册等服务治理场景
# \u6307\u5B9A\u5E94\u7528\u540D\u79F0, \u7528\u4E8E\u670D\u52A1\u6CE8\u518C\u7B49\u670D\u52A1\u6CBB\u7406\u573A\u666F
service.meta.application=default
# 指定服务版本, 用于服务注册、标签路由等服务治理场景
# \u6307\u5B9A\u670D\u52A1\u7248\u672C, \u7528\u4E8E\u670D\u52A1\u6CE8\u518C\u3001\u6807\u7B7E\u8DEF\u7531\u7B49\u670D\u52A1\u6CBB\u7406\u573A\u666F
service.meta.version=1.0.0
# 指定服务命名空间, 用于服务注册等服务治理场景
# \u6307\u5B9A\u670D\u52A1\u547D\u540D\u7A7A\u95F4, \u7528\u4E8E\u670D\u52A1\u6CE8\u518C\u7B49\u670D\u52A1\u6CBB\u7406\u573A\u666F
service.meta.project=default
# 指定服务所在环境, 用于服务注册等服务治理场景
# \u6307\u5B9A\u670D\u52A1\u6240\u5728\u73AF\u5883, \u7528\u4E8E\u670D\u52A1\u6CE8\u518C\u7B49\u670D\u52A1\u6CBB\u7406\u573A\u666F
service.meta.environment=
# 指定服务所在az(可用区), 用于服务注册、标签路由等服务治理场景
# \u6307\u5B9A\u670D\u52A1\u6240\u5728az\uFF08\u53EF\u7528\u533A\uFF09, \u7528\u4E8E\u670D\u52A1\u6CE8\u518C\u3001\u6807\u7B7E\u8DEF\u7531\u7B49\u670D\u52A1\u6CBB\u7406\u573A\u666F
service.meta.zone=
7 changes: 7 additions & 0 deletions sermant-agentcore/sermant-agentcore-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,13 @@
<version>${mockito-inline.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.kohsuke.metainf-services</groupId>
<artifactId>metainf-services</artifactId>
<version>1.9</version>
<optional>true</optional>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<extensions>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ public class ServiceConfig implements BaseConfig {
@ConfigFieldKey("dynamic.config.enable")
private boolean dynamicConfigEnable = false;

@ConfigFieldKey("httpserver.enable")
private boolean httpserverEnable = false;

public boolean isHeartBeatEnable() {
return heartBeatEnable;
}
Expand Down Expand Up @@ -83,6 +86,14 @@ public void setDynamicConfigEnable(boolean dynamicConfigEnable) {
this.dynamicConfigEnable = dynamicConfigEnable;
}

public boolean isHttpserverEnable() {
return httpserverEnable;
}

public void setHttpserverEnable(boolean httpserverEnable) {
this.httpserverEnable = httpserverEnable;
}

/**
* 通过服务的类名来检查该类型服务是否开启
*
Expand All @@ -105,6 +116,9 @@ public boolean checkServiceEnable(String serviceName) {
if (ServiceManager.INJECT_SERVICE_IMPL.equals(serviceName)) {
return isInjectEnable();
}
if (ServiceManager.HTTP_SERVER_SERVICE_IMPL.equals(serviceName)) {
return isHttpserverEnable();
}
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,7 @@
import com.huaweicloud.sermant.core.utils.KeyGenerateUtils;
import com.huaweicloud.sermant.core.utils.SpiLoadUtils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.ServiceLoader;
import java.util.Set;
import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;

Expand Down Expand Up @@ -78,6 +73,12 @@ public class ServiceManager {
public static final String TRACING_SERVICE_IMPL =
"com.huaweicloud.sermant.implement.service.tracing.TracingServiceImpl";

/**
* HttpServer服务类名
*/
public static final String HTTP_SERVER_SERVICE_IMPL =
"com.huaweicloud.sermant.implement.service.httpserver.HttpServerServiceImpl";

/**
* 日志
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright (C) 2023-2023 Huawei Technologies Co., Ltd. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR C¬ONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.huaweicloud.sermant.core.service.httpserver;

import com.huaweicloud.sermant.core.service.BaseService;

/**
* HTTP Server
* @author zwmagic
* @since 2024-01-31
*/
public interface HttpServerService extends BaseService {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright (C) 2023-2023 Huawei Technologies Co., Ltd. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR C¬ONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.huaweicloud.sermant.core.service.httpserver.annotation;

import com.huaweicloud.sermant.core.service.httpserver.api.HttpMethod;

import java.lang.annotation.*;

/**
* http route映射注解,类似 springmvc @RequestMapping
* @author zwmagic
* @since 2024-02-02
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE})
@Documented
public @interface HttpRouteMapping {

/**
* 请求方法
*/
HttpMethod method();

/**
* 请求路径
*/
String path();

/**
* 描述信息
*/
String desc() default "";

}

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright (C) 2023-2023 Huawei Technologies Co., Ltd. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR C¬ONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.huaweicloud.sermant.core.service.httpserver.api;

/**
* HTTP 方法
* @author zwmagic
* @since 2024-02-03
*/
public enum HttpMethod {

ALL, GET, POST, PUT, DELETE, PATCH, HEAD, OPTIONS;

}
Loading

0 comments on commit 303be05

Please sign in to comment.