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