From 0c57e212ad19b746b50eb15b6892f5ca01f72e9b Mon Sep 17 00:00:00 2001 From: Dan Ballard Date: Tue, 21 Apr 2015 21:40:18 -0700 Subject: [PATCH] pool get --- cmd/warrend/cmd_list.go | 1 - cmd/warrend/cmd_pool.go | 9 +++++---- cmd/warrend/conf/conf.go | 9 ++++++++- cmd/warrend/main.go | 1 - 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/cmd/warrend/cmd_list.go b/cmd/warrend/cmd_list.go index 0773675..c9390eb 100644 --- a/cmd/warrend/cmd_list.go +++ b/cmd/warrend/cmd_list.go @@ -31,6 +31,5 @@ func listRun(cmd *SockCommand, writer *bufio.Writer, path string, args ...string fmt.Print("List\n") for name, dep := range conf.GetConf().Deployments { writer.WriteString(name+" (ports " + strconv.Itoa(dep.Pool.Low) +":"+strconv.Itoa(dep.Pool.High)+") : "+dep.Path+"\n") - fmt.Print(name+" (ports " + strconv.Itoa(dep.Pool.Low) +":"+strconv.Itoa(dep.Pool.High)+") : "+dep.Path+"\n") } } diff --git a/cmd/warrend/cmd_pool.go b/cmd/warrend/cmd_pool.go index cc49dde..51f958c 100644 --- a/cmd/warrend/cmd_pool.go +++ b/cmd/warrend/cmd_pool.go @@ -1,10 +1,10 @@ package main import ( - //"github.com/dballard/warren/cmd/warrend/conf" + "github.com/dballard/warren/cmd/warrend/conf" "github.com/dballard/warren/lib/warren" "bufio" - "strings" + "strconv" ) var poolUsage = ` @@ -23,14 +23,15 @@ var poolCmd = &SockCommand{ // pool [name] -- get // pool [name] [low] [high] -- set func poolRun(cmd *SockCommand, writer *bufio.Writer, path string, args ...string) { - if len(args) > 0 && args[0] == "help" { + if len(args) == 0 || args[0] == "" || (len(args) > 0 && args[0] == "help") { writer.WriteString(cmd.Usage) return } // GET if len(args) == 1 { - writer.WriteString("Pool GET " + strings.Join(args, ", ") + "\n") + deployment := conf.GetConfFor(args[0]) + writer.WriteString("Pool " + strconv.Itoa(deployment.Pool.Low) + " to " + strconv.Itoa(deployment.Pool.High)) return } if len(args) == 3 { diff --git a/cmd/warrend/conf/conf.go b/cmd/warrend/conf/conf.go index 8062985..a4f5af2 100644 --- a/cmd/warrend/conf/conf.go +++ b/cmd/warrend/conf/conf.go @@ -104,6 +104,14 @@ func GetConf() *Conf { return conf } +func GetConfFor(depName string) *Deployment { + deployment, ok := conf.Deployments[depName] + if !ok { + return nil + } + return &deployment +} + func Run() { loadConf() if conf == nil { @@ -131,5 +139,4 @@ func Run() { } m.reply <- err } - } diff --git a/cmd/warrend/main.go b/cmd/warrend/main.go index c31a664..e822fce 100644 --- a/cmd/warrend/main.go +++ b/cmd/warrend/main.go @@ -70,7 +70,6 @@ func sockCmdHandle(c net.Conn) { icmd.(*SockCommand).Exec(writer, args[0], args[2:]) writer.WriteByte(0) writer.Flush() - fmt.Println("flushed") } // determine if warrend is already running