How to use the qcfractal.web_handlers.APIHandler function in qcfractal

To help you get started, we’ve selected a few qcfractal examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github MolSSI / QCFractal / qcfractal / queue / handlers.py View on Github external
if (body.data.id is None) and (body.data.procedure_id is None):
            raise tornado.web.HTTPError(status_code=400, reason="Id or ProcedureId must be specified.")

        if body.meta.operation == "restart":
            updates = self.storage.update_service_status("running", **body.data.dict())
            data = {"n_updated": updates}
        else:
            raise tornado.web.HTTPError(status_code=400, reason=f"Operation '{operation}' is not valid.")

        response = response_model(data=data, meta={"errors": [], "success": True, "error_description": False})

        self.logger.info(f"PUT: TaskQueue - Operation: {body.meta.operation} - {updates}.")
        self.write(response)


class QueueManagerHandler(APIHandler):
    """
    Takes in a data packet the contains the molecule_hash, modelchem and options objects.
    Manages the external queue.
    """
    _required_auth = "queue"

    def _get_name_from_metadata(self, meta):
        """
        Form the canonical name string.
        """
        ret = meta.cluster + "-" + meta.hostname + "-" + meta.uuid
        return ret

    @staticmethod
    def insert_complete_tasks(storage_socket, results, logger):
        # Pivot data so that we group all results in categories
github MolSSI / QCFractal / qcfractal / web_handlers.py View on Github external
A handler that returns public server information.
    """

    _required_auth = "read"

    def get(self):
        """

        """

        self.logger.info("GET: Information")

        self.write(self.objects["public_information"])


class KVStoreHandler(APIHandler):
    """
    A handler to push and get molecules.
    """

    _required_auth = "read"
    _logging_param_counts = {"id"}

    def get(self):
        """

        Experimental documentation, need to find a decent format.

        Request:
            "data" - A list of key requests

        Returns:
github MolSSI / QCFractal / qcfractal / queue / handlers.py View on Github external
if (body.data.id is None) and (body.data.base_result is None):
            raise tornado.web.HTTPError(status_code=400, reason="Id or ResultId must be specified.")

        if body.meta.operation == "restart":
            tasks_updated = self.storage.queue_reset_status(**body.data.dict(), reset_error=True)
            data = {"n_updated": tasks_updated}
        else:
            raise tornado.web.HTTPError(status_code=400, reason=f"Operation '{operation}' is not valid.")

        response = response_model(data=data, meta={"errors": [], "success": True, "error_description": False})

        self.logger.info(f"PUT: TaskQueue - Operation: {body.meta.operation} - {tasks_updated}.")
        self.write(response)


class ServiceQueueHandler(APIHandler):
    """
    Takes in a data packet the contains the molecule_hash, modelchem and options objects.
    """

    _required_auth = "compute"

    def post(self):
        """Posts new services to the service queue.
        """

        body_model, response_model = rest_model("service_queue", "post")
        body = self.parse_bodymodel(body_model)

        new_services = []
        for service_input in body.data:
            # Get molecules with ids
github MolSSI / QCFractal / qcfractal / queue / handlers.py View on Github external
"""
Queue backend abstraction manager.
"""

import collections
import traceback

import tornado.web

from ..interface.models.rest_models import rest_model
from ..procedures import check_procedure_available, get_procedure_parser
from ..services import initialize_service
from ..web_handlers import APIHandler


class TaskQueueHandler(APIHandler):
    """
    Takes in a data packet the contains the molecule_hash, modelchem and options objects.
    """

    _required_auth = "compute"

    def post(self):
        """Posts new tasks to the task queue.
        """

        body_model, response_model = rest_model("task_queue", "post")
        body = self.parse_bodymodel(body_model)

        # Format and submit tasks
        if not check_procedure_available(body.meta.procedure):
            raise tornado.web.HTTPError(status_code=400, reason="Unknown procedure {}.".format(body.meta.procedure))
github MolSSI / QCFractal / qcfractal / queue / handlers.py View on Github external
def get(self):
        """Posts new services to the service queue.
        """

        body_model, response_model = rest_model("task_queue", "get")
        body = self.parse_bodymodel(body_model)

        tasks = self.storage.get_queue(**body.data.dict(), projection=body.meta.projection)
        response = response_model(**tasks)

        self.logger.info("GET: TaskQueue - {} pulls.".format(len(response.data)))
        self.write(response.json())


class ServiceQueueHandler(APIHandler):
    """
    Takes in a data packet the contains the molecule_hash, modelchem and options objects.
    """

    _required_auth = "compute"

    def post(self):
        """Posts new services to the service queue.
        """

        body_model, response_model = rest_model("service_queue", "post")
        body = self.parse_bodymodel(body_model)

        new_services = []
        for service_input in body.data:
            # Get molecules with ids
github MolSSI / QCFractal / qcfractal / web_handlers.py View on Github external
if collection_id is not None or view_function is not None:
            meta = add_metadata_template()
            meta["success"] = False
            meta["error_description"] = "POST requests not supported for sub-resources of /collection"
            self.write(response_model(meta=meta, data=None))
            self.logger.info("POST: Collections - Access attempted on subresource.")
            return

        ret = self.storage.add_collection(body.data.dict(), overwrite=body.meta.overwrite)
        response = response_model(**ret)

        self.logger.info("POST: Collections - {} inserted.".format(response.meta.n_inserted))
        self.write(response)


class ResultHandler(APIHandler):
    """
    A handler to push and get molecules.
    """

    _required_auth = "read"
    _logging_param_counts = {"id", "molecule"}

    def get(self):

        body_model, response_model = rest_model("result", "get")
        body = self.parse_bodymodel(body_model)

        ret = self.storage.get_results(**{**body.data.dict(), **body.meta.dict()})
        result = response_model(**ret)

        self.logger.info("GET: Results - {} pulls.".format(len(result.data)))
github MolSSI / QCFractal / qcfractal / web_handlers.py View on Github external
def parse_bodymodel(self, model):

        try:
            return model(**self.data)
        except ValidationError as exc:
            raise tornado.web.HTTPError(status_code=401, reason="Invalid REST")

    def write(self, data):
        if not isinstance(data, (str, bytes)):
            data = serialize(data, self.encoding)

        return super().write(data)


class InformationHandler(APIHandler):
    """
    A handler that returns public server information.
    """

    _required_auth = "read"

    def get(self):
        """

        """

        self.logger.info("GET: Information")

        self.write(self.objects["public_information"])
github MolSSI / QCFractal / qcfractal / web_handlers.py View on Github external
if collection_id is not None or view_function is not None:
            meta = add_metadata_template()
            meta["success"] = False
            meta["error_description"] = "POST requests not supported for sub-resources of /collection"
            self.write(response_model(meta=meta, data=None))
            self.logger.info("POST: Collections - Access attempted on subresource.")
            return

        ret = self.storage.add_collection(body.data.dict(), overwrite=body.meta.overwrite)
        response = response_model(**ret)

        self.logger.info("POST: Collections - {} inserted.".format(response.meta.n_inserted))
        self.write(response)


class ResultHandler(APIHandler):
    """
    A handler to push and get molecules.
    """

    _required_auth = "read"
    _logging_param_counts = {"id", "molecule"}

    def get(self):

        body_model, response_model = rest_model("result", "get")
        body = self.parse_bodymodel(body_model)

        ret = self.storage.get_results(**{**body.data.dict(), **body.meta.dict()})
        result = response_model(**ret)

        self.logger.info("GET: Results - {} pulls.".format(len(result.data)))
github MolSSI / QCFractal / qcfractal / web_handlers.py View on Github external
"data" - A dictionary of {key : id} results
        """

        self.authenticate("write")

        body_model, response_model = rest_model("molecule", "post")
        body = self.parse_bodymodel(body_model)

        ret = self.storage.add_molecules(body.data)
        response = response_model(**ret)

        self.logger.info("POST: Molecule - {} inserted.".format(response.meta.n_inserted))
        self.write(response)


class KeywordHandler(APIHandler):
    """
    A handler to push and get molecules.
    """

    _required_auth = "read"
    _logging_param_counts = {"id"}

    def get(self):

        body_model, response_model = rest_model("keyword", "get")
        body = self.parse_bodymodel(body_model)

        ret = self.storage.get_keywords(**{**body.data.dict(), **body.meta.dict()}, with_ids=False)
        response = response_model(**ret)

        self.logger.info("GET: Keywords - {} pulls.".format(len(response.data)))
github MolSSI / QCFractal / qcfractal / web_handlers.py View on Github external
"data" - A dictionary of {key : id} results
        """

        self.authenticate("write")

        body_model, response_model = rest_model("molecule", "post")
        body = self.parse_bodymodel(body_model)

        ret = self.storage.add_molecules(body.data)
        response = response_model(**ret)

        self.logger.info("POST: Molecule - {} inserted.".format(response.meta.n_inserted))
        self.write(response)


class KeywordHandler(APIHandler):
    """
    A handler to push and get molecules.
    """

    _required_auth = "read"
    _logging_param_counts = {"id"}

    def get(self):

        body_model, response_model = rest_model("keyword", "get")
        body = self.parse_bodymodel(body_model)

        ret = self.storage.get_keywords(**{**body.data.dict(), **body.meta.dict()}, with_ids=False)
        response = response_model(**ret)

        self.logger.info("GET: Keywords - {} pulls.".format(len(response.data)))