Update: snakeyaml deals with custom Java objects

Posted by Daniel Rauer Thu, 10 Dec 2009 23:55:00 GMT

Andrey, the owner of snakeyaml, has written a reply to our latest blogpost :
In record time he patched snakeyaml to be compliant with our example of a Ruby-generated yaml file. By defining some conversion directives like

addTypeDescription(new TypeDescription(Sub1.class, "!ruby/object:Test::Module::Sub1"));
to the parser and
addClassTag(Sub1.class, "!ruby/object:Test::Module::Sub1");
to the dumping emitter snakeyaml seems to be able to do the Ruby->Java transfer, and vice versa.

Thanks alot to Andrey, a great job in very short time!

yaml in Java and Ruby: Welcome yamlbeans!

Posted by Daniel Rauer Mon, 07 Dec 2009 13:26:00 GMT

During our hackathon at the North Sea Bernd and I were thinking about how to share objects between Java and Ruby. We had to decide between JSON and YAML, both very powerful, slim and well supported in both languages.
YAML has won the award, because there are no major differences between YAML and JSON, and Ruby offers excellent support for YAML.
So, the Ruby side was done, now we came to the Java part: Reading about Java and YAML you will always find the following libraries:
- JvYaml
- JYaml
- snakeyaml

To make a long story short: None of them work out of the box for our purposes, which is importing a Ruby generated YAML into JAVA, generating the Java beans and write back these beans as YAML our Ruby app can parse. Not a big deal, you might think.
The YAML file our Ruby code produces looks quite similar to this one:

--- !ruby/object:Test::Module::Object
  sub1: !ruby/object:Test::Module::Sub1
    subsub1s:
    - !ruby/object:Test::Module::Sub1::SubSub1
      att1: []
      att2: true
      att3: 11111
      att5:
    att1: []
    att2: 0
    att3: []
  sub2: !ruby/object:Test::Module::Sub2
    att1: MyString
    att2:
    - entry1
    att3: 12345
    subsub2: !ruby/object:Test::Module::Sub2::SubSub2
      att1: true
      att2: true



JvYaml was the first we tried: The code to generate the beans out of the YAML should be easy like that:

Module module = (Module)YAML.load(new FileReader("example.yml"));
Result:
java.lang.ClassCastException: org.jvyaml.PrivateType cannot be cast to net.bytemine.jvyaml.Module
To come to its defense: JvYaml is no longer supported, last version is from september 2006, and it is not documented :(



This was leading us to JYaml, also with a very slim api:

Module module = Yaml.loadType(new File("example.yml"), Module.class);
This produces an instance of the Module class, but none of its attributes or subclasses where instanciated. Also gambling around with the jyaml.yml config file did not work any better.
Result: JYaml is better maintained (last release in august 2007 ;) ), and much better documented than JvYaml. But still not working for us.



snakeyaml:

Config config = (Config)new Yaml().load(new FileInputStream(new File("example.yml"))); 
produces the following error:
Can't construct a java object for !ruby/object:Test::Module::Object; exception=Class not found: st::Module::Object
Because snakeyaml seems to have a syntactical problem with this YAML document we did no further investigations on snakeyaml. But: It is very well documented, at just yesterday somebody was committing something to the project. Perhaps snakeyaml will become more interesting by the time.



The solution:
Late at night I stumbled over a different project: yamlbeans. This library seemes to be highly flexible in its configuration and is documented in an excellent manor. So I gave it a try, and after some reading and testing I finally was able to extract our whole class hierarchy from the YAML. Even better: The exported YAML looked quite like the original. After patching three lines of code into the library we finally got the solution on how to exchange objects between both worlds.
This patch has been already applied to the newest version 1.0 by Nate, who is the maintainer and author of yamlbeans.

And finally here is the code doing the job for us:

YamlReader reader = new YamlReader(new FileReader("example.yml"));
reader.getConfig().setClassTag("ruby/object:Test::Module::Object", Module.class);
reader.getConfig().setClassTag("ruby/object:Test::Module::Sub1", Sub1.class);
...
Module module = reader.read(Module.class);

YamlWriter writer = new YamlWriter(new FileWriter("example-out.yml"));
// writes also false values
writer.getConfig().writeConfig.setWriteDefaultValues(true);
// writes root tag with prefix '--- '
writer.getConfig().writeConfig.setExplicitFirstDocument(true);
// writes out every unknown classname
writer.getConfig().writeConfig.setAlwaysWriteClassname(true);
writer.getConfig().setClassTag("ruby/object:Test::Module::Object", Module.class);
...
writer.write(module); 
writer.close();

Thanks again to Nate of the yamlbeans project, he did an excellent job!

Enjoying Rails Underground 2009 - Day 2

Posted by Bernd Ahlers Wed, 29 Jul 2009 15:29:00 GMT

Following Felix’s summary for day 1 of Rails Underground, here are my highlights of day 2.

The day started pretty early with Yehuda Katz’s keynote about Rails3 and interfaces in Ruby general. Really nice talk! Yehuda is working full-time on Rails and did some great refactoring for version 3. I’m looking forward to the new major release. video

For the next talk I decided to attend Ben Scofield’s presentation about Rack integration in Rails. Rack acts as the glue between webservers for Ruby and Ruby web frameworks. Ben showed how Rack works and lots of nice ways to work with it. (like some middleware projects) I will definately dig a bit deeper into Rack. Really nice! slide video

Pat Allan gave a nice talk about sharing your knowledge with other people or using your knowledge to help people. He gave some examples like giving guest lectures at universities (_Teach the stuff you’d like to have learned at the university._), organizing meetings in your local area or doing charity work in other countries. Pat himself did charity work in Cambodia for three months and helped local organizations with their websites. Awesome! slide video

There also was a Q&A panel with Obie Fernandez, Jim Weirich, Jonathan Siegel and David Heinemeier Hansson. Unfortunately David didn’t attend the conference personally but was only connected via video link. That was a bit weird and I didn’t really liked that. Not that many questions from the audience but some interesting discussions between the panel members.

Lindsay Holmwood talked about Behaviour driven monitoring with cucumber-nagios. This was really inspiring and is a cool way of doing regression tests for your websites. Thinking a bit further, this can not only be used for websites, but also to test other types of services, like asterisk (checking your dialplan, for example) or smtp sessions testing your mail addresses or mail routing. He also mentioned his own monitoring tool flapjack which he’s currently writing. I’ll give it a try soon!

It’s a bit sad that I missed Jim Weirich’s talk about object oriented programming stuff but I hope there will be slides and a video.

All in all, Rails Underground was a really nice conference. Thanks to the organizers, speakers and all people who made it happen.

We’ll come back next year!

Oh, I almost forgot that I won a Ruby In Practice book at the book-lottery. YAY! :)

Enjoying Rails Underground 2009 - Day 1

Posted by Felix Kronlage Sat, 25 Jul 2009 13:04:00 GMT

Rails Underground turned out to be a good conference to be at. While we do many conferences, it was my first Ruby / Rails conference and the first software development conference in quite a while. Apart from it being very well organized, the lectures and talks are very informative and held pretty well.

The first conference day started with a Keynote by Fred George. Fred George has been in IT for the last fourty years and throughout the keynote his experience regarding software engineering was clearly visible.

The plenary on JRuby, with the lead developer of JRuby Charles Nutter, was one of the highlights on the first day. Especially, since I originally come from the java world. Another nice talk was given by Obie Fernandez, the guy behind hashrocket. He talked on running a software development company practicing agile methods. I was more than delighted to notice, that a lot of the things he mentioned are part of our culture at bytemine.

The third talk that I really enjoyed on the first day, was on CouchDB. CouchDB is a distributed, fault-tolerant and schema-free document-oriented database accessible via a RESTful HTTP/JSON API. Highly interesting, something I will definitly will look at again in the future.

The evening was closed by a lightning talk session, which was very entertaining and again, very informative. As soon as I’ve talked to the various people involved and got their permission for publishing pictures of them, we will post a few pictures here as well.

I will poke Bernd to cover the second day. Since for him, being our main ruby and rails head, there were lot’s of interesting talks as well.

Rails Underground 2009 - London

Posted by Bernd Ahlers Thu, 23 Jul 2009 07:53:00 GMT

Felix and I are currently sitting on the Hamburg airport waiting for our plane to London. We’re visiting the Rails Underground 2009 conference which has lots of nice talks about Ruby On Rails and Ruby in general.

So if you’re in London as well or even visiting the conference, drop us a comment or email. We’re looking forward to meet you there! :)

Redmine Pureftpd User Plugin

Posted by Bernd Ahlers Tue, 26 May 2009 19:34:00 GMT

We just released our first Redmine plugin on Github.

This plugin maintains a separate table for PureFTPD users. We need this because PureFTPD cannot handle the SHA1 passwords used by Redmine.

The plugin is really easy to install and use. Just run script/plugin install as documented in the README file and you’re done. Now every time a new user gets created or a user changes his password the plugin takes care of syncing the PureFTPD users table.

Please let us know if you like the plugin, if it’s useful to you and if there are any problems.

Github url: git://github.com/bytemine/redmine_pureftpd_user.git

Rails and Rubies - powered by bytemine

Posted by Bernd Ahlers Wed, 28 Jan 2009 09:27:00 GMT

What’s a serious mine without some rails and rubies?

Since the beginning of 2009 bytemine is offering hosting services for Ruby on Rails and other Ruby based web application frameworks. So if you’re looking for a new home for your awesome Ruby based web application, you just found one.

Our portfolio includes (but is most certainly not limited to) shared hosting, VPS based hosting or hosting on bare metal. Of course we will satisfy special requirements and/or wishes from your side, no matter whether it are small configuration changes or large-scale code changes (for which you can book our ruby developers! ;)

Building blocks

We are using the following powerful components to drive your applications.

  • Xen & CentOS
  • Ruby Enterprise Edition
  • Apache & Passenger

Xen & CentOS

The shared hosting and VPS hosting options are powered by the CentOS operating system and the Xen hypervisor. This allows us to scale shared hosting virtual machines easily and deploy new VPS within minutes.

Ruby Enterprise Edition

Ruby Enterprise Edition is a modified Ruby interpreter which has been built to reduce the memory usage and improve the speed of Ruby applications. It’s a drop-in replacement for the regular Ruby 1.8 runtime so you don’t have to do any modifications on new or existing applications. Ruby Enterprise Edition is developed and released as an open source product by the smart guys at Phusion.

Apache & Passenger

The well known Apache web server combined with another great open source product of Phusion named Phusion Passenger (aka. mod_rails/mod_rack) is on its way to become the de-facto standard of running and deploying Ruby based web applications. Deploying a web application on Passenger is just a matter of uploading the application files via FTP. No special configuration steps required. Passenger is managing the needed Ruby background processes tranparently by quitting and spawning them as needed.

This blog is running on Apache and Phusion Passenger, of course. :)

We can also offer you other deployment platforms – like the popular nginx & mongrel couple – if needed.

Support

This infrastructure is driven by our skilled unix and Ruby guys who will happily answer your questions and solve any problems that may arise.

Questions

Don’t hesitate to contact us if you have any questions or if you would like to use some of our services.