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