Search in sources :

Example 11 with NamedReader

use of com.yahoo.io.reader.NamedReader in project vespa by vespa-engine.

the class FilesApplicationPackage method searchDefinitionContents.

@Override
public Collection<NamedReader> searchDefinitionContents() {
    Map<String, NamedReader> ret = new LinkedHashMap<>();
    Set<String> fileSds = new LinkedHashSet<>();
    Set<String> bundleSds = new LinkedHashSet<>();
    try {
        for (File f : getSearchDefinitionFiles()) {
            fileSds.add(f.getName());
            ret.put(f.getName(), new NamedReader(f.getName(), new FileReader(f)));
        }
        for (Map.Entry<String, String> e : allSdsFromDocprocBundlesAndClasspath(appDir).entrySet()) {
            bundleSds.add(e.getKey());
            ret.put(e.getKey(), new NamedReader(e.getKey(), new StringReader(e.getValue())));
        }
    } catch (Exception e) {
        throw new IllegalArgumentException("Couldn't get search definition contents.", e);
    }
    verifySdsDisjoint(fileSds, bundleSds);
    return ret.values();
}
Also used : NamedReader(com.yahoo.io.reader.NamedReader) TransformerException(javax.xml.transform.TransformerException) URISyntaxException(java.net.URISyntaxException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException) JarFile(java.util.jar.JarFile) ApplicationFile(com.yahoo.config.application.api.ApplicationFile)

Example 12 with NamedReader

use of com.yahoo.io.reader.NamedReader in project vespa by vespa-engine.

the class FilesApplicationPackage method getFiles.

private List<NamedReader> getFiles(Path relativePath, String namePrefix, String suffix, boolean recurse) {
    try {
        List<NamedReader> readers = new ArrayList<>();
        File dir = new File(appDir, relativePath.getRelative());
        if (!dir.isDirectory())
            return readers;
        File[] files = dir.listFiles();
        if (files != null) {
            for (File file : files) {
                if (file.isDirectory()) {
                    if (recurse)
                        readers.addAll(getFiles(relativePath.append(file.getName()), namePrefix + "/" + file.getName(), suffix, recurse));
                } else {
                    if (suffix == null || file.getName().endsWith(suffix))
                        readers.add(new NamedReader(file.getName(), new FileReader(file)));
                }
            }
        }
        return readers;
    } catch (IOException e) {
        throw new RuntimeException("Could not open (all) files in '" + relativePath + "'", e);
    }
}
Also used : NamedReader(com.yahoo.io.reader.NamedReader) JarFile(java.util.jar.JarFile) ApplicationFile(com.yahoo.config.application.api.ApplicationFile)

Example 13 with NamedReader

use of com.yahoo.io.reader.NamedReader in project vespa by vespa-engine.

the class PageTemplates method validate.

/**
 * The number of pages in this, for reporting
 */
// private int pages=0;
/**
 * Validates page templates in an application package. The passed readers will be closed.
 */
public static void validate(ApplicationPackage applicationPackage) {
    List<NamedReader> pageTemplateFiles = null;
    try {
        pageTemplateFiles = applicationPackage.getPageTemplateFiles();
        // Parse XML for validation only
        new PageTemplateXMLReader().read(pageTemplateFiles, true);
    } finally {
        NamedReader.closeAll(pageTemplateFiles);
    }
}
Also used : NamedReader(com.yahoo.io.reader.NamedReader) PageTemplateXMLReader(com.yahoo.search.pagetemplates.config.PageTemplateXMLReader)

Example 14 with NamedReader

use of com.yahoo.io.reader.NamedReader in project vespa by vespa-engine.

the class ZooKeeperClient method writeSearchDefinitions.

