Search in sources :

Example 1 with ConfigPayloadBuilder

use of com.yahoo.vespa.config.ConfigPayloadBuilder in project vespa by vespa-engine.

the class VespaModel method createBuilder.

public ConfigInstance.Builder createBuilder(ConfigDefinitionKey key, ConfigDefinition targetDef) {
    String className = createClassName(key.getName());
    Class<?> clazz;
    final String fullClassName = InstanceResolver.packageName(key) + "." + className;
    final String builderName = fullClassName + "$Builder";
    final String producerName = fullClassName + "$Producer";
    ClassLoader classLoader = getConfigClassLoader(producerName);
    if (classLoader == null) {
        classLoader = getClass().getClassLoader();
        if (logDebug()) {
            log.log(LogLevel.DEBUG, "No producer found to get classloader from for " + fullClassName + ". Using default");
        }
    }
    try {
        clazz = classLoader.loadClass(builderName);
    } catch (ClassNotFoundException e) {
        if (logDebug()) {
            log.log(LogLevel.DEBUG, "Tried to load " + builderName + ", not found, trying with generic builder");
        }
        // return compiler.compile(targetDef.generateClass()).newInstance();
        return new GenericConfig.GenericConfigBuilder(key, new ConfigPayloadBuilder());
    }
    Object i;
    try {
        i = clazz.newInstance();
    } catch (InstantiationException | IllegalAccessException e) {
        throw new ConfigurationRuntimeException(e);
    }
    if (!(i instanceof ConfigInstance.Builder)) {
        throw new ConfigurationRuntimeException(fullClassName + " is not a ConfigInstance.Builder, can not produce config for the name '" + key.getName() + "'.");
    }
    return (ConfigInstance.Builder) i;
}
Also used : ConfigurationRuntimeException(com.yahoo.config.ConfigurationRuntimeException) VespaDomBuilder(com.yahoo.vespa.model.builder.xml.dom.VespaDomBuilder) Builder(com.yahoo.config.ConfigInstance.Builder) ConfigPayloadBuilder(com.yahoo.vespa.config.ConfigPayloadBuilder) ConfigBuilder(com.yahoo.config.ConfigBuilder) VespaModelBuilder(com.yahoo.vespa.model.builder.VespaModelBuilder) GenericConfig(com.yahoo.vespa.config.GenericConfig) ConfigPayloadBuilder(com.yahoo.vespa.config.ConfigPayloadBuilder)

Example 2 with ConfigPayloadBuilder

use of com.yahoo.vespa.config.ConfigPayloadBuilder in project vespa by vespa-engine.

the class VespaModel method getConfigFromBuilder.

private ConfigPayload getConfigFromBuilder(ConfigKey configKey, ConfigBuilder builder, InnerCNode targetDef) {
    try {
        ConfigInstance instance = InstanceResolver.resolveToInstance(configKey, builder, targetDef);
        log.log(LogLevel.DEBUG, () -> "getConfigFromBuilder for " + configKey + ",instance=" + instance);
        return ConfigPayload.fromInstance(instance);
    } catch (ConfigurationRuntimeException e) {
        // This can happen in cases where services ask for config that no longer exist before they have been able
        // to reconfigure themselves. This happens for instance whenever jdisc reconfigures itself until
        // ticket 6599572 is fixed. When that happens, consider propagating a full error rather than empty payload
        // back to the client.
        log.log(LogLevel.INFO, "Error resolving instance for key '" + configKey + "', returning empty config: " + Exceptions.toMessageString(e));
        return ConfigPayload.fromBuilder(new ConfigPayloadBuilder());
    }
}
Also used : ConfigurationRuntimeException(com.yahoo.config.ConfigurationRuntimeException) ConfigPayloadBuilder(com.yahoo.vespa.config.ConfigPayloadBuilder) ConfigInstance(com.yahoo.config.ConfigInstance)

Example 3 with ConfigPayloadBuilder

use of com.yahoo.vespa.config.ConfigPayloadBuilder in project vespa by vespa-engine.

the class DomConfigPayloadBuilderTest method require_that_exceptions_are_issued.

@Test(expected = ConfigurationRuntimeException.class)
public void require_that_exceptions_are_issued() throws ParserConfigurationException, FileNotFoundException {
    Element configRoot = getDocument("<config name=\"simpletypes\">" + "<longval>invalid</longval>" + "</config>");
    DefParser defParser = new DefParser("simpletypes", new FileReader(new File("src/test/resources/configdefinitions/simpletypes.def")));
    ConfigDefinition def = ConfigDefinitionBuilder.createConfigDefinition(defParser.getTree());
    ConfigPayloadBuilder builder = new DomConfigPayloadBuilder(def).build(configRoot);
// assertThat(builder.warnings().size(), is(1));
}
Also used : Element(org.w3c.dom.Element) ConfigDefinition(com.yahoo.vespa.config.ConfigDefinition) DefParser(com.yahoo.config.codegen.DefParser) ConfigPayloadBuilder(com.yahoo.vespa.config.ConfigPayloadBuilder) Test(org.junit.Test)

