/////////////////////////////////////////////////////////////////////////////// // throws : BadParameter void helper::check_scheme(saga::url& rm, bool local_ok) { std::string scheme(rm.get_scheme()); if (scheme == "rns") { std::cout << "RNS good" << std::endl; return; } if (scheme.empty() || scheme == "file") { if (local_ok) { SAGA_LOG_DEBUG("local file."); return; } else { SAGA_OSSTREAM strm; strm << "Could not initialize file for [" << rm << "]. " << "Only any:// and rns:// " << "schemes are supported."; SAGA_ADAPTOR_THROW_NO_CONTEXT(SAGA_OSSTREAM_GETSTRING(strm), saga::BadParameter); } } //SRA : rns if (!(scheme == "irods" || scheme == "any")) { SAGA_OSSTREAM strm; strm << "Could not initialize file for [" << rm << "]. " << "Only any:// and rns:// " << "schemes are supported."; SAGA_ADAPTOR_THROW_NO_CONTEXT(SAGA_OSSTREAM_GETSTRING(strm), saga::BadParameter); } }
omii_gridsam_job_service::omii_gridsam_job_service (proxy* p, cpi_info const& info, saga::ini::ini const& glob_ini, saga::ini::ini const& adap_ini, TR1::shared_ptr<saga::adaptor> adaptor) : base_cpi (p, info, adaptor, cpi::Noflags) { // check if we can handle this request instance_data data(this); std::string rm(data->rm_.get_url()); saga::url rm_url(rm); std::string scheme(rm_url.get_scheme()); if (scheme.empty() || (scheme != "gridsam" && scheme != "any" && scheme != "https")) { SAGA_OSSTREAM strm; strm << "Could not initialize job service for [" << data->rm_ << "]. " << "Only any://, gridsam:// and https:// schemes are supported."; SAGA_ADAPTOR_THROW(SAGA_OSSTREAM_GETSTRING(strm), saga::adaptors::AdaptorDeclined); } if (rm_url.get_host().empty()) { SAGA_OSSTREAM strm; strm << "Could not initialize job service for [" << data->rm_ << "]. " << "No hostname given."; SAGA_ADAPTOR_THROW(SAGA_OSSTREAM_GETSTRING(strm), saga::BadParameter); } // use the rm as provided endpoint_ = rm; }
file_transfer_ptr file_transfer_parser_impl::parse(std::string spec) const { std::string left, right; saga::adaptors::file_transfer_operator mode; if (!parse_file_transfer_specification(spec, left, mode, right)) { SAGA_OSSTREAM strm; strm << "Parse failed: " << "(FileTransfer entry: '" << spec << "')."; SAGA_ADAPTOR_THROW_NO_CONTEXT(SAGA_OSSTREAM_GETSTRING(strm), saga::BadParameter); throw; } #if 0 if (!check_filename(left) || !check_filename(right)) { SAGA_OSSTREAM strm; strm << "Cannot handle the specified URL " << "(FileTransfer entry: '" << spec << "')."; SAGA_ADAPTOR_THROW_NO_CONTEXT(SAGA_OSSTREAM_GETSTRING(strm), saga::IncorrectURL); } #endif file_transfer_ptr p; switch (mode) { case saga::adaptors::copy_local_remote: p = file_transfer_ptr(new file_transfer_impl(left, right, file_transfer::in)); break; case saga::adaptors::copy_remote_local: p = file_transfer_ptr(new file_transfer_impl(right, left, file_transfer::out)); break; case saga::adaptors::append_local_remote: case saga::adaptors::append_remote_local: { SAGA_OSSTREAM strm; strm << "Append operation is unsupported " << "(FileTransfer entry: '" << spec << "')."; SAGA_ADAPTOR_THROW_NO_CONTEXT(SAGA_OSSTREAM_GETSTRING(strm), saga::NotImplemented); } break; case saga::adaptors::unknown_mode: default: { // from condor SAGA_OSSTREAM strm; strm << "Unknown FileTransfer operator " << "(FileTransfer entry: '" << spec << "')."; SAGA_ADAPTOR_THROW_NO_CONTEXT(SAGA_OSSTREAM_GETSTRING(strm), saga::BadParameter); } break; } return p; }
file_cpi_impl::file_cpi_impl (proxy * p, cpi_info const & info, saga::ini::ini const & glob_ini, saga::ini::ini const & adap_ini, boost::shared_ptr <saga::adaptor> adaptor) : file_cpi (p, info, adaptor, cpi::Noflags) { adaptor_data_t adata (this); file_instance_data_t idata (this); //SAGA_ADAPTOR_THROW ("Not Implemented (yet), but soon will be!", saga::NotImplemented); saga::url location(idata->location_); std::string host(location.get_host()); std::string scheme(location.get_scheme()); // make sure that we only allow globusonline:// URLs if (scheme != "globusonline") { SAGA_OSSTREAM strm; strm << "Could not initialize file object for [" << idata->location_ << "]. " << "Only globusonline:// schemes are supported."; SAGA_ADAPTOR_THROW(SAGA_OSSTREAM_GETSTRING(strm), saga::adaptors::AdaptorDeclined); } }
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); }
// constructor job_service_cpi_impl::job_service_cpi_impl (proxy * p, cpi_info const & info, saga::ini::ini const & glob_ini, saga::ini::ini const & adap_ini, TR1::shared_ptr <saga::adaptor> adaptor) : base_cpi (p, info, adaptor, cpi::Noflags) { instance_data data(this); if (!data->rm_.get_url().empty()) { saga::url rm(data->rm_); std::string scheme(rm.get_scheme()); if (!scheme.empty() && scheme != "pbspro" && scheme != "any") { SAGA_OSSTREAM strm; strm << "Could not initialize job service for [" << data->rm_ << "]. " << "Only any:// and pbspro:// schemes are supported."; SAGA_ADAPTOR_THROW(SAGA_OSSTREAM_GETSTRING(strm), saga::BadParameter); } localhost = rm.get_host(); if (localhost.empty()) { // TODO && local host check SAGA_OSSTREAM strm; strm << "Could not initialize job service for [" << data->rm_ << "]. " << "invalid hostname."; SAGA_ADAPTOR_THROW(SAGA_OSSTREAM_GETSTRING(strm), saga::BadParameter); } jobid_converter = helper::jobid_converter(rm); } else { SAGA_OSSTREAM strm; strm << "Could not initialize job service for [" << data->rm_ << "]. " << "Resource discovery is not available yet."; SAGA_ADAPTOR_THROW(SAGA_OSSTREAM_GETSTRING(strm), saga::BadParameter); } }
void log (T1 const & t1) { // open (); SAGA_OSSTREAM tmp; tmp << t1; // std::cout << t1; f_.write (saga::buffer (SAGA_OSSTREAM_GETSTRING (tmp))); // close (); }
// constructor job_cpi_impl::job_cpi_impl (proxy * p, cpi_info const & info, saga::ini::ini const & glob_ini, saga::ini::ini const & adap_ini, TR1::shared_ptr <saga::adaptor> adaptor) : base_cpi (p, info, adaptor, cpi::Noflags) , session_ (p->get_session ()) , state_ (saga::job::New) { instance_data idata (this); adaptor_data_type adata (this); saga::url contact_url = idata->rm_; SAGA_LOG_INFO("url: " + contact_url.get_url ()); // check if URL is usable if ( ! contact_url.get_scheme ().empty () && contact_url.get_scheme () != "drmaa" && contact_url.get_scheme () != "any" ) { SAGA_OSSTREAM strm; strm << "Could not initialize job service for [" << contact_url << "]. " << "Only these schemas are supported: any://, drmaa://, or none."; SAGA_ADAPTOR_THROW (SAGA_OSSTREAM_GETSTRING (strm), saga::adaptors::AdaptorDeclined); } // TODO: load drmaa && drmaa_init SAGA_LOG_INFO("getting DRMAA singleton"); drmaa_ = &(saga::adaptors::utils::get_singleton<psnc_drmaa::drmaa>()); if ( idata->init_from_jobid_ ) { jobid_ = idata->jobid_; state_ = drmaa_->get_state(jobid_); } else { // init from job description jd_ = idata->jd_; state_ = saga::job::New; if ( ! jd_.attribute_exists (sja::description_executable) ) { SAGA_ADAPTOR_THROW ("job description misses executable", saga::BadParameter); } } // FIXME: register metrics etc. }
/** * 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::check_permissions(saga::replica::flags flags, char const* name, std::string const& adname) { instance_data data (this); this->check_if_open ("logical_file_cpi_impl::check_permissions", data->location_); if (!(data->mode_ & flags)) { SAGA_OSSTREAM strm; strm << name << " could not access (" << ((flags == saga::replica::Read) ? "read" : "write") << ") : " << adname; SAGA_ADAPTOR_THROW(SAGA_OSSTREAM_GETSTRING(strm), saga::PermissionDenied); } }
/////////////////////////////////////////////////////////////////////////////// // logical_file functions void logical_file_cpi_impl::sync_list_locations(std::vector<saga::url>& locations) { adaptor_data_t adaptorData(this); instance_data instanceData (this); saga::url lfn_url(instanceData->location_); this->check_if_open ("logical_file_cpi_impl::sync_list_locations", instanceData->location_); try { RLSConnection * RLSHandle = adaptorData->getConnectionHandle(instanceData->location_); locations = RLSHandle->LFNGetPFNList(lfn_url.get_path()); } catch(globus_rls_replica_adaptor::exception const & e) { SAGA_OSSTREAM strm; strm << "Could not list locations for logical file [" << instanceData->location_ << "]. " << e.RLSErrorText(); SAGA_ADAPTOR_THROW(SAGA_OSSTREAM_GETSTRING(strm), e.SAGAError()); } }
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()); } }
//////////////////////////////////////////////////////////////////////// // constructor advertdirectory_cpi_impl::advertdirectory_cpi_impl (proxy * p, cpi_info const & info, saga::ini::ini const & glob_ini, saga::ini::ini const & adap_ini, TR1::shared_ptr <saga::adaptor> adaptor) : saga::adaptors::v1_0::advert_directory_cpi <advertdirectory_cpi_impl> (p, info, adaptor, cpi::Noflags) { saga::url advert_url; instance_data data (this); advert_url = data->location_.clone(); std::string path; int port; path = advert_url.get_path(); if (path.empty()) path = "/"; // root only std::string host(advert_url.get_host()); if (host.empty()) { SAGA_OSSTREAM strm; strm << "advert::advert_cpi_impl::init: " "cannot handle advert entry name: " << advert_url.get_url(); SAGA_ADAPTOR_THROW(SAGA_OSSTREAM_GETSTRING(strm), saga::IncorrectURL); } std::string scheme(advert_url.get_scheme()); if (!scheme.empty() && scheme != "hbase" && scheme != "any") { SAGA_OSSTREAM strm; strm << "advert::advert_cpi_impl::init: " "cannot handle advert entry name: " << advert_url.get_url(); SAGA_ADAPTOR_THROW(SAGA_OSSTREAM_GETSTRING(strm), saga::IncorrectURL); } port = advert_url.get_port(); boost::shared_ptr<TTransport> socket(new TSocket(host, port)); transport_ = boost::shared_ptr<TTransport>(new TBufferedTransport(socket)); boost::shared_ptr<TProtocol> protocol(new TBinaryProtocol(transport_)); client_ = new HbaseClient(protocol); transport_->open(); saga::advert::flags mode = (saga::advert::flags)data->mode_; if(path == "/") { } else if (((mode & saga::advert::Create) || (mode & saga::advert::CreateParents)) && (mode & saga::advert::Exclusive)) { if(!url_exists(*client_, advert_url.get_url())) { SAGA_OSSTREAM strm; strm << "advert::advert_cpi_impl::init: " "advert already exists: " << advert_url.get_url(); SAGA_ADAPTOR_THROW(SAGA_OSSTREAM_GETSTRING(strm), saga::AlreadyExists); } } else if ((mode & saga::advert::Create) || (mode & saga::advert::CreateParents)) { if(!url_exists(*client_, advert_url.get_url())) { if(!create_url(*client_, advert_url.get_url(), true)) { // failed to create url SAGA_OSSTREAM strm; strm << "advert::advert_cpi_impl::init: " "advert couldn't create url: " << advert_url.get_url(); SAGA_ADAPTOR_THROW(SAGA_OSSTREAM_GETSTRING(strm), saga::AlreadyExists); } } // no need to create this entry twice data->mode_ &= ~(saga::advert::Create | saga::advert::CreateParents); } /*if(!url_exists(*client_, advert_url.get_url())) { //here is where I am SAGA_OSSTREAM strm; strm << "advert::advert_cpi_impl::init: " "advert does not exist: " << advert_url.get_url(); SAGA_ADAPTOR_THROW(SAGA_OSSTREAM_GETSTRING(strm), saga::BadParameter); }*/ //SAGA_ADAPTOR_THROW ("Not Implemented", saga::NotImplemented); }
// constructor job_service_cpi_impl::job_service_cpi_impl (proxy * p, cpi_info const & info, saga::ini::ini const & glob_ini, saga::ini::ini const & adap_ini, TR1::shared_ptr <saga::adaptor> adaptor) : base_cpi (p, info, adaptor, cpi::Noflags) , session_ (p->get_session ()) { try { bp_.initialize (); } catch ( const char & m ) { SAGA_ADAPTOR_THROW ((std::string ("Could not initialize backend library: ") + m).c_str (), saga::NoSuccess); } catch ( const saga::exception & e ) { SAGA_ADAPTOR_THROW ((std::string ("Could not initialize backend library: ") + e.what ()).c_str (), saga::NoSuccess); } instance_data idata (this); rm_ = idata->rm_; // check if URL is usable if ( ! rm_.get_scheme ().empty () && rm_.get_scheme () != "bes" && rm_.get_scheme () != "http" && rm_.get_scheme () != "https" && rm_.get_scheme () != "epr" && // read epr from url rm_.get_scheme () != "any" ) { SAGA_OSSTREAM strm; strm << "Could not initialize job service for [" << rm_ << "]. " << "Only these schemas are supported: any://, bes://, http(s)://, epr://, or none."; SAGA_ADAPTOR_THROW (SAGA_OSSTREAM_GETSTRING (strm), saga::adaptors::AdaptorDeclined); } if ( rm_.get_scheme () == "any" || rm_.get_scheme () == "bes" ) { rm_.set_scheme ("https"); } if ( rm_.get_scheme () == "epr" ) { // read epr from file, using saga::filesystem saga::url e (rm_); e.set_scheme ("any"); try { saga::filesystem::file f (e); saga::size_t s = f.get_size (); saga::mutable_buffer b (s + 1); f.read (b); static_cast <char *> (b.get_data ())[s] = '\0'; bp_.set_host_epr (static_cast <const char*> (b.get_data ())); } catch ( const char & m ) { SAGA_ADAPTOR_THROW ((std::string ("Could not handle EPR: ") + m).c_str (), saga::BadParameter); } catch ( const saga::exception & e ) { SAGA_ADAPTOR_THROW ((std::string ("Could not handle EPR: ") + e.what ()).c_str (), saga::BadParameter); } } else { try { bp_.set_host_endpoint (rm_.get_string ()); } catch ( const char & m ) { SAGA_ADAPTOR_THROW ((std::string ("Could not handle endpoint url: ") + m).c_str (), saga::BadParameter); } catch ( const saga::exception & e ) { SAGA_ADAPTOR_THROW ((std::string ("Could not handle endpoint url: ") + e.what ()).c_str (), saga::BadParameter); } } // cycle over contexts and see which ones we can use. // We accept x509 and UserPass bool context_found = false; std::vector <saga::context> contexts = session_.list_contexts (); try { for ( unsigned int i = 0; i < contexts.size (); i++ ) { saga::context c = contexts[i]; if ( c.attribute_exists (saga::attributes::context_type) ) { if ( c.get_attribute (saga::attributes::context_type) == "UserPass" ) { std::string user; std::string pass; if ( c.attribute_exists (saga::attributes::context_userid) ) { user = c.get_attribute (saga::attributes::context_userid); } if ( c.attribute_exists (saga::attributes::context_userpass) ) { pass = c.get_attribute (saga::attributes::context_userpass); } bp_.set_security ("", "", "", user, pass); context_found = true; } else if ( c.get_attribute (saga::attributes::context_type) == "UserPass" ) { std::string cert; std::string pass; std::string cadir; if ( c.attribute_exists (saga::attributes::context_certrepository) ) { cadir = c.get_attribute (saga::attributes::context_certrepository); } if ( c.attribute_exists (saga::attributes::context_usercert) ) { cert = c.get_attribute (saga::attributes::context_usercert); } if ( c.attribute_exists (saga::attributes::context_userpass) ) { pass = c.get_attribute (saga::attributes::context_userpass); } bp_.set_security (cert, pass, cadir, "", ""); context_found = true; } if ( context_found ) { // TODO?: test if context can be used to contact server. // If not, set context_found to false again, and free // the bes context } } } } catch ( const char & m ) { SAGA_ADAPTOR_THROW ((std::string ("Could not handle context information: ") + m).c_str (), saga::BadParameter); } catch ( const saga::exception & e ) { SAGA_ADAPTOR_THROW ((std::string ("Could not handle context information: ") + e.what ()).c_str (), saga::BadParameter); } if ( ! context_found ) { // this is not really an error, maybe there is no security on the endpoint // whatsoever - but its actually unlikely that calls will succeed. So, we // print a warning SAGA_ADAPTOR_THROW ("No suitable context found - use either X509 or UserPass context", saga::AuthenticationFailed); } // TODO: check if host exists and can be used, otherwise throw BadParameter // easiest would probably to run an invalid job request and see if we get // a sensible error... But latency *sigh* }
dir_cpi_impl::dir_cpi_impl (proxy * p, cpi_info const & info, saga::ini::ini const & glob_ini, saga::ini::ini const & adap_ini, boost::shared_ptr<saga::adaptor> adaptor) : directory_cpi (p, info, adaptor, cpi::Noflags) { adaptor_data_t adata (this); directory_instance_data_t idata (this); saga::url dir_url(idata->location_); std::string host(dir_url.get_host()); if (host.empty()) { SAGA_OSSTREAM strm; strm << "dir_cpi_impl::init: cannot handle file: " << dir_url.get_url(); SAGA_ADAPTOR_THROW(SAGA_OSSTREAM_GETSTRING(strm), saga::BadParameter); } std::string scheme(dir_url.get_scheme()); if (!scheme.empty() && scheme != "kfs" && scheme != "any") { SAGA_OSSTREAM strm; strm << "dir_cpi_impl::init: cannot handle file: " << dir_url.get_url(); SAGA_ADAPTOR_THROW(SAGA_OSSTREAM_GETSTRING(strm), saga::BadParameter); } fs_ = getKfsClientFactory()->GetClient(dir_url.get_host(), dir_url.get_port()); if(!fs_) { SAGA_OSSTREAM strm; strm << "Could not connect to host : " << dir_url.get_host(); strm << "on port " << dir_url.get_port(); SAGA_ADAPTOR_THROW(SAGA_OSSTREAM_GETSTRING(strm), saga::NoSuccess); } // check if file exists AND is a dir (not a file) bool exists = false; bool is_dir = false; if(fs_->Exists(dir_url.get_path().c_str())) { exists = true; //Check to see if it is a directory instance_data idata(this); if(fs_->IsDirectory(dir_url.get_path().c_str())) is_dir = true; } saga::filesystem::flags OpenMode = (saga::filesystem::flags)idata->mode_; if(exists) { if(!is_dir) { SAGA_ADAPTOR_THROW ("URL does not point to a directory: " + idata->location_.get_url(), saga::BadParameter); } else { if((OpenMode & saga::filesystem::Create) && (OpenMode & saga::filesystem::Exclusive)) { SAGA_ADAPTOR_THROW ("Directory " + idata->location_.get_url() + " already exists.", saga::AlreadyExists); } } } else { // !exists if(!(OpenMode & saga::filesystem::Create)) { SAGA_ADAPTOR_THROW ("Directory does not exist and saga::filesystem::Create flag not given: " + idata->location_.get_url(), saga::DoesNotExist); } else { if(fs_->Mkdir(dir_url.get_path().c_str()) != 0) { SAGA_OSSTREAM strm; strm << "Could not create directory " << idata->location_.get_path(); SAGA_ADAPTOR_THROW(SAGA_OSSTREAM_GETSTRING(strm), saga::DoesNotExist); } } } exists = false; is_dir = false; //Make sure directory exists if(fs_->Exists(dir_url.get_path().c_str())) exists = true; if ((idata->mode_ & saga::filesystem::Create || idata->mode_ & saga::filesystem::CreateParents) && idata->mode_ & saga::filesystem::Exclusive) { //Check to see if it is a directory if(fs_->IsDirectory(dir_url.get_path().c_str())) is_dir = true; if(is_dir) { SAGA_ADAPTOR_THROW(dir_url.get_path().c_str() + ": already exists", saga::AlreadyExists); } } if(!exists) { //create directory if needed if (idata->mode_ & saga::filesystem::Create) { if(fs_->Mkdir(dir_url.get_path().c_str()) != 0) { SAGA_OSSTREAM strm; strm << "Could not create directory " << idata->location_.get_path(); SAGA_ADAPTOR_THROW(SAGA_OSSTREAM_GETSTRING(strm), saga::DoesNotExist); } } } // we don't need to create the directory twice idata->mode_ &= ~(saga::filesystem::Create | saga::filesystem::CreateParents); if (idata->mode_ & saga::filesystem::Read || idata->mode_ & saga::filesystem::Write || idata->mode_ & saga::filesystem::ReadWrite) { //check to see if it exists and is a direcotory exists = false; is_dir = false; if(fs_->Exists(dir_url.get_path().c_str())) { exists = true; //Check to see if it is a directory if(fs_->IsDirectory(dir_url.get_path().c_str())) is_dir = true; } if (!exists || !is_dir) { SAGA_OSSTREAM strm; strm << idata->location_.get_path() << ": doesn't refer to a directory object"; SAGA_ADAPTOR_THROW(SAGA_OSSTREAM_GETSTRING(strm), saga::BadParameter); } } if (idata->mode_ & ~( saga::filesystem::Create | saga::filesystem::CreateParents | saga::filesystem::Exclusive | saga::filesystem::Overwrite | saga::filesystem::Read | saga::filesystem::Write | saga::filesystem::ReadWrite )) { SAGA_ADAPTOR_THROW("Unknown openmode value: " + boost::lexical_cast<std::string>(idata->mode_), saga::BadParameter); } //SAGA_ADAPTOR_THROW ("Not Implemented", saga::NotImplemented); }
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) { 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); } } }
logical_file_cpi_impl::logical_file_cpi_impl (proxy* p, cpi_info const& info, saga::ini::ini const& glob_ini, saga::ini::ini const& adap_ini, TR1::shared_ptr<saga::adaptor> adaptor) : base_cpi (p, info, adaptor, cpi::Noflags) { adaptor_data_t adaptorData(this); instance_data instanceData (this); saga::url lfn_url(instanceData->location_); // we support only any:// and lfn:// schemes FIXME: what about LRC/RLI ?!? std::string scheme(instanceData->location_.get_scheme()); std::string host(instanceData->location_.get_host()); if (scheme != "any" && scheme != "lfn" && scheme != GLOBUS_RLS_URL_SCHEME && scheme != GLOBUS_RLS_URL_SCHEME_NOAUTH) { SAGA_OSSTREAM strm; strm << "Could not open logical file [" << instanceData->location_ << "]. " << "Supported URL schemes are: any:// and lfn://"; SAGA_ADAPTOR_THROW(SAGA_OSSTREAM_GETSTRING(strm), saga::adaptors::AdaptorDeclined); } // and we always fall back to 'localhost' if the hostname is empty if( host.empty() ) { instanceData->location_.set_host("localhost"); } // If we've made it here, it should be safe to load // the GRAM modules now. The loader employs a sigleton mechanism, // so ut doesn't matter if we call this method multiple times. globus_module_loader::globus_init (); // try to create/retreive a connection handle for the given host bool exists = false; try { RLSConnection * RLSHandle = adaptorData->getConnectionHandle(instanceData->location_); exists = RLSHandle->LFNExists(lfn_url.get_path()); } catch(globus_rls_replica_adaptor::exception const & e) { SAGA_OSSTREAM strm; strm << "Could not open logical file [" << instanceData->location_ << "]. " << e.RLSErrorText(); SAGA_ADAPTOR_THROW(SAGA_OSSTREAM_GETSTRING(strm), e.SAGAError()); } saga::replica::flags mode = (saga::replica::flags)instanceData->mode_; if (((mode & saga::replica::Create) || (mode & saga::replica::CreateParents)) && (mode & saga::replica::Exclusive)) { // FIXME: handle modes... } if ((mode & saga::replica::Create) || (mode & saga::replica::CreateParents)) { // FIXME: Create replica entry if the create flag is given... } if(!exists) { SAGA_OSSTREAM strm; strm << "Could not open logical file [" << instanceData->location_ << "]. " << "The file doesn't exist and the 'Create' flag is not set!"; SAGA_ADAPTOR_THROW(SAGA_OSSTREAM_GETSTRING(strm), saga::DoesNotExist); } is_open_ = true; }