Search in sources :

Example 1 with SolrException

use of org.apache.solr.common.SolrException in project Xponents by OpenSextant.

the class CloserThread method load.

//-------------------------------------------------------------------
// Initialization / Cleanup
//-------------------------------------------------------------------
/**
   * Load the cores defined for this CoreContainer
   */
public void load() {
    log.info("Loading cores into CoreContainer [instanceDir={}]", loader.getInstanceDir());
    // add the sharedLib to the shared resource loader before initializing cfg based plugins
    String libDir = cfg.getSharedLibDirectory();
    if (libDir != null) {
        File f = FileUtils.resolvePath(new File(solrHome), libDir);
        log.info("loading shared library: " + f.getAbsolutePath());
        loader.addToClassLoader(libDir, null, false);
        loader.reloadLuceneSPI();
    }
    shardHandlerFactory = ShardHandlerFactory.newInstance(cfg.getShardHandlerFactoryPluginInfo(), loader);
    updateShardHandler = new UpdateShardHandler(cfg);
    solrCores.allocateLazyCores(cfg.getTransientCacheSize(), loader);
    logging = LogWatcher.newRegisteredLogWatcher(cfg.getLogWatcherConfig(), loader);
    hostName = cfg.getHost();
    log.info("Host Name: " + hostName);
    zkSys.initZooKeeper(this, solrHome, cfg);
    collectionsHandler = createHandler(cfg.getCollectionsHandlerClass(), CollectionsHandler.class);
    infoHandler = createHandler(cfg.getInfoHandlerClass(), InfoHandler.class);
    coreAdminHandler = createHandler(cfg.getCoreAdminHandlerClass(), CoreAdminHandler.class);
    coreConfigService = cfg.createCoreConfigService(loader, zkSys.getZkController());
    containerProperties = cfg.getSolrProperties("solr");
    // setup executor to load cores in parallel
    // do not limit the size of the executor in zk mode since cores may try and wait for each other.
    ExecutorService coreLoadExecutor = Executors.newFixedThreadPool((zkSys.getZkController() == null ? cfg.getCoreLoadThreadCount() : Integer.MAX_VALUE), new DefaultSolrThreadFactory("coreLoadExecutor"));
    // OpenSextant
    List<Future<SolrCore>> startupResults = Collections.emptyList();
    try {
        List<CoreDescriptor> cds = coresLocator.discover(this);
        checkForDuplicateCoreNames(cds);
        List<Callable<SolrCore>> creators = new ArrayList<>();
        for (final CoreDescriptor cd : cds) {
            if (cd.isTransient() || !cd.isLoadOnStartup()) {
                solrCores.putDynamicDescriptor(cd.getName(), cd);
            }
            if (cd.isLoadOnStartup()) {
                creators.add(new Callable<SolrCore>() {

                    @Override
                    public SolrCore call() throws Exception {
                        if (zkSys.getZkController() != null) {
                            zkSys.getZkController().throwErrorIfReplicaReplaced(cd);
                        }
                        return create(cd, false);
                    }
                });
            }
        }
        try {
            // changed by OpenSextant
            startupResults = coreLoadExecutor.invokeAll(creators);
        } catch (InterruptedException e) {
            throw new SolrException(SolrException.ErrorCode.SERVICE_UNAVAILABLE, "Interrupted while loading cores");
        }
        // Start the background thread
        backgroundCloser = new CloserThread(this, solrCores, cfg);
        backgroundCloser.start();
    } finally {
        ExecutorUtil.shutdownNowAndAwaitTermination(coreLoadExecutor);
        // OpenSextant custom
        for (Future<SolrCore> core : startupResults) {
            try {
                core.get();
                log.info("Successfully loaded a core.");
            } catch (InterruptedException e) {
            // ignore, we've been cancelled
            } catch (ExecutionException e) {
                log.error("Error starting solr core.", e);
            }
        }
    // OpenSextant custom
    }
    if (isZooKeeperAware()) {
        // register in zk in background threads
        Collection<SolrCore> cores = getCores();
        if (cores != null) {
            for (SolrCore core : cores) {
                try {
                    zkSys.registerInZk(core, true);
                } catch (Throwable t) {
                    SolrException.log(log, "Error registering SolrCore", t);
                }
            }
        }
        zkSys.getZkController().checkOverseerDesignate();
    }
}
Also used : CollectionsHandler(org.apache.solr.handler.admin.CollectionsHandler) CoreAdminHandler(org.apache.solr.handler.admin.CoreAdminHandler) ArrayList(java.util.ArrayList) UpdateShardHandler(org.apache.solr.update.UpdateShardHandler) Callable(java.util.concurrent.Callable) ExecutionException(java.util.concurrent.ExecutionException) SolrException(org.apache.solr.common.SolrException) DefaultSolrThreadFactory(org.apache.solr.util.DefaultSolrThreadFactory) InfoHandler(org.apache.solr.handler.admin.InfoHandler) SolrException(org.apache.solr.common.SolrException) KeeperException(org.apache.zookeeper.KeeperException) ExecutionException(java.util.concurrent.ExecutionException) ExecutorService(java.util.concurrent.ExecutorService) Future(java.util.concurrent.Future) File(java.io.File)

Example 2 with SolrException

use of org.apache.solr.common.SolrException in project Xponents by OpenSextant.

the class CloserThread method reload.

// ---------------- Core name related methods --------------- 
/**
   * Recreates a SolrCore.
   * While the new core is loading, requests will continue to be dispatched to
   * and processed by the old core
   * 
   * @param name the name of the SolrCore to reload
   */
public void reload(String name) {
    name = checkDefault(name);
    SolrCore core = solrCores.getCoreFromAnyList(name, false);
    if (core == null)
        throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "No such core: " + name);
    CoreDescriptor cd = core.getCoreDescriptor();
    try {
        solrCores.waitAddPendingCoreOps(name);
        ConfigSet coreConfig = coreConfigService.getConfig(cd);
        log.info("Reloading SolrCore '{}' using configuration from {}", cd.getName(), coreConfig.getName());
        SolrCore newCore = core.reload(coreConfig);
        registerCore(name, newCore, false);
    } catch (Exception e) {
        coreInitFailures.put(cd.getName(), new CoreLoadFailure(cd, e));
        throw new SolrException(ErrorCode.SERVER_ERROR, "Unable to reload core [" + cd.getName() + "]", e);
    } finally {
        solrCores.removeFromPendingOps(name);
    }
}
Also used : SolrException(org.apache.solr.common.SolrException) SolrException(org.apache.solr.common.SolrException) KeeperException(org.apache.zookeeper.KeeperException) ExecutionException(java.util.concurrent.ExecutionException)

Example 3 with SolrException

use of org.apache.solr.common.SolrException in project ORCID-Source by ORCID.

the class SolrDaoImpl method findByOrcidAsReader.

@Override
public Reader findByOrcidAsReader(String orcid) {
    SolrQuery query = new SolrQuery();
    query.setQuery(ORCID + ":\"" + orcid + "\"").setFields(SCORE, ORCID, PUBLIC_PROFILE);
    query.add("wt", "orcidProfile");
    try {
        QueryResponse queryResponse = solrServerForStreaming.query(query);
        InputStream inputStream = (InputStream) queryResponse.getResponse().get("stream");
        return new InputStreamReader(inputStream, "UTF-8");
    } catch (SolrServerException | SolrException e) {
        String errorMessage = MessageFormat.format("Error when attempting to retrieve stream for orcid {0}", new Object[] { orcid });
        throw new NonTransientDataAccessResourceException(errorMessage, e);
    } catch (UnsupportedEncodingException e) {
        throw new RuntimeException(e);
    }
}
Also used : NonTransientDataAccessResourceException(org.springframework.dao.NonTransientDataAccessResourceException) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) SolrServerException(org.apache.solr.client.solrj.SolrServerException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) SolrQuery(org.apache.solr.client.solrj.SolrQuery) SolrException(org.apache.solr.common.SolrException)

Example 4 with SolrException

use of org.apache.solr.common.SolrException in project lucene-solr by apache.

the class UIMAUpdateRequestProcessorFactory method getInstance.

@Override
public UpdateRequestProcessor getInstance(SolrQueryRequest req, SolrQueryResponse rsp, UpdateRequestProcessor next) {
    SolrUIMAConfiguration configuration = new SolrUIMAConfigurationReader(args).readSolrUIMAConfiguration();
    synchronized (this) {
        if (ae == null && pool == null) {
            AEProvider aeProvider = AEProviderFactory.getInstance().getAEProvider(req.getCore().getName(), configuration.getAePath(), configuration.getRuntimeParameters());
            try {
                ae = aeProvider.getAE();
                pool = new JCasPool(10, ae);
            } catch (ResourceInitializationException e) {
                throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, e);
            }
        }
    }
    return new UIMAUpdateRequestProcessor(next, req.getCore().getName(), configuration, ae, pool);
}
Also used : AEProvider(org.apache.lucene.analysis.uima.ae.AEProvider) ResourceInitializationException(org.apache.uima.resource.ResourceInitializationException) JCasPool(org.apache.uima.util.JCasPool) SolrException(org.apache.solr.common.SolrException)

Example 5 with SolrException

use of org.apache.solr.common.SolrException in project lucene-solr by apache.

the class ApiBag method getCommandOperations.

public static List<CommandOperation> getCommandOperations(Reader reader, Map<String, JsonSchemaValidator> validators, boolean validate) {
    List<CommandOperation> parsedCommands = null;
    try {
        parsedCommands = CommandOperation.parse(reader);
    } catch (IOException e) {
        throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, e);
    }
    if (validators == null || !validate) {
        // no validation possible because we do not have a spec
        return parsedCommands;
    }
    List<CommandOperation> commandsCopy = CommandOperation.clone(parsedCommands);
    for (CommandOperation cmd : commandsCopy) {
        JsonSchemaValidator validator = validators.get(cmd.name);
        if (validator == null) {
            cmd.addError(formatString("Unknown operation ''{0}'' available ops are ''{1}''", cmd.name, validators.keySet()));
            continue;
        } else {
            List<String> errs = validator.validateJson(cmd.getCommandData());
            if (errs != null)
                for (String err : errs) cmd.addError(err);
        }
    }
    List<Map> errs = CommandOperation.captureErrors(commandsCopy);
    if (!errs.isEmpty()) {
        throw new ExceptionWithErrObject(SolrException.ErrorCode.BAD_REQUEST, "Error in command payload", errs);
    }
    return commandsCopy;
}
Also used : CommandOperation(org.apache.solr.common.util.CommandOperation) IOException(java.io.IOException) StrUtils.formatString(org.apache.solr.common.util.StrUtils.formatString) HashMap(java.util.HashMap) Map(java.util.Map) ValidatingJsonMap(org.apache.solr.common.util.ValidatingJsonMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) SolrException(org.apache.solr.common.SolrException) JsonSchemaValidator(org.apache.solr.util.JsonSchemaValidator)

Aggregations

SolrException (org.apache.solr.common.SolrException)662 IOException (java.io.IOException)195 ArrayList (java.util.ArrayList)109 HashMap (java.util.HashMap)86 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)85 NamedList (org.apache.solr.common.util.NamedList)85 Map (java.util.Map)77 SolrParams (org.apache.solr.common.params.SolrParams)68 KeeperException (org.apache.zookeeper.KeeperException)60 Test (org.junit.Test)59 SolrServerException (org.apache.solr.client.solrj.SolrServerException)56 Replica (org.apache.solr.common.cloud.Replica)48 SimpleOrderedMap (org.apache.solr.common.util.SimpleOrderedMap)46 List (java.util.List)45 Slice (org.apache.solr.common.cloud.Slice)45 SolrInputDocument (org.apache.solr.common.SolrInputDocument)44 DocCollection (org.apache.solr.common.cloud.DocCollection)41 SchemaField (org.apache.solr.schema.SchemaField)40 SolrCore (org.apache.solr.core.SolrCore)38 SolrQueryRequest (org.apache.solr.request.SolrQueryRequest)36