Search in sources :

Example 56 with SolrException

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

the class CloserThread method create.

/**
   * Creates a new core based on a CoreDescriptor.
   *
   * @param dcore        a core descriptor
   * @param publishState publish core state to the cluster if true
   *
   * @return the newly created core
   */
private SolrCore create(CoreDescriptor dcore, boolean publishState, boolean newCollection) {
    if (isShutDown) {
        throw new SolrException(ErrorCode.SERVICE_UNAVAILABLE, "Solr has been shutdown.");
    }
    SolrCore core = null;
    try {
        MDCLoggingContext.setCoreDescriptor(this, dcore);
        SolrIdentifierValidator.validateCoreName(dcore.getName());
        if (zkSys.getZkController() != null) {
            zkSys.getZkController().preRegister(dcore);
        }
        ConfigSet coreConfig = coreConfigService.getConfig(dcore);
        dcore.setConfigSetTrusted(coreConfig.isTrusted());
        log.info("Creating SolrCore '{}' using configuration from {}, trusted={}", dcore.getName(), coreConfig.getName(), dcore.isConfigSetTrusted());
        try {
            core = new SolrCore(this, dcore, coreConfig);
        } catch (SolrException e) {
            core = processCoreCreateException(e, dcore, coreConfig);
        }
        // always kick off recovery if we are in non-Cloud mode
        if (!isZooKeeperAware() && core.getUpdateHandler().getUpdateLog() != null) {
            core.getUpdateHandler().getUpdateLog().recoverFromLog();
        }
        registerCore(dcore, core, publishState, newCollection);
        return core;
    } catch (Exception e) {
        coreInitFailures.put(dcore.getName(), new CoreLoadFailure(dcore, e));
        final SolrException solrException = new SolrException(ErrorCode.SERVER_ERROR, "Unable to create core [" + dcore.getName() + "]", e);
        if (core != null && !core.isClosed())
            IOUtils.closeQuietly(core);
        throw solrException;
    } catch (Throwable t) {
        SolrException e = new SolrException(ErrorCode.SERVER_ERROR, "JVM Error creating core [" + dcore.getName() + "]: " + t.getMessage(), t);
        coreInitFailures.put(dcore.getName(), new CoreLoadFailure(dcore, e));
        if (core != null && !core.isClosed())
            IOUtils.closeQuietly(core);
        throw t;
    } finally {
        MDCLoggingContext.clear();
    }
}
Also used : SolrException(org.apache.solr.common.SolrException) CorruptIndexException(org.apache.lucene.index.CorruptIndexException) SolrException(org.apache.solr.common.SolrException) KeeperException(org.apache.zookeeper.KeeperException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException)

Example 57 with SolrException

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

the class CloserThread method create.

/**
   * Creates a new core in a specified instance directory, publishing the core state to the cluster
   * @param coreName the core name
   * @param instancePath the instance directory
   * @param parameters the core parameters
   * @return the newly created core
   */
