Esempio n. 1
0
    // =-=-=-=-=-=-=-
    // pass_thru_file_rebalance - code which would rebalance the subtree
    irods::error pass_thru_file_rebalance(
        irods::resource_plugin_context& _ctx ) {
        // =-=-=-=-=-=-=-
        // forward request for rebalance to children
        irods::error result = SUCCESS();
        irods::resource_child_map::iterator itr = _ctx.child_map().begin();
        for ( ; itr != _ctx.child_map().end(); ++itr ) {
            irods::error ret = itr->second.second->call(
                                   _ctx.comm(),
                                   irods::RESOURCE_OP_REBALANCE,
                                   _ctx.fco() );
            if ( !ret.ok() ) {
                irods::log( PASS( ret ) );
                result = ret;
            }
        }
        
        if( !result.ok() ) {
            return PASS( result );
        }

        return update_resource_object_count( 
                   _ctx.comm(),
                   _ctx.prop_map() );

    } // pass_thru_file_rebalancec
Esempio n. 2
0
irods::error random_get_resc_for_call(
    irods::resource_plugin_context& _ctx,
    irods::resource_ptr&            _resc ) {
    irods::error result = SUCCESS();

    // =-=-=-=-=-=-=-
    // check incoming parameters
    irods::error err = random_check_params< DEST_TYPE >( _ctx );
    if ( ( result = ASSERT_PASS( err, "Bad resource context." ) ).ok() ) {

        // =-=-=-=-=-=-=-
        // get the object's name
        std::string name;
        err = _ctx.prop_map().get< std::string >( irods::RESOURCE_NAME, name );
        if ( ( result = ASSERT_PASS( err, "Failed to get property." ) ).ok() ) {

            // =-=-=-=-=-=-=-
            // get the object's hier string
            boost::shared_ptr< DEST_TYPE > dst_obj = boost::dynamic_pointer_cast< DEST_TYPE >( _ctx.fco() );
            std::string hier = dst_obj->resc_hier( );

            // =-=-=-=-=-=-=-
            // get the next child pointer given our name and the hier string
            err = get_next_child_in_hier( name, hier, _ctx.child_map(), _resc );
            result = ASSERT_PASS( err, "Get next child failed." );
        }
    }

    return result;

} // random_get_resc_for_call
irods::error round_robin_get_resc_for_call(
    irods::resource_plugin_context& _ctx,
    irods::resource_ptr&            _resc ) {
    // =-=-=-=-=-=-=-
    // check incoming parameters
    irods::error err = round_robin_check_params< DEST_TYPE >( _ctx );
    if ( !err.ok() ) {
        return PASSMSG( "round_robin_get_resc_for_call - bad resource context", err );
    }

    // =-=-=-=-=-=-=-
    // get the object's name
    std::string name;
    err = _ctx.prop_map().get< std::string >( irods::RESOURCE_NAME, name );
    if ( !err.ok() ) {
        return PASSMSG( "round_robin_get_resc_for_call - failed to get property 'name'.", err );
    }

    // =-=-=-=-=-=-=-
    // get the object's hier string
    boost::shared_ptr< DEST_TYPE > obj = boost::dynamic_pointer_cast< DEST_TYPE >( _ctx.fco() );
    std::string hier = obj->resc_hier( );

    // =-=-=-=-=-=-=-
    // get the next child pointer given our name and the hier string
    err = get_next_child_in_hier( name, hier, _ctx.child_map(), _resc );
    if ( !err.ok() ) {
        return PASSMSG( "round_robin_get_resc_for_call - get_next_child_in_hier failed.", err );
    }

    return SUCCESS();

} // round_robin_get_resc_for_call
Esempio n. 4
0
    // =-=-=-=-=-=-=-
    // unixRedirectPlugin - used to allow the resource to determine which host
    //                      should provide the requested operation
    irods::error pass_thru_redirect_plugin(
        irods::resource_plugin_context& _ctx,
        const std::string*                  _opr,
        const std::string*                  _curr_host,
        irods::hierarchy_parser*           _out_parser,
        float*                              _out_vote ) {
        // =-=-=-=-=-=-=-
        // check incoming parameters
        irods::error result = SUCCESS();
        irods::error ret = pass_thru_check_params( _ctx );
        if ( !ret.ok() ) {
            result = PASSMSG( "pass_thru_redirect_plugin - invalid resource context.", ret );
        }
        if ( !_opr ) {
            return ERROR( SYS_INVALID_INPUT_PARAM, "pass_thru_redirect_plugin - null operation" );
        }
        if ( !_curr_host ) {
            return ERROR( SYS_INVALID_INPUT_PARAM, "pass_thru_redirect_plugin - null operation" );
        }
        if ( !_out_parser ) {
            return ERROR( SYS_INVALID_INPUT_PARAM, "pass_thru_redirect_plugin - null outgoing hier parser" );
        }
        if ( !_out_vote ) {
            return ERROR( SYS_INVALID_INPUT_PARAM, "pass_thru_redirect_plugin - null outgoing vote" );
        }

        // =-=-=-=-=-=-=-
        // get the name of this resource
        std::string resc_name;
        ret = _ctx.prop_map().get< std::string >( irods::RESOURCE_NAME, resc_name );
        if ( !ret.ok() ) {
            std::stringstream msg;
            msg << "pass_thru_redirect_plugin - failed in get property for name";
            return ERROR( -1, msg.str() );
        }

        // =-=-=-=-=-=-=-
        // add ourselves to the hierarchy parser by default
        _out_parser->add_child( resc_name );

        irods::resource_ptr resc;
        ret = pass_thru_get_first_chid_resc( _ctx.child_map(), resc );
        if ( !ret.ok() ) {
            return PASSMSG( "pass_thru_redirect_plugin - failed getting the first child resource pointer.", ret );
        }

        return resc->call < const std::string*,
               const std::string*,
               irods::hierarchy_parser*,
               float* > (
                   _ctx.comm(),
                   irods::RESOURCE_OP_RESOLVE_RESC_HIER,
                   _ctx.fco(),
                   _opr,
                   _curr_host,
                   _out_parser,
                   _out_vote );

    } // pass_thru_redirect_plugin
Esempio n. 5
0
    // =-=-=-=-=-=-=-
    // pass_thru_file_rebalance - code which would notify the subtree of a change
    irods::error pass_thru_file_notify(
        irods::resource_plugin_context& _ctx,
        const std::string*               _opr ) {
        // =-=-=-=-=-=-=-
        // forward request for notify to children
        irods::error result = SUCCESS();
        irods::resource_child_map::iterator itr = _ctx.child_map().begin();
        for ( ; itr != _ctx.child_map().end(); ++itr ) {
            irods::error ret = itr->second.second->call(
                                   _ctx.comm(),
                                   irods::RESOURCE_OP_NOTIFY,
                                   _ctx.fco(),
                                   _opr );
            if ( !ret.ok() ) {
                irods::log( PASS( ret ) );
                result = ret;
            }
        }

        return result;

    } // pass_thru_file_notify
Esempio n. 6
0
    // =-=-=-=-=-=-=-
    // interface to determine free space on a device given a path
    irods::error pass_thru_file_getfsfreespace_plugin(
        irods::resource_plugin_context& _ctx ) {
        irods::error result = SUCCESS();
        irods::error ret;

        ret = pass_thru_check_params( _ctx );
        if ( !ret.ok() ) {
            result = PASSMSG( "pass_thru_file_getfsfreespace_plugin - bad params.", ret );
        }
        else {
            irods::resource_ptr resc;
            ret = pass_thru_get_first_chid_resc( _ctx.child_map(), resc );
            if ( !ret.ok() ) {
                result = PASSMSG( "pass_thru_file_getfsfreespace_plugin - failed getting the first child resource pointer.", ret );
            }
            else {
                ret = resc->call( _ctx.comm(), irods::RESOURCE_OP_FREESPACE, _ctx.fco() );
                result = PASSMSG( "pass_thru_file_getfsfreespace_plugin - failed calling child freespace.", ret );
            }
        }
        return result;
    } // pass_thru_file_getfsfreespace_plugin
Esempio n. 7
0
    /// =-=-=-=-=-=-=-
    /// @brief interface to notify of a file unregistration
    irods::error pass_thru_file_unregistered(
        irods::resource_plugin_context& _ctx ) {
        irods::error result = SUCCESS();
        irods::error ret;

        ret = pass_thru_check_params( _ctx );
        if ( !ret.ok() ) {
            result = PASSMSG( "bad params.", ret );
        }
        else {
            irods::resource_ptr resc;
            ret = pass_thru_get_first_chid_resc( _ctx.child_map(), resc );
            if ( !ret.ok() ) {
                result = PASSMSG( "failed getting the first child resource pointer.", ret );
            }
            else {
                ret = resc->call( _ctx.comm(), irods::RESOURCE_OP_UNREGISTERED, _ctx.fco() );

                result = PASSMSG( "failed calling child unregistered.", ret );
            }
        }
        return result;
    } // pass_thru_file_unregistered
Esempio n. 8
0
    // =-=-=-=-=-=-=-
    // passthruStageToCache - This routine is for testing the TEST_STAGE_FILE_TYPE.
    // Just copy the file from filename to cacheFilename. optionalInfo info
    // is not used.
    irods::error pass_thru_stage_to_cache_plugin(
        irods::resource_plugin_context& _ctx,
        const char*                         _cache_file_name ) {
        irods::error result = SUCCESS();
        irods::error ret;

        ret = pass_thru_check_params( _ctx );
        if ( !ret.ok() ) {
            result = PASSMSG( "pass_thru_stage_to_cache_plugin - bad params.", ret );
        }
        else {
            irods::resource_ptr resc;
            ret = pass_thru_get_first_chid_resc( _ctx.child_map(), resc );
            if ( !ret.ok() ) {
                result = PASSMSG( "pass_thru_stage_to_cache_plugin - failed getting the first child resource pointer.", ret );
            }
            else {
                ret = resc->call<const char*>( _ctx.comm(), irods::RESOURCE_OP_STAGETOCACHE, _ctx.fco(), _cache_file_name );
                result = PASSMSG( "pass_thru_stage_to_cache_plugin - failed calling child stagetocache.", ret );
            }
        }
        return result;
    } // pass_thru_stage_to_cache_plugin
Esempio n. 9
0
    // =-=-=-=-=-=-=-
    // interface for POSIX readdir
    irods::error pass_thru_file_readdir_plugin(
        irods::resource_plugin_context& _ctx,
        struct rodsDirent**                 _dirent_ptr ) {
        irods::error result = SUCCESS();
        irods::error ret;

        ret = pass_thru_check_params( _ctx );
        if ( !ret.ok() ) {
            result = PASSMSG( "pass_thru_file_readdir_plugin - bad params.", ret );
        }
        else {
            irods::resource_ptr resc;
            ret = pass_thru_get_first_chid_resc( _ctx.child_map(), resc );
            if ( !ret.ok() ) {
                result = PASSMSG( "pass_thru_file_readdir_plugin - failed getting the first child resource pointer.", ret );
            }
            else {
                ret = resc->call<struct rodsDirent**>( _ctx.comm(), irods::RESOURCE_OP_READDIR, _ctx.fco(), _dirent_ptr );
                result = PASSMSG( "pass_thru_file_readdir_plugin - failed calling child readdir.", ret );
            }
        }
        return result;
    } // pass_thru_file_readdir_plugin
Esempio n. 10
0
    // =-=-=-=-=-=-=-
    // interface for POSIX Stat
    irods::error passthru_file_stat_plugin(
        irods::resource_plugin_context& _ctx,
        struct stat*                        _statbuf ) {
        irods::error result = SUCCESS();
        irods::error ret;

        ret = passthru_check_params( _ctx );
        if ( !ret.ok() ) {
            result = PASSMSG( "passthru_file_stat_plugin - bad params.", ret );
        }
        else {
            irods::resource_ptr resc;
            ret = passthru_get_first_child_resc( _ctx.child_map(), resc );
            if ( !ret.ok() ) {
                result = PASSMSG( "passthru_file_stat_plugin - failed getting the first child resource pointer.", ret );
            }
            else {
                ret = resc->call<struct stat*>( _ctx.comm(), irods::RESOURCE_OP_STAT, _ctx.fco(), _statbuf );
                result = PASSMSG( "passthru_file_stat_plugin - failed calling child stat.", ret );
            }
        }
        return result;
    } // passthru_file_stat_plugin
Esempio n. 11
0
    // =-=-=-=-=-=-=-
    // interface for POSIX lseek
    irods::error pass_thru_file_lseek_plugin(
        irods::resource_plugin_context& _ctx,
        long long                        _offset,
        int                              _whence ) {
        irods::error result = SUCCESS();
        irods::error ret;

        ret = pass_thru_check_params( _ctx );
        if ( !ret.ok() ) {
            result = PASSMSG( "pass_thru_file_lseek_plugin - bad params.", ret );
        }
        else {
            irods::resource_ptr resc;
            ret = pass_thru_get_first_chid_resc( _ctx.child_map(), resc );
            if ( !ret.ok() ) {
                result = PASSMSG( "pass_thru_file_lseek_plugin - failed getting the first child resource pointer.", ret );
            }
            else {
                ret = resc->call<long long, int>( _ctx.comm(), irods::RESOURCE_OP_LSEEK, _ctx.fco(), _offset, _whence );
                result = PASSMSG( "pass_thru_file_lseek_plugin - failed calling child lseek.", ret );
            }
        }
        return result;
    } // pass_thru_file_lseek_plugin
Esempio n. 12
0
    // =-=-=-=-=-=-=-
    // interface for POSIX Write
    irods::error pass_thru_file_write_plugin(
        irods::resource_plugin_context& _ctx,
        void*                               _buf,
        int                                 _len ) {
        irods::error result = SUCCESS();
        irods::error ret;

        ret = pass_thru_check_params( _ctx );
        if ( !ret.ok() ) {
            result = PASSMSG( "bad params.", ret );
        }
        else {
            irods::resource_ptr resc;
            ret = pass_thru_get_first_chid_resc( _ctx.child_map(), resc );
            if ( !ret.ok() ) {
                result = PASSMSG( "failed getting the first child resource pointer.", ret );
            }
            else {
                ret = resc->call<void*, int>( _ctx.comm(), irods::RESOURCE_OP_WRITE, _ctx.fco(), _buf, _len );
                result = PASSMSG( "pass_thru_file_write_plugin - failed calling child write.", ret );
            }
        }
        return result;
    } // pass_thru_file_write_plugin
Esempio n. 13
0
    /// =-=-=-=-=-=-=-
    /// @brief used to allow the resource to determine which host
    ///        should provide the requested operation
    irods::error random_redirect(
        irods::resource_plugin_context& _ctx,
        const std::string*               _opr,
        const std::string*               _curr_host,
        irods::hierarchy_parser*        _out_parser,
        float*                           _out_vote ) {
        irods::error result = SUCCESS();

        // =-=-=-=-=-=-=-
        // check incoming parameters
        irods::error err = random_check_params< irods::file_object >( _ctx );
        if ( ( result = ASSERT_PASS( err, "Invalid resource context." ) ).ok() ) {
            if ( ( result = ASSERT_ERROR( _opr && _curr_host && _out_parser && _out_vote, SYS_INVALID_INPUT_PARAM,
                                          "Invalid parameters." ) ).ok() ) {

                // =-=-=-=-=-=-=-
                // get the object's hier string
                irods::file_object_ptr file_obj = boost::dynamic_pointer_cast< irods::file_object >( _ctx.fco() );
                std::string hier = file_obj->resc_hier( );

                // =-=-=-=-=-=-=-
                // get the object's hier string
                std::string name;
                err = _ctx.prop_map().get< std::string >( irods::RESOURCE_NAME, name );
                if ( ( result = ASSERT_PASS( err, "Failed to get property: \"%s\".", irods::RESOURCE_NAME.c_str() ) ).ok() ) {

                    // =-=-=-=-=-=-=-
                    // add ourselves into the hierarchy before calling child resources
                    _out_parser->add_child( name );

                    // =-=-=-=-=-=-=-
                    // test the operation to determine which choices to make
                    if ( irods::OPEN_OPERATION   == ( *_opr )  ||
                            irods::WRITE_OPERATION  == ( *_opr ) ||
                            irods::UNLINK_OPERATION == ( *_opr )) {

                        // =-=-=-=-=-=-=-
                        // get the next child pointer in the hierarchy, given our name and the hier string
                        irods::resource_ptr resc;
                        err = get_next_child_for_open_or_write( name, file_obj, _ctx.child_map(), resc );
                        if ( err.ok() ) {
                            // =-=-=-=-=-=-=-
                            // forward the redirect call to the child for assertion of the whole operation,
                            // there may be more than a leaf beneath us
                            err = resc->call< const std::string*, const std::string*, irods::hierarchy_parser*, float* >( _ctx.comm(),
                                    irods::RESOURCE_OP_RESOLVE_RESC_HIER,
                                    _ctx.fco(), _opr, _curr_host, _out_parser,
                                    _out_vote );
                            result = ASSERT_PASS( err, "Failed calling child operation." );
                        }
                        else if ( err.code() == REPLICA_NOT_IN_RESC ) {
                            *_out_vote = 0;
                        }
                        else {
                            result = err;
                        }
                    }
                    else if ( irods::CREATE_OPERATION == ( *_opr ) ) {

                        // =-=-=-=-=-=-=-
                        // get the next_child resource for create
                        irods::resource_ptr resc;
                        err = get_next_valid_child_resource( _ctx, _opr, _curr_host, _out_parser, _out_vote );
                        result = ASSERT_PASS( err, "Failed getting next valid child." );
                    }
                    else {

                        // =-=-=-=-=-=-=-
                        // must have been passed a bad operation
                        result = ASSERT_ERROR( false, INVALID_OPERATION, "Operation not supported: \"%s\".",
                                               _opr->c_str() );
                    }
                }
            }
        }

        return result;
    } // random_redirect
Esempio n. 14
0
    /// =-=-=-=-=-=-=-
    /// @brief This routine is for testing the TEST_STAGE_FILE_TYPE.
    ///        Just copy the file from cacheFilename to filename. optionalInfo info
    ///        is not used.
    irods::error univ_mss_file_sync_to_arch(
        irods::resource_plugin_context& _ctx,
        const char*                         _cache_file_name ) {
        // =-=-=-=-=-=-=-
        // check context
        irods::error err = univ_mss_check_param< irods::file_object >( _ctx );
        if ( !err.ok() ) {
            std::stringstream msg;
            msg << __FUNCTION__;
            msg << " - invalid context";
            return PASSMSG( msg.str(), err );

        }

        // =-=-=-=-=-=-=-
        // snag a ref to the fco
        irods::file_object_ptr fco = boost::dynamic_pointer_cast< irods::file_object >( _ctx.fco() );
        std::string filename = fco->physical_path();

        // =-=-=-=-=-=-=-
        // first create the directory name
        char  dirname[MAX_NAME_LEN] = "";
        const char* lastpart = strrchr( filename.c_str(), '/' );
        int   lenDir   = strlen( filename.c_str() ) - strlen( lastpart );
        strncpy( dirname, filename.c_str(), lenDir );

        // =-=-=-=-=-=-=-
        // create a context to call the mkdir operation
        irods::collection_object_ptr coll_obj(
            new irods::collection_object(
                dirname,
                fco->resc_hier(),
                fco->mode(), 0 ) );
        irods::resource_plugin_context context(
            _ctx.prop_map(),
            coll_obj, "",
            _ctx.comm(),
            _ctx.child_map() );

        // =-=-=-=-=-=-=-
        // create the directory on the MSS
        int status = 0;
        err = univ_mss_file_mkdir( context );

        execCmdOut_t* execCmdOut = NULL;
        char  cmdArgv[HUGE_NAME_LEN] = "";

        execCmd_t execCmdInp;
        bzero( &execCmdInp, sizeof( execCmdInp ) );

        // =-=-=-=-=-=-=-
        // get the script property
        std::string script;
        err = _ctx.prop_map().get< std::string >( SCRIPT_PROP, script );
        if ( !err.ok() ) {
            return PASSMSG( __FUNCTION__, err );
        }

        rstrcpy( execCmdInp.cmd, script.c_str(), LONG_NAME_LEN );
        strcat( cmdArgv, "syncToArch" );
        strcat( cmdArgv, " " );
        strcat( cmdArgv, _cache_file_name );
        strcat( cmdArgv, " " );
        strcat( cmdArgv, filename.c_str() );
        strcat( cmdArgv, "" );

        rstrcpy( execCmdInp.cmdArgv, cmdArgv, HUGE_NAME_LEN );
        rstrcpy( execCmdInp.execAddr, "localhost", LONG_NAME_LEN );
        status = _rsExecCmd( _ctx.comm(), &execCmdInp, &execCmdOut );
        if ( status == 0 ) {
            err = univ_mss_file_chmod( _ctx );
            if ( !err.ok() ) {
                PASSMSG( "univ_mss_file_sync_to_arch - failed.", err );
            }
        }
        else {
            status = UNIV_MSS_SYNCTOARCH_ERR - errno;
            std::stringstream msg;
            msg << "univ_mss_file_sync_to_arch: copy of [";
            msg << _cache_file_name;
            msg << "] to [";
            msg << filename;
            msg << "] failed.";
            msg << "   stdout buff [";
            msg << execCmdOut->stdoutBuf.buf;
            msg << "]   stderr buff [";
            msg << execCmdOut->stderrBuf.buf;
            msg << "]  status [";
            msg << execCmdOut->status << "]";
            return ERROR( status, msg.str() );
        }

        return CODE( status );

    } // univ_mss_file_sync_to_arch
Esempio n. 15
0
    /// =-=-=-=-=-=-=-
    /// @brief used to allow the resource to determine which host
    ///        should provide the requested operation
    irods::error round_robin_redirect(
        irods::resource_plugin_context& _ctx,
        const std::string*               _opr,
        const std::string*               _curr_host,
        irods::hierarchy_parser*        _out_parser,
        float*                           _out_vote ) {
        // =-=-=-=-=-=-=-
        // check incoming parameters
        irods::error err = round_robin_check_params< irods::file_object >( _ctx );
        if ( !err.ok() ) {
            return PASSMSG( "round_robin_redirect - bad resource context", err );
        }
        if ( !_opr ) {
            return ERROR( SYS_INVALID_INPUT_PARAM, "round_robin_redirect - null operation" );
        }
        if ( !_curr_host ) {
            return ERROR( SYS_INVALID_INPUT_PARAM, "round_robin_redirect - null host" );
        }
        if ( !_out_parser ) {
            return ERROR( SYS_INVALID_INPUT_PARAM, "round_robin_redirect - null outgoing hier parser" );
        }
        if ( !_out_vote ) {
            return ERROR( SYS_INVALID_INPUT_PARAM, "round_robin_redirect - null outgoing vote" );
        }

        // =-=-=-=-=-=-=-
        // get the object's hier string
        irods::file_object_ptr file_obj = boost::dynamic_pointer_cast< irods::file_object >( _ctx.fco() );
        std::string hier = file_obj->resc_hier( );

        // =-=-=-=-=-=-=-
        // get the object's hier string
        std::string name;
        err = _ctx.prop_map().get< std::string >( irods::RESOURCE_NAME, name );
        if ( !err.ok() ) {
            return PASSMSG( "failed to get property 'name'.", err );
        }

        // =-=-=-=-=-=-=-
        // add ourselves into the hierarch before calling child resources
        _out_parser->add_child( name );

        // =-=-=-=-=-=-=-
        // test the operation to determine which choices to make
        if ( irods::OPEN_OPERATION  == ( *_opr )  ||
             irods::WRITE_OPERATION == ( *_opr ) ) {
            // =-=-=-=-=-=-=-
            // get the next child pointer in the hierarchy, given our name and the hier string
            irods::resource_ptr resc;
            err = get_next_child_for_open_or_write( 
                      name, 
                      file_obj, 
                      _ctx.child_map(), 
                      resc );
            if ( !err.ok() ) {
                (*_out_vote) = 0.0;
                return PASS( err );
            }

            // =-=-=-=-=-=-=-
            // forward the redirect call to the child for assertion of the whole operation,
            // there may be more than a leaf beneath us
            return resc->call < const std::string*,
                   const std::string*,
                   irods::hierarchy_parser*,
                   float* > (
                       _ctx.comm(),
                       irods::RESOURCE_OP_RESOLVE_RESC_HIER,
                       _ctx.fco(),
                       _opr,
                       _curr_host,
                       _out_parser,
                       _out_vote );

            std::string hier;
            _out_parser->str( hier );
            rodsLog( 
                LOG_DEBUG,
                "open :: resc hier [%s] vote [%f]",
                hier.c_str(),
                _out_vote );

        }
        else if ( irods::CREATE_OPERATION == ( *_opr ) ) {
            // =-=-=-=-=-=-=-
            // get the next available child resource
            irods::resource_ptr resc;
            irods::error err = get_next_valid_child_resource(
                                   _ctx.prop_map(),
                                   _ctx.child_map(),
                                   resc );
            if ( !err.ok() ) {
                return PASS( err );

            }

            // =-=-=-=-=-=-=-
            // forward the 'put' redirect to the appropriate child
            err = resc->call < const std::string*,
            const std::string*,
            irods::hierarchy_parser*,
            float* > (
                _ctx.comm(),
                irods::RESOURCE_OP_RESOLVE_RESC_HIER,
                _ctx.fco(),
                _opr,
                _curr_host,
                _out_parser,
                _out_vote );
            if ( !err.ok() ) {
                return PASSMSG( "forward of put redirect failed", err );

            }

            std::string hier;
            _out_parser->str( hier );
            rodsLog( 
                LOG_DEBUG,
                "round robin - create :: resc hier [%s] vote [%f]",
                hier.c_str(),
                _out_vote );

            std::string new_hier;
            _out_parser->str( new_hier );

            // =-=-=-=-=-=-=-
            // update the next_child appropriately as the above succeeded
            err = update_next_child_resource( _ctx.prop_map() );
            if ( !err.ok() ) {
                return PASSMSG( "update_next_child_resource failed", err );

            }

            return SUCCESS();
        }

        // =-=-=-=-=-=-=-
        // must have been passed a bad operation
        std::stringstream msg;
        msg << "round_robin_redirect - operation not supported [";
        msg << ( *_opr ) << "]";
        return ERROR( -1, msg.str() );

    } // round_robin_redirect
Esempio n. 16
0
    /// =-=-=-=-=-=-=-
    /// @brief find the next valid child resource for create operation
    irods::error get_next_valid_child_resource(
        irods::resource_plugin_context& _ctx,
        const std::string* _opr,
        const std::string* _curr_host,
        irods::hierarchy_parser* _out_parser,
        float* _out_vote ) {
        irods::error result = SUCCESS();
        irods::error ret;

        // =-=-=-=-=-=-=-
        // flag
        bool   child_found = false;

        // =-=-=-=-=-=-=-
        // the pool of resources (children) to try
        std::vector<irods::resource_ptr> candidate_resources;

        // =-=-=-=-=-=-=-
        // copy children from _cmap
        irods::resource_child_map::iterator itr = _ctx.child_map().begin();
        for ( ; itr != _ctx.child_map().end(); ++itr ) {
            candidate_resources.push_back( itr->second.second );
        }

        // =-=-=-=-=-=-=-
        // while we have not found a child and still have candidates
        while ( result.ok() && ( !child_found && !candidate_resources.empty() ) ) {

            // =-=-=-=-=-=-=-
            // generate random index
            size_t rand_index = irods::getRandom<unsigned int>() % candidate_resources.size();

            // =-=-=-=-=-=-=-
            // pick resource in pool at random index
            irods::resource_ptr resc = candidate_resources[rand_index];

            // =-=-=-=-=-=-=-
            // forward the 'create' redirect to the appropriate child
            ret = resc->call< const std::string*, const std::string*, irods::hierarchy_parser*, float* >( _ctx.comm(),
                    irods::RESOURCE_OP_RESOLVE_RESC_HIER,
                    _ctx.fco(), _opr, _curr_host, _out_parser,
                    _out_vote );
            // Found a valid child
            if ( ret.ok() && *_out_vote != 0 ) {
                child_found = true;
            }
            else {
                // =-=-=-=-=-=-=-
                // remove child from pool of candidates
                candidate_resources.erase( candidate_resources.begin() + rand_index );
            }
        } // while

        // =-=-=-=-=-=-=-
        // return appropriately
        if ( result.ok() ) {
            result = ASSERT_ERROR( child_found, NO_NEXT_RESC_FOUND, "No valid child found." );
        }

        return result;
    } // get_next_valid_child_resource
Esempio n. 17
0
    // =-=-=-=-=-=-=-
    // unixRedirectPlugin - used to allow the resource to determine which host
    //                      should provide the requested operation
    irods::error passthru_redirect_plugin(
        irods::resource_plugin_context& _ctx,
        const std::string*                  _opr,
        const std::string*                  _curr_host,
        irods::hierarchy_parser*           _out_parser,
        float*                              _out_vote ) {
        // =-=-=-=-=-=-=-
        // check incoming parameters
        irods::error result = SUCCESS();
        irods::error ret = passthru_check_params( _ctx );
        if ( !ret.ok() ) {
            result = PASSMSG( "passthru_redirect_plugin - invalid resource context.", ret );
        }
        if ( !_opr ) {
            return ERROR( SYS_INVALID_INPUT_PARAM, "passthru_redirect_plugin - null operation" );
        }
        if ( !_curr_host ) {
            return ERROR( SYS_INVALID_INPUT_PARAM, "passthru_redirect_plugin - null operation" );
        }
        if ( !_out_parser ) {
            return ERROR( SYS_INVALID_INPUT_PARAM, "passthru_redirect_plugin - null outgoing hier parser" );
        }
        if ( !_out_vote ) {
            return ERROR( SYS_INVALID_INPUT_PARAM, "passthru_redirect_plugin - null outgoing vote" );
        }

        // =-=-=-=-=-=-=-
        // get the name of this resource
        std::string resc_name;
        ret = _ctx.prop_map().get< std::string >( irods::RESOURCE_NAME, resc_name );
        if ( !ret.ok() ) {
            std::stringstream msg;
            msg << "passthru_redirect_plugin - failed in get property for name";
            return ERROR( -1, msg.str() );
        }

        // =-=-=-=-=-=-=-
        // add ourselves to the hierarchy parser by default
        _out_parser->add_child( resc_name );

        irods::resource_ptr resc;
        ret = passthru_get_first_child_resc( _ctx.child_map(), resc );
        if ( !ret.ok() ) {
            return PASSMSG( "passthru_redirect_plugin - failed getting the first child resource pointer.", ret );
        }

        irods::error final_ret = resc->call <
                                 const std::string*,
                                 const std::string*,
                                 irods::hierarchy_parser*,
                                 float* > (
                                     _ctx.comm(),
                                     irods::RESOURCE_OP_RESOLVE_RESC_HIER,
                                     _ctx.fco(),
                                     _opr,
                                     _curr_host,
                                     _out_parser,
                                     _out_vote );
        double orig_vote = *_out_vote;
        if ( irods::OPEN_OPERATION == ( *_opr ) &&
                _ctx.prop_map().has_entry( READ_WEIGHT_KW ) ) {
            double read_weight = 1.0;
            ret = _ctx.prop_map().get<double>(
                      READ_WEIGHT_KW,
                      read_weight );
            if ( !ret.ok() ) {
                irods::log( PASS( ret ) );

            }
            else {
                ( *_out_vote ) *= read_weight;

            }

        }
        else if ( ( irods::CREATE_OPERATION == ( *_opr ) ||
                    irods::WRITE_OPERATION == ( *_opr ) ) &&
                  _ctx.prop_map().has_entry( WRITE_WEIGHT_KW ) ) {
            double write_weight = 1.0;
            ret = _ctx.prop_map().get<double>(
                      WRITE_WEIGHT_KW,
                      write_weight );
            if ( !ret.ok() ) {
                irods::log( PASS( ret ) );

            }
            else {
                ( *_out_vote ) *= write_weight;

            }
        }

        rodsLog(
            LOG_DEBUG,
            "passthru_redirect_plugin - [%s] : %f - %f",
            _opr->c_str(),
            orig_vote,
            *_out_vote );

        return final_ret;

    } // passthru_redirect_plugin
