Skip to content
Snippets Groups Projects
TMSSBridge.cc 3.2 KiB
Newer Older
//  TMSSBridge.cc: Implementation of the TMSS Bridge, interface between MAC Scheduler and TMSS
//
//  Copyright (C) 2020
//  ASTRON (Netherlands Foundation for Research in Astronomy)
//  P.O.Box 2, 7990 AA Dwingeloo, The Netherlands, softwaresupport@astron.nl
//
//  This program is free software; you can redistribute it and/or modify
//  it under the terms of the GNU General Public License as published by
//  the Free Software Foundation; either version 2 of the License, or
//  (at your option) any later version.
//
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
//
//  You should have received a copy of the GNU General Public License
//  along with this program; if not, write to the Free Software
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
//
//  $Id$
#include "TMSSBridge.h"


#include <boost/property_tree/json_parser.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <cstdlib>
#include <iostream>
#include <string>
namespace pt = boost::property_tree;
using namespace std;


namespace LOFAR {
	namespace MainCU {

//
// TMSSBridge Constructor
//
TMSSBridge::TMSSBridge():
	itsUser		  ("test"),
	itsPassword	  ("test"),
	itsHost		  ("http://127.0.0.1"), // just to start with maybe user and password need
	itsPort       (8000)
{

}


//
// TMSSBridge Destructor
//
TMSSBridge::~TMSSBridge()
{

}


//
// get all subTaskIDS that should run within three minutes (ordered in time if multiple are found)
// for given cluster
//
vector<int> TMSSBridge::getSubTaskIDStartingInThreeMinutes(ptime currentTime, string clusterName)
{
    string currentTimeStr = to_iso_extended_string(currentTime);
    string queryStr = "/api/?start_time__lt=" + currentTimeStr + "&cluster__name==" + clusterName;
    Json::Value result = httpGET(itsHost, itsPort, queryStr);
    vector<string> urlList = translateHttpResultToSortedUrlList(result);
//
// Translate the HTTP result to json format and parse the json format
//     How to handle json structure in C++?
//     Get the number of taskIDs like python
//     json_response = response.json()
//     json_response.get('count'))
//     ... and results[idx].items('url)
//     if multiple found sort on startTime !
vector<string> TMSSBridge::translateHttpResultToSortedUrlList(Json::Value jsonResult)
    // Read values
    int nbrSubTasksFound = jsonResult["count"].asInt();
    urlList.push_back("20000000000");
// Performs an HTTP GET and return the response body 
// Need to check respons status code of http (200) 
// Example:
//    httpGET("http://127.0.0.1", 8000, "/api/subtask/?start_time__lt=2020-03-04T12:03:00"
//    results in a json string output
//
Json::Value TMSSBridge::httpGET(const string& host, const int port, const string& target)
    // TODO Execute using curl stuff and endup with Json::Value  
    // Check for http result 200

    Json::Value jsonResult("dummy");

    return jsonResult;