regorg sidebar
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
parent
aa567d43d7
commit
4128050052
10 changed files with 155 additions and 14 deletions
|
|
@ -152,7 +152,14 @@ func main() {
|
|||
|
||||
http.HandleFunc("/rpc", rpcHandler(taskQueue, resultChan))
|
||||
|
||||
log.Println("Serveur JSON-RPC sur :8080")
|
||||
log.Fatal(http.ListenAndServe(":8080", nil))
|
||||
|
||||
go func() {
|
||||
log.Println("Serveur JSON-RPC sur :8080")
|
||||
log.Fatal(http.ListenAndServe(":8080", nil))
|
||||
}()
|
||||
|
||||
for {
|
||||
time.Sleep(1 * time.Hour)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
|
@ -1,5 +1,3 @@
|
|||
# Agent kvm
|
||||
|
||||
## Fonctionnement
|
||||
|
||||
L'agent fera plusieurs chose:
|
||||
|
|
@ -26,9 +24,3 @@ Tout cela serait lancer depuis une api:
|
|||
- vm zmobie compris
|
||||
|
||||
## 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
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 qu’un 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]
|
||||
```
|
||||
2
Home.md
2
Home.md
|
|
@ -5,5 +5,3 @@ Bienvenue sur le wiki du projet syonad _/sjɔ.nad/_
|
|||
## Architecture
|
||||
|
||||
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
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)
|
||||
4
agent/agent_archi.drawio.svg
Normal file
4
agent/agent_archi.drawio.svg
Normal file
File diff suppressed because one or more lines are too long
|
After Width: | Height: | Size: 220 KiB |
Loading…
Add table
Add a link
Reference in a new issue