1 #include "otsdaq/CoreSupervisors/CorePropertySupervisorBase.h"
8 CorePropertySupervisorBase::CorePropertySupervisorBase(xdaq::Application* application)
9 : theConfigurationManager_(0)
10 , supervisorClass_(application->getApplicationDescriptor()->getClassName())
11 , supervisorClassNoNamespace_(
12 supervisorClass_.substr(supervisorClass_.find_last_of(
":") + 1, supervisorClass_.length() - supervisorClass_.find_last_of(
":")))
13 , supervisorContextUID_(
"UNINITIALIZED_supervisorContextUID")
17 , supervisorApplicationUID_(
"UNINITIALIZED_supervisorApplicationUID")
20 , supervisorConfigurationPath_(
"UNINITIALIZED_supervisorConfigurationPath")
23 , propertiesAreSetup_(false)
27 __SUP_COUTV__(application->getApplicationContext()->getContextDescriptor()->getURL());
28 __SUP_COUTV__(application->getApplicationDescriptor()->getLocalId());
29 __SUP_COUTV__(supervisorClass_);
30 __SUP_COUTV__(supervisorClassNoNamespace_);
33 allSupervisorInfo_.init(application->getApplicationContext());
35 if(allSupervisorInfo_.isMacroMakerMode())
38 __SUP_COUT__ <<
"Macro Maker mode detected. So skipping configuration location work for "
39 "supervisor of class '"
40 << supervisorClass_ <<
"'" << __E__;
42 supervisorContextUID_ =
"MacroMakerFEContext";
43 supervisorApplicationUID_ =
"MacroMakerFESupervisor";
44 supervisorConfigurationPath_ = CorePropertySupervisorBase::supervisorContextUID_ +
"/LinkToApplicationTable/" +
45 CorePropertySupervisorBase::supervisorApplicationUID_ +
"/LinkToSupervisorTable";
47 __SUP_COUTV__(CorePropertySupervisorBase::supervisorContextUID_);
48 __SUP_COUTV__(CorePropertySupervisorBase::supervisorApplicationUID_);
49 __SUP_COUTV__(CorePropertySupervisorBase::supervisorConfigurationPath_);
51 CorePropertySupervisorBase::indicateOtsAlive(0);
55 else if(allSupervisorInfo_.isWizardMode())
57 __SUP_COUT__ <<
"Wiz mode detected. So skipping configuration location work for "
58 "supervisor of class '"
59 << supervisorClass_ <<
"'" << __E__;
60 supervisorContextUID_ =
"NO CONTEXT ID IN WIZ MODE";
61 supervisorApplicationUID_ = std::to_string(application->getApplicationDescriptor()->getLocalId());
62 supervisorConfigurationPath_ =
"NO APP PATH IN WIZ MODE";
64 __SUP_COUTV__(CorePropertySupervisorBase::supervisorContextUID_);
65 __SUP_COUTV__(CorePropertySupervisorBase::supervisorApplicationUID_);
66 __SUP_COUTV__(CorePropertySupervisorBase::supervisorConfigurationPath_);
71 __SUP_COUT__ <<
"Getting configuration specific info for supervisor '" << (allSupervisorInfo_.getSupervisorInfo(application).getName()) <<
"' of class "
72 << supervisorClass_ <<
"." << __E__;
79 CorePropertySupervisorBase::supervisorContextUID_ =
80 theConfigurationManager_->__GET_CONFIG__(
XDAQContextTable)->getContextUID(application->getApplicationContext()->getContextDescriptor()->getURL());
84 __SUP_COUT_ERR__ <<
"XDAQ Supervisor could not access it's configuration through "
85 "the Configuration Manager."
86 <<
". The getApplicationContext()->getContextDescriptor()->getURL() = "
87 << application->getApplicationContext()->getContextDescriptor()->getURL() << __E__;
93 CorePropertySupervisorBase::supervisorApplicationUID_ = theConfigurationManager_->__GET_CONFIG__(
XDAQContextTable)
94 ->getApplicationUID(application->getApplicationContext()->getContextDescriptor()->getURL(),
95 application->getApplicationDescriptor()->getLocalId());
99 __SUP_COUT_ERR__ <<
"XDAQ Supervisor could not access it's configuration through "
100 "the Configuration Manager."
101 <<
" The supervisorContextUID_ = " << supervisorContextUID_ <<
". The supervisorApplicationUID = " << supervisorApplicationUID_
106 CorePropertySupervisorBase::supervisorConfigurationPath_ =
"/" + CorePropertySupervisorBase::supervisorContextUID_ +
"/LinkToApplicationTable/" +
107 CorePropertySupervisorBase::supervisorApplicationUID_ +
"/LinkToSupervisorTable";
109 __SUP_COUTV__(CorePropertySupervisorBase::supervisorContextUID_);
110 __SUP_COUTV__(CorePropertySupervisorBase::supervisorApplicationUID_);
111 __SUP_COUTV__(CorePropertySupervisorBase::supervisorConfigurationPath_);
113 CorePropertySupervisorBase::indicateOtsAlive(
this);
115 theConfigurationManager_->setOwnerContext(CorePropertySupervisorBase::supervisorContextUID_);
116 theConfigurationManager_->setOwnerApp(CorePropertySupervisorBase::supervisorApplicationUID_);
121 CorePropertySupervisorBase::~CorePropertySupervisorBase(
void)
123 if(theConfigurationManager_)
124 delete theConfigurationManager_;
130 char portStr[100] =
"0";
131 std::string hostname =
"wiz";
138 unsigned int port = properties->getContextTreeNode().getNode(properties->supervisorContextUID_).getNode(
"Port").getValue<
unsigned int>();
139 sprintf(portStr,
"%u", port);
141 hostname = properties->getContextTreeNode().getNode(properties->supervisorContextUID_).getNode(
"Address").getValue<std::string>();
143 size_t i = hostname.find(
"//");
144 if(i != std::string::npos)
145 hostname = hostname.substr(i + 2);
151 std::string filename = std::string(__ENV__(
"OTSDAQ_LOG_DIR")) +
"/otsdaq_is_alive-" + hostname +
"-" + portStr +
".dat";
152 FILE* fp = fopen(filename.c_str(),
"w");
155 __SS__ <<
"Failed to open the ots-is-alive file: " << filename << __E__;
158 fprintf(fp,
"%s %s %ld\n", hostname.c_str(), portStr, time(0));
161 __COUT__ <<
"Marked alive: " << filename << __E__;
166 XDAQ_CONST_CALL xdaq::ApplicationDescriptor* CorePropertySupervisorBase::getGatewaySupervisorDescriptor(
void)
168 return allSupervisorInfo_.isWizardMode() ? allSupervisorInfo_.getWizardDescriptor()
169 : allSupervisorInfo_.getGatewayDescriptor();
176 void CorePropertySupervisorBase::setSupervisorPropertyDefaults(
void)
186 CorePropertySupervisorBase::setSupervisorProperty(CorePropertySupervisorBase::SUPERVISOR_PROPERTIES.UserPermissionsThreshold,
"*=1");
187 CorePropertySupervisorBase::setSupervisorProperty(CorePropertySupervisorBase::SUPERVISOR_PROPERTIES.UserGroupsAllowed,
"");
188 CorePropertySupervisorBase::setSupervisorProperty(CorePropertySupervisorBase::SUPERVISOR_PROPERTIES.UserGroupsDisallowed,
"");
190 CorePropertySupervisorBase::setSupervisorProperty(CorePropertySupervisorBase::SUPERVISOR_PROPERTIES.CheckUserLockRequestTypes,
"");
191 CorePropertySupervisorBase::setSupervisorProperty(CorePropertySupervisorBase::SUPERVISOR_PROPERTIES.RequireUserLockRequestTypes,
"");
192 CorePropertySupervisorBase::setSupervisorProperty(CorePropertySupervisorBase::SUPERVISOR_PROPERTIES.AutomatedRequestTypes,
"");
193 CorePropertySupervisorBase::setSupervisorProperty(CorePropertySupervisorBase::SUPERVISOR_PROPERTIES.AllowNoLoginRequestTypes,
"");
194 CorePropertySupervisorBase::setSupervisorProperty(CorePropertySupervisorBase::SUPERVISOR_PROPERTIES.RequireSecurityRequestTypes,
"");
196 CorePropertySupervisorBase::setSupervisorProperty(CorePropertySupervisorBase::SUPERVISOR_PROPERTIES.NoXmlWhiteSpaceRequestTypes,
"");
197 CorePropertySupervisorBase::setSupervisorProperty(CorePropertySupervisorBase::SUPERVISOR_PROPERTIES.NonXMLRequestTypes,
"");
217 void CorePropertySupervisorBase::extractPermissionsMapFromString(
const std::string& permissionsString,
218 std::map<std::string, WebUsers::permissionLevel_t>& permissionsMap)
220 permissionsMap.clear();
221 StringMacros::getMapFromString(permissionsString, permissionsMap);
242 bool CorePropertySupervisorBase::doPermissionsGrantAccess(std::map<std::string, WebUsers::permissionLevel_t>& permissionLevelsMap,
243 std::map<std::string, WebUsers::permissionLevel_t>& permissionThresholdsMap)
252 for(
const auto& permissionLevelGroupPair : permissionLevelsMap)
257 for(
const auto& permissionThresholdGroupPair : permissionThresholdsMap)
261 if(permissionLevelGroupPair.first == permissionThresholdGroupPair.first && permissionThresholdGroupPair.second &&
262 permissionLevelGroupPair.second >= permissionThresholdGroupPair.second)
274 void CorePropertySupervisorBase::checkSupervisorPropertySetup()
276 if(propertiesAreSetup_)
282 propertiesAreSetup_ =
true;
284 CorePropertySupervisorBase::setSupervisorPropertyDefaults();
289 setSupervisorPropertyDefaults();
294 if(allSupervisorInfo_.isWizardMode())
295 __SUP_COUT__ <<
"Wiz mode detected. Skipping setup of supervisor properties for "
296 "supervisor of class '"
297 << supervisorClass_ <<
"'" << __E__;
298 else if(allSupervisorInfo_.isMacroMakerMode())
299 __SUP_COUT__ <<
"Maker Maker mode detected. Skipping setup of supervisor properties for "
300 "supervisor of class '"
301 << supervisorClass_ <<
"'" << __E__;
303 CorePropertySupervisorBase::loadUserSupervisorProperties();
309 forceSupervisorPropertyValues();
314 CorePropertySupervisorBase::extractPermissionsMapFromString(
315 getSupervisorProperty(CorePropertySupervisorBase::SUPERVISOR_PROPERTIES.UserPermissionsThreshold), propertyStruct_.UserPermissionsThreshold);
317 propertyStruct_.UserGroupsAllowed.clear();
318 StringMacros::getMapFromString(getSupervisorProperty(CorePropertySupervisorBase::SUPERVISOR_PROPERTIES.UserGroupsAllowed),
319 propertyStruct_.UserGroupsAllowed);
321 propertyStruct_.UserGroupsDisallowed.clear();
322 StringMacros::getMapFromString(getSupervisorProperty(CorePropertySupervisorBase::SUPERVISOR_PROPERTIES.UserGroupsDisallowed),
323 propertyStruct_.UserGroupsDisallowed);
325 auto nameIt = SUPERVISOR_PROPERTIES.allSetNames_.begin();
326 auto setIt = propertyStruct_.allSets_.begin();
327 while(nameIt != SUPERVISOR_PROPERTIES.allSetNames_.end() && setIt != propertyStruct_.allSets_.end())
330 StringMacros::getSetFromString(getSupervisorProperty(*(*nameIt)), *(*setIt));
336 __SUP_COUT__ <<
"Final supervisor property settings:" << __E__;
337 for(
auto& property : propertyMap_)
338 __SUP_COUT__ <<
"\t" <<
property.first <<
" = " <<
property.second << __E__;
346 if(supervisorContextUID_ ==
"" || supervisorApplicationUID_ ==
"")
348 __SUP_SS__ <<
"Empty supervisorContextUID_ or supervisorApplicationUID_." << __E__;
351 return theConfigurationManager_->getSupervisorNode(supervisorContextUID_, supervisorApplicationUID_);
355 __SUP_COUT_ERR__ <<
"XDAQ Supervisor could not access it's configuration node through "
356 "theConfigurationManager_ "
357 <<
"(Did you remember to initialize using CorePropertySupervisorBase::init()?)."
358 <<
" The supervisorContextUID_ = " << supervisorContextUID_ <<
". The supervisorApplicationUID = " << supervisorApplicationUID_ << __E__;
365 void CorePropertySupervisorBase::loadUserSupervisorProperties(
void)
372 auto supervisorNode = CorePropertySupervisorBase::getSupervisorTreeNode();
376 auto children = supervisorNode.getNode(
"LinkToPropertyTable").getChildren();
378 for(
auto& child : children)
380 if(child.second.getNode(
"Status").getValue<
bool>() ==
false)
383 auto propertyName = child.second.getNode(
"PropertyName").getValue();
384 setSupervisorProperty(propertyName, child.second.getNode(
"PropertyValue").getValue<std::string>());
389 __SUP_COUT__ <<
"No user supervisor property settings found in the configuration "
390 "tree, going with the defaults."
400 void CorePropertySupervisorBase::setSupervisorProperty(
const std::string& propertyName,
const std::string& propertyValue)
402 propertyMap_[propertyName] = propertyValue;
408 void CorePropertySupervisorBase::addSupervisorProperty(
const std::string& propertyName,
const std::string& propertyValue)
410 propertyMap_[propertyName] = propertyValue +
" | " + getSupervisorProperty(propertyName);
418 std::string CorePropertySupervisorBase::getSupervisorProperty(
const std::string& propertyName)
421 checkSupervisorPropertySetup();
423 auto it = propertyMap_.find(propertyName);
424 if(it == propertyMap_.end())
426 __SUP_SS__ <<
"Could not find property named " << propertyName << __E__;
429 return StringMacros::validateValueForDefaultStringDataType(it->second);
432 std::string CorePropertySupervisorBase::getSupervisorProperty(
const std::string& propertyName,
const std::string& defaultValue)
435 checkSupervisorPropertySetup();
437 auto it = propertyMap_.find(propertyName);
438 if(it == propertyMap_.end())
443 return StringMacros::validateValueForDefaultStringDataType(it->second);
449 WebUsers::permissionLevel_t CorePropertySupervisorBase::getSupervisorPropertyUserPermissionsThreshold(
const std::string& requestType)
452 checkSupervisorPropertySetup();
454 return StringMacros::getWildCardMatchFromMap(requestType, propertyStruct_.UserPermissionsThreshold);
471 checkSupervisorPropertySetup();
476 userInfo.automatedCommand_ = StringMacros::inWildCardSet(userInfo.requestType_,
477 propertyStruct_.AutomatedRequestTypes);
480 userInfo.NonXMLRequestType_ = StringMacros::inWildCardSet(userInfo.requestType_, propertyStruct_.NonXMLRequestTypes);
484 userInfo.NoXmlWhiteSpace_ = StringMacros::inWildCardSet(userInfo.requestType_, propertyStruct_.NoXmlWhiteSpaceRequestTypes);
489 userInfo.checkLock_ = StringMacros::inWildCardSet(userInfo.requestType_, propertyStruct_.CheckUserLockRequestTypes);
490 userInfo.requireLock_ = StringMacros::inWildCardSet(userInfo.requestType_, propertyStruct_.RequireUserLockRequestTypes);
491 userInfo.allowNoUser_ = StringMacros::inWildCardSet(userInfo.requestType_, propertyStruct_.AllowNoLoginRequestTypes);
492 userInfo.requireSecurity_ = StringMacros::inWildCardSet(userInfo.requestType_, propertyStruct_.RequireSecurityRequestTypes);
494 userInfo.permissionsThreshold_ = -1;
497 userInfo.permissionsThreshold_ = CorePropertySupervisorBase::getSupervisorPropertyUserPermissionsThreshold(userInfo.requestType_);
499 catch(std::runtime_error& e)
501 if(!userInfo.automatedCommand_)
502 __SUP_COUT__ <<
"No explicit permissions threshold for request '" << userInfo.requestType_
503 <<
"'... Defaulting to max threshold = " << (
unsigned int)userInfo.permissionsThreshold_ << __E__;
514 StringMacros::getSetFromString(StringMacros::getWildCardMatchFromMap(userInfo.requestType_, propertyStruct_.UserGroupsAllowed),
515 userInfo.groupsAllowed_);
517 catch(std::runtime_error& e)
519 userInfo.groupsAllowed_.clear();
528 StringMacros::getSetFromString(StringMacros::getWildCardMatchFromMap(userInfo.requestType_, propertyStruct_.UserGroupsDisallowed),
529 userInfo.groupsDisallowed_);
531 catch(std::runtime_error& e)
533 userInfo.groupsDisallowed_.clear();