// =-=-=-=-=-=-=-
    // used to allow the resource to determine which host
    // should provide the requested operation
    irods::error impostor_resource_redirect_plugin(
        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 the context validity
        irods::error ret = _ctx.valid< irods::file_object >();
        if ( ( result = ASSERT_PASS( ret, "Invalid resource context." ) ).ok() ) {

            // =-=-=-=-=-=-=-
            // check incoming parameters
            if ( ( result = ASSERT_ERROR( _opr && _curr_host && _out_parser && _out_vote, SYS_INVALID_INPUT_PARAM, "Invalid input parameter." ) ).ok() ) {
                // =-=-=-=-=-=-=-
                // cast down the chain to our understood object type
                irods::file_object_ptr file_obj = boost::dynamic_pointer_cast< irods::file_object >( _ctx.fco() );

                // =-=-=-=-=-=-=-
                // get the name of this resource
                std::string resc_name;
                ret = _ctx.prop_map().get< std::string >( irods::RESOURCE_NAME, resc_name );
                if ( ( result = ASSERT_PASS( ret, "Failed in get property for name." ) ).ok() ) {
                    // =-=-=-=-=-=-=-
                    // add ourselves to the hierarchy parser by default
                    _out_parser->add_child( resc_name );

                    // =-=-=-=-=-=-=-
                    // test the operation to determine which choices to make
                    if ( irods::OPEN_OPERATION  == ( *_opr ) ||
                            irods::WRITE_OPERATION == ( *_opr ) ) {
                        // =-=-=-=-=-=-=-
                        // call redirect determination for 'get' operation
                        ret = impostor_resource_redirect_open( _ctx.prop_map(), file_obj, resc_name, ( *_curr_host ), ( *_out_vote ) );
                        result = ASSERT_PASS_MSG( ret, "Failed redirecting for open." );

                    }
                    else if ( irods::CREATE_OPERATION == ( *_opr ) ) {
                        // =-=-=-=-=-=-=-
                        // call redirect determination for 'create' operation
                        ret = impostor_resource_redirect_create( _ctx.prop_map(), file_obj, resc_name, ( *_curr_host ), ( *_out_vote ) );
                        result = ASSERT_PASS_MSG( ret, "Failed redirecting for create." );
                    }

                    else {
                        // =-=-=-=-=-=-=-
                        // must have been passed a bad operation
                        result = ASSERT_ERROR( false, INVALID_OPERATION, "Operation not supported." );
                    }
                }
            }
        }

        return result;

    } // impostor_resource_redirect_plugin
示例#2
0
    /// =-=-=-=-=-=-=-
    /// @brief interface to notify of a file modification
    irods::error random_file_modified(
        irods::resource_plugin_context& _ctx ) {
        irods::error result = SUCCESS();

        // =-=-=-=-=-=-=-
        // get the child resc to call
        irods::resource_ptr resc;
        irods::error err = random_get_resc_for_call< irods::file_object >( _ctx, resc );
        if ( ( result = ASSERT_PASS( err, "Failed selecting random resource." ) ).ok() ) {

            // =-=-=-=-=-=-=-
            // call rename on the child
            err = resc->call( _ctx.comm(), irods::RESOURCE_OP_MODIFIED, _ctx.fco() );
            result = ASSERT_PASS_MSG( err, "Failed calling child operation." );
        }

        return result;
    } // random_file_modified
示例#3
0
    // =-=-=-=-=-=-=-
    /// @brief interface for POSIX closedir
    irods::error random_file_closedir(
        irods::resource_plugin_context& _ctx ) {
        irods::error result = SUCCESS();

        // =-=-=-=-=-=-=-
        // get the child resc to call
        irods::resource_ptr resc;
        irods::error err = random_get_resc_for_call< irods::collection_object >( _ctx, resc );
        if ( ( result = ASSERT_PASS( err, "Failed to select random resource." ) ).ok() ) {

            // =-=-=-=-=-=-=-
            // call closedir on the child
            err = resc->call( _ctx.comm(), irods::RESOURCE_OP_CLOSEDIR, _ctx.fco() );
            result = ASSERT_PASS_MSG( err, "Failed calling child operation." );
        }

        return result;
    } // random_file_closedir
示例#4
0
    // =-=-=-=-=-=-=-
    // interface for POSIX Open
    irods::error random_file_open(
        irods::resource_plugin_context& _ctx ) {
        irods::error result = SUCCESS();

        // =-=-=-=-=-=-=-
        // get the child resc to call
        irods::resource_ptr resc;
        irods::error err = random_get_resc_for_call< irods::file_object >( _ctx, resc );
        if ( ( result = ASSERT_PASS( err, "Failed in file open." ) ).ok() ) {

            // =-=-=-=-=-=-=-
            // call open operation on the child
            err = resc->call( _ctx.comm(), irods::RESOURCE_OP_OPEN, _ctx.fco() );
            result = ASSERT_PASS_MSG( err, "Failed calling open on the child." );
        }

        return result;
    } // random_file_open
