Search in sources :

Example 1 with ConfigDefinition

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

the class DomConfigPayloadBuilderTest method require_that_exceptions_are_issued.

@Test(expected = ConfigurationRuntimeException.class)
public void require_that_exceptions_are_issued() throws ParserConfigurationException, FileNotFoundException {
    Element configRoot = getDocument("<config name=\"simpletypes\">" + "<longval>invalid</longval>" + "</config>");
    DefParser defParser = new DefParser("simpletypes", new FileReader(new File("src/test/resources/configdefinitions/simpletypes.def")));
    ConfigDefinition def = ConfigDefinitionBuilder.createConfigDefinition(defParser.getTree());
    ConfigPayloadBuilder builder = new DomConfigPayloadBuilder(def).build(configRoot);
// assertThat(builder.warnings().size(), is(1));
}
Also used : Element(org.w3c.dom.Element) ConfigDefinition(com.yahoo.vespa.config.ConfigDefinition) DefParser(com.yahoo.config.codegen.DefParser) ConfigPayloadBuilder(com.yahoo.vespa.config.ConfigPayloadBuilder) Test(org.junit.Test)

Example 2 with ConfigDefinition

use of com.yahoo.vespa.config.ConfigDefinition 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 ConfigDefinition

use of com.yahoo.vespa.config.ConfigDefinition 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 ConfigDefinition

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

the class DeployState method getConfigDefinition.

@Override
public final Optional<ConfigDefinition> getConfigDefinition(ConfigDefinitionKey defKey) {
    if (existingConfigDefs == null) {
        existingConfigDefs = new LinkedHashMap<>();
        if (configDefinitionRepo.isPresent()) {
            existingConfigDefs.putAll(createLazyMapping(configDefinitionRepo.get()));
        }
        existingConfigDefs.putAll(applicationPackage.getAllExistingConfigDefs());
    }
    if (!existingConfigDefs.containsKey(defKey))
        return Optional.empty();
    if (defArchive.get(defKey) != null)
        return Optional.of(defArchive.get(defKey));
    ConfigDefinition def = existingConfigDefs.get(defKey).parse();
    defArchive.put(defKey, def);
    return Optional.of(def);
}
Also used : UnparsedConfigDefinition(com.yahoo.config.application.api.UnparsedConfigDefinition) ConfigDefinition(com.yahoo.vespa.config.ConfigDefinition)

Example 5 with ConfigDefinition

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

the class DeployStateTest method testGetConfigDefinition.

@Test
public void testGetConfigDefinition() {
    Map<ConfigDefinitionKey, com.yahoo.vespa.config.buildergen.ConfigDefinition> defs = new LinkedHashMap<>();
    defs.put(new ConfigDefinitionKey("test2", "a.b"), new com.yahoo.vespa.config.buildergen.ConfigDefinition("test2", new String[] { "namespace=a.b", "doubleVal double default=1.0" }));
    // defs.put(new ConfigDefinitionKey("test2", "c.d"), new com.yahoo.vespa.config.buildergen.ConfigDefinition("test2", new String[]{"namespace=c.d", "doubleVal double default=1.0"}));
    defs.put(new ConfigDefinitionKey("test3", "xyzzy"), new com.yahoo.vespa.config.buildergen.ConfigDefinition("test3", new String[] { "namespace=xyzzy", "message string" }));
    ApplicationPackage app = FilesApplicationPackage.fromFile(new File("src/test/cfg//application/app1"));
    DeployState state = createDeployState(app, defs);
    assertNotNull(state.getConfigDefinition(new ConfigDefinitionKey("test2", "a.b")));
    ConfigDefinition test1 = state.getConfigDefinition(new ConfigDefinitionKey("test2", "a.b")).get();
    assertNotNull(test1);
    assertThat(test1.getName(), is("test2"));
    assertThat(test1.getNamespace(), is("a.b"));
}
Also used : ConfigDefinitionKey(com.yahoo.vespa.config.ConfigDefinitionKey) ApplicationPackage(com.yahoo.config.application.api.ApplicationPackage) MockApplicationPackage(com.yahoo.config.model.test.MockApplicationPackage) FilesApplicationPackage(com.yahoo.config.model.application.provider.FilesApplicationPackage) LinkedHashMap(java.util.LinkedHashMap) ConfigDefinition(com.yahoo.vespa.config.ConfigDefinition) File(java.io.File) Test(org.junit.Test)

Aggregations

ConfigDefinition (com.yahoo.vespa.config.ConfigDefinition)7 ConfigDefinitionKey (com.yahoo.vespa.config.ConfigDefinitionKey)5 UnparsedConfigDefinition (com.yahoo.config.application.api.UnparsedConfigDefinition)4 Test (org.junit.Test)4 DefParser (com.yahoo.config.codegen.DefParser)3 File (java.io.File)3 LinkedHashMap (java.util.LinkedHashMap)3 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 JarFile (java.util.jar.JarFile)2 ApplicationFile (com.yahoo.config.application.api.ApplicationFile)1 DeployState (com.yahoo.config.model.deploy.DeployState)1 ConfigPayloadBuilder (com.yahoo.vespa.config.ConfigPayloadBuilder)1 Element (org.w3c.dom.Element)1