public SolrCore create(String coreName, Path instancePath, Map<String, String> parameters, boolean newCollection) {
    CoreDescriptor cd = new CoreDescriptor(coreName, instancePath, parameters, getContainerProperties(), isZooKeeperAware());
    // TODO: There's a race here, isn't there?
    if (getLoadedCoreNames().contains(coreName)) {
        log.warn("Creating a core with existing name is not allowed");
        // TODO: Shouldn't this be a BAD_REQUEST?
        throw new SolrException(ErrorCode.SERVER_ERROR, "Core with name '" + coreName + "' already exists.");
    }
    boolean preExisitingZkEntry = false;
    try {
        if (getZkController() != null) {
            if (!Overseer.isLegacy(getZkController().getZkStateReader())) {
                if (cd.getCloudDescriptor().getCoreNodeName() == null) {
                    throw new SolrException(ErrorCode.SERVER_ERROR, "non legacy mode coreNodeName missing " + parameters.toString());
                }
            }
            preExisitingZkEntry = getZkController().checkIfCoreNodeNameAlreadyExists(cd);
        }
        SolrCore core = create(cd, true, newCollection);
        // only write out the descriptor if the core is successfully created
        coresLocator.create(this, cd);
        return core;
    } catch (Exception ex) {
        if (isZooKeeperAware() && !preExisitingZkEntry) {
            try {
                getZkController().unregister(coreName, cd);
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
                SolrException.log(log, null, e);
            } catch (KeeperException e) {
                SolrException.log(log, null, e);
            }
        }
        Throwable tc = ex;
        Throwable c = null;
        do {
            tc = tc.getCause();
            if (tc != null) {
                c = tc;
            }
        } while (tc != null);
        String rootMsg = "";
        if (c != null) {
            rootMsg = " Caused by: " + c.getMessage();
        }
        throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Error CREATEing SolrCore '" + coreName + "': " + ex.getMessage() + rootMsg, ex);
    }
}
Also used : SolrException(org.apache.solr.common.SolrException) CorruptIndexException(org.apache.lucene.index.CorruptIndexException) SolrException(org.apache.solr.common.SolrException) KeeperException(org.apache.zookeeper.KeeperException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) KeeperException(org.apache.zookeeper.KeeperException)

Example 58 with SolrException

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

the class CorePropertiesLocator method discover.

@Override
public List<CoreDescriptor> discover(final CoreContainer cc) {
    logger.debug("Looking for core definitions underneath {}", rootDirectory);
    final List<CoreDescriptor> cds = Lists.newArrayList();
    try {
        Set<FileVisitOption> options = new HashSet<>();
        options.add(FileVisitOption.FOLLOW_LINKS);
        final int maxDepth = 256;
        Files.walkFileTree(this.rootDirectory, options, maxDepth, new SimpleFileVisitor<Path>() {

            @Override
            public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
                if (file.getFileName().toString().equals(PROPERTIES_FILENAME)) {
                    CoreDescriptor cd = buildCoreDescriptor(file, cc);
                    if (cd != null) {
                        logger.debug("Found core {} in {}", cd.getName(), cd.getInstanceDir());
                        cds.add(cd);
                    }
                    return FileVisitResult.SKIP_SIBLINGS;
                }
                return FileVisitResult.CONTINUE;
            }

            @Override
            public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException {
                // otherwise, log a warning and continue to try and load other cores
                if (file.equals(rootDirectory)) {
                    logger.error("Error reading core root directory {}: {}", file, exc);
                    throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Error reading core root directory");
                }
                logger.warn("Error visiting {}: {}", file, exc);
                return FileVisitResult.CONTINUE;
            }
        });
    } catch (IOException e) {
        throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Couldn't walk file tree under " + this.rootDirectory, e);
    }
    logger.info("Found {} core definitions underneath {}", cds.size(), rootDirectory);
    if (cds.size() > 0) {
        logger.info("Cores are: {}", cds.stream().map(CoreDescriptor::getName).collect(Collectors.toList()));
    }
    return cds;
}
Also used : Path(java.nio.file.Path) FileVisitOption(java.nio.file.FileVisitOption) FileVisitResult(java.nio.file.FileVisitResult) IOException(java.io.IOException) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes) SolrException(org.apache.solr.common.SolrException) HashSet(java.util.HashSet)

Example 59 with SolrException

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

the class BlobRepository method fetchBlob.

/**
   *  Package local for unit tests only please do not use elsewhere
   */
