diff --git a/ANode/parser/test/ParseOnly.cpp b/ANode/parser/test/ParseOnly.cpp index 954c301a6..f801b30e5 100644 --- a/ANode/parser/test/ParseOnly.cpp +++ b/ANode/parser/test/ParseOnly.cpp @@ -12,9 +12,9 @@ // // Description : //============================================================================ -#include -#include #include +#include +#include #include "Defs.hpp" #include "PrintStyle.hpp" @@ -28,46 +28,45 @@ using namespace ecf; // user 0m2.59s // sys 0m0.18s -int main(int argc, char* argv[]) -{ -// cout << "argc = " << argc << "\n"; -// for(int i = 0; i < argc; i++) { -// cout << "arg " << i << ":" << argv[i] << "\n"; -// } +int main(int argc, char* argv[]) { + // cout << "argc = " << argc << "\n"; + // for(int i = 0; i < argc; i++) { + // cout << "arg " << i << ":" << argv[i] << "\n"; + // } - if (argc != 2) { - cout << "Expect single argument which is path to a defs file\n"; - return 1; - } + if (argc != 2) { + cout << "Expect single argument which is path to a defs file\n"; + return 1; + } - std::string path = argv[1]; + std::string path = argv[1]; - Defs defs; - std::string errorMsg,warningMsg; - if (!defs.restore(path,errorMsg,warningMsg)) { - cout << errorMsg << "\n"; - cout << warningMsg << "\n"; - return 1; - } + Defs defs; + std::string errorMsg, warningMsg; + if (!defs.restore(path, errorMsg, warningMsg)) { + cout << errorMsg << "\n"; + cout << warningMsg << "\n"; + return 1; + } -// // Determine average number of variables for nodes with variables -// vector nodes; -// defs.getAllNodes(nodes); -// cout << "Total number of nodes: " << nodes.size() << "\n"; -// size_t number_of_variables = 0; -// size_t nodes_with_variables = 0; -// for(const auto& n : nodes) { -// // cout << n->variables().size() << "\n"; -// if (n->variables().size() > 0) { -// number_of_variables += n->variables().size(); -// nodes_with_variables++; -// } -// } -// cout << "number_of_variables " << number_of_variables << "\n"; -// cout << "nodes_with_variables " << nodes_with_variables << "\n"; -// cout <<"Average number of variables per node " << (double)number_of_variables/nodes_with_variables << "\n"; + // // Determine average number of variables for nodes with variables + // vector nodes; + // defs.getAllNodes(nodes); + // cout << "Total number of nodes: " << nodes.size() << "\n"; + // size_t number_of_variables = 0; + // size_t nodes_with_variables = 0; + // for(const auto& n : nodes) { + // // cout << n->variables().size() << "\n"; + // if (n->variables().size() > 0) { + // number_of_variables += n->variables().size(); + // nodes_with_variables++; + // } + // } + // cout << "number_of_variables " << number_of_variables << "\n"; + // cout << "nodes_with_variables " << nodes_with_variables << "\n"; + // cout <<"Average number of variables per node " << (double)number_of_variables/nodes_with_variables << "\n"; -// PrintStyle style(PrintStyle::MIGRATE); -// cout << defs; - return 0; + // PrintStyle style(PrintStyle::MIGRATE); + // cout << defs; + return 0; } diff --git a/ANode/parser/test/ParseTimer.cpp b/ANode/parser/test/ParseTimer.cpp index 4d72efbfa..28652710d 100644 --- a/ANode/parser/test/ParseTimer.cpp +++ b/ANode/parser/test/ParseTimer.cpp @@ -13,29 +13,29 @@ // Description : //============================================================================ -#include -#include #include +#include +#include +#include #include #include #include -#include -#include "DefsStructureParser.hpp" #include "Defs.hpp" -#include "NodeContainer.hpp" -#include "Suite.hpp" -#include "Task.hpp" +#include "DefsStructureParser.hpp" #include "Family.hpp" -#include "PrintStyle.hpp" -#include "PersistHelper.hpp" -#include "JobsParam.hpp" +#include "File.hpp" #include "Jobs.hpp" +#include "JobsParam.hpp" #include "Log.hpp" -#include "System.hpp" +#include "NodeContainer.hpp" +#include "PersistHelper.hpp" +#include "PrintStyle.hpp" #include "Str.hpp" -#include "File.hpp" +#include "Suite.hpp" +#include "System.hpp" +#include "Task.hpp" using namespace std; using namespace ecf; @@ -45,192 +45,214 @@ namespace fs = boost::filesystem; // This test is used to find a task given a path of the form: // suite/family/task // suite/family/family/task -void test_find_task_using_path( NodeContainer* f,const Defs& defs ) -{ - if (f != defs.findAbsNode(f->absNodePath()).get() ) cout << "Could not find path " << f->absNodePath() << "\n"; - - for(node_ptr t: f->nodeVec()) { - if (t.get() != defs.findAbsNode(t->absNodePath()).get()) cout << "Could not find path " << t->absNodePath() << "\n"; - Family* family = t->isFamily(); - if (family) { - test_find_task_using_path(family, defs); - } - } +void test_find_task_using_path(NodeContainer* f, const Defs& defs) { + if (f != defs.findAbsNode(f->absNodePath()).get()) + cout << "Could not find path " << f->absNodePath() << "\n"; + + for (node_ptr t : f->nodeVec()) { + if (t.get() != defs.findAbsNode(t->absNodePath()).get()) + cout << "Could not find path " << t->absNodePath() << "\n"; + Family* family = t->isFamily(); + if (family) { + test_find_task_using_path(family, defs); + } + } } // Create derived class, so that we can time the parse only // i.e ignore expression build/checking and limit checking class TestDefsStructureParser : public DefsStructureParser { public: - TestDefsStructureParser(Defs* defsfile, const std::string& file_name) : DefsStructureParser(defsfile,file_name) {} - bool do_parse_file(std::string& errorMsg) { return DefsStructureParser::do_parse_file(errorMsg); } + TestDefsStructureParser(Defs* defsfile, const std::string& file_name) : DefsStructureParser(defsfile, file_name) {} + bool do_parse_file(std::string& errorMsg) { return DefsStructureParser::do_parse_file(errorMsg); } }; +int main(int argc, char* argv[]) { + // cout << "argc = " << argc << "\n"; + // for(int i = 0; i < argc; i++) { + // cout << "arg " << i << ":" << argv[i] << "\n"; + // } + + if (argc != 2) { + cout << "Expect single argument which is path to a defs file\n"; + return 1; + } + + std::string path = argv[1]; + + auto_cpu_timer t; + cpu_timer timer; + + /// If this is moved below, we get some caching affect, with the persist and reload timing + Defs defs; + { + timer.start(); + std::string errorMsg, warningMsg; + bool result = defs.restore(path, errorMsg, warningMsg); + cout << " Parsing Node tree & AST creation time parse(" << result + << ") = " << timer.format(3, Str::cpu_timer_format()) << endl; + } + { + Defs local_defs; + timer.start(); + TestDefsStructureParser checkPtParser(&local_defs, path); + std::string errorMsg; + bool result = checkPtParser.do_parse_file(errorMsg); + cout << " Parsing Node tree *only* time parse(" << result + << ") = " << timer.format(3, Str::cpu_timer_format()) << endl; + } + { + timer.start(); + std::string defs_as_string; + defs.save_as_string(defs_as_string, PrintStyle::DEFS); + Defs newDefs; + std::string error_msg, warning_msg; // ignore error since some input defs have invalid triggers + newDefs.restore_from_string(defs_as_string, error_msg, warning_msg); + cout << " Save and restore as string(DEFS) = " << timer.format(3, Str::cpu_timer_format()) + << " -> string size(" << defs_as_string.size() << ")" << endl; + } + { + timer.start(); + std::string defs_as_string; + defs.save_as_string(defs_as_string, PrintStyle::NET); + Defs newDefs; + std::string error_msg, warning_msg; // ignore error since some input defs have invalid triggers + newDefs.restore_from_string(defs_as_string, error_msg, warning_msg); + cout << " Save and restore as string(NET) = " << timer.format(3, Str::cpu_timer_format()) + << " -> string size(" << defs_as_string.size() << ") checks relaxed" << endl; + } + { + timer.start(); + std::string defs_as_string; + defs.save_as_string(defs_as_string, PrintStyle::MIGRATE); + Defs newDefs; + std::string error_msg, warning_msg; // ignore error since some input defs have invalid triggers + newDefs.restore_from_string(defs_as_string, error_msg, warning_msg); + cout << " Save and restore as string(MIGRATE) = " << timer.format(3, Str::cpu_timer_format()) + << " -> string size(" << defs_as_string.size() << ")" << endl; + } + { + // Test time for persisting to defs file only + std::string tmpFilename = "tmp.def"; -int main(int argc, char* argv[]) -{ -// cout << "argc = " << argc << "\n"; -// for(int i = 0; i < argc; i++) { -// cout << "arg " << i << ":" << argv[i] << "\n"; -// } - - if (argc != 2) { - cout << "Expect single argument which is path to a defs file\n"; - return 1; - } - - std::string path = argv[1]; - - auto_cpu_timer t; - cpu_timer timer; - - /// If this is moved below, we get some caching affect, with the persist and reload timing - Defs defs; - { - timer.start(); - std::string errorMsg,warningMsg; - bool result = defs.restore(path,errorMsg,warningMsg); - cout << " Parsing Node tree & AST creation time parse(" << result << ") = " << timer.format(3,Str::cpu_timer_format()) << endl; - } - { - Defs local_defs; - timer.start(); - TestDefsStructureParser checkPtParser( &local_defs, path); - std::string errorMsg; - bool result = checkPtParser.do_parse_file(errorMsg); - cout << " Parsing Node tree *only* time parse(" << result << ") = " << timer.format(3,Str::cpu_timer_format()) << endl; - } - { - timer.start(); - std::string defs_as_string; - defs.save_as_string(defs_as_string,PrintStyle::DEFS); - Defs newDefs; - std::string error_msg,warning_msg; // ignore error since some input defs have invalid triggers - newDefs.restore_from_string( defs_as_string,error_msg,warning_msg ); - cout << " Save and restore as string(DEFS) = " << timer.format(3,Str::cpu_timer_format()) << " -> string size(" << defs_as_string.size() << ")" << endl; - } - { - timer.start(); - std::string defs_as_string; - defs.save_as_string(defs_as_string,PrintStyle::NET); - Defs newDefs; - std::string error_msg,warning_msg; // ignore error since some input defs have invalid triggers - newDefs.restore_from_string( defs_as_string,error_msg,warning_msg ); - cout << " Save and restore as string(NET) = " << timer.format(3,Str::cpu_timer_format()) << " -> string size(" << defs_as_string.size() << ") checks relaxed" << endl; - } - { - timer.start(); - std::string defs_as_string; - defs.save_as_string(defs_as_string,PrintStyle::MIGRATE); - Defs newDefs; - std::string error_msg,warning_msg; // ignore error since some input defs have invalid triggers - newDefs.restore_from_string( defs_as_string,error_msg,warning_msg ); - cout << " Save and restore as string(MIGRATE) = " << timer.format(3,Str::cpu_timer_format()) << " -> string size(" << defs_as_string.size() << ")" << endl; - } - { - // Test time for persisting to defs file only - std::string tmpFilename = "tmp.def"; - - timer.start(); - defs.save_as_checkpt(tmpFilename); - cout << " Save as DEFS checkpoint, time taken = " << timer.format(3,Str::cpu_timer_format()) << endl; - - std::remove(tmpFilename.c_str()); - } - - { - // Test time for persisting to CEREAL checkpoint file only - fs::path fs_path(path); - // std::cout << "parent path " << fs_path.parent_path() << "\n"; - // std::cout << "root path " << fs_path.root_path() << "\n"; - // std::cout << "root name " << fs_path.root_name() << "\n"; - // std::cout << "root directory " << fs_path.root_directory() << "\n"; - // std::cout << "relative_path " << fs_path.relative_path() << "\n"; - // std::cout << "filename " << fs_path.filename() << "\n"; - // std::cout << "stem " << fs_path.stem() << "\n"; - // std::cout << "extension " << fs_path.extension() << "\n"; - - std::stringstream ss; + timer.start(); + defs.save_as_checkpt(tmpFilename); + cout << " Save as DEFS checkpoint, time taken = " << timer.format(3, Str::cpu_timer_format()) + << endl; + + std::remove(tmpFilename.c_str()); + } + + { + // Test time for persisting to CEREAL checkpoint file only + fs::path fs_path(path); + // std::cout << "parent path " << fs_path.parent_path() << "\n"; + // std::cout << "root path " << fs_path.root_path() << "\n"; + // std::cout << "root name " << fs_path.root_name() << "\n"; + // std::cout << "root directory " << fs_path.root_directory() << "\n"; + // std::cout << "relative_path " << fs_path.relative_path() << "\n"; + // std::cout << "filename " << fs_path.filename() << "\n"; + // std::cout << "stem " << fs_path.stem() << "\n"; + // std::cout << "extension " << fs_path.extension() << "\n"; + + std::stringstream ss; #ifdef DEBUG - ss << "/var/tmp/ma0/JSON/debug_" << fs_path.stem() << ".json"; + ss << "/var/tmp/ma0/JSON/debug_" << fs_path.stem() << ".json"; #else - ss << "/var/tmp/ma0/JSON/" << fs_path.stem() << ".json"; + ss << "/var/tmp/ma0/JSON/" << fs_path.stem() << ".json"; #endif - std::string json_filepath = ss.str(); - Str::replaceall(json_filepath,"\"",""); // fs_path.stem() seems to add ", so remove them - //cout << " json_filepath: " << json_filepath << endl; - - std::remove(json_filepath.c_str()); - timer.start(); - defs.cereal_save_as_checkpt(json_filepath); - cout << " Save as CEREAL checkpoint, time taken = " << timer.format(3,Str::cpu_timer_format()) << endl; - } - - { - // may need to comment out output for large differences. Will double the time. - bool do_compare = false; - timer.start(); - PersistHelper helper; - bool result = helper.test_defs_checkpt_and_reload(defs,do_compare); - cout << " Checkpt(DEFS) and reload, time taken = " - << timer.format(3,Str::cpu_timer_format()) << " file_size(" << helper.file_size() << ") result(" << result << ") msg(" << helper.errorMsg() << ")" << endl; - } - - { - bool do_compare = false; - timer.start(); - PersistHelper helper; - bool result = helper.test_cereal_checkpt_and_reload(defs, do_compare); - cout << " Checkpt(CEREAL) and reload , time taken = "; - cout << timer.format(3,Str::cpu_timer_format()) << " file_size(" << helper.file_size() << ") result(" << result << ") msg(" << helper.errorMsg() << ")" << endl; - } - - - { - timer.start(); - for(suite_ptr s : defs.suiteVec()) { test_find_task_using_path(s.get(),defs); } - cout << " Test all paths can be found. time taken = " << timer.format(3,Str::cpu_timer_format()) << endl; - } - { - // Time how long it takes for job submission. Must call begin on all suites first. - timer.start(); - defs.beginAll(); - int count = 10; - JobsParam jobsParam; // default is not to create jobs, hence only used in testing - Jobs jobs(&defs); - for (int i = 0; i < count; i++) {jobs.generate(jobsParam);} - cout << " time for 10 jobSubmissions = " << timer.format(3,Str::cpu_timer_format()) << " jobs:" << jobsParam.submitted().size() << endl; - } - { - // Time how long it takes for post process - timer.start(); - string errorMsg,warningMsg; - bool result = defs.check(errorMsg,warningMsg); - cout << " Time for Defs::check(inlimit resolution) = " << timer.format(3,Str::cpu_timer_format()) << " result(" << result << ")" << endl; - } - { - // Time how long it takes to delete all nodes/ references. Delete all tasks and then suites/families. - timer.start(); - std::vector tasks; - defs.getAllTasks(tasks); - for(Task* ta: tasks) { - if (!defs.deleteChild(ta)) cout << "Failed to delete task\n"; - } - tasks.clear(); defs.getAllTasks(tasks); - if (!tasks.empty()) cout << "Expected all tasks to be deleted but found " << tasks.size() << "\n"; - - std::vector vec = defs.suiteVec(); // make a copy, to avoid invalidating iterators - for(suite_ptr s: vec) { - std::vector familyVec = s->nodeVec(); // make a copy, to avoid invalidating iterators - for(node_ptr f: familyVec) { - if (!defs.deleteChild(f.get())) cout << "Failed to delete family\n"; - } - if (!s->nodeVec().empty()) cout << "Expected all Families to be deleted but found " << s->nodeVec().size() << "\n"; - if (!defs.deleteChild(s.get())) cout << "Failed to delete suite\n"; - } - if (!defs.suiteVec().empty()) cout << "Expected all Suites to be deleted but found " << defs.suiteVec().size() << "\n"; - - cout << " time for deleting all nodes = " << timer.format(3,Str::cpu_timer_format()) << endl; - } + std::string json_filepath = ss.str(); + Str::replaceall(json_filepath, "\"", ""); // fs_path.stem() seems to add ", so remove them + // cout << " json_filepath: " << json_filepath << endl; + + std::remove(json_filepath.c_str()); + timer.start(); + defs.cereal_save_as_checkpt(json_filepath); + cout << " Save as CEREAL checkpoint, time taken = " << timer.format(3, Str::cpu_timer_format()) + << endl; + } + + { + // may need to comment out output for large differences. Will double the time. + bool do_compare = false; + timer.start(); + PersistHelper helper; + bool result = helper.test_defs_checkpt_and_reload(defs, do_compare); + cout << " Checkpt(DEFS) and reload, time taken = " << timer.format(3, Str::cpu_timer_format()) + << " file_size(" << helper.file_size() << ") result(" << result << ") msg(" << helper.errorMsg() << ")" + << endl; + } + + { + bool do_compare = false; + timer.start(); + PersistHelper helper; + bool result = helper.test_cereal_checkpt_and_reload(defs, do_compare); + cout << " Checkpt(CEREAL) and reload , time taken = "; + cout << timer.format(3, Str::cpu_timer_format()) << " file_size(" << helper.file_size() << ") result(" + << result << ") msg(" << helper.errorMsg() << ")" << endl; + } + + { + timer.start(); + for (suite_ptr s : defs.suiteVec()) { + test_find_task_using_path(s.get(), defs); + } + cout << " Test all paths can be found. time taken = " << timer.format(3, Str::cpu_timer_format()) + << endl; + } + { + // Time how long it takes for job submission. Must call begin on all suites first. + timer.start(); + defs.beginAll(); + int count = 10; + JobsParam jobsParam; // default is not to create jobs, hence only used in testing + Jobs jobs(&defs); + for (int i = 0; i < count; i++) { + jobs.generate(jobsParam); + } + cout << " time for 10 jobSubmissions = " << timer.format(3, Str::cpu_timer_format()) + << " jobs:" << jobsParam.submitted().size() << endl; + } + { + // Time how long it takes for post process + timer.start(); + string errorMsg, warningMsg; + bool result = defs.check(errorMsg, warningMsg); + cout << " Time for Defs::check(inlimit resolution) = " << timer.format(3, Str::cpu_timer_format()) + << " result(" << result << ")" << endl; + } + { + // Time how long it takes to delete all nodes/ references. Delete all tasks and then suites/families. + timer.start(); + std::vector tasks; + defs.getAllTasks(tasks); + for (Task* ta : tasks) { + if (!defs.deleteChild(ta)) + cout << "Failed to delete task\n"; + } + tasks.clear(); + defs.getAllTasks(tasks); + if (!tasks.empty()) + cout << "Expected all tasks to be deleted but found " << tasks.size() << "\n"; + + std::vector vec = defs.suiteVec(); // make a copy, to avoid invalidating iterators + for (suite_ptr s : vec) { + std::vector familyVec = s->nodeVec(); // make a copy, to avoid invalidating iterators + for (node_ptr f : familyVec) { + if (!defs.deleteChild(f.get())) + cout << "Failed to delete family\n"; + } + if (!s->nodeVec().empty()) + cout << "Expected all Families to be deleted but found " << s->nodeVec().size() << "\n"; + if (!defs.deleteChild(s.get())) + cout << "Failed to delete suite\n"; + } + if (!defs.suiteVec().empty()) + cout << "Expected all Suites to be deleted but found " << defs.suiteVec().size() << "\n"; + + cout << " time for deleting all nodes = " << timer.format(3, Str::cpu_timer_format()) + << endl; + } } diff --git a/ANode/parser/test/PersistHelper.cpp b/ANode/parser/test/PersistHelper.cpp index cbc90911a..88592ab8b 100644 --- a/ANode/parser/test/PersistHelper.cpp +++ b/ANode/parser/test/PersistHelper.cpp @@ -1,23 +1,24 @@ //============================================================================ // Name : // Author : Avi -// Revision : $Revision$ +// Revision : $Revision$ // // Copyright 2009- ECMWF. -// This software is licensed under the terms of the Apache Licence version 2.0 -// which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. -// In applying this licence, ECMWF does not waive the privileges and immunities -// granted to it by virtue of its status as an intergovernmental organisation -// nor does it submit to any jurisdiction. +// This software is licensed under the terms of the Apache Licence version 2.0 +// which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. +// In applying this licence, ECMWF does not waive the privileges and immunities +// granted to it by virtue of its status as an intergovernmental organisation +// nor does it submit to any jurisdiction. // // Description : //============================================================================ +#include "PersistHelper.hpp" + #include #include -#include "PersistHelper.hpp" #include "Defs.hpp" #include "Ecf.hpp" #include "File.hpp" @@ -26,307 +27,303 @@ namespace fs = boost::filesystem; using namespace std; using namespace ecf; -bool PersistHelper::test_persist_and_reload( const Defs& theInMemoryDefs, PrintStyle::Type_t file_type_on_disk,bool do_compare) -{ - // Write parsed file to disk, and reload, then compare defs, they should be the same - errorMsg_.clear(); - file_size_ = 0; +bool PersistHelper::test_persist_and_reload(const Defs& theInMemoryDefs, + PrintStyle::Type_t file_type_on_disk, + bool do_compare) { + // Write parsed file to disk, and reload, then compare defs, they should be the same + errorMsg_.clear(); + file_size_ = 0; #ifdef DEBUG - std::string tmpFilename = "tmp_d.def"; + std::string tmpFilename = "tmp_d.def"; #else - std::string tmpFilename = "tmp.def"; + std::string tmpFilename = "tmp.def"; #endif - { - // The file MUST be written in the *SAME* form that it was read, Otherwise they will not compare: - theInMemoryDefs.save_as_filename(tmpFilename,file_type_on_disk); - } - - // Reload the file we just persisted and compare with in memory defs - Defs savedDef; - return reload_from_defs_file(theInMemoryDefs,savedDef,tmpFilename,do_compare); + { + // The file MUST be written in the *SAME* form that it was read, Otherwise they will not compare: + theInMemoryDefs.save_as_filename(tmpFilename, file_type_on_disk); + } + + // Reload the file we just persisted and compare with in memory defs + Defs savedDef; + return reload_from_defs_file(theInMemoryDefs, savedDef, tmpFilename, do_compare); } -bool PersistHelper::test_defs_checkpt_and_reload( const Defs& theInMemoryDefs, bool do_compare) -{ - // Write parsed file to disk, and reload, then compare defs, they should be the same - errorMsg_.clear(); - file_size_ = 0; +bool PersistHelper::test_defs_checkpt_and_reload(const Defs& theInMemoryDefs, bool do_compare) { + // Write parsed file to disk, and reload, then compare defs, they should be the same + errorMsg_.clear(); + file_size_ = 0; #ifdef DEBUG - std::string tmpFilename = "tmp_d.def"; + std::string tmpFilename = "tmp_d.def"; #else - std::string tmpFilename = "tmp.def"; + std::string tmpFilename = "tmp.def"; #endif - { - // The file MUST be written in the *SAME* form that it was read, Otherwise they will not compare: - theInMemoryDefs.save_as_checkpt(tmpFilename); - } - - // Reload the file we just persisted and compare with in memory defs - Defs savedDef; - bool reload_result = reload_from_defs_file(theInMemoryDefs,savedDef,tmpFilename,do_compare); - if (reload_result) return savedDef.checkInvariants(errorMsg_); - return false; + { + // The file MUST be written in the *SAME* form that it was read, Otherwise they will not compare: + theInMemoryDefs.save_as_checkpt(tmpFilename); + } + + // Reload the file we just persisted and compare with in memory defs + Defs savedDef; + bool reload_result = reload_from_defs_file(theInMemoryDefs, savedDef, tmpFilename, do_compare); + if (reload_result) + return savedDef.checkInvariants(errorMsg_); + return false; } - -bool PersistHelper::test_cereal_checkpt_and_reload( const Defs& theInMemoryDefs, bool do_compare) -{ - errorMsg_.clear(); - file_size_ = 0; - if (!theInMemoryDefs.checkInvariants(errorMsg_)) { - return false; - } - - // Save in memory defs as a check pt file, then restore and compare - Defs reloaded_defs; - bool reload_result = reload_from_cereal_checkpt_file(theInMemoryDefs,reloaded_defs,do_compare); - if (reload_result) return reloaded_defs.checkInvariants(errorMsg_); - return false; +bool PersistHelper::test_cereal_checkpt_and_reload(const Defs& theInMemoryDefs, bool do_compare) { + errorMsg_.clear(); + file_size_ = 0; + if (!theInMemoryDefs.checkInvariants(errorMsg_)) { + return false; + } + + // Save in memory defs as a check pt file, then restore and compare + Defs reloaded_defs; + bool reload_result = reload_from_cereal_checkpt_file(theInMemoryDefs, reloaded_defs, do_compare); + if (reload_result) + return reloaded_defs.checkInvariants(errorMsg_); + return false; } -bool PersistHelper::test_state_persist_and_reload_with_checkpt(const Defs& theInMemoryDefs ) -{ - // Write Defs to disk, and reload, then compare defs reloaded checkpt file, they should be the same - errorMsg_.clear(); - file_size_ = 0; - if (!theInMemoryDefs.checkInvariants(errorMsg_)) { - return false; - } +bool PersistHelper::test_state_persist_and_reload_with_checkpt(const Defs& theInMemoryDefs) { + // Write Defs to disk, and reload, then compare defs reloaded checkpt file, they should be the same + errorMsg_.clear(); + file_size_ = 0; + if (!theInMemoryDefs.checkInvariants(errorMsg_)) { + return false; + } - DebugEquality debug_equality; // only as affect in DEBUG build + DebugEquality debug_equality; // only as affect in DEBUG build #ifdef DEBUG - std::string tmpFilename = "tmp_d.def"; + std::string tmpFilename = "tmp_d.def"; #else - std::string tmpFilename = "tmp.def"; + std::string tmpFilename = "tmp.def"; #endif - { - // The file MUST be written in the *SAME* form that it was read, Otherwise they will not compare: - theInMemoryDefs.save_as_checkpt(tmpFilename); // will save edit history - } - - Defs reload_strings_def; - { - // Open file, and parse as a string. - std::string defs_as_string; - if (!File::open(tmpFilename,defs_as_string)) { - errorMsg_ += "Could not file file: " + tmpFilename ; - return false; - } - std::string error_msg, warning; - if (!reload_strings_def.restore_from_string(defs_as_string,error_msg, warning)) { - errorMsg_ += error_msg ; - return false; - } - if (!reload_strings_def.checkInvariants(errorMsg_)) { - return false; - } - } - - - // Reload the file we just persisted and compare with in memory defs - Defs reloaded_defs; - if (!reload_from_defs_file(theInMemoryDefs,reloaded_defs,tmpFilename)) { - return false; - } - if (!reloaded_defs.checkInvariants(errorMsg_)) { - return false; - } - - - // Save in memory defs as a check pt file, then restore and compare - Defs reloaded_cereal_checkPt_defs; - if (!reload_from_cereal_checkpt_file(theInMemoryDefs,reloaded_cereal_checkPt_defs ,true)) { - return false; - } - if (!reloaded_cereal_checkPt_defs.checkInvariants(errorMsg_)) { - return false; - } - - - // Make sure reloading def's file with state is same as the checkpt file - bool match = reloaded_defs == reloaded_cereal_checkPt_defs; - - if (!match) { - std::stringstream ss; - ss << "\nPersistHelper::test_state_persist_and_reload_with_checkpt\n"; - ss << "In reloaded_defs_file and reloaded_checkPt_defs don't match\n"; - ss << "+++++++++++++ in memory defs ++++++++++++++++++++++++++++\n"; - PrintStyle style(PrintStyle::MIGRATE); // will save edit history - ss << theInMemoryDefs; - ss << "+++++++++++++ reloaded_defs ++++++++++++++++++++++++++++\n"; - ss << reloaded_defs; - ss << "++++++++++++++ reloaded_checkPt_defs ++++++++++++++++++++++++++++\n"; - ss << reloaded_cereal_checkPt_defs ; - errorMsg_ += ss.str(); - } - else { - if (compare_edit_history_ && !reloaded_defs.compare_edit_history(reloaded_cereal_checkPt_defs )) { - std::stringstream ss; - ss << "\nPersistHelper::test_state_persist_and_reload_with_checkpt compare_edit_history_\n"; - ss << "In reloaded_defs_file and reloaded_checkPt_defs edit history don't match\n"; - ss << "+++++++++++++ in memory defs ++++++++++++++++++++++++++++\n"; - PrintStyle style(PrintStyle::MIGRATE); // will save edit history - ss << theInMemoryDefs; - ss << "+++++++++++++ reloaded_defs ++++++++++++++++++++++++++++\n"; - ss << reloaded_defs; - ss << "++++++++++++++ reloaded_checkPt_defs ++++++++++++++++++++++++++++\n"; - ss << reloaded_cereal_checkPt_defs; - errorMsg_ += ss.str(); - } - } - if ( !reloaded_defs.compare_change_no(reloaded_cereal_checkPt_defs )) { - errorMsg_ += "\nPersistHelper::test_state_persist_and_reload_with_checkpt: Change numbers don't compare between reloaded_defs and reloaded_cereal_checkPt_defs \n"; - } - - - // Make sure reloading def's file with state is same as the checkpt file - match = reload_strings_def == reloaded_cereal_checkPt_defs; - if (!match) { - std::stringstream ss; - ss << "\nPersistHelper::test_state_persist_and_reload_with_checkpt\n"; - ss << "In reloaded_defs file AS STRING and reloaded_checkPt_defs don't match\n"; - ss << "+++++++++++++ in memory defs ++++++++++++++++++++++++++++\n"; - PrintStyle style(PrintStyle::MIGRATE); // will save edit history - ss << theInMemoryDefs; - ss << "+++++++++++++ reload_strings_def ++++++++++++++++++++++++++++\n"; - ss << reload_strings_def; - ss << "++++++++++++++ reloaded_checkPt_defs ++++++++++++++++++++++++++++\n"; - ss << reloaded_cereal_checkPt_defs ; - errorMsg_ += ss.str(); - } - else { - if (compare_edit_history_ && !reload_strings_def.compare_edit_history(reloaded_cereal_checkPt_defs )) { - std::stringstream ss; - ss << "\nPersistHelper::test_state_persist_and_reload_with_checkpt compare_edit_history_\n"; - ss << "In reloaded_defs_file and reloaded_checkPt_defs edit history don't match\n"; - ss << "+++++++++++++ in memory defs ++++++++++++++++++++++++++++\n"; - PrintStyle style(PrintStyle::MIGRATE); // will save edit history - ss << theInMemoryDefs; - ss << "+++++++++++++ reload_strings_def ++++++++++++++++++++++++++++\n"; - ss << reload_strings_def; - ss << "++++++++++++++ reloaded_checkPt_defs ++++++++++++++++++++++++++++\n"; - ss << reloaded_cereal_checkPt_defs; - errorMsg_ += ss.str(); - } - } - if ( !reload_strings_def.compare_change_no(reloaded_cereal_checkPt_defs )) { - errorMsg_ += "\nPersistHelper::test_state_persist_and_reload_with_checkpt: Change numbers don't compare between reload_strings_def and reloaded_cereal_checkPt_defs\n"; - } - - return errorMsg_.empty(); + { + // The file MUST be written in the *SAME* form that it was read, Otherwise they will not compare: + theInMemoryDefs.save_as_checkpt(tmpFilename); // will save edit history + } + + Defs reload_strings_def; + { + // Open file, and parse as a string. + std::string defs_as_string; + if (!File::open(tmpFilename, defs_as_string)) { + errorMsg_ += "Could not file file: " + tmpFilename; + return false; + } + std::string error_msg, warning; + if (!reload_strings_def.restore_from_string(defs_as_string, error_msg, warning)) { + errorMsg_ += error_msg; + return false; + } + if (!reload_strings_def.checkInvariants(errorMsg_)) { + return false; + } + } + + // Reload the file we just persisted and compare with in memory defs + Defs reloaded_defs; + if (!reload_from_defs_file(theInMemoryDefs, reloaded_defs, tmpFilename)) { + return false; + } + if (!reloaded_defs.checkInvariants(errorMsg_)) { + return false; + } + + // Save in memory defs as a check pt file, then restore and compare + Defs reloaded_cereal_checkPt_defs; + if (!reload_from_cereal_checkpt_file(theInMemoryDefs, reloaded_cereal_checkPt_defs, true)) { + return false; + } + if (!reloaded_cereal_checkPt_defs.checkInvariants(errorMsg_)) { + return false; + } + + // Make sure reloading def's file with state is same as the checkpt file + bool match = reloaded_defs == reloaded_cereal_checkPt_defs; + + if (!match) { + std::stringstream ss; + ss << "\nPersistHelper::test_state_persist_and_reload_with_checkpt\n"; + ss << "In reloaded_defs_file and reloaded_checkPt_defs don't match\n"; + ss << "+++++++++++++ in memory defs ++++++++++++++++++++++++++++\n"; + PrintStyle style(PrintStyle::MIGRATE); // will save edit history + ss << theInMemoryDefs; + ss << "+++++++++++++ reloaded_defs ++++++++++++++++++++++++++++\n"; + ss << reloaded_defs; + ss << "++++++++++++++ reloaded_checkPt_defs ++++++++++++++++++++++++++++\n"; + ss << reloaded_cereal_checkPt_defs; + errorMsg_ += ss.str(); + } + else { + if (compare_edit_history_ && !reloaded_defs.compare_edit_history(reloaded_cereal_checkPt_defs)) { + std::stringstream ss; + ss << "\nPersistHelper::test_state_persist_and_reload_with_checkpt compare_edit_history_\n"; + ss << "In reloaded_defs_file and reloaded_checkPt_defs edit history don't match\n"; + ss << "+++++++++++++ in memory defs ++++++++++++++++++++++++++++\n"; + PrintStyle style(PrintStyle::MIGRATE); // will save edit history + ss << theInMemoryDefs; + ss << "+++++++++++++ reloaded_defs ++++++++++++++++++++++++++++\n"; + ss << reloaded_defs; + ss << "++++++++++++++ reloaded_checkPt_defs ++++++++++++++++++++++++++++\n"; + ss << reloaded_cereal_checkPt_defs; + errorMsg_ += ss.str(); + } + } + if (!reloaded_defs.compare_change_no(reloaded_cereal_checkPt_defs)) { + errorMsg_ += "\nPersistHelper::test_state_persist_and_reload_with_checkpt: Change numbers don't compare " + "between reloaded_defs and reloaded_cereal_checkPt_defs \n"; + } + + // Make sure reloading def's file with state is same as the checkpt file + match = reload_strings_def == reloaded_cereal_checkPt_defs; + if (!match) { + std::stringstream ss; + ss << "\nPersistHelper::test_state_persist_and_reload_with_checkpt\n"; + ss << "In reloaded_defs file AS STRING and reloaded_checkPt_defs don't match\n"; + ss << "+++++++++++++ in memory defs ++++++++++++++++++++++++++++\n"; + PrintStyle style(PrintStyle::MIGRATE); // will save edit history + ss << theInMemoryDefs; + ss << "+++++++++++++ reload_strings_def ++++++++++++++++++++++++++++\n"; + ss << reload_strings_def; + ss << "++++++++++++++ reloaded_checkPt_defs ++++++++++++++++++++++++++++\n"; + ss << reloaded_cereal_checkPt_defs; + errorMsg_ += ss.str(); + } + else { + if (compare_edit_history_ && !reload_strings_def.compare_edit_history(reloaded_cereal_checkPt_defs)) { + std::stringstream ss; + ss << "\nPersistHelper::test_state_persist_and_reload_with_checkpt compare_edit_history_\n"; + ss << "In reloaded_defs_file and reloaded_checkPt_defs edit history don't match\n"; + ss << "+++++++++++++ in memory defs ++++++++++++++++++++++++++++\n"; + PrintStyle style(PrintStyle::MIGRATE); // will save edit history + ss << theInMemoryDefs; + ss << "+++++++++++++ reload_strings_def ++++++++++++++++++++++++++++\n"; + ss << reload_strings_def; + ss << "++++++++++++++ reloaded_checkPt_defs ++++++++++++++++++++++++++++\n"; + ss << reloaded_cereal_checkPt_defs; + errorMsg_ += ss.str(); + } + } + if (!reload_strings_def.compare_change_no(reloaded_cereal_checkPt_defs)) { + errorMsg_ += "\nPersistHelper::test_state_persist_and_reload_with_checkpt: Change numbers don't compare " + "between reload_strings_def and reloaded_cereal_checkPt_defs\n"; + } + + return errorMsg_.empty(); } - -bool PersistHelper::reload_from_defs_file(const Defs& theInMemoryDefs, Defs& reloaded_defs, const std::string& tmpFilename,bool do_compare ) -{ - DebugEquality debug_equality; // only as affect in DEBUG build - - std::string warningMsg; - if (!reloaded_defs.restore(tmpFilename,errorMsg_,warningMsg)) { - std::stringstream ss; - ss << "RE-PARSE failed for " << tmpFilename << "\n"; - errorMsg_ += ss.str(); - return false; - } - - if (do_compare) { - // Make sure the file we just parsed match's the one we persisted - bool match = reloaded_defs == theInMemoryDefs; - - if (!match) { - std::stringstream ss; - ss << "\nPersistHelper::reload_from_defs_file\n"; - ss << "In memory and reloaded def's don't match\n"; - ss << "+++++++++++++ Saved/reloaded_defs ++++++++++++++++++++++++++++\n"; - PrintStyle style(PrintStyle::STATE); - ss << reloaded_defs; - ss << "++++++++++++++ In memory def ++++++++++++++++++++++++++++\n"; - ss << theInMemoryDefs; - errorMsg_ += ss.str(); - } - else { - if (compare_edit_history_ && !reloaded_defs.compare_edit_history(theInMemoryDefs)) { +bool PersistHelper::reload_from_defs_file(const Defs& theInMemoryDefs, + Defs& reloaded_defs, + const std::string& tmpFilename, + bool do_compare) { + DebugEquality debug_equality; // only as affect in DEBUG build + + std::string warningMsg; + if (!reloaded_defs.restore(tmpFilename, errorMsg_, warningMsg)) { + std::stringstream ss; + ss << "RE-PARSE failed for " << tmpFilename << "\n"; + errorMsg_ += ss.str(); + return false; + } + + if (do_compare) { + // Make sure the file we just parsed match's the one we persisted + bool match = reloaded_defs == theInMemoryDefs; + + if (!match) { std::stringstream ss; - ss << "\nPersistHelper::reload_from_defs_file compare_edit_history_\n"; + ss << "\nPersistHelper::reload_from_defs_file\n"; ss << "In memory and reloaded def's don't match\n"; ss << "+++++++++++++ Saved/reloaded_defs ++++++++++++++++++++++++++++\n"; - PrintStyle style(PrintStyle::MIGRATE); + PrintStyle style(PrintStyle::STATE); ss << reloaded_defs; ss << "++++++++++++++ In memory def ++++++++++++++++++++++++++++\n"; ss << theInMemoryDefs; errorMsg_ += ss.str(); - } - } - if ( !reloaded_defs.compare_change_no( theInMemoryDefs )) { - errorMsg_ += "\nPersistHelper::reload_from_defs_file: Change numbers don't compare between reloaded_defs and theInMemoryDefs \n"; - } - } - - file_size_ = fs::file_size(tmpFilename); - std::remove(tmpFilename.c_str()); - return errorMsg_.empty(); + } + else { + if (compare_edit_history_ && !reloaded_defs.compare_edit_history(theInMemoryDefs)) { + std::stringstream ss; + ss << "\nPersistHelper::reload_from_defs_file compare_edit_history_\n"; + ss << "In memory and reloaded def's don't match\n"; + ss << "+++++++++++++ Saved/reloaded_defs ++++++++++++++++++++++++++++\n"; + PrintStyle style(PrintStyle::MIGRATE); + ss << reloaded_defs; + ss << "++++++++++++++ In memory def ++++++++++++++++++++++++++++\n"; + ss << theInMemoryDefs; + errorMsg_ += ss.str(); + } + } + if (!reloaded_defs.compare_change_no(theInMemoryDefs)) { + errorMsg_ += "\nPersistHelper::reload_from_defs_file: Change numbers don't compare between reloaded_defs " + "and theInMemoryDefs \n"; + } + } + + file_size_ = fs::file_size(tmpFilename); + std::remove(tmpFilename.c_str()); + return errorMsg_.empty(); } - -bool PersistHelper::reload_from_cereal_checkpt_file(const Defs& theInMemoryDefs, - Defs& reloaded_defs, - bool do_compare) -{ - // make sure edit history is saved +bool PersistHelper::reload_from_cereal_checkpt_file(const Defs& theInMemoryDefs, Defs& reloaded_defs, bool do_compare) { + // make sure edit history is saved #ifdef DEBUG - std::string tmpCheckPt_file = "tmp.check_debug"; + std::string tmpCheckPt_file = "tmp.check_debug"; #else - std::string tmpCheckPt_file = "tmp.check"; + std::string tmpCheckPt_file = "tmp.check"; #endif - theInMemoryDefs.cereal_save_as_checkpt(tmpCheckPt_file); - - DebugEquality debug_equality; // only as affect in DEBUG build + theInMemoryDefs.cereal_save_as_checkpt(tmpCheckPt_file); + + DebugEquality debug_equality; // only as affect in DEBUG build + + try { + // Parse the file we just persisted and load the defs file into memory. + reloaded_defs.cereal_restore_from_checkpt(tmpCheckPt_file); + + if (do_compare) { + // Make sure the checkpoint file file we just parsed match's the one we persisted + bool match = reloaded_defs == theInMemoryDefs; + if (!match) { + std::stringstream ss; + ss << "\nPersistHelper::reload_from_cereal_checkpt_file\n"; + ss << "In memory and reloaded def's don't match\n"; + ss << "+++++++++++++ Saved/reloaded check pt file ++++++++++++++++++++++++++++\n"; + PrintStyle style(PrintStyle::STATE); + ss << reloaded_defs; + ss << "++++++++++++++ In memory def ++++++++++++++++++++++++++++\n"; + ss << theInMemoryDefs; + errorMsg_ += ss.str(); + } + else { + if (compare_edit_history_ && !reloaded_defs.compare_edit_history(theInMemoryDefs)) { + std::stringstream ss; + ss << "\nPersistHelper::reload_from_cereal_checkpt_file compare_edit_history_\n"; + ss << "In reloaded_defs_file and reloaded_checkPt_defs edit history don't match\n"; + ss << "+++++++++++++ Saved/reloaded check pt file ++++++++++++++++++++++++++++\n"; + PrintStyle style(PrintStyle::MIGRATE); + ss << reloaded_defs; + ss << "++++++++++++++ theInMemoryDefs ++++++++++++++++++++++++++++\n"; + ss << theInMemoryDefs; + errorMsg_ += ss.str(); + } + } + if (!reloaded_defs.compare_change_no(theInMemoryDefs)) { + errorMsg_ += "\nPersistHelper::reload_from_cereal_checkpt_file: Change numbers don't compare between " + "reloaded_defs and theInMemoryDefs \n"; + } + } + } + catch (std::exception& e) { + errorMsg_ = "PersistHelper::reload_from_cereal_checkpt_file: " + string(e.what()); + } - try { - // Parse the file we just persisted and load the defs file into memory. - reloaded_defs.cereal_restore_from_checkpt(tmpCheckPt_file); + file_size_ = fs::file_size(tmpCheckPt_file); + std::remove(tmpCheckPt_file.c_str()); - if (do_compare ) { - // Make sure the checkpoint file file we just parsed match's the one we persisted - bool match = reloaded_defs == theInMemoryDefs; - if (!match) { - std::stringstream ss; - ss << "\nPersistHelper::reload_from_cereal_checkpt_file\n"; - ss << "In memory and reloaded def's don't match\n"; - ss << "+++++++++++++ Saved/reloaded check pt file ++++++++++++++++++++++++++++\n"; - PrintStyle style(PrintStyle::STATE); - ss << reloaded_defs; - ss << "++++++++++++++ In memory def ++++++++++++++++++++++++++++\n"; - ss << theInMemoryDefs; - errorMsg_ += ss.str(); - } - else { - if (compare_edit_history_ && !reloaded_defs.compare_edit_history(theInMemoryDefs)) { - std::stringstream ss; - ss << "\nPersistHelper::reload_from_cereal_checkpt_file compare_edit_history_\n"; - ss << "In reloaded_defs_file and reloaded_checkPt_defs edit history don't match\n"; - ss << "+++++++++++++ Saved/reloaded check pt file ++++++++++++++++++++++++++++\n"; - PrintStyle style(PrintStyle::MIGRATE); - ss << reloaded_defs; - ss << "++++++++++++++ theInMemoryDefs ++++++++++++++++++++++++++++\n"; - ss << theInMemoryDefs; - errorMsg_ += ss.str(); - } - } - if ( !reloaded_defs.compare_change_no( theInMemoryDefs )) { - errorMsg_ += "\nPersistHelper::reload_from_cereal_checkpt_file: Change numbers don't compare between reloaded_defs and theInMemoryDefs \n"; - } - } - } - catch (std::exception& e) { - errorMsg_ = "PersistHelper::reload_from_cereal_checkpt_file: " + string(e.what()); - } - - file_size_ = fs::file_size(tmpCheckPt_file); - std::remove(tmpCheckPt_file.c_str()); - - return errorMsg_.empty(); + return errorMsg_.empty(); } diff --git a/ANode/parser/test/PersistHelper.hpp b/ANode/parser/test/PersistHelper.hpp index e15b04329..b33846247 100644 --- a/ANode/parser/test/PersistHelper.hpp +++ b/ANode/parser/test/PersistHelper.hpp @@ -3,20 +3,20 @@ //============================================================================ // Name : // Author : Avi -// Revision : $Revision$ +// Revision : $Revision$ // // Copyright 2009- ECMWF. -// This software is licensed under the terms of the Apache Licence version 2.0 -// which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. -// In applying this licence, ECMWF does not waive the privileges and immunities -// granted to it by virtue of its status as an intergovernmental organisation -// nor does it submit to any jurisdiction. +// This software is licensed under the terms of the Apache Licence version 2.0 +// which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. +// In applying this licence, ECMWF does not waive the privileges and immunities +// granted to it by virtue of its status as an intergovernmental organisation +// nor does it submit to any jurisdiction. // // Description : //============================================================================ - #include + #include "PrintStyle.hpp" class Defs; @@ -25,35 +25,33 @@ class Defs; /// to ensure they are the same class PersistHelper { public: - explicit PersistHelper(bool compare_edit_history = false) : compare_edit_history_(compare_edit_history) {} + explicit PersistHelper(bool compare_edit_history = false) : compare_edit_history_(compare_edit_history) {} - bool test_persist_and_reload( const Defs& theInMemoryDefs, PrintStyle::Type_t file_type_on_disk,bool do_compare = true ); - bool test_defs_checkpt_and_reload( const Defs& theInMemoryDefs, bool do_compare = true ); - bool test_cereal_checkpt_and_reload( const Defs& theInMemoryDefs, bool do_compare = true); - bool test_state_persist_and_reload_with_checkpt( const Defs& theInMemoryDefs ); - const std::string& errorMsg() const { return errorMsg_;} + bool + test_persist_and_reload(const Defs& theInMemoryDefs, PrintStyle::Type_t file_type_on_disk, bool do_compare = true); + bool test_defs_checkpt_and_reload(const Defs& theInMemoryDefs, bool do_compare = true); + bool test_cereal_checkpt_and_reload(const Defs& theInMemoryDefs, bool do_compare = true); + bool test_state_persist_and_reload_with_checkpt(const Defs& theInMemoryDefs); + const std::string& errorMsg() const { return errorMsg_; } - /// returns the file size of the temporary file created by: - /// test_persist_and_reload(..) or test_cereal_checkpt_and_reload(..) - size_t file_size() const { return file_size_;} + /// returns the file size of the temporary file created by: + /// test_persist_and_reload(..) or test_cereal_checkpt_and_reload(..) + size_t file_size() const { return file_size_; } private: - - bool reload_from_defs_file( const Defs& theInMemoryDefs, Defs& reloaded_defs, const std::string& filename,bool do_compare = true ); - bool reload_from_cereal_checkpt_file(const Defs& theInMemoryDefs, - Defs& reloaded_defs, - bool do_compare = true); + bool reload_from_defs_file(const Defs& theInMemoryDefs, + Defs& reloaded_defs, + const std::string& filename, + bool do_compare = true); + bool reload_from_cereal_checkpt_file(const Defs& theInMemoryDefs, Defs& reloaded_defs, bool do_compare = true); private: - PersistHelper(const PersistHelper&) = delete; - const PersistHelper& operator=(const PersistHelper&) = delete; + PersistHelper(const PersistHelper&) = delete; + const PersistHelper& operator=(const PersistHelper&) = delete; private: - std::string errorMsg_; - size_t file_size_{0}; - bool compare_edit_history_; + std::string errorMsg_; + size_t file_size_{0}; + bool compare_edit_history_; }; #endif - - - diff --git a/ANode/parser/test/TestAutoAddExterns.cpp b/ANode/parser/test/TestAutoAddExterns.cpp index fd0ad9797..2c3d9165f 100644 --- a/ANode/parser/test/TestAutoAddExterns.cpp +++ b/ANode/parser/test/TestAutoAddExterns.cpp @@ -1,20 +1,20 @@ //============================================================================ // Name : // Author : Avi -// Revision : $Revision$ +// Revision : $Revision$ // // Copyright 2009- ECMWF. -// This software is licensed under the terms of the Apache Licence version 2.0 -// which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. -// In applying this licence, ECMWF does not waive the privileges and immunities -// granted to it by virtue of its status as an intergovernmental organisation -// nor does it submit to any jurisdiction. +// This software is licensed under the terms of the Apache Licence version 2.0 +// which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. +// In applying this licence, ECMWF does not waive the privileges and immunities +// granted to it by virtue of its status as an intergovernmental organisation +// nor does it submit to any jurisdiction. // // Description : //============================================================================ -#include #include +#include #include #include @@ -26,32 +26,38 @@ namespace fs = boost::filesystem; using namespace std; using namespace ecf; -BOOST_AUTO_TEST_SUITE( ParserTestSuite ) +BOOST_AUTO_TEST_SUITE(ParserTestSuite) // Test that automatic add of externs -BOOST_AUTO_TEST_CASE( test_auto_add_externs ) -{ - std::string path = File::test_data("ANode/parser/test/data/single_defs/test_auto_add_extern.def","parser"); - - size_t mega_file_size = fs::file_size(path); - cout << "AParser:: ...test_auto_add_externs " << path << " file_size(" << mega_file_size << ")\n"; - - Defs defs; - std::string errorMsg,warningMsg; - BOOST_REQUIRE_MESSAGE(defs.restore(path,errorMsg,warningMsg),"Expected no errors, but found " << errorMsg); - BOOST_REQUIRE_MESSAGE(warningMsg.empty(),"Expected no warnings but found:\n" << warningMsg); - - // Check number of extrens read in: Duplicate should be ignore - BOOST_REQUIRE_MESSAGE(defs.externs().size() == 11 ,"Expected 11 externs as starting point but found " << defs.externs().size() << "\n" << defs << "\n"); - - // Test auto extern generation. Don't remove existing extern's - defs.auto_add_externs(false/* remove_existing_externs_first*/); - BOOST_REQUIRE_MESSAGE(defs.externs().size() == 11 ,"Expected 11, auto_add_extern(false) gave: " << defs.externs().size() << "\n" << defs << "\n"); - - // By removing the externs read, in we can determine the real number of extern;s from - // parsing all the trigger expressions, and inlimit references - defs.auto_add_externs(true/* remove_existing_externs_first*/); - BOOST_REQUIRE_MESSAGE(defs.externs().size() == 10 ,"Expected 10 externs, since redundant externs removed, auto_add_extern(true) gave: " << defs.externs().size() << "\n"<< defs << "\n"); +BOOST_AUTO_TEST_CASE(test_auto_add_externs) { + std::string path = File::test_data("ANode/parser/test/data/single_defs/test_auto_add_extern.def", "parser"); + + size_t mega_file_size = fs::file_size(path); + cout << "AParser:: ...test_auto_add_externs " << path << " file_size(" << mega_file_size << ")\n"; + + Defs defs; + std::string errorMsg, warningMsg; + BOOST_REQUIRE_MESSAGE(defs.restore(path, errorMsg, warningMsg), "Expected no errors, but found " << errorMsg); + BOOST_REQUIRE_MESSAGE(warningMsg.empty(), "Expected no warnings but found:\n" << warningMsg); + + // Check number of extrens read in: Duplicate should be ignore + BOOST_REQUIRE_MESSAGE(defs.externs().size() == 11, + "Expected 11 externs as starting point but found " << defs.externs().size() << "\n" + << defs << "\n"); + + // Test auto extern generation. Don't remove existing extern's + defs.auto_add_externs(false /* remove_existing_externs_first*/); + BOOST_REQUIRE_MESSAGE(defs.externs().size() == 11, + "Expected 11, auto_add_extern(false) gave: " << defs.externs().size() << "\n" + << defs << "\n"); + + // By removing the externs read, in we can determine the real number of extern;s from + // parsing all the trigger expressions, and inlimit references + defs.auto_add_externs(true /* remove_existing_externs_first*/); + BOOST_REQUIRE_MESSAGE(defs.externs().size() == 10, + "Expected 10 externs, since redundant externs removed, auto_add_extern(true) gave: " + << defs.externs().size() << "\n" + << defs << "\n"); } BOOST_AUTO_TEST_SUITE_END() diff --git a/ANode/parser/test/TestDefsStructurePersistAndReload.cpp b/ANode/parser/test/TestDefsStructurePersistAndReload.cpp index 4f1744dd4..e23a95a9b 100644 --- a/ANode/parser/test/TestDefsStructurePersistAndReload.cpp +++ b/ANode/parser/test/TestDefsStructurePersistAndReload.cpp @@ -1,30 +1,30 @@ //============================================================================ // Name : // Author : Avi -// Revision : $Revision$ +// Revision : $Revision$ // // Copyright 2009- ECMWF. -// This software is licensed under the terms of the Apache Licence version 2.0 -// which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. -// In applying this licence, ECMWF does not waive the privileges and immunities -// granted to it by virtue of its status as an intergovernmental organisation -// nor does it submit to any jurisdiction. +// This software is licensed under the terms of the Apache Licence version 2.0 +// which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. +// In applying this licence, ECMWF does not waive the privileges and immunities +// granted to it by virtue of its status as an intergovernmental organisation +// nor does it submit to any jurisdiction. // // Description : //============================================================================ -#include #include +#include #include +#include "MyDefsFixture.hpp" #include "PersistHelper.hpp" #include "PrintStyle.hpp" -#include "MyDefsFixture.hpp" using namespace std; using namespace ecf; -BOOST_AUTO_TEST_SUITE( ParserTestSuite ) +BOOST_AUTO_TEST_SUITE(ParserTestSuite) //============================================================================= // This test case will save the defs file in old style format @@ -32,65 +32,60 @@ BOOST_AUTO_TEST_SUITE( ParserTestSuite ) // we can automatically check that what we save can be parsed back in. // Specifically written to test the parser. // Note: Aliases are *NOT* written in the defs file BUT are when in MIGRATE -BOOST_AUTO_TEST_CASE( test_defs_structure_persistence_and_reload ) -{ - cout << "AParser:: ...test_defs_structure_persistence_and_reload\n"; - - MyDefsFixture theDefsFixture; - PersistHelper helper; - BOOST_CHECK_MESSAGE( helper.test_cereal_checkpt_and_reload(theDefsFixture.defsfile_), helper.errorMsg()); - - // Note: Aliases are *NOT* written in PrintStyle::DEFS file - // Hence in order for this test to pass, we must delete the alias first & reset task alias_no - std::vector alias_vec; - theDefsFixture.defsfile_.get_all_aliases(alias_vec); - for(alias_ptr al:alias_vec) { - al->parent()->isTask()->reset_alias_number(); - al->remove(); - } - BOOST_CHECK_MESSAGE( helper.test_persist_and_reload(theDefsFixture.defsfile_, PrintStyle::DEFS), helper.errorMsg()); +BOOST_AUTO_TEST_CASE(test_defs_structure_persistence_and_reload) { + cout << "AParser:: ...test_defs_structure_persistence_and_reload\n"; + + MyDefsFixture theDefsFixture; + PersistHelper helper; + BOOST_CHECK_MESSAGE(helper.test_cereal_checkpt_and_reload(theDefsFixture.defsfile_), helper.errorMsg()); + + // Note: Aliases are *NOT* written in PrintStyle::DEFS file + // Hence in order for this test to pass, we must delete the alias first & reset task alias_no + std::vector alias_vec; + theDefsFixture.defsfile_.get_all_aliases(alias_vec); + for (alias_ptr al : alias_vec) { + al->parent()->isTask()->reset_alias_number(); + al->remove(); + } + BOOST_CHECK_MESSAGE(helper.test_persist_and_reload(theDefsFixture.defsfile_, PrintStyle::DEFS), helper.errorMsg()); } -BOOST_AUTO_TEST_CASE( test_defs_checkpt_persistence_and_reload ) -{ - cout << "AParser:: ...test_defs_checkpt_persistence_and_reload\n"; +BOOST_AUTO_TEST_CASE(test_defs_checkpt_persistence_and_reload) { + cout << "AParser:: ...test_defs_checkpt_persistence_and_reload\n"; - MyDefsFixture theDefsFixture; - PersistHelper helper; - BOOST_CHECK_MESSAGE( helper.test_cereal_checkpt_and_reload(theDefsFixture.defsfile_), helper.errorMsg()); - BOOST_CHECK_MESSAGE( helper.test_defs_checkpt_and_reload(theDefsFixture.defsfile_), helper.errorMsg()); + MyDefsFixture theDefsFixture; + PersistHelper helper; + BOOST_CHECK_MESSAGE(helper.test_cereal_checkpt_and_reload(theDefsFixture.defsfile_), helper.errorMsg()); + BOOST_CHECK_MESSAGE(helper.test_defs_checkpt_and_reload(theDefsFixture.defsfile_), helper.errorMsg()); } - // This test is used to find a task given a path of the form: // suite/family/task // suite/family/family/task // -void test_find_task_using_path( NodeContainer* f,const Defs& defs ) -{ - BOOST_CHECK_MESSAGE(f == defs.findAbsNode(f->absNodePath()).get(), "Could not find path " << f->absNodePath() << "\n"); - - for(node_ptr t: f->nodeVec()) { - BOOST_CHECK_MESSAGE( t.get() == defs.findAbsNode(t->absNodePath()).get(), "Could not find path " << t->absNodePath() << "\n"); - Family* family = t->isFamily(); - if (family) { - test_find_task_using_path(family, defs); - } - } +void test_find_task_using_path(NodeContainer* f, const Defs& defs) { + BOOST_CHECK_MESSAGE(f == defs.findAbsNode(f->absNodePath()).get(), + "Could not find path " << f->absNodePath() << "\n"); + + for (node_ptr t : f->nodeVec()) { + BOOST_CHECK_MESSAGE(t.get() == defs.findAbsNode(t->absNodePath()).get(), + "Could not find path " << t->absNodePath() << "\n"); + Family* family = t->isFamily(); + if (family) { + test_find_task_using_path(family, defs); + } + } } -BOOST_AUTO_TEST_CASE( test_find_task_using_paths ) -{ - cout << "AParser:: ...test_find_task_using_paths\n"; +BOOST_AUTO_TEST_CASE(test_find_task_using_paths) { + cout << "AParser:: ...test_find_task_using_paths\n"; - MyDefsFixture theDefsFixture; + MyDefsFixture theDefsFixture; - const std::vector& suiteVec = theDefsFixture.defsfile_.suiteVec(); - for(suite_ptr s: suiteVec) { - test_find_task_using_path(s.get(),theDefsFixture.defsfile_); - } + const std::vector& suiteVec = theDefsFixture.defsfile_.suiteVec(); + for (suite_ptr s : suiteVec) { + test_find_task_using_path(s.get(), theDefsFixture.defsfile_); + } } BOOST_AUTO_TEST_SUITE_END() - - diff --git a/ANode/parser/test/TestMementoPersistAndReload.cpp b/ANode/parser/test/TestMementoPersistAndReload.cpp index 0a8c7f6bd..e50dd0767 100644 --- a/ANode/parser/test/TestMementoPersistAndReload.cpp +++ b/ANode/parser/test/TestMementoPersistAndReload.cpp @@ -12,14 +12,14 @@ // // Description : //============================================================================ -#include #include +#include #include #include "Defs.hpp" -#include "PersistHelper.hpp" #include "Memento.hpp" +#include "PersistHelper.hpp" using namespace std; using namespace ecf; @@ -41,388 +41,432 @@ using namespace ecf; // Finally compare the two *RELOADED* defs file. // ******************************************************************** -BOOST_AUTO_TEST_SUITE( ParserTestSuite ) - -BOOST_AUTO_TEST_CASE( test_memento_persist_and_reload ) -{ - std::vector aspects; - bool aspect_only = false; - cout << "AParser:: ...test_memento_persist_and_reload\n"; - { - Defs defs; - suite_ptr suite = defs.add_suite("s1"); - node_ptr t = suite->add_task("t1"); - - StateMemento memento2(NState::ABORTED); - defs.set_memento(&memento2,aspects,aspect_only); - - PersistHelper helper; - BOOST_CHECK_MESSAGE( helper.test_state_persist_and_reload_with_checkpt(defs),"StateMemento failed: " << helper.errorMsg()); - } - { - Defs defs; - suite_ptr suite = defs.add_suite("s1"); - node_ptr t = suite->add_task("t1"); - - std::pair state; - state.first = NState::ABORTED; - state.second = boost::posix_time::time_duration(1,1,1,0); - NodeStateMemento memento(state); - t->set_memento(&memento,aspects,aspect_only); - - PersistHelper helper; - BOOST_CHECK_MESSAGE( helper.test_state_persist_and_reload_with_checkpt(defs),"NodeStateMemento failed: " << helper.errorMsg()); - } - { - Defs defs; - suite_ptr suite = defs.add_suite("s1"); - node_ptr t = suite->add_task("t1"); - - NodeDefStatusDeltaMemento memento(DState::ABORTED); - t->set_memento(&memento,aspects,aspect_only); - - PersistHelper helper; - BOOST_CHECK_MESSAGE( helper.test_state_persist_and_reload_with_checkpt(defs),"NodeDefStatusDeltaMemento failed: " << helper.errorMsg()); - } - { - Defs defs; - suite_ptr suite = defs.add_suite("s1"); - node_ptr t = suite->add_task("t1"); - - SuspendedMemento memento(true); - t->set_memento(&memento,aspects,aspect_only); - - PersistHelper helper; - BOOST_CHECK_MESSAGE( helper.test_state_persist_and_reload_with_checkpt(defs),"SuspendedMemento failed: " << helper.errorMsg()); - - SuspendedMemento memento1; - t->set_memento(&memento1,aspects,aspect_only); - BOOST_CHECK_MESSAGE( helper.test_state_persist_and_reload_with_checkpt(defs),"SuspendedMemento failed: " << helper.errorMsg()); - } - { - Defs defs; - suite_ptr suite = defs.add_suite("s1"); - node_ptr t = suite->add_task("t1"); - - Event event(1); - NodeEventMemento memento(event); - t->set_memento(&memento,aspects,aspect_only); // add event - - PersistHelper helper; - BOOST_CHECK_MESSAGE( helper.test_state_persist_and_reload_with_checkpt(defs),"NodeEventMemento failed: " << helper.errorMsg()); - - event.set_value(true); - NodeEventMemento memento1(event); // set event - t->set_memento(&memento1,aspects,aspect_only); - BOOST_CHECK_MESSAGE( helper.test_state_persist_and_reload_with_checkpt(defs),"NodeEventMemento failed: " << helper.errorMsg()); - } - { - Defs defs; - suite_ptr suite = defs.add_suite("s1"); - node_ptr t = suite->add_task("t1"); - - Meter meter("meter",0,100); - - NodeMeterMemento memento(meter); - t->set_memento(&memento,aspects,aspect_only); // add meter - - PersistHelper helper; - BOOST_CHECK_MESSAGE( helper.test_state_persist_and_reload_with_checkpt(defs),"NodeMeterMemento failed: " << helper.errorMsg()); - - meter.set_value(100); - NodeMeterMemento memento1( meter); // change meter - t->set_memento(&memento1,aspects,aspect_only); - BOOST_CHECK_MESSAGE( helper.test_state_persist_and_reload_with_checkpt(defs),"NodeMeterMemento failed: " << helper.errorMsg()); - } - { - Defs defs; - suite_ptr suite = defs.add_suite("s1"); - node_ptr t = suite->add_task("t1"); - - Label label("label","xxx"); - - NodeLabelMemento memento(label); - t->set_memento(&memento,aspects,aspect_only); // add label; - - PersistHelper helper; - BOOST_CHECK_MESSAGE( helper.test_state_persist_and_reload_with_checkpt(defs),"NodeLabelMemento failed: " << helper.errorMsg()); - - label.set_new_value("yyy"); - NodeLabelMemento memento1( label ); // change label - t->set_memento(&memento1,aspects,aspect_only); - BOOST_CHECK_MESSAGE( helper.test_state_persist_and_reload_with_checkpt(defs),"NodeLabelMemento failed: " << helper.errorMsg()); - } - { - Defs defs; - suite_ptr suite = defs.add_suite("s1"); - node_ptr t = suite->add_task("t1"); - - Expression exp("1 == 0"); - - NodeTriggerMemento memento(exp); - t->set_memento(&memento,aspects,aspect_only); // add trigger; - - PersistHelper helper; - BOOST_CHECK_MESSAGE( helper.test_state_persist_and_reload_with_checkpt(defs),"NodeTriggerMemento failed: " << helper.errorMsg()); - - exp.setFree(); - NodeTriggerMemento memento1( exp ); // free trigger - t->set_memento(&memento1,aspects,aspect_only); - BOOST_CHECK_MESSAGE( helper.test_state_persist_and_reload_with_checkpt(defs),"NodeTriggerMemento failed: " << helper.errorMsg()); - - exp.clearFree(); - NodeTriggerMemento memento2( exp ); // clear trigger - t->set_memento(&memento2,aspects,aspect_only); - BOOST_CHECK_MESSAGE( helper.test_state_persist_and_reload_with_checkpt(defs),"NodeTriggerMemento failed: " << helper.errorMsg()); - } - { - Defs defs; - suite_ptr suite = defs.add_suite("s1"); - node_ptr t = suite->add_task("t1"); - - Expression exp("1 == 0"); - - NodeCompleteMemento memento(exp); - t->set_memento(&memento,aspects,aspect_only); // add trigger; - - PersistHelper helper; - BOOST_CHECK_MESSAGE( helper.test_state_persist_and_reload_with_checkpt(defs),"NodeCompleteMemento failed: " << helper.errorMsg()); - - exp.setFree(); - NodeCompleteMemento memento1( exp ); // free trigger - t->set_memento(&memento1,aspects,aspect_only); - BOOST_CHECK_MESSAGE( helper.test_state_persist_and_reload_with_checkpt(defs),"NodeCompleteMemento failed: " << helper.errorMsg()); - - exp.clearFree(); - NodeCompleteMemento memento2( exp ); // clear trigger - t->set_memento(&memento2,aspects,aspect_only); - BOOST_CHECK_MESSAGE( helper.test_state_persist_and_reload_with_checkpt(defs),"NodeCompleteMemento failed: " << helper.errorMsg()); - } - { - Defs defs; - suite_ptr suite = defs.add_suite("s1"); - node_ptr t = suite->add_task("t1"); - - Repeat repeat(RepeatDate("YMD",20090916,20090916,1) ); - - NodeRepeatMemento memento(repeat); - t->set_memento(&memento,aspects,aspect_only); // add repeat; - - PersistHelper helper; - BOOST_CHECK_MESSAGE( helper.test_state_persist_and_reload_with_checkpt(defs),"NodeRepeatMemento failed: " << helper.errorMsg()); - - repeat.increment(); - NodeRepeatMemento memento1( repeat ); // change repeat - t->set_memento(&memento1,aspects,aspect_only); - BOOST_CHECK_MESSAGE( helper.test_state_persist_and_reload_with_checkpt(defs),"NodeRepeatMemento failed: " << helper.errorMsg()); - } - { - Defs defs; - suite_ptr suite = defs.add_suite("s1"); - node_ptr t = suite->add_task("t1"); - - Repeat repeat(RepeatDateList("YMD",{20090916,20090916})); - - NodeRepeatMemento memento(repeat); - t->set_memento(&memento,aspects,aspect_only); // add repeat; - - PersistHelper helper; - BOOST_CHECK_MESSAGE( helper.test_state_persist_and_reload_with_checkpt(defs),"NodeRepeatMemento failed: " << helper.errorMsg()); - - repeat.increment(); - NodeRepeatMemento memento1( repeat ); // change repeat - t->set_memento(&memento1,aspects,aspect_only); - BOOST_CHECK_MESSAGE( helper.test_state_persist_and_reload_with_checkpt(defs),"NodeRepeatMemento failed: " << helper.errorMsg()); - } - { - Defs defs; - suite_ptr suite = defs.add_suite("s1"); - node_ptr t = suite->add_task("t1"); - - Limit limit("suiteLimit",10); - - NodeLimitMemento memento(limit); - t->set_memento(&memento,aspects,aspect_only); // add limit; - - PersistHelper helper; - BOOST_CHECK_MESSAGE( helper.test_state_persist_and_reload_with_checkpt(defs),"NodeLimitMemento failed: " << helper.errorMsg()); - - std::set paths; - paths.insert("/s1/t1"); - - limit.set_state(20,2,paths); - NodeLimitMemento memento1( limit ); // change limit - t->set_memento(&memento1,aspects,aspect_only); - BOOST_CHECK_MESSAGE( helper.test_state_persist_and_reload_with_checkpt(defs),"NodeLimitMemento failed: " << helper.errorMsg()); - } - { - Defs defs; - suite_ptr suite = defs.add_suite("s1"); - node_ptr t = suite->add_task("t1"); - - InLimit inlimit("suiteLimit","/path/to/node",2); - - NodeInLimitMemento memento(inlimit); - t->set_memento(&memento,aspects,aspect_only); // add inlimit only, no state - - PersistHelper helper; - BOOST_CHECK_MESSAGE( helper.test_state_persist_and_reload_with_checkpt(defs),"NodeInLimitMemento failed: " << helper.errorMsg()); - } - { - Defs defs; - suite_ptr suite = defs.add_suite("s1"); - node_ptr t = suite->add_task("t1"); - - Variable variable("name","value"); - - NodeVariableMemento memento(variable); - t->set_memento(&memento,aspects,aspect_only); // add variable; - - PersistHelper helper; - BOOST_CHECK_MESSAGE( helper.test_state_persist_and_reload_with_checkpt(defs),"NodeVariableMemento failed: " << helper.errorMsg()); - - variable.set_value("new value"); - NodeVariableMemento memento1( variable ); // change variable - t->set_memento(&memento1,aspects,aspect_only); - BOOST_CHECK_MESSAGE( helper.test_state_persist_and_reload_with_checkpt(defs),"NodeVariableMemento failed: " << helper.errorMsg()); - } - { - Defs defs; - suite_ptr suite = defs.add_suite("s1"); - node_ptr t = suite->add_task("t1"); - - ecf::LateAttr lateAttr; - lateAttr.addSubmitted( ecf::TimeSlot(3,12) ); - lateAttr.addActive( ecf::TimeSlot(3,12) ); - lateAttr.addComplete( ecf::TimeSlot(4,12), true); - - NodeLateMemento memento(lateAttr); - t->set_memento(&memento,aspects,aspect_only); // add late; - - PersistHelper helper; - BOOST_CHECK_MESSAGE( helper.test_state_persist_and_reload_with_checkpt(defs),"NodeLateMemento failed: " << helper.errorMsg()); - - lateAttr.setLate(true); - NodeLateMemento memento1( lateAttr ); // change late - t->set_memento(&memento1,aspects,aspect_only); - BOOST_CHECK_MESSAGE( helper.test_state_persist_and_reload_with_checkpt(defs),"NodeLateMemento failed: " << helper.errorMsg()); - } - { - Defs defs; - suite_ptr suite = defs.add_suite("s1"); - node_ptr t = suite->add_task("t1"); - - ecf::TodayAttr attr(ecf::TimeSlot(10,12)) ; - - NodeTodayMemento memento(attr); - t->set_memento(&memento,aspects,aspect_only); // add today; - - PersistHelper helper; - BOOST_CHECK_MESSAGE( helper.test_state_persist_and_reload_with_checkpt(defs),"NodeTodayMemento failed: " << helper.errorMsg()); - - attr.setFree(); - NodeTodayMemento memento1( attr ); // change today - t->set_memento(&memento1,aspects,aspect_only); - BOOST_CHECK_MESSAGE( helper.test_state_persist_and_reload_with_checkpt(defs),"NodeTodayMemento failed: " << helper.errorMsg()); - } - { - Defs defs; - suite_ptr suite = defs.add_suite("s1"); - node_ptr t = suite->add_task("t1"); - - ecf::TimeAttr attr(ecf::TimeSlot(10,12)) ; - - NodeTimeMemento memento(attr); - t->set_memento(&memento,aspects,aspect_only); // add time; - - PersistHelper helper; - BOOST_CHECK_MESSAGE( helper.test_state_persist_and_reload_with_checkpt(defs),"NodeTimeMemento failed: " << helper.errorMsg()); - - attr.setFree(); - NodeTimeMemento memento1( attr ); // change time - t->set_memento(&memento1,aspects,aspect_only); - BOOST_CHECK_MESSAGE( helper.test_state_persist_and_reload_with_checkpt(defs),"NodeTimeMemento failed: " << helper.errorMsg()); - } - { - Defs defs; - suite_ptr suite = defs.add_suite("s1"); - node_ptr t = suite->add_task("t1"); - - DayAttr attr(DayAttr::MONDAY); - - NodeDayMemento memento(attr); - t->set_memento(&memento,aspects,aspect_only); // add day; - - PersistHelper helper; - BOOST_CHECK_MESSAGE( helper.test_state_persist_and_reload_with_checkpt(defs),"NodeDayMemento failed: " << helper.errorMsg()); - - attr.setFree(); - NodeDayMemento memento1( attr ); // change day - t->set_memento(&memento1,aspects,aspect_only); - BOOST_CHECK_MESSAGE( helper.test_state_persist_and_reload_with_checkpt(defs),"NodeDayMemento failed: " << helper.errorMsg()); - } - { - Defs defs; - suite_ptr suite = defs.add_suite("s1"); - node_ptr t = suite->add_task("t1"); - - DateAttr attr(1,2,2009); - - NodeDateMemento memento(attr); - t->set_memento(&memento,aspects,aspect_only); // add date; - - PersistHelper helper; - BOOST_CHECK_MESSAGE( helper.test_state_persist_and_reload_with_checkpt(defs),"NodeDateMemento failed: " << helper.errorMsg()); - - attr.setFree(); - NodeDateMemento memento1( attr ); // change date - t->set_memento(&memento1,aspects,aspect_only); - BOOST_CHECK_MESSAGE( helper.test_state_persist_and_reload_with_checkpt(defs),"NodeDateMemento failed: " << helper.errorMsg()); - } - { - Defs defs; - suite_ptr suite = defs.add_suite("s1"); - node_ptr t = suite->add_task("t1"); - - ecf::CronAttr attr; - ecf::TimeSlot start( 0, 0 ); - ecf::TimeSlot finish( 10, 0 ); - ecf::TimeSlot incr( 0, 5 ); - std::vector weekdays; for(int i=0;i<7;++i) weekdays.push_back(i); - std::vector daysOfMonth;for(int i=1;i<32;++i) daysOfMonth.push_back(i); - std::vector months; for(int i=1;i<13;++i) months.push_back(i); - attr.addTimeSeries(start,finish,incr); - attr.addWeekDays( weekdays ); - attr.addDaysOfMonth(daysOfMonth); - attr.addMonths( months ); - - NodeCronMemento memento(attr); - t->set_memento(&memento,aspects,aspect_only); // add cron; - - PersistHelper helper; - BOOST_CHECK_MESSAGE( helper.test_state_persist_and_reload_with_checkpt(defs),"NodeCronMemento failed: " << helper.errorMsg()); - - attr.setFree(); - NodeCronMemento memento1( attr ); // change cron - t->set_memento(&memento1,aspects,aspect_only); - BOOST_CHECK_MESSAGE( helper.test_state_persist_and_reload_with_checkpt(defs),"NodeCronMemento failed: " << helper.errorMsg()); - } - - { - Defs defs; - suite_ptr suite = defs.add_suite("s1"); - node_ptr t = suite->add_task("t1"); - - std::vector child_cmds = ecf::Child::list(); - - ZombieAttr attr(ecf::Child::USER, child_cmds, ecf::User::FOB,10); - - NodeZombieMemento memento(attr); - t->set_memento(&memento,aspects,aspect_only); // add zombie; - - PersistHelper helper; - BOOST_CHECK_MESSAGE( helper.test_state_persist_and_reload_with_checkpt(defs),"NodeZombieMemento failed: " << helper.errorMsg()); - } +BOOST_AUTO_TEST_SUITE(ParserTestSuite) + +BOOST_AUTO_TEST_CASE(test_memento_persist_and_reload) { + std::vector aspects; + bool aspect_only = false; + cout << "AParser:: ...test_memento_persist_and_reload\n"; + { + Defs defs; + suite_ptr suite = defs.add_suite("s1"); + node_ptr t = suite->add_task("t1"); + + StateMemento memento2(NState::ABORTED); + defs.set_memento(&memento2, aspects, aspect_only); + + PersistHelper helper; + BOOST_CHECK_MESSAGE(helper.test_state_persist_and_reload_with_checkpt(defs), + "StateMemento failed: " << helper.errorMsg()); + } + { + Defs defs; + suite_ptr suite = defs.add_suite("s1"); + node_ptr t = suite->add_task("t1"); + + std::pair state; + state.first = NState::ABORTED; + state.second = boost::posix_time::time_duration(1, 1, 1, 0); + NodeStateMemento memento(state); + t->set_memento(&memento, aspects, aspect_only); + + PersistHelper helper; + BOOST_CHECK_MESSAGE(helper.test_state_persist_and_reload_with_checkpt(defs), + "NodeStateMemento failed: " << helper.errorMsg()); + } + { + Defs defs; + suite_ptr suite = defs.add_suite("s1"); + node_ptr t = suite->add_task("t1"); + + NodeDefStatusDeltaMemento memento(DState::ABORTED); + t->set_memento(&memento, aspects, aspect_only); + + PersistHelper helper; + BOOST_CHECK_MESSAGE(helper.test_state_persist_and_reload_with_checkpt(defs), + "NodeDefStatusDeltaMemento failed: " << helper.errorMsg()); + } + { + Defs defs; + suite_ptr suite = defs.add_suite("s1"); + node_ptr t = suite->add_task("t1"); + + SuspendedMemento memento(true); + t->set_memento(&memento, aspects, aspect_only); + + PersistHelper helper; + BOOST_CHECK_MESSAGE(helper.test_state_persist_and_reload_with_checkpt(defs), + "SuspendedMemento failed: " << helper.errorMsg()); + + SuspendedMemento memento1; + t->set_memento(&memento1, aspects, aspect_only); + BOOST_CHECK_MESSAGE(helper.test_state_persist_and_reload_with_checkpt(defs), + "SuspendedMemento failed: " << helper.errorMsg()); + } + { + Defs defs; + suite_ptr suite = defs.add_suite("s1"); + node_ptr t = suite->add_task("t1"); + + Event event(1); + NodeEventMemento memento(event); + t->set_memento(&memento, aspects, aspect_only); // add event + + PersistHelper helper; + BOOST_CHECK_MESSAGE(helper.test_state_persist_and_reload_with_checkpt(defs), + "NodeEventMemento failed: " << helper.errorMsg()); + + event.set_value(true); + NodeEventMemento memento1(event); // set event + t->set_memento(&memento1, aspects, aspect_only); + BOOST_CHECK_MESSAGE(helper.test_state_persist_and_reload_with_checkpt(defs), + "NodeEventMemento failed: " << helper.errorMsg()); + } + { + Defs defs; + suite_ptr suite = defs.add_suite("s1"); + node_ptr t = suite->add_task("t1"); + + Meter meter("meter", 0, 100); + + NodeMeterMemento memento(meter); + t->set_memento(&memento, aspects, aspect_only); // add meter + + PersistHelper helper; + BOOST_CHECK_MESSAGE(helper.test_state_persist_and_reload_with_checkpt(defs), + "NodeMeterMemento failed: " << helper.errorMsg()); + + meter.set_value(100); + NodeMeterMemento memento1(meter); // change meter + t->set_memento(&memento1, aspects, aspect_only); + BOOST_CHECK_MESSAGE(helper.test_state_persist_and_reload_with_checkpt(defs), + "NodeMeterMemento failed: " << helper.errorMsg()); + } + { + Defs defs; + suite_ptr suite = defs.add_suite("s1"); + node_ptr t = suite->add_task("t1"); + + Label label("label", "xxx"); + + NodeLabelMemento memento(label); + t->set_memento(&memento, aspects, aspect_only); // add label; + + PersistHelper helper; + BOOST_CHECK_MESSAGE(helper.test_state_persist_and_reload_with_checkpt(defs), + "NodeLabelMemento failed: " << helper.errorMsg()); + + label.set_new_value("yyy"); + NodeLabelMemento memento1(label); // change label + t->set_memento(&memento1, aspects, aspect_only); + BOOST_CHECK_MESSAGE(helper.test_state_persist_and_reload_with_checkpt(defs), + "NodeLabelMemento failed: " << helper.errorMsg()); + } + { + Defs defs; + suite_ptr suite = defs.add_suite("s1"); + node_ptr t = suite->add_task("t1"); + + Expression exp("1 == 0"); + + NodeTriggerMemento memento(exp); + t->set_memento(&memento, aspects, aspect_only); // add trigger; + + PersistHelper helper; + BOOST_CHECK_MESSAGE(helper.test_state_persist_and_reload_with_checkpt(defs), + "NodeTriggerMemento failed: " << helper.errorMsg()); + + exp.setFree(); + NodeTriggerMemento memento1(exp); // free trigger + t->set_memento(&memento1, aspects, aspect_only); + BOOST_CHECK_MESSAGE(helper.test_state_persist_and_reload_with_checkpt(defs), + "NodeTriggerMemento failed: " << helper.errorMsg()); + + exp.clearFree(); + NodeTriggerMemento memento2(exp); // clear trigger + t->set_memento(&memento2, aspects, aspect_only); + BOOST_CHECK_MESSAGE(helper.test_state_persist_and_reload_with_checkpt(defs), + "NodeTriggerMemento failed: " << helper.errorMsg()); + } + { + Defs defs; + suite_ptr suite = defs.add_suite("s1"); + node_ptr t = suite->add_task("t1"); + + Expression exp("1 == 0"); + + NodeCompleteMemento memento(exp); + t->set_memento(&memento, aspects, aspect_only); // add trigger; + + PersistHelper helper; + BOOST_CHECK_MESSAGE(helper.test_state_persist_and_reload_with_checkpt(defs), + "NodeCompleteMemento failed: " << helper.errorMsg()); + + exp.setFree(); + NodeCompleteMemento memento1(exp); // free trigger + t->set_memento(&memento1, aspects, aspect_only); + BOOST_CHECK_MESSAGE(helper.test_state_persist_and_reload_with_checkpt(defs), + "NodeCompleteMemento failed: " << helper.errorMsg()); + + exp.clearFree(); + NodeCompleteMemento memento2(exp); // clear trigger + t->set_memento(&memento2, aspects, aspect_only); + BOOST_CHECK_MESSAGE(helper.test_state_persist_and_reload_with_checkpt(defs), + "NodeCompleteMemento failed: " << helper.errorMsg()); + } + { + Defs defs; + suite_ptr suite = defs.add_suite("s1"); + node_ptr t = suite->add_task("t1"); + + Repeat repeat(RepeatDate("YMD", 20090916, 20090916, 1)); + + NodeRepeatMemento memento(repeat); + t->set_memento(&memento, aspects, aspect_only); // add repeat; + + PersistHelper helper; + BOOST_CHECK_MESSAGE(helper.test_state_persist_and_reload_with_checkpt(defs), + "NodeRepeatMemento failed: " << helper.errorMsg()); + + repeat.increment(); + NodeRepeatMemento memento1(repeat); // change repeat + t->set_memento(&memento1, aspects, aspect_only); + BOOST_CHECK_MESSAGE(helper.test_state_persist_and_reload_with_checkpt(defs), + "NodeRepeatMemento failed: " << helper.errorMsg()); + } + { + Defs defs; + suite_ptr suite = defs.add_suite("s1"); + node_ptr t = suite->add_task("t1"); + + Repeat repeat(RepeatDateList("YMD", {20090916, 20090916})); + + NodeRepeatMemento memento(repeat); + t->set_memento(&memento, aspects, aspect_only); // add repeat; + + PersistHelper helper; + BOOST_CHECK_MESSAGE(helper.test_state_persist_and_reload_with_checkpt(defs), + "NodeRepeatMemento failed: " << helper.errorMsg()); + + repeat.increment(); + NodeRepeatMemento memento1(repeat); // change repeat + t->set_memento(&memento1, aspects, aspect_only); + BOOST_CHECK_MESSAGE(helper.test_state_persist_and_reload_with_checkpt(defs), + "NodeRepeatMemento failed: " << helper.errorMsg()); + } + { + Defs defs; + suite_ptr suite = defs.add_suite("s1"); + node_ptr t = suite->add_task("t1"); + + Limit limit("suiteLimit", 10); + + NodeLimitMemento memento(limit); + t->set_memento(&memento, aspects, aspect_only); // add limit; + + PersistHelper helper; + BOOST_CHECK_MESSAGE(helper.test_state_persist_and_reload_with_checkpt(defs), + "NodeLimitMemento failed: " << helper.errorMsg()); + + std::set paths; + paths.insert("/s1/t1"); + + limit.set_state(20, 2, paths); + NodeLimitMemento memento1(limit); // change limit + t->set_memento(&memento1, aspects, aspect_only); + BOOST_CHECK_MESSAGE(helper.test_state_persist_and_reload_with_checkpt(defs), + "NodeLimitMemento failed: " << helper.errorMsg()); + } + { + Defs defs; + suite_ptr suite = defs.add_suite("s1"); + node_ptr t = suite->add_task("t1"); + + InLimit inlimit("suiteLimit", "/path/to/node", 2); + + NodeInLimitMemento memento(inlimit); + t->set_memento(&memento, aspects, aspect_only); // add inlimit only, no state + + PersistHelper helper; + BOOST_CHECK_MESSAGE(helper.test_state_persist_and_reload_with_checkpt(defs), + "NodeInLimitMemento failed: " << helper.errorMsg()); + } + { + Defs defs; + suite_ptr suite = defs.add_suite("s1"); + node_ptr t = suite->add_task("t1"); + + Variable variable("name", "value"); + + NodeVariableMemento memento(variable); + t->set_memento(&memento, aspects, aspect_only); // add variable; + + PersistHelper helper; + BOOST_CHECK_MESSAGE(helper.test_state_persist_and_reload_with_checkpt(defs), + "NodeVariableMemento failed: " << helper.errorMsg()); + + variable.set_value("new value"); + NodeVariableMemento memento1(variable); // change variable + t->set_memento(&memento1, aspects, aspect_only); + BOOST_CHECK_MESSAGE(helper.test_state_persist_and_reload_with_checkpt(defs), + "NodeVariableMemento failed: " << helper.errorMsg()); + } + { + Defs defs; + suite_ptr suite = defs.add_suite("s1"); + node_ptr t = suite->add_task("t1"); + + ecf::LateAttr lateAttr; + lateAttr.addSubmitted(ecf::TimeSlot(3, 12)); + lateAttr.addActive(ecf::TimeSlot(3, 12)); + lateAttr.addComplete(ecf::TimeSlot(4, 12), true); + + NodeLateMemento memento(lateAttr); + t->set_memento(&memento, aspects, aspect_only); // add late; + + PersistHelper helper; + BOOST_CHECK_MESSAGE(helper.test_state_persist_and_reload_with_checkpt(defs), + "NodeLateMemento failed: " << helper.errorMsg()); + + lateAttr.setLate(true); + NodeLateMemento memento1(lateAttr); // change late + t->set_memento(&memento1, aspects, aspect_only); + BOOST_CHECK_MESSAGE(helper.test_state_persist_and_reload_with_checkpt(defs), + "NodeLateMemento failed: " << helper.errorMsg()); + } + { + Defs defs; + suite_ptr suite = defs.add_suite("s1"); + node_ptr t = suite->add_task("t1"); + + ecf::TodayAttr attr(ecf::TimeSlot(10, 12)); + + NodeTodayMemento memento(attr); + t->set_memento(&memento, aspects, aspect_only); // add today; + + PersistHelper helper; + BOOST_CHECK_MESSAGE(helper.test_state_persist_and_reload_with_checkpt(defs), + "NodeTodayMemento failed: " << helper.errorMsg()); + + attr.setFree(); + NodeTodayMemento memento1(attr); // change today + t->set_memento(&memento1, aspects, aspect_only); + BOOST_CHECK_MESSAGE(helper.test_state_persist_and_reload_with_checkpt(defs), + "NodeTodayMemento failed: " << helper.errorMsg()); + } + { + Defs defs; + suite_ptr suite = defs.add_suite("s1"); + node_ptr t = suite->add_task("t1"); + + ecf::TimeAttr attr(ecf::TimeSlot(10, 12)); + + NodeTimeMemento memento(attr); + t->set_memento(&memento, aspects, aspect_only); // add time; + + PersistHelper helper; + BOOST_CHECK_MESSAGE(helper.test_state_persist_and_reload_with_checkpt(defs), + "NodeTimeMemento failed: " << helper.errorMsg()); + + attr.setFree(); + NodeTimeMemento memento1(attr); // change time + t->set_memento(&memento1, aspects, aspect_only); + BOOST_CHECK_MESSAGE(helper.test_state_persist_and_reload_with_checkpt(defs), + "NodeTimeMemento failed: " << helper.errorMsg()); + } + { + Defs defs; + suite_ptr suite = defs.add_suite("s1"); + node_ptr t = suite->add_task("t1"); + + DayAttr attr(DayAttr::MONDAY); + + NodeDayMemento memento(attr); + t->set_memento(&memento, aspects, aspect_only); // add day; + + PersistHelper helper; + BOOST_CHECK_MESSAGE(helper.test_state_persist_and_reload_with_checkpt(defs), + "NodeDayMemento failed: " << helper.errorMsg()); + + attr.setFree(); + NodeDayMemento memento1(attr); // change day + t->set_memento(&memento1, aspects, aspect_only); + BOOST_CHECK_MESSAGE(helper.test_state_persist_and_reload_with_checkpt(defs), + "NodeDayMemento failed: " << helper.errorMsg()); + } + { + Defs defs; + suite_ptr suite = defs.add_suite("s1"); + node_ptr t = suite->add_task("t1"); + + DateAttr attr(1, 2, 2009); + + NodeDateMemento memento(attr); + t->set_memento(&memento, aspects, aspect_only); // add date; + + PersistHelper helper; + BOOST_CHECK_MESSAGE(helper.test_state_persist_and_reload_with_checkpt(defs), + "NodeDateMemento failed: " << helper.errorMsg()); + + attr.setFree(); + NodeDateMemento memento1(attr); // change date + t->set_memento(&memento1, aspects, aspect_only); + BOOST_CHECK_MESSAGE(helper.test_state_persist_and_reload_with_checkpt(defs), + "NodeDateMemento failed: " << helper.errorMsg()); + } + { + Defs defs; + suite_ptr suite = defs.add_suite("s1"); + node_ptr t = suite->add_task("t1"); + + ecf::CronAttr attr; + ecf::TimeSlot start(0, 0); + ecf::TimeSlot finish(10, 0); + ecf::TimeSlot incr(0, 5); + std::vector weekdays; + for (int i = 0; i < 7; ++i) + weekdays.push_back(i); + std::vector daysOfMonth; + for (int i = 1; i < 32; ++i) + daysOfMonth.push_back(i); + std::vector months; + for (int i = 1; i < 13; ++i) + months.push_back(i); + attr.addTimeSeries(start, finish, incr); + attr.addWeekDays(weekdays); + attr.addDaysOfMonth(daysOfMonth); + attr.addMonths(months); + + NodeCronMemento memento(attr); + t->set_memento(&memento, aspects, aspect_only); // add cron; + + PersistHelper helper; + BOOST_CHECK_MESSAGE(helper.test_state_persist_and_reload_with_checkpt(defs), + "NodeCronMemento failed: " << helper.errorMsg()); + + attr.setFree(); + NodeCronMemento memento1(attr); // change cron + t->set_memento(&memento1, aspects, aspect_only); + BOOST_CHECK_MESSAGE(helper.test_state_persist_and_reload_with_checkpt(defs), + "NodeCronMemento failed: " << helper.errorMsg()); + } + + { + Defs defs; + suite_ptr suite = defs.add_suite("s1"); + node_ptr t = suite->add_task("t1"); + + std::vector child_cmds = ecf::Child::list(); + + ZombieAttr attr(ecf::Child::USER, child_cmds, ecf::User::FOB, 10); + + NodeZombieMemento memento(attr); + t->set_memento(&memento, aspects, aspect_only); // add zombie; + + PersistHelper helper; + BOOST_CHECK_MESSAGE(helper.test_state_persist_and_reload_with_checkpt(defs), + "NodeZombieMemento failed: " << helper.errorMsg()); + } } BOOST_AUTO_TEST_SUITE_END() diff --git a/ANode/parser/test/TestMigration.cpp b/ANode/parser/test/TestMigration.cpp index 17a5fc032..019b4d4b1 100644 --- a/ANode/parser/test/TestMigration.cpp +++ b/ANode/parser/test/TestMigration.cpp @@ -12,18 +12,18 @@ // // Description : //============================================================================ -#include #include +#include #include #include "Defs.hpp" #include "Family.hpp" -#include "Task.hpp" -#include "PersistHelper.hpp" #include "Flag.hpp" #include "Memento.hpp" #include "MyDefsFixture.hpp" +#include "PersistHelper.hpp" +#include "Task.hpp" using namespace std; using namespace ecf; @@ -46,500 +46,571 @@ using namespace boost::gregorian; // Finally compare the two *RELOADED* defs file. // ******************************************************************** -BOOST_AUTO_TEST_SUITE( ParserTestSuite ) +BOOST_AUTO_TEST_SUITE(ParserTestSuite) -BOOST_AUTO_TEST_CASE( test_state_parser ) -{ - cout << "AParser:: ...test_state_parser\n"; - // **** The persistence will NOT write the defaults, hence we need to change the states - // **** to test the persistence - PersistHelper helper; - std::vector flag_list = Flag::list(); - { - Defs defs; - BOOST_CHECK_MESSAGE( helper.test_state_persist_and_reload_with_checkpt(defs), "Empty Defs failed: " << helper.errorMsg()); - } - { - Defs defs; - suite_ptr suite = defs.add_suite("s1"); - - // Change state other the default - defs.beginAll(); - suite->set_state(NState::ABORTED); - for (auto & i : flag_list) suite->flag().set( i ); - suite->suspend(); - BOOST_CHECK_MESSAGE( helper.test_state_persist_and_reload_with_checkpt(defs),"Add one suite failed: " << helper.errorMsg()); - } - { - Defs defs; - suite_ptr suite = defs.add_suite("s1"); - family_ptr f1 = suite->add_family("f1"); - - // Change state other the default - f1->set_state(NState::COMPLETE); - for (auto & i : flag_list) f1->flag().set( i ); - f1->suspend(); - BOOST_CHECK_MESSAGE( helper.test_state_persist_and_reload_with_checkpt(defs),"Add one family failed: " << helper.errorMsg()); - - // Test multiple - suite->add_family("f2"); - suite->add_family("f3"); - BOOST_CHECK_MESSAGE( helper.test_state_persist_and_reload_with_checkpt(defs),"Add one family failed: " << helper.errorMsg()); - } - { - Defs defs; - family_ptr f1 = defs.add_suite("s1")->add_family("f1"); - task_ptr t1 = f1->add_task("t1"); - - for (auto & i : flag_list) t1->flag().set( i ); - t1->suspend(); - t1->set_state(NState::COMPLETE); - - // Use memento to modify task state - SubmittableMemento memento( "Jobs_password","the_rid","the abort reason with spaces",12); - std::vector aspects; - t1->set_memento(&memento,aspects,false); - - BOOST_CHECK_MESSAGE( helper.test_state_persist_and_reload_with_checkpt(defs), "Add one task failed: " << helper.errorMsg()); - - // Test multiple - f1->add_task("t2"); - f1->add_task("t3"); - BOOST_CHECK_MESSAGE( helper.test_state_persist_and_reload_with_checkpt(defs), "Add one task failed: " << helper.errorMsg()); - } - { - Defs defs; - task_ptr task = defs.add_suite("s1")->add_family("f1")->add_task("t1"); - alias_ptr t1 = task->add_alias_only(); - for (auto & i : flag_list) t1->flag().set( i ); - t1->suspend(); - t1->set_state(NState::COMPLETE); - // Use memento to modify alias state - SubmittableMemento memento( "Jobs_password","the_rid","the abort reason with spaces",12); - std::vector aspects; - t1->set_memento(&memento,aspects,false); - BOOST_CHECK_MESSAGE( helper.test_state_persist_and_reload_with_checkpt(defs), "Add one alias failed: " << helper.errorMsg()); - - // Test multiple - task->add_alias_only(); - task->add_alias_only(); - // PrintStyle style(PrintStyle::MIGRATE); std::cout << defs; - BOOST_CHECK_MESSAGE( helper.test_state_persist_and_reload_with_checkpt(defs), "Add multiple alias failed: " << helper.errorMsg()); - } +BOOST_AUTO_TEST_CASE(test_state_parser) { + cout << "AParser:: ...test_state_parser\n"; + // **** The persistence will NOT write the defaults, hence we need to change the states + // **** to test the persistence + PersistHelper helper; + std::vector flag_list = Flag::list(); + { + Defs defs; + BOOST_CHECK_MESSAGE(helper.test_state_persist_and_reload_with_checkpt(defs), + "Empty Defs failed: " << helper.errorMsg()); + } + { + Defs defs; + suite_ptr suite = defs.add_suite("s1"); + + // Change state other the default + defs.beginAll(); + suite->set_state(NState::ABORTED); + for (auto& i : flag_list) + suite->flag().set(i); + suite->suspend(); + BOOST_CHECK_MESSAGE(helper.test_state_persist_and_reload_with_checkpt(defs), + "Add one suite failed: " << helper.errorMsg()); + } + { + Defs defs; + suite_ptr suite = defs.add_suite("s1"); + family_ptr f1 = suite->add_family("f1"); + + // Change state other the default + f1->set_state(NState::COMPLETE); + for (auto& i : flag_list) + f1->flag().set(i); + f1->suspend(); + BOOST_CHECK_MESSAGE(helper.test_state_persist_and_reload_with_checkpt(defs), + "Add one family failed: " << helper.errorMsg()); + + // Test multiple + suite->add_family("f2"); + suite->add_family("f3"); + BOOST_CHECK_MESSAGE(helper.test_state_persist_and_reload_with_checkpt(defs), + "Add one family failed: " << helper.errorMsg()); + } + { + Defs defs; + family_ptr f1 = defs.add_suite("s1")->add_family("f1"); + task_ptr t1 = f1->add_task("t1"); + + for (auto& i : flag_list) + t1->flag().set(i); + t1->suspend(); + t1->set_state(NState::COMPLETE); + + // Use memento to modify task state + SubmittableMemento memento("Jobs_password", "the_rid", "the abort reason with spaces", 12); + std::vector aspects; + t1->set_memento(&memento, aspects, false); + + BOOST_CHECK_MESSAGE(helper.test_state_persist_and_reload_with_checkpt(defs), + "Add one task failed: " << helper.errorMsg()); + + // Test multiple + f1->add_task("t2"); + f1->add_task("t3"); + BOOST_CHECK_MESSAGE(helper.test_state_persist_and_reload_with_checkpt(defs), + "Add one task failed: " << helper.errorMsg()); + } + { + Defs defs; + task_ptr task = defs.add_suite("s1")->add_family("f1")->add_task("t1"); + alias_ptr t1 = task->add_alias_only(); + for (auto& i : flag_list) + t1->flag().set(i); + t1->suspend(); + t1->set_state(NState::COMPLETE); + // Use memento to modify alias state + SubmittableMemento memento("Jobs_password", "the_rid", "the abort reason with spaces", 12); + std::vector aspects; + t1->set_memento(&memento, aspects, false); + BOOST_CHECK_MESSAGE(helper.test_state_persist_and_reload_with_checkpt(defs), + "Add one alias failed: " << helper.errorMsg()); + + // Test multiple + task->add_alias_only(); + task->add_alias_only(); + // PrintStyle style(PrintStyle::MIGRATE); std::cout << defs; + BOOST_CHECK_MESSAGE(helper.test_state_persist_and_reload_with_checkpt(defs), + "Add multiple alias failed: " << helper.errorMsg()); + } } -BOOST_AUTO_TEST_CASE( test_state_node_attributes ) -{ - cout << "AParser:: ...test_state_node_attributes\n"; - PersistHelper helper; - { - Defs defs; - suite_ptr suite = defs.add_suite("s1"); - task_ptr task = suite->add_task("t1"); - ecf::LateAttr lateAttr; - lateAttr.addSubmitted( ecf::TimeSlot(3,12) ); - lateAttr.addActive( ecf::TimeSlot(3,12) ); - lateAttr.addComplete( ecf::TimeSlot(4,12), true); - lateAttr.setLate(true); - task->addLate(lateAttr); - - ecf::LateAttr lateAttr1; - lateAttr1.addSubmitted( ecf::TimeSlot(3,12) ); - lateAttr1.addActive( ecf::TimeSlot(3,12) ); - lateAttr1.addComplete( ecf::TimeSlot(4,12), false); - lateAttr1.setLate(true); - task_ptr task1 = suite->add_task("t2"); - task1->addLate(lateAttr1); - -// PrintStyle style(PrintStyle::MIGRATE); std::cout << defs; - BOOST_CHECK_MESSAGE( helper.test_state_persist_and_reload_with_checkpt(defs), "Late state: failed: " << helper.errorMsg()); - } - { - Defs defs; - task_ptr task = defs.add_suite("s1")->add_task("t1"); - Meter meter("meter",0,100,100); meter.set_value(10); - task->addMeter(meter); -// PrintStyle style(PrintStyle::MIGRATE); std::cout << defs; - BOOST_CHECK_MESSAGE( helper.test_state_persist_and_reload_with_checkpt(defs), "Meter state: failed: " << helper.errorMsg()); - } - { - Defs defs; - task_ptr task = defs.add_suite("s1")->add_task("t1"); - Event event("event"); event.set_value(true); - Event event2(10,"event"); event2.set_value(true); - Event event3(10); event3.set_value(true); - Event event4(10,"event4",true/*init value*/,true/*value*/); - Event event5(10,"event5",true/*init value*/,false/*value*/); - task->addEvent(event); - task->addEvent(event2); - task->addEvent(event3); - task->addEvent(event4); - task->addEvent(event5); - // PrintStyle style(PrintStyle::MIGRATE); std::cout << defs; - BOOST_CHECK_MESSAGE( helper.test_state_persist_and_reload_with_checkpt(defs), "Event state: failed: " << helper.errorMsg()); - } - { - Defs defs; - suite_ptr suite = defs.add_suite("s1"); - family_ptr fam = suite->add_family("f1"); - task_ptr t = fam->add_task("t"); - std::vector queue_items; queue_items.emplace_back("001"); queue_items.emplace_back("002"); queue_items.emplace_back("003"); - QueueAttr queue("queue",queue_items); queue.active(); queue.active(); - QueueAttr queue1("queue1",queue_items); queue1.active(); - suite->add_queue(queue); suite->add_queue(queue1); - fam->add_queue(queue); fam->add_queue(queue1); - t->add_queue(queue); t->add_queue(queue1); - //PrintStyle::setStyle(PrintStyle::MIGRATE); std::cout << defs; - BOOST_CHECK_MESSAGE( helper.test_state_persist_and_reload_with_checkpt(defs), "Queue state: failed: " << helper.errorMsg()); - } - { - { - Defs defs; - task_ptr task = defs.add_suite("s1")->add_task("t1"); - Label label("name","value"); label.set_new_value("new value"); - task->addLabel(label); - // PrintStyle style(PrintStyle::MIGRATE); std::cout << defs; - BOOST_CHECK_MESSAGE( helper.test_state_persist_and_reload_with_checkpt(defs), "Label state: failed: " << helper.errorMsg()); - } - { - Defs defs; - suite_ptr suite = defs.add_suite("s1"); - Label label("name","value"); label.set_new_value("new value"); - suite->addLabel(label); - // PrintStyle style(PrintStyle::MIGRATE); std::cout << defs; - BOOST_CHECK_MESSAGE( helper.test_state_persist_and_reload_with_checkpt(defs), "Label state: failed: " << helper.errorMsg()); - } - { - Defs defs; - suite_ptr suite = defs.add_suite("s1"); - Label label("name","value\nvalue"); - suite->addLabel(label); - // PrintStyle style(PrintStyle::MIGRATE); std::cout << defs; - BOOST_CHECK_MESSAGE( helper.test_state_persist_and_reload_with_checkpt(defs), "Label state: failed: " << helper.errorMsg()); - } - { - Defs defs; - suite_ptr suite = defs.add_suite("s1"); - Label label("name","value\nvalue"); label.set_new_value("value\nwith\nmany\nnewlines"); - suite->addLabel(label); - // PrintStyle style(PrintStyle::MIGRATE); std::cout << defs; - BOOST_CHECK_MESSAGE( helper.test_state_persist_and_reload_with_checkpt(defs), "Label state: failed: " << helper.errorMsg()); - } - } - { - Defs defs; - suite_ptr suite = defs.add_suite("s1"); - task_ptr t1 = suite->add_task("t1"); - task_ptr t2 = suite->add_task("t2"); - task_ptr t3 = suite->add_task("t3"); - task_ptr t4 = suite->add_task("t4"); - Limit limit("limit",10); - limit.increment(1,t1->absNodePath()); - limit.increment(1,t2->absNodePath()); - limit.increment(1,t3->absNodePath()); - limit.increment(1,t4->absNodePath()); - suite->addLimit(limit); - // PrintStyle style(PrintStyle::MIGRATE); std::cout << defs; - BOOST_CHECK_MESSAGE( helper.test_state_persist_and_reload_with_checkpt(defs), "Limit state: failed: " << helper.errorMsg()); - } - { - Defs defs; - suite_ptr suite = defs.add_suite("s1"); - task_ptr t1 = suite->add_task("t1"); - InLimit inlimit1("limit","/s1",10,true); // limit has state when 'limit this node only' is set - inlimit1.set_incremented(true); // the state - InLimit inlimit2("limit2","/s1",10); - t1->addInLimit(inlimit1); - t1->addInLimit(inlimit2); - - // PrintStyle style(PrintStyle::MIGRATE); std::cout << defs; - BOOST_CHECK_MESSAGE( helper.test_state_persist_and_reload_with_checkpt(defs), "InLimit state: failed: " << helper.errorMsg()); - } - { +BOOST_AUTO_TEST_CASE(test_state_node_attributes) { + cout << "AParser:: ...test_state_node_attributes\n"; + PersistHelper helper; + { Defs defs; suite_ptr suite = defs.add_suite("s1"); - task_ptr t1 = suite->add_task("t1"); - task_ptr t2 = suite->add_task("t2"); - task_ptr t3 = suite->add_task("t3"); - task_ptr t4 = suite->add_task("t4"); - task_ptr t5 = suite->add_task("t5"); - task_ptr t6 = suite->add_task("t6"); - - std::vector stringList; stringList.reserve(3); - stringList.emplace_back("20130101"); - stringList.emplace_back("20130201"); - stringList.emplace_back("20130301"); - - RepeatEnumerated rep("AEnum",stringList); - rep.increment(); - t1->addRepeat( rep ); - - RepeatString rep2("AEnum",stringList); - rep2.increment(); - t2->addRepeat( rep2 ); - - RepeatDate rep3("YMD",20090916,20090916,1); - rep3.increment(); - t3->addRepeat( rep3 ); - - RepeatInteger rep4("rep",0,100,1); - rep4.increment(); - t4->addRepeat( rep4 ); - t4->increment_repeat(); - - RepeatDay rep5(2); - rep5.increment(); - t5->addRepeat( rep5 ); - - RepeatDateList rep6("YMD",{20090916,20090916}); - rep6.increment(); - t6->addRepeat( rep6 ); + task_ptr task = suite->add_task("t1"); + ecf::LateAttr lateAttr; + lateAttr.addSubmitted(ecf::TimeSlot(3, 12)); + lateAttr.addActive(ecf::TimeSlot(3, 12)); + lateAttr.addComplete(ecf::TimeSlot(4, 12), true); + lateAttr.setLate(true); + task->addLate(lateAttr); + + ecf::LateAttr lateAttr1; + lateAttr1.addSubmitted(ecf::TimeSlot(3, 12)); + lateAttr1.addActive(ecf::TimeSlot(3, 12)); + lateAttr1.addComplete(ecf::TimeSlot(4, 12), false); + lateAttr1.setLate(true); + task_ptr task1 = suite->add_task("t2"); + task1->addLate(lateAttr1); // PrintStyle style(PrintStyle::MIGRATE); std::cout << defs; - BOOST_CHECK_MESSAGE( helper.test_state_persist_and_reload_with_checkpt(defs), "Repeat state: failed: " << helper.errorMsg()); - } + BOOST_CHECK_MESSAGE(helper.test_state_persist_and_reload_with_checkpt(defs), + "Late state: failed: " << helper.errorMsg()); + } + { + Defs defs; + task_ptr task = defs.add_suite("s1")->add_task("t1"); + Meter meter("meter", 0, 100, 100); + meter.set_value(10); + task->addMeter(meter); + // PrintStyle style(PrintStyle::MIGRATE); std::cout << defs; + BOOST_CHECK_MESSAGE(helper.test_state_persist_and_reload_with_checkpt(defs), + "Meter state: failed: " << helper.errorMsg()); + } + { + Defs defs; + task_ptr task = defs.add_suite("s1")->add_task("t1"); + Event event("event"); + event.set_value(true); + Event event2(10, "event"); + event2.set_value(true); + Event event3(10); + event3.set_value(true); + Event event4(10, "event4", true /*init value*/, true /*value*/); + Event event5(10, "event5", true /*init value*/, false /*value*/); + task->addEvent(event); + task->addEvent(event2); + task->addEvent(event3); + task->addEvent(event4); + task->addEvent(event5); + // PrintStyle style(PrintStyle::MIGRATE); std::cout << defs; + BOOST_CHECK_MESSAGE(helper.test_state_persist_and_reload_with_checkpt(defs), + "Event state: failed: " << helper.errorMsg()); + } + { + Defs defs; + suite_ptr suite = defs.add_suite("s1"); + family_ptr fam = suite->add_family("f1"); + task_ptr t = fam->add_task("t"); + std::vector queue_items; + queue_items.emplace_back("001"); + queue_items.emplace_back("002"); + queue_items.emplace_back("003"); + QueueAttr queue("queue", queue_items); + queue.active(); + queue.active(); + QueueAttr queue1("queue1", queue_items); + queue1.active(); + suite->add_queue(queue); + suite->add_queue(queue1); + fam->add_queue(queue); + fam->add_queue(queue1); + t->add_queue(queue); + t->add_queue(queue1); + // PrintStyle::setStyle(PrintStyle::MIGRATE); std::cout << defs; + BOOST_CHECK_MESSAGE(helper.test_state_persist_and_reload_with_checkpt(defs), + "Queue state: failed: " << helper.errorMsg()); + } + {{Defs defs; + task_ptr task = defs.add_suite("s1")->add_task("t1"); + Label label("name", "value"); + label.set_new_value("new value"); + task->addLabel(label); + // PrintStyle style(PrintStyle::MIGRATE); std::cout << defs; + BOOST_CHECK_MESSAGE(helper.test_state_persist_and_reload_with_checkpt(defs), + "Label state: failed: " << helper.errorMsg()); } - -BOOST_AUTO_TEST_CASE( test_state_time_attributes ) { - cout << "AParser:: ...test_state_time_attributes\n"; - PersistHelper helper; - { - Defs defs; - suite_ptr suite = defs.add_suite("s1"); suite->begin(); - task_ptr task = suite->add_task("t1"); - TimeAttr time(10,10); time.setFree(); time.miss_next_time_slot(); - TimeAttr time2(10,10,true); time2.calendarChanged(suite->calendar()); time2.setFree(); time2.miss_next_time_slot(); - TimeAttr time3(TimeSlot(10,10),TimeSlot(12,10),TimeSlot(0,10),true); time3.calendarChanged(suite->calendar());time3.setFree(); time3.miss_next_time_slot(); - - task->addTime(time); - task->addTime(time2); - task->addTime(time3); - // PrintStyle style(PrintStyle::MIGRATE); std::cout << defs; - BOOST_CHECK_MESSAGE( helper.test_state_persist_and_reload_with_checkpt(defs), "Time state: failed: " << helper.errorMsg()); - } - { - Defs defs; - suite_ptr suite = defs.add_suite("s1"); suite->begin(); - task_ptr task = suite->add_task("t1"); - TodayAttr time(10,10); time.setFree(); time.miss_next_time_slot(); - TodayAttr time2(10,10,true); time2.calendarChanged(suite->calendar()); time2.setFree(); time2.miss_next_time_slot(); - TodayAttr time3(TimeSlot(10,10),TimeSlot(12,10),TimeSlot(0,10),true); time3.calendarChanged(suite->calendar());time3.setFree(); time3.miss_next_time_slot(); - task->addToday(time); - task->addToday(time2); - task->addToday(time3); - // PrintStyle style(PrintStyle::MIGRATE); std::cout << defs; - BOOST_CHECK_MESSAGE( helper.test_state_persist_and_reload_with_checkpt(defs), "Today state: failed: " << helper.errorMsg()); - } - { - Defs defs; - task_ptr task = defs.add_suite("s1")->add_task("t1"); - DayAttr day; - DayAttr day1; day1.setFree(); - DayAttr day2(DayAttr::FRIDAY); day2.setFree(); - task->addDay(day); - task->addDay(day1); - task->addDay(day2); - // PrintStyle style(PrintStyle::MIGRATE); std::cout << defs; - BOOST_CHECK_MESSAGE( helper.test_state_persist_and_reload_with_checkpt(defs), "Day state: failed: " << helper.errorMsg()); - } - { - Defs defs; - task_ptr task = defs.add_suite("s1")->add_task("t1"); - DateAttr d; - DateAttr d1; d1.setFree(); - DateAttr d2(1,1,2012); d2.setFree(); - DateAttr d3(0,0,2012); d3.setFree(); - task->addDate(d); - task->addDate(d1); - task->addDate(d2); - task->addDate(d3); - // PrintStyle style(PrintStyle::MIGRATE); std::cout << defs; - BOOST_CHECK_MESSAGE( helper.test_state_persist_and_reload_with_checkpt(defs), "Date state: failed: " << helper.errorMsg()); - } - { - Defs defs; - suite_ptr suite = defs.add_suite("s1"); suite->begin(); - task_ptr task = suite->add_task("t1"); - task_ptr task2 = suite->add_task("t2"); - - ecf::CronAttr cronAttr; - ecf::TimeSlot start( 0, 0 ); - ecf::TimeSlot finish( 10, 0 ); - ecf::TimeSlot incr( 0, 5 ); - std::vector weekdays; for(int i=0;i<7;++i) weekdays.push_back(i); - std::vector daysOfMonth;for(int i=1;i<32;++i) daysOfMonth.push_back(i); - std::vector months; for(int i=1;i<13;++i) months.push_back(i); - cronAttr.addTimeSeries(start,finish,incr); - cronAttr.addWeekDays( weekdays ); - cronAttr.addDaysOfMonth(daysOfMonth); - cronAttr.addMonths( months ); - cronAttr.setFree(); - task->addCron(cronAttr); - - // Change TimeSeries state - TimeSeries ts(start,finish,incr,true); - ts.calendarChanged(suite->calendar()); - ts.miss_next_time_slot(); - cronAttr.addTimeSeries(ts); - task2->addCron(cronAttr); - - // PrintStyle style(PrintStyle::MIGRATE); std::cout << defs; - BOOST_CHECK_MESSAGE( helper.test_state_persist_and_reload_with_checkpt(defs), "Date state: failed: " << helper.errorMsg()); - } - - // ZombieAttr do not have any changeable state + Defs defs; + suite_ptr suite = defs.add_suite("s1"); + Label label("name", "value"); + label.set_new_value("new value"); + suite->addLabel(label); + // PrintStyle style(PrintStyle::MIGRATE); std::cout << defs; + BOOST_CHECK_MESSAGE(helper.test_state_persist_and_reload_with_checkpt(defs), + "Label state: failed: " << helper.errorMsg()); } - -BOOST_AUTO_TEST_CASE( test_state_edit_history ) { - cout << "AParser:: ...test_state_edit_history\n"; - PersistHelper helper(true /* compare edit History */); - Defs defs; - suite_ptr suite = defs.add_suite("s1"); - defs.add_edit_history(suite->absNodePath(),"request1 with single spaces"); - defs.add_edit_history(suite->absNodePath(),"request2 with double spaces"); - defs.add_edit_history(suite->absNodePath(),"request3_with_no_spaces!|?<>$%^&*()_{}:@<>?"); - suite_ptr suite2 = defs.add_suite("s2"); - defs.add_edit_history(suite2->absNodePath(),"request1 with single spaces"); - defs.add_edit_history(suite2->absNodePath(),"request2 with double spaces"); - defs.add_edit_history(suite2->absNodePath(),"request3_with_no_spaces!|?<>$%^&*()_{}:@<>?"); -// PrintStyle style(PrintStyle::MIGRATE); std::cout << defs; - BOOST_REQUIRE_MESSAGE( helper.test_state_persist_and_reload_with_checkpt(defs), "Edit history failed: " << helper.errorMsg()); + Defs defs; + suite_ptr suite = defs.add_suite("s1"); + Label label("name", "value\nvalue"); + suite->addLabel(label); + // PrintStyle style(PrintStyle::MIGRATE); std::cout << defs; + BOOST_CHECK_MESSAGE(helper.test_state_persist_and_reload_with_checkpt(defs), + "Label state: failed: " << helper.errorMsg()); } - - -static std::string dump_edit_history(const std::unordered_map >& edit_history) { - std::stringstream ss; - for(const auto& i : edit_history) { - ss << "node: " << i.first << "\n"; - for(const auto& h : i.second) { - ss << " " << h << "\n"; - } - } - return ss.str(); + Defs defs; + suite_ptr suite = defs.add_suite("s1"); + Label label("name", "value\nvalue"); + label.set_new_value("value\nwith\nmany\nnewlines"); + suite->addLabel(label); + // PrintStyle style(PrintStyle::MIGRATE); std::cout << defs; + BOOST_CHECK_MESSAGE(helper.test_state_persist_and_reload_with_checkpt(defs), + "Label state: failed: " << helper.errorMsg()); +} } - -BOOST_AUTO_TEST_CASE( test_state_edit_history_pruning ) { - cout << "AParser:: ...test_state_edit_history_pruning\n"; - Defs defs; - suite_ptr suite = defs.add_suite("s1"); - defs.add_edit_history(suite->absNodePath(),"MSG:[07:36:05 10.3.2016] --requeue force /s1 :maj"); - defs.add_edit_history(suite->absNodePath(),"MSG:[09:15:33 26.8.2016] --run /s1 :mab"); - defs.add_edit_history(suite->absNodePath(),"MSG:[06:45:18 26.8.2017] --force=queued /s1 :ma0"); - suite_ptr suite2 = defs.add_suite("s2"); - defs.add_edit_history(suite2->absNodePath(),"MSG:[19:13:44 21.6.2016] --suspend /s2 :ma"); - defs.add_edit_history(suite2->absNodePath(),"MSG:[11:28:12 6.10.2016] --requeue abort /s2 :ma"); - defs.add_edit_history(suite2->absNodePath(),"MSG:[09:15:33 26.8.2016] --run /s2 :mab"); -// PrintStyle style(PrintStyle::MIGRATE); std::cout << defs; -// cout << dump_edit_history(defs.get_edit_history()) << "\n"; - - std::string tmpFilename = "test_state_edit_history_pruning.def"; - defs.save_as_checkpt(tmpFilename); - - { - // If any edit history is older than 1 day, then prune - Defs reloaded_defs; - reloaded_defs.ecf_prune_node_log(1); - - std::string errorMsg, warningMsg; - BOOST_REQUIRE_MESSAGE( reloaded_defs.restore(tmpFilename,errorMsg,warningMsg), "RE-PARSE failed for " << tmpFilename); - - const std::unordered_map >& edit_history = reloaded_defs.get_edit_history(); - BOOST_REQUIRE_MESSAGE( edit_history.empty() , "Expected no edit history after pruning, but found:\n" << dump_edit_history(edit_history) ); - } - - std::remove(tmpFilename.c_str()); + Defs defs; + suite_ptr suite = defs.add_suite("s1"); + task_ptr t1 = suite->add_task("t1"); + task_ptr t2 = suite->add_task("t2"); + task_ptr t3 = suite->add_task("t3"); + task_ptr t4 = suite->add_task("t4"); + Limit limit("limit", 10); + limit.increment(1, t1->absNodePath()); + limit.increment(1, t2->absNodePath()); + limit.increment(1, t3->absNodePath()); + limit.increment(1, t4->absNodePath()); + suite->addLimit(limit); + // PrintStyle style(PrintStyle::MIGRATE); std::cout << defs; + BOOST_CHECK_MESSAGE(helper.test_state_persist_and_reload_with_checkpt(defs), + "Limit state: failed: " << helper.errorMsg()); } - -BOOST_AUTO_TEST_CASE( test_state_edit_history_pruning2 ) { - cout << "AParser:: ...test_state_edit_history_pruning2\n"; - - // Create edit history for today, this should not be affected by pruning - date todays_date_in_utc = day_clock::universal_day(); - std::string history = "MSG:[07:36:05 "; - history += boost::lexical_cast(todays_date_in_utc.day()); - history += "."; - history += boost::lexical_cast(todays_date_in_utc.month()); - history += "."; - history += boost::lexical_cast(todays_date_in_utc.year()); - history += "] --requeue force /s1 :maj"; - - - - Defs defs; - suite_ptr suite = defs.add_suite("s1"); - defs.add_edit_history(suite->absNodePath(),history); - defs.add_edit_history(suite->absNodePath(),history); - defs.add_edit_history(suite->absNodePath(),history); -// PrintStyle style(PrintStyle::MIGRATE); std::cout << defs; -// cout << dump_edit_history(defs.get_edit_history()) << "\n"; + Defs defs; + suite_ptr suite = defs.add_suite("s1"); + task_ptr t1 = suite->add_task("t1"); + InLimit inlimit1("limit", "/s1", 10, true); // limit has state when 'limit this node only' is set + inlimit1.set_incremented(true); // the state + InLimit inlimit2("limit2", "/s1", 10); + t1->addInLimit(inlimit1); + t1->addInLimit(inlimit2); + + // PrintStyle style(PrintStyle::MIGRATE); std::cout << defs; + BOOST_CHECK_MESSAGE(helper.test_state_persist_and_reload_with_checkpt(defs), + "InLimit state: failed: " << helper.errorMsg()); +} +{ + Defs defs; + suite_ptr suite = defs.add_suite("s1"); + task_ptr t1 = suite->add_task("t1"); + task_ptr t2 = suite->add_task("t2"); + task_ptr t3 = suite->add_task("t3"); + task_ptr t4 = suite->add_task("t4"); + task_ptr t5 = suite->add_task("t5"); + task_ptr t6 = suite->add_task("t6"); + + std::vector stringList; + stringList.reserve(3); + stringList.emplace_back("20130101"); + stringList.emplace_back("20130201"); + stringList.emplace_back("20130301"); + + RepeatEnumerated rep("AEnum", stringList); + rep.increment(); + t1->addRepeat(rep); + + RepeatString rep2("AEnum", stringList); + rep2.increment(); + t2->addRepeat(rep2); + + RepeatDate rep3("YMD", 20090916, 20090916, 1); + rep3.increment(); + t3->addRepeat(rep3); + + RepeatInteger rep4("rep", 0, 100, 1); + rep4.increment(); + t4->addRepeat(rep4); + t4->increment_repeat(); + + RepeatDay rep5(2); + rep5.increment(); + t5->addRepeat(rep5); + + RepeatDateList rep6("YMD", {20090916, 20090916}); + rep6.increment(); + t6->addRepeat(rep6); + + // PrintStyle style(PrintStyle::MIGRATE); std::cout << defs; + BOOST_CHECK_MESSAGE(helper.test_state_persist_and_reload_with_checkpt(defs), + "Repeat state: failed: " << helper.errorMsg()); +} +} - std::string tmpFilename = "test_state_edit_history_pruning2.def"; - defs.save_as_checkpt(tmpFilename); +BOOST_AUTO_TEST_CASE(test_state_time_attributes) { + cout << "AParser:: ...test_state_time_attributes\n"; + PersistHelper helper; + { + Defs defs; + suite_ptr suite = defs.add_suite("s1"); + suite->begin(); + task_ptr task = suite->add_task("t1"); + TimeAttr time(10, 10); + time.setFree(); + time.miss_next_time_slot(); + TimeAttr time2(10, 10, true); + time2.calendarChanged(suite->calendar()); + time2.setFree(); + time2.miss_next_time_slot(); + TimeAttr time3(TimeSlot(10, 10), TimeSlot(12, 10), TimeSlot(0, 10), true); + time3.calendarChanged(suite->calendar()); + time3.setFree(); + time3.miss_next_time_slot(); + + task->addTime(time); + task->addTime(time2); + task->addTime(time3); + // PrintStyle style(PrintStyle::MIGRATE); std::cout << defs; + BOOST_CHECK_MESSAGE(helper.test_state_persist_and_reload_with_checkpt(defs), + "Time state: failed: " << helper.errorMsg()); + } + { + Defs defs; + suite_ptr suite = defs.add_suite("s1"); + suite->begin(); + task_ptr task = suite->add_task("t1"); + TodayAttr time(10, 10); + time.setFree(); + time.miss_next_time_slot(); + TodayAttr time2(10, 10, true); + time2.calendarChanged(suite->calendar()); + time2.setFree(); + time2.miss_next_time_slot(); + TodayAttr time3(TimeSlot(10, 10), TimeSlot(12, 10), TimeSlot(0, 10), true); + time3.calendarChanged(suite->calendar()); + time3.setFree(); + time3.miss_next_time_slot(); + task->addToday(time); + task->addToday(time2); + task->addToday(time3); + // PrintStyle style(PrintStyle::MIGRATE); std::cout << defs; + BOOST_CHECK_MESSAGE(helper.test_state_persist_and_reload_with_checkpt(defs), + "Today state: failed: " << helper.errorMsg()); + } + { + Defs defs; + task_ptr task = defs.add_suite("s1")->add_task("t1"); + DayAttr day; + DayAttr day1; + day1.setFree(); + DayAttr day2(DayAttr::FRIDAY); + day2.setFree(); + task->addDay(day); + task->addDay(day1); + task->addDay(day2); + // PrintStyle style(PrintStyle::MIGRATE); std::cout << defs; + BOOST_CHECK_MESSAGE(helper.test_state_persist_and_reload_with_checkpt(defs), + "Day state: failed: " << helper.errorMsg()); + } + { + Defs defs; + task_ptr task = defs.add_suite("s1")->add_task("t1"); + DateAttr d; + DateAttr d1; + d1.setFree(); + DateAttr d2(1, 1, 2012); + d2.setFree(); + DateAttr d3(0, 0, 2012); + d3.setFree(); + task->addDate(d); + task->addDate(d1); + task->addDate(d2); + task->addDate(d3); + // PrintStyle style(PrintStyle::MIGRATE); std::cout << defs; + BOOST_CHECK_MESSAGE(helper.test_state_persist_and_reload_with_checkpt(defs), + "Date state: failed: " << helper.errorMsg()); + } + { + Defs defs; + suite_ptr suite = defs.add_suite("s1"); + suite->begin(); + task_ptr task = suite->add_task("t1"); + task_ptr task2 = suite->add_task("t2"); + + ecf::CronAttr cronAttr; + ecf::TimeSlot start(0, 0); + ecf::TimeSlot finish(10, 0); + ecf::TimeSlot incr(0, 5); + std::vector weekdays; + for (int i = 0; i < 7; ++i) + weekdays.push_back(i); + std::vector daysOfMonth; + for (int i = 1; i < 32; ++i) + daysOfMonth.push_back(i); + std::vector months; + for (int i = 1; i < 13; ++i) + months.push_back(i); + cronAttr.addTimeSeries(start, finish, incr); + cronAttr.addWeekDays(weekdays); + cronAttr.addDaysOfMonth(daysOfMonth); + cronAttr.addMonths(months); + cronAttr.setFree(); + task->addCron(cronAttr); + + // Change TimeSeries state + TimeSeries ts(start, finish, incr, true); + ts.calendarChanged(suite->calendar()); + ts.miss_next_time_slot(); + cronAttr.addTimeSeries(ts); + task2->addCron(cronAttr); - { - // Since the history is todays it should be preserved, and not affected by pruning - Defs reloaded_defs; - reloaded_defs.ecf_prune_node_log(1); + // PrintStyle style(PrintStyle::MIGRATE); std::cout << defs; + BOOST_CHECK_MESSAGE(helper.test_state_persist_and_reload_with_checkpt(defs), + "Date state: failed: " << helper.errorMsg()); + } - std::string errorMsg, warningMsg; - BOOST_REQUIRE_MESSAGE( reloaded_defs.restore(tmpFilename,errorMsg,warningMsg), "RE-PARSE failed for " << tmpFilename); + // ZombieAttr do not have any changeable state +} - const std::unordered_map >& edit_history = reloaded_defs.get_edit_history(); -// cout << dump_edit_history(defs.get_edit_history()) << "\n"; +BOOST_AUTO_TEST_CASE(test_state_edit_history) { + cout << "AParser:: ...test_state_edit_history\n"; + PersistHelper helper(true /* compare edit History */); + Defs defs; + suite_ptr suite = defs.add_suite("s1"); + defs.add_edit_history(suite->absNodePath(), "request1 with single spaces"); + defs.add_edit_history(suite->absNodePath(), "request2 with double spaces"); + defs.add_edit_history(suite->absNodePath(), "request3_with_no_spaces!|?<>$%^&*()_{}:@<>?"); + suite_ptr suite2 = defs.add_suite("s2"); + defs.add_edit_history(suite2->absNodePath(), "request1 with single spaces"); + defs.add_edit_history(suite2->absNodePath(), "request2 with double spaces"); + defs.add_edit_history(suite2->absNodePath(), "request3_with_no_spaces!|?<>$%^&*()_{}:@<>?"); + // PrintStyle style(PrintStyle::MIGRATE); std::cout << defs; + BOOST_REQUIRE_MESSAGE(helper.test_state_persist_and_reload_with_checkpt(defs), + "Edit history failed: " << helper.errorMsg()); +} - BOOST_REQUIRE_MESSAGE(!edit_history.empty() , "Expected edit history but found none"); - } +static std::string dump_edit_history(const std::unordered_map>& edit_history) { + std::stringstream ss; + for (const auto& i : edit_history) { + ss << "node: " << i.first << "\n"; + for (const auto& h : i.second) { + ss << " " << h << "\n"; + } + } + return ss.str(); +} - std::remove(tmpFilename.c_str()); +BOOST_AUTO_TEST_CASE(test_state_edit_history_pruning) { + cout << "AParser:: ...test_state_edit_history_pruning\n"; + Defs defs; + suite_ptr suite = defs.add_suite("s1"); + defs.add_edit_history(suite->absNodePath(), "MSG:[07:36:05 10.3.2016] --requeue force /s1 :maj"); + defs.add_edit_history(suite->absNodePath(), "MSG:[09:15:33 26.8.2016] --run /s1 :mab"); + defs.add_edit_history(suite->absNodePath(), "MSG:[06:45:18 26.8.2017] --force=queued /s1 :ma0"); + suite_ptr suite2 = defs.add_suite("s2"); + defs.add_edit_history(suite2->absNodePath(), "MSG:[19:13:44 21.6.2016] --suspend /s2 :ma"); + defs.add_edit_history(suite2->absNodePath(), "MSG:[11:28:12 6.10.2016] --requeue abort /s2 :ma"); + defs.add_edit_history(suite2->absNodePath(), "MSG:[09:15:33 26.8.2016] --run /s2 :mab"); + // PrintStyle style(PrintStyle::MIGRATE); std::cout << defs; + // cout << dump_edit_history(defs.get_edit_history()) << "\n"; + + std::string tmpFilename = "test_state_edit_history_pruning.def"; + defs.save_as_checkpt(tmpFilename); + + { + // If any edit history is older than 1 day, then prune + Defs reloaded_defs; + reloaded_defs.ecf_prune_node_log(1); + + std::string errorMsg, warningMsg; + BOOST_REQUIRE_MESSAGE(reloaded_defs.restore(tmpFilename, errorMsg, warningMsg), + "RE-PARSE failed for " << tmpFilename); + + const std::unordered_map>& edit_history = + reloaded_defs.get_edit_history(); + BOOST_REQUIRE_MESSAGE(edit_history.empty(), + "Expected no edit history after pruning, but found:\n" + << dump_edit_history(edit_history)); + } + + std::remove(tmpFilename.c_str()); } +BOOST_AUTO_TEST_CASE(test_state_edit_history_pruning2) { + cout << "AParser:: ...test_state_edit_history_pruning2\n"; + + // Create edit history for today, this should not be affected by pruning + date todays_date_in_utc = day_clock::universal_day(); + std::string history = "MSG:[07:36:05 "; + history += boost::lexical_cast(todays_date_in_utc.day()); + history += "."; + history += boost::lexical_cast(todays_date_in_utc.month()); + history += "."; + history += boost::lexical_cast(todays_date_in_utc.year()); + history += "] --requeue force /s1 :maj"; + + Defs defs; + suite_ptr suite = defs.add_suite("s1"); + defs.add_edit_history(suite->absNodePath(), history); + defs.add_edit_history(suite->absNodePath(), history); + defs.add_edit_history(suite->absNodePath(), history); + // PrintStyle style(PrintStyle::MIGRATE); std::cout << defs; + // cout << dump_edit_history(defs.get_edit_history()) << "\n"; + + std::string tmpFilename = "test_state_edit_history_pruning2.def"; + defs.save_as_checkpt(tmpFilename); + + { + // Since the history is todays it should be preserved, and not affected by pruning + Defs reloaded_defs; + reloaded_defs.ecf_prune_node_log(1); + + std::string errorMsg, warningMsg; + BOOST_REQUIRE_MESSAGE(reloaded_defs.restore(tmpFilename, errorMsg, warningMsg), + "RE-PARSE failed for " << tmpFilename); + + const std::unordered_map>& edit_history = + reloaded_defs.get_edit_history(); + // cout << dump_edit_history(defs.get_edit_history()) << "\n"; + + BOOST_REQUIRE_MESSAGE(!edit_history.empty(), "Expected edit history but found none"); + } + + std::remove(tmpFilename.c_str()); +} -BOOST_AUTO_TEST_CASE( test_server_state ) -{ - cout << "AParser:: ...test_server_state\n"; - PersistHelper helper(true /* compare edit History */); - { - Defs defs; - defs.set_server().set_state(SState::HALTED); - // PrintStyle style(PrintStyle::MIGRATE); std::cout << defs; - BOOST_CHECK_MESSAGE( helper.test_state_persist_and_reload_with_checkpt(defs), "Set server state failed " << helper.errorMsg()); - } - { - Defs defs; - defs.set_server().set_state(SState::RUNNING); - // PrintStyle style(PrintStyle::MIGRATE); std::cout << defs; - BOOST_CHECK_MESSAGE( helper.test_state_persist_and_reload_with_checkpt(defs), "Set server state failed " << helper.errorMsg()); - } - { - Defs defs; - defs.set_server().set_state(SState::SHUTDOWN); - // PrintStyle style(PrintStyle::MIGRATE); std::cout << defs; - BOOST_CHECK_MESSAGE( helper.test_state_persist_and_reload_with_checkpt(defs), "Set server state failed " << helper.errorMsg()); - } - { - Defs defs; - std::vector vec; - vec.emplace_back("name","value1"); - vec.emplace_back("name2","val with 'spaces' "); - vec.emplace_back("name3",""); - defs.set_server().set_user_variables(vec); - // PrintStyle style(PrintStyle::MIGRATE); std::cout << defs; - BOOST_CHECK_MESSAGE( helper.test_state_persist_and_reload_with_checkpt(defs), "Set server variables failed " << helper.errorMsg()); - } +BOOST_AUTO_TEST_CASE(test_server_state) { + cout << "AParser:: ...test_server_state\n"; + PersistHelper helper(true /* compare edit History */); + { + Defs defs; + defs.set_server().set_state(SState::HALTED); + // PrintStyle style(PrintStyle::MIGRATE); std::cout << defs; + BOOST_CHECK_MESSAGE(helper.test_state_persist_and_reload_with_checkpt(defs), + "Set server state failed " << helper.errorMsg()); + } + { + Defs defs; + defs.set_server().set_state(SState::RUNNING); + // PrintStyle style(PrintStyle::MIGRATE); std::cout << defs; + BOOST_CHECK_MESSAGE(helper.test_state_persist_and_reload_with_checkpt(defs), + "Set server state failed " << helper.errorMsg()); + } + { + Defs defs; + defs.set_server().set_state(SState::SHUTDOWN); + // PrintStyle style(PrintStyle::MIGRATE); std::cout << defs; + BOOST_CHECK_MESSAGE(helper.test_state_persist_and_reload_with_checkpt(defs), + "Set server state failed " << helper.errorMsg()); + } + { + Defs defs; + std::vector vec; + vec.emplace_back("name", "value1"); + vec.emplace_back("name2", "val with 'spaces' "); + vec.emplace_back("name3", ""); + defs.set_server().set_user_variables(vec); + // PrintStyle style(PrintStyle::MIGRATE); std::cout << defs; + BOOST_CHECK_MESSAGE(helper.test_state_persist_and_reload_with_checkpt(defs), + "Set server variables failed " << helper.errorMsg()); + } } -BOOST_AUTO_TEST_CASE( test_state_fixture_defs ) -{ - cout << "AParser:: ...test_state_fixture_defs\n"; - PersistHelper helper; - MyDefsFixture theDefsFixture; - BOOST_REQUIRE_MESSAGE( helper.test_state_persist_and_reload_with_checkpt(theDefsFixture.defsfile_), "Fixture failed: " << helper.errorMsg()); +BOOST_AUTO_TEST_CASE(test_state_fixture_defs) { + cout << "AParser:: ...test_state_fixture_defs\n"; + PersistHelper helper; + MyDefsFixture theDefsFixture; + BOOST_REQUIRE_MESSAGE(helper.test_state_persist_and_reload_with_checkpt(theDefsFixture.defsfile_), + "Fixture failed: " << helper.errorMsg()); } BOOST_AUTO_TEST_SUITE_END() - diff --git a/ANode/parser/test/TestParser.cpp b/ANode/parser/test/TestParser.cpp index b3c524974..1b6ac91fa 100644 --- a/ANode/parser/test/TestParser.cpp +++ b/ANode/parser/test/TestParser.cpp @@ -2,230 +2,240 @@ /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 // Name : Request // Author : Avi -// Revision : $Revision$ +// Revision : $Revision$ // // Copyright 2009- ECMWF. -// This software is licensed under the terms of the Apache Licence version 2.0 -// which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. -// In applying this licence, ECMWF does not waive the privileges and immunities -// granted to it by virtue of its status as an intergovernmental organisation -// nor does it submit to any jurisdiction. +// This software is licensed under the terms of the Apache Licence version 2.0 +// which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. +// In applying this licence, ECMWF does not waive the privileges and immunities +// granted to it by virtue of its status as an intergovernmental organisation +// nor does it submit to any jurisdiction. // // Description : //============================================================================ -#include #include +#include -#include #include #include +#include -#include "DefsStructureParser.hpp" #include "Defs.hpp" -#include "PersistHelper.hpp" -#include "File.hpp" +#include "DefsStructureParser.hpp" #include "Ecf.hpp" +#include "File.hpp" #include "Node.hpp" -//#include "PrintStyle.hpp" +#include "PersistHelper.hpp" +// #include "PrintStyle.hpp" namespace fs = boost::filesystem; using namespace std; using namespace ecf; std::vector defs_with_expected_warnings() { - return { "limit/limit3.def" }; + return {"limit/limit3.def"}; } -BOOST_AUTO_TEST_SUITE( ParserTestSuite ) - -void test_defs(const std::string& directory, bool pass) -{ - fs::path full_path( fs::initial_path() ); - full_path = fs::system_complete( fs::path( directory ) ); - - BOOST_CHECK(fs::exists( full_path )); - BOOST_CHECK(fs::is_directory( full_path )); - DebugEquality debug_equality; // only as affect in DEBUG build - - //std::cout << "\nIn directory: " << full_path.directory_string() << "\n\n"; - fs::directory_iterator end_iter; - for ( fs::directory_iterator dir_itr( full_path ); dir_itr != end_iter; ++dir_itr ) - { - try - { - fs::path relPath(directory + "/" + dir_itr->path().filename().string()); - - // recurse down directories - if ( fs::is_directory(dir_itr->status()) ) { - test_defs(relPath.string(),pass); - continue; - } - - //std::cout << "......Parsing file " << relPath.string() << "\n"; - - Defs defs; - DefsStructureParser parser( &defs , relPath.string() ); - - std::string errorMsg,warningMsg; - bool parsedOk = parser.doParse(errorMsg,warningMsg); - if (pass) { - // Test expected to pass - BOOST_CHECK_MESSAGE(parsedOk,"Failed to parse file " << relPath << "\n" << errorMsg); - - if (parsedOk) { - // Check triggers and limits - std::string err_msg,warn_msg; - defs.check(err_msg,warn_msg); - BOOST_CHECK_MESSAGE(err_msg.empty(),"Expected no errors but found:" << err_msg << "File: " << relPath.string()); - - // expect warnings for some file: - bool ignore = false; - for(auto path: defs_with_expected_warnings()) { if (relPath.string().find(path) != std::string::npos) { ignore = true; break; }} - if (!ignore) BOOST_CHECK_MESSAGE(warn_msg.empty(),"Expected no warnings but found:" << warn_msg << "File: " << relPath.string()); - - // Write parsed file to a temporary file on disk, and reload, then compare defs, should be the same - PersistHelper helper; - BOOST_CHECK_MESSAGE( helper.test_persist_and_reload(defs,parser.get_file_type()), relPath.string() << " " << helper.errorMsg()); - BOOST_CHECK_MESSAGE( helper.test_cereal_checkpt_and_reload(defs), relPath.string() << " " << helper.errorMsg()); - - // test copy constructor - Defs copy_of_defs = Defs(defs); - BOOST_CHECK_MESSAGE(copy_of_defs == defs,"Error copy constructor failed " << relPath); - - // Test parse by string is same as parsing by file: - { - std::string contents; - BOOST_CHECK_MESSAGE(File::open(relPath.string(),contents) ,"Error could not open file " << relPath); - // cout << "parsing file " << relPath << " by string\n"; - - Defs defs2; - std::string errorMsg2,warningMsg2; - BOOST_CHECK_MESSAGE(defs2.restore_from_string(contents,errorMsg2,warningMsg2), - "restore from string failed for file " << relPath << "\n" << errorMsg2); - BOOST_CHECK_MESSAGE(defs2 == defs,"Parse by string != parse by filename for file:\n" << relPath); - } - - // Make sure all nodes can be found - std::vector all_nodes; - defs.getAllNodes(all_nodes); - for(auto node : all_nodes) { - node_ptr found_node = defs.findAbsNode(node->absNodePath()); - BOOST_CHECK_MESSAGE(found_node.get(),"Could not find node " << node->debugNodePath()); - BOOST_CHECK_MESSAGE(found_node.get() == node," Expected to find " << node->debugNodePath() << " but found " << found_node->debugNodePath()); - } - } - } - else { - // test expected to fail - if (parsedOk) { - // Check triggers and limits - std::string err_msg,warn_msg; - defs.check(err_msg,warn_msg); - BOOST_CHECK_MESSAGE(!err_msg.empty() || !warn_msg.empty(),"Expected problems with trigger/limits but found none for file" << relPath << "\n" ); - } - else { - BOOST_CHECK_MESSAGE(!parsedOk,"Parse expected to fail for " << relPath << "\n" << errorMsg); - } - } - } - catch ( const std::exception & ex ) - { - std::cout << dir_itr->path().filename() << " " << ex.what() << std::endl; - } - } +BOOST_AUTO_TEST_SUITE(ParserTestSuite) + +void test_defs(const std::string& directory, bool pass) { + fs::path full_path(fs::initial_path()); + full_path = fs::system_complete(fs::path(directory)); + + BOOST_CHECK(fs::exists(full_path)); + BOOST_CHECK(fs::is_directory(full_path)); + DebugEquality debug_equality; // only as affect in DEBUG build + + // std::cout << "\nIn directory: " << full_path.directory_string() << "\n\n"; + fs::directory_iterator end_iter; + for (fs::directory_iterator dir_itr(full_path); dir_itr != end_iter; ++dir_itr) { + try { + fs::path relPath(directory + "/" + dir_itr->path().filename().string()); + + // recurse down directories + if (fs::is_directory(dir_itr->status())) { + test_defs(relPath.string(), pass); + continue; + } + + // std::cout << "......Parsing file " << relPath.string() << "\n"; + + Defs defs; + DefsStructureParser parser(&defs, relPath.string()); + + std::string errorMsg, warningMsg; + bool parsedOk = parser.doParse(errorMsg, warningMsg); + if (pass) { + // Test expected to pass + BOOST_CHECK_MESSAGE(parsedOk, "Failed to parse file " << relPath << "\n" << errorMsg); + + if (parsedOk) { + // Check triggers and limits + std::string err_msg, warn_msg; + defs.check(err_msg, warn_msg); + BOOST_CHECK_MESSAGE(err_msg.empty(), + "Expected no errors but found:" << err_msg << "File: " << relPath.string()); + + // expect warnings for some file: + bool ignore = false; + for (auto path : defs_with_expected_warnings()) { + if (relPath.string().find(path) != std::string::npos) { + ignore = true; + break; + } + } + if (!ignore) + BOOST_CHECK_MESSAGE(warn_msg.empty(), + "Expected no warnings but found:" << warn_msg + << "File: " << relPath.string()); + + // Write parsed file to a temporary file on disk, and reload, then compare defs, should be the same + PersistHelper helper; + BOOST_CHECK_MESSAGE(helper.test_persist_and_reload(defs, parser.get_file_type()), + relPath.string() << " " << helper.errorMsg()); + BOOST_CHECK_MESSAGE(helper.test_cereal_checkpt_and_reload(defs), + relPath.string() << " " << helper.errorMsg()); + + // test copy constructor + Defs copy_of_defs = Defs(defs); + BOOST_CHECK_MESSAGE(copy_of_defs == defs, "Error copy constructor failed " << relPath); + + // Test parse by string is same as parsing by file: + { + std::string contents; + BOOST_CHECK_MESSAGE(File::open(relPath.string(), contents), + "Error could not open file " << relPath); + // cout << "parsing file " << relPath << " by string\n"; + + Defs defs2; + std::string errorMsg2, warningMsg2; + BOOST_CHECK_MESSAGE(defs2.restore_from_string(contents, errorMsg2, warningMsg2), + "restore from string failed for file " << relPath << "\n" + << errorMsg2); + BOOST_CHECK_MESSAGE(defs2 == defs, + "Parse by string != parse by filename for file:\n" + << relPath); + } + + // Make sure all nodes can be found + std::vector all_nodes; + defs.getAllNodes(all_nodes); + for (auto node : all_nodes) { + node_ptr found_node = defs.findAbsNode(node->absNodePath()); + BOOST_CHECK_MESSAGE(found_node.get(), "Could not find node " << node->debugNodePath()); + BOOST_CHECK_MESSAGE(found_node.get() == node, + " Expected to find " << node->debugNodePath() << " but found " + << found_node->debugNodePath()); + } + } + } + else { + // test expected to fail + if (parsedOk) { + // Check triggers and limits + std::string err_msg, warn_msg; + defs.check(err_msg, warn_msg); + BOOST_CHECK_MESSAGE(!err_msg.empty() || !warn_msg.empty(), + "Expected problems with trigger/limits but found none for file" << relPath + << "\n"); + } + else { + BOOST_CHECK_MESSAGE(!parsedOk, "Parse expected to fail for " << relPath << "\n" << errorMsg); + } + } + } + catch (const std::exception& ex) { + std::cout << dir_itr->path().filename() << " " << ex.what() << std::endl; + } + } } -BOOST_AUTO_TEST_CASE( test_parsing_for_good_defs ) -{ - cout << "AParser:: ...test_parsing_for_good_defs\n"; +BOOST_AUTO_TEST_CASE(test_parsing_for_good_defs) { + cout << "AParser:: ...test_parsing_for_good_defs\n"; - std::string path = File::test_data("ANode/parser/test/data/good_defs","parser"); + std::string path = File::test_data("ANode/parser/test/data/good_defs", "parser"); - // All the defs in this directory are expected to pass - test_defs(path, true); + // All the defs in this directory are expected to pass + test_defs(path, true); } -BOOST_AUTO_TEST_CASE( test_parsing_for_bad_defs ) -{ - cout << "AParser:: ...test_parsing_for_bad_defs\n"; +BOOST_AUTO_TEST_CASE(test_parsing_for_bad_defs) { + cout << "AParser:: ...test_parsing_for_bad_defs\n"; - std::string path = File::test_data("ANode/parser/test/data/bad_defs","parser"); + std::string path = File::test_data("ANode/parser/test/data/bad_defs", "parser"); - // All the defs in this directory are expected to fail - test_defs(path, false); + // All the defs in this directory are expected to fail + test_defs(path, false); } -BOOST_AUTO_TEST_CASE( test_parsing_for_good_defs_state ) -{ - cout << "AParser:: ...test_parsing_for_good_defs_state\n"; +BOOST_AUTO_TEST_CASE(test_parsing_for_good_defs_state) { + cout << "AParser:: ...test_parsing_for_good_defs_state\n"; - std::string path = File::test_data("ANode/parser/test/data/good_defs_state","parser"); + std::string path = File::test_data("ANode/parser/test/data/good_defs_state", "parser"); - // All the defs in this directory are expected to pass - test_defs(path, true); + // All the defs in this directory are expected to pass + test_defs(path, true); } -void test_node_defs(const std::string& directory, bool pass) -{ - fs::path full_path( fs::initial_path() ); - full_path = fs::system_complete( fs::path( directory ) ); - - BOOST_CHECK(fs::exists( full_path )); - BOOST_CHECK(fs::is_directory( full_path )); - - //std::cout << "\nIn directory: " << full_path.directory_string() << "\n\n"; - fs::directory_iterator end_iter; - for ( fs::directory_iterator dir_itr( full_path ); dir_itr != end_iter; ++dir_itr ) - { - try - { - fs::path relPath(directory + "/" + dir_itr->path().filename().string()); - - // recurse down directories - if ( fs::is_directory(dir_itr->status()) ) { - test_node_defs(relPath.string(),pass); - continue; - } - - //std::cout << "......Parsing file " << relPath.string() << "\n"; - std::string file_contents; - if (!ecf::File::open( relPath.string(), file_contents )) { - std::cout << "......Could not open file" << relPath.string() << "\n"; - continue; - } - - // Parse string as a standalone node. - DefsStructureParser parser( file_contents ); - std::string errorMsg,warningMsg; - bool parsedOk = parser.doParse(errorMsg,warningMsg); - if (pass) { - // Test expected to pass - BOOST_CHECK_MESSAGE( parsedOk,"Failed to parse file " << relPath << "\n" << errorMsg); - BOOST_CHECK_MESSAGE(parser.the_node_ptr(),"Failed to parse file " << relPath << "\n" << errorMsg); - //PrintStyle print_style(PrintStyle::MIGRATE); - //parser.the_node_ptr()->print(cout); - } - else { - // test expected to fail - //std::cout << errorMsg << "\n"; - BOOST_CHECK_MESSAGE(!parser.the_node_ptr(),"Parse expected to fail for " << relPath << "\n" << errorMsg); - } - } - catch ( const std::exception & ex ) { - std::cout << dir_itr->path().filename() << " " << ex.what() << std::endl; - } - } +void test_node_defs(const std::string& directory, bool pass) { + fs::path full_path(fs::initial_path()); + full_path = fs::system_complete(fs::path(directory)); + + BOOST_CHECK(fs::exists(full_path)); + BOOST_CHECK(fs::is_directory(full_path)); + + // std::cout << "\nIn directory: " << full_path.directory_string() << "\n\n"; + fs::directory_iterator end_iter; + for (fs::directory_iterator dir_itr(full_path); dir_itr != end_iter; ++dir_itr) { + try { + fs::path relPath(directory + "/" + dir_itr->path().filename().string()); + + // recurse down directories + if (fs::is_directory(dir_itr->status())) { + test_node_defs(relPath.string(), pass); + continue; + } + + // std::cout << "......Parsing file " << relPath.string() << "\n"; + std::string file_contents; + if (!ecf::File::open(relPath.string(), file_contents)) { + std::cout << "......Could not open file" << relPath.string() << "\n"; + continue; + } + + // Parse string as a standalone node. + DefsStructureParser parser(file_contents); + std::string errorMsg, warningMsg; + bool parsedOk = parser.doParse(errorMsg, warningMsg); + if (pass) { + // Test expected to pass + BOOST_CHECK_MESSAGE(parsedOk, "Failed to parse file " << relPath << "\n" << errorMsg); + BOOST_CHECK_MESSAGE(parser.the_node_ptr(), "Failed to parse file " << relPath << "\n" << errorMsg); + // PrintStyle print_style(PrintStyle::MIGRATE); + // parser.the_node_ptr()->print(cout); + } + else { + // test expected to fail + // std::cout << errorMsg << "\n"; + BOOST_CHECK_MESSAGE(!parser.the_node_ptr(), + "Parse expected to fail for " << relPath << "\n" + << errorMsg); + } + } + catch (const std::exception& ex) { + std::cout << dir_itr->path().filename() << " " << ex.what() << std::endl; + } + } } -BOOST_AUTO_TEST_CASE( test_parsing_node ) -{ - cout << "AParser:: ...test_parsing_node\n"; +BOOST_AUTO_TEST_CASE(test_parsing_node) { + cout << "AParser:: ...test_parsing_node\n"; - std::string path = File::test_data("ANode/parser/test/data/good_node_defs","parser"); + std::string path = File::test_data("ANode/parser/test/data/good_node_defs", "parser"); - // All the defs in this directory are expected to pass - test_node_defs(path, true); + // All the defs in this directory are expected to pass + test_node_defs(path, true); } BOOST_AUTO_TEST_SUITE_END() diff --git a/ANode/parser/test/TestSingleDefsFile.cpp b/ANode/parser/test/TestSingleDefsFile.cpp index 5f934c682..532fe24c9 100644 --- a/ANode/parser/test/TestSingleDefsFile.cpp +++ b/ANode/parser/test/TestSingleDefsFile.cpp @@ -3,296 +3,339 @@ //============================================================================ // Name : // Author : Avi -// Revision : $Revision$ +// Revision : $Revision$ // // Copyright 2009- ECMWF. -// This software is licensed under the terms of the Apache Licence version 2.0 -// which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. -// In applying this licence, ECMWF does not waive the privileges and immunities -// granted to it by virtue of its status as an intergovernmental organisation -// nor does it submit to any jurisdiction. +// This software is licensed under the terms of the Apache Licence version 2.0 +// which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. +// In applying this licence, ECMWF does not waive the privileges and immunities +// granted to it by virtue of its status as an intergovernmental organisation +// nor does it submit to any jurisdiction. // // Description : //============================================================================ -#include -#include #include +#include +#include -#include -#include -#include #include #include +#include +#include #include +#include -#include "DefsStructureParser.hpp" #include "Defs.hpp" -#include "NodeContainer.hpp" -#include "Suite.hpp" -#include "Task.hpp" +#include "DefsStructureParser.hpp" #include "Family.hpp" -#include "PrintStyle.hpp" -#include "PersistHelper.hpp" -#include "JobsParam.hpp" +#include "File.hpp" #include "Jobs.hpp" +#include "JobsParam.hpp" #include "Log.hpp" -#include "System.hpp" -#include "File.hpp" +#include "NodeContainer.hpp" +#include "PersistHelper.hpp" +#include "PrintStyle.hpp" #include "Str.hpp" +#include "Suite.hpp" +#include "System.hpp" +#include "Task.hpp" namespace fs = boost::filesystem; using namespace std; using namespace ecf; using namespace boost::posix_time; -BOOST_AUTO_TEST_SUITE( ParserTestSuite ) +BOOST_AUTO_TEST_SUITE(ParserTestSuite) // This test is used to find a task given a path of the form: // suite/family/task // suite/family/family/task -void test_find_task_using_path( NodeContainer* f,const Defs& defs ) -{ - BOOST_CHECK_MESSAGE(f == defs.findAbsNode(f->absNodePath()).get(), "Could not find path " << f->absNodePath() << "\n"); +void test_find_task_using_path(NodeContainer* f, const Defs& defs) { + BOOST_CHECK_MESSAGE(f == defs.findAbsNode(f->absNodePath()).get(), + "Could not find path " << f->absNodePath() << "\n"); - for(node_ptr t: f->nodeVec()) { - BOOST_CHECK_MESSAGE(t.get() == defs.findAbsNode(t->absNodePath()).get(), "Could not find path " << t->absNodePath() << "\n"); - Family* family = t->isFamily(); - if (family) { - test_find_task_using_path(family, defs); - } - } + for (node_ptr t : f->nodeVec()) { + BOOST_CHECK_MESSAGE(t.get() == defs.findAbsNode(t->absNodePath()).get(), + "Could not find path " << t->absNodePath() << "\n"); + Family* family = t->isFamily(); + if (family) { + test_find_task_using_path(family, defs); + } + } } // Create derived class, so that we can time the parse only // i.e ignore expression build/checking and limit checking class TestDefsStructureParser : public DefsStructureParser { public: - TestDefsStructureParser(Defs* defsfile, const std::string& file_name) : DefsStructureParser(defsfile,file_name) {} - bool do_parse_file(std::string& errorMsg) { return DefsStructureParser::do_parse_file(errorMsg); } + TestDefsStructureParser(Defs* defsfile, const std::string& file_name) : DefsStructureParser(defsfile, file_name) {} + bool do_parse_file(std::string& errorMsg) { return DefsStructureParser::do_parse_file(errorMsg); } }; -double get_seconds( const boost::timer::nanosecond_type& elapsed ) -{ - return static_cast( - boost::chrono::nanoseconds( elapsed ).count() - ) * boost::chrono::nanoseconds::period::num / boost::chrono::nanoseconds::period::den; +double get_seconds(const boost::timer::nanosecond_type& elapsed) { + return static_cast(boost::chrono::nanoseconds(elapsed).count()) * boost::chrono::nanoseconds::period::num / + boost::chrono::nanoseconds::period::den; } +BOOST_AUTO_TEST_CASE(test_single_defs) { + boost::timer::auto_cpu_timer auto_cpu_timer; -BOOST_AUTO_TEST_CASE( test_single_defs ) -{ - boost::timer::auto_cpu_timer auto_cpu_timer; - - std::string path = File::test_data("ANode/parser/test/data/single_defs/mega.def","parser"); - size_t mega_file_size = fs::file_size(path); - cout << "AParser:: ...test_single_defs " << path << " file_size(" << mega_file_size << ")\n"; + std::string path = File::test_data("ANode/parser/test/data/single_defs/mega.def", "parser"); + size_t mega_file_size = fs::file_size(path); + cout << "AParser:: ...test_single_defs " << path << " file_size(" << mega_file_size << ")\n"; - // Time parse/resolve dependencies: This will need to be #defined depending on the platform - // Change for file_iterator to plain string halved the time taken to load operation suite - boost::timer::cpu_timer timer; + // Time parse/resolve dependencies: This will need to be #defined depending on the platform + // Change for file_iterator to plain string halved the time taken to load operation suite + boost::timer::cpu_timer timer; #ifdef DEBUG -#if defined(HPUX) || defined(_AIX) - double expectedTimeForParse = 15.0; - double expectedTimeForParseOnly = 10.0; - double expectedTimeForResolveDependencies = 3.5; // this is time for 10 job submissions - double checkExprAndLimits = 1.0; - double expectedTimeForFindAllPaths = 7.2; - double expectedTimeForDefsPersistOnly = 6 ; - double expectedTimeForDefsPersistAndReload = 24; - double expectedTimeForCheckPtPersistAndReload = 27; + #if defined(HPUX) || defined(_AIX) + double expectedTimeForParse = 15.0; + double expectedTimeForParseOnly = 10.0; + double expectedTimeForResolveDependencies = 3.5; // this is time for 10 job submissions + double checkExprAndLimits = 1.0; + double expectedTimeForFindAllPaths = 7.2; + double expectedTimeForDefsPersistOnly = 6; + double expectedTimeForDefsPersistAndReload = 24; + double expectedTimeForCheckPtPersistAndReload = 27; + #else + double expectedTimeForParse = 4.5; + double expectedTimeForParseOnly = 2.0; + double expectedTimeForResolveDependencies = 0.5; // this is time for 10 job submissions + double checkExprAndLimits = 0.5; + double expectedTimeForFindAllPaths = 1.2; + double expectedTimeForDefsPersistOnly = 2; + double expectedTimeForDefsPersistAndReload = 4.5; + double expectedTimeForCheckPtPersistAndReload = 8.0; + #endif #else - double expectedTimeForParse = 4.5; - double expectedTimeForParseOnly = 2.0; - double expectedTimeForResolveDependencies = 0.5 ; // this is time for 10 job submissions - double checkExprAndLimits = 0.5; - double expectedTimeForFindAllPaths = 1.2; - double expectedTimeForDefsPersistOnly = 2 ; - double expectedTimeForDefsPersistAndReload = 4.5; - double expectedTimeForCheckPtPersistAndReload = 8.0; -#endif -#else -#if defined(HPUX) || defined(_AIX) - double expectedTimeForParse = 7.8; - double expectedTimeForParseOnly = 5.0; - double expectedTimeForResolveDependencies = 3.5; // this is time for 10 job submissions - double checkExprAndLimits = 1.0; - double expectedTimeForFindAllPaths = 4.5; - double expectedTimeForDefsPersistOnly = 3.5 ; - double expectedTimeForDefsPersistAndReload = 9.5; - double expectedTimeForCheckPtPersistAndReload = 11.5; -#else - double expectedTimeForParse = 1.2; - double expectedTimeForParseOnly = 0.6; - double expectedTimeForResolveDependencies = 0.2 ; // this is time for 10 job submissions - double checkExprAndLimits = 0.1; - double expectedTimeForFindAllPaths = 0.58; - double expectedTimeForDefsPersistOnly = 0.4 ; - double expectedTimeForDefsPersistAndReload = 1.4; - double expectedTimeForCheckPtPersistAndReload = 1.6; -#endif + #if defined(HPUX) || defined(_AIX) + double expectedTimeForParse = 7.8; + double expectedTimeForParseOnly = 5.0; + double expectedTimeForResolveDependencies = 3.5; // this is time for 10 job submissions + double checkExprAndLimits = 1.0; + double expectedTimeForFindAllPaths = 4.5; + double expectedTimeForDefsPersistOnly = 3.5; + double expectedTimeForDefsPersistAndReload = 9.5; + double expectedTimeForCheckPtPersistAndReload = 11.5; + #else + double expectedTimeForParse = 1.2; + double expectedTimeForParseOnly = 0.6; + double expectedTimeForResolveDependencies = 0.2; // this is time for 10 job submissions + double checkExprAndLimits = 0.1; + double expectedTimeForFindAllPaths = 0.58; + double expectedTimeForDefsPersistOnly = 0.4; + double expectedTimeForDefsPersistAndReload = 1.4; + double expectedTimeForCheckPtPersistAndReload = 1.6; + #endif #endif - // **************************************************************************************** - // Please note: that for Parsing: that the predominate time is taken in creating the AST/ and checking + // **************************************************************************************** + // Please note: that for Parsing: that the predominate time is taken in creating the AST/ and checking - /// If this is moved below, we get some caching affect, with the persist and reload timing - Defs defs; - { - timer.start(); - std::string errorMsg,warningMsg; - BOOST_REQUIRE_MESSAGE(defs.restore(path,errorMsg,warningMsg),errorMsg); - BOOST_CHECK_MESSAGE(get_seconds(timer.elapsed().user) < expectedTimeForParse,"Performance regression, expected < " << expectedTimeForParse << " seconds for parse/node tree creation but found " << timer.format(3,Str::cpu_timer_format())); - cout << " Parsing Node tree and AST creation time = " - << timer.format(3,Str::cpu_timer_format()) << " < limit(" << expectedTimeForParse << ")" << endl; - } - { - Defs local_defs; - timer.start(); - TestDefsStructureParser checkPtParser( &local_defs, path); - std::string errorMsg; - BOOST_REQUIRE_MESSAGE(checkPtParser.do_parse_file(errorMsg),errorMsg); - BOOST_CHECK_MESSAGE(get_seconds(timer.elapsed().user) < expectedTimeForParse,"Performance regression, expected < " << expectedTimeForParseOnly << " seconds for parse/node tree creation but found " << timer.format(3,Str::cpu_timer_format())); - cout << " Parsing Node tree *only* time = " - << timer.format(3,Str::cpu_timer_format()) << " < limit(" << expectedTimeForParseOnly << ")" << endl; - } - { - timer.start(); - for(suite_ptr s: defs.suiteVec()) { test_find_task_using_path(s.get(),defs); } - BOOST_CHECK_MESSAGE(get_seconds(timer.elapsed().user) < expectedTimeForFindAllPaths,"Performance regression, expected < " << expectedTimeForFindAllPaths << " seconds to find all paths, but found " << timer.format(3,Str::cpu_timer_format())); - cout << " Test all paths can be found. time taken = " - << timer.format(3,Str::cpu_timer_format()) << " < limit(" << expectedTimeForFindAllPaths << ")" << endl; - } + /// If this is moved below, we get some caching affect, with the persist and reload timing + Defs defs; + { + timer.start(); + std::string errorMsg, warningMsg; + BOOST_REQUIRE_MESSAGE(defs.restore(path, errorMsg, warningMsg), errorMsg); + BOOST_CHECK_MESSAGE(get_seconds(timer.elapsed().user) < expectedTimeForParse, + "Performance regression, expected < " << expectedTimeForParse + << " seconds for parse/node tree creation but found " + << timer.format(3, Str::cpu_timer_format())); + cout << " Parsing Node tree and AST creation time = " << timer.format(3, Str::cpu_timer_format()) + << " < limit(" << expectedTimeForParse << ")" << endl; + } + { + Defs local_defs; + timer.start(); + TestDefsStructureParser checkPtParser(&local_defs, path); + std::string errorMsg; + BOOST_REQUIRE_MESSAGE(checkPtParser.do_parse_file(errorMsg), errorMsg); + BOOST_CHECK_MESSAGE(get_seconds(timer.elapsed().user) < expectedTimeForParse, + "Performance regression, expected < " << expectedTimeForParseOnly + << " seconds for parse/node tree creation but found " + << timer.format(3, Str::cpu_timer_format())); + cout << " Parsing Node tree *only* time = " << timer.format(3, Str::cpu_timer_format()) + << " < limit(" << expectedTimeForParseOnly << ")" << endl; + } + { + timer.start(); + for (suite_ptr s : defs.suiteVec()) { + test_find_task_using_path(s.get(), defs); + } + BOOST_CHECK_MESSAGE(get_seconds(timer.elapsed().user) < expectedTimeForFindAllPaths, + "Performance regression, expected < " << expectedTimeForFindAllPaths + << " seconds to find all paths, but found " + << timer.format(3, Str::cpu_timer_format())); + cout << " Test all paths can be found. time taken = " << timer.format(3, Str::cpu_timer_format()) + << " < limit(" << expectedTimeForFindAllPaths << ")" << endl; + } - { - // Test time for persisting to defs file only + { + // Test time for persisting to defs file only #ifdef DEBUG - std::string tmpFilename = "tmp_d.def"; + std::string tmpFilename = "tmp_d.def"; #else - std::string tmpFilename = "tmp.def"; + std::string tmpFilename = "tmp.def"; #endif - timer.start(); - PrintStyle style(PrintStyle::DEFS); - std::ofstream ofs( tmpFilename.c_str() ); ofs << defs; - BOOST_CHECK_MESSAGE(get_seconds(timer.elapsed().user) < expectedTimeForDefsPersistOnly,"Performance regression, expected < " << expectedTimeForDefsPersistOnly << " to persist defs file, but found " << timer.format(3,Str::cpu_timer_format())); - cout << " Persist only, time taken = " << timer.format(3,Str::cpu_timer_format()) << " < limit(" << expectedTimeForDefsPersistOnly << ")" << endl; + timer.start(); + PrintStyle style(PrintStyle::DEFS); + std::ofstream ofs(tmpFilename.c_str()); + ofs << defs; + BOOST_CHECK_MESSAGE(get_seconds(timer.elapsed().user) < expectedTimeForDefsPersistOnly, + "Performance regression, expected < " << expectedTimeForDefsPersistOnly + << " to persist defs file, but found " + << timer.format(3, Str::cpu_timer_format())); + cout << " Persist only, time taken = " << timer.format(3, Str::cpu_timer_format()) + << " < limit(" << expectedTimeForDefsPersistOnly << ")" << endl; - std::remove(tmpFilename.c_str()); - } + std::remove(tmpFilename.c_str()); + } - { - // may need to comment out output for large differences. Will double the time. - timer.start(); - PersistHelper helper; - BOOST_CHECK_MESSAGE( helper.test_persist_and_reload(defs,PrintStyle::DEFS), helper.errorMsg()); - BOOST_CHECK_MESSAGE(get_seconds(timer.elapsed().user) < expectedTimeForDefsPersistAndReload,"Performance regression, expected < " << expectedTimeForDefsPersistAndReload << " seconds to persist and reload, but found " << timer.format(3,Str::cpu_timer_format())); - cout << " Persist and reload(DEFS) and compare, time taken = " - << timer.format(3,Str::cpu_timer_format()) << " < limit(" << expectedTimeForDefsPersistAndReload << ")" - << " file_size(" << helper.file_size() << ")" << endl; - } - { - timer.start(); - PersistHelper helper; - BOOST_CHECK_MESSAGE( helper.test_persist_and_reload(defs,PrintStyle::STATE), helper.errorMsg()); - cout << " Persist and reload(STATE) and compare, time taken = " << timer.format(3,Str::cpu_timer_format()) - << " file_size(" << helper.file_size() << ")" << endl; - } - { - timer.start(); - PersistHelper helper; - BOOST_CHECK_MESSAGE( helper.test_persist_and_reload(defs,PrintStyle::MIGRATE), helper.errorMsg()); - BOOST_CHECK_MESSAGE(get_seconds(timer.elapsed().user) < expectedTimeForDefsPersistAndReload,"Performance regression, expected < " << expectedTimeForDefsPersistAndReload << " seconds to persist and reload *state*, but found " << timer.format(3,Str::cpu_timer_format())); - cout << " Persist and reload(MIGRATE) and compare, time taken = " - << timer.format(3,Str::cpu_timer_format()) << " < limit(" << expectedTimeForDefsPersistAndReload << ")" - << " file_size(" << helper.file_size() << ")" << endl; + { + // may need to comment out output for large differences. Will double the time. + timer.start(); + PersistHelper helper; + BOOST_CHECK_MESSAGE(helper.test_persist_and_reload(defs, PrintStyle::DEFS), helper.errorMsg()); + BOOST_CHECK_MESSAGE(get_seconds(timer.elapsed().user) < expectedTimeForDefsPersistAndReload, + "Performance regression, expected < " << expectedTimeForDefsPersistAndReload + << " seconds to persist and reload, but found " + << timer.format(3, Str::cpu_timer_format())); + cout << " Persist and reload(DEFS) and compare, time taken = " << timer.format(3, Str::cpu_timer_format()) + << " < limit(" << expectedTimeForDefsPersistAndReload << ")" + << " file_size(" << helper.file_size() << ")" << endl; + } + { + timer.start(); + PersistHelper helper; + BOOST_CHECK_MESSAGE(helper.test_persist_and_reload(defs, PrintStyle::STATE), helper.errorMsg()); + cout << " Persist and reload(STATE) and compare, time taken = " << timer.format(3, Str::cpu_timer_format()) + << " file_size(" << helper.file_size() << ")" << endl; + } + { + timer.start(); + PersistHelper helper; + BOOST_CHECK_MESSAGE(helper.test_persist_and_reload(defs, PrintStyle::MIGRATE), helper.errorMsg()); + BOOST_CHECK_MESSAGE(get_seconds(timer.elapsed().user) < expectedTimeForDefsPersistAndReload, + "Performance regression, expected < " + << expectedTimeForDefsPersistAndReload + << " seconds to persist and reload *state*, but found " + << timer.format(3, Str::cpu_timer_format())); + cout << " Persist and reload(MIGRATE) and compare, time taken = " << timer.format(3, Str::cpu_timer_format()) + << " < limit(" << expectedTimeForDefsPersistAndReload << ")" + << " file_size(" << helper.file_size() << ")" << endl; - // each platform will have a slightly different size, since the server environment variables - // will be different, i.e host, pid, i.e check point etc, encompasses the host name, which will be different - BOOST_CHECK_MESSAGE(helper.file_size() <= 6679000 ,"File size regression expected <= 6679000 but found " << helper.file_size()); - } - { - timer.start(); - PersistHelper helper; - BOOST_CHECK_MESSAGE( helper.test_persist_and_reload(defs,PrintStyle::NET), helper.errorMsg()); - BOOST_CHECK_MESSAGE(get_seconds(timer.elapsed().user) < expectedTimeForDefsPersistAndReload,"Performance regression, expected < " << expectedTimeForDefsPersistAndReload << " seconds to persist and reload *state*, but found " << timer.format(3,Str::cpu_timer_format())); - cout << " Persist and reload(NET) and compare, time taken = " - << timer.format(3,Str::cpu_timer_format()) << " < limit(" << expectedTimeForDefsPersistAndReload << ")" - << " file_size(" << helper.file_size() << ")" << endl; + // each platform will have a slightly different size, since the server environment variables + // will be different, i.e host, pid, i.e check point etc, encompasses the host name, which will be different + BOOST_CHECK_MESSAGE(helper.file_size() <= 6679000, + "File size regression expected <= 6679000 but found " << helper.file_size()); + } + { + timer.start(); + PersistHelper helper; + BOOST_CHECK_MESSAGE(helper.test_persist_and_reload(defs, PrintStyle::NET), helper.errorMsg()); + BOOST_CHECK_MESSAGE(get_seconds(timer.elapsed().user) < expectedTimeForDefsPersistAndReload, + "Performance regression, expected < " + << expectedTimeForDefsPersistAndReload + << " seconds to persist and reload *state*, but found " + << timer.format(3, Str::cpu_timer_format())); + cout << " Persist and reload(NET) and compare, time taken = " << timer.format(3, Str::cpu_timer_format()) + << " < limit(" << expectedTimeForDefsPersistAndReload << ")" + << " file_size(" << helper.file_size() << ")" << endl; - // each platform will have a slightly different size, since the server environment variables - // will be different, i.e host, pid, i.e check point etc, encompasses the host name, which will be different - BOOST_CHECK_MESSAGE(helper.file_size() <= 6679000 ,"File size regression expected <= 6679000 but found " << helper.file_size()); - } + // each platform will have a slightly different size, since the server environment variables + // will be different, i.e host, pid, i.e check point etc, encompasses the host name, which will be different + BOOST_CHECK_MESSAGE(helper.file_size() <= 6679000, + "File size regression expected <= 6679000 but found " << helper.file_size()); + } - { - timer.start(); - PersistHelper helper; - BOOST_CHECK_MESSAGE( helper.test_cereal_checkpt_and_reload(defs,true), helper.errorMsg()); - BOOST_CHECK_MESSAGE(get_seconds(timer.elapsed().user) < expectedTimeForCheckPtPersistAndReload,"Performance regression, expected < " << expectedTimeForCheckPtPersistAndReload << " seconds to persist and reload, but found " << timer.format(3,Str::cpu_timer_format())); - cout << " Checkpt(CEREAL) and reload and compare, time taken = "; - cout << timer.format(3,Str::cpu_timer_format()) << " < limit(" << expectedTimeForCheckPtPersistAndReload << ")" << " file_size(" << helper.file_size() << ")" << endl; - } + { + timer.start(); + PersistHelper helper; + BOOST_CHECK_MESSAGE(helper.test_cereal_checkpt_and_reload(defs, true), helper.errorMsg()); + BOOST_CHECK_MESSAGE(get_seconds(timer.elapsed().user) < expectedTimeForCheckPtPersistAndReload, + "Performance regression, expected < " << expectedTimeForCheckPtPersistAndReload + << " seconds to persist and reload, but found " + << timer.format(3, Str::cpu_timer_format())); + cout << " Checkpt(CEREAL) and reload and compare, time taken = "; + cout << timer.format(3, Str::cpu_timer_format()) << " < limit(" << expectedTimeForCheckPtPersistAndReload << ")" + << " file_size(" << helper.file_size() << ")" << endl; + } - { - // Time how long it takes for job submission. Must call begin on all suites first. - timer.start(); - defs.beginAll(); - int count = 10; - JobsParam jobsParam; // default is *not* to create jobs, and *not* to spawn jobs, hence only used in testing - Jobs jobs(&defs); - for (int i = 0; i < count; i++) {jobs.generate(jobsParam);} - cout << " " << count << " jobSubmissions = " - << timer.format(3,Str::cpu_timer_format()) << "s jobs:" << jobsParam.submitted().size() << " < limit(" << expectedTimeForResolveDependencies << ")" << endl; - BOOST_CHECK_MESSAGE(get_seconds(timer.elapsed().user) < expectedTimeForResolveDependencies, - "jobSubmission Performance regression, expected < " << expectedTimeForResolveDependencies << " seconds for resolving dependencies but found " << timer.format(3,Str::cpu_timer_format()) ); - } + { + // Time how long it takes for job submission. Must call begin on all suites first. + timer.start(); + defs.beginAll(); + int count = 10; + JobsParam jobsParam; // default is *not* to create jobs, and *not* to spawn jobs, hence only used in testing + Jobs jobs(&defs); + for (int i = 0; i < count; i++) { + jobs.generate(jobsParam); + } + cout << " " << count + << " jobSubmissions = " << timer.format(3, Str::cpu_timer_format()) + << "s jobs:" << jobsParam.submitted().size() << " < limit(" << expectedTimeForResolveDependencies << ")" + << endl; + BOOST_CHECK_MESSAGE(get_seconds(timer.elapsed().user) < expectedTimeForResolveDependencies, + "jobSubmission Performance regression, expected < " + << expectedTimeForResolveDependencies + << " seconds for resolving dependencies but found " + << timer.format(3, Str::cpu_timer_format())); + } - { - // Time how long it takes for post process - timer.start(); - string errorMsg,warningMsg; - BOOST_CHECK(defs.check(errorMsg,warningMsg)); - cout << " Defs::check (inlimit resolution) = " - << timer.format(3,Str::cpu_timer_format()) << " < limit(" << checkExprAndLimits << ")" << endl; - BOOST_CHECK_MESSAGE(get_seconds(timer.elapsed().user) < checkExprAndLimits, - "Defs::check Performance regression, expected < " << checkExprAndLimits << " seconds for resolving dependencies but found " << timer.format(3,Str::cpu_timer_format()) ); - } + { + // Time how long it takes for post process + timer.start(); + string errorMsg, warningMsg; + BOOST_CHECK(defs.check(errorMsg, warningMsg)); + cout << " Defs::check (inlimit resolution) = " << timer.format(3, Str::cpu_timer_format()) + << " < limit(" << checkExprAndLimits << ")" << endl; + BOOST_CHECK_MESSAGE(get_seconds(timer.elapsed().user) < checkExprAndLimits, + "Defs::check Performance regression, expected < " + << checkExprAndLimits << " seconds for resolving dependencies but found " + << timer.format(3, Str::cpu_timer_format())); + } - { - // Time how long it takes to delete all nodes/ references. Delete all tasks and then suites/families. - timer.start(); - std::vector tasks; - defs.getAllTasks(tasks); - BOOST_CHECK_MESSAGE( tasks.size() > 0,"Expected > 0 tasks but found " << tasks.size()); - for(Task* t: tasks) { - BOOST_REQUIRE_MESSAGE(defs.deleteChild(t)," Failed to delete task"); - } - tasks.clear(); defs.getAllTasks(tasks); - BOOST_REQUIRE_MESSAGE( tasks.empty(),"Expected all tasks to be deleted but found " << tasks.size()); + { + // Time how long it takes to delete all nodes/ references. Delete all tasks and then suites/families. + timer.start(); + std::vector tasks; + defs.getAllTasks(tasks); + BOOST_CHECK_MESSAGE(tasks.size() > 0, "Expected > 0 tasks but found " << tasks.size()); + for (Task* t : tasks) { + BOOST_REQUIRE_MESSAGE(defs.deleteChild(t), " Failed to delete task"); + } + tasks.clear(); + defs.getAllTasks(tasks); + BOOST_REQUIRE_MESSAGE(tasks.empty(), "Expected all tasks to be deleted but found " << tasks.size()); - std::vector vec = defs.suiteVec(); // make a copy, to avoid invalidating iterators - BOOST_CHECK_MESSAGE( vec.size() > 0,"Expected > 0 Suites but found " << vec.size()); - for(suite_ptr s: vec) { - std::vector familyVec = s->nodeVec(); // make a copy, to avoid invalidating iterators - for(node_ptr f: familyVec) { - BOOST_REQUIRE_MESSAGE(defs.deleteChild(f.get())," Failed to delete family"); - } - BOOST_REQUIRE_MESSAGE( s->nodeVec().empty(),"Expected all Families to be deleted but found " << s->nodeVec().size()); - BOOST_REQUIRE_MESSAGE(defs.deleteChild(s.get())," Failed to delete suite"); - } - BOOST_REQUIRE_MESSAGE( defs.suiteVec().empty(),"Expected all Suites to be deleted but found " << defs.suiteVec().size()); + std::vector vec = defs.suiteVec(); // make a copy, to avoid invalidating iterators + BOOST_CHECK_MESSAGE(vec.size() > 0, "Expected > 0 Suites but found " << vec.size()); + for (suite_ptr s : vec) { + std::vector familyVec = s->nodeVec(); // make a copy, to avoid invalidating iterators + for (node_ptr f : familyVec) { + BOOST_REQUIRE_MESSAGE(defs.deleteChild(f.get()), " Failed to delete family"); + } + BOOST_REQUIRE_MESSAGE(s->nodeVec().empty(), + "Expected all Families to be deleted but found " << s->nodeVec().size()); + BOOST_REQUIRE_MESSAGE(defs.deleteChild(s.get()), " Failed to delete suite"); + } + BOOST_REQUIRE_MESSAGE(defs.suiteVec().empty(), + "Expected all Suites to be deleted but found " << defs.suiteVec().size()); - cout << " time for deleting all nodes = " << timer.format(3,Str::cpu_timer_format()) << endl; - } + cout << " time for deleting all nodes = " << timer.format(3, Str::cpu_timer_format()) + << endl; + } - // Explicitly destroy, To keep valgrind happy - Log::destroy(); - System::destroy(); + // Explicitly destroy, To keep valgrind happy + Log::destroy(); + System::destroy(); - // cout << "Printing Defs \n"; - // PrintStyle style(PrintStyle::DEFS); - // std::cout << defs; + // cout << "Printing Defs \n"; + // PrintStyle style(PrintStyle::DEFS); + // std::cout << defs; } BOOST_AUTO_TEST_SUITE_END() diff --git a/ANode/parser/test/TestVariableParsing.cpp b/ANode/parser/test/TestVariableParsing.cpp index 10218079b..904eb08e2 100644 --- a/ANode/parser/test/TestVariableParsing.cpp +++ b/ANode/parser/test/TestVariableParsing.cpp @@ -1,75 +1,75 @@ - //============================================================================ +//============================================================================ // Name : // Author : Avi -// Revision : $Revision$ +// Revision : $Revision$ // // Copyright 2009- ECMWF. -// This software is licensed under the terms of the Apache Licence version 2.0 -// which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. -// In applying this licence, ECMWF does not waive the privileges and immunities -// granted to it by virtue of its status as an intergovernmental organisation -// nor does it submit to any jurisdiction. +// This software is licensed under the terms of the Apache Licence version 2.0 +// which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. +// In applying this licence, ECMWF does not waive the privileges and immunities +// granted to it by virtue of its status as an intergovernmental organisation +// nor does it submit to any jurisdiction. // // Description : //============================================================================ -#include #include +#include #include #include "Defs.hpp" -#include "Suite.hpp" #include "File.hpp" +#include "Suite.hpp" using namespace std; using namespace ecf; -BOOST_AUTO_TEST_SUITE( ParserTestSuite ) +BOOST_AUTO_TEST_SUITE(ParserTestSuite) -BOOST_AUTO_TEST_CASE( test_single_defs ) { +BOOST_AUTO_TEST_CASE(test_single_defs) { - cout << "AParser:: ...test_variable \n"; + cout << "AParser:: ...test_variable \n"; - std::string path = File::test_data("ANode/parser/test/data/good_defs/edit/edit.def","parser"); + std::string path = File::test_data("ANode/parser/test/data/good_defs/edit/edit.def", "parser"); - Defs defs; - std::string errorMsg,warningMsg; - BOOST_REQUIRE_MESSAGE(defs.restore(path,errorMsg,warningMsg),errorMsg); + Defs defs; + std::string errorMsg, warningMsg; + BOOST_REQUIRE_MESSAGE(defs.restore(path, errorMsg, warningMsg), errorMsg); -// suite edit -// edit ECF_INCLUDE /home/ma/map/sms/example/x # comment line -// edit ECF_FILES /home/ma/map/sms/example/x #comment line -// edit EXPVER 'f8na' # -// edit USER 'ecgems' #comment -// edit USER2 "ecgems" # comment -// edit INT1 "10" # comment -// edit INT2 '11' # comment -// edit YMD '20091012' # comment -// family family -// edit var "smsfetch -F %ECF_FILES% -I %ECF_INCLUDE%" # comment line -// edit var2 'smsfetch -F %ECF_FILES% -I %ECF_INCLUDE%' #comment line -// task t2 -// endfamily -// endsuite - suite_ptr editSuite = defs.findSuite("edit"); - BOOST_REQUIRE_MESSAGE(editSuite,"Could not find the edit suite"); + // suite edit + // edit ECF_INCLUDE /home/ma/map/sms/example/x # comment line + // edit ECF_FILES /home/ma/map/sms/example/x #comment line + // edit EXPVER 'f8na' # + // edit USER 'ecgems' #comment + // edit USER2 "ecgems" # comment + // edit INT1 "10" # comment + // edit INT2 '11' # comment + // edit YMD '20091012' # comment + // family family + // edit var "smsfetch -F %ECF_FILES% -I %ECF_INCLUDE%" # comment line + // edit var2 'smsfetch -F %ECF_FILES% -I %ECF_INCLUDE%' #comment line + // task t2 + // endfamily + // endsuite + suite_ptr editSuite = defs.findSuite("edit"); + BOOST_REQUIRE_MESSAGE(editSuite, "Could not find the edit suite"); - const Variable& int1 = editSuite->findVariable("INT1"); - BOOST_REQUIRE_MESSAGE(!int1.empty(),"Could not find variable INT1"); - BOOST_REQUIRE_MESSAGE(int1.value() == 10,"Expected INT1 to have a value of 10, but found " << int1.value()); + const Variable& int1 = editSuite->findVariable("INT1"); + BOOST_REQUIRE_MESSAGE(!int1.empty(), "Could not find variable INT1"); + BOOST_REQUIRE_MESSAGE(int1.value() == 10, "Expected INT1 to have a value of 10, but found " << int1.value()); - const Variable& int2 = editSuite->findVariable("INT2"); - BOOST_REQUIRE_MESSAGE(!int2.empty(),"Could not find variable INT2"); - BOOST_REQUIRE_MESSAGE(int2.value() == 11,"Expected INT2 to have a value of 11, but found " << int2.value()); + const Variable& int2 = editSuite->findVariable("INT2"); + BOOST_REQUIRE_MESSAGE(!int2.empty(), "Could not find variable INT2"); + BOOST_REQUIRE_MESSAGE(int2.value() == 11, "Expected INT2 to have a value of 11, but found " << int2.value()); - const Variable& ymd = editSuite->findVariable("YMD"); - BOOST_REQUIRE_MESSAGE(!ymd.empty(),"Could not find variable YMD"); - BOOST_REQUIRE_MESSAGE(ymd.value() == 20091012,"Expected YMD to have a value of 20091012, but found " << ymd.value()); + const Variable& ymd = editSuite->findVariable("YMD"); + BOOST_REQUIRE_MESSAGE(!ymd.empty(), "Could not find variable YMD"); + BOOST_REQUIRE_MESSAGE(ymd.value() == 20091012, + "Expected YMD to have a value of 20091012, but found " << ymd.value()); - const Variable& user = editSuite->findVariable("USER"); - BOOST_REQUIRE_MESSAGE(!user.empty(),"Could not find variable USER"); - BOOST_REQUIRE_MESSAGE(user.value() == 0,"Expected user to have a value of 0, but found " << user.value()); + const Variable& user = editSuite->findVariable("USER"); + BOOST_REQUIRE_MESSAGE(!user.empty(), "Could not find variable USER"); + BOOST_REQUIRE_MESSAGE(user.value() == 0, "Expected user to have a value of 0, but found " << user.value()); } BOOST_AUTO_TEST_SUITE_END() - diff --git a/ANode/src/Node.hpp b/ANode/src/Node.hpp index af081df37..49af4f974 100644 --- a/ANode/src/Node.hpp +++ b/ANode/src/Node.hpp @@ -616,7 +616,9 @@ class Node : public std::enable_shared_from_this { virtual node_ptr findImmediateChild(const std::string& /*name*/, size_t& /*child_pos*/) const { return node_ptr(); } virtual node_ptr find_immediate_child(const boost::string_view&) const { return node_ptr(); } - virtual std::string find_node_path(const std::string& /*type*/, const std::string& /*name*/) const { return std::string(); } + virtual std::string find_node_path(const std::string& /*type*/, const std::string& /*name*/) const { + return std::string(); + } const Variable& findVariable(const std::string& name) const; std::string find_parent_variable_sub_value(const std::string& name) const; const Variable& find_parent_variable(const std::string& name) const; diff --git a/ANode/test/MyDefsFixture.hpp b/ANode/test/MyDefsFixture.hpp index 507ca3cc4..2038160d4 100644 --- a/ANode/test/MyDefsFixture.hpp +++ b/ANode/test/MyDefsFixture.hpp @@ -17,21 +17,22 @@ // Serialisation read/write and migration of previous fixtures //============================================================================ #include //for for_each() + #include -#include "Str.hpp" -#include "Defs.hpp" -#include "Suite.hpp" -#include "Family.hpp" -#include "Task.hpp" #include "Alias.hpp" -#include "AutoRestoreAttr.hpp" -#include "AutoCancelAttr.hpp" #include "AutoArchiveAttr.hpp" +#include "AutoCancelAttr.hpp" +#include "AutoRestoreAttr.hpp" +#include "Defs.hpp" +#include "Expression.hpp" +#include "Family.hpp" #include "LateAttr.hpp" #include "Limit.hpp" #include "MiscAttrs.hpp" -#include "Expression.hpp" +#include "Str.hpp" +#include "Suite.hpp" +#include "Task.hpp" // ======================================================================= // This struct is used in the node migration tests. @@ -39,240 +40,248 @@ // **Ensure** that we keep old fixture.def file, to test that future ecflow // versions can migrate old data. // ======================================================================= -struct MyDefsFixture { - - explicit MyDefsFixture(const std::string& port = ecf::Str::DEFAULT_PORT_NUMBER()) : defsfile_(port) - { - suite_ptr suite = create_suite(); - - // Must be done last - defsfile_.addSuite( suite ); - defsfile_.add_extern("/limits:event"); - defsfile_.add_extern("/a/b/c:meter"); - defsfile_.add_extern("/a/b/c/d"); - - // add an empty suite. Needed for CHECK_JOB_GEN_ONLY cmd - defsfile_.addSuite( Suite::create("EmptySuite" ) ); - - // Check expression parse - std::string errorMsg, warningMsg; - bool result = defsfile_.check(errorMsg,warningMsg); - if (!result || !errorMsg.empty()) { - std::cout << errorMsg; - assert(false); - } - } - ~MyDefsFixture() = default; - - const Defs& fixtureDefsFile() const { return defsfile_; } - - defs_ptr create_defs(const std::string& port = ecf::Str::DEFAULT_PORT_NUMBER()) const { - - defs_ptr defs = Defs::create(port); - - defs->addSuite( create_suite() ); - defs->add_extern("/limits:event"); - defs->add_extern("/a/b/c:meter"); - defs->add_extern("/a/b/c/d"); - defs->set_server().add_or_update_user_variables("MyDefsFixture_user_variable","This is a user variable added to server"); - defs->set_server().add_or_update_server_variable("MyDefsFixture_server_variable","This is a server variable"); - - // add an empty suite. Needed for CHECK_JOB_GEN_ONLY cmd - defs->addSuite( Suite::create("EmptySuite" ) ); - - // Check expression parse - std::string errorMsg, warningMsg; - bool result = defs->check(errorMsg,warningMsg); - if (!result || !errorMsg.empty()) { - std::cout << errorMsg; - assert(false); - } - return defs; - } - - Defs defsfile_; +struct MyDefsFixture +{ + + explicit MyDefsFixture(const std::string& port = ecf::Str::DEFAULT_PORT_NUMBER()) : defsfile_(port) { + suite_ptr suite = create_suite(); + + // Must be done last + defsfile_.addSuite(suite); + defsfile_.add_extern("/limits:event"); + defsfile_.add_extern("/a/b/c:meter"); + defsfile_.add_extern("/a/b/c/d"); + + // add an empty suite. Needed for CHECK_JOB_GEN_ONLY cmd + defsfile_.addSuite(Suite::create("EmptySuite")); + + // Check expression parse + std::string errorMsg, warningMsg; + bool result = defsfile_.check(errorMsg, warningMsg); + if (!result || !errorMsg.empty()) { + std::cout << errorMsg; + assert(false); + } + } + ~MyDefsFixture() = default; + + const Defs& fixtureDefsFile() const { return defsfile_; } + + defs_ptr create_defs(const std::string& port = ecf::Str::DEFAULT_PORT_NUMBER()) const { + + defs_ptr defs = Defs::create(port); + + defs->addSuite(create_suite()); + defs->add_extern("/limits:event"); + defs->add_extern("/a/b/c:meter"); + defs->add_extern("/a/b/c/d"); + defs->set_server().add_or_update_user_variables("MyDefsFixture_user_variable", + "This is a user variable added to server"); + defs->set_server().add_or_update_server_variable("MyDefsFixture_server_variable", "This is a server variable"); + + // add an empty suite. Needed for CHECK_JOB_GEN_ONLY cmd + defs->addSuite(Suite::create("EmptySuite")); + + // Check expression parse + std::string errorMsg, warningMsg; + bool result = defs->check(errorMsg, warningMsg); + if (!result || !errorMsg.empty()) { + std::cout << errorMsg; + assert(false); + } + return defs; + } + + Defs defsfile_; private: - suite_ptr create_suite() const { - std::string sname = "suiteName"; - suite_ptr suite = Suite::create( sname ); - - ClockAttr clockAttr(false); - clockAttr.date(1,1,2009); - clockAttr.set_gain_in_seconds(3600); - suite->addClock( clockAttr ); - - suite->addAutoCancel( ecf::AutoCancelAttr(2) ); - suite->addVariable( Variable("VAR","value") ); - suite->addVariable( Variable("VAR1","\"value\"") ); - suite->addVariable( Variable("ECF_FETCH","\"smsfetch -F %ECF_FILES% -I %ECF_INCLUDE%\"") ); - - std::vector queue_items; queue_items.emplace_back("000"); queue_items.emplace_back("001"); queue_items.emplace_back("002"); - suite->add_queue(QueueAttr("queue",queue_items)); - suite->add_queue(QueueAttr("queue1",queue_items)); - suite->add_generic(GenericAttr("gen1",queue_items)); - suite->add_generic(GenericAttr("gen2",queue_items)); - suite->add_task( "t1" ); - suite->add_task( "t2" ); - task_ptr suiteTask = suite->add_task( "t3" ); - suiteTask->add_part_trigger( PartExpression("t1 == complete") ); - suiteTask->add_part_trigger( PartExpression("t2 == complete",false) ); - suiteTask->add_part_complete( PartExpression("t1 == complete") ); - suiteTask->add_part_complete( PartExpression("t2 == complete",true) ); - - std::vector child_cmds = ecf::Child::list(); - suiteTask->addZombie( ZombieAttr(ecf::Child::USER, child_cmds, ecf::User::FOB,10) ); - suiteTask->addZombie( ZombieAttr(ecf::Child::PATH, child_cmds, ecf::User::BLOCK,100) ); - suiteTask->addZombie( ZombieAttr(ecf::Child::ECF, child_cmds, ecf::User::FAIL,100) ); - suiteTask->addZombie( ZombieAttr(ecf::Child::ECF_PID, child_cmds, ecf::User::FAIL,100) ); - suiteTask->addZombie( ZombieAttr(ecf::Child::ECF_PASSWD, child_cmds, ecf::User::FAIL,100) ); - suiteTask->addZombie( ZombieAttr(ecf::Child::ECF_PID_PASSWD, child_cmds, ecf::User::FAIL,100) ); - - - task_ptr suiteTask4 = suite->add_task( "t4" ); - suiteTask4->addZombie( ZombieAttr(ecf::Child::USER, child_cmds, ecf::User::ADOPT,10) ); - suiteTask4->addZombie( ZombieAttr(ecf::Child::PATH, child_cmds, ecf::User::BLOCK,100) ); - suiteTask4->addZombie( ZombieAttr(ecf::Child::ECF, child_cmds, ecf::User::REMOVE,100) ); - suiteTask4->addZombie( ZombieAttr(ecf::Child::ECF_PID, child_cmds, ecf::User::KILL,100) ); - suiteTask4->addZombie( ZombieAttr(ecf::Child::ECF_PASSWD, child_cmds, ecf::User::FOB,100) ); - suiteTask4->addZombie( ZombieAttr(ecf::Child::ECF_PID_PASSWD, child_cmds, ecf::User::BLOCK,100) ); - - - ecf::CronAttr cronAttr; - ecf::TimeSlot start( 0, 0 ); - ecf::TimeSlot finish( 10, 0 ); - ecf::TimeSlot incr( 0, 5 ); - std::vector weekdays; for(int i=0;i<7;++i) weekdays.push_back(i); - std::vector daysOfMonth;for(int i=1;i<32;++i) daysOfMonth.push_back(i); - std::vector months; for(int i=1;i<13;++i) months.push_back(i); - cronAttr.addTimeSeries(start,finish,incr); - cronAttr.addWeekDays( weekdays ); - cronAttr.addDaysOfMonth(daysOfMonth); - cronAttr.addMonths( months ); - suite->addCron( cronAttr ); - - ecf::LateAttr lateAttr; - lateAttr.addSubmitted( ecf::TimeSlot(3,12) ); - lateAttr.addActive( ecf::TimeSlot(3,12) ); - lateAttr.addComplete( ecf::TimeSlot(4,12), true); - - std::string suiteLimit = "suiteLimit"; - std::string suiteLimit2 = "suiteLimit2"; - std::string suiteLimit3 = "suiteLimit3"; - suite->addLimit( Limit(suiteLimit,10) ); - suite->addLimit( Limit(suiteLimit2,10) ); - suite->addLimit( Limit(suiteLimit3,10) ); - - // Add tasks with all the repeat variants - std::vector stringList{"10","20","30"}; - task_ptr t5 = suite->add_task( "t5" ); - t5->addRepeat( RepeatEnumerated("AEnum",stringList)); - - task_ptr t6 = suite->add_task( "t6" ); - t6->addRepeat( RepeatString("aString",stringList)); - - task_ptr t7 = suite->add_task( "t7" ); - t7->addRepeat( RepeatInteger("rep",0,100,1) ); - - task_ptr t8 = suite->add_task( "t8" ); - t8->addRepeat( RepeatDate("YMD",20090916,20090916,1) ); - - task_ptr t9 = suite->add_task( "t9" ); - t9->addRepeat( RepeatDateList("YMD",{20090916,20090916}) ); - - task_ptr t10 = suite->add_task( "t10" ); - t10->addRepeat( RepeatDay(2) ); - - suite->add_family("f1")->add_autoarchive( ecf::AutoArchiveAttr( ecf::TimeSlot(1,0), true)); - suite->add_family("f2")->add_autoarchive( ecf::AutoArchiveAttr( 5,22, true)); - suite->add_family("f3")->add_autoarchive( ecf::AutoArchiveAttr( 4)); - suite->add_family("f4")->add_autoarchive( ecf::AutoArchiveAttr( 0)); - suite->add_family("f5")->add_autoarchive( ecf::AutoArchiveAttr( ecf::TimeSlot(1,0), true,true)); - suite->add_family("f6")->add_autoarchive( ecf::AutoArchiveAttr( 5,22, true,true)); - suite->add_family("f7")->add_autoarchive( ecf::AutoArchiveAttr( 4,true)); - suite->add_family("f8")->add_autoarchive( ecf::AutoArchiveAttr( 0,true)); - - - for (int i = 0; i < 3; ++i) { - std::string fname = "familyName"; - std::string tname = "taskName"; - std::string eventName = "eventName"; - std::string labelName = "labelName"; - std::string limitName = "limitName"; - if ( i != 0 ) { - fname += boost::lexical_cast< std::string >( i ); - tname += boost::lexical_cast< std::string >( i ); - labelName += boost::lexical_cast< std::string >( i ); - } - - family_ptr fam = suite->add_family( fname ); - fam->addDate( DateAttr(0,0,2009) ); // 0 is equivalent to a * - fam->addRepeat( RepeatEnumerated("AEnum",stringList)); - fam->addAutoCancel( ecf::AutoCancelAttr( ecf::TimeSlot(1,0), true)); - fam->addVariable( Variable("VAR","value") ); - fam->addTime( ecf::TimeAttr(ecf::TimeSlot(0,0),ecf::TimeSlot(10,1),ecf::TimeSlot(0,1),true) ); - fam->addLimit( Limit(limitName,20) ); - fam->addLate( lateAttr ); - fam->addInLimit( InLimit(suiteLimit2,"/" + sname,2,true/*limit this node only*/ )); - fam->add_queue(QueueAttr("queue1",queue_items)); - fam->add_generic(GenericAttr("gen1",queue_items)); - - task_ptr task = fam->add_task( tname ); - task->addDate( DateAttr(1,2,2009) ); - task->addDay( DayAttr(DayAttr::MONDAY) ); - task->addVariable( Variable("VAR1","\"value\"") ); - task->addEvent( Event(i) ); - task->addEvent( Event(i+1, eventName ) ); - task->addEvent( Event(i+2, "my_event", true/*init value*/ ) ); - task->addMeter( Meter("myMeter",0,100,100) ); - task->addLabel( Label(labelName,"\"labelValue\"") ); - task->addTime( ecf::TimeAttr(ecf::TimeSlot(10,10),true) ); - task->addToday( ecf::TodayAttr(ecf::TimeSlot(10,12)) ); - task->addToday( ecf::TodayAttr(ecf::TimeSlot(0,1),ecf::TimeSlot(0,3),ecf::TimeSlot(0,1),true) ); - task->addDefStatus( DState::COMPLETE ); - task->addInLimit( InLimit(suiteLimit,"/" + sname )); - task->addInLimit( InLimit(suiteLimit3,"/" + sname,1,false/*limit this node only*/,true/*limit submission*/ )); - task->addVerify( VerifyAttr(NState::COMPLETE,3) ); - task->addLate( lateAttr ); - task->add_queue(QueueAttr("queue1",queue_items)); - task->add_generic(GenericAttr("gen1",queue_items)); - task->add_generic(GenericAttr("gen2",std::vector())); - - std::vector nodes_to_restore; nodes_to_restore.emplace_back("/EmptySuite"); - task->add_autorestore(ecf::AutoRestoreAttr(nodes_to_restore)); - if (i == 2) { - std::string compExpr = "../familyName" + boost::lexical_cast< std::string >( i-1 ); - compExpr += "/taskName" + boost::lexical_cast< std::string >( i-1 ); - compExpr += ":myMeter ge 10"; - task->add_complete( compExpr ); - - std::string expression = "../familyName" + boost::lexical_cast< std::string >( i-1 ); - expression += "/taskName" + boost::lexical_cast< std::string >( i-1 ); - expression += " == complete"; - task->add_trigger( expression ); - } - task->add_alias_only(); //add alias without creating dir & .usr file - task->add_alias_only(); - - - // Add a hierarchical family to the first family - if (i == 0) { - std::string heirFamily = "heir_" + fname; - family_ptr hierFam = fam->add_family( heirFamily ); - hierFam->addVariable( Variable("VAR1","value") ); - hierFam->addRepeat( RepeatString("aString",stringList)); - hierFam->add_autoarchive( ecf::AutoArchiveAttr( ecf::TimeSlot(1,0), true)); - - task_ptr task1 = hierFam->add_task( tname ); - task1->addVariable( Variable("VAR1","value") ); - task1->addEvent( Event(i) ); - task1->addEvent( Event(i+1, eventName ) ); - task1->addEvent( Event(i+2, "my_event", true/*init value*/ ) ); - task1->addMeter( Meter("myMeter",0,100,100) ); - task1->addAutoCancel( ecf::AutoCancelAttr( ecf::TimeSlot(0,1), false)); - } - } - return suite; - } + suite_ptr create_suite() const { + std::string sname = "suiteName"; + suite_ptr suite = Suite::create(sname); + + ClockAttr clockAttr(false); + clockAttr.date(1, 1, 2009); + clockAttr.set_gain_in_seconds(3600); + suite->addClock(clockAttr); + + suite->addAutoCancel(ecf::AutoCancelAttr(2)); + suite->addVariable(Variable("VAR", "value")); + suite->addVariable(Variable("VAR1", "\"value\"")); + suite->addVariable(Variable("ECF_FETCH", "\"smsfetch -F %ECF_FILES% -I %ECF_INCLUDE%\"")); + + std::vector queue_items; + queue_items.emplace_back("000"); + queue_items.emplace_back("001"); + queue_items.emplace_back("002"); + suite->add_queue(QueueAttr("queue", queue_items)); + suite->add_queue(QueueAttr("queue1", queue_items)); + suite->add_generic(GenericAttr("gen1", queue_items)); + suite->add_generic(GenericAttr("gen2", queue_items)); + suite->add_task("t1"); + suite->add_task("t2"); + task_ptr suiteTask = suite->add_task("t3"); + suiteTask->add_part_trigger(PartExpression("t1 == complete")); + suiteTask->add_part_trigger(PartExpression("t2 == complete", false)); + suiteTask->add_part_complete(PartExpression("t1 == complete")); + suiteTask->add_part_complete(PartExpression("t2 == complete", true)); + + std::vector child_cmds = ecf::Child::list(); + suiteTask->addZombie(ZombieAttr(ecf::Child::USER, child_cmds, ecf::User::FOB, 10)); + suiteTask->addZombie(ZombieAttr(ecf::Child::PATH, child_cmds, ecf::User::BLOCK, 100)); + suiteTask->addZombie(ZombieAttr(ecf::Child::ECF, child_cmds, ecf::User::FAIL, 100)); + suiteTask->addZombie(ZombieAttr(ecf::Child::ECF_PID, child_cmds, ecf::User::FAIL, 100)); + suiteTask->addZombie(ZombieAttr(ecf::Child::ECF_PASSWD, child_cmds, ecf::User::FAIL, 100)); + suiteTask->addZombie(ZombieAttr(ecf::Child::ECF_PID_PASSWD, child_cmds, ecf::User::FAIL, 100)); + + task_ptr suiteTask4 = suite->add_task("t4"); + suiteTask4->addZombie(ZombieAttr(ecf::Child::USER, child_cmds, ecf::User::ADOPT, 10)); + suiteTask4->addZombie(ZombieAttr(ecf::Child::PATH, child_cmds, ecf::User::BLOCK, 100)); + suiteTask4->addZombie(ZombieAttr(ecf::Child::ECF, child_cmds, ecf::User::REMOVE, 100)); + suiteTask4->addZombie(ZombieAttr(ecf::Child::ECF_PID, child_cmds, ecf::User::KILL, 100)); + suiteTask4->addZombie(ZombieAttr(ecf::Child::ECF_PASSWD, child_cmds, ecf::User::FOB, 100)); + suiteTask4->addZombie(ZombieAttr(ecf::Child::ECF_PID_PASSWD, child_cmds, ecf::User::BLOCK, 100)); + + ecf::CronAttr cronAttr; + ecf::TimeSlot start(0, 0); + ecf::TimeSlot finish(10, 0); + ecf::TimeSlot incr(0, 5); + std::vector weekdays; + for (int i = 0; i < 7; ++i) + weekdays.push_back(i); + std::vector daysOfMonth; + for (int i = 1; i < 32; ++i) + daysOfMonth.push_back(i); + std::vector months; + for (int i = 1; i < 13; ++i) + months.push_back(i); + cronAttr.addTimeSeries(start, finish, incr); + cronAttr.addWeekDays(weekdays); + cronAttr.addDaysOfMonth(daysOfMonth); + cronAttr.addMonths(months); + suite->addCron(cronAttr); + + ecf::LateAttr lateAttr; + lateAttr.addSubmitted(ecf::TimeSlot(3, 12)); + lateAttr.addActive(ecf::TimeSlot(3, 12)); + lateAttr.addComplete(ecf::TimeSlot(4, 12), true); + + std::string suiteLimit = "suiteLimit"; + std::string suiteLimit2 = "suiteLimit2"; + std::string suiteLimit3 = "suiteLimit3"; + suite->addLimit(Limit(suiteLimit, 10)); + suite->addLimit(Limit(suiteLimit2, 10)); + suite->addLimit(Limit(suiteLimit3, 10)); + + // Add tasks with all the repeat variants + std::vector stringList{"10", "20", "30"}; + task_ptr t5 = suite->add_task("t5"); + t5->addRepeat(RepeatEnumerated("AEnum", stringList)); + + task_ptr t6 = suite->add_task("t6"); + t6->addRepeat(RepeatString("aString", stringList)); + + task_ptr t7 = suite->add_task("t7"); + t7->addRepeat(RepeatInteger("rep", 0, 100, 1)); + + task_ptr t8 = suite->add_task("t8"); + t8->addRepeat(RepeatDate("YMD", 20090916, 20090916, 1)); + + task_ptr t9 = suite->add_task("t9"); + t9->addRepeat(RepeatDateList("YMD", {20090916, 20090916})); + + task_ptr t10 = suite->add_task("t10"); + t10->addRepeat(RepeatDay(2)); + + suite->add_family("f1")->add_autoarchive(ecf::AutoArchiveAttr(ecf::TimeSlot(1, 0), true)); + suite->add_family("f2")->add_autoarchive(ecf::AutoArchiveAttr(5, 22, true)); + suite->add_family("f3")->add_autoarchive(ecf::AutoArchiveAttr(4)); + suite->add_family("f4")->add_autoarchive(ecf::AutoArchiveAttr(0)); + suite->add_family("f5")->add_autoarchive(ecf::AutoArchiveAttr(ecf::TimeSlot(1, 0), true, true)); + suite->add_family("f6")->add_autoarchive(ecf::AutoArchiveAttr(5, 22, true, true)); + suite->add_family("f7")->add_autoarchive(ecf::AutoArchiveAttr(4, true)); + suite->add_family("f8")->add_autoarchive(ecf::AutoArchiveAttr(0, true)); + + for (int i = 0; i < 3; ++i) { + std::string fname = "familyName"; + std::string tname = "taskName"; + std::string eventName = "eventName"; + std::string labelName = "labelName"; + std::string limitName = "limitName"; + if (i != 0) { + fname += boost::lexical_cast(i); + tname += boost::lexical_cast(i); + labelName += boost::lexical_cast(i); + } + + family_ptr fam = suite->add_family(fname); + fam->addDate(DateAttr(0, 0, 2009)); // 0 is equivalent to a * + fam->addRepeat(RepeatEnumerated("AEnum", stringList)); + fam->addAutoCancel(ecf::AutoCancelAttr(ecf::TimeSlot(1, 0), true)); + fam->addVariable(Variable("VAR", "value")); + fam->addTime(ecf::TimeAttr(ecf::TimeSlot(0, 0), ecf::TimeSlot(10, 1), ecf::TimeSlot(0, 1), true)); + fam->addLimit(Limit(limitName, 20)); + fam->addLate(lateAttr); + fam->addInLimit(InLimit(suiteLimit2, "/" + sname, 2, true /*limit this node only*/)); + fam->add_queue(QueueAttr("queue1", queue_items)); + fam->add_generic(GenericAttr("gen1", queue_items)); + + task_ptr task = fam->add_task(tname); + task->addDate(DateAttr(1, 2, 2009)); + task->addDay(DayAttr(DayAttr::MONDAY)); + task->addVariable(Variable("VAR1", "\"value\"")); + task->addEvent(Event(i)); + task->addEvent(Event(i + 1, eventName)); + task->addEvent(Event(i + 2, "my_event", true /*init value*/)); + task->addMeter(Meter("myMeter", 0, 100, 100)); + task->addLabel(Label(labelName, "\"labelValue\"")); + task->addTime(ecf::TimeAttr(ecf::TimeSlot(10, 10), true)); + task->addToday(ecf::TodayAttr(ecf::TimeSlot(10, 12))); + task->addToday(ecf::TodayAttr(ecf::TimeSlot(0, 1), ecf::TimeSlot(0, 3), ecf::TimeSlot(0, 1), true)); + task->addDefStatus(DState::COMPLETE); + task->addInLimit(InLimit(suiteLimit, "/" + sname)); + task->addInLimit( + InLimit(suiteLimit3, "/" + sname, 1, false /*limit this node only*/, true /*limit submission*/)); + task->addVerify(VerifyAttr(NState::COMPLETE, 3)); + task->addLate(lateAttr); + task->add_queue(QueueAttr("queue1", queue_items)); + task->add_generic(GenericAttr("gen1", queue_items)); + task->add_generic(GenericAttr("gen2", std::vector())); + + std::vector nodes_to_restore; + nodes_to_restore.emplace_back("/EmptySuite"); + task->add_autorestore(ecf::AutoRestoreAttr(nodes_to_restore)); + if (i == 2) { + std::string compExpr = "../familyName" + boost::lexical_cast(i - 1); + compExpr += "/taskName" + boost::lexical_cast(i - 1); + compExpr += ":myMeter ge 10"; + task->add_complete(compExpr); + + std::string expression = "../familyName" + boost::lexical_cast(i - 1); + expression += "/taskName" + boost::lexical_cast(i - 1); + expression += " == complete"; + task->add_trigger(expression); + } + task->add_alias_only(); // add alias without creating dir & .usr file + task->add_alias_only(); + + // Add a hierarchical family to the first family + if (i == 0) { + std::string heirFamily = "heir_" + fname; + family_ptr hierFam = fam->add_family(heirFamily); + hierFam->addVariable(Variable("VAR1", "value")); + hierFam->addRepeat(RepeatString("aString", stringList)); + hierFam->add_autoarchive(ecf::AutoArchiveAttr(ecf::TimeSlot(1, 0), true)); + + task_ptr task1 = hierFam->add_task(tname); + task1->addVariable(Variable("VAR1", "value")); + task1->addEvent(Event(i)); + task1->addEvent(Event(i + 1, eventName)); + task1->addEvent(Event(i + 2, "my_event", true /*init value*/)); + task1->addMeter(Meter("myMeter", 0, 100, 100)); + task1->addAutoCancel(ecf::AutoCancelAttr(ecf::TimeSlot(0, 1), false)); + } + } + return suite; + } }; #endif diff --git a/Base/src/cts/ClientToServerCmd.hpp b/Base/src/cts/ClientToServerCmd.hpp index 196c448c0..27f0714f0 100644 --- a/Base/src/cts/ClientToServerCmd.hpp +++ b/Base/src/cts/ClientToServerCmd.hpp @@ -3,31 +3,31 @@ /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 // Name : Cmd // Author : Avi -// Revision : $Revision: #143 $ +// Revision : $Revision: #143 $ // // Copyright 2009- ECMWF. -// This software is licensed under the terms of the Apache Licence version 2.0 -// which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. -// In applying this licence, ECMWF does not waive the privileges and immunities -// granted to it by virtue of its status as an intergovernmental organisation -// nor does it submit to any jurisdiction. +// This software is licensed under the terms of the Apache Licence version 2.0 +// which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. +// In applying this licence, ECMWF does not waive the privileges and immunities +// granted to it by virtue of its status as an intergovernmental organisation +// nor does it submit to any jurisdiction. // // Description : /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 #include -#include "PrintStyle.hpp" +#include "CheckPt.hpp" +#include "Child.hpp" #include "Cmd.hpp" -#include "NodeFwd.hpp" -#include "NOrder.hpp" -#include "Zombie.hpp" #include "Flag.hpp" -#include "Child.hpp" -#include "CheckPt.hpp" +#include "NOrder.hpp" +#include "NodeFwd.hpp" #include "PreAllocatedReply.hpp" +#include "PrintStyle.hpp" #include "Serialization.hpp" #include "Variable.hpp" +#include "Zombie.hpp" class AbstractServer; class AbstractClientEnv; @@ -36,169 +36,172 @@ class GroupCTSCmd; /////////////////////////////////////////////////////////////////////////////////// // Client->Server cmd's /////////////////////////////////////////////////////////////////////////////////// -class ClientToServerCmd { +class ClientToServerCmd { public: - virtual ~ClientToServerCmd(); - - /// The host where the client was called - const std::string& hostname() const { return cl_host_;} - - /// The second print is for use by EditHistoryMgr when we have commands that take multiple paths - /// The EditHistoryMgr records what command was applied to each node. However when logging the - /// the command we do not want logs all the paths, for each node.(performance bottleneck - /// when dealing with thousands of paths) - virtual void print(std::string& os) const = 0; - virtual void print(std::string& os, const std::string& /*path*/) const { print(os); } - - /// Print the command without trailing @. Used by Group command, avoids duplicate user@host for each child command - virtual void print_only(std::string& os ) const { return print(os); } - - /// Print with minimal information. Deals with errors report where cmd have thousands of paths. truncate to one path. - /// This should *NOT* include trailing @ - virtual std::string print_short() const { std::string ret; print_only(ret); return ret; } - - virtual bool equals(ClientToServerCmd* rhs) const; - - /// Called by the _server_ to service the client depending on the Command - /// The server will pass itself down via the AbstractServer - /// The returned Server to Client command is sent back to the client - /// Uses template pattern, it first authenticates request and then calls - /// doHandleRequest. This function can throw exceptions. std::runtime_error - STC_Cmd_ptr handleRequest(AbstractServer*) const; - - /// After handleRequest() has run, this function can be used reclaim memory - virtual void cleanup() {} - - /// Returns true if handleRequest is testable. Only used in TEST - virtual bool handleRequestIsTestable() const { return true ;} - - /// How long in seconds the client to attempt to send request and get a reply back - /// before the request fails. This timeout affects the wait for the outward request - /// and inward reply. - /// - /// The timeout feature allow the client to fail gracefully in the case - /// where the server has died/crashed. The timeout will ensure the socket is closed. - /// allowing the server to be restarted without getting the address is use error. - /// - /// NOTE: We also have a timeout in ClientInvoker/ClientEnvironment, *that* is different, - /// as that applies to CHILD/task commands, and control how long we continue - /// to iterate over the hosts files - virtual int timeout() const { return 60; } - - /// A command can be read only command or write only command - /// A read only command will not change the state of the suites in the server - /// A write only command can modify the state of suite in the server - /// Used by the server for authentication since only write only users are allowed to edit. - virtual bool isWrite() const { return false; /* returning false means read only */ } - - /// Some read only commands under exceptional situation can modify the DEFS. - /// i.e if write permission is removed from ECF_HOME then the check_pt command can fail - /// in which case if can set flags, Flag::LATE, Flag::CHECKPT_ERROR, Flag::LOG_ERROR to warn the users - /// This function is used to avoid unnecessary warning message. - virtual bool is_mutable() const { return false;} - - /// Some commands modify the server but do not affect defs. i.e reload white list file,password file - /// Other like ClientHandleCmd make edits to defs(well kind off) but are read only.(i.e anyone can call them) - /// This return true for those commands that affect the defs, that we need sync on the client side. - virtual bool cmd_updates_defs() const { return isWrite(); } - - /// This Must be called for client->server commands.As this is required - /// for authentication. *However* task based commands have their own authentication - /// mechanism, and don't need setup_user_authentification(). - virtual void setup_user_authentification(const std::string& user, const std::string& passwd) = 0; // Used by PlugCmd - virtual bool setup_user_authentification(AbstractClientEnv&) = 0; // set user and passwd - virtual void setup_user_authentification() = 0; // if user empty setup. - - /// Allow control over connection to different servers/hosts if the main server is down - /// i.e for a getCmd, we do not want to wait 24 hours, trying all the servers - /// However for Task based commands like , init,abort,event, meter,complete we - /// want this behaviour as it can alter Node tree state and thus affect dependent nodes - virtual bool connect_to_different_servers() const { return false; } - - /// The show occurs on the client side - virtual PrintStyle::Type_t show_style() const { return PrintStyle::NOTHING;} - - // Other commands - virtual bool get_cmd() const { return false; } - virtual bool task_cmd() const { return false; } - virtual bool terminate_cmd() const { return false; } - virtual bool group_cmd() const { return false; } - virtual bool ping_cmd() const { return false;} - virtual bool why_cmd( std::string& ) const { return false;} - virtual bool show_cmd() const { return false ;} - virtual void add_edit_history(Defs*) const; - - // used by group_cmd to postfix syncCmd on all user commands that modify defs - virtual void set_client_handle(int /*client_handle*/) {} // used by group_cmd - virtual void set_group_cmd(const GroupCTSCmd*) {} - - // CLIENT side Parse and command construction, create can throw std::runtime_error for errors - virtual const char* theArg() const = 0; // used for argument parsing - virtual void addOption(boost::program_options::options_description& desc) const = 0; - virtual void create( Cmd_ptr& cmd, - boost::program_options::variables_map& vm, - AbstractClientEnv* clientEnv) const = 0; -protected: - ClientToServerCmd(); + virtual ~ClientToServerCmd(); + + /// The host where the client was called + const std::string& hostname() const { return cl_host_; } + + /// The second print is for use by EditHistoryMgr when we have commands that take multiple paths + /// The EditHistoryMgr records what command was applied to each node. However when logging the + /// the command we do not want logs all the paths, for each node.(performance bottleneck + /// when dealing with thousands of paths) + virtual void print(std::string& os) const = 0; + virtual void print(std::string& os, const std::string& /*path*/) const { print(os); } + + /// Print the command without trailing @. Used by Group command, avoids duplicate user@host for each + /// child command + virtual void print_only(std::string& os) const { return print(os); } + + /// Print with minimal information. Deals with errors report where cmd have thousands of paths. truncate to one + /// path. This should *NOT* include trailing @ + virtual std::string print_short() const { + std::string ret; + print_only(ret); + return ret; + } + + virtual bool equals(ClientToServerCmd* rhs) const; + + /// Called by the _server_ to service the client depending on the Command + /// The server will pass itself down via the AbstractServer + /// The returned Server to Client command is sent back to the client + /// Uses template pattern, it first authenticates request and then calls + /// doHandleRequest. This function can throw exceptions. std::runtime_error + STC_Cmd_ptr handleRequest(AbstractServer*) const; + + /// After handleRequest() has run, this function can be used reclaim memory + virtual void cleanup() {} + + /// Returns true if handleRequest is testable. Only used in TEST + virtual bool handleRequestIsTestable() const { return true; } + + /// How long in seconds the client to attempt to send request and get a reply back + /// before the request fails. This timeout affects the wait for the outward request + /// and inward reply. + /// + /// The timeout feature allow the client to fail gracefully in the case + /// where the server has died/crashed. The timeout will ensure the socket is closed. + /// allowing the server to be restarted without getting the address is use error. + /// + /// NOTE: We also have a timeout in ClientInvoker/ClientEnvironment, *that* is different, + /// as that applies to CHILD/task commands, and control how long we continue + /// to iterate over the hosts files + virtual int timeout() const { return 60; } + + /// A command can be read only command or write only command + /// A read only command will not change the state of the suites in the server + /// A write only command can modify the state of suite in the server + /// Used by the server for authentication since only write only users are allowed to edit. + virtual bool isWrite() const { return false; /* returning false means read only */ } + + /// Some read only commands under exceptional situation can modify the DEFS. + /// i.e if write permission is removed from ECF_HOME then the check_pt command can fail + /// in which case if can set flags, Flag::LATE, Flag::CHECKPT_ERROR, Flag::LOG_ERROR to warn the users + /// This function is used to avoid unnecessary warning message. + virtual bool is_mutable() const { return false; } + + /// Some commands modify the server but do not affect defs. i.e reload white list file,password file + /// Other like ClientHandleCmd make edits to defs(well kind off) but are read only.(i.e anyone can call them) + /// This return true for those commands that affect the defs, that we need sync on the client side. + virtual bool cmd_updates_defs() const { return isWrite(); } + + /// This Must be called for client->server commands.As this is required + /// for authentication. *However* task based commands have their own authentication + /// mechanism, and don't need setup_user_authentification(). + virtual void setup_user_authentification(const std::string& user, const std::string& passwd) = 0; // Used by PlugCmd + virtual bool setup_user_authentification(AbstractClientEnv&) = 0; // set user and passwd + virtual void setup_user_authentification() = 0; // if user empty setup. + + /// Allow control over connection to different servers/hosts if the main server is down + /// i.e for a getCmd, we do not want to wait 24 hours, trying all the servers + /// However for Task based commands like , init,abort,event, meter,complete we + /// want this behaviour as it can alter Node tree state and thus affect dependent nodes + virtual bool connect_to_different_servers() const { return false; } + + /// The show occurs on the client side + virtual PrintStyle::Type_t show_style() const { return PrintStyle::NOTHING; } + + // Other commands + virtual bool get_cmd() const { return false; } + virtual bool task_cmd() const { return false; } + virtual bool terminate_cmd() const { return false; } + virtual bool group_cmd() const { return false; } + virtual bool ping_cmd() const { return false; } + virtual bool why_cmd(std::string&) const { return false; } + virtual bool show_cmd() const { return false; } + virtual void add_edit_history(Defs*) const; + + // used by group_cmd to postfix syncCmd on all user commands that modify defs + virtual void set_client_handle(int /*client_handle*/) {} // used by group_cmd + virtual void set_group_cmd(const GroupCTSCmd*) {} + + // CLIENT side Parse and command construction, create can throw std::runtime_error for errors + virtual const char* theArg() const = 0; // used for argument parsing + virtual void addOption(boost::program_options::options_description& desc) const = 0; + virtual void + create(Cmd_ptr& cmd, boost::program_options::variables_map& vm, AbstractClientEnv* clientEnv) const = 0; - /// called by handleRequest, part of the template pattern - virtual STC_Cmd_ptr doHandleRequest(AbstractServer*) const = 0; - - /// return true if authentication succeeds, false and STC_Cmd_ptr to return otherwise - /// This function is called from doHandleRequest and hence is called - /// from within the server. The default implementation will get the current - /// user and authenticate with reference to the white list file - virtual bool authenticate(AbstractServer*, STC_Cmd_ptr&) const = 0; +protected: + ClientToServerCmd(); - /// Log the command. Must typically be done before call doHandleRequest(), in case of crash/exception - /// In rare case allow override. (i.e for additional debug) - /// called by handleRequest, part of the template pattern - /// If logging fails set late flag to warn users ECFLOW-536 - virtual void do_log(AbstractServer*) const; + /// called by handleRequest, part of the template pattern + virtual STC_Cmd_ptr doHandleRequest(AbstractServer*) const = 0; - /// Some commands which cause a change in state, should force an immediate job submission. - /// Providing the server is *NOT* shutdown - static STC_Cmd_ptr doJobSubmission(AbstractServer* as); + /// return true if authentication succeeds, false and STC_Cmd_ptr to return otherwise + /// This function is called from doHandleRequest and hence is called + /// from within the server. The default implementation will get the current + /// user and authenticate with reference to the white list file + virtual bool authenticate(AbstractServer*, STC_Cmd_ptr&) const = 0; - static void dumpVecArgs(const char* argOption, const std::vector& args); + /// Log the command. Must typically be done before call doHandleRequest(), in case of crash/exception + /// In rare case allow override. (i.e for additional debug) + /// called by handleRequest, part of the template pattern + /// If logging fails set late flag to warn users ECFLOW-536 + virtual void do_log(AbstractServer*) const; - /// Find the node otherwise throw std:::runtime_error - node_ptr find_node(Defs*, const std::string& absNodepath) const; + /// Some commands which cause a change in state, should force an immediate job submission. + /// Providing the server is *NOT* shutdown + static STC_Cmd_ptr doJobSubmission(AbstractServer* as); - /// Find The node for edit, otherwise throw std:::runtime_error - /// Will add the node edit history collection - node_ptr find_node_for_edit(Defs*, const std::string& absNodepath) const; + static void dumpVecArgs(const char* argOption, const std::vector& args); - /// Find The node for edit, otherwise return a NULL pointer - /// Will add the node edit history collection - node_ptr find_node_for_edit_no_throw(Defs*, const std::string& absNodepath) const; + /// Find the node otherwise throw std:::runtime_error + node_ptr find_node(Defs*, const std::string& absNodepath) const; - /// finds the associated node and adds to edit history nodes - void add_node_for_edit_history(Defs* as, const std::string& absNodepath) const; - void add_node_for_edit_history(node_ptr) const; - void add_node_path_for_edit_history(const std::string& absNodepath) const; + /// Find The node for edit, otherwise throw std:::runtime_error + /// Will add the node edit history collection + node_ptr find_node_for_edit(Defs*, const std::string& absNodepath) const; + /// Find The node for edit, otherwise return a NULL pointer + /// Will add the node edit history collection + node_ptr find_node_for_edit_no_throw(Defs*, const std::string& absNodepath) const; - void add_edit_history(Defs*,const std::string& path) const; - void add_delete_edit_history(Defs*,const std::string& path) const; + /// finds the associated node and adds to edit history nodes + void add_node_for_edit_history(Defs* as, const std::string& absNodepath) const; + void add_node_for_edit_history(node_ptr) const; + void add_node_path_for_edit_history(const std::string& absNodepath) const; + void add_edit_history(Defs*, const std::string& path) const; + void add_delete_edit_history(Defs*, const std::string& path) const; - mutable bool use_EditHistoryMgr_{true}; // sometime quicker to add edit history in command, than using EditHistoryMgr + mutable bool use_EditHistoryMgr_{ + true}; // sometime quicker to add edit history in command, than using EditHistoryMgr private: - friend class GroupCTSCmd; - friend class EditHistoryMgr; - mutable std::vector edit_history_nodes_; // NOT persisted - mutable std::vector edit_history_node_paths_; // NOT persisted, used when deleting + friend class GroupCTSCmd; + friend class EditHistoryMgr; + mutable std::vector edit_history_nodes_; // NOT persisted + mutable std::vector edit_history_node_paths_; // NOT persisted, used when deleting - std::string cl_host_; // The host where the client was called + std::string cl_host_; // The host where the client was called private: - friend class cereal::access; - template - void serialize(Archive & ar, std::uint32_t const /*version*/ ) - { - ar( CEREAL_NVP(cl_host_) ); - } + friend class cereal::access; + template + void serialize(Archive& ar, std::uint32_t const /*version*/) { + ar(CEREAL_NVP(cl_host_)); + } }; //================================================================================= @@ -206,406 +209,399 @@ class ClientToServerCmd { // ================================================================================ class TaskCmd : public ClientToServerCmd { protected: - TaskCmd( const std::string& pathToSubmittable, + TaskCmd(const std::string& pathToSubmittable, const std::string& jobsPassword, const std::string& process_or_remote_id, int try_no) - : submittable_(nullptr), - path_to_submittable_(pathToSubmittable), - jobs_password_(jobsPassword),process_or_remote_id_(process_or_remote_id), try_no_(try_no){assert(!hostname().empty());} + : submittable_(nullptr), + path_to_submittable_(pathToSubmittable), + jobs_password_(jobsPassword), + process_or_remote_id_(process_or_remote_id), + try_no_(try_no) { + assert(!hostname().empty()); + } - TaskCmd() = default; + TaskCmd() = default; public: + bool isWrite() const override { return true; } + int timeout() const override { return 190; } // ECFLOW-157 80 -> 190 - bool isWrite() const override { return true; } - int timeout() const override { return 190; } // ECFLOW-157 80 -> 190 + const std::string& path_to_node() const { return path_to_submittable_; } + const std::string& jobs_password() const { return jobs_password_; } + const std::string& process_or_remote_id() const { return process_or_remote_id_; } + int try_no() const { return try_no_; } + virtual ecf::Child::CmdType child_type() const = 0; - const std::string& path_to_node() const { return path_to_submittable_;} - const std::string& jobs_password() const { return jobs_password_;} - const std::string& process_or_remote_id() const { return process_or_remote_id_;} - int try_no() const { return try_no_;} - virtual ecf::Child::CmdType child_type() const = 0; + bool equals(ClientToServerCmd*) const override; + bool task_cmd() const override { return true; } + bool connect_to_different_servers() const override { return true; } - bool equals(ClientToServerCmd*) const override; - bool task_cmd() const override { return true; } - bool connect_to_different_servers() const override { return true; } - - bool password_missmatch() const { return password_missmatch_;} - bool pid_missmatch() const { return pid_missmatch_;} + bool password_missmatch() const { return password_missmatch_; } + bool pid_missmatch() const { return pid_missmatch_; } protected: - /// Overridden to do nothing since Task based commands don't need _user_ based authentication - void setup_user_authentification(const std::string& /*user*/, const std::string& /*passwd*/) override{} - bool setup_user_authentification(AbstractClientEnv&) override{return true;} - void setup_user_authentification() override{} + /// Overridden to do nothing since Task based commands don't need _user_ based authentication + void setup_user_authentification(const std::string& /*user*/, const std::string& /*passwd*/) override {} + bool setup_user_authentification(AbstractClientEnv&) override { return true; } + void setup_user_authentification() override {} - bool authenticate(AbstractServer*, STC_Cmd_ptr&) const override; /// Task have their own mechanism,can throw std::runtime_error - Submittable* get_submittable(AbstractServer* as) const ; // can throw std::runtime_error + bool authenticate(AbstractServer*, + STC_Cmd_ptr&) const override; /// Task have their own mechanism,can throw std::runtime_error + Submittable* get_submittable(AbstractServer* as) const; // can throw std::runtime_error protected: - mutable Submittable* submittable_{nullptr}; // stored during authentication and re-used handle request, not persisted, server side only + mutable Submittable* submittable_{ + nullptr}; // stored during authentication and re-used handle request, not persisted, server side only private: - std::string path_to_submittable_; - std::string jobs_password_; - std::string process_or_remote_id_; - int try_no_{0}; + std::string path_to_submittable_; + std::string jobs_password_; + std::string process_or_remote_id_; + int try_no_{0}; private: - mutable bool password_missmatch_{false}; // stored during authentication and re-used handle request, not persisted, server side only - mutable bool pid_missmatch_{false}; // stored during authentication and re-used handle request, not persisted, server side only - - friend class cereal::access; - template - void serialize(Archive & ar, std::uint32_t const /*version*/ ) - { - ar(cereal::base_class< ClientToServerCmd >( this ), - CEREAL_NVP(path_to_submittable_), - CEREAL_NVP(jobs_password_), - CEREAL_NVP(process_or_remote_id_), - CEREAL_NVP(try_no_)); - } + mutable bool password_missmatch_{ + false}; // stored during authentication and re-used handle request, not persisted, server side only + mutable bool pid_missmatch_{ + false}; // stored during authentication and re-used handle request, not persisted, server side only + + friend class cereal::access; + template + void serialize(Archive& ar, std::uint32_t const /*version*/) { + ar(cereal::base_class(this), + CEREAL_NVP(path_to_submittable_), + CEREAL_NVP(jobs_password_), + CEREAL_NVP(process_or_remote_id_), + CEREAL_NVP(try_no_)); + } }; class InitCmd final : public TaskCmd { public: - InitCmd(const std::string& pathToTask, + InitCmd(const std::string& pathToTask, const std::string& jobsPassword, const std::string& process_or_remote_id, int try_no, const std::vector& vec = {}) - : TaskCmd(pathToTask,jobsPassword,process_or_remote_id,try_no), var_to_add_(vec) {} + : TaskCmd(pathToTask, jobsPassword, process_or_remote_id, try_no), + var_to_add_(vec) {} + + InitCmd() : TaskCmd() {} - InitCmd() : TaskCmd() {} + const std::vector& variables_to_add() const { return var_to_add_; } - const std::vector& variables_to_add() const { return var_to_add_;} + void print(std::string&) const override; + bool equals(ClientToServerCmd*) const override; - void print(std::string&) const override; - bool equals(ClientToServerCmd*) const override; + const char* theArg() const override { return arg(); } + void addOption(boost::program_options::options_description& desc) const override; + void create(Cmd_ptr& cmd, boost::program_options::variables_map& vm, AbstractClientEnv* clientEnv) const override; - const char* theArg() const override { return arg();} - void addOption(boost::program_options::options_description& desc) const override; - void create( Cmd_ptr& cmd, - boost::program_options::variables_map& vm, - AbstractClientEnv* clientEnv ) const override; private: - static const char* arg(); // used for argument parsing - static const char* desc(); // The description of the argument as provided to user + static const char* arg(); // used for argument parsing + static const char* desc(); // The description of the argument as provided to user - STC_Cmd_ptr doHandleRequest(AbstractServer*) const override; - ecf::Child::CmdType child_type() const override { return ecf::Child::INIT; } + STC_Cmd_ptr doHandleRequest(AbstractServer*) const override; + ecf::Child::CmdType child_type() const override { return ecf::Child::INIT; } private: - std::vector var_to_add_; - - friend class cereal::access; - template - void serialize(Archive & ar, std::uint32_t const /*version*/ ) - { - ar(cereal::base_class< TaskCmd >( this )); - CEREAL_OPTIONAL_NVP(ar, var_to_add_, [this](){return !var_to_add_.empty(); }); // conditionally save - } + std::vector var_to_add_; + + friend class cereal::access; + template + void serialize(Archive& ar, std::uint32_t const /*version*/) { + ar(cereal::base_class(this)); + CEREAL_OPTIONAL_NVP(ar, var_to_add_, [this]() { return !var_to_add_.empty(); }); // conditionally save + } }; class CompleteCmd final : public TaskCmd { public: - CompleteCmd(const std::string& pathToTask, - const std::string& jobsPassword, - const std::string& process_or_remote_id = "", - int try_no = 1, - const std::vector& vec = std::vector()) - : TaskCmd(pathToTask,jobsPassword,process_or_remote_id,try_no), var_to_del_(vec) {} - CompleteCmd() : TaskCmd() {} - - const std::vector& variables_to_delete() const { return var_to_del_;} - - void print(std::string&) const override; - bool equals(ClientToServerCmd*) const override; - - const char* theArg() const override { return arg();} - void addOption(boost::program_options::options_description& desc) const override; - void create( Cmd_ptr& cmd, - boost::program_options::variables_map& vm, - AbstractClientEnv* clientEnv ) const override; + CompleteCmd(const std::string& pathToTask, + const std::string& jobsPassword, + const std::string& process_or_remote_id = "", + int try_no = 1, + const std::vector& vec = std::vector()) + : TaskCmd(pathToTask, jobsPassword, process_or_remote_id, try_no), + var_to_del_(vec) {} + CompleteCmd() : TaskCmd() {} + + const std::vector& variables_to_delete() const { return var_to_del_; } + + void print(std::string&) const override; + bool equals(ClientToServerCmd*) const override; + + const char* theArg() const override { return arg(); } + void addOption(boost::program_options::options_description& desc) const override; + void create(Cmd_ptr& cmd, boost::program_options::variables_map& vm, AbstractClientEnv* clientEnv) const override; + private: - static const char* arg(); // used for argument parsing - static const char* desc(); // The description of the argument as provided to user + static const char* arg(); // used for argument parsing + static const char* desc(); // The description of the argument as provided to user - STC_Cmd_ptr doHandleRequest(AbstractServer*) const override; - ecf::Child::CmdType child_type() const override { return ecf::Child::COMPLETE; } + STC_Cmd_ptr doHandleRequest(AbstractServer*) const override; + ecf::Child::CmdType child_type() const override { return ecf::Child::COMPLETE; } private: - std::vector var_to_del_; // variables to delete on task - - friend class cereal::access; - template - void serialize(Archive & ar, std::uint32_t const /*version*/ ) - { - ar(cereal::base_class< TaskCmd >( this )); - CEREAL_OPTIONAL_NVP(ar, var_to_del_, [this](){return !var_to_del_.empty(); }); // conditionally save - } + std::vector var_to_del_; // variables to delete on task + + friend class cereal::access; + template + void serialize(Archive& ar, std::uint32_t const /*version*/) { + ar(cereal::base_class(this)); + CEREAL_OPTIONAL_NVP(ar, var_to_del_, [this]() { return !var_to_del_.empty(); }); // conditionally save + } }; /// A child command that evaluates a expression. If the expression is false. /// Then client invoker will block. class CtsWaitCmd final : public TaskCmd { public: - CtsWaitCmd(const std::string& pathToTask, - const std::string& jobsPassword, - const std::string& process_or_remote_id, - int try_no, - const std::string& expression); - CtsWaitCmd() : TaskCmd() {} + CtsWaitCmd(const std::string& pathToTask, + const std::string& jobsPassword, + const std::string& process_or_remote_id, + int try_no, + const std::string& expression); + CtsWaitCmd() : TaskCmd() {} - const std::string& expression() const { return expression_;} + const std::string& expression() const { return expression_; } - void print(std::string&) const override; - bool equals(ClientToServerCmd*) const override; + void print(std::string&) const override; + bool equals(ClientToServerCmd*) const override; - const char* theArg() const override { return arg();} - void addOption(boost::program_options::options_description& desc) const override; - void create( Cmd_ptr& cmd, - boost::program_options::variables_map& vm, - AbstractClientEnv* clientEnv ) const override; -private: + const char* theArg() const override { return arg(); } + void addOption(boost::program_options::options_description& desc) const override; + void create(Cmd_ptr& cmd, boost::program_options::variables_map& vm, AbstractClientEnv* clientEnv) const override; - static const char* arg(); // used for argument parsing - static const char* desc(); // The description of the argument as provided to user +private: + static const char* arg(); // used for argument parsing + static const char* desc(); // The description of the argument as provided to user - STC_Cmd_ptr doHandleRequest(AbstractServer*) const override; - ecf::Child::CmdType child_type() const override { return ecf::Child::WAIT; } + STC_Cmd_ptr doHandleRequest(AbstractServer*) const override; + ecf::Child::CmdType child_type() const override { return ecf::Child::WAIT; } - std::string expression_; + std::string expression_; - friend class cereal::access; - template - void serialize(Archive & ar, std::uint32_t const /*version*/ ) - { - ar(cereal::base_class< TaskCmd >( this ), - CEREAL_NVP(expression_)); - } + friend class cereal::access; + template + void serialize(Archive& ar, std::uint32_t const /*version*/) { + ar(cereal::base_class(this), CEREAL_NVP(expression_)); + } }; class AbortCmd final : public TaskCmd { public: - AbortCmd(const std::string& pathToTask, - const std::string& jobsPassword, - const std::string& process_or_remote_id, - int try_no = 1, - const std::string& reason = ""); - AbortCmd() : TaskCmd() {} + AbortCmd(const std::string& pathToTask, + const std::string& jobsPassword, + const std::string& process_or_remote_id, + int try_no = 1, + const std::string& reason = ""); + AbortCmd() : TaskCmd() {} + + const std::string& reason() const { return reason_; } - const std::string& reason() const {return reason_; } + void print(std::string&) const override; + bool equals(ClientToServerCmd*) const override; - void print(std::string&) const override; - bool equals(ClientToServerCmd*) const override; + const char* theArg() const override { return arg(); } + void addOption(boost::program_options::options_description& desc) const override; + void create(Cmd_ptr& cmd, boost::program_options::variables_map& vm, AbstractClientEnv* clientEnv) const override; - const char* theArg() const override { return arg();} - void addOption(boost::program_options::options_description& desc) const override; - void create( Cmd_ptr& cmd, - boost::program_options::variables_map& vm, - AbstractClientEnv* clientEnv ) const override; private: - static const char* arg(); // used for argument parsing - static const char* desc(); // The description of the argument as provided to user + static const char* arg(); // used for argument parsing + static const char* desc(); // The description of the argument as provided to user - STC_Cmd_ptr doHandleRequest(AbstractServer*) const override; - ecf::Child::CmdType child_type() const override { return ecf::Child::ABORT; } + STC_Cmd_ptr doHandleRequest(AbstractServer*) const override; + ecf::Child::CmdType child_type() const override { return ecf::Child::ABORT; } - std::string reason_; + std::string reason_; - friend class cereal::access; - template - void serialize(Archive & ar, std::uint32_t const /*version*/ ) - { - ar(cereal::base_class< TaskCmd >( this ), - CEREAL_NVP(reason_)); - } + friend class cereal::access; + template + void serialize(Archive& ar, std::uint32_t const /*version*/) { + ar(cereal::base_class(this), CEREAL_NVP(reason_)); + } }; class EventCmd final : public TaskCmd { public: - EventCmd(const std::string& pathToTask, - const std::string& jobsPassword, - const std::string& process_or_remote_id, - int try_no, - const std::string& eventName, - bool value = true) // true = set(default), false = clear - : TaskCmd(pathToTask,jobsPassword,process_or_remote_id,try_no),name_(eventName),value_(value) {} - EventCmd() : TaskCmd() {} - - const std::string& name() const { return name_; } - bool value() const { return value_; } - - void print(std::string&) const override; - bool equals(ClientToServerCmd*) const override; - - const char* theArg() const override { return arg();} - void addOption(boost::program_options::options_description& desc) const override; - void create( Cmd_ptr& cmd, - boost::program_options::variables_map& vm, - AbstractClientEnv* clientEnv ) const override; + EventCmd(const std::string& pathToTask, + const std::string& jobsPassword, + const std::string& process_or_remote_id, + int try_no, + const std::string& eventName, + bool value = true) // true = set(default), false = clear + : TaskCmd(pathToTask, jobsPassword, process_or_remote_id, try_no), + name_(eventName), + value_(value) {} + EventCmd() : TaskCmd() {} + + const std::string& name() const { return name_; } + bool value() const { return value_; } + + void print(std::string&) const override; + bool equals(ClientToServerCmd*) const override; + + const char* theArg() const override { return arg(); } + void addOption(boost::program_options::options_description& desc) const override; + void create(Cmd_ptr& cmd, boost::program_options::variables_map& vm, AbstractClientEnv* clientEnv) const override; + private: - static const char* arg(); // used for argument parsing - static const char* desc(); // The description of the argument as provided to user + static const char* arg(); // used for argument parsing + static const char* desc(); // The description of the argument as provided to user - STC_Cmd_ptr doHandleRequest(AbstractServer*) const override; - ecf::Child::CmdType child_type() const override { return ecf::Child::EVENT; } + STC_Cmd_ptr doHandleRequest(AbstractServer*) const override; + ecf::Child::CmdType child_type() const override { return ecf::Child::EVENT; } private: - std::string name_; // the events name - bool value_{true}; // true = set(default), false = clear - - friend class cereal::access; - template - void serialize(Archive & ar, std::uint32_t const /*version*/ ) - { - ar(cereal::base_class< TaskCmd >( this ), CEREAL_NVP(name_)); - CEREAL_OPTIONAL_NVP(ar, value_, [this](){return !value_;}); // conditionally save if value is false - } + std::string name_; // the events name + bool value_{true}; // true = set(default), false = clear + + friend class cereal::access; + template + void serialize(Archive& ar, std::uint32_t const /*version*/) { + ar(cereal::base_class(this), CEREAL_NVP(name_)); + CEREAL_OPTIONAL_NVP(ar, value_, [this]() { return !value_; }); // conditionally save if value is false + } }; class MeterCmd final : public TaskCmd { public: - MeterCmd(const std::string& pathToTask, - const std::string& jobsPassword, - const std::string& process_or_remote_id, - int try_no, - const std::string& meterName, - int meterValue) - : TaskCmd(pathToTask,jobsPassword,process_or_remote_id,try_no), name_(meterName), value_(meterValue) {} - MeterCmd() : TaskCmd() {} - - const std::string& name() const { return name_; } - int value() const { return value_; } - - void print(std::string&) const override; - bool equals(ClientToServerCmd*) const override; - - const char* theArg() const override { return arg();} - void addOption(boost::program_options::options_description& desc) const override; - void create( Cmd_ptr& cmd, - boost::program_options::variables_map& vm, - AbstractClientEnv* clientEnv ) const override; + MeterCmd(const std::string& pathToTask, + const std::string& jobsPassword, + const std::string& process_or_remote_id, + int try_no, + const std::string& meterName, + int meterValue) + : TaskCmd(pathToTask, jobsPassword, process_or_remote_id, try_no), + name_(meterName), + value_(meterValue) {} + MeterCmd() : TaskCmd() {} + + const std::string& name() const { return name_; } + int value() const { return value_; } + + void print(std::string&) const override; + bool equals(ClientToServerCmd*) const override; + + const char* theArg() const override { return arg(); } + void addOption(boost::program_options::options_description& desc) const override; + void create(Cmd_ptr& cmd, boost::program_options::variables_map& vm, AbstractClientEnv* clientEnv) const override; + private: - static const char* arg(); // used for argument parsing - static const char* desc(); // The description of the argument as provided to user + static const char* arg(); // used for argument parsing + static const char* desc(); // The description of the argument as provided to user - STC_Cmd_ptr doHandleRequest(AbstractServer*) const override; - ecf::Child::CmdType child_type() const override { return ecf::Child::METER; } + STC_Cmd_ptr doHandleRequest(AbstractServer*) const override; + ecf::Child::CmdType child_type() const override { return ecf::Child::METER; } private: - std::string name_; // the meters name - int value_{0}; // the meters value - - friend class cereal::access; - template - void serialize(Archive & ar, std::uint32_t const /*version*/ ) - { - ar(cereal::base_class< TaskCmd >( this ), - CEREAL_NVP(name_), - CEREAL_NVP(value_)); - } + std::string name_; // the meters name + int value_{0}; // the meters value + + friend class cereal::access; + template + void serialize(Archive& ar, std::uint32_t const /*version*/) { + ar(cereal::base_class(this), CEREAL_NVP(name_), CEREAL_NVP(value_)); + } }; - class LabelCmd final : public TaskCmd { public: - LabelCmd(const std::string& pathToTask, - const std::string& jobsPassword, - const std::string& process_or_remote_id, - int try_no, - const std::string& name, - const std::string& label) - : TaskCmd(pathToTask,jobsPassword,process_or_remote_id,try_no), name_(name), label_(label) {} - LabelCmd() : TaskCmd() {} - - const std::string& name() const { return name_; } - const std::string& label() const { return label_;} - - void print(std::string&) const override; - bool equals(ClientToServerCmd*) const override; - - const char* theArg() const override { return arg();} - void addOption(boost::program_options::options_description& desc) const override; - void create( Cmd_ptr& cmd, - boost::program_options::variables_map& vm, - AbstractClientEnv* clientEnv ) const override; + LabelCmd(const std::string& pathToTask, + const std::string& jobsPassword, + const std::string& process_or_remote_id, + int try_no, + const std::string& name, + const std::string& label) + : TaskCmd(pathToTask, jobsPassword, process_or_remote_id, try_no), + name_(name), + label_(label) {} + LabelCmd() : TaskCmd() {} + + const std::string& name() const { return name_; } + const std::string& label() const { return label_; } + + void print(std::string&) const override; + bool equals(ClientToServerCmd*) const override; + + const char* theArg() const override { return arg(); } + void addOption(boost::program_options::options_description& desc) const override; + void create(Cmd_ptr& cmd, boost::program_options::variables_map& vm, AbstractClientEnv* clientEnv) const override; + private: - static const char* arg(); // used for argument parsing - static const char* desc(); // The description of the argument as provided to user + static const char* arg(); // used for argument parsing + static const char* desc(); // The description of the argument as provided to user - STC_Cmd_ptr doHandleRequest(AbstractServer*) const override; - ecf::Child::CmdType child_type() const override { return ecf::Child::LABEL; } + STC_Cmd_ptr doHandleRequest(AbstractServer*) const override; + ecf::Child::CmdType child_type() const override { return ecf::Child::LABEL; } private: - std::string name_; // the label name - std::string label_; // a single label, or multi-line label - - friend class cereal::access; - template - void serialize(Archive & ar, std::uint32_t const /*version*/ ) - { - ar(cereal::base_class< TaskCmd >( this ), - CEREAL_NVP(name_), - CEREAL_NVP(label_)); - } + std::string name_; // the label name + std::string label_; // a single label, or multi-line label + + friend class cereal::access; + template + void serialize(Archive& ar, std::uint32_t const /*version*/) { + ar(cereal::base_class(this), CEREAL_NVP(name_), CEREAL_NVP(label_)); + } }; class QueueAttr; class QueueCmd final : public TaskCmd { public: - QueueCmd(const std::string& pathToTask, - const std::string& jobsPassword, - const std::string& process_or_remote_id, - int try_no, - const std::string& queueName, - const std::string& action, - const std::string& step = "", - const std::string& path_to_node_with_queue = "") // if empty search for queue up node tree - : TaskCmd(pathToTask,jobsPassword,process_or_remote_id,try_no), - name_(queueName),action_(action),step_(step),path_to_node_with_queue_(path_to_node_with_queue) {} - QueueCmd() : TaskCmd() {} - - const std::string& name() const { return name_; } - const std::string& action() const { return action_; } - const std::string& step() const { return step_; } - const std::string& path_to_node_with_queue() const { return path_to_node_with_queue_; } - - void print(std::string&) const override; - bool equals(ClientToServerCmd*) const override; - - const char* theArg() const override { return arg();} - void addOption(boost::program_options::options_description& desc) const override; - void create( Cmd_ptr& cmd, - boost::program_options::variables_map& vm, - AbstractClientEnv* clientEnv ) const override; + QueueCmd(const std::string& pathToTask, + const std::string& jobsPassword, + const std::string& process_or_remote_id, + int try_no, + const std::string& queueName, + const std::string& action, + const std::string& step = "", + const std::string& path_to_node_with_queue = "") // if empty search for queue up node tree + : TaskCmd(pathToTask, jobsPassword, process_or_remote_id, try_no), + name_(queueName), + action_(action), + step_(step), + path_to_node_with_queue_(path_to_node_with_queue) {} + QueueCmd() : TaskCmd() {} + + const std::string& name() const { return name_; } + const std::string& action() const { return action_; } + const std::string& step() const { return step_; } + const std::string& path_to_node_with_queue() const { return path_to_node_with_queue_; } + + void print(std::string&) const override; + bool equals(ClientToServerCmd*) const override; + + const char* theArg() const override { return arg(); } + void addOption(boost::program_options::options_description& desc) const override; + void create(Cmd_ptr& cmd, boost::program_options::variables_map& vm, AbstractClientEnv* clientEnv) const override; + private: - static const char* arg(); // used for argument parsing - static const char* desc(); // The description of the argument as provided to user + static const char* arg(); // used for argument parsing + static const char* desc(); // The description of the argument as provided to user - STC_Cmd_ptr doHandleRequest(AbstractServer*) const override; - ecf::Child::CmdType child_type() const override { return ecf::Child::QUEUE; } + STC_Cmd_ptr doHandleRequest(AbstractServer*) const override; + ecf::Child::CmdType child_type() const override { return ecf::Child::QUEUE; } - std::string handle_queue(QueueAttr& queue_attr) const; + std::string handle_queue(QueueAttr& queue_attr) const; private: - std::string name_; // the queue name - std::string action_; // [ active | aborted | complete | no_of_aborted ] - std::string step_; // will be empty when action is [ active | no_of_aborted] - std::string path_to_node_with_queue_; - - friend class cereal::access; - template - void serialize(Archive & ar, std::uint32_t const /*version*/ ) - { - ar(cereal::base_class< TaskCmd >( this ), - CEREAL_NVP(name_), - CEREAL_NVP(action_), - CEREAL_NVP(step_), - CEREAL_NVP(path_to_node_with_queue_)); - } + std::string name_; // the queue name + std::string action_; // [ active | aborted | complete | no_of_aborted ] + std::string step_; // will be empty when action is [ active | no_of_aborted] + std::string path_to_node_with_queue_; + + friend class cereal::access; + template + void serialize(Archive& ar, std::uint32_t const /*version*/) { + ar(cereal::base_class(this), + CEREAL_NVP(name_), + CEREAL_NVP(action_), + CEREAL_NVP(step_), + CEREAL_NVP(path_to_node_with_queue_)); + } }; //================================================================================= @@ -613,51 +609,47 @@ class QueueCmd final : public TaskCmd { // ================================================================================ class UserCmd : public ClientToServerCmd { public: - UserCmd()= default; + UserCmd() = default; - const std::string& user() const { return user_;} - const std::string& passwd() const { return pswd_;} + const std::string& user() const { return user_; } + const std::string& passwd() const { return pswd_; } - void setup_user_authentification(const std::string& user, const std::string& passwd) override; - bool setup_user_authentification(AbstractClientEnv&) override; - void setup_user_authentification() override; + void setup_user_authentification(const std::string& user, const std::string& passwd) override; + bool setup_user_authentification(AbstractClientEnv&) override; + void setup_user_authentification() override; protected: + bool equals(ClientToServerCmd*) const override; + bool authenticate(AbstractServer*, STC_Cmd_ptr&) const override; + bool do_authenticate(AbstractServer* as, STC_Cmd_ptr&, const std::string& path) const; + bool do_authenticate(AbstractServer* as, STC_Cmd_ptr&, const std::vector& paths) const; - bool equals(ClientToServerCmd*) const override; - bool authenticate(AbstractServer*, STC_Cmd_ptr&) const override; - bool do_authenticate(AbstractServer* as, STC_Cmd_ptr&, const std::string& path) const; - bool do_authenticate(AbstractServer* as, STC_Cmd_ptr&, const std::vector& paths) const; + /// Prompt the user for confirmation: If user responds with no, will exit client + static void prompt_for_confirmation(const std::string& prompt); - /// Prompt the user for confirmation: If user responds with no, will exit client - static void prompt_for_confirmation(const std::string& prompt); + /// All user commands will be pre_fixed with "--" and post_fixed with :user@host + void user_cmd(std::string& os, const std::string& the_cmd) const; - /// All user commands will be pre_fixed with "--" and post_fixed with :user@host - void user_cmd(std::string& os, const std::string& the_cmd) const; + static int time_out_for_load_sync_and_get(); - - static int time_out_for_load_sync_and_get(); - - // The order is preserved during the split. Paths assumed to start with '/' char - static void split_args_to_options_and_paths( - const std::vector& args, - std::vector& options, - std::vector& paths, - bool treat_colon_in_path_as_path = false); + // The order is preserved during the split. Paths assumed to start with '/' char + static void split_args_to_options_and_paths(const std::vector& args, + std::vector& options, + std::vector& paths, + bool treat_colon_in_path_as_path = false); private: - std::string user_; - std::string pswd_; - bool cu_ = false; // custom user, i.e used set_user_name() || ECF_USER || --user -> only check this password - - friend class cereal::access; - template - void serialize(Archive & ar, std::uint32_t const /*version*/ ) - { - ar(cereal::base_class< ClientToServerCmd >( this ), CEREAL_NVP(user_)); - CEREAL_OPTIONAL_NVP(ar, pswd_, [this](){return !pswd_.empty(); }); // conditionally save - CEREAL_OPTIONAL_NVP(ar, cu_, [this](){return cu_; }); // conditionally save - } + std::string user_; + std::string pswd_; + bool cu_ = false; // custom user, i.e used set_user_name() || ECF_USER || --user -> only check this password + + friend class cereal::access; + template + void serialize(Archive& ar, std::uint32_t const /*version*/) { + ar(cereal::base_class(this), CEREAL_NVP(user_)); + CEREAL_OPTIONAL_NVP(ar, pswd_, [this]() { return !pswd_.empty(); }); // conditionally save + CEREAL_OPTIONAL_NVP(ar, cu_, [this]() { return cu_; }); // conditionally save + } }; // ======================================================================== @@ -666,27 +658,24 @@ class UserCmd : public ClientToServerCmd { // ======================================================================== class ServerVersionCmd final : public UserCmd { public: - ServerVersionCmd()= default; - - void print(std::string&) const override; - void print_only(std::string&) const override; - bool equals(ClientToServerCmd*) const override; - const char* theArg() const override; - void addOption(boost::program_options::options_description& desc) const override; - void create( Cmd_ptr& cmd, - boost::program_options::variables_map& vm, - AbstractClientEnv* clientEnv ) const override; + ServerVersionCmd() = default; + + void print(std::string&) const override; + void print_only(std::string&) const override; + bool equals(ClientToServerCmd*) const override; + const char* theArg() const override; + void addOption(boost::program_options::options_description& desc) const override; + void create(Cmd_ptr& cmd, boost::program_options::variables_map& vm, AbstractClientEnv* clientEnv) const override; + private: - STC_Cmd_ptr doHandleRequest(AbstractServer*) const override; - - friend class cereal::access; - template - void serialize(Archive & ar, std::uint32_t const /*version*/ ) - { - ar(cereal::base_class< UserCmd >( this )); - } -}; + STC_Cmd_ptr doHandleRequest(AbstractServer*) const override; + friend class cereal::access; + template + void serialize(Archive& ar, std::uint32_t const /*version*/) { + ar(cereal::base_class(this)); + } +}; // This command is used to encapsulate all commands that are // simple signals to the server. This helps to cut down on the @@ -701,232 +690,221 @@ class ServerVersionCmd final : public UserCmd { // ========================================================================= class CtsCmd final : public UserCmd { public: - enum Api { NO_CMD, RESTORE_DEFS_FROM_CHECKPT, - RESTART_SERVER, SHUTDOWN_SERVER, HALT_SERVER, TERMINATE_SERVER, - RELOAD_WHITE_LIST_FILE, - FORCE_DEP_EVAL, - PING, GET_ZOMBIES, STATS, SUITES, - DEBUG_SERVER_ON, DEBUG_SERVER_OFF, - SERVER_LOAD, STATS_RESET, - RELOAD_PASSWD_FILE, - STATS_SERVER, - RELOAD_CUSTOM_PASSWD_FILE - }; - - explicit CtsCmd(Api a) : api_(a) {} - CtsCmd()= default; - - Api api() const { return api_;} - - void print(std::string&) const override; - void print_only(std::string&) const override; - bool equals(ClientToServerCmd*) const override; - - bool isWrite() const override; - bool cmd_updates_defs() const override; - bool terminate_cmd() const override { return api_ == TERMINATE_SERVER; } - bool ping_cmd() const override { return api_ == PING; } - int timeout() const override; - - bool handleRequestIsTestable() const override; - - const char* theArg() const override; - void addOption(boost::program_options::options_description& desc) const override; - void create( Cmd_ptr& cmd, - boost::program_options::variables_map& vm, - AbstractClientEnv* clientEnv ) const override; + enum Api { + NO_CMD, + RESTORE_DEFS_FROM_CHECKPT, + RESTART_SERVER, + SHUTDOWN_SERVER, + HALT_SERVER, + TERMINATE_SERVER, + RELOAD_WHITE_LIST_FILE, + FORCE_DEP_EVAL, + PING, + GET_ZOMBIES, + STATS, + SUITES, + DEBUG_SERVER_ON, + DEBUG_SERVER_OFF, + SERVER_LOAD, + STATS_RESET, + RELOAD_PASSWD_FILE, + STATS_SERVER, + RELOAD_CUSTOM_PASSWD_FILE + }; + + explicit CtsCmd(Api a) : api_(a) {} + CtsCmd() = default; + + Api api() const { return api_; } + + void print(std::string&) const override; + void print_only(std::string&) const override; + bool equals(ClientToServerCmd*) const override; + + bool isWrite() const override; + bool cmd_updates_defs() const override; + bool terminate_cmd() const override { return api_ == TERMINATE_SERVER; } + bool ping_cmd() const override { return api_ == PING; } + int timeout() const override; + + bool handleRequestIsTestable() const override; + + const char* theArg() const override; + void addOption(boost::program_options::options_description& desc) const override; + void create(Cmd_ptr& cmd, boost::program_options::variables_map& vm, AbstractClientEnv* clientEnv) const override; + private: - STC_Cmd_ptr doHandleRequest(AbstractServer*) const override; + STC_Cmd_ptr doHandleRequest(AbstractServer*) const override; - Api api_{NO_CMD}; + Api api_{NO_CMD}; - friend class cereal::access; - template - void serialize(Archive & ar, std::uint32_t const /*version*/ ) - { - ar(cereal::base_class< UserCmd >( this ), - CEREAL_NVP(api_)); - } + friend class cereal::access; + template + void serialize(Archive& ar, std::uint32_t const /*version*/) { + ar(cereal::base_class(this), CEREAL_NVP(api_)); + } }; class CheckPtCmd final : public UserCmd { public: - CheckPtCmd(ecf::CheckPt::Mode m, int interval,int checkpt_save_time_alarm) - : mode_(m), check_pt_interval_(interval),check_pt_save_time_alarm_(checkpt_save_time_alarm) {} - CheckPtCmd() = default; - - ecf::CheckPt::Mode mode() const { return mode_;} - int check_pt_interval() const { return check_pt_interval_;} - int check_pt_save_time_alarm() const { return check_pt_save_time_alarm_;} - - void print(std::string&) const override; - void print_only(std::string&) const override; - bool equals(ClientToServerCmd*) const override; - bool isWrite() const override; - bool is_mutable() const override; - const char* theArg() const override; - void addOption(boost::program_options::options_description& desc) const override; - void create( Cmd_ptr& cmd, - boost::program_options::variables_map& vm, - AbstractClientEnv* clientEnv ) const override; + CheckPtCmd(ecf::CheckPt::Mode m, int interval, int checkpt_save_time_alarm) + : mode_(m), + check_pt_interval_(interval), + check_pt_save_time_alarm_(checkpt_save_time_alarm) {} + CheckPtCmd() = default; + + ecf::CheckPt::Mode mode() const { return mode_; } + int check_pt_interval() const { return check_pt_interval_; } + int check_pt_save_time_alarm() const { return check_pt_save_time_alarm_; } + + void print(std::string&) const override; + void print_only(std::string&) const override; + bool equals(ClientToServerCmd*) const override; + bool isWrite() const override; + bool is_mutable() const override; + const char* theArg() const override; + void addOption(boost::program_options::options_description& desc) const override; + void create(Cmd_ptr& cmd, boost::program_options::variables_map& vm, AbstractClientEnv* clientEnv) const override; + private: - STC_Cmd_ptr doHandleRequest(AbstractServer*) const override; + STC_Cmd_ptr doHandleRequest(AbstractServer*) const override; private: - ecf::CheckPt::Mode mode_{ecf::CheckPt::UNDEFINED}; - int check_pt_interval_{0}; - int check_pt_save_time_alarm_{0}; - - friend class cereal::access; - template - void serialize(Archive & ar, std::uint32_t const /*version*/ ) - { - ar(cereal::base_class< UserCmd >( this ), - CEREAL_NVP(mode_), - CEREAL_NVP(check_pt_interval_), - CEREAL_NVP(check_pt_save_time_alarm_)); - } + ecf::CheckPt::Mode mode_{ecf::CheckPt::UNDEFINED}; + int check_pt_interval_{0}; + int check_pt_save_time_alarm_{0}; + + friend class cereal::access; + template + void serialize(Archive& ar, std::uint32_t const /*version*/) { + ar(cereal::base_class(this), + CEREAL_NVP(mode_), + CEREAL_NVP(check_pt_interval_), + CEREAL_NVP(check_pt_save_time_alarm_)); + } }; - // Client---(CSyncCmd::SYNC_FULL)---->Server-----(SSyncCmd)--->client: // Client---(CSyncCmd::SYNC)--------->Server-----(SSyncCmd)--->client: // Client---(CSyncCmd::SYNC_CLOCK)--->Server-----(SSyncCmd)--->client: // Client---(CSyncCmd::NEWS)--------->Server-----(SNewsCmd)--->client: class CSyncCmd final : public UserCmd { public: - enum Api { NEWS, SYNC, SYNC_FULL, SYNC_CLOCK}; - - CSyncCmd(Api a, unsigned int client_handle,unsigned int client_state_change_no, unsigned int client_modify_change_no) - : api_(a), - client_handle_(client_handle), - client_state_change_no_(client_state_change_no), - client_modify_change_no_(client_modify_change_no) {} - explicit CSyncCmd(unsigned int client_handle) - : api_(SYNC_FULL), - client_handle_(client_handle) - {} - CSyncCmd()= default; - - Api api() const { return api_;} - int client_state_change_no() const { return client_state_change_no_;} - int client_modify_change_no() const { return client_modify_change_no_;} - int client_handle() const { return client_handle_;} - - void set_client_handle(int client_handle) override { client_handle_ = client_handle;} // used by group_cmd - void print(std::string&) const override; - std::string print_short() const override; - void print_only(std::string&) const override; - bool equals(ClientToServerCmd*) const override; - int timeout() const override; - - const char* theArg() const override; - void addOption(boost::program_options::options_description& desc) const override; - void create( Cmd_ptr& cmd, - boost::program_options::variables_map& vm, - AbstractClientEnv* clientEnv ) const override; -private: + enum Api { NEWS, SYNC, SYNC_FULL, SYNC_CLOCK }; + + CSyncCmd(Api a, + unsigned int client_handle, + unsigned int client_state_change_no, + unsigned int client_modify_change_no) + : api_(a), + client_handle_(client_handle), + client_state_change_no_(client_state_change_no), + client_modify_change_no_(client_modify_change_no) {} + explicit CSyncCmd(unsigned int client_handle) : api_(SYNC_FULL), client_handle_(client_handle) {} + CSyncCmd() = default; + + Api api() const { return api_; } + int client_state_change_no() const { return client_state_change_no_; } + int client_modify_change_no() const { return client_modify_change_no_; } + int client_handle() const { return client_handle_; } + + void set_client_handle(int client_handle) override { client_handle_ = client_handle; } // used by group_cmd + void print(std::string&) const override; + std::string print_short() const override; + void print_only(std::string&) const override; + bool equals(ClientToServerCmd*) const override; + int timeout() const override; + + const char* theArg() const override; + void addOption(boost::program_options::options_description& desc) const override; + void create(Cmd_ptr& cmd, boost::program_options::variables_map& vm, AbstractClientEnv* clientEnv) const override; - /// Custom handling of command logging to add additional debug on same line - /// makes it easier to debug errors in syncing. - void do_log(AbstractServer*) const override; - - STC_Cmd_ptr doHandleRequest(AbstractServer*) const override; - - Api api_{SYNC}; - int client_handle_{0}; - int client_state_change_no_{0}; - int client_modify_change_no_{0}; - - friend class cereal::access; - template - void serialize(Archive & ar, std::uint32_t const /*version*/ ) - { - ar(cereal::base_class< UserCmd >( this ), - CEREAL_NVP(api_), - CEREAL_NVP(client_handle_), - CEREAL_NVP(client_state_change_no_), - CEREAL_NVP(client_modify_change_no_)); - } +private: + /// Custom handling of command logging to add additional debug on same line + /// makes it easier to debug errors in syncing. + void do_log(AbstractServer*) const override; + + STC_Cmd_ptr doHandleRequest(AbstractServer*) const override; + + Api api_{SYNC}; + int client_handle_{0}; + int client_state_change_no_{0}; + int client_modify_change_no_{0}; + + friend class cereal::access; + template + void serialize(Archive& ar, std::uint32_t const /*version*/) { + ar(cereal::base_class(this), + CEREAL_NVP(api_), + CEREAL_NVP(client_handle_), + CEREAL_NVP(client_state_change_no_), + CEREAL_NVP(client_modify_change_no_)); + } }; class ClientHandleCmd final : public UserCmd { public: - enum Api { REGISTER, DROP, DROP_USER, ADD, REMOVE, AUTO_ADD , SUITES }; - - explicit ClientHandleCmd(Api api = AUTO_ADD) - : api_(api) {} - - ClientHandleCmd(int client_handle,const std::vector& suites, bool add_add_new_suites) - : api_(REGISTER), - client_handle_(client_handle), - suites_(suites), - auto_add_new_suites_(add_add_new_suites) - {} - - explicit ClientHandleCmd(int client_handle) - : api_(DROP), - client_handle_(client_handle) - {} - - explicit ClientHandleCmd(const std::string& drop_user) - : api_(DROP_USER), - drop_user_(drop_user) - {} - - ClientHandleCmd(int client_handle, const std::vector& suites, Api api) - : api_(api), // Must be ADD or REMOVE - client_handle_(client_handle), - suites_(suites) - {} - - ClientHandleCmd(int client_handle, bool add_add_new_suites) - : api_(AUTO_ADD), - client_handle_(client_handle), - auto_add_new_suites_(add_add_new_suites) - {} - - Api api() const { return api_;} - const std::string& drop_user() const { return drop_user_;} - - bool cmd_updates_defs() const override; - void print(std::string&) const override; - void print_only(std::string&) const override; - bool equals(ClientToServerCmd*) const override; - - const char* theArg() const override; - void addOption(boost::program_options::options_description& desc) const override; - void create( Cmd_ptr& cmd, - boost::program_options::variables_map& vm, - AbstractClientEnv* clientEnv ) const override; - - // called in the server - void set_group_cmd(const GroupCTSCmd* cmd) override { group_cmd_ = cmd;} + enum Api { REGISTER, DROP, DROP_USER, ADD, REMOVE, AUTO_ADD, SUITES }; + + explicit ClientHandleCmd(Api api = AUTO_ADD) : api_(api) {} + + ClientHandleCmd(int client_handle, const std::vector& suites, bool add_add_new_suites) + : api_(REGISTER), + client_handle_(client_handle), + suites_(suites), + auto_add_new_suites_(add_add_new_suites) {} + + explicit ClientHandleCmd(int client_handle) : api_(DROP), client_handle_(client_handle) {} + + explicit ClientHandleCmd(const std::string& drop_user) : api_(DROP_USER), drop_user_(drop_user) {} + + ClientHandleCmd(int client_handle, const std::vector& suites, Api api) + : api_(api), // Must be ADD or REMOVE + client_handle_(client_handle), + suites_(suites) {} + + ClientHandleCmd(int client_handle, bool add_add_new_suites) + : api_(AUTO_ADD), + client_handle_(client_handle), + auto_add_new_suites_(add_add_new_suites) {} + + Api api() const { return api_; } + const std::string& drop_user() const { return drop_user_; } + + bool cmd_updates_defs() const override; + void print(std::string&) const override; + void print_only(std::string&) const override; + bool equals(ClientToServerCmd*) const override; + + const char* theArg() const override; + void addOption(boost::program_options::options_description& desc) const override; + void create(Cmd_ptr& cmd, boost::program_options::variables_map& vm, AbstractClientEnv* clientEnv) const override; + + // called in the server + void set_group_cmd(const GroupCTSCmd* cmd) override { group_cmd_ = cmd; } private: - STC_Cmd_ptr doHandleRequest(AbstractServer*) const override; - - Api api_; - int client_handle_{0}; - std::string drop_user_; - std::vector suites_; - bool auto_add_new_suites_{false}; - - friend class cereal::access; - template - void serialize(Archive & ar, std::uint32_t const /*version*/ ) - { - ar(cereal::base_class< UserCmd >( this ), - CEREAL_NVP(api_), - CEREAL_NVP(client_handle_), - CEREAL_NVP(drop_user_), - CEREAL_NVP(suites_), - CEREAL_NVP(auto_add_new_suites_) - ); - } + STC_Cmd_ptr doHandleRequest(AbstractServer*) const override; + + Api api_; + int client_handle_{0}; + std::string drop_user_; + std::vector suites_; + bool auto_add_new_suites_{false}; + + friend class cereal::access; + template + void serialize(Archive& ar, std::uint32_t const /*version*/) { + ar(cereal::base_class(this), + CEREAL_NVP(api_), + CEREAL_NVP(client_handle_), + CEREAL_NVP(drop_user_), + CEREAL_NVP(suites_), + CEREAL_NVP(auto_add_new_suites_)); + } private: - const GroupCTSCmd* group_cmd_ = nullptr; // not persisted only used in server + const GroupCTSCmd* group_cmd_ = nullptr; // not persisted only used in server }; // Collection of commands, that all take a abs node path as their only arg @@ -944,492 +922,458 @@ class ClientHandleCmd final : public UserCmd { // if absNodepath is empty we will generate jobs for all tasks class CtsNodeCmd final : public UserCmd { public: - enum Api { NO_CMD, JOB_GEN, CHECK_JOB_GEN_ONLY, GET, WHY, GET_STATE, MIGRATE }; - CtsNodeCmd(Api a, const std::string& absNodePath) : api_(a),absNodePath_(absNodePath) {} - explicit CtsNodeCmd(Api a) : api_(a) { assert(a != NO_CMD); } - CtsNodeCmd()= default; - - Api api() const { return api_;} - const std::string& absNodePath() const { return absNodePath_;} - - void print(std::string&) const override; - void print_only(std::string&) const override; - bool equals(ClientToServerCmd*) const override; - - PrintStyle::Type_t show_style() const override; - - int timeout() const override; - bool isWrite() const override; - bool handleRequestIsTestable() const override { return !terminate_cmd();} - bool why_cmd( std::string& nodePath) const override; - bool get_cmd() const override { return api_ == GET; } - - const char* theArg() const override; - void addOption(boost::program_options::options_description& desc) const override; - void create( Cmd_ptr& cmd, - boost::program_options::variables_map& vm, - AbstractClientEnv* clientEnv ) const override; + enum Api { NO_CMD, JOB_GEN, CHECK_JOB_GEN_ONLY, GET, WHY, GET_STATE, MIGRATE }; + CtsNodeCmd(Api a, const std::string& absNodePath) : api_(a), absNodePath_(absNodePath) {} + explicit CtsNodeCmd(Api a) : api_(a) { assert(a != NO_CMD); } + CtsNodeCmd() = default; + + Api api() const { return api_; } + const std::string& absNodePath() const { return absNodePath_; } + + void print(std::string&) const override; + void print_only(std::string&) const override; + bool equals(ClientToServerCmd*) const override; + + PrintStyle::Type_t show_style() const override; + + int timeout() const override; + bool isWrite() const override; + bool handleRequestIsTestable() const override { return !terminate_cmd(); } + bool why_cmd(std::string& nodePath) const override; + bool get_cmd() const override { return api_ == GET; } + + const char* theArg() const override; + void addOption(boost::program_options::options_description& desc) const override; + void create(Cmd_ptr& cmd, boost::program_options::variables_map& vm, AbstractClientEnv* clientEnv) const override; + private: - STC_Cmd_ptr doHandleRequest(AbstractServer*) const override; - bool authenticate(AbstractServer*, STC_Cmd_ptr&) const override; + STC_Cmd_ptr doHandleRequest(AbstractServer*) const override; + bool authenticate(AbstractServer*, STC_Cmd_ptr&) const override; private: - Api api_{NO_CMD}; - std::string absNodePath_; - - friend class cereal::access; - template - void serialize(Archive & ar, std::uint32_t const /*version*/ ) - { - ar(cereal::base_class< UserCmd >( this ), - CEREAL_NVP(api_), - CEREAL_NVP(absNodePath_)); - } + Api api_{NO_CMD}; + std::string absNodePath_; + + friend class cereal::access; + template + void serialize(Archive& ar, std::uint32_t const /*version*/) { + ar(cereal::base_class(this), CEREAL_NVP(api_), CEREAL_NVP(absNodePath_)); + } }; // DELETE If paths_ empty will delete all suites (beware) else will delete the chosen nodes. class DeleteCmd final : public UserCmd { public: - explicit DeleteCmd(const std::vector& paths, bool force = false) - : group_cmd_(nullptr),paths_(paths),force_(force){} - explicit DeleteCmd(const std::string& absNodePath, bool force = false); - DeleteCmd()= default; + explicit DeleteCmd(const std::vector& paths, bool force = false) + : group_cmd_(nullptr), + paths_(paths), + force_(force) {} + explicit DeleteCmd(const std::string& absNodePath, bool force = false); + DeleteCmd() = default; - const std::vector& paths() const { return paths_;} - bool force() const { return force_;} + const std::vector& paths() const { return paths_; } + bool force() const { return force_; } - void print(std::string&) const override; - void print_only(std::string&) const override; - void print(std::string& os, const std::string& path) const override; + void print(std::string&) const override; + void print_only(std::string&) const override; + void print(std::string& os, const std::string& path) const override; - bool equals(ClientToServerCmd*) const override; - bool isWrite() const override { return true;} + bool equals(ClientToServerCmd*) const override; + bool isWrite() const override { return true; } - const char* theArg() const override; - void addOption(boost::program_options::options_description& desc) const override; - void create( Cmd_ptr& cmd, - boost::program_options::variables_map& vm, - AbstractClientEnv* clientEnv ) const override; + const char* theArg() const override; + void addOption(boost::program_options::options_description& desc) const override; + void create(Cmd_ptr& cmd, boost::program_options::variables_map& vm, AbstractClientEnv* clientEnv) const override; - // called in the server - void set_group_cmd(const GroupCTSCmd* cmd) override { group_cmd_ = cmd;} + // called in the server + void set_group_cmd(const GroupCTSCmd* cmd) override { group_cmd_ = cmd; } - static void check_for_active_or_submitted_tasks(AbstractServer* as,Node* theNodeToDelete); + static void check_for_active_or_submitted_tasks(AbstractServer* as, Node* theNodeToDelete); private: - STC_Cmd_ptr doHandleRequest(AbstractServer*) const override; - bool authenticate(AbstractServer*, STC_Cmd_ptr&) const override; - void cleanup() override { std::vector().swap(paths_);} /// run in the server, after handlerequest + STC_Cmd_ptr doHandleRequest(AbstractServer*) const override; + bool authenticate(AbstractServer*, STC_Cmd_ptr&) const override; + void cleanup() override { std::vector().swap(paths_); } /// run in the server, after handlerequest private: - const GroupCTSCmd* group_cmd_{nullptr}; // not persisted only used in server - std::vector paths_; - bool force_{false}; - - friend class cereal::access; - template - void serialize(Archive & ar, std::uint32_t const /*version*/ ) - { - ar(cereal::base_class< UserCmd >( this ), - CEREAL_NVP(paths_), - CEREAL_NVP(force_) - ); - } + const GroupCTSCmd* group_cmd_{nullptr}; // not persisted only used in server + std::vector paths_; + bool force_{false}; + + friend class cereal::access; + template + void serialize(Archive& ar, std::uint32_t const /*version*/) { + ar(cereal::base_class(this), CEREAL_NVP(paths_), CEREAL_NVP(force_)); + } }; // DELETE If paths_ empty will delete all suites (beware) else will delete the chosen nodes. class PathsCmd final : public UserCmd { public: - enum Api { NO_CMD, SUSPEND, RESUME, KILL, STATUS, CHECK, EDIT_HISTORY, ARCHIVE, RESTORE }; - - PathsCmd(Api api,const std::vector& paths, bool force = false) - : api_(api),paths_(paths),force_(force){} - PathsCmd(Api api,const std::string& absNodePath, bool force = false); - explicit PathsCmd(Api api) - : api_(api) { assert(api != NO_CMD); } - PathsCmd() = default; - - Api api() const { return api_; } - const std::vector& paths() const { return paths_;} - bool force() const { return force_;} - - void print(std::string&) const override; - std::string print_short() const override; - void print_only(std::string&) const override; - void print(std::string& os, const std::string& path) const override; - - bool equals(ClientToServerCmd*) const override; - bool isWrite() const override; - - const char* theArg() const override; - void addOption(boost::program_options::options_description& desc) const override; - void create( Cmd_ptr& cmd, - boost::program_options::variables_map& vm, - AbstractClientEnv* clientEnv ) const override; + enum Api { NO_CMD, SUSPEND, RESUME, KILL, STATUS, CHECK, EDIT_HISTORY, ARCHIVE, RESTORE }; + + PathsCmd(Api api, const std::vector& paths, bool force = false) + : api_(api), + paths_(paths), + force_(force) {} + PathsCmd(Api api, const std::string& absNodePath, bool force = false); + explicit PathsCmd(Api api) : api_(api) { assert(api != NO_CMD); } + PathsCmd() = default; + + Api api() const { return api_; } + const std::vector& paths() const { return paths_; } + bool force() const { return force_; } + + void print(std::string&) const override; + std::string print_short() const override; + void print_only(std::string&) const override; + void print(std::string& os, const std::string& path) const override; + + bool equals(ClientToServerCmd*) const override; + bool isWrite() const override; + + const char* theArg() const override; + void addOption(boost::program_options::options_description& desc) const override; + void create(Cmd_ptr& cmd, boost::program_options::variables_map& vm, AbstractClientEnv* clientEnv) const override; + private: - STC_Cmd_ptr doHandleRequest(AbstractServer*) const override; - bool authenticate(AbstractServer*, STC_Cmd_ptr&) const override; - void cleanup() override { std::vector().swap(paths_);} /// run in the server, after handlerequest + STC_Cmd_ptr doHandleRequest(AbstractServer*) const override; + bool authenticate(AbstractServer*, STC_Cmd_ptr&) const override; + void cleanup() override { std::vector().swap(paths_); } /// run in the server, after handlerequest - void my_print(std::string& os, const std::vector& paths) const; - void my_print_only(std::string& os, const std::vector& paths) const; + void my_print(std::string& os, const std::vector& paths) const; + void my_print_only(std::string& os, const std::vector& paths) const; private: - Api api_{NO_CMD}; - std::vector paths_; - bool force_{false}; - - friend class cereal::access; - template - void serialize(Archive & ar, std::uint32_t const /*version*/ ) - { - ar(cereal::base_class< UserCmd >( this ), - CEREAL_NVP(api_), - CEREAL_NVP(paths_), - CEREAL_NVP(force_) - ); - } + Api api_{NO_CMD}; + std::vector paths_; + bool force_{false}; + + friend class cereal::access; + template + void serialize(Archive& ar, std::uint32_t const /*version*/) { + ar(cereal::base_class(this), CEREAL_NVP(api_), CEREAL_NVP(paths_), CEREAL_NVP(force_)); + } }; - /// The LogCmd is paired with SStringCmd /// Client---(LogCmd)---->Server-----(SStringCmd)--->client: /// When doHandleRequest is called in the server it will return SStringCmd /// The SStringCmd is used to transport the log file contents to the client class LogCmd final : public UserCmd { public: - enum LogApi { GET, CLEAR, FLUSH, NEW , PATH }; - explicit LogCmd(LogApi a, int get_last_n_lines = 0); // for zero we take default from log. Avoid adding dependency on log.hpp - explicit LogCmd(const std::string& path); // NEW - LogCmd(); - - LogApi api() const { return api_;} - int get_last_n_lines() const { return get_last_n_lines_;} - const std::string& new_path() const { return new_path_;} - - void print(std::string&) const override; - void print_only(std::string&) const override; - bool equals(ClientToServerCmd*) const override; - - bool isWrite() const override; - const char* theArg() const override { return arg();} - void addOption(boost::program_options::options_description& desc) const override; - void create( Cmd_ptr& cmd, - boost::program_options::variables_map& vm, - AbstractClientEnv* clientEnv ) const override; + enum LogApi { GET, CLEAR, FLUSH, NEW, PATH }; + explicit LogCmd(LogApi a, + int get_last_n_lines = 0); // for zero we take default from log. Avoid adding dependency on log.hpp + explicit LogCmd(const std::string& path); // NEW + LogCmd(); + + LogApi api() const { return api_; } + int get_last_n_lines() const { return get_last_n_lines_; } + const std::string& new_path() const { return new_path_; } + + void print(std::string&) const override; + void print_only(std::string&) const override; + bool equals(ClientToServerCmd*) const override; + + bool isWrite() const override; + const char* theArg() const override { return arg(); } + void addOption(boost::program_options::options_description& desc) const override; + void create(Cmd_ptr& cmd, boost::program_options::variables_map& vm, AbstractClientEnv* clientEnv) const override; + private: - static const char* arg(); // used for argument parsing - static const char* desc(); // The description of the argument as provided to user - - STC_Cmd_ptr doHandleRequest(AbstractServer*) const override; - - LogApi api_{LogCmd::GET}; - int get_last_n_lines_; // default to 100 -> ECFLOW-174 - std::string new_path_; - - friend class cereal::access; - template - void serialize(Archive & ar, std::uint32_t const /*version*/ ) - { - ar(cereal::base_class< UserCmd >( this ), - CEREAL_NVP(api_), - CEREAL_NVP(get_last_n_lines_), - CEREAL_NVP(new_path_)); - } + static const char* arg(); // used for argument parsing + static const char* desc(); // The description of the argument as provided to user + + STC_Cmd_ptr doHandleRequest(AbstractServer*) const override; + + LogApi api_{LogCmd::GET}; + int get_last_n_lines_; // default to 100 -> ECFLOW-174 + std::string new_path_; + + friend class cereal::access; + template + void serialize(Archive& ar, std::uint32_t const /*version*/) { + ar(cereal::base_class(this), CEREAL_NVP(api_), CEREAL_NVP(get_last_n_lines_), CEREAL_NVP(new_path_)); + } }; /// Simply writes the message to the log file class LogMessageCmd final : public UserCmd { public: - explicit LogMessageCmd(const std::string& msg) : msg_(msg) {} - LogMessageCmd() = default; + explicit LogMessageCmd(const std::string& msg) : msg_(msg) {} + LogMessageCmd() = default; - const std::string& msg() const { return msg_;} + const std::string& msg() const { return msg_; } - void print(std::string&) const override; - void print_only(std::string&) const override; - bool equals(ClientToServerCmd*) const override; + void print(std::string&) const override; + void print_only(std::string&) const override; + bool equals(ClientToServerCmd*) const override; + + const char* theArg() const override { return arg(); } + void addOption(boost::program_options::options_description& desc) const override; + void create(Cmd_ptr& cmd, boost::program_options::variables_map& vm, AbstractClientEnv* clientEnv) const override; - const char* theArg() const override { return arg();} - void addOption(boost::program_options::options_description& desc) const override; - void create( Cmd_ptr& cmd, - boost::program_options::variables_map& vm, - AbstractClientEnv* clientEnv ) const override; private: - STC_Cmd_ptr doHandleRequest(AbstractServer*) const override; - static const char* arg(); // used for argument parsing - static const char* desc(); // The description of the argument as provided to user - - std::string msg_; - - friend class cereal::access; - template - void serialize(Archive & ar, std::uint32_t const /*version*/ ) - { - ar(cereal::base_class< UserCmd >( this ), - CEREAL_NVP(msg_)); - } -}; + STC_Cmd_ptr doHandleRequest(AbstractServer*) const override; + static const char* arg(); // used for argument parsing + static const char* desc(); // The description of the argument as provided to user + std::string msg_; + + friend class cereal::access; + template + void serialize(Archive& ar, std::uint32_t const /*version*/) { + ar(cereal::base_class(this), CEREAL_NVP(msg_)); + } +}; // class Begin: if suiteName is empty we will begin all suites class BeginCmd final : public UserCmd { public: - explicit BeginCmd(const std::string& suiteName, bool force = false); - BeginCmd()= default; + explicit BeginCmd(const std::string& suiteName, bool force = false); + BeginCmd() = default; + + const std::string& suiteName() const { return suiteName_; } + bool force() const { return force_; } - const std::string& suiteName() const { return suiteName_;} - bool force() const { return force_;} + int timeout() const override { return 80; } - int timeout() const override { return 80; } + bool isWrite() const override { return true; } + void print(std::string&) const override; + void print_only(std::string&) const override; + bool equals(ClientToServerCmd*) const override; - bool isWrite() const override { return true; } - void print(std::string&) const override; - void print_only(std::string&) const override; - bool equals(ClientToServerCmd*) const override; + const char* theArg() const override { return arg(); } + void addOption(boost::program_options::options_description& desc) const override; + void create(Cmd_ptr& cmd, boost::program_options::variables_map& vm, AbstractClientEnv* clientEnv) const override; - const char* theArg() const override { return arg();} - void addOption(boost::program_options::options_description& desc) const override; - void create( Cmd_ptr& cmd, - boost::program_options::variables_map& vm, - AbstractClientEnv* clientEnv ) const override; private: - static const char* arg(); // used for argument parsing - static const char* desc(); // The description of the argument as provided to user + static const char* arg(); // used for argument parsing + static const char* desc(); // The description of the argument as provided to user - STC_Cmd_ptr doHandleRequest(AbstractServer*) const override; + STC_Cmd_ptr doHandleRequest(AbstractServer*) const override; private: - std::string suiteName_; - bool force_{false}; // reset begin status on suites & bypass checks, can create zombies, used in test only - - friend class cereal::access; - template - void serialize(Archive & ar, std::uint32_t const /*version*/ ) - { - ar(cereal::base_class< UserCmd >( this ), - CEREAL_NVP(suiteName_), - CEREAL_NVP(force_)); - } + std::string suiteName_; + bool force_{false}; // reset begin status on suites & bypass checks, can create zombies, used in test only + + friend class cereal::access; + template + void serialize(Archive& ar, std::uint32_t const /*version*/) { + ar(cereal::base_class(this), CEREAL_NVP(suiteName_), CEREAL_NVP(force_)); + } }; class ZombieCmd final : public UserCmd { public: - ZombieCmd(ecf::User::Action uc, const std::vector& paths, const std::string& process_id, const std::string& password) - : user_action_(uc), process_id_(process_id), password_(password),paths_(paths) {} - explicit ZombieCmd(ecf::User::Action uc = ecf::User::BLOCK) : user_action_(uc) {} - - const std::vector& paths() const { return paths_;} - const std::string& process_or_remote_id() const { return process_id_;} - const std::string& password() const { return password_;} - - void print(std::string&) const override; - void print_only(std::string&) const override; - bool equals(ClientToServerCmd*) const override; - - const char* theArg() const override; - void addOption(boost::program_options::options_description& desc) const override; - void create( Cmd_ptr& cmd, - boost::program_options::variables_map& vm, - AbstractClientEnv* clientEnv ) const override; + ZombieCmd(ecf::User::Action uc, + const std::vector& paths, + const std::string& process_id, + const std::string& password) + : user_action_(uc), + process_id_(process_id), + password_(password), + paths_(paths) {} + explicit ZombieCmd(ecf::User::Action uc = ecf::User::BLOCK) : user_action_(uc) {} + + const std::vector& paths() const { return paths_; } + const std::string& process_or_remote_id() const { return process_id_; } + const std::string& password() const { return password_; } + + void print(std::string&) const override; + void print_only(std::string&) const override; + bool equals(ClientToServerCmd*) const override; + + const char* theArg() const override; + void addOption(boost::program_options::options_description& desc) const override; + void create(Cmd_ptr& cmd, boost::program_options::variables_map& vm, AbstractClientEnv* clientEnv) const override; private: - STC_Cmd_ptr doHandleRequest(AbstractServer*) const override; - void cleanup() override { std::vector().swap(paths_);} /// run in the server, after handlerequest - - ecf::User::Action user_action_; - std::string process_id_; // should be empty for multiple paths and when using CLI - std::string password_; // should be empty for multiple paths and when using CLI - std::vector paths_; - - friend class cereal::access; - template - void serialize(Archive & ar, std::uint32_t const /*version*/ ) - { - ar(cereal::base_class< UserCmd >( this ), - CEREAL_NVP(user_action_), - CEREAL_NVP(process_id_), - CEREAL_NVP(password_), - CEREAL_NVP(paths_)); - } + STC_Cmd_ptr doHandleRequest(AbstractServer*) const override; + void cleanup() override { std::vector().swap(paths_); } /// run in the server, after handlerequest + + ecf::User::Action user_action_; + std::string process_id_; // should be empty for multiple paths and when using CLI + std::string password_; // should be empty for multiple paths and when using CLI + std::vector paths_; + + friend class cereal::access; + template + void serialize(Archive& ar, std::uint32_t const /*version*/) { + ar(cereal::base_class(this), + CEREAL_NVP(user_action_), + CEREAL_NVP(process_id_), + CEREAL_NVP(password_), + CEREAL_NVP(paths_)); + } }; class RequeueNodeCmd final : public UserCmd { public: - enum Option { NO_OPTION, ABORT, FORCE }; + enum Option { NO_OPTION, ABORT, FORCE }; + + explicit RequeueNodeCmd(const std::vector& paths, Option op = NO_OPTION) + : paths_(paths), + option_(op) {} - explicit RequeueNodeCmd(const std::vector& paths, Option op = NO_OPTION) - : paths_(paths), option_(op) {} + explicit RequeueNodeCmd(const std::string& absNodepath, Option op = NO_OPTION) + : paths_(std::vector(1, absNodepath)), + option_(op) {} - explicit RequeueNodeCmd(const std::string& absNodepath, Option op = NO_OPTION) - : paths_(std::vector(1,absNodepath)), option_(op) {} + RequeueNodeCmd() = default; - RequeueNodeCmd()= default; + const std::vector& paths() const { return paths_; } + Option option() const { return option_; } - const std::vector& paths() const { return paths_;} - Option option() const { return option_;} + bool isWrite() const override { return true; } + void print(std::string&) const override; + void print_only(std::string&) const override; + void print(std::string& os, const std::string& path) const override; + bool equals(ClientToServerCmd*) const override; - bool isWrite() const override { return true; } - void print(std::string&) const override; - void print_only(std::string&) const override; - void print(std::string& os, const std::string& path) const override; - bool equals(ClientToServerCmd*) const override; + const char* theArg() const override { return arg(); } + void addOption(boost::program_options::options_description& desc) const override; + void create(Cmd_ptr& cmd, boost::program_options::variables_map& vm, AbstractClientEnv* clientEnv) const override; - const char* theArg() const override { return arg();} - void addOption(boost::program_options::options_description& desc) const override; - void create( Cmd_ptr& cmd, - boost::program_options::variables_map& vm, - AbstractClientEnv* clientEnv ) const override; private: - static const char* arg(); // used for argument parsing - static const char* desc(); // The description of the argument as provided to user + static const char* arg(); // used for argument parsing + static const char* desc(); // The description of the argument as provided to user - STC_Cmd_ptr doHandleRequest(AbstractServer*) const override; - bool authenticate(AbstractServer*, STC_Cmd_ptr&) const override; - void cleanup() override { std::vector().swap(paths_);} /// run in the server, after doHandleRequest + STC_Cmd_ptr doHandleRequest(AbstractServer*) const override; + bool authenticate(AbstractServer*, STC_Cmd_ptr&) const override; + void cleanup() override { std::vector().swap(paths_); } /// run in the server, after doHandleRequest private: - mutable std::vector paths_; // mutable to allow swap to clear & reclaim memory, as soon as possible - Option option_{NO_OPTION}; - - friend class cereal::access; - template - void serialize(Archive & ar, std::uint32_t const /*version*/ ) - { - ar(cereal::base_class< UserCmd >( this ), - CEREAL_NVP(paths_), - CEREAL_NVP(option_)); - } + mutable std::vector paths_; // mutable to allow swap to clear & reclaim memory, as soon as possible + Option option_{NO_OPTION}; + + friend class cereal::access; + template + void serialize(Archive& ar, std::uint32_t const /*version*/) { + ar(cereal::base_class(this), CEREAL_NVP(paths_), CEREAL_NVP(option_)); + } }; class OrderNodeCmd final : public UserCmd { public: - OrderNodeCmd(const std::string& absNodepath, NOrder::Order op) - : absNodepath_(absNodepath), option_(op) {} - OrderNodeCmd()= default; - - const std::string& absNodepath() const { return absNodepath_;} - NOrder::Order option() const { return option_;} - - bool isWrite() const override { return true; } - void print(std::string&) const override; - void print_only(std::string&) const override; - bool equals(ClientToServerCmd*) const override; - - const char* theArg() const override { return arg();} - void addOption(boost::program_options::options_description& desc) const override; - void create( Cmd_ptr& cmd, - boost::program_options::variables_map& vm, - AbstractClientEnv* clientEnv ) const override; + OrderNodeCmd(const std::string& absNodepath, NOrder::Order op) : absNodepath_(absNodepath), option_(op) {} + OrderNodeCmd() = default; + + const std::string& absNodepath() const { return absNodepath_; } + NOrder::Order option() const { return option_; } + + bool isWrite() const override { return true; } + void print(std::string&) const override; + void print_only(std::string&) const override; + bool equals(ClientToServerCmd*) const override; + + const char* theArg() const override { return arg(); } + void addOption(boost::program_options::options_description& desc) const override; + void create(Cmd_ptr& cmd, boost::program_options::variables_map& vm, AbstractClientEnv* clientEnv) const override; + private: - static const char* arg(); // used for argument parsing - static const char* desc(); // The description of the argument as provided to user + static const char* arg(); // used for argument parsing + static const char* desc(); // The description of the argument as provided to user - STC_Cmd_ptr doHandleRequest(AbstractServer*) const override; - bool authenticate(AbstractServer*, STC_Cmd_ptr&) const override; + STC_Cmd_ptr doHandleRequest(AbstractServer*) const override; + bool authenticate(AbstractServer*, STC_Cmd_ptr&) const override; private: - std::string absNodepath_; - NOrder::Order option_{NOrder::TOP}; - - friend class cereal::access; - template - void serialize(Archive & ar, std::uint32_t const /*version*/ ) - { - ar(cereal::base_class< UserCmd >( this ), - CEREAL_NVP(absNodepath_), - CEREAL_NVP(option_)); - } + std::string absNodepath_; + NOrder::Order option_{NOrder::TOP}; + + friend class cereal::access; + template + void serialize(Archive& ar, std::uint32_t const /*version*/) { + ar(cereal::base_class(this), CEREAL_NVP(absNodepath_), CEREAL_NVP(option_)); + } }; - // The absNodepath must be provided class RunNodeCmd final : public UserCmd { public: - RunNodeCmd(const std::string& absNodepath, bool force, bool test = false) - : paths_(std::vector(1,absNodepath)), force_(force), test_(test) {} + RunNodeCmd(const std::string& absNodepath, bool force, bool test = false) + : paths_(std::vector(1, absNodepath)), + force_(force), + test_(test) {} - RunNodeCmd(const std::vector& paths, bool force, bool test = false) - : paths_(paths), force_(force), test_(test) {} + RunNodeCmd(const std::vector& paths, bool force, bool test = false) + : paths_(paths), + force_(force), + test_(test) {} - RunNodeCmd()= default; + RunNodeCmd() = default; - const std::vector& paths() const { return paths_;} - bool force() const { return force_;} + const std::vector& paths() const { return paths_; } + bool force() const { return force_; } - bool isWrite() const override { return true; } - void print(std::string&) const override; - void print_only(std::string&) const override; - void print(std::string& os, const std::string& path) const override; - bool equals(ClientToServerCmd*) const override; + bool isWrite() const override { return true; } + void print(std::string&) const override; + void print_only(std::string&) const override; + void print(std::string& os, const std::string& path) const override; + bool equals(ClientToServerCmd*) const override; + + const char* theArg() const override { return arg(); } + void addOption(boost::program_options::options_description& desc) const override; + void create(Cmd_ptr& cmd, boost::program_options::variables_map& vm, AbstractClientEnv* clientEnv) const override; - const char* theArg() const override { return arg();} - void addOption(boost::program_options::options_description& desc) const override; - void create( Cmd_ptr& cmd, - boost::program_options::variables_map& vm, - AbstractClientEnv* clientEnv ) const override; private: - static const char* arg(); // used for argument parsing - static const char* desc(); // The description of the argument as provided to user + static const char* arg(); // used for argument parsing + static const char* desc(); // The description of the argument as provided to user - STC_Cmd_ptr doHandleRequest(AbstractServer*) const override; - bool authenticate(AbstractServer*, STC_Cmd_ptr&) const override; - void cleanup() override { std::vector().swap(paths_);} /// run in the server, after doHandleRequest + STC_Cmd_ptr doHandleRequest(AbstractServer*) const override; + bool authenticate(AbstractServer*, STC_Cmd_ptr&) const override; + void cleanup() override { std::vector().swap(paths_); } /// run in the server, after doHandleRequest private: - std::vector paths_; - bool force_{false}; - bool test_{false}; // only for test, hence we don't serialise this - - friend class cereal::access; - template - void serialize(Archive & ar, std::uint32_t const /*version*/ ) - { - ar(cereal::base_class< UserCmd >( this ), - CEREAL_NVP(paths_), - CEREAL_NVP(force_)); - } + std::vector paths_; + bool force_{false}; + bool test_{false}; // only for test, hence we don't serialise this + + friend class cereal::access; + template + void serialize(Archive& ar, std::uint32_t const /*version*/) { + ar(cereal::base_class(this), CEREAL_NVP(paths_), CEREAL_NVP(force_)); + } }; - // Does Nothing in the server, however allows client code to display the // returned Defs in different showStyles // This class has no need for persistence, i.e client side only class ShowCmd final : public UserCmd { public: - explicit ShowCmd(PrintStyle::Type_t s = PrintStyle::DEFS) : style_(s) {} + explicit ShowCmd(PrintStyle::Type_t s = PrintStyle::DEFS) : style_(s) {} - // returns the showStyle - bool show_cmd() const override { return true ;} - PrintStyle::Type_t show_style() const override { return style_;} + // returns the showStyle + bool show_cmd() const override { return true; } + PrintStyle::Type_t show_style() const override { return style_; } - void print(std::string&) const override; - void print_only(std::string&) const override; - bool equals(ClientToServerCmd*) const override; + void print(std::string&) const override; + void print_only(std::string&) const override; + bool equals(ClientToServerCmd*) const override; + + const char* theArg() const override { return arg(); } + void addOption(boost::program_options::options_description& desc) const override; + void create(Cmd_ptr& cmd, boost::program_options::variables_map& vm, AbstractClientEnv* clientEnv) const override; - const char* theArg() const override { return arg();} - void addOption(boost::program_options::options_description& desc) const override; - void create( Cmd_ptr& cmd, - boost::program_options::variables_map& vm, - AbstractClientEnv* clientEnv ) const override; private: - static const char* arg(); // used for argument parsing - static const char* desc(); // The description of the argument as provided to user - - // The Show Cmd is processed on the client side, - // Likewise the doHandleRequest does nothing, - STC_Cmd_ptr doHandleRequest(AbstractServer*) const override; - - PrintStyle::Type_t style_; - - // Persistence is still required since show command can be *USED* in a *GROUP* command - // However its ONLY used on the client side, hence no need to serialise data members - friend class cereal::access; - template - void serialize(Archive & ar, std::uint32_t const /*version*/ ) - { - ar(cereal::base_class< UserCmd >( this )); - } + static const char* arg(); // used for argument parsing + static const char* desc(); // The description of the argument as provided to user + + // The Show Cmd is processed on the client side, + // Likewise the doHandleRequest does nothing, + STC_Cmd_ptr doHandleRequest(AbstractServer*) const override; + + PrintStyle::Type_t style_; + + // Persistence is still required since show command can be *USED* in a *GROUP* command + // However its ONLY used on the client side, hence no need to serialise data members + friend class cereal::access; + template + void serialize(Archive& ar, std::uint32_t const /*version*/) { + ar(cereal::base_class(this)); + } }; // Will *load* the suites, into the server. @@ -1437,100 +1381,101 @@ class ShowCmd final : public UserCmd { // to Node, events, meters, limits, variables defined on another suite. class LoadDefsCmd final : public UserCmd { public: - explicit LoadDefsCmd(const defs_ptr& defs, bool force = false); - explicit LoadDefsCmd(const std::string& defs_filename,bool force = false,bool check_only = false/* not persisted */,bool print = false/* not persisted */, - bool stats = false/* not persisted */, - const std::vector >& client_env = std::vector >()); - LoadDefsCmd()= default; - - // Uses by equals only - const std::string& defs_as_string() const { return defs_; } - - bool isWrite() const override { return true; } - int timeout() const override { return time_out_for_load_sync_and_get(); } - void print(std::string&) const override; - void print_only(std::string&) const override; - bool equals(ClientToServerCmd*) const override; - - const char* theArg() const override { return arg();} - void addOption(boost::program_options::options_description& desc) const override; - void create( Cmd_ptr& cmd, - boost::program_options::variables_map& vm, - AbstractClientEnv* clientEnv ) const override; - static Cmd_ptr create(const std::string& defs_filename,bool force,bool check_only,bool print,bool stats,AbstractClientEnv* clientEnv); + explicit LoadDefsCmd(const defs_ptr& defs, bool force = false); + explicit LoadDefsCmd(const std::string& defs_filename, + bool force = false, + bool check_only = false /* not persisted */, + bool print = false /* not persisted */, + bool stats = false /* not persisted */, + const std::vector>& client_env = + std::vector>()); + LoadDefsCmd() = default; + + // Uses by equals only + const std::string& defs_as_string() const { return defs_; } + + bool isWrite() const override { return true; } + int timeout() const override { return time_out_for_load_sync_and_get(); } + void print(std::string&) const override; + void print_only(std::string&) const override; + bool equals(ClientToServerCmd*) const override; + + const char* theArg() const override { return arg(); } + void addOption(boost::program_options::options_description& desc) const override; + void create(Cmd_ptr& cmd, boost::program_options::variables_map& vm, AbstractClientEnv* clientEnv) const override; + static Cmd_ptr create(const std::string& defs_filename, + bool force, + bool check_only, + bool print, + bool stats, + AbstractClientEnv* clientEnv); private: - static const char* arg(); // used for argument parsing - static const char* desc(); // The description of the command as provided to user - - STC_Cmd_ptr doHandleRequest(AbstractServer*) const override; - - bool force_{false}; - std::string defs_; - std::string defs_filename_; - - friend class cereal::access; - template - void serialize(Archive & ar, std::uint32_t const /*version*/ ) - { - ar(cereal::base_class< UserCmd >( this ), - CEREAL_NVP(force_), - CEREAL_NVP(defs_), - CEREAL_NVP(defs_filename_)); - } + static const char* arg(); // used for argument parsing + static const char* desc(); // The description of the command as provided to user + + STC_Cmd_ptr doHandleRequest(AbstractServer*) const override; + + bool force_{false}; + std::string defs_; + std::string defs_filename_; + + friend class cereal::access; + template + void serialize(Archive& ar, std::uint32_t const /*version*/) { + ar(cereal::base_class(this), CEREAL_NVP(force_), CEREAL_NVP(defs_), CEREAL_NVP(defs_filename_)); + } }; class ReplaceNodeCmd final : public UserCmd { public: - ReplaceNodeCmd(const std::string& node_path, bool createNodesAsNeeded, defs_ptr client_defs, bool force ); - ReplaceNodeCmd(const std::string& node_path, bool createNodesAsNeeded, const std::string& path_to_defs, bool force); - ReplaceNodeCmd()= default; - - const std::string& the_client_defs() const { return clientDefs_; } - const std::string& pathToNode() const { return pathToNode_; } - const std::string& path_to_defs() const { return path_to_defs_;} - bool createNodesAsNeeded() const { return createNodesAsNeeded_;} - bool force() const { return force_;} - - bool isWrite() const override { return true; } - int timeout() const override { return 300; } - void print(std::string&) const override; - void print_only(std::string&) const override; - bool equals(ClientToServerCmd*) const override; - - const char* theArg() const override { return arg();} - void addOption(boost::program_options::options_description& desc) const override; - void create( Cmd_ptr& cmd, - boost::program_options::variables_map& vm, - AbstractClientEnv* clientEnv ) const override; - - //void set_client_env(const std::vector >& env ) { client_env_ = env;} // only used in test + ReplaceNodeCmd(const std::string& node_path, bool createNodesAsNeeded, defs_ptr client_defs, bool force); + ReplaceNodeCmd(const std::string& node_path, bool createNodesAsNeeded, const std::string& path_to_defs, bool force); + ReplaceNodeCmd() = default; + + const std::string& the_client_defs() const { return clientDefs_; } + const std::string& pathToNode() const { return pathToNode_; } + const std::string& path_to_defs() const { return path_to_defs_; } + bool createNodesAsNeeded() const { return createNodesAsNeeded_; } + bool force() const { return force_; } + + bool isWrite() const override { return true; } + int timeout() const override { return 300; } + void print(std::string&) const override; + void print_only(std::string&) const override; + bool equals(ClientToServerCmd*) const override; + + const char* theArg() const override { return arg(); } + void addOption(boost::program_options::options_description& desc) const override; + void create(Cmd_ptr& cmd, boost::program_options::variables_map& vm, AbstractClientEnv* clientEnv) const override; + + // void set_client_env(const std::vector >& env ) { client_env_ = env;} // only + // used in test private: - static const char* arg(); // used for argument parsing - static const char* desc(); // The description of the argument as provided to user - - STC_Cmd_ptr doHandleRequest(AbstractServer*) const override; - bool authenticate(AbstractServer*, STC_Cmd_ptr&) const override; - void cleanup() override { std::string().swap(clientDefs_);} /// run in the server, after command send to client - - bool createNodesAsNeeded_{false}; - bool force_{false}; - std::string pathToNode_; - std::string path_to_defs_; // Can be empty if defs loaded in memory via python api - std::string clientDefs_; - - friend class cereal::access; - template - void serialize(Archive & ar, std::uint32_t const /*version*/ ) - { - ar(cereal::base_class< UserCmd >( this ), - CEREAL_NVP(createNodesAsNeeded_), - CEREAL_NVP(force_), - CEREAL_NVP(pathToNode_), - CEREAL_NVP(path_to_defs_), - CEREAL_NVP(clientDefs_)); - } + static const char* arg(); // used for argument parsing + static const char* desc(); // The description of the argument as provided to user + + STC_Cmd_ptr doHandleRequest(AbstractServer*) const override; + bool authenticate(AbstractServer*, STC_Cmd_ptr&) const override; + void cleanup() override { std::string().swap(clientDefs_); } /// run in the server, after command send to client + + bool createNodesAsNeeded_{false}; + bool force_{false}; + std::string pathToNode_; + std::string path_to_defs_; // Can be empty if defs loaded in memory via python api + std::string clientDefs_; + + friend class cereal::access; + template + void serialize(Archive& ar, std::uint32_t const /*version*/) { + ar(cereal::base_class(this), + CEREAL_NVP(createNodesAsNeeded_), + CEREAL_NVP(force_), + CEREAL_NVP(pathToNode_), + CEREAL_NVP(path_to_defs_), + CEREAL_NVP(clientDefs_)); + } }; // Set the state on the affected node ONLY. @@ -1540,261 +1485,363 @@ class ReplaceNodeCmd final : public UserCmd { // < unknown | suspended | complete | queued | submitted | active | aborted | clear | set > class ForceCmd final : public UserCmd { public: - ForceCmd(const std::vector& paths, - const std::string& stateOrEvent, - bool recursive, - bool setRepeatToLastValue) - : paths_(paths), stateOrEvent_(stateOrEvent), - recursive_(recursive), setRepeatToLastValue_(setRepeatToLastValue) {} - ForceCmd(const std::string& path, - const std::string& stateOrEvent, - bool recursive, - bool setRepeatToLastValue) - : paths_(std::vector(1,path)), stateOrEvent_(stateOrEvent), - recursive_(recursive), setRepeatToLastValue_(setRepeatToLastValue) {} - ForceCmd()= default; - - // Uses by equals only - const std::vector paths() const { return paths_; } - const std::string& stateOrEvent() const { return stateOrEvent_;} - bool recursive() const { return recursive_;} - bool setRepeatToLastValue() const { return setRepeatToLastValue_;} - - bool isWrite() const override { return true; } - void print(std::string&) const override; - std::string print_short() const override; - void print_only(std::string&) const override; - void print(std::string& os, const std::string& path) const override; - bool equals(ClientToServerCmd*) const override; - - const char* theArg() const override { return arg();} - void addOption(boost::program_options::options_description& desc) const override; - void create( Cmd_ptr& cmd, - boost::program_options::variables_map& vm, - AbstractClientEnv* clientEnv ) const override; + ForceCmd(const std::vector& paths, + const std::string& stateOrEvent, + bool recursive, + bool setRepeatToLastValue) + : paths_(paths), + stateOrEvent_(stateOrEvent), + recursive_(recursive), + setRepeatToLastValue_(setRepeatToLastValue) {} + ForceCmd(const std::string& path, const std::string& stateOrEvent, bool recursive, bool setRepeatToLastValue) + : paths_(std::vector(1, path)), + stateOrEvent_(stateOrEvent), + recursive_(recursive), + setRepeatToLastValue_(setRepeatToLastValue) {} + ForceCmd() = default; + + // Uses by equals only + const std::vector paths() const { return paths_; } + const std::string& stateOrEvent() const { return stateOrEvent_; } + bool recursive() const { return recursive_; } + bool setRepeatToLastValue() const { return setRepeatToLastValue_; } + + bool isWrite() const override { return true; } + void print(std::string&) const override; + std::string print_short() const override; + void print_only(std::string&) const override; + void print(std::string& os, const std::string& path) const override; + bool equals(ClientToServerCmd*) const override; + + const char* theArg() const override { return arg(); } + void addOption(boost::program_options::options_description& desc) const override; + void create(Cmd_ptr& cmd, boost::program_options::variables_map& vm, AbstractClientEnv* clientEnv) const override; + private: - static const char* arg(); // used for argument parsing - static const char* desc(); // The description of the argument as provided to user + static const char* arg(); // used for argument parsing + static const char* desc(); // The description of the argument as provided to user - STC_Cmd_ptr doHandleRequest(AbstractServer*) const override; - bool authenticate(AbstractServer*, STC_Cmd_ptr&) const override; - void cleanup() override { std::vector().swap(paths_);} /// run in the server, after doHandleRequest + STC_Cmd_ptr doHandleRequest(AbstractServer*) const override; + bool authenticate(AbstractServer*, STC_Cmd_ptr&) const override; + void cleanup() override { std::vector().swap(paths_); } /// run in the server, after doHandleRequest - void my_print(std::string& os, const std::vector& paths) const; - void my_print_only(std::string& os, const std::vector& paths) const; + void my_print(std::string& os, const std::vector& paths) const; + void my_print_only(std::string& os, const std::vector& paths) const; private: - std::vector paths_; - std::string stateOrEvent_; - bool recursive_{false}; - bool setRepeatToLastValue_{false}; - - friend class cereal::access; - template - void serialize(Archive & ar, std::uint32_t const /*version*/ ) - { - ar(cereal::base_class< UserCmd >( this ), - CEREAL_NVP(paths_), - CEREAL_NVP(stateOrEvent_), - CEREAL_NVP(recursive_), - CEREAL_NVP(setRepeatToLastValue_)); - } + std::vector paths_; + std::string stateOrEvent_; + bool recursive_{false}; + bool setRepeatToLastValue_{false}; + + friend class cereal::access; + template + void serialize(Archive& ar, std::uint32_t const /*version*/) { + ar(cereal::base_class(this), + CEREAL_NVP(paths_), + CEREAL_NVP(stateOrEvent_), + CEREAL_NVP(recursive_), + CEREAL_NVP(setRepeatToLastValue_)); + } }; // Free Dependencies class FreeDepCmd final : public UserCmd { public: - explicit FreeDepCmd(const std::vector& paths, - bool trigger = true, - bool all = false, // day, date, time, today, trigger, cron - bool date = false, - bool time = false // includes time, day, date, today, cron - ) - : paths_(paths), trigger_(trigger), all_(all), date_(date), time_(time) {} - - explicit FreeDepCmd(const std::string& path, - bool trigger = true, - bool all = false, // day, date, time, today, trigger, cron - bool date = false, - bool time = false // includes time, day, date, today, cron - ) - : paths_(std::vector(1,path)), trigger_(trigger), all_(all), date_(date), time_(time) {} - - FreeDepCmd() = default; - - // Uses by equals only - const std::vector& paths() const { return paths_; } - bool trigger() const { return trigger_;} - bool all() const { return all_;} - bool date() const { return date_;} - bool time() const { return time_;} - - bool isWrite() const override { return true; } - void print(std::string&) const override; - void print_only(std::string&) const override; - void print(std::string& os, const std::string& path) const override; - bool equals(ClientToServerCmd*) const override; - - const char* theArg() const override { return arg();} - void addOption(boost::program_options::options_description& desc) const override; - void create( Cmd_ptr& cmd, - boost::program_options::variables_map& vm, - AbstractClientEnv* clientEnv ) const override; + explicit FreeDepCmd(const std::vector& paths, + bool trigger = true, + bool all = false, // day, date, time, today, trigger, cron + bool date = false, + bool time = false // includes time, day, date, today, cron + ) + : paths_(paths), + trigger_(trigger), + all_(all), + date_(date), + time_(time) {} + + explicit FreeDepCmd(const std::string& path, + bool trigger = true, + bool all = false, // day, date, time, today, trigger, cron + bool date = false, + bool time = false // includes time, day, date, today, cron + ) + : paths_(std::vector(1, path)), + trigger_(trigger), + all_(all), + date_(date), + time_(time) {} + + FreeDepCmd() = default; + + // Uses by equals only + const std::vector& paths() const { return paths_; } + bool trigger() const { return trigger_; } + bool all() const { return all_; } + bool date() const { return date_; } + bool time() const { return time_; } + + bool isWrite() const override { return true; } + void print(std::string&) const override; + void print_only(std::string&) const override; + void print(std::string& os, const std::string& path) const override; + bool equals(ClientToServerCmd*) const override; + + const char* theArg() const override { return arg(); } + void addOption(boost::program_options::options_description& desc) const override; + void create(Cmd_ptr& cmd, boost::program_options::variables_map& vm, AbstractClientEnv* clientEnv) const override; + private: - static const char* arg(); // used for argument parsing - static const char* desc(); // The description of the argument as provided to user + static const char* arg(); // used for argument parsing + static const char* desc(); // The description of the argument as provided to user - STC_Cmd_ptr doHandleRequest(AbstractServer*) const override; - bool authenticate(AbstractServer*, STC_Cmd_ptr&) const override; - void cleanup() override { std::vector().swap(paths_);} /// run in the server, after doHandleRequest + STC_Cmd_ptr doHandleRequest(AbstractServer*) const override; + bool authenticate(AbstractServer*, STC_Cmd_ptr&) const override; + void cleanup() override { std::vector().swap(paths_); } /// run in the server, after doHandleRequest private: - std::vector paths_; - bool trigger_{true}; - bool all_{false}; - bool date_{false}; - bool time_{false}; - - friend class cereal::access; - template - void serialize(Archive & ar, std::uint32_t const /*version*/ ) - { - ar(cereal::base_class< UserCmd >( this ), - CEREAL_NVP(paths_), - CEREAL_NVP(trigger_), - CEREAL_NVP(all_), - CEREAL_NVP(date_), - CEREAL_NVP(time_)); - } + std::vector paths_; + bool trigger_{true}; + bool all_{false}; + bool date_{false}; + bool time_{false}; + + friend class cereal::access; + template + void serialize(Archive& ar, std::uint32_t const /*version*/) { + ar(cereal::base_class(this), + CEREAL_NVP(paths_), + CEREAL_NVP(trigger_), + CEREAL_NVP(all_), + CEREAL_NVP(date_), + CEREAL_NVP(time_)); + } }; class AlterCmd final : public UserCmd { public: - enum Delete_attr_type { DEL_VARIABLE, DEL_TIME, DEL_TODAY, DEL_DATE, DEL_DAY, - DEL_CRON, DEL_EVENT, DEL_METER, DEL_LABEL, - DEL_TRIGGER, DEL_COMPLETE, DEL_REPEAT, DEL_LIMIT, DEL_LIMIT_PATH, - DEL_INLIMIT, DEL_ZOMBIE, DELETE_ATTR_ND, DEL_LATE, DEL_QUEUE, DEL_GENERIC }; - - enum Change_attr_type { VARIABLE, CLOCK_TYPE, CLOCK_DATE, CLOCK_GAIN, EVENT, METER, LABEL, - TRIGGER, COMPLETE, REPEAT, LIMIT_MAX, LIMIT_VAL, DEFSTATUS, CHANGE_ATTR_ND, CLOCK_SYNC, LATE, TIME, TODAY }; - - enum Add_attr_type { ADD_TIME, ADD_TODAY, ADD_DATE, ADD_DAY, ADD_ZOMBIE, ADD_VARIABLE, ADD_ATTR_ND, ADD_LATE, ADD_LIMIT, ADD_INLIMIT, ADD_LABEL }; - - // Python - AlterCmd(const std::vector& paths, + enum Delete_attr_type { + DEL_VARIABLE, + DEL_TIME, + DEL_TODAY, + DEL_DATE, + DEL_DAY, + DEL_CRON, + DEL_EVENT, + DEL_METER, + DEL_LABEL, + DEL_TRIGGER, + DEL_COMPLETE, + DEL_REPEAT, + DEL_LIMIT, + DEL_LIMIT_PATH, + DEL_INLIMIT, + DEL_ZOMBIE, + DELETE_ATTR_ND, + DEL_LATE, + DEL_QUEUE, + DEL_GENERIC + }; + + enum Change_attr_type { + VARIABLE, + CLOCK_TYPE, + CLOCK_DATE, + CLOCK_GAIN, + EVENT, + METER, + LABEL, + TRIGGER, + COMPLETE, + REPEAT, + LIMIT_MAX, + LIMIT_VAL, + DEFSTATUS, + CHANGE_ATTR_ND, + CLOCK_SYNC, + LATE, + TIME, + TODAY + }; + + enum Add_attr_type { + ADD_TIME, + ADD_TODAY, + ADD_DATE, + ADD_DAY, + ADD_ZOMBIE, + ADD_VARIABLE, + ADD_ATTR_ND, + ADD_LATE, + ADD_LIMIT, + ADD_INLIMIT, + ADD_LABEL + }; + + // Python + AlterCmd(const std::vector& paths, const std::string& alterType, /* one of [ add | change | delete | set_flag | clear_flag ] */ const std::string& attrType, const std::string& name, const std::string& value); - // add - AlterCmd(const std::string& path, Add_attr_type attr, const std::string& name, const std::string& value = "" ) - : paths_(std::vector(1,path)), name_(name), value_(value), add_attr_type_(attr) {} - AlterCmd(const std::vector& paths, Add_attr_type attr, const std::string& name, const std::string& value = "" ) - : paths_(paths), name_(name), value_(value), add_attr_type_(attr) {} - // delete - AlterCmd(const std::string& path, Delete_attr_type del, const std::string& name = "" , const std::string& value = "") - : paths_(std::vector(1,path)), name_(name), value_(value), - del_attr_type_(del) {} - AlterCmd(const std::vector& paths, Delete_attr_type del, const std::string& name = "" , const std::string& value = "") - : paths_(paths), name_(name), value_(value), - del_attr_type_(del) {} - // change - AlterCmd(const std::string& path, Change_attr_type attr, const std::string& name, const std::string& value = "") - : paths_(std::vector(1,path)), name_(name), value_(value), change_attr_type_(attr) {} - AlterCmd(const std::vector& paths, Change_attr_type attr, const std::string& name, const std::string& value = "") - : paths_(paths), name_(name), value_(value), change_attr_type_(attr) {} - // flag - AlterCmd(const std::string& path, ecf::Flag::Type ft, bool flag) - : paths_(std::vector(1,path)), flag_type_(ft), flag_(flag) {} - AlterCmd(const std::vector& paths, ecf::Flag::Type ft, bool flag) - : paths_(paths), flag_type_(ft), flag_(flag) {} - // sort - AlterCmd(const std::string& path, const std::string& name,const std::string& value) - : paths_(std::vector(1,path)), name_(name),value_(value) {} - AlterCmd(const std::vector& paths, const std::string& name,const std::string& value) - : paths_(paths), name_(name),value_(value) {} - - AlterCmd()= default; - - // Uses by equals only - const std::vector& paths() const { return paths_; } - const std::string& name() const { return name_; } - const std::string& value() const { return value_; } - Delete_attr_type delete_attr_type() const { return del_attr_type_;} - Change_attr_type change_attr_type() const { return change_attr_type_;} - Add_attr_type add_attr_type() const { return add_attr_type_;} - ecf::Flag::Type flag_type() const { return flag_type_;} - bool flag() const { return flag_;} - - bool isWrite() const override { return true; } - void print(std::string&) const override; - void print(std::string& os, const std::string& path) const override; - void print_only(std::string&) const override; - bool equals(ClientToServerCmd*) const override; - - const char* theArg() const override { return arg();} - void addOption(boost::program_options::options_description& desc) const override; - void create( Cmd_ptr& cmd, - boost::program_options::variables_map& vm, - AbstractClientEnv* clientEnv ) const override; -private: - static const char* arg(); // used for argument parsing - static const char* desc(); // The description of the argument as provided to user - - STC_Cmd_ptr doHandleRequest(AbstractServer*) const override; - STC_Cmd_ptr alter_server_state(AbstractServer*) const; - bool authenticate(AbstractServer*, STC_Cmd_ptr&) const override; - void cleanup() override { std::vector().swap(paths_);} /// run in the server, after doHandleRequest - - void my_print(std::string& os, const std::vector& paths) const; - - Add_attr_type get_add_attr_type(const std::string&) const; - void createAdd( Cmd_ptr& cmd, std::vector& options, std::vector& paths) const; - void extract_name_and_value_for_add(Add_attr_type ,std::string& name,std::string& value, std::vector& options, std::vector& paths) const; - void check_for_add(Add_attr_type ,const std::string& name, const std::string& value) const; - - Delete_attr_type get_delete_attr_type(const std::string&) const; - void createDelete( Cmd_ptr& cmd, const std::vector& options, const std::vector& paths) const; - void extract_name_and_value_for_delete(Delete_attr_type,std::string& name,std::string& value,const std::vector& options,const std::vector& paths) const; - void check_for_delete(Delete_attr_type,const std::string& name, const std::string& value) const; - - Change_attr_type get_change_attr_type(const std::string&) const; - void createChange( Cmd_ptr& cmd, std::vector& options, std::vector& paths) const; - void extract_name_and_value_for_change(Change_attr_type,std::string& name,std::string& value,std::vector& options,std::vector& paths) const; - void check_for_change(Change_attr_type,const std::string& name, const std::string& value) const; - - ecf::Flag::Type get_flag_type(const std::string&) const; - void create_flag( Cmd_ptr& cmd, const std::vector& options, const std::vector& paths, bool flag) const; - - void check_sort_attr_type(const std::string&) const; - void create_sort_attributes(Cmd_ptr& cmd,const std::vector& options,const std::vector& paths ) const; + // add + AlterCmd(const std::string& path, Add_attr_type attr, const std::string& name, const std::string& value = "") + : paths_(std::vector(1, path)), + name_(name), + value_(value), + add_attr_type_(attr) {} + AlterCmd(const std::vector& paths, + Add_attr_type attr, + const std::string& name, + const std::string& value = "") + : paths_(paths), + name_(name), + value_(value), + add_attr_type_(attr) {} + // delete + AlterCmd(const std::string& path, Delete_attr_type del, const std::string& name = "", const std::string& value = "") + : paths_(std::vector(1, path)), + name_(name), + value_(value), + del_attr_type_(del) {} + AlterCmd(const std::vector& paths, + Delete_attr_type del, + const std::string& name = "", + const std::string& value = "") + : paths_(paths), + name_(name), + value_(value), + del_attr_type_(del) {} + // change + AlterCmd(const std::string& path, Change_attr_type attr, const std::string& name, const std::string& value = "") + : paths_(std::vector(1, path)), + name_(name), + value_(value), + change_attr_type_(attr) {} + AlterCmd(const std::vector& paths, + Change_attr_type attr, + const std::string& name, + const std::string& value = "") + : paths_(paths), + name_(name), + value_(value), + change_attr_type_(attr) {} + // flag + AlterCmd(const std::string& path, ecf::Flag::Type ft, bool flag) + : paths_(std::vector(1, path)), + flag_type_(ft), + flag_(flag) {} + AlterCmd(const std::vector& paths, ecf::Flag::Type ft, bool flag) + : paths_(paths), + flag_type_(ft), + flag_(flag) {} + // sort + AlterCmd(const std::string& path, const std::string& name, const std::string& value) + : paths_(std::vector(1, path)), + name_(name), + value_(value) {} + AlterCmd(const std::vector& paths, const std::string& name, const std::string& value) + : paths_(paths), + name_(name), + value_(value) {} + + AlterCmd() = default; + + // Uses by equals only + const std::vector& paths() const { return paths_; } + const std::string& name() const { return name_; } + const std::string& value() const { return value_; } + Delete_attr_type delete_attr_type() const { return del_attr_type_; } + Change_attr_type change_attr_type() const { return change_attr_type_; } + Add_attr_type add_attr_type() const { return add_attr_type_; } + ecf::Flag::Type flag_type() const { return flag_type_; } + bool flag() const { return flag_; } + + bool isWrite() const override { return true; } + void print(std::string&) const override; + void print(std::string& os, const std::string& path) const override; + void print_only(std::string&) const override; + bool equals(ClientToServerCmd*) const override; + + const char* theArg() const override { return arg(); } + void addOption(boost::program_options::options_description& desc) const override; + void create(Cmd_ptr& cmd, boost::program_options::variables_map& vm, AbstractClientEnv* clientEnv) const override; - void alter_and_attr_type(std::string& alter_type,std::string& attr_type ) const; +private: + static const char* arg(); // used for argument parsing + static const char* desc(); // The description of the argument as provided to user + + STC_Cmd_ptr doHandleRequest(AbstractServer*) const override; + STC_Cmd_ptr alter_server_state(AbstractServer*) const; + bool authenticate(AbstractServer*, STC_Cmd_ptr&) const override; + void cleanup() override { std::vector().swap(paths_); } /// run in the server, after doHandleRequest + + void my_print(std::string& os, const std::vector& paths) const; + + Add_attr_type get_add_attr_type(const std::string&) const; + void createAdd(Cmd_ptr& cmd, std::vector& options, std::vector& paths) const; + void extract_name_and_value_for_add(Add_attr_type, + std::string& name, + std::string& value, + std::vector& options, + std::vector& paths) const; + void check_for_add(Add_attr_type, const std::string& name, const std::string& value) const; + + Delete_attr_type get_delete_attr_type(const std::string&) const; + void + createDelete(Cmd_ptr& cmd, const std::vector& options, const std::vector& paths) const; + void extract_name_and_value_for_delete(Delete_attr_type, + std::string& name, + std::string& value, + const std::vector& options, + const std::vector& paths) const; + void check_for_delete(Delete_attr_type, const std::string& name, const std::string& value) const; + + Change_attr_type get_change_attr_type(const std::string&) const; + void createChange(Cmd_ptr& cmd, std::vector& options, std::vector& paths) const; + void extract_name_and_value_for_change(Change_attr_type, + std::string& name, + std::string& value, + std::vector& options, + std::vector& paths) const; + void check_for_change(Change_attr_type, const std::string& name, const std::string& value) const; + + ecf::Flag::Type get_flag_type(const std::string&) const; + void create_flag(Cmd_ptr& cmd, + const std::vector& options, + const std::vector& paths, + bool flag) const; + + void check_sort_attr_type(const std::string&) const; + void create_sort_attributes(Cmd_ptr& cmd, + const std::vector& options, + const std::vector& paths) const; + + void alter_and_attr_type(std::string& alter_type, std::string& attr_type) const; private: - std::vector paths_; - std::string name_; - std::string value_; - Add_attr_type add_attr_type_{ADD_ATTR_ND}; - Delete_attr_type del_attr_type_{DELETE_ATTR_ND}; - Change_attr_type change_attr_type_{CHANGE_ATTR_ND}; - ecf::Flag::Type flag_type_{ecf::Flag::NOT_SET}; - bool flag_{false}; // true means set false means clear - - friend class cereal::access; - template - void serialize(Archive & ar, std::uint32_t const /*version*/ ) - { - ar(cereal::base_class< UserCmd >( this ), - CEREAL_NVP(paths_), - CEREAL_NVP(name_), - CEREAL_NVP(value_), - CEREAL_NVP(add_attr_type_), - CEREAL_NVP(del_attr_type_), - CEREAL_NVP(change_attr_type_), - CEREAL_NVP(flag_type_), - CEREAL_NVP(flag_)); - } + std::vector paths_; + std::string name_; + std::string value_; + Add_attr_type add_attr_type_{ADD_ATTR_ND}; + Delete_attr_type del_attr_type_{DELETE_ATTR_ND}; + Change_attr_type change_attr_type_{CHANGE_ATTR_ND}; + ecf::Flag::Type flag_type_{ecf::Flag::NOT_SET}; + bool flag_{false}; // true means set false means clear + + friend class cereal::access; + template + void serialize(Archive& ar, std::uint32_t const /*version*/) { + ar(cereal::base_class(this), + CEREAL_NVP(paths_), + CEREAL_NVP(name_), + CEREAL_NVP(value_), + CEREAL_NVP(add_attr_type_), + CEREAL_NVP(del_attr_type_), + CEREAL_NVP(change_attr_type_), + CEREAL_NVP(flag_type_), + CEREAL_NVP(flag_)); + } }; //================================================================================ @@ -1803,50 +1850,47 @@ class AlterCmd final : public UserCmd { //================================================================================ class CFileCmd final : public UserCmd { public: - enum File_t { ECF, JOB, JOBOUT, MANUAL, KILL, STAT }; - CFileCmd(const std::string& pathToNode, File_t file, size_t max_lines) - : file_(file), pathToNode_(pathToNode), max_lines_(max_lines) {} - CFileCmd(const std::string& pathToNode, const std::string& file_type, const std::string& max_lines); - CFileCmd() = default; - - // Uses by equals only - const std::string& pathToNode() const { return pathToNode_; } - File_t fileType() const { return file_;} - size_t max_lines() const { return max_lines_;} - - static std::vector fileTypesVec(); - static std::string toString(File_t); - - bool handleRequestIsTestable() const override { return false ;} - void print(std::string&) const override; - void print_only(std::string&) const override; - bool equals(ClientToServerCmd*) const override; - - const char* theArg() const override { return arg();} - void addOption(boost::program_options::options_description& desc) const override; - void create( Cmd_ptr& cmd, - boost::program_options::variables_map& vm, - AbstractClientEnv* clientEnv ) const override; + enum File_t { ECF, JOB, JOBOUT, MANUAL, KILL, STAT }; + CFileCmd(const std::string& pathToNode, File_t file, size_t max_lines) + : file_(file), + pathToNode_(pathToNode), + max_lines_(max_lines) {} + CFileCmd(const std::string& pathToNode, const std::string& file_type, const std::string& max_lines); + CFileCmd() = default; + + // Uses by equals only + const std::string& pathToNode() const { return pathToNode_; } + File_t fileType() const { return file_; } + size_t max_lines() const { return max_lines_; } + + static std::vector fileTypesVec(); + static std::string toString(File_t); + + bool handleRequestIsTestable() const override { return false; } + void print(std::string&) const override; + void print_only(std::string&) const override; + bool equals(ClientToServerCmd*) const override; + + const char* theArg() const override { return arg(); } + void addOption(boost::program_options::options_description& desc) const override; + void create(Cmd_ptr& cmd, boost::program_options::variables_map& vm, AbstractClientEnv* clientEnv) const override; + private: - static const char* arg(); // used for argument parsing - static const char* desc(); // The description of the argument as provided to user - - STC_Cmd_ptr doHandleRequest(AbstractServer*) const override; - bool authenticate(AbstractServer*, STC_Cmd_ptr&) const override; - - File_t file_{ECF}; - std::string pathToNode_; - size_t max_lines_{0}; - - friend class cereal::access; - template - void serialize(Archive & ar, std::uint32_t const /*version*/ ) - { - ar(cereal::base_class< UserCmd >( this ), - CEREAL_NVP(file_), - CEREAL_NVP(pathToNode_), - CEREAL_NVP(max_lines_)); - } + static const char* arg(); // used for argument parsing + static const char* desc(); // The description of the argument as provided to user + + STC_Cmd_ptr doHandleRequest(AbstractServer*) const override; + bool authenticate(AbstractServer*, STC_Cmd_ptr&) const override; + + File_t file_{ECF}; + std::string pathToNode_; + size_t max_lines_{0}; + + friend class cereal::access; + template + void serialize(Archive& ar, std::uint32_t const /*version*/) { + ar(cereal::base_class(this), CEREAL_NVP(file_), CEREAL_NVP(pathToNode_), CEREAL_NVP(max_lines_)); + } }; //================================================================================ @@ -1855,215 +1899,215 @@ class CFileCmd final : public UserCmd { //================================================================================ class EditScriptCmd final : public UserCmd { public: - enum EditType { EDIT, PREPROCESS, SUBMIT, PREPROCESS_USER_FILE, SUBMIT_USER_FILE }; - EditScriptCmd(const std::string& path_to_node,EditType et) // EDIT or PREPROCESS - : edit_type_(et), path_to_node_(path_to_node) - {} - - EditScriptCmd(const std::string& path_to_node, const NameValueVec& user_variables) - : edit_type_(SUBMIT), path_to_node_(path_to_node), user_variables_(user_variables) - {} - - EditScriptCmd(const std::string& path_to_node, const std::vector& user_file_contents) - : edit_type_(PREPROCESS_USER_FILE), path_to_node_(path_to_node), user_file_contents_(user_file_contents) - {} - - EditScriptCmd( const std::string& path_to_node, + enum EditType { EDIT, PREPROCESS, SUBMIT, PREPROCESS_USER_FILE, SUBMIT_USER_FILE }; + EditScriptCmd(const std::string& path_to_node, EditType et) // EDIT or PREPROCESS + : edit_type_(et), + path_to_node_(path_to_node) {} + + EditScriptCmd(const std::string& path_to_node, const NameValueVec& user_variables) + : edit_type_(SUBMIT), + path_to_node_(path_to_node), + user_variables_(user_variables) {} + + EditScriptCmd(const std::string& path_to_node, const std::vector& user_file_contents) + : edit_type_(PREPROCESS_USER_FILE), + path_to_node_(path_to_node), + user_file_contents_(user_file_contents) {} + + EditScriptCmd(const std::string& path_to_node, const NameValueVec& user_variables, const std::vector& user_file_contents, bool create_alias, - bool run_alias - ) - : edit_type_(SUBMIT_USER_FILE), path_to_node_(path_to_node), user_file_contents_(user_file_contents),user_variables_(user_variables), - alias_(create_alias),run_(run_alias) - {} - - EditScriptCmd()= default; - - // Uses by equals only - const std::string& path_to_node() const { return path_to_node_; } - EditType edit_type() const { return edit_type_;} - bool alias() const { return alias_;} - bool run() const { return run_;} - - bool handleRequestIsTestable() const override { return false ;} - bool isWrite() const override; - void print(std::string&) const override; - void print_only(std::string&) const override; - bool equals(ClientToServerCmd*) const override; - - const char* theArg() const override { return arg();} - void addOption(boost::program_options::options_description& desc) const override; - void create( Cmd_ptr& cmd, - boost::program_options::variables_map& vm, - AbstractClientEnv* clientEnv ) const override; + bool run_alias) + : edit_type_(SUBMIT_USER_FILE), + path_to_node_(path_to_node), + user_file_contents_(user_file_contents), + user_variables_(user_variables), + alias_(create_alias), + run_(run_alias) {} + + EditScriptCmd() = default; + + // Uses by equals only + const std::string& path_to_node() const { return path_to_node_; } + EditType edit_type() const { return edit_type_; } + bool alias() const { return alias_; } + bool run() const { return run_; } + + bool handleRequestIsTestable() const override { return false; } + bool isWrite() const override; + void print(std::string&) const override; + void print_only(std::string&) const override; + bool equals(ClientToServerCmd*) const override; + + const char* theArg() const override { return arg(); } + void addOption(boost::program_options::options_description& desc) const override; + void create(Cmd_ptr& cmd, boost::program_options::variables_map& vm, AbstractClientEnv* clientEnv) const override; + private: - static const char* arg(); // used for argument parsing - static const char* desc(); // The description of the argument as provided to user + static const char* arg(); // used for argument parsing + static const char* desc(); // The description of the argument as provided to user - STC_Cmd_ptr doHandleRequest(AbstractServer*) const override; - bool authenticate(AbstractServer*, STC_Cmd_ptr&) const override; - void cleanup() override{ std::vector().swap(user_file_contents_);} /// run in the server, after doHandleRequest + STC_Cmd_ptr doHandleRequest(AbstractServer*) const override; + bool authenticate(AbstractServer*, STC_Cmd_ptr&) const override; + void cleanup() override { + std::vector().swap(user_file_contents_); + } /// run in the server, after doHandleRequest private: - EditType edit_type_{EDIT}; - std::string path_to_node_; - mutable std::vector user_file_contents_; - NameValueVec user_variables_; - bool alias_{false}; - bool run_{false}; - - friend class cereal::access; - template - void serialize(Archive & ar, std::uint32_t const /*version*/ ) - { - ar(cereal::base_class< UserCmd >( this ), - CEREAL_NVP(edit_type_), - CEREAL_NVP(path_to_node_), - CEREAL_NVP(user_file_contents_), - CEREAL_NVP(user_variables_), - CEREAL_NVP(alias_), - CEREAL_NVP(run_)); - } + EditType edit_type_{EDIT}; + std::string path_to_node_; + mutable std::vector user_file_contents_; + NameValueVec user_variables_; + bool alias_{false}; + bool run_{false}; + + friend class cereal::access; + template + void serialize(Archive& ar, std::uint32_t const /*version*/) { + ar(cereal::base_class(this), + CEREAL_NVP(edit_type_), + CEREAL_NVP(path_to_node_), + CEREAL_NVP(user_file_contents_), + CEREAL_NVP(user_variables_), + CEREAL_NVP(alias_), + CEREAL_NVP(run_)); + } }; class PlugCmd final : public UserCmd { public: - PlugCmd(const std::string& source, const std::string& dest) : source_(source), dest_(dest) {} - PlugCmd() = default; - - // Uses by equals only - const std::string& source() const { return source_; } - const std::string& dest() const { return dest_; } - - int timeout() const override { return 120; } - bool handleRequestIsTestable() const override { return false ;} - bool isWrite() const override { return true; } - void print(std::string&) const override; - void print_only(std::string&) const override; - bool equals(ClientToServerCmd*) const override; - - const char* theArg() const override { return arg();} - void addOption(boost::program_options::options_description& desc) const override; - void create( Cmd_ptr& cmd, - boost::program_options::variables_map& vm, - AbstractClientEnv* clientEnv ) const override; + PlugCmd(const std::string& source, const std::string& dest) : source_(source), dest_(dest) {} + PlugCmd() = default; + + // Uses by equals only + const std::string& source() const { return source_; } + const std::string& dest() const { return dest_; } + + int timeout() const override { return 120; } + bool handleRequestIsTestable() const override { return false; } + bool isWrite() const override { return true; } + void print(std::string&) const override; + void print_only(std::string&) const override; + bool equals(ClientToServerCmd*) const override; + + const char* theArg() const override { return arg(); } + void addOption(boost::program_options::options_description& desc) const override; + void create(Cmd_ptr& cmd, boost::program_options::variables_map& vm, AbstractClientEnv* clientEnv) const override; + private: - static const char* arg(); // used for argument parsing - static const char* desc(); // The description of the argument as provided to user + static const char* arg(); // used for argument parsing + static const char* desc(); // The description of the argument as provided to user - STC_Cmd_ptr doHandleRequest(AbstractServer*) const override; + STC_Cmd_ptr doHandleRequest(AbstractServer*) const override; private: - std::string source_; - std::string dest_; - - friend class cereal::access; - template - void serialize(Archive & ar, std::uint32_t const /*version*/ ) - { - ar(cereal::base_class< UserCmd >( this ), - CEREAL_NVP(source_), - CEREAL_NVP(dest_)); - } + std::string source_; + std::string dest_; + + friend class cereal::access; + template + void serialize(Archive& ar, std::uint32_t const /*version*/) { + ar(cereal::base_class(this), CEREAL_NVP(source_), CEREAL_NVP(dest_)); + } }; class MoveCmd final : public UserCmd { public: - MoveCmd(const std::pair& host_port, Node* src, const std::string& dest); - MoveCmd(); - ~MoveCmd() override; + MoveCmd(const std::pair& host_port, Node* src, const std::string& dest); + MoveCmd(); + ~MoveCmd() override; - Node* source() const; - const std::string& src_node() const { return src_node_;} - const std::string& dest() const { return dest_; } + Node* source() const; + const std::string& src_node() const { return src_node_; } + const std::string& dest() const { return dest_; } - bool handleRequestIsTestable() const override { return false ;} - bool isWrite() const override { return true; } + bool handleRequestIsTestable() const override { return false; } + bool isWrite() const override { return true; } - void print(std::string&) const override; - bool equals(ClientToServerCmd*) const override; + void print(std::string&) const override; + bool equals(ClientToServerCmd*) const override; + + const char* theArg() const override { return arg(); } + void addOption(boost::program_options::options_description& desc) const override; + void create(Cmd_ptr& cmd, boost::program_options::variables_map& vm, AbstractClientEnv* clientEnv) const override; - const char* theArg() const override { return arg();} - void addOption(boost::program_options::options_description& desc) const override; - void create( Cmd_ptr& cmd, - boost::program_options::variables_map& vm, - AbstractClientEnv* clientEnv ) const override; private: - static const char* arg(); // used for argument parsing - static const char* desc(); // The description of the argument as provided to user + static const char* arg(); // used for argument parsing + static const char* desc(); // The description of the argument as provided to user - STC_Cmd_ptr doHandleRequest(AbstractServer*) const override; + STC_Cmd_ptr doHandleRequest(AbstractServer*) const override; - bool check_source() const; + bool check_source() const; private: - std::string src_node_; - std::string src_host_; - std::string src_port_; - std::string src_path_; - std::string dest_; - - friend class cereal::access; - template - void serialize(Archive & ar, std::uint32_t const /*version*/ ) - { - ar(cereal::base_class< UserCmd >( this ), - CEREAL_NVP(src_node_), - CEREAL_NVP(src_host_), - CEREAL_NVP(src_port_), - CEREAL_NVP(src_path_), - CEREAL_NVP(dest_)); - } + std::string src_node_; + std::string src_host_; + std::string src_port_; + std::string src_path_; + std::string dest_; + + friend class cereal::access; + template + void serialize(Archive& ar, std::uint32_t const /*version*/) { + ar(cereal::base_class(this), + CEREAL_NVP(src_node_), + CEREAL_NVP(src_host_), + CEREAL_NVP(src_port_), + CEREAL_NVP(src_path_), + CEREAL_NVP(dest_)); + } }; class QueryCmd final : public UserCmd { public: - QueryCmd(const std::string& query_type, - const std::string& path_to_attribute, - const std::string& attribute, - const std::string& path_to_task ) - : query_type_(query_type),path_to_attribute_(path_to_attribute),attribute_(attribute),path_to_task_(path_to_task){} - QueryCmd() : UserCmd(){} - ~QueryCmd() override; - - const std::string& query_type() const { return query_type_; } - const std::string& path_to_attribute() const { return path_to_attribute_; } - const std::string& attribute() const { return attribute_; } - const std::string& path_to_task() const { return path_to_task_;} - - void print(std::string&) const override; - void print_only(std::string&) const override; - bool equals(ClientToServerCmd*) const override; - - const char* theArg() const override { return arg();} - void addOption(boost::program_options::options_description& desc) const override; - void create( Cmd_ptr& cmd, - boost::program_options::variables_map& vm, - AbstractClientEnv* clientEnv ) const override; + QueryCmd(const std::string& query_type, + const std::string& path_to_attribute, + const std::string& attribute, + const std::string& path_to_task) + : query_type_(query_type), + path_to_attribute_(path_to_attribute), + attribute_(attribute), + path_to_task_(path_to_task) {} + QueryCmd() : UserCmd() {} + ~QueryCmd() override; + + const std::string& query_type() const { return query_type_; } + const std::string& path_to_attribute() const { return path_to_attribute_; } + const std::string& attribute() const { return attribute_; } + const std::string& path_to_task() const { return path_to_task_; } + + void print(std::string&) const override; + void print_only(std::string&) const override; + bool equals(ClientToServerCmd*) const override; + + const char* theArg() const override { return arg(); } + void addOption(boost::program_options::options_description& desc) const override; + void create(Cmd_ptr& cmd, boost::program_options::variables_map& vm, AbstractClientEnv* clientEnv) const override; + private: - static const char* arg(); // used for argument parsing - static const char* desc(); // The description of the argument as provided to user + static const char* arg(); // used for argument parsing + static const char* desc(); // The description of the argument as provided to user - bool handleRequestIsTestable() const override { return false;} - STC_Cmd_ptr doHandleRequest(AbstractServer*) const override; + bool handleRequestIsTestable() const override { return false; } + STC_Cmd_ptr doHandleRequest(AbstractServer*) const override; private: - std::string query_type_; // [ state | dstate | event | meter | label | trigger ] - std::string path_to_attribute_; - std::string attribute_; // [ event_name | meter_name | label_name | variable_name | trigger expression] empty for state and dstate - std::string path_to_task_; // The task the invoked this command, needed for logging - - friend class cereal::access; - template - void serialize(Archive & ar, std::uint32_t const /*version*/ ) - { - ar(cereal::base_class< UserCmd >( this ), - CEREAL_NVP(query_type_), - CEREAL_NVP(path_to_attribute_), - CEREAL_NVP(attribute_), - CEREAL_NVP(path_to_task_)); - } + std::string query_type_; // [ state | dstate | event | meter | label | trigger ] + std::string path_to_attribute_; + std::string attribute_; // [ event_name | meter_name | label_name | variable_name | trigger expression] empty for + // state and dstate + std::string path_to_task_; // The task the invoked this command, needed for logging + + friend class cereal::access; + template + void serialize(Archive& ar, std::uint32_t const /*version*/) { + ar(cereal::base_class(this), + CEREAL_NVP(query_type_), + CEREAL_NVP(path_to_attribute_), + CEREAL_NVP(attribute_), + CEREAL_NVP(path_to_task_)); + } }; // The group command allows a series of commands to be be executed: @@ -2079,62 +2123,56 @@ class QueryCmd final : public UserCmd { // class GroupCTSCmd final : public UserCmd { public: - GroupCTSCmd(const std::string& list_of_commands,AbstractClientEnv* clientEnv); - explicit GroupCTSCmd(Cmd_ptr cmd) : cli_(false) { addChild(cmd);} - GroupCTSCmd()= default; + GroupCTSCmd(const std::string& list_of_commands, AbstractClientEnv* clientEnv); + explicit GroupCTSCmd(Cmd_ptr cmd) : cli_(false) { addChild(cmd); } + GroupCTSCmd() = default; - bool isWrite() const override; - bool cmd_updates_defs() const override; + bool isWrite() const override; + bool cmd_updates_defs() const override; - PrintStyle::Type_t show_style() const override; - bool get_cmd() const override; - bool task_cmd() const override; - bool terminate_cmd() const override; - bool why_cmd( std::string& ) const override; - bool group_cmd() const override { return true; } + PrintStyle::Type_t show_style() const override; + bool get_cmd() const override; + bool task_cmd() const override; + bool terminate_cmd() const override; + bool why_cmd(std::string&) const override; + bool group_cmd() const override { return true; } - void set_client_handle(int client_handle) const; // used in group sync with client register + void set_client_handle(int client_handle) const; // used in group sync with client register - void print(std::string&) const override; - std::string print_short() const override; - bool equals(ClientToServerCmd*) const override; + void print(std::string&) const override; + std::string print_short() const override; + bool equals(ClientToServerCmd*) const override; - void addChild(Cmd_ptr childCmd); - const std::vector& cmdVec() const { return cmdVec_;} + void addChild(Cmd_ptr childCmd); + const std::vector& cmdVec() const { return cmdVec_; } - const char* theArg() const override { return arg();} - void addOption(boost::program_options::options_description& desc) const override; - void create( Cmd_ptr& cmd, - boost::program_options::variables_map& vm, - AbstractClientEnv* clientEnv ) const override; + const char* theArg() const override { return arg(); } + void addOption(boost::program_options::options_description& desc) const override; + void create(Cmd_ptr& cmd, boost::program_options::variables_map& vm, AbstractClientEnv* clientEnv) const override; - void add_edit_history(Defs*) const override; + void add_edit_history(Defs*) const override; private: - static const char* arg(); // used for argument parsing - static const char* desc(); // The description of the argument as provided to user + static const char* arg(); // used for argument parsing + static const char* desc(); // The description of the argument as provided to user - void setup_user_authentification(const std::string& user, const std::string& passwd) override; - bool setup_user_authentification(AbstractClientEnv&) override; - void setup_user_authentification() override; + void setup_user_authentification(const std::string& user, const std::string& passwd) override; + bool setup_user_authentification(AbstractClientEnv&) override; + void setup_user_authentification() override; - bool authenticate(AbstractServer*, STC_Cmd_ptr&) const override; - STC_Cmd_ptr doHandleRequest(AbstractServer*) const override; - void cleanup() override; // cleanup all children + bool authenticate(AbstractServer*, STC_Cmd_ptr&) const override; + STC_Cmd_ptr doHandleRequest(AbstractServer*) const override; + void cleanup() override; // cleanup all children private: - std::vector cmdVec_; - bool cli_{true}; - - friend class cereal::access; - template - void serialize(Archive & ar, std::uint32_t const /*version*/ ) - { - ar(cereal::base_class< UserCmd >( this ), - CEREAL_NVP(cmdVec_), - CEREAL_NVP(cli_) - ); - } + std::vector cmdVec_; + bool cli_{true}; + + friend class cereal::access; + template + void serialize(Archive& ar, std::uint32_t const /*version*/) { + ar(cereal::base_class(this), CEREAL_NVP(cmdVec_), CEREAL_NVP(cli_)); + } }; std::ostream& operator<<(std::ostream& os, const ServerVersionCmd&); diff --git a/Base/src/cts/CtsApi.hpp b/Base/src/cts/CtsApi.hpp index 706b9dda6..2e04a6518 100644 --- a/Base/src/cts/CtsApi.hpp +++ b/Base/src/cts/CtsApi.hpp @@ -3,21 +3,22 @@ //============================================================================ // Name : // Author : Avi -// Revision : $Revision: #74 $ +// Revision : $Revision: #74 $ // // Copyright 2009- ECMWF. -// This software is licensed under the terms of the Apache Licence version 2.0 -// which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. -// In applying this licence, ECMWF does not waive the privileges and immunities -// granted to it by virtue of its status as an intergovernmental organisation -// nor does it submit to any jurisdiction. +// This software is licensed under the terms of the Apache Licence version 2.0 +// which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. +// In applying this licence, ECMWF does not waive the privileges and immunities +// granted to it by virtue of its status as an intergovernmental organisation +// nor does it submit to any jurisdiction. // // Description : (C)lient (t)o (s)erver API //============================================================================ #include #include -#include "NodeFwd.hpp" + #include "CheckPt.hpp" +#include "NodeFwd.hpp" // The two variant api must correspond i.e '--get' and 'get' since this is used by boost program options // ************************************************************************************* @@ -25,222 +26,259 @@ // *************************************************************************************** class CtsApi { public: - CtsApi(const CtsApi&) = delete; - const CtsApi& operator=(const CtsApi&) = delete; - - static std::string to_string(const std::vector& ); - - static std::string server_version(); - - // For python - static defs_ptr load( defs_ptr defs) { return defs;} - static std::vector loadDefs(const std::string& filePath,bool force,bool check_only,bool print); // check_only & print are client side only - static std::string get(const std::string& absNodePath = ""); - static std::string get_state(const std::string& absNodePath = ""); - static std::string migrate(const std::string& absNodePath = ""); - static std::vector sync(unsigned int client_handle, unsigned int state_change_no, unsigned int modify_change_no ); - static std::vector sync_clock(unsigned int client_handle, unsigned int state_change_no, unsigned int modify_change_no ); - static std::string sync_full(unsigned int client_handle); - static std::vector news(unsigned int client_handle, unsigned int state_change_no, unsigned int modify_change_no ); - - static std::vector ch_register(int client_handle, bool auto_add_new_suites, const std::vector& suites); - static std::string ch_suites(); - static std::string ch_drop(int client_handle); - static std::string ch_drop_user(const std::string& user); - static std::vector ch_add(int client_handle, const std::vector& suites); - static std::vector ch_remove(int client_handle, const std::vector& suites); - static std::vector ch_auto_add(int client_handle, bool auto_add_new_suites); - static std::string suites(); // returns list if all suites, and client handles. - - static std::string restartServer(); - static std::string haltServer(bool auto_confirm = true); - static std::string shutdownServer(bool auto_confirm = true); - static std::string terminateServer(bool auto_confirm = true); - static std::string pingServer(); - static std::string server_load(const std::string& path_to_log_file); - static std::string debug_server_on(); - static std::string debug_server_off(); - - // odd one out, take multi-args but expects string - static std::string begin(const std::string& suiteName = "", bool force = false); // no suite begins all suites - - static std::string job_gen(const std::string& absNodePath = ""); - static std::string checkJobGenOnly(const std::string& absNodePath = ""); - - static std::vector check(const std::string& absNodePath = ""); - static std::vector check(const std::vector& paths); - static std::vector delete_node(const std::vector& paths, bool force = false, bool auto_confirm = true); // no paths specified ,delete all suites, for test - static std::vector delete_node(const std::string& absNodePath = "", bool force = false, bool auto_confirm = true); // no node specified ,delete all suites, for test - static std::vector suspend(const std::string& absNodePath); - static std::vector suspend(const std::vector& paths); - static std::vector resume(const std::string& absNodePath); - static std::vector resume(const std::vector& paths); - static std::vector kill(const std::string& absNodePath); - static std::vector kill(const std::vector& paths); - static std::vector status(const std::string& absNodePath); - static std::vector status(const std::vector& paths); - static std::vector edit_history(const std::vector& paths); - static std::vector edit_history(const std::string& absNodePath); - static std::vector archive(const std::vector& paths,bool force = false); - static std::vector archive(const std::string& absNodePath,bool force = false); - static std::vector restore(const std::vector& paths); - static std::vector restore(const std::string& absNodePath); - - static std::string why(const std::string& absNodePath); - static std::string zombieGet(); - static std::vector zombieFob(const std::vector& paths,const std::string& process_id, const std::string& password); - static std::vector zombieFail(const std::vector& paths,const std::string& process_id, const std::string& password); - static std::vector zombieAdopt(const std::vector& paths,const std::string& process_id, const std::string& password); - static std::vector zombieRemove(const std::vector& paths,const std::string& process_id, const std::string& password); - static std::vector zombieBlock(const std::vector& paths,const std::string& process_id, const std::string& password); - static std::vector zombieKill(const std::vector& paths,const std::string& process_id, const std::string& password); - static std::string zombieFobCli(const std::string& task_path); - static std::string zombieFailCli(const std::string& task_path); - static std::string zombieAdoptCli(const std::string& task_path); - static std::string zombieRemoveCli(const std::string& task_path); - static std::string zombieBlockCli(const std::string& task_path); - static std::string zombieKillCli(const std::string& task_path); - static std::vector zombieFobCli(const std::vector& paths); - static std::vector zombieFailCli(const std::vector& paths); - static std::vector zombieAdoptCli(const std::vector& paths); - static std::vector zombieRemoveCli(const std::vector& paths); - static std::vector zombieBlockCli(const std::vector& paths); - static std::vector zombieKillCli(const std::vector& paths); - - static std::vector replace( const std::string& absNodePath, - const std::string& path_to_client_defs, - bool create_parents_as_required = true, - bool force = false); - static std::vector requeue(const std::vector& paths, const std::string& option/* [ "" | "force" | "abort" ] */); - static std::vector requeue(const std::string& absNodePath, const std::string& option/* [ "" | "force" | "abort" ] */); - static std::vector run(const std::vector& paths,bool force = false); - static std::vector run(const std::string& absNodePath,bool force = false); - static std::vector order(const std::string& absNodePath,const std::string& orderType); - - static std::string checkPtDefs(ecf::CheckPt::Mode m = ecf::CheckPt::UNDEFINED, int check_pt_interval = 0, int check_pt_save_time_alarm = 0); - static std::string restoreDefsFromCheckPt(); - - static std::vector force(const std::vector& paths,const std::string& state_or_event,bool recursive = false,bool set_repeats_to_last_value = false); - static std::vector force(const std::string& path,const std::string& state_or_event,bool recursive = false,bool set_repeats_to_last_value = false); - - static std::vector freeDep(const std::vector& paths,bool trigger = true, bool all = false, bool date = false, bool time = false); - static std::vector freeDep(const std::string& absNodePath,bool trigger = true, bool all = false, bool date = false, bool time = false); - - static std::vector file(const std::string& absNodePath, const std::string& fileType, const std::string& max_lines); - static std::vector plug(const std::string& sourcePath, const std::string& destPath); - - static std::vector alter(const std::string& path, - const std::string& alterType, /* one of [ 'add' | 'change' | 'delete' | 'set_flag' | 'clear_flag' ] */ - const std::string& attrType, - const std::string& name = "", - const std::string& value = ""); - static std::vector alter(const std::vector& paths, - const std::string& alterType, /* one of [ 'add' | 'change' | 'delete' | 'set_flag' | 'clear_flag' ] */ - const std::string& attrType, - const std::string& name = "", - const std::string& value = ""); - static std::vector alter_sort(const std::vector& paths, - const std::string& sortable_attribute_name, - bool recursive); - - - static std::string reloadwsfile(); - static std::string reloadpasswdfile(); - static std::string reloadcustompasswdfile(); - - // "expect string of the form "shutdown; get" must be ';' separated - static std::string group(const std::string& cmds); - - static std::string logMsg(const std::string& theMsgToLog); - static std::vector getLog(int lastLines = 0); - static std::vector new_log(const std::string& new_path); - static std::string get_log_path(); - static std::string clearLog(); - static std::string flushLog(); - static std::string forceDependencyEval(); - - static std::string stats(); - static std::string stats_server(); // used in test, as serialisation subject to change - static std::string stats_reset(); - - static std::vector edit_script(const std::string& path_to_task, - const std::string& edit_type, - const std::string& path_to_script = "", - bool create_alias = false, - bool run = true); - static std::vector query( - const std::string& query_type, const std::string& path_to_attribute, - const std::string& attribute); - - // Only to be used in Cmd - static const char* server_version_arg(); - static const char* statsArg(); - static const char* stats_server_arg(); - static const char* stats_reset_arg(); - static const char* suitesArg(); - static const char* ch_register_arg(); - static const char* ch_drop_arg(); - static const char* ch_suites_arg(); - static const char* ch_drop_user_arg(); - static const char* ch_add_arg(); - static const char* ch_remove_arg(); - static const char* ch_auto_add_arg(); - - static const char* terminateServerArg(); - static const char* restartServerArg(); - static const char* haltServerArg(); - static const char* shutdownServerArg(); - static const char* pingServerArg(); - static const char* server_load_arg(); - static const char* debug_server_on_arg(); - static const char* debug_server_off_arg(); - - static const char* getArg(); - static const char* get_state_arg(); - static const char* migrate_arg(); - static const char* syncArg(); - static const char* sync_clock_arg(); - static const char* sync_full_arg(); - static const char* newsArg(); - static const char* loadDefsArg(); - static const char* beginArg(); - static const char* job_genArg(); - static const char* check_arg(); - static const char* checkJobGenOnlyArg(); - static const char* delete_node_arg(); - static const char* suspend_arg(); - static const char* resume_arg(); - static const char* kill_arg(); - static const char* statusArg(); - static const char* edit_history_arg(); - static const char* archive_arg(); - static const char* restore_arg(); - static const char* whyArg(); - static const char* zombieGetArg(); - static const char* zombieFobArg(); - static const char* zombieFailArg(); - static const char* zombieAdoptArg(); - static const char* zombieRemoveArg(); - static const char* zombieBlockArg(); - static const char* zombieKillArg(); - static const char* replace_arg(); - static const char* requeueArg(); - static const char* runArg(); - static const char* orderArg(); - static const char* checkPtDefsArg(); - static const char* restoreDefsFromCheckPtArg(); - static const char* logMsgArg(); - static const char* forceArg(); - static const char* freeDepArg(); - static const char* fileArg(); - static const char* plugArg(); - static const char* reloadwsfileArg(); - static const char* reloadpasswdfile_arg(); - static const char* reloadcustompasswdfile_arg(); - static const char* groupArg(); - static const char* forceDependencyEvalArg(); - static const char* alterArg(); - static const char* edit_script_arg(); - static const char* queryArg(); + CtsApi(const CtsApi&) = delete; + const CtsApi& operator=(const CtsApi&) = delete; + + static std::string to_string(const std::vector&); + + static std::string server_version(); + + // For python + static defs_ptr load(defs_ptr defs) { return defs; } + static std::vector loadDefs(const std::string& filePath, + bool force, + bool check_only, + bool print); // check_only & print are client side only + static std::string get(const std::string& absNodePath = ""); + static std::string get_state(const std::string& absNodePath = ""); + static std::string migrate(const std::string& absNodePath = ""); + static std::vector + sync(unsigned int client_handle, unsigned int state_change_no, unsigned int modify_change_no); + static std::vector + sync_clock(unsigned int client_handle, unsigned int state_change_no, unsigned int modify_change_no); + static std::string sync_full(unsigned int client_handle); + static std::vector + news(unsigned int client_handle, unsigned int state_change_no, unsigned int modify_change_no); + + static std::vector + ch_register(int client_handle, bool auto_add_new_suites, const std::vector& suites); + static std::string ch_suites(); + static std::string ch_drop(int client_handle); + static std::string ch_drop_user(const std::string& user); + static std::vector ch_add(int client_handle, const std::vector& suites); + static std::vector ch_remove(int client_handle, const std::vector& suites); + static std::vector ch_auto_add(int client_handle, bool auto_add_new_suites); + static std::string suites(); // returns list if all suites, and client handles. + + static std::string restartServer(); + static std::string haltServer(bool auto_confirm = true); + static std::string shutdownServer(bool auto_confirm = true); + static std::string terminateServer(bool auto_confirm = true); + static std::string pingServer(); + static std::string server_load(const std::string& path_to_log_file); + static std::string debug_server_on(); + static std::string debug_server_off(); + + // odd one out, take multi-args but expects string + static std::string begin(const std::string& suiteName = "", bool force = false); // no suite begins all suites + + static std::string job_gen(const std::string& absNodePath = ""); + static std::string checkJobGenOnly(const std::string& absNodePath = ""); + + static std::vector check(const std::string& absNodePath = ""); + static std::vector check(const std::vector& paths); + static std::vector + delete_node(const std::vector& paths, + bool force = false, + bool auto_confirm = true); // no paths specified ,delete all suites, for test + static std::vector + delete_node(const std::string& absNodePath = "", + bool force = false, + bool auto_confirm = true); // no node specified ,delete all suites, for test + static std::vector suspend(const std::string& absNodePath); + static std::vector suspend(const std::vector& paths); + static std::vector resume(const std::string& absNodePath); + static std::vector resume(const std::vector& paths); + static std::vector kill(const std::string& absNodePath); + static std::vector kill(const std::vector& paths); + static std::vector status(const std::string& absNodePath); + static std::vector status(const std::vector& paths); + static std::vector edit_history(const std::vector& paths); + static std::vector edit_history(const std::string& absNodePath); + static std::vector archive(const std::vector& paths, bool force = false); + static std::vector archive(const std::string& absNodePath, bool force = false); + static std::vector restore(const std::vector& paths); + static std::vector restore(const std::string& absNodePath); + + static std::string why(const std::string& absNodePath); + static std::string zombieGet(); + static std::vector + zombieFob(const std::vector& paths, const std::string& process_id, const std::string& password); + static std::vector + zombieFail(const std::vector& paths, const std::string& process_id, const std::string& password); + static std::vector + zombieAdopt(const std::vector& paths, const std::string& process_id, const std::string& password); + static std::vector + zombieRemove(const std::vector& paths, const std::string& process_id, const std::string& password); + static std::vector + zombieBlock(const std::vector& paths, const std::string& process_id, const std::string& password); + static std::vector + zombieKill(const std::vector& paths, const std::string& process_id, const std::string& password); + static std::string zombieFobCli(const std::string& task_path); + static std::string zombieFailCli(const std::string& task_path); + static std::string zombieAdoptCli(const std::string& task_path); + static std::string zombieRemoveCli(const std::string& task_path); + static std::string zombieBlockCli(const std::string& task_path); + static std::string zombieKillCli(const std::string& task_path); + static std::vector zombieFobCli(const std::vector& paths); + static std::vector zombieFailCli(const std::vector& paths); + static std::vector zombieAdoptCli(const std::vector& paths); + static std::vector zombieRemoveCli(const std::vector& paths); + static std::vector zombieBlockCli(const std::vector& paths); + static std::vector zombieKillCli(const std::vector& paths); + + static std::vector replace(const std::string& absNodePath, + const std::string& path_to_client_defs, + bool create_parents_as_required = true, + bool force = false); + static std::vector requeue(const std::vector& paths, + const std::string& option /* [ "" | "force" | "abort" ] */); + static std::vector requeue(const std::string& absNodePath, + const std::string& option /* [ "" | "force" | "abort" ] */); + static std::vector run(const std::vector& paths, bool force = false); + static std::vector run(const std::string& absNodePath, bool force = false); + static std::vector order(const std::string& absNodePath, const std::string& orderType); + + static std::string checkPtDefs(ecf::CheckPt::Mode m = ecf::CheckPt::UNDEFINED, + int check_pt_interval = 0, + int check_pt_save_time_alarm = 0); + static std::string restoreDefsFromCheckPt(); + + static std::vector force(const std::vector& paths, + const std::string& state_or_event, + bool recursive = false, + bool set_repeats_to_last_value = false); + static std::vector force(const std::string& path, + const std::string& state_or_event, + bool recursive = false, + bool set_repeats_to_last_value = false); + + static std::vector freeDep(const std::vector& paths, + bool trigger = true, + bool all = false, + bool date = false, + bool time = false); + static std::vector freeDep(const std::string& absNodePath, + bool trigger = true, + bool all = false, + bool date = false, + bool time = false); + + static std::vector + file(const std::string& absNodePath, const std::string& fileType, const std::string& max_lines); + static std::vector plug(const std::string& sourcePath, const std::string& destPath); + + static std::vector + alter(const std::string& path, + const std::string& alterType, /* one of [ 'add' | 'change' | 'delete' | 'set_flag' | 'clear_flag' ] */ + const std::string& attrType, + const std::string& name = "", + const std::string& value = ""); + static std::vector + alter(const std::vector& paths, + const std::string& alterType, /* one of [ 'add' | 'change' | 'delete' | 'set_flag' | 'clear_flag' ] */ + const std::string& attrType, + const std::string& name = "", + const std::string& value = ""); + static std::vector + alter_sort(const std::vector& paths, const std::string& sortable_attribute_name, bool recursive); + + static std::string reloadwsfile(); + static std::string reloadpasswdfile(); + static std::string reloadcustompasswdfile(); + + // "expect string of the form "shutdown; get" must be ';' separated + static std::string group(const std::string& cmds); + + static std::string logMsg(const std::string& theMsgToLog); + static std::vector getLog(int lastLines = 0); + static std::vector new_log(const std::string& new_path); + static std::string get_log_path(); + static std::string clearLog(); + static std::string flushLog(); + static std::string forceDependencyEval(); + + static std::string stats(); + static std::string stats_server(); // used in test, as serialisation subject to change + static std::string stats_reset(); + + static std::vector edit_script(const std::string& path_to_task, + const std::string& edit_type, + const std::string& path_to_script = "", + bool create_alias = false, + bool run = true); + static std::vector + query(const std::string& query_type, const std::string& path_to_attribute, const std::string& attribute); + + // Only to be used in Cmd + static const char* server_version_arg(); + static const char* statsArg(); + static const char* stats_server_arg(); + static const char* stats_reset_arg(); + static const char* suitesArg(); + static const char* ch_register_arg(); + static const char* ch_drop_arg(); + static const char* ch_suites_arg(); + static const char* ch_drop_user_arg(); + static const char* ch_add_arg(); + static const char* ch_remove_arg(); + static const char* ch_auto_add_arg(); + + static const char* terminateServerArg(); + static const char* restartServerArg(); + static const char* haltServerArg(); + static const char* shutdownServerArg(); + static const char* pingServerArg(); + static const char* server_load_arg(); + static const char* debug_server_on_arg(); + static const char* debug_server_off_arg(); + + static const char* getArg(); + static const char* get_state_arg(); + static const char* migrate_arg(); + static const char* syncArg(); + static const char* sync_clock_arg(); + static const char* sync_full_arg(); + static const char* newsArg(); + static const char* loadDefsArg(); + static const char* beginArg(); + static const char* job_genArg(); + static const char* check_arg(); + static const char* checkJobGenOnlyArg(); + static const char* delete_node_arg(); + static const char* suspend_arg(); + static const char* resume_arg(); + static const char* kill_arg(); + static const char* statusArg(); + static const char* edit_history_arg(); + static const char* archive_arg(); + static const char* restore_arg(); + static const char* whyArg(); + static const char* zombieGetArg(); + static const char* zombieFobArg(); + static const char* zombieFailArg(); + static const char* zombieAdoptArg(); + static const char* zombieRemoveArg(); + static const char* zombieBlockArg(); + static const char* zombieKillArg(); + static const char* replace_arg(); + static const char* requeueArg(); + static const char* runArg(); + static const char* orderArg(); + static const char* checkPtDefsArg(); + static const char* restoreDefsFromCheckPtArg(); + static const char* logMsgArg(); + static const char* forceArg(); + static const char* freeDepArg(); + static const char* fileArg(); + static const char* plugArg(); + static const char* reloadwsfileArg(); + static const char* reloadpasswdfile_arg(); + static const char* reloadcustompasswdfile_arg(); + static const char* groupArg(); + static const char* forceDependencyEvalArg(); + static const char* alterArg(); + static const char* edit_script_arg(); + static const char* queryArg(); }; #endif diff --git a/Base/src/cts/CtsCmdRegistry.hpp b/Base/src/cts/CtsCmdRegistry.hpp index b1c592108..456c67bb8 100644 --- a/Base/src/cts/CtsCmdRegistry.hpp +++ b/Base/src/cts/CtsCmdRegistry.hpp @@ -3,14 +3,14 @@ //============================================================================ // Name : // Author : Avi -// Revision : $Revision: #5 $ +// Revision : $Revision: #5 $ // // Copyright 2009- ECMWF. -// This software is licensed under the terms of the Apache Licence version 2.0 -// which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. -// In applying this licence, ECMWF does not waive the privileges and immunities -// granted to it by virtue of its status as an intergovernmental organisation -// nor does it submit to any jurisdiction. +// This software is licensed under the terms of the Apache Licence version 2.0 +// which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. +// In applying this licence, ECMWF does not waive the privileges and immunities +// granted to it by virtue of its status as an intergovernmental organisation +// nor does it submit to any jurisdiction. // // Description : Registration of all the client to server commands // This allows us to parse the arg associated with @@ -20,39 +20,39 @@ // must be added to this class. //============================================================================ -#include #include + +#include + #include "Cmd.hpp" class AbstractClientEnv; class CtsCmdRegistry { public: - CtsCmdRegistry(const CtsCmdRegistry&) = delete; - const CtsCmdRegistry& operator=(const CtsCmdRegistry&) = delete; - - explicit CtsCmdRegistry(bool addGroupCmd = true ); - - /// These option describe the arguments for each of the commands - /// They also can be presented to the user via --help option. - void addAllOptions(boost::program_options::options_description& desc) const; - void addCmdOptions(boost::program_options::options_description& desc) const; - - /// Parse arguments given in 'vm' and use that to create a command - /// that will be sent to the server. Will throw std::runtime_error for errors - /// Returns true if command line argument specified via 'vm', matches one of the - /// registered command. - /// *** This allows us to distinguish between where we match with a registered - /// *** command, but do *NOT* set Cmd_ptr, ie since its a client specific command - /// *** i.e there is no need to send it to the server - bool parse( Cmd_ptr& cmd, - boost::program_options::variables_map& vm, - AbstractClientEnv* clientEnv ) const; + CtsCmdRegistry(const CtsCmdRegistry&) = delete; + const CtsCmdRegistry& operator=(const CtsCmdRegistry&) = delete; + + explicit CtsCmdRegistry(bool addGroupCmd = true); + + /// These option describe the arguments for each of the commands + /// They also can be presented to the user via --help option. + void addAllOptions(boost::program_options::options_description& desc) const; + void addCmdOptions(boost::program_options::options_description& desc) const; + + /// Parse arguments given in 'vm' and use that to create a command + /// that will be sent to the server. Will throw std::runtime_error for errors + /// Returns true if command line argument specified via 'vm', matches one of the + /// registered command. + /// *** This allows us to distinguish between where we match with a registered + /// *** command, but do *NOT* set Cmd_ptr, ie since its a client specific command + /// *** i.e there is no need to send it to the server + bool parse(Cmd_ptr& cmd, boost::program_options::variables_map& vm, AbstractClientEnv* clientEnv) const; private: - std::vector vec_; + std::vector vec_; - void addHelpOption(boost::program_options::options_description& desc) const; + void addHelpOption(boost::program_options::options_description& desc) const; }; #endif diff --git a/Base/src/cts/EditHistoryMgr.hpp b/Base/src/cts/EditHistoryMgr.hpp index 4593f7e4e..dc40b3f06 100644 --- a/Base/src/cts/EditHistoryMgr.hpp +++ b/Base/src/cts/EditHistoryMgr.hpp @@ -22,15 +22,15 @@ class ClientToServerCmd; class AbstractServer; -class EditHistoryMgr : private boost::noncopyable { +class EditHistoryMgr : private boost::noncopyable { public: - EditHistoryMgr(const ClientToServerCmd*,AbstractServer*); - ~EditHistoryMgr(); + EditHistoryMgr(const ClientToServerCmd*, AbstractServer*); + ~EditHistoryMgr(); private: - const ClientToServerCmd* cts_cmd_; - AbstractServer* as_; - mutable unsigned int state_change_no_; // detect state change in defs - mutable unsigned int modify_change_no_; // detect state change in defs + const ClientToServerCmd* cts_cmd_; + AbstractServer* as_; + mutable unsigned int state_change_no_; // detect state change in defs + mutable unsigned int modify_change_no_; // detect state change in defs }; #endif diff --git a/Base/src/cts/TaskApi.hpp b/Base/src/cts/TaskApi.hpp index c9db3cbca..628f1b1b8 100644 --- a/Base/src/cts/TaskApi.hpp +++ b/Base/src/cts/TaskApi.hpp @@ -3,14 +3,14 @@ //============================================================================ // Name : // Author : Avi -// Revision : $Revision: #4 $ +// Revision : $Revision: #4 $ // // Copyright 2009- ECMWF. -// This software is licensed under the terms of the Apache Licence version 2.0 -// which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. -// In applying this licence, ECMWF does not waive the privileges and immunities -// granted to it by virtue of its status as an intergovernmental organisation -// nor does it submit to any jurisdiction. +// This software is licensed under the terms of the Apache Licence version 2.0 +// which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. +// In applying this licence, ECMWF does not waive the privileges and immunities +// granted to it by virtue of its status as an intergovernmental organisation +// nor does it submit to any jurisdiction. // // Description : Task api. i.e the child commands, typically called from the jobs files // The two variant api must correspond i.e '--get' and 'get' @@ -21,27 +21,30 @@ class TaskApi { public: - TaskApi(const TaskApi&) = delete; - const TaskApi& operator=(const TaskApi&) = delete; + TaskApi(const TaskApi&) = delete; + const TaskApi& operator=(const TaskApi&) = delete; - /// Used to construct arguments, for argc,argv - static std::string init(const std::string& process_id); - static std::string abort(const std::string& reason = ""); - static std::vector event(const std::string& eventName,const std::string& value = "set"); - static std::vector meter(const std::string& meterName,const std::string& metervalue); - static std::vector queue(const std::string& queueName,const std::string& action, const std::string& step,const std::string& path_to_node_with_queue); - static std::vector label(const std::string& label_name, const std::vector& labels ); - static std::string complete(); - static std::string wait(const std::string& expression); + /// Used to construct arguments, for argc,argv + static std::string init(const std::string& process_id); + static std::string abort(const std::string& reason = ""); + static std::vector event(const std::string& eventName, const std::string& value = "set"); + static std::vector meter(const std::string& meterName, const std::string& metervalue); + static std::vector queue(const std::string& queueName, + const std::string& action, + const std::string& step, + const std::string& path_to_node_with_queue); + static std::vector label(const std::string& label_name, const std::vector& labels); + static std::string complete(); + static std::string wait(const std::string& expression); - // Only to be used in Cmd - static const char* initArg(); - static const char* abortArg(); - static const char* eventArg(); - static const char* meterArg(); - static const char* queue_arg(); - static const char* labelArg(); - static const char* completeArg(); - static const char* waitArg(); + // Only to be used in Cmd + static const char* initArg(); + static const char* abortArg(); + static const char* eventArg(); + static const char* meterArg(); + static const char* queue_arg(); + static const char* labelArg(); + static const char* completeArg(); + static const char* waitArg(); }; #endif diff --git a/Base/src/stc/BlockClientZombieCmd.hpp b/Base/src/stc/BlockClientZombieCmd.hpp index b95dcef1b..678a1fc84 100644 --- a/Base/src/stc/BlockClientZombieCmd.hpp +++ b/Base/src/stc/BlockClientZombieCmd.hpp @@ -15,8 +15,8 @@ // Description : /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 -#include "ServerToClientCmd.hpp" #include "Child.hpp" +#include "ServerToClientCmd.hpp" // // This command send the zombie type to the client @@ -25,28 +25,27 @@ // class BlockClientZombieCmd final : public ServerToClientCmd { public: - explicit BlockClientZombieCmd(ecf::Child::ZombieType zt) : zombie_type_(zt) {} - BlockClientZombieCmd() = default; + explicit BlockClientZombieCmd(ecf::Child::ZombieType zt) : zombie_type_(zt) {} + BlockClientZombieCmd() = default; - void init(ecf::Child::ZombieType zt) { zombie_type_ = zt; } // server context - ecf::Child::ZombieType zombie_type() const { return zombie_type_;} + void init(ecf::Child::ZombieType zt) { zombie_type_ = zt; } // server context + ecf::Child::ZombieType zombie_type() const { return zombie_type_; } - std::string print() const override; - bool equals(ServerToClientCmd*) const override; - bool handle_server_response( ServerReply& server_reply, Cmd_ptr cts_cmd, bool debug ) const override; // client context + std::string print() const override; + bool equals(ServerToClientCmd*) const override; + bool + handle_server_response(ServerReply& server_reply, Cmd_ptr cts_cmd, bool debug) const override; // client context - bool is_returnable_in_group_cmd() const override { return false; } /// used by group command + bool is_returnable_in_group_cmd() const override { return false; } /// used by group command private: - ecf::Child::ZombieType zombie_type_{ecf::Child::NOT_SET}; + ecf::Child::ZombieType zombie_type_{ecf::Child::NOT_SET}; - friend class cereal::access; - template - void serialize(Archive & ar, std::uint32_t const version ) - { - ar(cereal::base_class< ServerToClientCmd >( this ), - CEREAL_NVP(zombie_type_)); - } + friend class cereal::access; + template + void serialize(Archive& ar, std::uint32_t const version) { + ar(cereal::base_class(this), CEREAL_NVP(zombie_type_)); + } }; std::ostream& operator<<(std::ostream& os, const BlockClientZombieCmd&); #endif diff --git a/Base/src/stc/DefsCache.hpp b/Base/src/stc/DefsCache.hpp index 0f1c0a9b7..40b2e84e8 100644 --- a/Base/src/stc/DefsCache.hpp +++ b/Base/src/stc/DefsCache.hpp @@ -15,6 +15,7 @@ // Description : /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 #include + #include "NodeFwd.hpp" //================================================================================ @@ -47,23 +48,23 @@ //================================================================================ class DefsCache : private boost::noncopyable { public: - // Server side - static void update_cache_if_state_changed(Defs* defs); - static void update_cache( Defs* defs ); + // Server side + static void update_cache_if_state_changed(Defs* defs); + static void update_cache(Defs* defs); - // Client side - static defs_ptr restore_defs_from_string(const std::string&); - static defs_ptr restore_defs_from_string(); // used in test + // Client side + static defs_ptr restore_defs_from_string(const std::string&); + static defs_ptr restore_defs_from_string(); // used in test private: - friend class SSyncCmd; - friend class DefsCmd; + friend class SSyncCmd; + friend class DefsCmd; - DefsCache() = delete; - ~DefsCache() = delete; - static std::string full_server_defs_as_string_; - static unsigned int state_change_no_; // detect state change in defs across clients - static unsigned int modify_change_no_; // detect state change in defs across clients + DefsCache() = delete; + ~DefsCache() = delete; + static std::string full_server_defs_as_string_; + static unsigned int state_change_no_; // detect state change in defs across clients + static unsigned int modify_change_no_; // detect state change in defs across clients }; #endif diff --git a/Base/src/stc/DefsCmd.hpp b/Base/src/stc/DefsCmd.hpp index 42a234c4f..c7ed59460 100644 --- a/Base/src/stc/DefsCmd.hpp +++ b/Base/src/stc/DefsCmd.hpp @@ -3,20 +3,20 @@ /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 // Name : // Author : Avi -// Revision : $Revision: #14 $ +// Revision : $Revision: #14 $ // // Copyright 2009- ECMWF. -// This software is licensed under the terms of the Apache Licence version 2.0 -// which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. -// In applying this licence, ECMWF does not waive the privileges and immunities -// granted to it by virtue of its status as an intergovernmental organisation -// nor does it submit to any jurisdiction. +// This software is licensed under the terms of the Apache Licence version 2.0 +// which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. +// In applying this licence, ECMWF does not waive the privileges and immunities +// granted to it by virtue of its status as an intergovernmental organisation +// nor does it submit to any jurisdiction. // // Description : /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 -#include "ServerToClientCmd.hpp" #include "DefsCache.hpp" +#include "ServerToClientCmd.hpp" class AbstractServer; //================================================================================ @@ -25,34 +25,34 @@ class AbstractServer; //================================================================================ class DefsCmd final : public ServerToClientCmd { public: - explicit DefsCmd(AbstractServer* as, bool save_edit_history = false); - DefsCmd()= default; + explicit DefsCmd(AbstractServer* as, bool save_edit_history = false); + DefsCmd() = default; - void init(AbstractServer* as, bool save_edit_history); + void init(AbstractServer* as, bool save_edit_history); - bool handle_server_response( ServerReply&, Cmd_ptr cts_cmd, bool debug ) const override; - std::string print() const override; - bool equals(ServerToClientCmd*) const override; - void cleanup() override { std::string().swap(full_server_defs_as_string_); } /// run in the server, after command send to client + bool handle_server_response(ServerReply&, Cmd_ptr cts_cmd, bool debug) const override; + std::string print() const override; + bool equals(ServerToClientCmd*) const override; + void cleanup() override { + std::string().swap(full_server_defs_as_string_); + } /// run in the server, after command send to client private: - - std::string full_server_defs_as_string_; - - friend class cereal::access; - template - void serialize(Archive & ar, std::uint32_t const version ) - { - ar(cereal::base_class< ServerToClientCmd >( this )); - - if (Archive::is_saving::value) { - // Avoid copying the string. As this could be very large - ar & DefsCache::full_server_defs_as_string_; - } - else { - ar & full_server_defs_as_string_; - } - } + std::string full_server_defs_as_string_; + + friend class cereal::access; + template + void serialize(Archive& ar, std::uint32_t const version) { + ar(cereal::base_class(this)); + + if (Archive::is_saving::value) { + // Avoid copying the string. As this could be very large + ar& DefsCache::full_server_defs_as_string_; + } + else { + ar& full_server_defs_as_string_; + } + } }; std::ostream& operator<<(std::ostream& os, const DefsCmd&); diff --git a/Base/src/stc/ErrorCmd.hpp b/Base/src/stc/ErrorCmd.hpp index 3466c027d..6d1b9f78d 100644 --- a/Base/src/stc/ErrorCmd.hpp +++ b/Base/src/stc/ErrorCmd.hpp @@ -3,14 +3,14 @@ /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 // Name : // Author : Avi -// Revision : $Revision: #7 $ +// Revision : $Revision: #7 $ // // Copyright 2009- ECMWF. -// This software is licensed under the terms of the Apache Licence version 2.0 -// which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. -// In applying this licence, ECMWF does not waive the privileges and immunities -// granted to it by virtue of its status as an intergovernmental organisation -// nor does it submit to any jurisdiction. +// This software is licensed under the terms of the Apache Licence version 2.0 +// which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. +// In applying this licence, ECMWF does not waive the privileges and immunities +// granted to it by virtue of its status as an intergovernmental organisation +// nor does it submit to any jurisdiction. // // Description : /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 @@ -18,28 +18,26 @@ class ErrorCmd final : public ServerToClientCmd { public: - explicit ErrorCmd(const std::string& errorMsg); - ErrorCmd() : ServerToClientCmd() {} + explicit ErrorCmd(const std::string& errorMsg); + ErrorCmd() : ServerToClientCmd() {} - void init( const std::string& errorMsg); - std::string print() const override; - bool equals(ServerToClientCmd*) const override; - bool handle_server_response( ServerReply&, Cmd_ptr cts_cmd, bool debug ) const override; + void init(const std::string& errorMsg); + std::string print() const override; + bool equals(ServerToClientCmd*) const override; + bool handle_server_response(ServerReply&, Cmd_ptr cts_cmd, bool debug) const override; - std::string error() const override { return error_msg_;} /// Used by test - bool ok() const override { return false; } /// Used by group command - void cleanup() override { std::string().swap(error_msg_);} /// run in the server, after command send to client + std::string error() const override { return error_msg_; } /// Used by test + bool ok() const override { return false; } /// Used by group command + void cleanup() override { std::string().swap(error_msg_); } /// run in the server, after command send to client private: - std::string error_msg_; + std::string error_msg_; - friend class cereal::access; - template - void serialize(Archive & ar, std::uint32_t const version ) - { - ar(cereal::base_class< ServerToClientCmd >( this ), - CEREAL_NVP(error_msg_)); - } + friend class cereal::access; + template + void serialize(Archive& ar, std::uint32_t const version) { + ar(cereal::base_class(this), CEREAL_NVP(error_msg_)); + } }; std::ostream& operator<<(std::ostream& os, const ErrorCmd&); diff --git a/Base/src/stc/GroupSTCCmd.hpp b/Base/src/stc/GroupSTCCmd.hpp index 11c5adb6b..2f71f4655 100644 --- a/Base/src/stc/GroupSTCCmd.hpp +++ b/Base/src/stc/GroupSTCCmd.hpp @@ -3,14 +3,14 @@ /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 // Name : // Author : Avi -// Revision : $Revision: #8 $ +// Revision : $Revision: #8 $ // // Copyright 2009- ECMWF. -// This software is licensed under the terms of the Apache Licence version 2.0 -// which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. -// In applying this licence, ECMWF does not waive the privileges and immunities -// granted to it by virtue of its status as an intergovernmental organisation -// nor does it submit to any jurisdiction. +// This software is licensed under the terms of the Apache Licence version 2.0 +// which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. +// In applying this licence, ECMWF does not waive the privileges and immunities +// granted to it by virtue of its status as an intergovernmental organisation +// nor does it submit to any jurisdiction. // // Description : /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 @@ -19,31 +19,29 @@ class GroupSTCCmd final : public ServerToClientCmd { public: - GroupSTCCmd() : ServerToClientCmd() {} + GroupSTCCmd() : ServerToClientCmd() {} - void cleanup() override; /// After the command has run this function can be used to reclaim memory + void cleanup() override; /// After the command has run this function can be used to reclaim memory - std::string print() const override; - bool equals(ServerToClientCmd*) const override; - bool handle_server_response( ServerReply& server_reply, Cmd_ptr cts_cmd, bool debug ) const override; + std::string print() const override; + bool equals(ServerToClientCmd*) const override; + bool handle_server_response(ServerReply& server_reply, Cmd_ptr cts_cmd, bool debug) const override; - void addChild(STC_Cmd_ptr childCmd); - const std::vector& cmdVec() const { return cmdVec_;} + void addChild(STC_Cmd_ptr childCmd); + const std::vector& cmdVec() const { return cmdVec_; } - // these two must be opposite of each other - bool ok() const override; - std::string error() const override; + // these two must be opposite of each other + bool ok() const override; + std::string error() const override; private: - std::vector cmdVec_; - - friend class cereal::access; - template - void serialize(Archive & ar, std::uint32_t const version ) - { - ar(cereal::base_class< ServerToClientCmd >( this ), - CEREAL_NVP(cmdVec_)); - } + std::vector cmdVec_; + + friend class cereal::access; + template + void serialize(Archive& ar, std::uint32_t const version) { + ar(cereal::base_class(this), CEREAL_NVP(cmdVec_)); + } }; std::ostream& operator<<(std::ostream& os, const GroupSTCCmd&); diff --git a/Base/src/stc/PreAllocatedReply.hpp b/Base/src/stc/PreAllocatedReply.hpp index 06bd911ba..c8b5838b0 100644 --- a/Base/src/stc/PreAllocatedReply.hpp +++ b/Base/src/stc/PreAllocatedReply.hpp @@ -3,22 +3,24 @@ //============================================================================ // Name : // Author : Avi -// Revision : $Revision: #22 $ +// Revision : $Revision: #22 $ // // Copyright 2009- ECMWF. -// This software is licensed under the terms of the Apache Licence version 2.0 -// which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. -// In applying this licence, ECMWF does not waive the privileges and immunities -// granted to it by virtue of its status as an intergovernmental organisation -// nor does it submit to any jurisdiction. +// This software is licensed under the terms of the Apache Licence version 2.0 +// which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. +// In applying this licence, ECMWF does not waive the privileges and immunities +// granted to it by virtue of its status as an intergovernmental organisation +// nor does it submit to any jurisdiction. // // Description : //============================================================================ #include + #include + +#include "Child.hpp" #include "Cmd.hpp" #include "NodeFwd.hpp" -#include "Child.hpp" class AbstractServer; // class PreAllocatedReply: @@ -28,50 +30,53 @@ class AbstractServer; // should be cleared first class PreAllocatedReply : private boost::noncopyable { public: - static STC_Cmd_ptr ok_cmd(); - static STC_Cmd_ptr block_client_server_halted_cmd(); - static STC_Cmd_ptr block_client_on_home_server_cmd(); - static STC_Cmd_ptr block_client_zombie_cmd(ecf::Child::ZombieType zt); - static STC_Cmd_ptr delete_all_cmd(); + static STC_Cmd_ptr ok_cmd(); + static STC_Cmd_ptr block_client_server_halted_cmd(); + static STC_Cmd_ptr block_client_on_home_server_cmd(); + static STC_Cmd_ptr block_client_zombie_cmd(ecf::Child::ZombieType zt); + static STC_Cmd_ptr delete_all_cmd(); - static STC_Cmd_ptr defs_cmd(AbstractServer*, bool save_edit_history); - static STC_Cmd_ptr node_cmd(AbstractServer*,node_ptr); - static STC_Cmd_ptr stats_cmd(AbstractServer*); - static STC_Cmd_ptr suites_cmd(AbstractServer*); - static STC_Cmd_ptr zombie_get_cmd(AbstractServer*); - static STC_Cmd_ptr error_cmd(const std::string& error_msg); - static STC_Cmd_ptr client_handle_cmd(int handle); - static STC_Cmd_ptr client_handle_suites_cmd(AbstractServer*); - static STC_Cmd_ptr string_cmd(const std::string& any_string); - static STC_Cmd_ptr string_vec_cmd(const std::vector&); - static STC_Cmd_ptr server_load_cmd(const std::string& any_string); - static STC_Cmd_ptr news_cmd(unsigned int client_handle, - unsigned int client_state_change_no, - unsigned int client_modify_change_no, AbstractServer* as); - static STC_Cmd_ptr sync_cmd(unsigned int client_handle, - unsigned int client_state_change_no, - unsigned int client_modify_change_no, AbstractServer* as); - static STC_Cmd_ptr sync_clock_cmd(unsigned int client_handle, - unsigned int client_state_change_no, - unsigned int client_modify_change_no, AbstractServer* as); - static STC_Cmd_ptr sync_full_cmd(unsigned int client_handle,AbstractServer* as); -private: + static STC_Cmd_ptr defs_cmd(AbstractServer*, bool save_edit_history); + static STC_Cmd_ptr node_cmd(AbstractServer*, node_ptr); + static STC_Cmd_ptr stats_cmd(AbstractServer*); + static STC_Cmd_ptr suites_cmd(AbstractServer*); + static STC_Cmd_ptr zombie_get_cmd(AbstractServer*); + static STC_Cmd_ptr error_cmd(const std::string& error_msg); + static STC_Cmd_ptr client_handle_cmd(int handle); + static STC_Cmd_ptr client_handle_suites_cmd(AbstractServer*); + static STC_Cmd_ptr string_cmd(const std::string& any_string); + static STC_Cmd_ptr string_vec_cmd(const std::vector&); + static STC_Cmd_ptr server_load_cmd(const std::string& any_string); + static STC_Cmd_ptr news_cmd(unsigned int client_handle, + unsigned int client_state_change_no, + unsigned int client_modify_change_no, + AbstractServer* as); + static STC_Cmd_ptr sync_cmd(unsigned int client_handle, + unsigned int client_state_change_no, + unsigned int client_modify_change_no, + AbstractServer* as); + static STC_Cmd_ptr sync_clock_cmd(unsigned int client_handle, + unsigned int client_state_change_no, + unsigned int client_modify_change_no, + AbstractServer* as); + static STC_Cmd_ptr sync_full_cmd(unsigned int client_handle, AbstractServer* as); - static STC_Cmd_ptr stc_cmd_; - static STC_Cmd_ptr defs_cmd_; - static STC_Cmd_ptr node_cmd_; - static STC_Cmd_ptr stats_cmd_; - static STC_Cmd_ptr suites_cmd_; - static STC_Cmd_ptr zombie_get_cmd_; - static STC_Cmd_ptr error_cmd_; - static STC_Cmd_ptr client_handle_cmd_; - static STC_Cmd_ptr client_handle_suites_cmd_; - static STC_Cmd_ptr string_cmd_; - static STC_Cmd_ptr string_vec_cmd_; - static STC_Cmd_ptr server_load_cmd_; - static STC_Cmd_ptr news_cmd_; - static STC_Cmd_ptr sync_cmd_; - static STC_Cmd_ptr block_client_zombie_cmd_; +private: + static STC_Cmd_ptr stc_cmd_; + static STC_Cmd_ptr defs_cmd_; + static STC_Cmd_ptr node_cmd_; + static STC_Cmd_ptr stats_cmd_; + static STC_Cmd_ptr suites_cmd_; + static STC_Cmd_ptr zombie_get_cmd_; + static STC_Cmd_ptr error_cmd_; + static STC_Cmd_ptr client_handle_cmd_; + static STC_Cmd_ptr client_handle_suites_cmd_; + static STC_Cmd_ptr string_cmd_; + static STC_Cmd_ptr string_vec_cmd_; + static STC_Cmd_ptr server_load_cmd_; + static STC_Cmd_ptr news_cmd_; + static STC_Cmd_ptr sync_cmd_; + static STC_Cmd_ptr block_client_zombie_cmd_; }; #endif diff --git a/Base/src/stc/SClientHandleCmd.hpp b/Base/src/stc/SClientHandleCmd.hpp index c0b08e25c..88c26fb65 100644 --- a/Base/src/stc/SClientHandleCmd.hpp +++ b/Base/src/stc/SClientHandleCmd.hpp @@ -3,14 +3,14 @@ /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 // Name : // Author : Avi -// Revision : $Revision: #7 $ +// Revision : $Revision: #7 $ // // Copyright 2009- ECMWF. -// This software is licensed under the terms of the Apache Licence version 2.0 -// which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. -// In applying this licence, ECMWF does not waive the privileges and immunities -// granted to it by virtue of its status as an intergovernmental organisation -// nor does it submit to any jurisdiction. +// This software is licensed under the terms of the Apache Licence version 2.0 +// which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. +// In applying this licence, ECMWF does not waive the privileges and immunities +// granted to it by virtue of its status as an intergovernmental organisation +// nor does it submit to any jurisdiction. // // Description : /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 @@ -18,24 +18,22 @@ class SClientHandleCmd final : public ServerToClientCmd { public: - explicit SClientHandleCmd(int handle) : handle_(handle) {} - SClientHandleCmd() : ServerToClientCmd(){} + explicit SClientHandleCmd(int handle) : handle_(handle) {} + SClientHandleCmd() : ServerToClientCmd() {} - void init(int handle) { handle_ = handle; } - std::string print() const override; - bool equals(ServerToClientCmd*) const override; - bool handle_server_response( ServerReply&, Cmd_ptr cts_cmd, bool debug ) const override; + void init(int handle) { handle_ = handle; } + std::string print() const override; + bool equals(ServerToClientCmd*) const override; + bool handle_server_response(ServerReply&, Cmd_ptr cts_cmd, bool debug) const override; private: - int handle_{0}; + int handle_{0}; - friend class cereal::access; - template - void serialize(Archive & ar, std::uint32_t const version ) - { - ar(cereal::base_class< ServerToClientCmd >( this ), - CEREAL_NVP(handle_)); - } + friend class cereal::access; + template + void serialize(Archive& ar, std::uint32_t const version) { + ar(cereal::base_class(this), CEREAL_NVP(handle_)); + } }; std::ostream& operator<<(std::ostream& os, const SClientHandleCmd&); diff --git a/Base/src/stc/SClientHandleSuitesCmd.hpp b/Base/src/stc/SClientHandleSuitesCmd.hpp index 3f769051f..160d05367 100644 --- a/Base/src/stc/SClientHandleSuitesCmd.hpp +++ b/Base/src/stc/SClientHandleSuitesCmd.hpp @@ -21,26 +21,23 @@ class AbstractServer; //================================================================================ class SClientHandleSuitesCmd final : public ServerToClientCmd { public: - explicit SClientHandleSuitesCmd(AbstractServer* as ); - SClientHandleSuitesCmd() : ServerToClientCmd() {} + explicit SClientHandleSuitesCmd(AbstractServer* as); + SClientHandleSuitesCmd() : ServerToClientCmd() {} - void init(AbstractServer* as); - std::string print() const override; - bool equals(ServerToClientCmd*) const override; - bool handle_server_response( ServerReply& server_reply, Cmd_ptr cts_cmd, bool debug ) const override; + void init(AbstractServer* as); + std::string print() const override; + bool equals(ServerToClientCmd*) const override; + bool handle_server_response(ServerReply& server_reply, Cmd_ptr cts_cmd, bool debug) const override; private: - std::vector > > users_; // users , list of handles - std::vector > > client_handles_; // handle, list of suites + std::vector>> users_; // users , list of handles + std::vector>> client_handles_; // handle, list of suites - friend class cereal::access; - template - void serialize(Archive & ar, std::uint32_t const version ) - { - ar(cereal::base_class< ServerToClientCmd >( this ), - CEREAL_NVP(users_), - CEREAL_NVP(client_handles_)); - } + friend class cereal::access; + template + void serialize(Archive& ar, std::uint32_t const version) { + ar(cereal::base_class(this), CEREAL_NVP(users_), CEREAL_NVP(client_handles_)); + } }; std::ostream& operator<<(std::ostream& os, const SClientHandleSuitesCmd&); diff --git a/Base/src/stc/SNewsCmd.hpp b/Base/src/stc/SNewsCmd.hpp index 55c090369..1995abcbe 100644 --- a/Base/src/stc/SNewsCmd.hpp +++ b/Base/src/stc/SNewsCmd.hpp @@ -3,14 +3,14 @@ /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 // Name : // Author : Avi -// Revision : $Revision: #9 $ +// Revision : $Revision: #9 $ // // Copyright 2009- ECMWF. -// This software is licensed under the terms of the Apache Licence version 2.0 -// which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. -// In applying this licence, ECMWF does not waive the privileges and immunities -// granted to it by virtue of its status as an intergovernmental organisation -// nor does it submit to any jurisdiction. +// This software is licensed under the terms of the Apache Licence version 2.0 +// which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. +// In applying this licence, ECMWF does not waive the privileges and immunities +// granted to it by virtue of its status as an intergovernmental organisation +// nor does it submit to any jurisdiction. // // Description : class SNewsCmd: Used to determine any change in the server // @@ -28,35 +28,33 @@ class AbstractServer; class SNewsCmd final : public ServerToClientCmd { public: - // The constructor is *called* in the server. - SNewsCmd(unsigned int client_handle, // a reference to a set of suites used by client - unsigned int client_state_change_no, - unsigned int client_modify_change_no, - AbstractServer* as); - SNewsCmd() : ServerToClientCmd(){} + // The constructor is *called* in the server. + SNewsCmd(unsigned int client_handle, // a reference to a set of suites used by client + unsigned int client_state_change_no, + unsigned int client_modify_change_no, + AbstractServer* as); + SNewsCmd() : ServerToClientCmd() {} - void init(unsigned int client_handle, // a reference to a set of suites used by client - unsigned int client_state_change_no, - unsigned int client_modify_change_no, - AbstractServer* as); + void init(unsigned int client_handle, // a reference to a set of suites used by client + unsigned int client_state_change_no, + unsigned int client_modify_change_no, + AbstractServer* as); - ServerReply::News_t news() const { return news_;} // used by equals only - bool get_news() const { return ( news_ != ServerReply::NO_NEWS); } + ServerReply::News_t news() const { return news_; } // used by equals only + bool get_news() const { return (news_ != ServerReply::NO_NEWS); } - std::string print() const override; - bool equals(ServerToClientCmd*) const override; - bool handle_server_response( ServerReply& server_reply, Cmd_ptr cts_cmd, bool debug ) const override; + std::string print() const override; + bool equals(ServerToClientCmd*) const override; + bool handle_server_response(ServerReply& server_reply, Cmd_ptr cts_cmd, bool debug) const override; private: - ServerReply::News_t news_{ServerReply::NO_NEWS}; - - friend class cereal::access; - template - void serialize(Archive & ar, std::uint32_t const version ) - { - ar(cereal::base_class< ServerToClientCmd >( this ), - CEREAL_NVP(news_)); - } + ServerReply::News_t news_{ServerReply::NO_NEWS}; + + friend class cereal::access; + template + void serialize(Archive& ar, std::uint32_t const version) { + ar(cereal::base_class(this), CEREAL_NVP(news_)); + } }; std::ostream& operator<<(std::ostream& os, const SNewsCmd&); diff --git a/Base/src/stc/SNodeCmd.hpp b/Base/src/stc/SNodeCmd.hpp index 3780b386f..d94710e7a 100644 --- a/Base/src/stc/SNodeCmd.hpp +++ b/Base/src/stc/SNodeCmd.hpp @@ -3,14 +3,14 @@ /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 // Name : // Author : Avi -// Revision : $Revision: #6 $ +// Revision : $Revision: #6 $ // // Copyright 2009- ECMWF. -// This software is licensed under the terms of the Apache Licence version 2.0 -// which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. -// In applying this licence, ECMWF does not waive the privileges and immunities -// granted to it by virtue of its status as an intergovernmental organisation -// nor does it submit to any jurisdiction. +// This software is licensed under the terms of the Apache Licence version 2.0 +// which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. +// In applying this licence, ECMWF does not waive the privileges and immunities +// granted to it by virtue of its status as an intergovernmental organisation +// nor does it submit to any jurisdiction. // // Description : /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 @@ -24,27 +24,25 @@ class AbstractServer; //================================================================================ class SNodeCmd final : public ServerToClientCmd { public: - SNodeCmd(AbstractServer* as,node_ptr node); - SNodeCmd() = default; + SNodeCmd(AbstractServer* as, node_ptr node); + SNodeCmd() = default; - void init(AbstractServer* as, node_ptr node); + void init(AbstractServer* as, node_ptr node); - bool handle_server_response( ServerReply&, Cmd_ptr cts_cmd, bool debug ) const override; - std::string print() const override; - bool equals(ServerToClientCmd*) const override; - void cleanup() override { std::string().swap(the_node_str_);} /// run in the server, after command send to client + bool handle_server_response(ServerReply&, Cmd_ptr cts_cmd, bool debug) const override; + std::string print() const override; + bool equals(ServerToClientCmd*) const override; + void cleanup() override { std::string().swap(the_node_str_); } /// run in the server, after command send to client private: - node_ptr get_node_ptr(std::string& error_msg) const; - std::string the_node_str_; - - friend class cereal::access; - template - void serialize(Archive & ar, std::uint32_t const version ) - { - ar(cereal::base_class< ServerToClientCmd >( this ), - CEREAL_NVP(the_node_str_)); - } + node_ptr get_node_ptr(std::string& error_msg) const; + std::string the_node_str_; + + friend class cereal::access; + template + void serialize(Archive& ar, std::uint32_t const version) { + ar(cereal::base_class(this), CEREAL_NVP(the_node_str_)); + } }; std::ostream& operator<<(std::ostream& os, const SNodeCmd&); diff --git a/Base/src/stc/SServerLoadCmd.hpp b/Base/src/stc/SServerLoadCmd.hpp index c536299ad..114f859c8 100644 --- a/Base/src/stc/SServerLoadCmd.hpp +++ b/Base/src/stc/SServerLoadCmd.hpp @@ -3,14 +3,14 @@ /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 // Name : // Author : Avi -// Revision : $Revision: #4 $ +// Revision : $Revision: #4 $ // // Copyright 2009- ECMWF. -// This software is licensed under the terms of the Apache Licence version 2.0 -// which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. -// In applying this licence, ECMWF does not waive the privileges and immunities -// granted to it by virtue of its status as an intergovernmental organisation -// nor does it submit to any jurisdiction. +// This software is licensed under the terms of the Apache Licence version 2.0 +// which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. +// In applying this licence, ECMWF does not waive the privileges and immunities +// granted to it by virtue of its status as an intergovernmental organisation +// nor does it submit to any jurisdiction. // // Description : /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 @@ -23,26 +23,24 @@ ///================================================================================ class SServerLoadCmd final : public ServerToClientCmd { public: - explicit SServerLoadCmd(const std::string& log_file_path) : log_file_path_(log_file_path) {} - SServerLoadCmd() : ServerToClientCmd() {} + explicit SServerLoadCmd(const std::string& log_file_path) : log_file_path_(log_file_path) {} + SServerLoadCmd() : ServerToClientCmd() {} - void init(const std::string& s) { log_file_path_ = s;} - const std::string& log_file_path() const { return log_file_path_; } - std::string print() const override; - bool equals(ServerToClientCmd*) const override; - bool handle_server_response( ServerReply& server_reply, Cmd_ptr cts_cmd, bool debug ) const override; - void cleanup() override { std::string().swap(log_file_path_);} /// run in the server, after command send to client + void init(const std::string& s) { log_file_path_ = s; } + const std::string& log_file_path() const { return log_file_path_; } + std::string print() const override; + bool equals(ServerToClientCmd*) const override; + bool handle_server_response(ServerReply& server_reply, Cmd_ptr cts_cmd, bool debug) const override; + void cleanup() override { std::string().swap(log_file_path_); } /// run in the server, after command send to client private: - std::string log_file_path_; + std::string log_file_path_; - friend class cereal::access; - template - void serialize(Archive & ar, std::uint32_t const version ) - { - ar(cereal::base_class< ServerToClientCmd >( this ), - CEREAL_NVP(log_file_path_)); - } + friend class cereal::access; + template + void serialize(Archive& ar, std::uint32_t const version) { + ar(cereal::base_class(this), CEREAL_NVP(log_file_path_)); + } }; std::ostream& operator<<(std::ostream& os, const SServerLoadCmd&); diff --git a/Base/src/stc/SStatsCmd.hpp b/Base/src/stc/SStatsCmd.hpp index 797c791b7..87b458998 100644 --- a/Base/src/stc/SStatsCmd.hpp +++ b/Base/src/stc/SStatsCmd.hpp @@ -3,14 +3,14 @@ /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 // Name : // Author : Avi -// Revision : $Revision: #8 $ +// Revision : $Revision: #8 $ // // Copyright 2009- ECMWF. -// This software is licensed under the terms of the Apache Licence version 2.0 -// which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. -// In applying this licence, ECMWF does not waive the privileges and immunities -// granted to it by virtue of its status as an intergovernmental organisation -// nor does it submit to any jurisdiction. +// This software is licensed under the terms of the Apache Licence version 2.0 +// which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. +// In applying this licence, ECMWF does not waive the privileges and immunities +// granted to it by virtue of its status as an intergovernmental organisation +// nor does it submit to any jurisdiction. // // Description : /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 @@ -28,25 +28,23 @@ class AbstractServer; //================================================================================ class SStatsCmd final : public ServerToClientCmd { public: - explicit SStatsCmd(AbstractServer* as ); - SStatsCmd() : ServerToClientCmd() {} + explicit SStatsCmd(AbstractServer* as); + SStatsCmd() : ServerToClientCmd() {} - void init(AbstractServer* as); + void init(AbstractServer* as); - std::string print() const override; - bool equals(ServerToClientCmd*) const override; - bool handle_server_response( ServerReply& server_reply, Cmd_ptr cts_cmd, bool debug ) const override; + std::string print() const override; + bool equals(ServerToClientCmd*) const override; + bool handle_server_response(ServerReply& server_reply, Cmd_ptr cts_cmd, bool debug) const override; private: - Stats stats_; - - friend class cereal::access; - template - void serialize(Archive & ar, std::uint32_t const version ) - { - ar(cereal::base_class< ServerToClientCmd >( this ), - CEREAL_NVP(stats_)); - } + Stats stats_; + + friend class cereal::access; + template + void serialize(Archive& ar, std::uint32_t const version) { + ar(cereal::base_class(this), CEREAL_NVP(stats_)); + } }; std::ostream& operator<<(std::ostream& os, const SStatsCmd&); diff --git a/Base/src/stc/SStringCmd.hpp b/Base/src/stc/SStringCmd.hpp index 33554cb4a..0dc42be3a 100644 --- a/Base/src/stc/SStringCmd.hpp +++ b/Base/src/stc/SStringCmd.hpp @@ -3,14 +3,14 @@ /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 // Name : // Author : Avi -// Revision : $Revision: #4 $ +// Revision : $Revision: #4 $ // // Copyright 2009- ECMWF. -// This software is licensed under the terms of the Apache Licence version 2.0 -// which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. -// In applying this licence, ECMWF does not waive the privileges and immunities -// granted to it by virtue of its status as an intergovernmental organisation -// nor does it submit to any jurisdiction. +// This software is licensed under the terms of the Apache Licence version 2.0 +// which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. +// In applying this licence, ECMWF does not waive the privileges and immunities +// granted to it by virtue of its status as an intergovernmental organisation +// nor does it submit to any jurisdiction. // // Description : /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 @@ -29,26 +29,24 @@ ///================================================================================ class SStringCmd final : public ServerToClientCmd { public: - explicit SStringCmd(const std::string& s) : str_(s) {} - SStringCmd() : ServerToClientCmd() {} + explicit SStringCmd(const std::string& s) : str_(s) {} + SStringCmd() : ServerToClientCmd() {} - void init(const std::string& s) { str_ = s;} - std::string print() const override; - bool equals(ServerToClientCmd*) const override; - const std::string& get_string() const override { return str_;} - bool handle_server_response( ServerReply& server_reply, Cmd_ptr cts_cmd, bool debug ) const override; - void cleanup() override { std::string().swap(str_);} /// run in the server, after command send to client + void init(const std::string& s) { str_ = s; } + std::string print() const override; + bool equals(ServerToClientCmd*) const override; + const std::string& get_string() const override { return str_; } + bool handle_server_response(ServerReply& server_reply, Cmd_ptr cts_cmd, bool debug) const override; + void cleanup() override { std::string().swap(str_); } /// run in the server, after command send to client private: - std::string str_; + std::string str_; - friend class cereal::access; - template - void serialize(Archive & ar, std::uint32_t const version ) - { - ar(cereal::base_class< ServerToClientCmd >( this ), - CEREAL_NVP(str_)); - } + friend class cereal::access; + template + void serialize(Archive& ar, std::uint32_t const version) { + ar(cereal::base_class(this), CEREAL_NVP(str_)); + } }; std::ostream& operator<<(std::ostream& os, const SStringCmd&); diff --git a/Base/src/stc/SStringVecCmd.hpp b/Base/src/stc/SStringVecCmd.hpp index 84a913b7e..00da0c6a0 100644 --- a/Base/src/stc/SStringVecCmd.hpp +++ b/Base/src/stc/SStringVecCmd.hpp @@ -20,27 +20,27 @@ ///================================================================================ class SStringVecCmd final : public ServerToClientCmd { public: - explicit SStringVecCmd(const std::vector& s) : vec_(s) {} - SStringVecCmd() : ServerToClientCmd() {} + explicit SStringVecCmd(const std::vector& s) : vec_(s) {} + SStringVecCmd() : ServerToClientCmd() {} - void init(const std::vector& s) { vec_ = s;} - const std::vector& get_string_vec() const { return vec_;} + void init(const std::vector& s) { vec_ = s; } + const std::vector& get_string_vec() const { return vec_; } - std::string print() const override; - bool equals(ServerToClientCmd*) const override; - bool handle_server_response( ServerReply& server_reply, Cmd_ptr cts_cmd, bool debug ) const override; - void cleanup() override { std::vector().swap(vec_);} /// run in the server, after command send to client + std::string print() const override; + bool equals(ServerToClientCmd*) const override; + bool handle_server_response(ServerReply& server_reply, Cmd_ptr cts_cmd, bool debug) const override; + void cleanup() override { + std::vector().swap(vec_); + } /// run in the server, after command send to client private: - std::vector vec_; - - friend class cereal::access; - template - void serialize(Archive & ar, std::uint32_t const version ) - { - ar(cereal::base_class< ServerToClientCmd >( this ), - CEREAL_NVP(vec_)); - } + std::vector vec_; + + friend class cereal::access; + template + void serialize(Archive& ar, std::uint32_t const version) { + ar(cereal::base_class(this), CEREAL_NVP(vec_)); + } }; std::ostream& operator<<(std::ostream& os, const SStringVecCmd&); diff --git a/Base/src/stc/SSuitesCmd.hpp b/Base/src/stc/SSuitesCmd.hpp index 3786a33de..b43835105 100644 --- a/Base/src/stc/SSuitesCmd.hpp +++ b/Base/src/stc/SSuitesCmd.hpp @@ -3,14 +3,14 @@ /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 // Name : // Author : Avi -// Revision : $Revision: #8 $ +// Revision : $Revision: #8 $ // // Copyright 2009- ECMWF. -// This software is licensed under the terms of the Apache Licence version 2.0 -// which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. -// In applying this licence, ECMWF does not waive the privileges and immunities -// granted to it by virtue of its status as an intergovernmental organisation -// nor does it submit to any jurisdiction. +// This software is licensed under the terms of the Apache Licence version 2.0 +// which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. +// In applying this licence, ECMWF does not waive the privileges and immunities +// granted to it by virtue of its status as an intergovernmental organisation +// nor does it submit to any jurisdiction. // // Description : /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 @@ -24,25 +24,25 @@ class AbstractServer; //================================================================================ class SSuitesCmd final : public ServerToClientCmd { public: - explicit SSuitesCmd(AbstractServer* as ); - SSuitesCmd() : ServerToClientCmd() {} + explicit SSuitesCmd(AbstractServer* as); + SSuitesCmd() : ServerToClientCmd() {} - void init(AbstractServer* as); - std::string print() const override; - bool equals(ServerToClientCmd*) const override; - bool handle_server_response( ServerReply& server_reply, Cmd_ptr cts_cmd, bool debug ) const override; - void cleanup() override { std::vector().swap(suites_);} /// run in the server, after command send to client + void init(AbstractServer* as); + std::string print() const override; + bool equals(ServerToClientCmd*) const override; + bool handle_server_response(ServerReply& server_reply, Cmd_ptr cts_cmd, bool debug) const override; + void cleanup() override { + std::vector().swap(suites_); + } /// run in the server, after command send to client private: - std::vector suites_; + std::vector suites_; - friend class cereal::access; - template - void serialize(Archive & ar, std::uint32_t const version ) - { - ar(cereal::base_class< ServerToClientCmd >( this ), - CEREAL_NVP(suites_)); - } + friend class cereal::access; + template + void serialize(Archive& ar, std::uint32_t const version) { + ar(cereal::base_class(this), CEREAL_NVP(suites_)); + } }; std::ostream& operator<<(std::ostream& os, const SSuitesCmd&); diff --git a/Base/src/stc/SSyncCmd.hpp b/Base/src/stc/SSyncCmd.hpp index 9689d6581..c7b002924 100644 --- a/Base/src/stc/SSyncCmd.hpp +++ b/Base/src/stc/SSyncCmd.hpp @@ -3,21 +3,21 @@ /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 // Name : // Author : Avi -// Revision : $Revision: #25 $ +// Revision : $Revision: #25 $ // // Copyright 2009- ECMWF. -// This software is licensed under the terms of the Apache Licence version 2.0 -// which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. -// In applying this licence, ECMWF does not waive the privileges and immunities -// granted to it by virtue of its status as an intergovernmental organisation -// nor does it submit to any jurisdiction. +// This software is licensed under the terms of the Apache Licence version 2.0 +// which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. +// In applying this licence, ECMWF does not waive the privileges and immunities +// granted to it by virtue of its status as an intergovernmental organisation +// nor does it submit to any jurisdiction. // // Description : /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 -#include "ServerToClientCmd.hpp" -#include "DefsDelta.hpp" #include "DefsCache.hpp" +#include "DefsDelta.hpp" +#include "ServerToClientCmd.hpp" class AbstractServer; //================================================================================ @@ -36,77 +36,75 @@ class AbstractServer; //================================================================================ class SSyncCmd final : public ServerToClientCmd { public: - // The constructor is *called* in the server. - // This will collate the incremental changes made so far relative to the client_state_change_no. - // For large scale change we use client_modify_change_no this will require a full update - SSyncCmd(unsigned int client_handle, // a reference to a set of suites used by client - unsigned int client_state_change_no, - unsigned int client_modify_change_no, - AbstractServer* as); + // The constructor is *called* in the server. + // This will collate the incremental changes made so far relative to the client_state_change_no. + // For large scale change we use client_modify_change_no this will require a full update + SSyncCmd(unsigned int client_handle, // a reference to a set of suites used by client + unsigned int client_state_change_no, + unsigned int client_modify_change_no, + AbstractServer* as); - SSyncCmd() : ServerToClientCmd(), incremental_changes_(0) {} + SSyncCmd() : ServerToClientCmd(), incremental_changes_(0) {} - std::string print() const override; - bool equals(ServerToClientCmd*) const override; + std::string print() const override; + bool equals(ServerToClientCmd*) const override; - // Client side functions: - bool handle_server_response( ServerReply& server_reply, Cmd_ptr cts_cmd, bool debug ) const override; + // Client side functions: + bool handle_server_response(ServerReply& server_reply, Cmd_ptr cts_cmd, bool debug) const override; - /// do_sync() is invoked on the *client side*, Can throw std::runtime_error - /// Either does a *FULL* or *INCREMENTAL sync depending on the - /// changes in the server. Returns true if client defs changed. - bool do_sync( ServerReply& server_reply, bool debug = false) const; + /// do_sync() is invoked on the *client side*, Can throw std::runtime_error + /// Either does a *FULL* or *INCREMENTAL sync depending on the + /// changes in the server. Returns true if client defs changed. + bool do_sync(ServerReply& server_reply, bool debug = false) const; private: + friend class PreAllocatedReply; + void init(unsigned int client_handle, // a reference to a set of suites used by client + unsigned int client_state_change_no, + unsigned int client_modify_change_no, + bool full_sync, + bool sync_suite_clock, + AbstractServer* as); - friend class PreAllocatedReply; - void init(unsigned int client_handle, // a reference to a set of suites used by client - unsigned int client_state_change_no, - unsigned int client_modify_change_no, - bool full_sync, - bool sync_suite_clock, - AbstractServer* as); - - /// For use when doing a full sync - void init(unsigned int client_handle,AbstractServer* as); + /// For use when doing a full sync + void init(unsigned int client_handle, AbstractServer* as); - void reset_data_members(unsigned int client_state_change_no, bool sync_suite_clock); - void full_sync(unsigned int client_handle,AbstractServer* as); - void cleanup() override; /// run in the server, after command sent to client + void reset_data_members(unsigned int client_state_change_no, bool sync_suite_clock); + void full_sync(unsigned int client_handle, AbstractServer* as); + void cleanup() override; /// run in the server, after command sent to client private: - - bool full_defs_{false}; - DefsDelta incremental_changes_; - std::string server_defs_; // for returning a subset of the suites - std::string full_server_defs_as_string_; // semi-persisted, i.e on load & not on saving, used to return cached defs - - friend class cereal::access; - template - void serialize(Archive & ar, std::uint32_t const version ) - { - ar(cereal::base_class< ServerToClientCmd >( this ), - CEREAL_NVP(full_defs_), // returning full defs as a string - CEREAL_NVP(incremental_changes_), // state changes, small scale changes - - /// When the server_defs_ was created the def's pointer on the suites was reset back to real server defs - /// This is not correct for server_defs_, since we use the *same* suites - /// **** This is OK since by default the Defs serialisation will fix up the suite's def's pointers *** - /// The alternative is to clone all the suites, which is very expensive - CEREAL_NVP(server_defs_)); // large scale changes, if non zero handle, a small subset of the suites - - // when full_defs_ is set 'server_defs_' will be empty. - if (Archive::is_saving::value) { - // Avoid copying the string. As this could be very large - if (full_defs_) { - ar & DefsCache::full_server_defs_as_string_; - } - else ar & full_server_defs_as_string_; - } - else { - ar & full_server_defs_as_string_; - } - } + bool full_defs_{false}; + DefsDelta incremental_changes_; + std::string server_defs_; // for returning a subset of the suites + std::string full_server_defs_as_string_; // semi-persisted, i.e on load & not on saving, used to return cached defs + + friend class cereal::access; + template + void serialize(Archive& ar, std::uint32_t const version) { + ar(cereal::base_class(this), + CEREAL_NVP(full_defs_), // returning full defs as a string + CEREAL_NVP(incremental_changes_), // state changes, small scale changes + + /// When the server_defs_ was created the def's pointer on the suites was reset back to real server defs + /// This is not correct for server_defs_, since we use the *same* suites + /// **** This is OK since by default the Defs serialisation will fix up the suite's def's pointers *** + /// The alternative is to clone all the suites, which is very expensive + CEREAL_NVP(server_defs_)); // large scale changes, if non zero handle, a small subset of the suites + + // when full_defs_ is set 'server_defs_' will be empty. + if (Archive::is_saving::value) { + // Avoid copying the string. As this could be very large + if (full_defs_) { + ar& DefsCache::full_server_defs_as_string_; + } + else + ar& full_server_defs_as_string_; + } + else { + ar& full_server_defs_as_string_; + } + } }; std::ostream& operator<<(std::ostream& os, const SSyncCmd&); diff --git a/Base/src/stc/ServerToClientCmd.hpp b/Base/src/stc/ServerToClientCmd.hpp index 3968833a9..1b091e83e 100644 --- a/Base/src/stc/ServerToClientCmd.hpp +++ b/Base/src/stc/ServerToClientCmd.hpp @@ -3,54 +3,54 @@ /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 // Name : // Author : Avi -// Revision : $Revision: #19 $ +// Revision : $Revision: #19 $ // // Copyright 2009- ECMWF. -// This software is licensed under the terms of the Apache Licence version 2.0 -// which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. -// In applying this licence, ECMWF does not waive the privileges and immunities -// granted to it by virtue of its status as an intergovernmental organisation -// nor does it submit to any jurisdiction. +// This software is licensed under the terms of the Apache Licence version 2.0 +// which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. +// In applying this licence, ECMWF does not waive the privileges and immunities +// granted to it by virtue of its status as an intergovernmental organisation +// nor does it submit to any jurisdiction. // // Description : /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 #include "Cmd.hpp" #include "NodeFwd.hpp" -#include "ServerReply.hpp" #include "Serialization.hpp" +#include "ServerReply.hpp" //================================================================================ // Start of Server->client //================================================================================ class ServerToClientCmd { public: - virtual ~ServerToClientCmd(); + virtual ~ServerToClientCmd(); - virtual void cleanup() {} /// After the command has run this function can be used to reclaim memory + virtual void cleanup() {} /// After the command has run this function can be used to reclaim memory - virtual std::string print() const = 0; - virtual bool equals(ServerToClientCmd*) const { return true;} + virtual std::string print() const = 0; + virtual bool equals(ServerToClientCmd*) const { return true; } - virtual const std::string& get_string() const; /// Used by group command, can return any string, including file contents - virtual bool ok() const { return true;} /// Used by group command - virtual bool is_returnable_in_group_cmd() const { return true; } /// used by group command + virtual const std::string& + get_string() const; /// Used by group command, can return any string, including file contents + virtual bool ok() const { return true; } /// Used by group command + virtual bool is_returnable_in_group_cmd() const { return true; } /// used by group command - virtual std::string error() const { return std::string();} /// Used by test + virtual std::string error() const { return std::string(); } /// Used by test - // Called in client, if any data to be returned , the set on class ServerReply - // Cmd_ptr cts_cmd can used for additional context. - // return true, if client should exit, returns false, if further work required, ie blocking, errors, etc - virtual bool handle_server_response( ServerReply&, Cmd_ptr cts_cmd, bool debug ) const = 0; + // Called in client, if any data to be returned , the set on class ServerReply + // Cmd_ptr cts_cmd can used for additional context. + // return true, if client should exit, returns false, if further work required, ie blocking, errors, etc + virtual bool handle_server_response(ServerReply&, Cmd_ptr cts_cmd, bool debug) const = 0; protected: - ServerToClientCmd()= default; + ServerToClientCmd() = default; + private: - friend class cereal::access; - template - void serialize(Archive & ar, std::uint32_t const version ) - { - } + friend class cereal::access; + template + void serialize(Archive& ar, std::uint32_t const version) {} }; #endif diff --git a/Base/src/stc/StcCmd.hpp b/Base/src/stc/StcCmd.hpp index 6a79b9d65..4e46134f0 100644 --- a/Base/src/stc/StcCmd.hpp +++ b/Base/src/stc/StcCmd.hpp @@ -3,14 +3,14 @@ /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 // Name : // Author : Avi -// Revision : $Revision: #8 $ +// Revision : $Revision: #8 $ // // Copyright 2009- ECMWF. -// This software is licensed under the terms of the Apache Licence version 2.0 -// which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. -// In applying this licence, ECMWF does not waive the privileges and immunities -// granted to it by virtue of its status as an intergovernmental organisation -// nor does it submit to any jurisdiction. +// This software is licensed under the terms of the Apache Licence version 2.0 +// which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. +// In applying this licence, ECMWF does not waive the privileges and immunities +// granted to it by virtue of its status as an intergovernmental organisation +// nor does it submit to any jurisdiction. // // Description : /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 @@ -23,39 +23,38 @@ // symbols due to use of boost serialisation, will use a single command class StcCmd final : public ServerToClientCmd { public: - enum Api { OK, - BLOCK_CLIENT_SERVER_HALTED, - BLOCK_CLIENT_ON_HOME_SERVER, - DELETE_ALL, - INVALID_ARGUMENT, // Created on the Client side - END_OF_FILE - }; - explicit StcCmd(Api a) : api_(a) {} - StcCmd()= default; - - void init(Api a) { api_ = a;} - Api api() const { return api_;} - - std::string print() const override; - bool equals(ServerToClientCmd*) const override; - bool handle_server_response( ServerReply& server_reply, Cmd_ptr cts_cmd, bool debug ) const override; - - /// Other legitimate ServerToClientCmd commands also return ok() as true - bool ok() const override { return api_ == OK; } // used by group command - - // avoid adding OK to group command. Since groupCmd will return true from GroupSTCCmd::ok() *IF* there are no errors - bool is_returnable_in_group_cmd() const override { return api_ == DELETE_ALL; } + enum Api { + OK, + BLOCK_CLIENT_SERVER_HALTED, + BLOCK_CLIENT_ON_HOME_SERVER, + DELETE_ALL, + INVALID_ARGUMENT, // Created on the Client side + END_OF_FILE + }; + explicit StcCmd(Api a) : api_(a) {} + StcCmd() = default; + + void init(Api a) { api_ = a; } + Api api() const { return api_; } + + std::string print() const override; + bool equals(ServerToClientCmd*) const override; + bool handle_server_response(ServerReply& server_reply, Cmd_ptr cts_cmd, bool debug) const override; + + /// Other legitimate ServerToClientCmd commands also return ok() as true + bool ok() const override { return api_ == OK; } // used by group command + + // avoid adding OK to group command. Since groupCmd will return true from GroupSTCCmd::ok() *IF* there are no errors + bool is_returnable_in_group_cmd() const override { return api_ == DELETE_ALL; } private: - Api api_{OK}; - - friend class cereal::access; - template - void serialize(Archive & ar, std::uint32_t const version ) - { - ar(cereal::base_class< ServerToClientCmd >( this ), - CEREAL_NVP(api_)); - } + Api api_{OK}; + + friend class cereal::access; + template + void serialize(Archive& ar, std::uint32_t const version) { + ar(cereal::base_class(this), CEREAL_NVP(api_)); + } }; std::ostream& operator<<(std::ostream& os, const StcCmd&); #endif diff --git a/Base/src/stc/ZombieGetCmd.hpp b/Base/src/stc/ZombieGetCmd.hpp index 86a107692..05cc901d2 100644 --- a/Base/src/stc/ZombieGetCmd.hpp +++ b/Base/src/stc/ZombieGetCmd.hpp @@ -3,14 +3,14 @@ /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 // Name : // Author : Avi -// Revision : $Revision: #4 $ +// Revision : $Revision: #4 $ // // Copyright 2009- ECMWF. -// This software is licensed under the terms of the Apache Licence version 2.0 -// which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. -// In applying this licence, ECMWF does not waive the privileges and immunities -// granted to it by virtue of its status as an intergovernmental organisation -// nor does it submit to any jurisdiction. +// This software is licensed under the terms of the Apache Licence version 2.0 +// which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. +// In applying this licence, ECMWF does not waive the privileges and immunities +// granted to it by virtue of its status as an intergovernmental organisation +// nor does it submit to any jurisdiction. // // Description : /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 @@ -25,25 +25,25 @@ class AbstractServer; //================================================================================ class ZombieGetCmd final : public ServerToClientCmd { public: - explicit ZombieGetCmd(AbstractServer*); - ZombieGetCmd() : ServerToClientCmd() {} + explicit ZombieGetCmd(AbstractServer*); + ZombieGetCmd() : ServerToClientCmd() {} - void init(AbstractServer*); - bool handle_server_response( ServerReply&, Cmd_ptr cts_cmd, bool debug ) const override; - std::string print() const override; - bool equals(ServerToClientCmd*) const override; - void cleanup() override { std::vector().swap(zombies_);} /// run in the server, after command send to client + void init(AbstractServer*); + bool handle_server_response(ServerReply&, Cmd_ptr cts_cmd, bool debug) const override; + std::string print() const override; + bool equals(ServerToClientCmd*) const override; + void cleanup() override { + std::vector().swap(zombies_); + } /// run in the server, after command send to client private: - std::vector zombies_; + std::vector zombies_; - friend class cereal::access; - template - void serialize(Archive & ar, std::uint32_t const version ) - { - ar(cereal::base_class< ServerToClientCmd >( this ), - CEREAL_NVP(zombies_)); - } + friend class cereal::access; + template + void serialize(Archive& ar, std::uint32_t const version) { + ar(cereal::base_class(this), CEREAL_NVP(zombies_)); + } }; std::ostream& operator<<(std::ostream& os, const ZombieGetCmd&); diff --git a/Http/test/Certificate.hpp b/Http/test/Certificate.hpp index c9e375952..dfaf69683 100644 --- a/Http/test/Certificate.hpp +++ b/Http/test/Certificate.hpp @@ -8,76 +8,70 @@ #include #include -class Certificate -{ - public: +class Certificate { +public: Certificate() = delete; Certificate(const std::string& path); ~Certificate(); - private: +private: std::string path_; EVP_PKEY* generate_key(); - X509 * generate_x509(EVP_PKEY* pkey); + X509* generate_x509(EVP_PKEY* pkey); void write_to_disk(EVP_PKEY* pkey, X509* x509); }; -inline -Certificate::Certificate(const std::string& path) : path_(path) { - //std::cout << "Generating RSA key..." << std::endl; +inline Certificate::Certificate(const std::string& path) : path_(path) { + // std::cout << "Generating RSA key..." << std::endl; + + EVP_PKEY* pkey = generate_key(); - EVP_PKEY * pkey = generate_key(); - /* Generate the certificate. */ - //std::cout << "Generating x509 certificate..." << std::endl; - - X509 * x509 = generate_x509(pkey); - if(!x509) - { + // std::cout << "Generating x509 certificate..." << std::endl; + + X509* x509 = generate_x509(pkey); + if (!x509) { EVP_PKEY_free(pkey); - throw std::runtime_error("Unable to create certificate");; + throw std::runtime_error("Unable to create certificate"); + ; } - + /* Write the private key and certificate out to disk. */ - //std::cout << "Writing key and certificate to disk..." << std::endl; - + // std::cout << "Writing key and certificate to disk..." << std::endl; + write_to_disk(pkey, x509); } -inline -Certificate::~Certificate() { +inline Certificate::~Certificate() { if (remove((path_ + "/server.crt").c_str()) != 0) { std::cerr << "Failed to remove file server.crt" << std::endl; } else { - std::cout << "Removed file " << (path_ + "/server.crt") << std::endl; + std::cout << "Removed file " << (path_ + "/server.crt") << std::endl; } if (remove((path_ + "/server.key").c_str()) != 0) { std::cerr << "Failed to remove file server.key" << std::endl; } else { - std::cout << "Removed file " << (path_ + "/server.key") << std::endl; + std::cout << "Removed file " << (path_ + "/server.key") << std::endl; } } /* Generates a 2048-bit RSA key. */ -inline -EVP_PKEY* Certificate::generate_key() -{ +inline EVP_PKEY* Certificate::generate_key() { const int KEY_LEN = 2048; #if OPENSSL_VERSION_MAJOR >= 3 - EVP_PKEY * pkey = EVP_RSA_gen(KEY_LEN); - if(!pkey) - { + EVP_PKEY* pkey = EVP_RSA_gen(KEY_LEN); + if (!pkey) { throw std::runtime_error("Unable to create EVP_PKEY structure"); } #else /* Allocate memory for the EVP_PKEY structure. */ - EVP_PKEY * pkey = EVP_PKEY_new(); - + EVP_PKEY* pkey = EVP_PKEY_new(); + /* Generate the RSA key and assign it to pkey. */ - RSA * rsa = RSA_new(); + RSA* rsa = RSA_new(); BIGNUM* bne = BN_new(); if (!BN_set_word(bne, 65537)) { @@ -89,100 +83,89 @@ EVP_PKEY* Certificate::generate_key() } // RSA * rsa = RSA_generate_key(2048, RSA_F4, NULL, NULL); - if(!EVP_PKEY_assign_RSA(pkey, rsa)) - { + if (!EVP_PKEY_assign_RSA(pkey, rsa)) { EVP_PKEY_free(pkey); throw std::runtime_error("Unable to generate 2048-bit RSA key"); } #endif - + /* The key has been generated, return it. */ return pkey; } /* Generates a self-signed x509 certificate. */ -inline -X509 * Certificate::generate_x509(EVP_PKEY * pkey) -{ +inline X509* Certificate::generate_x509(EVP_PKEY* pkey) { /* Allocate memory for the X509 structure. */ - X509 * x509 = X509_new(); - if(!x509) - { + X509* x509 = X509_new(); + if (!x509) { EVP_PKEY_free(pkey); throw std::runtime_error("Unable to create X509 structure"); } - + /* Set the serial number. */ ASN1_INTEGER_set(X509_get_serialNumber(x509), 1); - + /* This certificate is valid from now until exactly one year from now. */ X509_gmtime_adj(X509_get_notBefore(x509), 0); X509_gmtime_adj(X509_get_notAfter(x509), 31536000L); - + /* Set the public key for our certificate. */ X509_set_pubkey(x509, pkey); - + /* We want to copy the subject name to the issuer name. */ - X509_NAME * name = X509_get_subject_name(x509); - + X509_NAME* name = X509_get_subject_name(x509); + /* Set the country code and common name. */ - X509_NAME_add_entry_by_txt(name, "C", MBSTRING_ASC, (unsigned char *)"CA", -1, -1, 0); - X509_NAME_add_entry_by_txt(name, "O", MBSTRING_ASC, (unsigned char *)"ecflow-test", -1, -1, 0); - X509_NAME_add_entry_by_txt(name, "CN", MBSTRING_ASC, (unsigned char *)"localhost", -1, -1, 0); - + X509_NAME_add_entry_by_txt(name, "C", MBSTRING_ASC, (unsigned char*)"CA", -1, -1, 0); + X509_NAME_add_entry_by_txt(name, "O", MBSTRING_ASC, (unsigned char*)"ecflow-test", -1, -1, 0); + X509_NAME_add_entry_by_txt(name, "CN", MBSTRING_ASC, (unsigned char*)"localhost", -1, -1, 0); + /* Now set the issuer name. */ X509_set_issuer_name(x509, name); - + /* Actually sign the certificate with our key. */ - if(!X509_sign(x509, pkey, EVP_sha1())) - { + if (!X509_sign(x509, pkey, EVP_sha1())) { X509_free(x509); EVP_PKEY_free(pkey); throw std::runtime_error("Error signing certificate"); } - + return x509; } -inline -void Certificate::write_to_disk(EVP_PKEY * pkey, X509 * x509) -{ +inline void Certificate::write_to_disk(EVP_PKEY* pkey, X509* x509) { /* Open the PEM file for writing the key to disk. */ - FILE * pkey_file = fopen((path_ + "/server.key").c_str(), "wb"); - if(!pkey_file) - { + FILE* pkey_file = fopen((path_ + "/server.key").c_str(), "wb"); + if (!pkey_file) { EVP_PKEY_free(pkey); throw std::runtime_error("Unable to open " + path_ + "/server.key for writing"); } - + /* Write the key to disk. */ bool ret = PEM_write_PrivateKey(pkey_file, pkey, NULL, NULL, 0, NULL, NULL); fclose(pkey_file); - + EVP_PKEY_free(pkey); - if(!ret) - { + if (!ret) { X509_free(x509); throw std::runtime_error("Unable to write private key to disk"); } - + /* Open the PEM file for writing the certificate to disk. */ - FILE * x509_file = fopen((path_ + "/server.crt").c_str(), "wb"); - if(!x509_file) - { + FILE* x509_file = fopen((path_ + "/server.crt").c_str(), "wb"); + if (!x509_file) { X509_free(x509); throw std::runtime_error("Unable to open " + path_ + "/server.crt for writing"); } - + /* Write the certificate to disk. */ ret = PEM_write_X509(x509_file, x509); fclose(x509_file); - X509_free(x509); - if(!ret) - { + X509_free(x509); + if (!ret) { throw std::runtime_error("Unable to write private key to disk"); } } \ No newline at end of file diff --git a/Http/test/InvokeServer.hpp b/Http/test/InvokeServer.hpp index 1f620a688..94d144e43 100644 --- a/Http/test/InvokeServer.hpp +++ b/Http/test/InvokeServer.hpp @@ -3,14 +3,14 @@ /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 // Name : // Author : Avi -// Revision : $Revision: #32 $ +// Revision : $Revision: #32 $ // // Copyright 2009- ECMWF. -// This software is licensed under the terms of the Apache Licence version 2.0 -// which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. -// In applying this licence, ECMWF does not waive the privileges and immunities -// granted to it by virtue of its status as an intergovernmental organisation -// nor does it submit to any jurisdiction. +// This software is licensed under the terms of the Apache Licence version 2.0 +// which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. +// In applying this licence, ECMWF does not waive the privileges and immunities +// granted to it by virtue of its status as an intergovernmental organisation +// nor does it submit to any jurisdiction. // // Description : /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 @@ -31,10 +31,9 @@ class InvokeServer { public: - InvokeServer() - { + InvokeServer() { std::string port(getenv("ECF_PORT")); - /// Remove check pt and backup check pt file, else server will load it & remove log file + /// Remove check pt and backup check pt file, else server will load it & remove log file ecf::Host h; boost::filesystem::remove(h.ecf_checkpt_file(port)); boost::filesystem::remove(h.ecf_backup_checkpt_file(port)); @@ -42,14 +41,13 @@ class InvokeServer { std::string theServerInvokePath = ecf::File::find_ecf_server_path(); - BOOST_REQUIRE_MESSAGE(!theServerInvokePath.empty(),"The server program could not be found"); - BOOST_REQUIRE_MESSAGE(boost::filesystem::exists(theServerInvokePath),"Server exe does not exist at:" << theServerInvokePath); + BOOST_REQUIRE_MESSAGE(!theServerInvokePath.empty(), "The server program could not be found"); + BOOST_REQUIRE_MESSAGE(boost::filesystem::exists(theServerInvokePath), + "Server exe does not exist at:" << theServerInvokePath); BOOST_TEST_MESSAGE("Using eclow_server from " << theServerInvokePath); - std::thread t([&]{ - system(theServerInvokePath.c_str()); - }); + std::thread t([&] { system(theServerInvokePath.c_str()); }); t.detach(); @@ -63,29 +61,32 @@ class InvokeServer { else { server_started = false; } - } - - ~InvokeServer() { - std::string port(getenv("ECF_PORT")); - - BOOST_TEST_MESSAGE("*****InvokeServer:: Closing server on port " << port); - { - ClientInvoker theClient("localhost",port); - BOOST_REQUIRE_NO_THROW( theClient.terminateServer() ); - BOOST_REQUIRE_MESSAGE( theClient.wait_for_server_death(),"Failed to terminate server after 60 seconds\n"); - } - - ecf::Host h; - boost::filesystem::remove(h.ecf_log_file(port)); - BOOST_CHECK_MESSAGE(!boost::filesystem::exists(h.ecf_log_file(port)), "log file " << h.ecf_log_file(port) << " not deleted\n"); - - boost::filesystem::remove(h.ecf_checkpt_file(port)); - boost::filesystem::remove(h.ecf_backup_checkpt_file(port)); - BOOST_CHECK_MESSAGE(!boost::filesystem::exists(h.ecf_checkpt_file(port)), "file " << h.ecf_checkpt_file(port) << " not deleted\n"); - BOOST_CHECK_MESSAGE(!boost::filesystem::exists(h.ecf_backup_checkpt_file(port)), "file " << h.ecf_backup_checkpt_file(port) << " not deleted\n"); - } - - bool server_started{false}; + } + + ~InvokeServer() { + std::string port(getenv("ECF_PORT")); + + BOOST_TEST_MESSAGE("*****InvokeServer:: Closing server on port " << port); + { + ClientInvoker theClient("localhost", port); + BOOST_REQUIRE_NO_THROW(theClient.terminateServer()); + BOOST_REQUIRE_MESSAGE(theClient.wait_for_server_death(), "Failed to terminate server after 60 seconds\n"); + } + + ecf::Host h; + boost::filesystem::remove(h.ecf_log_file(port)); + BOOST_CHECK_MESSAGE(!boost::filesystem::exists(h.ecf_log_file(port)), + "log file " << h.ecf_log_file(port) << " not deleted\n"); + + boost::filesystem::remove(h.ecf_checkpt_file(port)); + boost::filesystem::remove(h.ecf_backup_checkpt_file(port)); + BOOST_CHECK_MESSAGE(!boost::filesystem::exists(h.ecf_checkpt_file(port)), + "file " << h.ecf_checkpt_file(port) << " not deleted\n"); + BOOST_CHECK_MESSAGE(!boost::filesystem::exists(h.ecf_backup_checkpt_file(port)), + "file " << h.ecf_backup_checkpt_file(port) << " not deleted\n"); + } + + bool server_started{false}; }; #endif diff --git a/Http/test/TokenFile.hpp b/Http/test/TokenFile.hpp index 58b928771..9c272d670 100644 --- a/Http/test/TokenFile.hpp +++ b/Http/test/TokenFile.hpp @@ -5,16 +5,16 @@ #include "nlohmann/json.hpp" class TokenFile { - public: - TokenFile() = delete; - TokenFile(const std::string& tokenfile); +public: + TokenFile() = delete; + TokenFile(const std::string& tokenfile); ~TokenFile(); - private: + +private: std::string tokenfile_; }; -inline -TokenFile::TokenFile(const std::string& tokenfile) : tokenfile_(tokenfile) { +inline TokenFile::TokenFile(const std::string& tokenfile) : tokenfile_(tokenfile) { // write api token file // api-keys: 3a8c3f7ac204d9c6370b5916bd8b86166c208e10776285edcbc741d56b5b4c1e // 351db772d94310a6d57aa7144448f4c108e7ee2e2a00a74edbdf8edb11bee71b @@ -22,23 +22,32 @@ TokenFile::TokenFile(const std::string& tokenfile) : tokenfile_(tokenfile) { // 5c6f6a003f3292c4d7671c9ad8ca10fb76e2273e584992f0d1f8fdf4abcdc81e nlohmann::json j = { - { {"hash", "sha256$22660ab1789dc30e$7e24f61129294505b6ac310ebe891df9800f4854a67bac953bb86bf9fd726813"}, {"description", "test-app-1"}, {"expires_at", ""} }, - { {"hash", "pbkdf2:sha256:20000$Iqbh8Bz86hYHpkpn$ea95e8fb276c602fe4a4b56569fbcc321be5b31a3caa6bb3a9001e595349887f"}, {"description", "test-app-2"}, {"expires_at", "2100-01-01T00:00:00Z"} }, - { {"hash", "pbkdf2:sha256:20000$Iqbh8Bz86hYHpkpn$ea95e8fb276c602fe4a4b56569fbcc321be5b31a3caa6bb3a9001e595349887f"}, {"description", "test-app-3"}, {"expires_at", "2000-01-01T00:00:00Z"} }, - { {"hash", "pbkdf2:sha256:20000$Iqbh8Bz86hYHpkpn$ea95e8fb276c602fe4a4b56569fbcc321be5b31a3caa6bb3a9001e595349887f"}, {"description", "test-app-4"}, {"revoked_at", "2000-01-01T00:00:00Z"} } - }; + {{"hash", "sha256$22660ab1789dc30e$7e24f61129294505b6ac310ebe891df9800f4854a67bac953bb86bf9fd726813"}, + {"description", "test-app-1"}, + {"expires_at", ""}}, + {{"hash", + "pbkdf2:sha256:20000$Iqbh8Bz86hYHpkpn$ea95e8fb276c602fe4a4b56569fbcc321be5b31a3caa6bb3a9001e595349887f"}, + {"description", "test-app-2"}, + {"expires_at", "2100-01-01T00:00:00Z"}}, + {{"hash", + "pbkdf2:sha256:20000$Iqbh8Bz86hYHpkpn$ea95e8fb276c602fe4a4b56569fbcc321be5b31a3caa6bb3a9001e595349887f"}, + {"description", "test-app-3"}, + {"expires_at", "2000-01-01T00:00:00Z"}}, + {{"hash", + "pbkdf2:sha256:20000$Iqbh8Bz86hYHpkpn$ea95e8fb276c602fe4a4b56569fbcc321be5b31a3caa6bb3a9001e595349887f"}, + {"description", "test-app-4"}, + {"revoked_at", "2000-01-01T00:00:00Z"}}}; std::ofstream o(tokenfile_); o << std::setw(4) << j << std::endl; setenv("ECF_API_TOKEN_FILE", tokenfile_.c_str(), 1); } -inline -TokenFile::~TokenFile() { - if (remove(tokenfile_.c_str()) != 0) { - std::cerr << "Failed to remove token file " << tokenfile_ << std::endl; - } - else { - BOOST_TEST_MESSAGE("Removed token file " << tokenfile_); - } +inline TokenFile::~TokenFile() { + if (remove(tokenfile_.c_str()) != 0) { + std::cerr << "Failed to remove token file " << tokenfile_ << std::endl; + } + else { + BOOST_TEST_MESSAGE("Removed token file " << tokenfile_); + } } diff --git a/Viewer/ecflowUI/src/ComboMulti.cpp b/Viewer/ecflowUI/src/ComboMulti.cpp index b0d575f2d..bc71e9595 100644 --- a/Viewer/ecflowUI/src/ComboMulti.cpp +++ b/Viewer/ecflowUI/src/ComboMulti.cpp @@ -179,8 +179,9 @@ void ComboMultiDelegate::paint(QPainter* painter, const QStyleOptionViewItem& op style->drawControl(QStyle::CE_CheckBox, &opt, painter); } -QWidget* -ComboMultiDelegate::createEditor(QWidget* parent, const QStyleOptionViewItem& /*option*/, const QModelIndex& /*index*/) const { +QWidget* ComboMultiDelegate::createEditor(QWidget* parent, + const QStyleOptionViewItem& /*option*/, + const QModelIndex& /*index*/) const { auto* editor = new QCheckBox(parent); return editor; } diff --git a/Viewer/ecflowUI/src/LogLoadView.cpp b/Viewer/ecflowUI/src/LogLoadView.cpp index 400cbe731..6c523a57c 100644 --- a/Viewer/ecflowUI/src/LogLoadView.cpp +++ b/Viewer/ecflowUI/src/LogLoadView.cpp @@ -1222,11 +1222,11 @@ void LogRequestView::clearCharts() { // We do it in this way to get rid of error message: //"Cannot remove axis. Axis not found on the chart." - auto *ax = ViewerUtil::chartAxisX(v->chart()); + auto* ax = ViewerUtil::chartAxisX(v->chart()); if (v->chart()->axes(Qt::Horizontal).contains(ax)) { v->chart()->removeAxis(ax); } - auto *ay = ViewerUtil::chartAxisY(v->chart()); + auto* ay = ViewerUtil::chartAxisY(v->chart()); if (v->chart()->axes(Qt::Vertical).contains(ay)) { v->chart()->removeAxis(ay); } @@ -1326,7 +1326,7 @@ void LogRequestView::build(ChartView* view, QLineSeries* series, QString title, } else { chart->addSeries(series); - auto *ax = ViewerUtil::chartAxisX(chart); + auto* ax = ViewerUtil::chartAxisX(chart); if (ax != nullptr) { series->attachAxis(ax); } @@ -1673,8 +1673,8 @@ void LogTotalRequestView::addSuite(int idx) { data_->getSuiteTotalReq(idx, *series); chart = getChart(TotalChartType); chart->addSeries(series); - auto *ax = ViewerUtil::chartAxisX(chart); - auto *ay = ViewerUtil::chartAxisY(chart); + auto* ax = ViewerUtil::chartAxisX(chart); + auto* ay = ViewerUtil::chartAxisY(chart); if (ax != nullptr) { series->attachAxis(ax); } diff --git a/Viewer/ecflowUI/src/NodeQueryEngine.cpp b/Viewer/ecflowUI/src/NodeQueryEngine.cpp index 4c4f50f91..e04ed7d18 100644 --- a/Viewer/ecflowUI/src/NodeQueryEngine.cpp +++ b/Viewer/ecflowUI/src/NodeQueryEngine.cpp @@ -128,7 +128,7 @@ bool NodeQueryEngine::runQuery(NodeQuery* query, QStringList allServers) { } // Notify the servers that the search began - for(ServerHandler* s: servers_) { + for (ServerHandler* s : servers_) { s->searchBegan(); } @@ -271,7 +271,7 @@ void NodeQueryEngine::broadcastChunk(bool force) { void NodeQueryEngine::slotFinished() { // Notify the servers that the search finished - for (ServerHandler* s: servers_) { + for (ServerHandler* s : servers_) { s->searchFinished(); } } diff --git a/Viewer/ecflowUI/src/PropertyLine.cpp b/Viewer/ecflowUI/src/PropertyLine.cpp index 34f8ae477..178577ccf 100644 --- a/Viewer/ecflowUI/src/PropertyLine.cpp +++ b/Viewer/ecflowUI/src/PropertyLine.cpp @@ -12,7 +12,6 @@ #include -#include #include #include #include @@ -27,6 +26,7 @@ #include #include #include +#include #include "ComboMulti.hpp" #include "Sound.hpp" @@ -522,10 +522,10 @@ FontPropertyLine::FontPropertyLine(VProperty* guiProp, bool addLabel, QWidget* p hb->addWidget(familyCb_); #if QT_VERSION >= QT_VERSION_CHECK(6, 2, 0) - for (QString s: QFontDatabase::families(QFontDatabase::Latin)) { + for (QString s : QFontDatabase::families(QFontDatabase::Latin)) { #else QFontDatabase db; - for (QString s: db.families(QFontDatabase::Latin)) { + for (QString s : db.families(QFontDatabase::Latin)) { #endif familyCb_->addItem(s); } diff --git a/Viewer/ecflowUI/src/TableNodeView.cpp b/Viewer/ecflowUI/src/TableNodeView.cpp index c7b306262..d9eb52c2d 100644 --- a/Viewer/ecflowUI/src/TableNodeView.cpp +++ b/Viewer/ecflowUI/src/TableNodeView.cpp @@ -791,9 +791,9 @@ void TableNodeHeader::mousePressEvent(QMouseEvent* event) { Q_EMIT customButtonClicked(it.value().id(), #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) - event->globalPosition().toPoint()); + event->globalPosition().toPoint()); #else - event->globalPos()); + event->globalPos()); #endif } ++it; diff --git a/Viewer/ecflowUI/src/TreeNodeViewDelegate.cpp b/Viewer/ecflowUI/src/TreeNodeViewDelegate.cpp index 1b813e0e6..ef3462671 100644 --- a/Viewer/ecflowUI/src/TreeNodeViewDelegate.cpp +++ b/Viewer/ecflowUI/src/TreeNodeViewDelegate.cpp @@ -1303,7 +1303,7 @@ int TreeNodeViewDelegate::nodeWidth(const QModelIndex& index, int height, QStrin else { QVariant va = index.data(AbstractNodeModel::IconRole); #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) - if (va.typeId() == QMetaType::QVariantList) { + if (va.typeId() == QMetaType::QVariantList) { #else if (va.type() == QVariant::List) { #endif diff --git a/Viewer/ecflowUI/src/VNode.cpp b/Viewer/ecflowUI/src/VNode.cpp index fffeb6ebe..103680a4c 100644 --- a/Viewer/ecflowUI/src/VNode.cpp +++ b/Viewer/ecflowUI/src/VNode.cpp @@ -1452,7 +1452,9 @@ void VServer::beginUpdate(VNode* node, const std::vector& asp // If anything does not match we return false that will call reset!!! //------------------------------------------------------------------------------------------- -void VServer::endUpdate(VNode* /*node*/, const std::vector& /*aspect*/, const VNodeChange& /*change*/) { +void VServer::endUpdate(VNode* /*node*/, + const std::vector& /*aspect*/, + const VNodeChange& /*change*/) { } void VServer::beginUpdate(const std::vector& aspect) { diff --git a/Viewer/ecflowUI/src/VProperty.cpp b/Viewer/ecflowUI/src/VProperty.cpp index b28380673..97978f01f 100644 --- a/Viewer/ecflowUI/src/VProperty.cpp +++ b/Viewer/ecflowUI/src/VProperty.cpp @@ -135,7 +135,7 @@ void VProperty::setValue(const std::string& val) { } } #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) - if (!defaultValue_.isNull() && defaultValue_.typeId() != value_.typeId()) { + if (!defaultValue_.isNull() && defaultValue_.typeId() != value_.typeId()) { #else if (!defaultValue_.isNull() && defaultValue_.type() != value_.type()) { #endif @@ -152,7 +152,7 @@ void VProperty::setValue(QVariant val) { if (master_ && useMaster_) return; #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) - if (!defaultValue_.isNull() && defaultValue_.typeId() != val.typeId()) { + if (!defaultValue_.isNull() && defaultValue_.typeId() != val.typeId()) { #else if (!defaultValue_.isNull() && defaultValue_.type() != val.type()) { #endif diff --git a/Viewer/ecflowUI/src/ViewerUtil.cpp b/Viewer/ecflowUI/src/ViewerUtil.cpp index 2ba128d49..6904b2c93 100644 --- a/Viewer/ecflowUI/src/ViewerUtil.cpp +++ b/Viewer/ecflowUI/src/ViewerUtil.cpp @@ -352,23 +352,21 @@ void ViewerUtil::showShortcutInContextMenu(QAction* ac) { } #ifdef ECFLOW_LOGVIEW -QAbstractAxis* ViewerUtil::chartAxisX(QChart* chart) -{ -#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0) +QAbstractAxis* ViewerUtil::chartAxisX(QChart* chart) { + #if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0) auto axLst = chart->axes(Qt::Horizontal); - return (axLst.size() > 0)?axLst[0]:nullptr; -#else + return (axLst.size() > 0) ? axLst[0] : nullptr; + #else return chart->axisX(); -#endif + #endif } -QAbstractAxis* ViewerUtil::chartAxisY(QChart* chart) -{ -#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0) +QAbstractAxis* ViewerUtil::chartAxisY(QChart* chart) { + #if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0) auto axLst = chart->axes(Qt::Vertical); - return (axLst.size() > 0)?axLst[0]:nullptr; -#else + return (axLst.size() > 0) ? axLst[0] : nullptr; + #else return chart->axisY(); -#endif + #endif } #endif diff --git a/Viewer/ecflowUI/src/ViewerUtil.hpp b/Viewer/ecflowUI/src/ViewerUtil.hpp index 0b66ba7c9..0d5787360 100644 --- a/Viewer/ecflowUI/src/ViewerUtil.hpp +++ b/Viewer/ecflowUI/src/ViewerUtil.hpp @@ -19,7 +19,7 @@ #include #ifdef ECFLOW_LOGVIEW -#include + #include #endif class QAction; @@ -52,7 +52,7 @@ class ViewerUtil { static QString wildcardToRegex(const QString&); static QFont findMonospaceFont(); static QIcon makeExpandIcon(bool targetOnRight); - static void showShortcutInContextMenu(QAction*); + static void showShortcutInContextMenu(QAction*); #ifdef ECFLOW_LOGVIEW static QAbstractAxis* chartAxisX(QChart* chart); static QAbstractAxis* chartAxisY(QChart* chart); diff --git a/Viewer/ecflowUI/src/WidgetNameProvider.cpp b/Viewer/ecflowUI/src/WidgetNameProvider.cpp index 75801413a..de7d1195c 100644 --- a/Viewer/ecflowUI/src/WidgetNameProvider.cpp +++ b/Viewer/ecflowUI/src/WidgetNameProvider.cpp @@ -49,12 +49,12 @@ void WidgetNameProvider::nameChildren(QWidget* w) { } void WidgetNameProvider::nameButtons(QList acLst) { - for (QAction* ac: acLst) { + for (QAction* ac : acLst) { #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) - for (QObject* obj: ac->associatedObjects()) { + for (QObject* obj : ac->associatedObjects()) { auto w = qobject_cast(obj); #else - for (QWidget* w: ac->associatedWidgets()) { + for (QWidget* w : ac->associatedWidgets()) { #endif if (w->objectName().isEmpty()) { w->setObjectName(ac->objectName());