32 #include <boost/lexical_cast.hpp>
33 #include <boost/function.hpp>
34 #include <boost/any.hpp>
57 template<
typename DEST_TYPE >
64 return PASSMSG(
"resource context is invalid", ret );
75 template<
typename DEST_TYPE >
81 irods::error ret = compound_check_param< DEST_TYPE >( _ctx );
83 return PASSMSG(
"invalid resource context", ret );
96 boost::shared_ptr< DEST_TYPE > dst_obj = boost::dynamic_pointer_cast< DEST_TYPE >( _ctx.
fco() );
97 parser.set_string( dst_obj->resc_hier() );
112 std::pair< std::string, irods::resource_ptr > resc_pair;
113 ret = cmap_ref->
get( child, resc_pair );
118 _resc = resc_pair.second;
124 std::stringstream msg;
125 msg <<
"child not found [" << child <<
"]";
139 irods::error ret = compound_check_param< irods::file_object >( _ctx );
141 return PASSMSG(
"invalid resource context", ret );
146 std::string resc_name;
159 std::pair< std::string, irods::resource_ptr > resc_pair;
160 ret = cmap_ref->
get( resc_name, resc_pair );
162 std::stringstream msg;
163 msg <<
"failed to get child resource [" << resc_name <<
"]";
164 return PASSMSG( msg.str(), ret );
169 _resc = resc_pair.second;
182 irods::error ret = compound_check_param< irods::file_object >( _ctx );
184 return PASSMSG(
"invalid resource context", ret );
189 std::string resc_name;
201 std::pair< std::string, irods::resource_ptr > resc_pair;
202 ret = cmap_ref->
get( resc_name, resc_pair );
204 std::stringstream msg;
205 msg <<
"failed to get child resource [" << resc_name <<
"]";
206 return PASSMSG( msg.str(), ret );
211 _resc = resc_pair.second;
218 template<
typename DEST_TYPE >
228 if ( !( ret =
get_cache( _ctx, _resc ) ).ok() ) {
229 std::stringstream msg;
230 msg <<
"Failed to get cache resource.";
231 result =
PASSMSG( msg.str(), ret );
235 else if ( !( ret = get_next_child< DEST_TYPE >( _ctx, next_resc ) ).ok() ) {
236 std::stringstream msg;
237 msg <<
"Failed to get next child resource.";
238 result =
PASSMSG( msg.str(), ret );
242 else if ( _resc != next_resc ) {
243 boost::shared_ptr< DEST_TYPE > obj = boost::dynamic_pointer_cast< DEST_TYPE >( _ctx.
fco() );
244 std::stringstream msg;
245 msg <<
"Cannot open data object: \"";
246 msg << obj->physical_path();
247 msg <<
"\" It is stored in an archive resource which is not directly accessible.";
259 const std::string& _results,
260 std::string& _policy ) {
267 if ( !kvp_err.
ok() ) {
268 return PASS( kvp_err );
272 if (
value.empty() ) {
275 "stage policy value not found" );
297 if ( cmap_ref->
size() == 0 || cmap_ref->
size() > 2 ) {
298 std::stringstream msg;
299 msg <<
"compound resource: invalid number of children [";
300 msg << cmap_ref->
size() <<
"]";
306 std::string first_child_name;
308 if ( itr == cmap_ref->
end() ) {
309 return ERROR( -1,
"child map is empty" );
312 std::string first_child_ctx = itr->second.first;
315 if ( !get_err.
ok() ) {
316 return PASS( get_err );
321 std::string second_child_name;
323 if ( itr == cmap_ref->
end() ) {
327 std::string second_child_ctx = itr->second.first;
329 get_err = second_child_resc->get_property<std::string>(
irods::RESOURCE_NAME, second_child_name );
330 if ( !get_err.
ok() ) {
331 return PASS( get_err );
370 if ( first_child_ctx == second_child_ctx ) {
371 std::stringstream msg;
372 msg <<
"matching child context strings :: ";
373 msg <<
"[" << first_child_ctx <<
"] vs ";
374 msg <<
"[" << second_child_ctx <<
"]";
389 const char* _stage_sync_kw ) {
403 parser.set_string( obj->resc_hier() );
405 std::string resource;
406 parser.first_resc( resource );
409 std::string parent_id_str;
411 if ( ( result =
ASSERT_PASS( ret,
"Failed to get the parent name." ) ).ok() ) {
413 std::string parent_name;
423 std::string cache_name;
425 if ( ( result =
ASSERT_PASS( ret,
"Failed to get the cache name." ) ).ok() ) {
429 std::string arch_name;
431 if ( ( result =
ASSERT_PASS( ret,
"Failed to get the archive name." ) ).ok() ) {
435 std::string keyword = _stage_sync_kw;
436 std::string inp_hier = obj->resc_hier();
438 std::string tgt_name, src_name;
440 tgt_name = cache_name;
441 src_name = arch_name;
444 tgt_name = arch_name;
445 src_name = cache_name;
448 std::stringstream msg;
449 msg <<
"stage_sync_kw value is unexpected [" << _stage_sync_kw <<
"]";
453 std::string current_name;
455 if ( ( result =
ASSERT_PASS( ret,
"Failed to get the resource name." ) ).ok() ) {
456 size_t pos = inp_hier.find( parent_name );
457 if ( std::string::npos == pos ) {
458 std::stringstream msg;
459 msg <<
"parent resc ["
461 <<
"] not in fco resc hier ["
471 std::string dst_hier = inp_hier.substr( 0, pos + parent_name.size() );
472 if ( !dst_hier.empty() ) {
475 dst_hier += current_name +
479 std::string src_hier = inp_hier.substr( 0, pos + parent_name.size() );
480 if ( !src_hier.empty() ) {
483 src_hier += current_name +
489 parser.set_string( src_hier );
490 std::string sub_hier;
491 parser.str( sub_hier, current_name );
497 bzero( &data_obj_inp,
sizeof( data_obj_inp ) );
521 std::stringstream msg;
522 msg <<
"Failed to replicate the data object [" << obj->logical_path() <<
"] ";
523 msg <<
"for operation [" << _stage_sync_kw <<
"]";
547 irods::error ret = compound_check_param< irods::file_object >( _ctx );
549 return PASSMSG(
"invalid resource context", ret );
555 ret = get_next_child< irods::file_object >( _ctx, resc );
572 irods::error ret = compound_check_param< irods::file_object >( _ctx );
574 return PASSMSG(
"invalid resource context", ret );
580 if ( !( ret = get_cache_resc< irods::file_object >( _ctx, cache_resc ) ).ok() ) {
581 std::stringstream msg;
582 msg <<
"Failed to get cache resource.";
583 return PASSMSG( msg.str(), ret );
600 irods::error ret = compound_check_param< irods::file_object >( _ctx );
602 return PASSMSG(
"invalid resource context", ret );
610 return PASSMSG(
"Unable to get cache resource.", ret );
627 irods::error ret = compound_check_param< irods::file_object >( _ctx );
629 return PASSMSG(
"invalid resource context", ret );
652 irods::error ret = compound_check_param< irods::file_object >( _ctx );
654 return PASSMSG(
"invalid resource context", ret );
683 irods::error ret = compound_check_param< irods::data_object >( _ctx );
685 return PASSMSG(
"invalid resource context", ret );
691 ret = get_next_child< irods::data_object >( _ctx, resc );
706 struct stat* _statbuf ) {
709 irods::error ret = compound_check_param< irods::data_object >( _ctx );
711 return PASSMSG(
"invalid resource context", ret );
717 ret = get_next_child< irods::data_object >( _ctx, resc );
736 irods::error ret = compound_check_param< irods::file_object >( _ctx );
738 return PASSMSG(
"invalid resource context", ret );
744 ret = get_next_child< irods::file_object >( _ctx, resc );
761 irods::error ret = compound_check_param< irods::collection_object >( _ctx );
763 return PASSMSG(
"invalid resource context", ret );
769 ret = get_next_child< irods::collection_object >( _ctx, resc );
786 irods::error ret = compound_check_param< irods::collection_object >( _ctx );
788 return PASSMSG(
"invalid resource context", ret );
794 ret = get_next_child< irods::collection_object >( _ctx, resc );
811 irods::error ret = compound_check_param< irods::collection_object >( _ctx );
813 return PASSMSG(
"invalid resource context", ret );
819 ret = get_next_child< irods::collection_object >( _ctx, resc );
836 irods::error ret = compound_check_param< irods::collection_object >( _ctx );
838 return PASSMSG(
"invalid resource context", ret );
844 ret = get_next_child< irods::collection_object >( _ctx, resc );
862 irods::error ret = compound_check_param< irods::collection_object >( _ctx );
864 return PASSMSG(
"invalid resource context", ret );
870 ret = get_next_child< irods::collection_object >( _ctx, resc );
885 const char* _new_file_name ) {
888 irods::error ret = compound_check_param< irods::data_object >( _ctx );
890 return PASSMSG(
"invalid resource context", ret );
896 ret = get_next_child< irods::data_object >( _ctx, resc );
913 irods::error ret = compound_check_param< irods::data_object >( _ctx );
915 return PASSMSG(
"invalid resource context", ret );
921 ret = get_next_child< irods::data_object >( _ctx, resc );
938 irods::error ret = compound_check_param< irods::data_object >( _ctx );
940 return PASSMSG(
"invalid resource context", ret );
946 ret = get_next_child< irods::data_object >( _ctx, resc );
967 const char* _cache_file_name ) {
970 irods::error ret = compound_check_param< irods::file_object >( _ctx );
972 std::stringstream msg;
973 msg <<
"Invalid resource context";
974 return PASSMSG( msg.str(), ret );
997 const char* _cache_file_name ) {
1000 irods::error ret = compound_check_param< irods::file_object >( _ctx );
1002 std::stringstream msg;
1003 msg <<
"Invalid resource context";
1004 return PASSMSG( msg.str(), ret );
1027 irods::error ret = compound_check_param< irods::file_object >( _ctx );
1029 std::stringstream msg;
1030 msg <<
"Invalid resource context";
1031 return PASSMSG( msg.str(), ret );
1043 irods::error ret = compound_check_param< irods::file_object >( _ctx );
1045 std::stringstream msg;
1046 msg <<
"Invalid resource context";
1047 return PASSMSG( msg.str(), ret );
1056 std::string auto_repl;
1079 irods::error ret = compound_check_param< irods::file_object >( _ctx );
1080 if ( ( result =
ASSERT_PASS( ret,
"Invalid resource context." ) ).ok() ) {
1081 std::string operation;
1086 if ( ( result =
ASSERT_PASS( ret,
"Failed to get the resource name." ) ).ok() ) {
1089 sub_parser.
set_string( file_obj->in_pdmo() );
1105 const std::string* _opr ) {
1110 irods::error ret = compound_check_param< irods::file_object >( _ctx );
1111 if ( ( result =
ASSERT_PASS( ret,
"Invalid resource context." ) ).ok() ) {
1112 std::string operation;
1117 "compound_file_notify - oper [%s] changed to [%s]",
1119 operation.c_str() );
1128 "compound_file_notify - skipping [%s]",
1142 const std::string& _operation,
1143 const std::string* _curr_host,
1145 float* _out_vote ) {
1148 int resc_status = 0;
1151 return PASSMSG(
"failed to get 'status' property", ret );
1157 ( *_out_vote ) = 0.0;
1171 ret = resc->call <
const std::string*,
const std::string*,
1174 &_operation, _curr_host,
1175 _out_parser, _out_vote );
1190 const std::string& _operation,
1191 const std::string* _curr_host,
1193 float* _out_vote ) {
1196 int resc_status = 0;
1199 return PASSMSG(
"failed to get 'status' property", ret );
1205 ( *_out_vote ) = 0.0;
1219 ret = resc->call <
const std::string*,
const std::string*,
1222 &_operation, _curr_host,
1223 _out_parser, _out_vote );
1227 if (*_out_vote > 0.0) {
1240 ret = resc->call <
const std::string*,
const std::string*,
1243 &_operation, _curr_host,
1244 _out_parser, _out_vote );
1254 const std::string* _curr_host,
1256 float* _out_vote ) {
1259 if ( !_curr_host ) {
1262 if ( !_out_parser ) {
1288 int repl_requested = f_ptr->repl_requested();
1289 f_ptr->repl_requested( -1 );
1293 float arch_check_vote = 0.0;
1295 ret = arch_resc->call <
const std::string*,
const std::string*,
1299 &arch_check_parser, &arch_check_vote );
1300 if ( !ret.
ok() || 0.0 == arch_check_vote ) {
1303 "replica not found in archive for [%s]",
1304 f_ptr->logical_path().c_str() );
1309 float cache_check_vote = 0.0;
1311 ret = cache_resc->call <
const std::string*,
const std::string*,
1315 &cache_check_parser, &cache_check_vote );
1320 if( 0.0 == cache_check_vote ) {
1327 ( *_out_parser ) = cache_check_parser;
1328 ( *_out_vote ) = cache_check_vote;
1338 std::string arch_hier;
1339 arch_check_parser.str( arch_hier );
1340 f_ptr->resc_hier( arch_hier );
1348 f_ptr->resc_id(resc_id);
1355 "prefer_archive_policy" );
1367 f_ptr->repl_requested( repl_requested );
1374 std::string parent_id_str;
1380 std::string parent_name;
1390 std::string current_name;
1398 std::string cache_name;
1408 std::string inp_hier = obj->resc_hier();
1412 size_t pos = inp_hier.find( parent_name );
1413 if ( std::string::npos == pos ) {
1416 "parent resc not in fco resc hier" );
1421 std::string dst_hier = inp_hier.substr( 0, pos + parent_name.size() );
1422 if ( !dst_hier.empty() ) {
1425 dst_hier += current_name +
1432 ( *_out_vote ) = arch_check_vote;
1442 const std::string* _opr,
1443 const std::string* _curr_host,
1445 float* _out_vote ) {
1448 if ( !_curr_host ) {
1451 if ( !_out_parser ) {
1466 std::string cache_resc_name;
1467 ret = cache_resc->get_property<std::string>(
1484 float cache_check_vote = 0.0;
1486 ret = cache_resc->call <
const std::string*,
const std::string*,
1490 &cache_check_parser, &cache_check_vote );
1494 if ( 0.0 == cache_check_vote ) {
1498 int repl_requested = f_ptr->repl_requested();
1499 f_ptr->repl_requested( -1 );
1503 float arch_check_vote = 0.0;
1505 ret = arch_resc->call <
const std::string*,
const std::string*,
1509 &arch_check_parser, &arch_check_vote );
1514 if( 0.0 == arch_check_vote ) {
1520 ( *_out_parser ) = arch_check_parser;
1521 ( *_out_vote ) = arch_check_vote;
1529 std::string arch_hier;
1530 arch_check_parser.str( arch_hier );
1531 f_ptr->resc_hier( arch_hier );
1542 f_ptr->repl_requested( repl_requested );
1549 cache_check_parser.add_child( cache_resc_name );
1550 ( *_out_parser ) = cache_check_parser;
1551 ( *_out_vote ) = arch_check_vote;
1557 ( *_out_vote ) = cache_check_vote;
1558 ( *_out_parser ) = cache_check_parser;
1571 const std::string* _opr,
1572 const std::string* _curr_host,
1574 float* _out_vote ) {
1577 if ( !_curr_host ) {
1580 if ( !_out_parser ) {
1589 int resc_status = 0;
1598 ( *_out_vote ) = 0.0;
1621 std::stringstream msg;
1622 msg <<
"invalid stage policy [" << policy <<
"]";
1635 const std::string* _opr,
1636 const std::string* _curr_host,
1638 float* _out_vote ) {
1644 std::stringstream msg;
1645 msg <<
"resource context is invalid";
1646 return PASSMSG( msg.str(), ret );
1654 if ( !_curr_host ) {
1657 if ( !_out_parser ) {
1664 ( *_out_vote ) = 0.0f;
1668 std::string resc_name;
1671 std::stringstream msg;
1672 msg <<
"failed in get property for name";
1709 std::stringstream msg;
1710 msg <<
"operation not supported [";
1711 msg << ( *_opr ) <<
"]";
1712 return ERROR( -1, msg.str() );
1728 for ( ; itr != cmap_ref->
end(); ++itr ) {
1739 if ( !result.ok() ) {
1740 return PASS( result );
1754 const std::string& _context ) :
1762 std::vector< std::string > props;
1770 "libcompound: invalid context [%s]",
1776 irods::kvp_map_t::iterator itr = kvp.begin();
1777 for( ; itr != kvp.end(); ++itr ) {
1783 std::string parent_id_str;
1798 return ERROR( -1,
"nop" );
1812 const std::string& _context ) {
1822 using namespace irods;
1823 using namespace std;
1842 function<error(plugin_context&,void*,int)>(
1857 function<error(plugin_context&, struct stat*)>(
1872 function<error(plugin_context&,struct rodsDirent**)>(
1877 function<error(plugin_context&, const char*)>(
1887 function<error(plugin_context&, long long, int)>(
1902 function<error(plugin_context&, const char*)>(
1907 function<error(plugin_context&, const char*)>(
1927 function<error(plugin_context&, const std::string*)>(
1937 function<error(plugin_context&,const std::string*, const std::string*, irods::hierarchy_parser*, float*)>(