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