コード例 #1
0
import flask_praetorian
from flask_restful import Resource
from xenon_runsDB_api.app import guard, app, api, mongo
from marshmallow import Schema, fields
from webargs.flaskparser import use_kwargs, use_args


class Root(Resource):
    def get(self):
        return {
            'status': 'OK',
            'mongo': str(mongo.db),
        }


api.add_resource(Root, '/')


class SiteMap(Resource):
    def get(self):
        return flask.jsonify(
            {"routes": ['%s' % rule for rule in app.url_map.iter_rules()]})


api.add_resource(SiteMap, '/sitemap')

user_args = {
    "username": fields.String(required=True),
    "password": fields.String(required=True)
}
コード例 #2
0
ファイル: gains.py プロジェクト: rynge/xenon_runsDB_api
    """
    Inherited class from run that provides interface when using timestamp
    """
    def get(self, timestamp):
        return self._get_("timestamp", timestamp)

    # Decorater passes the "gains" object that was parsed out of the json
    # piece of the PUT request to the kwarg of the function
    @use_kwargs(gain_args, locations=["json"])
    def put(self, timestamp, gains):
        return self._put_("name", timestamp, gains)


# Adding routes according what identifier is used.
api.add_resource(RunObjectIDGains,
                 '/run/objectid/<ObjectId:object_id>/gains/',
                 endpoint="run_object_id_gains")
api.add_resource(RunRunIDGains,
                 '/run/runnumber/<int:run_number>/gains/',
                 endpoint="run_run_id_gains")
api.add_resource(RunRunIDGains,
                 '/run/number/<int:run_number>/gains/',
                 endpoint="run_run_number_gains")
api.add_resource(RunTimestampGains,
                 '/run/timestamp/<string:timestamp>/gains/',
                 endpoint="run_timestamp_gains")
api.add_resource(RunTimestampGains,
                 '/run/name/<string:timestamp>/gains/',
                 endpoint="run_timestamp_name_gains")
# Including the path for runs. Just in case we change our
# mind down the road
コード例 #3
0
ファイル: status.py プロジェクト: rynge/xenon_runsDB_api

class RunsStatusPAXVersion(Resource):
    @flask_praetorian.roles_required('user')
    def get(self, status, pax_version, data_field=None):
        app.logger.debug(('Requesting all runs with status: %s and '
                          'PAX version: %s'),
                         (status, pax_version))
        if status == "processing":
            query = {"$elemMatch": {"type": "processed",
                                    "status": "processing",
                                    "pax_version": pax_version}}
        elif status == "processed":
            query = {"$elemMatch": {"type": "processed",
                                    "status": "processed",
                                    "pax_version": pax_version}}
        results = util.get_data_single_top_level(query, data_field)
        app.logger.debug("results: %s" % results)
        if results:
            return results
        else:
            return flask.abort(404,
                               ("No run with status {} and PAX version {} "
                                "found").format(status, pax_version))


api.add_resource(RunsStatusInfo, '/runs/status')
api.add_resource(RunsStatus, '/runs/status/<string:status>')
api.add_resource(RunsStatusPAXVersion, ('/runs/status/<string:status>/'
                                        'pax_version/<string:pax_version>/'
                                         '<string:data_field>'))
コード例 #4
0
class RunTimestampData(RunData):
    def get(self, timestamp, data_type=None):
        result = self._get_("name", timestamp, data_type)
        return flask.jsonify({"results": result})

    @use_kwargs(data_args, locations=["json"])
    def post(self, timestamp, **data):
        return self._post_data_("name", timestamp, data)

    @use_kwargs(data_args, locations=["json"])
    def delete(self, timestamp, **data):
        return self._delete_("name", timestamp, data)


api.add_resource(RunObjectIDData,
                 '/run/objectid/<ObjectId:object_id>/data/',
                 endpoint="run_object_id_data_no_type")
api.add_resource(RunObjectIDData,
                 '/run/objectid/<ObjectId:object_id>/data/<string:data_type>/',
                 endpoint="run_object_id_data",
                 methods=['GET'])

api.add_resource(RunObjectIDData,
                 '/runs/objectid/<ObjectId:object_id>/data/',
                 endpoint="runs_object_id_data_no_type")
api.add_resource(
    RunObjectIDData,
    '/runs/objectid/<ObjectId:object_id>/data/<string:data_type>/',
    endpoint="runs_object_id_data",
    methods=['GET'])
コード例 #5
0
ファイル: location.py プロジェクト: rynge/xenon_runsDB_api
import flask
import flask_praetorian
from flask_restful import Resource
from xenon_runsDB_api.common import util
from xenon_runsDB_api.app import app, api


class RunsLocationList(Resource):
    @flask_praetorian.roles_required('user')
    def get(self, location, data_field=None):
        query = {
            "data": {
                "$elemMatch": {
                    "host": "rucio-catalogue",
                    "rse": location
                }
            }
        }
        results = util.get_data_single_top_level(query)
        if results:
            return flask.jsonify({"results": results})
        else:
            return flask.abort(
                404, "No run with location {} found".format(location))


api.add_resource(RunsLocationList, '/runs/location/<string:location>/',
                 '/runs/location/<string:location>/<string:data_field>')
コード例 #6
0
import flask
import flask_praetorian
from flask_restful import Resource
from xenon_runsDB_api.common import util
from xenon_runsDB_api.app import app, api


class RunsTag(Resource):
    @flask_praetorian.roles_required('user')
    def get(self, tag, data_field=None):
        app.logger.debug("Getting all runs with tag %s" % tag)
        query = {"tags.name": tag}
        results = util.get_data_single_top_level(query, data_field)
        if results:
            return flask.jsonify({"results": results})
        else:
            return flask.abort(404, "No run with tag {} found".format(tag))


api.add_resource(RunsTag, '/runs/tag/<string:tag>/',
                 '/runs/tag/<string:tag>/<string:data_field>')
コード例 #7
0
ファイル: detector.py プロジェクト: rynge/xenon_runsDB_api
import flask_praetorian
from flask_restful import Resource
from xenon_runsDB_api.app import app, api, mongo


class RunsDetector(Resource):
    @flask_praetorian.roles_required('user')
    def get(self, detector, data_field=None):
        app.logger.debug('Requesting all runs with detector: %s', detector)
        query = {'detector': detector}
        results = util.get_data_single_top_level(query, data_field)
        if results:
            return flask.jsonify({"results": results})
        else:
            return flask.abort(404, "No run with tag {} found".format(tag))


api.add_resource(RunsDetector, '/runs/detector/<string:detector>/',
                 '/runs/detector/<string:detector>/<string:data_field>')
コード例 #8
0
    def put(self, run_number, status):
        app.logger.debug("Requesting data for run with run number %s" %
                         run_number)
        result = mongo.db["runs_new"].find_one_or_404({"number": run_number})


class RunStatusTimestamp(Resource):
    def put(self, timestamp, status):
        app.logger.debug("Requesting data for run with timestamp %s",
                         timestamp)
        result = mongo.db["runs_new"].find_one_or_404({"name": timestamp})


# Adding routes according what identifier is used.
api.add_resource(RunObjectID,
                 '/run/objectid/<ObjectId:object_id>/<string:status>',
                 endpoint="run_object_id_status")
api.add_resource(RunRunNumber,
                 '/run/runnumber/<int:run_number>/<string:status>',
                 endpoint="run_run_id_status")
api.add_resource(RunRunNumber,
                 '/run/number/<int:run_number>/<string:status>',
                 endpoint="run_run_number_status")
api.add_resource(RunTimestamp,
                 '/run/timestamp/<string:timestamp>/<string:status>',
                 endpoint="run_timestamp_status")
api.add_resource(RunTimestamp,
                 '/runs/name/<string:timestamp>/<string:status>',
                 endpoint="run_timestamp_name_status")
# Including the path for runs. Just in case we change our
# mind down the road
コード例 #9
0
ファイル: run.py プロジェクト: rynge/xenon_runsDB_api
            top_level=None,
            second_level=None,
            third_level=None):
        return self._get_("name", timestamp, top_level, second_level,
                          third_level)

    def delete(self, timestamp):
        return self._delete_("name", timestamp)


# Adding routes according what identifier is used.
api.add_resource(
    RunObjectID,
    '/run/objectid/<ObjectId:object_id>/',
    '/run/objectid/<ObjectId:object_id>/filter/<string:top_level>',
    ('/run/objectid/<ObjectId:object_id>/filter/'
     '<string:top_level>/<string:second_level>/'),
    ('/run/objectid/<ObjectId:object_id>/filter/'
     '<string:top_level>/<string:second_level>/'
     '<string:third_level>'),
    endpoint="run_object_id")
api.add_resource(RunRunNumber,
                 '/run/runnumber/<int:run_number>/',
                 '/run/runnumber/<int:run_number>/filter/<string:top_level>',
                 ('/run/runnumber/<int:run_number>/filter/'
                  '<string:top_level>/<string:second_level>/'),
                 ('/run/runnumber/<int:run_number>/filter/'
                  '<string:top_level>/<string:second_level>/'
                  '<string:third_level>'),
                 endpoint="run_run_number")
api.add_resource(RunRunNumber,
                 '/run/number/<int:run_number>/',
コード例 #10
0
ファイル: source.py プロジェクト: rynge/xenon_runsDB_api
import flask
import flask_praetorian
from flask_restful import Resource
from xenon_runsDB_api.common import util
from xenon_runsDB_api.app import app, api, mongo


class RunsSource(Resource):
    @flask_praetorian.roles_required('user')
    def get(self, source, data_field=None):
        app.logger.debug('Requesting all runs with source: %s', source)
        if source == "calibration":
            query = {"source.type": {"$not": {"$eq": "none"}}}
        else:
            query = {"source.type": source}
        app.logger.debug("query: {}".format(query))
        results = util.get_data_single_top_level(query, data_field)
        app.logger.debug("results: %s" % results)
        if results:
            return flask.jsonify({"results": results})
        else:
            return flask.abort(404,
                               "No run with source {} found".format(source))


api.add_resource(RunsSource, '/runs/source/<string:source>/',
                 '/runs/source/<string:source>/<string:data_field>/')
コード例 #11
0
import flask_praetorian
from flask_restful import Resource
from xenon_runsDB_api.common import util
from xenon_runsDB_api.app import app, api, mongo


class RunsProcessingVersion(Resource):
    @flask_praetorian.roles_required('user')
    def get(self, version):
        app.logger.debug('Requesting all runs with status: %s', status)
        if not version.startswith('v'):
            version = "v" + version
        query = {
            "data": {
                "$elemMatch": {
                    "type": "processed",
                    "status": "transferred",
                    "pax_version": version
                }
            }
        }
        results = util.get_data_single_top_level(query, "data")
        app.logger.debug("results: %s" % results)
        if results:
            return results
        else:
            return flask.abort(404)


api.add_resource(RunsProcessingVersion,
                 '/runs/process_version/<string:version>')
コード例 #12
0
ファイル: query.py プロジェクト: rynge/xenon_runsDB_api
import flask
import flask_praetorian
from flask_restful import Resource
from webargs import fields
from webargs.flaskparser import use_args
from xenon_runsDB_api.app import app, api, mongo, config

user_args = {'query': fields.Dict()}


class RunsQuery(Resource):
    def __init__(self):
        self.mongodb = mongo.db[config["runsDB"]["database_name"]]

    @use_args(user_args)
    def post(self, args, locations=["json"]):
        # args = request.args
        app.logger.debug("args passed to query: %s" % args)
        query = args["query"]
        cursor = self.mongodb.find(query)
        results = [x for x in cursor]
        app.logger.debug("results: %s" % results)
        return flask.jsonify({"results": results})


api.add_resource(RunsQuery, '/runs/query', endpoint="runs_query")
コード例 #13
0
ファイル: rucio.py プロジェクト: rynge/xenon_runsDB_api

class RunRunNumberRucio(RunRucio):
    def get(self, run_number, data_type=None):
        result = self._get_("number", run_number, data_type)
        return flask.jsonify({"results": result})


class RunTimestampRucio(RunRucio):
    def get(self, timestamp, data_type=None):
        result = self._get_("name", timestamp, data_type)
        return flask.jsonify({"results": result})


api.add_resource(RunObjectIDRucio,
                 '/run/objectid/<ObjectId:object_id>/data/dids/',
                 endpoint="run_did_object_id_data_no_type")
api.add_resource(RunObjectIDRucio, ('/run/objectid/<ObjectId:object_id>'
                                    '/data/dids/<string:data_type>/'),
                 endpoint="run_did_object_id_data",
                 methods=['GET'])

api.add_resource(RunObjectIDRucio,
                 '/runs/objectid/<ObjectId:object_id>/data/dids/',
                 endpoint="runs_did_object_id_data_no_type")
api.add_resource(RunObjectIDRucio, ('/runs/objectid/<ObjectId:object_id>'
                                    '/data/dids/<string:data_type>/'),
                 endpoint="runs_did_object_id_data",
                 methods=['GET'])

api.add_resource(RunRunNumberRucio,
コード例 #14
0
ファイル: list.py プロジェクト: rynge/xenon_runsDB_api
import flask
import flask_praetorian
from flask_restful import Resource
from xenon_runsDB_api.common import util
from xenon_runsDB_api.app import app, api, mongo


class RunsList(Resource):
    @flask_praetorian.roles_required('user')
    def get(self, data_field=None):
        app.logger.debug("Getting ALL runs")
        results = util.get_data_single_top_level({}, data_field)
        if results:
            return flask.jsonify({"results": results})
        else:
            return flask.abort(404, "No runs found. Check the database!")


api.add_resource(RunsList, '/runs/', '/runs/<string:data_field>')