config_manager.h 2.3 KB
Newer Older
W
wangguibao 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
// 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
#include <map>
#include <string>
G
guru4elephant 已提交
18 19
#include "core/sdk-cpp/include/common.h"
#include "core/sdk-cpp/include/endpoint_config.h"
W
sdk-cpp  
wangguibao 已提交
20 21 22 23 24 25

namespace baidu {
namespace paddle_serving {
namespace sdk_cpp {

class EndpointConfigManager {
W
wangguibao 已提交
26 27 28 29 30 31 32 33
 public:
  static EndpointConfigManager& instance() {
    static EndpointConfigManager singleton;
    return singleton;
  }

  EndpointConfigManager()
      : _last_update_timestamp(0), _current_endpointmap_id(1) {}
W
sdk-cpp  
wangguibao 已提交
34

G
guru4elephant 已提交
35 36 37 38
  int create(const std::string & sdk_desc_str);

  int load(const std::string & sdk_desc_str);

W
wangguibao 已提交
39
  int create(const char* path, const char* file);
W
sdk-cpp  
wangguibao 已提交
40

W
wangguibao 已提交
41
  int load();
W
sdk-cpp  
wangguibao 已提交
42

W
wangguibao 已提交
43
  bool need_reload() { return false; }
W
sdk-cpp  
wangguibao 已提交
44

W
wangguibao 已提交
45 46 47 48
  int reload() {
    if (!need_reload()) {
      LOG(INFO) << "Noneed reload endpoin config";
      return 0;
W
sdk-cpp  
wangguibao 已提交
49 50
    }

W
wangguibao 已提交
51 52
    return load();
  }
W
sdk-cpp  
wangguibao 已提交
53

W
wangguibao 已提交
54
  const std::map<std::string, EndpointInfo>& config() { return _ep_map; }
W
sdk-cpp  
wangguibao 已提交
55

W
wangguibao 已提交
56
  const std::map<std::string, EndpointInfo>& config() const { return _ep_map; }
W
sdk-cpp  
wangguibao 已提交
57

W
wangguibao 已提交
58 59 60
 private:
  int init_one_variant(const configure::VariantConf& conf,
                       VariantInfo& var);  // NOLINT
W
sdk-cpp  
wangguibao 已提交
61

W
wangguibao 已提交
62 63 64
  int init_one_endpoint(const configure::Predictor& conf,
                        EndpointInfo& ep,  // NOLINT
                        const VariantInfo& default_var);
W
sdk-cpp  
wangguibao 已提交
65

W
wangguibao 已提交
66 67 68
  int merge_variant(const VariantInfo& default_var,
                    const configure::VariantConf& conf,
                    VariantInfo& merged_var);  // NOLINT
W
sdk-cpp  
wangguibao 已提交
69

W
wangguibao 已提交
70 71 72 73 74 75 76 77 78
  int parse_tag_values(SplitParameters& split);  // NOLINT

 private:
  std::map<std::string, EndpointInfo> _ep_map;
  std::string _endpoint_config_path;
  std::string _endpoint_config_file;
  uint32_t _last_update_timestamp;
  uint32_t _current_endpointmap_id;
};
W
sdk-cpp  
wangguibao 已提交
79

W
wangguibao 已提交
80 81 82
}  // namespace sdk_cpp
}  // namespace paddle_serving
}  // namespace baidu