示例#1
0
文件: main.go 项目: xiekeyang/gowfs
func testConnection(fs *gowfs.FileSystem) {
	_, err := fs.ListStatus(gowfs.Path{Name: "/"})
	if err != nil {
		log.Fatal("Unable to connect to server. ", err)
	}
	log.Printf("Connected to server %s... OK.\n", fs.Config.Addr)
}
示例#2
0
文件: main.go 项目: xiekeyang/gowfs
func renameRemoteFile(fs *gowfs.FileSystem, oldName, newName string) {
	_, err := fs.Rename(gowfs.Path{Name: oldName}, gowfs.Path{Name: newName})
	if err != nil {
		log.Fatal("Unable to rename remote file ", oldName, " to ", newName)
	}
	log.Println("HDFS file ", oldName, " renamed to ", newName)
	ls(fs, newName)
}
示例#3
0
文件: main.go 项目: xiekeyang/gowfs
func createTestDir(fs *gowfs.FileSystem, hdfsPath string) {
	path := gowfs.Path{Name: hdfsPath}
	ok, err := fs.MkDirs(path, 0744)
	if err != nil || !ok {
		log.Fatal("Unable to create test directory ", hdfsPath, ":", err)
	}
	log.Println("HDFS Path ", path.Name, " created.")
	ls(fs, path.Name)
}
示例#4
0
文件: main.go 项目: xiekeyang/gowfs
func changeMod(fs *gowfs.FileSystem, hdfsPath string) {
	shell := gowfs.FsShell{FileSystem: fs}
	_, err := shell.Chmod([]string{hdfsPath}, 0744)
	if err != nil {
		log.Fatal("Chmod() failed for ", hdfsPath, ": ", err.Error())
	}
	stat, err := fs.GetFileStatus(gowfs.Path{Name: hdfsPath})
	if err != nil {
		log.Fatal("Unable to validate Chmod() operation: ", err.Error())
	}
	if stat.Permission == "744" {
		log.Println("Chmod for ", hdfsPath, " OK ")
		ls(fs, hdfsPath)
	} else {
		log.Fatal("Chmod() failed.")
	}
}
示例#5
0
文件: main.go 项目: xiekeyang/gowfs
func changeGroup(fs *gowfs.FileSystem, hdfsPath string) {
	shell := gowfs.FsShell{FileSystem: fs}
	_, err := shell.Chgrp([]string{hdfsPath}, "superduper")
	if err != nil {
		log.Fatal("Chgrp failed for ", hdfsPath, ": ", err.Error())
	}
	stat, err := fs.GetFileStatus(gowfs.Path{Name: hdfsPath})
	if err != nil {
		log.Fatal("Unable to validate chgrp() operation: ", err.Error())
	}
	if stat.Group == "superduper" {
		log.Println("Chgrp for ", hdfsPath, " OK ")
		ls(fs, hdfsPath)
	} else {
		log.Fatal("Chgrp() failed.")
	}
}
示例#6
0
文件: main.go 项目: xiekeyang/gowfs
func changeOwner(fs *gowfs.FileSystem, hdfsPath string) {
	shell := gowfs.FsShell{FileSystem: fs}
	_, err := shell.Chown([]string{hdfsPath}, "owner2")
	if err != nil {
		log.Fatal("Chown failed for ", hdfsPath, ": ", err.Error())
	}
	stat, err := fs.GetFileStatus(gowfs.Path{Name: hdfsPath})
	if err != nil {
		log.Fatal("Unable to validate chown() operation: ", err.Error())
	}
	if stat.Owner == "owner2" {
		log.Println("Chown for ", hdfsPath, " OK ")
		ls(fs, hdfsPath)
	} else {
		log.Fatal("Chown() failed.")
	}
}
示例#7
0
文件: main.go 项目: xiekeyang/gowfs
func ls(fs *gowfs.FileSystem, hdfsPath string) {
	stats, err := fs.ListStatus(gowfs.Path{Name: hdfsPath})
	if err != nil {
		log.Fatal("Unable to list paths: ", err)
	}
	log.Printf("Found %d file(s) at %s\n", len(stats), hdfsPath)
	for _, stat := range stats {
		fmt.Printf(
			"%-11s %3s %s\t%s\t%11d %20v %s\n",
			formatFileMode(stat.Permission, stat.Type),
			formatReplication(stat.Replication, stat.Type),
			stat.Owner,
			stat.Group,
			stat.Length,
			formatModTime(stat.ModificationTime),
			stat.PathSuffix)
	}
}
示例#8
0
文件: main.go 项目: xiekeyang/gowfs
func moveRemoteFileLocal(fs *gowfs.FileSystem, remoteFile string) {
	log.Println("Moving Remote file!!")
	shell := gowfs.FsShell{FileSystem: fs}
	remotePath, fileName := path.Split(remoteFile)
	_, err := shell.MoveToLocal(remoteFile, fileName)
	if err != nil {
		log.Fatal("MoveToLocal() failed: ", err.Error())
	}
	file, err := os.Open(fileName)
	if err != nil {
		log.Fatal("MoveToLocal() - local file can't be open. ")
	}
	defer file.Close()
	defer os.Remove(file.Name())

	_, err = fs.GetFileStatus(gowfs.Path{Name: remoteFile})
	if err == nil {
		log.Fatal("Expecing a FileNotFoundException, but file is found. ", remoteFile, ": ", err.Error())
	}
	log.Printf("Remote file %s has been removed Ok", remoteFile)
	ls(fs, remotePath)
}
示例#9
0
文件: main.go 项目: xiekeyang/gowfs
func appendToRemoteFile(fs *gowfs.FileSystem, localFile, hdfsPath string) {
	stat, err := fs.GetFileStatus(gowfs.Path{Name: hdfsPath})
	if err != nil {
		log.Fatal("Unable to get file info for ", hdfsPath, ":", err.Error())
	}
	shell := gowfs.FsShell{FileSystem: fs}
	_, err = shell.AppendToFile([]string{localFile}, hdfsPath)
	if err != nil {
		log.Fatal("AppendToFile() failed: ", err.Error())
	}

	stat2, err := fs.GetFileStatus(gowfs.Path{Name: hdfsPath})
	if err != nil {
		log.Fatal("Something went wrong, unable to get file info:", err.Error())
	}
	if stat2.Length > stat.Length {
		log.Println("AppendToFile() for ", hdfsPath, " OK.")
		ls(fs, hdfsPath)
	} else {
		log.Fatal("AppendToFile failed. File size for ", hdfsPath, " expected to be larger.")
	}
}