use of com.yahoo.config.codegen.DefParser in project vespa by vespa-engine.
the class RpcServerTest method createResponse.
public ConfigResponse createResponse() {
SimpletypesConfig.Builder builder = new SimpletypesConfig.Builder();
builder.intval(123);
SimpletypesConfig responseConfig = new SimpletypesConfig(builder);
ConfigPayload responsePayload = ConfigPayload.fromInstance(responseConfig);
InnerCNode targetDef = new DefParser(SimpletypesConfig.CONFIG_DEF_NAME, new StringReader(Joiner.on("\n").join(SimpletypesConfig.CONFIG_DEF_SCHEMA))).getTree();
return SlimeConfigResponse.fromConfigPayload(responsePayload, targetDef, 3l, ConfigUtils.getMd5(responsePayload));
}
use of com.yahoo.config.codegen.DefParser 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.codegen.DefParser in project vespa by vespa-engine.
the class HttpConfigResponseTest method require_that_response_is_created_from_config.
@Test
public void require_that_response_is_created_from_config() throws IOException {
final long generation = 1L;
ConfigPayload payload = ConfigPayload.fromInstance(new SimpletypesConfig(new SimpletypesConfig.Builder()));
// TODO: Hope to be able to remove this mess soon.
DefParser dParser = new DefParser(SimpletypesConfig.getDefName(), new StringReader(StringUtilities.implode(SimpletypesConfig.CONFIG_DEF_SCHEMA, "\n")));
InnerCNode targetDef = dParser.getTree();
ConfigResponse configResponse = SlimeConfigResponse.fromConfigPayload(payload, targetDef, generation, "mymd5");
HttpConfigResponse response = HttpConfigResponse.createFromConfig(configResponse);
assertThat(SessionHandlerTest.getRenderedString(response), is("{\"boolval\":false,\"doubleval\":0.0,\"enumval\":\"VAL1\",\"intval\":0,\"longval\":0,\"stringval\":\"s\"}"));
}
Aggregations