def post(self, req, resp): """ Start of stop the profiler. """ if yappi is None: raise http.Error(http.NOT_FOUND, "yappi is not installed") run = validate.enum(req.query, "run", ("y", "n")) if run == "y": clock = validate.enum( req.query, "clock", ("cpu", "wall"), default="cpu") self._start_profiling(clock) else: self._stop_profiling()
def post(self, req, resp): """ Start of stop the profiler. """ if yappi is None: raise http.Error(http.NOT_FOUND, "yappi is not installed") run = validate.enum(req.query, "run", ("y", "n")) if run == "y": clock = validate.enum(req.query, "clock", ("cpu", "wall"), default="cpu") self._start_profiling(clock) else: self._stop_profiling()
def post(self): """ Start of stop the profiler. """ if yappi is None: raise HTTPNotFound("yappi is not installed") run = validate.enum(self.request.params, "run", ("y", "n")) if run == "y": clock = validate.enum(self.request.params, "clock", ("cpu", "wall"), default="cpu") self._start_profiling(clock) else: self._stop_profiling() return web.response()
def put(self, ticket_id): if not ticket_id: raise HTTPBadRequest("Ticket id is required") size = self.request.content_length if size is None: raise HTTPBadRequest("Content-Length header is required") if size < 0: raise HTTPBadRequest("Invalid Content-Length header: %r" % size) content_range = web.content_range(self.request) offset = content_range.start or 0 # For backward compatibility, we flush by default. flush = validate.enum(self.request.params, "flush", ("y", "n"), default="y") flush = (flush == "y") ticket = tickets.authorize(ticket_id, "write", offset, size) # TODO: cancel copy if ticket expired or revoked self.log.info( "Writing %d bytes at offset %d flush %s to %s for ticket %s", size, offset, flush, ticket.url.path, ticket_id) op = directio.Receive(ticket.url.path, self.request.body_file_raw, size, offset=offset, flush=flush, buffersize=self.config.daemon.buffer_size, clock=self.clock) try: ticket.run(op) except errors.PartialContent as e: raise HTTPBadRequest(str(e)) return web.response()
def patch(self, ticket_id): if not ticket_id: raise HTTPBadRequest("Ticket id is required") try: msg = self.request.json except ValueError as e: raise HTTPBadRequest("Invalid JSON message: %s" % e) op = validate.enum(msg, "op", ("zero", "flush")) if op == "zero": return self._zero(ticket_id, msg) elif op == "flush": return self._flush(ticket_id, msg) else: raise RuntimeError("Unreachable")
def patch(self, req, resp, ticket_id): if not ticket_id: raise http.Error(http.BAD_REQUEST, "Ticket id is required") # TODO: Reject requests with too big payloads. We know the maximum size # of a payload based on the keys and the size of offset and size. try: msg = json.loads(req.read()) except ValueError as e: raise http.Error( http.BAD_REQUEST, "Invalid JSON message {}" .format(e)) op = validate.enum(msg, "op", ("zero", "flush")) if op == "zero": return self._zero(req, resp, ticket_id, msg) elif op == "flush": return self._flush(req, resp, ticket_id, msg) else: raise RuntimeError("Unreachable")
def put(self, req, resp, ticket_id): if not ticket_id: raise http.Error(http.BAD_REQUEST, "Ticket id is required") size = req.content_length if size is None: raise http.Error( http.BAD_REQUEST, "Content-Length header is required") offset = req.content_range.first if req.content_range else 0 # For backward compatibility, we flush by default. flush = validate.enum(req.query, "flush", ("y", "n"), default="y") flush = (flush == "y") try: ticket = auth.authorize(ticket_id, "write") except errors.AuthorizationError as e: raise http.Error(http.FORBIDDEN, str(e)) validate.allowed_range(offset, size, ticket) log.info( "[%s] WRITE size=%d offset=%d flush=%s ticket=%s", req.client_addr, size, offset, flush, ticket_id) op = ops.Receive( self._backend(req, ticket), req, size, offset=offset, flush=flush, buffersize=self.config.daemon.buffer_size, clock=req.clock) try: ticket.run(op) except errors.PartialContent as e: raise http.Error(http.BAD_REQUEST, str(e))
def put(self, req, resp, ticket_id): if not ticket_id: raise http.Error(http.BAD_REQUEST, "Ticket id is required") size = req.content_length if size is None: raise http.Error( http.BAD_REQUEST, "Content-Length header is required") offset = req.content_range.first if req.content_range else 0 # For backward compatibility, we flush by default. flush = validate.enum(req.query, "flush", ("y", "n"), default="y") flush = (flush == "y") try: ticket = auth.authorize(ticket_id, "write", offset, size) except errors.AuthorizationError as e: raise http.Error(http.FORBIDDEN, str(e)) log.info( "[%s] WRITE size=%d offset=%d flush=%s ticket=%s", req.client_addr, size, offset, flush, ticket_id) op = ops.Receive( self._backend(req, ticket), req, size, offset=offset, flush=flush, buffersize=self.config.daemon.buffer_size, clock=req.clock) try: ticket.run(op) except errors.PartialContent as e: raise http.Error(http.BAD_REQUEST, str(e))