Search in sources :

Example 26 with DefParser

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

the class RpcServerTest method createResponse.

public ConfigResponse createResponse() {
    SimpletypesConfig.Builder builder = new SimpletypesConfig.Builder();
    builder.intval(123);
    SimpletypesConfig responseConfig = new SimpletypesConfig(builder);
    ConfigPayload responsePayload = ConfigPayload.fromInstance(responseConfig);
    InnerCNode targetDef = new DefParser(SimpletypesConfig.CONFIG_DEF_NAME, new StringReader(Joiner.on("\n").join(SimpletypesConfig.CONFIG_DEF_SCHEMA))).getTree();
    return SlimeConfigResponse.fromConfigPayload(responsePayload, targetDef, 3l, ConfigUtils.getMd5(responsePayload));
}
Also used : SimpletypesConfig(com.yahoo.config.SimpletypesConfig) InnerCNode(com.yahoo.config.codegen.InnerCNode) StringReader(java.io.StringReader) DefParser(com.yahoo.config.codegen.DefParser)

Example 27 with DefParser

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

the class FilesApplicationPackage method addAllDefsFromConfigDir.

private void addAllDefsFromConfigDir(Map<ConfigDefinitionKey, UnparsedConfigDefinition> defs, File configDefsDir) {
    if (!configDefsDir.isDirectory())
        return;
    log.log(LogLevel.DEBUG, "Getting all config definitions from '" + configDefsDir + "'");
    for (File def : configDefsDir.listFiles(new FilenameFilter() {

        @Override
        public boolean accept(File dir, String name) {
            // TODO: Fix
            return name.matches(".*\\.def");
        }
    })) {
        log.log(LogLevel.DEBUG, "Processing config definition '" + def + "'");
        String[] nv = def.getName().split("\\.def");
        ConfigDefinitionKey key;
        try {
            key = ConfigUtils.createConfigDefinitionKeyFromDefFile(def);
        } catch (IOException e) {
            // TODO: Fix
            e.printStackTrace();
            break;
        }
        if (key.getNamespace().isEmpty())
            throw new IllegalArgumentException("Config definition '" + def + "' has no namespace");
        if (defs.containsKey(key)) {
            if (nv[0].contains(".")) {
                log.log(LogLevel.INFO, "Two config definitions found for the same name and namespace: " + key + ". The file '" + def + "' will take precedence");
            } else {
                log.log(LogLevel.INFO, "Two config definitions found for the same name and namespace: " + key + ". Skipping '" + def + "', as it does not contain namespace in filename");
                // skip
                continue;
            }
        }
        defs.put(key, new UnparsedConfigDefinition() {

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

            @Override
            public String getUnparsedContent() {
                return readConfigDefinition(def);
            }
        });
    }
}
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) JarFile(java.util.jar.JarFile) ApplicationFile(com.yahoo.config.application.api.ApplicationFile)

Example 28 with DefParser

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

the class HttpConfigResponseTest method require_that_response_is_created_from_config.

@Test
public void require_that_response_is_created_from_config() throws IOException {
    final long generation = 1L;
    ConfigPayload payload = ConfigPayload.fromInstance(new SimpletypesConfig(new SimpletypesConfig.Builder()));
    // TODO: Hope to be able to remove this mess soon.
    DefParser dParser = new DefParser(SimpletypesConfig.getDefName(), new StringReader(StringUtilities.implode(SimpletypesConfig.CONFIG_DEF_SCHEMA, "\n")));
    InnerCNode targetDef = dParser.getTree();
    ConfigResponse configResponse = SlimeConfigResponse.fromConfigPayload(payload, targetDef, generation, "mymd5");
    HttpConfigResponse response = HttpConfigResponse.createFromConfig(configResponse);
    assertThat(SessionHandlerTest.getRenderedString(response), is("{\"boolval\":false,\"doubleval\":0.0,\"enumval\":\"VAL1\",\"intval\":0,\"longval\":0,\"stringval\":\"s\"}"));
}
Also used : SimpletypesConfig(com.yahoo.config.SimpletypesConfig) InnerCNode(com.yahoo.config.codegen.InnerCNode) ConfigPayload(com.yahoo.vespa.config.ConfigPayload) StringReader(java.io.StringReader) SlimeConfigResponse(com.yahoo.vespa.config.protocol.SlimeConfigResponse) ConfigResponse(com.yahoo.vespa.config.protocol.ConfigResponse) DefParser(com.yahoo.config.codegen.DefParser) Test(org.junit.Test)

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