void logical_file_cpi_impl::sync_update_location(saga::impl::void_t& ret, 
                                                     saga::url oldlocation, saga::url newlocation)
    {
        adaptor_data_t  adaptorData(this);
        instance_data   instanceData (this);
        saga::url lfn_url(instanceData->location_);
        
        this->check_if_open ("logical_file_cpi_impl::sync_update_location", instanceData->location_);
        
        check_permissions(saga::replica::Write, "update_location", lfn_url.get_url());
        
        bool oldExists = false; // worst case - update will fail
        bool newExists = true;  //
        
        SAGA_OSSTREAM strm;
        strm << "Could not update location for logical file ["
        << instanceData->location_ << "]. ";
        
        try {
            RLSConnection * RLSHandle = 
			adaptorData->getConnectionHandle(instanceData->location_);
            oldExists = RLSHandle->LFNtoPFNMappingExists(lfn_url.get_path(), 
                                                         oldlocation.get_url());
            newExists = RLSHandle->LFNtoPFNMappingExists(lfn_url.get_path(), 
                                                         newlocation.get_url());
        }
        catch(globus_rls_replica_adaptor::exception const & e)
        {
            strm << e.RLSErrorText();
            SAGA_ADAPTOR_THROW(SAGA_OSSTREAM_GETSTRING(strm), e.SAGAError()); 
        }
        
        if(!oldExists) {
            strm << "PFN: [" << oldlocation << "] doesn't exist!";
            SAGA_ADAPTOR_THROW(SAGA_OSSTREAM_GETSTRING(strm), saga::DoesNotExist);
        }
        
        if(newExists) {
            strm << "PFN: [" << newlocation << "] already exist!";
            SAGA_ADAPTOR_THROW(SAGA_OSSTREAM_GETSTRING(strm), saga::AlreadyExists);
        }
        
        // everyting seems to be ok. let's update the LFN
        sync_add_location(ret, newlocation);
        sync_remove_location(ret, oldlocation);
    }
Exemple #2
0
 /**
 * adds file profile to Grid Service Object
 */
 void cpr_checkpoint_cpi_impl::sync_add_file (int &ret,
                                                saga::url url)
 {
     std::string guid;
     {//scoped lock
           adaptor_data_t d(this);
           guid = d->migol_guid;
           if ( guid == "")
           {
             SAGA_ADAPTOR_THROW (std::string ("Migol infrastructure could not be initialized."), 
                                 saga::IncorrectState);
           }
           std::cout << "cpr_checkpoint_cpi_impl::add_file: " << guid << std::endl;
     }
     
     // translate 'any' and 'cpr' url schemes to lfn, decline all others
     std::string scheme (url.get_scheme ());
     
     if ( ! scheme.empty () && 
         scheme != "gsiftp")
     {
         SAGA_OSSTREAM strm;
         strm << "cpr::migol_cpr_checkpoint_cpi_impl::add_file: "
         "cannot handle checkpoint name: " << url;
         SAGA_ADAPTOR_THROW(SAGA_OSSTREAM_GETSTRING(strm), saga::BadParameter);
     }
     
     bool result = false;
     {
         result =  migol::instance()->register_checkpoint(guid, url.get_url());
     }
     
     if (!result)
     { 
         SAGA_OSSTREAM strm;
         strm << "cpr::migol_cpr_checkpoint_cpi_impl::add_file: "
         "cannot handle checkpoint name: " << url.get_url();
         SAGA_ADAPTOR_THROW(SAGA_OSSTREAM_GETSTRING(strm), saga::BadParameter);
     }
 }
    void logical_file_cpi_impl::sync_remove_location(saga::impl::void_t&, saga::url location)
    {
        adaptor_data_t  adaptorData(this);
        instance_data   instanceData (this);
        saga::url lfn_url(instanceData->location_);
        
        this->check_if_open ("logical_file_cpi_impl::sync_remove_location", instanceData->location_);
        
        check_permissions(saga::replica::Write, "remove_location", lfn_url.get_url());
        
        try {
            RLSConnection * RLSHandle = 
			adaptorData->getConnectionHandle(instanceData->location_);
            RLSHandle->LFNRemovePFN(lfn_url.get_path(), location.get_url());
        }
        catch(globus_rls_replica_adaptor::exception const & e)
        {
            SAGA_OSSTREAM strm;
            strm << "Could not remove location from logical file [" << 
            instanceData->location_ << "]. " << e.RLSErrorText();
            SAGA_ADAPTOR_THROW(SAGA_OSSTREAM_GETSTRING(strm), e.SAGAError()); 
        }
    }
