mirror of
https://github.com/dragonheim/gagent.git
synced 2025-04-26 13:58:59 -07: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:
|
branch:
|
||||||
include:
|
include:
|
||||||
- issues/1
|
- issues/1
|
||||||
|
- issues/3
|
||||||
|
- issues/4
|
||||||
exclude:
|
exclude:
|
||||||
- main
|
- main
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@ import (
|
||||||
|
|
||||||
// client "git.dragonheim.net/dragonheim/gagent/src/client"
|
// client "git.dragonheim.net/dragonheim/gagent/src/client"
|
||||||
gr "git.dragonheim.net/dragonheim/gagent/src/router"
|
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"
|
docopt "github.com/aviddiviner/docopt-go"
|
||||||
hclsimple "github.com/hashicorp/hcl/v2/hclsimple"
|
hclsimple "github.com/hashicorp/hcl/v2/hclsimple"
|
||||||
|
@ -30,7 +30,6 @@ var exitCodes = struct {
|
||||||
"AGENT_LOAD_FAILED": 4,
|
"AGENT_LOAD_FAILED": 4,
|
||||||
"AGENT_MISSING_TAGS": 5,
|
"AGENT_MISSING_TAGS": 5,
|
||||||
"NO_ROUTERS_DEFINED": 6,
|
"NO_ROUTERS_DEFINED": 6,
|
||||||
"NO_WORKERS_DEFINED": 6,
|
|
||||||
"NO_WORKERS_DEFINED": 7,
|
"NO_WORKERS_DEFINED": 7,
|
||||||
}}
|
}}
|
||||||
|
|
||||||
|
@ -149,6 +148,12 @@ func main() {
|
||||||
log.Printf("Arguments are %v\n", arguments)
|
log.Printf("Arguments are %v\n", arguments)
|
||||||
log.Printf("Configuration is %v\n", config)
|
log.Printf("Configuration is %v\n", config)
|
||||||
log.Printf("Running in router mode\n")
|
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)
|
go gr.Main(config)
|
||||||
select {}
|
select {}
|
||||||
|
|
||||||
|
@ -161,8 +166,15 @@ func main() {
|
||||||
*/
|
*/
|
||||||
log.Printf("Arguments are %v\n", arguments)
|
log.Printf("Arguments are %v\n", arguments)
|
||||||
log.Printf("Configuration is %v\n", config)
|
log.Printf("Configuration is %v\n", config)
|
||||||
// go worker.Main(config)
|
log.Printf("Running in worker mode\n")
|
||||||
// select {}
|
|
||||||
|
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":
|
case "setup":
|
||||||
log.Printf("Running in setup mode\n")
|
log.Printf("Running in setup mode\n")
|
||||||
|
|
|
@ -5,8 +5,8 @@ type GagentConfig struct {
|
||||||
Name string `hcl:"name,optional"`
|
Name string `hcl:"name,optional"`
|
||||||
Mode string `hcl:"mode,attr"`
|
Mode string `hcl:"mode,attr"`
|
||||||
UUID string `hcl:"uuid,optional"`
|
UUID string `hcl:"uuid,optional"`
|
||||||
ListenAddr string `hcl:"address,optional"`
|
ListenAddr string `hcl:"listenaddr,optional"`
|
||||||
ListenPort int `hcl:"port,optional"`
|
ListenPort int `hcl:"listenport,optional"`
|
||||||
Clients []*ClientDetails `hcl:"client,block"`
|
Clients []*ClientDetails `hcl:"client,block"`
|
||||||
Routers []*RouterDetails `hcl:"router,block"`
|
Routers []*RouterDetails `hcl:"router,block"`
|
||||||
Workers []*WorkerDetails `hcl:"worker,block"`
|
Workers []*WorkerDetails `hcl:"worker,block"`
|
||||||
|
@ -43,7 +43,7 @@ type RouterDetails struct {
|
||||||
* which MQ router to send the agent's requests to.
|
* which MQ router to send the agent's requests to.
|
||||||
* This attempts to keep the routers unique globally.
|
* 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
|
* 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
|
* send agents to. This attempts to keep the
|
||||||
* workers unique globally.
|
* workers unique globally.
|
||||||
*/
|
*/
|
||||||
WorkerID string `hcl:"workerid,attr"`
|
WorkerID string `hcl:"uuid,attr"`
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* These tags will be passed to the router upon
|
* These tags will be passed to the router upon
|
||||||
|
|
|
@ -2,7 +2,7 @@ package worker
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
// "log"
|
"log"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -23,34 +23,8 @@ func pop(msg []string) (head, tail []string) {
|
||||||
return
|
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
|
// Each worker task works on one request at a time and sends a random number
|
||||||
// of replies back, with random delays between replies:
|
// of replies back, with random delays between replies:
|
||||||
|
|
||||||
func agentHandler(workerNum int) {
|
func agentHandler(workerNum int) {
|
||||||
interp := picol.InitInterp()
|
interp := picol.InitInterp()
|
||||||
interp.RegisterCoreCommands()
|
interp.RegisterCoreCommands()
|
||||||
|
@ -70,8 +44,35 @@ func agentHandler(workerNum int) {
|
||||||
// Sleep for some fraction of a second
|
// Sleep for some fraction of a second
|
||||||
time.Sleep(time.Duration(rand.Intn(1000)+1) * time.Millisecond)
|
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)
|
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
Add a link
Reference in a new issue