Commit 65a9d79c authored by Aleksandr Sharaban's avatar Aleksandr Sharaban Committed by Matija Obreza

Feature #30601. Implemented controller and view at /admin/elastic. Created...

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.
parent 9c634be1
......@@ -127,43 +127,6 @@ public class AdminController {
return "redirect:/admin/";
}
/**
* Completely recreate Elasticsearch indexes: create, index, re-alias.
*
* @return
*/
@RequestMapping(method = RequestMethod.POST, value = "/elastic", params = { "regenerate" })
public String regenerateElastic() {
elasticService.regenerateIndexes();
return "redirect:/admin/";
}
/**
* This method refreshes data in the currently active index. It is very
* handy when having to refresh part of ES after direct database update.
*
* @param jsonFilter
* @throws IOException
*/
@RequestMapping(method = RequestMethod.POST, value = "/elastic", params = { "reindex", "filter" })
public String reindexElasticFiltered(@RequestParam(value = "filter", required = true) String jsonFilter) throws IOException {
AppliedFilters filters = mapper.readValue(jsonFilter, AppliedFilters.class);
elasticService.reindex(filters);
return "redirect:/admin/";
}
/**
* Clear ES queue
*
* @return
*/
@RequestMapping(method = RequestMethod.POST, value = "/elastic", params = { "clear-queues" })
public String clearElasticQueues() {
elasticUpdater.clearQueues();
return "redirect:/admin/";
}
@RequestMapping(method = RequestMethod.POST, value = "/updateAccessionCountryRefs")
public String updateAccessionCountryRefs() {
genesysService.updateAccessionCountryRefs();
......
/**
* Copyright 2014 Global Crop Diversity Trust
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
package org.genesys2.server.servlet.controller.admin;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.elasticsearch.client.Client;
import org.elasticsearch.cluster.metadata.AliasMetaData;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.common.collect.ImmutableOpenMap;
import org.elasticsearch.common.hppc.cursors.ObjectObjectCursor;
import org.genesys2.server.service.ElasticService;
import org.genesys2.server.service.impl.FilterHandler;
import org.genesys2.server.service.worker.ElasticUpdater;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
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;
@Controller
@RequestMapping("/admin")
@PreAuthorize("hasRole('ADMINISTRATOR')")
public class ElasticSearchController {
public static final Log LOG = LogFactory.getLog(ElasticSearchController.class);
@Autowired
ElasticUpdater elasticUpdater;
@Autowired
ElasticService elasticService;
@Autowired
private Client client;
ObjectMapper mapper = new ObjectMapper();
/**
* Renders view where indexes and their aliases are displayed.
*
* @param model
* @return
*/
@RequestMapping("/elastic")
public String viewIndexesAndAliases(Model model) {
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) {
List<AliasMetaData> innerAliasList = new ArrayList<>();
for (ObjectObjectCursor<String, AliasMetaData> innerCursor : cursor.value.getAliases()) {
innerAliasList.add(innerCursor.value);
}
indexMap.put(cursor.key, innerAliasList);
}
model.addAttribute("indexes", indexMap);
return "/admin/elastic/index";
}
/**
* Completely recreate Elasticsearch indexes: create, index, re-alias.
*
* @return
*/
@RequestMapping(method = RequestMethod.POST, value = "/elastic", params = { "regenerate" })
public String regenerateElastic() {
elasticService.regenerateIndexes();
return "redirect:/admin/";
}
/**
* This method refreshes data in the currently active index. It is very
* handy when having to refresh part of ES after direct database update.
*
* @param jsonFilter
* @throws IOException
*/
@RequestMapping(method = RequestMethod.POST, value = "/elastic", params = { "reindex", "filter" })
public String reindexElasticFiltered(@RequestParam(value = "filter", required = true) String jsonFilter) throws IOException {
FilterHandler.AppliedFilters filters = mapper.readValue(jsonFilter, FilterHandler.AppliedFilters.class);
elasticService.reindex(filters);
return "redirect:/admin/";
}
/**
* Clear ES queue
*
* @return
*/
@RequestMapping(method = RequestMethod.POST, value = "/elastic", params = { "clear-queues" })
public String clearElasticQueues() {
elasticUpdater.clearQueues();
return "redirect:/admin/";
}
}
<!DOCTYPE html>
<%@include file="/WEB-INF/jsp/init.jsp"%>
<html>
<head>
<title><spring:message code="admin.page.title" /></title>
</head>
<body>
<%@ include file="/WEB-INF/jsp/admin/menu.jsp"%>
<a href="<c:url value="/admin/" />" class="btn btn-default">Back</a>
<h3>Indexes and their aliases</h3>
<c:if test="${empty indexes}">
<h5>No indexes found.</h5>
</c:if>
<c:forEach items="${indexes}" var="indexMap" varStatus="i">
<div>Index #${i.count}: ${indexMap.key}</div>
<c:choose>
<c:when test="${empty indexMap.value}">
<h5>No aliases found.</h5>
</c:when>
<c:otherwise>
<table>
<tr>
<th>#</th>
<th>Name</th>
<th>Filter</th>
<th>Index routing</th>
<th>Search routing</th>
</tr>
<c:forEach items="${indexMap.value}" var="alias" varStatus="j">
<tr>
<td>${j.count}</td>
<td>${alias.alias}</td>
<td>${alias.filter}</td>
<td>${alias.indexRouting}</td>
<td>${alias.searchRouting}</td>
</tr>
</c:forEach>
</table>
</c:otherwise>
</c:choose>
<br/>
</c:forEach>
</body>
</html>
\ No newline at end of file
......@@ -42,6 +42,7 @@
<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>
<a href="<c:url value="/admin/elastic" />" class="btn btn-default">Show indexes and aliases</a>
<h3>Country data</h3>
<form method="post" action="<c:url value="/admin/refreshCountries" />">
......
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