Exemplo n.º 1
0
func getInitialView(bindAddr string, initialProc string) *view.View {
	hostname, err := os.Hostname()
	if err != nil {
		log.Fatalln(err)
	}

	if initialProc == "" {
		var updates []view.Update
		switch {
		case strings.Contains(hostname, "node-"): // emulab.net
			updates = []view.Update{
				view.Update{Type: view.Join, Process: view.Process{"10.1.1.2:5000"}},
				view.Update{Type: view.Join, Process: view.Process{"10.1.1.3:5000"}},
				view.Update{Type: view.Join, Process: view.Process{"10.1.1.4:5000"}},
			}
		default:
			updates = []view.Update{
				view.Update{Type: view.Join, Process: view.Process{"[::]:5000"}},
				view.Update{Type: view.Join, Process: view.Process{"[::]:5001"}},
				view.Update{Type: view.Join, Process: view.Process{"[::]:5002"}},
			}
		}
		hardCodedView := view.NewWithUpdates(updates...)

		// don't ask for current view if the process is in the hardCodedView
		if hardCodedView.HasMember(view.Process{bindAddr}) {
			return hardCodedView
		}

		for _, u := range updates {
			v, err := client.GetCurrentView(u.Process)
			if err != nil {
				log.Println("Failed to get current view from process %v: %v\n", u.Process, err)
				continue
			}

			if v.Equal(hardCodedView) {
				return hardCodedView
			} else {
				return v
			}
		}
		log.Fatalln("Fatal: None of the hard coded initial processes are responsive.")
		return nil
	} else {
		process := view.Process{initialProc}
		initialView, err := client.GetCurrentView(process)
		if err != nil {
			log.Fatalf("Failed to get current view from process %v: %v\n", process, err)
		}
		return initialView
	}
}
Exemplo n.º 2
0
func getInitialView() (*view.View, error) {
	hostname, err := os.Hostname()
	if err != nil {
		log.Panicln(err)
	}

	if *initialProcess == "" {
		switch {
		case strings.Contains(hostname, "node-"): // emulab.net
			updates := []view.Update{view.Update{Type: view.Join, Process: view.Process{"10.1.1.2:5000"}},
				view.Update{Type: view.Join, Process: view.Process{"10.1.1.3:5000"}},
				view.Update{Type: view.Join, Process: view.Process{"10.1.1.4:5000"}},
			}
			return view.NewWithUpdates(updates...), nil
		default:
			updates := []view.Update{view.Update{Type: view.Join, Process: view.Process{"[::]:5000"}},
				view.Update{Type: view.Join, Process: view.Process{"[::]:5001"}},
				view.Update{Type: view.Join, Process: view.Process{"[::]:5002"}},
			}
			return view.NewWithUpdates(updates...), nil
		}
	} else {
		process := view.Process{*initialProcess}
		initialView, err := client.GetCurrentView(process)
		if err != nil {
			log.Fatalf("Failed to get current view from process %v: %v\n", process, err)
		}
		return initialView, nil
	}
}
Exemplo n.º 3
0
func getFurtherViews() (*view.View, error) {
	view, err := client.GetCurrentView(view.Process{*retryProcess})
	if err != nil {
		return nil, err
	}

	return view, nil
}
Exemplo n.º 4
0
func getFurtherViewsFunc(retryProcess string) func() (*view.View, error) {
	return func() (*view.View, error) {
		view, err := client.GetCurrentView(view.Process{retryProcess})
		if err != nil {
			return nil, err
		}

		return view, nil
	}
}