System.setProperty(dataDirPropertyName, tmpDataDir.getAbsolutePath());
System.setProperty("enable.special-handlers", "false"); // All we need is the update request handler
System.setProperty("enable.cache-warming", "false"); // We certainly don't need to warm the cache
CoreContainer coreContainer = new CoreContainer(tmpSolrHome.getAbsolutePath());
try {
coreContainer.load();
Collection<SolrCore> cores = coreContainer.getCores();
SolrCore core = null;
if (cores.size() == 0) {
throw new TapException("No Solr cores are available");
} else if (cores.size() > 1) {
throw new TapException("Only one Solr core is supported");
} else {
core = cores.iterator().next();
}
IndexSchema schema = core.getLatestSchema();
Map<String, SchemaField> solrFields = schema.getFields();
Set<String> schemeFieldnames = new HashSet<String>();
for (int i = 0; i < schemeFields.size(); i++) {
String fieldName = schemeFields.get(i).toString();
if (!solrFields.containsKey(fieldName)) {
throw new TapException("Sink field name doesn't exist in Solr schema: " + fieldName);
}
schemeFieldnames.add(fieldName);
}
for (String solrFieldname : solrFields.keySet()) {
SchemaField solrField = solrFields.get(solrFieldname);
if (solrField.isRequired() && !schemeFieldnames.contains(solrFieldname)) {
throw new TapException("No sink field name for required Solr field: " + solrFieldname);
}
}
} finally {
if (coreContainer != null) {
coreContainer.shutdown();
}
}
}