├── .github └── workflows │ └── gitee-sync.yml ├── .gitignore ├── Contributing.md ├── LICENSE ├── README.md ├── docs-en └── tars_protocol.md ├── docs └── tars_protocol.md ├── framework ├── AdminReg.tars ├── CMakeLists.txt ├── MonitorQuery.tars ├── Node.tars ├── NodeDescriptor.tars ├── NodePush.tars ├── Patch.tars ├── Registry.tars ├── RegistryDescriptor.tars ├── Topology.tars └── TraceData.tars ├── servant ├── AdminF.tars ├── AuthF.tars ├── BaseF.tars ├── CMakeLists.txt ├── ConfigF.tars ├── EndpointF.tars ├── LogF.tars ├── NodeF.tars ├── NotifyF.tars ├── PropertyF.tars ├── QueryF.tars └── StatF.tars └── tup └── RequestF.tars /.github/workflows/gitee-sync.yml: -------------------------------------------------------------------------------- 1 | on: 2 | push: 3 | branches: 4 | - master 5 | tags: 6 | - "*" 7 | 8 | name: Sync to Gitee 9 | jobs: 10 | run: 11 | name: Run 12 | runs-on: ubuntu-latest 13 | steps: 14 | - name: Checkout source code 15 | uses: actions/checkout@v1 16 | - name: Mirror Github to Gitee 17 | uses: Yikun/hub-mirror-action@v1.2 18 | with: 19 | src: github/TarsCloud 20 | dst: gitee/TarsCloud 21 | dst_key: ${{ secrets.GITEE_PRIVATE_KEY }} 22 | dst_token: ${{ secrets.GITEE_TOKEN }} 23 | account_type: org 24 | timeout: 600 25 | debug: true 26 | force_update: true 27 | static_list: "TarsProtocol" -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | 3 | framework/AdminReg.h 4 | framework/MonitorQuery.h 5 | framework/Node.h 6 | framework/NodeDescriptor.h 7 | framework/Patch.h 8 | framework/Registry.h 9 | framework/RegistryDescriptor.h 10 | servant/AdminF.h 11 | servant/AuthF.h 12 | servant/BaseF.h 13 | servant/ConfigF.h 14 | servant/EndpointF.h 15 | servant/LogF.h 16 | servant/NodeF.h 17 | servant/NotifyF.h 18 | servant/PropertyF.h 19 | servant/QueryF.h 20 | servant/StatF.h 21 | -------------------------------------------------------------------------------- /Contributing.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | 4 | If you contributed but cannot find your ID here, please submit PR and add your GitHub ID to both [Tars repo](https://github.com/TarsCloud/Tars/pulls) and [here](https://github.com/TarsCloud/TarsProtocol/pulls). 5 | 6 | ## TarsProtocol 7 | 8 | - jerrylucky 9 | - ruanshudong 10 | - shevqko 11 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | BSD 3-Clause License 2 | 3 | Copyright (c) 2020, THE TARS FOUNDATION 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | 9 | 1. Redistributions of source code must retain the above copyright notice, this 10 | list of conditions and the following disclaimer. 11 | 12 | 2. Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | 3. Neither the name of the copyright holder nor the names of its 17 | contributors may be used to endorse or promote products derived from 18 | this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | tars protocol files 2 | 3 | framework/protocol 4 | 5 | servant/protocol 6 | 7 | servant/tup 8 | 9 | -------------------------------------------------------------------------------- /docs-en/tars_protocol.md: -------------------------------------------------------------------------------- 1 | [Tars Protocol documentation](https://github.com/TarsCloud/TarsDocs_en/blob/master/base/tars-protocol.md) 2 | -------------------------------------------------------------------------------- /docs/tars_protocol.md: -------------------------------------------------------------------------------- 1 | [Tars 协议文档](https://github.com/TarsCloud/TarsDocs/blob/master/base/tars-protocol.md) 2 | -------------------------------------------------------------------------------- /framework/AdminReg.tars: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tars available. 3 | * 4 | * Copyright (C) 2016THL 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 "NodeDescriptor.tars" 18 | 19 | module tars 20 | { 21 | struct ServerStateDesc 22 | { 23 | 0 require string settingStateInReg; 24 | 1 require string presentStateInReg; 25 | 2 require string presentStateInNode; 26 | 3 require int processId; 27 | 4 require string patchVersion; 28 | 5 require string patchTime; 29 | 6 require string patchUser; 30 | }; 31 | 32 | enum tarsErrCode 33 | { 34 | //请求的node节点没有注册或者节点心跳超时 35 | EM_TARS_NODE_NOT_REGISTRY_ERR = 1001, 36 | //主控请求node节点超时 37 | EM_TARS_CALL_NODE_TIMEOUT_ERR = 1002, 38 | //从主控数据库获取服务的描述信息错误 39 | EM_TARS_LOAD_SERVICE_DESC_ERR = 1003, 40 | //服务可能处在停止或者发布过程中 41 | EM_TARS_SERVICE_STATE_ERR = 1004, 42 | //同样的请求已经在处理了 43 | EM_TARS_REQ_ALREADY_ERR = 1005, 44 | //请求来自非法的ip地址,如并非合法的主控地址 45 | EM_TARS_INVALID_IP_ERR = 1006, 46 | //参数错误 47 | EM_TARS_PARAMETER_ERR = 1007, 48 | //非tars方面的问题,用于node判断业务机器问题等 49 | EM_TARS_OTHER_ERR = 1008, 50 | //获取patch file异常 51 | EM_TARS_GET_PATCH_FILE_ERR = 1009, 52 | //调用patch server准备发布包失败 53 | EM_TARS_PREPARE_ERR = 1010, 54 | //不能执行 55 | EM_TARS_CAN_NOT_EXECUTE = 1011, 56 | //tarsnode没有连接 57 | EM_TARS_NODE_NO_CONNECTION = 1012, 58 | //未知错误 59 | EM_TARS_UNKNOWN_ERR = -1, 60 | //成功 61 | EM_TARS_SUCCESS = 0 62 | }; 63 | 64 | /** 65 | * 管理平台过来的命令 66 | */ 67 | enum EMTaskCommand 68 | { 69 | EM_CMD_START, 70 | EM_CMD_STOP, 71 | EM_CMD_PATCH, 72 | EM_CMD_UNINSTALL 73 | }; 74 | 75 | /** 76 | * 任务的状态 77 | */ 78 | enum EMTaskStatus { 79 | EM_T_NOT_START, 80 | EM_T_PREPARE, 81 | EM_T_RUNNING, 82 | EM_T_SUCCESS, 83 | EM_T_FAILED, 84 | EM_T_CANCEL, 85 | EM_T_PARIAL, 86 | }; 87 | 88 | /** 89 | * 任务ITEM状态 90 | */ 91 | enum EMTaskItemStatus 92 | { 93 | EM_I_NOT_START, 94 | EM_I_PREPARE, //正在准备发布文件或镜像 95 | EM_I_RUNNING, 96 | EM_I_SUCCESS, 97 | EM_I_FAILED, 98 | EM_I_CANCEL, 99 | EM_I_PAUSE_FLOW, 100 | }; 101 | 102 | /** 103 | * 异步任务 104 | */ 105 | struct TaskItemReq 106 | { 107 | 0 optional string taskNo; 108 | 1 optional string itemNo; 109 | 2 optional string application; 110 | 3 optional string serverName; 111 | 4 optional string nodeName; 112 | 5 optional string setName; 113 | 6 optional string command; 114 | 7 optional string userName; 115 | 8 optional map parameters; 116 | }; 117 | 118 | /** 119 | * 任务当前的信息 120 | */ 121 | struct TaskItemRsp 122 | { 123 | 0 optional TaskItemReq req; 124 | 1 optional string startTime; 125 | 2 optional string endTime; 126 | 3 optional EMTaskItemStatus status; 127 | 4 optional string statusInfo; 128 | 5 optional string executeLog; 129 | 6 optional int percent; 130 | }; 131 | 132 | /** 133 | * Task任务 134 | */ 135 | struct TaskReq 136 | { 137 | 0 optional vector taskItemReq; 138 | 1 optional string taskNo; 139 | 2 optional bool serial; 140 | 3 optional string userName; 141 | 4 optional bool isElegant = false; 142 | 5 optional int eachNum = 1; 143 | }; 144 | 145 | struct TaskRsp 146 | { 147 | 0 optional vector taskItemRsp; 148 | 1 optional string taskNo; 149 | 2 optional bool serial; 150 | 3 optional string userName; 151 | 4 optional EMTaskStatus status; 152 | 5 optional string createTime; 153 | 6 optional string executeLog; 154 | }; 155 | 156 | struct FrameworkServer 157 | { 158 | 0 require string serverName; 159 | 1 require string nodeName; 160 | 2 require string objName; 161 | }; 162 | 163 | struct ServerConf 164 | { 165 | 0 optional string application; 166 | 1 optional string serverName; 167 | 2 optional string nodeName; 168 | 3 optional string basePath; 169 | 4 optional string exePath; 170 | 5 optional string settingState = "active"; 171 | 6 optional string profile; 172 | 7 optional string serverType; 173 | 8 optional string startScript; 174 | 9 optional string stopScript; 175 | 10 optional string monitorScript; 176 | 11 optional int asyncThreadNum = 3; 177 | 12 optional string enableGroup = "M"; //N/Y 178 | 13 optional string ipGroupName; //N/Y 179 | }; 180 | 181 | struct AdapterConf 182 | { 183 | 0 optional string adapterName; 184 | 1 optional int threadNum = 5; 185 | 2 optional string endpoint; 186 | 3 optional int maxConnections = 10240; 187 | 4 optional string allowIp; 188 | 5 optional string servant; 189 | 6 optional int queuecap = 100000; 190 | 7 optional int queuetimeout = 600000; 191 | 8 optional string protocol = "tars"; //tars/not_tars 192 | }; 193 | 194 | struct PluginConf 195 | { 196 | 0 optional string name; 197 | 1 optional string name_en; 198 | 2 optional string obj; 199 | 3 optional int type; //类型: 1, 全局插件; 2: 服务级别插件 200 | 4 optional string path; //转发路径 201 | 5 optional bool k8s = false; 202 | 6 optional int fextern = 0; //外部连接 203 | }; 204 | 205 | struct ServerTree 206 | { 207 | 0 optional string application; 208 | 1 optional string server_name; 209 | 2 optional string enable_set; 210 | 3 optional string set_name; 211 | 4 optional string set_area; 212 | 5 optional string set_group; 213 | }; 214 | 215 | struct PatchPackage 216 | { 217 | 0 optional int id; 218 | 1 optional string md5; 219 | }; 220 | 221 | struct ApplicationServerName 222 | { 223 | 0 optional string application; 224 | 1 optional string serverName; 225 | }; 226 | 227 | /** 228 | * admin 管理接口 229 | */ 230 | interface AdminReg 231 | { 232 | /** 233 | * 长连接模式下, tarsnode上报自身 234 | * 235 | * @param nodeName node名称(通常是IP, 要能被其他节点解析的地址) 236 | * @param sid, sessionId, 客户端生成的唯一字符串 237 | * @return 注册是否成功 238 | */ 239 | int reportNode(ReportNode rn); 240 | 241 | /** 242 | * 长连接模式, 有代理的模式下, 同时tarsnode下线 243 | * 244 | * @param nodeName node名称(通常是IP, 要能被其他节点解析的地址) 245 | * @param sid, sessionId, 客户端生成的唯一字符串 246 | * @return 247 | */ 248 | int deleteNode(ReportNode rn); 249 | 250 | /** 251 | * tarsnode上报执行命令的结果 252 | * 253 | */ 254 | int reportResult(int requestId, string funcName, int ret, string result); 255 | 256 | /** 257 | * 请求异步任务 258 | * 259 | * @param taskList : 任务列表 260 | * @param serial: 串行 261 | * 262 | * @return 0: 成功, <0:失败 263 | */ 264 | int addTaskReq(TaskReq taskReq); 265 | 266 | /** 267 | * 获取任务状态 268 | * 269 | * @param taskIdList : 任务列表id 270 | * 271 | * @return 任务状态 272 | */ 273 | int getTaskRsp(string taskNo, out TaskRsp taskRsp); 274 | 275 | /** 276 | * 获取根据应用, 服务, 命令字获取历史任务状态 277 | * 278 | * @param application : 应用名 279 | * @param serverName : 服务名 280 | * @param command : 命令字 281 | * 282 | * @return TaskRsp 283 | */ 284 | int getTaskHistory(string application, string serverName, string command, out vector taskRsps); 285 | 286 | /** 287 | * 设置task item的信息(内部使用) 288 | * @param itemNo, itemno 289 | * @param startTime, 开始时间 290 | * @param endTime, 结束时间 291 | * @param status, 状态 292 | * @param log, 异常日志 293 | * @return int, 0: 成功, <0: 失败 294 | */ 295 | int setTaskItemInfo(string itemNo, map info); 296 | 297 | ////////////////////////////////////////////////////////////////////////////////// 298 | /** 299 | * 获取application列表 300 | * 301 | * @param out result : 结果描述 302 | * 303 | * @return application列表 304 | */ 305 | vector getAllApplicationNames(out string result); 306 | 307 | /** 308 | * 获取node列表 309 | * 310 | * @param out result : 结果描述 311 | * 312 | * @return node 列表 313 | */ 314 | vector getAllNodeNames(out string result); 315 | 316 | /** 317 | * ping node 318 | * 319 | * @param name: node id 320 | * @param out result : 结果描述 321 | * 322 | * @return : true-ping通;false-不通 323 | */ 324 | bool pingNode(string name, out string result); 325 | 326 | /** 327 | * get node version 328 | * 329 | * @param name: node id 330 | * @param out version :版本 331 | * @param out result : 结果描述 332 | * 333 | * @return : 0-成功 others-失败 334 | */ 335 | int getNodeVesion(string name, out string version, out string result); 336 | 337 | /** 338 | * 停止 node 339 | * 340 | * @param name: node id 341 | * @param out result : 结果描述 342 | * 343 | * @return : 0-成功 others-失败 344 | */ 345 | int shutdownNode(string name, out string result); 346 | 347 | /** 348 | * 获取server列表 349 | * 350 | * @param name: null 351 | * @param out result : 结果描述 352 | * 353 | * @return: server列表及相关信息 354 | */ 355 | vector > getAllServerIds(out string result); 356 | 357 | /** 358 | * 获取特定server状态 359 | * 360 | * @param application: 应用 361 | * @param serverName : server名 362 | * @param nodeNmae : node id 363 | * @param out state : 状态 364 | * @param out result : 结果描述 365 | * 366 | * @return : 返回值详见tarsErrCode枚举值 367 | */ 368 | int getServerState(string application,string serverName, string nodeName, out ServerStateDesc state, out string result); 369 | 370 | /** 371 | * 获取某ip所属group 用于机房部署 例如某ip属于那个机房 372 | * 373 | * @param nodeNmae : ip 374 | * @param out int : group id 375 | * @param out result : 结果描述 376 | * 377 | * @return : 处理结果 378 | */ 379 | int getGroupId(string ip, out int groupId, out string result); 380 | 381 | /** 382 | * 启动特定server 383 | * 384 | * @param application: 应用 385 | * @param serverName : server名 386 | * @param nodeName : node id 387 | * @param out result : 结果描述 388 | * 389 | * @return : 返回值详见tarsErrCode枚举值 390 | */ 391 | int startServer(string application,string serverName, string nodeName, out string result); 392 | 393 | /** 394 | * 停止特定server 395 | * 396 | * @param application: 应用 397 | * @param serverName : server名 398 | * @param nodeName : node id 399 | * @param out result : 结果描述 400 | * 401 | * @return : 返回值详见tarsErrCode枚举值 402 | */ 403 | int stopServer(string application,string serverName, string nodeName, out string result); 404 | 405 | /** 406 | * 重启特定server 407 | * 408 | * @param application: 应用 409 | * @param serverName : server名 410 | * @param nodeName : node id 411 | * @param out result : 结果描述 412 | * 413 | * @return : 返回值详见tarsErrCode枚举值 414 | */ 415 | int restartServer(string application,string serverName, string nodeName, out string result); 416 | 417 | /** 418 | * 从Node上删除特定server 419 | * 420 | * @param application: 应用 421 | * @param serverName : server名 422 | * @param nodeName : node id 423 | * @param out result : 结果描述 424 | * 425 | * @return : 返回值详见tarsErrCode枚举值 426 | */ 427 | int destroyServer(string application,string serverName, string nodeName, out string result); 428 | 429 | /** 430 | * 通知server 431 | * 432 | * @param application: 应用 433 | * @param serverName : server名 434 | * @param nodeName : node id 435 | * @param command : 命令 436 | * @param out result : 结果描述 437 | * 438 | * @return : 返回值详见tarsErrCode枚举值 439 | */ 440 | int notifyServer(string application,string serverName, string nodeName, string command, out string result); 441 | 442 | /** 443 | * 发布服务 444 | * @param req 445 | * @return 0: 成功, <0: 失败 446 | */ 447 | int batchPatch(PatchRequest req, out string result); 448 | 449 | /** 450 | * 卸载服务 451 | * @param application 452 | * @param serverName 453 | * @param nodeName 454 | * @return 0: 成功, <0: 失败 455 | */ 456 | int undeploy(string application, string serverName, string nodeName, string user, out string log); 457 | 458 | /** 459 | * 更新发布状态 460 | * 461 | * 462 | * @return : 返回值详见tarsErrCode枚举值 463 | */ 464 | int updatePatchLog(string application, string serverName, string nodeName, string patchId, string user, string patchType, bool succ); 465 | 466 | /** 467 | * 获取服务发布进度 468 | * @param application : 服务所属应用名 469 | * @param serverName : 服务名 470 | * @param nodeName : node id 471 | * @out tPatchInfo :发布信息 472 | * 473 | * @return : 返回值详见tarsErrCode枚举值 474 | */ 475 | int getPatchPercent(string application,string serverName,string nodeName,out PatchInfo tPatchInfo); 476 | 477 | /** 478 | *备份和删除cache的共享内存 479 | *@param sFullCacheName cache服务全名 480 | *@param sBackupPath 备份路径 481 | *@param sKey 共享内存的key值,如果为空则通过路径和‘D’生成 482 | *@return int 483 | */ 484 | int delCache(string nodeName, string sFullCacheName,string sBackupPath, string sKey, out string result); 485 | 486 | /** 487 | * 加载特定server 488 | * 489 | * @param application: 应用 490 | * @param serverName : server名 491 | * @param nodeName : node id 492 | * @param out result : 结果描述 493 | * 494 | * @return : 返回值详见tarsErrCode枚举值 495 | */ 496 | int loadServer(string application, string serverName, string nodeName, out string result); 497 | 498 | /** 499 | * 获取相应模板 500 | * 501 | * @param profileName: 模板名称 502 | * @param out profileTemplate: 模板内容 503 | * @param out resultDesc: 结果描述 504 | * 505 | * @return : 0-成功 others-失败 506 | */ 507 | int getProfileTemplate(string profileName , out string profileTemplate, out string resultDesc); 508 | 509 | /** 510 | * 获取服务相应模板 511 | * 512 | * @param application: 应用 513 | * @param serverName : server名 514 | * @param nodeName : node id 515 | * @param out profileTemplate: 模板内容 516 | * @param out resultDesc: 结果描述 517 | * 518 | * @return : 0-成功 others-失败 519 | */ 520 | int getServerProfileTemplate(string application, string serverName, string nodeName, out string profileTemplate, out string resultDesc); 521 | 522 | /** 523 | * node通过接口获取连接上主控的node ip 524 | * @param sNodeIp: node 的ip 525 | * 526 | * @return 0-成功 others-失败 527 | */ 528 | int getClientIp(out string sClientIp); 529 | 530 | /** 531 | *  获取日志文件列表 532 | * 533 | * @param application: 应用 534 | * @param serverName : server名 535 | * @param nodeName : node id 536 | * @param out result : 结果描述 537 | * 538 | * @return : 返回值详见tarsErrCode枚举值 539 | */ 540 | int getLogFileList(string application, string serverName, string nodeName, out vector logFileList); 541 | 542 | /** 543 | *  获取日志文件内容 544 | * 545 | * @param application: 应用 546 | * @param serverName : server名 547 | * @param nodeName : node id 548 | * @param logFile : 日志文件 549 | * @param cmd : 命令信息 550 | * @param out fileData : 结果描述 551 | * 552 | * @return : 返回值详见tarsErrCode枚举值 553 | */ 554 | int getLogData(string application, string serverName, string nodeName, string logFile, string cmd, out string fileData); 555 | 556 | /** 557 | * 获取某台服务器的基本负载情况 558 | */ 559 | int getNodeLoad(string application, string serverName, string nodeName, int pid, out string fileData); 560 | 561 | /** 562 | * 删除发布包 563 | * @param application : 服务所属应用名 564 | * @param serverName : 服务名 565 | * @param patchFile: patchFile 566 | * 567 | * @return : 0-成功 others-失败 568 | */ 569 | int deletePatchFile(string application,string serverName, string patchFile); 570 | 571 | /** 572 | * get server need check 573 | * 574 | * @return : 0-成功 others-失败 575 | */ 576 | int getServers(out vector servers); 577 | 578 | /** 579 | * 检查框架的联通性 580 | * 581 | * @return : 0-成功 others-失败 582 | */ 583 | int checkServer(FrameworkServer server); 584 | 585 | /** 586 | * 获取framework的version 587 | * 588 | * @return : 0-成功 others-失败 589 | */ 590 | int getVersion(out string version); 591 | 592 | /** 593 | * 暂停服务,关闭服务流量,无损发布用等 594 | * 595 | * @return : 0-成功 others-失败 596 | */ 597 | int updateServerFlowState(string application, string serverName, vector nodeList, bool bActive); 598 | 599 | /** 600 | * 强制node执行docker登录逻辑 601 | * @return 0: 成功, others: 失败 602 | */ 603 | int forceDockerLogin(string nodeName, out vector result); 604 | 605 | /** 606 | * 检查是否登录镜像仓库 607 | * 608 | * @params result: 是否可以登录仓库 609 | */ 610 | int checkDockerRegistry(string registry, string userName, string password, out string result); 611 | 612 | /** 613 | * 调用某台主控, 拉取基础镜像 614 | * @params result: 返回信息 615 | */ 616 | int dockerPull(string baseImageId); 617 | 618 | /** 619 | * 获取tarsnode长连接心跳 620 | * @params nodeNames: 节点信息 621 | * @params heartbeats: 心跳信息<节点名称, 心跳时间> 622 | */ 623 | int getNodeList(vector nodeNames, out map heartbeats); 624 | 625 | /** 626 | * 卸载服务(从数据库中删除数据) 627 | * 628 | * @param application: 应用 629 | * @param serverName : server名 630 | * @param nodeName : node id 631 | * @param out result : 结果描述 632 | * 633 | * @return : 返回值详见tarsErrCode枚举值 634 | */ 635 | int uninstallServer(string application, string serverName, string nodeName, out string result); 636 | 637 | /** 638 | * 是否有服务 639 | * 640 | * @param application: 服务基本信心 641 | * @param serverName: 是否替换 642 | * @return : 返回值详见tarsErrCode枚举值 643 | */ 644 | int hasServer(string application, string serverName, out bool has); 645 | 646 | /** 647 | * 新增服务 648 | * 649 | * @param conf: 服务基本信心 650 | * @param replace: 是否替换(false时, 如果有冲突就insert失败) 651 | * @return : 返回值详见tarsErrCode枚举值 652 | */ 653 | int insertServerConf(ServerConf conf, bool replace); 654 | 655 | /** 656 | * 新增adapter 657 | * 658 | * @param conf: 服务基本信心 659 | * @param replace: 是否替换(false时, 如果有冲突就insert失败) 660 | * @return : 返回值详见tarsErrCode枚举值 661 | */ 662 | int insertAdapterConf(string sApplication, string serverName, string nodeName, AdapterConf conf, bool replace); 663 | 664 | /** 665 | * 新增配置文件 666 | * 667 | * @param replace: 是否替换(false时, 如果有冲突就insert失败) 668 | * @return : 返回值详见tarsErrCode枚举值 669 | */ 670 | int insertConfigFile(string sFullServerName, string fileName, string content, string nodeName, int level, bool replace); 671 | 672 | /** 673 | * 获取配置文件ID 674 | * 675 | * @return : 返回值详见tarsErrCode枚举值 676 | */ 677 | int getConfigFileId(string sFullServerName, string fileName, string nodeName, int level, out int configId); 678 | 679 | /** 680 | * 新增配置文件 681 | * 682 | * @param replace: 是否替换(false时, 如果有冲突就insert失败) 683 | * @return : 返回值详见tarsErrCode枚举值 684 | */ 685 | int insertHistoryConfigFile(int configId, string reason, string content, bool replace); 686 | 687 | /** 688 | * 注册插件 689 | * 690 | * @return : 返回值详见tarsErrCode枚举值 691 | */ 692 | int registerPlugin(PluginConf conf); 693 | 694 | /** 695 | * 是否有有开发权限 696 | * 697 | * @return : 返回值详见tarsErrCode枚举值 698 | */ 699 | int hasDevAuth(string application, string serverName, string uid, out bool has); 700 | 701 | /** 702 | * 是否有运维权限 703 | * 704 | * @return : 返回值详见tarsErrCode枚举值 705 | */ 706 | int hasOpeAuth(string application, string serverName, string uid, out bool has); 707 | 708 | /** 709 | * 是否有有管理员权限 710 | * 711 | * @return : 返回值详见tarsErrCode枚举值 712 | */ 713 | int hasAdminAuth(string uid, out bool has); 714 | 715 | /** 716 | * 解析ticket, uid不为空则有效, 否则无效需要重新登录 717 | * 718 | * @return : 返回值详见tarsErrCode枚举值 719 | */ 720 | int checkTicket(string ticket, out string uid); 721 | 722 | /** 723 | * 获取目录树 724 | * 725 | * @return : 返回值详见tarsErrCode枚举值 726 | */ 727 | int getServerTree(out vector tree); 728 | 729 | /** 730 | * 获取发布包信息(packageType无效) 731 | * 732 | * @return : 返回值详见tarsErrCode枚举值 733 | */ 734 | int getPatchPackage(string application, string serverName, int packageType, int defaultVersion, out PatchPackage pack); 735 | 736 | /** 737 | * 根据服务完整名称, 获取服务基本信息列表 738 | * 739 | * @return : 返回值详见tarsErrCode枚举值 740 | */ 741 | int getServerNameList(vector fullServerName, out vector> serverList); 742 | }; 743 | }; 744 | 745 | -------------------------------------------------------------------------------- /framework/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(OUT_DEPENDS_LIST) 2 | 3 | set(SERVANT_PROTOCOL "${servant_SOURCE_DIR}/protocol/servant") 4 | 5 | complice_tars(OUT_DEPENDS_LIST "" ${SERVANT_PROTOCOL}) 6 | 7 | add_custom_target(FRAMEWORK-PROTOCOL ALL DEPENDS ${OUT_DEPENDS_LIST} COPY-SERVENT-TARS) 8 | 9 | set(FRAMEWORKPROTOCOLS 10 | AdminReg.tars 11 | AdminReg.h 12 | MonitorQuery.tars 13 | MonitorQuery.h 14 | Node.tars 15 | Node.h 16 | NodePush.tars 17 | NodePush.h 18 | Topology.tars 19 | Topology.h 20 | TraceData.h 21 | TraceData.tars 22 | NodeDescriptor.tars 23 | NodeDescriptor.h 24 | Patch.tars 25 | Patch.h 26 | Registry.tars 27 | Registry.h 28 | RegistryDescriptor.tars 29 | RegistryDescriptor.h) 30 | 31 | INSTALL(FILES ${FRAMEWORKPROTOCOLS} DESTINATION include/framework) 32 | 33 | -------------------------------------------------------------------------------- /framework/MonitorQuery.tars: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tars available. 3 | * 4 | * Copyright (C) 2016THL 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 | module tars 18 | { 19 | enum OP 20 | { 21 | EQ, 22 | GT, 23 | GTE, 24 | LT, 25 | LTE, 26 | LIKE 27 | }; 28 | 29 | struct Condition 30 | { 31 | 0 require string field; 32 | 1 require OP op; 33 | 2 require string val; 34 | }; 35 | 36 | struct MonitorQueryReq 37 | { 38 | 0 require string uid; 39 | 1 require string method = "query"; 40 | 41 | //query table 42 | //tars_stat / tars_property 43 | 2 require string dataid; 44 | 45 | 3 require string date; 46 | 47 | 4 require string tflag1; 48 | 5 require string tflag2; 49 | 50 | //query conditions 51 | 6 require vector conditions; 52 | 53 | //stat item 54 | //tars_stat ["succ_count", "timeout_count", 'exce_count", "total_time"] 55 | //tars_property ["value"] 56 | 7 require vector indexs; 57 | 58 | //group field 59 | //tars_stat [f_date、master_name/interface_name/master_ip/slave_ip] or [f_tflag] 60 | //tars_property [f_date、master_name/master_ip/property_name/policy] or [f_tflag] 61 | 8 require vector groupby; 62 | }; 63 | 64 | struct MonitorQueryRsp 65 | { 66 | 67 | 0 require int ret; //0: succ, -1: error 68 | 1 optional string msg; 69 | 2 require string lastTime; 70 | 3 require int activeDb; 71 | 4 require int totalDb; 72 | 5 require vector retThreads; 73 | 6 optional map> result; //key: group1,group2,group3... 74 | }; 75 | 76 | interface MonitorQuery 77 | { 78 | int query(MonitorQueryReq req, out MonitorQueryRsp rsp); 79 | }; 80 | }; -------------------------------------------------------------------------------- /framework/Node.tars: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tars available. 3 | * 4 | * Copyright (C) 2016THL 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 "NodeDescriptor.tars" 18 | #include "RegistryDescriptor.tars" 19 | module tars 20 | { 21 | 22 | interface Node 23 | { 24 | /** 25 | * 销毁指定服务 26 | * @param application 服务所属应用名 27 | * @param serverName 服务名 28 | * @return int 0成功 其它失败 29 | */ 30 | int destroyServer(string application,string serverName, out string result); 31 | 32 | /** 33 | * 增强的发布接口 34 | * pushRequest 插入发布请求到队列 35 | * @param req 发布请求 36 | * @return int 0成功 其它失败 37 | */ 38 | int patchPro(PatchRequest req, out string result); 39 | 40 | ///** 41 | //* 下载指定文件 42 | //* @param application 服务所属应用名 43 | //* @param serverName 服务名 44 | //* @param file 文件名 45 | //* @param out result 失败说明 46 | //* @return int 0成功 非0失败 47 | //*/ 48 | //int addFile(string application, string serverName, string file,out string result); 49 | 50 | ///** 51 | //* 获取node名称 52 | //* @return string 53 | //*/ 54 | //string getName(); 55 | 56 | ///** 57 | //* 获取node上负载 58 | //* @return LoadInfo 59 | //*/ 60 | //LoadInfo getLoad(); 61 | 62 | /** 63 | * 关闭node 64 | * @return int 65 | */ 66 | int shutdown(out string result); 67 | 68 | /** 69 | * 关闭node上所有服务 70 | * @return int 71 | */ 72 | int stopAllServers(out string result); 73 | 74 | /** 75 | * 载入指定服务 76 | * @param application 服务所属应用名 77 | * @param serverName 服务名 78 | * @return int 79 | */ 80 | int loadServer(string application, string serverName, out string result); 81 | 82 | /** 83 | * 启动指定服务 84 | * @param application 服务所属应用名 85 | * @param serverName 服务名 86 | * @return int 87 | */ 88 | int startServer(string application,string serverName, out string result); 89 | 90 | /** 91 | * 停止指定服务 92 | * @param application 服务所属应用名 93 | * @param serverName 服务名 94 | * @return int 95 | */ 96 | int stopServer(string application,string serverName, out string result); 97 | 98 | /** 99 | * 通知服务 100 | * @return int 101 | */ 102 | int notifyServer(string application, string serverName, string command, out string result); 103 | 104 | ///** 105 | //* 获取指定服务pid进程号 106 | //* @param application 服务所属应用名 107 | //* @param serverName 服务名 108 | //* @return int 109 | //*/ 110 | //int getServerPid(string application,string serverName, out string result); 111 | 112 | ///** 113 | //* 获取指定服务registry设置的状态 114 | //* @param application 服务所属应用名 115 | //* @param serverName 服务名 116 | //* @return int 117 | //*/ 118 | //ServerState getSettingState(string application,string serverName, out string result); 119 | 120 | ///** 121 | //* 获取指定服务状态 122 | //* @param application 服务所属应用名 123 | //* @param serverName 服务名 124 | //* @return ServerState 125 | //*/ 126 | //ServerState getState(string application,string serverName, out string result); 127 | 128 | /** 129 | * 获取指定服务在node信息 130 | * @param application 服务所属应用名 131 | * @param serverName 服务名 132 | * @return ServerState 133 | */ 134 | int getStateInfo(string application,string serverName,out ServerStateInfo info,out string result); 135 | 136 | ///** 137 | //* 同步服务状态 138 | //* @param application 服务所属应用名 139 | //* @param serverName 服务名 140 | //* @return int 141 | //*/ 142 | //int synState(string application,string serverName, out string result); 143 | 144 | /** 145 | * 发布服务进度 146 | * @param application 服务所属应用名 147 | * @param serverName 服务名 148 | * @out tPatchInfo下载信息 149 | * @return int 150 | */ 151 | int getPatchPercent(string application,string serverName,out PatchInfo tPatchInfo); 152 | 153 | /** 154 | *备份和删除cache的共享内存 155 | *@param sFullCacheName cache服务全名 156 | *@param sBackupPath 备份路径 157 | *@param sKey 共享内存的key值,如果为空则通过路径和‘D’生成 158 | *@return int 159 | */ 160 | int delCache(string sFullCacheName,string sBackupPath, string sKey, out string result); 161 | // 162 | ///** 163 | //* 获取机器没有使用的共享内存的key列表,每台机器最多分配256个key, -1分配失败 164 | //*/ 165 | //int getUnusedShmKeys(int count, out vector shm_keys); 166 | 167 | /** 168 | * 列举某个app下面某个服务的日志文件列表,以文件最后修改时间倒排序 169 | */ 170 | int getLogFileList(string application, string serverName, out vector logFileList); 171 | 172 | /** 173 | * 获取某个日志文件的内容,cmd表示参数, 比如 tail -1000 ${logFile}| grep xxx 174 | */ 175 | int getLogData(string application, string serverName, string logFile, string cmd, out string fileData); 176 | 177 | /** 178 | * 获取节点负载 179 | */ 180 | int getNodeLoad(string application, string serverName, int pid, out string fileData); 181 | 182 | /** 183 | * 强制docker登录 184 | */ 185 | int forceDockerLogin(out vector result); 186 | }; 187 | 188 | }; 189 | 190 | -------------------------------------------------------------------------------- /framework/NodeDescriptor.tars: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tars available. 3 | * 4 | * Copyright (C) 2016THL 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 | module tars 18 | { 19 | enum ServerState 20 | { 21 | Inactive, 22 | Activating, 23 | Active, 24 | Deactivating, 25 | Destroying, 26 | Destroyed, 27 | }; 28 | 29 | struct LoadInfo 30 | { 31 | //过去1分钟负载 32 | 0 require float avg1; 33 | //过去5分钟负载 34 | 1 require float avg5; 35 | //过去15分钟负载 36 | 2 require float avg15; 37 | //1分钟内cpu使用率均值 38 | 3 optional int avgCpu; 39 | }; 40 | 41 | struct PatchInfo 42 | { 43 | //是否正在发布 44 | 0 require bool bPatching = false; 45 | //发布百分比 46 | 1 require int iPercent; 47 | //最近百分比修改时间 48 | 2 require int iModifyTime; 49 | //版本 50 | 3 require string sVersion; 51 | //结果描述 52 | 4 require string sResult; 53 | //发布结果 54 | 5 optional bool bSucc = false; 55 | }; 56 | 57 | struct NodeInfo 58 | { 59 | 0 require string nodeName; 60 | 1 require string nodeObj; 61 | 2 require string endpointIp; 62 | 3 require int endpointPort; 63 | 4 require short timeOut; 64 | 5 require string dataDir; 65 | 6 optional string version; 66 | 7 optional string coreFileSize; //启动tarsnode时,从start.tmp获取,设置的core大小,core file size,因为可能值为unlimited 67 | 8 optional int openFiles; //启动tarsnode时,从start.tmp获取,设置的open files 68 | }; 69 | 70 | //上报节点 71 | struct ReportNode 72 | { 73 | 0 require string nodeName; 74 | 1 require string sid; //进程唯一 75 | }; 76 | 77 | struct ServerStateInfo 78 | { 79 | //present state 80 | 0 require ServerState serverState; 81 | 1 require int processId; 82 | 2 optional string nodeName; 83 | 3 optional string application; 84 | 4 optional string serverName; 85 | //setting states 86 | 5 optional ServerState settingState; 87 | 6 optional map exState; 88 | }; 89 | 90 | struct PatchRequest 91 | { 92 | 0 require string appname; 93 | 1 require string servername; 94 | 2 require string nodename; 95 | 3 require string groupname; 96 | 4 require string binname; 97 | 5 require string version; 98 | 6 require string user; 99 | 7 require string servertype; 100 | 8 require string patchobj; 101 | 9 require string md5; 102 | //操作系统类型,如:suse、tlinux等 103 | 10 optional string ostype; 104 | // 带路径的发布包文件名,如果未指定filepath,则node将根据appname、servername、version、ostype等按规则组装发布包文件路径; 105 | // 若已指定filepath,则node从filepath下载发布包,node不检查filepath的合法性。 106 | 11 optional string filepath; 107 | }; 108 | }; 109 | 110 | -------------------------------------------------------------------------------- /framework/NodePush.tars: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tars available. 3 | * 4 | * Copyright (C) 2016THL 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 "NodeDescriptor.tars" 18 | #include "RegistryDescriptor.tars" 19 | 20 | module tars 21 | { 22 | interface NodePush 23 | { 24 | /** 25 | * 检查是否活着 26 | */ 27 | void ping(out int requestId, out string nodeName); 28 | 29 | /** 30 | * 增强的发布接口 31 | * pushRequest 插入发布请求到队列 32 | * @param req 发布请求 33 | * @return int 0成功 其它失败 34 | */ 35 | void patchPro(out int requestId, out string nodeName, out PatchRequest req); 36 | 37 | /** 38 | * 关闭node 39 | */ 40 | void shutdown(out int requestId, out string nodeName); 41 | 42 | /** 43 | * 载入指定服务 44 | * @param application 服务所属应用名 45 | * @param serverName 服务名 46 | */ 47 | void loadServer(out int requestId, out string nodeName, out string application, out string serverName); 48 | 49 | /** 50 | * 删除节点服务 51 | * @param application 服务所属应用名 52 | * @param serverName 服务名 53 | */ 54 | void destroyServer(out int requestId, out string nodeName, out string application, out string serverName); 55 | 56 | /** 57 | * 启动指定服务 58 | * @param application 服务所属应用名 59 | * @param serverName 服务名 60 | */ 61 | void startServer(out int requestId, out string nodeName, out string application, out string serverName); 62 | 63 | /** 64 | * 停止指定服务 65 | * @param application 服务所属应用名 66 | * @param serverName 服务名 67 | */ 68 | void stopServer(out int requestId, out string nodeName, out string application, out string serverName); 69 | 70 | /** 71 | * 通知服务 72 | */ 73 | void notifyServer(out int requestId, out string nodeName, out string application, out string serverName, out string command); 74 | 75 | /** 76 | * 获取指定服务在node信息 77 | * @param application 服务所属应用名 78 | * @param serverName 服务名 79 | */ 80 | void getStateInfo(out int requestId, out string nodeName, out string application, out string serverName); 81 | 82 | /** 83 | * 发布服务进度 84 | * @param application 服务所属应用名 85 | * @param serverName 服务名 86 | * @out tPatchInfo下载信息 87 | */ 88 | void getPatchPercent(out int requestId, out string nodeName, out string application, out string serverName); 89 | 90 | /** 91 | *备份和删除cache的共享内存 92 | *@param sFullCacheName cache服务全名 93 | *@param sBackupPath 备份路径 94 | *@param sKey 共享内存的key值,如果为空则通过路径和‘D’生成 95 | *@return int 96 | */ 97 | void delCache(out int requestId, out string nodeName, out string sFullCacheName, out string sBackupPath, out string sKey); 98 | 99 | /** 100 | * 列举某个app下面某个服务的日志文件列表,以文件最后修改时间倒排序 101 | */ 102 | void getLogFileList(out int requestId, out string nodeName, out string application, out string serverName); 103 | 104 | /** 105 | * 获取某个日志文件的内容,cmd表示参数, 比如 tail -1000 ${logFile}| grep xxx 106 | */ 107 | void getLogData(out int requestId, out string nodeName, out string application, out string serverName, out string logFile, out string cmd); 108 | 109 | /** 110 | * 获取节点负载 111 | */ 112 | void getNodeLoad(out int requestId, out string nodeName, out string application, out string serverName, out int pid); 113 | 114 | /** 115 | * 强制docker登录 116 | */ 117 | void forceDockerLogin(out int requestId, out string nodeName); 118 | }; 119 | 120 | }; 121 | 122 | -------------------------------------------------------------------------------- /framework/Patch.tars: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tars available. 3 | * 4 | * Copyright (C) 2016THL 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 | module tars 18 | { 19 | 20 | struct FileInfo 21 | { 22 | /** 23 | * 文件路径, 相对listFileInfo中path的路径 24 | **/ 25 | 0 require string path; 26 | 27 | /** 28 | * 文件大小, 字节数 29 | **/ 30 | 1 require int size; 31 | 32 | /** 33 | * 文件是否可执行 34 | */ 35 | 2 require bool canExec; 36 | 37 | /** 38 | * 该文件的MD5值 39 | */ 40 | 3 optional string md5; 41 | }; 42 | 43 | struct FileContent 44 | { 45 | /** 46 | * 文件md5,文件id并校验最终文件准确性 47 | **/ 48 | 0 require string md5; 49 | /** 50 | * 文件名称 51 | **/ 52 | 1 require string name; 53 | /** 54 | * 是否第一个包(默认串行) 55 | **/ 56 | 2 require bool firstChunk; 57 | /** 58 | * 是否最后一个包(默认串行) 59 | **/ 60 | 3 require bool lastChunk; 61 | /** 62 | * 文件内容 63 | **/ 64 | 4 require vector content; 65 | }; 66 | 67 | /** 68 | * 69 | * 发布服务的接口 70 | * 71 | **/ 72 | interface Patch 73 | { 74 | /** 75 | * 获取路径下所有文件列表信息 76 | * @param path, 目录路径, 路径中不能包含.. 77 | * @param vector, 文件列表信息 78 | * @return int, 返回0表示path是目录, 1表示path是文件, -1表示路径错误 79 | */ 80 | int listFileInfo(string path, out vector vf); 81 | 82 | /** 83 | * 下载文件 84 | * @param file, 文件路径 85 | * @param pos, 从什么位置开始下载 86 | * @param vector, 文件内容 87 | * @param int, 0:读取表示成功, 1:读取到文件末尾了, <0: 读取失败 88 | */ 89 | int download(string file, int pos, out vector vb); 90 | 91 | /** 92 | * 准备好需要patch的文件 93 | * @param patchFile, 需要发布的文件名 94 | * @return int, 0: 成功, <0: 失败 95 | */ 96 | int preparePatchFile(string app, string serverName, string patchFile, out string result); 97 | 98 | /** 99 | * 删除发布文件 100 | * @return int, 0: 成功, <0: 失败 101 | */ 102 | int deletePatchFile(string app, string serverName, string patchFile); 103 | 104 | /** 105 | * 上传文件 106 | * @param content, 文件分片 107 | * @param int, 0:上传成功, <0: 上传失败 108 | */ 109 | int upload(string app, string serverName, FileContent content); 110 | }; 111 | 112 | }; 113 | -------------------------------------------------------------------------------- /framework/Registry.tars: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tars available. 3 | * 4 | * Copyright (C) 2016THL 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 "NodeDescriptor.tars" 18 | #include "RegistryDescriptor.tars" 19 | 20 | module tars 21 | { 22 | struct PatchResult 23 | { 24 | 0 require string sApplication; 25 | 1 require string sServerName; 26 | 2 require string sNodeName; 27 | 3 require string sVersion; 28 | 4 require string sUserName; 29 | }; 30 | 31 | struct BaseImageInfo 32 | { 33 | 0 optional string id; 34 | 1 optional string image; 35 | 2 optional string registryId; 36 | 3 optional string sha; 37 | }; 38 | 39 | struct DockerRegistry 40 | { 41 | 0 optional string sId; 42 | 1 optional string sRegistry; //仓库地址 43 | 2 optional string sUserName; //用户名 44 | 3 optional string sPassword; //密码 45 | 4 optional bool bSucc = false;//是否成功登录过 46 | 5 optional vector baseImages; 47 | }; 48 | 49 | struct FrameworkKey 50 | { 51 | 0 optional string cuid; 52 | 1 optional string priKey; 53 | }; 54 | 55 | /** 56 | * registry接口 57 | */ 58 | interface Registry 59 | { 60 | /** 61 | * 长连接模式下, tarsnode上报自身 62 | * 63 | * @param ni node详细信息 64 | * @param li node机器负载信息 65 | * 66 | * @return 注册是否成功 67 | */ 68 | int reportNode(ReportNode rn); 69 | 70 | /** 71 | * node启动的时候往registry注册一个session 72 | * 73 | * @param nodeName node名称 74 | * @param ni node详细信息 75 | * @param li node机器负载信息 76 | * 77 | * @return 注册是否成功 78 | */ 79 | int registerNode(string nodeName, NodeInfo ni, LoadInfo li); 80 | 81 | /** 82 | * node上报心跳及机器负载 83 | * 84 | * @param nodeName node名称 85 | * @param load node机器负载信息 86 | */ 87 | int keepAlive(string nodeName, LoadInfo load); 88 | 89 | /** 90 | * 获取在该node部署的server列表 91 | * 92 | * @param app: 应用 93 | * @param serverName: server 名 94 | * @param nodeName : node id 95 | * 96 | * @return server信息列表 97 | */ 98 | vector getServers(string app, string serverName, string nodeName); 99 | 100 | /** 101 | * 更新server状态 102 | * 103 | * @param app: 应用 104 | * @param serverName: server 名 105 | * @param nodeName : node id 106 | * @param state : server状态信息 107 | * 108 | * @return 0-成功 others-失败 109 | */ 110 | int updateServer(string app, string serverName, string nodeName, ServerStateInfo state); 111 | 112 | /** 113 | * 批量更新server状态 114 | * 115 | * @param state : server状态信息 116 | * 117 | * @return 0-成功 others-失败 118 | */ 119 | int updateServerBatch(vector vState); 120 | 121 | /** 122 | * node停止,释放node的会话 123 | * 124 | * @param nodeName node名称 125 | * 126 | * @return 0-成功 others-失败 127 | */ 128 | int destroyNode(string nodeName); 129 | 130 | /** 131 | * 上报server的tars库版本 132 | * @param app: 应用 133 | * @param serverName: server 名 134 | * @param nodeName : node id 135 | * @param version: server基于的tars版本号 136 | * 137 | * @return 0-成功 others-失败 138 | */ 139 | int reportVersion(string app, string serverName, string nodeName, string version); 140 | 141 | /** 142 | * 获取node的模板配置 143 | * @param nodeName: node名称 144 | * @param out profileTemplate: 对应模板内容 145 | * 146 | * @return 0-成功 others-失败 147 | */ 148 | int getNodeTemplate(string nodeName, out string profileTemplate); 149 | 150 | /** 151 | * node通过接口获取连接上主控的node ip 152 | * @param sNodeIp: node 的ip 153 | * 154 | * @return 0-成功 others-失败 155 | */ 156 | int getClientIp(out string sClientIp); 157 | 158 | /** 159 | * 发布服务完毕之后统一UPDATE发布版本和发布人 160 | * 161 | */ 162 | int updatePatchResult(PatchResult result); 163 | 164 | /** 165 | * 获取docker的镜像仓库 166 | */ 167 | int getDockerRegistry(out vector doctorRegistries); 168 | 169 | /** 170 | * 拉取基础镜像 171 | */ 172 | int dockerPull(string baseImageId); 173 | 174 | /** 175 | * 获取框架在市场上的key 176 | */ 177 | int getFrameworkKey(out FrameworkKey fKey); 178 | }; 179 | 180 | }; 181 | 182 | -------------------------------------------------------------------------------- /framework/RegistryDescriptor.tars: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tars available. 3 | * 4 | * Copyright (C) 2016THL 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 "EndpointF.tars" 18 | 19 | module tars 20 | { 21 | struct AdapterDescriptor 22 | { 23 | 0 require string adapterName; 24 | 1 require string threadNum; 25 | 2 require string endpoint; 26 | 3 require int maxConnections; 27 | 4 require string allowIp; 28 | 5 require string servant; 29 | 6 require int queuecap; 30 | 7 require int queuetimeout; 31 | 8 require int grid; //该字段已弃用,为平滑升级而保留定义 32 | 9 optional string protocol; 33 | 10 optional string handlegroup; 34 | 11 optional int shmkey = 0; //该字段用作共享内存key(不再使用) 35 | 12 optional int shmcap = 0; //该字段用作共享内存大小(不再使用) 36 | }; 37 | 38 | struct ServerDescriptor 39 | { 40 | 0 require string application; 41 | 1 require string serverName; 42 | 2 require string nodeName; 43 | 3 require string basePath; 44 | 4 require string exePath; 45 | 5 require string settingState; 46 | 6 require string presentState; 47 | 7 require string profile; 48 | 8 require string patchVersion; 49 | 9 require string patchTime; 50 | 10 require string patchUser; 51 | 11 require map adapters; 52 | 12 optional string serverType; 53 | 13 optional string startScript; 54 | 14 optional string stopScript; 55 | 15 optional string monitorScript; 56 | 16 optional int configCenterPort; 57 | 17 optional int asyncThreadNum; 58 | 18 optional string setId; 59 | 19 optional string sJmx_port; //tarsjava服务专用 60 | 20 optional string runType; //"container": 则以容器方式运行 61 | 21 optional string baseImage; //容器运行时指定的基础镜像 62 | 22 optional string sha; //容器镜像的sha 63 | 23 optional string baseImageId; //镜像ID, 便于定位仓库 64 | }; 65 | 66 | //struct ObjectName 67 | //{ 68 | // 0 require string ObjectId; 69 | //}; 70 | // 71 | ////在1.5.5版本中除去了(2 require vector vActiveEpGroupId和3 require vector vInactiveEpGroupId) 72 | //struct ObjectItem 73 | //{ 74 | // 0 require vector vActiveEndpoints; 75 | // 1 require vector vInactiveEndpoints; 76 | //}; 77 | //主控idc分组信息结构,用来缓存信息 78 | struct ServerGroupRule 79 | { 80 | 0 require vector< map > vGroupRuleInfo; 81 | }; 82 | }; 83 | -------------------------------------------------------------------------------- /framework/Topology.tars: -------------------------------------------------------------------------------- 1 | module tars 2 | { 3 | struct Vertex 4 | { 5 | 0 require string vertex; 6 | 1 require long callCount; 7 | 2 require long callTime; 8 | }; 9 | key[Vertex,vertex]; 10 | 11 | struct Edge 12 | { 13 | 0 require string fromVertex; 14 | 1 require string toVertex; 15 | 2 require long callCount; 16 | 3 require long callTime; 17 | 4 require string spanId; 18 | 5 require long csTime; 19 | 6 require long srTime; 20 | 7 require long ssTime; 21 | 8 require long crTime; 22 | 9 require string csData; 23 | 10 require string srData; 24 | 11 require string ssData; 25 | 12 require string crData; 26 | 13 require string ret; 27 | 14 require int order; 28 | }; 29 | key[Edge,order,csTime,fromVertex,toVertex]; 30 | 31 | struct Graph { 32 | 0 require vector vs; 33 | 1 require vector es; 34 | }; 35 | 36 | struct Summary{ 37 | 0 require string name; 38 | 1 require long startTime; 39 | 2 require long endTime; 40 | }; 41 | 42 | 43 | interface Topology 44 | { 45 | int graphServer(string date, string serverName, out vector graph); 46 | 47 | int graphFunction(string date, string functionName, out vector graph); 48 | 49 | int graphTrace(string date, string traceId, out Graph graph); 50 | 51 | int listFunction(string date, string serverName, out vector fs); 52 | 53 | int listTrace(string date, string serverName, out vector ts); 54 | 55 | int listTraceSummary(string date, long beginTime,long endTime, string serverName, out vector ts); 56 | }; 57 | }; -------------------------------------------------------------------------------- /framework/TraceData.tars: -------------------------------------------------------------------------------- 1 | module internal { 2 | struct IRawLog{ 3 | 0 require string trace; 4 | 1 require string span; 5 | 2 require string parent; 6 | 3 require string type; 7 | 4 require string master; 8 | 5 require string slave; 9 | 6 require string function; 10 | 7 require long time; 11 | 8 require string ret; 12 | 9 require string data; 13 | }; 14 | 15 | struct ISpan { 16 | 0 require string span; 17 | 1 require string parent; 18 | 2 require string master; 19 | 3 require string slave; 20 | 4 require string function; 21 | 5 require long csTime; 22 | 6 require long crTime; 23 | 7 require long ssTime; 24 | 8 require long srTime; 25 | 9 require string csData; 26 | 10 require string srData; 27 | 11 require string ssData; 28 | 12 require string crData; 29 | 13 require string ret; 30 | 14 require vector children; 31 | }; 32 | 33 | struct ITrace { 34 | 0 require string trace; 35 | 1 require string tSpan; 36 | 2 require string tMaster; 37 | 3 require long tsTime; 38 | 4 require long teTime; 39 | 5 require vector spans; 40 | 6 require long sHash; 41 | 7 require long fHash; 42 | }; 43 | 44 | struct IVertex 45 | { 46 | 0 require string vertex; 47 | 1 require long callCount; 48 | 2 require long callTime; 49 | }; 50 | key [IVertex,vertex]; 51 | 52 | 53 | struct IEdge 54 | { 55 | 0 require string fromVertex; 56 | 1 require string toVertex; 57 | 2 require long callCount; 58 | 3 require long callTime; 59 | 4 require int order; 60 | }; 61 | key [IEdge,order,fromVertex,toVertex]; 62 | 63 | struct IGraph { 64 | 0 require string type; 65 | 1 require vector vertexes; 66 | 2 require vector edges; 67 | }; 68 | 69 | struct Snapshot 70 | { 71 | 0 require string fileName; 72 | 1 require long seek; 73 | 2 require map traces; 74 | 3 require map graphs; 75 | }; 76 | }; 77 | -------------------------------------------------------------------------------- /servant/AdminF.tars: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tars available. 3 | * 4 | * Copyright (C) 2016THL 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 | module tars 18 | { 19 | interface AdminF 20 | { 21 | /** 22 | * 关闭服务 23 | */ 24 | void shutdown(); 25 | 26 | /** 27 | * 通知服务 28 | */ 29 | string notify(string command); 30 | 31 | /** 32 | * 获取服务的pid 33 | */ 34 | long getPid(); 35 | }; 36 | }; 37 | 38 | -------------------------------------------------------------------------------- /servant/AuthF.tars: -------------------------------------------------------------------------------- 1 | module tars 2 | { 3 | 4 | /* 5 | * local auth 6 | */ 7 | struct BasicAuthInfo 8 | { 9 | 1 optional string sObjName; 10 | 2 optional string sAccessKey; // AK 11 | 3 optional string sSecretKey; // SK plainText 12 | 4 optional string sHashSecretKey2; // or SK with sha 2 times, ascii format 13 | }; 14 | 15 | /* 16 | * The auth message client send 17 | */ 18 | struct BasicAuthPackage 19 | { 20 | 1 require string sObjName; 21 | 2 require string sAccessKey; // AK 22 | 3 require long iTime; // timestamp 23 | 4 optional string sHashMethod = "sha1"; 24 | 25 | // how to use sign 26 | // 1. tmpKey = md5sum(secret2 | timestamp); all know this 16bytes 27 | // 2. client use tmpKey to enc secret1, ie, the client knows secret 28 | // 3. server use tmpKey to dec secret1, then sha1(secret1) to check if ok 29 | 5 optional string sSignature; 30 | }; 31 | 32 | // 认证状态: 33 | enum AUTH_STATE 34 | { 35 | AUTH_INIT = -127, 36 | AUTH_SUCC = 0, 37 | 38 | AUTH_PROTO_ERR = -100, 39 | AUTH_WRONG_OBJ = -101, 40 | AUTH_WRONG_AK = -102, 41 | AUTH_WRONG_TIME = -103, // wrong timestamp 42 | AUTH_NOT_SUPPORT_ENC = -104, 43 | AUTH_DEC_FAIL = -105, // may be wrong secret key 44 | AUTH_ERROR = -106, 45 | // other positive : user defined intermediate states 46 | // other negative : user defined failed states 47 | }; 48 | 49 | enum AUTH_TYPE 50 | { 51 | AUTH_TYPENONE = 0, // no auth 52 | AUTH_TYPELOCAL = 1, // local auth 53 | }; 54 | 55 | /* 56 | * token唯一标识 57 | */ 58 | struct TokenKey 59 | { 60 | 1 require string sApplication; // client's app 61 | 2 require string sServer; // client's server 62 | 3 require string sObjName; // call this obj, name是全局唯一的 63 | }; 64 | 65 | 66 | /* 67 | * 鉴权请求,从client到业务server到AUTH 68 | */ 69 | struct AuthRequest 70 | { 71 | 1 require TokenKey sKey; 72 | 2 require string sToken; 73 | }; 74 | 75 | /*鉴权结果是int, state的值*/ 76 | 77 | /* 78 | * 账号请求,从web到AUTH 79 | */ 80 | struct TokenRequest 81 | { 82 | 1 require vector vObjName; // objname是全局唯一的 83 | }; 84 | 85 | /* 86 | * 账号库,从AUTH到web 87 | */ 88 | struct TokenResponse 89 | { 90 | 1 require string sObjName; // objname是全局唯一的 91 | 2 require map mTokens; // key = 主调方app.server, value = token 92 | }; 93 | /* 94 | * req 申请token,从web到AUTH, web ip需要认证,最好是白名单 95 | */ 96 | struct ApplyTokenRequest 97 | { 98 | 1 require TokenKey sKey; 99 | }; 100 | 101 | /* 102 | * rsp 103 | */ 104 | struct ApplyTokenResponse 105 | { 106 | 1 require TokenKey sKey; 107 | 2 require string sToken; 108 | }; 109 | 110 | /* 111 | * req 删除token,从web到AUTH, web ip需要认证,最好是白名单 112 | */ 113 | struct DeleteTokenRequest 114 | { 115 | 1 require TokenKey sKey; 116 | }; 117 | 118 | 119 | interface Auth 120 | { 121 | /** 122 | * 请求远程鉴权,被调服务向authserver发送token,authserver返回状态 123 | **/ 124 | int authProcess(AuthRequest request); 125 | /** 126 | * 请求token账号库 127 | **/ 128 | vector getTokens(TokenRequest request); 129 | /** 130 | * 创建token 131 | **/ 132 | ApplyTokenResponse applyToken(ApplyTokenRequest request); 133 | /** 134 | * del token from web 135 | **/ 136 | int deleteToken(DeleteTokenRequest request); 137 | }; 138 | 139 | }; 140 | -------------------------------------------------------------------------------- /servant/BaseF.tars: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tars available. 3 | * 4 | * Copyright (C) 2016THL 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 | module tars 18 | { 19 | //////////////////////////////////////////////////////////////// 20 | // 定义协议的版本号 21 | 22 | const short TARSVERSION = 0x01; 23 | const short TUPVERSION = 0x03; 24 | const short XMLVERSION = 0x04; 25 | const short JSONVERSION = 0x05; 26 | 27 | //////////////////////////////////////////////////////////////// 28 | // 定义消息的类型 29 | 30 | // 普通调用 31 | const byte TARSNORMAL = 0x00; 32 | 33 | // 单向调用 34 | const byte TARSONEWAY = 0x01; 35 | 36 | //////////////////////////////////////////////////////////////// 37 | // TARS定义的返回码 38 | 39 | const int TARSSERVERSUCCESS = 0; //服务器端处理成功 40 | const int TARSSERVERDECODEERR = -1; //服务器端解码异常 41 | const int TARSSERVERENCODEERR = -2; //服务器端编码异常 42 | const int TARSSERVERNOFUNCERR = -3; //服务器端没有该函数 43 | const int TARSSERVERNOSERVANTERR = -4; //服务器端没有该Servant对象 44 | const int TARSSERVERRESETGRID = -5; //服务器端灰度状态不一致 45 | const int TARSSERVERQUEUETIMEOUT = -6; //服务器队列超过限制 46 | const int TARSASYNCCALLTIMEOUT = -7; //异步调用超时 47 | const int TARSINVOKETIMEOUT = -7; //调用超时 48 | const int TARSPROXYCONNECTERR = -8; //proxy链接异常 49 | const int TARSSERVEROVERLOAD = -9; //服务器端超负载,超过队列长度 50 | const int TARSADAPTERNULL = -10; //客户端选路为空,服务不存在或者所有服务down掉了 51 | const int TARSINVOKEBYINVALIDESET = -11; //客户端按set规则调用非法 52 | const int TARSCLIENTDECODEERR = -12; //客户端解码异常 53 | const int TARSSENDREQUESTERR = -13; //发送出错 54 | const int TARSSERVERUNKNOWNERR = -99; //服务器端位置异常 55 | 56 | ///////////////////////////////////////////////////////////////// 57 | // 定义按位的消息状态类型,可复合 58 | 59 | const int TARSMESSAGETYPENULL = 0x00; //无状态 60 | const int TARSMESSAGETYPEHASH = 0x01; //HASH消息 61 | const int TARSMESSAGETYPEGRID = 0x02; //灰度消息 62 | const int TARSMESSAGETYPEDYED = 0x04; //染色消息 63 | const int TARSMESSAGETYPESAMPLE = 0x08; //stat采样消息 64 | const int TARSMESSAGETYPEASYNC = 0x10; //异步调用程序 65 | //const int TARSMESSAGETYPELOADED = 0x20; //按负载值调用程序 66 | //const int TARSMESSAGETYPESETED = 0x40; //按set规则调用类型,此字段后面将不使用 67 | const int TARSMESSAGETYPESETNAME = 0x80; //按setname规则调用类型 68 | const int TARSMESSAGETYPETRACE = 0x100; //track调用链消息 69 | ///////////////////////////////////////////////////////////////// 70 | }; 71 | -------------------------------------------------------------------------------- /servant/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | ########################################################################################## 3 | #生成tars文件, 并将.h文件copy到servant目录下 4 | 5 | set(OUT_DEPENDS_LIST) 6 | 7 | #在当前目录生成tars对应的文件 8 | complice_tars(OUT_DEPENDS_LIST "servant" "") 9 | 10 | FILE(GLOB SRC_LIST "*.tars") 11 | 12 | set(CLEAN_LIST) 13 | 14 | #将生成tars文件copy到对应的源码目录 15 | foreach (FILE ${SRC_LIST}) 16 | 17 | #copy .h文件 18 | get_filename_component(NAME_WE ${FILE} NAME_WE) 19 | set(TARS_H ${NAME_WE}.h) 20 | set(CP_SOURCE_H_DIR "${PROJECT_SOURCE_DIR}/servant") 21 | 22 | add_custom_command( 23 | OUTPUT ${CP_SOURCE_H_DIR}/${TARS_H} 24 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} 25 | COMMAND ${CMAKE_COMMAND} -E copy ${TARS_H} ${CP_SOURCE_H_DIR} 26 | DEPENDS ${FILE} ${TARS_H} tars2cpp 27 | COMMENT "${CMAKE_COMMAND} -E copy ${TARS_H} ${CP_SOURCE_H_DIR}") 28 | 29 | #设置依赖 30 | list(APPEND OUT_DEPENDS_LIST ${CP_SOURCE_H_DIR}/${TARS_H}) 31 | 32 | #设置需要清除的.h文件 33 | list(APPEND CLEAN_LIST ${CP_SOURCE_CPP_DIR}/${NAME_WE}.h) 34 | 35 | endforeach () 36 | 37 | #设置需要清除的文件 38 | set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "${CLEAN_LIST}") 39 | 40 | add_custom_target(COPY-SERVENT-TARS ALL DEPENDS TUP-TARS ${OUT_DEPENDS_LIST}) 41 | 42 | set(TARSPROTOCOLS 43 | AdminF.tars 44 | AdminF.h 45 | AuthF.tars 46 | AuthF.h 47 | BaseF.tars 48 | BaseF.h 49 | ConfigF.tars 50 | ConfigF.h 51 | EndpointF.tars 52 | EndpointF.h 53 | LogF.tars 54 | LogF.h 55 | NodeF.tars 56 | NodeF.h 57 | NotifyF.tars 58 | NotifyF.h 59 | PropertyF.tars 60 | PropertyF.h 61 | QueryF.tars 62 | QueryF.h 63 | StatF.tars 64 | StatF.h) 65 | 66 | install(DIRECTORY . DESTINATION include/servant 67 | PATTERN "*.tars" 68 | PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ WORLD_READ WORLD_EXECUTE) 69 | 70 | if(WIN32) 71 | INSTALL(FILES ${TARSPROTOCOLS} DESTINATION c:\\tarsproto\\protocol\\) 72 | elseif(APPLE) 73 | INSTALL(FILES ${TARSPROTOCOLS} DESTINATION $ENV{HOME}/tarsproto/protocol/) 74 | elseif(UNIX) 75 | INSTALL(FILES ${TARSPROTOCOLS} DESTINATION /home/tarsproto/protocol/) 76 | endif() 77 | -------------------------------------------------------------------------------- /servant/ConfigF.tars: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tars available. 3 | * 4 | * Copyright (C) 2016THL 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 | module tars 18 | { 19 | struct ConfigInfo 20 | { 21 | //业务名称 22 | 0 require string appname; 23 | //服务名称 24 | 1 require string servername; 25 | //配置文件名称 26 | 2 require string filename; 27 | //是否只获取应用配置,默认为false,如果为true则servername可以为空 28 | 3 require bool bAppOnly=false; 29 | //服务所在节点(ip) 30 | 4 optional string host; 31 | //set分组名称 32 | 5 optional string setdivision; 33 | }; 34 | 35 | struct GetConfigListInfo 36 | { 37 | //业务名称 38 | 0 require string appname; 39 | //服务名称 40 | 1 optional string servername; 41 | //是否只获取应用配置,默认为false,如果为true只拉取应用级别的列表,其它级别无效 42 | 2 optional bool bAppOnly=false; 43 | //服务所在节点(ip),要机器级别的,请赋值 44 | 3 optional string host=""; 45 | //set分组名称,需要拉取set级别的,请赋值 46 | 4 optional string setdivision=""; 47 | //容器级别,需要拉取容器级别的,请赋值 48 | 5 optional string containername=""; 49 | }; 50 | 51 | /** 52 | * config obj to load server's system config. 53 | **/ 54 | interface Config 55 | { 56 | /** 57 | * 读取配置文件列表 58 | * @param app, app name 59 | * @param server, server name 60 | * @param vf, config file name 61 | **/ 62 | int ListConfig(string app, string server, out vector vf); 63 | 64 | /** 65 | * 读取配置文件 66 | * @param app, app name 67 | * @param server, server name 68 | * @param filename, config file name 69 | * @param config, 配置文件内容 70 | **/ 71 | int loadConfig(string app, string server, string filename, out string config); 72 | 73 | /** 74 | * 根据host读取文件 75 | * @param appSerever, app.server 76 | * @param filename, config file name 77 | * @param host, ip 78 | * @param config, 配置文件内容 79 | **/ 80 | int loadConfigByHost(string appServerName, string filename, string host, out string config); 81 | 82 | /** 83 | * 检查配置文件是否服务TC_Config格式 84 | * @param appSerever, app.server 85 | * @param filename, config file name 86 | * @param host, ip 87 | * @param result, 提示 88 | * @return int 0: 合法, -1:非法 89 | **/ 90 | int checkConfig(string appServerName, string filename, string host, out string result); 91 | 92 | /** 93 | * 读取服务所在节点的配置文件列表 94 | * 95 | * @param configInfo, ConfigInfo 配置文件信息,如果没有set分组信息,请设置setdivision为空"" 96 | * @param vf, config file name 97 | * @return int 0: 成功, -1:失败 98 | **/ 99 | int ListConfigByInfo(ConfigInfo configInfo, out vector vf); 100 | 101 | /** 102 | * 读取配置文件 103 | * @param configInfo, ConfigInfo 配置文件信息 104 | * @param config, 配置文件内容 105 | * @return int 0: 成功, -1:失败 106 | **/ 107 | int loadConfigByInfo(ConfigInfo configInfo, out string config); 108 | 109 | /** 110 | * 检查配置文件是否符合TC_Config格式 111 | * @param configInfo, ConfigInfo 配置文件信息 112 | * @param result, 提示 113 | * @return int 0: 合法, -1:非法 114 | **/ 115 | int checkConfigByInfo(ConfigInfo configInfo, out string result); 116 | 117 | /** 118 | * 获取服务的所有配置文件列表, 119 | * @param configInfo 支持拉取应用配置列表,服务配置列表,机器配置列表 120 | * @param[out] vf 获取到的文件名称列表 121 | * @return int 0: 成功, -1:失败 122 | **/ 123 | int ListAllConfigByInfo(GetConfigListInfo configInfo, out vector vf); 124 | 125 | }; 126 | }; 127 | 128 | -------------------------------------------------------------------------------- /servant/EndpointF.tars: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tars available. 3 | * 4 | * Copyright (C) 2016THL 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 | module tars 18 | { 19 | /** 20 | * 端口信息 21 | */ 22 | struct EndpointF 23 | { 24 | 0 require string host; 25 | 1 require int port; 26 | 2 require int timeout; 27 | 3 require int istcp; 28 | 4 require int grid; 29 | 5 optional int groupworkid; 30 | 6 optional int grouprealid; 31 | 7 optional string setId; 32 | 8 optional int qos; 33 | 9 optional int bakFlag; 34 | 11 optional int weight; 35 | 12 optional int weightType; 36 | 13 optional int authType; 37 | 14 optional string nodeName; 38 | }; 39 | key[EndpointF, host, port, timeout, istcp, grid, qos, weight, weightType, authType]; 40 | 41 | struct ObjectItem 42 | { 43 | 0 optional vector vActiveEndpoints; 44 | 1 optional vector vInactiveEndpoints; 45 | }; 46 | 47 | 48 | }; 49 | 50 | 51 | -------------------------------------------------------------------------------- /servant/LogF.tars: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tars available. 3 | * 4 | * Copyright (C) 2016THL 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 | module tars 18 | { 19 | struct LogInfo 20 | { 21 | //业务名称 22 | 0 require string appname; 23 | //服务名称 24 | 1 require string servername; 25 | //日志文件名称 26 | 2 require string sFilename; 27 | //时间格式 28 | 3 require string sFormat; 29 | //set分组名称 30 | 4 optional string setdivision; 31 | // 日志文件名是否带.log后缀 32 | 5 optional bool bHasSufix=true; 33 | // 是否允许框架在日志文件名上增加业务相关的标识 34 | 6 optional bool bHasAppNamePrefix=true; 35 | // 框架内部的日期和时间部分是否加上[]符号 36 | 7 optional bool bHasSquareBracket=false; 37 | // 日志文件名中用户自定义字符与日期字符间的连接符,默认是"_" 38 | 8 optional string sConcatStr="_"; 39 | // 日志内容项之间的分隔符,默认是"|" 40 | 9 optional string sSepar="|"; 41 | //按天/小时/分钟输出日志时的记录类型,例如,按一天:day或者1day;按两小时:2hour;按10分钟:10minute 42 | 10 optional string sLogType = ""; 43 | }; 44 | interface Log 45 | { 46 | /** 47 | * 记录远程日志 48 | * @param app, 应用名称 49 | * @param server, 服务名称 50 | * @param file, 文件名称 51 | * @param format, 日志时间格式(%Y%m%d) 52 | * @param buffer, 日志内容 53 | */ 54 | void logger(string app, string server, string file, string format, vector buffer); 55 | 56 | /** 57 | * 记录远程日志 58 | * @param info, LogInfo 59 | * @param buffer, 日志内容 60 | */ 61 | void loggerbyInfo(LogInfo info, vector buffer); 62 | }; 63 | }; 64 | -------------------------------------------------------------------------------- /servant/NodeF.tars: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tars available. 3 | * 4 | * Copyright (C) 2016THL 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 | module tars 18 | { 19 | struct ServerInfo 20 | { 21 | 0 require string application; 22 | 1 require string serverName; 23 | 2 require int pid; 24 | 3 optional string adapter; 25 | }; 26 | 27 | interface ServerF 28 | { 29 | /** 30 | * 向node定时上报serverInfo 31 | * @param serverInfo 服务状态 32 | * @return int 33 | */ 34 | int keepAlive(ServerInfo serverInfo); 35 | 36 | /** 37 | * 向node定时上报serverInfo(Activing状态) 38 | * @param serverInfo 服务状态 39 | * @return int 40 | */ 41 | int keepActiving(ServerInfo serverInfo); 42 | 43 | /** 44 | * 向node上报TARS版本信息 45 | * @param string 版本信息 46 | * @return int 47 | */ 48 | int reportVersion(string app,string serverName,string version); 49 | 50 | /** 51 | * 获取最近keepalive的时间戳 52 | * @return 最后一次keepalive的时间戳 53 | */ 54 | unsigned int getLatestKeepAliveTime(); 55 | }; 56 | }; -------------------------------------------------------------------------------- /servant/NotifyF.tars: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tars available. 3 | * 4 | * Copyright (C) 2016THL 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 | module tars 18 | { 19 | // 20 | ///** 21 | //* notify信息的键值 22 | //*/ 23 | //struct NotifyKey 24 | //{ 25 | // 1 require string name; //为app+servername 例如:Comm.BindServer 26 | // 2 require string ip; //ip 27 | // 3 require int page; 28 | //}; 29 | // 30 | ///** 31 | //* 上报信息的单条内容 32 | //*/ 33 | //struct NotifyItem 34 | //{ 35 | // 1 require string sTimeStamp; 36 | // 2 require string sServerId; 37 | // 3 require int iLevel; 38 | // 4 require string sMessage; 39 | //}; 40 | // 41 | ///** 42 | //* 上报的信息分页记录 43 | //*/ 44 | //struct NotifyInfo 45 | //{ 46 | // 1 require int nextpage; 47 | // 2 require vector notifyItems; 48 | //}; 49 | // 50 | /** 51 | * 定义上报信息的等级 52 | */ 53 | enum NOTIFYLEVEL 54 | { 55 | NOTIFYNORMAL, 56 | NOTIFYWARN, 57 | NOTIFYERROR, 58 | }; 59 | 60 | /* 61 | *上报类型 62 | */ 63 | enum ReportType 64 | { 65 | REPORT, 66 | NOTIFY 67 | }; 68 | 69 | /* 70 | *上报notify信息的数据结构 71 | */ 72 | struct ReportInfo 73 | { 74 | 1 require ReportType eType; 75 | 2 require string sApp; 76 | 3 require string sSet; 77 | 4 require string sContainer; 78 | 5 require string sServer; 79 | 6 require string sMessage; 80 | 7 optional string sThreadId; 81 | 8 optional NOTIFYLEVEL eLevel; 82 | 9 optional string sNodeName; 83 | 84 | }; 85 | 86 | interface Notify 87 | { 88 | ///** 89 | //* 框架上报的信息, 保存于数据库中 90 | //* @param sServerName, server name 91 | //* @param sThreadId, server current thread id 92 | //* @param sMessage, message 93 | //**/ 94 | //void reportServer(string sServerName, string sThreadId, string sMessage); 95 | // 96 | // 97 | ///** 98 | //* 业务上报的信息, 用于报警 99 | //* @param sServerName, server name 100 | //* @param level, notify level 101 | //* @param sMessage, message 102 | //**/ 103 | //void notifyServer(string sServerName, NOTIFYLEVEL level, string sMessage); 104 | // 105 | ///** 106 | //* 获取上报信息 107 | //* @param sServerName, server name 108 | //* @param out , notify info detail 109 | //* @return int 0=success, others=failed 110 | //**/ 111 | //int getNotifyInfo(NotifyKey stKey, out NotifyInfo stInfo); 112 | 113 | /* 114 | *上报框架信息以及业务告警信息 115 | */ 116 | void reportNotifyInfo(ReportInfo info); 117 | }; 118 | 119 | }; 120 | -------------------------------------------------------------------------------- /servant/PropertyF.tars: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tars available. 3 | * 4 | * Copyright (C) 2016THL 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 | module tars 18 | { 19 | 20 | //属性上报消息包 Prop = property 21 | struct StatPropMsgHead 22 | { 23 | 0 require string moduleName; //模块name 24 | 1 require string ip; //ip 25 | 2 require string propertyName; //属性name 26 | 3 optional string setName; //set名 27 | 4 optional string setArea; //set地区名 28 | 5 optional string setID; //set组名 29 | 6 optional string sContainer; //容器名 30 | 7 optional int iPropertyVer=1; //协议版本 31 | }; 32 | 33 | key[StatPropMsgHead, moduleName, ip, propertyName, setName, setArea, setID ]; 34 | 35 | //属性值信息 36 | struct StatPropInfo 37 | { 38 | 0 require string policy; //Sum\Avg\Distr\Count\Max\Min 39 | 1 require string value; //值 40 | }; 41 | 42 | //属性上报包体 43 | struct StatPropMsgBody 44 | { 45 | 0 require vector vInfo; //上报信息 46 | }; 47 | 48 | /** 49 | * 50 | * 上报服务的接口 51 | * 52 | **/ 53 | interface PropertyF 54 | { 55 | /** 56 | * 上报属性统计信息 Prop = property 57 | * @param statmsg, 上报信息 58 | * @return int, 返回0表示成功 59 | */ 60 | int reportPropMsg( map statmsg ); 61 | }; 62 | 63 | 64 | }; 65 | -------------------------------------------------------------------------------- /servant/QueryF.tars: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tars available. 3 | * 4 | * Copyright (C) 2016THL 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 "EndpointF.tars" 18 | 19 | module tars 20 | { 21 | 22 | struct GetMasterSlaveLock 23 | { 24 | 0 optional string application; 25 | 1 optional string server_name; 26 | 2 optional string node_name; 27 | 3 optional bool isMaster; 28 | 4 optional bool lastErr; 29 | 5 optional int timeout; //超时毫秒 30 | 6 optional int bakType; //0 不需要切换,1:自动主从切换, 2:自动切换但是不屏蔽主控路由 31 | }; 32 | 33 | /** 34 | * 获取对象endpoint的query接口 35 | */ 36 | 37 | interface QueryF 38 | { 39 | /** 根据id获取对象 40 | * 41 | * @param id 对象名称 42 | * 43 | * @return 返回所有该对象的活动endpoint列表 44 | */ 45 | vector findObjectById(string id); 46 | 47 | /**根据id获取所有对象,包括活动和非活动对象 48 | * 49 | * @param id 对象名称 50 | * @param activeEp 存活endpoint列表 51 | * @param inactiveEp 非存活endpoint列表 52 | * @return: 0-成功 others-失败 53 | */ 54 | int findObjectById4Any(string id, out vector activeEp, out vector inactiveEp); 55 | 56 | /** 根据id获取对象所有endpoint列表,功能同findObjectByIdInSameGroup 57 | * 58 | * @param id 对象名称 59 | * @param activeEp 存活endpoint列表 60 | * @param inactiveEp 非存活endpoint列表 61 | * @return: 0-成功 others-失败 62 | */ 63 | int findObjectById4All(string id, out vector activeEp, out vector inactiveEp); 64 | 65 | /** 根据id获取对象同组endpoint列表 66 | * 67 | * @param id 对象名称 68 | * @param activeEp 存活endpoint列表 69 | * @param inactiveEp 非存活endpoint列表 70 | * @return: 0-成功 others-失败 71 | */ 72 | int findObjectByIdInSameGroup(string id, out vector activeEp, out vector inactiveEp); 73 | 74 | 75 | /** 根据id获取对象指定归属地的endpoint列表 76 | * 77 | * @param id 对象名称 78 | * @param activeEp 存活endpoint列表 79 | * @param inactiveEp 非存活endpoint列表 80 | * @return: 0-成功 others-失败 81 | */ 82 | int findObjectByIdInSameStation(string id, string sStation, out vector activeEp, out vector inactiveEp); 83 | 84 | /** 根据id获取对象同组endpoint列表 85 | * 86 | * @param id 对象名称 87 | * @param setId set全称,格式为setname.setarea.setgroup 88 | * @param activeEp 存活endpoint列表 89 | * @param inactiveEp 非存活endpoint列表 90 | * @return: 0-成功 others-失败 91 | */ 92 | int findObjectByIdInSameSet(string id, string setId, out vector activeEp, out vector inactiveEp); 93 | 94 | /** 查找某个obj部署在哪些节点上 (企业版功能) 95 | * 96 | * @param id obj名称 97 | * @return: 0-成功 others-失败 98 | */ 99 | int findObjectNodeName(string id, out vector nodeName); 100 | 101 | /** 注册数据变化的通知, 通知变化内容(企业版功能) 102 | * 103 | * @param name 当前模块名称 104 | * @return: 0-成功 others-失败 105 | */ 106 | int registerChange(map timestamp, string name); 107 | 108 | /** 注册id变化的通知, 通知时后需要自己主动调用find去查找(企业版功能) 109 | * 110 | * @param id 对象名称 111 | * @param name 当前模块名称 112 | * @return: 0-成功 others-失败 113 | */ 114 | int registerQuery(string id, string name); 115 | 116 | /** 117 | * 获取锁, 实现业务服务一主多备的模式(企业版功能) 118 | * @param req 119 | * @return 0: 获取锁成功; 1:获取锁失败; 2: 数据异常, -1:其他异常 120 | */ 121 | int getLocker(GetMasterSlaveLock req); 122 | 123 | }; 124 | 125 | }; 126 | 127 | 128 | -------------------------------------------------------------------------------- /servant/StatF.tars: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tars available. 3 | * 4 | * Copyright (C) 2016THL 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 | module tars 18 | { 19 | 20 | //模块间调用包头 Mic = module interval call 21 | struct StatMicMsgHead 22 | { 23 | 0 require string masterName; //主调模块name 24 | 1 require string slaveName; //被调模块name 25 | 2 require string interfaceName; //被调模块接口name 26 | 3 require string masterIp; //主调ip 27 | 4 require string slaveIp; //被调ip 28 | 5 require int slavePort; //被调端口 29 | 6 require int returnValue; //返回值 30 | 7 optional string slaveSetName; //被调set名 31 | 8 optional string slaveSetArea; //被调set地区名 32 | 9 optional string slaveSetID; //被调set组名 33 | 10 optional string tarsVersion; //主调tars版本 34 | }; 35 | 36 | key[StatMicMsgHead, masterName, slaveName,interfaceName,masterIp,slaveIp,slavePort,returnValue, slaveSetName, slaveSetArea, slaveSetID, tarsVersion]; 37 | 38 | //模块间调用包体协议 39 | struct StatMicMsgBody 40 | { 41 | 0 require int count; //成功调用量 42 | 1 require int timeoutCount; //超时调用量 43 | 2 require int execCount; //异常调用量 44 | //以下字段针对成功调用量所作统计 45 | 3 require map intervalCount; //时间间隔内调用量 46 | 4 require long totalRspTime; //调用总时间用来计算平均时间 47 | 5 require int maxRspTime; //最大响应时间 48 | 6 require int minRspTime; //最小响应时间 49 | }; 50 | 51 | //模块间调用采样信息 52 | struct StatSampleMsg 53 | { 54 | 0 require string unid; //唯一id值 55 | 1 require string masterName; //主调模块name 56 | 2 require string slaveName; //被调模块name 57 | 3 require string interfaceName; //被调模块接口name 58 | 4 require string masterIp; //主调ip 59 | 5 require string slaveIp; //被调ip 60 | 6 require int depth; //深度值 61 | 7 require int width; //广度值 62 | 8 require int parentWidth; //父节点广度值 63 | }; 64 | 65 | struct ProxyInfo 66 | { 67 | 0 require bool bFromClient;//是否来自客户端 68 | }; 69 | /** 70 | * 71 | * 上报服务的接口 72 | * 73 | **/ 74 | interface StatF 75 | { 76 | /** 77 | * 上报模块间调用信息 Mic = module interval call 78 | * @param statmsg, 上报信息 79 | * @param bFromServer, 上报源 bFromClient: true 客户端发起的上报 false 服务端发起上报 80 | * @return int, 返回0表示成功 81 | */ 82 | int reportMicMsg( map msg, bool bFromClient); 83 | 84 | /** 85 | * 上报模块间调用采样信息 Mic = module interval call 86 | * @param msg, 上报信息 87 | * @return int, 返回0表示成功 88 | */ 89 | int reportSampleMsg(vector msg); 90 | }; 91 | 92 | }; 93 | -------------------------------------------------------------------------------- /tup/RequestF.tars: -------------------------------------------------------------------------------- 1 | /** 2 | * Tencent is pleased to support the open source community by making Tars available. 3 | * 4 | * Copyright (C) 2016THL 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 | module tars 18 | { 19 | //请求包体 20 | struct RequestPacket 21 | { 22 | 1 require short iVersion; 23 | 2 require byte cPacketType = 0; 24 | 3 require int iMessageType = 0; 25 | 4 require int iRequestId; 26 | 5 require string sServantName = ""; 27 | 6 require string sFuncName = ""; 28 | 7 require vector sBuffer; 29 | 8 require int iTimeout = 0; 30 | 9 require map context; 31 | 10 require map status; 32 | }; 33 | 34 | //响应包体 35 | struct ResponsePacket 36 | { 37 | 1 require short iVersion; 38 | 2 require byte cPacketType = 0; 39 | 3 require int iRequestId; 40 | 4 require int iMessageType = 0; 41 | 5 require int iRet = 0; 42 | 6 require vector sBuffer; 43 | 7 require map status; 44 | 8 optional string sResultDesc; 45 | 9 optional map context; 46 | }; 47 | }; 48 | --------------------------------------------------------------------------------