Example #1
0
func newVISGHSExecutor() *ghsvisExecutor {
	log.Infoln("Initializing the VISGHS Executor...", *tracerAddr)
	c, err := tracer.NewGRPCDisplayClient(*tracerAddr, grpc.WithInsecure())
	if err != nil {
		log.Fatalf("failed to connect: %v", err)
	}
	t := tracer.New(c)

	// Establish gRPC on the deisgnated port
	lis, err := net.Listen("tcp", ":0")
	if err != nil {
		log.Fatalf("grpc failed to listen: %v", err)
	}
	grpcServer := grpc.NewServer()

	// build command executor
	nexec := prepareExecutorInfo(lis.Addr())
	s := newvisghsScheduler(nexec)

	t := tracer.NewHTTPDisplay(http.DefaultServeMux, s.OnRun)
	server := tracer.NewGRPCServer(t)
	tracer.RegisterTraceServiceServer(grpcServer, server)
	go grpcServer.Serve(lis)
	time.Sleep(2 * time.Second)
	go http.ListenAndServe(":12345", nil)

	return &ghsvisExecutor{tasksLaunched: 0, Tracer: t}
}
Example #2
0
func setupGHS(mux *http.ServeMux) {
	s := state{}

	t := tracer.NewHTTPDisplay(mux, s.OnRun)

	s.wg = &sync.WaitGroup{}

	count := 25
	s.wg.Add(count)
	nodes := make([]*graphalg.Node, 0)
	s.ghs = make([]*ghs.State, 0)

	for i := 0; i < count; i++ {
		n := &graphalg.Node{
			ID:     graphalg.NodeID(fmt.Sprintf("n%v", i+1)),
			Tracer: t,
		}
		nodes = append(nodes, n)
		s.ghs = append(s.ghs, &ghs.State{Node: n})
	}

	for i := 0; i < count; i++ {
		for j := i + 1; j < count; j++ {
			log.Println("join", i, j)
			w := rand.NormFloat64()*1.0 + 4.0
			nodes[i].Join(nodes[j], w, graphalg.MakeChanPair)
		}
	}

	for _, g := range s.ghs {
		go func(g *ghs.State) {
			n := g.Node
			n.NodeUpdate("from node")
			for _, e := range n.Edges() {
				e.EdgeUpdate()
			}

			graphalg.Run(g, s.wg.Done)
		}(g)
	}

	log.Println("running")
}
Example #3
0
func main() {
	if *ghsNode {
		ghsNodeMain()
		return
	}

	// Allocate a port for GRPC
	lis, err := net.Listen("tcp", ":0")
	if err != nil {
		log.Fatalf("grpc failed to listen: %v", err)
	}
	grpcServer := grpc.NewServer()

	// build command executor
	nexec := prepareExecutorInfo(lis.Addr())
	s := newvisghsScheduler(nexec)

	t := tracer.NewHTTPDisplay(http.DefaultServeMux, s.OnRun)
	server := tracer.NewGRPCServer(t)
	tracer.RegisterTraceServiceServer(grpcServer, server)
	go grpcServer.Serve(lis)
	time.Sleep(2 * time.Second)
	go http.ListenAndServe(":12345", nil)

	// the framework
	fwinfo := &mesos.FrameworkInfo{
		User: proto.String(""), // Mesos-go will fill in user.
		Name: proto.String("visghs"),
	}

	cred := (*mesos.Credential)(nil)
	if *mesosAuthPrincipal != "" {
		fwinfo.Principal = proto.String(*mesosAuthPrincipal)
		cred = &mesos.Credential{
			Principal: proto.String(*mesosAuthPrincipal),
		}
		if *mesosAuthSecretFile != "" {
			_, err := os.Stat(*mesosAuthSecretFile)
			if err != nil {
				log.Fatal("missing secret file: ", err.Error())
			}
			secret, err := ioutil.ReadFile(*mesosAuthSecretFile)
			if err != nil {
				log.Fatal("failed to read secret file: ", err.Error())
			}
			cred.Secret = proto.String(string(secret))
		}
	}

	bindingAddress := parseIP(*address)
	config := sched.DriverConfig{
		Scheduler:      s,
		Framework:      fwinfo,
		Master:         *master,
		Credential:     cred,
		BindingAddress: bindingAddress,
		WithAuthContext: func(ctx context.Context) context.Context {
			ctx = auth.WithLoginProvider(ctx, *authProvider)
			ctx = sasl.WithBindingAddress(ctx, bindingAddress)
			return ctx
		},
	}
	driver, err := sched.NewMesosSchedulerDriver(config)

	if err != nil {
		log.Errorln("Unable to create a SchedulerDriver ", err.Error())
	}

	if stat, err := driver.Run(); err != nil {
		log.Infof("Framework stopped with status %s and error: %s\n", stat.String(), err.Error())
		time.Sleep(2 * time.Second)
		os.Exit(1)
	}
	log.Infof("framework terminating")
}