MM-22235: Fixing stop/start behavior on Elasticsearch engine (#13887)

Co-authored-by: mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
Jesús Espino
2020-03-03 17:52:59 +01:00
коммит произвёл GitHub
родитель 058f235050
Коммит ccc57e56c3
4 изменённых файлов: 17 добавлений и 12 удалений

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

@@ -43,7 +43,7 @@ type AppIface interface {
AddConfigListener(listener func(*model.Config, *model.Config)) string
AddCursorIdsForPostList(originalList *model.PostList, afterPost, beforePost string, since int64, page, perPage int)
AddDirectChannels(teamId string, user *model.User) *model.AppError
AddLicenseListener(listener func()) string
AddLicenseListener(listener func(oldLicense, newLicense *model.License)) string
AddNotificationEmailToBatch(user *model.User, post *model.Post, team *model.Team) *model.AppError
AddPublicKey(name string, key io.Reader) *model.AppError
AddSamlIdpCertificate(fileData *multipart.FileHeader) *model.AppError

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

@@ -13,8 +13,6 @@ import (
)
func (a *App) LoadLicense() {
a.SetLicense(nil)
licenseId := ""
props, err := a.Srv().Store.System().Get()
if err == nil {
@@ -37,6 +35,7 @@ func (a *App) LoadLicense() {
record, err := a.Srv().Store.License().Get(licenseId)
if err != nil {
mlog.Info("License key from https://mattermost.com required to unlock enterprise features.")
a.SetLicense(nil)
return
}
@@ -108,9 +107,15 @@ func (a *App) License() *model.License {
}
func (a *App) SetLicense(license *model.License) bool {
oldLicense := a.Srv().licenseValue.Load()
defer func() {
for _, listener := range a.Srv().licenseListeners {
listener()
if oldLicense == nil {
listener(nil, license)
} else {
listener(oldLicense.(*model.License), license)
}
}
}()
@@ -169,13 +174,13 @@ func (a *App) RemoveLicense() *model.AppError {
return nil
}
func (s *Server) AddLicenseListener(listener func()) string {
func (s *Server) AddLicenseListener(listener func(oldLicense, newLicense *model.License)) string {
id := model.NewId()
s.licenseListeners[id] = listener
return id
}
func (a *App) AddLicenseListener(listener func()) string {
func (a *App) AddLicenseListener(listener func(oldLicense, newLicense *model.License)) string {
id := model.NewId()
a.Srv().licenseListeners[id] = listener
return id

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

@@ -82,7 +82,7 @@ type Server struct {
licenseValue atomic.Value
clientLicenseValue atomic.Value
licenseListeners map[string]func()
licenseListeners map[string]func(*model.License, *model.License)
timezones *timezones.Timezones
@@ -143,7 +143,7 @@ func NewServer(options ...Option) (*Server, error) {
s := &Server{
goroutineExitSignal: make(chan struct{}, 1),
RootRouter: rootRouter,
licenseListeners: map[string]func(){},
licenseListeners: map[string]func(*model.License, *model.License){},
clientConfig: make(map[string]string),
}
@@ -776,14 +776,14 @@ func (s *Server) StartElasticsearch() {
}
})
s.AddLicenseListener(func() {
if s.License() != nil {
s.AddLicenseListener(func(oldLicense, newLicense *model.License) {
if oldLicense == nil && newLicense != nil {
s.Go(func() {
if err := s.Elasticsearch.Start(); err != nil {
mlog.Error(err.Error())
}
})
} else {
} else if oldLicense != nil && newLicense == nil {
s.Go(func() {
if err := s.Elasticsearch.Stop(); err != nil {
mlog.Error(err.Error())

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

@@ -39,7 +39,7 @@ func (s *Server) RunOldAppInitialization() error {
s.FakeApp().Publish(message)
})
})
s.FakeApp().Srv().licenseListenerId = s.FakeApp().AddLicenseListener(func() {
s.FakeApp().Srv().licenseListenerId = s.FakeApp().AddLicenseListener(func(oldLicense, newLicense *model.License) {
s.FakeApp().configOrLicenseListener()
message := model.NewWebSocketEvent(model.WEBSOCKET_EVENT_LICENSE_CHANGED, "", "", "", nil)