Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor README to simplify VM setup procedure #43

Merged
merged 3 commits into from
Sep 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
176 changes: 4 additions & 172 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,177 +1,9 @@
# Agent

## Build Agent
## Use Agent with Manager

To create a stand-alone `agent` executable, on the host machine, in the root of the `agent` repository run
To see how to use Agent with Manager, see (Manager's README)[https://github.com/ultravioletrs/manager].

```sh
go build -o ./bin/agent -ldflags="-linkmode=external -extldflags=-static -s -w" cmd/agent/main.go
```
## Use Agent with Cocos

## Copy files to virtual drive

Log in the VM and create `/cocos` directory. Shut down `QEmu-alpine-standard-x86_64` virtual machine.

On the host machine install [libguestfs-tools](https://libguestfs.org/). `libguestfs-tools` is "a set of tools for accessing and modifying virtual machine (VM) disk images".

```sh
sudo apt-get install libguestfs-tools
```

Set path to the VM disk image:

```sh
QCOW2_PATH=~/go/src/github.com/ultravioletrs/manager/cmd/manager/img/boot.img
```

Set path to the `agent` executable and its VM image path, and copy `agent` to the VM disk image.

```sh
HOST_AGENT_BIN_PATH=~/go/src/github.com/ultravioletrs/agent/bin/agent; \
GUEST_AGENT_BIN_PATH=/cocos/; \
sudo virt-copy-in -a $QCOW2_PATH $HOST_AGENT_BIN_PATH $GUEST_AGENT_BIN_PATH
```

Copy [OpenRC](https://wiki.alpinelinux.org/wiki/OpenRC) init script to the VM disk image:

```sh
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 init script is used to start `agent` executable as a system service (daemon) on the Alpine Linux boot.

### OpenRC

Once the OpenRC `agent` script is copied into the `/etc/init.d/`, i.e. on the guest system, log into the guest system and run

```sh
rc-update add agent default
```

and reboot.

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

```sh
ps aux | grep agent
```

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

```sh
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

```sh
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

```sh
ip addr show eth0
```

in the host machine and

```sh
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 `agent` deamon is responding to the requests, run on the host

```sh
GUEST_ADDR=192.168.122.251:9031
```

To run a computation

```sh
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](https://github.com/ultravioletrs/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

```sh
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

```sh
curl -sSi -X POST http://localhost:9000/computations/$COMPUTATION_ID/run
```
To see how to use Agent with Cocos, see (Cocos' README)[https://github.com/ultravioletrs/cocos].
25 changes: 0 additions & 25 deletions alpine/agent

This file was deleted.

8 changes: 0 additions & 8 deletions alpine/packer/script.sh

This file was deleted.

66 changes: 0 additions & 66 deletions alpine/packer/template.json

This file was deleted.

2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ require (
github.com/mainflux/mainflux v0.0.0-20230726142711-2b78902e0170
github.com/prometheus/client_golang v1.16.0
github.com/spf13/cobra v1.7.0
github.com/spf13/pflag v1.0.5
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.42.0
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.42.0
go.opentelemetry.io/contrib/propagators/jaeger v1.17.0
Expand Down Expand Up @@ -37,7 +38,6 @@ require (
github.com/prometheus/client_model v0.4.0 // indirect
github.com/prometheus/common v0.44.0 // indirect
github.com/prometheus/procfs v0.11.1 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/subosito/gotenv v1.4.2 // indirect
go.opentelemetry.io/otel/metric v1.16.0 // indirect
golang.org/x/net v0.12.0 // indirect
Expand Down
4 changes: 2 additions & 2 deletions pkg/clients/grpc/connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ var (
type Config struct {
ClientTLS bool `env:"CLIENT_TLS" envDefault:"false"`
CACerts string `env:"CA_CERTS" envDefault:""`
URL string `env:"URL" envDefault:"localhost:7002"`
Timeout time.Duration `env:"TIMEOUT" envDefault:"1s"`
URL string `env:"URL" envDefault:"localhost:7020"`
Timeout time.Duration `env:"TIMEOUT" envDefault:"60s"`
}

type Client interface {
Expand Down
12 changes: 7 additions & 5 deletions alpine/cocos-agent.service → systemd/cocos-agent.service
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@ After=network.target
StandardOutput=file:/var/log/cocos/agent.stdout
StandardError=file:/var/log/cocos/agent.stderr

ExecStartPre=ip link set dev enp0s2 up
ExecStartPre=dhclient enp0s2
Environment=NETWORK_INTERFACE=enp0s3
Environment=AGENT_GRPC_HOST=10.0.2.15
Environment=AGENT_GRPC_PORT=7002
Environment=AGENT_LOG_LEVEL=info

ExecStartPre=ip link set dev $NETWORK_INTERFACE up
ExecStartPre=dhclient $NETWORK_INTERFACE
ExecStartPre=mkdir -p /var/log/cocos

ExecStart=/cocos/agent

Environment=AGENT_LOG_LEVEL=info
Environment=AGENT_GRPC_ADDR=10.0.2.15:7002

[Install]
WantedBy=default.target
Loading