ByteBuffer fetchBlob(String key) {
    Replica replica = getSystemCollReplica();
    String url = replica.getStr(BASE_URL_PROP) + "/.system/blob/" + key + "?wt=filestream";
    HttpClient httpClient = coreContainer.getUpdateShardHandler().getHttpClient();
    HttpGet httpGet = new HttpGet(url);
    ByteBuffer b;
    try {
        HttpResponse entity = httpClient.execute(httpGet);
        int statusCode = entity.getStatusLine().getStatusCode();
        if (statusCode != 200) {
            throw new SolrException(SolrException.ErrorCode.NOT_FOUND, "no such blob or version available: " + key);
        }
        b = SimplePostTool.inputStreamToByteArray(entity.getEntity().getContent());
    } catch (Exception e) {
        if (e instanceof SolrException) {
            throw (SolrException) e;
        } else {
            throw new SolrException(SolrException.ErrorCode.NOT_FOUND, "could not load : " + key, e);
        }
    } finally {
        httpGet.releaseConnection();
    }
    return b;
}
Also used : HttpClient(org.apache.http.client.HttpClient) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) Replica(org.apache.solr.common.cloud.Replica) ByteBuffer(java.nio.ByteBuffer) SolrException(org.apache.solr.common.SolrException) SolrException(org.apache.solr.common.SolrException)

Example 60 with SolrException

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

the class Config method complainAboutUnknownAttributes.

/**
   * Logs an error and throws an exception if any of the element(s) at the given elementXpath
   * contains an attribute name that is not among knownAttributes. 
   */
public void complainAboutUnknownAttributes(String elementXpath, String... knownAttributes) {
    SortedMap<String, SortedSet<String>> problems = new TreeMap<>();
    NodeList nodeList = getNodeList(elementXpath, false);
    for (int i = 0; i < nodeList.getLength(); ++i) {
        Element element = (Element) nodeList.item(i);
        Set<String> unknownAttributes = getUnknownAttributes(element, knownAttributes);
        if (null != unknownAttributes) {
            String elementName = element.getNodeName();
            SortedSet<String> allUnknownAttributes = problems.get(elementName);
            if (null == allUnknownAttributes) {
                allUnknownAttributes = new TreeSet<>();
                problems.put(elementName, allUnknownAttributes);
            }
            allUnknownAttributes.addAll(unknownAttributes);
        }
    }
    if (problems.size() > 0) {
        StringBuilder message = new StringBuilder();
        for (Map.Entry<String, SortedSet<String>> entry : problems.entrySet()) {
            if (message.length() > 0) {
                message.append(", ");
            }
            message.append('<');
            message.append(entry.getKey());
            for (String attributeName : entry.getValue()) {
                message.append(' ');
                message.append(attributeName);
                message.append("=\"...\"");
            }
            message.append('>');
        }
        message.insert(0, "Unknown attribute(s) on element(s): ");
        String msg = message.toString();
        SolrException.log(log, msg);
        throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, msg);
    }
}
Also used : NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) TreeMap(java.util.TreeMap) SortedSet(java.util.SortedSet) Map(java.util.Map) NamedNodeMap(org.w3c.dom.NamedNodeMap) TreeMap(java.util.TreeMap) SortedMap(java.util.SortedMap) SolrException(org.apache.solr.common.SolrException)

Aggregations

SolrException (org.apache.solr.common.SolrException)617 IOException (java.io.IOException)172 ArrayList (java.util.ArrayList)100 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)80 NamedList (org.apache.solr.common.util.NamedList)79 HashMap (java.util.HashMap)75 Map (java.util.Map)70 SolrParams (org.apache.solr.common.params.SolrParams)64 KeeperException (org.apache.zookeeper.KeeperException)60 Test (org.junit.Test)55 Replica (org.apache.solr.common.cloud.Replica)48 Slice (org.apache.solr.common.cloud.Slice)45 DocCollection (org.apache.solr.common.cloud.DocCollection)41 SolrInputDocument (org.apache.solr.common.SolrInputDocument)39 SchemaField (org.apache.solr.schema.SchemaField)39 List (java.util.List)38 SimpleOrderedMap (org.apache.solr.common.util.SimpleOrderedMap)38 SolrServerException (org.apache.solr.client.solrj.SolrServerException)37 SolrQueryRequest (org.apache.solr.request.SolrQueryRequest)34 SolrCore (org.apache.solr.core.SolrCore)33