Search in sources :

Example 11 with DefParser

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

the class ConfigFileFormatterTest method assertConfigFormat.

private void assertConfigFormat(Slime slime, String expected_simpletypes) throws IOException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    InnerCNode def = new DefParser("simpletypes", new StringReader(StringUtilities.implode(SimpletypesConfig.CONFIG_DEF_SCHEMA, "\n"))).getTree();
    new ConfigFileFormat(def).encode(baos, slime);
    assertThat(baos.toString(), is(expected_simpletypes));
}
Also used : InnerCNode(com.yahoo.config.codegen.InnerCNode) StringReader(java.io.StringReader) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DefParser(com.yahoo.config.codegen.DefParser)

Example 12 with DefParser

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

the class ConfigDefinition method generateClass.

public ConfigDefinitionClass generateClass() {
    File tempDir = Files.createTempDir();
    DefParser parser = new DefParser(name, new StringReader(StringUtilities.implode(defSchema, "\n")));
    JavaClassBuilder builder = new JavaClassBuilder(parser.getTree(), parser.getNormalizedDefinition(), tempDir, null);
    String className = builder.className();
    return new ConfigDefinitionClass(className, builder.javaPackage(), builder.getConfigClass(className));
}
Also used : StringReader(java.io.StringReader) JavaClassBuilder(com.yahoo.config.codegen.JavaClassBuilder) DefParser(com.yahoo.config.codegen.DefParser) File(java.io.File)

Example 13 with DefParser

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

the class DefaultValueApplierTest method apply.

public Slime apply(Slime slime, String... extraFields) {
    StringBuilder defBuilder = new StringBuilder();
    defBuilder.append("namespace=test").append("\n");
    defBuilder.append("str string").append("\n");
    for (String field : extraFields) {
        defBuilder.append(field).append("\n");
    }
    Cursor cursor = slime.get();
    cursor.setString("str", "myvalue");
    InnerCNode def = new DefParser("simpletypes", new StringReader(defBuilder.toString())).getTree();
    DefaultValueApplier applier = new DefaultValueApplier();
    return applier.applyDefaults(slime, def);
}
Also used : InnerCNode(com.yahoo.config.codegen.InnerCNode) StringReader(java.io.StringReader) DefParser(com.yahoo.config.codegen.DefParser) Cursor(com.yahoo.slime.Cursor)

Example 14 with DefParser

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

the class ZKApplicationPackage method getAllExistingConfigDefs.

@Override
public Map<ConfigDefinitionKey, UnparsedConfigDefinition> getAllExistingConfigDefs() {
    Map<ConfigDefinitionKey, UnparsedConfigDefinition> ret = new LinkedHashMap<>();
    List<String> allDefs = liveApp.getChildren(ConfigCurator.DEFCONFIGS_ZK_SUBPATH);
    for (final String nodeName : allDefs) {
        final ConfigDefinitionKey key = ConfigUtils.createConfigDefinitionKeyFromZKString(nodeName);
        ret.put(key, new UnparsedConfigDefinition() {

            @Override
            public ConfigDefinition parse() {
                DefParser parser = new DefParser(key.getName(), retrieveConfigDefReader(nodeName));
                return ConfigDefinitionBuilder.createConfigDefinition(parser.getTree());
            }

            @Override
            public String getUnparsedContent() {
                try {
                    return IOUtils.readAll(retrieveConfigDefReader(nodeName));
                } catch (Exception e) {
                    throw new RuntimeException("Error retriving def file", e);
                }
            }
        });
    }
    return ret;
}
Also used : UnparsedConfigDefinition(com.yahoo.config.application.api.UnparsedConfigDefinition) UnparsedConfigDefinition(com.yahoo.config.application.api.UnparsedConfigDefinition) ConfigDefinition(com.yahoo.vespa.config.ConfigDefinition) ConfigDefinitionKey(com.yahoo.vespa.config.ConfigDefinitionKey) DefParser(com.yahoo.config.codegen.DefParser) LinkedHashMap(java.util.LinkedHashMap)

Example 15 with DefParser

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

the class ConfigResponseFactoryTest method setup.

@Before
public void setup() {
    DefParser dParser = new DefParser(SimpletypesConfig.getDefName(), new StringReader(StringUtilities.implode(SimpletypesConfig.CONFIG_DEF_SCHEMA, "\n")));
    def = dParser.getTree();
}
Also used : StringReader(java.io.StringReader) DefParser(com.yahoo.config.codegen.DefParser) Before(org.junit.Before)

Aggregations

DefParser (com.yahoo.config.codegen.DefParser)28 StringReader (java.io.StringReader)24 InnerCNode (com.yahoo.config.codegen.InnerCNode)21 Test (org.junit.Test)20 ByteArrayOutputStream (java.io.ByteArrayOutputStream)17 Cursor (com.yahoo.slime.Cursor)15 Slime (com.yahoo.slime.Slime)14 Ignore (org.junit.Ignore)5 ConfigDefinition (com.yahoo.vespa.config.ConfigDefinition)3 ConfigDefinitionKey (com.yahoo.vespa.config.ConfigDefinitionKey)3 ConfigPayload (com.yahoo.vespa.config.ConfigPayload)3 SimpletypesConfig (com.yahoo.config.SimpletypesConfig)2 UnparsedConfigDefinition (com.yahoo.config.application.api.UnparsedConfigDefinition)2 SimpletypesConfig (com.yahoo.foo.SimpletypesConfig)2 File (java.io.File)2 ApplicationFile (com.yahoo.config.application.api.ApplicationFile)1 CNode (com.yahoo.config.codegen.CNode)1 JavaClassBuilder (com.yahoo.config.codegen.JavaClassBuilder)1 Utf8Array (com.yahoo.text.Utf8Array)1 ConfigPayloadBuilder (com.yahoo.vespa.config.ConfigPayloadBuilder)1