Example #1
0
 def wapper():
     eventlet.sleep(random.randint(0, 5))
     # save report log
     session = get_session()
     report = AgentReportLog(**snapshot)
     session.add(report)
     session.flush()
     session.close()
     process = snapshot.get('running') + snapshot.get('sleeping')
     free = snapshot.get('free') + snapshot.get('cached')
     conns = snapshot.get('syn') + snapshot.get('enable')
     cputime = snapshot.get('iowait') + snapshot.get('user') \
               + snapshot.get('system') + snapshot.get('nice')\
               + snapshot.get('irq') + snapshot.get('sirq')
     rpc = get_client()
     # send to rpc server
     rpc.cast(targetutils.target_rpcserver(fanout=True),
              ctxt = {},
              msg={'method': 'changesource',
                   'args': {'agent_id': agent_id,
                            'free':  free,
                            'process': process,
                            'cputime': cputime,
                            'iowait': snapshot.get('iowait'),
                            'left': snapshot.get('left'),
                            'fds': snapshot.get('num_fds'),
                            'conns': conns,
                            'metadata': metadata,
                            }})
Example #2
0
 def send_asyncrequest(asyncrequest,
                       rpc_target,
                       rpc_ctxt,
                       rpc_method,
                       rpc_args=None,
                       async_ctxt=None):
     rpc = get_client()
     session = get_session()
     try:
         rpc.cast(
             targetutils.target_rpcserver(),
             # ctxt={'finishtime': asyncrequest.finishtime-2},
             ctxt=async_ctxt or {},
             msg={
                 'method': 'asyncrequest',
                 'args': {
                     'asyncrequest': asyncrequest.to_dict(),
                     'rpc_target': rpc_target.to_dict(),
                     'rpc_method': rpc_method,
                     'rpc_ctxt': rpc_ctxt,
                     'rpc_args': rpc_args or dict()
                 }
             })
     except AMQPDestinationNotFound as e:
         LOG.error('Send async request to scheduler fail %s' %
                   e.__class__.__name__)
         asyncrequest.status = manager_common.FINISH
         asyncrequest.result = e.message
         asyncrequest.resultcode = manager_common.SCHEDULER_NOTIFY_ERROR
         try:
             session.add(asyncrequest)
             session.flush()
         except DBDuplicateEntry:
             LOG.warning(
                 'Async request rpc call result is None, but recode found')
     except Exception as e:
         if LOG.isEnabledFor(logging.DEBUG):
             LOG.exception('Async request rpc cast fail')
         else:
             LOG.error('Async request rpc cast unkonw error')
         asyncrequest.status = manager_common.FINISH
         asyncrequest.result = 'Async request rpc cast error: %s' % e.__class__.__name__
         asyncrequest.resultcode = manager_common.RESULT_ERROR
         try:
             session.add(asyncrequest)
             session.flush()
             raise
         except DBDuplicateEntry:
             LOG.warning(
                 'Async request rpc call result is None, but recode found')
Example #3
0
 def chioces(endpoint, includes=None, weighters=None):
     """return a agents list sort by weigher"""
     rpc = get_client()
     chioces_result = rpc.call(targetutils.target_rpcserver(),
                               ctxt=dict(),
                               msg={
                                   'method': 'chioces',
                                   'args': {
                                       'target': endpoint,
                                       'includes': includes,
                                       'weighters': weighters
                                   }
                               })
     if not chioces_result:
         raise RpcResultError('Active agent chioces result is None')
     if chioces_result.pop('resultcode') != manager_common.RESULT_SUCCESS:
         raise RpcResultError('Call agent chioces fail: ' +
                              chioces_result.get('result'))
     return chioces_result['agents']
Example #4
0
 def wapper():
     rpc.cast(targetutils.target_rpcserver(fanout=True),
              msg={'method': 'deletesource',
                   'args': {'agent_id': agent_id}})
Example #5
0
 def __init__(self):
     super(RpcServerManager, self).__init__(target=targetutils.target_rpcserver(CONF.host, fanout=True))
     self.conf = CONF[manager_common.SERVER]
     self.agents_loads = {}
     self.executers = {}
     self.conditions = {}