// Copyright (c) 2008 João Abecasis // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) #ifndef SAGA_ADAPTORS_CONDOR_JOB_HELPER_HPP_INCLUDED #define SAGA_ADAPTORS_CONDOR_JOB_HELPER_HPP_INCLUDED #include #include #include #include #include #include #include namespace saga { namespace adaptors { namespace condor { namespace detail { bool is_localhost(std::string const &); bool is_localhost(saga::url const &); struct helper { // Formats a vector of command-line arguments (or environment // variables) into a string suitable for use in Condor submit // descriptions. static std::string args_to_condor_arg( std::vector const & args) { std::string result; BOOST_FOREACH(std::string arg, args) { boost::replace_all(arg, "\"", "\"\""); if (boost::contains(arg, "'") || boost::contains(arg, " ")) { boost::replace_all(arg, "'", "''"); arg = "'" + arg + "'"; } result += arg + " "; } if (!result.empty()) result = "\"" + result + "\""; return result; } static std::string saga_jd_to_condor_jd( saga::job::description const & jd) { using namespace saga::job::attributes; std::string condor_jd("Universe = Vanilla\n"); std::string exename(jd.get_attribute(description_executable)); condor_jd += "\n Executable = " + exename; if (jd.attribute_exists(description_arguments)) { std::string args = args_to_condor_arg( jd.get_vector_attribute(description_arguments)); if (!args.empty()) condor_jd += "\n Arguments = " + args; } if (jd.attribute_exists(description_input)) { std::string input(jd.get_attribute(description_input)); condor_jd += "\n Input = " + input; } if (jd.attribute_exists(description_output)) { std::string output(jd.get_attribute(description_output)); condor_jd += "\n Output = " + output; } if (jd.attribute_exists(description_error)) { std::string error(jd.get_attribute(description_error)); condor_jd += "\n Error = " + error; } if (jd.attribute_exists(description_environment)) { std::string envs = args_to_condor_arg( jd.get_vector_attribute(description_environment)); if (!envs.empty()) condor_jd += "\n Environment = " + envs; } if (jd.attribute_exists( saga::job::attributes::description_file_transfer)) { std::string input, output; BOOST_FOREACH(std::string const & ft, jd.get_vector_attribute(description_file_transfer)) { std::string left, right; file_transfer_operator mode; if (!parse_file_transfer_specification(ft, left, mode, right)) SAGA_ADAPTOR_THROW_NO_CONTEXT( "Ill-formatted file " "transfer specification: " + ft, saga::BadParameter); // TODO: Remote renaming is not supported. Should either // rename locally or just check/inform user in case // of mismatches between left and right. // TODO: Implement appending. switch (mode) { case copy_local_remote: input += " " + left; break; case copy_remote_local: output += " " + right; break; case append_local_remote: case append_remote_local: SAGA_ADAPTOR_THROW_NO_CONTEXT("Appending not " "currently supported in FileTransfer " "attribute.", saga::BadParameter); default: SAGA_ADAPTOR_THROW_NO_CONTEXT("Unknown operator in " "FileTransfer: " + ft, saga::BadParameter); } } if (!input.empty()) condor_jd += "\n Transfer_Input_Files =" + input; if (!output.empty()) condor_jd += "\n Transfer_Output_Files =" + output; } condor_jd += "\n\nQueue"; return condor_jd; } }; }}}} // namespace saga::adaptors::condor::detail #endif // include guard