Search in sources :

Example 11 with ConfigDefinitionKey

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"));
}
Also used : ConfigDefinitionKey(com.yahoo.vespa.config.ConfigDefinitionKey) IOException(java.io.IOException) File(java.io.File) Test(org.junit.Test)

Example 12 with ConfigDefinitionKey

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");
}
Also used : UnparsedConfigDefinition(com.yahoo.config.application.api.UnparsedConfigDefinition) ConfigDefinitionKey(com.yahoo.vespa.config.ConfigDefinitionKey) Map(java.util.Map)

Example 13 with ConfigDefinitionKey

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;
}
Also used : UnparsedConfigDefinition(com.yahoo.config.application.api.UnparsedConfigDefinition) UnparsedConfigDefinition(com.yahoo.config.application.api.UnparsedConfigDefinition) ConfigDefinition(com.yahoo.vespa.config.ConfigDefinition) ConfigDefinitionKey(com.yahoo.vespa.config.ConfigDefinitionKey) DefParser(com.yahoo.config.codegen.DefParser) LinkedHashMap(java.util.LinkedHashMap)

Example 14 with ConfigDefinitionKey

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");
    }
}
Also used : VespaModelCreatorWithMockPkg(com.yahoo.vespa.model.test.utils.VespaModelCreatorWithMockPkg) GenericConfig(com.yahoo.vespa.config.GenericConfig) VespaModel(com.yahoo.vespa.model.VespaModel) ConfigDefinitionKey(com.yahoo.vespa.config.ConfigDefinitionKey) Matchers.containsString(org.hamcrest.Matchers.containsString) ConfigPayloadBuilder(com.yahoo.vespa.config.ConfigPayloadBuilder) Test(org.junit.Test) DomBuilderTest(com.yahoo.config.model.builder.xml.test.DomBuilderTest)

Example 15 with ConfigDefinitionKey

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());
}
Also used : ConfigDefinitionKey(com.yahoo.vespa.config.ConfigDefinitionKey) Slime(com.yahoo.slime.Slime) Cursor(com.yahoo.slime.Cursor) ConfigPayload(com.yahoo.vespa.config.ConfigPayload) ConfigPayloadApplier(com.yahoo.vespa.config.ConfigPayloadApplier) File(java.io.File) ConfigInstance(com.yahoo.config.ConfigInstance) Test(org.junit.Test)

Aggregations

ConfigDefinitionKey (com.yahoo.vespa.config.ConfigDefinitionKey)28 Test (org.junit.Test)15 File (java.io.File)7 UnparsedConfigDefinition (com.yahoo.config.application.api.UnparsedConfigDefinition)6 UserConfigRepo (com.yahoo.config.model.producer.UserConfigRepo)5 ConfigDefinition (com.yahoo.vespa.config.ConfigDefinition)5 BaseDeployLogger (com.yahoo.config.model.application.provider.BaseDeployLogger)4 JarFile (java.util.jar.JarFile)4 Element (org.w3c.dom.Element)4 DefParser (com.yahoo.config.codegen.DefParser)3 ConfigPayloadBuilder (com.yahoo.vespa.config.ConfigPayloadBuilder)3 ConfigDefinition (com.yahoo.vespa.config.buildergen.ConfigDefinition)3 LinkedHashMap (java.util.LinkedHashMap)3 ConfigInstance (com.yahoo.config.ConfigInstance)2 ApplicationFile (com.yahoo.config.application.api.ApplicationFile)2 ApplicationPackage (com.yahoo.config.application.api.ApplicationPackage)2 FilesApplicationPackage (com.yahoo.config.model.application.provider.FilesApplicationPackage)2 MockApplicationPackage (com.yahoo.config.model.test.MockApplicationPackage)2 GenericConfig (com.yahoo.vespa.config.GenericConfig)2 VespaModel (com.yahoo.vespa.model.VespaModel)2