Search in sources :

Example 1 with UpdateRequestProcessorFactory

use of org.apache.solr.update.processor.UpdateRequestProcessorFactory in project lucene-solr by apache.

the class TestSchemalessBufferedUpdates method processAdd.

private SolrInputDocument processAdd(final SolrInputDocument docIn) throws IOException {
    UpdateRequestProcessorChain processorChain = h.getCore().getUpdateProcessingChain(UPDATE_CHAIN);
    assertNotNull("Undefined URP chain '" + UPDATE_CHAIN + "'", processorChain);
    List<UpdateRequestProcessorFactory> factoriesUpToDUP = new ArrayList<>();
    for (UpdateRequestProcessorFactory urpFactory : processorChain.getProcessors()) {
        factoriesUpToDUP.add(urpFactory);
        if (urpFactory.getClass().equals(DistributedUpdateProcessorFactory.class))
            break;
    }
    UpdateRequestProcessorChain chainUpToDUP = new UpdateRequestProcessorChain(factoriesUpToDUP, h.getCore());
    assertNotNull("URP chain '" + UPDATE_CHAIN + "'", chainUpToDUP);
    SolrQueryResponse rsp = new SolrQueryResponse();
    SolrQueryRequest req = req();
    try {
        SolrRequestInfo.setRequestInfo(new SolrRequestInfo(req, rsp));
        AddUpdateCommand cmd = new AddUpdateCommand(req);
        cmd.solrDoc = docIn;
        UpdateRequestProcessor processor = chainUpToDUP.createProcessor(req, rsp);
        processor.processAdd(cmd);
        if (cmd.solrDoc.get("f_dt").getValue() instanceof Date) {
            // Non-JSON types (Date in this case) aren't handled properly in noggit-0.6.  Although this is fixed in 
            // https://github.com/yonik/noggit/commit/ec3e732af7c9425e8f40297463cbe294154682b1 to call obj.toString(), 
            // Date::toString produces a Date representation that Solr doesn't like, so we convert using Instant::toString
            cmd.solrDoc.get("f_dt").setValue(((Date) cmd.solrDoc.get("f_dt").getValue()).toInstant().toString());
        }
        return cmd.solrDoc;
    } finally {
        SolrRequestInfo.clearRequestInfo();
        req.close();
    }
}
Also used : UpdateRequestProcessorFactory(org.apache.solr.update.processor.UpdateRequestProcessorFactory) SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) ArrayList(java.util.ArrayList) UpdateRequestProcessorChain(org.apache.solr.update.processor.UpdateRequestProcessorChain) UpdateRequestProcessor(org.apache.solr.update.processor.UpdateRequestProcessor) SolrRequestInfo(org.apache.solr.request.SolrRequestInfo) AddUpdateCommand(org.apache.solr.update.AddUpdateCommand) Date(java.util.Date)

Example 2 with UpdateRequestProcessorFactory

use of org.apache.solr.update.processor.UpdateRequestProcessorFactory in project lucene-solr by apache.

the class DocExpirationUpdateProcessorFactoryTest method testAutomaticDeletes.

