Search in sources :

Example 16 with DatabaseConfigurationException

use of org.exist.util.DatabaseConfigurationException in project exist by eXist-db.

the class JMXAgent method addMBean.

@Override
public synchronized void addMBean(final PerInstanceMBean mbean) throws DatabaseConfigurationException {
    try {
        addMBean(mbean.getName(), mbean);
        if (mbean.getInstanceId() != null) {
            Deque<ObjectName> stack = registeredMBeans.get(mbean.getInstanceId());
            if (stack == null) {
                stack = new ArrayDeque<>();
                registeredMBeans.put(mbean.getInstanceId(), stack);
            }
            stack.push(mbean.getName());
        }
        beanInstances.put(mbean.getName(), mbean);
    } catch (final MalformedObjectNameException e) {
        LOG.warn("Problem registering JMX MBean: {}", e.getMessage(), e);
        throw new DatabaseConfigurationException("Exception while registering JMX MBean: " + e.getMessage());
    }
}
Also used : MalformedObjectNameException(javax.management.MalformedObjectNameException) DatabaseConfigurationException(org.exist.util.DatabaseConfigurationException) ObjectName(javax.management.ObjectName)

Example 17 with DatabaseConfigurationException

use of org.exist.util.DatabaseConfigurationException in project exist by eXist-db.

the class LuceneIndex method open.

@Override
public void open() throws DatabaseConfigurationException {
    Path dir = getDataDir().resolve(getDirName());
    Path taxoDir = dir.resolve(TAXONOMY_DIR_NAME);
    if (LOG.isDebugEnabled())
        LOG.debug("Opening Lucene index directory: {}", dir.toAbsolutePath().toString());
    IndexWriter writer = null;
    try {
        if (Files.exists(dir)) {
            if (!Files.isDirectory(dir))
                throw new DatabaseConfigurationException("Lucene index location is not a directory: " + dir.toAbsolutePath().toString());
        } else {
            Files.createDirectories(taxoDir);
        }
        directory = FSDirectory.open(dir.toFile());
        taxoDirectory = FSDirectory.open(taxoDir.toFile());
        final IndexWriterConfig idxWriterConfig = new IndexWriterConfig(LUCENE_VERSION_IN_USE, defaultAnalyzer);
        idxWriterConfig.setRAMBufferSizeMB(bufferSize);
        cachedWriter = new IndexWriter(directory, idxWriterConfig);
        cachedTaxonomyWriter = new DirectoryTaxonomyWriter(taxoDirectory);
        searcherManager = new SearcherTaxonomyManager(cachedWriter, true, null, cachedTaxonomyWriter);
        readerManager = new ReaderManager(cachedWriter, true);
    } catch (IOException e) {
        throw new DatabaseConfigurationException("Exception while reading lucene index directory: " + e.getMessage(), e);
    } finally {
        releaseWriter(writer);
    }
}
Also used : Path(java.nio.file.Path) DirectoryTaxonomyWriter(org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyWriter) DatabaseConfigurationException(org.exist.util.DatabaseConfigurationException) IOException(java.io.IOException) SearcherTaxonomyManager(org.apache.lucene.facet.taxonomy.SearcherTaxonomyManager)

Example 18 with DatabaseConfigurationException

use of org.exist.util.DatabaseConfigurationException in project exist by eXist-db.

the class LuceneConfig method parseConfig.

/**
 * Parse a configuration entry. The main configuration entries for this index
 * are the &lt;text&gt; elements. They may be enclosed by a &lt;lucene&gt; element.
 *
 * @param configNodes the configuration
 * @param namespaces the namespaces
 *
 * @throws DatabaseConfigurationException if the configuration can't be parsed
 */
protected void parseConfig(final NodeList configNodes, final Map<String, String> namespaces) throws DatabaseConfigurationException {
    Node node;
    for (int i = 0; i < configNodes.getLength(); i++) {
        node = configNodes.item(i);
        if (node.getNodeType() == Node.ELEMENT_NODE) {
            try {
                final String localName = node.getLocalName();
                if (null != localName) {
                    switch(localName) {
                        case CONFIG_ROOT:
                            {
                                Element elem = (Element) node;
                                if (elem.hasAttribute(BOOST_ATTRIB)) {
                                    String value = elem.getAttribute(BOOST_ATTRIB);
                                    try {
                                        boost = Float.parseFloat(value);
                                    } catch (NumberFormatException e) {
                                        throw new DatabaseConfigurationException("Invalid value for 'boost' attribute in " + "lucene index config: float expected, got " + value);
                                    }
                                }
                                if (elem.hasAttribute(DIACRITICS)) {
                                    String value = elem.getAttribute(DIACRITICS);
                                    if (value.equalsIgnoreCase("no")) {
                                        analyzers.setDefaultAnalyzer(new NoDiacriticsStandardAnalyzer(LuceneIndex.LUCENE_VERSION_IN_USE));
                                    }
                                }
                                parseConfig(node.getChildNodes(), namespaces);
                                break;
                            }
                        case ANALYZER_ELEMENT:
                            analyzers.addAnalyzer((Element) node);
                            break;
                        case PARSER_ELEMENT:
                            queryParser = ((Element) node).getAttribute("class");
                            break;
                        case MODULE_ELEMENT:
                            if (imports == null) {
                                imports = new ArrayList<>(3);
                            }
                            imports.add(new ModuleImport((Element) node));
                            break;
                        case FIELD_TYPE_ELEMENT:
                            FieldType type = new FieldType((Element) node, analyzers);
                            fieldTypes.put(type.getId(), type);
                            break;
                        case INDEX_ELEMENT:
                            {
                                // found an index definition
                                Element elem = (Element) node;
                                LuceneIndexConfig config = new LuceneIndexConfig(this, elem, namespaces, analyzers, fieldTypes);
                                // if it is a named index, add it to the namedIndexes map
                                if (config.getName() != null) {
                                    namedIndexes.put(config.getName(), config);
                                }
                                // register index either by QName or path
                                if (config.getNodePathPattern().hasWildcard()) {
                                    wildcardPaths.add(config);
                                } else {
                                    LuceneIndexConfig idxConf = paths.get(config.getNodePathPattern().getLastComponent());
                                    if (idxConf == null) {
                                        paths.put(config.getNodePathPattern().getLastComponent(), config);
                                    } else {
                                        idxConf.add(config);
                                    }
                                }
                                break;
                            }
                        case INLINE_ELEMENT:
                            {
                                Element elem = (Element) node;
                                QName qname = LuceneIndexConfig.parseQName(elem, namespaces);
                                if (inlineNodes == null) {
                                    inlineNodes = new TreeSet<>();
                                }
                                inlineNodes.add(qname);
                                break;
                            }
                        case IGNORE_ELEMENT:
                            {
                                Element elem = (Element) node;
                                QName qname = LuceneIndexConfig.parseQName(elem, namespaces);
                                if (ignoreNodes == null) {
                                    ignoreNodes = new TreeSet<>();
                                }
                                ignoreNodes.add(qname);
                                break;
                            }
                    }
                }
            } catch (DatabaseConfigurationException e) {
                LOG.warn("Invalid lucene configuration element: {}", e.getMessage());
            }
        }
    }
}
Also used : QName(org.exist.dom.QName) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) NoDiacriticsStandardAnalyzer(org.exist.indexing.lucene.analyzers.NoDiacriticsStandardAnalyzer) DatabaseConfigurationException(org.exist.util.DatabaseConfigurationException)

Example 19 with DatabaseConfigurationException

use of org.exist.util.DatabaseConfigurationException in project exist by eXist-db.

the class AbstractExistHttpServlet method getOrCreateBrokerPool.

