Skip to content

Commit b3bca30

Browse files
committed
https://telecominfraproject.atlassian.net/browse/WIFI-12868
Signed-off-by: stephb9959 <stephane.bourque@gmail.com>
1 parent fe4256c commit b3bca30

12 files changed

Lines changed: 92 additions & 16 deletions

src/framework/ALBserver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ namespace OpenWifi {
2626
Response.set("Connection", "keep-alive");
2727
Response.setVersion(Poco::Net::HTTPMessage::HTTP_1_1);
2828
std::ostream &Answer = Response.send();
29-
Answer << "process Alive and kicking!";
29+
Answer << ALBHealthCheckServer()->CallbackText();
3030
} catch (...) {
3131
}
3232
}

src/framework/ALBserver.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ namespace OpenWifi {
3737
inline static std::atomic_uint64_t req_id_ = 1;
3838
};
3939

40+
typedef std::string ALBHealthMessageCallback();
41+
4042
class ALBHealthCheckServer : public SubSystemServer {
4143
public:
4244
ALBHealthCheckServer();
@@ -48,10 +50,22 @@ namespace OpenWifi {
4850

4951
int Start() override;
5052
void Stop() override;
53+
inline void RegisterExtendedHealthMessage(ALBHealthMessageCallback *F) {
54+
Callback_=F;
55+
};
56+
57+
inline std::string CallbackText() {
58+
if(Callback_== nullptr) {
59+
return "process Alive and kicking!";
60+
} else {
61+
return Callback_();
62+
}
63+
}
5164

5265
private:
5366
std::unique_ptr<Poco::Net::HTTPServer> Server_;
5467
std::unique_ptr<Poco::Net::ServerSocket> Socket_;
68+
ALBHealthMessageCallback *Callback_= nullptr;
5569
int Port_ = 0;
5670
mutable std::atomic_bool Running_ = false;
5771
};

src/framework/KafkaManager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ namespace OpenWifi {
213213
}
214214

215215
void KafkaProducer::Produce(const char *Topic, const std::string &Key,
216-
const std::shared_ptr<std::string> Payload) {
216+
std::shared_ptr<std::string> Payload) {
217217
std::lock_guard G(Mutex_);
218218
Queue_.enqueueNotification(new KafkaMessage(Topic, Key, Payload));
219219
}

src/framework/KafkaManager.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ namespace OpenWifi {
1818

1919
class KafkaMessage : public Poco::Notification {
2020
public:
21-
KafkaMessage(const char * Topic, const std::string &Key, const std::shared_ptr<std::string> Payload)
22-
: Topic_(Topic), Key_(Key), Payload_(std::move(Payload)) {}
21+
KafkaMessage(const char * Topic, const std::string &Key, std::shared_ptr<std::string> Payload)
22+
: Topic_(Topic), Key_(Key), Payload_(Payload) {}
2323

2424
inline const char * Topic() { return Topic_; }
2525
inline const std::string &Key() { return Key_; }
@@ -36,7 +36,7 @@ namespace OpenWifi {
3636
void run() override;
3737
void Start();
3838
void Stop();
39-
void Produce(const char *Topic, const std::string &Key, const std::shared_ptr<std::string> Payload);
39+
void Produce(const char *Topic, const std::string &Key, std::shared_ptr<std::string> Payload);
4040

4141
private:
4242
std::recursive_mutex Mutex_;
@@ -92,9 +92,9 @@ namespace OpenWifi {
9292
void Stop() override;
9393

9494
void PostMessage(const char *topic, const std::string &key,
95-
const std::shared_ptr<std::string> PayLoad, bool WrapMessage = true);
96-
void Dispatch(const char *Topic, const std::string &Key, const std::shared_ptr<std::string> Payload);
97-
[[nodiscard]] const std::shared_ptr<std::string> WrapSystemId(const std::shared_ptr<std::string> PayLoad);
95+
std::shared_ptr<std::string> PayLoad, bool WrapMessage = true);
96+
void Dispatch(const char *Topic, const std::string &Key, std::shared_ptr<std::string> Payload);
97+
[[nodiscard]] const std::shared_ptr<std::string> WrapSystemId(std::shared_ptr<std::string> PayLoad);
9898
[[nodiscard]] inline bool Enabled() const { return KafkaEnabled_; }
9999
uint64_t RegisterTopicWatcher(const std::string &Topic, Types::TopicNotifyFunction &F);
100100
void UnregisterTopicWatcher(const std::string &Topic, uint64_t Id);

src/framework/MicroService.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ namespace OpenWifi {
129129
}
130130
} else {
131131
poco_error(logger(), "Bad bus message.");
132+
std::ostringstream os;
133+
Object->stringify(std::cout);
132134
}
133135

134136
auto i = Services_.begin();

src/framework/MicroServiceFuncs.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
#include "framework/MicroServiceFuncs.h"
66
#include "framework/MicroService.h"
77

8+
#include "framework/ALBserver.h"
9+
810
namespace OpenWifi {
911
const std::string &MicroServiceDataDirectory() { return MicroService::instance().DataDir(); }
1012

@@ -123,4 +125,8 @@ namespace OpenWifi {
123125
return MicroService::instance().AllowExternalMicroServices();
124126
}
125127

128+
void MicroServiceALBCallback( std::string Callback()) {
129+
return ALBHealthCheckServer()->RegisterExtendedHealthMessage(Callback);
130+
}
131+
126132
} // namespace OpenWifi

src/framework/MicroServiceFuncs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,5 @@ namespace OpenWifi {
5353
std::string MicroServiceGetPublicAPIEndPoint();
5454
void MicroServiceDeleteOverrideConfiguration();
5555
bool AllowExternalMicroServices();
56+
void MicroServiceALBCallback( std::string Callback());
5657
} // namespace OpenWifi

src/framework/OpenWifiTypes.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ namespace OpenWifi::Types {
2828
typedef std::string UUID_t;
2929
typedef std::vector<UUID_t> UUIDvec_t;
3030
typedef std::map<std::string, std::map<uint32_t, uint64_t>> Counted3DMapSII;
31+
typedef std::vector<int64_t> IntList;
32+
typedef std::vector<uint64_t> UIntList;
33+
typedef std::vector<double> DoubleList;
3134

3235
struct MicroServiceMeta {
3336
uint64_t Id = 0;

src/framework/RESTAPI_utils.h

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,20 @@ namespace OpenWifi::RESTAPI_utils {
102102
Obj.set(Field, A);
103103
}
104104

105+
inline void field_to_json(Poco::JSON::Object &Obj, const char *Field, const Types::DoubleList &V) {
106+
Poco::JSON::Array A;
107+
for (const auto &i : V)
108+
A.add(i);
109+
Obj.set(Field, A);
110+
}
111+
112+
inline void field_to_json(Poco::JSON::Object &Obj, const char *Field, const Types::IntList &V) {
113+
Poco::JSON::Array A;
114+
for (const auto &i : V)
115+
A.add(i);
116+
Obj.set(Field, A);
117+
}
118+
105119
inline void field_to_json(Poco::JSON::Object &Obj, const char *Field, const Types::TagList &V) {
106120
Poco::JSON::Array A;
107121
for (const auto &i : V)
@@ -284,6 +298,28 @@ namespace OpenWifi::RESTAPI_utils {
284298
}
285299
}
286300

301+
inline void field_from_json(const Poco::JSON::Object::Ptr &Obj, const char *Field,
302+
Types::DoubleList &Value) {
303+
if (Obj->isArray(Field) && !Obj->isNull(Field)) {
304+
Value.clear();
305+
Poco::JSON::Array::Ptr A = Obj->getArray(Field);
306+
for (const auto &i : *A) {
307+
Value.push_back(i);
308+
}
309+
}
310+
}
311+
312+
inline void field_from_json(const Poco::JSON::Object::Ptr &Obj, const char *Field,
313+
Types::IntList &Value) {
314+
if (Obj->isArray(Field) && !Obj->isNull(Field)) {
315+
Value.clear();
316+
Poco::JSON::Array::Ptr A = Obj->getArray(Field);
317+
for (const auto &i : *A) {
318+
Value.push_back(i);
319+
}
320+
}
321+
}
322+
287323
template <class T>
288324
void field_from_json(const Poco::JSON::Object::Ptr &Obj, const char *Field,
289325
std::vector<T> &Value) {

src/framework/StorageClass.h

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,8 @@ namespace OpenWifi {
2222

2323
class StorageClass : public SubSystemServer {
2424
public:
25-
StorageClass() noexcept : SubSystemServer("StorageClass", "STORAGE-SVR", "storage") {}
2625

27-
int Start() override {
26+
inline int Start() override {
2827
std::lock_guard Guard(Mutex_);
2928

3029
Logger().notice("Starting.");
@@ -40,17 +39,22 @@ namespace OpenWifi {
4039
return 0;
4140
}
4241

43-
void Stop() override { Pool_->shutdown(); }
42+
inline void Stop() override { Pool_->shutdown(); }
4443

4544
DBType Type() const { return dbType_; };
4645

46+
StorageClass() noexcept : SubSystemServer("StorageClass", "STORAGE-SVR", "storage") {
47+
48+
}
49+
4750
private:
4851
inline int Setup_SQLite();
4952
inline int Setup_MySQL();
5053
inline int Setup_PostgreSQL();
5154

52-
protected:
53-
std::unique_ptr<Poco::Data::SessionPool> Pool_;
55+
56+
protected:
57+
std::shared_ptr<Poco::Data::SessionPool> Pool_;
5458
Poco::Data::SQLite::Connector SQLiteConn_;
5559
Poco::Data::PostgreSQL::Connector PostgresConn_;
5660
Poco::Data::MySQL::Connector MySQLConn_;
@@ -81,7 +85,7 @@ namespace OpenWifi {
8185
// Poco::Data::SessionPool(SQLiteConn_.name(), DBName, 8,
8286
// (int)NumSessions,
8387
// (int)IdleTime));
84-
Pool_ = std::make_unique<Poco::Data::SessionPool>(SQLiteConn_.name(), DBName, 8,
88+
Pool_ = std::make_shared<Poco::Data::SessionPool>(SQLiteConn_.name(), DBName, 8,
8589
(int)NumSessions, (int)IdleTime);
8690
return 0;
8791
}
@@ -102,7 +106,7 @@ namespace OpenWifi {
102106
";compress=true;auto-reconnect=true";
103107

104108
Poco::Data::MySQL::Connector::registerConnector();
105-
Pool_ = std::make_unique<Poco::Data::SessionPool>(MySQLConn_.name(), ConnectionStr, 8,
109+
Pool_ = std::make_shared<Poco::Data::SessionPool>(MySQLConn_.name(), ConnectionStr, 8,
106110
NumSessions, IdleTime);
107111

108112
return 0;
@@ -126,7 +130,7 @@ namespace OpenWifi {
126130
" connect_timeout=" + ConnectionTimeout;
127131

128132
Poco::Data::PostgreSQL::Connector::registerConnector();
129-
Pool_ = std::make_unique<Poco::Data::SessionPool>(PostgresConn_.name(), ConnectionStr, 8,
133+
Pool_ = std::make_shared<Poco::Data::SessionPool>(PostgresConn_.name(), ConnectionStr, 8,
130134
NumSessions, IdleTime);
131135

132136
return 0;

0 commit comments

Comments
 (0)