Ejemplo n.º 1
0
 void dir_cpi_impl::sync_is_dir (bool    & is_dir, 
                                 saga::url url)
 {
    instance_data idata (this);
    is_dir = false;
   
    saga::url dir_url(idata->location_);
    boost::filesystem::path name (url.get_path(), boost::filesystem::native);
    boost::filesystem::path path (idata->location_.get_path(), boost::filesystem::native);
   
    if ( ! name.has_root_path () )
      path /= name;
    else
      path = name;
   
    if(hdfsExists(fs_, path.string().c_str()) == 0)
    {
       //Check to see if it is a directory
       hdfsFileInfo *info;
       instance_data idata(this);
    
       info = hdfsGetPathInfo(fs_, path.string().c_str());
       if(info == NULL)
       {
          SAGA_ADAPTOR_THROW("file_cpi_impl::init failed",
                           saga::NoSuccess);
       }
       if(info->mKind == kObjectKindDirectory)
          is_dir = true;
       hdfsFreeFileInfo(info, 1);
     }
 }
//// connection pool handling - remove a handle //////////////////////////////
//
void adaptor::removeConnectionHandle (const saga::url url)
{
    // extract protocol, server & port from given url
    std::string location("");
    location.append(url.get_scheme());
    location.append("://");
    location.append(url.get_host());
    
    if( RLSConnectionPool_ == NULL )
    {
        return;
    }
    else
    {
        RLSConnectionPool_->erase(location);
    }
}
Ejemplo n.º 3
0
void logical_directory_cpi_impl::sync_make_dir(saga::impl::void_t&, saga::url url,
    int flags)
{
//    SAGA_ADAPTOR_THROW ("Not implemented! sync_make_dir", saga::NotImplemented);
	SAGA_LOG_DEBUG("dir, sync_make_dir()");
	check_state();

	saga::url irods_url_org;
	this->sync_get_cwd(irods_url_org); // to get rid of the /. at the end...
	std::string irods_path = irods_url_org.get_path();

	std::string mkdir_path;
	boost::filesystem::path i_path(url.get_path());
	if (i_path.has_root_path()){
		mkdir_path = url.get_path();
	}
	else {
		mkdir_path = irods_url_org.get_path() + "/" + url.get_path();
	}

	// to get rid of the / at the end the mkdir_path
	if (mkdir_path.substr(mkdir_path.size()-1,1) == "/"){
		mkdir_path.erase(mkdir_path.size()-1);
	}

	bool exists = false;
	try {
		exists  = irdsdir.exists(mkdir_path);
	}
	catch (boost::system::system_error const& e) {
		SAGA_ADAPTOR_THROW(e.what(), saga::NoSuccess);
	}

	if (exists){
		SAGA_ADAPTOR_THROW ("The specified target already exists. ", saga::AlreadyExists);
	}


	try {
//		std::cout<< "mkdir_path    :" << mkdir_path << std::endl;
		irdsdir.make_dir(mkdir_path, flags);
	}
	catch (boost::system::system_error const& e) {
		SAGA_ADAPTOR_THROW(e.what(), saga::NoSuccess);
	}
}
Ejemplo n.º 4
0
void logical_directory_cpi_impl::sync_is_entry(bool& is_entry, saga::url url)
{
//    SAGA_ADAPTOR_THROW ("Not implemented! sync_is_entry", saga::NotImplemented);

	SAGA_LOG_CRITICAL("call namespace, dir, sync_is_entry()");

	SAGA_LOG_DEBUG("sync_is_entry()");
	check_state();

	saga::url irods_url_org;
	this->sync_get_cwd(irods_url_org); // to get rid of the /. at the end...
	std::string irods_path = irods_url_org.get_path();

	std::string check_path;
	boost::filesystem::path i_path(url.get_path());
	if (i_path.has_root_path()){
		check_path = url.get_path();
	}
	else {
		check_path = irods_url_org.get_path() + "/" + url.get_path();
	}

	// to get rid of the / at the end the check_path
	if (check_path.substr(check_path.size()-1,1) == "/"){
		check_path.erase(check_path.size()-1);
	}

	bool exists = false;
	try {
		exists  = irdsdir.exists(check_path);
	}
	catch (boost::system::system_error const& e) {
		SAGA_ADAPTOR_THROW(e.what(), saga::NoSuccess);
	}

	if (!exists){
		SAGA_ADAPTOR_THROW ("The specified entry does not exist. ", saga::DoesNotExist);
	}

	try {
		is_entry  = irdsdir.is_entry(check_path);
	}
	catch (boost::system::system_error const& e) {
		SAGA_ADAPTOR_THROW(e.what(), saga::NoSuccess);
	}
}
    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);
    }
Ejemplo n.º 6
0
void logical_directory_cpi_impl::sync_remove(saga::impl::void_t&, saga::url url,
    int flags)
{
//    SAGA_ADAPTOR_THROW ("Not implemented! sync_remove", saga::NotImplemented);
	SAGA_LOG_DEBUG("dir, sync_remove(src, dst, flags)");
	check_state();

	saga::url irods_url_org;
	this->sync_get_cwd(irods_url_org); // to get rid of the /. at the end...
	std::string irods_path = irods_url_org.get_path();

	std::string rm_path;
	boost::filesystem::path i_path(url.get_path());
	if (i_path.has_root_path()){
		rm_path = url.get_path();
	}
	else {
		rm_path = irods_url_org.get_path() + "/" + url.get_path();
	}

	// to get rid of the / at the end the rm_path
	if (rm_path.substr(rm_path.size()-1,1) == "/"){
		rm_path.erase(rm_path.size()-1);
	}

	bool exists = false;
	try {
		exists  = irdsdir.exists(rm_path);
	}
	catch (boost::system::system_error const& e) {
		SAGA_ADAPTOR_THROW(e.what(), saga::NoSuccess);
	}

	if (!exists){
		SAGA_ADAPTOR_THROW ("The specified source entry does not exist. ", saga::DoesNotExist);
	}

	try {
//		std::cout << "rm_path=" << rm_path << std::endl;
		irdsdir.remove(rm_path, flags);
	}
	catch (boost::system::system_error const& e) {
		SAGA_ADAPTOR_THROW(e.what(), saga::NoSuccess);
	}
}
Ejemplo n.º 7
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);
     }
 }
Ejemplo n.º 8
0
  bool dir_cpi_impl::resolve( saga::url const &url_, std::string &ret )
  {
    std::string temp = url_.get_host() ; 

    if( temp.empty() )
    {

       if( (! ( url_.get_path()).empty() ))
       {
           ret = url_.get_path() ; 

           if ( url_.get_scheme().empty() &&
                url_.get_host().empty()   &&
                url_.get_path ()[0] != '/' )
           {
              return true ;      
           }

           return false ;    
      }

    }

    ret = temp ; 

    return false ; 
  }
  TR1::shared_ptr <sshfs> filesystem_adaptor::get_sshfs (const saga::session & s, 
                                                         const saga::url     & u)
  {
    // only mount anything if the URL is ssh (or any) based
    if ( u.get_scheme () != "ssh" &&
         u.get_scheme () != "any" )
    {
      SAGA_ADAPTOR_THROW_NO_CONTEXT ("Cannot mount sshfs for non-ssh urls", 
                                     saga::BadParameter);
    }

    return mount_sshfs (s, u);
  }
Ejemplo n.º 10
0
  void dir_cpi_impl::sync_remove (saga::impl::void_t & ret, 
                                  saga::url            url, 
                                  int                  flags)
  {
     instance_data idata (this);
     saga::url dir_url(idata->location_);
     boost::filesystem::path src_location (idata->location_.get_path(), boost::filesystem::native);
     // complete paths
     boost::filesystem::path src_path (url.get_path(), boost::filesystem::native);
     if ( ! src_path.has_root_path () )
         src_location /= src_path;
     else
         src_location = src_path;

     bool is_src_dir = false;
     if(hdfsExists(fs_, src_location.string().c_str()) != 0)
     {
         SAGA_ADAPTOR_THROW("directory::remove: Can't remove directory: "
           "Does not exist", saga::DoesNotExist);
     }
     else
     {
        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);

     }
     if (is_src_dir) {
         if (saga::name_space::Recursive != flags)
         {
             SAGA_ADAPTOR_THROW("directory::remove: Can't remove directory. "
                 "Please use recursive mode!", saga::BadParameter);
         }
         else {
            saga_hdfs_delete(fs_, src_location.string().c_str()); 
         }
     }
     else {
        saga_hdfs_delete(fs_, src_location.string().c_str()); 
     }
  }
