diff --git a/.gitattributes b/.gitattributes index 84333b9d01e642fcf3a0c094bdb8d143e52dbf4d..d774ca5b7db852942edb127c41229c7c9c4abbe1 100644 --- a/.gitattributes +++ b/.gitattributes @@ -2831,10 +2831,14 @@ LTA/ltastorageoverview/bin/ltastorageoverviewscraper -text LTA/ltastorageoverview/lib/CMakeLists.txt -text LTA/ltastorageoverview/lib/scraper.py -text LTA/ltastorageoverview/lib/store.py -text +LTA/ltastorageoverview/lib/webservice/webservice.py -text LTA/ltastorageoverview/test/CMakeLists.txt -text LTA/ltastorageoverview/test/test_store.py -text LTA/ltastorageoverview/test/test_store.run -text LTA/ltastorageoverview/test/test_store.sh -text +LTA/ltastorageoverview/test/test_webservice.py -text +LTA/ltastorageoverview/test/test_webservice.run -text +LTA/ltastorageoverview/test/test_webservice.sh -text MAC/APL/APLCommon/include/APL/APLCommon/AntennaField.h -text MAC/APL/APLCommon/src/AntennaField.cc -text MAC/APL/APLCommon/src/StartDaemon_Protocol.prot -text svneol=native#application/octet-stream diff --git a/.gitignore b/.gitignore index 1b49be898dcab6ea5c79243fe30e3feea59a2b22..17b93f3edc7ed285c893360f3b83df88d82a8091 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +/.kdev4 CEP/Calibration/BBSControl/Makefile.common CEP/Calibration/BBSControl/autoconf_share CEP/Calibration/BBSControl/lofarconf @@ -255,3 +256,5 @@ SAS/OTB/nbproject SAS/OTDB/Makefile.common SAS/OTDB/autoconf_share SAS/OTDB/lofarconf +/build +/wcblofar.kdev4 diff --git a/LTA/ltastorageoverview/lib/CMakeLists.txt b/LTA/ltastorageoverview/lib/CMakeLists.txt index d53e36ed74fca0c98d55131bd7815401cbbfcfb4..9c40bde523c2bc76fb896cbf1162caf669c4e28c 100644 --- a/LTA/ltastorageoverview/lib/CMakeLists.txt +++ b/LTA/ltastorageoverview/lib/CMakeLists.txt @@ -3,5 +3,6 @@ python_install( scraper.py store.py + webservice/webservice.py DESTINATION ltastorageoverview) diff --git a/LTA/ltastorageoverview/lib/webservice/webservice.py b/LTA/ltastorageoverview/lib/webservice/webservice.py new file mode 100755 index 0000000000000000000000000000000000000000..e7bdf8a1963001b42518f1eab8d1e7c518fbcdda --- /dev/null +++ b/LTA/ltastorageoverview/lib/webservice/webservice.py @@ -0,0 +1,59 @@ +#!/usr/bin/python + +# Copyright (C) 2012-2015 ASTRON (Netherlands Institute for Radio Astronomy) +# P.O. Box 2, 7990 AA Dwingeloo, The Netherlands +# +# This file is part of the LOFAR software suite. +# The LOFAR software suite 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 3 of the License, or +# (at your option) any later version. +# +# The LOFAR software suite 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 the LOFAR software suite. If not, see <http://www.gnu.org/licenses/>. + +import sys +import os +import os.path +import flask +import threading +from ltastorageoverview import store + +app = flask.Flask('LTA storage overview') +db = None + +def run(): + app.run() + +def runThreaded(): + serviceThread = threading.Thread(target=run) + serviceThread.daemon = True + serviceThread.start() + +@app.route('/') +def hello_world(): + return 'Hello World!' + +@app.route('/json/sites/') +def get_sites(): + sites = {'sites' : [ {'id':x[0], 'name':x[1], 'url':x[2] } for x in db.sites()]} + return flask.json.jsonify(sites) + +@app.route('/json/sites/<int:site_id>') +def get_site(site_id): + site = db.site.site(site_id) + site_dict = {'id':site[0], 'name':site[1], 'url':site[2] } + return flask.json.jsonify(site_dict) + +def main(argv): + db = store.LTAStorageDb(argv[0] if argv else 'ltastoragedb.sqlite') + run() + +if __name__ == '__main__': + main(sys.argv[1:]) + diff --git a/LTA/ltastorageoverview/test/CMakeLists.txt b/LTA/ltastorageoverview/test/CMakeLists.txt index 8c467bac7bf35222bc91bf0864f7ec3d9d72a0c1..15d0e1bbd18d8bfa24be4c93504b9b0939a89b78 100644 --- a/LTA/ltastorageoverview/test/CMakeLists.txt +++ b/LTA/ltastorageoverview/test/CMakeLists.txt @@ -2,8 +2,10 @@ include(LofarCTest) lofar_add_test(test_store) +lofar_add_test(test_webservice) python_install( test_store.py + test_webservice.py DESTINATION ltastorageoverview/test) diff --git a/LTA/ltastorageoverview/test/test_webservice.py b/LTA/ltastorageoverview/test/test_webservice.py new file mode 100755 index 0000000000000000000000000000000000000000..31d1ab29208c50db7bb4a6847d258f360525d57c --- /dev/null +++ b/LTA/ltastorageoverview/test/test_webservice.py @@ -0,0 +1,49 @@ +#!/usr/bin/env python + +import unittest +import os +import time +import os.path +import tempfile +import urllib2 +import json +from StringIO import StringIO +from flask.ext.testing import LiveServerTestCase as FlaskLiveTestCase +from ltastorageoverview import store +import ltastorageoverview.webservice.webservice as webservice + +def setUpModule(): + tmpfile = os.path.join(tempfile.gettempdir(), 'test.sqlite') + webservice.db = store.LTAStorageDb(tmpfile) + + webservice.db.insertSite('siteA', 'srm://siteA.org') + webservice.db.insertSite('siteB', 'srm://siteB.org') + +def tearDownModule(): + if os.path.exists(webservice.db.db_filename): + os.remove(webservice.db.db_filename) + +class TestLTAStorageWebService(FlaskLiveTestCase): + def create_app(self): + return webservice.app + + def testSites(self): + response = urllib2.urlopen('http://localhost:5000/json/sites/') + self.assertEqual(200, response.code) + self.assertEqual('application/json', response.info()['Content-Type']) + + content = json.load(StringIO(response.read())) + + self.assertTrue('sites' in content) + sites = content['sites'] + + sitesDict = dict([(x['name'], x) for x in sites]) + self.assertTrue('siteA' in sitesDict) + self.assertEqual('srm://siteA.org', sitesDict['siteA']['url']) + self.assertTrue('siteB' in sitesDict) + self.assertEqual('srm://siteB.org', sitesDict['siteB']['url']) + + +# run tests if main +if __name__ == '__main__': + unittest.main(verbosity=2) diff --git a/LTA/ltastorageoverview/test/test_webservice.run b/LTA/ltastorageoverview/test/test_webservice.run new file mode 100755 index 0000000000000000000000000000000000000000..ac230e9d6ba2bec53ffc6814eef96d8efe3b02a2 --- /dev/null +++ b/LTA/ltastorageoverview/test/test_webservice.run @@ -0,0 +1,3 @@ +#!/bin/bash + +python test_webservice.py diff --git a/LTA/ltastorageoverview/test/test_webservice.sh b/LTA/ltastorageoverview/test/test_webservice.sh new file mode 100755 index 0000000000000000000000000000000000000000..7e3cc422b7d5ff90b62bc02a2dbcfef3e2c76ee3 --- /dev/null +++ b/LTA/ltastorageoverview/test/test_webservice.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +./runctest.sh test_webservice