示例#5
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 random_file_sync_to_arch(
        irods::resource_plugin_context& _ctx,
        const char*                         _cache_file_name ) {
        irods::error result = SUCCESS();

        // =-=-=-=-=-=-=-
        // get the child resc to call
        irods::resource_ptr resc;
        irods::error err = random_get_resc_for_call< irods::file_object >( _ctx, resc );
        if ( ( result = ASSERT_PASS( err, "Failed selecting random resource." ) ).ok() ) {

            // =-=-=-=-=-=-=-
            // call synctoarch on the child
            err = resc->call< const char* >( _ctx.comm(), irods::RESOURCE_OP_SYNCTOARCH, _ctx.fco(), _cache_file_name );
            result = ASSERT_PASS_MSG( err, "Failed calling child operation." );
        }

        return result;
    } // random_file_sync_to_arch
示例#6
0
    /// =-=-=-=-=-=-=-
    /// @brief interface for POSIX rename
    irods::error random_file_rename(
        irods::resource_plugin_context& _ctx,
        const char*                         _new_file_name ) {
        irods::error result = SUCCESS();

        // =-=-=-=-=-=-=-
        // get the child resc to call
        irods::resource_ptr resc;
        irods::error err = random_get_resc_for_call< irods::file_object >( _ctx, resc );
        if ( ( result = ASSERT_PASS( err, "Failed to select random resource." ) ).ok() ) {

            // =-=-=-=-=-=-=-
            // call rename on the child
            err = resc->call< const char* >( _ctx.comm(), irods::RESOURCE_OP_RENAME, _ctx.fco(), _new_file_name );
            result = ASSERT_PASS_MSG( err, "Failed calling child operation." );
        }

        return result;
    } // random_file_rename
示例#7
0
    /// =-=-=-=-=-=-=-
    /// @brief interface for POSIX Stat
    irods::error random_file_stat(
        irods::resource_plugin_context& _ctx,
        struct stat*                     _statbuf ) {
        irods::error result = SUCCESS();

        // =-=-=-=-=-=-=-
        // get the child resc to call
        irods::resource_ptr resc;
        irods::error err = random_get_resc_for_call< irods::data_object >( _ctx, resc );
        if ( ( result = ASSERT_PASS( err, "Failed selecting random child resource." ) ).ok() ) {

            // =-=-=-=-=-=-=-
            // call stat on the child
            err = resc->call< struct stat* >( _ctx.comm(), irods::RESOURCE_OP_STAT, _ctx.fco(), _statbuf );
            result = ASSERT_PASS_MSG( err, "Failed in call to child operation." );
        }

        return result;
    } // random_file_stat
示例#8
0
    /// =-=-=-=-=-=-=-
    /// @brief interface for POSIX lseek
    irods::error random_file_lseek(
        irods::resource_plugin_context& _ctx,
        long long                        _offset,
        int                              _whence ) {
        irods::error result = SUCCESS();

        // =-=-=-=-=-=-=-
        // get the child resc to call
        irods::resource_ptr resc;
        irods::error err = random_get_resc_for_call< irods::file_object >( _ctx, resc );
        if ( ( result = ASSERT_PASS( err, "Failed to select random child." ) ).ok() ) {

            // =-=-=-=-=-=-=-
            // call lseek on the child
            err = resc->call< long long, int >( _ctx.comm(), irods::RESOURCE_OP_LSEEK, _ctx.fco(), _offset, _whence );
            result = ASSERT_PASS_MSG( err, "Failed calling child operation." );
        }

        return result;
    } // random_file_lseek
示例#9
0
    /// =-=-=-=-=-=-=-
    /// @brief interface for POSIX Write
    irods::error random_file_write(
        irods::resource_plugin_context& _ctx,
        void*                               _buf,
        int                                 _len ) {
        irods::error result = SUCCESS();

        // =-=-=-=-=-=-=-
        // get the child resc to call
        irods::resource_ptr resc;
        irods::error err = random_get_resc_for_call< irods::file_object >( _ctx, resc );
        if ( ( result = ASSERT_PASS( err, "Failed choosing child resource." ) ).ok() ) {

            // =-=-=-=-=-=-=-
            // call write on the child
            err = resc->call< void*, int >( _ctx.comm(), irods::RESOURCE_OP_WRITE, _ctx.fco(), _buf, _len );
            result = ASSERT_PASS_MSG( err, "Failed calling operation on child resource." );
        }

        return result;
    } // random_file_write
示例#10
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 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 ( ( result = ASSERT_PASS( err, "Failed to get next child in the hierarchy." ) ).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_MSG( err, "Failed calling child operation." );
                        }
                    }
                    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