66 {
67
69 const char* chost=
getenv(
"ATLAS_CONDDB");
72 const char* chost=
getenv(
"HOSTNAME");
74
77 char cstr_host[HOST_NAME_MAX];
78 if (gethostname(cstr_host, sizeof(cstr_host))==0) {
80 }
81 }
82 }
83 std::cout <<
"Using machine hostname " <<
m_hostname <<
" for DB replica resolution" << std::endl;
84
85 const char* cfrontier=
getenv(
"FRONTIER_SERVER");
86 if (cfrontier && strcmp(cfrontier,"")!=0) {
87 std::cout << "Frontier server at " << cfrontier << " will be considered"
88 << std::endl;
90 }
91
92
93 FILE* p_inp=0;
95 if (datapath!=0) p_inp =
findFile(
"dbreplica.config",datapath);
96 if (p_inp==0) {
97 std::cout << "Cannot open/locate configuration file dbreplica.config"
98 << std::endl;
99 return false;
100 }
101
102 unsigned int bufsize=999;
103 char* p_buf=new char[bufsize];
104 while (!feof(p_inp)) {
105 char* p_line=fgets(p_buf,bufsize,p_inp);
106 if (p_line!=NULL && p_line[0]!='#') {
107 std::string
buf=std::string(p_line);
108 std::string::size_type iofs1=0;
109
110 bool sequal=false;
111 std::vector<std::string> domains;
112 std::vector<std::string> servers;
113 bool atCERN = false;
114 while (iofs1<
buf.size()) {
115 std::string::size_type iofs2=
buf.find(
' ',iofs1);
116
117 if (iofs2==std::string::npos) iofs2=
buf.size()-1;
118 std::string token=
buf.substr(iofs1,iofs2-iofs1);
119
120 if (token!="" && token!=" ") {
121 if (token=="=") {
122 sequal=true;
123 } else if (!sequal) {
124
125 domains.push_back(token);
126 if(token=="cern.ch") atCERN = true;
127 } else {
128
129
130 if(atCERN && token=="ATONR_CONF") atCERN = false;
131 if (token!=
"ATLF" ||
m_frontiergen) servers.push_back(std::move(token));
132 }
133 }
134 iofs1=iofs2+1;
135 }
136
137
138 bool useit=false;
139 unsigned int bestlen=0;
140 for (std::vector<std::string>::const_iterator itr=domains.begin();
141 itr!=domains.end();++itr) {
142 std::string::size_type len=(itr->size());
143 std::string::size_type hlen=
m_hostname.size();
144 if (hlen>=len && *itr==
m_hostname.substr(hlen-len,len)) {
145 if (len>bestlen) {
146 atCERN=true;
147 useit=true;
148 bestlen=len;
149 }
150 }
151
152
154 std::cout <<
155 "No specific match for domain found - use default fallback"
156 << std::endl;
157 useit=true;
158 bestlen=0;
159 }
160 }
161 if (useit) {
162 if(atCERN) {
163 servers.push_back("ATONR_COOL");
164 servers.push_back("ATONR_CONF");
165 }
166
167
168 for (
unsigned int i=0;
i<servers.size();++
i) {
171 }
172 }
173 }
174 }
175 fclose(p_inp);
176 delete [] p_buf;
178 " servers found for host " <<
m_hostname << std::endl;
179 return true;
180}
FILE * findFile(const std::string &filename, const std::string &pathvar)
std::pair< std::string, int > ServerPair
std::string getenv(const std::string &variableName)
get an environment variable