Пример #1
0
func main() {
	log.SetFlags(log.Lshortfile)
	flag.Parse()
	log.Println("RUNNING DEPLOY2DETER WITH RATE:", rate)
	os.MkdirAll("remote", 0777)
	var wg sync.WaitGroup
	// start building the necessary packages
	packages := []string{"../logserver", "../timeclient", "../exec", "../forkexec", "../deter"}
	for _, p := range packages {
		wg.Add(1)
		if p == "../deter" {
			go func(p string) {
				defer wg.Done()
				// the users node has a 386 FreeBSD architecture
				err := cliutils.Build(p, "386", "freebsd")
				if err != nil {
					log.Fatal(err)
				}
			}(p)
			continue
		}
		go func(p string) {
			defer wg.Done()
			// deter has an amd64, linux architecture
			err := cliutils.Build(p, "amd64", "linux")
			if err != nil {
				log.Fatal(err)
			}
		}(p)
	}
	// killssh processes on users
	cliutils.SshRunStdout("dvisher", "users.isi.deterlab.net", "killall ssh scp deter 2>/dev/null 1>/dev/null")

	// parse the hosts.txt file to create a separate list (and file)
	// of physical nodes and virtual nodes. Such that each host on line i, in phys.txt
	// corresponds to each host on line i, in virt.txt.
	physVirt, err := cliutils.ReadLines("hosts.txt")
	phys := make([]string, 0, len(physVirt)/2)
	virt := make([]string, 0, len(physVirt)/2)
	for i := 0; i < len(physVirt); i += 2 {
		phys = append(phys, physVirt[i])
		virt = append(virt, physVirt[i+1])
	}
	nloggers := 3
	// only use the number of machines that we need
	phys = phys[:nmachs+nloggers]
	virt = virt[:nmachs+nloggers]
	physOut := strings.Join(phys, "\n")
	virtOut := strings.Join(virt, "\n")

	// phys.txt and virt.txt only contain the number of machines that we need
	err = ioutil.WriteFile("remote/phys.txt", []byte(physOut), 0666)
	if err != nil {
		log.Fatal("failed to write physical nodes file", err)
	}

	err = ioutil.WriteFile("remote/virt.txt", []byte(virtOut), 0666)
	if err != nil {
		log.Fatal("failed to write virtual nodes file", err)
	}

	masterLogger := phys[0]
	// slaveLogger1 := phys[1]
	// slaveLogger2 := phys[2]
	virt = virt[3:]
	phys = phys[3:]
	t, hostnames, depth, err := graphs.TreeFromList(virt, hpn, bf)
	log.Println("DEPTH:", depth)
	log.Println("TOTAL HOSTS:", len(hostnames))

	// wait for the build to finish
	wg.Wait()

	// copy the logserver directory to the current directory
	err = exec.Command("rsync", "-au", "../logserver", "remote/").Run()
	if err != nil {
		log.Fatal("error rsyncing logserver directory into remote directory:", err)
	}
	err = exec.Command("rsync", "-au", "remote/phys.txt", "remote/virt.txt", "remote/logserver/").Run()
	if err != nil {
		log.Fatal("error rsyncing phys, virt, and remote/logserver:", err)
	}
	err = os.Rename("logserver", "remote/logserver/logserver")
	if err != nil {
		log.Fatal("error renaming logserver:", err)
	}

	b, err := json.Marshal(t)
	if err != nil {
		log.Fatal("unable to generate tree from list")
	}
	err = ioutil.WriteFile("remote/logserver/cfg.json", b, 0660)
	if err != nil {
		log.Fatal("unable to write configuration file")
	}

	// NOTE: now remote/logserver is ready for transfer
	// it has logserver/ folder, binary, and cfg.json, and phys.txt, virt.txt

	// generate the configuration file from the tree
	cf := config.ConfigFromTree(t, hostnames)
	cfb, err := json.Marshal(cf)
	err = ioutil.WriteFile("remote/cfg.json", cfb, 0666)
	if err != nil {
		log.Fatal(err)
	}

	// scp the files that we need over to the boss node
	files := []string{"timeclient", "exec", "forkexec", "deter"}
	for _, f := range files {
		cmd := exec.Command("rsync", "-au", f, "remote/")
		cmd.Stdout = os.Stdout
		cmd.Stderr = os.Stderr
		err := cmd.Run()
		if err != nil {
			log.Fatal("error unable to rsync file into remote directory:", err)
		}
	}
	err = cliutils.Rsync("dvisher", "users.isi.deterlab.net", "remote", "")
	if err != nil {
		log.Fatal(err)
	}
	killssh := exec.Command("pkill", "-f", "ssh -t -t")
	killssh.Stdout = os.Stdout
	killssh.Stderr = os.Stderr
	err = killssh.Run()
	if err != nil {
		log.Print(err)
	}

	// setup port forwarding for viewing log server
	// ssh -L 8080:pcXXX:80 [email protected]
	// ssh [email protected] -L 8118:somenode.experiment.YourClass.isi.deterlab.net:80
	fmt.Println("setup port forwarding for master logger: ", masterLogger)
	cmd := exec.Command(
		"ssh",
		"-t",
		"-t",
		"*****@*****.**",
		"-L",
		"8080:"+masterLogger+":10000")
	err = cmd.Start()
	if err != nil {
		log.Fatal("failed to setup portforwarding for logging server")
	}
	log.Println("runnning deter with nmsgs:", nmsgs)
	// run the deter lab boss nodes process
	// it will be responsible for forwarding the files and running the individual
	// timestamping servers
	log.Fatal(cliutils.SshRunStdout("dvisher", "users.isi.deterlab.net",
		"GOMAXPROCS=8 remote/deter -nmsgs="+strconv.Itoa(nmsgs)+
			" -hpn="+strconv.Itoa(hpn)+
			" -bf="+strconv.Itoa(bf)+
			" -rate="+strconv.Itoa(rate)+
			" -rounds="+strconv.Itoa(rounds)+
			" -debug="+strconv.FormatBool(debug)+
			" -failures="+strconv.Itoa(failures)+
			" -rfail="+strconv.Itoa(rFail)+
			" -ffail="+strconv.Itoa(fFail)+
			" -test_connect="+strconv.FormatBool(testConnect)+
			" -app="+app+
			" -suite="+suite+
			" -kill="+strconv.FormatBool(kill)))
}
Пример #2
0
func main() {
	flag.Parse()
	content, err := ioutil.ReadFile(hostfile)
	if err != nil {
		log.Fatal(hostfile, ": ", err)
	}
	// get the specified hostnames from the file
	hostnames := strings.Fields(string(content))
	log.Println("hostnames: ", hostnames)
	content, err = ioutil.ReadFile(clientfile)
	if err != nil {
		log.Fatal(err)
	}
	// get the specified hostnames from the file
	clientnames := strings.Fields(string(content))
	log.Println("clientnames: ", clientnames)

	if err := cliutils.Build("../latency_test", "386", "linux"); err != nil {
		log.Fatal(err)
	}
	if err := cliutils.Build("../exec", "386", "linux"); err != nil {
		log.Fatal(err)
	}
	if app == "time" {
		if err := cliutils.Build("../timeclient", "386", "linux"); err != nil {
			log.Fatal(err)
		}
	}

	// test the latency between nodes and remove bad ones
	uniquehosts := getUniqueHosts(hostnames)
	uniqueclients := getUniqueHosts(clientnames)

	if kill {
		var wg sync.WaitGroup
		for _, h := range hostnames {
			wg.Add(1)
			go func(h string) {
				defer wg.Done()
				cliutils.SshRun(uname, h, "killall logserver; killall timeclient; killall latency_test; killall cocoexec; rm -rf cocoexec; rm -rf latency_test; rm -rf timeclient")
			}(h)
		}
		for _, h := range clientnames {
			wg.Add(1)
			go func(h string) {
				defer wg.Done()
				cliutils.SshRun(uname, h, "killall logserver; killall timeclient; killall latency_test; killall cocoexec; rm -rf cocoexec; rm -rf latency_test; rm -rf timeclient")
			}(h)
		}
		wg.Wait()
		return
	}
	log.Println("uniquehosts: ", uniquehosts)
	failed := scpTestFiles(uniquehosts)
	goodhosts, edgelist := testNodes(hostnames, failed)
	hostnames = goodhosts

	// create a new graph with just these good nodes
	g := graphs.NewGraph(goodhosts)
	g.LoadEdgeList(edgelist)

	// this network into a tree with the given depth
	log.Println("CONSTRUCTING TREE OF DEPTH:", depth)
	t := g.Tree(depth)

	// generate the public and private keys for each node in this tree
	suite := nist.NewAES128SHA256P256()
	t.GenKeys(nist.NewAES128SHA256P256(), suite.Cipher([]byte("example")))
	log.Println("tree:", t)

	// turn this config into a config file for deployment
	cf := config.ConfigFromTree(t, goodhosts)

	// give each host in the file the specified port
	cf.AddPorts(port)

	log.Println("config file contents:", cf)
	b, err := json.Marshal(cf)
	if err != nil {
		log.Fatal(err)
	}

	// write this file out to disk for scp
	log.Println("config file:", string(b))
	err = ioutil.WriteFile("cfg.json", b, 0644)
	if err != nil {
		log.Fatal(err)
	}
	log.Infoln("setting up logger")
	setupLogger()
	log.Infoln("set up logger")
	uniqueclients = getUniqueHosts(clientnames)
	uniquehosts = getUniqueHosts(cf.Hosts)
	log.Infoln("running clients and servers")
	scpClientFiles(uniqueclients)
	scpServerFiles(uniquehosts)
	runClients(clientnames, cf.Hosts, cps)
	deployServers(cf.Hosts)
}