Merge pull request #739 from harshavardhana/pr_out_renaming_nimble_to_minhttp

master
Harshavardhana 10 years ago
commit 4c95775864
  1. 0
      pkg/server/minhttp/LICENSE.Facebook
  2. 0
      pkg/server/minhttp/LICENSE.Minio
  3. 10
      pkg/server/minhttp/http.go
  4. 32
      pkg/server/minhttp/net.go
  5. 14
      pkg/server/minhttp/net_test.go
  6. 4
      pkg/server/server.go

@ -14,12 +14,12 @@
* limitations under the License. * limitations under the License.
*/ */
// Package nimble provides easy to use graceful restart for a set of HTTP services // Package minhttp provides easy to use graceful restart for a set of HTTP services
// //
// This package originally from https://github.com/facebookgo/grace // This package is a fork from https://github.com/facebookgo/grace
// //
// Re-licensing with Apache License 2.0, with code modifications // Re-licensing with Apache License 2.0, with code modifications
package nimble package minhttp
import ( import (
"crypto/tls" "crypto/tls"
@ -40,7 +40,7 @@ type app struct {
servers []*http.Server servers []*http.Server
listeners []net.Listener listeners []net.Listener
sds []httpdown.Server sds []httpdown.Server
net *nimbleNet net *minNet
errors chan error errors chan error
} }
@ -128,7 +128,7 @@ func ListenAndServe(servers ...*http.Server) error {
servers: servers, servers: servers,
listeners: make([]net.Listener, 0, len(servers)), listeners: make([]net.Listener, 0, len(servers)),
sds: make([]httpdown.Server, 0, len(servers)), sds: make([]httpdown.Server, 0, len(servers)),
net: &nimbleNet{}, net: &minNet{},
errors: make(chan error, 1+(len(servers)*2)), errors: make(chan error, 1+(len(servers)*2)),
} }

