[MM-32665] app/product_notices: support notice for deprecating elasticsearch (#16966)
* app/product_notices: support notice for deprecating elasticsearch * add a test case
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
7277e23e04
Коммит
6d320ce9a0
@@ -54,7 +54,7 @@ func cleanupVersion(originalVersion string) string {
|
|||||||
|
|
||||||
func noticeMatchesConditions(config *model.Config, preferences store.PreferenceStore, userID string,
|
func noticeMatchesConditions(config *model.Config, preferences store.PreferenceStore, userID string,
|
||||||
client model.NoticeClientType, clientVersion string, postCount int64, userCount int64, isSystemAdmin bool,
|
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) {
|
notice *model.ProductNotice) (bool, error) {
|
||||||
cnd := notice.Conditions
|
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 false, errors.Wrapf(err, "Cannot parse DBMS version %s", dbVer)
|
||||||
}
|
}
|
||||||
return extDepVersion.GreaterThan(serverDBMSVersion), nil
|
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:
|
default:
|
||||||
return false, nil
|
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
|
isCloud := a.Srv().License() != nil && *a.Srv().License().Features.Cloud
|
||||||
dbName := *a.Srv().Config().SqlSettings.DriverName
|
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)
|
filteredNotices := make([]model.NoticeMessage, 0)
|
||||||
|
|
||||||
for noticeIndex, notice := range cachedNotices {
|
for noticeIndex, notice := range cachedNotices {
|
||||||
@@ -289,6 +305,8 @@ func (a *App) GetProductNotices(userID, teamID string, client model.NoticeClient
|
|||||||
sku,
|
sku,
|
||||||
dbName,
|
dbName,
|
||||||
cachedDBMSVersion,
|
cachedDBMSVersion,
|
||||||
|
searchEngineName,
|
||||||
|
searchEngineVersion,
|
||||||
&cachedNotices[noticeIndex])
|
&cachedNotices[noticeIndex])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, model.NewAppError("GetProductNotices", "api.system.update_notices.validating_failed", nil, err.Error(), http.StatusBadRequest)
|
return nil, model.NewAppError("GetProductNotices", "api.system.update_notices.validating_failed", nil, err.Error(), http.StatusBadRequest)
|
||||||
|
|||||||
@@ -62,6 +62,8 @@ func TestNoticeValidation(t *testing.T) {
|
|||||||
notice *model.ProductNotice
|
notice *model.ProductNotice
|
||||||
dbmsName string
|
dbmsName string
|
||||||
dbmsVer string
|
dbmsVer string
|
||||||
|
searchEngineName string
|
||||||
|
searchEngineVer string
|
||||||
}
|
}
|
||||||
messages := map[string]model.NoticeMessageInternal{
|
messages := map[string]model.NoticeMessageInternal{
|
||||||
"en": {
|
"en": {
|
||||||
@@ -610,6 +612,23 @@ func TestNoticeValidation(t *testing.T) {
|
|||||||
wantErr: false,
|
wantErr: false,
|
||||||
wantOk: 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 {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
@@ -635,6 +654,8 @@ func TestNoticeValidation(t *testing.T) {
|
|||||||
tt.args.sku,
|
tt.args.sku,
|
||||||
tt.args.dbmsName,
|
tt.args.dbmsName,
|
||||||
tt.args.dbmsVer,
|
tt.args.dbmsVer,
|
||||||
|
tt.args.searchEngineName,
|
||||||
|
tt.args.searchEngineVer,
|
||||||
tt.args.notice,
|
tt.args.notice,
|
||||||
); (err != nil) != tt.wantErr {
|
); (err != nil) != tt.wantErr {
|
||||||
t.Errorf("noticeMatchesConditions() error = %v, wantErr %v", err, tt.wantErr)
|
t.Errorf("noticeMatchesConditions() error = %v, wantErr %v", err, tt.wantErr)
|
||||||
|
|||||||
@@ -36,6 +36,8 @@ const (
|
|||||||
DATABASE_DRIVER_MYSQL = "mysql"
|
DATABASE_DRIVER_MYSQL = "mysql"
|
||||||
DATABASE_DRIVER_POSTGRES = "postgres"
|
DATABASE_DRIVER_POSTGRES = "postgres"
|
||||||
|
|
||||||
|
SEARCHENGINE_ELASTICSEARCH = "elasticsearch"
|
||||||
|
|
||||||
MINIO_ACCESS_KEY = "minioaccesskey"
|
MINIO_ACCESS_KEY = "minioaccesskey"
|
||||||
MINIO_SECRET_KEY = "miniosecretkey"
|
MINIO_SECRET_KEY = "miniosecretkey"
|
||||||
MINIO_BUCKET = "mattermost-test"
|
MINIO_BUCKET = "mattermost-test"
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user