public void testAutomaticDeletes() throws Exception {
    // get a handle on our recorder
    UpdateRequestProcessorChain chain = h.getCore().getUpdateProcessingChain("scheduled-delete");
    assertNotNull(chain);
    List<UpdateRequestProcessorFactory> factories = chain.getProcessors();
    assertEquals("did number of processors configured in chain get changed?", 5, factories.size());
    assertTrue("Expected [1] RecordingUpdateProcessorFactory: " + factories.get(1).getClass(), factories.get(1) instanceof RecordingUpdateProcessorFactory);
    RecordingUpdateProcessorFactory recorder = (RecordingUpdateProcessorFactory) factories.get(1);
    try {
        recorder.startRecording();
        // more then one iter to verify it's recurring
        final int numItersToCheck = 1 + RANDOM_MULTIPLIER;
        for (int i = 0; i < numItersToCheck; i++) {
            UpdateCommand tmp;
            // be generous in how long we wait, some jenkins machines are slooooow
            tmp = recorder.commandQueue.poll(30, TimeUnit.SECONDS);
            // we can be confident in the order because DocExpirationUpdateProcessorFactory
            // uses the same request for both the delete & the commit -- and both 
            // RecordingUpdateProcessorFactory's getInstance & startRecording methods are 
            // synchronized.  So it should not be possible to start recording in the 
            // middle of the two commands
            assertTrue("expected DeleteUpdateCommand: " + tmp.getClass(), tmp instanceof DeleteUpdateCommand);
            DeleteUpdateCommand delete = (DeleteUpdateCommand) tmp;
            assertFalse(delete.isDeleteById());
            assertNotNull(delete.getQuery());
            assertTrue(delete.getQuery(), delete.getQuery().startsWith("{!cache=false}eXpField_tdt:[* TO "));
            // commit should be immediately after the delete
            tmp = recorder.commandQueue.poll(5, TimeUnit.SECONDS);
            assertTrue("expected CommitUpdateCommand: " + tmp.getClass(), tmp instanceof CommitUpdateCommand);
            CommitUpdateCommand commit = (CommitUpdateCommand) tmp;
            assertTrue(commit.softCommit);
            assertTrue(commit.openSearcher);
        }
    } finally {
        recorder.stopRecording();
    }
}
Also used : UpdateRequestProcessorFactory(org.apache.solr.update.processor.UpdateRequestProcessorFactory) DeleteUpdateCommand(org.apache.solr.update.DeleteUpdateCommand) CommitUpdateCommand(org.apache.solr.update.CommitUpdateCommand) UpdateCommand(org.apache.solr.update.UpdateCommand) UpdateRequestProcessorChain(org.apache.solr.update.processor.UpdateRequestProcessorChain) DeleteUpdateCommand(org.apache.solr.update.DeleteUpdateCommand) CommitUpdateCommand(org.apache.solr.update.CommitUpdateCommand)

Example 3 with UpdateRequestProcessorFactory

use of org.apache.solr.update.processor.UpdateRequestProcessorFactory in project lucene-solr by apache.

the class SolrCore method loadUpdateProcessorChains.

/**
   * Load the request processors
   */
private Map<String, UpdateRequestProcessorChain> loadUpdateProcessorChains() {
    Map<String, UpdateRequestProcessorChain> map = new HashMap<>();
    UpdateRequestProcessorChain def = initPlugins(map, UpdateRequestProcessorChain.class, UpdateRequestProcessorChain.class.getName());
    if (def == null) {
        def = map.get(null);
    }
    if (def == null) {
        log.debug("no updateRequestProcessorChain defined as default, creating implicit default");
        // construct the default chain
        UpdateRequestProcessorFactory[] factories = new UpdateRequestProcessorFactory[] { new LogUpdateProcessorFactory(), new DistributedUpdateProcessorFactory(), new RunUpdateProcessorFactory() };
        def = new UpdateRequestProcessorChain(Arrays.asList(factories), this);
    }
    map.put(null, def);
    map.put("", def);
    return map;
}
Also used : UpdateRequestProcessorFactory(org.apache.solr.update.processor.UpdateRequestProcessorFactory) RunUpdateProcessorFactory(org.apache.solr.update.processor.RunUpdateProcessorFactory) LogUpdateProcessorFactory(org.apache.solr.update.processor.LogUpdateProcessorFactory) LinkedHashMap(java.util.LinkedHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) DistributedUpdateProcessorFactory(org.apache.solr.update.processor.DistributedUpdateProcessorFactory) UpdateRequestProcessorChain(org.apache.solr.update.processor.UpdateRequestProcessorChain)

Aggregations

UpdateRequestProcessorChain (org.apache.solr.update.processor.UpdateRequestProcessorChain)3 UpdateRequestProcessorFactory (org.apache.solr.update.processor.UpdateRequestProcessorFactory)3 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 SolrQueryRequest (org.apache.solr.request.SolrQueryRequest)1 SolrRequestInfo (org.apache.solr.request.SolrRequestInfo)1 SolrQueryResponse (org.apache.solr.response.SolrQueryResponse)1 AddUpdateCommand (org.apache.solr.update.AddUpdateCommand)1 CommitUpdateCommand (org.apache.solr.update.CommitUpdateCommand)1 DeleteUpdateCommand (org.apache.solr.update.DeleteUpdateCommand)1 UpdateCommand (org.apache.solr.update.UpdateCommand)1 DistributedUpdateProcessorFactory (org.apache.solr.update.processor.DistributedUpdateProcessorFactory)1 LogUpdateProcessorFactory (org.apache.solr.update.processor.LogUpdateProcessorFactory)1 RunUpdateProcessorFactory (org.apache.solr.update.processor.RunUpdateProcessorFactory)1 UpdateRequestProcessor (org.apache.solr.update.processor.UpdateRequestProcessor)1