incubator-cassandra-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Heinrich Götzger <goetz...@web.de>
Subject creation of yaml-configuration from existing Config-object fails
Date Tue, 02 Apr 2013 18:47:41 GMT
Hello,

I try to read, edit, write and re-read a cassandra-yaml-config file 
programmatically, but this unfortunately does not work as expected:

Here is my example:

/* start */
package com.fue;

import java.io.*;

import org.apache.cassandra.config.*;
import org.apache.cassandra.utils.SkipNullRepresenter;
import org.yaml.snakeyaml.*;
import org.yaml.snakeyaml.DumperOptions.*;
import org.yaml.snakeyaml.constructor.*;
import org.yaml.snakeyaml.nodes.*;

public class YamlConfigTest {

    public static void main(String[] args) throws IOException {

       // 1. reading an existing config-file,
       InputStream input = new FileInputStream("/tmp/cassandra-1.2.3.yaml");

       Constructor constructor = new Constructor(Config.class);
       TypeDescription seedDesc = new 
TypeDescription(SeedProviderDef.class);
       seedDesc.putMapPropertyType("parameters", String.class, 
String.class);
       constructor.addTypeDescription(seedDesc);
       Yaml cassandraConfYaml = new Yaml(new Loader(constructor));

       Config conf = (Config) cassandraConfYaml.load(input);

       // 2. change the setting in the Config-object
       SeedProviderDef spd = conf.seed_provider;
       spd.parameters.put("seeds", "192.168.1.2");

       DumperOptions options = new DumperOptions();
       options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
       options.setDefaultScalarStyle(ScalarStyle.PLAIN);

       SkipNullRepresenter representer = new SkipNullRepresenter();
       representer.addClassTag(Config.class, Tag.MAP);

       Dumper dumper = new Dumper(representer, options);

       Yaml yamlWriter = new Yaml(new Loader(constructor), dumper);

       // 3. and writing it back to another file.
       String fileName = "/tmp/myCassandra.yaml";
       Writer output = new FileWriter(fileName);
       yamlWriter.dump(conf, output);

       Reader reader = new FileReader(fileName);

       Yaml myCassandraConfYaml = new Yaml(new Loader(constructor));

       // This procedure looses these two dashes and makes the 
configuration not
       // usable for further processing in other tasks.
       Config myConf = (Config) myCassandraConfYaml.load(reader);

    }
}
/* end */

And this is the output:

Exception in thread "main" Can't construct a java object for 
tag:yaml.org,2002:org.apache.cassandra.config.Config; exception=Cannot 
create property=seed_provider for 
JavaBean=org.apache.cassandra.config.Config@3c3ac93e; 
java.lang.NoSuchMethodException: 
org.apache.cassandra.config.SeedProviderDef.<init>()
  in 'reader', line 1, column 1:
     authenticator: org.apache.cassan ...
     ^

	at 
org.yaml.snakeyaml.constructor.Constructor$ConstructYamlObject.construct(Constructor.java:333)
	at 
org.yaml.snakeyaml.constructor.BaseConstructor.constructObject(BaseConstructor.java:182)
	at 
org.yaml.snakeyaml.constructor.BaseConstructor.constructDocument(BaseConstructor.java:141)
	at 
org.yaml.snakeyaml.constructor.BaseConstructor.getSingleData(BaseConstructor.java:127)
	at org.yaml.snakeyaml.Yaml.loadFromReader(Yaml.java:481)
	at org.yaml.snakeyaml.Yaml.load(Yaml.java:424)
	at com.fue.YamlConfigTest.main(YamlConfigTest.java:53)
Caused by: org.yaml.snakeyaml.error.YAMLException: Cannot create 
property=seed_provider for 
JavaBean=org.apache.cassandra.config.Config@3c3ac93e; 
java.lang.NoSuchMethodException: 
org.apache.cassandra.config.SeedProviderDef.<init>()
	at 
org.yaml.snakeyaml.constructor.Constructor$ConstructMapping.constructJavaBean2ndStep(Constructor.java:299)
	at 
org.yaml.snakeyaml.constructor.Constructor$ConstructMapping.construct(Constructor.java:189)
	at 
org.yaml.snakeyaml.constructor.Constructor$ConstructYamlObject.construct(Constructor.java:331)
	... 6 more
Caused by: org.yaml.snakeyaml.error.YAMLException: 
java.lang.NoSuchMethodException: 
org.apache.cassandra.config.SeedProviderDef.<init>()
	at 
org.yaml.snakeyaml.constructor.Constructor$ConstructMapping.createEmptyJavaBean(Constructor.java:219)
	at 
org.yaml.snakeyaml.constructor.Constructor$ConstructMapping.construct(Constructor.java:189)
	at 
org.yaml.snakeyaml.constructor.BaseConstructor.constructObject(BaseConstructor.java:182)
	at 
org.yaml.snakeyaml.constructor.Constructor$ConstructMapping.constructJavaBean2ndStep(Constructor.java:296)
	... 8 more
Caused by: java.lang.NoSuchMethodException: 
org.apache.cassandra.config.SeedProviderDef.<init>()
	at java.lang.Class.getConstructor0(Class.java:2715)
	at java.lang.Class.getDeclaredConstructor(Class.java:1987)
	at 
org.yaml.snakeyaml.constructor.Constructor$ConstructMapping.createEmptyJavaBean(Constructor.java:215)
	... 11 more

I'm using:
- snakeyaml-1.12
- cassandra-1.2.3

What am I doing wrong?
Is it a theme for cassandra or for yaml, is it in between or do I expect 
impossible things.


There is a thread about this in th SnakeYAML-group already:
https://groups.google.com/forum/?fromgroups=#!topic/snakeyaml-core/D4M0Ciy023E

Thanks for helping with some ideas.


Cheers

Heinrich

Mime
View raw message