PLT-6595: API to purge Elasticsearch indexes. (#6971)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
97f34e483b
Коммит
fe368a7456
@@ -16,6 +16,7 @@ func InitElasticsearch() {
|
|||||||
l4g.Debug(utils.T("api.elasticsearch.init.debug"))
|
l4g.Debug(utils.T("api.elasticsearch.init.debug"))
|
||||||
|
|
||||||
BaseRoutes.Elasticsearch.Handle("/test", ApiSessionRequired(testElasticsearch)).Methods("POST")
|
BaseRoutes.Elasticsearch.Handle("/test", ApiSessionRequired(testElasticsearch)).Methods("POST")
|
||||||
|
BaseRoutes.Elasticsearch.Handle("/purge_indexes", ApiSessionRequired(purgeElasticsearchIndexes)).Methods("POST")
|
||||||
}
|
}
|
||||||
|
|
||||||
func testElasticsearch(c *Context, w http.ResponseWriter, r *http.Request) {
|
func testElasticsearch(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||||
@@ -36,3 +37,17 @@ func testElasticsearch(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
ReturnStatusOK(w)
|
ReturnStatusOK(w)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func purgeElasticsearchIndexes(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||||
|
if !app.SessionHasPermissionTo(c.Session, model.PERMISSION_MANAGE_SYSTEM) {
|
||||||
|
c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := app.PurgeElasticsearchIndexes(); err != nil {
|
||||||
|
c.Err = err
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
ReturnStatusOK(w)
|
||||||
|
}
|
||||||
|
|||||||
@@ -17,3 +17,14 @@ func TestElasticsearchTest(t *testing.T) {
|
|||||||
_, resp = th.SystemAdminClient.TestElasticsearch()
|
_, resp = th.SystemAdminClient.TestElasticsearch()
|
||||||
CheckNotImplementedStatus(t, resp)
|
CheckNotImplementedStatus(t, resp)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestElasticsearchPurgeIndexes(t *testing.T) {
|
||||||
|
th := Setup().InitBasic().InitSystemAdmin()
|
||||||
|
defer TearDown()
|
||||||
|
|
||||||
|
_, resp := th.Client.PurgeElasticsearchIndexes()
|
||||||
|
CheckForbiddenStatus(t, resp)
|
||||||
|
|
||||||
|
_, resp = th.SystemAdminClient.PurgeElasticsearchIndexes()
|
||||||
|
CheckNotImplementedStatus(t, resp)
|
||||||
|
}
|
||||||
|
|||||||
@@ -31,3 +31,16 @@ func TestElasticsearch(cfg *model.Config) *model.AppError {
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func PurgeElasticsearchIndexes() *model.AppError {
|
||||||
|
if esI := einterfaces.GetElasticsearchInterface(); esI != nil {
|
||||||
|
if err := esI.PurgeIndexes(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
err := model.NewAppError("PurgeElasticsearchIndexes", "ent.elasticsearch.test_config.license.error", nil, "", http.StatusNotImplemented)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ type ElasticsearchInterface interface {
|
|||||||
SearchPosts(channels *model.ChannelList, searchParams []*model.SearchParams) ([]string, *model.AppError)
|
SearchPosts(channels *model.ChannelList, searchParams []*model.SearchParams) ([]string, *model.AppError)
|
||||||
DeletePost(postId string) *model.AppError
|
DeletePost(postId string) *model.AppError
|
||||||
TestConfig(cfg *model.Config) *model.AppError
|
TestConfig(cfg *model.Config) *model.AppError
|
||||||
|
PurgeIndexes() *model.AppError
|
||||||
}
|
}
|
||||||
|
|
||||||
var theElasticsearchInterface ElasticsearchInterface
|
var theElasticsearchInterface ElasticsearchInterface
|
||||||
|
|||||||
@@ -3511,6 +3511,14 @@
|
|||||||
"id": "ent.elasticsearch.search_posts.disabled",
|
"id": "ent.elasticsearch.search_posts.disabled",
|
||||||
"translation": "ElasticSearch searching is disabled on this server"
|
"translation": "ElasticSearch searching is disabled on this server"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"id": "ent.elasticsearch.generic.disabled",
|
||||||
|
"translation": "ElasticSearch search is not enabled on this server"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "ent.elasticsearch.purge_indexes.delete_failed",
|
||||||
|
"translation": "Failed to delete Elasticsearch index"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"id": "ent.elasticsearch.search_posts.search_failed",
|
"id": "ent.elasticsearch.search_posts.search_failed",
|
||||||
"translation": "Search failed to complete"
|
"translation": "Search failed to complete"
|
||||||
|
|||||||
@@ -2551,6 +2551,16 @@ func (c *Client4) TestElasticsearch() (bool, *Response) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PurgeElasticsearchIndexes immediately deletes all Elasticsearch indexes.
|
||||||
|
func (c *Client4) PurgeElasticsearchIndexes() (bool, *Response) {
|
||||||
|
if r, err := c.DoApiPost(c.GetElasticsearchRoute()+"/test", ""); err != nil {
|
||||||
|
return false, BuildErrorResponse(r, err)
|
||||||
|
} else {
|
||||||
|
defer closeBody(r)
|
||||||
|
return CheckStatusOK(r), BuildResponse(r)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Commands Section
|
// Commands Section
|
||||||
|
|
||||||
// CreateCommand will create a new command if the user have the right permissions.
|
// CreateCommand will create a new command if the user have the right permissions.
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user