Java Code Examples for org.apache.solr.core.SolrCore#getCoreContainer()

The following examples show how to use org.apache.solr.core.SolrCore#getCoreContainer() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StreamHandler.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings({"rawtypes"})
public void inform(SolrCore core) {
  String defaultCollection;
  String defaultZkhost;
  CoreContainer coreContainer = core.getCoreContainer();
  this.solrClientCache = coreContainer.getSolrClientCache();
  this.coreName = core.getName();
  String cacheKey = this.getClass().getName() + "_" + coreName + "_";
  this.objectCache = coreContainer.getObjectCache().computeIfAbsent(cacheKey + "objectCache",
      ConcurrentHashMap.class, k-> new ConcurrentHashMap());
  if (coreContainer.isZooKeeperAware()) {
    defaultCollection = core.getCoreDescriptor().getCollectionName();
    defaultZkhost = core.getCoreContainer().getZkController().getZkServerAddress();
    streamFactory.withCollectionZkHost(defaultCollection, defaultZkhost);
    streamFactory.withDefaultZkHost(defaultZkhost);
    modelCache = coreContainer.getObjectCache().computeIfAbsent(cacheKey + "modelCache",
        ModelCache.class,
        k -> new ModelCache(250, defaultZkhost, solrClientCache));
  }
  streamFactory.withSolrResourceLoader(core.getResourceLoader());

  // This pulls all the overrides and additions from the config
  addExpressiblePlugins(streamFactory, core);
}
 
Example 2
Source File: RoutedAlias.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
/**
 * Create as many collections as required. This method loops to allow for the possibility that the route value
 * requires more than one collection to be created. Since multiple threads may be invoking maintain on separate
 * requests to the same alias, we must pass in a descriptor that details what collection is to be created.
 * This assumption is checked when the command is executed in the overseer. When this method
 * finds that all collections required have been created it returns the (possibly new) destination collection
 * for the document that caused the creation cycle.
 *
 * @param cmd                  the update command being processed
 * @param targetCollectionDesc the descriptor for the presently selected collection .
 * @return The destination collection, possibly created during this method's execution
 */
private String createAllRequiredCollections(AddUpdateCommand cmd, CandidateCollection targetCollectionDesc) {

  SolrQueryRequest req = cmd.getReq();
  SolrCore core = req.getCore();
  CoreContainer coreContainer = core.getCoreContainer();
  do {
    switch (targetCollectionDesc.getCreationType()) {
      case NONE:
        return targetCollectionDesc.destinationCollection; // we don't need another collection
      case SYNCHRONOUS:
        targetCollectionDesc = doSynchronous( cmd, targetCollectionDesc, coreContainer);
        break;
      case ASYNC_PREEMPTIVE:
        return doPreemptive(targetCollectionDesc, core, coreContainer);
      default:
        throw unknownCreateType();
    }
  } while (true);
}
 
Example 3
Source File: RoutedAliasUpdateProcessor.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
public static UpdateRequestProcessor wrap(SolrQueryRequest req, UpdateRequestProcessor next) {
  String aliasName = null;
  // Demeter please don't arrest us... hide your eyes :(
  // todo: a core should have a more direct way of finding a collection name, and the collection properties
  SolrCore core = req.getCore();
  CoreDescriptor coreDescriptor = core.getCoreDescriptor();
  CloudDescriptor cloudDescriptor = coreDescriptor.getCloudDescriptor();
  if (cloudDescriptor != null) {
    String collectionName = cloudDescriptor.getCollectionName();
    CoreContainer coreContainer = core.getCoreContainer();
    ZkController zkController = coreContainer.getZkController();
    ZkStateReader zkStateReader = zkController.getZkStateReader();
    Map<String, String> collectionProperties = zkStateReader.getCollectionProperties(collectionName, CACHE_FOR_MILLIS);
    aliasName = collectionProperties.get(RoutedAlias.ROUTED_ALIAS_NAME_CORE_PROP);
  }
  // fall back on core properties (legacy)
  if (StringUtils.isBlank(aliasName)) {
    aliasName = coreDescriptor.getCoreProperty(RoutedAlias.ROUTED_ALIAS_NAME_CORE_PROP, null);
  }
  final DistribPhase shardDistribPhase =
      DistribPhase.parseParam(req.getParams().get(DISTRIB_UPDATE_PARAM));
  final DistribPhase aliasDistribPhase =
      DistribPhase.parseParam(req.getParams().get(ALIAS_DISTRIB_UPDATE_PARAM));
  if (aliasName == null || aliasDistribPhase != DistribPhase.NONE || shardDistribPhase != DistribPhase.NONE) {
    // if aliasDistribPhase is not NONE, then there is no further collection routing to be done here.
    //    TODO this may eventually not be true but at the moment it is
    // if shardDistribPhase is not NONE, then the phase is after the scope of this URP
    return next;
  } else {
    try {
      RoutedAlias alias = RoutedAlias.fromProps(aliasName, getAliasProps(req, aliasName));
      return new RoutedAliasUpdateProcessor(req, next, aliasDistribPhase, alias);
    } catch (Exception e) { // ensure we throw SERVER_ERROR not BAD_REQUEST at this stage
      throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Routed alias has invalid properties: " + e, e);
    }

  }
}
 
