00001
00002
00003
00004
00005
00006
00007
00008 #include "getHostForPut.h"
00009 #include "rodsLog.h"
00010 #include "rsGlobalExtern.h"
00011 #include "rcGlobalExtern.h"
00012 #include "getRemoteZoneResc.h"
00013 #include "dataObjCreate.h"
00014 #include "objMetaOpr.h"
00015 #include "resource.h"
00016 #include "collection.h"
00017 #include "specColl.h"
00018 #include "miscServerFunct.h"
00019
00020
00021
00022 #include "eirods_resource_backport.h"
00023 #include "eirods_resource_redirect.h"
00024
00025
00026 int rsGetHostForPut(
00027 rsComm_t* rsComm,
00028 dataObjInp_t* dataObjInp,
00029 char ** outHost ) {
00030
00031
00032
00033
00034 std::string hier;
00035 if( getValByKey( &dataObjInp->condInput, RESC_HIER_STR_KW ) == NULL ) {
00036 eirods::error ret = eirods::resolve_resource_hierarchy( eirods::EIRODS_CREATE_OPERATION, rsComm,
00037 dataObjInp, hier );
00038 if( !ret.ok() ) {
00039 std::stringstream msg;
00040 msg << __FUNCTION__;
00041 msg << " :: failed in eirods::resolve_resource_hierarchy for [";
00042 msg << dataObjInp->objPath << "]";
00043 eirods::log( PASSMSG( msg.str(), ret ) );
00044 return ret.code();
00045 }
00046
00047
00048
00049 addKeyVal( &dataObjInp->condInput, RESC_HIER_STR_KW, hier.c_str() );
00050
00051 }
00052
00053
00054
00055 std::string location;
00056 eirods::error ret = eirods::get_loc_for_hier_string( hier, location );
00057 if( !ret.ok() ) {
00058 eirods::log( PASSMSG( "rsGetHostForPut - failed in get_loc_for_hier_String", ret ) );
00059 return -1;
00060 }
00061
00062
00063
00064 *outHost = strdup( location.c_str() );
00065 return 0;
00066
00067 #if 0
00068 int status = 0;
00069 rescGrpInfo_t *myRescGrpInfo;
00070 rescInfo_t *myRescInfo = 0;
00071 rodsServerHost_t *rodsServerHost;
00072 rodsHostAddr_t addr;
00073 specCollCache_t *specCollCache = NULL;
00074 char *myHost;
00075 int remoteFlag = 0;
00076
00077 *outHost = NULL;
00078 if (getValByKey (&dataObjInp->condInput, ALL_KW) != NULL ||
00079 getValByKey (&dataObjInp->condInput, FORCE_FLAG_KW) != NULL) {
00080
00081
00082 *outHost = strdup (THIS_ADDRESS);
00083 return 0;
00084 }
00085
00086 resolveLinkedPath (rsComm, dataObjInp->objPath, &specCollCache, NULL);
00087 if (isLocalZone (dataObjInp->objPath) == 0) {
00088 resolveLinkedPath (rsComm, dataObjInp->objPath, &specCollCache,
00089 &dataObjInp->condInput);
00090 remoteFlag = getAndConnRcatHost (rsComm, SLAVE_RCAT,
00091 dataObjInp->objPath, &rodsServerHost);
00092 if (remoteFlag < 0) {
00093 return (remoteFlag);
00094 } else if (remoteFlag == LOCAL_HOST) {
00095 *outHost = strdup (THIS_ADDRESS);
00096 return 0;
00097 } else {
00098 status = rcGetHostForPut (rodsServerHost->conn, dataObjInp,
00099 outHost);
00100 if (status >= 0 && *outHost != NULL &&
00101 strcmp (*outHost, THIS_ADDRESS) == 0) {
00102 free (*outHost);
00103 *outHost = strdup (rodsServerHost->hostName->name);
00104 }
00105 return (status);
00106 }
00107 }
00108
00109 status = getSpecCollCache (rsComm, dataObjInp->objPath, 0, &specCollCache);
00110 if (status >= 0 && NULL != specCollCache) {
00111 if (specCollCache->specColl.collClass == MOUNTED_COLL) {
00112
00113
00114
00115
00116
00117
00118
00119 myRescInfo = new rescInfo_t;
00120 eirods::error err = eirods::get_resc_info( specCollCache->specColl.resource, *myRescInfo );
00121 if( !err.ok() ) {
00122 std::stringstream msg;
00123 msg << "rsGetHostForPut - failed for [";
00124 msg << specCollCache->specColl.resource;
00125 msg << "]";
00126 eirods::log( PASS( false, -1, msg.str(), err ) );
00127 }
00128
00129
00130
00131 } else {
00132 *outHost = strdup (THIS_ADDRESS);
00133 return 0;
00134 }
00135 } else {
00136
00137 status = getRescGrpForCreate (rsComm, dataObjInp, &myRescGrpInfo);
00138 if (status < 0)
00139 return status;
00140
00141 myRescInfo = myRescGrpInfo->rescInfo;
00142 freeAllRescGrpInfo (myRescGrpInfo);
00143 }
00144
00145
00146 bzero (&addr, sizeof (addr));
00147
00148 status = resolveHost (&addr, &rodsServerHost);
00149 delete myRescInfo;
00150 if (status < 0) return status;
00151 if (rodsServerHost->localFlag == LOCAL_HOST) {
00152 *outHost = strdup (THIS_ADDRESS);
00153 return 0;
00154 }
00155
00156 myHost = getSvrAddr (rodsServerHost);
00157 if (myHost != NULL) {
00158 *outHost = strdup (myHost);
00159 return 0;
00160 } else {
00161 *outHost = NULL;
00162 return SYS_INVALID_SERVER_HOST;
00163 }
00164 #endif
00165 }
00166