Search in sources :

Example 66 with CoreContainer

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();
    }
}
Also used : CoreContainer(org.apache.solr.core.CoreContainer) SolrCore(org.apache.solr.core.SolrCore) SolrParams(org.apache.solr.common.params.SolrParams) SolrException(org.apache.solr.common.SolrException)

Example 67 with CoreContainer

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);
}
Also used : CoreContainer(org.apache.solr.core.CoreContainer) SolrException(org.apache.solr.common.SolrException)

Example 68 with CoreContainer

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;
}
Also used : SolrResourceLoader(org.apache.solr.core.SolrResourceLoader) CoreContainer(org.apache.solr.core.CoreContainer)

Example 69 with CoreContainer

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();
    }
}
Also used : CoreContainer(org.apache.solr.core.CoreContainer) SolrCore(org.apache.solr.core.SolrCore) UpdateLog(org.apache.solr.update.UpdateLog) SolrParams(org.apache.solr.common.params.SolrParams) SolrException(org.apache.solr.common.SolrException) SolrException(org.apache.solr.common.SolrException)

Example 70 with CoreContainer

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);
    }
}
Also used : CoreContainer(org.apache.solr.core.CoreContainer) InputStream(java.io.InputStream) OutputStreamWriter(java.io.OutputStreamWriter) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter) CloseShieldOutputStream(org.apache.commons.io.output.CloseShieldOutputStream)

Aggregations

CoreContainer (org.apache.solr.core.CoreContainer)95 SolrCore (org.apache.solr.core.SolrCore)30 Test (org.junit.Test)23 SolrException (org.apache.solr.common.SolrException)16 JettySolrRunner (org.apache.solr.client.solrj.embedded.JettySolrRunner)14 File (java.io.File)13 HashMap (java.util.HashMap)11 Replica (org.apache.solr.common.cloud.Replica)11 CoreDescriptor (org.apache.solr.core.CoreDescriptor)11 Path (java.nio.file.Path)10 IOException (java.io.IOException)9 ArrayList (java.util.ArrayList)8 SolrMetricManager (org.apache.solr.metrics.SolrMetricManager)8 SolrQueryResponse (org.apache.solr.response.SolrQueryResponse)8 Map (java.util.Map)7 SolrResourceLoader (org.apache.solr.core.SolrResourceLoader)7 Properties (java.util.Properties)6 DocCollection (org.apache.solr.common.cloud.DocCollection)6 Slice (org.apache.solr.common.cloud.Slice)6 SolrZkClient (org.apache.solr.common.cloud.SolrZkClient)6