hdfs

package module
v0.0.0-...-c42c9d7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 27, 2016 License: MIT Imports: 14 Imported by: 0

README

hdfs

Golang wrapper for WebHDFS client

Usage
go get -u github.com/juragan360/hdfs
Connect to HDFS
h, e := NewHdfs(NewHdfsConfig("http://localhost:50070", "hadoopuser")) 
h, e := NewHdfs(NewHdfsConfig("http://localhost:50070", ""))  //--- automatically pass username from OS Context

Make a HDFS dir
es := h.MakeDirs([]string{"/user/ariefdarmawan/inbox", "/user/ariefdarmawan/inbox/temp", "user/ariefdarmawan/outbox", "user/ariefdarmawan/done"}, 0)
	
if es != nil {
	for k, v := range es {
		fmt.Printf("Error when create %v : %v \n", k, v)
	}
}
Put single file
err = h.Put("/users/ariefdarmawan/Temp/config.json", "/user/ariefdarmawan/inbox/temp/config.json", 0, map[string]string{"overwrite": "true"})
Put multiple files
fmt.Println(">>>> TEST PUT FILE<<<<")
es = h.Puts([]string{
	"/users/ariefdarmawan/Temp/config.json",
	"/users/ariefdarmawan/Temp/ecis_test.js",
}, "/user/ariefdarmawan/inbox/temp/", 0, nil)
if es != nil {
	for k, v := range es {
		t.Error(fmt.Sprintf("Error when write %v : %v \n", k, v))
	}
}
Read HDFS Status
hdata, _ := h.List("/user/ariefdarmawan")
fmt.Printf("Data:\n%v\n", hdata.FileStatuses.FileStatus)

Documentation

Overview

Provide HDFS WebApi wrapper to connect to Hadoop cluster. This package was written on 2.5.1 but should be work on other version that has same signature

Index

Constants

View Source
const (
	OP_OPEN                  = "OPEN"
	OP_CREATE                = "CREATE"
	OP_APPEND                = "APPEND"
	OP_CONCAT                = "CONCAT"
	OP_RENAME                = "RENAME"
	OP_DELETE                = "DELETE"
	OP_SETPERMISSION         = "SETPERMISSION"
	OP_SETOWNER              = "SETOWNER"
	OP_SETREPLICATION        = "SETREPLICATION"
	OP_SETTIMES              = "SETTIMES"
	OP_MKDIRS                = "MKDIRS"
	OP_CREATESYMLINK         = "CREATESYMLINK"
	OP_LISTSTATUS            = "LISTSTATUS"
	OP_GETFILESTATUS         = "GETFILESTATUS"
	OP_GETCONTENTSUMMARY     = "GETCONTENTSUMMARY"
	OP_GETFILECHECKSUM       = "GETFILECHECKSUM"
	OP_GETDELEGATIONTOKEN    = "GETDELEGATIONTOKEN"
	OP_GETDELEGATIONTOKENS   = "GETDELEGATIONTOKENS"
	OP_RENEWDELEGATIONTOKEN  = "RENEWDELEGATIONTOKEN"
	OP_CANCELDELEGATIONTOKEN = "CANCELDELEGATIONTOKEN"
)
View Source
const WebHdfsApi string = "/webhdfs/v1/"

Constant

Variables

This section is empty.

Functions

This section is empty.

Types

type ContentSummary

type ContentSummary struct {
	DirectoryCount int64
	FileCount      int64
	Length         int64
	Quota          int64
	SpaceConsumed  int64
	SpaceQuota     int64
}
Type for HDFS FileSystem content summary (FileSystem.getContentSummary())
See http://hadoop.apache.org/docs/r2.2.0/hadoop-project-dist/hadoop-hdfs/WebHDFS.html#ContentSummary_JSON_Schema

Example:

{
  "ContentSummary":
  {
    "directoryCount": 2,
    "fileCount"     : 1,
    "length"        : 24930,
    "quota"         : -1,
    "spaceConsumed" : 24930,
    "spaceQuota"    : -1
  }
}

type FileChecksum

type FileChecksum struct {
	Algorithm string
	Bytes     string
	Length    int64
}
Type for HDFS FileSystem.getFileChecksum()
See http://hadoop.apache.org/docs/r2.2.0/hadoop-project-dist/hadoop-hdfs/WebHDFS.html#FileChecksum_JSON_Schema

Example:

{
  "FileChecksum":
  {
    "algorithm": "MD5-of-1MD5-of-512CRC32",
    "bytes"    : "eadb10de24aa315748930df6e185c0d ...",
    "length"   : 28
  }
}

type FileStatus

type FileStatus struct {
	AccesTime        int64
	BlockSize        int64
	Group            string
	Length           int64
	ModificationTime int64
	Owner            string
	PathSuffix       string
	Permission       string
	Replication      int64
	Type             string
}

Represents HDFS FileStatus (FileSystem.getStatus()) See http://hadoop.apache.org/docs/r2.2.0/hadoop-project-dist/hadoop-hdfs/WebHDFS.html#FileStatus_JSON_Schema

Example:

{
  "FileStatus":
  {
    "accessTime"      : 0, 				// integer
    "blockSize"       : 0, 				// integer
    "group"           : "grp",			// string
    "length"          : 0,             	// integer - zero for directories
    "modificationTime": 1320173277227,	// integer
    "owner"           : "webuser",		// string
    "pathSuffix"      : "",				// string
    "permission"      : "777",			// string
    "replication"     : 0,				// integer
    "type"            : "DIRECTORY"    	// string - enum {FILE, DIRECTORY, SYMLINK}
  }
}

type FileStatuses

type FileStatuses struct {
	FileStatus []FileStatus
}

Container type for multiple FileStatus for directory, etc (see HDFS FileSystem.listStatus()) NOTE: the confusing naming and Plurality is to match WebHDFS schema.

type Hdfs

type Hdfs struct {
	Config *HdfsConfig
	// contains filtered or unexported fields
}

func NewHdfs

func NewHdfs(config *HdfsConfig) (*Hdfs, error)

func (*Hdfs) Append

func (h *Hdfs) Append(localfile string, destination string) error

func (*Hdfs) Delete

func (h *Hdfs) Delete(path string, recursive bool) error

func (*Hdfs) Deletes

func (h *Hdfs) Deletes(paths []string, recursive bool) map[string]error

func (*Hdfs) Get

func (h *Hdfs) Get(path string) ([]byte, error)

func (*Hdfs) GetToLocal

func (h *Hdfs) GetToLocal(path string, destination string, permission string) error

func (*Hdfs) List

func (h *Hdfs) List(path string) (*HdfsData, error)

func (*Hdfs) MakeDir

func (h *Hdfs) MakeDir(path string, permission string) error

func (*Hdfs) MakeDirs

func (h *Hdfs) MakeDirs(paths []string, permission string) map[string]error

func (*Hdfs) Put

func (h *Hdfs) Put(localfile string, destination string, permission string, parms map[string]string) error

func (*Hdfs) PutDir

func (h *Hdfs) PutDir(dirname string, destination string) (error, map[string]error)

func (*Hdfs) Puts

func (h *Hdfs) Puts(paths []string, destinationFolder string, permission string, parms map[string]string) map[string]error

func (*Hdfs) Rename

func (h *Hdfs) Rename(path string, destination string) error

func (*Hdfs) SetOwner

func (h *Hdfs) SetOwner(path string, owner string, group string) error

func (*Hdfs) SetPermission

func (h *Hdfs) SetPermission(path string, user string) error

type HdfsConfig

type HdfsConfig struct {
	Host     string
	UserId   string
	Password string
	Token    string
	Method   string
	TimeOut  time.Duration
	PoolSize int
}

func NewHdfsConfig

func NewHdfsConfig(host, userid string) *HdfsConfig

type HdfsData

type HdfsData struct {
	Boolean         bool
	FileStatus      FileStatus
	FileStatuses    FileStatuses
	FileChecksum    FileChecksum
	ContentSummary  ContentSummary
	Token           Token
	Tokens          Tokens
	Long            int64
	RemoteException RemoteException
}

Root level struct for data JSON data from WebHDFS.

type Path

type Path struct {
	Name       string  // Relative path representation (/root/leaf)
	RefererUrl url.URL // URL related to path (http://server:port/root/leaf)
}

Represents a remote webHDFS path

type RemoteException

type RemoteException struct {
	Exception     string
	JavaClassName string
	Message       string
}

Example:

{
  "RemoteException":
  {
    "exception"    : "FileNotFoundException",
    "javaClassName": "java.io.FileNotFoundException",
    "message"      : "File does not exist: /foo/a.patch"
  }
}

func (RemoteException) Error

func (re RemoteException) Error() string

Implementation of error type. Returns string representation of RemoteException.

type Token

type Token struct {
	UrlString string
}

Example:

{
  "Token":
  {
    "urlString": "JQAIaG9y..."
  }
}

type Tokens

type Tokens struct {
	Token []Token
}

Container type for Token

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL