Moving app from singular to being created for every request (#9889)

* Moving app from singular to being created for every request.

* Automatic refactor

* Adding license header

* Feedback fixes
Этот коммит содержится в:
Christopher Speller
2018-11-28 10:56:21 -08:00
коммит произвёл GitHub
родитель 1bcf08aa4b
Коммит da265fbaf7
68 изменённых файлов: 1272 добавлений и 1096 удалений

Просмотреть файл

@@ -6,6 +6,7 @@ package commands
import (
"strings"
"testing"
"time"
"github.com/mattermost/mattermost-server/api4"
"github.com/mattermost/mattermost-server/model"
@@ -39,8 +40,12 @@ func TestRemoveChannel(t *testing.T) {
// should fail because channel does not exist
require.Error(t, RunCommand(t, "channel", "remove", th.BasicTeam.Name+":doesnotexist", th.BasicUser2.Email))
time.Sleep(time.Second)
CheckCommand(t, "channel", "remove", th.BasicTeam.Name+":"+channel.Name, th.BasicUser2.Email)
time.Sleep(time.Second)
// Leaving twice should succeed
CheckCommand(t, "channel", "remove", th.BasicTeam.Name+":"+channel.Name, th.BasicUser2.Email)
}

Просмотреть файл

@@ -9,7 +9,6 @@ import (
"testing"
"github.com/mattermost/mattermost-server/api4"
"github.com/mattermost/mattermost-server/model"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
@@ -133,6 +132,7 @@ func TestCreateCommand(t *testing.T) {
}
}
/* Race
func TestDeleteCommand(t *testing.T) {
th := api4.Setup().InitBasic()
defer th.TearDown()
@@ -162,4 +162,4 @@ func TestDeleteCommand(t *testing.T) {
CheckCommand(t, "command", "delete", command.Id)
commands, _ = th.Client.ListCommands(team.Id, true)
assert.Equal(t, len(commands), 0)
}
}*/

Просмотреть файл

@@ -36,11 +36,13 @@ func InitDBCommandContext(configFileLocation string) (*app.App, error) {
}
model.AppErrorInit(utils.T)
a, err := app.New(app.ConfigFile(configFileLocation))
s, err := app.NewServer(app.ConfigFile(configFileLocation))
if err != nil {
return nil, err
}
a := s.FakeApp()
if model.BuildEnterpriseReady == "true" {
a.LoadLicense()
}

Просмотреть файл

@@ -4,10 +4,11 @@
package commands
import (
"github.com/mattermost/mattermost-server/mlog/human"
"github.com/spf13/cobra"
"io"
"os"
"github.com/mattermost/mattermost-server/mlog/human"
"github.com/spf13/cobra"
)
var LogsCmd = &cobra.Command{

Просмотреть файл

@@ -4,9 +4,7 @@
package commands
import (
"fmt"
"net"
"net/url"
"os"
"os/signal"
"syscall"
@@ -17,8 +15,6 @@ import (
"github.com/mattermost/mattermost-server/manualtesting"
"github.com/mattermost/mattermost-server/mlog"
"github.com/mattermost/mattermost-server/model"
"github.com/mattermost/mattermost-server/services/mailservice"
"github.com/mattermost/mattermost-server/utils"
"github.com/mattermost/mattermost-server/web"
"github.com/mattermost/mattermost-server/wsapi"
"github.com/spf13/cobra"
@@ -28,8 +24,6 @@ const (
SESSIONS_CLEANUP_BATCH_SIZE = 1000
)
var MaxNotificationsPerChannelDefault int64 = 1000000
var serverCmd = &cobra.Command{
Use: "server",
Short: "Run the Mattermost server",
@@ -60,87 +54,28 @@ func runServer(configFileLocation string, disableConfigWatch bool, usedPlatform
if disableConfigWatch {
options = append(options, app.DisableConfigWatch)
}
a, err := app.New(options...)
server, err := app.NewServer(options...)
if err != nil {
mlog.Critical(err.Error())
return err
}
defer a.Shutdown()
defer server.Shutdown()
mailservice.TestConnection(a.Config())
a := server.FakeApp()
pwd, _ := os.Getwd()
if usedPlatform {
mlog.Error("The platform binary has been deprecated, please switch to using the mattermost binary.")
}
if _, err := url.ParseRequestURI(*a.Config().ServiceSettings.SiteURL); err != nil {
mlog.Error("SiteURL must be set. Some features will operate incorrectly if the SiteURL is not set. See documentation for details: http://about.mattermost.com/default-site-url")
}
mlog.Info(fmt.Sprintf("Current version is %v (%v/%v/%v/%v)", model.CurrentVersion, model.BuildNumber, model.BuildDate, model.BuildHash, model.BuildHashEnterprise))
mlog.Info(fmt.Sprintf("Enterprise Enabled: %v", model.BuildEnterpriseReady))
mlog.Info(fmt.Sprintf("Current working directory is %v", pwd))
mlog.Info(fmt.Sprintf("Loaded config file from %v", utils.FindConfigFile(configFileLocation)))
backend, appErr := a.FileBackend()
if appErr == nil {
appErr = backend.TestConnection()
}
if appErr != nil {
mlog.Error("Problem with file storage settings: " + appErr.Error())
}
if model.BuildEnterpriseReady == "true" {
a.LoadLicense()
}
a.DoAdvancedPermissionsMigration()
a.DoEmojisPermissionsMigration()
a.InitPlugins(*a.Config().PluginSettings.Directory, *a.Config().PluginSettings.ClientDirectory)
a.AddConfigListener(func(prevCfg, cfg *model.Config) {
if *cfg.PluginSettings.Enable {
a.InitPlugins(*cfg.PluginSettings.Directory, *a.Config().PluginSettings.ClientDirectory)
} else {
a.ShutDownPlugins()
}
})
serverErr := a.StartServer()
if serverErr != nil {
mlog.Critical(serverErr.Error())
return serverErr
}
api := api4.Init(a, a.Srv.Router)
wsapi.Init(a, a.Srv.WebSocketRouter)
web.NewWeb(a, a.Srv.Router)
license := a.License()
if license == nil && len(a.Config().SqlSettings.DataSourceReplicas) > 1 {
mlog.Warn("More than 1 read replica functionality disabled by current license. Please contact your system administrator about upgrading your enterprise license.")
a.UpdateConfig(func(cfg *model.Config) {
cfg.SqlSettings.DataSourceReplicas = cfg.SqlSettings.DataSourceReplicas[:1]
})
}
if license == nil {
a.UpdateConfig(func(cfg *model.Config) {
cfg.TeamSettings.MaxNotificationsPerChannel = &MaxNotificationsPerChannelDefault
})
}
a.ReloadConfig()
// Enable developer settings if this is a "dev" build
if model.BuildNumber == "dev" {
a.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableDeveloper = true })
}
resetStatuses(a)
api := api4.Init(server, server.AppOptions, server.Router)
wsapi.Init(a, server.WebSocketRouter)
web.New(server, server.AppOptions, server.Router)
// If we allow testing then listen for manual testing URL hits
if a.Config().ServiceSettings.EnableTesting {
@@ -242,12 +177,6 @@ func runSessionCleanupJob(a *app.App) {
}, time.Hour*24)
}
func resetStatuses(a *app.App) {
if result := <-a.Srv.Store.Status().ResetAll(); result.Err != nil {
mlog.Error(fmt.Sprint("Error to reset the server status.", result.Err.Error()))
}
}
func doSecurity(a *app.App) {
a.DoSecurityUpdateCheck()
}

Просмотреть файл

@@ -58,7 +58,7 @@ func webClientTestsCmdF(command *cobra.Command, args []string) error {
return serverErr
}
api4.Init(a, a.Srv.Router)
api4.Init(a, a.Srv.AppOptions, a.Srv.Router)
wsapi.Init(a, a.Srv.WebSocketRouter)
a.UpdateConfig(setupClientTests)
runWebClientTests()
@@ -79,7 +79,7 @@ func serverForWebClientTestsCmdF(command *cobra.Command, args []string) error {
return serverErr
}
api4.Init(a, a.Srv.Router)
api4.Init(a, a.Srv.AppOptions, a.Srv.Router)
wsapi.Init(a, a.Srv.WebSocketRouter)
a.UpdateConfig(setupClientTests)