Commit c72fbd62 authored by Pavel Vainerman's avatar Pavel Vainerman

(Http API): добавил получение списка заказчиков по указанным

в параметрах датчкам
parent 2f1dbf5a
...@@ -314,7 +314,9 @@ namespace uniset ...@@ -314,7 +314,9 @@ namespace uniset
offset - начиная с, offset - начиная с,
limit - количество в ответе. limit - количество в ответе.
/consumers - получить список заказчиков по каждому датчику /consumers?sens1,sens2,sens3 - получить список заказчиков по каждому датчику
Не обязательные параметры:
sens1,... - список по каким датчикам выдать ответ
/lost - получить список заказчиков с которыми терялась связь (и они удалялись из списка) /lost - получить список заказчиков с которыми терялась связь (и они удалялись из списка)
*/ */
class SharedMemory: class SharedMemory:
......
...@@ -6,7 +6,7 @@ ulimit -Sc 10000000000 ...@@ -6,7 +6,7 @@ ulimit -Sc 10000000000
./uniset2-start.sh -f ./uniset2-smemory --smemory-id SharedMemory \ ./uniset2-start.sh -f ./uniset2-smemory --smemory-id SharedMemory \
--confile test.xml --datfile test.xml --db-logging 1 --ulog-add-levels system,level1 \ --confile test.xml --datfile test.xml --db-logging 1 --ulog-add-levels system,level1 \
--sm-log-add-levels any $* --sm-run-logserver \ --sm-log-add-levels any $* --sm-run-logserver --activator-run-httpserver \
#--pulsar-id DO_C --pulsar-iotype DO --pulsar-msec 100 #--pulsar-id DO_C --pulsar-iotype DO --pulsar-msec 100
......
...@@ -326,6 +326,7 @@ class IONotifyController: ...@@ -326,6 +326,7 @@ class IONotifyController:
// http api // http api
nlohmann::json request_consumers( const std::string& req, const Poco::URI::QueryParameters& p ); nlohmann::json request_consumers( const std::string& req, const Poco::URI::QueryParameters& p );
nlohmann::json request_lost( const string& req, const Poco::URI::QueryParameters& p ); nlohmann::json request_lost( const string& req, const Poco::URI::QueryParameters& p );
nlohmann::json getConsumers( uniset::ObjectId sid, ConsumerListInfo& clist, bool noEmpty = true );
private: private:
friend class NCRestorer; friend class NCRestorer;
......
...@@ -1169,6 +1169,7 @@ nlohmann::json IONotifyController::httpHelp(const Poco::URI::QueryParameters& p) ...@@ -1169,6 +1169,7 @@ nlohmann::json IONotifyController::httpHelp(const Poco::URI::QueryParameters& p)
{ {
nlohmann::json jdata = IOController::httpHelp(p); nlohmann::json jdata = IOController::httpHelp(p);
jdata[myname]["help"]["consumers"]["desc"] = "get consumers list"; jdata[myname]["help"]["consumers"]["desc"] = "get consumers list";
jdata[myname]["help"]["consumers"]["params"] = {"sensor1,sensor2,sensor3","get consumers for sensors"};
jdata[myname]["help"]["lost"]["desc"] = "get lost consumers list"; jdata[myname]["help"]["lost"]["desc"] = "get lost consumers list";
return std::move(jdata); return std::move(jdata);
} }
...@@ -1184,7 +1185,7 @@ nlohmann::json IONotifyController::httpRequest( const string& req, const Poco::U ...@@ -1184,7 +1185,7 @@ nlohmann::json IONotifyController::httpRequest( const string& req, const Poco::U
return IOController::httpRequest(req,p); return IOController::httpRequest(req,p);
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
nlohmann::json IONotifyController::request_consumers(const string& req, const Poco::URI::QueryParameters& p) nlohmann::json IONotifyController::request_consumers( const string& req, const Poco::URI::QueryParameters& p )
{ {
//! \todo Не реализовано //! \todo Не реализовано
nlohmann::json json; nlohmann::json json;
...@@ -1193,40 +1194,85 @@ nlohmann::json IONotifyController::request_consumers(const string& req, const Po ...@@ -1193,40 +1194,85 @@ nlohmann::json IONotifyController::request_consumers(const string& req, const Po
auto oind = uniset_conf()->oind; auto oind = uniset_conf()->oind;
uniset_rwmutex_rlock lock(askIOMutex); std::list<ParamSInfo> slist;
if( p.size() > 0 )
for( auto&& a : askIOList )
{ {
auto& i = a.second; if( !p[0].first.empty() )
slist = uniset::getSInfoList( p[0].first, uniset_conf() );
uniset_rwmutex_rlock lock(i.mut); if( slist.empty() )
{
ostringstream err;
err << "(request_consumers): Bad request parameter: '" << p[0].first << "'";
throw uniset::SystemError(err.str());
}
}
// отображаем только датчики с "не пустым" списком заказчиков uniset_rwmutex_rlock lock(askIOMutex);
if( i.clst.empty() )
continue;
string sid( std::to_string(a.first) ); // Проход по списку заданных..
auto& jsens = jdata[sid]; if( !slist.empty() )
{
auto& jnotfound = json[myname]["notfound"];
jsens["id"] = a.first; for( const auto& s: slist )
jsens["sensor_name"] = ORepHelpers::getShortName(oind->getMapName(a.first)); {
auto& jcons = jsens["consumers"]; auto a = askIOList.find(s.si.id);
if( a == askIOList.end() )
{
jnotfound.push_back(std::to_string(s.si.id));
continue;
}
for( const auto& c : i.clst ) // Включаем в ответ все, даже если список заказчиков пустой
jdata.push_back( getConsumers(a->first,a->second,false) );
}
}
else // Проход по всему списку
{
for( auto&& a : askIOList )
{ {
string cid( std::to_string(c.id) ); // добавляем только датчики с непустым списком заказчиков
auto& jconsinfo = jcons[cid]; auto jret = getConsumers(a.first,a.second,true);
jconsinfo["id"] = c.id; if( !jret.empty() )
jconsinfo["name"] = ORepHelpers::getShortName(oind->getMapName(c.id)); jdata.push_back( std::move(jret) );
jconsinfo["lostEvents"] = c.lostEvents;
jconsinfo["attempt"] = c.attempt;
jconsinfo["smCount"] = c.smCount;
} }
} }
return std::move(json); return std::move(json);
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
nlohmann::json IONotifyController::getConsumers( ObjectId sid, ConsumerListInfo& ci, bool noEmpty )
{
nlohmann::json jret;
auto oind = uniset_conf()->oind;
uniset_rwmutex_rlock lock(ci.mut);
if( ci.clst.empty() && noEmpty )
return std::move(jret);
string strID( std::to_string(sid) );
auto& jsens = jret[strID];
jsens["id"] = strID;
jsens["sensor_name"] = ORepHelpers::getShortName(oind->getMapName(sid));
auto& jcons = jsens["consumers"];
for( const auto& c : ci.clst )
{
string cid( std::to_string(c.id) );
auto& jconsinfo = jcons[cid];
jconsinfo["id"] = c.id;
jconsinfo["name"] = ORepHelpers::getShortName(oind->getMapName(c.id));
jconsinfo["lostEvents"] = c.lostEvents;
jconsinfo["attempt"] = c.attempt;
jconsinfo["smCount"] = c.smCount;
}
return std::move(jret);
}
// -----------------------------------------------------------------------------
nlohmann::json IONotifyController::request_lost( const string& req, const Poco::URI::QueryParameters& p ) nlohmann::json IONotifyController::request_lost( const string& req, const Poco::URI::QueryParameters& p )
{ {
//! \todo Не реализовано //! \todo Не реализовано
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment