示例#1
0
    def on_put(self, req, resp, hostname, validated_body):
        """
        updates a worker's status or creates a new worker entry if not found
        """

        # load validated json payload in body
        body = validated_body["worker_status"]

        # find the worker in db
        worker = worker_util.find_worker(hostname)

        if worker is None:
            # instantiate new worker object
            new_worker = Worker(**body)
            # persist the new worker
            worker_util.create_worker(new_worker)
            resp.status = falcon.HTTP_202
            return

        if "status" in body:
            worker.status = body["status"]

        if "system_info" in body:
            worker.system_info = SystemInfo(**body["system_info"])

        worker_util.save_worker(worker)
        resp.status = falcon.HTTP_200
示例#2
0
    def on_put(self, req, resp, hostname, validated_body):
        """
        updates a worker's status or creates a new worker entry if not found
        """

        #load validated json payload in body
        body = validated_body['worker_status']

        #find the worker in db
        worker = worker_util.find_worker(hostname)

        if worker is None:
            #instantiate new worker object
            new_worker = Worker(**body)
            #persist the new worker
            worker_util.create_worker(new_worker)
            resp.status = falcon.HTTP_202
            return

        if 'status' in body:
            worker.status = body['status']

        if 'system_info' in body:
            worker.system_info = SystemInfo(**body['system_info'])

        worker_util.save_worker(worker)
        resp.status = falcon.HTTP_200
示例#3
0
 def test_find_worker_returns_none(self):
     find_one_method = MagicMock(return_value=None)
     with patch('meniscus.data.model.worker_util._db_handler.find_one',
                find_one_method):
         worker = worker_util.find_worker(self.worker.hostname)
         find_one_method.assert_called_once_with(
             'worker', {'hostname': self.worker.hostname})
         self.assertIsNone(worker)
示例#4
0
 def test_find_worker_returns_none(self):
     find_one_method = MagicMock(return_value=None)
     with patch('meniscus.data.model.worker_util._db_handler.find_one',
                find_one_method):
         worker = worker_util.find_worker(self.worker.hostname)
         find_one_method.assert_called_once_with(
             'worker', {'hostname': self.worker.hostname})
         self.assertIsNone(worker)
示例#5
0
    def on_get(self, req, resp, hostname):
        """
        Retrieve the status of a specified worker node
        """
        #find the worker in db
        worker = worker_util.find_worker(hostname)

        if worker is None:
            api.abort(falcon.HTTP_404, 'Unable to locate worker.')

        resp.status = falcon.HTTP_200
        resp.body = api.format_response_body({'status': worker.get_status()})
示例#6
0
    def on_get(self, req, resp, hostname):
        """
        Retrieve the status of a specified worker node
        """
        # find the worker in db
        worker = worker_util.find_worker(hostname)

        if worker is None:
            api.abort(falcon.HTTP_404, "Unable to locate worker.")

        resp.status = falcon.HTTP_200
        resp.body = api.format_response_body({"status": worker.get_status()})
示例#7
0
    def on_get(self, req, resp, worker_id):
        """
        Retrieve the status of a specified worker node
        """
        #find the worker in db
        worker = worker_util.find_worker(worker_id)

        if worker is None:
            _worker_not_found()

        resp.status = falcon.HTTP_200
        resp.body = api.format_response_body({'status': worker.get_status()})
示例#8
0
    def on_put(self, req, resp, worker_id, validated_body):
        """
        updates a worker's status
        """

        #load validated json payload in body
        body = validated_body['worker_status']

        #find the worker in db
        worker = worker_util.find_worker(worker_id)

        if worker is None:
            _worker_not_found()

        if 'status' in body:
            worker.status = body['status']

        if 'system_info' in body:
            worker.system_info = SystemInfo(**body['system_info'])

        worker_util.save_worker(worker)
        resp.status = falcon.HTTP_200