Exemplo n.º 1
0
    def node_request(self, node, method, path, **kwargs):
        url = 'http://%s:%s%s' % (node.hostname, node.port, path)
        headers = {'X-Request-Id': getattr(logger.local, 'request_id',
                                           'lunr-%s' % uuid4())}

        if method in ('GET', 'HEAD', 'DELETE'):
            url += '?' + urlencode(kwargs)

        req = Request(url, urlencode(kwargs), headers=headers)
        req.get_method = lambda *args, **kwargs: method
        try:
            resp = urlopen(req, timeout=self.app.node_timeout)
            logger.debug(
                "%s on %s succeeded with %s" %
                (req.get_method(), req.get_full_url(), resp.getcode()))
            return loads(resp.read())
        except (socket.timeout, urllib2.HTTPError,
                urllib2.URLError, HTTPException), e:
            raise NodeError(req, e)
Exemplo n.º 2
0
def node_request(node_ip, node_port, method, path, **kwargs):
    url = 'http://%s:%s%s' % (node_ip, node_port, path)
    req_id = getattr(logger.local, 'request_id', None)
    # This uuid() call can hang after a fork. libuuid reads from the wrong fd.
    # This is a workaround for when node_request is used in the storage clone
    # callback. We already have a request_id in that case.
    if not req_id:
        req_id = 'lunr-%s' % uuid4()
    headers = {'X-Request-Id': req_id}

    if method in ('GET', 'HEAD', 'DELETE'):
        url += '?' + urlencode(kwargs)

    req = Request(url, urlencode(kwargs), headers=headers)
    req.get_method = lambda *args, **kwargs: method
    try:
        # FIXME. Magic number.
        resp = urlopen(req, timeout=120)
        logger.debug("%s on %s succeeded with %s" %
                     (req.get_method(), req.get_full_url(), resp.getcode()))
        return loads(resp.read())
    except (socket.timeout, HTTPError, URLError, HTTPException), e:
        raise NodeError(req, e)
Exemplo n.º 3
0
 def node_request(*args, **kwargs):
     raise NodeError(MockRequest(), URLError('something bad'))