EIO_Status Soaker(const string& url, const string& data, const STimeout* read_tmo, const STimeout* write_tmo) { static const STimeout kZeroTimeout = { 0 }; CConn_HttpStream http(url, fHTTP_AutoReconnect, write_tmo); http.SetTimeout(eIO_Close, read_tmo); http.SetTimeout(eIO_Read, read_tmo); http << data << flush; EIO_Status status = CONN_Wait(http.GetCONN(), eIO_Read, &kZeroTimeout); if (status != eIO_Success) { if (status != eIO_Timeout) return status; status = http.Status(eIO_Write); if (status != eIO_Success) return status; } CWStream null(new CNullWriter, 0, 0, CRWStreambuf::fOwnWriter); NcbiStreamCopy(null, http); status = http.Status(); if (status != eIO_Success && status != eIO_Closed) return status; status = http.Status(eIO_Read); if (status != eIO_Closed) return status; return eIO_Success; }
string CNetScheduleJobSerializer::SaveJobOutput( CNetScheduleAPI::EJobStatus job_status, const string& target_dir, CNetCacheAPI& nc_api) { string target_file = CDirEntry::ConcatPath(target_dir, m_Job.job_id + ".out"); CNcbiOfstream output_stream(target_file.c_str(), CNcbiOfstream::binary); output_stream << "job_status=" << CNetScheduleAPI::StatusToString(job_status) << " ret_code=" << m_Job.ret_code; if (!m_Job.error_msg.empty()) { output_stream << " error_msg=\"" << NStr::PrintableString(m_Job.error_msg) << '"'; } output_stream << NcbiEndl; CStringOrBlobStorageReader job_output_reader(m_Job.output, nc_api); CRStream job_output_istream(&job_output_reader); NcbiStreamCopy(output_stream, job_output_istream); return target_file; }
void CNetScheduleJobSerializer::LoadJobInput(const string& source_file) { CNcbiIfstream input_stream(source_file.c_str(), CNcbiIfstream::binary); if (input_stream.fail() && !input_stream.eof()) { NCBI_THROW_FMT(CIOException, eRead, "Error while reading job input from '" << source_file << '\''); } string header; getline(input_stream, header); CAttrListParser attr_parser; attr_parser.Reset(header); CAttrListParser::ENextAttributeType attr_type; CTempString attr_name; string attr_value; size_t attr_column; #define ATTR_POS " at column " << attr_column while ((attr_type = attr_parser.NextAttribute(&attr_name, &attr_value, &attr_column)) != CAttrListParser::eNoMoreAttributes) { if (attr_name == "affinity") m_Job.affinity = attr_value; else if (attr_name == "group") m_Job.group = attr_value; else if (attr_name == "exclusive") { m_Job.mask = CNetScheduleAPI::eExclusiveJob; continue; } else { NCBI_THROW_FMT(CArgException, eInvalidArg, "unknown attribute '" << attr_name << "'" ATTR_POS); } if (attr_type != CAttrListParser::eAttributeWithValue) { NCBI_THROW_FMT(CArgException, eInvalidArg, "attribute '" << attr_name << "' requires a value" ATTR_POS); } } if (!input_stream.eof()) { CStringOrBlobStorageWriter job_input_writer( numeric_limits<size_t>().max(), NULL, m_Job.input); CWStream job_input_ostream(&job_input_writer, 0, NULL); NcbiStreamCopy(job_input_ostream, input_stream); } CDirEntry file_name(source_file); m_Job.job_id = file_name.GetBase(); }
static void DumpStdStreams(const CArgValue& arg, CNSInfoCollector* info_collector, CNcbiOstream* out, bool use_stderr) { CCmdLineArgList job_list( CCmdLineArgList::CreateFrom(arg.AsString())); std::string job_id; while (job_list.GetNextArg(job_id)) { CNSJobInfo job_info(job_id, *info_collector); NcbiStreamCopy(*out, use_stderr ? job_info.GetStdErr() : job_info.GetStdOut()); } }
BEGIN_NCBI_SCOPE string CNetScheduleJobSerializer::SaveJobInput(const string& target_dir, CNetCacheAPI& nc_api) { string target_file = CDirEntry::ConcatPath(target_dir, m_Job.job_id + ".in"); CNcbiOfstream output_stream(target_file.c_str(), CNcbiOfstream::binary); bool need_space = false; if (!m_Job.affinity.empty()) { output_stream << "affinity=\"" << NStr::PrintableString(m_Job.affinity) << '"'; need_space = true; } if (!m_Job.group.empty()) { if (need_space) output_stream << ' '; output_stream << "group=\"" << NStr::PrintableString(m_Job.group) << '"'; need_space = true; } if ((m_Job.mask & CNetScheduleAPI::eExclusiveJob) != 0) { if (need_space) output_stream << ' '; output_stream << "exclusive"; } output_stream << NcbiEndl; CStringOrBlobStorageReader job_input_reader(m_Job.input, nc_api); CRStream job_input_istream(&job_input_reader); NcbiStreamCopy(output_stream, job_input_istream); return target_file; }