add pool stub, start blowing out deployment struct

This commit is contained in:
Dan Ballard 2015-04-06 23:19:31 -07:00
parent 5d1d80310e
commit 362474421d
5 changed files with 60 additions and 8 deletions

42
cmd/warrend/cmd_pool.go Normal file
View File

@ -0,0 +1,42 @@
package main
import (
//"github.com/dballard/warren/cmd/warrend/conf"
"github.com/dballard/warren/lib/warren"
"net"
"strings"
)
var poolUsage = `
pool [NAME] [LOW HIGH]
`
var poolCmd = &SockCommand{
Command: warren.Command{
Name: "pool",
Usage: poolUsage,
Summary: "Get/Set port pool range for deployment",
},
Run: poolRun,
}
// pool [name] -- get
// pool [name] [low] [high] -- set
func poolRun(cmd *SockCommand, c net.Conn, path string, args ...string) {
if len(args) > 0 && args[0] == "help" {
warren.WriteStringz(c, cmd.Usage)
return
}
// GET
if len(args) == 1 {
warren.WriteStringz(c, "Pool GET " + strings.Join(args, ", ") + "\n")
return
}
if len(args) == 3 {
warren.WriteStringz(c, "Pool SET\n")
return
}
warren.WriteStringz(c, cmd.Usage)
return
}

View File

@ -32,14 +32,24 @@ func (m *Msg) Call() error {
}
// Conf package - thread safe conf
// All write ops are public API functions
// All write ops are public API functions ( Msg.Call() )
// that internall use channels to thread safely queue writes
// all write ops cause FS conf writes so that state is preserved
// Reads return copies of data
type Pool struct {
High int
Low int
}
type Deployment struct {
Path string
Pool Pool
}
type Conf struct {
// name : path
Deployments map[string]string
Deployments map[string]Deployment
}
var conf *Conf = nil
@ -63,11 +73,11 @@ func loadConf() {
fmt.Println("Error parsing ", warren.WarrendConf, ": ", err)
}
if conf.Deployments == nil {
conf.Deployments = make(map[string]string)
conf.Deployments = make(map[string]Deployment)
}
// populate reverse map
for nick, dir := range conf.Deployments {
dirToNick[dir] = nick
for nick, dep := range conf.Deployments {
dirToNick[dep.Path] = nick
}
}
@ -90,6 +100,7 @@ func saveConf() error {
return nil
}
// TODO: return copies
func GetConf() Conf {
return *conf
}

View File

@ -10,8 +10,6 @@ import (
// reverse look up map
var dirToNick map[string]string = make(map[string]string)
// given a valid deployment, add it
// internal, thread unsafe
func addDeployment(d *Msg) error {
@ -47,7 +45,6 @@ func rmDeployment(d *Msg) error {
}
// Validate a deployment is ok to insert
// internal thread unsafe
func validateDeployment(d *Msg) error {
// check if exists
if _, ok := conf.Deployments[d.Args["Name"]]; ok {

1
cmd/warrend/conf/pool.go Normal file
View File

@ -0,0 +1 @@
package conf

View File

@ -133,6 +133,7 @@ func main() {
warren.RegisterCommand(listCmd)
warren.RegisterCommand(regCmd)
warren.RegisterCommand(unregCmd)
warren.RegisterCommand(poolCmd)
// Handle signals
c := make(chan os.Signal, 1)