Example 4
Source File: ExportHandler.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public void inform(SolrCore core) {
  super.inform(core);
  String defaultCollection;
  String defaultZkhost;
  CoreContainer coreContainer = core.getCoreContainer();
  this.solrClientCache = coreContainer.getSolrClientCache();
  this.coreName = core.getName();

  if (coreContainer.isZooKeeperAware()) {
    defaultCollection = core.getCoreDescriptor().getCollectionName();
    defaultZkhost = core.getCoreContainer().getZkController().getZkServerAddress();
    streamFactory.withCollectionZkHost(defaultCollection, defaultZkhost);
    streamFactory.withDefaultZkHost(defaultZkhost);
    modelCache = new ModelCache(250,
        defaultZkhost,
        solrClientCache);
  }
  streamFactory.withSolrResourceLoader(core.getResourceLoader());
  StreamHandler.addExpressiblePlugins(streamFactory, core);
  initialStreamContext = new StreamContext();
  initialStreamContext.setStreamFactory(streamFactory);
  initialStreamContext.setSolrClientCache(solrClientCache);
  initialStreamContext.setModelCache(modelCache);
  initialStreamContext.setObjectCache(objectCache);
  initialStreamContext.put("core", this.coreName);
  initialStreamContext.put("solr-core", core);
}
 
Example 5
Source File: SQLHandler.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
public void inform(SolrCore core) {
  CoreContainer coreContainer = core.getCoreContainer();

  if(coreContainer.isZooKeeperAware()) {
    defaultZkhost = core.getCoreContainer().getZkController().getZkServerAddress();
    defaultWorkerCollection = core.getCoreDescriptor().getCollectionName();
    isCloud = true;
  }
}
 
Example 6
Source File: MDCLoggingContext.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
/**
 * Sets multiple information from the params.
 * REMEMBER TO CALL {@link #clear()} in a finally!
 */
public static void setCore(SolrCore core) {
  CoreContainer coreContainer = core == null ? null : core.getCoreContainer();
  CoreDescriptor coreDescriptor = core == null ? null : core.getCoreDescriptor();
  setCoreDescriptor(coreContainer, coreDescriptor);
}
 
Example 7
Source File: GraphHandler.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings({"unchecked"})
public void inform(SolrCore core) {
  String defaultCollection;
  String defaultZkhost;
  CoreContainer coreContainer = core.getCoreContainer();
  this.coreName = core.getName();
  this.solrClientCache = coreContainer.getSolrClientCache();

  if(coreContainer.isZooKeeperAware()) {
    defaultCollection = core.getCoreDescriptor().getCollectionName();
    defaultZkhost = core.getCoreContainer().getZkController().getZkServerAddress();
    streamFactory.withCollectionZkHost(defaultCollection, defaultZkhost);
    streamFactory.withDefaultZkHost(defaultZkhost);
  }

  // This pulls all the overrides and additions from the config
  StreamHandler.addExpressiblePlugins(streamFactory, core);

  // Check deprecated approach.
  Object functionMappingsObj = initArgs.get("streamFunctions");
  if(null != functionMappingsObj){
    log.warn("solrconfig.xml: <streamFunctions> is deprecated for adding additional streaming functions to GraphHandler.");
    NamedList<?> functionMappings = (NamedList<?>)functionMappingsObj;
    for(Entry<String,?> functionMapping : functionMappings) {
      String key = functionMapping.getKey();
      PluginInfo pluginInfo = new PluginInfo(key, Collections.singletonMap("class", functionMapping.getValue()));

      if (pluginInfo.pkgName == null) {
        Class<? extends Expressible> clazz = core.getResourceLoader().findClass((String) functionMapping.getValue(),
            Expressible.class);
        streamFactory.withFunctionName(key, clazz);
      } else {
        @SuppressWarnings("resource")
        StreamHandler.ExpressibleHolder holder = new StreamHandler.ExpressibleHolder(pluginInfo, core, SolrConfig.classVsSolrPluginInfo.get(Expressible.class.getName()));
        streamFactory.withFunctionName(key, () -> holder.getClazz());
      }

    }

  }
}
 
Example 8
Source File: EmbeddedSolrServer.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
/**
 * Create an EmbeddedSolrServer wrapping a particular SolrCore
 */
public EmbeddedSolrServer(SolrCore core) {
  this(core.getCoreContainer(), core.getName());
}