예제 #1
0
  /**
   * Handle 'CREATE' action.
   *
   * @param req
   * @param rsp
   * @return true if a modification has resulted that requires persistance of the CoreContainer
   *     configuration.
   * @throws SolrException in case of a configuration error.
   */
  protected boolean handleCreateAction(SolrQueryRequest req, SolrQueryResponse rsp)
      throws SolrException {
    try {
      SolrParams params = req.getParams();
      String name = params.get(CoreAdminParams.NAME);
      CoreDescriptor dcore =
          new CoreDescriptor(coreContainer, name, params.get(CoreAdminParams.INSTANCE_DIR));

      //  fillup optional parameters
      String opts = params.get(CoreAdminParams.CONFIG);
      if (opts != null) dcore.setConfigName(opts);

      opts = params.get(CoreAdminParams.SCHEMA);
      if (opts != null) dcore.setSchemaName(opts);

      opts = params.get(CoreAdminParams.DATA_DIR);
      if (opts != null) dcore.setDataDir(opts);

      // Process all property.name=value parameters and set them as name=value core properties
      Properties coreProperties = new Properties();
      Iterator<String> parameterNamesIterator = params.getParameterNamesIterator();
      while (parameterNamesIterator.hasNext()) {
        String parameterName = parameterNamesIterator.next();
        if (parameterName.startsWith(CoreAdminParams.PROPERTY_PREFIX)) {
          String parameterValue = params.get(parameterName);
          String propertyName =
              parameterName.substring(CoreAdminParams.PROPERTY_PREFIX.length()); // skip prefix
          coreProperties.put(propertyName, parameterValue);
        }
      }
      dcore.setCoreProperties(coreProperties);

      SolrCore core = coreContainer.create(dcore);
      coreContainer.register(name, core, false);
      rsp.add("core", core.getName());
      return coreContainer.isPersistent();
    } catch (Exception ex) {
      throw new SolrException(
          SolrException.ErrorCode.BAD_REQUEST,
          "Error executing default implementation of CREATE",
          ex);
    }
  }
예제 #2
0
 protected NamedList<Object> getCoreStatus(CoreContainer cores, String cname) throws IOException {
   NamedList<Object> info = new SimpleOrderedMap<Object>();
   SolrCore core = cores.getCore(cname);
   if (core != null) {
     try {
       info.add("name", core.getName());
       info.add("instanceDir", normalizePath(core.getResourceLoader().getInstanceDir()));
       info.add("dataDir", normalizePath(core.getDataDir()));
       info.add("startTime", new Date(core.getStartTime()));
       info.add("uptime", System.currentTimeMillis() - core.getStartTime());
       RefCounted<SolrIndexSearcher> searcher = core.getSearcher();
       try {
         info.add("index", LukeRequestHandler.getIndexInfo(searcher.get().getReader(), false));
       } finally {
         searcher.decref();
       }
     } finally {
       core.close();
     }
   }
   return info;
 }
예제 #3
0
 // It's important that this be the _only_ thread removing things from pendingDynamicCloses!
 // This is single-threaded, but I tried a multi-threaded approach and didn't see any performance
 // gains, so
 // there's no good justification for the complexity. I suspect that the locking on things like
 // DefaultSolrCoreState
 // essentially create a single-threaded process anyway.
 @Override
 public void run() {
   while (!container.isShutDown()) {
     synchronized (solrCores.getModifyLock()) { // need this so we can wait and be awoken.
       try {
         solrCores.getModifyLock().wait();
       } catch (InterruptedException e) {
         // Well, if we've been told to stop, we will. Otherwise, continue on and check to see if
         // there are
         // any cores to close.
       }
     }
     for (SolrCore removeMe = solrCores.getCoreToClose();
         removeMe != null && !container.isShutDown();
         removeMe = solrCores.getCoreToClose()) {
       try {
         removeMe.close();
       } finally {
         solrCores.removeFromPendingOps(removeMe.getName());
       }
     }
   }
 }