func HookupHDFS(namenode, webapi, role string) error { err := "" if len(role) <= 0 { if u, e := user.Current(); e != nil { err += fmt.Sprintf("Unknown current user: %v\n", e) } else { role = u.Username } } log.Printf("Establish HDFS protobuf-based RPC connection as %s@%s", role, namenode) if fs, e := hdfs.NewForUser(namenode, role); e != nil { err += fmt.Sprintf("Cannot estabilish RPC connection to %s@%s: %v", role, namenode, e) } else { rpcfs = fs } log.Printf("Establish WebHDFS connection as %s@%s", role, webapi) if fs, e := gowfs.NewFileSystem(gowfs.Configuration{Addr: webapi, User: role}); e != nil { err += fmt.Sprintf("Cannot establish WebHDFS connection to %s@%s: %v", role, webapi, e) } else { webfs = fs if e := testConnection(); e != nil { err += fmt.Sprintf("Failed checking WebHDFS connection: %v", e) } } if len(err) > 0 { return fmt.Errorf(err) } return nil }
func main() { flag.Parse() fs, err := gowfs.NewFileSystem(gowfs.Configuration{Addr: *nn, User: *user}) if err != nil { log.Fatal(err) } statuses, err := fs.ListStatus(gowfs.Path{Path: *path}) if err != nil { log.Fatal(err) } fmt.Printf("Found %d item(s)\n", len(statuses)) for _, v := range statuses { fmt.Printf( "%-11s %3s %s\t%s\t%11d %20v %s\n", formatFileMode(v.Permission, v.Type), formatReplication(v.Replication, v.Type), v.Owner, v.Group, v.Length, formatModTime(v.ModificationTime), v.PathSuffix) } }
func main() { flag.Parse() fs, err := gowfs.NewFileSystem(gowfs.Configuration{Addr: *nn, User: *user}) if err != nil { log.Fatal(err) } checksum, err := fs.GetFileChecksum(gowfs.Path{Path: *path}) if err != nil { log.Fatal(err) } fmt.Println("Checksum for ", *path) fmt.Println(checksum) }