Esempio n. 18
0
    /// =-=-=-=-=-=-=-
    /// @brief
    irods::error load_balanced_redirect_for_open_operation(
        irods::resource_plugin_context& _ctx,
        const std::string*              _opr,
        const std::string*              _curr_host,
        irods::hierarchy_parser*        _out_parser,
        float*                          _out_vote ) {
        // =-=-=-=-=-=-=-
        // data struct to hold parser and vote from the search
        std::map< float, irods::hierarchy_parser > result_map;

        // =-=-=-=-=-=-=-
        // iterate over all the children and pick the highest vote
        irods::resource_child_map::iterator itr = _ctx.child_map().begin();
        for ( ; itr != _ctx.child_map().end(); ++itr ) {
            // =-=-=-=-=-=-=-
            // cache resc ptr for ease of use
            irods::resource_ptr resc = itr->second.second;

            // =-=-=-=-=-=-=-
            // temp results from open redirect call - init parser with incoming
            // hier parser
            float                   vote   = 0.0;
            irods::hierarchy_parser parser = ( *_out_parser );

            // =-=-=-=-=-=-=-
            // forward the redirect call to the child for assertion of the whole operation,
            // there may be more than a leaf beneath us
            irods::error err = resc->call <
                               const std::string*,
                               const std::string*,
                               irods::hierarchy_parser*,
                               float* > (
                                   _ctx.comm(),
                                   irods::RESOURCE_OP_RESOLVE_RESC_HIER,
                                   _ctx.fco(),
                                   _opr,
                                   _curr_host,
                                   &parser,
                                   &vote );
            std::string hier;
            parser.str( hier );
            rodsLog( LOG_DEBUG1, "load_balanced node - hier : [%s], vote %f", hier.c_str(), vote );
            if ( !err.ok() ) {
                irods::log( PASS( err ) );
            }
            else {
                result_map[ vote ] = parser;
            }

        } // for

        // =-=-=-=-=-=-=-
        // now that we have collected all of the results the map
        // will have put the largest one at the end of the map
        // so grab that one and return the result if it is non zero
        float high_vote = result_map.rbegin()->first;
        if ( high_vote > 0.0 ) {
            ( *_out_parser ) = result_map.rbegin()->second;
            ( *_out_vote )   = high_vote;
            return SUCCESS();

        }
        else {
            return ERROR( -1, "no valid data object found to open" );
        }

    } // load_balanced_redirect_for_open_operation
Esempio n. 19
0
    /// =-=-=-=-=-=-=-
    /// @brief
    irods::error load_balanced_redirect_for_create_operation(
        irods::resource_plugin_context& _ctx,
        const std::string*              _opr,
        const std::string*              _curr_host,
        irods::hierarchy_parser*        _out_parser,
        float*                          _out_vote ) {
        // =-=-=-=-=-=-=-
        // capture the name, time and load lists from the DB
        std::vector< std::string > names;
        std::vector< int >         loads;
        std::vector< int >         times;
        irods::error ret = get_load_lists(
                               _ctx,
                               names,
                               loads,
                               times );
        if ( !ret.ok() ) {
            return PASS( ret );
        }

        // =-=-=-=-=-=-=-
        // retrieve local time in order to check if the load information is up
        // to date, ie less than MAX_ELAPSE_TIME seconds old
        int    min_load = 100;
        time_t time_now = 0;
        time( &time_now );

        // =-=-=-=-=-=-=-
        // iterate over children and find them in the lists
        bool resc_found = false;
        irods::resource_ptr selected_resource;
        irods::resource_child_map::iterator itr = _ctx.child_map().begin();
        for ( ; itr != _ctx.child_map().end(); ++itr ) {
            // =-=-=-=-=-=-=-
            // cache resc ptr for ease of use
            irods::resource_ptr resc = itr->second.second;

            // =-=-=-=-=-=-=-
            // get the resource name for comparison
            std::string resc_name;
            ret = resc->get_property< std::string >( irods::RESOURCE_NAME, resc_name );
            if ( !ret.ok() ) {
                return PASS( ret );
            }

            // =-=-=-=-=-=-=-
            // scan the list for a match
            for ( size_t i = 0; i < names.size(); ++i ) {
                if ( resc_name == names[ i ] ) {
                    if ( loads[ i ] >= 0 &&
                            min_load > loads[ i ] &&
                            ( time_now - times[ i ] ) < MAX_ELAPSE_TIME ) {
                        resc_found = true;
                        min_load = loads[i];
                        selected_resource = resc;
                    }

                } // if match

            } // for i

        } // for itr

        // =-=-=-=-=-=-=-
        // if we did not find a resource, this is definitely an error
        if ( !resc_found ) {
            return ERROR(
                       CHILD_NOT_FOUND,
                       "failed to find child resc in load list" );
        }

        // =-=-=-=-=-=-=-
        // forward the redirect call to the child for assertion of the whole operation,
        // there may be more than a leaf beneath us
        float                   vote   = 0.0;
        irods::hierarchy_parser parser = ( *_out_parser );
        irods::error err = selected_resource->call <
                           const std::string*,
                           const std::string*,
                           irods::hierarchy_parser*,
                           float* > (
                               _ctx.comm(),
                               irods::RESOURCE_OP_RESOLVE_RESC_HIER,
                               _ctx.fco(),
                               _opr,
                               _curr_host,
                               &parser,
                               &vote );
        std::string hier;
        parser.str( hier );
        rodsLog(
            LOG_DEBUG1,
            "load_balanced node - hier : [%s], vote %f",
            hier.c_str(),
            vote );
        if ( !err.ok() ) {
            irods::log( PASS( err ) );
        }

        // =-=-=-=-=-=-=-
        // set the out variables
        ( *_out_parser ) = parser;
        ( *_out_vote )   = vote;

        return SUCCESS();

    } // load_balanced_redirect_for_create_operation
