Commit 2bc9df2c authored by Matija Obreza's avatar Matija Obreza
Browse files

Merge branch 'master' into staging

* master:
  Delete and move ES aliases
  ES admin buttons moved
  Feature #30601. Implemented controller and view at /admin/elastic. Created action "/" for viewing list of indexes and their aliases. Related actions moved from AdminController class.

# Conflicts:
#	src/main/java/org/genesys2/server/servlet/controller/admin/ElasticSearchController.java
#	src/main/webapp/WEB-INF/jsp/admin/elastic/index.jsp
parents 25b6be95 d4c814d7
...@@ -58,4 +58,14 @@ public interface ElasticService { ...@@ -58,4 +58,14 @@ public interface ElasticService {
*/ */
void regenerateIndexes(); void regenerateIndexes();
/**
* Move alias to a different index
*
* @param aliasName
* @param indexName
*/
void realias(String aliasName, String indexName);
void deleteAlias(String aliasName);
} }
...@@ -490,11 +490,23 @@ public class ElasticsearchSearchServiceImpl implements ElasticService, Initializ ...@@ -490,11 +490,23 @@ public class ElasticsearchSearchServiceImpl implements ElasticService, Initializ
* @param indexName * @param indexName
* The index the alias points to * The index the alias points to
*/ */
private void realias(String aliasName, String indexName) { @Override
public void realias(String aliasName, String indexName) {
if (LOG.isDebugEnabled()) if (LOG.isDebugEnabled())
LOG.debug("Loading alias definition for " + aliasName); 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() ImmutableOpenMap<String, AliasMetaData> x = client.admin().cluster().prepareState().execute().actionGet().getState().getMetaData().getAliases()
.get(aliasName); .get(aliasName);
...@@ -511,12 +523,6 @@ public class ElasticsearchSearchServiceImpl implements ElasticService, Initializ ...@@ -511,12 +523,6 @@ public class ElasticsearchSearchServiceImpl implements ElasticService, Initializ
elasticsearchTemplate.removeAlias(query); 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) { private void createIndex(String indexName, Map<?, ?> indexMapping, Map<?, ?> settings) {
......
...@@ -16,7 +16,12 @@ ...@@ -16,7 +16,12 @@
package org.genesys2.server.servlet.controller.admin; 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.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.elasticsearch.client.Client; import org.elasticsearch.client.Client;
...@@ -35,11 +40,7 @@ import org.springframework.web.bind.annotation.RequestMapping; ...@@ -35,11 +40,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import java.io.IOException; import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Controller @Controller
@RequestMapping("/admin/elastic") @RequestMapping("/admin/elastic")
...@@ -66,10 +67,8 @@ public class ElasticSearchController { ...@@ -66,10 +67,8 @@ public class ElasticSearchController {
*/ */
@RequestMapping("/") @RequestMapping("/")
public String viewIndexesAndAliases(Model model) { public String viewIndexesAndAliases(Model model) {
ImmutableOpenMap<String, IndexMetaData> indicesImmutableMap = client.admin().cluster() ImmutableOpenMap<String, IndexMetaData> indicesImmutableMap = client.admin().cluster().prepareState().execute().actionGet().getState().getMetaData()
.prepareState().execute() .getIndices();
.actionGet().getState()
.getMetaData().getIndices();
Map<String, List<AliasMetaData>> indexMap = new HashMap<>(); Map<String, List<AliasMetaData>> indexMap = new HashMap<>();
for (ObjectObjectCursor<String, IndexMetaData> cursor : indicesImmutableMap) { for (ObjectObjectCursor<String, IndexMetaData> cursor : indicesImmutableMap) {
...@@ -121,4 +120,16 @@ public class ElasticSearchController { ...@@ -121,4 +120,16 @@ public class ElasticSearchController {
elasticUpdater.clearQueues(); elasticUpdater.clearQueues();
return "redirect:/admin/elastic/"; 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/";
}
} }
...@@ -20,6 +20,13 @@ ...@@ -20,6 +20,13 @@
<input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}" /> <input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}" />
<button type="submit" class="btn btn-default" name="clear-queues">Clear ES update queues</button> <button type="submit" class="btn btn-default" name="clear-queues">Clear ES update queues</button>
</form> </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> <h3>Indexes and their aliases</h3>
<c:if test="${empty indexes}"> <c:if test="${empty indexes}">
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment