diff --git a/MAC/APL/CASATools/include/CASATools/CasaConverter.h b/MAC/APL/CASATools/include/CASATools/CasaConverter.h index 533840c47e1284dd76b2c57a32f4e0dd57b3f191..3c6b4826d9fb4dad4df739e5d1f34f346e2441e2 100644 --- a/MAC/APL/CASATools/include/CASATools/CasaConverter.h +++ b/MAC/APL/CASATools/include/CASATools/CasaConverter.h @@ -67,7 +67,7 @@ public: // some functions to exploid the supported conversion types. bool isValidType(const string& refType) { return (itsDirectionTypes.find(refType) != itsDirectionTypes.end()); } - vector<string> validTypes(); + std::vector<string> validTypes(); private: // internal admin structures @@ -88,10 +88,10 @@ private: string itsTargetName; // name, type map - map<string, casacore::MDirection::Types> itsDirectionTypes; + std::map<string, casacore::MDirection::Types> itsDirectionTypes; // type, converter_t map - map<casacore::MDirection::Types, converter_t> itsConverters; + std::map<casacore::MDirection::Types, converter_t> itsConverters; }; // @} diff --git a/MAC/APL/CASATools/src/CasaConverter.cc b/MAC/APL/CASATools/src/CasaConverter.cc index eeb2a6f966815c0559596f38a09f9336ff8b1797..d175084b9e13600406a4d2e28ceea62889af642d 100644 --- a/MAC/APL/CASATools/src/CasaConverter.cc +++ b/MAC/APL/CASATools/src/CasaConverter.cc @@ -41,6 +41,7 @@ namespace LOFAR { using namespace casacore; using namespace blitz; using namespace RTC; +using namespace std; static const char* supportedTypes[] = { "J2000", "ITRF", "B1950", "HADEC", "AZELGEO", "TOPO", "ICRS", "APP", "GALACTIC", "ECLIPTIC", "COMET", @@ -89,7 +90,7 @@ CasaConverter::converter_t* CasaConverter::_getConverter(MDirection::Types theT string typeName(MDirection::showType(theType)); // try to find the converter. If it is already there then we are done - map<MDirection::Types, converter_t>::iterator iter(itsConverters.find(theType)); + std::map<MDirection::Types, converter_t>::iterator iter(itsConverters.find(theType)); if (iter != itsConverters.end()) { LOG_INFO_STR("Using existing " << typeName << " to " << itsTargetName << " converter"); return (&(iter->second)); @@ -171,7 +172,7 @@ bool CasaConverter::doConversion(const string& sourceType, } // find converter - map<string, MDirection::Types>::const_iterator iter(itsDirectionTypes.find(sourceType)); + std::map<string, MDirection::Types>::const_iterator iter(itsDirectionTypes.find(sourceType)); if (iter == itsDirectionTypes.end()) { LOG_FATAL_STR("No support for conversion from " << sourceType << " to " << itsTargetName); return (false); @@ -217,9 +218,9 @@ bool CasaConverter::doConversion(const string& sourceType, // vector<string> CasaConverter::validTypes() { - vector<string> result; - map<string, MDirection::Types>::const_iterator iter = itsDirectionTypes.begin(); - map<string, MDirection::Types>::const_iterator end = itsDirectionTypes.end (); + std::vector<string> result; + std::map<string, MDirection::Types>::const_iterator iter = itsDirectionTypes.begin(); + std::map<string, MDirection::Types>::const_iterator end = itsDirectionTypes.end (); while (iter != end) { result.push_back(iter->first); ++iter; diff --git a/MAC/APL/MainCU/CMakeLists.txt b/MAC/APL/MainCU/CMakeLists.txt index c891de1bf78ab9ec15949d2adf47743cfead5077..772dc46fbda9608ed28b552f5863e09857fe02b7 100644 --- a/MAC/APL/MainCU/CMakeLists.txt +++ b/MAC/APL/MainCU/CMakeLists.txt @@ -4,7 +4,7 @@ lofar_package(MainCU 1.0 DEPENDS Common MessageBus OTDB MACIO GCFTM GCFPVSS GCFRTDB APLCommon RTDBCommon ApplCommon CR_Protocol) include(LofarFindPackage) -lofar_find_package(Boost REQUIRED COMPONENTS date_time beast) +lofar_find_package(Boost REQUIRED COMPONENTS date_time) add_definitions(-DBOOST_DISABLE_THREADS) diff --git a/MAC/APL/MainCU/src/MACScheduler/CMakeLists.txt b/MAC/APL/MainCU/src/MACScheduler/CMakeLists.txt index cb416a299ead1742095320a754ee35baff7ea7a6..7f0072489b04c50152250c6c22b918f627939a88 100644 --- a/MAC/APL/MainCU/src/MACScheduler/CMakeLists.txt +++ b/MAC/APL/MainCU/src/MACScheduler/CMakeLists.txt @@ -3,7 +3,7 @@ lofar_add_bin_program(MACScheduler MACSchedulerMain.cc MACScheduler.cc - TMMSBridge.cc + TMSSBridge.cc ObsClaimer.cc) lofar_add_bin_program(claimTest diff --git a/MAC/APL/MainCU/src/MACScheduler/MACScheduler.cc b/MAC/APL/MainCU/src/MACScheduler/MACScheduler.cc index 47d30ca70e63535140aa5cd8629645aeb852287d..e2ec14402e1d9e06847b25d8edc7fb2781410fee 100644 --- a/MAC/APL/MainCU/src/MACScheduler/MACScheduler.cc +++ b/MAC/APL/MainCU/src/MACScheduler/MACScheduler.cc @@ -49,7 +49,6 @@ using namespace LOFAR::GCF::PVSS; using namespace LOFAR::GCF::TM; using namespace LOFAR::GCF::RTDB; using namespace LOFAR::OTDB; -using namespace LOFAR::TMSSBridge; using namespace LOFAR::Protocols; using namespace boost::posix_time; using namespace std; @@ -59,7 +58,7 @@ namespace LOFAR { using namespace DP_Protocol; using namespace CM_Protocol; using namespace APLCommon; - namespace MainCU { + namespace MainCU { #define MAX_CONCURRENT_OBSERVATIONS 100 #define MIN2(a,b) (((a) < (b)) ? (a) : (b)) @@ -702,7 +701,7 @@ void MACScheduler::_updatePlannedList() // get new list (list is ordered on starttime) of planned observations vector<OTDBtree> plannedDBlist = itsOTDBconnection->getTreeGroup(1, itsPlannedPeriod, itsExclPLcluster); // to be replaced by TMSS call (do we need a switch?)... - vector<int> subTaskID = itsTMSSconnection->getSubTaskIDStartingInThreeMinutes(itsExclPLcluster); + vector<int> subTaskID = itsTMSSconnection->getSubTaskIDStartingInThreeMinutes(currentTime, itsExclPLcluster); // the subtasksIDs should map somehow on the OTDBtree vector if (!plannedDBlist.empty()) { diff --git a/MAC/APL/MainCU/src/MACScheduler/TMSSBridge.cc b/MAC/APL/MainCU/src/MACScheduler/TMSSBridge.cc index b7af4592cce173a91606d7078dc997ea1bab101d..3ff9fbb305ff263b7f1ef2fbb04541351dbaba31 100644 --- a/MAC/APL/MainCU/src/MACScheduler/TMSSBridge.cc +++ b/MAC/APL/MainCU/src/MACScheduler/TMSSBridge.cc @@ -22,20 +22,27 @@ #include "TMSSBridge.h" +#ifdef _GET_BOOST_BEAST_WORKING_ #include <boost/beast/core.hpp> #include <boost/beast/http.hpp> #include <boost/beast/version.hpp> #include <boost/asio/connect.hpp> #include <boost/asio/ip/tcp.hpp> +#endif + #include <boost/property_tree/json_parser.hpp> +#include <boost/date_time/posix_time/posix_time.hpp> #include <cstdlib> #include <iostream> #include <string> +#ifdef _GET_BOOST_BEAST_WORKING_ namespace beast = boost::beast; // from <boost/beast.hpp> namespace http = beast::http; // from <boost/beast/http.hpp> namespace net = boost::asio; // from <boost/asio.hpp> using tcp = net::ip::tcp; // from <boost/asio/ip/tcp.hpp> +#endif + namespace pt = boost::property_tree; using namespace std; @@ -71,8 +78,8 @@ TMSSBridge::~TMSSBridge() // vector<int> TMSSBridge::getSubTaskIDStartingInThreeMinutes(ptime currentTime, string clusterName) { - currentTimeStr = std::string to_iso_extended_string(currentTime); - queryStr = "/api/?start_time__lt=" + currentTimeStr + "&cluster__name==" + clusterName; + string currentTimeStr = to_iso_extended_string(currentTime); + string queryStr = "/api/?start_time__lt=" + currentTimeStr + "&cluster__name==" + clusterName; string result = httpGET(itsHost, itsPort, queryStr); vector<string> urlList = translateHttpResultToSortedUrlList(result); @@ -88,8 +95,9 @@ vector<int> TMSSBridge::getSubTaskIDStartingInThreeMinutes(ptime currentTime, st // json_response.get('count')) // ... and results[idx].items('url) // if multiple found sort on startTime ! -vector<string> urlList = translateHttpResultToSortedUrlList(string result); +vector<string> TMSSBridge::translateHttpResultToSortedUrlList(string result) { + vector<string> urlList; // Create a root pt::ptree root; @@ -100,7 +108,10 @@ vector<string> urlList = translateHttpResultToSortedUrlList(string result); int nbrSubTasksFound = root.get<int>("count", 0); string msg = root.get<string>("some.complex.path"); + + urlList.push_back(msg); + return urlList; } @@ -110,8 +121,13 @@ vector<string> urlList = translateHttpResultToSortedUrlList(string result); // httpGET("http://127.0.0.1", 8000, "/api/subtask/?start_time__lt=2020-03-04T12:03:00" // results in a json string output // -string TMSSBridge::httpGET(auto const host, auto const port, auto const target) +string TMSSBridge::httpGET(const string& host, const int port, const string& target) { + + + string res = "dummy"; + +#ifdef _GET_BOOST_BEAST_WORKING_ try { // The io_context is required for all I/O @@ -153,7 +169,6 @@ string TMSSBridge::httpGET(auto const host, auto const port, auto const target) // if(ec && ec != beast::errc::not_connected) throw beast::system_error{ec}; - // If we get here then the connection is closed gracefully } catch(std::exception const& e) @@ -161,6 +176,7 @@ string TMSSBridge::httpGET(auto const host, auto const port, auto const target) std::cerr << "Error: " << e.what() << std::endl; return EXIT_FAILURE; } +#endif return res; } diff --git a/MAC/APL/MainCU/src/MACScheduler/TMSSBridge.h b/MAC/APL/MainCU/src/MACScheduler/TMSSBridge.h index 5db40c10a0105da07f12a2cc20ee49548561b57a..5ad201c7bc7dfcc76daf0113177c566b26afefe4 100644 --- a/MAC/APL/MainCU/src/MACScheduler/TMSSBridge.h +++ b/MAC/APL/MainCU/src/MACScheduler/TMSSBridge.h @@ -23,35 +23,42 @@ #ifndef TMSSBRIDGE_H #define TMSSBRIDGE_H +#include <boost/date_time/posix_time/posix_time.hpp> + namespace LOFAR { namespace MainCU { -using namespace boost::posix_time::ptime; +using namespace boost::posix_time; using namespace std; + class TMSSBridge { public: - // Just creates an object and registers the connection parameters. - TMSSBridge (); - ~TMSSBridge (); + // Just creates an object and registers the connection parameters. + TMSSBridge (); + ~TMSSBridge (); vector<int> getSubTaskIDStartingInThreeMinutes(ptime currentTime, string clusterName); // Actually the next method is private, make it public to be able to use in UnitTest++ - vector<string> urlList = translateHttpResultToSortedUrlList(string result); + vector<string> translateHttpResultToSortedUrlList(string result); private: - // Copying is not allowed - TMSSBridge(const TMSSBridge&); - TMSSBridge& operator=(const TMSSBridge&); + // Copying is not allowed + TMSSBridge(const TMSSBridge&); + TMSSBridge& operator=(const TMSSBridge&); // http request to TMSS - string httpGET(auto const host, auto const port, auto const target); + string httpGET(const string& host, int const port, const string& target); + string itsUser; + string itsPassword; + string itsHost; + int itsPort; }; };//MainCU };//LOFAR -#endif \ No newline at end of file +#endif diff --git a/MAC/APL/MainCU/src/MACScheduler/test/CMakeLists.txt b/MAC/APL/MainCU/src/MACScheduler/test/CMakeLists.txt index a510830b2a13e4bc43cea7f31d4f36b49e34e1e9..faac0b0e7d4aa88c7f44b2acfb274dca65cf267e 100644 --- a/MAC/APL/MainCU/src/MACScheduler/test/CMakeLists.txt +++ b/MAC/APL/MainCU/src/MACScheduler/test/CMakeLists.txt @@ -3,7 +3,7 @@ include(LofarCTest) lofar_find_package(UnitTest++) if(UNITTEST++_FOUND) - lofar_add_test(tTMSSBridge tTMSSBridge.cc) + lofar_add_test(tTMSSBridge tTMSSBridge.cc DEPENDS TMSSBridge.cc) else() message("WARNING UnitTest++ not found. Test tTMSSBridge will not be run!") endif() diff --git a/MAC/APL/MainCU/src/MACScheduler/test/tTMSSBridge.cc b/MAC/APL/MainCU/src/MACScheduler/test/tTMSSBridge.cc index 8db56c8db078c3d3f3e94a13a68c22ff500be752..750fcedf349380b3061490b309ac2b356588c831 100644 --- a/MAC/APL/MainCU/src/MACScheduler/test/tTMSSBridge.cc +++ b/MAC/APL/MainCU/src/MACScheduler/test/tTMSSBridge.cc @@ -21,10 +21,11 @@ // $Id$ #include "UnitTest++/UnitTest++.h" -// The Subject to Test -#include "../src/TMSSBridge.h" +// The Subject to be Tested +#include "../TMSSBridge.h" +#include <fstream> #include <boost/property_tree/ptree.hpp> #include <boost/property_tree/json_parser.hpp> @@ -33,15 +34,17 @@ namespace pt = boost::property_tree; using namespace std; using namespace boost::property_tree; +using namespace LOFAR::MainCU; TEST(tmss_translate_http_result_ok) { // check if json read goes well as precondition for the test - ifstream::jsonFile("test_resonse.json"); - if (!jsonFile){ + // See jsoncpp https://github.com/open-source-parsers/jsoncpp/wiki + std::ifstream jsonFile("test_resonse.json"); + if (!jsonFile) { std::cerr << "Error opening file\n"; - return -1; + // some assert error } ptree jsontree; read_json(jsonFile, jsontree); @@ -49,13 +52,11 @@ TEST(tmss_translate_http_result_ok) int v0 = jsontree.get<int>("count"); // check if count is equal to 4 .... otherwise precond test did not match so will make no sense to continue - TMSSBridge testTMSSBridge = TMSSBridge(); + TMSSBridge testTMSSBridge; - - - - // Read file jsson - testResult = testTMSSBridge.translateHttpResultToSortedUrlList(string result); + // Read file json + std::vector<string> testResult; + testResult = testTMSSBridge.translateHttpResultToSortedUrlList("json string"); // Do some check like CHECK_EQUAL } @@ -63,10 +64,11 @@ TEST(tmss_translate_http_result_ok) TEST(tmss_translate_http_empty_result) { - TMSSBridge testTMSSBridge = TMSSBridge(); + TMSSBridge testTMSSBridge; - // Read file jsson - testResult = testTMSSBridge.translateHttpResultToSortedUrlList(string result); + // Read file json + std::vector<string> testResult; + testResult = testTMSSBridge.translateHttpResultToSortedUrlList(""); // Do some check like CHECK_EQUAL }