35 #include <sys/types.h>
47 using std::ostringstream ;
64 map<string, BESCatalogUtils *> BESCatalogUtils::_instances ;
67 BESCatalogUtils(
const string &n )
68 : _name( n ), _follow_syms( false )
70 string key =
"BES.Catalog." + n +
".RootDirectory" ;
73 if( !found || _root_dir ==
"" )
75 string s = key +
" not defined in BES configuration file" ;
78 DIR *dip = opendir( _root_dir.c_str() ) ;
81 string serr =
"BESCatalogDirectory - root directory "
82 + _root_dir +
" does not exist" ;
88 key = (string)
"BES.Catalog." + n +
".Exclude" ;
91 vector<string>::iterator ei = vals.begin() ;
92 vector<string>::iterator ee = vals.end() ;
93 for( ; ei != ee; ei++ )
95 string e_str = (*ei) ;
96 if( !e_str.empty() && e_str !=
";" )
100 key = (string)
"BES.Catalog." + n +
".Include" ;
103 vector<string>::iterator ii = vals.begin() ;
104 vector<string>::iterator ie = vals.end() ;
105 for( ; ii != ie; ii++ )
107 string i_str = (*ii) ;
108 if( !i_str.empty() && i_str !=
";" )
112 key =
"BES.Catalog." + n +
".TypeMatch" ;
113 list<string> match_list ;
116 if( !found || vals.size() == 0 )
118 string s = key +
" not defined in key file" ;
121 vector<string>::iterator vi = vals.begin() ;
122 vector<string>::iterator ve = vals.end() ;
123 for( ; vi != ve; vi++ )
128 list<string>::iterator mli = match_list.begin() ;
129 list<string>::iterator mle = match_list.end() ;
130 for( ; mli != mle; mli++ )
132 if( !((*mli).empty()) && *(mli) !=
";" )
134 list<string> amatch ;
136 if( amatch.size() != 2 )
138 string s = (string)
"Catalog type match malformed, "
139 +
"looking for type:regexp;[type:regexp;]" ;
142 list<string>::iterator ami = amatch.begin() ;
144 newval.
type = (*ami) ;
146 newval.
reg = (*ami) ;
147 _match_list.push_back( newval ) ;
151 key = (string)
"BES.Catalog." + n +
".FollowSymLinks" ;
155 if( s_str ==
"yes" || s_str ==
"on" || s_str ==
"true" )
157 _follow_syms = true ;
172 BESCatalogUtils::_instances[_name] = 0 ;
180 bool toInclude = false ;
185 if( _include.size() == 0 )
191 list<string>::const_iterator i_iter = _include.begin() ;
192 list<string>::const_iterator i_end = _include.end() ;
193 for( ; i_iter != i_end; i_iter++ )
195 string reg = *i_iter ;
203 if( reg_expr.match( inQuestion.c_str(),
204 inQuestion.length() ) ==
205 static_cast<int>(inQuestion.length()) )
212 string serr = (string)
"Unable to get catalog information, "
213 +
"malformed Catalog Include parameter "
214 +
"in bes configuration file around "
222 if( toInclude ==
true )
236 list<string>::const_iterator e_iter = _exclude.begin() ;
237 list<string>::const_iterator e_end = _exclude.end() ;
238 for( ; e_iter != e_end; e_iter++ )
240 string reg = *e_iter ;
246 if( reg_expr.match( inQuestion.c_str(), inQuestion.length() ) ==
247 static_cast<int>(inQuestion.length()) )
254 string serr = (string)
"Unable to get catalog information, "
255 +
"malformed Catalog Exclude parameter "
256 +
"in bes configuration file around "
268 return _match_list.begin() ;
274 return _match_list.end() ;
279 const string &use_node,
const string &coi,
283 unsigned int cnt = 0 ;
285 int statret = stat( fullnode.c_str(), &cbuf ) ;
286 int my_errno = errno ;
293 while( ( dit = readdir( dip ) ) != NULL )
295 string dirEntry = dit->d_name ;
296 if( dirEntry !=
"." && dirEntry !=
".." )
298 string fullPath = fullnode +
"/" + dirEntry ;
305 bool continue_checking = true ;
309 int lstatret = lstat( fullPath.c_str(), &lbuf ) ;
311 (void)lstat( fullPath.c_str(), &lbuf ) ;
312 if( S_ISLNK( lbuf.st_mode ) )
314 continue_checking = false ;
318 if( continue_checking )
324 statret = stat( fullPath.c_str(), &buf ) ;
325 if ( statret == 0 && S_ISDIR( buf.st_mode ) )
327 if(
exclude( dirEntry ) == false )
333 bes_get_stat_info( curr_entry, buf ) ;
346 else if ( statret == 0 && S_ISREG( buf.st_mode ) )
348 if( !dirs_only &&
include( dirEntry ) )
353 bes_get_stat_info( curr_entry, buf ) ;
355 list<string> services ;
356 isData( fullPath, _name, services ) ;
359 bes_get_stat_info( curr_entry, buf ) ;
371 if( my_errno == ENOENT )
373 string error =
"Node " + use_node +
" does not exist" ;
374 char *s_err = strerror( my_errno ) ;
384 string error =
"Access denied for node " + use_node ;
385 char *s_err = strerror( my_errno ) ;
388 error = error + s_err ;
402 map<string,string> props ;
414 props[
"name"] = name ;
421 props[
"node"] =
"true" ;
424 props[
"count"] = strm.str() ;
428 props[
"node"] =
"false" ;
433 if( services.size() )
435 list<string>::const_iterator si = services.begin() ;
436 list<string>::const_iterator se = services.end() ;
437 for( ; si != se; si++ )
439 info->
add_tag(
"serviceRef", (*si) ) ;
446 const string &fullnode )
449 int statret = stat( fullnode.c_str(), &cbuf ) ;
452 bes_get_stat_info( entry, cbuf ) ;
460 off_t sz = buf.st_size ;
465 time_t mod = buf.st_mtime ;
466 struct tm *stm = gmtime( &mod ) ;
468 strftime( mdate, 64,
"%Y-%m-%d", stm ) ;
470 strftime( mtime, 64,
"%T", stm ) ;
483 const string &catalog,
484 list<string> &services )
491 return store->
isData( inQuestion, services ) ;
498 << (
void *)
this <<
")" << endl ;
503 if( _include.size() )
507 list<string>::const_iterator i_iter = _include.begin() ;
508 list<string>::const_iterator i_end = _include.end() ;
509 for( ; i_iter != i_end; i_iter++ )
511 if( !(*i_iter).empty() )
523 if( _exclude.size() )
527 list<string>::const_iterator e_iter = _exclude.begin() ;
528 list<string>::const_iterator e_end = _exclude.end() ;
529 for( ; e_iter != e_end; e_iter++ )
531 if( !(*e_iter).empty() )
543 if( _match_list.size() )
549 for( ; i != ie; i++ )
553 << match.
reg << endl ;
581 BESCatalogUtils::_instances[cat_name] = utils ;
virtual list< string > get_service_list()
error thrown if the resource requested cannot be found
provides persistent storage for data storage information represented by a container.
BESCatalogUtils::match_citer match_list_begin() const
virtual ~BESCatalogUtils()
BESCatalogUtils::match_citer match_list_end() const
virtual string get_catalog()
exception thrown if inernal error encountered
virtual unsigned int get_count()
virtual BESContainerStorage * find_persistence(const string &persist_name)
find the persistence store with the given name
static string lowercase(const string &s)
Convert a string to all lower case.
virtual void add_tag(const string &tag_name, const string &tag_data, map< string, string > *attrs=0)=0
a C++ interface to POSIX regular expression functions.
virtual void set_mod_date(const string &mod_date)
error thrown if there is a user syntax error in the request or any other user error ...
virtual void set_service_list(list< string > &slist)
vector< type_reg >::const_iterator match_citer
virtual void set_mod_time(const string &mod_time)
virtual string get_message()
get the error message for this exception
virtual bool isData(const string &inQuestion, list< string > &provides)=0
determine if the given container is data and what servies are available for it
virtual void add_entry(BESCatalogEntry *entry)
informational response object
Abstract exception class for the BES with basic string message.
static void bes_add_stat_info(BESCatalogEntry *entry, const string &fullnode)
virtual string default_catalog()
virtual string get_name()
virtual void begin_tag(const string &tag_name, map< string, string > *attrs=0)
static ostream & LMarg(ostream &strm)
bool follow_sym_links() const
static void explode(char delim, const string &str, list< string > &values)
explode a string into an array given a delimiter
virtual void dump(ostream &strm) const
dump the contents of this object to the specified ostream
static bool isData(const string &inQuestion, const string &catalog, list< string > &services)
virtual string get_mod_time()
static void display_entry(BESCatalogEntry *entry, BESInfo *info)
void get_value(const string &s, string &val, bool &found)
Retrieve the value of a given key, if set.
static BESContainerStorageList * TheList()
virtual void set_size(off_t size)
virtual bool include(const string &inQuestion) const
void get_values(const string &s, vector< string > &vals, bool &found)
Retrieve the values of a given key, if set.
virtual string get_size()
virtual bool exclude(const string &inQuestion) const
static BESCatalogUtils * Utils(const string &name)
virtual unsigned int get_entries(DIR *dip, const string &fullnode, const string &use_node, const string &coi, BESCatalogEntry *entry, bool dirs_only)
virtual bool is_collection()
static BESCatalogList * TheCatalogList()
returns the singleton BESCatalogList instance
static BESKeys * TheKeys()
virtual string get_mod_date()