Esempio n. 20
0
    /// =-=-=-=-=-=-=-
    /// @brief interface for POSIX rename
    irods::error univ_mss_file_rename(
        irods::resource_plugin_context& _ctx,
        const char*                      _new_file_name ) {
        // =-=-=-=-=-=-=-
        // check context
        irods::error err = univ_mss_check_param< irods::file_object >( _ctx );
        if ( !err.ok() ) {
            std::stringstream msg;
            msg << __FUNCTION__;
            msg << " - invalid context";
            return PASSMSG( msg.str(), err );

        }

        // =-=-=-=-=-=-=-
        // get the script property
        std::string script;
        err = _ctx.prop_map().get< std::string >( SCRIPT_PROP, script );
        if ( !err.ok() ) {
            return PASSMSG( __FUNCTION__, err );
        }

        // =-=-=-=-=-=-=-
        // snag a ref to the fco
        irods::file_object_ptr fco = boost::dynamic_pointer_cast< irods::file_object >( _ctx.fco() );
        std::string filename = fco->physical_path();

        // =-=-=-=-=-=-=-
        // first create the directory name
        char  dirname[MAX_NAME_LEN] = "";
        const char* lastpart = strrchr( _new_file_name, '/' );
        int   lenDir   = strlen( _new_file_name ) - strlen( lastpart );
        strncpy( dirname, _new_file_name, lenDir );

        // =-=-=-=-=-=-=-
        // create a context to call the mkdir operation
        irods::collection_object_ptr coll_obj(
            new irods::collection_object(
                dirname,
                fco->resc_hier(),
                fco->mode(), 0 ) );
        irods::resource_plugin_context context(
            _ctx.prop_map(),
            coll_obj, "",
            _ctx.comm(),
            _ctx.child_map() );

        // =-=-=-=-=-=-=-
        // create the directory on the MSS
        int status = 0;
        err = univ_mss_file_mkdir( context );

        execCmd_t execCmdInp;

        bzero( &execCmdInp, sizeof( execCmdInp ) );
        snprintf( execCmdInp.cmd, sizeof( execCmdInp.cmd ), "%s", script.c_str() );
        snprintf( execCmdInp.cmdArgv, sizeof( execCmdInp.cmdArgv ), "mv '%s' '%s'", filename.c_str(), _new_file_name );
        snprintf( execCmdInp.execAddr, sizeof( execCmdInp.execAddr ), "%s", "localhost" );
        execCmdOut_t *execCmdOut = NULL;
        status = _rsExecCmd( &execCmdInp, &execCmdOut );
        freeCmdExecOut( execCmdOut );

        if ( status < 0 ) {
            status = UNIV_MSS_RENAME_ERR - errno;
            std::stringstream msg;
            msg << "univ_mss_file_rename - failed for [";
            msg << filename;
            msg << "]";
            return ERROR( status, msg.str() );

        }

        return CODE( status );

    } // univ_mss_file_rename
Esempio n. 21
0
    /// =-=-=-=-=-=-=-
    /// @brief find the next valid child resource for create operation
    irods::error get_next_valid_child_resource(
        irods::resource_plugin_context& _ctx,
        const std::string*              _opr,
        const std::string*              _curr_host,
        irods::hierarchy_parser*        _out_parser,
        float*                          _out_vote ) {

        // =-=-=-=-=-=-=-
        // counter and flag
        int  child_ctr   = 0;
        bool child_found = false;

        // =-=-=-=-=-=-=-
        // while we have not found a child and have not
        // exhausted all the children in the map
        while ( !child_found &&
                child_ctr < _ctx.child_map().size() ) {
            // =-=-=-=-=-=-=-
            // increment child counter
            child_ctr++;

            // =-=-=-=-=-=-=-
            // get the next_child property
            std::string next_child;
            irods::error err = _ctx.prop_map().get< std::string >(
                                   NEXT_CHILD_PROP,
                                   next_child );
            if ( !err.ok() ) {
                return PASSMSG( "get property for 'next_child' failed.", err );

            }

            // =-=-=-=-=-=-=-
            // get the next_child resource
            if ( !_ctx.child_map().has_entry( next_child ) ) {
                std::stringstream msg;
                msg << "child map has no child by name [";
                msg << next_child << "]";
                return PASSMSG( msg.str(), err );

            }

            // =-=-=-=-=-=-=-
            // request our child resource to test it
            irods::resource_ptr resc = _ctx.child_map()[ next_child ].second;

            // =-=-=-=-=-=-=-
            // get the resource's status
            int resc_status = 0;
            err = resc->get_property<int>( irods::RESOURCE_STATUS, resc_status );
            if ( !err.ok() ) {
                return PASSMSG( "failed to get property", err );

            }

            // =-=-=-=-=-=-=-
            // forward the 'put' redirect to the appropriate child
            err = resc->call < const std::string*,
                const std::string*,
                irods::hierarchy_parser*,
                float* > (
                        _ctx.comm(),
                        irods::RESOURCE_OP_RESOLVE_RESC_HIER,
                        _ctx.fco(),
                        _opr,
                        _curr_host,
                        _out_parser,
                        _out_vote );
            if ( !err.ok() ) {
                rodsLog(
                        LOG_ERROR,
                        "forward of put redirect failed" );
                continue;

            }

            if( *_out_vote > 0 ) {
                // =-=-=-=-=-=-=-
                // we found a valid child, set out variable
                child_found = true;
            }
            else {
                // =-=-=-=-=-=-=-
                // update the next_child as we do not have a valid child yet
                err = update_next_child_resource( _ctx.prop_map() );
                if ( !err.ok() ) {
                    return PASSMSG( "update_next_child_resource failed", err );
                }
            }

        } // while

        // =-=-=-=-=-=-=-
        // return appropriately
        if ( child_found ) {
            return SUCCESS();
        }
        else {
            return ERROR(
                       NO_NEXT_RESC_FOUND,
                       "no valid child found" );
        }

    } // get_next_valid_child_resource