Ejemplo n.º 1
0
// NewServer creates and initializes a new instance of Server.
func NewServer(config *Config) (*Server, error) {
	if err := config.Validate(); err != nil {
		return nil, err
	}

	var err error
	s := &Server{
		config: config,
	}

	// Internal socket for requests from providers
	internalSocket := filepath.Join(
		config.SocketDir(),
		"coordinator",
		config.ServiceName()+".sock")
	s.internal = acomm.NewUnixListener(internalSocket, 0)

	// External server for requests from outside
	mux := http.NewServeMux()
	mux.HandleFunc("/stream", acomm.ProxyStreamHandler)
	mux.HandleFunc("/", s.externalHandler)
	s.external = &graceful.Server{
		Server: &http.Server{
			Addr:    fmt.Sprintf(":%d", config.ExternalPort()),
			Handler: mux,
		},
		NoSignalHandling: true,
	}

	// Response socket for proxied requests
	responseSocket := filepath.Join(
		config.SocketDir(),
		"response",
		config.ServiceName()+".sock")

	streamURL, err := url.ParseRequestURI(
		fmt.Sprintf("http://%s:%d/stream", getLocalIP(), config.ExternalPort()))
	if err != nil {
		log.WithFields(log.Fields{
			"error": err,
		}).Error("failed to generate stream url")
	}
	s.proxy, err = acomm.NewTracker(responseSocket, streamURL, config.RequestTimeout())
	if err != nil {
		return nil, err
	}
	log.WithFields(log.Fields{
		"response": responseSocket,
		"stream":   streamURL.String(),
		"internal": internalSocket,
		"external": fmt.Sprintf(":%d", config.ExternalPort()),
	}).Info("server addresses")

	return s, nil
}
Ejemplo n.º 2
0
func (s *TrackerTestSuite) SetupTest() {
	var err error

	s.Request, err = acomm.NewRequest("foobar", s.RespServer.URL, nil, nil, nil)
	s.Require().NoError(err, "request should be valid")

	streamAddr, _ := url.ParseRequestURI(s.StreamServer.URL)
	s.Tracker, err = acomm.NewTracker("", streamAddr, 0)
	s.Require().NoError(err, "failed to create new Tracker")
	s.Require().NotNil(s.Tracker, "failed to create new Tracker")
}
Ejemplo n.º 3
0
// NewServer creates and initializes a new Server.
func NewServer(config *Config) (*Server, error) {
	if err := config.Validate(); err != nil {
		return nil, err
	}

	responseSocket := filepath.Join(
		config.SocketDir(),
		"response",
		config.ServiceName()+".sock")
	tracker, err := acomm.NewTracker(responseSocket, nil, config.RequestTimeout())
	if err != nil {
		return nil, err
	}

	return &Server{
		config:  config,
		tasks:   make(map[string]*task),
		tracker: tracker,
	}, nil
}