Merge pull request 'fix: (issues/7): Client mode is unable to read the agent script file.' (#8) from issues/7 into main

Reviewed-on: #8
This commit is contained in:
James Wells 2021-04-04 00:22:50 +00:00
commit 881a11316d
7 changed files with 106 additions and 27 deletions

View file

@ -1,10 +1,9 @@
--- ---
kind: pipeline kind: pipeline
type: docker type: docker
name: default name: build amd64
platform: platform:
os: linux
arch: amd64 arch: amd64
# trigger: # trigger:
@ -21,7 +20,7 @@ volumes:
path: /run/docker.sock path: /run/docker.sock
steps: steps:
- name: Build ${DRONE_REPO} Container Image - name: Build ${DRONE_REPO} Container Image On amd64
image: plugins/docker image: plugins/docker
volumes: volumes:
- name: dockersock - name: dockersock
@ -31,7 +30,10 @@ steps:
daemon_off: true daemon_off: true
debug: false debug: false
dockerfile: docker/Dockerfile dockerfile: docker/Dockerfile
dry_run: true
experimental: true
mirror: "https://registry.dragonheim.net/" mirror: "https://registry.dragonheim.net/"
pull_image: false
purge: true purge: true
repo: ${DRONE_REPO} repo: ${DRONE_REPO}
# target: development # target: development
@ -46,7 +48,64 @@ steps:
api_key: api_key:
from_secret: Datadog from_secret: Datadog
events: events:
- title: "Build failure" - title: "Build failure on amd64"
text: "Build ${DRONE_BUILD_NUMBER}"
alert_type: "error"
when:
status:
- failure
---
kind: pipeline
type: docker
name: build arm
platform:
arch: arm
# trigger:
# branch:
# exclude:
# - main
clone:
depth: 1
volumes:
- name: dockersock
host:
path: /run/docker.sock
steps:
- name: Build ${DRONE_REPO} Container Image On arm
image: plugins/docker
volumes:
- name: dockersock
path: /var/run/docker.sock
settings:
auto_tag: false
daemon_off: true
debug: false
dockerfile: docker/Dockerfile
dry_run: true
experimental: true
mirror: "https://registry.dragonheim.net/"
pull_image: false
purge: true
repo: ${DRONE_REPO}
# target: development
username:
from_secret: docker_username
password:
from_secret: docker_auth
- name: Send Status To Datadog
image: dragonheim/drone-datadog
settings:
api_key:
from_secret: Datadog
events:
- title: "Build failure on arm"
text: "Build ${DRONE_BUILD_NUMBER}" text: "Build ${DRONE_BUILD_NUMBER}"
alert_type: "error" alert_type: "error"
when: when:

View file

@ -25,10 +25,12 @@ Imagine, for a moment, that you are on Mars and need to perform a search for dat
``` ```
Lines 1 - 3 are simple comments Lines 1 - 3 are simple comments
Line 4 Tells the G'Agent router that this is the start of the hints to route for. Line 4 indicates the start of the hints.
Lines 5 - 7 are a list of hints that the router will use to determine which router(s) may have domain specific information. Lines 5 - 7 are a list of hints that the router will use to determine which router(s) may have domain specific information.
Line 8 indicates the end of the hints.
Lines 9 - 11 are a tcl procedure that will be executed on the worker before sending the results back to the client. Lines 9 - 11 are a tcl procedure that will be executed on the worker before sending the results back to the client.
Line 12 executes the procedure defined above. Line 12 executes the procedure defined above.

View file

@ -44,12 +44,12 @@ uuid = "7e9d13fe-5151-5876-66c0-20ca03e8fca4"
/. /.
* This is the port to listen on, it defaults to * This is the port to listen on, it defaults to
* 33570. It is strongly recommended that you not * 35570. It is strongly recommended that you not
* use ports 0 - 1024 * use ports 0 - 1024
* *
* Optional. * Optional.
* *
* listenport = 33570 * listenport = 35570
*/ */
/* /*

View file

@ -1,17 +1,16 @@
package main package main
import ( import (
// "fmt"
"io/ioutil" "io/ioutil"
"log" "log"
"os" "os"
"time"
// "math/rand" // "math/rand"
"time"
gs "git.dragonheim.net/dragonheim/gagent/src/gstructs" gs "git.dragonheim.net/dragonheim/gagent/src/gstructs"
// client "git.dragonheim.net/dragonheim/gagent/src/client" gc "git.dragonheim.net/dragonheim/gagent/src/client"
gr "git.dragonheim.net/dragonheim/gagent/src/router" gr "git.dragonheim.net/dragonheim/gagent/src/router"
gw "git.dragonheim.net/dragonheim/gagent/src/worker" gw "git.dragonheim.net/dragonheim/gagent/src/worker"
@ -31,6 +30,7 @@ var exitCodes = struct {
"AGENT_MISSING_TAGS": 5, "AGENT_MISSING_TAGS": 5,
"NO_ROUTERS_DEFINED": 6, "NO_ROUTERS_DEFINED": 6,
"NO_WORKERS_DEFINED": 7, "NO_WORKERS_DEFINED": 7,
"AGENT_NOT_DEFINED": 8,
}} }}
func main() { func main() {
@ -125,17 +125,20 @@ 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 client mode\n") log.Printf("Running in client mode\n")
if arguments["--agent"] == nil {
log.Printf("Agent file not specified")
os.Exit(exitCodes.m["AGENT_NOT_DEFINED"])
}
agent, err := ioutil.ReadFile(arguments["--agent"].(string)) agent, err := ioutil.ReadFile(arguments["--agent"].(string))
if err == nil { if err != nil {
log.Printf("Agent containts %v\n", string(agent)) log.Printf("Failed to load Agent file: %s", arguments["--agent"])
log.Printf("Forking...\n")
// go client.Main(config, string(agent))
log.Printf("Forked thread has completed\n")
time.Sleep(10 * time.Second)
} else {
log.Printf("Failed to load Agent file: %s.\n", arguments["--agent"].(string))
os.Exit(exitCodes.m["AGENT_LOAD_FAILED"]) os.Exit(exitCodes.m["AGENT_LOAD_FAILED"])
} }
for key := range config.Routers {
log.Printf("Calling for router %d", key)
go gc.Main(config, key, string(agent))
time.Sleep(10 * time.Second)
}
case "router": case "router":
/* /*

View file

@ -2,6 +2,8 @@ package client
import ( import (
"fmt" "fmt"
"log"
"strconv"
"sync" "sync"
"time" "time"
@ -11,13 +13,19 @@ import (
) )
// Main is the initiation function for a Client // Main is the initiation function for a Client
func Main(config gs.GagentConfig, agent string) { func Main(config gs.GagentConfig, routerID int, agent string) {
var mu sync.Mutex var mu sync.Mutex
var rport = int(config.ListenPort)
if config.Routers[routerID].RouterPort != "" {
rport, _ = strconv.Atoi(config.Routers[routerID].RouterPort)
}
fmt.Printf("Did we make it this far?\n") log.Printf("--|%#v|--\n", agent)
fmt.Printf("--|%#v|--\n", agent)
connectString := fmt.Sprintf("tcp://%s", config.Routers[0].RouterAddr) connectString := fmt.Sprintf("tcp://%s:%d",
config.Routers[routerID].RouterAddr,
rport)
log.Printf("Attempting to connect to %s\n", connectString)
sock, _ := zmq.NewSocket(zmq.DEALER) sock, _ := zmq.NewSocket(zmq.DEALER)
defer sock.Close() defer sock.Close()
@ -36,7 +44,7 @@ func Main(config gs.GagentConfig, agent string) {
mu.Lock() mu.Lock()
msg, err := sock.RecvMessage(zmq.DONTWAIT) msg, err := sock.RecvMessage(zmq.DONTWAIT)
if err == nil { if err == nil {
fmt.Println(msg[0], config.UUID) log.Println(msg[0], config.UUID)
} }
mu.Unlock() mu.Unlock()
} }

View file

@ -46,12 +46,20 @@ type RouterDetails struct {
RouterID string `hcl:"uuid,attr"` RouterID string `hcl:"uuid,attr"`
/* /*
* This is the IP Address and port that the router * This is the IP address or hostname the router
* will listen on. The router will start up a 0MQ * will listen on. The router will start up a 0MQ
* service that clients and workers will connect to. * service that clients and workers will connect to.
*/ */
RouterAddr string `hcl:"address,attr"` RouterAddr string `hcl:"address,attr"`
/*
* This is the is the port that the router listens
* on. If not defined, it will default to 35570
* The router will start up a 0MQ service that
* clients and workers will connect to.
*/
RouterPort string `hcl:"port,optional"`
/* /*
* These tags will be passed to the router upon * These tags will be passed to the router upon
* connection. The router will then use these * connection. The router will then use these

View file

@ -37,6 +37,7 @@ func agentRouter(workerNum int) {
// The DEALER socket gives us the reply envelope and message // The DEALER socket gives us the reply envelope and message
msg, _ := worker.RecvMessage(0) msg, _ := worker.RecvMessage(0)
identity, content := pop(msg) identity, content := pop(msg)
log.Printf("Recieved message: %s", content)
// Send 0..4 replies back // Send 0..4 replies back
replies := rand.Intn(5) replies := rand.Intn(5)
@ -51,7 +52,6 @@ func agentRouter(workerNum int) {
} }
} }
// Main is the initiation function for a Router // Main is the initiation function for a Router
func Main(config gs.GagentConfig) { func Main(config gs.GagentConfig) {
/* /*
@ -84,4 +84,3 @@ func Main(config gs.GagentConfig) {
err := zmq.Proxy(frontend, backend, nil) err := zmq.Proxy(frontend, backend, nil)
log.Fatalln("Proxy interrupted:", err) log.Fatalln("Proxy interrupted:", err)
} }