mirror of https://github.com/apache/lucene.git
SOLR-6258: Added onRollback event handler hook to Data Import Handler
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1612124 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
80fe3c277f
commit
adaaaf041a
|
@ -143,6 +143,9 @@ New Features
|
|||
value for the fetchMailsSince filter.
|
||||
(Peter Sturge, Timothy Potter)
|
||||
|
||||
* SOLR-6258: Added onRollback event handler hook to Data Import Handler (DIH).
|
||||
(ehatcher)
|
||||
|
||||
|
||||
Bug Fixes
|
||||
----------------------
|
||||
|
|
|
@ -308,6 +308,9 @@ public class DocBuilder {
|
|||
writer.rollback();
|
||||
statusMessages.put("", "Indexing failed. Rolled back all changes.");
|
||||
addStatusMessage("Rolledback");
|
||||
if ((config != null) && (config.getOnRollback() != null)) {
|
||||
invokeEventListener(config.getOnRollback());
|
||||
}
|
||||
}
|
||||
|
||||
private void doFullDump() {
|
||||
|
|
|
@ -56,6 +56,7 @@ public class DIHConfiguration {
|
|||
private final List<Entity> entities;
|
||||
private final String onImportStart;
|
||||
private final String onImportEnd;
|
||||
private final String onRollback;
|
||||
private final List<Map<String, String>> functions;
|
||||
private final Script script;
|
||||
private final Map<String, Map<String,String>> dataSources;
|
||||
|
@ -71,6 +72,7 @@ public class DIHConfiguration {
|
|||
this.deleteQuery = ConfigParseUtil.getStringAttribute(element, "deleteQuery", null);
|
||||
this.onImportStart = ConfigParseUtil.getStringAttribute(element, "onImportStart", null);
|
||||
this.onImportEnd = ConfigParseUtil.getStringAttribute(element, "onImportEnd", null);
|
||||
this.onRollback = ConfigParseUtil.getStringAttribute(element, "onRollback", null);
|
||||
List<Entity> modEntities = new ArrayList<>();
|
||||
List<Element> l = ConfigParseUtil.getChildNodes(element, "entity");
|
||||
boolean docRootFound = false;
|
||||
|
@ -163,6 +165,9 @@ public class DIHConfiguration {
|
|||
public String getOnImportEnd() {
|
||||
return onImportEnd;
|
||||
}
|
||||
public String getOnRollback() {
|
||||
return onRollback;
|
||||
}
|
||||
public List<Map<String,String>> getFunctions() {
|
||||
return functions;
|
||||
}
|
||||
|
|
|
@ -75,6 +75,17 @@ public class TestDocBuilder2 extends AbstractDataImportHandlerTestCase {
|
|||
assertTrue("Update request processor finish was not called", TestUpdateRequestProcessor.finishCalled);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRollbackHandler() throws Exception {
|
||||
List rows = new ArrayList();
|
||||
rows.add(createMap("id", "1", "FORCE_ROLLBACK", "true"));
|
||||
MockDataSource.setIterator("select * from x", rows.iterator());
|
||||
|
||||
runFullImport(dataConfigWithRollbackHandler);
|
||||
|
||||
assertTrue("Rollback event listener was not called", RollbackEventListener.executed);
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testDynamicFields() throws Exception {
|
||||
|
@ -276,6 +287,13 @@ public class TestDocBuilder2 extends AbstractDataImportHandlerTestCase {
|
|||
}
|
||||
}
|
||||
|
||||
public static class ForcedExceptionTransformer extends Transformer {
|
||||
@Override
|
||||
public Object transformRow(Map<String, Object> row, Context context) {
|
||||
throw new DataImportHandlerException(DataImportHandlerException.SEVERE, "ForcedException");
|
||||
}
|
||||
}
|
||||
|
||||
public static class MockDataSource2 extends MockDataSource {
|
||||
|
||||
}
|
||||
|
@ -298,6 +316,15 @@ public class TestDocBuilder2 extends AbstractDataImportHandlerTestCase {
|
|||
}
|
||||
}
|
||||
|
||||
public static class RollbackEventListener implements EventListener {
|
||||
public static boolean executed = false;
|
||||
|
||||
@Override
|
||||
public void onEvent(Context ctx) {
|
||||
executed = true;
|
||||
}
|
||||
}
|
||||
|
||||
private final String requestParamAsVariable = "<dataConfig>\n" +
|
||||
" <dataSource type=\"MockDataSource\" />\n" +
|
||||
" <document>\n" +
|
||||
|
@ -350,6 +377,15 @@ public class TestDocBuilder2 extends AbstractDataImportHandlerTestCase {
|
|||
" </document>\n" +
|
||||
"</dataConfig>";
|
||||
|
||||
private final String dataConfigWithRollbackHandler = "<dataConfig> <dataSource type=\"MockDataSource\"/>\n" +
|
||||
" <document onRollback=\"TestDocBuilder2$RollbackEventListener\">\n" +
|
||||
" <entity name=\"books\" query=\"select * from x\" transformer=\"TestDocBuilder2$ForcedExceptionTransformer\">\n" +
|
||||
" <field column=\"id\" />\n" +
|
||||
" <field column=\"FORCE_ROLLBACK\" />\n" +
|
||||
" </entity>\n" +
|
||||
" </document>\n" +
|
||||
"</dataConfig>";
|
||||
|
||||
private final String dataConfigWithTemplatizedFieldNames = "<dataConfig><dataSource type=\"MockDataSource\"/>\n" +
|
||||
" <document>\n" +
|
||||
" <entity name=\"books\" query=\"select * from x\">\n" +
|
||||
|
|
Loading…
Reference in New Issue