mirror of
https://github.com/minio/minio.git
synced 2024-12-24 06:05:55 -05:00
Merge pull request #739 from harshavardhana/pr_out_renaming_nimble_to_minhttp
This commit is contained in:
commit
4c95775864
@ -14,12 +14,12 @@
|
||||
* 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
|
||||
package nimble
|
||||
package minhttp
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
@ -40,7 +40,7 @@ type app struct {
|
||||
servers []*http.Server
|
||||
listeners []net.Listener
|
||||
sds []httpdown.Server
|
||||
net *nimbleNet
|
||||
net *minNet
|
||||
errors chan error
|
||||
}
|
||||
|
||||
@ -128,7 +128,7 @@ func ListenAndServe(servers ...*http.Server) error {
|
||||
servers: servers,
|
||||
listeners: make([]net.Listener, 0, len(servers)),
|
||||
sds: make([]httpdown.Server, 0, len(servers)),
|
||||
net: &nimbleNet{},
|
||||
net: &minNet{},
|
||||
errors: make(chan error, 1+(len(servers)*2)),
|
||||
}
|
||||
|
@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package nimble
|
||||
package minhttp
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@ -28,7 +28,7 @@ import (
|
||||
"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
|
||||
|
||||
@ -50,17 +50,17 @@ const (
|
||||
// it at startup.
|
||||
var originalWD, _ = os.Getwd()
|
||||
|
||||
// nimbleNet provides the family of Listen functions and maintains the associated
|
||||
// state. Typically you will have only once instance of nimbleNet per application.
|
||||
type nimbleNet struct {
|
||||
// minNet provides the family of Listen functions and maintains the associated
|
||||
// state. Typically you will have only once instance of minNet per application.
|
||||
type minNet struct {
|
||||
inheritedListeners []net.Listener
|
||||
activeListeners []net.Listener
|
||||
mutex sync.Mutex
|
||||
inheritOnce sync.Once
|
||||
}
|
||||
|
||||
// nimbleAddr simple wrapper over net.Addr interface to implement IsEqual()
|
||||
type nimbleAddr struct {
|
||||
// minAddr simple wrapper over net.Addr interface to implement IsEqual()
|
||||
type minAddr struct {
|
||||
net.Addr
|
||||
}
|
||||
|
||||
@ -70,7 +70,7 @@ type fileListener interface {
|
||||
}
|
||||
|
||||
// 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
|
||||
n.inheritOnce.Do(func() {
|
||||
n.mutex.Lock()
|
||||
@ -108,7 +108,7 @@ func (n *nimbleNet) getInheritedListeners() error {
|
||||
// a stream-oriented network: "tcp", "tcp4", "tcp6", "unix" or "unixpacket". It
|
||||
// returns an inherited net.Listener for the matching network and address, or
|
||||
// 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 {
|
||||
default:
|
||||
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
|
||||
// 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.
|
||||
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 {
|
||||
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
|
||||
continue
|
||||
}
|
||||
equal := nimbleAddr{l.Addr()}.IsEqual(laddr)
|
||||
equal := minAddr{l.Addr()}.IsEqual(laddr)
|
||||
if equal {
|
||||
n.inheritedListeners[i] = nil
|
||||
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
|
||||
// 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.
|
||||
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 {
|
||||
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
|
||||
continue
|
||||
}
|
||||
equal := nimbleAddr{l.Addr()}.IsEqual(laddr)
|
||||
equal := minAddr{l.Addr()}.IsEqual(laddr)
|
||||
if equal {
|
||||
n.inheritedListeners[i] = nil
|
||||
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.
|
||||
func (n *nimbleNet) getActiveListeners() ([]net.Listener, error) {
|
||||
func (n *minNet) getActiveListeners() ([]net.Listener, error) {
|
||||
n.mutex.Lock()
|
||||
defer n.mutex.Unlock()
|
||||
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
|
||||
func (n1 nimbleAddr) IsEqual(n2 net.Addr) bool {
|
||||
func (n1 minAddr) IsEqual(n2 net.Addr) bool {
|
||||
if n1.Network() != n2.Network() {
|
||||
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
|
||||
// deployed binary to be started. It returns the pid of the newly started
|
||||
// process when successful.
|
||||
func (n *nimbleNet) StartProcess() (int, error) {
|
||||
func (n *minNet) StartProcess() (int, error) {
|
||||
listeners, err := n.getActiveListeners()
|
||||
if err != nil {
|
||||
return 0, iodine.New(err, nil)
|
@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package nimble
|
||||
package minhttp
|
||||
|
||||
import (
|
||||
"os"
|
||||
@ -33,19 +33,19 @@ var _ = Suite(&MySuite{})
|
||||
|
||||
func (s *MySuite) TestEmptyCountEnvVariable(c *C) {
|
||||
os.Setenv(envCountKey, "")
|
||||
n := &nimbleNet{}
|
||||
n := &minNet{}
|
||||
c.Assert(n.getInheritedListeners(), IsNil)
|
||||
}
|
||||
|
||||
func (s *MySuite) TestZeroCountEnvVariable(c *C) {
|
||||
os.Setenv(envCountKey, "0")
|
||||
n := &nimbleNet{}
|
||||
n := &minNet{}
|
||||
c.Assert(n.getInheritedListeners(), IsNil)
|
||||
}
|
||||
|
||||
func (s *MySuite) TestInvalidCountEnvVariable(c *C) {
|
||||
os.Setenv(envCountKey, "a")
|
||||
n := &nimbleNet{}
|
||||
n := &minNet{}
|
||||
expected := regexp.MustCompile("^found invalid count value: LISTEN_FDS=a$")
|
||||
err := n.getInheritedListeners()
|
||||
c.Assert(err, Not(IsNil))
|
||||
@ -54,7 +54,7 @@ func (s *MySuite) TestInvalidCountEnvVariable(c *C) {
|
||||
|
||||
func (s *MySuite) TestInheritErrorOnListenTCPWithInvalidCount(c *C) {
|
||||
os.Setenv(envCountKey, "a")
|
||||
n := &nimbleNet{}
|
||||
n := &minNet{}
|
||||
expected := regexp.MustCompile("^found invalid count value: LISTEN_FDS=a$")
|
||||
_, err := n.Listen("tcp", ":0")
|
||||
c.Assert(err, Not(IsNil))
|
||||
@ -63,7 +63,7 @@ func (s *MySuite) TestInheritErrorOnListenTCPWithInvalidCount(c *C) {
|
||||
|
||||
func (s *MySuite) TestInvalidNetwork(c *C) {
|
||||
os.Setenv(envCountKey, "")
|
||||
n := &nimbleNet{}
|
||||
n := &minNet{}
|
||||
_, err := n.Listen("foo", "")
|
||||
c.Assert(err, Not(IsNil))
|
||||
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) {
|
||||
os.Setenv(envCountKey, "")
|
||||
n := &nimbleNet{}
|
||||
n := &minNet{}
|
||||
_, err := n.Listen("tcp", "abc")
|
||||
c.Assert(err, Not(IsNil))
|
||||
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/server/api"
|
||||
"github.com/minio/minio/pkg/server/nimble"
|
||||
"github.com/minio/minio/pkg/server/minhttp"
|
||||
)
|
||||
|
||||
// getAPI server instance
|
||||
@ -114,7 +114,7 @@ func StartServices(conf api.Config) error {
|
||||
// start ticket master
|
||||
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 nil
|
||||
|
Loading…
Reference in New Issue
Block a user