Example 4 with ConfigPayloadBuilder

use of com.yahoo.vespa.config.ConfigPayloadBuilder in project vespa by vespa-engine.

the class VespaDomBuilderTest method testUserConfigsWithNamespace.

@Test
public void testUserConfigsWithNamespace() throws Exception {
    VespaModel model = createModel(hosts, servicesWithNamespace);
    GenericConfig.GenericConfigBuilder builder = new GenericConfig.GenericConfigBuilder(new ConfigDefinitionKey("testnamespace", "foo"), new ConfigPayloadBuilder());
    model.getConfig(builder, "admin");
    assertEquals(builder.getPayload().toString(), "{\n" + " \"basicStruct\": {\n" + "  \"stringVal\": \"default\"\n" + " }\n" + "}\n");
    model = createModel(hosts, servicesWithNamespace2);
    builder = new GenericConfig.GenericConfigBuilder(new ConfigDefinitionKey("testnamespace", "foo"), new ConfigPayloadBuilder());
    model.getConfig(builder, "admin");
    assertEquals(builder.getPayload().toString(), "{\n" + " \"basicStruct\": {\n" + "  \"stringVal\": \"default\"\n" + " }\n" + "}\n");
}
Also used : GenericConfig(com.yahoo.vespa.config.GenericConfig) VespaModel(com.yahoo.vespa.model.VespaModel) ConfigDefinitionKey(com.yahoo.vespa.config.ConfigDefinitionKey) ConfigPayloadBuilder(com.yahoo.vespa.config.ConfigPayloadBuilder) Test(org.junit.Test)

Example 5 with ConfigPayloadBuilder

use of com.yahoo.vespa.config.ConfigPayloadBuilder in project vespa by vespa-engine.

the class UserConfigBuilderTest method no_exception_when_config_class_does_not_exist.

@Test
public void no_exception_when_config_class_does_not_exist() throws ParserConfigurationException, IOException, SAXException {
    Element configRoot = getDocument("<config name=\"unknown\">" + "    <foo>1</foo>" + "</config>");
    UserConfigRepo repo = UserConfigBuilder.build(configRoot, configDefinitionStore, new BaseDeployLogger());
    ConfigPayloadBuilder builder = repo.get(new ConfigDefinitionKey("unknown", "config"));
    assertNotNull(builder);
}
Also used : UserConfigRepo(com.yahoo.config.model.producer.UserConfigRepo) BaseDeployLogger(com.yahoo.config.model.application.provider.BaseDeployLogger) Element(org.w3c.dom.Element) ConfigDefinitionKey(com.yahoo.vespa.config.ConfigDefinitionKey) ConfigPayloadBuilder(com.yahoo.vespa.config.ConfigPayloadBuilder) Test(org.junit.Test)

Aggregations

ConfigPayloadBuilder (com.yahoo.vespa.config.ConfigPayloadBuilder)8 Test (org.junit.Test)4 ConfigDefinitionKey (com.yahoo.vespa.config.ConfigDefinitionKey)3 GenericConfig (com.yahoo.vespa.config.GenericConfig)3 ConfigurationRuntimeException (com.yahoo.config.ConfigurationRuntimeException)2 VespaModel (com.yahoo.vespa.model.VespaModel)2 Element (org.w3c.dom.Element)2 ConfigBuilder (com.yahoo.config.ConfigBuilder)1 ConfigInstance (com.yahoo.config.ConfigInstance)1 Builder (com.yahoo.config.ConfigInstance.Builder)1 DefParser (com.yahoo.config.codegen.DefParser)1 BaseDeployLogger (com.yahoo.config.model.application.provider.BaseDeployLogger)1 DomBuilderTest (com.yahoo.config.model.builder.xml.test.DomBuilderTest)1 UserConfigRepo (com.yahoo.config.model.producer.UserConfigRepo)1 ConfigDefinition (com.yahoo.vespa.config.ConfigDefinition)1 VespaModelBuilder (com.yahoo.vespa.model.builder.VespaModelBuilder)1 VespaDomBuilder (com.yahoo.vespa.model.builder.xml.dom.VespaDomBuilder)1 VespaModelCreatorWithMockPkg (com.yahoo.vespa.model.test.utils.VespaModelCreatorWithMockPkg)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1