Ejemplo n.º 11
0
  void dir_cpi_impl::sync_open_dir (saga::filesystem::directory & ret, 
                                    saga::url                     name, 
                                    int                           openmode)
  {

    std::string to_open ; 

    if ( name.get_scheme().empty() &&
         name.get_host().empty()   &&
         name.get_path ()[0] != '/' )
    {
       to_open += "sector://" ; 
       to_open += dir_ ; 
       to_open += '/' ; 
       to_open += name.get_path() ; 
       ret = saga::filesystem::directory ( s_, saga::url (to_open), openmode ) ; 
       return ; 
    }

    ret = saga::filesystem::directory (s_,  name, openmode ) ; 
    return ; 

  }
Ejemplo n.º 12
0
  void dir_cpi_impl::sync_open (saga::filesystem::file & ret,
                                saga::url                name,
                                int                      openmode)
  {
//    SAGA_ADAPTOR_THROW ("Not Implemented", saga::NotImplemented);

	SAGA_LOG_DEBUG("dir, sync_open()");
	check_state();

	SAGA_LOG_CRITICAL("call namespace, dir, sync_open()");

	saga::url irods_url_org;
	this->sync_get_cwd(irods_url_org); // to get rid of the /. at the end...

	std::string str_buf = "irods_url_org: " + irods_url_org.get_string();
	SAGA_LOG_CRITICAL(str_buf.c_str());


	std::string irods_path;
	boost::filesystem::path i_path(name.get_path());
	if (i_path.has_root_path()){
		irods_path = name.get_path();
	}
	else {
		irods_path = irods_url_org.get_path() + "/" + name.get_path();
	}

	saga::url open_url;
	this->sync_get_cwd(open_url); // to get rid of the /. at the end...
	open_url.set_path(irods_path);

	str_buf = "open_url: " + open_url.get_string();
	SAGA_LOG_CRITICAL(str_buf.c_str());

	saga::filesystem::file file(open_url, openmode);
	ret = file;
  }
Ejemplo n.º 13
0
void logical_directory_cpi_impl::sync_get_cwd(saga::url& cwd)
{
//    SAGA_ADAPTOR_THROW ("Not implemented! sync_get_cwd", saga::NotImplemented);
	SAGA_LOG_DEBUG("sync_get_cwd()");
	check_state();

	if (path.empty()) {
	  SAGA_ADAPTOR_THROW ("path is empty.", saga::NoSuccess);
	}

	adaptor_data_t  adaptorData(this);
	instance_data   instanceData (this);

	cwd = instanceData->location_;
	cwd.set_path(path.branch_path().string()); // remove last element.
}
Ejemplo n.º 14
0
 void dir_cpi_impl::sync_exists (bool    & exists, 
                                 saga::url url)
 {
    instance_data idata (this);
    
    saga::url dir_url(idata->location_);
    boost::filesystem::path name (url.get_path(), boost::filesystem::native);
    boost::filesystem::path path (idata->location_.get_path(), boost::filesystem::native);
    
    if ( ! name.has_root_path () )
      path /= name;
    else
      path = name;
    exists = false;
    if(hdfsExists(fs_, path.string().c_str()) == 0)
    {
       exists = true;
    }
 }
 bool filesystem_adaptor::is_absolute (const saga::url & u)
 {
   if ( u.get_scheme   ().empty ()  &&
        u.get_host     ().empty ()  &&
        u.get_username ().empty ()  &&
        u.get_password ().empty ()  &&
        u.get_port     ()    == -1  &&
        u.get_path     ()[0] != '/' )
   {
     return false;
   }
   
   return true;
 }
Ejemplo n.º 16
0
    void logical_file_cpi_impl::sync_add_location(saga::impl::void_t&, saga::url location)
    {

//        SAGA_ADAPTOR_THROW ("Not implemented! ", saga::NotImplemented);
    	SAGA_LOG_DEBUG("file, sync_add_location()");
    	check_state();

    	instance_data   instanceData (this);
        std::string rns_path = instanceData->location_.get_path();
        std::string loc_url = location.get_string();

//    	bool exists = false;
//    	try {
//    		exists  = rns_ldir.exists(rns_path);
//    	}
//    	catch (boost::system::system_error const& e) {
//    		SAGA_ADAPTOR_THROW(e.what(), saga::NoSuccess);
//    	}
//
//    	if (exists){
////    		SAGA_ADAPTOR_THROW ("The specified target already exists. ", saga::AlreadyExists);
//    		std::cout<< "The specified target already exists." << rns_path << std::endl;
//    		std::cout<< "Adding the location : " << location << std::endl;
//    		// rns_lfile.add_location??
//    	}


    	try {
//    		std::cout<< "rns_path : " << rns_path << std::endl;
//    		std::cout<< "loc_url  : " << loc_url  << std::endl;
    		rns_lfile.add_location(rns_path, loc_url);
    	}
    	catch (boost::system::system_error const& e) {
    		SAGA_ADAPTOR_THROW(e.what(), saga::NoSuccess);
    	}


    }
Ejemplo n.º 17
0
  void dir_cpi_impl::sync_make_dir (saga::impl::void_t & ret, 
                                    saga::url            url, 
                                    int                  flags)
  {
     instance_data idata (this);
    
     // verify current working directory is local
     saga::url dir_url(idata->location_);
    
     boost::filesystem::path src_location (idata->location_.get_path(), boost::filesystem::native);
     // complete paths
     boost::filesystem::path src_path (url.get_path(), boost::filesystem::native);
    
     if ( ! src_path.has_root_path () )
         src_location /= src_path;
     else
         src_location = src_path;

     if(hdfsCreateDirectory(fs_, src_location.string().c_str()) != 0)
     {
        SAGA_ADAPTOR_THROW("Could not create directory", saga::NoSuccess);
     }
  }
    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()); 
        }
    }
Ejemplo n.º 19
0
  void file_cpi_impl::sync_copy (saga::impl::void_t & ret, 
                                 saga::url            dest, 
                                 int                  flags)
  {
    adaptor_data_t       adata (this);
    file_instance_data_t idata (this);

    // check preconditions
    // We can only check coditions for local targets
    
    if ( saga::adaptors::utils::is_local_address (dest) )
    {
      saga::filesystem::directory loc ("/");

      if ( loc.exists (dest.get_path ()) )
      {
        if ( ! (flags & saga::name_space::Overwrite) )
        {
          std::stringstream ss;
          ss << "Target exists: " << dest;
          SAGA_ADAPTOR_THROW (ss.str (), saga::AlreadyExists);
        }
      }
    }

    std::string src (u_.get_string ());
    std::string tgt (dest.get_string ());


    CURLcode code;

    // get handle for input and output curl ops (see README)
    CURL * in  = adata->get_curl_handle_in  ();
    CURL * out = adata->get_curl_handle_out ();

    // create buffer file
    FILE * buf = ::fopen ("/tmp/curl-cache.dat", "w+");
    ensure (NULL != buf, "fopen() failed: ", ::strerror (errno));

    // read data into buffer
    code = curl_easy_setopt (in, CURLOPT_URL, src.c_str ());
    ensure (0 == code, "Curl Error: ", curl_easy_strerror (code));

    code = curl_easy_setopt (in, CURLOPT_WRITEDATA, buf);
    ensure (0 == code, "Curl Error: ", curl_easy_strerror (code));

    code = curl_easy_perform (in);
    ensure (0 == code, "Curl Error: ", curl_easy_strerror (code));


    // data are in buffer - now rewind buffer, and copy data to target location
    ::rewind (buf);

    code = curl_easy_setopt (out, CURLOPT_URL, tgt.c_str ());
    ensure (0 == code, "Curl Error: ", curl_easy_strerror (code));

    code = curl_easy_setopt (out, CURLOPT_VERBOSE, "true");
    ensure (0 == code, "Curl Error: ", curl_easy_strerror (code));

    code = curl_easy_setopt (out, CURLOPT_USERPWD, "merzky:Z(I)nfandel");
    ensure (0 == code, "Curl Error: ", curl_easy_strerror (code));

    code = curl_easy_setopt (out, CURLOPT_UPLOAD, "true");
    ensure (0 == code, "Curl Error: ", curl_easy_strerror (code));

    code = curl_easy_setopt (out, CURLOPT_READDATA, buf);
    ensure (0 == code, "Curl Error: ", curl_easy_strerror (code));

    code = curl_easy_perform (out);
    ensure (0 == code, "Curl Error: ", curl_easy_strerror (code));

    ::fclose (buf);

    // done :-)
  }
Ejemplo n.º 20
0
 inline void remove_drive(saga::url& u)
 {
   std::string p(u.get_path());
   if (p.size() >= 2 && std::isalpha(p[0]) && p[1] == ':')
     u.set_path(p.substr(2));
 }
Ejemplo n.º 21
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);
        }
     }
  }
double compare(saga::url testUrl, saga::url baseUrl) {
   // Need to create tmp names, since I need ImageMagick to understand the names
   // therefore I need to copy the images to those files
   // If I can get imagemagick to read directly from the url, I woudn't waste
   // the time in copying files...  
   char tName[] = "/tmp/testImgXXXXXX";
   char bName[] = "/tmp/baseImgXXXXXX";
   std::cerr << "about to generate names!" << std::endl;
   int testFile = mkstemp(tName);
   std::cerr << "got one (" << tName << ")" << std::endl;
   if(testFile == -1) 
      perror(NULL);
   int baseFile = mkstemp(bName);
   std::cerr << "got two (" << bName << ")" << std::endl;
   if(baseFile == -1) 
      perror(NULL);

   std::cerr << "Before copying the files... " << std::endl; 
   
   saga::size_t const KB64 = 1024*64; //64KB
   saga::size_t bytesRead;
   std::cerr << "about to open files (" << testUrl.get_string() << ", " << baseUrl.get_string() << ")" << std::endl;
   saga::filesystem::file test(testUrl, saga::filesystem::Read);
   std::cerr << "1opened!" << std::endl;
   saga::filesystem::file base    (baseUrl    , saga::filesystem::Read);
   std::cerr << "2opened!" << std::endl;
   
   char data[KB64+1];
   std::cerr << "about to read" << std::endl;
   try {
      while((bytesRead = test.read(saga::buffer(data,KB64)))!=0) {
         std::cerr << "read from testFile" << std::endl;
         int retval = write(testFile, data, bytesRead);
         if(retval < 0)
            perror(NULL);
      }
   }
   catch(saga::exception const & e) {
      std::cerr << "Exception caught: " << e.what() << std::endl;
   }
   test.close();
   fsync(testFile);
   close(testFile);
   try {
      while((bytesRead = base.read(saga::buffer(data,KB64)))!=0) {
         std::cerr << "read from baseFile" << std::endl;
         std::cerr << "size = " << base.get_size() << std::endl;
         int retval = write(baseFile, data, bytesRead);
         if(retval < 0)
            perror(NULL);
      }
   }
   catch(saga::exception const & e) {
      std::cerr << "Exception caught: " << e.what() << std::endl;
   }
   base.close();
   fsync(baseFile);
   close(baseFile);
   
   std::cerr << "Just before Image magick" << std::endl;
   
   MagickWand *magick_wand_1;
   MagickWand *magick_wand_2;
   MagickWand *compare_wand;
   double difference;
   MagickBooleanType status_1, status_2;
   
   MagickWandGenesis();
   magick_wand_1=NewMagickWand();
   status_1=MagickReadImage(magick_wand_1,bName);
   if (status_1 == MagickFalse)
	   ThrowWandException(magick_wand_1);
   MagickWandGenesis();
   magick_wand_2=NewMagickWand();
   status_2=MagickReadImage(magick_wand_2,tName);
   if (status_2 == MagickFalse)
	   ThrowWandException(magick_wand_2);
   compare_wand = NewMagickWand();
   compare_wand=MagickCompareImages(magick_wand_1,magick_wand_2, AbsoluteErrorMetric, &difference);
   std::cerr << "Difference is: " << difference << std::endl;
   
   DestroyMagickWand(magick_wand_1);
   DestroyMagickWand(magick_wand_2);

   MagickWandTerminus();
   remove(bName);
   remove(tName);
   return difference;
}
Ejemplo n.º 23
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);
     }
  }
void dir_cpi_impl::sync_copy (saga::impl::void_t & ret, saga::url src, 
                              saga::url dst, int flags)
{
    adaptor_data_t AdaptorData(this);
    directory_instance_data_t InstanceData (this);
    
    if(dst.get_scheme().empty() && dst.get_host().empty())
    {
        SAGA_OSSTREAM strm;
        strm << "Could not copy [" << InstanceData->location_ << " -> " << dst
        << "]. Please specify scheme and/or hostname.";
        SAGA_ADAPTOR_THROW(SAGA_OSSTREAM_GETSTRING(strm), saga::BadParameter);                                     
    }
    
    if(dst.get_scheme() == "file")
    {
    	if(dst.get_host() != "localhost") {
            SAGA_OSSTREAM strm;
            strm << "Could not copy [" << InstanceData->location_ << " -> " << dst
            << "]. If target URL scheme is 'file://', only 'localhost' is accepted as host.";
           SAGA_ADAPTOR_THROW(SAGA_OSSTREAM_GETSTRING(strm), saga::BadParameter);   
        }
        
        // avoid file:// -> file:// copy.
        if (InstanceData->location_.get_scheme() != "gridftp" 
	     && InstanceData->location_.get_scheme() != "gsiftp")
	    {
            SAGA_OSSTREAM strm;
            strm << "Cannot copy file [" << InstanceData->location_ << "]. " 
                 << "Supported source URL schemes are: gridftp:// and gsiftp://";
            SAGA_ADAPTOR_THROW(SAGA_OSSTREAM_GETSTRING(strm), saga::adaptors::AdaptorDeclined);
	    }           

    }
    else
    {
        if(dst.get_scheme() != "gridftp" && dst.get_scheme() != "gsiftp" )
        {
            SAGA_OSSTREAM strm;
            strm << "Could not copy [" << InstanceData->location_ << " -> " << dst
            << "]. Only gridftp:// and gsiftp:// and file:// schemes are supported for target urls.";
            SAGA_ADAPTOR_THROW(SAGA_OSSTREAM_GETSTRING(strm), saga::BadParameter);         
        }
    }
        
    this->check_if_open ("dir_cpi_impl::sync_copy", InstanceData->location_);
    
    saga::url u_src = merge_urls(InstanceData->location_.get_url(), src);
    saga::url u_dst = merge_urls(InstanceData->location_.get_url(), dst);
    
    try {
        
        GridFTPConnection * ConnectionHandle = 
        AdaptorData->getConnectionHandleForURL(InstanceData->location_, write_log_, logfile_loc_);
        
        if(ConnectionHandle->exist(u_dst.get_url())) {
			if(ConnectionHandle->is_dir(u_dst.get_url())) {
				std::string url_path = u_dst.get_path();
				if(url_path.rfind("/") != url_path.length()-1) url_path.append("/");
				saga::url this_name; this->sync_get_name(this_name);
				url_path.append(this_name.get_path());
				u_dst.set_path(url_path);
            }
		}
        ConnectionHandle->copy_url(u_src.get_url(), u_dst.get_url());
    }
    catch( globus_gridftp_file_adaptor::exception const & e )
    {
        error_package ep = globus_gridftp_file_adaptor
        ::error_default_redirect(e, u_src.get_url());
        SAGA_OSSTREAM strm;
        strm << "Could not copy [" << u_src << " -> " << u_dst
        << "]. " << ep.error_text;
        SAGA_ADAPTOR_THROW(SAGA_OSSTREAM_GETSTRING(strm), ep.saga_error);  
    }
    
}