Exemplo n.º 1
0
Arquivo: main.go Projeto: vmware/xenon
func main() {
	services := []struct {
		uri string
		svc host.Service
	}{
		// Examples
		{
			"/core/examples",
			host.NewFactoryServiceContext(&host.ExampleFactoryService{}),
		},
		// Examples
		{
			"/core/ping",
			host.NewPingService(),
		},
	}

	var err error

	flag.Parse()

	glog.Infof("Started with %s", os.Args[1:])

	h := host.NewServiceHost()
	err = h.Initialize(bindAddress.String())
	if err != nil {
		glog.Fatalf("Error initializing: %s\n", err)
	}

	ctx := operation.SetAuthorizationToken(context.Background(), authToken)
	_, err = host.GetServiceHostManagementState(ctx)
	if err != nil {
		glog.Fatalf("Error getting ServiceHostState: %s\n", err)
	}

	var ops []*operation.Operation
	for _, s := range services {
		op := operation.NewPost(ctx, uri.Extend(uri.Empty(), s.uri), nil)
		ops = append(ops, op)
		h.StartService(op, s.svc)
	}

	_, err = operation.Join(ops)
	if err != nil {
		glog.Fatalf("Error starting services: %s", err)
	}

	start(h)
}
Exemplo n.º 2
0
func NewServiceHost(t *testing.T) *ServiceHost {
	th := ServiceHost{
		ServiceHost: host.NewServiceHost(),

		t: t,
	}

	err := th.Initialize(fmt.Sprintf("%s:0", net.IPv4zero))
	if err != nil {
		t.Fatal(err)
	}

	// Set xenon flag so uri.WithLocalHost points to mock services
	hostURI := th.URI()
	flag.Set("xenon", hostURI.Host)

	th.doneCh = make(chan struct{})
	go func() {
		th.Start()
		close(th.doneCh)
	}()

	return &th
}