diff --git a/src/lib/api/services/AnalyticsService.proto b/src/lib/api/services/AnalyticsService.proto index 240a806ca..d75b261e7 100644 --- a/src/lib/api/services/AnalyticsService.proto +++ b/src/lib/api/services/AnalyticsService.proto @@ -5,6 +5,7 @@ import "lib/api/apioptions.proto"; import "lib/api/apicore.proto"; message VolSurfaceEntry{ + uint64 save_time = 1 [(bts.api.key)=true]; int32 vs_id = 10; string vs_name = 20; bytes volsurface = 30; @@ -25,4 +26,8 @@ service AnalyticsService { rpc save_volsurface(VolSurfaceEntry) returns (bts.api.ResultMessage); rpc delete_volsurface(IntWrapper) returns (bts.api.ResultMessage); rpc clean_up(IntWrapper) returns (bts.api.VoidMessage); + + // subscription + rpc volsurfaces(bts.api.VoidMessage) returns (stream VolSurfaceEntry); + } \ No newline at end of file diff --git a/src/server/sparkd/analytics/AnalyticsServiceServer.cpp b/src/server/sparkd/analytics/AnalyticsServiceServer.cpp index e9f5f2879..10da8be01 100644 --- a/src/server/sparkd/analytics/AnalyticsServiceServer.cpp +++ b/src/server/sparkd/analytics/AnalyticsServiceServer.cpp @@ -1,15 +1,43 @@ #include "AnalyticsServiceServer.h" +#include "lib/logging/logging.h" #include "lib/persistence/SqliteStore.h" #include "lib/utils/PBUtils.h" #include "lib/utils/Puid.h" +#include namespace bts::analytics { -struct AnalyticsServiceServer::PImpl {}; +struct AnalyticsServiceServer::PImpl { + bts::api::ServiceContext &context; + std::unique_ptr vs_fill_store; + AnalyticsServiceBase::VolsurfacesStatefulPublisher vs_publisher; + PImpl( + bts::api::ServiceContext &context, + const AnalyticsServiceBase::VolsurfacesStatefulPublisher &vs_publisher) + : context(context), + vs_fill_store( + std::make_unique("volsurfaces")), + vs_publisher(vs_publisher) {} +}; AnalyticsServiceServer::AnalyticsServiceServer( bts::api::ServiceContext &context) - : AnalyticsServiceBase(context) {} + : AnalyticsServiceBase(context), + me(new PImpl(context, make_volsurfaces_stateful_publisher())) { + auto all = me->vs_fill_store->retrieve_all(); + LOG(persist, Info, "Finished loading all {} manual fills", all.size()); + for (auto const &ns_vals : all) { + const std::string &vs_name = ns_vals.first; + const std::map &vals = ns_vals.second; + LOG(OrderMan, Info, "vs:{} entries:{}", vs_name, vals.size()); + for (const auto &kvp : vals) { + const std::string &key = kvp.first; + const std::string &val = kvp.second; + LOG(OrderMan, Info, "vs:{} key:{} val:{}", vs_name, key, val); + } + } + me->vs_publisher.flush(); +} void AnalyticsServiceServer::get_new_volsurface_id( const ::bts::api::VoidMessage &, @@ -18,7 +46,11 @@ void AnalyticsServiceServer::get_new_volsurface_id( void AnalyticsServiceServer::save_volsurface( const ::bts::api::analytics::VolSurfaceEntry &, - const api::Response<::bts::api::ResultMessage> &) {} + const api::Response<::bts::api::ResultMessage> &) { + // ns = vs_key_name + // key = posix save time + // val = VolSurfaceEntry +} void AnalyticsServiceServer::delete_volsurface( const ::bts::api::analytics::IntWrapper &,