00001
00002
00003 #include "structFileSync.h"
00004 #include "miscServerFunct.h"
00005 #include "dataObjOpr.h"
00006
00007
00008
00009 #include "eirods_structured_object.h"
00010 #include "eirods_resource_backport.h"
00011 #include "eirods_stacktrace.h"
00012
00013 int
00014 rsStructFileSync (rsComm_t *rsComm, structFileOprInp_t *structFileOprInp)
00015 {
00016 rodsServerHost_t *rodsServerHost;
00017 int remoteFlag;
00018 int status;
00019
00020 char* resc_hier = getValByKey( &structFileOprInp->condInput, RESC_HIER_STR_KW );
00021 if( resc_hier != NULL ) {
00022 eirods::error ret = eirods::get_host_for_hier_string( resc_hier, remoteFlag, rodsServerHost );
00023 if( !ret.ok() ) {
00024 eirods::log( PASSMSG( "rsStructFileSync - failed in call to eirods::get_host_for_hier_string", ret ) );
00025 return -1;
00026 }
00027 } else {
00028 return -1;
00029 }
00030
00031
00032
00033 if (remoteFlag == LOCAL_HOST) {
00034 status = _rsStructFileSync (rsComm, structFileOprInp);
00035 } else if (remoteFlag == REMOTE_HOST) {
00036 status = remoteStructFileSync (rsComm, structFileOprInp, rodsServerHost);
00037 } else {
00038 if (remoteFlag < 0) {
00039 return (remoteFlag);
00040 } else {
00041 rodsLog (LOG_NOTICE,
00042 "rsStructFileSync: resolveHost returned unrecognized value %d",
00043 remoteFlag);
00044 return (SYS_UNRECOGNIZED_REMOTE_FLAG);
00045 }
00046 }
00047
00048 return (status);
00049 }
00050
00051 int
00052 remoteStructFileSync (rsComm_t *rsComm, structFileOprInp_t *structFileOprInp,
00053 rodsServerHost_t *rodsServerHost)
00054 {
00055 int status;
00056
00057 if (rodsServerHost == NULL) {
00058 rodsLog (LOG_NOTICE,
00059 "remoteStructFileSync: Invalid rodsServerHost");
00060 return SYS_INVALID_SERVER_HOST;
00061 }
00062
00063 if ((status = svrToSvrConnect (rsComm, rodsServerHost)) < 0) {
00064 return status;
00065 }
00066
00067 status = rcStructFileSync (rodsServerHost->conn, structFileOprInp);
00068
00069 if (status < 0) {
00070 rodsLog (LOG_NOTICE,
00071 "remoteStructFileSync: rcStructFileSync failed for %s, status = %d",
00072 structFileOprInp->specColl->collection, status);
00073 }
00074
00075 return status;
00076 }
00077
00078
00079
00080 int _rsStructFileSync( rsComm_t* _comm,
00081 structFileOprInp_t* _struct_inp ) {
00082
00083
00084
00085 eirods::structured_object struct_obj;
00086 struct_obj.spec_coll( _struct_inp->specColl );
00087 struct_obj.addr( _struct_inp->addr );
00088 struct_obj.flags( _struct_inp->flags );
00089 struct_obj.comm( _comm );
00090 struct_obj.opr_type( _struct_inp->oprType );
00091 struct_obj.resc_hier( eirods::EIRODS_LOCAL_USE_ONLY_RESOURCE );
00092
00093
00094
00095 char* data_type = getValByKey( &_struct_inp->condInput, DATA_TYPE_KW );
00096 if( data_type ) {
00097 struct_obj.data_type( data_type );
00098 }
00099
00100
00101
00102 eirods::resource_ptr resc;
00103 eirods::error ret_err = struct_obj.resolve( resc_mgr, resc );
00104 if( !ret_err.ok() ) {
00105 eirods::error err = PASS( false, -1, "_rsStructFileSync - failed to resolve resource", ret_err );
00106 eirods::log( err );
00107 return ret_err.code();
00108 }
00109
00110
00111
00112 ret_err = resc->call( _comm, "sync", &struct_obj );
00113
00114
00115
00116 if( !ret_err.ok() ) {
00117 eirods::error err = PASS( false, ret_err.code(), "_rsStructFileSync - failed to call 'sync'", ret_err );
00118 eirods::log( err );
00119 return ret_err.code();
00120 } else {
00121 return ret_err.code();
00122 }
00123
00124 }
00125