summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGeorge Goldberg <george@gberg.me>2017-07-07 15:36:17 +0100
committerGitHub <noreply@github.com>2017-07-07 15:36:17 +0100
commitdb2f6cf0766543b6d9e9fb4ecd10947ce60b46b9 (patch)
treebadd2021308c320d893824bc1ac1b28ba92d384d
parent0495a519499d6cefa289982a94d8f42de541c1f0 (diff)
downloadchat-db2f6cf0766543b6d9e9fb4ecd10947ce60b46b9.tar.gz
chat-db2f6cf0766543b6d9e9fb4ecd10947ce60b46b9.tar.bz2
chat-db2f6cf0766543b6d9e9fb4ecd10947ce60b46b9.zip
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.
-rw-r--r--Makefile19
-rw-r--r--app/elasticsearch.go2
-rw-r--r--app/post.go12
-rw-r--r--cmd/platform/server.go4
-rw-r--r--einterfaces/elasticsearch.go16
-rw-r--r--i18n/en.json16
-rw-r--r--model/license.go10
-rw-r--r--model/license_test.go8
-rw-r--r--utils/config.go2
9 files changed, 62 insertions, 27 deletions
diff --git a/Makefile b/Makefile
index 5a72f5ceb..9407e2ea0 100644
--- a/Makefile
+++ b/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
diff --git a/app/elasticsearch.go b/app/elasticsearch.go
index c021b15e8..87687ddcc 100644
--- a/app/elasticsearch.go
+++ b/app/elasticsearch.go
@@ -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
}
diff --git a/app/post.go b/app/post.go
index f5eb29367..d9e08c864 100644
--- a/app/post.go
+++ b/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
}
diff --git a/cmd/platform/server.go b/cmd/platform/server.go
index 1edb6c2f3..3413472da 100644
--- a/cmd/platform/server.go
+++ b/cmd/platform/server.go
@@ -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())
}
}
diff --git a/einterfaces/elasticsearch.go b/einterfaces/elasticsearch.go
index af89b38a5..e4803aa88 100644
--- a/einterfaces/elasticsearch.go
+++ b/einterfaces/elasticsearch.go
@@ -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
}
diff --git a/i18n/en.json b/i18n/en.json
index 03e833fa3..88ada5ba4 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -3492,6 +3492,18 @@
"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"
},
@@ -3524,6 +3536,10 @@
"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."
},
diff --git a/model/license.go b/model/license.go
index 443d78282..8d53bd4cd 100644
--- a/model/license.go
+++ b/model/license.go
@@ -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 {
diff --git a/model/license_test.go b/model/license_test.go
index 8b65d0700..952ab493e 100644
--- a/model/license_test.go
+++ b/model/license_test.go
@@ -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`
diff --git a/utils/config.go b/utils/config.go
index 22ece13a4..f8ceccc2c 100644
--- a/utils/config.go
+++ b/utils/config.go
@@ -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)
}