Skip to content
Snippets Groups Projects
Commit 7fc34b28 authored by Jorrit Schaap's avatar Jorrit Schaap
Browse files

TMSS-156: use hostname, port, user and pass from configuration file. TODO:...

TMSS-156: use hostname, port, user and pass from configuration file. TODO: replace test user/pass with secret user/pass which is not stored in git
parent e4a5baa1
No related branches found
No related tags found
1 merge request!116TMSS-156: Resolve TMSS-156
...@@ -328,8 +328,13 @@ GCFEvent::TResult MACScheduler::initial_state(GCFEvent& event, GCFPortInterface& ...@@ -328,8 +328,13 @@ GCFEvent::TResult MACScheduler::initial_state(GCFEvent& event, GCFPortInterface&
LOG_INFO ("Connected to the OTDB"); LOG_INFO ("Connected to the OTDB");
itsPropertySet->setValue(PN_MS_OTDB_CONNECTED, GCFPVBool(true)); itsPropertySet->setValue(PN_MS_OTDB_CONNECTED, GCFPVBool(true));
LOG_INFO ("Trying to connect to the TMSS " ); std::string tmss_username = pParamSet->getString("TMSSusername", "test");
itsTMSSconnection= new TMSSBridge(); std::string tmss_password = pParamSet->getString("TMSSpassword", "test");
std::string tmss_hostname = pParamSet->getString("TMSShostname", "120.0.0.1");
int tmss_port = pParamSet->getInt("TMSSport", 8008);
LOG_INFO_STR ("Trying to connect to the TMSS " << tmss_hostname << ":" << tmss_port << " user/pass:" << tmss_username << "/******" );
itsTMSSconnection= new TMSSBridge(tmss_hostname, tmss_port, tmss_username, tmss_password);
LOG_INFO ("Connected to the TMSSBridge"); LOG_INFO ("Connected to the TMSSBridge");
......
...@@ -7,6 +7,12 @@ OTDBusername = paulus ...@@ -7,6 +7,12 @@ OTDBusername = paulus
OTDBpassword = boskabouter OTDBpassword = boskabouter
OTDBpollInterval = 5s OTDBpollInterval = 5s
# TMSS connection info
TMSShostname = tmss-ua.control.lofar
TMSSport = 8008
TMSSusername = test # TODO: replace test user/pass with secret user/pass which is not stored in git
TMSSpassword = test # TODO: replace test user/pass with secret user/pass which is not stored in git
# startup periods of Observations # startup periods of Observations
QueuePeriod = 3m QueuePeriod = 3m
......
...@@ -39,16 +39,14 @@ namespace LOFAR { ...@@ -39,16 +39,14 @@ namespace LOFAR {
// //
// TMSSBridge Constructor // TMSSBridge Constructor
// //
TMSSBridge::TMSSBridge(): TMSSBridge::TMSSBridge(const std::string &hostname, int port, const std::string &username, const std::string &password):
itsUser("test"), itsUser(username),
itsPassword("test"), itsPassword(password),
itsHost("http://127.0.0.1"), // just to start with maybe user and password need itsHost(hostname),
itsPort(8000) itsPort(port)
{ {
} }
// //
// TMSSBridge Destructor // TMSSBridge Destructor
// //
...@@ -116,16 +114,22 @@ std::size_t callback(const char* in, ...@@ -116,16 +114,22 @@ std::size_t callback(const char* in,
// Need to check respons status code of http (200) // Need to check respons status code of http (200)
// Inspired by https://gist.github.com/connormanning/41efa6075515019e499c // Inspired by https://gist.github.com/connormanning/41efa6075515019e499c
// Example: // Example:
// httpGET("http://127.0.0.1", 8000, "/api/subtask/?start_time__lt=2020-03-04T12:03:00" // httpGET("/api/subtask/?start_time__lt=2020-03-04T12:03:00"
// results in a json string output // results in a json string output
// //
Json::Value TMSSBridge::httpGET(const string& host, const int port, const string& target) Json::Value TMSSBridge::httpGET(const string& target)
{ {
Json::Value jsonData(""); Json::Value jsonData("");
const std::string url(host + target);
const std::string url(std::format("http://{}:{}/{}", itsHost, itsPort, target));
CURL* curl = curl_easy_init(); CURL* curl = curl_easy_init();
// setup authentication
curl_easy_setopt(curl, CURLOPT_USERNAME, itsUser.c_str());
curl_easy_setopt(curl, CURLOPT_PASSWORD, itsPassword.c_str());
curl_easy_setopt(curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
// Set remote URL. // Set remote URL.
curl_easy_setopt(curl, CURLOPT_URL, url.c_str()); curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
......
...@@ -41,6 +41,7 @@ class TMSSBridge ...@@ -41,6 +41,7 @@ class TMSSBridge
public: public:
// Just creates an object and registers the connection parameters. // Just creates an object and registers the connection parameters.
TMSSBridge (); TMSSBridge ();
TMSSBridge (const std::string &hostname, int port, const std::string &username, const std::string &password);
~TMSSBridge (); ~TMSSBridge ();
vector<int> getSubTaskIDStartingInThreeMinutes(ptime currentTime, string clusterName); vector<int> getSubTaskIDStartingInThreeMinutes(ptime currentTime, string clusterName);
...@@ -49,7 +50,7 @@ public: ...@@ -49,7 +50,7 @@ public:
vector<string> translateHttpResultToSortedUrlList(Json::Value result); vector<string> translateHttpResultToSortedUrlList(Json::Value result);
// http request to TMSS // http request to TMSS
Json::Value httpGET(const string& host, int const port, const string& target); Json::Value httpGET(const string& target);
private: private:
// Copying is not allowed // Copying is not allowed
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment