use of com.yahoo.config.ConfigurationRuntimeException in project vespa by vespa-engine.
the class InstanceResolver method getConfigClass.
/**
* Returns a {@link ConfigInstance} of right type for given key using reflection
*
* @param cKey a ConfigKey
* @return a {@link ConfigInstance} or null if not available in classpath
*/
@SuppressWarnings("unchecked")
private static Class<? extends ConfigInstance> getConfigClass(ConfigDefinitionKey cKey, ClassLoader instanceLoader) {
String className = createClassName(cKey.getName());
String fullClassName = packageName(cKey) + "." + className;
Class<?> clazz;
try {
clazz = instanceLoader != null ? instanceLoader.loadClass(fullClassName) : Class.forName(fullClassName);
} catch (ClassNotFoundException e) {
throw new ConfigurationRuntimeException("Could not find config class for key " + cKey, e);
}
if (!ConfigInstance.class.isAssignableFrom(clazz)) {
throw new ConfigurationRuntimeException(fullClassName + " is not a ConfigInstance subclass, can not produce config for " + cKey);
}
return (Class<? extends ConfigInstance>) clazz;
}
use of com.yahoo.config.ConfigurationRuntimeException 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.config.ConfigurationRuntimeException 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.config.ConfigurationRuntimeException in project vespa by vespa-engine.
the class DomConfigPayloadBuilder method parseLeaf.
/**
* Parse leaf value in an xml tree
*/
private void parseLeaf(Element element, ConfigPayloadBuilder payloadBuilder, String parentName) {
String name = extractName(element);
String value = XML.getValue(element);
if (value == null) {
throw new ConfigurationRuntimeException("Element '" + name + "' must have either children or a value");
}
if (element.hasAttribute("index")) {
// Check for legacy (pre Vespa 6) usage
throw new IllegalArgumentException("The 'index' attribute on config elements is not supported - use <item>");
} else if (element.hasAttribute("operation")) {
// leaf array, currently the only supported operation is 'append'
verifyLegalOperation(element);
ConfigPayloadBuilder.Array a = payloadBuilder.getArray(name);
a.append(value);
} else if ("item".equals(name)) {
if (parentName == null)
throw new ConfigurationRuntimeException("<item> is a reserved keyword for array and map elements");
if (element.hasAttribute("key")) {
payloadBuilder.getMap(parentName).put(element.getAttribute("key"), value);
} else {
payloadBuilder.getArray(parentName).append(value);
}
} else {
// leaf scalar, e.g. <intVal>3</intVal>
payloadBuilder.setField(name, value);
}
}
use of com.yahoo.config.ConfigurationRuntimeException in project vespa by vespa-engine.
the class DomConfigPayloadBuilder method parseComplex.
private void parseComplex(Element element, List<Element> children, ConfigPayloadBuilder payloadBuilder, String parentName) {
String name = extractName(element);
// Inner value
if (element.hasAttribute("index")) {
// Check for legacy (pre Vespa 6) usage
throw new IllegalArgumentException("The 'index' attribute on config elements is not supported - use <item>");
} else if (element.hasAttribute("operation")) {
// inner array, currently the only supported operation is 'append'
verifyLegalOperation(element);
ConfigPayloadBuilder childPayloadBuilder = payloadBuilder.getArray(name).append();
// Cursor array = node.setArray(name);
for (Element child : children) {
// Cursor struct = array.addObject();
parseElement(child, childPayloadBuilder, name);
}
} else if ("item".equals(name)) {
// Reserved item means array/map element as struct
if (element.hasAttribute("key")) {
ConfigPayloadBuilder childPayloadBuilder = payloadBuilder.getMap(parentName).get(element.getAttribute("key"));
for (Element child : children) {
parseElement(child, childPayloadBuilder, parentName);
}
} else {
ConfigPayloadBuilder.Array array = payloadBuilder.getArray(parentName);
ConfigPayloadBuilder childPayloadBuilder = array.append();
for (Element child : children) {
parseElement(child, childPayloadBuilder, parentName);
}
}
} else {
int numMatching = 0;
for (Element child : children) {
numMatching += ("item".equals(child.getTagName())) ? 1 : 0;
}
if (numMatching == 0) {
// struct, e.g. <basicStruct>
ConfigPayloadBuilder p = payloadBuilder.getObject(name);
// Cursor struct = node.setObject(name);
for (Element child : children) parseElement(child, p, name);
} else if (numMatching == children.size()) {
// Array with <item elements>
for (Element child : children) {
parseElement(child, payloadBuilder, name);
}
} else {
throw new ConfigurationRuntimeException("<item> is a reserved keyword for array and map elements");
}
}
}
Aggregations