Exemple #1
0
func main() {
	flag.Parse()

	aerpc.RegisterCommands()

	if *isPrintHelp {
		printHelp()
		return
	}

	addr := aerpc.NormalizeAddr(*serverAddr)
	client, err := rpcclient.NewClient(addr)
	if err != nil {
		fmt.Printf("Can't connect to %s:\n%v\n", addr, err)
		return
	}
	defer client.Close()
	var i int
	for {
		cmd := new(aerpc.RpcCommandStatus)
		err = cmd.Execute(client)
		if err != nil {
			panic(err)
			return
		}
		if i%10 == 0 {
			printHead()
		}
		stat := cmd.Data().(*aerpc.RpcCommandStatus)
		printStats(stat)
		time.Sleep(time.Second)
		i++
	}
}
Exemple #2
0
func main() {
	flag.Parse()

	aerpc.RegisterCommands()

	if *isPrintHelp {
		printHelp()
		return
	}

	command, args := parseArgs()

	if command == "" {
		fmt.Println("Command not specified")
		return
	}

	cmd, ok := aerpc.Commands[command]
	if !ok {
		fmt.Printf("Call to undefined command: %s\n", command)
		return
	}

	addr := aerpc.NormalizeAddr(*serverAddr)
	client, err := rpcclient.NewClient(addr)
	if err != nil {
		fmt.Printf("Can't connect to %s:\n%v\n", addr, err)
		return
	}
	defer client.Close()

	if args != nil && len(args) > 0 {
		err = cmd.SetArgs(args)
		if err != nil {
			fmt.Printf("Invalid args format: %v\n", err)
			return
		}
	}
	err = cmd.Execute(client)
	if err != nil {
		fmt.Printf("Server return error:\n%v\n", err)
	} else {
		cmd.Print()
	}
}
Exemple #3
0
func main() {
	flag.Parse()

	aerpc.RegisterCommands()

	cmd, ok := aerpc.Commands["FILELIST"]
	if !ok {
		fmt.Printf("Call to undefined command: %s\n", "FILELIST")
		return
	}

	*method = strings.ToUpper(*method)

	switch *method {
	case "PUT":
	case "POST":
	case "DELETE":
		break
	default:
		fmt.Println("Unexpected http method:", *method)
	}

	if !strings.HasPrefix(*readAddr, "http") {
		readUrl = "http://" + *readAddr + "/"
	} else {
		readUrl = *readAddr + "/"
	}
	if !strings.HasPrefix(*writeAddr, "http") {
		writeUrl = "http://" + *writeAddr + "/"
	} else {
		writeUrl = *writeAddr + "/"
	}

	addr := aerpc.NormalizeAddr(*rpcAddr)
	client, err := rpcclient.NewClient(addr)
	fmt.Println("Connect to", addr)
	if err != nil {
		fmt.Printf("Can't connect to %s:\n%v\n", addr, err)
		return
	}
	defer client.Close()

	fmt.Println("Get list of files...")
	if cmd.Execute(client); err != nil {
		fmt.Printf("Error: %v\n", err)
		return
	}
	fileList := cmd.Data().([]string)
	bar := pb.StartNew(len(fileList))
	wg := &sync.WaitGroup{}
	c := make(chan string)
	for i := 0; i < *clients; i++ {
		wg.Add(1)
		go func() {
			StartClient(c, bar)
			wg.Done()
		}()
	}

	for _, file := range fileList {
		c <- file
	}
	close(c)
	wg.Wait()
	bar.Finish()
}