PLT-6976: Elasticsearch capitalisation and tests. (#6839)
* Fixes Elasticsearch to have consistent capitalisation everywhere across the code and UI (except the config file unfortunately). * Adds basic unit tests for Elastichsearch. * Adds a Elasticsearch docker image to the Makefile to enable testing the Elasticsearch feature.
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
0495a51949
Коммит
db2f6cf076
19
Makefile
19
Makefile
@@ -123,6 +123,14 @@ ifeq ($(BUILD_ENTERPRISE_READY),true)
|
||||
docker start mattermost-openldap > /dev/null; \
|
||||
sleep 10; \
|
||||
fi
|
||||
|
||||
@if [ $(shell docker ps -a | grep -ci mattermost-elasticsearch) -eq 0 ]; then \
|
||||
echo starting mattermost-elasticsearch; \
|
||||
docker run --name mattermost-elasticsearch -p 9200:9200 -e "http.host=0.0.0.0" -e "transport.host=127.0.0.1" -e "ES_JAVA_OPTS=-Xms250m -Xmx250m" -d grundleborg/elasticsearch:latest > /dev/null; \
|
||||
elif [ $(shell docker ps | grep -ci mattermost-elasticsearch) -eq 0 ]; then \
|
||||
echo restarting mattermost-elasticsearch; \
|
||||
docker start mattermost-elasticsearch> /dev/null; \
|
||||
fi
|
||||
endif
|
||||
|
||||
stop-docker:
|
||||
@@ -148,6 +156,11 @@ stop-docker:
|
||||
docker stop mattermost-inbucket > /dev/null; \
|
||||
fi
|
||||
|
||||
@if [ $(shell docker ps -a | grep -ci mattermost-elasticsearch) -eq 1 ]; then \
|
||||
echo stopping mattermost-elasticsearch; \
|
||||
docker stop mattermost-elasticsearch > /dev/null; \
|
||||
fi
|
||||
|
||||
clean-docker:
|
||||
@echo Removing docker containers
|
||||
|
||||
@@ -175,6 +188,12 @@ clean-docker:
|
||||
docker rm -v mattermost-inbucket > /dev/null; \
|
||||
fi
|
||||
|
||||
@if [ $(shell docker ps -a | grep -ci mattermost-elasticsearch) -eq 1 ]; then \
|
||||
echo removing mattermost-elasticsearch; \
|
||||
docker stop mattermost-elasticsearch > /dev/null; \
|
||||
docker rm -v mattermost-elasticsearch > /dev/null; \
|
||||
fi
|
||||
|
||||
check-client-style:
|
||||
@echo Checking client style
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
)
|
||||
|
||||
func TestElasticsearch() *model.AppError {
|
||||
if esI := einterfaces.GetElasticSearchInterface(); esI != nil {
|
||||
if esI := einterfaces.GetElasticsearchInterface(); esI != nil {
|
||||
if err := esI.TestConfig(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
12
app/post.go
12
app/post.go
@@ -99,7 +99,7 @@ func CreatePost(post *model.Post, teamId string, triggerWebhooks bool) (*model.P
|
||||
rpost = result.Data.(*model.Post)
|
||||
}
|
||||
|
||||
esInterface := einterfaces.GetElasticSearchInterface()
|
||||
esInterface := einterfaces.GetElasticsearchInterface()
|
||||
if esInterface != nil && *utils.Cfg.ElasticSearchSettings.EnableIndexing {
|
||||
go esInterface.IndexPost(rpost, teamId)
|
||||
}
|
||||
@@ -284,7 +284,7 @@ func UpdatePost(post *model.Post, safeUpdate bool) (*model.Post, *model.AppError
|
||||
} else {
|
||||
rpost := result.Data.(*model.Post)
|
||||
|
||||
esInterface := einterfaces.GetElasticSearchInterface()
|
||||
esInterface := einterfaces.GetElasticsearchInterface()
|
||||
if esInterface != nil && *utils.Cfg.ElasticSearchSettings.EnableIndexing {
|
||||
go func() {
|
||||
if rchannel := <-Srv.Store.Channel().GetForPost(rpost.Id); rchannel.Err != nil {
|
||||
@@ -471,7 +471,7 @@ func DeletePost(postId string) (*model.Post, *model.AppError) {
|
||||
go DeletePostFiles(post)
|
||||
go DeleteFlaggedPosts(post.Id)
|
||||
|
||||
esInterface := einterfaces.GetElasticSearchInterface()
|
||||
esInterface := einterfaces.GetElasticsearchInterface()
|
||||
if esInterface != nil && *utils.Cfg.ElasticSearchSettings.EnableIndexing {
|
||||
go esInterface.DeletePost(post.Id)
|
||||
}
|
||||
@@ -502,8 +502,8 @@ func DeletePostFiles(post *model.Post) {
|
||||
func SearchPostsInTeam(terms string, userId string, teamId string, isOrSearch bool) (*model.PostList, *model.AppError) {
|
||||
paramsList := model.ParseSearchParams(terms)
|
||||
|
||||
esInterface := einterfaces.GetElasticSearchInterface()
|
||||
if esInterface != nil && *utils.Cfg.ElasticSearchSettings.EnableSearching && utils.IsLicensed && *utils.License.Features.ElasticSearch {
|
||||
esInterface := einterfaces.GetElasticsearchInterface()
|
||||
if esInterface != nil && *utils.Cfg.ElasticSearchSettings.EnableSearching && utils.IsLicensed && *utils.License.Features.Elasticsearch {
|
||||
finalParamsList := []*model.SearchParams{}
|
||||
|
||||
for _, params := range paramsList {
|
||||
@@ -539,7 +539,7 @@ func SearchPostsInTeam(terms string, userId string, teamId string, isOrSearch bo
|
||||
return nil, err
|
||||
}
|
||||
|
||||
postIds, err := einterfaces.GetElasticSearchInterface().SearchPosts(userChannels, finalParamsList)
|
||||
postIds, err := einterfaces.GetElasticsearchInterface().SearchPosts(userChannels, finalParamsList)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -120,8 +120,8 @@ func runServer(configFileLocation string) {
|
||||
einterfaces.GetMetricsInterface().StartServer()
|
||||
}
|
||||
|
||||
if einterfaces.GetElasticSearchInterface() != nil {
|
||||
if err := einterfaces.GetElasticSearchInterface().Start(); err != nil {
|
||||
if einterfaces.GetElasticsearchInterface() != nil {
|
||||
if err := einterfaces.GetElasticsearchInterface().Start(); err != nil {
|
||||
l4g.Error(err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,20 +5,20 @@ package einterfaces
|
||||
|
||||
import "github.com/mattermost/platform/model"
|
||||
|
||||
type ElasticSearchInterface interface {
|
||||
type ElasticsearchInterface interface {
|
||||
Start() *model.AppError
|
||||
IndexPost(post *model.Post, teamId string)
|
||||
IndexPost(post *model.Post, teamId string) *model.AppError
|
||||
SearchPosts(channels *model.ChannelList, searchParams []*model.SearchParams) ([]string, *model.AppError)
|
||||
DeletePost(postId string)
|
||||
DeletePost(postId string) *model.AppError
|
||||
TestConfig() *model.AppError
|
||||
}
|
||||
|
||||
var theElasticSearchInterface ElasticSearchInterface
|
||||
var theElasticsearchInterface ElasticsearchInterface
|
||||
|
||||
func RegisterElasticSearchInterface(newInterface ElasticSearchInterface) {
|
||||
theElasticSearchInterface = newInterface
|
||||
func RegisterElasticsearchInterface(newInterface ElasticsearchInterface) {
|
||||
theElasticsearchInterface = newInterface
|
||||
}
|
||||
|
||||
func GetElasticSearchInterface() ElasticSearchInterface {
|
||||
return theElasticSearchInterface
|
||||
func GetElasticsearchInterface() ElasticsearchInterface {
|
||||
return theElasticsearchInterface
|
||||
}
|
||||
|
||||
16
i18n/en.json
16
i18n/en.json
@@ -3491,6 +3491,18 @@
|
||||
"id": "ent.compliance.run_started.info",
|
||||
"translation": "Compliance export started for job '{{.JobName}}' at '{{.FilePath}}'"
|
||||
},
|
||||
{
|
||||
"id": "ent.elasticsearch.delete_post.error",
|
||||
"translation": "Failed to delete the post"
|
||||
},
|
||||
{
|
||||
"id": "ent.elasticsearch.index_post.error",
|
||||
"translation": "Failed to index the post"
|
||||
},
|
||||
{
|
||||
"id": "ent.elasticsearch.not_started.error",
|
||||
"translation": "Elasticsearch is not started"
|
||||
},
|
||||
{
|
||||
"id": "ent.elasticsearch.search_posts.disabled",
|
||||
"translation": "ElasticSearch searching is disabled on this server"
|
||||
@@ -3523,6 +3535,10 @@
|
||||
"id": "ent.elasticsearch.start.index_settings_failed",
|
||||
"translation": "Failed to set ElasticSearch index settings"
|
||||
},
|
||||
{
|
||||
"id": "ent.elasticsearch.test_config.connect_failed",
|
||||
"translation": "Connecting to Elasticsearch server failed."
|
||||
},
|
||||
{
|
||||
"id": "ent.elasticsearch.test_config.indexing_disabled.error",
|
||||
"translation": "Elasticsearch is disabled."
|
||||
|
||||
@@ -49,7 +49,7 @@ type Features struct {
|
||||
MHPNS *bool `json:"mhpns"`
|
||||
SAML *bool `json:"saml"`
|
||||
PasswordRequirements *bool `json:"password_requirements"`
|
||||
ElasticSearch *bool `json:"elastic_search"`
|
||||
Elasticsearch *bool `json:"elastic_search"`
|
||||
Announcement *bool `json:"announcement"`
|
||||
// after we enabled more features for webrtc we'll need to control them with this
|
||||
FutureFeatures *bool `json:"future_features"`
|
||||
@@ -68,7 +68,7 @@ func (f *Features) ToMap() map[string]interface{} {
|
||||
"mhpns": *f.MHPNS,
|
||||
"saml": *f.SAML,
|
||||
"password": *f.PasswordRequirements,
|
||||
"elastic_search": *f.ElasticSearch,
|
||||
"elastic_search": *f.Elasticsearch,
|
||||
"future": *f.FutureFeatures,
|
||||
}
|
||||
}
|
||||
@@ -139,9 +139,9 @@ func (f *Features) SetDefaults() {
|
||||
*f.PasswordRequirements = *f.FutureFeatures
|
||||
}
|
||||
|
||||
if f.ElasticSearch == nil {
|
||||
f.ElasticSearch = new(bool)
|
||||
*f.ElasticSearch = *f.FutureFeatures
|
||||
if f.Elasticsearch == nil {
|
||||
f.Elasticsearch = new(bool)
|
||||
*f.Elasticsearch = *f.FutureFeatures
|
||||
}
|
||||
|
||||
if f.Announcement == nil {
|
||||
|
||||
@@ -45,7 +45,7 @@ func TestLicenseFeaturesSetDefaults(t *testing.T) {
|
||||
CheckTrue(t, *f.MHPNS)
|
||||
CheckTrue(t, *f.SAML)
|
||||
CheckTrue(t, *f.PasswordRequirements)
|
||||
CheckTrue(t, *f.ElasticSearch)
|
||||
CheckTrue(t, *f.Elasticsearch)
|
||||
CheckTrue(t, *f.FutureFeatures)
|
||||
|
||||
f = Features{}
|
||||
@@ -64,7 +64,7 @@ func TestLicenseFeaturesSetDefaults(t *testing.T) {
|
||||
*f.MHPNS = true
|
||||
*f.SAML = true
|
||||
*f.PasswordRequirements = true
|
||||
*f.ElasticSearch = true
|
||||
*f.Elasticsearch = true
|
||||
|
||||
f.SetDefaults()
|
||||
|
||||
@@ -80,7 +80,7 @@ func TestLicenseFeaturesSetDefaults(t *testing.T) {
|
||||
CheckTrue(t, *f.MHPNS)
|
||||
CheckTrue(t, *f.SAML)
|
||||
CheckTrue(t, *f.PasswordRequirements)
|
||||
CheckTrue(t, *f.ElasticSearch)
|
||||
CheckTrue(t, *f.Elasticsearch)
|
||||
CheckFalse(t, *f.FutureFeatures)
|
||||
}
|
||||
|
||||
@@ -161,7 +161,7 @@ func TestLicenseToFromJson(t *testing.T) {
|
||||
CheckBool(t, *f1.MHPNS, *f.MHPNS)
|
||||
CheckBool(t, *f1.SAML, *f.SAML)
|
||||
CheckBool(t, *f1.PasswordRequirements, *f.PasswordRequirements)
|
||||
CheckBool(t, *f1.ElasticSearch, *f.ElasticSearch)
|
||||
CheckBool(t, *f1.Elasticsearch, *f.Elasticsearch)
|
||||
CheckBool(t, *f1.FutureFeatures, *f.FutureFeatures)
|
||||
|
||||
invalid := `{"asdf`
|
||||
|
||||
@@ -536,7 +536,7 @@ func getClientConfig(c *model.Config) map[string]string {
|
||||
props["PasswordRequireSymbol"] = strconv.FormatBool(*c.PasswordSettings.Symbol)
|
||||
}
|
||||
|
||||
if *License.Features.ElasticSearch {
|
||||
if *License.Features.Elasticsearch {
|
||||
props["ElasticSearchEnableIndexing"] = strconv.FormatBool(*c.ElasticSearchSettings.EnableIndexing)
|
||||
props["ElasticSearchEnableSearching"] = strconv.FormatBool(*c.ElasticSearchSettings.EnableSearching)
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user