/
apiserver.go
109 lines (86 loc) · 4.14 KB
/
apiserver.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package manager
import (
"fmt"
"net/http"
"sync"
echoSwagger "github.com/swaggo/echo-swagger"
"github.com/cloud-barista/cb-dragonfly/pkg/util"
"github.com/cloud-barista/cb-dragonfly/pkg/api/rest/agent"
"github.com/cloud-barista/cb-dragonfly/pkg/api/rest/alert"
restconfig "github.com/cloud-barista/cb-dragonfly/pkg/api/rest/config"
"github.com/cloud-barista/cb-dragonfly/pkg/api/rest/healthcheck"
"github.com/cloud-barista/cb-dragonfly/pkg/api/rest/metric"
"github.com/cloud-barista/cb-dragonfly/pkg/config"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
_ "github.com/cloud-barista/cb-dragonfly/pkg/docs" // docs is generated by Swag CLI, you have to import it.
)
type APIServer struct {
echo *echo.Echo
}
// NewAPIServer API 서버 초기화
func NewAPIServer() (*APIServer, error) {
e := echo.New()
apiServer := APIServer{
echo: e,
}
return &apiServer, nil
}
// StartAPIServer 모니터링 API 서버 실행
func (apiServer *APIServer) StartAPIServer(wg *sync.WaitGroup) error {
defer wg.Done()
util.GetLogger().Info("start CB-Dragonfly Framework API Server")
// 모니터링 API 라우팅 룰 설정
apiServer.SetRoutingRule(apiServer.echo)
// 모니터링 API 서버 실행
return apiServer.echo.Start(fmt.Sprintf(":%d", config.GetInstance().APIServer.Port))
}
func (apiServer *APIServer) SetRoutingRule(e *echo.Echo) {
e.Use(middleware.CORSWithConfig(middleware.CORSConfig{
AllowOrigins: []string{"*"},
AllowMethods: []string{http.MethodGet, http.MethodPut, http.MethodPost, http.MethodDelete},
}))
dragonfly := e.Group("/dragonfly")
dragonfly.GET("/swagger/*", echoSwagger.WrapHandler)
// 헬스체크
dragonfly.GET("/healthcheck", healthcheck.Ping)
// 멀티 클라우드 모니터링 정책 설정
dragonfly.PUT("/config", restconfig.SetMonConfig)
dragonfly.GET("/config", restconfig.GetMonConfig)
dragonfly.PUT("/config/reset", restconfig.ResetMonConfig)
// 멀티 클라우드 인프라 서비스 모니터링/실시간 모니터링 정보 조회
//dragonfly.GET("/ns/:ns_id/mcis/:mcis_id/info", metric.GetMCISMonInfo)
//dragonfly.GET("/ns/:ns_id/mcis/:mcis_id/rt-info", metric.GetMCISRealtimeMonInfo)
// MCIS 모니터링 (Milkyway)
dragonfly.GET("/ns/:ns_id/mcis/:mcis_id/vm/:vm_id/agent_ip/:agent_ip/mcis_metric/:metric_name/mcis-monitoring-info", metric.GetMCISMetric)
// 멀티클라우드 인프라 VM 온디멘드 모니터링
dragonfly.GET("/ns/:ns/mcis/:mcis_id/vm/:vm_id/agent_ip/:agent_ip/metric/:metric_name/ondemand-monitoring-info", metric.GetVMOnDemandMetric)
// 멀티 클라우드 인프라 VM 모니터링/실시간 모니터링 정보 조회
dragonfly.GET("/ns/:ns_id/mcis/:mcis_id/vm/:vm_id/metric/:metric_name/info", metric.GetVMMonInfo)
// windows 에이전트 config, package 파일 다운로드
//dragonfly.GET("/installer/cbinstaller.zip", agent.GetWindowInstaller)
//dragonfly.GET("/file/agent/conf", agent.GetTelegrafConfFile)
//dragonfly.GET("/file/agent/pkg", agent.GetTelegrafPkgFile)
// 에이전트 설치
dragonfly.POST("/agent", agent.InstallTelegraf)
// 에이전트 삭제
dragonfly.DELETE("/agent", agent.UninstallAgent)
// 에이전트 메타데이터 조회
dragonfly.GET("/agent/metadata", agent.ListAgentMetadata)
// 알람 이벤트 핸들러 조회, 생성, 삭제
dragonfly.GET("/alert/eventhandlers", alert.ListEventHandler)
dragonfly.GET("/alert/eventhandler/type/:type/event/:name", alert.GetEventHandler)
dragonfly.POST("/alert/eventhandler", alert.CreateEventHandler)
dragonfly.PUT("/alert/eventhandler/type/:type/event/:name", alert.UpdateEventHandler)
dragonfly.DELETE("/alert/eventhandler/type/:type/event/:name", alert.DeleteEventHandler)
// 알람 조회, 생성, 삭제
dragonfly.GET("/alert/tasks", alert.ListAlertTask)
dragonfly.GET("/alert/task/:task_id", alert.GetAlertTask)
dragonfly.POST("/alert/task", alert.CreateAlertTask)
dragonfly.PUT("/alert/task/:task_id", alert.UpdateAlertTask)
dragonfly.DELETE("/alert/task/:task_id", alert.DeleteAlertTask)
// 알람 이벤트 로그 조회, 생성
dragonfly.GET("/alert/task/:task_id/events", alert.ListEventLog)
dragonfly.POST("/alert/event", alert.CreateEventLog)
e.Logger.Fatal(e.Start(":9090"))
}