Example usage for org.apache.solr.update.processor UpdateRequestProcessor finish

List of usage examples for org.apache.solr.update.processor UpdateRequestProcessor finish

Introduction

In this page you can find the example usage for org.apache.solr.update.processor UpdateRequestProcessor finish.

Prototype

public void finish() throws IOException 

Source Link

Usage

From source file:de.qaware.chronix.solr.ingestion.AbstractIngestionHandler.java

License:Apache License

@Override
@SuppressWarnings("PMD.SignatureDeclareThrowsException")
public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception {
    formatResponseAsJson(req);/*from ww w .  java 2s. c om*/

    if (req.getContentStreams() == null) {
        LOGGER.warn("no content stream");
        rsp.add("error", "No content stream");
        return;
    }

    InputStream stream = req.getContentStreams().iterator().next().getStream();

    MetricTimeSeriesConverter converter = new MetricTimeSeriesConverter();

    UpdateRequestProcessorChain processorChain = req.getCore().getUpdateProcessorChain(req.getParams());
    UpdateRequestProcessor processor = processorChain.createProcessor(req, rsp);
    try {
        for (MetricTimeSeries series : formatParser.parse(stream)) {
            SolrInputDocument document = new SolrInputDocument();
            converter.to(series).getFields().forEach(document::addField);
            storeDocument(document, processor, req);
        }

        LOGGER.debug("Committing transaction...");
        processor.processCommit(new CommitUpdateCommand(req, false));
        LOGGER.debug("Committed transaction");
    } finally {
        processor.finish();
    }
}

From source file:lux.solr.SolrDocWriter.java

License:Mozilla Public License

private void writeToCloud(SolrInputDocument solrDoc, String uri) {
    ArrayList<String> urls = xqueryComponent.getShardURLs(true);
    LoggerFactory.getLogger(getClass()).debug("writing " + uri + " to cloud at " + urls);
    SolrQueryResponse rsp = new SolrQueryResponse();
    SolrQueryRequest req = UpdateDocCommand.makeSolrRequest(core);
    ((ModifiableSolrParams) req.getParams()).add(ShardParams.SHARDS, urls.toArray(new String[urls.size()]));
    UpdateRequest updateReq = new UpdateRequest();
    updateReq.add(solrDoc);// ww  w . j a v a 2  s.co  m
    UpdateDocCommand cmd = new UpdateDocCommand(req, solrDoc, null, uri);
    UpdateRequestProcessorChain updateChain = xqueryComponent.getCore()
            .getUpdateProcessingChain("lux-update-chain");
    try {
        UpdateRequestProcessor processor = updateChain.createProcessor(req, rsp);
        processor.processAdd(cmd);
        processor.finish();
    } catch (IOException e) {
        throw new LuxException(e);
    }
}

From source file:lux.solr.SolrDocWriter.java

License:Mozilla Public License

private void deleteCloud(DeleteUpdateCommand cmd) throws IOException {
    UpdateRequestProcessorChain updateChain = xqueryComponent.getCore()
            .getUpdateProcessingChain("lux-update-chain");
    SolrQueryResponse rsp = new SolrQueryResponse();
    SolrQueryRequest req = UpdateDocCommand.makeSolrRequest(core);
    UpdateRequestProcessor processor = updateChain.createProcessor(req, rsp);
    processor.processDelete(cmd);/*from  ww  w  .  j av a  2  s  . c  o  m*/
    processor.finish();
}

From source file:org.alfresco.solr.component.QueryLoggingComponent.java

License:Open Source License

private void log(ResponseBuilder rb) throws IOException {
    boolean isShard = rb.req.getParams().getBool(ShardParams.IS_SHARD, false);
    if (!isShard) {
        CoreContainer container = rb.req.getCore().getCoreContainer();
        SolrCore logCore = container.getCore(rb.req.getCore().getName() + "_qlog");
        if (logCore != null) {
            JSONObject json = (JSONObject) rb.req.getContext().get(AbstractQParser.ALFRESCO_JSON);

            SolrQueryRequest request = null;
            UpdateRequestProcessor processor = null;
            try {
                request = new LocalSolrQueryRequest(logCore, new NamedList<>());
                processor = logCore.getUpdateProcessingChain(null).createProcessor(request,
                        new SolrQueryResponse());

                AddUpdateCommand cmd = new AddUpdateCommand(request);
                cmd.overwrite = true;/*from w w w  .  java  2 s  .c  o  m*/
                SolrInputDocument input = new SolrInputDocument();
                input.addField("id", GUID.generate());
                input.addField("_version_", "1");

                input.addField("timestamp", DateTimeFormatter.ISO_INSTANT.format(Instant.now()));

                if (json != null) {
                    try {
                        ArrayList<String> authorityList = new ArrayList<String>(1);
                        JSONArray authorities = json.getJSONArray("authorities");
                        for (int i = 0; i < authorities.length(); i++) {
                            String authorityString = authorities.getString(i);
                            authorityList.add(authorityString);
                        }

                        for (String authority : authorityList) {
                            if (AuthorityType.getAuthorityType(authority) == AuthorityType.USER) {
                                input.addField("user", authority);
                                break;
                            }
                        }
                    } catch (JSONException e) {
                        input.addField("user", "<UNKNOWN>");
                    }
                } else {
                    input.addField("user", "<UNKNOWN>");
                }

                String userQuery = rb.req.getParams().get(SpellingParams.SPELLCHECK_Q);
                if (userQuery == null) {
                    if (json != null) {
                        try {
                            userQuery = json.getString("query");
                        } catch (JSONException e) {
                        }
                    }
                }
                if (userQuery == null) {
                    userQuery = rb.req.getParams().get(CommonParams.Q);
                }

                if (userQuery != null) {
                    input.addField("user_query", userQuery);
                }

                Query query = rb.getQuery();
                input.addField("query", query.toString());

                if (rb.getResults().docList != null) {
                    input.addField("found", rb.getResults().docList.matches());
                }
                input.addField("time", rb.req.getRequestTimer().getTime());

                cmd.solrDoc = input;
                processor.processAdd(cmd);
            }

            finally {
                if (processor != null) {
                    processor.finish();
                }
                if (request != null) {
                    request.close();
                }
            }
        }
    }
}

From source file:org.alfresco.solr.SolrInformationServer.java

License:Open Source License

@Override
public void commit() throws IOException {
    // avoid multiple commits and warming searchers
    commitAndRollbackLock.writeLock().lock();
    try {/*from  w  w w  .j  av  a  2s.com*/
        canUpdate();
        UpdateRequestProcessor processor = null;
        try (SolrQueryRequest request = newSolrQueryRequest()) {
            processor = this.core.getUpdateProcessingChain(null).createProcessor(request,
                    newSolrQueryResponse());
            processor.processCommit(new CommitUpdateCommand(request, false));
        } finally {
            if (processor != null) {
                processor.finish();
            }
        }
    } finally {
        commitAndRollbackLock.writeLock().unlock();
    }
}

From source file:org.alfresco.solr.SolrInformationServer.java

License:Open Source License

@Override
public void hardCommit() throws IOException {
    // avoid multiple commits and warming searchers
    commitAndRollbackLock.writeLock().lock();
    try {/*ww w.  j  a  v  a  2  s .  c o m*/
        UpdateRequestProcessor processor = null;
        try (SolrQueryRequest request = newSolrQueryRequest()) {
            processor = this.core.getUpdateProcessingChain(null).createProcessor(request,
                    newSolrQueryResponse());
            CommitUpdateCommand commitUpdateCommand = new CommitUpdateCommand(request, false);
            commitUpdateCommand.openSearcher = false;
            commitUpdateCommand.softCommit = false;
            commitUpdateCommand.waitSearcher = false;
            processor.processCommit(commitUpdateCommand);
        } finally {
            if (processor != null) {
                processor.finish();
            }
        }
    } finally {
        commitAndRollbackLock.writeLock().unlock();
    }
}

From source file:org.alfresco.solr.SolrInformationServer.java

License:Open Source License

@Override
public boolean commit(boolean openSearcher) throws IOException {
    canUpdate();//w w  w  .j a v  a2s . com
    UpdateRequestProcessor processor = null;
    boolean searcherOpened = false;
    try (SolrQueryRequest request = newSolrQueryRequest()) {
        processor = this.core.getUpdateProcessingChain(null).createProcessor(request, newSolrQueryResponse());
        CommitUpdateCommand command = new CommitUpdateCommand(request, false);
        if (openSearcher) {
            RefCounted<SolrIndexSearcher> active = null;
            RefCounted<SolrIndexSearcher> newest = null;
            try {
                active = core.getSearcher();
                newest = core.getNewestSearcher(false);
                if (active.get() == newest.get()) {
                    searcherOpened = command.openSearcher = true;
                    command.waitSearcher = false;
                } else {
                    searcherOpened = command.openSearcher = false;
                }
            } finally {
                if (active != null) {
                    active.decref();
                }

                if (newest != null) {
                    newest.decref();
                }
            }
        }
        processor.processCommit(command);
    } finally {
        if (processor != null) {
            processor.finish();
        }
    }

    return searcherOpened;
}

