Search in sources :

Example 16 with ConfigDefinitionKey

use of com.yahoo.vespa.config.ConfigDefinitionKey in project vespa by vespa-engine.

the class ConfigUtilsTest method testGetConfigDefinitionKey.

@Test
public void testGetConfigDefinitionKey() {
    String input = "foo.bar";
    ConfigDefinitionKey def = ConfigUtils.getConfigDefinitionKeyFromString(input);
    assertThat(def.getName(), is("bar"));
    assertThat(def.getNamespace(), is("foo"));
    input = "foo.bar.1";
    def = ConfigUtils.getConfigDefinitionKeyFromString(input);
    assertThat(def.getName(), is("bar"));
    assertThat(def.getNamespace(), is("foo"));
    input = "foo.bar.qux.2";
    def = ConfigUtils.getConfigDefinitionKeyFromString(input);
    assertThat(def.getName(), is("qux"));
    assertThat(def.getNamespace(), is("foo.bar"));
}
Also used : ConfigDefinitionKey(com.yahoo.vespa.config.ConfigDefinitionKey) Test(org.junit.Test)

Example 17 with ConfigDefinitionKey

use of com.yahoo.vespa.config.ConfigDefinitionKey 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 18 with ConfigDefinitionKey

use of com.yahoo.vespa.config.ConfigDefinitionKey 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 19 with ConfigDefinitionKey

use of com.yahoo.vespa.config.ConfigDefinitionKey in project vespa by vespa-engine.

the class StaticConfigDefinitionRepo method addConfigDefinition.

private void addConfigDefinition(File def) {
    try {
        ConfigDefinitionKey key = ConfigUtils.createConfigDefinitionKeyFromDefFile(def);
        if (key.getNamespace().isEmpty())
            key = new ConfigDefinitionKey(key.getName(), CNode.DEFAULT_NAMESPACE);
        addConfigDefinition(key, def);
    } catch (IOException e) {
        log.log(LogLevel.WARNING, "Exception adding config definition " + def, e);
    }
}
Also used : ConfigDefinitionKey(com.yahoo.vespa.config.ConfigDefinitionKey) IOException(java.io.IOException)

Example 20 with ConfigDefinitionKey

use of com.yahoo.vespa.config.ConfigDefinitionKey in project vespa by vespa-engine.

the class StaticConfigDefinitionRepoTest method testThatRepoIsCorrectlyInitialized.

@Test
public void testThatRepoIsCorrectlyInitialized() throws IOException {
    File topDir = folder.newFolder();
    File defDir = new File(topDir, "classes");
    defDir.mkdir();
    addFile(defDir, new ConfigDefinitionKey("foo", "foons"), "namespace=foons\nval int\n");
    addFile(defDir, new ConfigDefinitionKey("bar", "barns"), "namespace=barns\nval string\n");
    ConfigDefinitionRepo repo = new StaticConfigDefinitionRepo(defDir);
    assertThat(repo.getConfigDefinitions().size(), is(2));
}
Also used : StaticConfigDefinitionRepo(com.yahoo.config.model.application.provider.StaticConfigDefinitionRepo) ConfigDefinitionKey(com.yahoo.vespa.config.ConfigDefinitionKey) File(java.io.File) StaticConfigDefinitionRepo(com.yahoo.config.model.application.provider.StaticConfigDefinitionRepo) ConfigDefinitionRepo(com.yahoo.config.model.api.ConfigDefinitionRepo) Test(org.junit.Test)

Aggregations

ConfigDefinitionKey (com.yahoo.vespa.config.ConfigDefinitionKey)28 Test (org.junit.Test)15 File (java.io.File)7 UnparsedConfigDefinition (com.yahoo.config.application.api.UnparsedConfigDefinition)6 UserConfigRepo (com.yahoo.config.model.producer.UserConfigRepo)5 ConfigDefinition (com.yahoo.vespa.config.ConfigDefinition)5 BaseDeployLogger (com.yahoo.config.model.application.provider.BaseDeployLogger)4 JarFile (java.util.jar.JarFile)4 Element (org.w3c.dom.Element)4 DefParser (com.yahoo.config.codegen.DefParser)3 ConfigPayloadBuilder (com.yahoo.vespa.config.ConfigPayloadBuilder)3 ConfigDefinition (com.yahoo.vespa.config.buildergen.ConfigDefinition)3 LinkedHashMap (java.util.LinkedHashMap)3 ConfigInstance (com.yahoo.config.ConfigInstance)2 ApplicationFile (com.yahoo.config.application.api.ApplicationFile)2 ApplicationPackage (com.yahoo.config.application.api.ApplicationPackage)2 FilesApplicationPackage (com.yahoo.config.model.application.provider.FilesApplicationPackage)2 MockApplicationPackage (com.yahoo.config.model.test.MockApplicationPackage)2 GenericConfig (com.yahoo.vespa.config.GenericConfig)2 VespaModel (com.yahoo.vespa.model.VespaModel)2