use of com.yahoo.vespa.config.ConfigDefinitionKey in project vespa by vespa-engine.
the class ConfigUtilsTest method testCreateConfigDefinitionKeyFromDefFile.
@Test
public void testCreateConfigDefinitionKeyFromDefFile() {
ConfigDefinitionKey def = null;
try {
def = ConfigUtils.createConfigDefinitionKeyFromDefFile(new File("src/test/resources/configs/def-files/app.def"));
} catch (IOException e) {
e.printStackTrace();
fail();
}
assertThat(def.getName(), is("app"));
assertThat(def.getNamespace(), is("foo"));
try {
def = ConfigUtils.createConfigDefinitionKeyFromDefFile(new File("src/test/resources/configs/def-files/testnamespace.def"));
} catch (IOException e) {
e.printStackTrace();
fail();
}
assertThat(def.getName(), is("testnamespace"));
assertThat(def.getNamespace(), is("foo"));
try {
byte[] content = IOUtils.readFileBytes(new File("src/test/resources/configs/def-files/app.def"));
def = ConfigUtils.createConfigDefinitionKeyFromDefContent("app", content);
} catch (IOException e) {
fail();
}
assertThat(def.getName(), is("app"));
assertThat(def.getNamespace(), is("foo"));
try {
byte[] content = IOUtils.readFileBytes(new File("src/test/resources/configs/def-files-nogen/foo.bar.app.def"));
def = ConfigUtils.createConfigDefinitionKeyFromDefContent("app", content);
} catch (IOException e) {
fail();
}
assertThat(def.getName(), is("app"));
assertThat(def.getNamespace(), is("mynamespace"));
}
use of com.yahoo.vespa.config.ConfigDefinitionKey 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.vespa.config.ConfigDefinitionKey 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.ConfigDefinitionKey in project vespa by vespa-engine.
the class ContentBuilderTest method requireThatUserConfigCanBeSpecifiedForASearchDefinition.
@Test
public void requireThatUserConfigCanBeSpecifiedForASearchDefinition() throws Exception {
String services = getConfigOverrideServices("<node hostalias='mockhost' distribution-key='0'/>", " <config name='mynamespace.myconfig'>" + " <myfield>myvalue</myfield>" + " </config>");
VespaModel m = new VespaModelCreatorWithMockPkg(createAppWithMusic(getHosts(), services)).create();
String configId = "clu/search/cluster.clu/music";
{
GenericConfig.GenericConfigBuilder builder = new GenericConfig.GenericConfigBuilder(new ConfigDefinitionKey("myconfig", "mynamespace"), new ConfigPayloadBuilder());
m.getConfig(builder, configId);
assertEquals(builder.getPayload().getSlime().get().field("myfield").asString(), "myvalue");
}
}
use of com.yahoo.vespa.config.ConfigDefinitionKey in project vespa by vespa-engine.
the class ConfigBuilderGeneratorTest method require_that_custom_classes_can_be_generated.
@Test
public void require_that_custom_classes_can_be_generated() throws ClassNotFoundException, IllegalAccessException, InstantiationException, NoSuchMethodException, InvocationTargetException {
String[] schema = new String[] { "namespace=foo.bar", "intval int", "stringval string" };
File tempDir = Files.createTempDir();
ConfigDefinitionKey key = new ConfigDefinitionKey("quux", "foo.bar");
ConfigCompiler compiler = new LazyConfigCompiler(tempDir);
ConfigInstance.Builder builder = compiler.compile(new ConfigDefinition(key.getName(), schema).generateClass()).newInstance();
assertNotNull(builder);
ConfigPayloadApplier<?> payloadApplier = new ConfigPayloadApplier<>(builder);
Slime slime = new Slime();
Cursor root = slime.setObject();
root.setString("intval", "3");
root.setString("stringval", "Hello, world");
payloadApplier.applyPayload(new ConfigPayload(slime));
String className = createClassName(key.getName());
ConfigInstance instance = (ConfigInstance) builder.getClass().getClassLoader().loadClass("com.yahoo." + key.getNamespace() + "." + className).getConstructor(new Class<?>[] { builder.getClass() }).newInstance(builder);
assertNotNull(instance);
assertEquals("intval 3\nstringval \"Hello, world\"", instance.toString());
}
Aggregations