RTBKit  0.9
Open-source framework to create real-time ad bidding systems.
core/agent_configuration/agent_configuration_service.h
00001 /* configuration_service.h                                         -*- C++ -*-
00002    Jeremy Barnes, 26 November 2012
00003    Copyright (c) 2012 Datacratic Inc.  All rights reserved.
00004 */
00005 
00006 #pragma once
00007 
00008 #include "soa/service/rest_service_endpoint.h"
00009 #include "soa/service/service_base.h"
00010 #include "soa/service/rest_request_router.h"
00011 
00012 #include "rtbkit/core/monitor/monitor_provider.h"
00013 
00014 namespace RTBKIT {
00015 
00016 using namespace Datacratic;
00017 
00018 /*****************************************************************************/
00019 /* AGENT CONFIGURATION SERVICE                                               */
00020 /*****************************************************************************/
00021 
00035 struct AgentConfigurationService : public RestServiceEndpoint,
00036                                    public ServiceBase,
00037                                    public MonitorProvider
00038 {
00039 
00040     AgentConfigurationService(std::shared_ptr<ServiceProxies> services,
00041                               const std::string & serviceName = "agentConfigurationService");
00042 
00043     ~AgentConfigurationService()
00044     {
00045         shutdown();
00046         agents.shutdown();
00047         listeners.shutdown();
00048     }
00049 
00050     void init();
00051 
00052     void start()
00053     {
00054         RestServiceEndpoint::start();
00055         monitorProviderClient.start();
00056         //listeners.start();
00057     }
00058 
00059     void shutdown()
00060     {
00061         RestServiceEndpoint::shutdown();
00062         agents.shutdown();
00063         listeners.shutdown();
00064         monitorProviderClient.shutdown();
00065     }
00066 
00068     void handleAgentHeartbeat(const std::string & agent);
00069     
00071     void handleAgentConfig(const std::string & agent,
00072                            const Json::Value & config);
00073 
00075     Json::Value handleGetAgent(const std::string & agent) const;
00076 
00078     std::vector<std::string> handleGetAgentList() const;
00079 
00081     Json::Value handleGetAllAgents() const;
00082 
00084     void bindTcp();
00085 
00086     RestRequestRouter router;
00087 
00088     ZmqNamedClientBus agents;
00089 
00093     ZmqNamedClientBus listeners;
00094 
00095     struct ListenerInfo {
00096     };
00097     
00098     std::unordered_map<std::string, ListenerInfo> listenerInfo;
00099 
00100     struct AgentInfo {
00101         Json::Value config;
00102         std::string configStr;
00103         Date lastHeartbeat;
00104     };
00105 
00106     std::unordered_map<std::string, AgentInfo> agentInfo;
00107 
00108     /* Reponds to Monitor requests */
00109     MonitorProviderClient monitorProviderClient;
00110 
00111     /* MonitorProvider interface */
00112     std::string getProviderName() const;
00113     Json::Value getProviderIndicators() const;
00114 };
00115 
00116 } // namespace RTBKIT
00117 
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator