Ejemplo n.º 1
0
 def _send_request(self, msgop, target, specifier=None, payload=None, timeout=None, lockout_key=False):
     '''
     internal helper method to standardize sending request messages
     '''
     a_specifier = specifier if specifier is not None else ""
     a_request = MsgRequest.create(payload=scarab.to_param(payload), msg_op=msgop, routing_key=target, specifier=a_specifier)
     receive_reply = self.send(a_request)
     if not receive_reply.successful_send:
         raise DriplineError('unable to send request')
     return receive_reply
Ejemplo n.º 2
0
 def __init__(self, dripline_config={}, confirm_retcodes=True):
     '''
     dripline_config (dict): passed to dripline.core.Core to configure connection details
     confirm_retcodes (bool): if True and if a reply is received with retcode!=0, raise an exception
     '''
     default_config = DriplineConfig().to_python()
     default_config.update(dripline_config)
     Core.__init__(self, config=scarab.to_param(default_config))
     self._confirm_retcode = confirm_retcodes
     self._receiver = Receiver()
Ejemplo n.º 3
0
 def do_cmd_request(self, a_request_message):
     # Note: any command executed in this way must return a python data structure which is
     #       able to be converted to a Param object (to be returned in the reply message)
     method_name = a_request_message.specifier.to_string()
     try:
         method_ref = getattr(self, method_name)
     except AttributeError as e:
         raise ThrowReply('service_error_invalid_method', "error getting command's corresponding method: {}".format(str(e)))
     the_kwargs = a_request_message.payload.to_python()
     the_args = the_kwargs.pop('values', [])
     result = method_ref(*the_args, **the_kwargs)
     return a_request_message.reply(payload=scarab.to_param(result))
Ejemplo n.º 4
0
 def do_set_request(self, a_request_message):
     a_specifier =  a_request_message.specifier.to_string()
     if not "values" in a_request_message.payload:
         raise ThrowReply('service_error_bad_payload', 'setting called without values, but values are required for set')
     new_value = a_request_message.payload["values"][0]()
     new_value = getattr(new_value, "as_"+new_value.type())()
     logger.debug(f'new_value is [{new_value}]')
     if ( a_specifier ):
         if not hasattr(self, a_specifier):
             raise ThrowReply('service_error_invalid_specifier', "endpoint {} has no attribute {}, unable to set".format(self.name, a_specifier))
         setattr(self, a_specifier, new_value)
         return a_request_message.reply()
     else:
         result = self.on_set(new_value)
         return a_request_message.reply(payload=scarab.to_param(result))
Ejemplo n.º 5
0
 def do_get_request(self, a_request_message):
     logger.info("in get_request")
     a_specifier =  a_request_message.specifier.to_string()
     if (a_specifier):
         logger.debug("has specifier")
         try:
             logger.debug(f"specifier is: {a_specifier}")
             an_attribute = getattr(self, a_specifier)
             logger.debug(f"attribute '{a_specifier}' value is [{an_attribute}]")
             the_node = scarab.ParamNode()
             the_node["values"] = scarab.ParamArray()
             the_node["values"].push_back(scarab.ParamValue(an_attribute))
             return a_request_message.reply(payload=the_node)
         except AttributeError as this_error:
             raise ThrowReply('service_error_invalid_specifier', f"endpoint {self.name} has no attribute {a_specifier}, unable to get")
     else:
         logger.debug('no specifier')
         the_value = self.on_get()
         return a_request_message.reply(payload=scarab.to_param(the_value))
Ejemplo n.º 6
0
 def log_a_value(self, the_value):
     logger.debug(f"value to log is:\n{the_value}")
     the_alert = MsgAlert.create(payload=scarab.to_param(the_value), routing_key=f'{self.log_routing_key_prefix}.{self.name}')
     alert_sent = self.service.send(the_alert)