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));
}
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;
}
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);
}
});
}
}
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);
}
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"));
}
Aggregations