private void writeSearchDefinitions(ApplicationPackage app) throws IOException {
    Collection<NamedReader> sds = app.getSearchDefinitions();
    if (sds.isEmpty()) {
        return;
    }
    Path zkPath = getZooKeeperAppPath(ConfigCurator.USERAPP_ZK_SUBPATH).append(ApplicationPackage.SEARCH_DEFINITIONS_DIR);
    configCurator.createNode(zkPath.getAbsolute());
    // Ensures that ranking expressions and other files are also fed.
    writeDir(app.getFile(ApplicationPackage.SEARCH_DEFINITIONS_DIR), zkPath, false);
    for (NamedReader sd : sds) {
        String name = sd.getName();
        Reader reader = sd.getReader();
        String data = com.yahoo.io.IOUtils.readAll(reader);
        reader.close();
        configCurator.putData(zkPath.getAbsolute(), name, data);
    }
}
Also used : Path(com.yahoo.path.Path) NamedReader(com.yahoo.io.reader.NamedReader) Reader(java.io.Reader) NamedReader(com.yahoo.io.reader.NamedReader)

Example 15 with NamedReader

use of com.yahoo.io.reader.NamedReader in project vespa by vespa-engine.

the class QueryProfileXMLReader method read.

/**
 * Reads all query profile xml files in a given directory,
 * and all type xml files from the immediate subdirectory "types/" (if any)
 *
 * @throws RuntimeException if <code>directory</code> is not a readable directory, or if there is some error in the XML
 */
public QueryProfileRegistry read(String directory) {
    List<NamedReader> queryProfileReaders = new ArrayList<>();
    List<NamedReader> queryProfileTypeReaders = new ArrayList<>();
    try {
        File dir = new File(directory);
        if (!dir.isDirectory())
            throw new IllegalArgumentException("Could not read query profiles: '" + directory + "' is not a valid directory.");
        for (File file : sortFiles(dir)) {
            if (!file.getName().endsWith(".xml"))
                continue;
            queryProfileReaders.add(new NamedReader(file.getName(), new FileReader(file)));
        }
        File typeDir = new File(dir, "types");
        if (typeDir.isDirectory()) {
            for (File file : sortFiles(typeDir)) {
                if (!file.getName().endsWith(".xml"))
                    continue;
                queryProfileTypeReaders.add(new NamedReader(file.getName(), new FileReader(file)));
            }
        }
        return read(queryProfileTypeReaders, queryProfileReaders);
    } catch (IOException e) {
        throw new IllegalArgumentException("Could not read query profiles from '" + directory + "'", e);
    } finally {
        closeAll(queryProfileReaders);
        closeAll(queryProfileTypeReaders);
    }
}
Also used : ArrayList(java.util.ArrayList) NamedReader(com.yahoo.io.reader.NamedReader) FileReader(java.io.FileReader) IOException(java.io.IOException) File(java.io.File)

Aggregations

NamedReader (com.yahoo.io.reader.NamedReader)16 ArrayList (java.util.ArrayList)7 Element (org.w3c.dom.Element)4 ComponentId (com.yahoo.component.ComponentId)3 File (java.io.File)3 StringReader (java.io.StringReader)3 ApplicationFile (com.yahoo.config.application.api.ApplicationFile)2 QueryProfileType (com.yahoo.search.query.profile.types.QueryProfileType)2 FileReader (java.io.FileReader)2 IOException (java.io.IOException)2 JarFile (java.util.jar.JarFile)2 Path (com.yahoo.path.Path)1 PageTemplate (com.yahoo.search.pagetemplates.PageTemplate)1 PageTemplateXMLReader (com.yahoo.search.pagetemplates.config.PageTemplateXMLReader)1 QueryProfile (com.yahoo.search.query.profile.QueryProfile)1 ParseException (com.yahoo.searchdefinition.parser.ParseException)1 PageTemplates (com.yahoo.vespa.model.container.search.PageTemplates)1 NonNull (edu.umd.cs.findbugs.annotations.NonNull)1 Reader (java.io.Reader)1 URISyntaxException (java.net.URISyntaxException)1