int getAndConnRemoteZoneForCopy( rsComm_t *rsComm, dataObjCopyInp_t *dataObjCopyInp, rodsServerHost_t **rodsServerHost ) { int status; dataObjInp_t *srcDataObjInp, *destDataObjInp; rodsServerHost_t *srcIcatServerHost = NULL; rodsServerHost_t *destIcatServerHost = NULL; srcDataObjInp = &dataObjCopyInp->srcDataObjInp; destDataObjInp = &dataObjCopyInp->destDataObjInp; status = getRcatHost( MASTER_RCAT, srcDataObjInp->objPath, &srcIcatServerHost ); if ( status < 0 || NULL == srcIcatServerHost ) { // JMC cppcheck - nullptr rodsLog( LOG_ERROR, "getAndConnRemoteZoneForCopy: getRcatHost error for %s", srcDataObjInp->objPath ); return status; } if ( srcIcatServerHost->rcatEnabled != REMOTE_ICAT ) { /* local zone. nothing to do */ return LOCAL_HOST; } status = getRcatHost( MASTER_RCAT, destDataObjInp->objPath, &destIcatServerHost ); if ( status < 0 || NULL == destIcatServerHost ) { // JMC cppcheck - nullptr rodsLog( LOG_ERROR, "getAndConnRemoteZoneForCopy: getRcatHost error for %s", destDataObjInp->objPath ); return status; } if ( destIcatServerHost->rcatEnabled != REMOTE_ICAT ) { /* local zone. nothing to do */ return LOCAL_HOST; } /* remote zone to different remote zone copy. Have to handle it * locally because of proxy admin user privilege issue */ if ( srcIcatServerHost != destIcatServerHost ) { return LOCAL_HOST; } /* from the same remote zone. do it in the remote zone */ status = getAndConnRemoteZone( rsComm, destDataObjInp, rodsServerHost, REMOTE_CREATE ); return status; }
int _rsProcStat (rsComm_t *rsComm, procStatInp_t *procStatInp, genQueryOut_t **procStatOut) { int status; rodsServerHost_t *rodsServerHost; int remoteFlag; rodsHostAddr_t addr; procStatInp_t myProcStatInp; char *tmpStr; if (getValByKey (&procStatInp->condInput, ALL_KW) != NULL) { status = _rsProcStatAll (rsComm, procStatInp, procStatOut); return status; } if (getValByKey (&procStatInp->condInput, EXEC_LOCALLY_KW) != NULL) { status = localProcStat (rsComm, procStatInp, procStatOut); return status; } bzero (&addr, sizeof (addr)); bzero (&myProcStatInp, sizeof (myProcStatInp)); if (*procStatInp->addr != '\0') { /* given input addr */ rstrcpy (addr.hostAddr, procStatInp->addr, LONG_NAME_LEN); remoteFlag = resolveHost (&addr, &rodsServerHost); } else if ((tmpStr = getValByKey (&procStatInp->condInput, RESC_NAME_KW)) != NULL) { rescGrpInfo_t *rescGrpInfo = NULL; status = _getRescInfo (rsComm, tmpStr, &rescGrpInfo); if (status < 0) { rodsLog (LOG_ERROR, "_rsProcStat: _getRescInfo of %s error. stat = %d", tmpStr, status); return status; } rstrcpy (procStatInp->addr, rescGrpInfo->rescInfo->rescLoc, NAME_LEN); rodsServerHost = (rodsServerHost_t*)rescGrpInfo->rescInfo->rodsServerHost; if (rodsServerHost == NULL) { remoteFlag = SYS_INVALID_SERVER_HOST; } else { remoteFlag = rodsServerHost->localFlag; } } else { /* do the IES server */ remoteFlag = getRcatHost (MASTER_RCAT, NULL, &rodsServerHost); } if (remoteFlag < 0) { rodsLog (LOG_ERROR, "_rsProcStat: getRcatHost() failed. erro=%d", remoteFlag); return (remoteFlag); } else if (remoteFlag == REMOTE_HOST) { addKeyVal (&myProcStatInp.condInput, EXEC_LOCALLY_KW, ""); status = remoteProcStat (rsComm, &myProcStatInp, procStatOut, rodsServerHost); rmKeyVal (&myProcStatInp.condInput, EXEC_LOCALLY_KW); } else { status = localProcStat (rsComm, procStatInp, procStatOut); } return status; }
int disconnRcatHost( int rcatType, const char *rcatZoneHint ) { int status; rodsServerHost_t *rodsServerHost = NULL; status = getRcatHost( rcatType, rcatZoneHint, &rodsServerHost ); if ( status < 0 || NULL == rodsServerHost ) { // JMC cppcheck - nullptr return status; } if ( ( rodsServerHost )->localFlag == LOCAL_HOST ) { return LOCAL_HOST; } if ( rodsServerHost->conn != NULL ) { /* a connection exists */ status = rcDisconnect( rodsServerHost->conn ); rodsServerHost->conn = NULL; } if ( status >= 0 ) { return REMOTE_HOST; } else { return status; } }
int getAndConnRcatHostNoLogin( rsComm_t *rsComm, int rcatType, char *rcatZoneHint, rodsServerHost_t **rodsServerHost ) { int status = getRcatHost( rcatType, rcatZoneHint, rodsServerHost ); if ( status < 0 ) { return status; } if ( ( *rodsServerHost )->localFlag == LOCAL_HOST ) { return LOCAL_HOST; } status = svrToSvrConnectNoLogin( rsComm, *rodsServerHost ); if ( status < 0 ) { rodsLog( LOG_NOTICE, "getAndConnRcatHost: svrToSvrConnectNoLogin to %s failed", ( *rodsServerHost )->hostName->name ); if ( ( *rodsServerHost )->rcatEnabled == REMOTE_ICAT ) { status = convZoneSockError( status ); } } return status; }
int rsProcStat (rsComm_t *rsComm, procStatInp_t *procStatInp, genQueryOut_t **procStatOut) { int status; int remoteFlag; rodsServerHost_t *rodsServerHost; if (*procStatInp->rodsZone != '\0') { remoteFlag = getRcatHost (MASTER_RCAT, procStatInp->rodsZone, &rodsServerHost); if (remoteFlag < 0) { rodsLog (LOG_ERROR, "rsProcStat: getRcatHost() failed. erro=%d", remoteFlag); return (remoteFlag); } if (rodsServerHost->localFlag == REMOTE_HOST) { status = remoteProcStat (rsComm, procStatInp, procStatOut, rodsServerHost); } else { status = _rsProcStat (rsComm, procStatInp, procStatOut); } } else { status = _rsProcStat (rsComm, procStatInp, procStatOut); } return status; }
int resetRcatHost( int rcatType, const char *rcatZoneHint ) { rodsServerHost_t *rodsServerHost = NULL; int status = getRcatHost( rcatType, rcatZoneHint, &rodsServerHost ); if ( status < 0 || NULL == rodsServerHost ) { // JMC cppcheck - nullptr return status; } if ( rodsServerHost->localFlag == LOCAL_HOST ) { return LOCAL_HOST; } rodsServerHost->conn = NULL; return REMOTE_HOST; }
/* Check if there is a connected ICAT host, and if there is, disconnect */ int getAndDisconnRcatHost( int rcatType, char *rcatZoneHint, rodsServerHost_t **rodsServerHost ) { int status; status = getRcatHost( rcatType, rcatZoneHint, rodsServerHost ); if ( status < 0 ) { return status; } if ( ( *rodsServerHost )->conn != NULL ) { /* a connection exists */ status = rcDisconnect( ( *rodsServerHost )->conn ); return status; } return 0; }
int getReHost( rodsServerHost_t **rodsServerHost ) { int status; rodsServerHost_t *tmpRodsServerHost; tmpRodsServerHost = ServerHostHead; while ( tmpRodsServerHost != NULL ) { if ( tmpRodsServerHost->reHostFlag == 1 ) { *rodsServerHost = tmpRodsServerHost; return 0; } tmpRodsServerHost = tmpRodsServerHost->next; } status = getRcatHost( MASTER_RCAT, ( const char* )NULL, rodsServerHost ); return status; }
int getRemoteZoneHost( rsComm_t *rsComm, dataObjInp_t *dataObjInp, rodsServerHost_t **rodsServerHost, char *remoteZoneOpr ) { int status; rodsServerHost_t *icatServerHost = NULL; rodsHostAddr_t *rescAddr = NULL; status = getRcatHost( MASTER_RCAT, dataObjInp->objPath, &icatServerHost ); if ( status < 0 || NULL == icatServerHost ) { // JMC cppcheck - nullptr return status; } if ( icatServerHost->rcatEnabled != REMOTE_ICAT ) { /* local zone. nothing to do */ return LOCAL_HOST; } status = svrToSvrConnect( rsComm, icatServerHost ); if ( status < 0 ) { rodsLog( LOG_ERROR, "getRemoteZoneHost: svrToSvrConnect to %s failed, status = %d", icatServerHost->hostName->name, status ); status = convZoneSockError( status ); return status; } addKeyVal( &dataObjInp->condInput, REMOTE_ZONE_OPR_KW, remoteZoneOpr ); status = rcGetRemoteZoneResc( icatServerHost->conn, dataObjInp, &rescAddr ); if ( status < 0 ) { rodsLog( LOG_ERROR, "getRemoteZoneHost: rcGetRemoteZoneResc for %s failed, status = %d", dataObjInp->objPath, status ); return status; } status = resolveHost( rescAddr, rodsServerHost ); free( rescAddr ); return status; }
int isLocalZone( char *zoneHint ) { int status; rodsServerHost_t *icatServerHost = NULL; status = getRcatHost( MASTER_RCAT, zoneHint, &icatServerHost ); if ( status < 0 || NULL == icatServerHost ) { // JMC cppcheck - nullptr return 0; } if ( icatServerHost->rcatEnabled != REMOTE_ICAT ) { /* local zone. */ return 1; } else { return 0; } }
static irods::error get_server_reports(rsComm_t* _comm, json& _resc_arr) { _resc_arr = json::array(); std::map< rodsServerHost_t*, int > svr_reported; rodsServerHost_t* icat_host = 0; char* zone_name = getLocalZoneName(); int status = getRcatHost( MASTER_RCAT, zone_name, &icat_host ); if ( status < 0 ) { return ERROR(status, "getRcatHost failed"); } for (irods::resource_manager::iterator itr = resc_mgr.begin(); itr != resc_mgr.end(); ++itr) { irods::resource_ptr resc = itr->second; rodsServerHost_t* tmp_host = 0; irods::error ret = resc->get_property< rodsServerHost_t* >( irods::RESOURCE_HOST, tmp_host ); if ( !ret.ok() ) { irods::log( PASS( ret ) ); continue; } // skip the icat server as that is done separately // also skip null tmp_hosts resources ( coordinating ) // skip local host if ( !tmp_host || tmp_host == icat_host || LOCAL_HOST == tmp_host->localFlag ) { continue; } // skip previously reported servers std::map< rodsServerHost_t*, int >::iterator svr_itr = svr_reported.find( tmp_host ); if ( svr_itr != svr_reported.end() ) { continue; } std::string resc_name; ret = resc->get_property< std::string >( irods::RESOURCE_NAME, resc_name ); if ( !ret.ok() ) { irods::log( PASS( ret ) ); continue; } svr_reported[ tmp_host ] = 1; int status = svrToSvrConnect( _comm, tmp_host ); if ( status < 0 ) { report_server_connect_error( status, tmp_host->hostName->name, resc_name, _resc_arr); continue; } bytesBuf_t* bbuf = NULL; status = rcServerReport( tmp_host->conn, &bbuf ); if ( status < 0 ) { freeBBuf( bbuf ); bbuf = NULL; rodsLog( LOG_ERROR, "rcServerReport failed for [%s], status = %d", tmp_host->hostName->name, status ); } // possible null termination issues std::string tmp_str = bbuf ? std::string((char*) bbuf->buf, bbuf->len) : std::string(); try { _resc_arr.push_back(json::parse(tmp_str)); freeBBuf(bbuf); } catch (const json::type_error& e) { std::string msg = "json_loads failed ["; msg += e.what(); msg += "]"; irods::log(ERROR(ACTION_FAILED_ERR, msg)); } } // for itr return SUCCESS(); } // get_server_reports
irods::error get_server_reports( rsComm_t* _comm, json_t*& _resc_arr ) { _resc_arr = json_array(); if( !_resc_arr ) { return ERROR( SYS_MALLOC_ERR, "json_object() failed" ); } std::map< rodsServerHost_t*, int > svr_reported; rodsServerHost_t* icat_host = 0; char* zone_name = getLocalZoneName(); int status = getRcatHost( MASTER_RCAT, zone_name, &icat_host ); if( status < 0 ) { return ERROR( status, "getRcatHost failed" ); } resc_results_t rescs; irods::error ret = gather_resources( REMOTE_HOST, _comm, rescs ); for( size_t i = 0; i < rescs.size(); ++i ) { irods::lookup_table< std::string >& resc = rescs[ i ]; std::string resc_name; irods::error ret = resc.get( irods::RESOURCE_NAME, resc_name ); if( !ret.ok() ) { irods::log( PASS( ret ) ); continue; } irods::resource_ptr resc_ptr; ret = resc_mgr.resolve( resc_name, resc_ptr ); if( !ret.ok() ) { return PASS( ret ); } rodsServerHost_t* tmp_host = 0; ret = resc_ptr->get_property< rodsServerHost_t* >( irods::RESOURCE_HOST, tmp_host ); if( !ret.ok() ) { return PASS( ret ); } // skip the icat server as that is done separately // also skip null tmp_hosts resources ( coordinating ) if( !tmp_host || tmp_host == icat_host ) { continue; } // skip previously reported servers std::map< rodsServerHost_t*, int >::iterator svr_itr = svr_reported.find( tmp_host ); if( svr_itr != svr_reported.end() ) { continue; } svr_reported[ tmp_host ] = 1; int status = svrToSvrConnect( _comm, tmp_host ); if( status < 0 ) { irods::log( ERROR( status, "failed in svrToSvrConnect" ) ); continue; } bytesBuf_t* bbuf = 0; status = procApiRequest( tmp_host->conn, SERVER_REPORT_AN, NULL, NULL, (void**)&bbuf, NULL ); if( status < 0 ) { rodsLog( LOG_ERROR, "rcServerReport failed for [%s], status = %d", "", status ); continue; } // possible null termination issues std::string tmp_str; tmp_str.assign( (char*)bbuf->buf, bbuf->len ); json_error_t j_err; json_t* j_resc = json_loads( tmp_str.data(), tmp_str.size(), &j_err ); if( !j_resc ) { std::string msg( "json_loads failed [" ); msg += j_err.text; msg += "]"; irods::log( ERROR( ACTION_FAILED_ERR, msg ) ); continue; } json_array_append( _resc_arr, j_resc ); } // for itr return SUCCESS(); } // get_server_reports
int agentMain( rsComm_t *rsComm ) { if ( !rsComm ) { return SYS_INTERNAL_NULL_INPUT_ERR; } int status = 0; // =-=-=-=-=-=-=- // capture server properties irods::server_properties& props = irods::server_properties::getInstance(); irods::error result = props.capture_if_needed(); if ( !result.ok() ) { irods::log( PASSMSG( "failed to read server configuration", result ) ); } // =-=-=-=-=-=-=- // compiler backwards compatibility hack // see header file for more details irods::dynamic_cast_hack(); while ( result.ok() && status >= 0 ) { // set default to the native auth scheme here. if ( rsComm->auth_scheme == NULL ) { rsComm->auth_scheme = strdup( "native" ); } // construct an auth object based on the scheme specified in the comm irods::auth_object_ptr auth_obj; irods::error ret = irods::auth_factory( rsComm->auth_scheme, &rsComm->rError, auth_obj ); if ( ( result = ASSERT_PASS( ret, "Failed to factory an auth object for scheme: \"%s\".", rsComm->auth_scheme ) ).ok() ) { irods::plugin_ptr ptr; ret = auth_obj->resolve( irods::AUTH_INTERFACE, ptr ); if ( ( result = ASSERT_PASS( ret, "Failed to resolve the auth plugin for scheme: \"%s\".", rsComm->auth_scheme ) ).ok() ) { irods::auth_ptr auth_plugin = boost::dynamic_pointer_cast< irods::auth >( ptr ); // Call agent start char* foo = ""; ret = auth_plugin->call < const char* > ( rsComm, irods::AUTH_AGENT_START, auth_obj, foo ); result = ASSERT_PASS( ret, "Failed during auth plugin agent start for scheme: \"%s\".", rsComm->auth_scheme ); } // =-=-=-=-=-=-=- // add the user info to the server properties for // reach by the operation wrapper for access by the // dynamic policy enforcement points set_rule_engine_globals( rsComm, props ); } if ( result.ok() ) { if ( rsComm->ssl_do_accept ) { status = sslAccept( rsComm ); if ( status < 0 ) { rodsLog( LOG_ERROR, "sslAccept failed in agentMain with status %d", status ); } rsComm->ssl_do_accept = 0; } if ( rsComm->ssl_do_shutdown ) { status = sslShutdown( rsComm ); if ( status < 0 ) { rodsLog( LOG_ERROR, "sslShutdown failed in agentMain with status %d", status ); } rsComm->ssl_do_shutdown = 0; } status = readAndProcClientMsg( rsComm, READ_HEADER_TIMEOUT ); if ( status < 0 ) { if ( status == DISCONN_STATUS ) { status = 0; break; } } } } if ( !result.ok() ) { irods::log( result ); status = result.code(); return status; } // =-=-=-=-=-=-=- // determine if we even need to connect, break the // infinite reconnect loop. if ( !resc_mgr.need_maintenance_operations() ) { return status; } // =-=-=-=-=-=-=- // find the icat host rodsServerHost_t *rodsServerHost = 0; status = getRcatHost( MASTER_RCAT, 0, &rodsServerHost ); if ( status < 0 ) { irods::log( ERROR( status, "getRcatHost failed." ) ); return status; } // =-=-=-=-=-=-=- // connect to the icat host status = svrToSvrConnect( rsComm, rodsServerHost ); if ( status < 0 ) { irods::log( ERROR( status, "svrToSvrConnect failed." ) ); return status; } // =-=-=-=-=-=-=- // call post disconnect maintenance operations before exit status = resc_mgr.call_maintenance_operations( rodsServerHost->conn ); return status; }