use of org.apache.stanbol.commons.solr.IndexReference in project stanbol by apache.
the class SolrYardComponent method activate.
@Activate
protected void activate(ComponentContext ctx) throws ConfigurationException {
this.context = ctx.getBundleContext();
@SuppressWarnings("unchecked") SolrYardConfig config = new SolrYardConfig((Dictionary<String, Object>) ctx.getProperties());
log.info("activate {} (name:{})", getClass().getSimpleName(), config.getId());
String indexLocation = config.getSolrServerLocation();
if (indexLocation.startsWith("http") && indexLocation.indexOf("://") > 0) {
solrServer = new HttpSolrServer(indexLocation);
//directly register configs that use a remote server
updateSolrYardRegistration(solrServer, config);
} else {
//locally managed Server
IndexReference solrServerRef = IndexReference.parse(config.getSolrServerLocation());
//default
if (config.isAllowInitialisation() && solrServerRef.getServer() != null) {
throw new ConfigurationException(SolrYardConfig.SOLR_SERVER_LOCATION, "The SolrServerLocation ({server-name}:{index-name}) MUST NOT define a " + "{server-name} if '" + SolrYardConfig.ALLOW_INITIALISATION_STATE + "' is enabled. Change the cofiguration to use just a {index-name}");
}
//check if we need to init the SolrIndex
initManagedSolrIndex(managedSolrServer, config);
}
//globally set the config
this.config = config;
}
use of org.apache.stanbol.commons.solr.IndexReference in project stanbol by apache.
the class ConfiguredSolrCoreTracker method unbindManagedSolrServer.
protected void unbindManagedSolrServer(ManagedSolrServer managedSolrServer) {
if (this.managedSolrServer == managedSolrServer || solrCoreId != null) {
IndexReference indexReference = IndexReference.parse(solrCoreId);
if (!indexReference.checkServer(managedSolrServer.getServerName())) {
return;
}
String indexName = indexReference.getIndex();
IndexMetadata indexMetadata = managedSolrServer.getIndexMetadata(indexName);
if (indexMetadata != null && indexMetadata.isActive()) {
managedSolrServer.deactivateIndex(indexName);
}
this.managedSolrServer = null;
}
}
use of org.apache.stanbol.commons.solr.IndexReference in project stanbol by apache.
the class SolrYardIndexingDestination method initialise.
@Override
public void initialise() {
log.info("initialise {}", getClass().getSimpleName());
//The constructors and the setConfiguration(..) only validate the parsed
//parameters and initialise the member variables. This method performs
//the the actual initialisation of the SolrYard!
//copy a custom configuration (if present)
EmbeddedSolrServer server;
IndexReference solrServerRef = IndexReference.parse(solrYardConfig.getSolrServerLocation());
if (solrIndexConfig != null) {
//copy the configuration
try {
log.info(" ... copy Solr Configuration form {} to {}", solrIndexConfig, solrIndexLocation);
FileUtils.copyDirectory(solrIndexConfig, solrIndexLocation);
} catch (IOException e) {
throw new IllegalStateException(String.format("Unable to copy the Solr index configuration from %s to %s!", solrIndexConfig, solrIndexLocation), e);
}
solrYardConfig.setAllowInitialisation(Boolean.FALSE);
server = StandaloneEmbeddedSolrServerProvider.getInstance().getSolrServer(solrServerRef, solrServerRef.getIndex());
this.core = server.getCoreContainer().getCore(solrServerRef.getIndex());
} else {
//allow the default initialisation
solrYardConfig.setAllowInitialisation(Boolean.TRUE);
StandaloneEmbeddedSolrServerProvider.getInstance();
server = StandaloneEmbeddedSolrServerProvider.getInstance().getSolrServer(solrServerRef, solrYardConfig.getIndexConfigurationName());
if (server != null) {
log.info(" ... initialised SolrCore with default configuration");
this.core = server.getCoreContainer().getCore(solrServerRef.getIndex());
} else if (solrServerRef.isPath() && new File(solrServerRef.getIndex()).isAbsolute()) {
//the parsed absolute path is not within the managed SolrServer
//so we need to create some CoreContainer and init/register
//the core at the parsed location
StandaloneManagedSolrServer s;
if (solrServerRef.getServer() == null) {
s = StandaloneManagedSolrServer.getManagedServer();
} else {
s = StandaloneManagedSolrServer.getManagedServer(solrServerRef.getServer());
}
CoreContainer cc = s.getCoreContainer();
CoreDescriptor cd = new CoreDescriptor(cc, "dummy", solrServerRef.getIndex());
this.core = cc.create(cd);
cc.register(core, false);
server = new EmbeddedSolrServer(cc, "dummy");
log.info(" ... initialised existing SolrCore at {}", solrServerRef.getIndex());
} else {
throw new IllegalStateException("Unable to initialise SolrCore " + solrServerRef);
}
}
log.info(" ... create SolrYard");
this.solrYard = new SolrYard(server, solrYardConfig, namespacePrefixService);
}
Aggregations