endpoint_config.h 3.2 KB
Newer Older
W
wangguibao 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
// Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#pragma once
W
wangguibao 已提交
16
#include <stdint.h>
W
wangguibao 已提交
17 18
#include <string>
#include <vector>
G
guru4elephant 已提交
19
#include "core/sdk-cpp/include/common.h"
W
sdk-cpp  
wangguibao 已提交
20 21 22 23 24

namespace baidu {
namespace paddle_serving {
namespace sdk_cpp {

D
dongdaxiang 已提交
25 26 27 28 29 30 31
#define PARSE_CONF_ITEM(conf, item, name, fail)          \
  do {                                                   \
    if (conf.has_##name()) {                             \
      item.set(conf.name());                             \
    } else {                                             \
      VLOG(2) << "Not found key in configue: " << #name; \
    }                                                    \
W
wangguibao 已提交
32 33
  } while (0)

D
dongdaxiang 已提交
34 35 36 37 38 39 40 41
#define ASSIGN_CONF_ITEM(dest, src, fail)                       \
  do {                                                          \
    if (!src.init) {                                            \
      VLOG(2) << "Cannot assign an unintialized item: " << #src \
              << " to dest: " << #dest;                         \
      return fail;                                              \
    }                                                           \
    dest = src.value;                                           \
W
wangguibao 已提交
42 43 44 45 46
  } while (0)

template <typename T>
struct type_traits {
  static type_traits<T> tag;
W
sdk-cpp  
wangguibao 已提交
47 48
};

W
wangguibao 已提交
49
template <typename T>
W
wangguibao 已提交
50 51
type_traits<T> type_traits<T>::tag;

W
wangguibao 已提交
52 53 54 55 56 57 58 59 60
template <typename T>
struct ConfigItem {
  T value;
  bool init;
  ConfigItem() : init(false) {}
  void set(const T& unit) {
    value = unit;
    init = true;
  }
W
sdk-cpp  
wangguibao 已提交
61 62 63
};

struct Connection {
W
wangguibao 已提交
64 65 66 67 68 69 70
  ConfigItem<int32_t> tmo_conn;
  ConfigItem<int32_t> tmo_rpc;
  ConfigItem<int32_t> tmo_hedge;
  ConfigItem<uint32_t> cnt_retry_conn;
  ConfigItem<uint32_t> cnt_retry_hedge;
  ConfigItem<uint32_t> cnt_maxconn_per_host;
  ConfigItem<std::string> type_conn;
W
sdk-cpp  
wangguibao 已提交
71 72 73
};

struct NamingInfo {
W
wangguibao 已提交
74 75 76
  ConfigItem<std::string> cluster_naming;
  ConfigItem<std::string> load_balancer;
  ConfigItem<std::string> cluster_filter;
W
sdk-cpp  
wangguibao 已提交
77 78 79
};

struct RpcParameters {
W
wangguibao 已提交
80 81 82 83 84
  ConfigItem<std::string> protocol;
  ConfigItem<int32_t> compress_type;
  ConfigItem<uint32_t> package_size;
  ConfigItem<std::string> route_tag;
  ConfigItem<uint32_t> max_channel;
W
sdk-cpp  
wangguibao 已提交
85 86 87
};

struct SplitParameters {
W
wangguibao 已提交
88 89 90
  ConfigItem<std::string> split_tag;
  ConfigItem<std::string> tag_cands_str;
  std::vector<std::string> tag_values;
W
sdk-cpp  
wangguibao 已提交
91 92 93
};

struct VariantInfo {
W
wangguibao 已提交
94 95 96 97 98
  VariantInfo() {}
  Connection connection;
  NamingInfo naminginfo;
  RpcParameters parameters;
  SplitParameters splitinfo;
W
sdk-cpp  
wangguibao 已提交
99 100 101
};

struct EndpointInfo {
W
wangguibao 已提交
102 103 104 105 106
  EndpointInfo() : ab_test(NULL) {}
  std::string endpoint_name;
  std::string stub_service;
  std::vector<VariantInfo> vars;
  void* ab_test;
W
sdk-cpp  
wangguibao 已提交
107 108
};

W
wangguibao 已提交
109 110 111
}  // namespace sdk_cpp
}  // namespace paddle_serving
}  // namespace baidu