// if the solr core is managed, check that the index is properly activated
if (managedSolrServer != null && indexReference.checkServer(managedSolrServer.getServerName())
&& context != null && solrCoreConfig != null) {
log.info(" > check/init index {} on ManagedSolrServer {}", indexReference, managedSolrServer.getServerName());
String indexName = indexReference.getIndex();
final IndexMetadata indexMetadata;
ManagedIndexState indexState = managedSolrServer.getIndexState(indexName);
if(indexState == null){
if(solrCoreConfig.indexOf(".solrindex.") < 0){ //if the suffix is missing
solrCoreConfig = solrCoreConfig + ".solrindex.zip"; //append it
}
log.info("Create SolrCore {} (config: {}) on ManagedSolrServer {} ...",
new Object[]{indexName,solrCoreConfig,managedSolrServer.getServerName()});
indexMetadata = managedSolrServer.createSolrIndex(indexName,
solrCoreConfig, null);
if(indexMetadata != null)
log.info(" ... created {}", indexMetadata.getIndexReference());
} else {
indexMetadata = managedSolrServer.getIndexMetadata(indexName);
if(indexState != ManagedIndexState.ACTIVE){
log.info(" ... activate {}", indexMetadata.getIndexReference());
managedSolrServer.activateIndex(indexName);
} else {
log.info(" ... index {} already active", indexMetadata.getIndexReference());
}
}
// IndexMetadata indexMetadata = managedSolrServer.getIndexMetadata(indexName);
// if (indexMetadata == null) {
// // TODO: debug the DataFileProvider init race conditions instead
// // indexMetadata = managedSolrServer.createSolrIndex(indexName, indexArchiveName, null);
// dfp.getInputStream(context.getBundleContext().getBundle().getSymbolicName(),
// indexArchiveName + ".solrindex.zip", null);
// URL archiveUrl = context.getBundleContext().getBundle()
// .getEntry("/data-files/" + indexArchiveName + ".solrindex.zip");
// if (archiveUrl == null) {
// throw new ConfigurationException(solrCoreId, "Could not find index archive for "
// + indexArchiveName);
// }
// ZipArchiveInputStream zis = new ZipArchiveInputStream(archiveUrl.openStream());
// indexMetadata = managedSolrServer.updateIndex(indexName, zis, indexArchiveName);
// }
// if (!indexMetadata.isActive()) {
// managedSolrServer.activateIndex(indexName);
// }
indexReference = indexMetadata.getIndexReference();
}
return indexReference;
}