Пример #1
0
    async def handle_message(
            self,
            msg: core_pb2.CoreLocation) -> DataWrapper[core_pb2.Response]:
        response = DataWrapper(False, "location", core_pb2.Response())
        update = dap_update_pb2.DapUpdate()
        try:
            upd = update.update.add()
            upd.tablename = self._db_structure["table"]
            upd.fieldname = self._db_structure["field"]
            upd.key.core = msg.core_key
            upd.value.type = 9
            upd.value.l.CopyFrom(msg.location)
        except Exception as e:
            msg = "Failed to create dap_update proto from director location update: ", str(
                e)
            self.warning(msg)
            response.error_code = 500
            response.add_narrative(msg)

        try:
            status = self._dap_manager.update(update)
            response.success = status
        except Exception as e:
            msg = "DapManager: failed update: " + str(e)
            response.add_narrative(msg)
            self.warning(msg)

        return response
Пример #2
0
def process_update(self, msg) -> DataWrapper[response_pb2.UpdateResponse]:
    global _count_success, _count_request, _count_exception, _count_fails
    _count_request.inc()
    response = DataWrapper(False, "update", response_pb2.UpdateResponse())
    try:
        upd = self.proto_wrapper.get_instance(msg)
        status = self.dap_manager.update(upd.toDapUpdate())
        response.success = status
        if status:
            response.data.status = ResponseType.Value("SUCCESS")
            _count_success.inc()
        else:
            response.data.status = ResponseType.Value("ERROR")
            _count_fails.inc()
    except InvalidAttribute as e:
        msg = "Got invalid attribute: " + str(e)
        response.data.status = ResponseType.Value("INVALID_ATTRIBUTE")
        response.data.message = msg
        self.log.info(msg)
        _count_exception.inc()
    except MissingAddress as e:
        response.data.status = ResponseType.Value("MISSING_ADDRESS")
        msg = str(e)
        response.data.message = msg
        self.log.info(msg)
        _count_exception.inc()
    except Exception as e:
        msg = "Failed to update data, because: " + str(e)
        response.data.status = ResponseType.Value("ERROR")
        response.data.message = msg
        self.exception(e)
        _count_exception.inc()
    return response
Пример #3
0
 async def handle_message(self, msg: node_pb2.PeerUpdate) -> DataWrapper[core_pb2.Response]:
     response = DataWrapper(True, "peer", core_pb2.Response())
     try:
         self.info("ADD PEERS: ", msg)
         for peer in msg.add_peers:
             self._manager.add_peer(peer.name, peer.host, peer.port)
     except Exception as e:
         self.exception(e)
         response.success = False
     return response
 async def handle_message(
     self, msg: info_pb2.NodeInfoRequest
 ) -> DataWrapper[info_pb2.NodeInfoResponse]:
     response = DataWrapper(True, "info", info_pb2.NodeInfoResponse())
     try:
         self.info("GOT INFO request! ")
         response.data.search_key = self._node_config["search_key"]
         response.data.core_key = self._node_config["core_key"]
         response.data.host = self._node_config["host"]
         response.data.core_port = self._node_config["core_port"]
         response.data.search_port = self._node_config["search_port"]
     except Exception as e:
         self.exception(e)
         response.success = False
     return response
Пример #5
0
 async def handle_message(self, msg: Any) -> DataWrapper[Any]:
     response = DataWrapper(False, "", None)
     try:
         if isinstance(msg, dap_interface_pb2.NoInputParameter):
             proto = self._dap_call()
         else:
             proto = self._dap_call(msg)
         response.success = True
         response.data = proto
     except Exception as e:
         error = dap_interface_pb2.Successfulness()
         error.success = False
         error.errorcode = 503
         error.narrative.append(str(e))
         self.exception("Exception during DAP call: ", e)
         response.error_code = 503
         response.add_narrative(str(e))
         response.data = error
     return response