irods  4.2.8
About: iRODS (the integrated Rule Oriented Data System) is a distributed data-management system for creating data grids, digital libraries, persistent archives, and real-time data systems.
  Fossies Dox: irods-4.2.8.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

irods_resource_manager.hpp
Go to the documentation of this file.
1 #ifndef __IRODS_RESOURCE_MANAGER_HPP__
2 #define __IRODS_RESOURCE_MANAGER_HPP__
3 
4 // =-=-=-=-=-=-=-
5 #include "rods.h"
8 
9 #include <functional>
10 
11 namespace irods {
12 
13 // =-=-=-=-=-=-=-
14 //
15  const std::string EMPTY_RESC_HOST( "EMPTY_RESC_HOST" );
16  const std::string EMPTY_RESC_PATH( "EMPTY_RESC_PATH" );
17 
18 
19 
20 // =-=-=-=-=-=-=-
22  const std::string RESOURCE_INTERFACE( "irods_resource_interface" );
23 
24 // =-=-=-=-=-=-=-
26  const std::string LOCAL_USE_ONLY_RESOURCE( "LOCAL_USE_ONLY_RESOURCE" );
27  const std::string LOCAL_USE_ONLY_RESOURCE_VAULT( "/var/lib/irods/LOCAL_USE_ONLY_RESOURCE_VAULT" );
28  const std::string LOCAL_USE_ONLY_RESOURCE_TYPE( "unixfilesystem" );
29 
31  public:
32  // =-=-=-=-=-=-=-
36 
37  // =-=-=-=-=-=-=-
38  // @brief destructor
39  virtual ~resource_manager();
40 
41  // =-=-=-=-=-=-=-
42  // @brief resolve a resource from a key into the resource table
43  error resolve( std::string, // resource key
44  resource_ptr& ); // resource out variable
45 
46  // =-=-=-=-=-=-=-
47  // @brief resolve a resource from a key into the resource table
48  error resolve( rodsLong_t, // resource id
49  resource_ptr& ); // resource out variable
50 
51  // =-=-=-=-=-=-=-
52  // @brief resolve a resource from a match with a given property
53  error validate_vault_path( std::string, // physical path of the data object
54  rodsServerHost_t*, // host for which we find the path
55  std::string& ); // match vault path
56 
57  // =-=-=-=-=-=-=-
60 
61  // =-=-=-=-=-=-=-
64 
65  // =-=-=-=-=-=-=-
67  error init_from_type( std::string, // resource type
68  std::string, // resource name ( key )
69  std::string, // instance name
70  std::string, // resource context
71  resource_ptr& ); // resource out variable
72 
73  // =-=-=-=-=-=-=-
75  error get_root_resources( std::vector< std::string >& );
76 
77  // =-=-=-=-=-=-=-
79  error get_hier_to_root_for_resc( const std::string&, std::string& );
80 
81  // =-=-=-=-=-=-=-
83  // throws irods::exception
84  typedef std::vector<rodsLong_t> leaf_bundle_t;
85  std::vector<leaf_bundle_t> gather_leaf_bundles_for_resc(const std::string& _resource_name);
86 
87  // =-=-=-=-=-=-=-
89  void print_local_resources();
90 
91  // =-=-=-=-=-=-=-
94 
95  // =-=-=-=-=-=-=-
98 
99  // =-=-=-=-=-=-=-
101  std::vector<std::string> get_all_resc_hierarchies( void );
102 
103  // =-=-=-=-=-=-=-
105  error hier_to_leaf_id( const std::string&, rodsLong_t& );
106 
107  // =-=-=-=-=-=-=-
109  error leaf_id_to_hier( const rodsLong_t&, std::string& );
110 
111  // =-=-=-=-=-=-=-
113  error resc_id_to_name( const rodsLong_t&, std::string& );
114 
115  // =-=-=-=-=-=-=-
117  error resc_id_to_name( const std::string&, std::string& );
118 
119  // =-=-=-=-=-=-=-
121  error is_coordinating_resource( const std::string&, bool& );
122 
123  // =-=-=-=-=-=-=-
125  template< typename value_type >
126  error resolve_from_property( std::string _prop, // property key
127  value_type _value, // property value
128  resource_ptr& _resc ) { // outgoing resource variable
129  // =-=-=-=-=-=-=-
130  // simple flag to state a resource matching the prop and value is found
131  bool found = false;
132 
133  // =-=-=-=-=-=-=-
134  // quick check on the resource table
135  if ( resource_name_map_.empty() ) {
136  return ERROR( SYS_INVALID_INPUT_PARAM, "empty resource table" );
137  }
138 
139  // =-=-=-=-=-=-=-
140  // iterate through the map and search for our path
142  for ( ; itr != resource_name_map_.end(); ++itr ) {
143  // =-=-=-=-=-=-=-
144  // query resource for the property value
145  value_type value = NULL;
146  error ret = itr->second->get_property< value_type >( _prop, value );
147 
148  // =-=-=-=-=-=-=-
149  // if we get a good parameter
150  if ( ret.ok() ) {
151  // =-=-=-=-=-=-=-
152  // compare incoming value and stored value, assumes that the
153  // values support the comparison operator
154  if ( _value == value ) {
155  // =-=-=-=-=-=-=-
156  // if we get a match, cache the resource pointer
157  // in the given out variable and bail
158  found = true;
159  _resc = itr->second;
160  break;
161  }
162  }
163  else {
164  std::stringstream msg;
165  msg << "resource_manager::resolve_from_property - ";
166  msg << "failed to get vault parameter from resource";
167  irods::error err = PASSMSG( msg.str(), ret );
168 
169  }
170 
171  } // for itr
172 
173  // =-=-=-=-=-=-=-
174  // did we find a resource and is the ptr valid?
175  if ( true == found && _resc.get() ) {
176  return SUCCESS();
177  }
178  else {
179  std::stringstream msg;
180  msg << "failed to find resource for property [";
181  msg << _prop;
182  msg << "] and value [";
183  msg << _value;
184  msg << "]";
185  return ERROR( SYS_RESC_DOES_NOT_EXIST, msg.str() );
186  }
187 
188  } // resolve_from_property
189 
193 
194  private:
195  // =-=-=-=-=-=-=-
198  resource_ptr&,
199  const std::string,
200  const std::string,
201  const std::string);
202 
203  // =-=-=-=-=-=-=-
206 
207  // =-=-=-=-=-=-=-
209  error init_child_map( void );
210 
211  // =-=-=-=-=-=-=-
213  // operations from the resources, in breadth first order
214  error gather_operations( void );
215 
216  // =-=-=-=-=-=-=-
218  // plugins
220 
221  // =-=-=-=-=-=-=-
223  // maintenance operations from the resources, in breadth first order
224  error gather_operations_recursive( const std::string&, // child string of parent resc
225  std::vector< std::string >&, // vector of 'done' resc names
226  std::vector<pdmo_type>& ); // vector of ops for this composition
227 
228  // =-=-=-=-=-=-=-
230  error gather_leaf_bundle_for_child( const std::string&, leaf_bundle_t& );
231 
232  // =-=-=-=-=-=-=-
234  error get_parent_name( resource_ptr, std::string& );
235 
236  // =-=-=-=-=-=-=-
237  // Attributes
240  std::vector< std::vector< pdmo_type > > maintenance_operations_;
241 
242  }; // class resource_manager
243 
244 }; // namespace irods
245 
246 
247 #endif // __IRODS_RESOURCE_MANAGER_HPP__
irods::resource_manager::get_hier_to_root_for_resc
error get_hier_to_root_for_resc(const std::string &, std::string &)
Definition: irods_resource_manager.cpp:434
rcComm_t
Definition: rcConnect.h:95
NULL
#define NULL
Definition: rodsDef.h:70
rsComm_t
Definition: rcConnect.h:145
irods::LOCAL_USE_ONLY_RESOURCE_TYPE
const std::string LOCAL_USE_ONLY_RESOURCE_TYPE("unixfilesystem")
irods::resource_manager::is_coordinating_resource
error is_coordinating_resource(const std::string &, bool &)
Definition: irods_resource_manager.cpp:1229
irods::resource_manager::end
iterator end()
Definition: irods_resource_manager.hpp:192
irods::resource_manager::init_from_type
error init_from_type(std::string, std::string, std::string, std::string, resource_ptr &)
Definition: irods_resource_manager.cpp:718
irods::lookup_table
Definition: irods_lookup_table.hpp:24
irods::EMPTY_RESC_PATH
const std::string EMPTY_RESC_PATH("EMPTY_RESC_PATH")
irods::resource_manager::init_from_catalog
error init_from_catalog(rsComm_t *)
Definition: irods_resource_manager.cpp:217
irods::resource_manager::print_local_resources
void print_local_resources()
Definition: irods_resource_manager.cpp:800
irods::EMPTY_RESC_HOST
const std::string EMPTY_RESC_HOST("EMPTY_RESC_HOST")
irods::resource_ptr
boost::shared_ptr< resource > resource_ptr
Definition: irods_resource_types.hpp:11
irods::resource_manager::iterator
lookup_table< resource_ptr >::iterator iterator
Definition: irods_resource_manager.hpp:190
irods::resource_manager::load_resource_plugin
error load_resource_plugin(resource_ptr &, const std::string, const std::string, const std::string)
Definition: irods_resource_manager.cpp:94
irods::resource_manager::call_maintenance_operations
int call_maintenance_operations(rcComm_t *)
Definition: irods_resource_manager.cpp:1016
irods::resource_manager::resource_id_map_
lookup_table< resource_ptr, long, std::hash< long > > resource_id_map_
Definition: irods_resource_manager.hpp:239
irods::lookup_table::begin
iterator begin()
Definition: irods_lookup_table.hpp:53
PASSMSG
#define PASSMSG(message_, prev_error_)
Definition: irods_error.hpp:119
irods::resource_manager::resource_manager
resource_manager()
Definition: irods_resource_manager.cpp:36
SYS_INVALID_INPUT_PARAM
@ SYS_INVALID_INPUT_PARAM
Definition: rodsErrorTable.h:195
irods::resource_manager::gather_operations
error gather_operations(void)
Definition: irods_resource_manager.cpp:818
irods::resource_manager::maintenance_operations_
std::vector< std::vector< pdmo_type > > maintenance_operations_
Definition: irods_resource_manager.hpp:240
irods::resource_manager::~resource_manager
virtual ~resource_manager()
Definition: irods_resource_manager.cpp:46
irods_resource_plugin.hpp
SUCCESS
#define SUCCESS()
Definition: irods_error.hpp:121
irods::resource_manager::get_parent_name
error get_parent_name(resource_ptr, std::string &)
Definition: irods_resource_manager.cpp:386
irods::lookup_table::empty
bool empty() const
Definition: irods_lookup_table.hpp:50
irods::resource_manager::gather_leaf_bundle_for_child
error gather_leaf_bundle_for_child(const std::string &, leaf_bundle_t &)
Definition: irods_resource_manager.cpp:472
irods
Definition: apiHandler.hpp:35
irods::resource_manager::gather_leaf_bundles_for_resc
std::vector< leaf_bundle_t > gather_leaf_bundles_for_resc(const std::string &_resource_name)
Definition: irods_resource_manager.cpp:519
irods::RESOURCE_INTERFACE
const std::string RESOURCE_INTERFACE("irods_resource_interface")
irods::resource_manager::shut_down_resources
error shut_down_resources()
Definition: irods_resource_manager.cpp:341
SYS_RESC_DOES_NOT_EXIST
@ SYS_RESC_DOES_NOT_EXIST
Definition: rodsErrorTable.h:145
irods::resource_manager::need_maintenance_operations
bool need_maintenance_operations()
Definition: irods_resource_manager.cpp:990
irods::resource_manager::validate_vault_path
error validate_vault_path(std::string, rodsServerHost_t *, std::string &)
Definition: irods_resource_manager.cpp:132
irods::resource_manager::get_all_resc_hierarchies
std::vector< std::string > get_all_resc_hierarchies(void)
Definition: irods_resource_manager.cpp:1056
irods::resource_manager::resolve
error resolve(std::string, resource_ptr &)
Definition: irods_resource_manager.cpp:51
irods::resource_manager::leaf_bundle_t
std::vector< rodsLong_t > leaf_bundle_t
Definition: irods_resource_manager.hpp:84
GenQueryOut
Definition: rodsGenQuery.h:67
irods::resource_manager::start_resource_plugins
error start_resource_plugins(void)
Definition: irods_resource_manager.cpp:967
get_irods_version.value
dictionary value
Definition: get_irods_version.py:27
irods::resource_manager::init_child_map
error init_child_map(void)
Definition: irods_resource_manager.cpp:738
irods::lookup_table::end
iterator end()
Definition: irods_lookup_table.hpp:56
ERROR
#define ERROR(code_, message_)
Definition: irods_error.hpp:117
irods::error
Definition: irods_error.hpp:23
irods_first_class_object.hpp
irods::resource_manager::leaf_id_to_hier
error leaf_id_to_hier(const rodsLong_t &, std::string &)
Definition: irods_resource_manager.cpp:1119
irods::resource_manager::begin
iterator begin()
Definition: irods_resource_manager.hpp:191
irods::resource_manager::gather_operations_recursive
error gather_operations_recursive(const std::string &, std::vector< std::string > &, std::vector< pdmo_type > &)
private - lower level recursive call to gather the post disconnect
Definition: irods_resource_manager.cpp:887
irods::resource_manager::hier_to_leaf_id
error hier_to_leaf_id(const std::string &, rodsLong_t &)
Definition: irods_resource_manager.cpp:1082
irods::resource_manager::resource_name_map_
lookup_table< resource_ptr > resource_name_map_
Definition: irods_resource_manager.hpp:238
irods::resource_manager::process_init_results
error process_init_results(genQueryOut_t *)
Definition: irods_resource_manager.cpp:542
rodsServerHost
Definition: rodsConnect.h:62
irods::resource_manager::resolve_from_property
error resolve_from_property(std::string _prop, value_type _value, resource_ptr &_resc)
Definition: irods_resource_manager.hpp:126
irods::LOCAL_USE_ONLY_RESOURCE
const std::string LOCAL_USE_ONLY_RESOURCE("LOCAL_USE_ONLY_RESOURCE")
irods::resource_manager::get_root_resources
error get_root_resources(std::vector< std::string > &)
Definition: irods_resource_manager.cpp:358
irods::resource_manager
Definition: irods_resource_manager.hpp:30
irods::LOCAL_USE_ONLY_RESOURCE_VAULT
const std::string LOCAL_USE_ONLY_RESOURCE_VAULT("/var/lib/irods/LOCAL_USE_ONLY_RESOURCE_VAULT")
irods::error::ok
bool ok()
Definition: irods_error.cpp:258
irods::leaf_bundle_t
resource_manager::leaf_bundle_t leaf_bundle_t
Definition: irods_repl_rebalance.hpp:13
irods::resource_manager::resc_id_to_name
error resc_id_to_name(const rodsLong_t &, std::string &)
Definition: irods_resource_manager.cpp:1162
rods.h
rodsLong_t
long long rodsLong_t
Definition: rodsType.h:32