Search in sources :

Example 1 with ConfigurationRuntimeException

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;
}
Also used : ConfigurationRuntimeException(com.yahoo.config.ConfigurationRuntimeException) ConfigInstance(com.yahoo.config.ConfigInstance)

Example 2 with ConfigurationRuntimeException

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;
}
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 3 with ConfigurationRuntimeException

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());
    }
}
Also used : ConfigurationRuntimeException(com.yahoo.config.ConfigurationRuntimeException) ConfigPayloadBuilder(com.yahoo.vespa.config.ConfigPayloadBuilder) ConfigInstance(com.yahoo.config.ConfigInstance)

Example 4 with ConfigurationRuntimeException

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);
    }
}
Also used : ConfigurationRuntimeException(com.yahoo.config.ConfigurationRuntimeException)

Example 5 with ConfigurationRuntimeException

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");
        }
    }
}
Also used : ConfigurationRuntimeException(com.yahoo.config.ConfigurationRuntimeException) Element(org.w3c.dom.Element)

Aggregations

ConfigurationRuntimeException (com.yahoo.config.ConfigurationRuntimeException)15 Element (org.w3c.dom.Element)3 ConfigInstance (com.yahoo.config.ConfigInstance)2 ConfigPayload (com.yahoo.vespa.config.ConfigPayload)2 ConfigPayloadBuilder (com.yahoo.vespa.config.ConfigPayloadBuilder)2 Test (org.junit.Test)2 LbServicesConfig (com.yahoo.cloud.config.LbServicesConfig)1 RoutingConfig (com.yahoo.cloud.config.RoutingConfig)1 ChainSpecification (com.yahoo.component.chain.model.ChainSpecification)1 ConfigBuilder (com.yahoo.config.ConfigBuilder)1 Builder (com.yahoo.config.ConfigInstance.Builder)1 CfgConfigPayloadBuilder (com.yahoo.config.subscription.CfgConfigPayloadBuilder)1 ConfigInterruptedException (com.yahoo.config.subscription.ConfigInterruptedException)1 com.yahoo.vespa.config (com.yahoo.vespa.config)1 ConfigCacheKey (com.yahoo.vespa.config.ConfigCacheKey)1 ConfigKey (com.yahoo.vespa.config.ConfigKey)1 GenericConfig (com.yahoo.vespa.config.GenericConfig)1 ConfigDefinition (com.yahoo.vespa.config.buildergen.ConfigDefinition)1 ConfigResponse (com.yahoo.vespa.config.protocol.ConfigResponse)1 UnknownConfigDefinitionException (com.yahoo.vespa.config.server.UnknownConfigDefinitionException)1