From source file:org.alfresco.solr.SolrInformationServer.java

License:Open Source License

@Override
public long indexAcl(List<AclReaders> aclReaderList, boolean overwrite) throws IOException {
    long start = System.nanoTime();

    UpdateRequestProcessor processor = null;
    try (SolrQueryRequest request = newSolrQueryRequest()) {
        processor = this.core.getUpdateProcessingChain(null).createProcessor(request, newSolrQueryResponse());

        for (AclReaders aclReaders : aclReaderList) {
            AddUpdateCommand cmd = new AddUpdateCommand(request);
            cmd.overwrite = overwrite;//from w  ww. j a  v a2  s  .  c om
            SolrInputDocument input = new SolrInputDocument();
            String id = AlfrescoSolrDataModel.getAclDocumentId(aclReaders.getTenantDomain(),
                    aclReaders.getId());
            input.addField(FIELD_SOLR4_ID, id);
            input.addField(FIELD_VERSION, "0");
            input.addField(FIELD_ACLID, aclReaders.getId());
            input.addField(FIELD_INACLTXID, aclReaders.getAclChangeSetId());
            String tenant = aclReaders.getTenantDomain();

            for (String reader : aclReaders.getReaders()) {
                reader = addTenantToAuthority(reader, tenant);
                input.addField(FIELD_READER, reader);
            }

            for (String denied : aclReaders.getDenied()) {
                denied = addTenantToAuthority(denied, tenant);
                input.addField(FIELD_DENIED, denied);
            }
            input.addField(FIELD_DOC_TYPE, DOC_TYPE_ACL);
            cmd.solrDoc = input;
            processor.processAdd(cmd);
        }
    } finally {
        if (processor != null) {
            processor.finish();
        }
    }

    long end = System.nanoTime();
    return (end - start);
}

From source file:org.alfresco.solr.SolrInformationServer.java

License:Open Source License

@Override
public void indexAclTransaction(AclChangeSet changeSet, boolean overwrite) throws IOException {
    canUpdate();//from   ww w .  j  a v  a  2s.c om
    UpdateRequestProcessor processor = null;
    try (SolrQueryRequest request = newSolrQueryRequest()) {
        processor = this.core.getUpdateProcessingChain(null).createProcessor(request, newSolrQueryResponse());
        AddUpdateCommand cmd = new AddUpdateCommand(request);
        cmd.overwrite = overwrite;
        SolrInputDocument input = new SolrInputDocument();
        input.addField(FIELD_SOLR4_ID, AlfrescoSolrDataModel.getAclChangeSetDocumentId(changeSet.getId()));
        input.addField(FIELD_VERSION, "0");
        input.addField(FIELD_ACLTXID, changeSet.getId());
        input.addField(FIELD_INACLTXID, changeSet.getId());
        input.addField(FIELD_ACLTXCOMMITTIME, changeSet.getCommitTimeMs());
        input.addField(FIELD_DOC_TYPE, DOC_TYPE_ACL_TX);
        cmd.solrDoc = input;
        processor.processAdd(cmd);
        putAclTransactionState(processor, request, changeSet);
    } finally {
        if (processor != null) {
            processor.finish();
        }
    }
}

From source file:org.alfresco.solr.SolrInformationServer.java

License:Open Source License

@Override
public void capIndex(long dbid) throws IOException {
    UpdateRequestProcessor processor = null;
    try (SolrQueryRequest request = newSolrQueryRequest()) {
        processor = this.core.getUpdateProcessingChain(null).createProcessor(request, newSolrQueryResponse());

        SolrInputDocument input = new SolrInputDocument();
        input.addField(FIELD_SOLR4_ID, INDEX_CAP_ID);
        input.addField(FIELD_VERSION, 0);
        input.addField(FIELD_DBID, -dbid); //Making this negative to ensure it is never confused with node DBID
        input.addField(FIELD_DOC_TYPE, DOC_TYPE_STATE);

        AddUpdateCommand cmd = new AddUpdateCommand(request);
        cmd.overwrite = true;/* ww w . j  a  va 2  s. c  om*/
        cmd.solrDoc = input;
        processor.processAdd(cmd);
    } finally {
        if (processor != null) {
            processor.finish();
        }
    }
}