def probes(self, request): params = request.query_params() if not isinstance(params, dict): raise HttpReqError(400, "invalid arguments type") if not xys.validate(params, self.PROBES_QSCHEMA): raise HttpReqError(415, "invalid arguments for command") if not self.LOCK.acquire_read(self.lock_timeout): raise HttpReqError( 503, "unable to take LOCK for reading after %s seconds" % self.lock_timeout) try: uid = self._push_epts_sync(params['endpoint'], 'probes', params) res = self._get_result(uid) if res['error']: raise HttpReqError( 500, "failed to get results. (errors: %r)" % res['error']) return HttpResponse(data=res['result']) except HttpReqError: raise except Exception as e: LOG.exception(e) finally: gc.collect() self.LOCK.release()
def _push_epts_sync(self, endpoint, method, params, args=None): if endpoint not in EPTS_SYNC: raise HttpReqError(404, "unable to find endpoint: %r" % endpoint) elif EPTS_SYNC[endpoint].type != 'probe': raise HttpReqError( 400, "invalid endpoint type, correct type: %r" % EPTS_SYNC[endpoint].type) ept_sync = EPTS_SYNC[endpoint] uid = "%s:%s" % (ept_sync.name, uuid.uuid4()) ept_sync.qput( CovenantEPTObject(ept_sync.name, uid, endpoint, method, params, args, self._set_result)) return uid
def index(self, request): if not self.LOCK.acquire_read(self.lock_timeout): raise HttpReqError( 503, "unable to take LOCK for reading after %s seconds" % self.lock_timeout) try: self._push_epts_sync('replay', copy.copy(request)) return HttpResponse() except HttpReqError, e: raise
def server(self, request): # pylint: disable-msg=unused-argument if not self.LOCK.acquire_read(self.lock_timeout): raise HttpReqError( 503, "unable to take LOCK for reading after %s seconds" % self.lock_timeout) try: return HttpResponse(data=generate_latest()) except HttpReqError: raise except Exception as e: LOG.exception(e) finally: self.LOCK.release()
def _push_epts_sync(self, method, request, endpoint=None): if endpoint: if endpoint not in EPTS_SYNC: raise HttpReqError(404, "unable to find endpoint: %r" % endpoint) else: epts = {endpoint: EPTS_SYNC[endpoint]} else: epts = EPTS_SYNC for endpoint, ept_sync in epts.iteritems(): uid = "%s:%s" % (ept_sync.name, uuid.uuid4()) ept_sync.qput( FdReplayEPTObject(ept_sync.name, uid, endpoint, method, request)) return uid