Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Genesys PGR
Genesys Backend
Commits
d4c814d7
Commit
d4c814d7
authored
Apr 20, 2016
by
Matija Obreza
Browse files
Delete and move ES aliases
parent
5e6fefa9
Changes
4
Hide whitespace changes
Inline
Side-by-side
src/main/java/org/genesys2/server/service/ElasticService.java
View file @
d4c814d7
...
...
@@ -58,4 +58,14 @@ public interface ElasticService {
*/
void
regenerateIndexes
();
/**
* Move alias to a different index
*
* @param aliasName
* @param indexName
*/
void
realias
(
String
aliasName
,
String
indexName
);
void
deleteAlias
(
String
aliasName
);
}
src/main/java/org/genesys2/server/service/impl/ElasticsearchSearchServiceImpl.java
View file @
d4c814d7
...
...
@@ -490,11 +490,23 @@ public class ElasticsearchSearchServiceImpl implements ElasticService, Initializ
* @param indexName
* The index the alias points to
*/
private
void
realias
(
String
aliasName
,
String
indexName
)
{
@Override
public
void
realias
(
String
aliasName
,
String
indexName
)
{
if
(
LOG
.
isDebugEnabled
())
LOG
.
debug
(
"Loading alias definition for "
+
aliasName
);
deleteAlias
(
aliasName
);
AliasQuery
query
=
new
AliasQuery
();
query
.
setAliasName
(
aliasName
);
query
.
setIndexName
(
indexName
);
LOG
.
info
(
"Adding alias "
+
aliasName
+
" to index "
+
indexName
);
elasticsearchTemplate
.
addAlias
(
query
);
}
@Override
public
void
deleteAlias
(
String
aliasName
)
{
ImmutableOpenMap
<
String
,
AliasMetaData
>
x
=
client
.
admin
().
cluster
().
prepareState
().
execute
().
actionGet
().
getState
().
getMetaData
().
getAliases
()
.
get
(
aliasName
);
...
...
@@ -511,12 +523,6 @@ public class ElasticsearchSearchServiceImpl implements ElasticService, Initializ
elasticsearchTemplate
.
removeAlias
(
query
);
}
}
AliasQuery
query
=
new
AliasQuery
();
query
.
setAliasName
(
aliasName
);
query
.
setIndexName
(
indexName
);
LOG
.
info
(
"Adding alias "
+
aliasName
+
" to index "
+
indexName
);
elasticsearchTemplate
.
addAlias
(
query
);
}
private
void
createIndex
(
String
indexName
,
Map
<?,
?>
indexMapping
,
Map
<?,
?>
settings
)
{
...
...
src/main/java/org/genesys2/server/servlet/controller/admin/ElasticSearchController.java
View file @
d4c814d7
...
...
@@ -16,7 +16,12 @@
package
org.genesys2.server.servlet.controller.admin
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
java.io.IOException
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
org.apache.commons.logging.Log
;
import
org.apache.commons.logging.LogFactory
;
import
org.elasticsearch.client.Client
;
...
...
@@ -35,11 +40,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
java.io.IOException
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
@Controller
@RequestMapping
(
"/admin/elastic"
)
...
...
@@ -66,10 +67,8 @@ public class ElasticSearchController {
*/
@RequestMapping
(
"/"
)
public
String
viewIndexesAndAliases
(
Model
model
)
{
ImmutableOpenMap
<
String
,
IndexMetaData
>
indicesImmutableMap
=
client
.
admin
().
cluster
()
.
prepareState
().
execute
()
.
actionGet
().
getState
()
.
getMetaData
().
getIndices
();
ImmutableOpenMap
<
String
,
IndexMetaData
>
indicesImmutableMap
=
client
.
admin
().
cluster
().
prepareState
().
execute
().
actionGet
().
getState
().
getMetaData
()
.
getIndices
();
Map
<
String
,
List
<
AliasMetaData
>>
indexMap
=
new
HashMap
<>();
for
(
ObjectObjectCursor
<
String
,
IndexMetaData
>
cursor
:
indicesImmutableMap
)
{
...
...
@@ -121,4 +120,16 @@ public class ElasticSearchController {
elasticUpdater
.
clearQueues
();
return
"redirect:/admin/elastic/"
;
}
@RequestMapping
(
method
=
RequestMethod
.
POST
,
value
=
"/action"
,
params
=
{
"action=realias"
})
public
String
moveAlias
(
@RequestParam
(
name
=
"aliasName"
)
String
aliasName
,
@RequestParam
(
name
=
"indexName"
)
String
indexName
)
{
elasticService
.
realias
(
aliasName
,
indexName
);
return
"redirect:/admin/elastic/"
;
}
@RequestMapping
(
method
=
RequestMethod
.
POST
,
value
=
"/action"
,
params
=
{
"action=delete-alias"
})
public
String
deleteAlias
(
@RequestParam
(
name
=
"aliasName"
)
String
aliasName
)
{
elasticService
.
deleteAlias
(
aliasName
);
return
"redirect:/admin/elastic/"
;
}
}
src/main/webapp/WEB-INF/jsp/admin/elastic/index.jsp
View file @
d4c814d7
...
...
@@ -20,6 +20,13 @@
<input
type=
"hidden"
name=
"${_csrf.parameterName}"
value=
"${_csrf.token}"
/>
<button
type=
"submit"
class=
"btn btn-default"
name=
"clear-queues"
>
Clear ES update queues
</button>
</form>
<form
method=
"post"
action=
"
<c:url
value=
"/admin/elastic/action"
/>
"
>
<input
type=
"hidden"
name=
"${_csrf.parameterName}"
value=
"${_csrf.token}"
/>
Alias:
<input
type=
"text"
name=
"aliasName"
/>
Index:
<input
type=
"text"
name=
"indexName"
/>
<button
type=
"submit"
class=
"btn btn-primary"
value=
"realias"
name=
"action"
>
Move alias
</button>
<button
type=
"submit"
class=
"btn btn-default"
value=
"delete-alias"
name=
"action"
>
Delete alias
</button>
</form>
<h3>
Indexes and their aliases
</h3>
<c:if
test=
"
${
empty
indexes
}
"
>
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment