mirror of
https://github.com/dragonheim/gagent.git
synced 2025-01-18 09:36:28 -08:00
Going to trigger a build and test on the cluster.
This commit is contained in:
parent
856cebb0dc
commit
802d1b0a48
4 changed files with 51 additions and 36 deletions
|
@ -11,6 +11,8 @@ trigger:
|
|||
branch:
|
||||
include:
|
||||
- issues/1
|
||||
- issues/3
|
||||
- issues/4
|
||||
exclude:
|
||||
- main
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ import (
|
|||
|
||||
// client "git.dragonheim.net/dragonheim/gagent/src/client"
|
||||
gr "git.dragonheim.net/dragonheim/gagent/src/router"
|
||||
// worker "git.dragonheim.net/dragonheim/gagent/src/worker"
|
||||
gw "git.dragonheim.net/dragonheim/gagent/src/worker"
|
||||
|
||||
docopt "github.com/aviddiviner/docopt-go"
|
||||
hclsimple "github.com/hashicorp/hcl/v2/hclsimple"
|
||||
|
@ -30,7 +30,6 @@ var exitCodes = struct {
|
|||
"AGENT_LOAD_FAILED": 4,
|
||||
"AGENT_MISSING_TAGS": 5,
|
||||
"NO_ROUTERS_DEFINED": 6,
|
||||
"NO_WORKERS_DEFINED": 6,
|
||||
"NO_WORKERS_DEFINED": 7,
|
||||
}}
|
||||
|
||||
|
@ -149,6 +148,12 @@ func main() {
|
|||
log.Printf("Arguments are %v\n", arguments)
|
||||
log.Printf("Configuration is %v\n", config)
|
||||
log.Printf("Running in router mode\n")
|
||||
|
||||
if len(config.Workers) == 0 {
|
||||
log.Printf("No workers defined.\n")
|
||||
os.Exit(exitCodes.m["NO_WORKERS_DEFINED"])
|
||||
}
|
||||
|
||||
go gr.Main(config)
|
||||
select {}
|
||||
|
||||
|
@ -161,8 +166,15 @@ func main() {
|
|||
*/
|
||||
log.Printf("Arguments are %v\n", arguments)
|
||||
log.Printf("Configuration is %v\n", config)
|
||||
// go worker.Main(config)
|
||||
// select {}
|
||||
log.Printf("Running in worker mode\n")
|
||||
|
||||
if len(config.Routers) == 0 {
|
||||
log.Printf("No routers defined.\n")
|
||||
os.Exit(exitCodes.m["NO_ROUTERS_DEFINED"])
|
||||
}
|
||||
|
||||
go gw.Main(config)
|
||||
select {}
|
||||
|
||||
case "setup":
|
||||
log.Printf("Running in setup mode\n")
|
||||
|
|
|
@ -5,8 +5,8 @@ type GagentConfig struct {
|
|||
Name string `hcl:"name,optional"`
|
||||
Mode string `hcl:"mode,attr"`
|
||||
UUID string `hcl:"uuid,optional"`
|
||||
ListenAddr string `hcl:"address,optional"`
|
||||
ListenPort int `hcl:"port,optional"`
|
||||
ListenAddr string `hcl:"listenaddr,optional"`
|
||||
ListenPort int `hcl:"listenport,optional"`
|
||||
Clients []*ClientDetails `hcl:"client,block"`
|
||||
Routers []*RouterDetails `hcl:"router,block"`
|
||||
Workers []*WorkerDetails `hcl:"worker,block"`
|
||||
|
@ -43,7 +43,7 @@ type RouterDetails struct {
|
|||
* which MQ router to send the agent's requests to.
|
||||
* This attempts to keep the routers unique globally.
|
||||
*/
|
||||
RouterID string `hcl:"routerid,attr"`
|
||||
RouterID string `hcl:"uuid,attr"`
|
||||
|
||||
/*
|
||||
* This is the IP Address and port that the router
|
||||
|
@ -75,7 +75,7 @@ type WorkerDetails struct {
|
|||
* send agents to. This attempts to keep the
|
||||
* workers unique globally.
|
||||
*/
|
||||
WorkerID string `hcl:"workerid,attr"`
|
||||
WorkerID string `hcl:"uuid,attr"`
|
||||
|
||||
/*
|
||||
* These tags will be passed to the router upon
|
||||
|
|
|
@ -2,7 +2,7 @@ package worker
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
// "log"
|
||||
"log"
|
||||
"math/rand"
|
||||
"time"
|
||||
|
||||
|
@ -23,34 +23,8 @@ func pop(msg []string) (head, tail []string) {
|
|||
return
|
||||
}
|
||||
|
||||
// Main is the initiation function for a Worker
|
||||
func Main(config gs.GagentConfig) {
|
||||
// Frontend socket talks to clients over TCP
|
||||
frontend, _ := zmq.NewSocket(zmq.ROUTER)
|
||||
fmt.Printf("Running in worker mode\n")
|
||||
|
||||
defer frontend.Close()
|
||||
connectString := fmt.Sprintf("tcp://%s", config.Routers[0].RouterAddr)
|
||||
frontend.Bind(connectString)
|
||||
|
||||
// Backend socket talks to workers over inproc
|
||||
backend, _ := zmq.NewSocket(zmq.DEALER)
|
||||
defer backend.Close()
|
||||
backend.Bind("inproc://backend")
|
||||
|
||||
// Launch pool of agent handlers
|
||||
for i := 0; i < 5; i++ {
|
||||
go agentHandler(i)
|
||||
}
|
||||
|
||||
// Connect backend to frontend via a proxy
|
||||
// err := zmq.Proxy(frontend, backend, nil)
|
||||
// log.Fatalln("Proxy interrupted:", err)
|
||||
}
|
||||
|
||||
// Each worker task works on one request at a time and sends a random number
|
||||
// of replies back, with random delays between replies:
|
||||
|
||||
func agentHandler(workerNum int) {
|
||||
interp := picol.InitInterp()
|
||||
interp.RegisterCoreCommands()
|
||||
|
@ -70,8 +44,35 @@ func agentHandler(workerNum int) {
|
|||
// Sleep for some fraction of a second
|
||||
time.Sleep(time.Duration(rand.Intn(1000)+1) * time.Millisecond)
|
||||
|
||||
fmt.Println(fmt.Sprintf("Worker %d: %s", workerNum, identity))
|
||||
log.Printf(fmt.Sprintf("Worker %d: %s\n", workerNum, identity))
|
||||
worker.SendMessage(identity, content)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Main is the initiation function for a Worker
|
||||
func Main(config gs.GagentConfig) {
|
||||
// Frontend socket talks to clients over TCP
|
||||
frontend, _ := zmq.NewSocket(zmq.ROUTER)
|
||||
log.Printf("Starting worker\n")
|
||||
|
||||
defer frontend.Close()
|
||||
log.Printf("Attempting to connect to: %s(%s)\n", config.Routers[0].RouterName, config.Routers[0].RouterAddr)
|
||||
connectString := fmt.Sprintf("tcp://%s", config.Routers[0].RouterAddr)
|
||||
frontend.Bind(connectString)
|
||||
|
||||
// Backend socket talks to workers over inproc
|
||||
backend, _ := zmq.NewSocket(zmq.DEALER)
|
||||
defer backend.Close()
|
||||
backend.Bind("inproc://backend")
|
||||
|
||||
// Launch pool of agent handlers
|
||||
for i := 0; i < 5; i++ {
|
||||
go agentHandler(i)
|
||||
}
|
||||
|
||||
// Connect backend to frontend via a proxy
|
||||
// err := zmq.Proxy(frontend, backend, nil)
|
||||
// log.Fatalln("Proxy interrupted:", err)
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue