<commit_before>/*** Copyright (c), The Regents of the University of California            ***
 *** For more information please refer to files in the COPYRIGHT directory ***/
/* rsProcStat.c - server routine that handles the the ProcStat
 * API
 */

/* script generated code */
#include "procStat.hpp"
#include "objMetaOpr.hpp"
#include "resource.hpp"
#include "miscServerFunct.hpp"
#include "rodsLog.hpp"
#include "rsGlobalExtern.hpp"
#include "rcGlobalExtern.hpp"

// =-=-=-=-=-=-=-
#include "irods_resource_backport.hpp"

#include "reFuncDefs.hpp"
#include <boost/filesystem/operations.hpp>
#include <boost/filesystem/convenience.hpp>
using namespace boost::filesystem;




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
_rsProcStat( rsComm_t *rsComm, procStatInp_t *procStatInp,
             genQueryOut_t **procStatOut ) {
    int status = -1;
    rodsServerHost_t *rodsServerHost = NULL;
    int remoteFlag = -1;
    rodsHostAddr_t addr;
    procStatInp_t myProcStatInp;
    char *tmpStr = NULL;

    if ( getValByKey( &procStatInp->condInput, ALL_KW ) != NULL ) {
        status = _rsProcStatAll( rsComm, procStatOut );
        return status;
    }
    if ( getValByKey( &procStatInp->condInput, EXEC_LOCALLY_KW ) != NULL ) {
        status = localProcStat( 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 = new rescGrpInfo_t;

        //status = _getRescInfo (rsComm, tmpStr, &rescGrpInfo);
        irods::error err = irods::get_resc_grp_info( tmpStr, *rescGrpInfo );
        if ( !err.ok() ) { // (status < 0 || NULL == rescGrpInfo ) { // JMC cppcheck - nullptr
            rodsLog( LOG_ERROR,
                     "_rsProcStat: _getRescInfo of %s error. stat = %d",
                     tmpStr, status );
            delete rescGrpInfo;
            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;
        }

        delete rescGrpInfo;
    }
    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( procStatInp, procStatOut );
    }
    return status;
}

int
_rsProcStatAll( rsComm_t *rsComm,
                genQueryOut_t **procStatOut ) {
    rodsServerHost_t *tmpRodsServerHost;
    procStatInp_t myProcStatInp;
    int status;
    genQueryOut_t *singleProcStatOut = NULL;
    int savedStatus = 0;
<commit_msg>[#1472] Removed rescGrpInfo from rsProcStat()<commit_after>/*** Copyright (c), The Regents of the University of California            ***
 *** For more information please refer to files in the COPYRIGHT directory ***/
/* rsProcStat.c - server routine that handles the the ProcStat
 * API
 */

/* script generated code */
#include "procStat.hpp"
#include "objMetaOpr.hpp"
#include "resource.hpp"
#include "miscServerFunct.hpp"
#include "rodsLog.hpp"
#include "rsGlobalExtern.hpp"
#include "rcGlobalExtern.hpp"

// =-=-=-=-=-=-=-
#include "irods_resource_backport.hpp"

#include "reFuncDefs.hpp"
#include <boost/filesystem/operations.hpp>
#include <boost/filesystem/convenience.hpp>
using namespace boost::filesystem;




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
_rsProcStat( rsComm_t *rsComm, procStatInp_t *procStatInp,
             genQueryOut_t **procStatOut ) {
    int status = -1;
    rodsServerHost_t *rodsServerHost = NULL;
    int remoteFlag = -1;
    rodsHostAddr_t addr;
    procStatInp_t myProcStatInp;
    char *tmpStr = NULL;

    if ( getValByKey( &procStatInp->condInput, ALL_KW ) != NULL ) {
        status = _rsProcStatAll( rsComm, procStatOut );
        return status;
    }
    if ( getValByKey( &procStatInp->condInput, EXEC_LOCALLY_KW ) != NULL ) {
        status = localProcStat( 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 ) {

    	std::string resc_name(tmpStr);
    	irods::error ret = SUCCESS();

        // Get resource location
        std::string resc_loc;
        ret = irods::get_resource_property< std::string >( resc_name, irods::RESOURCE_LOCATION, resc_loc );
        if ( !ret.ok() ) {
            irods::log PASSMSG( "_rsProcStat - failed in get_resource_property", ret );
            return ret.code();
        }
        snprintf( procStatInp->addr, NAME_LEN, "%s", resc_loc.c_str() );

        // Get resource host
        std::string resc_host;
        ret = irods::get_resource_property< rodsServerHost_t* >(resc_name, irods::RESOURCE_HOST, rodsServerHost );
        if ( !ret.ok() ) {
            irods::log PASSMSG( "_rsProcStat - failed in get_resource_property", ret );
            return ret.code();
        }

        if ( !rodsServerHost ) {
            remoteFlag = SYS_INVALID_SERVER_HOST;
        }
        else {
            remoteFlag = rodsServerHost->localFlag;
        }

//        rescGrpInfo_t *rescGrpInfo = new rescGrpInfo_t;
//
//        //status = _getRescInfo (rsComm, tmpStr, &rescGrpInfo);
//        irods::error err = irods::get_resc_grp_info( tmpStr, *rescGrpInfo );
//        if ( !err.ok() ) { // (status < 0 || NULL == rescGrpInfo ) { // JMC cppcheck - nullptr
//            rodsLog( LOG_ERROR,
//                     "_rsProcStat: _getRescInfo of %s error. stat = %d",
//                     tmpStr, status );
//            delete rescGrpInfo;
//            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;
//        }
//
//        delete rescGrpInfo;
    }
    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( procStatInp, procStatOut );
    }
    return status;
}

int
_rsProcStatAll( rsComm_t *rsComm,
                genQueryOut_t **procStatOut ) {
    rodsServerHost_t *tmpRodsServerHost;
    procStatInp_t myProcStatInp;
    int status;
    genQueryOut_t *singleProcStatOut = NULL;
    int savedStatus = 0;

{'fraction_non_alphanumeric': 0.11399696816574027, 'fraction_numerical': 0.00202122283981809, 'mean_word_length': 2.3219201074185967, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7131635', 'n_tokens_mistral': 3286, 'n_tokens_neox': 3219, 'n_words': 681}