Ejemplo n.º 1
0
int
remotePhyBundleColl( rsComm_t *rsComm,
                     structFileExtAndRegInp_t *phyBundleCollInp, rodsServerHost_t *rodsServerHost ) {
    int status;

    if ( rodsServerHost == NULL ) {
        rodsLog( LOG_NOTICE,
                 "remotePhyBundleColl: Invalid rodsServerHost" );
        return SYS_INVALID_SERVER_HOST;
    }

    if ( ( status = svrToSvrConnect( rsComm, rodsServerHost ) ) < 0 ) {
        return status;
    }

    status = rcPhyBundleColl( rodsServerHost->conn, phyBundleCollInp );
    return status;
}
Ejemplo n.º 2
0
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;
}
Ejemplo n.º 3
0
int
remoteDataGet( rsComm_t *rsComm, dataOprInp_t *dataOprInp,
               portalOprOut_t **portalOprOut, rodsServerHost_t *rodsServerHost ) {
    int status;

    if ( rodsServerHost == NULL ) {
        rodsLog( LOG_NOTICE,
                 "remoteDataGet: Invalid rodsServerHost" );
        return SYS_INVALID_SERVER_HOST;
    }

    if ( ( status = svrToSvrConnect( rsComm, rodsServerHost ) ) < 0 ) {
        return status;
    }

    dataOprInp->srcL3descInx = convL3descInx( dataOprInp->srcL3descInx );
    status = rcDataGet( rodsServerHost->conn, dataOprInp, portalOprOut );

    return status;
}
Ejemplo n.º 4
0
int
remoteExecCmd (rsComm_t *rsComm, execCmd_t *execCmdInp, 
execCmdOut_t **execCmdOut, rodsServerHost_t *rodsServerHost)
{
    int status;

    if (rodsServerHost == NULL) {
        rodsLog (LOG_NOTICE,
          "remoteExecCmd: Invalid rodsServerHost");
        return SYS_INVALID_SERVER_HOST;
    }

    if ((status = svrToSvrConnect (rsComm, rodsServerHost)) < 0) {
        return status;
    }

    status = rcExecCmd (rodsServerHost->conn, execCmdInp, execCmdOut);

    if (status < 0) {
        rodsLog (LOG_ERROR,
         "remoteExecCmd: rcExecCmd failed for %s. status = %d",
          execCmdInp->cmd, status);
    } else if (status > 0 &&
      getValByKey (&execCmdInp->condInput, STREAM_STDOUT_KW) != NULL) {
	int fileInx = status;
        (*execCmdOut)->status = bindStreamToIRods (rodsServerHost, fileInx);
        if ((*execCmdOut)->status < 0) {
	    fileCloseInp_t remFileCloseInp;
            rodsLog (LOG_ERROR,
             "remoteExecCmd: bindStreamToIRods failed. status = %d",
              (*execCmdOut)->status);
            memset (&remFileCloseInp, 0, sizeof (remFileCloseInp));
            remFileCloseInp.fileInx = fileInx;
            rcFileClose (rodsServerHost->conn, &remFileCloseInp);
	}
	status = (*execCmdOut)->status;
    } else {
	status = 0;
    }
    return status;
}
Ejemplo n.º 5
0
int
resoAndConnHostByDataObjInfo( rsComm_t *rsComm, dataObjInfo_t *dataObjInfo,
                              rodsServerHost_t **rodsServerHost ) {
    int status;
    rodsHostAddr_t addr;
    int remoteFlag;
    if ( dataObjInfo == NULL ) {
        rodsLog( LOG_NOTICE,
                 "resoAndConnHostByDataObjInfo: NULL dataObjInfo" );
        return SYS_INTERNAL_NULL_INPUT_ERR;
    }

    // =-=-=-=-=-=-=-
    // extract the host location from the resource hierarchy
    std::string location;
    irods::error ret = irods::get_loc_for_hier_string( dataObjInfo->rescHier, location );
    if ( !ret.ok() ) {
        irods::log( PASSMSG( "resoAndConnHostByDataObjInfo - failed in get_loc_for_hier_string", ret ) );
        return ret.code();
    }


    memset( &addr, 0, sizeof( addr ) );
    rstrcpy( addr.hostAddr, location.c_str(), NAME_LEN );

    remoteFlag = resolveHost( &addr, rodsServerHost );

    if ( remoteFlag == REMOTE_HOST ) {
        status = svrToSvrConnect( rsComm, *rodsServerHost );
        if ( status < 0 ) {
            rodsLog( LOG_ERROR,
                     "resAndConnHostByDataObjInfo: svrToSvrConnect to %s failed",
                     ( *rodsServerHost )->hostName->name );
        }
    }
    return remoteFlag;
}
Ejemplo n.º 6
0
int
remoteFileSyncToArch( rsComm_t *rsComm, fileStageSyncInp_t *fileSyncToArchInp, fileSyncOut_t** sync_out, rodsServerHost_t *rodsServerHost ) {
    int status;

    if ( rodsServerHost == NULL ) {
        rodsLog( LOG_NOTICE,
                 "remoteFileSyncToArch: Invalid rodsServerHost" );
        return SYS_INVALID_SERVER_HOST;
    }

    if ( ( status = svrToSvrConnect( rsComm, rodsServerHost ) ) < 0 ) {
        return status;
    }

    status = rcFileSyncToArch( rodsServerHost->conn, fileSyncToArchInp, sync_out );

    if ( status < 0 ) {
        rodsLog( LOG_NOTICE,
                 "remoteFileSyncToArch: rcFileSyncToArch failed for %s",
                 fileSyncToArchInp->filename );
    }

    return status;
}
Ejemplo n.º 7
0
// =-=-=-=-=-=-=-
// static function to query resource for chosen server to which to redirect
// for a given operation
    error resource_redirect( const std::string&   _oper,
                             rsComm_t*            _comm,
                             dataObjInp_t*        _data_obj_inp,
                             std::string&         _out_hier,
                             rodsServerHost_t*&   _out_host,
                             int&                 _out_flag ) {
        // =-=-=-=-=-=-=-
        // default to local host if there is a failure
        _out_flag = LOCAL_HOST;

        // =-=-=-=-=-=-=-
        // resolve the resource hierarchy for this given operation and dataobjinp
        std::string resc_hier;
        error res_err = resolve_resource_hierarchy(
                            _oper,
                            _comm,
                            _data_obj_inp,
                            resc_hier );
        if ( !res_err.ok() ) {
            std::stringstream msg;
            msg << "resource_redirect - failed to resolve resource hierarchy for [";
            msg << _data_obj_inp->objPath;
            msg << "]";
            return PASSMSG( msg.str(), res_err );

        }

        // =-=-=-=-=-=-=-
        // we may have an empty hier due to special collections and other
        // unfortunate cases which we cannot control, check the hier string
        // and if it is empty return success ( for now )
        if ( resc_hier.empty() ) {
            return SUCCESS();
        }

        // =-=-=-=-=-=-=-
        // parse out the leaf resource for redirection
        std::string last_resc;
        hierarchy_parser parser;
        parser.set_string( resc_hier );
        parser.last_resc( last_resc );

        // =-=-=-=-=-=-=-
        // get the host property from the last resc and get the
        // host name from that host
        rodsServerHost_t* last_resc_host = NULL;
        error err = get_resource_property< rodsServerHost_t* >(
                        last_resc,
                        RESOURCE_HOST,
                        last_resc_host );
        if ( !err.ok() || NULL == last_resc_host ) {
            std::stringstream msg;
            msg << "resource_redirect :: failed in get_resource_property call ";
            msg << "for [" << last_resc << "]";
            return PASSMSG( msg.str(), err );
        }


        // =-=-=-=-=-=-=-
        // get current hostname, which is also done by init local server host
        char host_name_char[ MAX_NAME_LEN ];
        if ( gethostname( host_name_char, MAX_NAME_LEN ) < 0 ) {
            return ERROR( SYS_GET_HOSTNAME_ERR, "failed in gethostname" );

        }

        std::string host_name( host_name_char );

        // =-=-=-=-=-=-=
        // iterate over the list of hostName_t* and see if any match our
        // host name.  if we do, then were local
        bool        match_flg = false;
        hostName_t* tmp_host  = last_resc_host->hostName;
        while ( tmp_host ) {
            std::string name( tmp_host->name );
            if ( name.find( host_name ) != std::string::npos ) {
                match_flg = true;
                break;

            }

            tmp_host = tmp_host->next;

        } // while tmp_host

        // =-=-=-=-=-=-=-
        // are we really, really local?
        if ( match_flg ) {
            _out_hier = resc_hier;
            _out_flag = LOCAL_HOST;
            _out_host = 0;
            return SUCCESS();
        }

        // =-=-=-=-=-=-=-
        // it was not a local resource so then do a svr to svr connection
        int conn_err = svrToSvrConnect( _comm, last_resc_host );
        if ( conn_err < 0 ) {
            return ERROR( conn_err, "failed in svrToSvrConnect" );
        }


        // =-=-=-=-=-=-=-
        // return with a hier string and new connection as remote host
        _out_hier = resc_hier;
        _out_host = last_resc_host;
        _out_flag = REMOTE_HOST;

        return SUCCESS();

    } // resource_redirect
