NCBI C++ Toolkit Cross Reference

  C++/src/app/grid/grid_cli/automation.cpp


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834
/* $Id: automation.cpp 79845 2017-10-17 16:17:16Z sadyrovr $ * =========================================================================== * * PUBLIC DOMAIN NOTICE * National Center for Biotechnology Information * * This software/database is a "United States Government Work" under the * terms of the United States Copyright Act. It was written as part of * the author's official duties as a United States Government employee and * thus cannot be copyrighted. This software/database is freely available * to the public for use. The National Library of Medicine and the U.S. * Government have not placed any restriction on its use or reproduction. * * Although all reasonable efforts have been taken to ensure the accuracy * and reliability of the software and data, the NLM and the U.S. * Government do not and cannot warrant the performance or results that * may be obtained by using this software or data. The NLM and the U.S. * Government disclaim all warranties, express or implied, including * warranties of performance, merchantability or fitness for any particular * purpose. * * Please cite the author in any work or product based on this material. * * =========================================================================== * * Authors: Dmitry Kazimirov * * File Description: Declaration of the automation processor. * */ #include <ncbi_pch.hpp> #include <sstream> #include "nc_automation.hpp" #include "ns_automation.hpp" #include "wn_automation.hpp" #include "nst_automation.hpp" #include <corelib/request_ctx.hpp> #include <connect/ncbi_pipe.hpp> #include <connect/services/grid_app_version_info.hpp> #ifdef WIN32 #include <io.h> #include <fcntl.h> #endif #define PROTOCOL_VERSION 4 #define AUTOMATION_IO_BUFFER_SIZE 4096 #define PROTOCOL_ERROR_BASE_RETCODE 20 USING_NCBI_SCOPE; using namespace NAutomation; struct NAutomation::SCommandImpl { virtual ~SCommandImpl() {} virtual CJsonNode Help(const string& name, CJsonIterator& input) = 0; virtual bool Check(const string& name, SInputOutput& io, void*& data); virtual bool Exec(const string& name, SInputOutput& io, void* data) = 0; }; struct SSimpleCommandImpl : SCommandImpl { SSimpleCommandImpl(TArgsInit args, TCommandExecutor exec); CJsonNode Help(const string& name, CJsonIterator& input) override; bool Exec(const string& name, SInputOutput& io, void* data) override; private: TArguments m_Args; TCommandExecutor m_Exec; }; struct SVariadicCommandImpl : SCommandImpl { SVariadicCommandImpl(string args, TCommandExecutor exec); CJsonNode Help(const string& name, CJsonIterator& input) override; bool Exec(const string& name, SInputOutput& io, void* data) override; private: const string m_Args; TCommandExecutor m_Exec; }; struct SCommandGroupImpl : SCommandImpl { SCommandGroupImpl(TCommandGroup group); CJsonNode Help(const string& name, CJsonIterator& input) override; bool Check(const string& name, SInputOutput& io, void*& data) override; bool Exec(const string& name, SInputOutput& io, void* data) override; private: TCommands m_Commands; TCommandChecker m_Check; }; CJsonNode CArgument::Help() { CJsonNode help(CJsonNode::eObject); help.SetString("name", m_Name); help.SetString("type", m_TypeOrDefaultValue.GetTypeName()); if (m_Optional) help.SetByKey("default", m_TypeOrDefaultValue); return help; } void CArgument::Exec(const string& name, CJsonIterator& input) { if (input.IsValid()) { auto current = input.GetNode(); auto current_type = current.GetNodeType(); if ((current_type == CJsonNode::eNull) && m_Optional) { m_Value = m_TypeOrDefaultValue; return; } if (current_type != m_TypeOrDefaultValue.GetNodeType()) { NCBI_THROW_FMT(CAutomationException, eInvalidInput, name << ": invalid argument type (expected " << m_TypeOrDefaultValue.GetTypeName() << ")"); } m_Value = current; } else { if (!m_Optional) { NCBI_THROW_FMT(CAutomationException, eInvalidInput, name << ": insufficient number of arguments"); } m_Value = m_TypeOrDefaultValue; } } bool SCommandImpl::Check(const string& name, SInputOutput& io, void*&) { auto& input = io.input; if (!input.IsValid()) { NCBI_THROW_FMT(CAutomationException, eInvalidInput, name << ": insufficient number of arguments"); } // Call to a different element auto current = input.GetNode().AsString(); if (current != name) return false; ++input; return true; } SSimpleCommandImpl::SSimpleCommandImpl(TArgsInit args, TCommandExecutor exec) : m_Args(args), m_Exec(exec) { } CJsonNode SSimpleCommandImpl::Help(const string& name, CJsonIterator&) { // Full mode CJsonNode help(CJsonNode::eObject); help.SetString("command", name); if (m_Args.size()) { CJsonNode elements(CJsonNode::eArray); for (auto& element : m_Args) elements.Append(element.Help()); help.SetByKey("arguments", elements); } return help; } bool SSimpleCommandImpl::Exec(const string& name, SInputOutput& io, void* data) { auto& input = io.input; for (auto& element : m_Args) { element.Exec(name, input); if (input) ++input; } if (input) { NCBI_THROW_FMT(CAutomationException, eInvalidInput, name << ": too many arguments"); } if (m_Exec) m_Exec(m_Args, io, data); return true; } SVariadicCommandImpl::SVariadicCommandImpl(string args, TCommandExecutor exec) : m_Args(args), m_Exec(exec) { } CJsonNode SVariadicCommandImpl::Help(const string& name, CJsonIterator&) { // Full mode CJsonNode help(CJsonNode::eObject); help.SetString("command", name); help.SetString("arguments", m_Args); return help; } bool SVariadicCommandImpl::Exec(const string&, SInputOutput& io, void* data) { auto& input = io.input; TArguments args; for (; input; ++input) { args.emplace_back(input); } if (m_Exec) m_Exec(args, io, data); return true; } SCommandGroupImpl::SCommandGroupImpl(TCommandGroup group) : m_Commands(group.first), m_Check(group.second) { } CJsonNode SCommandGroupImpl::Help(const string& name, CJsonIterator& input) { // Full mode CJsonNode help(CJsonNode::eObject); help.SetString("command", name); if (m_Commands.size()) { CJsonNode elements(CJsonNode::eArray); for (auto& element : m_Commands) { if (CJsonNode sub_help = element.Help(input)) { // If help is called for a particular sub-command only if (sub_help.IsObject()) return sub_help; elements.Append(sub_help); } } help.SetByKey("sub-topics", elements); } return help; } bool SCommandGroupImpl::Check(const string& name, SInputOutput& io, void*& data) { if (m_Check) return m_Check(name, io, data); return SCommandImpl::Check(name, io, data); } bool SCommandGroupImpl::Exec(const string&, SInputOutput& io, void* data) { if (m_Commands.empty()) return false; for (auto& element : m_Commands) { if (element.Exec(io, data)) return true; } return false; } CCommand::CCommand(string name, TCommandExecutor exec, TArgsInit args) : m_Name(name), m_Impl(new SSimpleCommandImpl(args, exec)) { } CCommand::CCommand(string name, TCommandExecutor exec, const char * const args) : m_Name(name), m_Impl(new SVariadicCommandImpl(args, exec)) { } CCommand::CCommand(string name, TCommands commands) : CCommand(name, TCommandGroup(commands, nullptr)) { } CCommand::CCommand(string name, TCommandGroup group) : m_Name(name), m_Impl(new SCommandGroupImpl(group)) { } CJsonNode CCommand::Help(CJsonIterator& input) { // Short mode (enumeration) if (!input.IsValid()) { return CJsonNode(m_Name); } // Help for a different element if (input.GetNode().AsString() != m_Name) { return CJsonNode(); } return m_Impl->Help(m_Name, ++input); } bool CCommand::Exec(SInputOutput& io, void* data) { if (!m_Impl->Check(m_Name, io, data)) return false; return m_Impl->Exec(m_Name, io, data); } TAutomationObjectRef CAutomationProc::FindObjectByPtr(const void* impl_ptr) const { TPtrToObjectRefMap::const_iterator it = m_ObjectByPointer.find(impl_ptr); return it != m_ObjectByPointer.end() ? it->second : TAutomationObjectRef(); } CJsonNode SServerAddressToJson::ExecOn(CNetServer server) { switch (m_WhichPart) { case 1: return CJsonNode::NewStringNode(g_NetService_gethostnamebyaddr( server.GetHost())); case 2: return CJsonNode::NewIntegerNode(server.GetPort()); } return CJsonNode::NewStringNode(server.GetServerAddress()); } TCommands SNetServiceBase::CallCommands() { TCommands cmds = { { "get_name", ExecMethod<TSelf, &TSelf::ExecGetName>, }, { "get_address", ExecMethod<TSelf, &TSelf::ExecGetAddress>, { { "which_part", 0, } }}, // TODO: Remove this after GRID Python module stops using it #ifdef NCBI_GRID_XSITE_CONN_SUPPORT { "allow_xsite_connections", CAutomationProc::ExecAllowXSite, }, #endif }; return cmds; } void SNetServiceBase::ExecGetName(const TArguments&, SInputOutput& io) { auto& reply = io.reply; reply.AppendString(m_Service.GetServiceName()); } void SNetServiceBase::ExecGetAddress(const TArguments& args, SInputOutput& io) { _ASSERT(args.size() == 1); auto& reply = io.reply; const auto which_part = args["which_part"].AsInteger<int>(); SServerAddressToJson server_address_proc(which_part); reply.Append(g_ExecToJson(server_address_proc, m_Service, m_ActualServiceType)); } TCommands SNetService::CallCommands() { TCommands cmds = { { "server_info", ExecMethod<TSelf, &TSelf::ExecServerInfo>, }, { "exec", ExecMethod<TSelf, &TSelf::ExecExec>, { { "command", CJsonNode::eString, }, { "multiline", false, }, }}, }; TCommands base_cmds = SNetServiceBase::CallCommands(); cmds.insert(cmds.end(), base_cmds.begin(), base_cmds.end()); return cmds; } void SNetService::ExecServerInfo(const TArguments&, SInputOutput& io) { auto& reply = io.reply; reply.Append(g_ServerInfoToJson(m_Service, m_ActualServiceType, true)); } void SNetService::ExecExec(const TArguments& args, SInputOutput& io) { _ASSERT(args.size() == 2); auto& reply = io.reply; const auto command = args["command"].AsString(); const auto multiline = args["multiline"].AsBoolean(); reply.Append(g_ExecAnyCmdToJson(m_Service, m_ActualServiceType, command, multiline)); } CAutomationProc::CAutomationProc(IMessageSender* message_sender) : m_MessageSender(message_sender), m_OKNode(CJsonNode::NewBooleanNode(true)), m_ErrNode(CJsonNode::NewBooleanNode(false)), m_WarnNode(CJsonNode::NewStringNode("WARNING")) { } TCommands CAutomationProc::CallCommands() { return TCommands { SNetCacheBlob::CallCommand(), SNetCacheService::CallCommand(), SNetCacheServer::CallCommand(), SNetScheduleService::CallCommand(), SNetScheduleServer::CallCommand(), SNetStorageService::CallCommand(), SNetStorageServer::CallCommand(), SNetStorageObject::CallCommand(), SWorkerNode::CallCommand(), }; } TCommands CAutomationProc::NewCommands() { return TCommands { SNetCacheService::NewCommand(), SNetCacheServer::NewCommand(), SNetScheduleService::NewCommand(), SNetScheduleServer::NewCommand(), SNetStorageService::NewCommand(), SNetStorageServer::NewCommand(), SWorkerNode::NewCommand(), }; } TCommands CAutomationProc::Commands() { TCommands cmds = { { "exit", ExecExit }, { "call", CallCommands() }, { "new", NewCommands() }, { "del", ExecDel, { { "object_id", CJsonNode::eInteger, }, }}, { "whatis", ExecWhatIs, { { "some_id", CJsonNode::eString, }, }}, { "echo", ExecEcho, "any" }, { "version", ExecVersion }, { "set_context", ExecSetContext, { { "phid", CJsonNode::eString, }, { "sid", "", }, { "client_ip", "", }, }}, #ifdef NCBI_GRID_XSITE_CONN_SUPPORT { "allow_xsite_connections", ExecAllowXSite }, #endif }; return cmds; } void CAutomationProc::ExecExit(const TArguments&, SInputOutput& io, void*) { auto& reply = io.reply; reply = CJsonNode(); } void CAutomationProc::ExecDel(const TArguments& args, SInputOutput&, void* data) { _ASSERT(args.size() == 1); _ASSERT(data); auto that = static_cast<CAutomationProc*>(data); const auto object_id = args["object_id"].AsInteger(); auto& object = that->ObjectIdToRef(object_id); that->m_ObjectByPointer.erase(object->GetImplPtr()); object = NULL; } void CAutomationProc::ExecVersion(const TArguments&, SInputOutput& io, void*) { auto& reply = io.reply; reply.AppendString(GRID_APP_VERSION); reply.AppendString(__DATE__); } void CAutomationProc::ExecWhatIs(const TArguments& args, SInputOutput& io, void*) { _ASSERT(args.size() == 1); auto& reply = io.reply; const auto some_id = args["some_id"].AsString(); auto result = g_WhatIs(some_id); if (!result) { NCBI_THROW_FMT(CAutomationException, eCommandProcessingError, "Unable to recognize the specified token."); } reply.Append(result); } void CAutomationProc::ExecEcho(const TArguments& args, SInputOutput& io, void*) { auto& reply = io.reply; for (auto& arg: args) reply.Append(arg.Value()); } void CAutomationProc::ExecSetContext(const TArguments& args, SInputOutput&, void*) { _ASSERT(args.size() == 3); const auto phid = args["phid"].AsString(); const auto sid = args["sid"].AsString(); const auto client_ip = args["client_ip"].AsString(); auto& ctx = GetDiagContext().GetRequestContext(); if (!phid.empty()) ctx.SetHitID(phid); if (!sid.empty()) ctx.SetSessionID(sid); if (!client_ip.empty()) ctx.SetClientIP(client_ip); } void CAutomationProc::ExecAllowXSite(const TArguments&, SInputOutput&, void*) { #ifdef NCBI_GRID_XSITE_CONN_SUPPORT CNetService::AllowXSiteConnections(); #endif } CJsonNode CAutomationProc::ProcessMessage(const CJsonNode& message) { SInputOutput io(message); auto& input = io.input; auto& reply = io.reply; // Empty input (help) if (!input.IsValid()) { reply.AppendString("Type `help` (in single quotes) for usage. " "For help on a sub-topic, add it to the command, " "e.g. `help`, `call`, `nstobj`"); return reply; } const string help = "help"; SCommandGroupImpl all_cmds(TCommandGroup(CAutomationProc::Commands(), nullptr)); if (input.GetNode().AsString() == help) { return all_cmds.Help(help, ++input); } reply.Append(m_OKNode); if (!all_cmds.Exec("", io, this)) { NCBI_THROW_FMT(CAutomationException, eInvalidInput, "unknown command"); } return reply; } void CAutomationProc::SendWarning(const string& warn_msg, TAutomationObjectRef source) { CJsonNode warning(CJsonNode::NewArrayNode()); warning.Append(m_WarnNode); warning.AppendString(warn_msg); warning.AppendString(source->GetType()); warning.AppendInteger(source->GetID()); m_MessageSender->SendMessage(warning); } void CAutomationProc::SendError(const CTempString& error_message) { CJsonNode error(CJsonNode::NewArrayNode()); error.Append(m_ErrNode); error.AppendString(error_message); m_MessageSender->SendMessage(error); } TAutomationObjectRef& CAutomationProc::ObjectIdToRef(TObjectID object_id) { size_t index = (size_t) (object_id); if (index >= m_ObjectByIndex.size() || !m_ObjectByIndex[index]) { NCBI_THROW_FMT(CAutomationException, eCommandProcessingError, "Object with id '" << object_id << "' does not exist"); } return m_ObjectByIndex[index]; } class CMessageSender : public IMessageSender { public: CMessageSender(CJsonOverUTTPWriter& json_writer, CPipe& pipe) : m_JSONWriter(json_writer), m_Pipe(pipe) { } virtual void SendMessage(const CJsonNode& message); private: void SendOutputBuffer(); CJsonOverUTTPWriter& m_JSONWriter; CPipe& m_Pipe; }; void CMessageSender::SendMessage(const CJsonNode& message) { if (!m_JSONWriter.WriteMessage(message)) do SendOutputBuffer(); while (!m_JSONWriter.CompleteMessage()); SendOutputBuffer(); } void CMessageSender::SendOutputBuffer() { const char* output_buffer; size_t output_buffer_size; size_t bytes_written; do { m_JSONWriter.GetOutputBuffer(&output_buffer, &output_buffer_size); while (output_buffer_size > 0) { if (m_Pipe.Write(output_buffer, output_buffer_size, &bytes_written) != eIO_Success) { NCBI_THROW(CIOException, eWrite, "Error while writing to the pipe"); } output_buffer += bytes_written; output_buffer_size -= bytes_written; } } while (m_JSONWriter.NextOutputBuffer()); } class CMessageDumperSender : public IMessageSender { public: CMessageDumperSender(IMessageSender* actual_sender, FILE* protocol_dump_file); void DumpInputMessage(const CJsonNode& message); virtual void SendMessage(const CJsonNode& message); private: IMessageSender* m_ActualSender; FILE* m_ProtocolDumpFile; string m_ProtocolDumpTimeFormat; string m_DumpInputHeaderFormat; string m_DumpOutputHeaderFormat; }; CMessageDumperSender::CMessageDumperSender( IMessageSender* actual_sender, FILE* protocol_dump_file) : m_ActualSender(actual_sender), m_ProtocolDumpFile(protocol_dump_file), m_ProtocolDumpTimeFormat("Y/M/D h:m:s.l") { string pid_str(NStr::NumericToString((Int8) CProcess::GetCurrentPid())); m_DumpInputHeaderFormat.assign(1, '\n'); m_DumpInputHeaderFormat.append(71 + pid_str.length(), '='); m_DumpInputHeaderFormat.append("\n----- IN ------ %s (pid: "); m_DumpInputHeaderFormat.append(pid_str); m_DumpInputHeaderFormat.append(") -----------------------\n"); m_DumpOutputHeaderFormat.assign("----- OUT ----- %s (pid: "); m_DumpOutputHeaderFormat.append(pid_str); m_DumpOutputHeaderFormat.append(") -----------------------\n"); } void CMessageDumperSender::DumpInputMessage(const CJsonNode& message) { fprintf(m_ProtocolDumpFile, m_DumpInputHeaderFormat.c_str(), GetFastLocalTime().AsString(m_ProtocolDumpTimeFormat).c_str()); g_PrintJSON(m_ProtocolDumpFile, message); } void CMessageDumperSender::SendMessage(const CJsonNode& message) { fprintf(m_ProtocolDumpFile, m_DumpOutputHeaderFormat.c_str(), GetFastLocalTime().AsString(m_ProtocolDumpTimeFormat).c_str()); g_PrintJSON(m_ProtocolDumpFile, message); if (m_ActualSender != NULL) m_ActualSender->SendMessage(message); } int CGridCommandLineInterfaceApp::Automation_PipeServer() { CPipe pipe; pipe.OpenSelf(); #ifdef WIN32 setmode(fileno(stdin), O_BINARY); setmode(fileno(stdout), O_BINARY); #endif char read_buf[AUTOMATION_IO_BUFFER_SIZE]; char write_buf[AUTOMATION_IO_BUFFER_SIZE]; CUTTPReader reader; CUTTPWriter writer; writer.Reset(write_buf, sizeof(write_buf)); CJsonOverUTTPReader json_reader; CJsonOverUTTPWriter json_writer(writer); CMessageSender actual_message_sender(json_writer, pipe); IMessageSender* message_sender; auto_ptr<CMessageDumperSender> dumper_and_sender; if (!IsOptionSet(eProtocolDump)) message_sender = &actual_message_sender; else { dumper_and_sender.reset(new CMessageDumperSender(&actual_message_sender, m_Opts.protocol_dump)); message_sender = dumper_and_sender.get(); } { CJsonNode greeting(CJsonNode::NewArrayNode()); greeting.AppendString(GRID_APP_NAME); greeting.AppendInteger(PROTOCOL_VERSION); message_sender->SendMessage(greeting); } CAutomationProc proc(message_sender); size_t bytes_read; try { while (pipe.Read(read_buf, sizeof(read_buf), &bytes_read) == eIO_Success) { reader.SetNewBuffer(read_buf, bytes_read); while (json_reader.ReadMessage(reader)) { try { if (dumper_and_sender.get() != NULL) dumper_and_sender->DumpInputMessage( json_reader.GetMessage()); CJsonNode reply(proc.ProcessMessage( json_reader.GetMessage())); if (!reply) return 0; message_sender->SendMessage(reply); } catch (CAutomationException& e) { proc.SendError(e.ReportThis(eDPF_Log)); if (e.GetErrCode() == CAutomationException::eInvalidInput) return 2; } catch (CException& e) { proc.SendError(e.ReportThis(eDPF_Log)); } json_reader.Reset(); } } } catch (CJsonOverUTTPException& e) { return PROTOCOL_ERROR_BASE_RETCODE + e.GetErrCode(); } return 0; } #define DEBUG_CONSOLE_PROMPT ">>> " int CGridCommandLineInterfaceApp::Automation_DebugConsole() { printf("[" GRID_APP_NAME " automation debug console; " "protocol version " NCBI_AS_STRING(PROTOCOL_VERSION) "]\n" "Press ^D or type \"exit\" (in double qoutes) to quit.\n" "\n" DEBUG_CONSOLE_PROMPT); char read_buf[AUTOMATION_IO_BUFFER_SIZE]; CMessageDumperSender dumper_and_sender(NULL, stdout); CAutomationProc proc(&dumper_and_sender); while (fgets(read_buf, sizeof(read_buf), stdin) != NULL) { try { CJsonNode input_message(CJsonNode::ParseArray(read_buf)); try { dumper_and_sender.DumpInputMessage(input_message); CJsonNode reply(proc.ProcessMessage(input_message)); if (!reply) return 0; dumper_and_sender.SendMessage(reply); } catch (CException& e) { proc.SendError(e.ReportThis(eDPF_Log)); } } catch (CStringException& e) { printf("%*c syntax error\n", int(e.GetPos() + sizeof(DEBUG_CONSOLE_PROMPT) - 1), int('^')); } printf(DEBUG_CONSOLE_PROMPT); } puts(""); return 0; } int CGridCommandLineInterfaceApp::Cmd_Automate() { return IsOptionSet(eDebugConsole) ? Automation_DebugConsole() : Automation_PipeServer(); }

source navigation ]   [ diff markup ]   [ identifier search ]   [ freetext search ]   [ file search ]  

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.