This reads the DS configs from the standard location /home/deltasvr/cluster.xml, which if it exists, is presumed to be owned by root.
| Return Type | Function name | Arguments |
|---|---|---|
| hzEcode | ReadConfigDS | (void) |
Declared and defined in file: hdbADP.cpp
Function Logic:
Function body:
hzEcode ReadConfigDS (void)
{
// This reads the DS configs from the standard location /home/deltasvr/cluster.xml, which if it exists, is presumed to be owned by root.
_hzfunc(__func__) ;
FSTAT fs ; // File status
hzDocXml X ; // XML document
hzChain err ; // Error report
hzAttrset ai ; // Attribute iterator
hzXmlNode* pRoot ; // Root XML tag
hzXmlNode* pN ; // XML node/tag
hzXmlNode* pNC ; // XML node for <deltaCluster> tag
hzXmlNode* pNS ; // XML node for <point[A-D]> tags
hzString appName ; // Application name
hzIpaddr ipa ; // IP address
uint32_t nAppId ; // App id
uint32_t nPort ; // Port number
uint32_t nIndex ; // Server iterator
hzEcode rc ; // Return code
/*
** ** Read the DS config to obtain delta cluster info and to find the appID as used by the DS
** */
if (lstat(s_deltaConf, &fs) < 0)
return hzerr(E_NOTFOUND, "Delta config file %s not found\n", *s_deltaConf) ;
rc = X.Load(s_deltaConf) ;
if (rc != E_OK)
return hzerr(rc, "Config (%s): Could not load\n", *s_deltaConf) ;
pRoot = X.GetRoot() ;
if (!pRoot->NameEQ("ConfigDS"))
return hzerr(rc, "Config (%s): Expected <ConfigDS> root tag. Got <%s>\n", *s_deltaConf, pRoot->txtName()) ;
// Process <deltaCluster> tag
pNC = pRoot->GetFirstChild() ;
if (!pNC || !pNC->NameEQ("deltaCluster"))
return hzerr(rc, "Config (%s): Expected <deltaCluster> tag as 1st child of <ConfigDS>\n", *s_deltaConf) ;
// Expect <deltaCluster> subtags to describe servers
for (pNS = pNC->GetFirstChild() ; pNS ; pNS = pNS->Sibling())
{
if (pNS->NameEQ("pointA")) nIndex = 0;
else if (pNS->NameEQ("pointB")) nIndex = 1;
else if (pNS->NameEQ("pointC")) nIndex = 2;
else if (pNS->NameEQ("pointD")) nIndex = 3;
else
return hzerr(E_CONFIG, "Illegal tag <%s> in <deltaCluster>. Only <point[A-D]> allowed\n", pNS->txtName()) ;
if (s_DS_Hosts[nIndex])
return hzerr(E_DUPLICATE, "Duplicate tag <%s> in <deltaCluster>\n", pNS->txtName()) ;
for (ai = pNS ; ai.Valid() ; ai.Advance())
{
if (ai.NameEQ("host"))
s_DS_Hosts[nIndex] = ai.Value() ;
else if (ai.NameEQ("addr"))
{
if (ai.Value())
{
ipa = ai.Value() ;
if (ipa == _hzGlobal_nullIP)
return hzerr(E_CONFIG, "Line %d: Invalid IP address (%s)\n", pNS->Line(), ai.Value()) ;
s_DS_Addrs[nIndex] = ipa ;
}
}
else if (ai.NameEQ("port"))
{
if (ai.Value())
{
nPort = atoi(ai.Value()) ;
if (!nPort)
return hzerr(E_CONFIG, "Line %d: Invalid port (%s)\n", pNS->Line(), ai.Value()) ;
s_DS_Ports[nIndex] = nPort ;
}
}
else
return hzerr(E_CONFIG, "Line %d: Illegal attribute %s. Only host|addr|port allowed", pNS->Line(), ai.Name()) ;
}
// Check we have everything
if (!s_DS_Hosts[nIndex])
return hzerr(E_CONFIG, "No hostname specified for server %s", pNS->txtName()) ;
if (s_DS_Addrs[nIndex] || s_DS_Ports[nIndex])
{
// Both must be either NULL or set
if (s_DS_Addrs[nIndex] == _hzGlobal_nullIP)
return hzerr(E_CONFIG, "Line %d: Invalid IP address (port is %u)\n", pNS->Line(), s_DS_Ports[nIndex]) ;
if (!s_DS_Ports[nIndex])
return hzerr(E_CONFIG, "Line %d: IP address supplied but no port\n", pNS->Line()) ;
// Get port for notifications
if (ipa == _hzGlobal_livehost)
s_deltaPort = nPort ;
}
}
// Process <deltaCluster> siblings. Expect <dsApp> and <dsRealm> tags. Only process <dsApp>
for (pN = pNC->Sibling() ; rc == E_OK && pN ; pN = pN->Sibling())
{
// Only interested in <deltaCluster> here
if (!pN->NameEQ("dsRealm"))
continue ;
if (!pN->NameEQ("dsApp"))
{ rc = E_CONFIG ; err.Printf("Illegal tag <%s> in <ConfigDS>. Only <dsRealm> and <dsApp> allowed\n", pN->txtName()) ; }
// Process DS attributes
for (ai = pN ; ai.Valid() ; ai.Advance())
{
if (ai.NameEQ("appname"))
appName = ai.Value() ;
else if (ai.NameEQ("appid"))
{
if (ai.Value())
{
nAppId = atoi(ai.Value()) ;
if (!nAppId)
{ rc = E_CONFIG ; err.Printf("Line %d: Invalid app id (%s)\n", pNS->Line(), ai.Value()) ; }
}
}
else
{ rc = E_CONFIG ; err.Printf("Line %d: Illegal <dsApp> attribute %s. Only host|addr|port allowed", pN->Line(), ai.Name()) ; }
}
if (!appName) { rc = E_CONFIG ; err.Printf("Line %d: <dsApp> tag does not specify an appName\n", pN->Line()) ; }
if (!nAppId) { rc = E_CONFIG ; err.Printf("Line %d: <dsApp> tag does not specify an app ID\n", pN->Line()) ; }
if (rc == E_OK)
{
if (s_mapDS_AppsByName.Exists(appName)) { rc = E_DUPLICATE ; err.Printf("Line %d: App (%s) already exists\n", pN->Line(), *appName) ; }
if (s_mapDS_AppsByID.Exists(nAppId)) { rc = E_DUPLICATE ; err.Printf("Line %d: App ID (%u) already exists\n", pN->Line(), nAppId) ; }
}
}
if (err.Size())
threadLog(err) ;
return rc ;
}