File: stat_fs.go

package info (click to toggle)
golang-github-colinmarc-hdfs 2.3.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 3,760 kB
  • sloc: sh: 130; xml: 40; makefile: 31
file content (41 lines) | stat: -rw-r--r-- 1,081 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package hdfs

import (
	hdfs "github.com/colinmarc/hdfs/v2/internal/protocol/hadoop_hdfs"
)

// FsInfo provides information about HDFS
type FsInfo struct {
	Capacity              uint64
	Used                  uint64
	Remaining             uint64
	UnderReplicated       uint64
	CorruptBlocks         uint64
	MissingBlocks         uint64
	MissingReplOneBlocks  uint64
	BlocksInFuture        uint64
	PendingDeletionBlocks uint64
}

func (c *Client) StatFs() (FsInfo, error) {
	req := &hdfs.GetFsStatusRequestProto{}
	resp := &hdfs.GetFsStatsResponseProto{}

	err := c.namenode.Execute("getFsStats", req, resp)
	if err != nil {
		return FsInfo{}, err
	}

	var fs FsInfo
	fs.Capacity = resp.GetCapacity()
	fs.Used = resp.GetUsed()
	fs.Remaining = resp.GetRemaining()
	fs.UnderReplicated = resp.GetUnderReplicated()
	fs.CorruptBlocks = resp.GetCorruptBlocks()
	fs.MissingBlocks = resp.GetMissingBlocks()
	fs.MissingReplOneBlocks = resp.GetMissingReplOneBlocks()
	fs.BlocksInFuture = resp.GetBlocksInFuture()
	fs.PendingDeletionBlocks = resp.GetPendingDeletionBlocks()

	return fs, nil
}