func main() { programType := flag.String("type", "", "(c) controller or (t) task") job := flag.String("job", "", "job name") etcdURLs := []string{"http://localhost:4001"} flag.Parse() if *job == "" { log.Fatalf("Please specify a job name") } ntask := uint64(2) switch *programType { case "c": log.Printf("controller") controller := controller.New(*job, etcd.NewClient(etcdURLs), ntask) controller.Start() controller.WaitForJobDone() case "t": log.Printf("task") bootstrap := framework.NewBootStrap(*job, etcdURLs, createListener(), nil) taskBuilder := ®ression.SimpleTaskBuilder{ GDataChan: make(chan int32, 11), NumberOfIterations: 10, MasterConfig: map[string]string{"writefile": "result.txt"}, } bootstrap.SetTaskBuilder(taskBuilder) bootstrap.AddLinkage("Parents" : topo.NewTreeTopologyOfParent(2, ntask)) bootstrap.AddLinkage("Children" : topo.NewTreeTopologyOfChildren(2, ntask)) bootstrap.Start() default: log.Fatal("Please choose a type: (c) controller, (t) task") } }
func drive(t *testing.T, jobName string, etcds []string, taskBuilder taskgraph.TaskBuilder, topo map[string]taskgraph.Topology) { bootstrap := framework.NewBootStrap(jobName, etcds, createListener(t), nil) bootstrap.SetTaskBuilder(taskBuilder) for i, _ := range topo { bootstrap.AddLinkage(i, topo[i]) } bootstrap.Start() }
func main() { etcdUrlList := flag.String("etcd_urls", "", "ETCD server lists, sep by a comma.") jobName := flag.String("job_name", "bwmf", "Job name in etcd path.") jobType := flag.String("job_type", "c", "Job type, either 'c' for controller or 't' for task.") numTasks := flag.Int("num_tasks", 1, "Num of tasks.") taskConfigFile := flag.String("task_config", "", "Path to task config json file.") flag.Parse() if *jobName == "" { log.Fatal("Job name is required.") } crd, oErr := filesystem.NewLocalFSClient().OpenReadCloser(*taskConfigFile) if oErr != nil { log.Fatalf("Failed opening task config file. %s", oErr) } confData, rdErr := ioutil.ReadAll(crd) if rdErr != nil { log.Fatalf("Failed reading task config. %s", rdErr) } log.Printf("conf data: %s", confData) if *etcdUrlList == "" { log.Fatal("Please specify the etcd server urls.") } etcdUrls := strings.Split(*etcdUrlList, ",") log.Println("etcd urls: ", etcdUrls) topoMaster := topo.NewFullTopologyOfMaster(uint64(*numTasks)) topoNeighbors := topo.NewFullTopologyOfNeighbor(uint64(*numTasks)) switch *jobType { case "t": bootstrap := framework.NewBootStrap(*jobName, etcdUrls, createListener(), nil) taskBuilder := &bwmf.BWMFTaskBuilder{ NumOfTasks: uint64(*numTasks), ConfBytes: confData, } bootstrap.SetTaskBuilder(taskBuilder) bootstrap.AddLinkage("Master", topoMaster) bootstrap.AddLinkage("Neighbors", topoNeighbors) log.Println("Starting task..") bootstrap.Start() case "c": controller := controller.New(*jobName, etcd.NewClient(etcdUrls), uint64(*numTasks), []string{"Master", "Neighbors"}) controller.Start() log.Println("Controller started.") controller.WaitForJobDone() controller.Stop() default: log.Fatal("Please choose a type via '-jobtype': (c) controller, (t) task") } }