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