Ejemplo n.º 8
0
    /**
    * \fn msiH5Dataset_read (msParam_t *inpH5DatasetParam, msParam_t *outH5DatasetParam,
    * ruleExecInfo_t *rei)
    *
    * \brief This microservice is for reading a dataset from an opened HDF5 file.
    *
    * \module hdf5
    *
    * \since pre-2.1
    *
    * \author uiuc.edu Mike Wan
    * \date  2008
    *
    * \usage See clients/icommands/test/rules3.0/
    *
    * \param[in] inpH5DatasetParam - The input H5Dataset. Must be h5Dataset_MS_T.
    * \param[out] outH5DatasetParam - The output H5Dataset - Must be h5Dataset_MS_T.
    * \param[in,out] rei - The RuleExecInfo structure that is automatically
    *    handled by the rule engine. The user does not include rei as a
    *    parameter in the rule invocation.
    *
    * \DolVarDependence none
    * \DolVarModified none
    * \iCatAttrDependence none
    * \iCatAttrModified none
    * \sideeffect none
    *
    * \return integer
    * \retval 0 upon success
    * \pre none
    * \post none
    * \sa none
    **/
    int
    msiH5Dataset_read (msParam_t *inpH5DatasetParam, msParam_t *outH5DatasetParam,
    ruleExecInfo_t *rei)
    {
        rsComm_t *rsComm;
        H5Dataset *ind;
        H5Dataset *outd;
        int l1descInx;
        dataObjInfo_t *dataObjInfo;
        int remoteFlag;
        rodsServerHost_t *rodsServerHost;

        RE_TEST_MACRO ( ( char * )"    Calling msiH5Dataset_read")

        if (rei == NULL || rei->rsComm == NULL) {
            rodsLog (LOG_ERROR,
              "msiH5Dataset_read: input rei or rsComm is NULL");
            return (SYS_INTERNAL_NULL_INPUT_ERR);
        }

        rsComm = rei->rsComm;

        if (inpH5DatasetParam == NULL || outH5DatasetParam == NULL) {
            rei->status = SYS_INTERNAL_NULL_INPUT_ERR;
            rodsLogAndErrorMsg (LOG_ERROR, &rsComm->rError, rei->status,
              ( char * )"msiH5Dataset_read: NULL input/output Param");
            return (rei->status);
        }

        if (strcmp (inpH5DatasetParam->type, h5Dataset_MS_T) == 0) {
            ind = (H5Dataset*)inpH5DatasetParam->inOutStruct;
        } else {
            rei->status = USER_PARAM_TYPE_ERR;
            rodsLogAndErrorMsg (LOG_ERROR, &rsComm->rError, rei->status,
              ( char * )"msiH5Dataset_read: wrong inpH5DatasetParam type %s",
              inpH5DatasetParam->type);
            return (rei->status);
        }

        l1descInx = getL1descInxByFid (ind->fid);
        if (l1descInx < 0) {
            rei->status = SYS_BAD_FILE_DESCRIPTOR;
            rodsLogAndErrorMsg (LOG_ERROR, &rsComm->rError, rei->status,
              ( char * )"msiH5Dataset_read: bad fid %d", ind->fid);
            return (rei->status);
        }

        dataObjInfo = L1desc[l1descInx].dataObjInfo;

        remoteFlag = resolveHostByDataObjInfo (dataObjInfo,
          &rodsServerHost);

        if (remoteFlag == LOCAL_HOST) {
            outd = (H5Dataset*)malloc (sizeof (H5Dataset));
            rei->status = H5Dataset_read (ind, outd);
        } else {
            /* do the remote close */
            outd = NULL;
            if ((rei->status = svrToSvrConnect (rsComm, rodsServerHost)) >= 0) {
                rei->status = _clH5Dataset_read (rodsServerHost->conn, ind, &outd);
            }
        }

        /* prepare the output */

        fillMsParam (outH5DatasetParam, NULL, ( char * )h5Dataset_MS_T, outd, NULL);

        if (ind) H5Dataset_dtor(ind);

        return rei->status;

    }
