Skip to content
Snippets Groups Projects
Commit 6409ac56 authored by vagrant's avatar vagrant
Browse files

TMSS-156: Fixes to build TMSSBridge, remove boost beast dependency

parent ae3cf35f
No related branches found
No related tags found
1 merge request!116TMSS-156: Resolve TMSS-156
......@@ -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;
};
// @}
......
......@@ -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;
......
......@@ -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)
......
......@@ -3,7 +3,7 @@
lofar_add_bin_program(MACScheduler
MACSchedulerMain.cc
MACScheduler.cc
TMMSBridge.cc
TMSSBridge.cc
ObsClaimer.cc)
lofar_add_bin_program(claimTest
......
......@@ -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()) {
......
......@@ -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;
}
......
......@@ -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
......@@ -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()
......
......@@ -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
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment