Search in sources :

Example 1 with ConfigBuilder

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

the class ConfigPayloadApplier method handleLeafValue.

private void handleLeafValue(Inspector value) {
    trace("String ");
    printStack();
    NamedBuilder peek = stack.peek();
    trace("popping name stack");
    String name = peek.nameStack().pop();
    printStack();
    ConfigBuilder builder = peek.builder();
    trace("name=" + name + ",builder=" + builder + ",value=" + value.toString());
    setValueForLeafNode(builder, name, value);
}
Also used : ConfigBuilder(com.yahoo.config.ConfigBuilder)

Example 2 with ConfigBuilder

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

the class ConfigInstanceUtil method getNewInstance.

public static <T extends ConfigInstance> T getNewInstance(Class<T> type, String configId, ConfigPayload payload) {
    T instance;
    try {
        ConfigTransformer<?> transformer = new ConfigTransformer<T>(type);
        ConfigBuilder instanceBuilder = transformer.toConfigBuilder(payload);
        Constructor<T> constructor = type.getConstructor(instanceBuilder.getClass());
        instance = constructor.newInstance((ConfigInstance.Builder) instanceBuilder);
        // Workaround for JDK7, where compilation fails due to fields being
        // private and not accessible from T. Reference it as a
        // ConfigInstance to work around it. See
        // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=7022052 for
        // more information.
        ConfigInstance i = instance;
        i.postInitialize(configId);
        setConfigId(i, configId);
    } catch (InstantiationException | InvocationTargetException | NoSuchMethodException | NoSuchFieldException | IllegalAccessException e) {
        throw new IllegalArgumentException("Failed creating new instance of '" + type.getCanonicalName() + "' for config id '" + configId + "': " + Exceptions.toMessageString(e), e);
    }
    return instance;
}
Also used : ConfigBuilder(com.yahoo.config.ConfigBuilder) InvocationTargetException(java.lang.reflect.InvocationTargetException) ConfigBuilder(com.yahoo.config.ConfigBuilder) ConfigInstance(com.yahoo.config.ConfigInstance)

Example 3 with ConfigBuilder

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

the class VespaModel method getConfig.

/**
 * Resolve config for a given key and config definition
 *
 * @param configKey The key to resolve.
 * @param targetDef The config definition to use for the schema
 * @return The payload as a list of strings
 */
@Override
public ConfigPayload getConfig(ConfigKey configKey, com.yahoo.vespa.config.buildergen.ConfigDefinition targetDef) {
    ConfigBuilder builder = InstanceResolver.resolveToBuilder(configKey, this, targetDef);
    if (builder != null) {
        log.log(LogLevel.DEBUG, () -> "Found builder for " + configKey);
        ConfigPayload payload;
        InnerCNode innerCNode = targetDef != null ? targetDef.getCNode() : null;
        if (builder instanceof GenericConfig.GenericConfigBuilder) {
            payload = getConfigFromGenericBuilder(builder);
        } else {
            payload = getConfigFromBuilder(configKey, builder, innerCNode);
        }
        return (innerCNode != null) ? payload.applyDefaultsFromDef(innerCNode) : payload;
    }
    return null;
}
Also used : InnerCNode(com.yahoo.config.codegen.InnerCNode) ConfigPayload(com.yahoo.vespa.config.ConfigPayload) ConfigBuilder(com.yahoo.config.ConfigBuilder)

Example 4 with ConfigBuilder

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

the class ConfigPayloadApplier method setMapLeafValue.

private void setMapLeafValue(String key, Object value) {
    NamedBuilder parent = stack.peek();
    ConfigBuilder builder = parent.builder();
    String methodName = parent.peekName();
    // trace("class to obtain method from: " + builder.getClass().getName());
    try {
        // Need to convert reference into actual path if 'path' type is used
        if (isPathField(builder, methodName)) {
            FileReference wrappedPath = resolvePath((String) value);
            invokeSetter(builder, methodName, key, wrappedPath);
        } else {
            invokeSetter(builder, methodName, key, value);
        }
    } catch (InvocationTargetException | IllegalAccessException e) {
        throw new RuntimeException("Name: " + methodName + ", value '" + value + "'", e);
    } catch (NoSuchMethodException e) {
        log.log(LogLevel.INFO, "Skipping unknown field " + methodName + " in " + rootBuilder);
    }
}
Also used : ConfigBuilder(com.yahoo.config.ConfigBuilder) FileReference(com.yahoo.config.FileReference) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

ConfigBuilder (com.yahoo.config.ConfigBuilder)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 ConfigInstance (com.yahoo.config.ConfigInstance)1 FileReference (com.yahoo.config.FileReference)1 InnerCNode (com.yahoo.config.codegen.InnerCNode)1 ConfigPayload (com.yahoo.vespa.config.ConfigPayload)1