regorg sidebar

Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
GnomeZworc 2025-04-24 14:16:31 +02:00
commit 4128050052
Signed by: nicolas.boufideline
GPG key ID: 4406BBBF8845D632
10 changed files with 155 additions and 14 deletions

@ -152,7 +152,14 @@ func main() {
http.HandleFunc("/rpc", rpcHandler(taskQueue, resultChan)) http.HandleFunc("/rpc", rpcHandler(taskQueue, resultChan))
go func() {
log.Println("Serveur JSON-RPC sur :8080") log.Println("Serveur JSON-RPC sur :8080")
log.Fatal(http.ListenAndServe(":8080", nil)) log.Fatal(http.ListenAndServe(":8080", nil))
}()
for {
time.Sleep(1 * time.Hour)
}
} }
``` ```

@ -1,5 +1,3 @@
# Agent kvm
## Fonctionnement ## Fonctionnement
L'agent fera plusieurs chose: L'agent fera plusieurs chose:
@ -26,9 +24,3 @@ Tout cela serait lancer depuis une api:
- vm zmobie compris - vm zmobie compris
## Architecture ## Architecture
- [Reseaux](./agent/network/Home.md)
- [Les vms](./agent/instance/Home.md)
- [Serveur http](./agent/http/Home.md)
- [Persistance](./agent/persistance/Home.md)
- [Metadata](./agent/metadata/Home.md)

129
Event Bus.md Normal file

@ -0,0 +1,129 @@
# A simple event queue
## 🧱 Design simple en Go
### 🎛️ Structure `Event`
```go
type EventType string
const (
EventStart EventType = "start"
EventStop EventType = "stop"
EventReboot EventType = "reboot"
EventAttach EventType = "attach-disk"
EventDetach EventType = "detach-disk"
)
type VMEvent struct {
Type EventType
VMID string
Params map[string]string // optionnel selon le type
}
```
---
### 📬 EventQueue (thread-safe FIFO + notify)
```go
type EventQueue struct {
queue []VMEvent
lock sync.Mutex
signal chan struct{}
}
func NewEventQueue() *EventQueue {
return &EventQueue{
queue: make([]VMEvent, 0),
signal: make(chan struct{}, 1),
}
}
func (eq *EventQueue) Push(ev VMEvent) {
eq.lock.Lock()
defer eq.lock.Unlock()
eq.queue = append(eq.queue, ev)
select {
case eq.signal <- struct{}{}:
default:
// si déjà notify, pas besoin de spammer
}
}
func (eq *EventQueue) Pop() (VMEvent, bool) {
eq.lock.Lock()
defer eq.lock.Unlock()
if len(eq.queue) == 0 {
return VMEvent{}, false
}
ev := eq.queue[0]
eq.queue = eq.queue[1:]
return ev, true
}
```
---
### 🔁 Boucle d'exécution FIFO
```go
func StartEventLoop(eq *EventQueue, manager *Manager) {
go func() {
for {
<-eq.signal // bloquant jusqu'à ce quun event arrive
for {
ev, ok := eq.Pop()
if !ok {
break
}
log.Printf("⏳ Processing event %s for VM %s", ev.Type, ev.VMID)
switch ev.Type {
case EventStart:
manager.StartVMByID(ev.VMID)
case EventStop:
manager.StopVMByID(ev.VMID)
case EventAttach:
manager.AttachDisk(ev.VMID, ev.Params["path"])
case EventDetach:
manager.DetachDisk(ev.VMID, ev.Params["path"])
default:
log.Printf("⚠️ Unknown event type: %s", ev.Type)
}
}
}
}()
}
```
---
### 🌐 Exposition via HTTP (exemple minimal)
```go
func handleStartVM(w http.ResponseWriter, r *http.Request, eq *EventQueue) {
vmID := r.URL.Query().Get("id")
if vmID == "" {
http.Error(w, "missing id", 400)
return
}
eq.Push(VMEvent{Type: EventStart, VMID: vmID})
fmt.Fprintf(w, "Start request enqueued")
}
```
---
## 🔔 Résumé de la comm' inter-composants
```text
[API HTTP] --(Push VMEvent)--> [EventQueue] --(notify chan)--> [EventLoop]
|
[Pop / Switch exec based on event type]
```

@ -5,5 +5,3 @@ Bienvenue sur le wiki du projet syonad _/sjɔ.nad/_
## Architecture ## Architecture
Le projet sera developper en GO en suivant le [Standard Go Project Layout](https://github.com/golang-standards/project-layout). Le projet sera developper en GO en suivant le [Standard Go Project Layout](https://github.com/golang-standards/project-layout).
Il sera composer d'un [agent](./agent/Home.md)

11
_Sidebar.md Normal file

@ -0,0 +1,11 @@
**Project**
- [[Home]]
**Architecture**
- [Agent KVM](./Agent%20KVM.md)
- [Reseaux](./Agent%20Network.md)
- [Instance](./Agent%20Instance.md)
- [Metadata](./Agent%20Metadata.md)
- [Persistance](./Agent%20Persistance.md)
- [HTTP](./Agent%20HTTP.md)
- [Event BUS](./Event%20BUS.md)

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 220 KiB