use of org.apache.solr.core.CoreContainer in project lucene-solr by apache.
the class DeleteSnapshotOp method execute.
@Override
public void execute(CoreAdminHandler.CallInfo it) throws Exception {
CoreContainer cc = it.handler.getCoreContainer();
final SolrParams params = it.req.getParams();
String commitName = params.required().get(CoreAdminParams.COMMIT_NAME);
String cname = params.required().get(CoreAdminParams.CORE);
SolrCore core = cc.getCore(cname);
if (core == null) {
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Unable to locate core " + cname);
}
try {
core.deleteNamedSnapshot(commitName);
// Ideally we shouldn't need this. This is added since the RPC logic in
// OverseerCollectionMessageHandler can not provide the coreName as part of the result.
it.rsp.add(CoreAdminParams.CORE, core.getName());
it.rsp.add(CoreAdminParams.COMMIT_NAME, commitName);
} finally {
core.close();
}
}
use of org.apache.solr.core.CoreContainer in project lucene-solr by apache.
the class InfoHandler method handleRequestBody.
@Override
public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception {
// Make sure the cores is enabled
CoreContainer cores = getCoreContainer();
if (cores == null) {
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Core container instance missing");
}
String path = (String) req.getContext().get(PATH);
handle(req, rsp, path);
}
use of org.apache.solr.core.CoreContainer in project lucene-solr by apache.
the class InvokeOp method invokeAClass.
static Map<String, Object> invokeAClass(SolrQueryRequest req, String c) {
SolrResourceLoader loader = null;
if (req.getCore() != null)
loader = req.getCore().getResourceLoader();
else if (req.getContext().get(CoreContainer.class.getName()) != null) {
CoreContainer cc = (CoreContainer) req.getContext().get(CoreContainer.class.getName());
loader = cc.getResourceLoader();
}
CoreAdminHandler.Invocable invokable = loader.newInstance(c, CoreAdminHandler.Invocable.class);
Map<String, Object> result = invokable.invoke(req);
log.info("Invocable_invoked {}", result);
return result;
}
use of org.apache.solr.core.CoreContainer in project lucene-solr by apache.
the class RequestApplyUpdatesOp method execute.
@Override
public void execute(CoreAdminHandler.CallInfo it) throws Exception {
SolrParams params = it.req.getParams();
String cname = params.get(CoreAdminParams.NAME, "");
CoreAdminOperation.log().info("Applying buffered updates on core: " + cname);
CoreContainer coreContainer = it.handler.coreContainer;
try (SolrCore core = coreContainer.getCore(cname)) {
if (core == null)
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Core [" + cname + "] not found");
UpdateLog updateLog = core.getUpdateHandler().getUpdateLog();
if (updateLog.getState() != UpdateLog.State.BUFFERING) {
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Core " + cname + " not in buffering state");
}
Future<UpdateLog.RecoveryInfo> future = updateLog.applyBufferedUpdates();
if (future == null) {
CoreAdminOperation.log().info("No buffered updates available. core=" + cname);
it.rsp.add("core", cname);
it.rsp.add("status", "EMPTY_BUFFER");
return;
}
UpdateLog.RecoveryInfo report = future.get();
if (report.failed) {
SolrException.log(CoreAdminOperation.log(), "Replay failed");
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Replay failed");
}
coreContainer.getZkController().publish(core.getCoreDescriptor(), Replica.State.ACTIVE);
it.rsp.add("core", cname);
it.rsp.add("status", "BUFFER_APPLIED");
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
CoreAdminOperation.log().warn("Recovery was interrupted", e);
} catch (Exception e) {
if (e instanceof SolrException)
throw (SolrException) e;
else
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Could not apply buffered updates", e);
} finally {
if (it.req != null)
it.req.close();
}
}
use of org.apache.solr.core.CoreContainer in project lucene-solr by apache.
the class LoadAdminUiServlet method doGet.
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
// security: SOLR-7966 - avoid clickjacking for admin interface
response.addHeader("X-Frame-Options", "DENY");
// This attribute is set by the SolrDispatchFilter
String admin = request.getRequestURI().substring(request.getContextPath().length());
CoreContainer cores = (CoreContainer) request.getAttribute("org.apache.solr.CoreContainer");
InputStream in = getServletContext().getResourceAsStream(admin);
Writer out = null;
if (in != null && cores != null) {
try {
response.setCharacterEncoding("UTF-8");
response.setContentType("text/html");
// Protect container owned streams from being closed by us, see SOLR-8933
out = new OutputStreamWriter(new CloseShieldOutputStream(response.getOutputStream()), StandardCharsets.UTF_8);
String html = IOUtils.toString(in, "UTF-8");
Package pack = SolrCore.class.getPackage();
String[] search = new String[] { "${contextPath}", "${adminPath}", "${version}" };
String[] replace = new String[] { StringEscapeUtils.escapeJavaScript(request.getContextPath()), StringEscapeUtils.escapeJavaScript(CommonParams.CORES_HANDLER_PATH), StringEscapeUtils.escapeJavaScript(pack.getSpecificationVersion()) };
out.write(StringUtils.replaceEach(html, search, replace));
} finally {
IOUtils.closeQuietly(in);
IOUtils.closeQuietly(out);
}
} else {
response.sendError(404);
}
}
Aggregations