├── Introduction.en.md ├── Introduction.md ├── LICENSE.TXT ├── README.en.md ├── README.md ├── TseerAgent ├── CMakeLists.txt ├── README.md ├── TseerAgent.conf ├── protocol │ ├── CMakeLists.txt │ ├── Registry.tars │ ├── TseerAgent.tars │ ├── TseerAgentComm.tars │ └── TseerAgentUpdate.tars └── src │ ├── ApiLb.cpp │ ├── ApiLb.h │ ├── ApiLbFactory.cpp │ ├── ApiLbFactory.h │ ├── ApiLb_all.cpp │ ├── ApiLb_all.h │ ├── ApiLb_consistenthash.cpp │ ├── ApiLb_consistenthash.h │ ├── ApiLb_loop.cpp │ ├── ApiLb_loop.h │ ├── ApiLb_random.cpp │ ├── ApiLb_random.h │ ├── ApiLb_static_weight.cpp │ ├── ApiLb_static_weight.h │ ├── ApiRouter.cpp │ ├── ApiRouter.h │ ├── ApiRouterFactory.cpp │ ├── ApiRouterFactory.h │ ├── ApiRouterManager.cpp │ ├── ApiRouterManager.h │ ├── CMakeLists.txt │ ├── CacheManager.cpp │ ├── CacheManager.h │ ├── EndPoint.cpp │ ├── EndPoint.h │ ├── HeartBeatReportThread.cpp │ ├── HeartBeatReportThread.h │ ├── RollLogger.cpp │ ├── RollLogger.h │ ├── RouterImp.cpp │ ├── RouterImp.h │ ├── RouterManager.cpp │ ├── RouterManager.h │ ├── RouterStat.h │ ├── SelfUpdateThread.cpp │ ├── SelfUpdateThread.h │ ├── SyncRouterThread.cpp │ ├── SyncRouterThread.h │ ├── TseerAgentServer.cpp │ ├── TseerAgentServer.h │ ├── UpdateImp.cpp │ ├── UpdateImp.h │ └── util.h ├── TseerServer ├── CMakeLists.txt ├── TseerServer.conf ├── protocol │ ├── CMakeLists.txt │ ├── QueryF.tars │ ├── Registry.tars │ ├── RegistryDescriptor.tars │ ├── RetCode.tars │ ├── RouterData.tars │ └── TseerAgentUpdate.tars ├── src │ ├── ApiRegImp.cpp │ ├── ApiRegImp.h │ ├── BaseHandle.cpp │ ├── BaseHandle.h │ ├── CMakeLists.txt │ ├── EtcdCommon.h │ ├── EtcdDataCache.cpp │ ├── EtcdDataCache.h │ ├── EtcdHandle.cpp │ ├── EtcdHandle.h │ ├── EtcdHost.cpp │ ├── EtcdHost.h │ ├── FileWriterFactory.cpp │ ├── FileWriterFactory.h │ ├── MysqlHandle.cpp │ ├── MysqlHandle.h │ ├── QueryImp.cpp │ ├── QueryImp.h │ ├── ReapThread.cpp │ ├── ReapThread.h │ ├── RegistryImp.cpp │ ├── RegistryImp.h │ ├── RequestEtcdCallback.cpp │ ├── RequestEtcdCallback.h │ ├── StoreCache.cpp │ ├── StoreCache.h │ ├── StoreProxy.cpp │ ├── StoreProxy.h │ ├── TSeerServer.cpp │ ├── TSeerServer.h │ ├── UpdateThread.cpp │ ├── UpdateThread.h │ ├── reg_roll_logger.cpp │ ├── reg_roll_logger.h │ └── util.h ├── test │ ├── CMakeLists.txt │ ├── Global.h │ ├── IDCTest.cpp │ ├── IDCTest.h │ ├── NodeTest.cpp │ ├── NodeTest.h │ ├── QueryTest.cpp │ ├── QueryTest.h │ ├── SeerClientServiceTest.cpp │ ├── SeerClientServiceTest.h │ ├── ServerTest.cpp │ ├── ServerTest.h │ ├── ServiceGroupTest.cpp │ ├── ServiceGroupTest.h │ ├── Test.cpp │ ├── Util.cpp │ └── Util.h └── util │ ├── execute.sh │ ├── start.sh │ └── stop.sh ├── Tseer_Install.en.md ├── Tseer_Install.md ├── api ├── cplus │ ├── CMakeLists.txt │ ├── demo │ │ ├── main_agt_rt.cpp │ │ ├── main_agt_rts.cpp │ │ ├── main_reg_rt.cpp │ │ └── main_reg_rts.cpp │ ├── src │ │ ├── CMakeLists.txt │ │ ├── EndPoint.cpp │ │ ├── EndPoint.h │ │ ├── EndpointF.h │ │ ├── RequestF.h │ │ ├── StatF.h │ │ ├── Tars.h │ │ ├── TarsDisplayer.h │ │ ├── TarsType.h │ │ ├── TseerAgent.h │ │ ├── TseerAgentComm.h │ │ ├── Tseer_api.cpp │ │ ├── Tseer_api.h │ │ ├── Tseer_comm.h │ │ ├── Tseer_inner_comm.h │ │ ├── cache_manager.cpp │ │ ├── cache_manager.h │ │ ├── conn.cpp │ │ ├── conn.h │ │ ├── dns_packer.cpp │ │ ├── dns_packer.h │ │ ├── gc.cpp │ │ ├── gc.h │ │ ├── global.cpp │ │ ├── global.h │ │ ├── lb.cpp │ │ ├── lb.h │ │ ├── lb_all.cpp │ │ ├── lb_all.h │ │ ├── lb_consistenthash.cpp │ │ ├── lb_consistenthash.h │ │ ├── lb_factory.cpp │ │ ├── lb_factory.h │ │ ├── lb_loop.cpp │ │ ├── lb_loop.h │ │ ├── lb_random.cpp │ │ ├── lb_random.h │ │ ├── lb_static_weight.cpp │ │ ├── lb_static_weight.h │ │ ├── registry_ep_manager.cpp │ │ ├── registry_ep_manager.h │ │ ├── route_info_provider.cpp │ │ ├── route_info_provider.h │ │ ├── router.cpp │ │ ├── router.h │ │ ├── router_manager.cpp │ │ ├── router_manager.h │ │ ├── router_stat.h │ │ ├── stat_manager.cpp │ │ ├── stat_manager.h │ │ ├── tc_common.cpp │ │ ├── tc_common.h │ │ ├── tc_config.cpp │ │ ├── tc_config.h │ │ ├── tc_ex.cpp │ │ ├── tc_ex.h │ │ ├── tc_file.cpp │ │ ├── tc_file.h │ │ └── tup.h │ └── test │ │ ├── CMakeLists.txt │ │ └── main.cpp └── java │ ├── demo │ ├── pom.xml │ └── src │ │ └── main │ │ └── java │ │ └── com │ │ └── qq │ │ └── seer │ │ └── demo │ │ └── client │ │ └── ClientDemo.java │ ├── pom.xml │ └── src │ ├── TseerAgent.tars │ ├── TseerAgentComm.tars │ └── main │ └── java │ └── com │ └── qq │ └── cloud │ └── router │ └── client │ ├── CallResponse.java │ ├── LBGetType.java │ ├── LBType.java │ ├── Result.java │ ├── Router.java │ ├── RouterConfig.java │ ├── RouterFactory.java │ ├── RouterRequest.java │ ├── RouterResponse.java │ ├── RoutersRequest.java │ ├── RoutersResponse.java │ ├── ServerNode.java │ ├── faulttolerant │ ├── RouterNodeAliveChecker.java │ ├── RouterNodeAliveConfig.java │ └── RouterNodeAliveStat.java │ ├── impl │ ├── AgentRouterImpl.java │ └── ApiRouterImpl.java │ ├── loadblance │ ├── LoadBlanceContext.java │ ├── LoadBlanceStrategy.java │ └── impl │ │ ├── ConsistentHashing.java │ │ ├── ConsistentHashingContext.java │ │ ├── ConsistentHashingFunction.java │ │ ├── GenericLoadBlanceContext.java │ │ ├── RandomSelectContext.java │ │ ├── RandomSelectStrategy.java │ │ ├── RoundRobinContext.java │ │ ├── RoundRobinStrategy.java │ │ ├── StaticWeightRoundRobin.java │ │ └── StaticWeightRoundRobinContext.java │ ├── share │ └── tseer │ │ ├── AgentRouterRequest.java │ │ ├── AgentRouterResponse.java │ │ ├── LB_GET_TYPE.java │ │ ├── LB_TYPE.java │ │ ├── NodeStat.java │ │ ├── RouterNodeInfo.java │ │ ├── RouterPrx.java │ │ └── RouterPrxCallback.java │ └── util │ ├── ApiStatUtils.java │ ├── AssemblyRouteResponseUtil.java │ ├── CacheFileConfig.java │ ├── CacheFileStringParseUtil.java │ ├── CacheNodeCollection.java │ ├── CommonUtils.java │ ├── ConcurrentDateUtil.java │ ├── Constants.java │ ├── LogUtils.java │ ├── ScheduledExecutorManager.java │ ├── cache │ ├── AbstractCacheNodeManager.java │ ├── AgentCacheNodeManager.java │ ├── AgentCacheNodesManager.java │ ├── ApiCacheNodeManager.java │ ├── CacheFileManager.java │ └── CacheNodeManager.java │ └── stat │ ├── AgentStatManager.java │ ├── ApiProxyStat.java │ ├── DefaultApiStatManager.java │ └── StatManager.java ├── build ├── CMakeLists.txt ├── cmake │ ├── change_conf.sh │ ├── deploy_tars.sh │ ├── generate_utils.sh │ ├── installscript.tgz │ ├── local_install.sh │ ├── make_install.sh │ ├── mon_TseerAgent.sh │ ├── resolve_dependency.sh │ ├── start.sh │ ├── start_agent.sh │ ├── start_server.sh │ ├── start_service.sh │ └── stop.sh ├── etcd │ ├── __init__.py │ ├── check_etcd.sh │ ├── deploy_etcd.py │ └── deploy_etcd.sh ├── mysql │ ├── __init__.py │ ├── db.sql │ ├── deploy_mysql.py │ ├── deploy_mysql_source.sh │ └── deploy_mysql_yum.sh ├── patchagent.sh ├── tseer_deploy.ini ├── tseer_deploy.py ├── utils │ ├── __init__.py │ ├── get_os_info.py │ ├── seer_exceptions.py │ └── vssh.py └── webadmin │ └── __init__.py ├── docs ├── cplus-api-quickstart.md ├── images │ ├── addgroup.png │ ├── addmodule.png │ ├── group.png │ ├── module.png │ ├── pptseer.en.png │ ├── pptseer.png │ ├── seer_feature.en.png │ ├── seer_feature.png │ └── uploadagent.png └── seer-api-java-quickstart.md ├── examples ├── CMakeLists.txt └── TseerServer │ ├── CMakeLists.txt │ ├── Global.h │ ├── IDCTest.cpp │ ├── IDCTest.h │ ├── NodeTest.cpp │ ├── NodeTest.h │ ├── QueryTest.cpp │ ├── QueryTest.h │ ├── SeerClientServiceTest.cpp │ ├── SeerClientServiceTest.h │ ├── ServerTest.cpp │ ├── ServerTest.h │ ├── ServiceGroupTest.cpp │ ├── ServiceGroupTest.h │ ├── Test.cpp │ ├── Util.cpp │ ├── Util.h │ └── protocol │ ├── CMakeLists.txt │ ├── QueryF.tars │ ├── Registry.tars │ ├── RegistryDescriptor.tars │ ├── RetCode.tars │ ├── RouterData.tars │ └── TseerAgentUpdate.tars └── web ├── pom.xml └── src └── main ├── java └── com │ └── qq │ ├── seer │ ├── admin │ │ └── SeerAdmin.java │ ├── agent │ │ ├── AgentPackageMd5Util.java │ │ ├── SeerAgentModule.java │ │ ├── SeerAgentProxy.java │ │ └── UploadAgentPackage.java │ ├── common │ │ ├── codec │ │ │ └── CodecUtils.java │ │ ├── collection │ │ │ └── Pair.java │ │ ├── config │ │ │ └── PropertiesUtils.java │ │ ├── exception │ │ │ └── ThrowableInfo.java │ │ ├── http │ │ │ ├── CachedDnsResolver.java │ │ │ └── HttpUtils.java │ │ ├── lang │ │ │ └── Charsets.java │ │ ├── log │ │ │ └── LogUtils.java │ │ ├── prop │ │ │ └── SystemProperty.java │ │ ├── resource │ │ │ └── ResourceUtils.java │ │ ├── servlet │ │ │ ├── CommonHttpServlet.java │ │ │ ├── CommonServletBean.java │ │ │ ├── CommonServletContext.java │ │ │ ├── DebugableFreeMarkerServlet.java │ │ │ └── ServletUtils.java │ │ └── string │ │ │ └── StringUtils.java │ ├── http │ │ └── SeerInterface.java │ └── servlet │ │ ├── InterfaceServlet.java │ │ └── PageServlet.java │ └── tars │ └── tseer │ ├── PushPackageInfo.java │ ├── RegistryPrx.java │ └── RegistryPrxCallback.java ├── resources ├── j4log.property ├── log4j.properties ├── seer.conf ├── servlet.seer.page.xml └── system.properties └── webapp ├── 404.jsp ├── 500.jsp ├── MVN_CTL ├── copy-dependency-app.bat ├── copy-dependency-web.bat ├── eclipse-with-templib.bat ├── eclipse.bat └── jce2java.bat ├── WEB-INF └── web.xml ├── css └── base.css ├── global-libs ├── cloudJs │ ├── css │ │ ├── black │ │ │ └── cloudjs.css │ │ ├── blue │ │ │ └── cloudjs.css │ │ ├── green │ │ │ └── cloudjs.css │ │ ├── orange │ │ │ └── cloudjs.css │ │ ├── purple │ │ │ └── cloudjs.css │ │ └── red │ │ │ └── cloudjs.css │ ├── images │ │ ├── ajax_loading.gif │ │ ├── icons_new.png │ │ ├── icons_new_old.png │ │ ├── loading_small.gif │ │ ├── paging_loading.gif │ │ └── totop.png │ └── js │ │ ├── Clipboard.swf │ │ ├── calendar.js │ │ ├── cascade.js │ │ ├── clip.js │ │ ├── cloudjs.js │ │ ├── combobox.js │ │ ├── cookie.js │ │ ├── ctab.js │ │ ├── dialog.js │ │ ├── draggable.js │ │ ├── jquery.min.js │ │ ├── loadingGif.js │ │ ├── mask.js │ │ ├── menu.js │ │ ├── message.js │ │ ├── monthpicker.js │ │ ├── paging.js │ │ ├── pinyinspell.js │ │ ├── progressbar.js │ │ ├── resizable.js │ │ ├── slide.js │ │ ├── string.js │ │ ├── swfupload.js │ │ ├── swfupload.queue.js │ │ ├── swfupload.swf │ │ ├── tab.js │ │ ├── table.js │ │ ├── tips.js │ │ ├── totop.js │ │ ├── validate.js │ │ ├── version.js │ │ └── wsdtable.js ├── font-awesome │ ├── css │ │ ├── font-awesome-ie7.css │ │ ├── font-awesome-ie7.min.css │ │ ├── font-awesome.css │ │ └── font-awesome.min.css │ └── font │ │ ├── FontAwesome.otf │ │ ├── fontawesome-webfont.eot │ │ ├── fontawesome-webfont.svg │ │ ├── fontawesome-webfont.ttf │ │ └── fontawesome-webfont.woff ├── js │ ├── jquery.cookie.js │ ├── jquery.min.js │ └── json2.js └── odfl │ ├── comps │ ├── cookie.js │ ├── crossJs.js │ ├── json.js │ └── jsonp.js │ ├── comps_version.js │ ├── odfl.js │ └── style │ └── blue │ └── css │ └── dialog.css ├── images ├── 404.png ├── backspace-20.png ├── loading_big.gif ├── seer_framework.png ├── seer_index_table.png ├── select_down.png └── sprites.png ├── index.jsp ├── js ├── jquery.form.js ├── template.js └── util.js ├── pages ├── ftl │ ├── api │ │ ├── download.ftl │ │ ├── js │ │ │ └── upload.js │ │ └── upload.ftl │ ├── common │ │ └── layout.ftl │ ├── oplog │ │ ├── js │ │ │ └── log_show.js │ │ ├── log_show.ftl │ │ └── log_show_data_table.ftl │ ├── package │ │ ├── grayReleasedPage.ftl │ │ ├── inc │ │ │ └── incGrayReleasedPage.ftl │ │ ├── js │ │ │ ├── grayReleasedPage.js │ │ │ └── manage.js │ │ ├── manage.ftl │ │ └── upload.ftl │ └── router_manager │ │ ├── agentRouterInstall.ftl │ │ ├── css │ │ └── serviceGroupList.css │ │ ├── ipPortList.ftl │ │ ├── js │ │ ├── agentRouterInstall.js │ │ ├── ipPortList.js │ │ └── serviceGroupList.js │ │ └── serviceGroupList.ftl └── iframe │ ├── iframe.jsp │ └── js │ └── upload_back.js └── top.jsp /README.en.md: -------------------------------------------------------------------------------- 1 | ## TSeer 2 | 3 | TSeer is a suite of service registry, service discovery and service fault tolerant solutions that is a lightweight transformation of the Tars's name service.TSeer is widely used in Tencent Browser, YingYongBao, Tencent Manager, QQ ubook, Tencent Literature, GuangDianTong and many other businesses, which with an average daily requests of ten billions. 4 | 5 | In addition to the core features of service discovery, Tseer also supports a variety of excellent load balancing algorithms and provide reliable fault tolerant strategies. To handle the rapid development of massive services, Tseer supports three different routing strategies: nearest access, IDC Grouping , and Set Grouping. Through TSeer, the engineering services can achieve highly intelligent scheduling optimization, effectively solve the cross-regional cross-area room calls and other issues, greatly promoted the availability and performance. 6 | 7 | Users can choose web management interface or API access to use TSeer according to their needs. TSeer provides transparent service discovery through proxy nodes and proxy server mechanisms for services that require frequent changes. TSeer's learning cost is very low and its operation is very convenient. Therefore, it is very friendly to Business operations staff. 8 | 9 | At the same time, TSeer is so lightweight that it has low business intrusiveness. The services, not based on Tars, can also be seamlessly accessed. TSeer is an excellent name service solution in the microservices framework. 10 | 11 | Detailed product description can be found in the [TSeer Product Introduction](Introduction.en.md) 12 | 13 | ## Support Platform 14 | 15 | > * Linux 16 | 17 | ## Support Language 18 | 19 | > * JAVA 20 | > * C++ 21 | > * More versions in continuous development 22 | 23 | ## Installation Guidelines 24 | 25 | Tseer provide a one-click deployment script that is quick and easy to install. See the [TSeer installation documentation](Tseer_Install.en.md) 26 | 27 | ## api 28 | 29 | [c++ api](docs/cplus-api-quickstart.md) 30 | 31 | [java api](docs/seer-api-java-quickstart.md) -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [Click me switch to English version](README.en.md) 2 | 3 | ## TSeer 4 | 5 | TSeer是一套服务注册发现容错的解决方案,是对Tars名字服务功能的轻量化。在腾讯浏览器、应用宝、管家、手机书城、腾讯文学、广点通等众多业务中广泛采用,目前日均承载百亿级别的请求量。 6 | 7 | 在服务发现的核心功能之上,TSeer还支持多种优秀的负载均衡算法,提供可靠的故障容错策略。针对发展迅速的海量服务,还支持就近接入,按SET逻辑分组,全量调度三种不同的路由策略。实现了高度智能的调度优化,有效解决了业务跨地区跨机房调用等难题,极大提升服务的可用性和调用质量。 8 | 9 | TSeer拥有web管理界面和API接入两种方式可供用户根据需求自由选择,通过代理节点和代理服务器机制为需要频繁发布变更的业务提供透明的服务发现功能,学习成本很低,操作也很方便,对于业务维护人员十分友好。 10 | 11 | 同时TSeer轻巧灵便,对业务的侵入性低,非Tars服务亦可无缝接入,是微服务框架中优秀的名字服务解决方案。 12 | 13 | 产品详细说明文档参见[TSeer产品介绍](Introduction.md) 14 | 15 | ## 支持平台 16 | 17 | > * Linux 18 | 19 | ## 支持语言 20 | 21 | > * JAVA 22 | > * C++ 23 | > * 更多版本持续开发中... 24 | 25 | ## 安装指引 26 | 27 | TSeer提供了一键部署脚本,安装方便快捷。详见[TSeer安装文档](Tseer_Install.md) 28 | 29 | ## api 30 | 31 | [c++ api](docs/cplus-api-quickstart.md) 32 | 33 | [java api](docs/seer-api-java-quickstart.md) 34 | 35 | -------------------------------------------------------------------------------- /TseerAgent/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(TseerAgent) 2 | 3 | set(CMAKE_CXX_FLAGS "-std=c++11 -g -O2 -Wall -Wno-deprecated") 4 | 5 | add_definitions(-DTARS_VERSION="${TARS_VERSION}" -DOS_VERSION="${OS_VERSION}") 6 | 7 | set(TSEERAGENT_SERVER_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}) 8 | 9 | include_directories(${TSEERAGENT_SERVER_ROOT_DIR}/protocol 10 | ${TARS_DIR_INC} 11 | ${TARS_DIR_INC}/servant) 12 | 13 | link_directories(${TARS_DIR_LIB}) 14 | 15 | set(SERVER_NAME ${PROJECT_NAME}) 16 | 17 | add_subdirectory(protocol) 18 | add_subdirectory(src) 19 | 20 | install (FILES ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}.conf DESTINATION ${PROJECT_BINARY_DIR}/${PROJECT_NAME}/conf) -------------------------------------------------------------------------------- /TseerAgent/README.md: -------------------------------------------------------------------------------- 1 | #TseerAgent编译打包方式 2 | - 下载源码之后,进入build,执行./build.sh all 3 | - 然后再执行./patchagent.sh ,就会在当前目录生成带有操作系统版本号和md5值的压缩文件 -------------------------------------------------------------------------------- /TseerAgent/TseerAgent.conf: -------------------------------------------------------------------------------- 1 | 2 | #服务安装路径,默认是/usr/local,必填 3 | installpath=/usr/local 4 | #路由服务中心地址,必填 5 | locator=Tseer.TseerServer.QueryObj@tcp -h 127.0.0.1 -p 9903 6 | #方便云端路由中心管理的地址,必须是非127.0.0.1 7 | localip=127.0.0.1 8 | #提供给api查询的地址,默认是127.0.0.1 9 | #routerip=127.0.0.1 10 | 11 | -------------------------------------------------------------------------------- /TseerAgent/protocol/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(OUT_DEPENDS_LIST) 2 | 3 | complice_tars(OUT_DEPENDS_LIST "") 4 | 5 | add_custom_target(AGENT_TARS_HEADER ALL DEPENDS ${OUT_DEPENDS_LIST}) -------------------------------------------------------------------------------- /TseerAgent/protocol/TseerAgent.tars: -------------------------------------------------------------------------------- 1 | /************************************************************ 2 | * 文件定义了TseerAgent对api提供的接口 3 | ************************************************************/ 4 | 5 | #include "TseerAgentComm.tars" 6 | 7 | module Tseer 8 | { 9 | interface Router 10 | { 11 | /** 12 | * 获取某服务的SET、IDC、ALL节点;成功返回0,失败返回-1 13 | */ 14 | 15 | int getRouterNode(AgentRouterRequest req, out AgentRouterResponse rsp); 16 | 17 | /** 18 | * 模调数据上报;成功返回0,失败返回-1 19 | */ 20 | int reportStat(NodeStat stat); 21 | }; 22 | 23 | }; 24 | 25 | -------------------------------------------------------------------------------- /TseerAgent/protocol/TseerAgentComm.tars: -------------------------------------------------------------------------------- 1 | /************************************************************* 2 | * 文件定义了api向 TseerAgent通信需的数据类型 3 | *************************************************************/ 4 | 5 | module Tseer 6 | { 7 | //获取方式 8 | enum LB_GET_TYPE 9 | { 10 | GET_IDC, //按IDC 11 | GET_SET, //按set 12 | GET_ALL, //全部获取 13 | }; 14 | 15 | enum LB_TYPE 16 | { 17 | LB_TYPE_LOOP, 18 | LB_TYPE_RANDOM, 19 | LB_TYPE_STATIC_WEIGHT, 20 | LB_TYPE_CST_HASH, 21 | LB_TYPE_ALL 22 | }; 23 | 24 | //向Agent查询服务节点的数据结构 25 | struct AgentRouterRequest 26 | { 27 | 1 optional LB_GET_TYPE getType; //获取方式,必填 28 | 2 optional LB_TYPE lbType; //负载均衡方式,按照需要填写 29 | 3 optional string obj; //请求服务路由名称,必填 30 | 4 optional string setname; //set信息,当按照SET方式获取时必填 31 | 6 optional string apiVer; //API的版本号的版本号,选填 32 | 7 optional long hashKey; //hash key,选择哈希负载均衡时必填 33 | 8 optional string identifier; //进程号,用于区分客户端,必填 34 | }; 35 | 36 | //服务节点信息 37 | struct RouterNodeInfo 38 | { 39 | 1 optional string ip; //服务ip地址 40 | 2 optional int port; //端口 41 | 3 optional bool isTcp; //是否使用TCP,否则为UDP 42 | 4 optional int weight; //静态权重 43 | 5 optional string setname; //set信息,只当节点开启了set才有 44 | }; 45 | 46 | //从Agent获取服务节点的数据结构 47 | struct AgentRouterResponse 48 | { 49 | 1 optional LB_GET_TYPE getType; //获取方式(已废弃) 50 | 2 optional string obj; //服务路由名称 51 | 3 optional string setname; //set信息 52 | 4 optional vector resultList; //服务节点信息 53 | }; 54 | 55 | //上报调用状态的数据结构 56 | struct NodeStat { 57 | 1 optional string localIp; //本机ip 58 | 2 optional int timeCost; //调用耗时 59 | 3 optional int ret; //调用返回错误码 60 | 4 optional string moduleName; //主调模块名称 61 | 5 optional string ip; //被调服务ip 62 | 6 optional int port; //被调服务port 63 | 7 optional string obj; //被调服务路由名称 64 | 8 optional bool isTcp; //是否使用TCP,false为UDP 65 | 9 optional string setname; //set信息 66 | 10 optional string apiVer; //API的版本号的版本号,选填 67 | 11 optional LB_TYPE lbType; //负载均衡方式 68 | 12 optional LB_GET_TYPE getType; //获取方式 69 | 13 optional string identifier; //进程号,用于区分客户端 70 | }; 71 | }; 72 | -------------------------------------------------------------------------------- /TseerAgent/protocol/TseerAgentUpdate.tars: -------------------------------------------------------------------------------- 1 | module Tseer 2 | { 3 | struct AgentConfig 4 | { 5 | 0 require string locator; /* Tseer.TseerServer.QueryObj@tcp -hx.x.x.x -px -txxxx */ 6 | 1 require string nodeIp; /* node主机的ip */ 7 | }; 8 | 9 | 10 | interface Update 11 | { 12 | /** 13 | * 更新TseerAgent的TseerServer路由服务地址 14 | * @param cfg 更新TSeerAgent配置 15 | * @param [out] result 操作详情 16 | * @return int 0成功 其它失败 17 | */ 18 | int updateConfig(AgentConfig cfg, out string result); 19 | 20 | /** 21 | * 卸载TseerAgent:清理crontab,删除TseerAgent目录结构 22 | * @param [out] result 操作详情 23 | * @return int 0成功 其它失败 24 | */ 25 | int uninstall(out string result); 26 | }; 27 | }; 28 | 29 | -------------------------------------------------------------------------------- /TseerAgent/src/ApiLb.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tseer available. 3 | * 4 | * Copyright (C) 2018 THL A29 Limited, a Tencent company. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | #include "ApiLb.h" 18 | #include 19 | 20 | 21 | int LoadBalance::getRouters(vector &nodeInfoList, string &errMsg) 22 | { 23 | ostringstream os; 24 | os << FILE_FUN << "Unsupported method invocation."; 25 | errMsg = os.str(); 26 | return -1; 27 | } 28 | 29 | int LoadBalance::getRouter(Tseer::RouterNodeInfo& nodeInfo, string &errMsg) 30 | { 31 | ostringstream os; 32 | os << FILE_FUN << "Unsupported method invocation."; 33 | errMsg = os.str(); 34 | return -1; 35 | } 36 | 37 | int LoadBalance::getRouter(unsigned long long key, Tseer::RouterNodeInfo& nodeInfo, string &errMsg) 38 | { 39 | ostringstream os; 40 | os << FILE_FUN << "Unsupported method invocation."; 41 | errMsg = os.str(); 42 | return -1; 43 | } 44 | 45 | -------------------------------------------------------------------------------- /TseerAgent/src/ApiLbFactory.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tseer available. 3 | * 4 | * Copyright (C) 2018 THL A29 Limited, a Tencent company. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include "ApiLbFactory.h" 23 | 24 | #include "ApiLb_loop.h" 25 | #include "ApiLb_random.h" 26 | #include "ApiLb_consistenthash.h" 27 | #include "ApiLb_static_weight.h" 28 | #include "ApiLb_all.h" 29 | 30 | LoadBalance* LoadBalanceFactory::CreateLoadBalance(Tseer::LB_TYPE type) 31 | { 32 | LoadBalance *lb = NULL; 33 | switch(type) 34 | { 35 | case Tseer::LB_TYPE_LOOP: 36 | lb = new(std::nothrow) LBLoop; 37 | break; 38 | case Tseer::LB_TYPE_RANDOM: 39 | lb = new(std::nothrow) LBRandom; 40 | break; 41 | case Tseer::LB_TYPE_CST_HASH: 42 | lb = new(std::nothrow) LBConsistentHash; 43 | break; 44 | case Tseer::LB_TYPE_STATIC_WEIGHT: 45 | lb = new(std::nothrow) LBStaticWeight; 46 | break; 47 | case Tseer::LB_TYPE_ALL: 48 | lb = new(std::nothrow) LBAll; 49 | break; 50 | default: 51 | lb = NULL; 52 | break; 53 | } 54 | 55 | return lb; 56 | } 57 | 58 | -------------------------------------------------------------------------------- /TseerAgent/src/ApiLbFactory.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tseer available. 3 | * 4 | * Copyright (C) 2018 THL A29 Limited, a Tencent company. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | #ifndef __API_LB_FACTORY_H_ 18 | #define __API_LB_FACTORY_H_ 19 | 20 | #include "ApiLb.h" 21 | 22 | 23 | class LoadBalanceFactory 24 | { 25 | public: 26 | static LoadBalance* CreateLoadBalance(Tseer::LB_TYPE lb_type); 27 | }; 28 | 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /TseerAgent/src/ApiLb_all.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tseer available. 3 | * 4 | * Copyright (C) 2018 THL A29 Limited, a Tencent company. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | #ifndef __API_LB_ALL_H_ 18 | #define __API_LB_ALL_H_ 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include "ApiLb.h" 25 | #include "TseerAgentComm.h" 26 | 27 | 28 | class LBAll : public LoadBalance 29 | { 30 | public: 31 | LBAll(); 32 | 33 | ~LBAll(); 34 | 35 | virtual int addRouter(const Tseer::RouterNodeInfo& nodeInfo); 36 | 37 | virtual int getRouters(vector &nodeInfoList, string &errMsg); 38 | 39 | virtual void clear(); 40 | 41 | virtual int rebuild(); 42 | 43 | virtual int statResult(const Tseer::RouterNodeInfo& req, int ret, int timeCost); 44 | 45 | virtual int del(const vector &nodeInfoVec); 46 | 47 | private: 48 | std::vector _normalNodeInfo; 49 | 50 | std::map _normal; 51 | }; 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /TseerAgent/src/ApiLb_consistenthash.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tseer available. 3 | * 4 | * Copyright (C) 2018 THL A29 Limited, a Tencent company. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | #ifndef __API_LB_CONSISENT_HASH_ 18 | #define __API_LB_CONSISENT_HASH_ 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include "ApiLb.h" 25 | 26 | 27 | 28 | using namespace std; 29 | 30 | class LBConsistentHash : public LoadBalance 31 | { 32 | public: 33 | LBConsistentHash(); 34 | 35 | ~LBConsistentHash(); 36 | 37 | virtual int addRouter(const Tseer::RouterNodeInfo& nodeInfo); 38 | 39 | virtual int getRouter(Tseer::RouterNodeInfo& nodeInfo, string &errMsg); 40 | 41 | virtual int getRouter(unsigned long long key, Tseer::RouterNodeInfo& nodeInfo, string &errMsg); 42 | 43 | virtual void clear(); 44 | 45 | virtual int rebuild(); 46 | 47 | virtual int statResult(const Tseer::RouterNodeInfo& req, int ret, int timeCost); 48 | 49 | virtual int del(const vector &nodeInfoVec); 50 | 51 | private: 52 | 53 | bool checkActive(const Tseer::RouterNodeInfo& nodeInfo); 54 | 55 | unsigned int murmurHash32(const char *key, unsigned int len, unsigned int seed); 56 | 57 | 58 | std::map _statMap; 59 | 60 | std::map _normalMap; 61 | 62 | std::map _tableMap; 63 | }; 64 | 65 | #endif 66 | -------------------------------------------------------------------------------- /TseerAgent/src/ApiLb_loop.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tseer available. 3 | * 4 | * Copyright (C) 2018 THL A29 Limited, a Tencent company. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | #ifndef __API_LB_LOOP_H_ 18 | #define __API_LB_LOOP_H_ 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include "ApiLb.h" 25 | 26 | class LBLoop : public LoadBalance 27 | { 28 | public: 29 | LBLoop(); 30 | 31 | ~LBLoop(); 32 | 33 | virtual int addRouter(const Tseer::RouterNodeInfo& nodeInfo); 34 | 35 | virtual int getRouter(Tseer::RouterNodeInfo& nodeInfo, string &errMsg); 36 | 37 | virtual void clear(); 38 | 39 | virtual int rebuild(); 40 | 41 | virtual int statResult(const Tseer::RouterNodeInfo& req, int ret, int timeCost); 42 | 43 | virtual int del(const vector &nodeInfoMap); 44 | 45 | private: 46 | bool checkActive(const Tseer::RouterNodeInfo& nodeInfo); 47 | 48 | size_t _lastIndex; 49 | 50 | std::vector _normalNodeInfoVec; 51 | 52 | std::map _normalMap; 53 | 54 | std::map _statMap; 55 | }; 56 | 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /TseerAgent/src/ApiLb_random.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tseer available. 3 | * 4 | * Copyright (C) 2018 THL A29 Limited, a Tencent company. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | #ifndef __API_LB_RANOMD_H_ 18 | #define __API_LB_RANOMD_H_ 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include "ApiLb.h" 25 | 26 | 27 | using namespace std; 28 | 29 | class LBRandom : public LoadBalance 30 | { 31 | public: 32 | LBRandom(); 33 | 34 | ~LBRandom(); 35 | 36 | virtual int addRouter(const Tseer::RouterNodeInfo& nodeInfo); 37 | 38 | virtual int getRouter(Tseer::RouterNodeInfo& nodeInfo, string &subErr); 39 | 40 | virtual void clear(); 41 | 42 | virtual int rebuild(); 43 | 44 | virtual int statResult(const Tseer::RouterNodeInfo& req, int ret, int timeCost); 45 | 46 | virtual int del(const vector &nodeInfoVec); 47 | 48 | private: 49 | 50 | bool checkActive(const Tseer::RouterNodeInfo& nodeInfo); 51 | 52 | std::vector _normalNodeInfoVec; 53 | 54 | //由IP、Port、TCP/UDP组成的KEY 55 | std::map _normalMap; 56 | 57 | std::map _statMap; 58 | }; 59 | 60 | 61 | #endif 62 | -------------------------------------------------------------------------------- /TseerAgent/src/ApiLb_static_weight.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tseer available. 3 | * 4 | * Copyright (C) 2018 THL A29 Limited, a Tencent company. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | #ifndef __API_LB_STATIC_WEIGHT_H_ 18 | #define __API_LB_STATIC_WEIGHT_H_ 19 | 20 | #include "ApiLb.h" 21 | 22 | class LBStaticWeight : public LoadBalance 23 | { 24 | public: 25 | LBStaticWeight(); 26 | 27 | ~LBStaticWeight(); 28 | 29 | virtual int addRouter(const Tseer::RouterNodeInfo& nodeInfo); 30 | 31 | virtual int getRouter(Tseer::RouterNodeInfo& nodeInfo, string &errMsg); 32 | 33 | virtual void clear(); 34 | 35 | virtual int rebuild(); 36 | 37 | virtual int del(const vector &nodeInfoVec); 38 | 39 | virtual int statResult(const Tseer::RouterNodeInfo& nodeInfo, int ret, int timeCost); 40 | 41 | private: 42 | bool checkActive(const Tseer::RouterNodeInfo& nodeInfo); 43 | 44 | //计算全部节点权重的最大公约数,min为已知最小权重 45 | int gcdWeights(const std::vector nodes, int min); 46 | 47 | //节点列表 48 | std::vector _normalNodeInfoVec; 49 | 50 | //节点列表,KEY由服务的IP、Port、TCP/UDP组成 51 | std::map _normalMap; 52 | 53 | //节点状态,KEY由服务的IP、Port、TCP/UDP组成 54 | std::map _statMap; 55 | 56 | //各节点权重最大公约数 57 | int _gcdWeight; 58 | 59 | //各节点最大权重 60 | int _maxWeight; 61 | 62 | //权重筛选值,权重至少大于此值的机器才会被选中 63 | int _atLeastWeight; 64 | 65 | //上一轮选择的机器下标 66 | int _lastIndex; 67 | }; 68 | 69 | 70 | #endif 71 | -------------------------------------------------------------------------------- /TseerAgent/src/ApiRouterFactory.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tseer available. 3 | * 4 | * Copyright (C) 2018 THL A29 Limited, a Tencent company. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | #include "ApiRouterFactory.h" 18 | #include "RollLogger.h" 19 | 20 | ApiRouterFactory::~ApiRouterFactory() 21 | { 22 | TC_LockT lock(*this); 23 | for (map::iterator it = _apiRouterManager.begin(); it != _apiRouterManager.end(); it++) 24 | { 25 | delete (it->second); 26 | } 27 | } 28 | 29 | ApiRouterManager* ApiRouterFactory::getRouterMr(const Tseer::AgentRouterRequest &req) 30 | { 31 | TC_LockT lock(*this); 32 | string key; 33 | if (!req.identifier.empty()) 34 | { 35 | key = req.identifier; // pid 36 | } 37 | else 38 | { 39 | key = req.obj; 40 | } 41 | 42 | map::const_iterator it = _apiRouterManager.find(key); 43 | if (it != _apiRouterManager.end()) 44 | return it->second; 45 | 46 | ApiRouterManager* pApi = new ApiRouterManager(key); 47 | _apiRouterManager[key] = pApi; 48 | return pApi; 49 | } 50 | 51 | void ApiRouterFactory::timeout() 52 | { 53 | TC_LockT lock(*this); 54 | map::iterator it = _apiRouterManager.begin(); 55 | while(it != _apiRouterManager.end()) 56 | { 57 | if (it->second->timeout()) 58 | { 59 | delete (it->second); 60 | _apiRouterManager.erase(it++); 61 | } 62 | else 63 | { 64 | ++it; 65 | } 66 | } 67 | } 68 | 69 | -------------------------------------------------------------------------------- /TseerAgent/src/ApiRouterFactory.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tseer available. 3 | * 4 | * Copyright (C) 2018 THL A29 Limited, a Tencent company. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | #ifndef __APIROUTER_FACTORY_H_ 18 | #define __APIROUTER_FACTORY_H_ 19 | 20 | #include "util/tc_thread_mutex.h" 21 | #include "util/tc_lock.h" 22 | #include "util/tc_singleton.h" 23 | #include "util/tc_timeprovider.h" 24 | 25 | #include "ApiRouterManager.h" 26 | 27 | 28 | /*********************************************** 29 | * 文件定义了管理每个客户端请求过来的唯一标识ApiRouterManager 30 | ************************************************/ 31 | class ApiRouterFactory : public TC_ThreadRecMutex,public TC_Singleton 32 | { 33 | public: 34 | ApiRouterFactory() {} 35 | ~ApiRouterFactory(); 36 | 37 | ApiRouterManager* getRouterMr(const Tseer::AgentRouterRequest &req); 38 | 39 | void timeout(); 40 | private: 41 | map _apiRouterManager; 42 | }; 43 | 44 | #endif 45 | 46 | -------------------------------------------------------------------------------- /TseerAgent/src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/${PROJECT_NAME}/bin) 2 | 3 | aux_source_directory(. DIR_SRCS) 4 | add_executable(${SERVER_NAME} ${DIR_SRCS}) 5 | 6 | target_link_libraries(${SERVER_NAME} tarsservant tarsparse tarsutil rt 7 | pthread) -------------------------------------------------------------------------------- /TseerAgent/src/EndPoint.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tseer available. 3 | * 4 | * Copyright (C) 2018 THL A29 Limited, a Tencent company. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | #ifndef ENDPOINT_H_ 18 | #define ENDPOINT_H_ 19 | 20 | /** 文件定义了网络端口 21 | * eg. tcp -h 127.0.0.1 -p 2345 -t 10000 -w 100 22 | */ 23 | 24 | #include 25 | #include 26 | #include "TseerAgentComm.h" 27 | 28 | struct EndPoint 29 | { 30 | public: 31 | EndPoint(); 32 | 33 | EndPoint(bool isTcp, const std::string& host, int port, int timeout, 34 | const std::string &set, int weight = -1); 35 | 36 | EndPoint(const EndPoint& l); 37 | 38 | EndPoint& operator = (const EndPoint& l); 39 | 40 | bool operator == (const EndPoint& l); 41 | 42 | /** 用字符串描述来构造;成功返回0,失败返回-1 43 | * 格式:(tcp|udp) -h xx -p xx -t xx [-s xx] [-w xx] 44 | */ 45 | int parse(const std::string& str, std::string &sErr); 46 | 47 | std::string toString() const; 48 | 49 | Tseer::RouterNodeInfo toRouterNodeInfo() const; 50 | 51 | //类型 52 | bool _istcp; 53 | 54 | //ip 55 | std::string _host; 56 | 57 | //端口 58 | int _port; 59 | 60 | //超时时间 61 | int _timeout; 62 | 63 | ///节点的静态权重值 64 | int _weight; 65 | 66 | //节点的set信息 67 | std::string _set; 68 | }; 69 | 70 | #endif 71 | -------------------------------------------------------------------------------- /TseerAgent/src/HeartBeatReportThread.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tseer available. 3 | * 4 | * Copyright (C) 2018 THL A29 Limited, a Tencent company. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | #ifndef _HEART_BEAT_REPORT_H_ 18 | #define _HEART_BEAT_REPORT_H_ 19 | 20 | #include "util/tc_thread.h" 21 | #include "Registry.h" 22 | 23 | 24 | class HeartBeatReportThread : public tars::TC_Thread, public tars::TC_ThreadLock 25 | { 26 | public: 27 | HeartBeatReportThread(); 28 | 29 | //初始化,设置上报间隔(s),获取Registry的路由等;成功返回0,失败返回-1 30 | int init(int reportPeriod); 31 | 32 | virtual void run(); 33 | 34 | void terminate(); 35 | 36 | //添加api key信息 37 | void addKeyInfo(const string &key, const string &version); 38 | private: 39 | 40 | bool _terminate; 41 | 42 | int _reportPeriod; 43 | 44 | Tseer::RegistryPrx _registryPrx; 45 | 46 | time_t _lastReportKeyTime; 47 | TC_ThreadLock _apiKeyLock; 48 | set _apiKeys; 49 | bool _init; 50 | }; 51 | 52 | extern HeartBeatReportThread *g_ReapHeartBeatReportThread; 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /TseerAgent/src/RouterImp.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tseer available. 3 | * 4 | * Copyright (C) 2018 THL A29 Limited, a Tencent company. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | #ifndef __AGENT_ROUTER_IMP_H_ 18 | #define __AGENT_ROUTER_IMP_H_ 19 | 20 | #include "TseerAgent.h" 21 | 22 | class RouterImp : public Tseer::Router 23 | { 24 | public: 25 | 26 | virtual ~RouterImp() {} 27 | 28 | virtual void initialize(); 29 | 30 | virtual void destroy(); 31 | 32 | virtual tars::Int32 getRouterNode(const Tseer::AgentRouterRequest & req, Tseer::AgentRouterResponse &rsp,tars::TarsCurrentPtr current); 33 | 34 | //模调Stat数据上报 35 | virtual tars::Int32 reportStat(const Tseer::NodeStat & stat, tars::TarsCurrentPtr current); 36 | private: 37 | enum GET_ROUTER_RET 38 | { 39 | GET_ROUTER_SUCCESS = 0, //成功 40 | GET_ROUTER_NOT_EXIST = -1, //服务不存在(常因Obj名字错误或服务已经下线引起) 41 | GET_ROUTER_FAILED = -2, //失败 42 | GET_ROUTER_INNER_ERR = -3, //内部错误 43 | GET_ROUTER_PARAM_ERR = -4 //入参错误 44 | 45 | }; 46 | }; 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /TseerAgent/src/RouterStat.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tseer available. 3 | * 4 | * Copyright (C) 2018 THL A29 Limited, a Tencent company. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | #ifndef __ROUTER_STAT_H_ 18 | #define __ROUTER_STAT_H_ 19 | 20 | #include 21 | #include "TarsAgent.h" 22 | 23 | namespace tarsagent 24 | { 25 | 26 | struct CheckTimeoutInfo 27 | { 28 | uint32_t iMinTimeoutInvoke; 29 | uint32_t iCheckTimeoutInterval; 30 | uint32_t iFrequenceFailInvoke; 31 | uint32_t iMinFrequenceFailTime; 32 | float fRadio; 33 | uint32_t iTryTimeInterval; 34 | 35 | CheckTimeoutInfo() 36 | : iMinTimeoutInvoke(2) 37 | , iCheckTimeoutInterval(59) 38 | , iFrequenceFailInvoke(5) 39 | , iMinFrequenceFailTime(5) 40 | , fRadio(0.5) 41 | , iTryTimeInterval(30) 42 | { 43 | iMinTimeoutInvoke = g_app.getMinTimeoutInvoke(); 44 | iCheckTimeoutInterval = g_app.getCheckTimeoutInterval(); 45 | iFrequenceFailInvoke = g_app.getFrequenceFailInvoke(); 46 | iMinFrequenceFailTime = g_app.getMinFrequenceFailTime(); 47 | fRadio = g_app.getRadio(); 48 | iTryTimeInterval = g_app.getTryTimeInterval(); 49 | } 50 | }; 51 | 52 | struct RouterNodeStat 53 | { 54 | std::string ip; 55 | unsigned short port; 56 | unsigned int succNum; 57 | unsigned int errNum; 58 | unsigned int continueErrNum; 59 | unsigned long long timeCost; 60 | bool available; 61 | unsigned long long nextRetryTime; 62 | unsigned long long lastCheckTime; 63 | unsigned long long continueErrTime; 64 | }; 65 | 66 | } 67 | 68 | #endif 69 | -------------------------------------------------------------------------------- /TseerAgent/src/SelfUpdateThread.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tseer available. 3 | * 4 | * Copyright (C) 2018 THL A29 Limited, a Tencent company. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | #ifndef _NODE_SELF_UPDATE_THREAD_H__ 18 | #define _NODE_SELF_UPDATE_THREAD_H__ 19 | 20 | #include 21 | #include 22 | #include "util/tc_thread.h" 23 | #include "util/tc_monitor.h" 24 | #include "Registry.h" 25 | 26 | 27 | typedef bool (*upd_done_cb)(const string&); 28 | struct PacketData 29 | { 30 | Tseer::PackageInfo verMd5; 31 | upd_done_cb done_cb; 32 | bool trigger; 33 | }; 34 | 35 | class SelfUpdateThread : public TC_Thread, public TC_ThreadLock 36 | { 37 | public: 38 | SelfUpdateThread(bool autoUpdate, string path); 39 | ~SelfUpdateThread(){}; 40 | int init(); 41 | void run(); 42 | void terminate(); 43 | private: 44 | /** 45 | * 下载新的发布包 46 | */ 47 | bool download(const string &dstPath, const Tseer::PackageInfo &info); 48 | /** 49 | * 检查agent是否有新的发布包 50 | */ 51 | bool needUpdate(const Tseer::PackageInfo &reqInfo, const Tseer::PackageInfo &rspInfo); 52 | private: 53 | map _mPacketInfo; /* fullpath, packetdata */ 54 | 55 | Tseer::RegistryPrx _updtePrx; 56 | bool _terminate; 57 | 58 | time_t _tInterval; 59 | 60 | //是否允许自动更新,默认为true 61 | bool _autoUpdate; 62 | string _serName; 63 | string _servVersion; 64 | string _osVersion; 65 | string _path; 66 | string _packageName; 67 | }; 68 | 69 | 70 | #endif 71 | 72 | -------------------------------------------------------------------------------- /TseerAgent/src/UpdateImp.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tseer available. 3 | * 4 | * Copyright (C) 2018 THL A29 Limited, a Tencent company. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | #ifndef __UPDATE_IMP_H_ 18 | #define __UPDATE_IMP_H_ 19 | 20 | #include "TseerAgentUpdate.h" 21 | 22 | using Tseer::Update; 23 | 24 | class UpdateImp : public Update 25 | { 26 | public: 27 | /** 28 | * 29 | */ 30 | UpdateImp() 31 | { 32 | }; 33 | 34 | /** 35 | * 销毁服务 36 | * @param k 37 | * @param v 38 | * 39 | * @return 40 | */ 41 | ~UpdateImp() 42 | { 43 | }; 44 | 45 | /** 46 | * 初始化 47 | */ 48 | virtual void initialize(); 49 | 50 | /** 51 | * 退出 52 | */ 53 | virtual void destroy() 54 | { 55 | }; 56 | 57 | /** 58 | * 更新agent自身配置 59 | * @param cfg 更新agent配置 60 | * @return int 0成功 其它失败 61 | */ 62 | virtual tars::Int32 updateConfig(const Tseer::AgentConfig & cfg,std::string &result,tars::TarsCurrentPtr current); 63 | 64 | virtual tars::Int32 uninstall(std::string &result,tars::TarsCurrentPtr current); 65 | }; 66 | 67 | #endif 68 | -------------------------------------------------------------------------------- /TseerAgent/src/util.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tseer available. 3 | * 4 | * Copyright (C) 2018 THL A29 Limited, a Tencent company. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | #ifndef _UTIL_H 18 | #define _UTIL_H 19 | 20 | #include "util/tc_common.h" 21 | #include "RollLogger.h" 22 | 23 | inline bool popen_sendMsg(const string& sCommand) 24 | { 25 | FILE *fp; 26 | int rc = 0; // 用于接收命令返回值 27 | 28 | /*执行预先设定的命令,并读出该命令的标准输出*/ 29 | fp = popen(sCommand.c_str(), "r"); 30 | if(NULL == fp) 31 | { 32 | TSEER_LOG(UPDATE_LOG)->error() << FILE_FUN << "popen error,send message failed" << endl; 33 | return false; 34 | } 35 | 36 | /*等待命令执行完毕并关闭管道及文件指针*/ 37 | rc = pclose(fp); 38 | 39 | return true; 40 | } 41 | 42 | template 43 | inline string display(const T& t) 44 | { 45 | stringstream stream; 46 | stream.str(""); 47 | t.displaySimple(stream); 48 | return(stream.str()); 49 | } 50 | #endif 51 | 52 | -------------------------------------------------------------------------------- /TseerServer/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8) 2 | 3 | project(TseerServer) 4 | 5 | include_directories(${CMAKE_CURRENT_SOURCE_DIR}/protocol 6 | ${TARS_DIR_INC} 7 | ${RAPID_JSON_DIR} 8 | ${TARS_DIR_INC}/servant) 9 | 10 | link_directories(${TARS_DIR_LIB}) 11 | 12 | set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/${PROJECT_NAME}/bin) 13 | 14 | add_subdirectory(protocol) 15 | add_subdirectory(src) 16 | 17 | install (FILES ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}.conf DESTINATION ${PROJECT_BINARY_DIR}/${PROJECT_NAME}/conf) -------------------------------------------------------------------------------- /TseerServer/TseerServer.conf: -------------------------------------------------------------------------------- 1 | 2 | #服务安装路径,默认是/usr/local,必填 3 | installpath=/home/louishuang/onlineseer/seer/mytest 4 | #服务绑定本机地址,必填 5 | localip=127.0.0.1 6 | #服务日志等级,默认是DEBUG 7 | logLevel=DEBUG 8 | #服务默认的存储方式可选:etcd/mysql,默认是etcd 9 | store=etcd 10 | #服务Agent注册和心跳上报端口 11 | regport=9902 12 | #服务路由信息查询端口 13 | queryport=9903 14 | #服务管理员操作端口 15 | apiport=9904 16 | 17 | #store为mysql时必填 18 | 19 | charset=utf8 20 | dbhost=127.0.0.1 21 | dbname=seer 22 | dbuser=root 23 | dbpass= 24 | dbport=3306 25 | 26 | #store为etcd时必填 27 | 28 | #多个请用分号分割 29 | host=127.0.0.1:2379 30 | -------------------------------------------------------------------------------- /TseerServer/protocol/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(OUT_DEPENDS_LIST) 2 | 3 | complice_tars(OUT_DEPENDS_LIST "") 4 | 5 | add_custom_target(TSEERSERVER_TARS_HEADER ALL DEPENDS ${OUT_DEPENDS_LIST}) -------------------------------------------------------------------------------- /TseerServer/protocol/RetCode.tars: -------------------------------------------------------------------------------- 1 | module Tseer 2 | { 3 | /*公共错误码*/ 4 | const int TSEER_SERVERSUCCESS = 0; //请求成功 5 | const int TSEER_UNKNOW_ERROR = -99; //未知错误 6 | 7 | /*DockerRegistry专用返回码号段: 2000 ~ 2999*/ 8 | const int TSEER_REGISTRY_UNKNOWN = 2000; // 9 | const int TSEER_REGISTRY_PARAM_ERROR =2001; //请求参数不合规范 10 | const int TSEER_REGISTRY_UPDATESERVER_PARAM_ERROR = 2002; //updateServer接口参数错误 11 | const int TSEER_REGISTRY_GETSERVER_PARAM_ERROR = 2003; //get接口参数错误 12 | const int TSEER_REGISTRY_SETSERVER_PARAM_ERROR = 2004; //set接口参数错误 13 | const int TSEER_REGISTRY_DELTESERVER_PARAM_ERROR = 2005; //deletedata接口参数错误 14 | const int TSEER_REGISTRY_ADDSERVER_PARAM_ERROR = 2005; //deletedata接口参数错误 15 | 16 | /*TSeerServer etcd专用返回码号段: 2500 ~ 2999,结合*/ 17 | const int TSEER_REGISTRY_ETCD_UNKNOWN = 2500; // 18 | const int TSEER_REGISTRY_ETCD_PARSE_JSON_FAIL = 2501; //解析etcd返回的json结构失败 19 | const int TSEER_REGISTRY_ETCD_TIMEOUT = 2502;//调用etcd返回超时 20 | const int TSEER_REGISTRY_ETCD_RET_ERROR = 2503;//调用etcd出现内部错误 21 | const int TSEER_REGISTRY_ETCD_DATA_NOTFOUND = 2504;//etcd不存在指定的数据 22 | const int TSEER_REGISTRY_ETCD_SEND_REQ_FAIL = 2505;//向etcd服务发起网络请求失败 23 | }; 24 | 25 | -------------------------------------------------------------------------------- /TseerServer/protocol/RouterData.tars: -------------------------------------------------------------------------------- 1 | module Tseer 2 | { 3 | struct RouterData 4 | { 5 | 0 require string moduletype; 6 | 1 require string application; 7 | 2 require string service_name; 8 | 3 require string node_name; 9 | 4 require string container_name; 10 | //填 Y 或者 N 只有这两个值 11 | 5 require string enable_group; 12 | 6 require string ip_group_name; 13 | //填 Y 或者 N 只有这两个值 14 | 7 require string enable_set; 15 | 8 require string set_name; 16 | 9 require string set_area; 17 | 10 require string set_group; 18 | 11 require string weight; 19 | //填 active inactive activating deactivating destroying destroyed 只能填这几个值 20 | 12 require string setting_state; 21 | 13 require string process_id; 22 | //填 active inactive activating deactivating destroying destroyed 只能填这几个值 23 | 14 require string present_state; 24 | 15 require string node_port; 25 | 16 require string container_port; 26 | /* 27 | key=路由的obj名字,比如:normal.itil.jdsweb.main_port 28 | value=具体的endpoint字符串详情,例如tcp -h 10.209.19.235 -p 9903 -t 50000 29 | */ 30 | 17 require map servant; 31 | 18 require string bak_flag; 32 | 19 require string grid_flag; 33 | 20 optional string weighttype; //启用权重类型,默认空,不启用,1:静态权重,2:动态权重 34 | 21 optional string enable_heartbeat; //是否允许做心跳超时检测 35 | 22 optional string heartbeattimeout="60"; //服务心跳超时时间,单位秒 36 | }; 37 | 38 | struct RouterDataRequest 39 | { 40 | 0 require string moduletype; 41 | 1 require string application; 42 | 2 require string service_name; 43 | 3 require string node_name; 44 | 4 require string container_name; 45 | }; 46 | key[RouterDataRequest,moduletype,application,service_name,node_name,container_name]; 47 | }; 48 | 49 | -------------------------------------------------------------------------------- /TseerServer/protocol/TseerAgentUpdate.tars: -------------------------------------------------------------------------------- 1 | module Tseer 2 | { 3 | struct AgentConfig 4 | { 5 | 0 require string locator; /* TSeer.TSeerServer.QueryObj@tcp -hx.x.x.x -px -txxxx */ 6 | 1 require string nodeIp; /* node主机的ip */ 7 | }; 8 | 9 | interface Update 10 | { 11 | /** 12 | * 更新TSeerAgent的TSeerServer路由服务地址 13 | * @param cfg 更新TSeerAgent配置 14 | * @param [out] result 操作详情 15 | * @return int 0成功 其它失败 16 | */ 17 | int updateConfig(AgentConfig cfg, out string result); 18 | 19 | /** 20 | * 卸载TSeerAgent:清理crontab,删除TSeerAgent目录结构 21 | * @param [out] result 操作详情 22 | * @return int 0成功 其它失败 23 | */ 24 | int uninstall(out string result); 25 | }; 26 | }; 27 | 28 | -------------------------------------------------------------------------------- /TseerServer/src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8) 2 | project(TseerServer) 3 | 4 | if(USE_MYSQL) 5 | include_directories(${MYSQL_DIR_INC}) 6 | add_definitions(-DUSE_MYSQL) 7 | endif(USE_MYSQL) 8 | 9 | add_definitions(-DTARS_VERSION="${TARS_VERSION}" -DOS_VERSION="${OS_VERSION}") 10 | 11 | aux_source_directory(. DIR_SRCS) 12 | 13 | add_executable(${PROJECT_NAME} ${DIR_SRCS}) 14 | 15 | #set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/${PROJECT_NAME}/bin) 16 | 17 | 18 | if(USE_MYSQL) 19 | target_link_libraries(${PROJECT_NAME} tarsservant tarsparse tarsutil ${MYSQL_DIR_LIB}/libmysqlclient.a 20 | pthread z dl rt) 21 | else(USE_MYSQL) 22 | target_link_libraries(${PROJECT_NAME} tarsservant tarsparse tarsutil 23 | pthread) 24 | endif(USE_MYSQL) 25 | -------------------------------------------------------------------------------- /TseerServer/src/EtcdCommon.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tseer available. 3 | * 4 | * Copyright (C) 2018 THL A29 Limited, a Tencent company. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | #ifndef __ETCD_COMMON_H__ 18 | #define __ETCD_COMMON_H__ 19 | 20 | #include "util/tc_common.h" 21 | #include "Registry.h" 22 | 23 | using namespace Tseer; 24 | 25 | /*路由数据的value标识符*/ 26 | #define OBJNAMEEKEY string("key") 27 | #define PRESENTSTATEKEY string("present_state") 28 | 29 | const string DCNODE_NETWORK_ID = "dcnode"; 30 | const string TSEER_AGENT_NET_WORK_ID = "router_agent"; 31 | 32 | #endif -------------------------------------------------------------------------------- /TseerServer/src/ReapThread.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tseer available. 3 | * 4 | * Copyright (C) 2018 THL A29 Limited, a Tencent company. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | #ifndef __REAP_THREAD_H__ 18 | #define __REAP_THREAD_H__ 19 | 20 | #include 21 | 22 | #include "util/tc_thread.h" 23 | 24 | #include "StoreCache.h" 25 | 26 | using namespace Tseer; 27 | 28 | /** 29 | * 用于执行定时操作的线程类 30 | */ 31 | class ReapThread : public TC_Thread, public TC_ThreadLock 32 | { 33 | public: 34 | 35 | ReapThread(); 36 | 37 | ~ReapThread(); 38 | 39 | /* 40 | * 结束线程 41 | */ 42 | void terminate(); 43 | 44 | /** 45 | * 初始化 46 | */ 47 | int init(); 48 | 49 | /** 50 | * 轮询函数 51 | */ 52 | virtual void run(); 53 | private: 54 | /** 55 | * 更新服务自身心跳 56 | */ 57 | int updateRegistryInfo(); 58 | protected: 59 | //线程结束标志 60 | bool _terminate; 61 | 62 | //数据库操作 63 | StoreCache _storeCache; 64 | 65 | //全量加载时间,单位是秒,默认5秒 66 | int _loadAllObjectsInterval; 67 | 68 | //registry心跳频率,单位是秒,默认60秒 69 | int _registryHeartBeatInterval; 70 | 71 | //是否启用数据恢复保护功能,默认为打开 72 | bool _becoverProtect; 73 | 74 | //启用数据恢复保护功能状态下极限值 75 | int _recoverProtectRate; 76 | 77 | //主控心跳时间更新开关 78 | bool _regHeartBeatOff; 79 | }; 80 | 81 | #endif 82 | -------------------------------------------------------------------------------- /TseerServer/test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | aux_source_directory(. DIR_SRCS) 2 | 3 | add_executable(Test ${DIR_SRCS}) 4 | 5 | target_link_libraries(Test tarsservant tarsparse tarsutil 6 | pthread) -------------------------------------------------------------------------------- /TseerServer/test/Global.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tseer available. 3 | * 4 | * Copyright (C) 2018 THL A29 Limited, a Tencent company. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | #ifndef __GLOBAL_H__ 18 | #define __GLOBAL_H__ 19 | 20 | #include 21 | 22 | #include "servant/Communicator.h" 23 | 24 | std::string g_key = "webadmin"; 25 | 26 | std::string g_url = "http://127.0.0.1:9904/v1/interface"; 27 | 28 | std::string g_srvgrp = "apitest222"; 29 | 30 | std::string g_user = ""; 31 | std::string g_idcname = "idctest"; 32 | tars::Communicator g_com; 33 | 34 | int g_ttime = 0; 35 | 36 | int g_iloadInterval = 0; 37 | 38 | #endif -------------------------------------------------------------------------------- /TseerServer/test/IDCTest.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tseer available. 3 | * 4 | * Copyright (C) 2018 THL A29 Limited, a Tencent company. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | #ifndef __IDC_TEST_H__ 18 | #define __IDC_TEST_H__ 19 | 20 | void addIdcGroup(); 21 | 22 | void delIdcGroup(); 23 | 24 | void modifyIdcGroup(); 25 | 26 | void getAllIdcGroup(); 27 | 28 | void addPriority(); 29 | 30 | void delPriority(const string &priorityId); 31 | 32 | void modifyPriority(const string &priorityId); 33 | 34 | void getPriority(); 35 | 36 | void getIdcGroup(); 37 | 38 | #endif -------------------------------------------------------------------------------- /TseerServer/test/NodeTest.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tseer available. 3 | * 4 | * Copyright (C) 2018 THL A29 Limited, a Tencent company. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | #ifndef __NODE_TEST_H__ 18 | #define __NODE_TEST_H__ 19 | 20 | //测试添加一个Agent节点 21 | void addOneAgentNode(); 22 | 23 | //测试删除一个Agent节点 24 | void delOneAgentNode(); 25 | 26 | //测试上报Agent节点的心跳 27 | void keepAliveAgent(); 28 | 29 | //测试添加一个Node节点 30 | void registerNode(); 31 | 32 | //测试删除一个Node节点 33 | void destroyNode(); 34 | 35 | //测试上报Node节点的心跳 36 | void keepAlive(); 37 | 38 | void getagentbaseinfo(); 39 | void updateagentgraystate(); 40 | void getagentpackageinfo(); 41 | void updateagentpackageinfo(); 42 | void deleteagentpackage(); 43 | void updateagentlocator(); 44 | #endif -------------------------------------------------------------------------------- /TseerServer/test/QueryTest.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tseer available. 3 | * 4 | * Copyright (C) 2018 THL A29 Limited, a Tencent company. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | #ifndef __QUERY_TEST_H__ 18 | #define __QUERY_TEST_H__ 19 | 20 | //根据id获取所有对象,包括活动和非活动对象 21 | void findObjectById4Any(); 22 | 23 | void findObjectByIdInSameGroup(); 24 | 25 | void findObjectByIdInSameSet(); 26 | 27 | #endif -------------------------------------------------------------------------------- /TseerServer/test/SeerClientServiceTest.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tseer available. 3 | * 4 | * Copyright (C) 2018 THL A29 Limited, a Tencent company. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | #ifndef __SEER_CLIENT_SERVICE_TEST_H__ 18 | #define __SEER_CLIENT_SERVICE_TEST_H__ 19 | 20 | void addSeerClientService(); 21 | 22 | void modifySeerClientServiceManager(); 23 | 24 | void delSeerClientService(); 25 | 26 | void getSeerClientService(); 27 | 28 | #endif -------------------------------------------------------------------------------- /TseerServer/test/ServerTest.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tseer available. 3 | * 4 | * Copyright (C) 2018 THL A29 Limited, a Tencent company. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | #ifndef __SERVER_TEST_H__ 18 | #define __SERVER_TEST_H__ 19 | 20 | void addServers(); 21 | 22 | void deleteServers(); 23 | 24 | void updateServers(); 25 | 26 | void getServers(); 27 | 28 | void keepServerAlive(); 29 | 30 | 31 | void updateServerState(); 32 | 33 | void updateServerStates(); 34 | 35 | #endif -------------------------------------------------------------------------------- /TseerServer/test/ServiceGroupTest.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tseer available. 3 | * 4 | * Copyright (C) 2018 THL A29 Limited, a Tencent company. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | #ifndef __SERVICE_GROUP_TEST_H__ 18 | #define __SERVICE_GROUP_TEST_H__ 19 | 20 | void addServiceGroup(); 21 | 22 | void getServiceGroup(); 23 | 24 | void updateServiceGroup(); 25 | 26 | #endif -------------------------------------------------------------------------------- /TseerServer/test/Util.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tseer available. 3 | * 4 | * Copyright (C) 2018 THL A29 Limited, a Tencent company. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | #ifndef __UTIL_H__ 18 | #define __UTIL_H__ 19 | 20 | #include 21 | 22 | #include "util/tc_encoder.h" 23 | #include "util/tc_common.h" 24 | #include "util/tc_http.h" 25 | #include "servant/Communicator.h" 26 | 27 | 28 | //#define FILE_FUN __FUNCTION__ << ":" << __LINE__ << "|" << pthread_self() << "|" 29 | #define FILE_FUN __FUNCTION__ << ":" << __LINE__ 30 | 31 | #define REGISTRY_HTTP_API "http://127.0.0.1:9904/v1/client/" 32 | 33 | #define REGISTRY_OBJ "Tseer.TseerServer.RegistryObj@tcp -h 127.0.0.1 -p 9902 -t 30000" 34 | 35 | #define QUERY_OBJ "Tseer.TseerServer.QueryObj@tcp -h 127.0.0.1 -p 9903 -t 30000" 36 | 37 | std::string urlEncode(const std::string &in); 38 | 39 | std::string getRequestUrl(const std::string &interfaceName, const std::string ¶ms, const std::string &api = REGISTRY_HTTP_API); 40 | 41 | int doSyncRequest(const std::string &url, tars::TC_HttpResponse &response); 42 | 43 | #endif -------------------------------------------------------------------------------- /TseerServer/util/execute.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | ulimit -a 3 | bin="/usr/local/app/Seer/bin/SeerServer" 4 | 5 | PID=`ps -eopid,cmd | grep "$bin"| grep "SeerServer" | grep -v "grep" |awk '{print $1}'` 6 | 7 | echo $PID 8 | 9 | if [ "$PID" != "" ]; then 10 | kill -9 $PID 11 | echo "kill -9 $PID" 12 | fi 13 | ulimit -c unlimited 14 | $bin --config=/usr/local/app/Seer/SeerServer/conf/SeerServer.conf & 15 | -------------------------------------------------------------------------------- /TseerServer/util/start.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | installpath=/usr/local/app 4 | etcdcluster=yourmachine:2379 5 | localip=127.0.0.1 6 | 7 | bin="$installpath/Seer/SeerServer/bin/SeerServer" 8 | PID=`ps -eopid,cmd | grep "$bin"| grep "SeerServer" | grep -v "grep" |awk '{print $1}'` 9 | 10 | echo $PID 11 | 12 | if [ "$PID" != "" ]; then 13 | kill -9 $PID 14 | echo "kill -9 $PID" 15 | fi 16 | ulimit -c unlimited 17 | 18 | 19 | nohup $bin --etcd=$etcdcluster --localip=$localip --installpath=$installpath 2>&1 & 20 | -------------------------------------------------------------------------------- /TseerServer/util/stop.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | instalpath=/usr/local/app 4 | bin="$installpath/Seer/SeerServer/bin/SeerServer" 5 | 6 | PID=`ps -eopid,cmd | grep "$bin"| grep "SeerServer" | grep -v "grep" |awk '{print $1}'` 7 | 8 | echo $PID 9 | 10 | if [ "$PID" != "" ]; then 11 | kill -9 $PID 12 | echo "kill -9 $PID" 13 | fi -------------------------------------------------------------------------------- /Tseer_Install.en.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/TSeer/1c92b1e08ddb16b777d992a1e38fd765b5104385/Tseer_Install.en.md -------------------------------------------------------------------------------- /api/cplus/CMakeLists.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/TSeer/1c92b1e08ddb16b777d992a1e38fd765b5104385/api/cplus/CMakeLists.txt -------------------------------------------------------------------------------- /api/cplus/demo/main_agt_rt.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tseer available. 3 | * 4 | * Copyright (C) 2018 THL A29 Limited, a Tencent company. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | #include 18 | #include "seer_api.h" 19 | #include "seer_comm.h" 20 | 21 | using namespace std; 22 | using namespace routerapi; 23 | 24 | int main() 25 | { 26 | int iRet = 0; 27 | string sErr; 28 | 29 | InitAgentApiParams initParams; 30 | initParams.sServiceKey = "seerDemoKey"; 31 | iRet = ApiSetAgentIpInfo(initParams, sErr); 32 | if (iRet != 0) { 33 | cout << "init Agent error" << endl; 34 | return 0; 35 | } 36 | 37 | //初始化ApiGetRoute的参数 38 | RouterRequest req; 39 | req.sObj = "tencent.tencentServer.HelloService"; 40 | req.lbGetType = LB_GET_SET; 41 | req.sSetInfo = "sz.a.b"; 42 | req.type = LB_TYPE_LOOP; 43 | req.sModuleName = "seerClientDemo"; 44 | for (int i = 0; i < 100; i++) { 45 | 46 | iRet = ApiGetRoute(req, sErr); 47 | cout << "[out]iRet: " << iRet << " sErr: " << sErr << endl; 48 | cout << "[out]sIp: " << req.sIp << endl; 49 | cout << "[out]iPort: " << req.iPort << endl; 50 | cout << "[out]bTcp: " << req.bTcp << endl; 51 | 52 | if (iRet == 0) { 53 | //进行调用 54 | sleep(5); 55 | //调用结束上报调用结果 56 | ApiRouteResultUpdate(req, 0, 1, sErr); 57 | cout << "[report]sErr: " << sErr << endl; 58 | } 59 | 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /api/cplus/demo/main_reg_rt.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tseer available. 3 | * 4 | * Copyright (C) 2018 THL A29 Limited, a Tencent company. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | #include 18 | #include "seer_api.h" 19 | #include "seer_comm.h" 20 | 21 | using namespace std; 22 | using namespace routerapi; 23 | 24 | int main() 25 | { 26 | int iRet = 0; 27 | string sErr = ""; 28 | 29 | InitRawApiParams initParams; 30 | initParams.sServiceKey = "seerDemoKey"; 31 | iRet = ApiSetRegistryInfo(initParams, sErr); 32 | if (iRet != 0) { 33 | cout << "init Agent error" << endl; 34 | return 0; 35 | } 36 | 37 | //初始化ApiGetRoute的参数 38 | RouterRequest req; 39 | req.sObj = "tencent.tencentServer.HelloService"; 40 | req.lbGetType = LB_GET_SET; 41 | req.sSetInfo = "sz.a.b"; 42 | req.type = LB_TYPE_LOOP; 43 | req.sModuleName = "seerClientDemo"; 44 | iRet = ApiGetRoute(req, sErr); 45 | cout << "[out]iRet: " << iRet << " sErr: " << sErr << endl; 46 | cout << "[out]sIp: " << req.sIp << endl; 47 | cout << "[out]iPort: " << req.iPort << endl; 48 | cout << "[out]bTcp: " << req.bTcp << endl; 49 | 50 | if (iRet == 0) { 51 | //进行调用 52 | sleep(5); 53 | //调用结束上报调用结果 54 | ApiRouteResultUpdate(req, 0, 1, sErr); 55 | cout << "[report]sErr: " << sErr << endl; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /api/cplus/src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #project(tseerapi) 2 | 3 | #set(LIBRARY_OUTPUT_PATH ${TSEERAPI_ROOT_DIR}/lib) 4 | 5 | set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/${PROJECT_NAME}/lib) 6 | 7 | aux_source_directory(. DIR_SRCS) 8 | 9 | add_library(tseerapi STATIC ${DIR_SRCS}) 10 | 11 | target_link_libraries(tseerapi rt) 12 | -------------------------------------------------------------------------------- /api/cplus/src/EndPoint.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tseer available. 3 | * 4 | * Copyright (C) 2018 THL A29 Limited, a Tencent company. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | #ifndef __TSEER_API_ENDPOINT_H_ 18 | #define __TSEER_API_ENDPOINT_H_ 19 | 20 | /** 文件定义了网络端口 21 | * eg. tcp -h 127.0.0.1 -p 2345 -t 10000 -w 100 22 | */ 23 | 24 | #include 25 | #include 26 | #include "TseerAgentComm.h" 27 | 28 | namespace Tseerapi 29 | { 30 | 31 | struct EndPoint 32 | { 33 | public: 34 | EndPoint(); 35 | 36 | EndPoint(bool isTcp, const std::string& host, int port, int timeout, 37 | const std::string &set, int weight = -1); 38 | 39 | EndPoint(const EndPoint& l); 40 | 41 | EndPoint& operator = (const EndPoint& l); 42 | 43 | bool operator == (const EndPoint& l); 44 | 45 | /** 用字符串描述来构造;成功返回0,失败返回-1 46 | * 格式:(tcp|udp) -h xx -p xx -t xx [-s xx] [-w xx] 47 | */ 48 | int parse(const std::string& str, std::string &errMsg); 49 | 50 | std::string toString() const; 51 | 52 | Tseer::RouterNodeInfo toRouterNodeInfo(); 53 | 54 | //类型 55 | bool _istcp; 56 | 57 | //ip 58 | std::string _host; 59 | 60 | //端口 61 | int _port; 62 | 63 | //超时时间 64 | int _timeout; 65 | 66 | ///节点的静态权重值 67 | int _weight; 68 | 69 | //节点的set信息 70 | std::string _set; 71 | }; 72 | 73 | 74 | } 75 | 76 | #endif 77 | -------------------------------------------------------------------------------- /api/cplus/src/conn.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tseer available. 3 | * 4 | * Copyright (C) 2018 THL A29 Limited, a Tencent company. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | #ifndef __TSEER_API_CONN_H_ 18 | #define __TSEER_API_CONN_H_ 19 | 20 | /********************************************************* 21 | * 文件封装了使用TUP访问TARS服务的操作 22 | *********************************************************/ 23 | 24 | #include 25 | #include 26 | 27 | namespace Tseerapi 28 | { 29 | 30 | class Conn 31 | { 32 | public: 33 | //模调数据上报到Agent 34 | static int NodeStatSendAgent(const char *sendBuff, unsigned int sendLen, int timeOut, std::string &errMsg); 35 | 36 | //与Agent通信获取节点信息 37 | static int QueryAndRecvRouterFromAgent(const char *sendBuff, unsigned int sendLen, int timeOut, char *recvBuff, unsigned int& recvSize, std::string &errMsg); 38 | 39 | //与Registry通信获取节点信息 40 | static int QueryAndRecvRouterFromRegistry(const char *sendBuff, unsigned int sendLen, int timeOut, char *recvBuff, unsigned int& recvSize, const std::string ®istryIp, std::string &errMsg); 41 | }; 42 | 43 | } 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /api/cplus/src/lb.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tseer available. 3 | * 4 | * Copyright (C) 2018 THL A29 Limited, a Tencent company. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | #include "lb.h" 18 | #include "global.h" 19 | #include 20 | 21 | namespace Tseerapi 22 | { 23 | 24 | int LoadBalance::getRouters(std::vector &nodeInfoVec, std::string &errMsg) 25 | { 26 | std::ostringstream os; 27 | os << FILE_FUN << "Unsupported method invocation."; 28 | errMsg = os.str(); 29 | return -1; 30 | } 31 | 32 | int LoadBalance::getRouter(Tseer::RouterNodeInfo& nodeInfo, std::string &errMsg) 33 | { 34 | std::ostringstream os; 35 | os << FILE_FUN << "Unsupported method invocation."; 36 | errMsg = os.str(); 37 | return -1; 38 | } 39 | 40 | int LoadBalance::getRouter(unsigned long long key, Tseer::RouterNodeInfo& nodeInfo, std::string &errMsg) 41 | { 42 | std::ostringstream os; 43 | os << FILE_FUN << "Unsupported method invocation."; 44 | errMsg = os.str(); 45 | return -1; 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /api/cplus/src/lb.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tseer available. 3 | * 4 | * Copyright (C) 2018 THL A29 Limited, a Tencent company. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | #ifndef __TSEER_API_LB_H_ 18 | #define __TSEER_API_LB_H_ 19 | 20 | #include 21 | #include "Tseer_inner_comm.h" 22 | #include "TseerAgentComm.h" 23 | 24 | namespace Tseerapi 25 | { 26 | 27 | class LoadBalance 28 | { 29 | public: 30 | virtual ~LoadBalance(){}; 31 | 32 | //新增节点 33 | virtual int addRouter(const Tseer::RouterNodeInfo& nodeInfo) = 0; 34 | 35 | //根据负载均衡获取一个节点 36 | virtual int getRouter(Tseer::RouterNodeInfo& nodeInfo, std::string &errMsg); 37 | 38 | //根据负载均衡和key值获取一个节点,只当负载均衡算法与key值相关时此函数才有意义 39 | virtual int getRouter(unsigned long long key, Tseer::RouterNodeInfo& nodeInfo, std::string &errMsg); 40 | 41 | //获取所有节点 42 | virtual int getRouters(std::vector &nodeInfoVec, std::string &errMsg); 43 | 44 | //清理节点 45 | virtual void clear() = 0; 46 | 47 | //重建所有状态 48 | virtual int rebuild() = 0; 49 | 50 | //删除指定的节点 51 | virtual int del(const std::vector &nodeInfoVec) = 0; 52 | 53 | //记录节点调用状态 54 | virtual int statResult(const Tseer::RouterNodeInfo& req, int ret, int timeCost) = 0; 55 | }; 56 | 57 | } 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /api/cplus/src/lb_all.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tseer available. 3 | * 4 | * Copyright (C) 2018 THL A29 Limited, a Tencent company. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | #ifndef __TSEER_API_LB_ALL_H_ 18 | #define __TSEER_API_LB_ALL_H_ 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include "lb.h" 25 | #include "router_stat.h" 26 | #include "TseerAgentComm.h" 27 | 28 | namespace Tseerapi 29 | { 30 | 31 | class LBAll : public LoadBalance 32 | { 33 | public: 34 | LBAll(); 35 | 36 | ~LBAll(); 37 | 38 | virtual int addRouter(const Tseer::RouterNodeInfo& nodeInfo); 39 | 40 | virtual int getRouters(std::vector &nodeInfoVec, std::string &errMsg); 41 | 42 | virtual void clear(); 43 | 44 | virtual int rebuild(); 45 | 46 | virtual int statResult(const Tseer::RouterNodeInfo& req, int ret, int timeCost); 47 | 48 | virtual int del(const std::vector &nodeInfoVec); 49 | 50 | private: 51 | std::vector _normalNodeInfo; 52 | 53 | std::map _normal; 54 | }; 55 | 56 | } 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /api/cplus/src/lb_consistenthash.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tseer available. 3 | * 4 | * Copyright (C) 2018 THL A29 Limited, a Tencent company. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | #ifndef __TSEER_API_LB_CONSISENT_HASH_ 18 | #define __TSEER_API_LB_CONSISENT_HASH_ 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include "lb.h" 25 | #include "router_stat.h" 26 | #include "TseerAgentComm.h" 27 | 28 | namespace Tseerapi 29 | { 30 | 31 | class LBConsistentHash : public LoadBalance 32 | { 33 | public: 34 | LBConsistentHash(); 35 | 36 | ~LBConsistentHash(); 37 | 38 | virtual int addRouter(const Tseer::RouterNodeInfo& nodeInfo); 39 | 40 | virtual int getRouter(Tseer::RouterNodeInfo& nodeInfo, std::string &errMsg); 41 | 42 | virtual int getRouter(unsigned long long key, Tseer::RouterNodeInfo& nodeInfo, std::string &errMsg); 43 | 44 | virtual void clear(); 45 | 46 | virtual int rebuild(); 47 | 48 | virtual int statResult(const Tseer::RouterNodeInfo& req, int ret, int timeCost); 49 | 50 | virtual int del(const std::vector &nodeInfoVec); 51 | 52 | private: 53 | 54 | bool checkActive(const Tseer::RouterNodeInfo& nodeInfo); 55 | 56 | unsigned int murmurHash32(const char *key, unsigned int len, unsigned int seed); 57 | 58 | CheckTimeoutInfo _checkTimeoutInfo; 59 | 60 | std::map _statMap; 61 | 62 | std::map _normalMap; 63 | 64 | std::map _tableMap; 65 | }; 66 | 67 | } 68 | 69 | #endif 70 | -------------------------------------------------------------------------------- /api/cplus/src/lb_factory.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tseer available. 3 | * 4 | * Copyright (C) 2018 THL A29 Limited, a Tencent company. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include "lb_loop.h" 23 | #include "lb_random.h" 24 | #include "lb_consistenthash.h" 25 | #include "lb_static_weight.h" 26 | #include "lb_factory.h" 27 | #include "lb_all.h" 28 | 29 | namespace Tseerapi 30 | { 31 | 32 | LoadBalance* LoadBalanceFactory::CreateLoadBalance(LB_TYPE type) 33 | { 34 | LoadBalance *lb = NULL; 35 | switch(type) 36 | { 37 | case LB_TYPE_LOOP: 38 | lb = new(std::nothrow) LBLoop; 39 | break; 40 | case LB_TYPE_RANDOM: 41 | lb = new(std::nothrow) LBRandom; 42 | break; 43 | case LB_TYPE_CST_HASH: 44 | lb = new(std::nothrow) LBConsistentHash; 45 | break; 46 | case LB_TYPE_STATIC_WEIGHT: 47 | lb = new(std::nothrow) LBStaticWeight; 48 | break; 49 | case LB_TYPE_ALL: 50 | lb = new(std::nothrow) LBAll; 51 | break; 52 | default: 53 | lb = NULL; 54 | break; 55 | } 56 | 57 | return lb; 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /api/cplus/src/lb_factory.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tseer available. 3 | * 4 | * Copyright (C) 2018 THL A29 Limited, a Tencent company. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | #ifndef __TSEER_API_LB_FACTORY_H_ 18 | #define __TSEER_API_LB_FACTORY_H_ 19 | 20 | #include "lb.h" 21 | 22 | namespace Tseerapi 23 | { 24 | 25 | class LoadBalanceFactory 26 | { 27 | public: 28 | static LoadBalance* CreateLoadBalance(LB_TYPE lb_type); 29 | }; 30 | 31 | } 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /api/cplus/src/lb_loop.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tseer available. 3 | * 4 | * Copyright (C) 2018 THL A29 Limited, a Tencent company. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | #ifndef __TSEER_API_LB_LOOP_H_ 18 | #define __TSEER_API_LB_LOOP_H_ 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include "lb.h" 25 | #include "router_stat.h" 26 | #include "TseerAgentComm.h" 27 | 28 | namespace Tseerapi 29 | { 30 | 31 | class LBLoop : public LoadBalance 32 | { 33 | public: 34 | LBLoop(); 35 | 36 | ~LBLoop(); 37 | 38 | virtual int addRouter(const Tseer::RouterNodeInfo& nodeInfo); 39 | 40 | virtual int getRouter(Tseer::RouterNodeInfo& nodeInfo, std::string &errMsg); 41 | 42 | virtual void clear(); 43 | 44 | virtual int rebuild(); 45 | 46 | virtual int statResult(const Tseer::RouterNodeInfo& req, int ret, int timeCost); 47 | 48 | virtual int del(const std::vector &nodeInfoMap); 49 | 50 | private: 51 | bool checkActive(const Tseer::RouterNodeInfo& nodeInfo); 52 | 53 | size_t _lastIndex; 54 | 55 | std::vector _normalNodeInfoVec; 56 | 57 | std::map _normalMap; 58 | 59 | CheckTimeoutInfo _checkTimeoutInfo; 60 | 61 | std::map _statMap; 62 | }; 63 | 64 | } 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /api/cplus/src/lb_random.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tseer available. 3 | * 4 | * Copyright (C) 2018 THL A29 Limited, a Tencent company. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | #ifndef __TSEER_API_LB_RANOMD_H_ 18 | #define __TSEER_API_LB_RANOMD_H_ 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include "lb.h" 25 | #include "router_stat.h" 26 | #include "TseerAgentComm.h" 27 | 28 | namespace Tseerapi 29 | { 30 | 31 | class LBRandom : public LoadBalance 32 | { 33 | public: 34 | LBRandom(); 35 | 36 | ~LBRandom(); 37 | 38 | virtual int addRouter(const Tseer::RouterNodeInfo& nodeInfo); 39 | 40 | virtual int getRouter(Tseer::RouterNodeInfo& nodeInfo, std::string &subErr); 41 | 42 | virtual void clear(); 43 | 44 | virtual int rebuild(); 45 | 46 | virtual int statResult(const Tseer::RouterNodeInfo& req, int ret, int timeCost); 47 | 48 | virtual int del(const std::vector &nodeInfoVec); 49 | 50 | private: 51 | 52 | bool checkActive(const Tseer::RouterNodeInfo& nodeInfo); 53 | 54 | std::vector _normalNodeInfoVec; 55 | 56 | //由IP、Port、TCP/UDP组成的KEY 57 | std::map _normalMap; 58 | 59 | CheckTimeoutInfo _checkTimeoutInfo; 60 | 61 | std::map _statMap; 62 | }; 63 | 64 | } 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /api/cplus/src/registry_ep_manager.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tseer available. 3 | * 4 | * Copyright (C) 2018 THL A29 Limited, a Tencent company. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | #ifndef __TSEER_API_REGISTRY_EP_MANAGER_H_ 18 | #define __TSEER_API_REGISTRY_EP_MANAGER_H_ 19 | 20 | /************************************************************************ 21 | * 文件定义了Tseer服务端节点的管理类,该类负责维护Tseer服务端的节点 22 | ************************************************************************/ 23 | 24 | #include 25 | #include 26 | #include 27 | #include "router_stat.h" 28 | 29 | namespace Tseerapi 30 | { 31 | 32 | class RegistryEpManager 33 | { 34 | public: 35 | RegistryEpManager(); 36 | 37 | //获取一个可用的路由节点,成功返回0,失败返回-1 38 | int getAvaliableIp(std::string &ip, std::string &errMsg); 39 | 40 | //上报节点调用情况,调用结果分为0(成功),-1(失败) 41 | void reportResult(const std::string &ip, int result); 42 | 43 | //设置Tseer服务端固定节点,一旦调用该函数,应用将一直循环使用这几个节点(不会去更新) 44 | //参数ips如果有多个ip,用"|"分割 45 | void setConsantIp(const std::string &ips); 46 | 47 | private: 48 | 49 | void isNeedUpdate(); 50 | 51 | //判断节点是否可用 52 | bool checkActive(const std::string &ip); 53 | 54 | //从DNS获取Tseer服务端信息 55 | int getRegistryFromDNS(std::string &errMsg); 56 | 57 | private: 58 | //Tseer服务端的IP地址 59 | std::vector _registryIps; 60 | 61 | //IP及它们节点状态 62 | std::map _ipsStat; 63 | 64 | //节点屏蔽控制信息 65 | CheckTimeoutInfo _checkTimeoutInfo; 66 | 67 | //轮询Tseer服务端,使用的下标 68 | size_t _index; 69 | 70 | //上次更新时间 71 | time_t _lastUpdateTime; 72 | 73 | //是否使用固定的几个IP 74 | bool _isIpsConstant; 75 | }; 76 | 77 | } 78 | 79 | #endif 80 | -------------------------------------------------------------------------------- /api/cplus/src/tc_ex.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tseer available. 3 | * 4 | * Copyright (C) 2018 THL A29 Limited, a Tencent company. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | #include "tc_ex.h" 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | using std::string; 24 | 25 | namespace Tseerapi 26 | { 27 | 28 | TC_Exception::TC_Exception(const string &buffer) 29 | :_buffer(buffer), _code(0) 30 | { 31 | // getBacktrace(); 32 | } 33 | 34 | TC_Exception::TC_Exception(const string &buffer, int err) 35 | { 36 | _buffer = buffer + " :" + strerror(err); 37 | _code = err; 38 | // getBacktrace(); 39 | } 40 | 41 | TC_Exception::~TC_Exception() throw() 42 | { 43 | } 44 | 45 | const char* TC_Exception::what() const throw() 46 | { 47 | return _buffer.c_str(); 48 | } 49 | 50 | void TC_Exception::getBacktrace() 51 | { 52 | void * array[64]; 53 | int nSize = backtrace(array, 64); 54 | char ** symbols = backtrace_symbols(array, nSize); 55 | 56 | for (int i = 0; i < nSize; i++) 57 | { 58 | _buffer += symbols[i]; 59 | _buffer += "\n"; 60 | } 61 | free(symbols); 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /api/cplus/test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | include_directories(${TSEERAPI_ROOT_DIR}/src) 2 | 3 | aux_source_directory(. DIR_SRCS) 4 | add_executable(testapi ${DIR_SRCS}) 5 | 6 | set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/${PROJECT_NAME}/test) 7 | 8 | target_link_libraries(testapi tseerapi pthread) -------------------------------------------------------------------------------- /api/java/demo/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | qq-central 6 | tars-seer-demo 7 | 0.0.1-SNAPSHOT 8 | jar 9 | 10 | tars-seer-demo 11 | http://maven.apache.org 12 | 13 | 14 | UTF-8 15 | 16 | 17 | 18 | 19 | junit 20 | junit 21 | 3.8.1 22 | test 23 | 24 | 25 | qq-cloud-central 26 | Tseer-client 27 | 1.0.1 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /api/java/src/TseerAgent.tars: -------------------------------------------------------------------------------- 1 | /************************************************************ 2 | * 文件定义了TseerAgent对api提供的接口 3 | ************************************************************/ 4 | 5 | #include "TseerAgentComm.tars" 6 | 7 | module Tseer 8 | { 9 | interface Router 10 | { 11 | /** 12 | * 获取某服务的SET、IDC、ALL节点;成功返回0,失败返回-1 13 | */ 14 | 15 | int getRouterNode(AgentRouterRequest req, out AgentRouterResponse rsp); 16 | 17 | /** 18 | * 模调数据上报;成功返回0,失败返回-1 19 | */ 20 | int reportStat(NodeStat stat); 21 | }; 22 | 23 | }; 24 | 25 | -------------------------------------------------------------------------------- /api/java/src/TseerAgentComm.tars: -------------------------------------------------------------------------------- 1 | /************************************************************* 2 | * 文件定义了api向 TseerAgent通信需的数据类型 3 | *************************************************************/ 4 | 5 | module Tseer 6 | { 7 | //获取方式 8 | enum LB_GET_TYPE 9 | { 10 | GET_IDC, //按IDC 11 | GET_SET, //按set 12 | GET_ALL, //全部获取 13 | }; 14 | 15 | enum LB_TYPE 16 | { 17 | LB_TYPE_LOOP, 18 | LB_TYPE_RANDOM, 19 | LB_TYPE_STATIC_WEIGHT, 20 | LB_TYPE_CST_HASH, 21 | LB_TYPE_ALL 22 | }; 23 | 24 | //向Agent查询服务节点的数据结构 25 | struct AgentRouterRequest 26 | { 27 | 1 optional LB_GET_TYPE getType; //获取方式,必填 28 | 2 optional LB_TYPE lbType; //负载均衡方式,按照需要填写 29 | 3 optional string obj; //请求服务路由名称,必填 30 | 4 optional string setname; //set信息,当按照SET方式获取时必填 31 | 5 optional long tid; //请求的线程Id,选填 32 | 6 optional string apiVer; //API的版本号的版本号,选填 33 | 7 optional long hashKey; //hash key,选择哈希负载均衡时必填 34 | 8 optional string identifier; //进程号,用于区分客户端 35 | }; 36 | 37 | //服务节点信息 38 | struct RouterNodeInfo 39 | { 40 | 1 optional string ip; //服务ip地址 41 | 2 optional int port; //端口 42 | 3 optional bool isTcp; //是否使用TCP,否则为UDP 43 | 4 optional int weight; //静态权重 44 | 5 optional string setname; //set信息,只当节点开启了set才有 45 | }; 46 | 47 | //从Agent获取服务节点的数据结构 48 | struct AgentRouterResponse 49 | { 50 | 1 optional LB_GET_TYPE getType; //获取方式(已废弃) 51 | 2 optional string obj; //服务路由名称 52 | 3 optional string setname; //set信息 53 | 4 optional vector resultList; //服务节点信息 54 | 5 optional int expireInterval = 60; 55 | }; 56 | 57 | //上报调用状态的数据结构 58 | struct NodeStat { 59 | 1 optional string localIp; //本机ip 60 | 2 optional int timeCost; //调用耗时 61 | 3 optional int ret; //调用返回错误码 62 | 4 optional string moduleName; //主调模块名称 63 | 5 optional string ip; //被调服务ip 64 | 6 optional int port; //被调服务port 65 | 7 optional string obj; //被调服务路由名称 66 | 8 optional bool isTcp; //是否使用TCP,false为UDP 67 | 9 optional string funcName; //函数名 68 | 10 optional string version; //tseerapi版本号 69 | 11 optional LB_TYPE lbType; //负载均衡方式 70 | 12 optional LB_GET_TYPE getType; //获取方式 71 | 13 optional string identifier; //进程号,用于区分客户端 72 | }; 73 | }; 74 | -------------------------------------------------------------------------------- /api/java/src/main/java/com/qq/cloud/router/client/CallResponse.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tseer available. 3 | * 4 | * Copyright (C) 2018 THL A29 Limited, a Tencent company. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | package com.qq.cloud.router.client; 18 | 19 | public enum CallResponse { 20 | CALL_SUCCESS(0), 21 | CALL_FAIL(-1), 22 | CALL_TIMEOUT(-2); 23 | 24 | private int callResponse; 25 | 26 | private CallResponse(int callResponse) { 27 | this.callResponse = callResponse; 28 | } 29 | 30 | public int getCallResponse() { 31 | return callResponse; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /api/java/src/main/java/com/qq/cloud/router/client/LBGetType.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tseer available. 3 | * 4 | * Copyright (C) 2018 THL A29 Limited, a Tencent company. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | package com.qq.cloud.router.client; 18 | 19 | public enum LBGetType { 20 | LB_GET_IDC(0), 21 | LB_GET_SET(1), 22 | LB_GET_ALL(2); 23 | 24 | private final int lbGetType; 25 | 26 | private LBGetType(int lbGetType) { 27 | this.lbGetType = lbGetType; 28 | } 29 | 30 | public int getLBGetType() { 31 | return lbGetType; 32 | } 33 | 34 | public static LBGetType convert(int value) { 35 | for(LBGetType v : values()) { 36 | if(v.getLBGetType() == value) { 37 | return v; 38 | } 39 | } 40 | return null; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /api/java/src/main/java/com/qq/cloud/router/client/LBType.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tseer available. 3 | * 4 | * Copyright (C) 2018 THL A29 Limited, a Tencent company. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | package com.qq.cloud.router.client; 18 | 19 | public enum LBType { 20 | LB_TYPE_LOOP(0), 21 | LB_TYPE_RANDOM(1), 22 | LB_TYPE_STATIC_WEIGHT(2), 23 | LB_TYPE_CST_HASH(3), 24 | LB_TYPE_ALL(4); 25 | 26 | private final int lbType; 27 | 28 | private LBType(int lbGetType) { 29 | this.lbType = lbGetType; 30 | } 31 | 32 | public int getLBType() { 33 | return lbType; 34 | } 35 | 36 | public static LBType convert(int value) { 37 | for(LBType v : values()) { 38 | if(v.getLBType() == value) { 39 | return v; 40 | } 41 | } 42 | return null; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /api/java/src/main/java/com/qq/cloud/router/client/Result.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tseer available. 3 | * 4 | * Copyright (C) 2018 THL A29 Limited, a Tencent company. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | package com.qq.cloud.router.client; 18 | 19 | public class Result { 20 | 21 | int ret; 22 | T data; 23 | 24 | public int getRet() { 25 | return ret; 26 | } 27 | 28 | public void setRet(int ret) { 29 | this.ret = ret; 30 | } 31 | 32 | public T getData() { 33 | return data; 34 | } 35 | 36 | public void setData(T data) { 37 | this.data = data; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /api/java/src/main/java/com/qq/cloud/router/client/Router.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tseer available. 3 | * 4 | * Copyright (C) 2018 THL A29 Limited, a Tencent company. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | package com.qq.cloud.router.client; 18 | 19 | public interface Router { 20 | 21 | /** 22 | * 初始化路由,如果无特殊需求不需要手动调用 23 | * @param cfg 初始化配置 24 | */ 25 | void init(RouterConfig cfg); 26 | 27 | /** 28 | * 获取单个节点 29 | * @param req 路由请求 30 | * @return 包含目标节点的ip,port等信息和返回描述信息 31 | */ 32 | Result getRouter(RouterRequest req); 33 | 34 | /** 35 | * 获取所有目标节点 36 | * @param req 路由请求 37 | * @return 目标节点列表 38 | */ 39 | Result getRouters(RoutersRequest req); 40 | 41 | /** 42 | * 模调数据上报接口 43 | * @param req 路由请求 44 | * @param res 路由回复 45 | * @param ret 调用被调服务的返回值 46 | * @param timecost 调用被调服务花费的时间,单位毫秒 47 | * @return 描述信息 48 | */ 49 | Result resultReport(RouterRequest req, RouterResponse res, int ret, long timecost); 50 | } 51 | -------------------------------------------------------------------------------- /api/java/src/main/java/com/qq/cloud/router/client/RouterFactory.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tseer available. 3 | * 4 | * Copyright (C) 2018 THL A29 Limited, a Tencent company. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | package com.qq.cloud.router.client; 18 | 19 | import com.qq.cloud.router.client.impl.AgentRouterImpl; 20 | import com.qq.cloud.router.client.impl.ApiRouterImpl; 21 | import com.qq.cloud.router.client.util.stat.StatManager; 22 | 23 | public class RouterFactory { 24 | 25 | private static final RouterFactory instance = new RouterFactory(); 26 | 27 | private RouterFactory() {} 28 | 29 | public static RouterFactory getInstance() { 30 | return instance; 31 | } 32 | 33 | public Router createAgentRouter() { 34 | return createAgentRouter(new RouterConfig()); 35 | } 36 | 37 | public Router createAgentRouter(RouterConfig config) { 38 | AgentRouterImpl agentRouterImpl = new AgentRouterImpl(); 39 | config.setRouterLocater("Tseer.TseerAgent.RouterObj@udp -h 127.0.0.1 -p 8865 -t 60000"); 40 | config.setStatObj("Tseer.TseerAgent.RouterObj@udp -h 127.0.0.1 -p 8865 -t 60000"); 41 | agentRouterImpl.init(config); 42 | return agentRouterImpl; 43 | } 44 | 45 | public Router createApiRouter() { 46 | return createApiRouter(new RouterConfig()); 47 | } 48 | 49 | public Router createApiRouter(StatManager statManager) { 50 | RouterConfig config = new RouterConfig(); 51 | config.setStatManagerImpl(statManager); 52 | return createAgentRouter(config); 53 | } 54 | 55 | public Router createApiRouter(RouterConfig config) { 56 | ApiRouterImpl apiRouterImpl = new ApiRouterImpl(); 57 | apiRouterImpl.init(config); 58 | return apiRouterImpl; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /api/java/src/main/java/com/qq/cloud/router/client/RouterResponse.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tseer available. 3 | * 4 | * Copyright (C) 2018 THL A29 Limited, a Tencent company. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | package com.qq.cloud.router.client; 18 | 19 | 20 | 21 | public class RouterResponse { 22 | 23 | private ServerNode serverNode; 24 | private String responseMsg; 25 | 26 | public ServerNode getServerNode() { 27 | return serverNode; 28 | } 29 | public void setServerNode(ServerNode serverNode) { 30 | this.serverNode = serverNode; 31 | } 32 | public String getResponseMsg() { 33 | return responseMsg; 34 | } 35 | public void setResponseMsg(String responseMsg) { 36 | this.responseMsg = responseMsg; 37 | } 38 | public String getIP() { 39 | if (serverNode == null) 40 | return null; 41 | return serverNode.getsIP(); 42 | } 43 | public int getPort() { 44 | if (serverNode == null) 45 | return -1; 46 | return serverNode.getPort(); 47 | } 48 | public int getTimeout() { 49 | if (serverNode == null) 50 | return -1; 51 | return serverNode.getTimeout(); 52 | } 53 | public boolean isbTcp() { 54 | if (serverNode == null) 55 | return false; 56 | return serverNode.isbTcp(); 57 | } 58 | public int getWeight() { 59 | if (serverNode == null) 60 | return 0; 61 | return serverNode.getWeight(); 62 | } 63 | public String getSet() { 64 | if (serverNode == null) 65 | return null; 66 | return serverNode.getSet(); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /api/java/src/main/java/com/qq/cloud/router/client/RoutersResponse.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tseer available. 3 | * 4 | * Copyright (C) 2018 THL A29 Limited, a Tencent company. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | package com.qq.cloud.router.client; 18 | 19 | import java.util.List; 20 | 21 | public class RoutersResponse { 22 | 23 | private String ResponseMsg; 24 | private List node; 25 | 26 | public String getResponseMsg() { 27 | return ResponseMsg; 28 | } 29 | public void setResponseMsg(String responseMsg) { 30 | ResponseMsg = responseMsg; 31 | } 32 | public List getNode() { 33 | return node; 34 | } 35 | public void setNode(List node) { 36 | this.node = node; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /api/java/src/main/java/com/qq/cloud/router/client/faulttolerant/RouterNodeAliveChecker.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tseer available. 3 | * 4 | * Copyright (C) 2018 THL A29 Limited, a Tencent company. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | package com.qq.cloud.router.client.faulttolerant; 18 | 19 | import java.util.concurrent.ConcurrentHashMap; 20 | 21 | 22 | import com.qq.cloud.router.client.ServerNode; 23 | 24 | public class RouterNodeAliveChecker { 25 | 26 | private static final ConcurrentHashMap cache_state = new ConcurrentHashMap(); 27 | 28 | public static RouterNodeAliveStat get(ServerNode node) { 29 | RouterNodeAliveStat routerNodeAliveStat = cache_state.get(node); 30 | if (routerNodeAliveStat == null) { 31 | routerNodeAliveStat = new RouterNodeAliveStat(node); 32 | cache_state.putIfAbsent(node, routerNodeAliveStat); 33 | routerNodeAliveStat = cache_state.get(node); 34 | } 35 | return routerNodeAliveStat; 36 | } 37 | 38 | public static boolean statisticCallResult(int ret, ServerNode node, RouterNodeAliveConfig config) { 39 | RouterNodeAliveStat routerNodeAliveStat = get(node); 40 | routerNodeAliveStat.statisticCallResult(ret, config); 41 | return routerNodeAliveStat.isAlive(); 42 | } 43 | 44 | public static boolean isAlive(ServerNode node) { 45 | RouterNodeAliveStat routerNodeAliveStat = get(node); 46 | return routerNodeAliveStat.isAlive(); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /api/java/src/main/java/com/qq/cloud/router/client/loadblance/LoadBlanceContext.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tseer available. 3 | * 4 | * Copyright (C) 2018 THL A29 Limited, a Tencent company. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | package com.qq.cloud.router.client.loadblance; 18 | 19 | public interface LoadBlanceContext { 20 | 21 | Object getAttachment(String key); 22 | 23 | Object getAttachment(String key, Object defaultvalue); 24 | 25 | Object[] getAttachments(); 26 | } 27 | -------------------------------------------------------------------------------- /api/java/src/main/java/com/qq/cloud/router/client/loadblance/LoadBlanceStrategy.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tseer available. 3 | * 4 | * Copyright (C) 2018 THL A29 Limited, a Tencent company. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | package com.qq.cloud.router.client.loadblance; 18 | 19 | import java.util.Collection; 20 | 21 | import com.qq.cloud.router.client.Result; 22 | import com.qq.cloud.router.client.RouterResponse; 23 | import com.qq.cloud.router.client.ServerNode; 24 | 25 | public interface LoadBlanceStrategy { 26 | 27 | /** 28 | * 选取服务节点 29 | * @param nodes 本地缓存的服务节点列表 30 | * @param context 负载均衡的上下文 31 | * @return 选择的节点,使用Result包装,可以获取结果编号 32 | */ 33 | public Result selectRouteNode(Collection nodes, LoadBlanceContext context); 34 | 35 | } 36 | -------------------------------------------------------------------------------- /api/java/src/main/java/com/qq/cloud/router/client/loadblance/impl/ConsistentHashingContext.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tseer available. 3 | * 4 | * Copyright (C) 2018 THL A29 Limited, a Tencent company. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | package com.qq.cloud.router.client.loadblance.impl; 18 | 19 | import java.util.SortedMap; 20 | import java.util.TreeMap; 21 | 22 | import com.qq.cloud.router.client.ServerNode; 23 | 24 | public class ConsistentHashingContext extends GenericLoadBlanceContext { 25 | 26 | public ConsistentHashingContext() { 27 | } 28 | 29 | public ConsistentHashingContext(long hashKey, SortedMap circle) { 30 | setHashKey(hashKey); 31 | setCircle(circle); 32 | } 33 | 34 | public void setHashKey(long hashKey) { 35 | setAttachment("hashKey", hashKey); 36 | } 37 | 38 | public long getHashKey() { 39 | return (Long)getAttachment("hashKey", 0L); 40 | } 41 | 42 | public void setCircle(SortedMap circle) { 43 | setAttachment("circle", circle); 44 | } 45 | 46 | @SuppressWarnings("unchecked") 47 | public SortedMap getCircle() { 48 | return (SortedMap)getAttachment("circle", new TreeMap()); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /api/java/src/main/java/com/qq/cloud/router/client/loadblance/impl/ConsistentHashingFunction.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tseer available. 3 | * 4 | * Copyright (C) 2018 THL A29 Limited, a Tencent company. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | package com.qq.cloud.router.client.loadblance.impl; 18 | 19 | import java.io.UnsupportedEncodingException; 20 | import java.security.MessageDigest; 21 | import java.security.NoSuchAlgorithmException; 22 | 23 | 24 | public class ConsistentHashingFunction { 25 | 26 | public long hash(String key) { 27 | MessageDigest md5 = null; 28 | try { 29 | md5 = MessageDigest.getInstance("MD5"); 30 | } catch (NoSuchAlgorithmException e) { 31 | e.printStackTrace(); 32 | } 33 | 34 | md5.reset(); 35 | byte[] b = null; 36 | try { 37 | b = key.getBytes("UTF-8"); 38 | } catch (UnsupportedEncodingException e) { 39 | e.printStackTrace(); 40 | } 41 | md5.update(b); 42 | byte[] digest = md5.digest(); 43 | return byte2Int(digest); 44 | } 45 | 46 | private long byte2Int(byte[] b) { 47 | long result = 0; 48 | for (int i = 0; i < b.length; i++) { 49 | result += (b[i] & 0xff) << (24-8*i); 50 | } 51 | return result & 0xffffffffL; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /api/java/src/main/java/com/qq/cloud/router/client/loadblance/impl/RandomSelectContext.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tseer available. 3 | * 4 | * Copyright (C) 2018 THL A29 Limited, a Tencent company. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | package com.qq.cloud.router.client.loadblance.impl; 18 | 19 | public class RandomSelectContext extends GenericLoadBlanceContext { 20 | 21 | } 22 | -------------------------------------------------------------------------------- /api/java/src/main/java/com/qq/cloud/router/client/loadblance/impl/RoundRobinContext.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tseer available. 3 | * 4 | * Copyright (C) 2018 THL A29 Limited, a Tencent company. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | package com.qq.cloud.router.client.loadblance.impl; 18 | 19 | import java.util.concurrent.atomic.AtomicInteger; 20 | 21 | public class RoundRobinContext extends GenericLoadBlanceContext { 22 | 23 | public RoundRobinContext() {} 24 | 25 | public RoundRobinContext(AtomicInteger index) { 26 | setAttachment("RRIndex", index); 27 | } 28 | 29 | public void setIndex(AtomicInteger index) { 30 | setAttachment("RRIndex", index); 31 | } 32 | 33 | public AtomicInteger getIndex() { 34 | return (AtomicInteger) getAttachment("RRIndex", 0); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /api/java/src/main/java/com/qq/cloud/router/client/loadblance/impl/StaticWeightRoundRobinContext.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tseer available. 3 | * 4 | * Copyright (C) 2018 THL A29 Limited, a Tencent company. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | package com.qq.cloud.router.client.loadblance.impl; 18 | 19 | import java.util.Map; 20 | 21 | import com.qq.cloud.router.client.ServerNode; 22 | 23 | public class StaticWeightRoundRobinContext extends GenericLoadBlanceContext { 24 | 25 | public StaticWeightRoundRobinContext() {} 26 | 27 | public StaticWeightRoundRobinContext(Map current_weights) { 28 | setAttachment("current_weights", current_weights); 29 | } 30 | 31 | public void setCurrent_weights(Map current_weights) { 32 | setAttachment("current_weights", current_weights); 33 | } 34 | 35 | @SuppressWarnings("unchecked") 36 | public Map getCurrent_weights() { 37 | return (Map) getAttachment("current_weights", null); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /api/java/src/main/java/com/qq/cloud/router/client/share/tseer/LB_GET_TYPE.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tseer available. 3 | * 4 | * Copyright (C) 2018 THL A29 Limited, a Tencent company. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | // ********************************************************************** 18 | // This file was generated by a TARS parser! 19 | // TARS version 1.0.1. 20 | // ********************************************************************** 21 | 22 | package com.qq.cloud.router.client.share.tseer; 23 | 24 | public enum LB_GET_TYPE { 25 | 26 | GET_IDC(0), 27 | GET_SET(1), 28 | GET_ALL(2); 29 | 30 | private final int value; 31 | 32 | private LB_GET_TYPE(int value) { 33 | this.value = value; 34 | } 35 | 36 | public int value() { 37 | return this.value; 38 | } 39 | 40 | @Override 41 | public String toString() { 42 | return this.name() + ":" + this.value; 43 | } 44 | 45 | public static LB_GET_TYPE convert(int value) { 46 | for(LB_GET_TYPE v : values()) { 47 | if(v.value() == value) { 48 | return v; 49 | } 50 | } 51 | return null; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /api/java/src/main/java/com/qq/cloud/router/client/share/tseer/LB_TYPE.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tseer available. 3 | * 4 | * Copyright (C) 2018 THL A29 Limited, a Tencent company. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | // ********************************************************************** 18 | // This file was generated by a TARS parser! 19 | // TARS version 1.0.1. 20 | // ********************************************************************** 21 | 22 | package com.qq.cloud.router.client.share.tseer; 23 | 24 | public enum LB_TYPE { 25 | 26 | LB_TYPE_LOOP(0), 27 | LB_TYPE_RANDOM(1), 28 | LB_TYPE_STATIC_WEIGHT(2), 29 | LB_TYPE_CST_HASH(3), 30 | LB_TYPE_ALL(4); 31 | 32 | private final int value; 33 | 34 | private LB_TYPE(int value) { 35 | this.value = value; 36 | } 37 | 38 | public int value() { 39 | return this.value; 40 | } 41 | 42 | @Override 43 | public String toString() { 44 | return this.name() + ":" + this.value; 45 | } 46 | 47 | public static LB_TYPE convert(int value) { 48 | for(LB_TYPE v : values()) { 49 | if(v.value() == value) { 50 | return v; 51 | } 52 | } 53 | return null; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /api/java/src/main/java/com/qq/cloud/router/client/share/tseer/RouterPrxCallback.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tseer available. 3 | * 4 | * Copyright (C) 2018 THL A29 Limited, a Tencent company. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | // ********************************************************************** 18 | // This file was generated by a TARS parser! 19 | // TARS version 1.0.1. 20 | // ********************************************************************** 21 | 22 | package com.qq.cloud.router.client.share.tseer; 23 | 24 | import com.qq.tars.rpc.protocol.tars.support.TarsAbstractCallback; 25 | 26 | public abstract class RouterPrxCallback extends TarsAbstractCallback { 27 | 28 | public abstract void callback_getRouterNode(int ret, AgentRouterResponse rsp); 29 | 30 | public abstract void callback_reportStat(int ret); 31 | 32 | } 33 | -------------------------------------------------------------------------------- /api/java/src/main/java/com/qq/cloud/router/client/util/CommonUtils.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tseer available. 3 | * 4 | * Copyright (C) 2018 THL A29 Limited, a Tencent company. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | package com.qq.cloud.router.client.util; 18 | 19 | import java.lang.management.ManagementFactory; 20 | 21 | public class CommonUtils { 22 | 23 | public static String getCurrentPid() { 24 | return ManagementFactory.getRuntimeMXBean().getName().split("@")[0]; 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /api/java/src/main/java/com/qq/cloud/router/client/util/ConcurrentDateUtil.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tseer available. 3 | * 4 | * Copyright (C) 2018 THL A29 Limited, a Tencent company. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | package com.qq.cloud.router.client.util; 18 | 19 | import java.text.DateFormat; 20 | import java.text.ParseException; 21 | import java.text.SimpleDateFormat; 22 | import java.util.Date; 23 | 24 | public class ConcurrentDateUtil { 25 | 26 | private static ThreadLocal threadLocal = new ThreadLocal() { 27 | @Override 28 | protected DateFormat initialValue() { 29 | return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 30 | } 31 | }; 32 | 33 | public static Date parse(String dateStr) throws ParseException { 34 | return threadLocal.get().parse(dateStr); 35 | } 36 | 37 | public static String format(Date date) { 38 | return threadLocal.get().format(date); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /api/java/src/main/java/com/qq/cloud/router/client/util/LogUtils.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tseer available. 3 | * 4 | * Copyright (C) 2018 THL A29 Limited, a Tencent company. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | package com.qq.cloud.router.client.util; 18 | 19 | import java.io.File; 20 | 21 | import com.qq.tars.support.log.Logger; 22 | import com.qq.tars.support.log.Logger.LogType; 23 | import com.qq.tars.support.log.LoggerFactory; 24 | 25 | public class LogUtils { 26 | 27 | static { 28 | File log_dir = new File(Constants.DEFAULE_LOG_PATH); 29 | if (!log_dir.exists()) { 30 | log_dir.mkdir(); 31 | } 32 | LoggerFactory.config("info", Constants.DEFAULE_LOG_PATH); 33 | } 34 | 35 | private static final Logger logger = Logger.getLogger("Seer", LogType.LOCAL); 36 | 37 | public static void info(Object... args) { 38 | logger.info(join(args)); 39 | } 40 | 41 | public static void debug(Object... args) { 42 | logger.debug(join(args)); 43 | } 44 | 45 | public static void error(Throwable e, Object... args) { 46 | logger.error(join(args), e); 47 | } 48 | 49 | private static String join(Object... args) { 50 | return joinAll("|", true, args); 51 | } 52 | 53 | private static String joinAll(String separator, boolean startFirst, Object... args) { 54 | StringBuilder format = new StringBuilder(); 55 | if (startFirst) { 56 | format.append(separator); 57 | } 58 | for (int i = 0, len = args.length; i < len; i++) { 59 | format.append("%s"); 60 | if (i < (len - 1)) { 61 | format.append(separator); 62 | } 63 | } 64 | return String.format(format.toString(), args); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /api/java/src/main/java/com/qq/cloud/router/client/util/cache/CacheNodeManager.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tseer available. 3 | * 4 | * Copyright (C) 2018 THL A29 Limited, a Tencent company. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | package com.qq.cloud.router.client.util.cache; 18 | 19 | import com.qq.cloud.router.client.util.CacheNodeCollection; 20 | 21 | public interface CacheNodeManager { 22 | 23 | public CacheNodeCollection getCacheNodeCollection(T index); 24 | 25 | public void setCacheNodeCollection(T index, CacheNodeCollection value); 26 | 27 | public int init(T index); 28 | 29 | public void refresh(T index); 30 | } 31 | -------------------------------------------------------------------------------- /api/java/src/main/java/com/qq/cloud/router/client/util/stat/ApiProxyStat.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tseer available. 3 | * 4 | * Copyright (C) 2018 THL A29 Limited, a Tencent company. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | package com.qq.cloud.router.client.util.stat; 18 | 19 | import com.qq.cloud.router.client.util.ApiStatUtils; 20 | import com.qq.tars.common.util.StringUtils; 21 | import com.qq.tars.support.stat.ProxyStat; 22 | import com.qq.tars.support.stat.ProxyStatHead; 23 | 24 | public class ApiProxyStat { 25 | 26 | private static final ApiProxyStat instance = new ApiProxyStat(); 27 | 28 | 29 | public static ApiProxyStat getInstance() { 30 | return instance; 31 | } 32 | 33 | private ApiProxyStat() { 34 | } 35 | 36 | public void addInvokeTime(ProxyStat proxyStat, String moduleName, String objectName, String setDivision, String masterSet, String methodName, 37 | String masterIp, String slaveIp, int slavePort, int result, long costTimeMill) { 38 | ProxyStatHead head = null; 39 | if (masterSet != null) { 40 | String[] masterSetInfo = StringUtils.split(masterSet, "."); 41 | if (masterSetInfo != null && masterSetInfo.length == 3) { 42 | head = ApiStatUtils.getHead(moduleName, objectName, methodName, masterIp, slaveIp, slavePort, result, masterSetInfo[0], masterSetInfo[1], masterSetInfo[2], setDivision); 43 | } else { 44 | head = ApiStatUtils.getHead(moduleName, objectName, methodName, masterIp, slaveIp, slavePort, result, "", "", "", setDivision); 45 | } 46 | } else { 47 | head = ApiStatUtils.getHead(moduleName, objectName, methodName, masterIp, slaveIp, slavePort, result, "", "", "", setDivision); 48 | } 49 | proxyStat.addInvokeTime(head, costTimeMill, result); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /api/java/src/main/java/com/qq/cloud/router/client/util/stat/StatManager.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tseer available. 3 | * 4 | * Copyright (C) 2018 THL A29 Limited, a Tencent company. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | package com.qq.cloud.router.client.util.stat; 18 | 19 | import com.qq.cloud.router.client.RouterRequest; 20 | import com.qq.cloud.router.client.RouterResponse; 21 | 22 | public interface StatManager { 23 | 24 | public void reportStat(RouterRequest req, RouterResponse res, int ret, long costtime); 25 | } 26 | -------------------------------------------------------------------------------- /build/cmake/change_conf.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | seer_basedir=$1 4 | local_ip=$2 5 | storage=$3 6 | etcd_endpoint=$4 7 | regport=$5 8 | queryport=$6 9 | apiport=$7 10 | 11 | TIMESTAMP=`date "+%F %T"` 12 | # edit TseerServer config 13 | 14 | sed -i "s#installpath=.*#installpath=${seer_basedir}#g" ${seer_basedir}/Tseer/TseerServer/conf/TseerServer.conf 15 | sed -i "s#localip=.*#localip=${local_ip}#g" ${seer_basedir}/Tseer/TseerServer/conf/TseerServer.conf 16 | sed -i "s#store=.*#store=${storage}#g" ${seer_basedir}/Tseer/TseerServer/conf/TseerServer.conf 17 | sed -i "s#host=.*#host=${etcd_endpoint}#g" ${seer_basedir}/Tseer/TseerServer/conf/TseerServer.conf 18 | sed -i "s#regport=.*#regport=${regport}#g" ${seer_basedir}/Tseer/TseerServer/conf/TseerServer.conf 19 | sed -i "s#queryport=.*#queryport=${queryport}#g" ${seer_basedir}/Tseer/TseerServer/conf/TseerServer.conf 20 | sed -i "s#apiport=.*#apiport=${apiport}#g" ${seer_basedir}/Tseer/TseerServer/conf/TseerServer.conf 21 | # edit installscript 22 | sed -i "s#download.seer.wsd.com#${local_ip}:${apiport}#" ${seer_basedir}/Tseer/TseerServer/bin/installscript.tgz 23 | 24 | if [ "$?" -ne "0" ];then 25 | echo "[ERROR] $TIMESTAMP Change conf failed." 26 | exit 1 27 | fi 28 | 29 | 30 | # edit TseerAgent config 31 | sed -i "s#installpath=.*#installpath=${seer_basedir}#g" ${seer_basedir}/Tseer/TseerAgent/conf/TseerAgent.conf 32 | sed -i "s#localip=.*#localip=${local_ip}#g" ${seer_basedir}/Tseer/TseerAgent/conf/TseerAgent.conf 33 | sed -i "s#locator=.*#locator=Tseer.TseerServer.QueryObj@tcp -h ${local_ip} -p ${queryport}#g" ${seer_basedir}/Tseer/TseerAgent/conf/TseerAgent.conf 34 | 35 | 36 | if [ "$?" -ne "0" ];then 37 | echo "[ERROR] $TIMESTAMP Change conf failed." 38 | exit 1 39 | fi 40 | 41 | echo "[SUCC] $TIMESTAMP Change conf successfully." 42 | -------------------------------------------------------------------------------- /build/cmake/deploy_tars.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | TIMESTAMP=`date "+%F %T"` 4 | 5 | if [ -n "Tars" -a -e "Tars" ];then 6 | echo "[INFO] $TIMESTAMP we have already downloaded tars" 7 | else 8 | echo "[INFO] $TIMESTAMP downloading tars..." 9 | git clone https://github.com/Tencent/Tars.git --recurse-submodules=cpp >/dev/null 10 | if [ "$?" -ne "0" ]; then 11 | echo "[ERROR] $TIMESTAMP Download Tars failed." 12 | exit 2 13 | fi 14 | fi 15 | 16 | 17 | # process Tars source file 18 | rm -f ./Tars/cpp/util/src/tc_gzip.cpp 19 | rm -f ./Tars/cpp/util/src/tc_mysql.cpp 20 | sed -i '/framework/d' ./Tars/cpp/CMakeLists.txt 21 | sed -i '/INSTALL/d' ./Tars/cpp/CMakeLists.txt 22 | sed -i '/test/d' ./Tars/cpp/CMakeLists.txt 23 | 24 | # building 25 | mkdir -p ../thirdparty 26 | INSTALLTARSPATH=$(pwd)/../thirdparty/tars/ 27 | 28 | TIMESTAMP=`date "+%F %T"` 29 | echo "[INFO] $TIMESTAMP building tars into $INSTALLTARSPATH ..." 30 | cd ./Tars/cpp && cmake . -DCMAKE_INSTALL_PREFIX=$INSTALLTARSPATH && make && make install; 31 | if [ "$?" -ne "0" ]; then 32 | echo "[ERROR] $TIMESTAMP Compile Tars failed." 33 | exit 3 34 | fi 35 | 36 | rm -rf Tars 37 | 38 | echo "[SUCC] $TIMESTAMP Successfully install tars in $INSTALLTARSPATH" 39 | 40 | -------------------------------------------------------------------------------- /build/cmake/generate_utils.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | tseer_basedir=$1 4 | 5 | for item in TseerServer TseerAgent 6 | do 7 | mkdir ${tseer_basedir}/Tseer/${item}/util &>/dev/null 8 | sed "s#SEER_BASEDIR=.*#SEER_BASEDIR=${tseer_basedir}#g; s#TARGET=.*#TARGET=${item}#g" ./cmake/start.sh >${tseer_basedir}/Tseer/${item}/util/start.sh 9 | sed "s#SEER_BASEDIR=.*#SEER_BASEDIR=${tseer_basedir}#g; s#TARGET=.*#TARGET=${item}#g" ./cmake/stop.sh >${tseer_basedir}/Tseer/${item}/util/stop.sh 10 | done 11 | 12 | cp ./cmake/mon_TseerAgent.sh ${tseer_basedir}/Tseer/TseerAgent/util/mon_TseerAgent.sh &>/dev/null 13 | -------------------------------------------------------------------------------- /build/cmake/local_install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | TIMESTAMP=`date "+%F %T"` 4 | seer_basedir=$1 5 | 6 | mkdir -p $seer_basedir/Tseer/ &>/dev/null 7 | 8 | current_path=`pwd` 9 | current_dir=`dirname $current_path` 10 | 11 | if [ "$current_dir" == "$1/Tseer" ];then 12 | echo "[ERROR] $TIMESTAMP install path and source at same path" 13 | exit 1 14 | fi 15 | 16 | rm -fr $seer_basedir/Tseer/{api,TseerServer,TseerAgent} 17 | cp -fr ../{api,TseerServer,TseerAgent} $seer_basedir/Tseer &>./seer_make.log 18 | cp ./cmake/installscript.tgz ${seer_basedir}/Tseer/TseerServer/bin/ 19 | 20 | if [ "$?" -ne 0 ]; then 21 | echo "[ERROR] $TIMESTAMP local install seer failed, see log seer_make.log." 22 | exit 1 23 | fi 24 | chmod a+x ${seer_basedir}/Tseer/TseerServer/bin/TseerServer 25 | echo "[SUCC] $TIMESTAMP Successfully install seer." 26 | -------------------------------------------------------------------------------- /build/cmake/make_install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | TIMESTAMP=`date "+%F %T"` 4 | cmake_args=$@ 5 | 6 | install_path=`echo $cmake_args | tr -s ' ' '\n' | awk -F= '/INSTALL/{print $2}'` 7 | 8 | cp CMakeLists.txt ../ 9 | echo "[INFO] $TIMESTAMP start build tseer..." 10 | yum install gcc make gcc-c++ -y &>/dev/null 11 | cd .. 12 | cmake . ${cmake_args} &>>./build/tseer_make.log 13 | 14 | if [ "$?" -ne 0 ]; then 15 | echo "[ERROR] $TIMESTAMP cmake build seer failed, see log tseer_make.log." 16 | exit 1 17 | fi 18 | 19 | chmod a+x thirdparty/tars/tools/tars2cpp 20 | make &>>./build/tseer_make.log 21 | make install &>>./build/tseer_make.log 22 | 23 | if [ "$?" -ne 0 ]; then 24 | echo "[ERROR] $TIMESTAMP make install seer failed, see log tseer_make.log." 25 | exit 1 26 | fi 27 | echo "[INFO] $TIMESTAMP succ install tseer." 28 | 29 | # cp installscript to TseerServer 30 | mkdir -p ${install_path}/Tseer/TseerServer/{bin,conf} 31 | cp TseerServer/TseerServer/conf/TseerServer.conf ${install_path}/Tseer/TseerServer/conf/ 32 | cp TseerServer/TseerServer/bin/TseerServer ${install_path}/Tseer/TseerServer/bin/ 33 | cp build/cmake/installscript.tgz ${install_path}/Tseer/TseerServer/bin/ 34 | 35 | # build api 36 | cd api/cplus/src/ 37 | mkdir -p ${install_path}/Tseer/api/cplus/{include,lib} 38 | cmake . &>/dev/null 39 | make &>/dev/null 40 | cd - 41 | cd api/cplus/Tseerapi/lib/ 42 | cp Tseer_api.h Tseer_comm.h ${install_path}/Tseer/api/cplus/include/ 43 | cp libtseerapi.a ${install_path}/Tseer/api/cplus/lib/ 44 | 45 | # buid java api 46 | 47 | # build agent 48 | cd - && cd TseerAgent/TseerAgent 49 | mkdir -p ${install_path}/Tseer/TseerAgent/{bin,conf,utils} 50 | cp -fr bin/TseerAgent ${install_path}/Tseer/TseerAgent/bin/ 51 | cp -fr conf/TseerAgent.conf ${install_path}/Tseer/TseerAgent/conf/ 52 | 53 | echo "[SUCC] $TIMESTAMP Successfully install seer." 54 | -------------------------------------------------------------------------------- /build/cmake/mon_TseerAgent.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | IP=`ip a s |awk '/inet/ { if (($2 !~ /127.0.0.1/) && ($2 !~ /::1/)) { print $2} }'| cut -d / -f 1` 4 | PORT=9765 5 | BASE_DIR=/usr/local/ 6 | 7 | # if you are good admin, you should add alert here! 8 | 9 | stop_server() 10 | { 11 | bash ${BASE_DIR}/Tseer/TseerAgent/util/stop.sh 12 | sleep 2 13 | bash ${BASE_DIR}/Tseer/TseerAgent/util/stop.sh 14 | ps -ef |grep "${BASE_DIR}/Tseer/TseerAgent/bin/TseerAgent"|grep -v grep >/dev/null 2>&1 15 | if test $? = 0; then 16 | bash ${BASE_DIR}/Tseer/TseerAgent/util/stop.sh 17 | sleep 1 18 | ps -ef |grep "${BASE_DIR}/Tseer/TseerAgent/bin/TseerAgent"|grep -v grep >/dev/null 2>&1 19 | if test $? = 0; then 20 | echo "stop fail" 21 | fi 22 | fi 23 | return 0 24 | } 25 | 26 | start_server() 27 | { 28 | bash ${BASE_DIR}/Tseer/TseerAgent/util/start.sh 29 | sleep 5 30 | ps -ef |grep "${BASE_DIR}/Tseer/TseerAgent/bin/TseerAgent"|grep -v grep >/dev/null 2>&1 31 | if [ "$?" -ne "0" ]; then 32 | return 1 33 | fi 34 | return 0 35 | } 36 | 37 | mon_process() 38 | { 39 | ps -ef |grep "${BASE_DIR}/Tseer/TseerAgent/bin/TseerAgent"|grep -v grep >/dev/null 2>&1 40 | if test $? = 1; then 41 | echo "`date +%F\ %T` the TseerAgent process is not exist" 42 | return 1 43 | else 44 | return 0 45 | fi 46 | } 47 | 48 | mon_port() 49 | { 50 | result1=`echo quit|telnet $IP $PORT 2>/dev/null` 51 | echo $result1 |grep -q "Escape character" 52 | if test $? = 0; then 53 | echo "`date +"%Y-%m-%d %H:%M:%S"` the port $PORT is good" 54 | return 0 55 | else 56 | echo "`date +"%Y-%m-%d %H:%M:%S"` the port $PORT is not answer" 57 | return 1 58 | fi 59 | } 60 | 61 | mon_process 62 | flag_process=$? 63 | if test $flag_process = 1; then 64 | stop_server 65 | start_server 66 | else 67 | mon_port 68 | flag_port=$? 69 | if test $flag_port = 1;then 70 | stop_server 71 | start_server 72 | else 73 | echo "TseerAgent process and port state is good" 74 | fi 75 | fi 76 | exit 0 77 | -------------------------------------------------------------------------------- /build/cmake/resolve_dependency.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | TIMESTAMP=`date "+%F %T"` 4 | 5 | echo "[INFO] $TIMESTAMP resolve depedency rapidjson..." 6 | git clone https://github.com/Tencent/rapidjson.git >/dev/null 7 | 8 | if [ "$?" -ne "0" ]; then 9 | echo "[ERROR] $TIMESTAMP Download rapidjson failed." 10 | exit 3 11 | fi 12 | 13 | mkdir -p ../thirdparty/ 14 | 15 | cp -rf rapidjson/include/rapidjson ../thirdparty/ 16 | rm -rf rapidjson 17 | 18 | echo "[SUCC] $TIMESTAMP Successfully resolve dependency" 19 | -------------------------------------------------------------------------------- /build/cmake/start.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | SEER_BASEDIR="/usr/local/" 4 | TARGET="TseerServer" 5 | 6 | bin="${SEER_BASEDIR}/Tseer/${TARGET}/bin/${TARGET}" 7 | conf="${SEER_BASEDIR}/Tseer/${TARGET}/conf/${TARGET}.conf" 8 | 9 | PID=`ps -eopid,cmd | grep "$bin"| grep "${TARGET}" | grep -v "grep" |awk '{print $1}'` 10 | 11 | if [ "$PID" != "" ]; then 12 | kill -9 $PID &>/dev/null 13 | fi 14 | 15 | ulimit -c unlimited 16 | nohup $bin --config=$conf 2>&1 & 17 | -------------------------------------------------------------------------------- /build/cmake/start_agent.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | SEER_BASEDIR=$1 4 | TIMESTAMP=`date "+%F %T"` 5 | if [ -f $SEER_BASEDIR/Tseer/TseerAgent/bin/TseerAgent ];then 6 | chmod +x $SEER_BASEDIR/Tseer/TseerAgent/util/stop.sh 7 | chmod +x $SEER_BASEDIR/Tseer/TseerAgent/util/start.sh 8 | sh $SEER_BASEDIR/Tseer/TseerAgent/util/stop.sh 9 | sh $SEER_BASEDIR/Tseer/TseerAgent/util/start.sh 10 | fi 11 | 12 | if [ "$?" -ne "0" ]; then 13 | echo "[ERROR] $TIMESTAMP starting TseerAgent failed." 14 | exit 1 15 | fi 16 | -------------------------------------------------------------------------------- /build/cmake/start_server.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | SEER_BASEDIR=$1 4 | TIMESTAMP=`date "+%F %T"` 5 | 6 | # start Tseer server 7 | chmod +x $SEER_BASEDIR/Tseer/TseerServer/util/stop.sh 8 | chmod +x $SEER_BASEDIR/Tseer/TseerServer/util/start.sh 9 | sh $SEER_BASEDIR/Tseer/TseerServer/util/stop.sh 10 | sh $SEER_BASEDIR/Tseer/TseerServer/util/start.sh 11 | if [ "$?" -ne "0" ]; then 12 | echo "[ERROR] $TIMESTAMP starting TseerServer failed." 13 | exit 1 14 | fi 15 | -------------------------------------------------------------------------------- /build/cmake/start_service.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | SEER_BASEDIR=$1 4 | TIMESTAMP=`date "+%F %T"` 5 | # start Tseer server 6 | chmod +x $SEER_BASEDIR/Tseer/TseerServer/util/stop.sh 7 | chmod +x $SEER_BASEDIR/Tseer/TseerServer/util/start.sh 8 | sh $SEER_BASEDIR/Tseer/TseerServer/util/stop.sh 9 | sh $SEER_BASEDIR/Tseer/TseerServer/util/start.sh 10 | 11 | if [ "$?" -ne "0" ]; then 12 | echo "[ERROR] $TIMESTAMP starting TseerServer failed." 13 | exit 1 14 | fi 15 | 16 | sleep 5 17 | PID=`ps -eopid,cmd | grep "TseerServer"| grep -v "grep" |awk '{print $1}'` 18 | 19 | if [ "$PID" != "" -a -f $SEER_BASEDIR/Tseer/TseerAgent/bin/TseerAgent ];then 20 | chmod +x $SEER_BASEDIR/Tseer/TseerAgent/util/stop.sh 21 | chmod +x $SEER_BASEDIR/Tseer/TseerAgent/util/start.sh 22 | sh $SEER_BASEDIR/Tseer/TseerAgent/util/stop.sh 23 | sh $SEER_BASEDIR/Tseer/TseerAgent/util/start.sh 24 | fi 25 | 26 | -------------------------------------------------------------------------------- /build/cmake/stop.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | 4 | SEER_BASEDIR="/usr/local/" 5 | TARGET="TseerServer" 6 | 7 | bin="${SEER_BASEDIR}/Tseer/${TARGET}/bin/${TARGET}" 8 | 9 | PID=`ps -eopid,cmd | grep "$bin"| grep "${TARGET}" | grep -v "grep" |awk '{print $1}'` 10 | 11 | if [ "$PID" != "" ]; then 12 | kill -9 $PID 13 | fi 14 | -------------------------------------------------------------------------------- /build/etcd/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/TSeer/1c92b1e08ddb16b777d992a1e38fd765b5104385/build/etcd/__init__.py -------------------------------------------------------------------------------- /build/etcd/check_etcd.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | TIMESTAMP=`date "+%F %T"` 4 | ETCD_WORKDIR=$1 5 | host=$2 6 | 7 | stat=`curl -s -m 5 ${host}:2379/health |grep 'true'` 8 | if [ -z "$stat" ]; then 9 | echo "[ERROR] $TIMESTAMP check etcd failed, see log ${ETCD_WORKDIR}/log" 10 | exit 1 11 | else 12 | echo "[SUCC] $TIMESTAMP Deploy and check etcd success." 13 | fi 14 | -------------------------------------------------------------------------------- /build/etcd/deploy_etcd.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # coding:utf8 3 | from commands import * 4 | from utils.get_os_info import get_ip 5 | from utils.vssh import execute_script 6 | import time 7 | 8 | def linenumber(): 9 | from inspect import currentframe 10 | cf = currentframe() 11 | return "%s:%s" % (__file__,cf.f_back.f_lineno) 12 | 13 | def install_etcd(iplist='localhost', cluster_port=2380, client_port=2379, node_prefix='test', basedir='/usr/local/etcd/'): 14 | if iplist == 'localhost': 15 | remote_run = False 16 | cluster_port_list = [cluster_port, cluster_port + 1000, cluster_port + 2000] 17 | client_port_list = [client_port, client_port + 1000, client_port + 2000] 18 | local_ip = get_ip() 19 | iplist = [local_ip for _ in xrange(3)] 20 | else: 21 | remote_run = True 22 | iplist = iplist.split(';') 23 | cluster_port_list = [2380 for _ in xrange(len(iplist))] 24 | client_port_list = [2379 for _ in xrange(len(iplist))] 25 | 26 | cluster_member = ','.join(["%s%s=http://%s:%s" % (node_prefix, i[0], i[1], i[2]) for i in zip(range(len(iplist)), iplist, cluster_port_list)]) 27 | rst = {} 28 | for i in xrange(len(iplist)): 29 | args = " {node_prefix}{id} {node_ip} {cluster_port} {client_port} {cluster_member} {etcd_basedir}".format( 30 | node_prefix=node_prefix, id=i, node_ip=iplist[i], 31 | cluster_port=cluster_port_list[i], client_port=client_port_list[i], 32 | cluster_member=cluster_member, 33 | etcd_basedir=basedir 34 | ) 35 | item_rst = execute_script(script="./etcd/deploy_etcd.sh", args=args, remote=remote_run, ip_list=[iplist[i], ]) 36 | for k, v in item_rst.items(): 37 | if not v['stat']: 38 | rst[k] = v 39 | #check the etcd installing 40 | args = "%s %s" % (basedir,get_ip()) 41 | time.sleep(3) 42 | tmp_rst = execute_script(script='./etcd/check_etcd.sh',args=args)['localhost'] 43 | stat, chk_rst = tmp_rst['stat'], tmp_rst['rst'] 44 | #if not stat: 45 | # return False, rst 46 | return True, chk_rst 47 | 48 | 49 | if __name__ == '__main__': 50 | print install_etcd('localhost', node_prefix='seer_etcd') 51 | 52 | -------------------------------------------------------------------------------- /build/etcd/deploy_etcd.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | ETCD_VER=v3.2.5 4 | DOWNLOAD_URL="https://github.com/coreos/etcd/releases/download" 5 | TIMESTAMP=`date "+%F %T"` 6 | ETCD_TMPDIR="/data/tseer_tmp/" 7 | #ETCD_TMPDIR="$HOME/tseer_tmp/" 8 | node_name=$1 9 | node_ip=$2 10 | cluster_port=$3 11 | client_port=$4 12 | cluster_member=$5 13 | ETCD_WORKDIR=$6 14 | CDIR=`pwd` 15 | 16 | LOCAL_ETCDFILE=`find $CDIR -name "*etcd*.tar.gz"` 17 | TMP_ETCDFILE=`find $ETCD_TMPDIR -name "*etcd*.tar.gz"` 18 | 19 | mkdir -p $ETCD_TMPDIR 20 | mkdir -p ${ETCD_WORKDIR}/{bin,datadir,log}/ 21 | cd $ETCD_TMPDIR 22 | 23 | echo $LOCAL_ETCDFILE 24 | if [ -n "$LOCAL_ETCDFILE" -a -e "$LOCAL_ETCDFILE" ];then 25 | echo "[INFO] $TIMESTAMP we has etcd $LOCAL_ETCDFILE" 26 | cp $LOCAL_ETCDFILE $ETCD_TMPDIR 27 | elif [ -n "$TMP_ETCDFILE" -a -e "$TMP_ETCDFILE" ];then 28 | echo "[INFO] $TIMESTAMP we has etcd $TMP_ETCDFILE" 29 | else 30 | LOCAL_ETCDFILE=etcd-${ETCD_VER}-linux-amd64.tar.gz 31 | echo "[INFO] $TIMESTAMP Download etcd... $LOCAL_ETCDFILE" 32 | wget -q ${DOWNLOAD_URL}/${ETCD_VER}/${LOCAL_ETCDFILE} 33 | if [ "$?" -ne "0" ]; then 34 | echo "[ERROR] $TIMESTAMP Download etcd error!!!" 35 | exit 1 36 | fi 37 | fi 38 | 39 | # Install etcd 40 | echo "[INFO] $TIMESTAMP Install etcd..." 41 | 42 | TGZFILE=$(basename $LOCAL_ETCDFILE) 43 | tar xfz $TGZFILE 44 | 45 | REALFILE=${TGZFILE%.*.*} 46 | 47 | cd $REALFILE 48 | 49 | cp -rf etcd etcdctl ${ETCD_WORKDIR}/bin/ 50 | ${ETCD_WORKDIR}/bin/etcd --version 51 | if [ "$?" == "0" ];then 52 | echo "[INFO] $TIMESTAMP install etcd success" 53 | else 54 | echo "[ERROR] $TIMESTAMP install etcd failed" 55 | fi 56 | 57 | 58 | echo "[INFO] $TIMESTAMP Deploy etcd..." 59 | ${ETCD_WORKDIR}/bin/etcd --name ${node_name} -data-dir ${ETCD_WORKDIR}/datadir/${node_name}/ \ 60 | -initial-advertise-peer-urls http://${node_ip}:${cluster_port} -listen-peer-urls http://${node_ip}:${cluster_port} \ 61 | -listen-client-urls http://${node_ip}:${client_port} \ 62 | -advertise-client-urls http://${node_ip}:${client_port} \ 63 | --initial-cluster ${cluster_member} \ 64 | -initial-cluster-state new &>>${ETCD_WORKDIR}/log/${node_name}.log & 65 | -------------------------------------------------------------------------------- /build/mysql/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/TSeer/1c92b1e08ddb16b777d992a1e38fd765b5104385/build/mysql/__init__.py -------------------------------------------------------------------------------- /build/mysql/deploy_mysql.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | from utils.vssh import execute_script 3 | 4 | 5 | def install_mysql(install_type, base_dir): 6 | if install_type == 'yum': 7 | tmp_rst = execute_script(script="./mysql/deploy_mysql_yum.sh")['localhost'] 8 | stat, rst = tmp_rst['stat'], tmp_rst['rst'] 9 | 10 | elif install_type == 'source': 11 | tmp_rst = execute_script(script="./mysql/deploy_mysql_source.sh", args=base_dir) 12 | stat, rst = tmp_rst['stat'], tmp_rst['rst'] 13 | else: 14 | stat, rst = False, 'Unkown install mysql type' 15 | 16 | return stat, rst 17 | -------------------------------------------------------------------------------- /build/mysql/deploy_mysql_yum.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | TIMESTAMP=`date "+%F %T"` 4 | 5 | if yum list | grep mysql-server &>/dev/null; then 6 | yum install mysql mysql-server -y &>/dev/null 7 | if [ "$?" != "0" ];then 8 | echo "[ERROR] $TIMESTAMP deploy mysql error." 9 | exit 2 10 | fi 11 | systemctl start mysqld &>/dev/null 12 | if [ "$?" -ne "0" ];then 13 | service mysqld start &>/dev/null 14 | if [ "$?" -ne "0" ]; then 15 | echo "[ERROR] $TIMESTAMP start mysql error" 16 | exit 2 17 | fi 18 | fi 19 | echo "[INFO] $TIMESTAMP deploy mysql success" 20 | else 21 | yum install mysql mariadb-server -y &>/dev/null 22 | if [ "$?" != "0" ];then 23 | echo "[ERROR] $TIMESTAMP deploy mysql error." 24 | exit 2 25 | fi 26 | echo "[INFO] $TIMESTAMP deploy mysql success" 27 | systemctl start mariadb &>/dev/null 28 | 29 | if [ "$?" -ne "0" ];then 30 | service mysqld start &>/dev/null 31 | if [ "$?" -ne "0" ]; then 32 | echo "[ERROR] $TIMESTAMP start mysql error" 33 | exit 2 34 | fi 35 | fi 36 | 37 | fi 38 | 39 | echo "[INFO] $TIMESTAMP Initial db." 40 | mysql < ./mysql/db.sql &>/dev/null 41 | # create user, if failed, please use root for mysql and execute again 42 | mysql -e "grant all on seer.* to 'seer'@'%' identified by 'seer';" 43 | -------------------------------------------------------------------------------- /build/patchagent.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | PREFIX=$1/Tseer 4 | TARGET=TseerAgent 5 | 6 | if [ -d ${TARGET}_tmp_dir ]; then 7 | echo "dir has exist:${TARGET}_tmp_dir, abort."; 8 | exit 1; 9 | else 10 | mkdir -p ${TARGET}_tmp_dir/Tseer/${TARGET}/bin; 11 | mkdir -p ${TARGET}_tmp_dir/Tseer/${TARGET}/conf; 12 | mkdir -p ${TARGET}_tmp_dir/Tseer/${TARGET}/data; 13 | mkdir -p ${TARGET}_tmp_dir/Tseer/${TARGET}/util; 14 | cp -rf ${PREFIX}/TseerAgent/bin/${TARGET} ${TARGET}_tmp_dir/Tseer/${TARGET}/bin/; 15 | cp -rf ./cmake/start.sh ${TARGET}_tmp_dir/Tseer/${TARGET}/util/; 16 | sed -i "s#TARGET=.*#TARGET=${TARGET}#g" ${TARGET}_tmp_dir/Tseer/${TARGET}/util/start.sh 17 | cp -rf ./cmake/stop.sh ${TARGET}_tmp_dir/Tseer/${TARGET}/util/; 18 | sed -i "s#TARGET=.*#TARGET=${TARGET}#g" ${TARGET}_tmp_dir/Tseer/${TARGET}/util/stop.sh 19 | cp -rf ./cmake/mon_TseerAgent.sh ${TARGET}_tmp_dir/Tseer/${TARGET}/util/; 20 | cp -rf ${PREFIX}/TseerAgent/conf/TseerAgent.conf ${TARGET}_tmp_dir/Tseer/${TARGET}/conf/; 21 | cd ${TARGET}_tmp_dir; tar -czvf ${TARGET}.tgz Tseer/; cd ..; 22 | echo "`pwd`" 23 | VERSION=`strings ${TARGET}_tmp_dir/Tseer/${TARGET}/bin/${TARGET} | grep "TseerAgent_" | head -1|awk -F_ '{print $2 "_" $3}'`; 24 | mv ${TARGET}_tmp_dir/${TARGET}.tgz ./${TARGET}.tgz; 25 | MD5=`md5sum ${TARGET}.tgz | awk '{print $1}'`; 26 | TIME=`date +%Y%m%d%H%M%S`; 27 | mv ./${TARGET}.tgz ./${TARGET}_${TIME}_${VERSION}_${MD5}.tgz; 28 | rm -rf ${TARGET}_tmp_dir; 29 | echo ${TARGET}_${TIME}_${VERSION}_${MD5}.tgz; 30 | fi 31 | -------------------------------------------------------------------------------- /build/tseer_deploy.ini: -------------------------------------------------------------------------------- 1 | [tseer] 2 | ; install_type: bin, source; default: bin. 3 | ; binary install: place binary executable to your set base path 4 | ; source install: depend tars 5 | install_type=source 6 | ; storage: must be etcd. data storage. 7 | storage=etcd 8 | base_dir=/data/tseer_test/ 9 | bind_ip=localhost 10 | 11 | [webadmin] 12 | port=8080 13 | 14 | [tseer_server] 15 | ; agent registry and report heartbeat 16 | regport=9902 17 | ; query service ip and port 18 | queryport=9903 19 | ; admin port 20 | apiport=9904 21 | 22 | [tseer_agent] 23 | 24 | [etcd] 25 | ; host_list: localhost or like 10.0.0.1,192.168.0.10, 172.168.10.1 26 | ; localhost: start local 3 etcd instance 27 | ;host_list=localhost 28 | client_port=2379 29 | cluster_port=2380 30 | base_dir=/data/tseer_test/etcd/ 31 | 32 | -------------------------------------------------------------------------------- /build/utils/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/TSeer/1c92b1e08ddb16b777d992a1e38fd765b5104385/build/utils/__init__.py -------------------------------------------------------------------------------- /build/utils/get_os_info.py: -------------------------------------------------------------------------------- 1 | # coding:utf8 2 | 3 | import socket 4 | import fcntl 5 | import struct 6 | 7 | 8 | def get_ip(ifname='eth0'): 9 | try: 10 | s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) 11 | ad = socket.inet_ntoa(fcntl.ioctl( 12 | s.fileno(), 13 | 0x8915, # SIOCGIFADDR 14 | struct.pack('256s', ifname[:15]) 15 | )[20:24]) 16 | s.close() 17 | return ad 18 | except: 19 | return "127.0.0.1" 20 | finally: 21 | s.close() 22 | 23 | 24 | if __name__ == '__main__': 25 | print get_ip() 26 | 27 | -------------------------------------------------------------------------------- /build/utils/seer_exceptions.py: -------------------------------------------------------------------------------- 1 | 2 | class FileNotExist(Exception): 3 | def __init__(self, filename): 4 | self.filename = filename 5 | 6 | def __str__(self): 7 | return repr("File %s not exists" %(self.filename)) 8 | 9 | if __name__ == '__main__': 10 | raise FileNotExist('hosts') 11 | -------------------------------------------------------------------------------- /build/webadmin/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/TSeer/1c92b1e08ddb16b777d992a1e38fd765b5104385/build/webadmin/__init__.py -------------------------------------------------------------------------------- /docs/images/addgroup.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/TSeer/1c92b1e08ddb16b777d992a1e38fd765b5104385/docs/images/addgroup.png -------------------------------------------------------------------------------- /docs/images/addmodule.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/TSeer/1c92b1e08ddb16b777d992a1e38fd765b5104385/docs/images/addmodule.png -------------------------------------------------------------------------------- /docs/images/group.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/TSeer/1c92b1e08ddb16b777d992a1e38fd765b5104385/docs/images/group.png -------------------------------------------------------------------------------- /docs/images/module.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/TSeer/1c92b1e08ddb16b777d992a1e38fd765b5104385/docs/images/module.png -------------------------------------------------------------------------------- /docs/images/pptseer.en.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/TSeer/1c92b1e08ddb16b777d992a1e38fd765b5104385/docs/images/pptseer.en.png -------------------------------------------------------------------------------- /docs/images/pptseer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/TSeer/1c92b1e08ddb16b777d992a1e38fd765b5104385/docs/images/pptseer.png -------------------------------------------------------------------------------- /docs/images/seer_feature.en.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/TSeer/1c92b1e08ddb16b777d992a1e38fd765b5104385/docs/images/seer_feature.en.png -------------------------------------------------------------------------------- /docs/images/seer_feature.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/TSeer/1c92b1e08ddb16b777d992a1e38fd765b5104385/docs/images/seer_feature.png -------------------------------------------------------------------------------- /docs/images/uploadagent.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/TSeer/1c92b1e08ddb16b777d992a1e38fd765b5104385/docs/images/uploadagent.png -------------------------------------------------------------------------------- /examples/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8) 2 | project(examples) 3 | 4 | add_subdirectory(TseerServer) 5 | -------------------------------------------------------------------------------- /examples/TseerServer/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8) 2 | project(TestSeer) 3 | 4 | add_subdirectory(protocol) 5 | include_directories(${CMAKE_CURRENT_SOURCE_DIR}/protocol 6 | ${TARS_DIR_INC} 7 | ${RAPID_JSON_DIR} 8 | ${TARS_DIR_INC}/servant) 9 | 10 | link_directories(${TARS_DIR_LIB}) 11 | 12 | aux_source_directory(. DIR_SRCS) 13 | 14 | add_executable(${PROJECT_NAME} ${DIR_SRCS}) 15 | 16 | add_dependencies(${PROJECT_NAME} TESTSEERSERVER_TARS_HEADER) 17 | 18 | set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/${PROJECT_NAME}/bin) 19 | 20 | 21 | target_link_libraries(${PROJECT_NAME} tarsservant tarsparse tarsutil 22 | pthread) -------------------------------------------------------------------------------- /examples/TseerServer/Global.h: -------------------------------------------------------------------------------- 1 | #ifndef __GLOBAL_H__ 2 | #define __GLOBAL_H__ 3 | 4 | #include 5 | 6 | #include "servant/Communicator.h" 7 | 8 | std::string g_key = "webadmin"; 9 | 10 | std::string g_url = "http://127.0.0.1:9904/v1/interface"; 11 | 12 | std::string g_srvgrp = "apitest222"; 13 | 14 | std::string g_user = ""; 15 | std::string g_idcname = "idctest"; 16 | tars::Communicator g_com; 17 | 18 | int g_ttime = 0; 19 | 20 | int g_iloadInterval = 0; 21 | 22 | #endif -------------------------------------------------------------------------------- /examples/TseerServer/IDCTest.h: -------------------------------------------------------------------------------- 1 | #ifndef __IDC_TEST_H__ 2 | #define __IDC_TEST_H__ 3 | 4 | void addIdcGroup(); 5 | 6 | void delIdcGroup(); 7 | 8 | void modifyIdcGroup(); 9 | 10 | void getAllIdcGroup(); 11 | 12 | void addPriority(); 13 | 14 | void delPriority(const string &priorityId); 15 | 16 | void modifyPriority(const string &priorityId); 17 | 18 | void getPriority(); 19 | 20 | void getIdcGroup(); 21 | 22 | #endif -------------------------------------------------------------------------------- /examples/TseerServer/NodeTest.h: -------------------------------------------------------------------------------- 1 | #ifndef __NODE_TEST_H__ 2 | #define __NODE_TEST_H__ 3 | 4 | //测试添加一个Agent节点 5 | void addOneAgentNode(); 6 | 7 | //测试删除一个Agent节点 8 | void delOneAgentNode(); 9 | 10 | //测试上报Agent节点的心跳 11 | void keepAliveAgent(); 12 | 13 | //测试添加一个Node节点 14 | void registerNode(); 15 | 16 | //测试删除一个Node节点 17 | void destroyNode(); 18 | 19 | //测试上报Node节点的心跳 20 | void keepAlive(); 21 | 22 | void getagentbaseinfo(); 23 | void updateagentgraystate(); 24 | void getagentpackageinfo(); 25 | void updateagentpackageinfo(); 26 | void deleteagentpackage(); 27 | void updateagentlocator(); 28 | #endif -------------------------------------------------------------------------------- /examples/TseerServer/QueryTest.h: -------------------------------------------------------------------------------- 1 | #ifndef __QUERY_TEST_H__ 2 | #define __QUERY_TEST_H__ 3 | 4 | //根据id获取所有对象,包括活动和非活动对象 5 | void findObjectById4Any(); 6 | 7 | void findObjectByIdInSameGroup(); 8 | 9 | void findObjectByIdInSameSet(); 10 | 11 | #endif -------------------------------------------------------------------------------- /examples/TseerServer/SeerClientServiceTest.h: -------------------------------------------------------------------------------- 1 | #ifndef __SEER_CLIENT_SERVICE_TEST_H__ 2 | #define __SEER_CLIENT_SERVICE_TEST_H__ 3 | 4 | void addSeerClientService(); 5 | 6 | void modifySeerClientServiceManager(); 7 | 8 | void delSeerClientService(); 9 | 10 | void getSeerClientService(); 11 | 12 | #endif -------------------------------------------------------------------------------- /examples/TseerServer/ServerTest.h: -------------------------------------------------------------------------------- 1 | #ifndef __SERVER_TEST_H__ 2 | #define __SERVER_TEST_H__ 3 | 4 | void addServers(); 5 | 6 | void deleteServers(); 7 | 8 | void updateServers(); 9 | 10 | void getServers(); 11 | 12 | void keepServerAlive(); 13 | 14 | 15 | void updateServerState(); 16 | 17 | void updateServerStates(); 18 | 19 | #endif -------------------------------------------------------------------------------- /examples/TseerServer/ServiceGroupTest.h: -------------------------------------------------------------------------------- 1 | #ifndef __SERVICE_GROUP_TEST_H__ 2 | #define __SERVICE_GROUP_TEST_H__ 3 | 4 | void addServiceGroup(); 5 | 6 | void getServiceGroup(); 7 | 8 | void updateServiceGroup(); 9 | 10 | #endif -------------------------------------------------------------------------------- /examples/TseerServer/Util.cpp: -------------------------------------------------------------------------------- 1 | #include "Util.h" 2 | using namespace std; 3 | using namespace tars; 4 | 5 | string urlEncode(const string &sIn) 6 | { 7 | /** 8 | const char *str = sIn.c_str(); 9 | const int strSize = sIn.size(); 10 | string sOut; 11 | 12 | int i; 13 | char ch; 14 | 15 | for (i = 0; i < strSize; ++i) 16 | { 17 | ch = str[i]; 18 | if (((ch >= 'A') && (ch <= 'Z')) || 19 | ((ch >= 'a') && (ch <= 'z')) || 20 | ((ch >= '0') && (ch <= '9'))) 21 | { 22 | sOut += ch; 23 | } 24 | else if (ch == ' ') 25 | { 26 | sOut += '+'; 27 | } 28 | else if (ch == '.' || ch == '-' || ch == '_' || ch == '*') 29 | { 30 | sOut += ch; 31 | } 32 | else 33 | { 34 | char result[4] = {'\0'}; 35 | sprintf(result, "%%%02X", (unsigned char)ch); 36 | sOut += result; 37 | } 38 | } 39 | **/ 40 | return sIn; 41 | } 42 | 43 | string getRequestUrl(const string &interfaceName, const string ¶ms, const string &api) 44 | { 45 | string url = api + "?interface_name=" + interfaceName + "&interface_params=" + params; 46 | return url; 47 | } 48 | 49 | int doSyncRequest(const string &url, tars::TC_HttpResponse &response) 50 | { 51 | TC_HttpRequest stHttpReq; 52 | stHttpReq.setCacheControl("no-cache"); 53 | stHttpReq.setHeader("Content-Type", "application/x-www-form-urlencoded"); 54 | stHttpReq.setGetRequest(url); 55 | 56 | int iRet = stHttpReq.doRequest(response, 30000); 57 | if (iRet != 0) 58 | { 59 | cout << FILE_FUN << "send request failed, ret:" << iRet << endl; 60 | return -1; 61 | } 62 | 63 | return 0; 64 | } 65 | -------------------------------------------------------------------------------- /examples/TseerServer/Util.h: -------------------------------------------------------------------------------- 1 | #ifndef __UTIL_H__ 2 | #define __UTIL_H__ 3 | 4 | #include 5 | 6 | #include "util/tc_encoder.h" 7 | #include "util/tc_common.h" 8 | #include "util/tc_http.h" 9 | #include "servant/Communicator.h" 10 | 11 | 12 | //#define FILE_FUN __FUNCTION__ << ":" << __LINE__ << "|" << pthread_self() << "|" 13 | #define FILE_FUN __FUNCTION__ << ":" << __LINE__ 14 | 15 | #define REGISTRY_HTTP_API "http://127.0.0.1:9904/v1/client/" 16 | 17 | #define REGISTRY_OBJ "Tseer.TseerServer.RegistryObj@tcp -h 127.0.0.1 -p 9902 -t 30000" 18 | 19 | #define QUERY_OBJ "Tseer.TseerServer.QueryObj@tcp -h 127.0.0.1 -p 9903 -t 30000" 20 | 21 | std::string urlEncode(const std::string &in); 22 | 23 | std::string getRequestUrl(const std::string &interfaceName, const std::string ¶ms, const std::string &api = REGISTRY_HTTP_API); 24 | 25 | int doSyncRequest(const std::string &url, tars::TC_HttpResponse &response); 26 | 27 | #endif -------------------------------------------------------------------------------- /examples/TseerServer/protocol/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(OUT_DEPENDS_LIST) 2 | 3 | complice_tars(OUT_DEPENDS_LIST "") 4 | 5 | add_custom_target(TESTSEERSERVER_TARS_HEADER ALL DEPENDS ${OUT_DEPENDS_LIST}) -------------------------------------------------------------------------------- /examples/TseerServer/protocol/RetCode.tars: -------------------------------------------------------------------------------- 1 | module Tseer 2 | { 3 | /*公共错误码*/ 4 | const int TSEER_SERVERSUCCESS = 0; //请求成功 5 | const int TSEER_UNKNOW_ERROR = -99; //未知错误 6 | 7 | /*DockerRegistry专用返回码号段: 2000 ~ 2999*/ 8 | const int TSEER_REGISTRY_UNKNOWN = 2000; // 9 | const int TSEER_REGISTRY_PARAM_ERROR =2001; //请求参数不合规范 10 | const int TSEER_REGISTRY_UPDATESERVER_PARAM_ERROR = 2002; //updateServer接口参数错误 11 | const int TSEER_REGISTRY_GETSERVER_PARAM_ERROR = 2003; //get接口参数错误 12 | const int TSEER_REGISTRY_SETSERVER_PARAM_ERROR = 2004; //set接口参数错误 13 | const int TSEER_REGISTRY_DELTESERVER_PARAM_ERROR = 2005; //deletedata接口参数错误 14 | const int TSEER_REGISTRY_ADDSERVER_PARAM_ERROR = 2005; //deletedata接口参数错误 15 | 16 | /*TSeerServer etcd专用返回码号段: 2500 ~ 2999,结合*/ 17 | const int TSEER_REGISTRY_ETCD_UNKNOWN = 2500; // 18 | const int TSEER_REGISTRY_ETCD_PARSE_JSON_FAIL = 2501; //解析etcd返回的json结构失败 19 | const int TSEER_REGISTRY_ETCD_TIMEOUT = 2502;//调用etcd返回超时 20 | const int TSEER_REGISTRY_ETCD_RET_ERROR = 2503;//调用etcd出现内部错误 21 | const int TSEER_REGISTRY_ETCD_DATA_NOTFOUND = 2504;//etcd不存在指定的数据 22 | const int TSEER_REGISTRY_ETCD_SEND_REQ_FAIL = 2505;//向etcd服务发起网络请求失败 23 | }; 24 | 25 | -------------------------------------------------------------------------------- /examples/TseerServer/protocol/RouterData.tars: -------------------------------------------------------------------------------- 1 | module Tseer 2 | { 3 | struct RouterData 4 | { 5 | 0 require string moduletype; 6 | 1 require string application; 7 | 2 require string service_name; 8 | 3 require string node_name; 9 | 4 require string container_name; 10 | //填 Y 或者 N 只有这两个值 11 | 5 require string enable_group; 12 | 6 require string ip_group_name; 13 | //填 Y 或者 N 只有这两个值 14 | 7 require string enable_set; 15 | 8 require string set_name; 16 | 9 require string set_area; 17 | 10 require string set_group; 18 | 11 require string weight; 19 | //填 active inactive activating deactivating destroying destroyed 只能填这几个值 20 | 12 require string setting_state; 21 | 13 require string process_id; 22 | //填 active inactive activating deactivating destroying destroyed 只能填这几个值 23 | 14 require string present_state; 24 | 15 require string node_port; 25 | 16 require string container_port; 26 | /* 27 | key=路由的obj名字,比如:normal.itil.jdsweb.main_port 28 | value=具体的endpoint字符串详情,例如tcp -h 10.209.19.235 -p 9903 -t 50000 29 | */ 30 | 17 require map servant; 31 | 18 require string bak_flag; 32 | 19 require string grid_flag; 33 | 20 optional string weighttype; //启用权重类型,默认空,不启用,1:静态权重,2:动态权重 34 | 21 optional string enable_heartbeat; //是否允许做心跳超时检测 35 | 22 optional string heartbeattimeout="60"; //服务心跳超时时间,单位秒 36 | }; 37 | 38 | struct RouterDataRequest 39 | { 40 | 0 require string moduletype; 41 | 1 require string application; 42 | 2 require string service_name; 43 | 3 require string node_name; 44 | 4 require string container_name; 45 | }; 46 | key[RouterDataRequest,moduletype,application,service_name,node_name,container_name]; 47 | }; 48 | 49 | -------------------------------------------------------------------------------- /examples/TseerServer/protocol/TseerAgentUpdate.tars: -------------------------------------------------------------------------------- 1 | module Tseer 2 | { 3 | struct AgentConfig 4 | { 5 | 0 require string locator; /* TSeer.TSeerServer.QueryObj@tcp -hx.x.x.x -px -txxxx */ 6 | 1 require string nodeIp; /* node主机的ip */ 7 | }; 8 | 9 | interface Update 10 | { 11 | /** 12 | * 更新TSeerAgent的TSeerServer路由服务地址 13 | * @param cfg 更新TSeerAgent配置 14 | * @param [out] result 操作详情 15 | * @return int 0成功 其它失败 16 | */ 17 | int updateConfig(AgentConfig cfg, out string result); 18 | 19 | /** 20 | * 卸载TSeerAgent:清理crontab,删除TSeerAgent目录结构 21 | * @param [out] result 操作详情 22 | * @return int 0成功 其它失败 23 | */ 24 | int uninstall(out string result); 25 | }; 26 | }; 27 | 28 | -------------------------------------------------------------------------------- /web/src/main/java/com/qq/seer/agent/AgentPackageMd5Util.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tseer available. 3 | * 4 | * Copyright (C) 2018 THL A29 Limited, a Tencent company. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | package com.qq.seer.agent; 18 | 19 | import java.io.File; 20 | import java.io.FileInputStream; 21 | import java.io.IOException; 22 | import java.io.InputStream; 23 | import java.security.MessageDigest; 24 | import java.security.NoSuchAlgorithmException; 25 | 26 | import com.qq.seer.common.log.LogUtils; 27 | 28 | public class AgentPackageMd5Util { 29 | 30 | public static String getFileMd5(File file) { 31 | String md5 = ""; 32 | try { 33 | md5 = streamToMD5(new FileInputStream(file)); 34 | } catch (Exception e) { 35 | String error = "AgentPackageMd5Util getFileMd5 Exception : " + e.getMessage(); 36 | LogUtils.localLogError(error, e); 37 | } 38 | return md5; 39 | } 40 | 41 | 42 | public static String streamToMD5(InputStream inputStream) throws NoSuchAlgorithmException, IOException { 43 | String md5 = ""; 44 | MessageDigest mdTemp = MessageDigest.getInstance("MD5"); 45 | byte[] buffer = new byte[1024]; 46 | int numRead = 0; 47 | while ((numRead = inputStream.read(buffer)) > 0) { 48 | mdTemp.update(buffer, 0, numRead); 49 | } 50 | md5 = toHexString(mdTemp.digest()); 51 | return md5; 52 | } 53 | 54 | private static String toHexString(byte[] md) { 55 | char hexDigits[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 56 | 'a', 'b', 'c', 'd', 'e', 'f' }; 57 | int j = md.length; 58 | char str[] = new char[j * 2]; 59 | for (int i = 0; i < j; i++) { 60 | byte byte0 = md[i]; 61 | str[2 * i] = hexDigits[byte0 >>> 4 & 0xf]; 62 | str[i * 2 + 1] = hexDigits[byte0 & 0xf]; 63 | } 64 | return new String(str); 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /web/src/main/java/com/qq/seer/common/collection/Pair.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tseer available. 3 | * 4 | * Copyright (C) 2018 THL A29 Limited, a Tencent company. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | package com.qq.seer.common.collection; 18 | 19 | import java.io.Serializable; 20 | 21 | public class Pair implements Serializable { 22 | 23 | 24 | 25 | private static final long serialVersionUID = 1L; 26 | 27 | public final A first; 28 | 29 | public final B second; 30 | 31 | private Pair(A first, B second) { 32 | this.first = first; 33 | this.second = second; 34 | } 35 | 36 | /** 37 | * 用于生成新对象的工厂静态方法 38 | * @param first A类的对象 39 | * @param second B类的对象 40 | * @return 返回Pair的对象 41 | */ 42 | public static Pair of(A first, B second) { 43 | return new Pair(first, second); 44 | } 45 | 46 | @SuppressWarnings("unchecked") 47 | @Override 48 | public boolean equals(Object obj) { 49 | if (obj == null) { 50 | return false; 51 | } 52 | if (getClass() != obj.getClass()) { 53 | return false; 54 | } 55 | final Pair other = (Pair) obj; 56 | if (this.first != other.first && (this.first == null || !this.first.equals(other.first))) { 57 | return false; 58 | } 59 | return !(this.second != other.second && (this.second == null || !this.second.equals(other.second))); 60 | } 61 | 62 | @Override 63 | public int hashCode() { 64 | int hash = 7; 65 | hash = 37 * hash + (this.first != null ? this.first.hashCode() : 0); 66 | hash = 37 * hash + (this.second != null ? this.second.hashCode() : 0); 67 | return hash; 68 | } 69 | 70 | @Override 71 | public String toString() { 72 | return String.format("Pair[%s,%s]", first, second); 73 | } 74 | 75 | } 76 | -------------------------------------------------------------------------------- /web/src/main/java/com/qq/seer/common/exception/ThrowableInfo.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tseer available. 3 | * 4 | * Copyright (C) 2018 THL A29 Limited, a Tencent company. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | package com.qq.seer.common.exception; 18 | 19 | import java.io.IOException; 20 | import java.io.PrintWriter; 21 | import java.io.StringWriter; 22 | 23 | public class ThrowableInfo { 24 | 25 | 26 | 27 | private transient Throwable throwable; 28 | 29 | public ThrowableInfo(Throwable throwable) { 30 | this.throwable = throwable; 31 | } 32 | 33 | public Throwable getThrowable() { 34 | return throwable; 35 | } 36 | 37 | /** 38 | * 查看异常的堆栈信息 39 | * @return 堆栈详细信息 40 | */ 41 | public String getThrowableStr() { 42 | StringWriter sw = new StringWriter(); 43 | throwable.printStackTrace(new PrintWriter(sw, true)); 44 | String rtnValue = sw.toString(); 45 | try { 46 | sw.close(); 47 | } catch (IOException e) { 48 | e.printStackTrace(); 49 | } 50 | return rtnValue; 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /web/src/main/java/com/qq/seer/common/lang/Charsets.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tseer available. 3 | * 4 | * Copyright (C) 2018 THL A29 Limited, a Tencent company. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | package com.qq.seer.common.lang; 18 | 19 | public class Charsets { 20 | 21 | public static final String UTF8 = "UTF-8"; 22 | public static final String GBK = "GBk"; 23 | 24 | } 25 | -------------------------------------------------------------------------------- /web/src/main/java/com/qq/seer/common/log/LogUtils.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tseer available. 3 | * 4 | * Copyright (C) 2018 THL A29 Limited, a Tencent company. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | package com.qq.seer.common.log; 18 | 19 | import java.io.PrintWriter; 20 | import java.io.StringWriter; 21 | 22 | /** 23 | * 日志处理 24 | * 25 | */ 26 | public class LogUtils { 27 | 28 | public static void localLogInfo(long logId, String info) { 29 | long tid = Thread.currentThread().getId(); 30 | String logInfo = "[" + logId + "][" + tid + "]" + info; 31 | 32 | System.out.println(logInfo); 33 | } 34 | 35 | 36 | public static void localLogError(long logId, String error, Throwable th) { 37 | long tid = Thread.currentThread().getId(); 38 | String logError = "[" + logId + "][" + tid + "]" + error; 39 | System.out.println(logError); 40 | 41 | StringWriter sw = new StringWriter(); 42 | th.printStackTrace(new PrintWriter(sw, true)); 43 | String rtnValue = sw.toString(); 44 | System.out.println(rtnValue); 45 | } 46 | 47 | 48 | public static void localLogError(long logId, String error) { 49 | long tid = Thread.currentThread().getId(); 50 | String logError = "[" + logId + "][" + tid + "]" + error; 51 | System.out.println(logError); 52 | } 53 | 54 | public static void localLogInfo(String info) { 55 | long logId = 0; 56 | localLogInfo(logId, info); 57 | } 58 | 59 | 60 | public static void localLogError(String error, Throwable th) { 61 | long logId = 0; 62 | localLogError(logId, error, th); 63 | } 64 | 65 | public static void localLogError(String error) { 66 | long logId = 0; 67 | localLogError(logId, error); 68 | } 69 | 70 | } 71 | -------------------------------------------------------------------------------- /web/src/main/java/com/qq/seer/common/prop/SystemProperty.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tseer available. 3 | * 4 | * Copyright (C) 2018 THL A29 Limited, a Tencent company. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | package com.qq.seer.common.prop; 18 | 19 | import java.util.HashMap; 20 | import java.util.Map; 21 | 22 | import com.qq.seer.common.config.PropertiesUtils; 23 | 24 | /** 25 | * 系统配置 26 | * 27 | */ 28 | public class SystemProperty extends PropertiesUtils { 29 | 30 | private static Map systemConfig = new HashMap(); 31 | private static String fileName = "system.properties"; 32 | 33 | 34 | static { 35 | init(); 36 | } 37 | 38 | private static void init() { 39 | systemConfig = getPropertyMap(fileName); 40 | } 41 | 42 | 43 | public static String getValueByName(String name) { 44 | if (name ==null || name.length() < 1) { 45 | return ""; 46 | } 47 | return systemConfig.get(name); 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /web/src/main/java/com/qq/seer/common/servlet/ServletUtils.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tseer available. 3 | * 4 | * Copyright (C) 2018 THL A29 Limited, a Tencent company. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | package com.qq.seer.common.servlet; 18 | 19 | import org.slf4j.Logger; 20 | import org.slf4j.LoggerFactory; 21 | 22 | import javax.servlet.ServletContext; 23 | import java.io.UnsupportedEncodingException; 24 | import java.net.MalformedURLException; 25 | import java.net.URL; 26 | import java.net.URLDecoder; 27 | import java.nio.charset.Charset; 28 | 29 | public class ServletUtils { 30 | private static Logger log = LoggerFactory.getLogger(ServletUtils.class); 31 | 32 | public static String getFileRealPath(ServletContext context, String path) { 33 | String realPath = context.getRealPath("/" + path); 34 | if (null == realPath) { 35 | try { 36 | URL url = context.getResource("/" + path); 37 | if (null == url) { 38 | log.error("no file found, path=[" + path + "]"); 39 | } else { 40 | try { 41 | realPath = URLDecoder.decode(url.getFile(), Charset.defaultCharset().name()); 42 | } catch (UnsupportedEncodingException e) { 43 | e.printStackTrace(); 44 | } 45 | } 46 | } catch (MalformedURLException e) { 47 | e.printStackTrace(); 48 | } 49 | } 50 | return realPath; 51 | } 52 | 53 | 54 | } 55 | -------------------------------------------------------------------------------- /web/src/main/java/com/qq/tars/tseer/RegistryPrxCallback.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tseer available. 3 | * 4 | * Copyright (C) 2018 THL A29 Limited, a Tencent company. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | // ********************************************************************** 18 | // This file was generated by a TARS parser! 19 | // TARS version 1.0.1. 20 | // ********************************************************************** 21 | 22 | package com.qq.tars.tseer; 23 | 24 | import com.qq.tars.rpc.protocol.tars.support.TarsAbstractCallback; 25 | 26 | public abstract class RegistryPrxCallback extends TarsAbstractCallback { 27 | 28 | public abstract void callback_pushPackage(int ret, String result); 29 | 30 | } 31 | -------------------------------------------------------------------------------- /web/src/main/resources/j4log.property: -------------------------------------------------------------------------------- 1 | ## ----------------------- Standard Logs -------------------------- ## 2 | local=DEBUG,/data/log/seer/local.log 3 | 4 | -------------------------------------------------------------------------------- /web/src/main/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | # For Common Lib 2 | log4j.rootLogger=DEBUG,default 3 | log4j.appender.default=org.apache.log4j.DailyRollingFileAppender 4 | log4j.appender.default.File=/data/log/seer/_log4j.log 5 | log4j.appender.default.layout=org.apache.log4j.PatternLayout 6 | log4j.appender.default.layout.ConversionPattern=[%d{yyyy-MM-dd HH\:mm\:ss}][%-5p][%F|%L|%M] %m%n 7 | log4j.appender.local=org.apache.log4j.DailyRollingFileAppender 8 | log4j.appender.local.File=/data/log/seer/local.log 9 | log4j.appender.local.layout=org.apache.log4j.PatternLayout 10 | log4j.appender.local.layout.ConversionPattern=[%d{yyyy-MM-dd HH\:mm\:ss}][%-5p][%F|%L|%M] %m%n 11 | -------------------------------------------------------------------------------- /web/src/main/resources/seer.conf: -------------------------------------------------------------------------------- 1 | 2 | 3 | #proxy需要的配置 4 | 5 | #地址 6 | locator = Tseer.TseerServer.QueryObj@tcp -h 10.229.136.145 -p 9203 -t 50000 7 | sync-invoke-timeout = 20000 8 | #最大超时时间(毫秒) 9 | max-invoke-timeout = 60000 10 | #刷新端口时间间隔(毫秒) 11 | refresh-endpoint-interval = 300000 12 | #模块间调用[可选] 13 | #stat = 14 | #网络异步回调线程个数 15 | asyncthread = 3 16 | modulename = seer.system 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /web/src/main/resources/system.properties: -------------------------------------------------------------------------------- 1 | #Seer Agent包上传临时目录路径 2 | agent.package.dir=/data/seer/agent 3 | 4 | #Seer后台接口url 5 | seer.api.url=http://10.229.136.145:9204/v1/interface 6 | 7 | #Seer Agent安装命令 8 | seer.agent.onekey.install.url=http://10.229.136.145:9204/installscript 9 | 10 | -------------------------------------------------------------------------------- /web/src/main/webapp/404.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" contentType="text/html; charset=UTF-8" 2 | pageEncoding="UTF-8"%> 3 | 4 | 5 | 6 | 7 | 8 | 404 9 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /web/src/main/webapp/500.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" contentType="text/html; charset=UTF-8" 2 | pageEncoding="UTF-8"%> 3 | 4 | 5 | 6 | 7 | 8 | 500 9 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | -------------------------------------------------------------------------------- /web/src/main/webapp/MVN_CTL/copy-dependency-app.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | setlocal 3 | cd /D %0\..\.. 4 | call mvn org.apache.maven.plugins:maven-dependency-plugin:2.1:copy-dependencies -DoutputDirectory=lib/ -DexcludeScope=provided 5 | pause 6 | -------------------------------------------------------------------------------- /web/src/main/webapp/MVN_CTL/copy-dependency-web.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | setlocal 3 | cd /D %0\..\.. 4 | call mvn org.apache.maven.plugins:maven-dependency-plugin:2.1:copy-dependencies -DoutputDirectory=WEB-INF/lib/ -DexcludeScope=provided 5 | pause 6 | -------------------------------------------------------------------------------- /web/src/main/webapp/MVN_CTL/eclipse-with-templib.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | setlocal 3 | cd /D %0\..\.. 4 | call mvn qq-thirdparty:maven-eclipse-plugin:clean 5 | call mvn qq-thirdparty:maven-eclipse-plugin:eclipse 6 | call mvn qq-central:maven-eclipse-classpath-plugin:add_templib 7 | pause 8 | -------------------------------------------------------------------------------- /web/src/main/webapp/MVN_CTL/eclipse.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | setlocal 3 | cd /D %0\..\.. 4 | call mvn qq-thirdparty:maven-eclipse-plugin:clean 5 | call mvn qq-thirdparty:maven-eclipse-plugin:eclipse 6 | pause 7 | -------------------------------------------------------------------------------- /web/src/main/webapp/MVN_CTL/jce2java.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | setlocal 3 | cd /D %0\..\.. 4 | cls 5 | chdir 6 | call mvn qq-central:maven-taf-plugin:1.0.0-SNAPSHOT:jce2java -f jce.pom.xml 7 | pause 8 | -------------------------------------------------------------------------------- /web/src/main/webapp/global-libs/cloudJs/images/ajax_loading.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/TSeer/1c92b1e08ddb16b777d992a1e38fd765b5104385/web/src/main/webapp/global-libs/cloudJs/images/ajax_loading.gif -------------------------------------------------------------------------------- /web/src/main/webapp/global-libs/cloudJs/images/icons_new.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/TSeer/1c92b1e08ddb16b777d992a1e38fd765b5104385/web/src/main/webapp/global-libs/cloudJs/images/icons_new.png -------------------------------------------------------------------------------- /web/src/main/webapp/global-libs/cloudJs/images/icons_new_old.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/TSeer/1c92b1e08ddb16b777d992a1e38fd765b5104385/web/src/main/webapp/global-libs/cloudJs/images/icons_new_old.png -------------------------------------------------------------------------------- /web/src/main/webapp/global-libs/cloudJs/images/loading_small.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/TSeer/1c92b1e08ddb16b777d992a1e38fd765b5104385/web/src/main/webapp/global-libs/cloudJs/images/loading_small.gif -------------------------------------------------------------------------------- /web/src/main/webapp/global-libs/cloudJs/images/paging_loading.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/TSeer/1c92b1e08ddb16b777d992a1e38fd765b5104385/web/src/main/webapp/global-libs/cloudJs/images/paging_loading.gif -------------------------------------------------------------------------------- /web/src/main/webapp/global-libs/cloudJs/images/totop.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/TSeer/1c92b1e08ddb16b777d992a1e38fd765b5104385/web/src/main/webapp/global-libs/cloudJs/images/totop.png -------------------------------------------------------------------------------- /web/src/main/webapp/global-libs/cloudJs/js/Clipboard.swf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/TSeer/1c92b1e08ddb16b777d992a1e38fd765b5104385/web/src/main/webapp/global-libs/cloudJs/js/Clipboard.swf -------------------------------------------------------------------------------- /web/src/main/webapp/global-libs/cloudJs/js/string.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tseer available. 3 | * 4 | * Copyright (C) 2018 THL A29 Limited, a Tencent company. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | /** 18 | * 字符串大小写转换组件 19 | */ 20 | cloudjs.define({ 21 | string: function(options){ 22 | var action = arguments[0], 23 | str = arguments[1], 24 | callback = cloudjs.callback, 25 | result; 26 | 27 | if(!str || Object.prototype.toString.call(str) !== '[object String]'){ 28 | callback(result); 29 | return; 30 | } 31 | 32 | if(action === 'toLowerCase'){ 33 | result = str.toLowerCase(); 34 | }else if(action === 'toUpperCase'){ 35 | result = str.toUpperCase(); 36 | 37 | result = result + 'a';//假如这里多加个a,就通不过测试 38 | } 39 | 40 | callback(result); 41 | 42 | } 43 | }); -------------------------------------------------------------------------------- /web/src/main/webapp/global-libs/cloudJs/js/swfupload.swf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/TSeer/1c92b1e08ddb16b777d992a1e38fd765b5104385/web/src/main/webapp/global-libs/cloudJs/js/swfupload.swf -------------------------------------------------------------------------------- /web/src/main/webapp/global-libs/cloudJs/js/version.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tseer available. 3 | * 4 | * Copyright (C) 2018 THL A29 Limited, a Tencent company. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | cloudjs._comps_version = { 18 | resizable:'201602260001', 19 | draggable:'201602260001', 20 | paging:'201602260001', 21 | table:'201606230001', 22 | wsdtable:'201606230001', 23 | cascade:'201706270001', 24 | menu:'201705230001', 25 | clip:'201602260001', 26 | cookie:'201602260001', 27 | calendar:'201607210001', 28 | tab:'201602260001', 29 | ctab:'201608110001', 30 | slide:'201602260001', 31 | message:'201609220001', 32 | dialog:'201508310011', 33 | tips:'201512020007', 34 | validate:'201512020006', 35 | combobox:'201706270001', 36 | autocomp:'201602260001', 37 | ajaxbtn:'201602260001', 38 | calculate:'201602260001', 39 | string:'201602260001', 40 | progressbar:'201602260001', 41 | pinyinspell:'201603040001', 42 | css:'201601140001' //合并的css 43 | }; -------------------------------------------------------------------------------- /web/src/main/webapp/global-libs/font-awesome/font/FontAwesome.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/TSeer/1c92b1e08ddb16b777d992a1e38fd765b5104385/web/src/main/webapp/global-libs/font-awesome/font/FontAwesome.otf -------------------------------------------------------------------------------- /web/src/main/webapp/global-libs/font-awesome/font/fontawesome-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/TSeer/1c92b1e08ddb16b777d992a1e38fd765b5104385/web/src/main/webapp/global-libs/font-awesome/font/fontawesome-webfont.eot -------------------------------------------------------------------------------- /web/src/main/webapp/global-libs/font-awesome/font/fontawesome-webfont.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/TSeer/1c92b1e08ddb16b777d992a1e38fd765b5104385/web/src/main/webapp/global-libs/font-awesome/font/fontawesome-webfont.ttf -------------------------------------------------------------------------------- /web/src/main/webapp/global-libs/font-awesome/font/fontawesome-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/TSeer/1c92b1e08ddb16b777d992a1e38fd765b5104385/web/src/main/webapp/global-libs/font-awesome/font/fontawesome-webfont.woff -------------------------------------------------------------------------------- /web/src/main/webapp/global-libs/js/jquery.cookie.js: -------------------------------------------------------------------------------- 1 | jQuery.cookie = function(name, value, options) { 2 | if (typeof value != 'undefined') { // name and value given, set cookie 3 | options = options || {}; 4 | if (value === null) { 5 | value = ''; 6 | options.expires = -1; 7 | } 8 | var expires = ''; 9 | if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) { 10 | var date; 11 | if (typeof options.expires == 'number') { 12 | date = new Date(); 13 | date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000)); 14 | } else { 15 | date = options.expires; 16 | } 17 | expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE 18 | } 19 | // CAUTION: Needed to parenthesize options.path and options.domain 20 | // in the following expressions, otherwise they evaluate to undefined 21 | // in the packed version for some reason... 22 | var path = options.path ? '; path=' + (options.path) : ''; 23 | var domain = options.domain ? '; domain=' + (options.domain) : ''; 24 | var secure = options.secure ? '; secure' : ''; 25 | document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join(''); 26 | } else { // only name given, get cookie 27 | var cookieValue = null; 28 | if (document.cookie && document.cookie != '') { 29 | var cookies = document.cookie.split(';'); 30 | for (var i = 0; i < cookies.length; i++) { 31 | var cookie = jQuery.trim(cookies[i]); 32 | // Does this cookie string begin with the name we want? 33 | if (cookie.substring(0, name.length + 1) == (name + '=')) { 34 | cookieValue = decodeURIComponent(cookie.substring(name.length + 1)); 35 | break; 36 | } 37 | } 38 | } 39 | return cookieValue; 40 | } 41 | }; -------------------------------------------------------------------------------- /web/src/main/webapp/global-libs/odfl/comps/cookie.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tseer available. 3 | * 4 | * Copyright (C) 2018 THL A29 Limited, a Tencent company. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | var odfl = ($.odfl||odfl); 18 | odfl.define({ 19 | cookie: function(){ 20 | 21 | var $this = this, args = arguments, callback = odfl.callback, result; 22 | 23 | 24 | _(); 25 | 26 | function _(){ 27 | result = $.cookie.apply($, args); 28 | callback.call(odfl, result); 29 | } 30 | }, 31 | 32 | require: ['../../js/jquery.cookie.js'] 33 | }); 34 | -------------------------------------------------------------------------------- /web/src/main/webapp/global-libs/odfl/comps/crossJs.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tseer available. 3 | * 4 | * Copyright (C) 2018 THL A29 Limited, a Tencent company. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | var odfl = ($.odfl||odfl); 18 | odfl.define({ 19 | crossJs: function(){ 20 | 21 | var $this = this, args = arguments, page, params, level, callback = odfl.callback, hash, w, d, split = '__odfl__', id = '__odfl__'+odfl.uniq(); 22 | 23 | if(typeof args[0] === 'object'){ 24 | page = args[0].page; 25 | params = args[0].params||[]; 26 | if(page){ 27 | if(params.length){ 28 | hash = '#'+split+params.join(split); 29 | }else{ 30 | hash = ''; 31 | } 32 | $('').appendTo('body'); 33 | } 34 | }else{ 35 | 36 | level = parseInt(args[0]||1); 37 | 38 | hash = location.hash; 39 | params = hash.split(split); 40 | params.shift(); 41 | 42 | w = parent; 43 | 44 | while(level--){ 45 | w = w.parent; 46 | } 47 | 48 | w && callback.apply(w, params); 49 | } 50 | } 51 | }); 52 | -------------------------------------------------------------------------------- /web/src/main/webapp/global-libs/odfl/comps/json.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tseer available. 3 | * 4 | * Copyright (C) 2018 THL A29 Limited, a Tencent company. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | var odfl = ($.odfl||odfl); 18 | odfl.define({ 19 | json: function(){ 20 | var args = arguments, callback = odfl.callback, o, str2Json, json2Str; 21 | 22 | o = args[0]; 23 | 24 | _2(); 25 | 26 | function _1(){ 27 | if(typeof o === 'string'){ 28 | callback(str2Json(o)); 29 | }else{ 30 | callback(json2Str(o)); 31 | } 32 | } 33 | 34 | function _2(){ 35 | 36 | json2Str = JSON.stringify; 37 | 38 | if(typeof JSON !== 'undefined' && typeof JSON.parse === 'function'){ 39 | str2Json = JSON.parse; 40 | }else{ 41 | str2Json = $.parseJSON; 42 | } 43 | 44 | _1(); 45 | } 46 | }, 47 | 48 | require: function(){ 49 | if(typeof JSON === 'undefined' || typeof JSON.stringify !== 'function'){ 50 | return ['../../js/json2.js']; 51 | } 52 | } 53 | }); -------------------------------------------------------------------------------- /web/src/main/webapp/global-libs/odfl/comps_version.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tseer available. 3 | * 4 | * Copyright (C) 2018 THL A29 Limited, a Tencent company. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | odfl._comps_version = { 18 | dialog:'20150410944', 19 | validate:'20150410945', 20 | paging:'20150410988', 21 | cookie:'20150410944', 22 | autoSearch:'20150410945', 23 | zclip:'20150410944', 24 | tooltip:'20150408946', 25 | tabs:'20150410944', 26 | ajaxButton:'20150410944', 27 | multiselect:'20170221944', 28 | datepicker:'20150410944', 29 | datetimepicker:'20150410944', 30 | userChooser:'20150410944', 31 | errorPage:'20150410944', 32 | zTree:'20150410944', 33 | uploader:'20150410944', 34 | crossJs:'20150410944', 35 | guide:'20150410999', 36 | collect:'20150410944', 37 | guideList:'20150410945', 38 | ajax:'20150410944', 39 | jsonp:'20150410944', 40 | ipbox:'20150410944', 41 | layer:'20150410944', 42 | monitor:'20150410944', 43 | cascade:'201511161288', 44 | pageSense:'20150410945', 45 | json:'20150410944', 46 | checkNotNull:'20150410944', 47 | message:'20150410944', 48 | submit:'20150410946', 49 | columnResizable:'20150410947', 50 | proxyAjax:'201610109471', 51 | proxyWhen:'201610109471', 52 | newZclip:'201610109471', 53 | flow:'201610109472' 54 | }; -------------------------------------------------------------------------------- /web/src/main/webapp/images/404.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/TSeer/1c92b1e08ddb16b777d992a1e38fd765b5104385/web/src/main/webapp/images/404.png -------------------------------------------------------------------------------- /web/src/main/webapp/images/backspace-20.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/TSeer/1c92b1e08ddb16b777d992a1e38fd765b5104385/web/src/main/webapp/images/backspace-20.png -------------------------------------------------------------------------------- /web/src/main/webapp/images/loading_big.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/TSeer/1c92b1e08ddb16b777d992a1e38fd765b5104385/web/src/main/webapp/images/loading_big.gif -------------------------------------------------------------------------------- /web/src/main/webapp/images/seer_framework.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/TSeer/1c92b1e08ddb16b777d992a1e38fd765b5104385/web/src/main/webapp/images/seer_framework.png -------------------------------------------------------------------------------- /web/src/main/webapp/images/seer_index_table.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/TSeer/1c92b1e08ddb16b777d992a1e38fd765b5104385/web/src/main/webapp/images/seer_index_table.png -------------------------------------------------------------------------------- /web/src/main/webapp/images/select_down.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/TSeer/1c92b1e08ddb16b777d992a1e38fd765b5104385/web/src/main/webapp/images/select_down.png -------------------------------------------------------------------------------- /web/src/main/webapp/images/sprites.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/TSeer/1c92b1e08ddb16b777d992a1e38fd765b5104385/web/src/main/webapp/images/sprites.png -------------------------------------------------------------------------------- /web/src/main/webapp/pages/ftl/api/download.ftl: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 19 | 20 | 21 | API文件下载 22 | 23 | 24 | <#include "../common/layout.ftl"> 25 | 44 |
45 |

API文件列表

46 |
    47 | <#list fileList as item> 48 | <#if item??> 49 |
  • ${item}
  • 50 | 51 | 52 |
53 |
54 | 55 | 56 | -------------------------------------------------------------------------------- /web/src/main/webapp/pages/ftl/api/upload.ftl: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 19 | 20 | 21 | API文件上传 22 | 23 | 24 | <#include "../common/layout.ftl"> 25 |
26 | 27 |
28 | 29 | 30 |
31 |

API文件上传

32 | 33 | 34 | 35 |
36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /web/src/main/webapp/pages/iframe/iframe.jsp: -------------------------------------------------------------------------------- 1 | <%@page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> 2 | <% 3 | String js_name = request.getParameter("js_name"); 4 | %> 5 | 6 | 7 | 8 | 9 | 跨域js调用 10 | 11 | 12 | <% 13 | if(js_name != null && js_name.length() > 0 ){ 14 | %> 15 | 16 | <% 17 | } 18 | %> 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /web/src/main/webapp/pages/iframe/js/upload_back.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tseer available. 3 | * 4 | * Copyright (C) 2018 THL A29 Limited, a Tencent company. All rights reserved. 5 | * 6 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at 8 | * 9 | * https://opensource.org/licenses/BSD-3-Clause 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed 12 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the 14 | * specific language governing permissions and limitations under the License. 15 | */ 16 | 17 | /*** 18 | * mkt 19 | * 用于触发点击提交按钮 20 | */ 21 | $(function(){ 22 | $.odfl.crossJs(function(retCode, data){ 23 | 24 | __(retCode); 25 | __(data); 26 | this.uploadCallback(retCode, data); 27 | }); 28 | }); --------------------------------------------------------------------------------