Search in sources :

Example 1 with UnparsedConfigDefinition

use of com.yahoo.config.application.api.UnparsedConfigDefinition in project vespa by vespa-engine.

the class ZooKeeperClient method writeUserDefs.

/**
 * Feeds all user-defined .def file from the application package into ZooKeeper (both into
 * /defconfigs and /userdefconfigs
 */
private void writeUserDefs(ApplicationPackage applicationPackage) {
    Map<ConfigDefinitionKey, UnparsedConfigDefinition> configDefs = applicationPackage.getAllExistingConfigDefs();
    for (Map.Entry<ConfigDefinitionKey, UnparsedConfigDefinition> entry : configDefs.entrySet()) {
        ConfigDefinitionKey key = entry.getKey();
        String contents = entry.getValue().getUnparsedContent();
        write(key.getName(), key.getNamespace(), getZooKeeperAppPath(ConfigCurator.USER_DEFCONFIGS_ZK_SUBPATH).getAbsolute(), contents);
        write(key.getName(), key.getNamespace(), getZooKeeperAppPath(ConfigCurator.DEFCONFIGS_ZK_SUBPATH).getAbsolute(), contents);
    }
    logger.log(LogLevel.FINE, configDefs.size() + " user config definitions");
}
Also used : UnparsedConfigDefinition(com.yahoo.config.application.api.UnparsedConfigDefinition) ConfigDefinitionKey(com.yahoo.vespa.config.ConfigDefinitionKey) Map(java.util.Map)

Example 2 with UnparsedConfigDefinition

use of com.yahoo.config.application.api.UnparsedConfigDefinition in project vespa by vespa-engine.

the class ZKApplicationPackage method getAllExistingConfigDefs.

@Override
public Map<ConfigDefinitionKey, UnparsedConfigDefinition> getAllExistingConfigDefs() {
    Map<ConfigDefinitionKey, UnparsedConfigDefinition> ret = new LinkedHashMap<>();
    List<String> allDefs = liveApp.getChildren(ConfigCurator.DEFCONFIGS_ZK_SUBPATH);
    for (final String nodeName : allDefs) {
        final ConfigDefinitionKey key = ConfigUtils.createConfigDefinitionKeyFromZKString(nodeName);
        ret.put(key, new UnparsedConfigDefinition() {

            @Override
            public ConfigDefinition parse() {
                DefParser parser = new DefParser(key.getName(), retrieveConfigDefReader(nodeName));
                return ConfigDefinitionBuilder.createConfigDefinition(parser.getTree());
            }

            @Override
            public String getUnparsedContent() {
                try {
                    return IOUtils.readAll(retrieveConfigDefReader(nodeName));
                } catch (Exception e) {
                    throw new RuntimeException("Error retriving def file", e);
                }
            }
        });
    }
    return ret;
}
Also used : UnparsedConfigDefinition(com.yahoo.config.application.api.UnparsedConfigDefinition) UnparsedConfigDefinition(com.yahoo.config.application.api.UnparsedConfigDefinition) ConfigDefinition(com.yahoo.vespa.config.ConfigDefinition) ConfigDefinitionKey(com.yahoo.vespa.config.ConfigDefinitionKey) DefParser(com.yahoo.config.codegen.DefParser) LinkedHashMap(java.util.LinkedHashMap)

Example 3 with UnparsedConfigDefinition

use of com.yahoo.config.application.api.UnparsedConfigDefinition in project vespa by vespa-engine.

the class FilesApplicationPackage method addAllDefsFromConfigDir.

private void addAllDefsFromConfigDir(Map<ConfigDefinitionKey, UnparsedConfigDefinition> defs, File configDefsDir) {
    if (!configDefsDir.isDirectory())
        return;
    log.log(LogLevel.DEBUG, "Getting all config definitions from '" + configDefsDir + "'");
    for (File def : configDefsDir.listFiles(new FilenameFilter() {

        @Override
        public boolean accept(File dir, String name) {
            // TODO: Fix
            return name.matches(".*\\.def");
        }
    })) {
        log.log(LogLevel.DEBUG, "Processing config definition '" + def + "'");
        String[] nv = def.getName().split("\\.def");
        ConfigDefinitionKey key;
        try {
            key = ConfigUtils.createConfigDefinitionKeyFromDefFile(def);
        } catch (IOException e) {
            // TODO: Fix
            e.printStackTrace();
            break;
        }
        if (key.getNamespace().isEmpty())
            throw new IllegalArgumentException("Config definition '" + def + "' has no namespace");
        if (defs.containsKey(key)) {
            if (nv[0].contains(".")) {
                log.log(LogLevel.INFO, "Two config definitions found for the same name and namespace: " + key + ". The file '" + def + "' will take precedence");
            } else {
                log.log(LogLevel.INFO, "Two config definitions found for the same name and namespace: " + key + ". Skipping '" + def + "', as it does not contain namespace in filename");
                // skip
                continue;
            }
        }
        defs.put(key, new UnparsedConfigDefinition() {

            @Override
            public ConfigDefinition parse() {
                DefParser parser = new DefParser(key.getName(), retrieveConfigDefReader(def));
                return ConfigDefinitionBuilder.createConfigDefinition(parser.getTree());
            }

            @Override
            public String getUnparsedContent() {
                return readConfigDefinition(def);
            }
        });
    }
}
Also used : UnparsedConfigDefinition(com.yahoo.config.application.api.UnparsedConfigDefinition) UnparsedConfigDefinition(com.yahoo.config.application.api.UnparsedConfigDefinition) ConfigDefinition(com.yahoo.vespa.config.ConfigDefinition) ConfigDefinitionKey(com.yahoo.vespa.config.ConfigDefinitionKey) DefParser(com.yahoo.config.codegen.DefParser) JarFile(java.util.jar.JarFile) ApplicationFile(com.yahoo.config.application.api.ApplicationFile)

Example 4 with UnparsedConfigDefinition

use of com.yahoo.config.application.api.UnparsedConfigDefinition in project vespa by vespa-engine.

the class FilesApplicationPackage method getAllExistingConfigDefs.

@Override
public Map<ConfigDefinitionKey, UnparsedConfigDefinition> getAllExistingConfigDefs() {
    Map<ConfigDefinitionKey, UnparsedConfigDefinition> defs = new LinkedHashMap<>();
    addAllDefsFromConfigDir(defs, configDefsDir);
    if (includeSourceFiles) {
        // allow running from source, assuming mvn file project layout
        addAllDefsFromConfigDir(defs, new File("src/main/resources/configdefinitions"));
        addAllDefsFromConfigDir(defs, new File("src/test/resources/configdefinitions"));
    }
    addAllDefsFromBundles(defs, FilesApplicationPackage.getComponents(appDir));
    return defs;
}
Also used : UnparsedConfigDefinition(com.yahoo.config.application.api.UnparsedConfigDefinition) ConfigDefinitionKey(com.yahoo.vespa.config.ConfigDefinitionKey) JarFile(java.util.jar.JarFile) ApplicationFile(com.yahoo.config.application.api.ApplicationFile)

Example 5 with UnparsedConfigDefinition

use of com.yahoo.config.application.api.UnparsedConfigDefinition in project vespa by vespa-engine.

the class ApplicationDeployTest method testConfigDefinitionsFromJars.

@Test
public void testConfigDefinitionsFromJars() throws IOException {
    String appName = "src/test/cfg//application/app1";
    FilesApplicationPackage app = FilesApplicationPackage.fromFile(new File(appName), false);
    Map<ConfigDefinitionKey, UnparsedConfigDefinition> defs = app.getAllExistingConfigDefs();
    assertThat(defs.size(), is(5));
}
Also used : UnparsedConfigDefinition(com.yahoo.config.application.api.UnparsedConfigDefinition) ConfigDefinitionKey(com.yahoo.vespa.config.ConfigDefinitionKey) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) JarFile(java.util.jar.JarFile) File(java.io.File) Test(org.junit.Test)

Aggregations

UnparsedConfigDefinition (com.yahoo.config.application.api.UnparsedConfigDefinition)5 ConfigDefinitionKey (com.yahoo.vespa.config.ConfigDefinitionKey)5 JarFile (java.util.jar.JarFile)3 ApplicationFile (com.yahoo.config.application.api.ApplicationFile)2 DefParser (com.yahoo.config.codegen.DefParser)2 ConfigDefinition (com.yahoo.vespa.config.ConfigDefinition)2 File (java.io.File)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1 Test (org.junit.Test)1