Ejemplo n.º 9
0
int
localProcStat (rsComm_t *rsComm, procStatInp_t *procStatInp,
               genQueryOut_t **procStatOut)
{
    int numProc, status;
    procLog_t procLog;
    char childPath[MAX_NAME_LEN];
#ifndef USE_BOOST_FS
    DIR *dirPtr;
    struct dirent *myDirent;
#ifndef windows_platform
    struct stat statbuf;
#else
    struct irodsntstat statbuf;
#endif
#endif
    int count = 0;

    numProc = getNumFilesInDir (ProcLogDir) + 2; /* add 2 to give some room */

    bzero (&procLog, sizeof (procLog));
    /* init serverAddr */
    if (*procStatInp->addr != '\0') {   /* given input addr */
        rstrcpy (procLog.serverAddr, procStatInp->addr, NAME_LEN);
    } else {
        setLocalSrvAddr (procLog.serverAddr);
    }
    if (numProc <= 0) {
        /* add an empty entry with only serverAddr */
        initProcStatOut (procStatOut, 1);
        addProcToProcStatOut (&procLog, *procStatOut);
        return numProc;
    } else {
        initProcStatOut (procStatOut, numProc);
    }

    /* loop through the directory */
#ifdef USE_BOOST_FS
    path srcDirPath (ProcLogDir);
    if (!exists(srcDirPath) || !is_directory(srcDirPath)) {
#else
    dirPtr = opendir (ProcLogDir);
    if (dirPtr == NULL) {
#endif
        status = USER_INPUT_PATH_ERR - errno;
        rodsLogError (LOG_ERROR, status,
                      "localProcStat: opendir local dir error for %s", ProcLogDir);
        return status;
    }
#ifdef USE_BOOST_FS
    directory_iterator end_itr; // default construction yields past-the-end
    for (directory_iterator itr(srcDirPath); itr != end_itr; ++itr) {
        path p = itr->path();
        path cp = p.filename();
        if (!isdigit (*cp.c_str())) continue;   /* not a pid */
        snprintf (childPath, MAX_NAME_LEN, "%s",
                  p.c_str ());
#else
    while ((myDirent = readdir (dirPtr)) != NULL) {
        if (strcmp (myDirent->d_name, ".") == 0 ||
                strcmp (myDirent->d_name, "..") == 0) {
            continue;
        }
        if (!isdigit (*myDirent->d_name)) continue;   /* not a pid */
        snprintf (childPath, MAX_NAME_LEN, "%s/%s", ProcLogDir,
                  myDirent->d_name);
#endif
#ifdef USE_BOOST_FS
        if (!exists (p)) {
#else
#ifndef windows_platform
        status = stat (childPath, &statbuf);
#else
        status = iRODSNt_stat(childPath, &statbuf);
#endif
        if (status != 0) {
#endif  /* USE_BOOST_FS */
            rodsLogError (LOG_ERROR, status,
                          "localProcStat: stat error for %s", childPath);
            continue;
        }
#ifdef USE_BOOST_FS
        if (is_regular_file(p)) {
#else
        if (statbuf.st_mode & S_IFREG) {
#endif
            if (count >= numProc) {
                rodsLog (LOG_ERROR,
                         "localProcStat: proc count %d exceeded", numProc);
                break;
            }
#ifdef USE_BOOST_FS
            procLog.pid = atoi (cp.c_str());
#else
            procLog.pid = atoi (myDirent->d_name);
#endif
            if (readProcLog (procLog.pid, &procLog) < 0) continue;
            status = addProcToProcStatOut (&procLog, *procStatOut);
            if (status < 0) continue;
            count++;
        } else {
            continue;
        }
    }
#ifndef USE_BOOST_FS
    closedir (dirPtr);
#endif
    return 0;
}

int
remoteProcStat (rsComm_t *rsComm, procStatInp_t *procStatInp,
                genQueryOut_t **procStatOut, rodsServerHost_t *rodsServerHost)
{
    int status;
    procLog_t procLog;

    if (rodsServerHost == NULL) {
        rodsLog (LOG_ERROR,
                 "remoteProcStat: Invalid rodsServerHost");
        return SYS_INVALID_SERVER_HOST;
    }

    if (procStatInp == NULL || procStatOut == NULL) return USER__NULL_INPUT_ERR;

    status = svrToSvrConnect (rsComm, rodsServerHost);

    if (status >= 0) {
        status = rcProcStat (rodsServerHost->conn, procStatInp, procStatOut);
    }
    if (status < 0 && *procStatOut == NULL) {
        /* add an empty entry */
        initProcStatOut (procStatOut, 1);
        bzero (&procLog, sizeof (procLog));
        rstrcpy (procLog.serverAddr, rodsServerHost->hostName->name,
                 NAME_LEN);
        addProcToProcStatOut (&procLog, *procStatOut);
    }
    return status;
}

int
initProcStatOut (genQueryOut_t **procStatOut, int numProc)
{
    genQueryOut_t *myProcStatOut;

    if (procStatOut == NULL || numProc <= 0) return USER__NULL_INPUT_ERR;

    myProcStatOut = *procStatOut = (genQueryOut_t*)malloc (sizeof (genQueryOut_t));
    bzero (myProcStatOut, sizeof (genQueryOut_t));

    myProcStatOut->continueInx = -1;

    myProcStatOut->attriCnt = 9;

    myProcStatOut->sqlResult[0].attriInx = PID_INX;
    myProcStatOut->sqlResult[0].len = NAME_LEN;
    myProcStatOut->sqlResult[0].value =
        (char*)malloc (NAME_LEN * numProc);
    bzero (myProcStatOut->sqlResult[0].value, NAME_LEN * numProc);

    myProcStatOut->sqlResult[1].attriInx = STARTTIME_INX;
    myProcStatOut->sqlResult[1].len = NAME_LEN;
    myProcStatOut->sqlResult[1].value =
        (char*)malloc (NAME_LEN * numProc);
    bzero (myProcStatOut->sqlResult[1].value, NAME_LEN * numProc);

    myProcStatOut->sqlResult[2].attriInx = CLIENT_NAME_INX;
    myProcStatOut->sqlResult[2].len = NAME_LEN;
    myProcStatOut->sqlResult[2].value =
        (char*)malloc (NAME_LEN * numProc);
    bzero (myProcStatOut->sqlResult[2].value, NAME_LEN * numProc);

    myProcStatOut->sqlResult[3].attriInx = CLIENT_ZONE_INX;
    myProcStatOut->sqlResult[3].len = NAME_LEN;
    myProcStatOut->sqlResult[3].value =
        (char*)malloc (NAME_LEN * numProc);
    bzero (myProcStatOut->sqlResult[3].value, NAME_LEN * numProc);

    myProcStatOut->sqlResult[4].attriInx = PROXY_NAME_INX;
    myProcStatOut->sqlResult[4].len = NAME_LEN;
    myProcStatOut->sqlResult[4].value =
        (char*)malloc (NAME_LEN * numProc);
    bzero (myProcStatOut->sqlResult[4].value, NAME_LEN * numProc);

    myProcStatOut->sqlResult[5].attriInx = PROXY_ZONE_INX;
    myProcStatOut->sqlResult[5].len = NAME_LEN;
    myProcStatOut->sqlResult[5].value =
        (char*)malloc (NAME_LEN * numProc);
    bzero (myProcStatOut->sqlResult[5].value, NAME_LEN * numProc);

    myProcStatOut->sqlResult[6].attriInx = REMOTE_ADDR_INX;
    myProcStatOut->sqlResult[6].len = NAME_LEN;
    myProcStatOut->sqlResult[6].value =
        (char*)malloc (NAME_LEN * numProc);
    bzero (myProcStatOut->sqlResult[6].value, NAME_LEN * numProc);

    myProcStatOut->sqlResult[7].attriInx = SERVER_ADDR_INX;
    myProcStatOut->sqlResult[7].len = NAME_LEN;
    myProcStatOut->sqlResult[7].value =
        (char*)malloc (NAME_LEN * numProc);
    bzero (myProcStatOut->sqlResult[7].value, NAME_LEN * numProc);

    myProcStatOut->sqlResult[8].attriInx = PROG_NAME_INX;
    myProcStatOut->sqlResult[8].len = NAME_LEN;
    myProcStatOut->sqlResult[8].value =
        (char*)malloc (NAME_LEN * numProc);
    bzero (myProcStatOut->sqlResult[8].value, NAME_LEN * numProc);


    return 0;
}

int
addProcToProcStatOut (procLog_t *procLog, genQueryOut_t *procStatOut)
{
    int rowCnt;

    if (procLog == NULL || procStatOut == NULL) return USER__NULL_INPUT_ERR;
    rowCnt = procStatOut->rowCnt;

    snprintf (&procStatOut->sqlResult[0].value[NAME_LEN * rowCnt],
              NAME_LEN, "%d", procLog->pid);
    snprintf (&procStatOut->sqlResult[1].value[NAME_LEN * rowCnt],
              NAME_LEN, "%u", procLog->startTime);
    rstrcpy (&procStatOut->sqlResult[2].value[NAME_LEN * rowCnt],
             procLog->clientName, NAME_LEN);
    rstrcpy (&procStatOut->sqlResult[3].value[NAME_LEN * rowCnt],
             procLog->clientZone, NAME_LEN);
    rstrcpy (&procStatOut->sqlResult[4].value[NAME_LEN * rowCnt],
             procLog->proxyName, NAME_LEN);
    rstrcpy (&procStatOut->sqlResult[5].value[NAME_LEN * rowCnt],
             procLog->proxyZone, NAME_LEN);
    rstrcpy (&procStatOut->sqlResult[6].value[NAME_LEN * rowCnt],
             procLog->remoteAddr, NAME_LEN);
    rstrcpy (&procStatOut->sqlResult[7].value[NAME_LEN * rowCnt],
             procLog->serverAddr, NAME_LEN);
    rstrcpy (&procStatOut->sqlResult[8].value[NAME_LEN * rowCnt],
             procLog->progName, NAME_LEN);

    procStatOut->rowCnt++;

    return 0;
}
Ejemplo n.º 10
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
Ejemplo n.º 11
0
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
Ejemplo n.º 12
0
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;
}
Ejemplo n.º 13
0
int
rsStructFileExtAndReg (rsComm_t *rsComm,
structFileExtAndRegInp_t *structFileExtAndRegInp)
{
    int status;
    dataObjInp_t dataObjInp;
    openedDataObjInp_t dataObjCloseInp;
    dataObjInfo_t *dataObjInfo;
    int l1descInx;
    rescInfo_t *rescInfo;
    char *rescGroupName;
    int remoteFlag;
    rodsServerHost_t *rodsServerHost;
    char phyBunDir[MAX_NAME_LEN], *tmpStr;
    int flags = 0;
#if 0
    dataObjInp_t dirRegInp;
    structFileOprInp_t structFileOprInp;
#endif
    specCollCache_t *specCollCache = NULL;

    resolveLinkedPath (rsComm, structFileExtAndRegInp->objPath, &specCollCache,
      &structFileExtAndRegInp->condInput);

    resolveLinkedPath (rsComm, structFileExtAndRegInp->collection, 
      &specCollCache, NULL);

    if (!isSameZone (structFileExtAndRegInp->objPath, 
      structFileExtAndRegInp->collection))
        return SYS_CROSS_ZONE_MV_NOT_SUPPORTED;

    memset (&dataObjInp, 0, sizeof (dataObjInp));
    rstrcpy (dataObjInp.objPath, structFileExtAndRegInp->objPath,
      MAX_NAME_LEN);

    /* replicate the condInput. may have resource input */
    replKeyVal (&structFileExtAndRegInp->condInput, &dataObjInp.condInput);
    dataObjInp.openFlags = O_RDONLY;

    remoteFlag = getAndConnRemoteZone (rsComm, &dataObjInp, &rodsServerHost,
      REMOTE_OPEN);

    if (remoteFlag < 0) {
        return (remoteFlag);
    } else if (remoteFlag == REMOTE_HOST) {
        status = rcStructFileExtAndReg (rodsServerHost->conn, 
          structFileExtAndRegInp);
        return status;
    }

    /* open the structured file */
    addKeyVal (&dataObjInp.condInput, NO_OPEN_FLAG_KW, "");
    l1descInx = _rsDataObjOpen (rsComm, &dataObjInp);

    if (l1descInx < 0) {
        rodsLog (LOG_ERROR,
          "rsStructFileExtAndReg: _rsDataObjOpen of %s error. status = %d",
          dataObjInp.objPath, l1descInx);
        return (l1descInx);
    }

    rescInfo = L1desc[l1descInx].dataObjInfo->rescInfo;
    rescGroupName = L1desc[l1descInx].dataObjInfo->rescGroupName;
    remoteFlag = resolveHostByRescInfo (rescInfo, &rodsServerHost);
    bzero (&dataObjCloseInp, sizeof (dataObjCloseInp));
    dataObjCloseInp.l1descInx = l1descInx;

    if (remoteFlag == REMOTE_HOST) {
        addKeyVal (&structFileExtAndRegInp->condInput, RESC_NAME_KW,
          rescInfo->rescName);

        if ((status = svrToSvrConnect (rsComm, rodsServerHost)) < 0) {
            return status;
        }
        status = rcStructFileExtAndReg (rodsServerHost->conn,
          structFileExtAndRegInp);

        rsDataObjClose (rsComm, &dataObjCloseInp);


        return status;
    }

    status = chkCollForExtAndReg (rsComm, structFileExtAndRegInp->collection, 
      NULL);
    if (status < 0) return status;


    dataObjInfo = L1desc[l1descInx].dataObjInfo;

    createPhyBundleDir (rsComm, dataObjInfo->filePath, phyBunDir);

    status = unbunPhyBunFile (rsComm, dataObjInp.objPath, rescInfo, 
      dataObjInfo->filePath, phyBunDir, dataObjInfo->dataType, 0);

    if (status == SYS_DIR_IN_VAULT_NOT_EMPTY) {
	/* rename the phyBunDir */
    tmpStr = strdup(phyBunDir); // cppcheck - Undefined behavior: same parameter and destination in snprintf().
	snprintf (phyBunDir, MAX_NAME_LEN, "%s.%-d", tmpStr, (int) random ());
	free(tmpStr);
        status = unbunPhyBunFile (rsComm, dataObjInp.objPath, rescInfo,
          dataObjInfo->filePath, phyBunDir,  dataObjInfo->dataType, 0);
    }
    if (status < 0) {
        rodsLog (LOG_ERROR,
        "rsStructFileExtAndReg:unbunPhyBunFile err for %s to dir %s.stat=%d",
          dataObjInfo->filePath, phyBunDir, status);
        rsDataObjClose (rsComm, &dataObjCloseInp);
        return status;
    }

    if (getValByKey (&structFileExtAndRegInp->condInput, FORCE_FLAG_KW) 
      != NULL) {
	flags = flags | FORCE_FLAG_FLAG;
    }
    if (getValByKey (&structFileExtAndRegInp->condInput, BULK_OPR_KW)
      != NULL) {
        status = bulkRegUnbunSubfiles (rsComm, rescInfo, rescGroupName,
          structFileExtAndRegInp->collection, phyBunDir, flags, NULL);
    } else {
        status = regUnbunSubfiles (rsComm, rescInfo, rescGroupName,
          structFileExtAndRegInp->collection, phyBunDir, flags, NULL);
    }

    if (status == CAT_NO_ROWS_FOUND) {
        /* some subfiles have been deleted. harmless */
        status = 0;
    } else if (status < 0) {
        rodsLog (LOG_ERROR,
          "_rsUnbunAndRegPhyBunfile: rsStructFileExtAndReg for dir %s.stat=%d",
          phyBunDir, status);
    }
    rsDataObjClose (rsComm, &dataObjCloseInp);

    return status;
}