views.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:django-hdfs 作者: thanos 项目源码 文件源码
def hdfs_usage(request, root=None):
    host = settings.HDFS_STROAGE['hosts']
    if not root:
        root = settings.HDFS_STROAGE['HDFS_ROOT']

    log.info('http://%s/%s', host, root)
    client = hdfs.InsecureClient('http://%s' % host)
    tree = []
    try:
        for appcode in client.list(root):
            url = 'http://%s/webhdfs/v1%s/%s?op=GETCONTENTSUMMARY' % (host, root, appcode)
            data = requests.get(url).json()
            if data['ContentSummary']['directoryCount']:
                tree.append({
                    'name': appcode,
                    'value': round(data['ContentSummary']['length'] / 1000000.0, 2)
                })
    except HdfsError, e:
        log.warn("hdfs_usage error: %s", e)
        return HttpResponseNotFound(dumps(tree), content_type='application/json')
    return HttpResponse(dumps(tree), content_type='application/json')
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号