diff options
author | Corey Hulen <corey@hulen.com> | 2016-08-04 09:25:37 -0800 |
---|---|---|
committer | Harrison Healey <harrisonmhealey@gmail.com> | 2016-08-04 13:25:37 -0400 |
commit | 59d971dc751b0414c5b38c9df4b552e45f5641be (patch) | |
tree | d8c39aa5d1fa67d41d89bdd37f699a8e7ca7af36 /api/admin.go | |
parent | ac90f5b38962c301318fff9118c4556537002941 (diff) | |
download | chat-59d971dc751b0414c5b38c9df4b552e45f5641be.tar.gz chat-59d971dc751b0414c5b38c9df4b552e45f5641be.tar.bz2 chat-59d971dc751b0414c5b38c9df4b552e45f5641be.zip |
PLT-2899 adding clustering of app servers (#3682)
* PLT-2899 adding clustering of app servers
* PLT-2899 base framework
* PLT-2899 HA backend
* PLT-2899 Fixing config file
* PLT-2899 adding config syncing
* PLT-2899 set System console to readonly when clustering enabled.
* PLT-2899 Fixing publish API
* PLT-2899 fixing strings
Diffstat (limited to 'api/admin.go')
-rw-r--r-- | api/admin.go | 55 |
1 files changed, 52 insertions, 3 deletions
diff --git a/api/admin.go b/api/admin.go index a50271f8b..cab55e7d3 100644 --- a/api/admin.go +++ b/api/admin.go @@ -46,6 +46,7 @@ func InitAdmin() { BaseRoutes.Admin.Handle("/add_certificate", ApiAdminSystemRequired(addCertificate)).Methods("POST") BaseRoutes.Admin.Handle("/remove_certificate", ApiAdminSystemRequired(removeCertificate)).Methods("POST") BaseRoutes.Admin.Handle("/saml_cert_status", ApiAdminSystemRequired(samlCertificateStatus)).Methods("GET") + BaseRoutes.Admin.Handle("/cluster_status", ApiAdminSystemRequired(getClusterStatus)).Methods("GET") } func getLogs(c *Context, w http.ResponseWriter, r *http.Request) { @@ -54,13 +55,32 @@ func getLogs(c *Context, w http.ResponseWriter, r *http.Request) { return } + lines, err := GetLogs() + if err != nil { + c.Err = err + return + } + + if einterfaces.GetClusterInterface() != nil { + clines, err := einterfaces.GetClusterInterface().GetLogs() + if err != nil { + c.Err = err + return + } + + lines = append(lines, clines...) + } + + w.Write([]byte(model.ArrayToJson(lines))) +} + +func GetLogs() ([]string, *model.AppError) { var lines []string if utils.Cfg.LogSettings.EnableFile { - file, err := os.Open(utils.GetLogFileLocation(utils.Cfg.LogSettings.FileLocation)) if err != nil { - c.Err = model.NewLocAppError("getLogs", "api.admin.file_read_error", nil, err.Error()) + return nil, model.NewLocAppError("getLogs", "api.admin.file_read_error", nil, err.Error()) } defer file.Close() @@ -73,7 +93,21 @@ func getLogs(c *Context, w http.ResponseWriter, r *http.Request) { lines = append(lines, "") } - w.Write([]byte(model.ArrayToJson(lines))) + return lines, nil +} + +func getClusterStatus(c *Context, w http.ResponseWriter, r *http.Request) { + + if !c.HasSystemAdminPermissions("getClusterStatus") { + return + } + + infos := make([]*model.ClusterInfo, 0) + if einterfaces.GetClusterInterface() != nil { + infos = einterfaces.GetClusterInterface().GetClusterInfos() + } + + w.Write([]byte(model.ClusterInfosToJson(infos))) } func getAllAudits(c *Context, w http.ResponseWriter, r *http.Request) { @@ -150,11 +184,26 @@ func saveConfig(c *Context, w http.ResponseWriter, r *http.Request) { return } + if *utils.Cfg.ClusterSettings.Enable { + c.Err = model.NewLocAppError("saveConfig", "ent.cluster.save_config.error", nil, "") + return + } + c.LogAudit("") + //oldCfg := utils.Cfg utils.SaveConfig(utils.CfgFileName, cfg) utils.LoadConfig(utils.CfgFileName) + // Future feature is to sync the configuration files + // if einterfaces.GetClusterInterface() != nil { + // err := einterfaces.GetClusterInterface().ConfigChanged(cfg, oldCfg, true) + // if err != nil { + // c.Err = err + // return + // } + // } + rdata := map[string]string{} rdata["status"] = "OK" w.Write([]byte(model.MapToJson(rdata))) |