Exemple #4
0
  void dir_cpi_impl::sync_move (saga::impl::void_t & ret, 
                                saga::url            src, 
                                saga::url            dest, 
                                int                  flags)
  {
     instance_data idata (this);
     
     // verify current working directory is local
     saga::url url(idata->location_);
     
     // handle the files
     boost::filesystem::path src_location (idata->location_.get_path(), boost::filesystem::native);
     boost::filesystem::path dst_location (src_location);
     // complete paths
     boost::filesystem::path src_path  (src.get_path(), boost::filesystem::native);
     boost::filesystem::path dest_path (dest.get_path(), boost::filesystem::native);
     
     if ( ! src_path.has_root_path () )
         src_location /= src_path;
     else
         src_location = src_path;
     
     if ( ! dest_path.has_root_path () )
         dst_location /= dest_path;
     else
         dst_location = dest_path;
     
     bool is_src_dir;
     bool is_dst_dir;
     if(hdfsExists(fs_, src_location.string().c_str()) == 0)
     {
        //Check to see if it is a directory
        hdfsFileInfo *info;
       
        info = hdfsGetPathInfo(fs_, src_location.string().c_str());
        if(info == NULL)
        {
           SAGA_ADAPTOR_THROW("file_cpi_impl::init failed",
                            saga::NoSuccess);
        }
        if(info->mKind == kObjectKindDirectory)
           is_src_dir = true;
        else
           is_src_dir = false;
        hdfsFreeFileInfo(info, 1);
     }
     bool dst_exists = false;
     if(hdfsExists(fs_, dst_location.string().c_str()) == 0)
     {
        dst_exists = true;
        //Check to see if it is a directory
        hdfsFileInfo *info;
       
        info = hdfsGetPathInfo(fs_, dst_location.string().c_str());
        if(info == NULL)
        {
           SAGA_ADAPTOR_THROW("file_cpi_impl::init failed",
                            saga::NoSuccess);
        }
        if(info->mKind == kObjectKindDirectory)
           is_dst_dir = true;
        else
           is_dst_dir = false;
        hdfsFreeFileInfo(info, 1);
     }
     
     if (!is_src_dir && is_dst_dir)
         dst_location /= src_location.leaf();
     
     if ((flags & saga::name_space::Overwrite) && dst_exists) {
/*         if (is_dst_dir)
             fs::remove_all(dst_location);*/
        saga_hdfs_delete(fs_, dst_location.string().c_str()); 
     }
     // if destination still exists raise an error
     dst_exists = false;
     if(hdfsExists(fs_, dst_location.string().c_str()) == 0)
     {
        SAGA_OSSTREAM strm;
        strm << "namespace_dir_cpi_impl<Base>::sync_move: "
            "target file already exists: " << dest.get_url();
        SAGA_ADAPTOR_THROW(SAGA_OSSTREAM_GETSTRING(strm), saga::AlreadyExists);
     }
     if(hdfsMove(fs_, src_location.string().c_str(), fs_, dst_location.string().c_str()) != 0)
     {
        SAGA_ADAPTOR_THROW("Unable to move files", saga::NoSuccess);
     }
  }
Exemple #5
0
  void dir_cpi_impl::sync_copy (saga::impl::void_t & ret, 
                                saga::url            src, 
                                saga::url            dst, 
                                int                  flags)
  {
     instance_data idata (this);
     saga::url url(idata->location_);
   
     // handle the files
     boost::filesystem::path src_location (idata->location_.get_path(), boost::filesystem::native);
     boost::filesystem::path dst_location (src_location);
   
     // complete paths
     boost::filesystem::path src_path  (src.get_path(), boost::filesystem::native);
     boost::filesystem::path dest_path (dst.get_path(), boost::filesystem::native);
   
     if ( ! src_path.has_root_path () )
         src_location /= src_path;
     else
         src_location = src_path;
   
     if ( ! dest_path.has_root_path () )
         dst_location /= dest_path;
     else
         dst_location = dest_path;

     bool is_src_dir = false;
     if(hdfsExists(fs_, src_location.string().c_str()) == 0)
     {
        //Check to see if it is a directory
        hdfsFileInfo *info;

        info = hdfsGetPathInfo(fs_, src_location.string().c_str());
        if(info == NULL)
        {
           SAGA_ADAPTOR_THROW("file_cpi_impl::init failed",
              saga::NoSuccess);
        }
        if(info->mKind == kObjectKindDirectory)
           is_src_dir = true;
        hdfsFreeFileInfo(info, 1);
     }
     // src location refers to a is a directory
     if (is_src_dir) {
        SAGA_ADAPTOR_THROW("Cannot copy directory at moment.", saga::NotImplemented);
     }
     else {
         //Check to see if dst_location is a directory
        bool is_dst_dir = false;
        bool dst_exists = false;
        if(hdfsExists(fs_, dst_location.string().c_str()) == 0)
        {
           dst_exists = true;
           //Check to see if it is a directory
           hdfsFileInfo *info;
          
           info = hdfsGetPathInfo(fs_, dst_location.string().c_str());
           if(info == NULL)
           {
              SAGA_ADAPTOR_THROW("file_cpi_impl::init failed",
                               saga::NoSuccess);
           }
           if(info->mKind == kObjectKindDirectory)
              is_dst_dir = true;
           hdfsFreeFileInfo(info, 1);
        }
        else
        {
           SAGA_ADAPTOR_THROW("Path does not exists!", saga::NoSuccess);
        }

        if (is_dst_dir)
            dst_location /= src_location.leaf();
    
        // remove the file/directory if it exists and we should overwrite
        if ((flags & saga::name_space::Overwrite) && dst_exists) {
/*            if (is_dst_dir)
                fs::remove_all(dst_location);*/
           saga_hdfs_delete(fs_, dst_location.string().c_str()); 
        }
    
        if(hdfsExists(fs_, dst_location.string().c_str()) == 0)
        {
            SAGA_OSSTREAM strm;
            strm << "namespace_dir_cpi_impl<Base>::sync_copy: "
                "target file already exists: " << dst.get_url();
            SAGA_ADAPTOR_THROW(SAGA_OSSTREAM_GETSTRING(strm), saga::AlreadyExists);
        }
        if(hdfsCopy(fs_, src_location.string().c_str(), fs_, dst_location.string().c_str()) != 0)
        {
            SAGA_OSSTREAM strm;
            strm << "namespace_dir_cpi_impl<Base>::sync_copy: "
                "target file did not copy successfully: " << dst.get_url();
            SAGA_ADAPTOR_THROW(SAGA_OSSTREAM_GETSTRING(strm), saga::NoSuccess);
        }
     }
  }