Files
cocos/README.md
T
2023-06-14 16:19:19 +02:00

4.0 KiB

Agent

Build Agent

On the host machine in the root of agent repository run

go build -o ./bin/cocos-agent -ldflags="-linkmode=external -extldflags=-static -s -w" cmd/agent/main.go

Copy files to virtual drive

Shut down QEmu-alpine-standard-x86_64 virtual machine.

On the host machine

sudo apt-get install libguestfs-tools
QCOW2_PATH=~/go/src/github.com/ultravioletrs/manager/cmd/manager/img/boot.img
HOST_AGENT_BIN_PATH=~/go/src/github.com/ultravioletrs/agent/bin/cocos-agent; \
GUEST_AGENT_BIN_PATH=/root/; \
sudo virt-copy-in -a $QCOW2_PATH $HOST_AGENT_BIN_PATH $GUEST_AGENT_BIN_PATH
HOST_AGENT_SCRIPT_PATH=~/go/src/github.com/ultravioletrs/agent/alpine/agent; \
GUEST_AGENT_SCRIPT_PATH=/etc/init.d/; \
sudo virt-copy-in -a $QCOW2_PATH $HOST_AGENT_SCRIPT_PATH $GUEST_AGENT_SCRIPT_PATH

OpenRC

OpenRC is an Alpine's service manager.

Once the agent script is copied in /etc/init.d/ on the guest system, log into the guest system and run

rc-update add agent default

and reboot.

To see if the cocos-agent service (or deamon) is running, inside Alpine linux run

ps aux | grep cocos

To see if the ports are correctly configured, inside Alpine linux, i.e. guest machine, run

netstat -tuln | grep 9031
netstat -tuln | grep 7002

In the host machine, you can check if the ports of the guest machine are open and reachable from the host machine with

nc -zv 192.168.122.251 9031
nc -zv 192.168.122.251 7002

NB: to find out 192.168.122.251, i.e. the concrete address of the guest machine, you need to

ip addr show eth0

in the host machine and

ip addr show virbr0

on the host machine. In both cases, you will get something like inet 192.168.122.x/24, where 192.168.122 stands for the network part of the machine's virtual network interface address.

cURL

To check if the cocos-agent deamon is responding to the requests, run on the host

GUEST_ADDR=192.168.122.251:9031
curl -i -X POST -H "Content-Type: application/json" ${GUEST_ADDR}/agent -d '{"secret":"secret"}'

To run a computation

curl -sSi -X POST ${GUEST_ADDR}/run -H "Content-Type: application/json" -d @- <<EOF 
{
  "name": "computation_24",
  "description": "this_computes_the_number_24",
  "datasets": [
    "red", "green", "blue", "black", "white", "grey"
  ],
  "algorithms": [
    "toHSV", "toRGB"
  ],
  "status": "executed",
  "owner": "Hector",
  "dataset_providers": [
    "Maxi", "Idea", "Lidl"
  ],
  "algorithm_providers": [
    "ETF", "FON", "FTN"
  ],
  "result_consumers": [
    "Intesa", "KomBank", "OTP"
  ],
  "ttl": 32,
  "metadata": {}
}
EOF

Interaction with Cocos microservice

If the cocos is running, you can use cocos to send computation request to the agent via gRPC.

NB: you need to run cocos computations microservice with COCOS_COMPUTATIONS_AGENT_GRPC_URL=192.168.122.251:7002, i.e. with the correct address and port of the agent gRPC client running in the VM.

Create computation with

curl -sSi -X POST http://localhost:9000/computations -H "Content-Type: application/json" -d @- <<EOF
{
  "name": "computation_24",
  "description": "this_computes_the_number_24",
  "datasets": [
    "red", "green", "blue", "black", "white", "grey"
  ],
  "algorithms": [
    "toHSV", "toRGB"
  ],
  "status": "executed",
  "owner": "Hector",
  "dataset_providers": [
    "Maxi", "Idea", "Lidl"
  ],
  "algorithm_providers": [
    "ETF", "FON", "FTN"
  ],
  "result_consumers": [
    "Intesa", "KomBank", "OTP"
  ],
  "ttl": 32,
  "metadata": {}
}
EOF

You will get as a response

HTTP/1.1 201 Created
Content-Type: application/json
Location: /computations/9429a679-173e-4c2d-856f-74c92e08ab76
Date: Fri, 19 May 2023 12:30:56 GMT
Content-Length: 0

Note the computation id in the Location header. Set the environmnet variable COMPUTATION_ID=9429a679-173e-4c2d-856f-74c92e08ab76 and run it with

curl -sSi -X POST http://localhost:9000/computations/$COMPUTATION_ID/run