From 1f9a95897eff5985d77c4ae1d9ba2cb5d25fdff9 Mon Sep 17 00:00:00 2001 From: Vitaliy Pavlov Date: Wed, 31 Jul 2024 20:55:46 +0700 Subject: [PATCH] update types and add plugins submodule --- .gitignore | 3 +- .gitmodules | 3 ++ amqp/{agent_types.go => types/agent.go} | 22 ++++++------ .../controller.go} | 18 +++++----- main.go | 2 ++ plugins/dictionary | 1 + plugins/plugins.go | 22 ++++++++++++ services/misc.go | 1 - types/task.go | 34 +++++++++++-------- 9 files changed, 69 insertions(+), 37 deletions(-) create mode 100644 .gitmodules rename amqp/{agent_types.go => types/agent.go} (66%) rename amqp/{controller_types.go => types/controller.go} (59%) create mode 160000 plugins/dictionary create mode 100644 plugins/plugins.go diff --git a/.gitignore b/.gitignore index 0efc5d4..1432035 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .env -tmp \ No newline at end of file +tmp +.DS_Store \ No newline at end of file diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..7ddc72f --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "plugins/dictionary"] + path = plugins/dictionary + url = ../../plugins-dictionary diff --git a/amqp/agent_types.go b/amqp/types/agent.go similarity index 66% rename from amqp/agent_types.go rename to amqp/types/agent.go index 3ab8853..ff7723a 100644 --- a/amqp/agent_types.go +++ b/amqp/types/agent.go @@ -1,4 +1,4 @@ -package amqp +package types const ( AgentHello uint8 = iota @@ -16,33 +16,33 @@ const ( type AgentMessage struct { Message uint8 `json:"message"` - Data *AgentMessageData `json:"data"` + Data *agentMessageData `json:"data"` } -type AgentMessageData struct { - AgentHelloData - AgentErrorData - AgentStatusData +type agentMessageData struct { + agentHelloData + agentErrorData + agentStatusData } -type AgentErrorData struct { +type agentErrorData struct { Error string } -type AgentStatusData struct { +type agentStatusData struct { Error string `json:"error"` Status uint8 `json:"status"` TaskID int64 `json:"taskId"` Progress uint8 `json:"progress"` // 0-100, for AgentStatusRunning } -type AgentHelloData struct { +type agentHelloData struct { Hostname string `json:"hostname"` Version string `json:"version"` - Interfaces []InterfaceData `json:"interfaces"` + Interfaces []interfaceData `json:"interfaces"` } -type InterfaceData struct { +type interfaceData struct { Name string `json:"name"` IP string `json:"ip"` } diff --git a/amqp/controller_types.go b/amqp/types/controller.go similarity index 59% rename from amqp/controller_types.go rename to amqp/types/controller.go index 4d1fbeb..4216f49 100644 --- a/amqp/controller_types.go +++ b/amqp/types/controller.go @@ -1,4 +1,4 @@ -package amqp +package types import "system-trace/core/types" @@ -14,24 +14,24 @@ const ( type ControllerMessage struct { Message uint8 `json:"message"` - Data *ControllerMessageData `json:"data"` + Data *controllerMessageData `json:"data"` } -type ControllerMessageData struct { - TaskStartData - TaskPauseData - TaskStopData +type controllerMessageData struct { + taskStartData + taskPauseData + taskStopData } -type TaskStopData struct { +type taskStopData struct { TaskID int64 `json:"taskId"` } -type TaskPauseData struct { +type taskPauseData struct { TaskID int64 } -type TaskStartData struct { +type taskStartData struct { TaskID int64 Data *types.TaskVariables `json:"data"` } diff --git a/main.go b/main.go index 7831bd5..be05153 100644 --- a/main.go +++ b/main.go @@ -3,6 +3,7 @@ package main import ( "system-trace/core/database" "system-trace/core/environment" + "system-trace/core/plugins" "system-trace/core/validators" ) @@ -16,6 +17,7 @@ import ( // @externalDocs.description OpenAPI func main() { environment.Load() + plugins.LoadPlugins() validators.RegisterValidators() database.Connect() serveApp() diff --git a/plugins/dictionary b/plugins/dictionary new file mode 160000 index 0000000..40fcb5d --- /dev/null +++ b/plugins/dictionary @@ -0,0 +1 @@ +Subproject commit 40fcb5dc67bae495bccff549f3373dbbac854909 diff --git a/plugins/plugins.go b/plugins/plugins.go new file mode 100644 index 0000000..57a652c --- /dev/null +++ b/plugins/plugins.go @@ -0,0 +1,22 @@ +package plugins + +import ( + "encoding/json" + "log" + "os" + "system-trace/core/types" +) + +var plugins *[]types.Plugin + +func LoadPlugins() { + dictpath := "plugins/dictionary/dict.json" + d, err := os.ReadFile(dictpath) + if err != nil { + log.Fatal(err) + } + + if err := json.Unmarshal(d, &plugins); err != nil { + log.Fatal(err) + } +} diff --git a/services/misc.go b/services/misc.go index 1fc3b5e..7e96e47 100644 --- a/services/misc.go +++ b/services/misc.go @@ -10,7 +10,6 @@ import ( // @Summary Get list of permissions // @Description Returns key-value map with permissions // @Produce json -// @Header 200 {string} Token "accessToken=...;refreshToken=..." // @Success 200 {object} map[string]int8 // @Router /permissions [get] func GetPermissions(c *fiber.Ctx) error { diff --git a/types/task.go b/types/task.go index 77147ea..248d57a 100644 --- a/types/task.go +++ b/types/task.go @@ -10,32 +10,36 @@ const ( type TaskVariables struct { Mode uint8 `json:"mode" validate:"min=0,max=255"` Time uint32 `json:"time" validate:"min=0,max=4294967295"` // in seconds - Plugins []PluginData `json:"plugins" validate:"required"` - Performance PerformanceData `json:"performance" validate:"required"` - Tweaks PerformanceTweaks `json:"tweaks" validate:"required"` // [[time_in_seconds, value]]: [[10, 6570]] + Plugins []pluginData `json:"plugins" validate:"required"` + Performance performanceData `json:"performance" validate:"required"` + Tweaks performanceTweaks `json:"tweaks" validate:"required"` // [[time_in_seconds, value]]: [[10, 6570]] } -type PerformanceData struct { // Depends on selected mode - // MODE_THROUGHPUT - MaxBPS uint64 `json:"maxBps" validate:"min=0,max=18446744073709551615"` - MaxPPS uint64 `json:"maxPps" validate:"min=0,max=18446744073709551615"` +type performanceData struct { // Depends on selected mode + // MODE_THROUGHPUT_BPS + MaxBPS uint64 `json:"maxBps" validate:"min=0,max=18446744073709551615"` + // MODE_THROUGHPUT_PPS + MaxPPS uint64 `json:"maxPps" validate:"min=0,max=18446744073709551615"` + // MODE_TCP_CONNECTIONS MaxTCPConnections uint32 `json:"maxTcpConn" validate:"min=0,max=4294967295"` // MODE_USERS MaxUsers uint32 `json:"maxUsers" validate:"min=0,max=4294967295"` } -type PerformanceTweaks struct { - // MODE_THROUGHPUT - BPS TweaksData `json:"bps"` - PPS TweaksData `json:"pps"` - TCPConnections TweaksData `json:"tcpConn"` +type performanceTweaks struct { + // MODE_THROUGHPUT_BPS + BPS tweaksData `json:"bps"` + // MODE_THROUGHPUT_PPS + PPS tweaksData `json:"pps"` + // MODE_TCP_CONNECTIONS + TCPConnections tweaksData `json:"tcpConn"` // MODE_USERS - Users TweaksData `json:"users"` + Users tweaksData `json:"users"` } -type TweaksData [][]uint8 +type tweaksData [][]uint8 -type PluginData struct { +type pluginData struct { Plugin uint32 `json:"plugin" validate:"min=0,max=4294967295"` Weight uint8 `json:"weight" validate:"min=0,max=100"` // 0-100 }