@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
package nimble package minhttp
import ( import (
"fmt" "fmt"
@ -28,7 +28,7 @@ import (
"github.com/minio/minio/pkg/iodine" "github.com/minio/minio/pkg/iodine"
) )
// This package originally from https://github.com/facebookgo/grace // This package is a fork https://github.com/facebookgo/grace
// //
// Re-licensing with Apache License 2.0, with code modifications // Re-licensing with Apache License 2.0, with code modifications
@ -50,17 +50,17 @@ const (
// it at startup. // it at startup.
var originalWD, _ = os.Getwd() var originalWD, _ = os.Getwd()
// nimbleNet provides the family of Listen functions and maintains the associated // minNet provides the family of Listen functions and maintains the associated
// state. Typically you will have only once instance of nimbleNet per application. // state. Typically you will have only once instance of minNet per application.
type nimbleNet struct { type minNet struct {
inheritedListeners []net.Listener inheritedListeners []net.Listener
activeListeners []net.Listener activeListeners []net.Listener
mutex sync.Mutex mutex sync.Mutex
inheritOnce sync.Once inheritOnce sync.Once
} }
// nimbleAddr simple wrapper over net.Addr interface to implement IsEqual() // minAddr simple wrapper over net.Addr interface to implement IsEqual()
type nimbleAddr struct { type minAddr struct {
net.Addr net.Addr
} }
@ -70,7 +70,7 @@ type fileListener interface {
} }
// getInheritedListeners - look for LISTEN_FDS in environment variables and populate listeners accordingly // getInheritedListeners - look for LISTEN_FDS in environment variables and populate listeners accordingly
func (n *nimbleNet) getInheritedListeners() error { func (n *minNet) getInheritedListeners() error {
var retErr error var retErr error
n.inheritOnce.Do(func() { n.inheritOnce.Do(func() {
n.mutex.Lock() n.mutex.Lock()
@ -108,7 +108,7 @@ func (n *nimbleNet) getInheritedListeners() error {
// a stream-oriented network: "tcp", "tcp4", "tcp6", "unix" or "unixpacket". It // a stream-oriented network: "tcp", "tcp4", "tcp6", "unix" or "unixpacket". It
// returns an inherited net.Listener for the matching network and address, or // returns an inherited net.Listener for the matching network and address, or
// creates a new one using net.Listen() // creates a new one using net.Listen()
func (n *nimbleNet) Listen(nett, laddr string) (net.Listener, error) { func (n *minNet) Listen(nett, laddr string) (net.Listener, error) {
switch nett { switch nett {
default: default:
return nil, net.UnknownNetworkError(nett) return nil, net.UnknownNetworkError(nett)
@ -130,7 +130,7 @@ func (n *nimbleNet) Listen(nett, laddr string) (net.Listener, error) {
// ListenTCP announces on the local network address laddr. The network net must // ListenTCP announces on the local network address laddr. The network net must
// be: "tcp", "tcp4" or "tcp6". It returns an inherited net.Listener for the // be: "tcp", "tcp4" or "tcp6". It returns an inherited net.Listener for the
// matching network and address, or creates a new one using net.ListenTCP. // matching network and address, or creates a new one using net.ListenTCP.
func (n *nimbleNet) ListenTCP(nett string, laddr *net.TCPAddr) (*net.TCPListener, error) { func (n *minNet) ListenTCP(nett string, laddr *net.TCPAddr) (*net.TCPListener, error) {
if err := n.getInheritedListeners(); err != nil { if err := n.getInheritedListeners(); err != nil {
return nil, iodine.New(err, nil) return nil, iodine.New(err, nil)
} }
@ -143,7 +143,7 @@ func (n *nimbleNet) ListenTCP(nett string, laddr *net.TCPAddr) (*net.TCPListener
if l == nil { // we nil used inherited listeners if l == nil { // we nil used inherited listeners
continue continue
} }
equal := nimbleAddr{l.Addr()}.IsEqual(laddr) equal := minAddr{l.Addr()}.IsEqual(laddr)
if equal { if equal {
n.inheritedListeners[i] = nil n.inheritedListeners[i] = nil
n.activeListeners = append(n.activeListeners, l) n.activeListeners = append(n.activeListeners, l)
@ -163,7 +163,7 @@ func (n *nimbleNet) ListenTCP(nett string, laddr *net.TCPAddr) (*net.TCPListener
// ListenUnix announces on the local network address laddr. The network net // ListenUnix announces on the local network address laddr. The network net
// must be a: "unix" or "unixpacket". It returns an inherited net.Listener for // must be a: "unix" or "unixpacket". It returns an inherited net.Listener for
// the matching network and address, or creates a new one using net.ListenUnix. // the matching network and address, or creates a new one using net.ListenUnix.
func (n *nimbleNet) ListenUnix(nett string, laddr *net.UnixAddr) (*net.UnixListener, error) { func (n *minNet) ListenUnix(nett string, laddr *net.UnixAddr) (*net.UnixListener, error) {
if err := n.getInheritedListeners(); err != nil { if err := n.getInheritedListeners(); err != nil {
return nil, iodine.New(err, nil) return nil, iodine.New(err, nil)
} }
@ -176,7 +176,7 @@ func (n *nimbleNet) ListenUnix(nett string, laddr *net.UnixAddr) (*net.UnixListe
if l == nil { // we nil used inherited listeners if l == nil { // we nil used inherited listeners
continue continue
} }
equal := nimbleAddr{l.Addr()}.IsEqual(laddr) equal := minAddr{l.Addr()}.IsEqual(laddr)
if equal { if equal {
n.inheritedListeners[i] = nil n.inheritedListeners[i] = nil
n.activeListeners = append(n.activeListeners, l) n.activeListeners = append(n.activeListeners, l)
@ -194,7 +194,7 @@ func (n *nimbleNet) ListenUnix(nett string, laddr *net.UnixAddr) (*net.UnixListe
} }
// activeListeners returns a snapshot copy of the active listeners. // activeListeners returns a snapshot copy of the active listeners.
func (n *nimbleNet) getActiveListeners() ([]net.Listener, error) { func (n *minNet) getActiveListeners() ([]net.Listener, error) {
n.mutex.Lock() n.mutex.Lock()
defer n.mutex.Unlock() defer n.mutex.Unlock()
ls := make([]net.Listener, len(n.activeListeners)) ls := make([]net.Listener, len(n.activeListeners))
@ -203,7 +203,7 @@ func (n *nimbleNet) getActiveListeners() ([]net.Listener, error) {
} }
// IsEqual is synonymous with IP.IsEqual() method, here IsEqual matches net.Addr instead of net.IP // IsEqual is synonymous with IP.IsEqual() method, here IsEqual matches net.Addr instead of net.IP
func (n1 nimbleAddr) IsEqual(n2 net.Addr) bool { func (n1 minAddr) IsEqual(n2 net.Addr) bool {
if n1.Network() != n2.Network() { if n1.Network() != n2.Network() {
return false return false
} }
@ -228,7 +228,7 @@ func (n1 nimbleAddr) IsEqual(n2 net.Addr) bool {
// arguments as when it was originally started. This allows for a newly // arguments as when it was originally started. This allows for a newly
// deployed binary to be started. It returns the pid of the newly started // deployed binary to be started. It returns the pid of the newly started
// process when successful. // process when successful.
func (n *nimbleNet) StartProcess() (int, error) { func (n *minNet) StartProcess() (int, error) {
listeners, err := n.getActiveListeners() listeners, err := n.getActiveListeners()
if err != nil { if err != nil {
return 0, iodine.New(err, nil) return 0, iodine.New(err, nil)

@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
package nimble package minhttp
import ( import (
"os" "os"
@ -33,19 +33,19 @@ var _ = Suite(&MySuite{})
func (s *MySuite) TestEmptyCountEnvVariable(c *C) { func (s *MySuite) TestEmptyCountEnvVariable(c *C) {
os.Setenv(envCountKey, "") os.Setenv(envCountKey, "")
n := &nimbleNet{} n := &minNet{}
c.Assert(n.getInheritedListeners(), IsNil) c.Assert(n.getInheritedListeners(), IsNil)
} }
func (s *MySuite) TestZeroCountEnvVariable(c *C) { func (s *MySuite) TestZeroCountEnvVariable(c *C) {
os.Setenv(envCountKey, "0") os.Setenv(envCountKey, "0")
n := &nimbleNet{} n := &minNet{}
c.Assert(n.getInheritedListeners(), IsNil) c.Assert(n.getInheritedListeners(), IsNil)
} }
func (s *MySuite) TestInvalidCountEnvVariable(c *C) { func (s *MySuite) TestInvalidCountEnvVariable(c *C) {
os.Setenv(envCountKey, "a") os.Setenv(envCountKey, "a")
n := &nimbleNet{} n := &minNet{}
expected := regexp.MustCompile("^found invalid count value: LISTEN_FDS=a$") expected := regexp.MustCompile("^found invalid count value: LISTEN_FDS=a$")
err := n.getInheritedListeners() err := n.getInheritedListeners()
c.Assert(err, Not(IsNil)) c.Assert(err, Not(IsNil))
@ -54,7 +54,7 @@ func (s *MySuite) TestInvalidCountEnvVariable(c *C) {
func (s *MySuite) TestInheritErrorOnListenTCPWithInvalidCount(c *C) { func (s *MySuite) TestInheritErrorOnListenTCPWithInvalidCount(c *C) {
os.Setenv(envCountKey, "a") os.Setenv(envCountKey, "a")
n := &nimbleNet{} n := &minNet{}
expected := regexp.MustCompile("^found invalid count value: LISTEN_FDS=a$") expected := regexp.MustCompile("^found invalid count value: LISTEN_FDS=a$")
_, err := n.Listen("tcp", ":0") _, err := n.Listen("tcp", ":0")
c.Assert(err, Not(IsNil)) c.Assert(err, Not(IsNil))
@ -63,7 +63,7 @@ func (s *MySuite) TestInheritErrorOnListenTCPWithInvalidCount(c *C) {
func (s *MySuite) TestInvalidNetwork(c *C) { func (s *MySuite) TestInvalidNetwork(c *C) {
os.Setenv(envCountKey, "") os.Setenv(envCountKey, "")
n := &nimbleNet{} n := &minNet{}
_, err := n.Listen("foo", "") _, err := n.Listen("foo", "")
c.Assert(err, Not(IsNil)) c.Assert(err, Not(IsNil))
c.Assert(regexp.MustCompile("^unknown network foo$").MatchString(iodine.ToError(err).Error()), Equals, true) c.Assert(regexp.MustCompile("^unknown network foo$").MatchString(iodine.ToError(err).Error()), Equals, true)
@ -71,7 +71,7 @@ func (s *MySuite) TestInvalidNetwork(c *C) {
func (s *MySuite) TestInvalidTcpAddr(c *C) { func (s *MySuite) TestInvalidTcpAddr(c *C) {
os.Setenv(envCountKey, "") os.Setenv(envCountKey, "")
n := &nimbleNet{} n := &minNet{}
_, err := n.Listen("tcp", "abc") _, err := n.Listen("tcp", "abc")
c.Assert(err, Not(IsNil)) c.Assert(err, Not(IsNil))
c.Assert(regexp.MustCompile("^missing port in address abc$").MatchString(iodine.ToError(err).Error()), Equals, true) c.Assert(regexp.MustCompile("^missing port in address abc$").MatchString(iodine.ToError(err).Error()), Equals, true)

@ -26,7 +26,7 @@ import (
"github.com/minio/minio/pkg/iodine" "github.com/minio/minio/pkg/iodine"
"github.com/minio/minio/pkg/server/api" "github.com/minio/minio/pkg/server/api"
"github.com/minio/minio/pkg/server/nimble" "github.com/minio/minio/pkg/server/minhttp"
) )
// getAPI server instance // getAPI server instance
@ -114,7 +114,7 @@ func StartServices(conf api.Config) error {
// start ticket master // start ticket master
go startTM(minioAPI) go startTM(minioAPI)
if err := nimble.ListenAndServe(apiServer, rpcServer); err != nil { if err := minhttp.ListenAndServe(apiServer, rpcServer); err != nil {
return iodine.New(err, nil) return iodine.New(err, nil)
} }
return nil return nil

Loading…
Cancel
Save