private BrokerPool getOrCreateBrokerPool(final ServletConfig config) throws EXistException, DatabaseConfigurationException, ServletException {
    // Configure BrokerPool
    if (BrokerPool.isConfigured()) {
        getLog().info("Database already started. Skipping configuration ...");
    } else {
        final String confFile = Optional.ofNullable(config.getInitParameter("configuration")).orElse("conf.xml");
        final Optional<Path> dbHome = Optional.ofNullable(config.getInitParameter("basedir")).map(baseDir -> Optional.ofNullable(config.getServletContext().getRealPath(baseDir)).map(rp -> Optional.of(Paths.get(rp))).orElse(Optional.ofNullable(config.getServletContext().getRealPath("/")).map(dir -> Paths.get(dir).resolve("WEB-INF").toAbsolutePath()))).orElse(Optional.ofNullable(config.getServletContext().getRealPath("/")).map(Paths::get));
        getLog().info("EXistServlet: exist.home={}", dbHome.map(Path::toString).orElse("null"));
        final Path cf = dbHome.map(h -> h.resolve(confFile)).orElse(Paths.get(confFile));
        getLog().info("Reading configuration from {}", cf.toAbsolutePath().toString());
        if (!Files.isReadable(cf)) {
            throw new ServletException("Configuration file " + confFile + " not found or not readable");
        }
        final Configuration configuration = new Configuration(confFile, dbHome);
        final String start = config.getInitParameter("start");
        if (start != null && "true".equals(start)) {
            doDatabaseStartup(configuration);
        }
    }
    return BrokerPool.getInstance();
}
Also used : Path(java.nio.file.Path) BrokerPool(org.exist.storage.BrokerPool) ServletException(javax.servlet.ServletException) HttpServletRequest(javax.servlet.http.HttpServletRequest) Subject(org.exist.security.Subject) EXistException(org.exist.EXistException) Path(java.nio.file.Path) XMLDBException(org.xmldb.api.base.XMLDBException) XQueryURLRewrite(org.exist.http.urlrewrite.XQueryURLRewrite) DatabaseManager(org.xmldb.api.DatabaseManager) ServletConfig(javax.servlet.ServletConfig) HttpServlet(javax.servlet.http.HttpServlet) AuthenticationException(org.exist.security.AuthenticationException) Files(java.nio.file.Files) HttpServletResponse(javax.servlet.http.HttpServletResponse) Database(org.xmldb.api.base.Database) IOException(java.io.IOException) HttpAccount(org.exist.security.internal.web.HttpAccount) SecurityManager(org.exist.security.SecurityManager) Logger(org.apache.logging.log4j.Logger) Principal(java.security.Principal) XmldbPrincipal(org.exist.security.XmldbPrincipal) Paths(java.nio.file.Paths) Optional(java.util.Optional) Configuration(org.exist.util.Configuration) DatabaseConfigurationException(org.exist.util.DatabaseConfigurationException) ServletException(javax.servlet.ServletException) Configuration(org.exist.util.Configuration)

Aggregations

DatabaseConfigurationException (org.exist.util.DatabaseConfigurationException)19 EXistException (org.exist.EXistException)8 IOException (java.io.IOException)6 Configuration (org.exist.util.Configuration)6 Path (java.nio.file.Path)5 Element (org.w3c.dom.Element)4 Node (org.w3c.dom.Node)4 ServletException (javax.servlet.ServletException)3 QName (org.exist.dom.QName)3 PermissionDeniedException (org.exist.security.PermissionDeniedException)3 ClassLoaderSource (org.exist.source.ClassLoaderSource)3 Source (org.exist.source.Source)3 BrokerPool (org.exist.storage.BrokerPool)3 NodeList (org.w3c.dom.NodeList)3 FileSource (org.exist.source.FileSource)2 DBException (org.exist.storage.btree.DBException)2 BTreeStore (org.exist.storage.index.BTreeStore)2 FunctionReference (org.exist.xquery.value.FunctionReference)2 URI (java.net.URI)1 Files (java.nio.file.Files)1