From 6d320ce9a0c09b7b6cad5dd684a41db295f65a17 Mon Sep 17 00:00:00 2001 From: Ibrahim Serdar Acikgoz Date: Tue, 23 Feb 2021 13:38:50 +0300 Subject: [PATCH] [MM-32665] app/product_notices: support notice for deprecating elasticsearch (#16966) * app/product_notices: support notice for deprecating elasticsearch * add a test case --- app/product_notices.go | 20 +++++++++++++++++++- app/product_notices_test.go | 21 +++++++++++++++++++++ model/config.go | 2 ++ 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/app/product_notices.go b/app/product_notices.go index 97c22d8597..a8a886c1e0 100644 --- a/app/product_notices.go +++ b/app/product_notices.go @@ -54,7 +54,7 @@ func cleanupVersion(originalVersion string) string { func noticeMatchesConditions(config *model.Config, preferences store.PreferenceStore, userID string, client model.NoticeClientType, clientVersion string, postCount int64, userCount int64, isSystemAdmin bool, - isTeamAdmin bool, isCloud bool, sku, dbName, dbVer string, + isTeamAdmin bool, isCloud bool, sku, dbName, dbVer, searchEngineName, searchEngineVer string, notice *model.ProductNotice) (bool, error) { cnd := notice.Conditions @@ -163,6 +163,15 @@ func noticeMatchesConditions(config *model.Config, preferences store.PreferenceS return false, errors.Wrapf(err, "Cannot parse DBMS version %s", dbVer) } return extDepVersion.GreaterThan(serverDBMSVersion), nil + case model.SEARCHENGINE_ELASTICSEARCH: + if searchEngineName != model.SEARCHENGINE_ELASTICSEARCH { + return false, nil + } + semverESVersion, err := semver.NewVersion(searchEngineVer) + if err != nil { + return false, errors.Wrapf(err, "Cannot parse search engine version %s", searchEngineVer) + } + return extDepVersion.GreaterThan(semverESVersion), nil default: return false, nil } @@ -251,6 +260,13 @@ func (a *App) GetProductNotices(userID, teamID string, client model.NoticeClient isCloud := a.Srv().License() != nil && *a.Srv().License().Features.Cloud dbName := *a.Srv().Config().SqlSettings.DriverName + var searchEngineName, searchEngineVersion string + engine := a.SearchEngine().ElasticsearchEngine + if engine != nil { + searchEngineName = a.Srv().SearchEngine.ElasticsearchEngine.GetName() + searchEngineVersion = a.Srv().SearchEngine.ElasticsearchEngine.GetFullVersion() + } + filteredNotices := make([]model.NoticeMessage, 0) for noticeIndex, notice := range cachedNotices { @@ -289,6 +305,8 @@ func (a *App) GetProductNotices(userID, teamID string, client model.NoticeClient sku, dbName, cachedDBMSVersion, + searchEngineName, + searchEngineVersion, &cachedNotices[noticeIndex]) if err != nil { return nil, model.NewAppError("GetProductNotices", "api.system.update_notices.validating_failed", nil, err.Error(), http.StatusBadRequest) diff --git a/app/product_notices_test.go b/app/product_notices_test.go index 705fd42362..b519e53c26 100644 --- a/app/product_notices_test.go +++ b/app/product_notices_test.go @@ -62,6 +62,8 @@ func TestNoticeValidation(t *testing.T) { notice *model.ProductNotice dbmsName string dbmsVer string + searchEngineName string + searchEngineVer string } messages := map[string]model.NoticeMessageInternal{ "en": { @@ -610,6 +612,23 @@ func TestNoticeValidation(t *testing.T) { wantErr: false, wantOk: false, }, + { + name: "notice on deprecating elasticsearch, server has unsupported search engine", + args: args{ + searchEngineName: "elasticsearch", + searchEngineVer: "6.4.1", + notice: &model.ProductNotice{ + Conditions: model.Conditions{ + DeprecatingDependency: &model.ExternalDependency{ + Name: "elasticsearch", + MinimumVersion: "7", + }, + }, + }, + }, + wantErr: false, + wantOk: true, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -635,6 +654,8 @@ func TestNoticeValidation(t *testing.T) { tt.args.sku, tt.args.dbmsName, tt.args.dbmsVer, + tt.args.searchEngineName, + tt.args.searchEngineVer, tt.args.notice, ); (err != nil) != tt.wantErr { t.Errorf("noticeMatchesConditions() error = %v, wantErr %v", err, tt.wantErr) diff --git a/model/config.go b/model/config.go index c27b1d8533..8fb7b5954a 100644 --- a/model/config.go +++ b/model/config.go @@ -36,6 +36,8 @@ const ( DATABASE_DRIVER_MYSQL = "mysql" DATABASE_DRIVER_POSTGRES = "postgres" + SEARCHENGINE_ELASTICSEARCH = "elasticsearch" + MINIO_ACCESS_KEY = "minioaccesskey" MINIO_SECRET_KEY = "miniosecretkey" MINIO_BUCKET = "mattermost-test"