config_manager.h 2.1 KB
Newer Older
W
sdk-cpp  
wangguibao 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
/***************************************************************************
 * 
 * Copyright (c) 2018 Baidu.com, Inc. All Rights Reserved
 * 
 **************************************************************************/
 
 
 
/**
 * @file config_manager.h
 * @author wanlijin01(wanlijin01@baidu.com)
 * @date 2018/07/09 15:28:43
 * @brief 
 *  
 **/

#ifndef  BAIDU_PADDLE_SERVING_SDK_CPP_CONFIG_MANAGER_H
#define  BAIDU_PADDLE_SERVING_SDK_CPP_CONFIG_MANAGER_H

#include "common.h"
#include "endpoint_config.h"

namespace baidu {
namespace paddle_serving {
namespace sdk_cpp {

class EndpointConfigManager {
public:
    static EndpointConfigManager& instance() {
        static EndpointConfigManager singleton;
        return singleton;
    }

    EndpointConfigManager() 
        : _last_update_timestamp(0),
        _current_endpointmap_id(1) {}

    int create(const char* path, const char* file);

    int load();

    bool need_reload() {
        return false;
    }

    int reload() {
        if (!need_reload()) {
            LOG(INFO) << "Noneed reload endpoin config";
            return 0;
        }

        return load();
    }

    const std::map<std::string, EndpointInfo>& config() {
        return _ep_map;
    }

    const std::map<std::string, EndpointInfo>& config() const {
        return _ep_map;
    }

private:
    int init_one_variant(
W
wangguibao 已提交
65
            const configure::VariantConf& conf, 
W
sdk-cpp  
wangguibao 已提交
66 67 68
            VariantInfo& var);

    int init_one_endpoint(
W
wangguibao 已提交
69
            const configure::Predictor& conf,
W
sdk-cpp  
wangguibao 已提交
70 71 72 73 74
            EndpointInfo& ep,
            const VariantInfo& default_var);

    int merge_variant(
            const VariantInfo& default_var,
W
wangguibao 已提交
75
            const configure::VariantConf& conf,
W
sdk-cpp  
wangguibao 已提交
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
            VariantInfo& merged_var);

    int parse_tag_values(
            SplitParameters& split);
    
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;
};

} // sdk_cpp
} // paddle_serving
} // baidu

#endif  //BAIDU_PADDLE_SERVING_SDK_CPP_CONFIG_MANAGER_H

/* vim: set expandtab ts=4 sw=4 sts=4 tw=100: */