Move Bind/Connect/Attach to FairMQChannel

This commit is contained in:
Alexey Rybalchenko
2018-11-05 15:11:41 +01:00
committed by Dennis Klein
parent 3ca0d7236a
commit 25fcf13985
20 changed files with 603 additions and 696 deletions

View File

@@ -32,8 +32,7 @@ namespace parser
// function that convert property tree (given the json structure) to FairMQChannelMap
FairMQChannelMap ptreeToMQMap(const boost::property_tree::ptree& pt, const string& id, const string& rootNode)
{
if (id == "")
{
if (id == "") {
throw ParserError("no device ID provided. Provide with `--id` cmd option");
}
@@ -44,8 +43,7 @@ FairMQChannelMap ptreeToMQMap(const boost::property_tree::ptree& pt, const strin
// Extract value from boost::property_tree
Helper::DeviceParser(pt.get_child(rootNode), channelMap, id);
if (channelMap.empty())
{
if (channelMap.empty()) {
LOG(warn) << "---- No channel keys found for " << id;
LOG(warn) << "---- Check the JSON inputs and/or command line inputs";
}
@@ -68,20 +66,14 @@ void PrintDeviceList(const boost::property_tree::ptree& tree)
string deviceIdKey;
// do a first loop just to print the device-id in json input
for (const auto& p : tree)
{
if (p.first == "devices")
{
for (const auto& q : p.second.get_child(""))
{
for (const auto& p : tree) {
if (p.first == "devices") {
for (const auto& q : p.second.get_child("")) {
string key = q.second.get<string>("key", "");
if (key != "")
{
if (key != "") {
deviceIdKey = key;
LOG(debug) << "Found config for device key '" << deviceIdKey << "' in JSON input";
}
else
{
} else {
deviceIdKey = q.second.get<string>("id");
LOG(debug) << "Found config for device id '" << deviceIdKey << "' in JSON input";
}
@@ -95,33 +87,26 @@ void DeviceParser(const boost::property_tree::ptree& tree, FairMQChannelMap& cha
string deviceIdKey;
// For each node in fairMQOptions
for (const auto& p : tree)
{
if (p.first == "devices")
{
for (const auto& q : p.second)
{
for (const auto& p : tree) {
if (p.first == "devices") {
for (const auto& q : p.second) {
// check if key is provided, otherwise use id
string key = q.second.get<string>("key", "");
if (key != "")
{
if (key != "") {
deviceIdKey = key;
// LOG(debug) << "Found config for device key '" << deviceIdKey << "' in JSON input";
}
else
{
// LOG(trace) << "Found config for device key '" << deviceIdKey << "' in JSON input";
} else {
deviceIdKey = q.second.get<string>("id");
// LOG(debug) << "Found config for device id '" << deviceIdKey << "' in JSON input";
// LOG(trace) << "Found config for device id '" << deviceIdKey << "' in JSON input";
}
// if not correct device id, do not fill MQMap
if (deviceId != deviceIdKey)
{
if (deviceId != deviceIdKey) {
continue;
}
LOG(debug) << "Found following channels for device ID '" << deviceId << "' :";
LOG(trace) << "Found following channels for device ID '" << deviceId << "' :";
ChannelParser(q.second, channelMap);
}
@@ -133,12 +118,9 @@ void ChannelParser(const boost::property_tree::ptree& tree, FairMQChannelMap& ch
{
string channelKey;
for (const auto& p : tree)
{
if (p.first == "channels")
{
for (const auto& q : p.second)
{
for (const auto& p : tree) {
if (p.first == "channels") {
for (const auto& q : p.second) {
channelKey = q.second.get<string>("name");
int numSockets = q.second.get<int>("numSockets", 0);
@@ -154,36 +136,37 @@ void ChannelParser(const boost::property_tree::ptree& tree, FairMQChannelMap& ch
commonChannel.UpdateSndKernelSize(q.second.get<int>("sndKernelSize", commonChannel.GetSndKernelSize()));
commonChannel.UpdateRcvKernelSize(q.second.get<int>("rcvKernelSize", commonChannel.GetRcvKernelSize()));
commonChannel.UpdateLinger(q.second.get<int>("linger", commonChannel.GetLinger()));
commonChannel.UpdateRateLogging(q.second.get<int>("rateLogging", commonChannel.GetRateLogging()));
commonChannel.UpdatePortRangeMin(q.second.get<int>("portRangeMin", commonChannel.GetPortRangeMin()));
commonChannel.UpdatePortRangeMax(q.second.get<int>("portRangeMax", commonChannel.GetPortRangeMax()));
commonChannel.UpdateAutoBind(q.second.get<bool>("autoBind", commonChannel.GetAutoBind()));
// temporary FairMQChannel container
vector<FairMQChannel> channelList;
if (numSockets > 0)
{
LOG(debug) << "" << channelKey << ":";
LOG(debug) << "\tnumSockets of " << numSockets << " specified,";
LOG(debug) << "\tapplying common settings to each:";
if (numSockets > 0) {
LOG(trace) << "" << channelKey << ":";
LOG(trace) << "\tnumSockets of " << numSockets << " specified,";
LOG(trace) << "\tapplying common settings to each:";
LOG(debug) << "\ttype = " << commonChannel.GetType();
LOG(debug) << "\tmethod = " << commonChannel.GetMethod();
LOG(debug) << "\taddress = " << commonChannel.GetAddress();
LOG(debug) << "\ttransport = " << commonChannel.GetTransportName();
LOG(debug) << "\tsndBufSize = " << commonChannel.GetSndBufSize();
LOG(debug) << "\trcvBufSize = " << commonChannel.GetRcvBufSize();
LOG(debug) << "\tsndKernelSize = " << commonChannel.GetSndKernelSize();
LOG(debug) << "\trcvKernelSize = " << commonChannel.GetRcvKernelSize();
LOG(debug) << "\tlinger = " << commonChannel.GetLinger();
LOG(debug) << "\trateLogging = " << commonChannel.GetRateLogging();
LOG(trace) << "\ttype = " << commonChannel.GetType();
LOG(trace) << "\tmethod = " << commonChannel.GetMethod();
LOG(trace) << "\taddress = " << commonChannel.GetAddress();
LOG(trace) << "\ttransport = " << commonChannel.GetTransportName();
LOG(trace) << "\tsndBufSize = " << commonChannel.GetSndBufSize();
LOG(trace) << "\trcvBufSize = " << commonChannel.GetRcvBufSize();
LOG(trace) << "\tsndKernelSize = " << commonChannel.GetSndKernelSize();
LOG(trace) << "\trcvKernelSize = " << commonChannel.GetRcvKernelSize();
LOG(trace) << "\tlinger = " << commonChannel.GetLinger();
LOG(trace) << "\trateLogging = " << commonChannel.GetRateLogging();
LOG(trace) << "\tportRangeMin = " << commonChannel.GetPortRangeMin();
LOG(trace) << "\tportRangeMax = " << commonChannel.GetPortRangeMax();
LOG(trace) << "\tautoBind = " << commonChannel.GetAutoBind();
for (int i = 0; i < numSockets; ++i)
{
for (int i = 0; i < numSockets; ++i) {
FairMQChannel channel(commonChannel);
channelList.push_back(channel);
}
}
else
{
} else {
SocketParser(q.second.get_child(""), channelList, channelKey, commonChannel);
}
@@ -198,12 +181,9 @@ void SocketParser(const boost::property_tree::ptree& tree, vector<FairMQChannel>
// for each socket in channel
int socketCounter = 0;
for (const auto& p : tree)
{
if (p.first == "sockets")
{
for (const auto& q : p.second)
{
for (const auto& p : tree) {
if (p.first == "sockets") {
for (const auto& q : p.second) {
// create new channel and apply setting from the common channel
FairMQChannel channel(commonChannel);
@@ -218,18 +198,24 @@ void SocketParser(const boost::property_tree::ptree& tree, vector<FairMQChannel>
channel.UpdateRcvKernelSize(q.second.get<int>("rcvKernelSize", channel.GetRcvKernelSize()));
channel.UpdateLinger(q.second.get<int>("linger", channel.GetLinger()));
channel.UpdateRateLogging(q.second.get<int>("rateLogging", channel.GetRateLogging()));
channel.UpdatePortRangeMin(q.second.get<int>("portRangeMin", channel.GetPortRangeMin()));
channel.UpdatePortRangeMax(q.second.get<int>("portRangeMax", channel.GetPortRangeMax()));
channel.UpdateAutoBind(q.second.get<bool>("autoBind", channel.GetAutoBind()));
LOG(debug) << "" << channelName << "[" << socketCounter << "]:";
LOG(debug) << "\ttype = " << channel.GetType();
LOG(debug) << "\tmethod = " << channel.GetMethod();
LOG(debug) << "\taddress = " << channel.GetAddress();
LOG(debug) << "\ttransport = " << channel.GetTransportName();
LOG(debug) << "\tsndBufSize = " << channel.GetSndBufSize();
LOG(debug) << "\trcvBufSize = " << channel.GetRcvBufSize();
LOG(debug) << "\tsndKernelSize = " << channel.GetSndKernelSize();
LOG(debug) << "\trcvKernelSize = " << channel.GetRcvKernelSize();
LOG(debug) << "\tlinger = " << channel.GetLinger();
LOG(debug) << "\trateLogging = " << channel.GetRateLogging();
LOG(trace) << "" << channelName << "[" << socketCounter << "]:";
LOG(trace) << "\ttype = " << channel.GetType();
LOG(trace) << "\tmethod = " << channel.GetMethod();
LOG(trace) << "\taddress = " << channel.GetAddress();
LOG(trace) << "\ttransport = " << channel.GetTransportName();
LOG(trace) << "\tsndBufSize = " << channel.GetSndBufSize();
LOG(trace) << "\trcvBufSize = " << channel.GetRcvBufSize();
LOG(trace) << "\tsndKernelSize = " << channel.GetSndKernelSize();
LOG(trace) << "\trcvKernelSize = " << channel.GetRcvKernelSize();
LOG(trace) << "\tlinger = " << channel.GetLinger();
LOG(trace) << "\trateLogging = " << channel.GetRateLogging();
LOG(trace) << "\tportRangeMin = " << channel.GetPortRangeMin();
LOG(trace) << "\tportRangeMax = " << channel.GetPortRangeMax();
LOG(trace) << "\tautoBind = " << channel.GetAutoBind();
channelList.push_back(channel);
++socketCounter;
@@ -237,28 +223,28 @@ void SocketParser(const boost::property_tree::ptree& tree, vector<FairMQChannel>
}
} // end socket loop
if (socketCounter)
{
LOG(debug) << "Found " << socketCounter << " socket(s) in channel.";
}
else
{
LOG(debug) << "" << channelName << ":";
LOG(debug) << "\tNo sockets specified,";
LOG(debug) << "\tapplying common settings to the channel:";
if (socketCounter) {
LOG(trace) << "Found " << socketCounter << " socket(s) in channel.";
} else {
LOG(trace) << "" << channelName << ":";
LOG(trace) << "\tNo sockets specified,";
LOG(trace) << "\tapplying common settings to the channel:";
FairMQChannel channel(commonChannel);
LOG(debug) << "\ttype = " << channel.GetType();
LOG(debug) << "\tmethod = " << channel.GetMethod();
LOG(debug) << "\taddress = " << channel.GetAddress();
LOG(debug) << "\ttransport = " << channel.GetTransportName();
LOG(debug) << "\tsndBufSize = " << channel.GetSndBufSize();
LOG(debug) << "\trcvBufSize = " << channel.GetRcvBufSize();
LOG(debug) << "\tsndKernelSize = " << channel.GetSndKernelSize();
LOG(debug) << "\trcvKernelSize = " << channel.GetRcvKernelSize();
LOG(debug) << "\tlinger = " << channel.GetLinger();
LOG(debug) << "\trateLogging = " << channel.GetRateLogging();
LOG(trace) << "\ttype = " << channel.GetType();
LOG(trace) << "\tmethod = " << channel.GetMethod();
LOG(trace) << "\taddress = " << channel.GetAddress();
LOG(trace) << "\ttransport = " << channel.GetTransportName();
LOG(trace) << "\tsndBufSize = " << channel.GetSndBufSize();
LOG(trace) << "\trcvBufSize = " << channel.GetRcvBufSize();
LOG(trace) << "\tsndKernelSize = " << channel.GetSndKernelSize();
LOG(trace) << "\trcvKernelSize = " << channel.GetRcvKernelSize();
LOG(trace) << "\tlinger = " << channel.GetLinger();
LOG(trace) << "\trateLogging = " << channel.GetRateLogging();
LOG(trace) << "\tportRangeMin = " << channel.GetPortRangeMin();
LOG(trace) << "\tportRangeMax = " << channel.GetPortRangeMax();
LOG(trace) << "\tautoBind = " << channel.GetAutoBind();
channelList.push_back(channel);
}

View File

@@ -62,8 +62,6 @@ FairMQProgOptions::FairMQProgOptions()
("network-interface", po::value<string>()->default_value("default"), "Network interface to bind on (e.g. eth0, ib0..., default will try to detect the interface of the default route).")
("config-key", po::value<string>(), "Use provided value instead of device id for fetching the configuration from the config file.")
("initialization-timeout", po::value<int >()->default_value(120), "Timeout for the initialization in seconds (when expecting dynamic initialization).")
("port-range-min", po::value<int >()->default_value(22000), "Start of the port range for dynamic initialization.")
("port-range-max", po::value<int >()->default_value(32000), "End of the port range for dynamic initialization.")
("print-channels", po::value<bool >()->implicit_value(true), "Print registered channel endpoints in a machine-readable format (<channel name>:<min num subchannels>:<max num subchannels>)")
("shm-segment-size", po::value<size_t>()->default_value(2000000000), "Shared memory: size of the shared memory segment (in bytes).")
("shm-monitor", po::value<bool >()->default_value(true), "Shared memory: run monitor daemon.")
@@ -170,7 +168,6 @@ int FairMQProgOptions::ParseAll(const int argc, char const* const* argv, bool al
{
LOG(warn) << "--" << p->canonical_display_name();
}
LOG(warn) << "No channels will be created (You can create them manually).";
}
}
catch (exception& e)
@@ -270,12 +267,10 @@ void FairMQProgOptions::UpdateChannelInfo()
// create key for variable map as follow : channelName.index.memberName
void FairMQProgOptions::UpdateMQValues()
{
for (const auto& p : fFairMQChannelMap)
{
for (const auto& p : fFairMQChannelMap) {
int index = 0;
for (const auto& channel : p.second)
{
for (const auto& channel : p.second) {
string typeKey = "chans." + p.first + "." + to_string(index) + ".type";
string methodKey = "chans." + p.first + "." + to_string(index) + ".method";
string addressKey = "chans." + p.first + "." + to_string(index) + ".address";
@@ -286,6 +281,9 @@ void FairMQProgOptions::UpdateMQValues()
string rcvKernelSizeKey = "chans." + p.first + "." + to_string(index) + ".rcvKernelSize";
string lingerKey = "chans." + p.first + "." + to_string(index) + ".linger";
string rateLoggingKey = "chans." + p.first + "." + to_string(index) + ".rateLogging";
string portRangeMinKey = "chans." + p.first + "." + to_string(index) + ".portRangeMin";
string portRangeMaxKey = "chans." + p.first + "." + to_string(index) + ".portRangeMax";
string autoBindKey = "chans." + p.first + "." + to_string(index) + ".autoBind";
fChannelKeyMap[typeKey] = ChannelKey{p.first, index, "type"};
fChannelKeyMap[methodKey] = ChannelKey{p.first, index, "method"};
@@ -297,6 +295,9 @@ void FairMQProgOptions::UpdateMQValues()
fChannelKeyMap[rcvKernelSizeKey] = ChannelKey{p.first, index, "rcvkernelSize"};
fChannelKeyMap[lingerKey] = ChannelKey{p.first, index, "linger"};
fChannelKeyMap[rateLoggingKey] = ChannelKey{p.first, index, "rateLogging"};
fChannelKeyMap[portRangeMinKey] = ChannelKey{p.first, index, "portRangeMin"};
fChannelKeyMap[portRangeMaxKey] = ChannelKey{p.first, index, "portRangeMax"};
fChannelKeyMap[autoBindKey] = ChannelKey{p.first, index, "autoBind"};
UpdateVarMap<string>(typeKey, channel.GetType());
UpdateVarMap<string>(methodKey, channel.GetMethod());
@@ -308,86 +309,67 @@ void FairMQProgOptions::UpdateMQValues()
UpdateVarMap<int>(rcvKernelSizeKey, channel.GetRcvKernelSize());
UpdateVarMap<int>(lingerKey, channel.GetLinger());
UpdateVarMap<int>(rateLoggingKey, channel.GetRateLogging());
UpdateVarMap<int>(portRangeMinKey, channel.GetPortRangeMin());
UpdateVarMap<int>(portRangeMaxKey, channel.GetPortRangeMax());
UpdateVarMap<bool>(autoBindKey, channel.GetAutoBind());
index++;
}
UpdateVarMap<int>("chans." + p.first + ".numSockets", index);
}
}
int FairMQProgOptions::UpdateChannelValue(const string& channelName, int index, const string& member, const string& val)
{
if (member == "type")
{
if (member == "type") {
fFairMQChannelMap.at(channelName).at(index).UpdateType(val);
return 0;
}
if (member == "method")
{
} else if (member == "method") {
fFairMQChannelMap.at(channelName).at(index).UpdateMethod(val);
return 0;
}
if (member == "address")
{
} else if (member == "address") {
fFairMQChannelMap.at(channelName).at(index).UpdateAddress(val);
return 0;
}
if (member == "transport")
{
} else if (member == "transport") {
fFairMQChannelMap.at(channelName).at(index).UpdateTransport(val);
return 0;
}
else
{
//if we get there it means something is wrong
} else {
LOG(error) << "update of FairMQChannel map failed for the following key: " << channelName << "." << index << "." << member;
return 1;
}
return 0;
}
int FairMQProgOptions::UpdateChannelValue(const string& channelName, int index, const string& member, int val)
{
if (member == "sndBufSize")
{
if (member == "sndBufSize") {
fFairMQChannelMap.at(channelName).at(index).UpdateSndBufSize(val);
return 0;
}
if (member == "rcvBufSize")
{
} else if (member == "rcvBufSize") {
fFairMQChannelMap.at(channelName).at(index).UpdateRcvBufSize(val);
return 0;
}
if (member == "sndKernelSize")
{
} else if (member == "sndKernelSize") {
fFairMQChannelMap.at(channelName).at(index).UpdateSndKernelSize(val);
return 0;
}
if (member == "rcvKernelSize")
{
} else if (member == "rcvKernelSize") {
fFairMQChannelMap.at(channelName).at(index).UpdateRcvKernelSize(val);
return 0;
}
if (member == "linger")
{
} else if (member == "linger") {
fFairMQChannelMap.at(channelName).at(index).UpdateLinger(val);
return 0;
} else if (member == "rateLogging") {
fFairMQChannelMap.at(channelName).at(index).UpdateRateLogging(val);
} else if (member == "portRangeMin") {
fFairMQChannelMap.at(channelName).at(index).UpdatePortRangeMin(val);
} else if (member == "portRangeMax") {
fFairMQChannelMap.at(channelName).at(index).UpdatePortRangeMax(val);
} else {
LOG(error) << "update of FairMQChannel map failed for the following key: " << channelName << "." << index << "." << member;
return 1;
}
if (member == "rateLogging")
{
fFairMQChannelMap.at(channelName).at(index).UpdateRateLogging(val);
return 0;
}
int FairMQProgOptions::UpdateChannelValue(const string& channelName, int index, const string& member, bool val)
{
if (member == "autoBind") {
fFairMQChannelMap.at(channelName).at(index).UpdateAutoBind(val);
return 0;
}
else
{
// if we get there it means something is wrong
} else {
LOG(error) << "update of FairMQChannel map failed for the following key: " << channelName << "." << index << "." << member;
return 1;
}

View File

@@ -218,6 +218,7 @@ class FairMQProgOptions
}
int UpdateChannelValue(const std::string& channelName, int index, const std::string& member, const std::string& val);
int UpdateChannelValue(const std::string& channelName, int index, const std::string& member, int val);
int UpdateChannelValue(const std::string& channelName, int index, const std::string& member, bool val);
void UpdateChannelInfo();

View File

@@ -58,6 +58,9 @@ struct SUBOPT
RCVKERNELSIZE,
LINGER,
RATELOGGING, // logging rate
PORTRANGEMIN,
PORTRANGEMAX,
AUTOBIND,
NUMSOCKETS,
lastsocketkey
};
@@ -74,6 +77,9 @@ struct SUBOPT
/*[RCVKERNELSIZE] = */ "rcvKernelSize",
/*[LINGER] = */ "linger",
/*[RATELOGGING] = */ "rateLogging",
/*[PORTRANGEMIN] = */ "portRangeMin",
/*[PORTRANGEMAX] = */ "portRangeMax",
/*[AUTOBIND] = */ "autoBind",
/*[NUMSOCKETS] = */ "numSockets",
nullptr
};