Archive for the 'geek stuff' Category

01
Mar
10

Rest, I dont think I get it

I sent this as an internal email.. but figured I would post the question as well. File this into the “I dont get it” category. Not as bad as Google Wave, but close.

So.. I hear that Rest is a panacea, but mostly because it is “Rest not SOAP”. I actually understand many of the benefits that REST is gives you:

1) I can use a simple http client to access resources, therefore it is easier to adopt.
2) I inherit alot of the WS-* enhancements from the underlieing http transport, so the frameworks are lighter weight.
3) The ability to use the service both by a client and a browser.. mashups become easy.

What I keep getting hung up on is the absence of a formal description of the interface. I see WADL, but whenever I dig into this it seems to get brushed aside as a nuisance. If i want to write typed clients, then I need to have some formal contract of what can be passed in and what is returned. This contract seems to be what alot of the cruft around SOAP is for. Is there something I am missing with this? The answer the books/articles seem to give is “who needs a formal spec, it is all URI’s”. This tends to be a load of hooey, since some clients (rails in particular) do not handle nicely objects of the same type with heterogeneous data sets.

So.. it seems like Rest (which is not SOAP) makes it easy for the easy clients by skimping on the tools for the more complex clients. I can easily do jersey -> jersey, and I presume Resteasy -> Resteasy. But w/o that neutral definition.. cross implementation clients (robust ones) are actually harder.

Am I missing something?

02
Feb
10

Latest RHQ Build:l 3.0.0 Build 2

The second community build for RHQ has landed. You can download it from http://rhq-project.org/display/RHQ/Download and check out the release notes at http://rhq-project.org/display/RHQ/Release+Notes+3.0.0.B02. There is lots of goodness here including better content management, better alerting, and other stuff you will have to play with to see. Come on bye, and check it out. Better yet… contributions are welcome.

22
Dec
09

Cobbler Settings Lens for Augeas

After much help from David Lutterkort, I have a first cut of an Augeas lens for Cobbler . The settings file is basically a single YAML document, so this lens could be used to do generic yaml processing, but I would assume it would need some tweaks before then.

I figure it is best to get the first cut out there though. So here it is.

(*
	Parse the /etc/cobbler/settings file  which is in
	YAML 1.0 format.

	The lens can handle the following contructs
	* key: value
	* key: "value"
	* key: 'value'
	* key: [value1, value2]
	* key:
	   - value1
	   - value2
	* key:
	   key2: value1
	   key3: value2 

	Author: Bryan Kearney

	About: License
	  This file is licensed under the LGPLv2+, like the rest of Augeas.
*)
module CobblerSettings =
	autoload xfm

	let kw = /[a-zA-Z0-9_]+/
	(* TODO Would be better if this stripped off the " and ' chracters *)
	let kv = /([^]['", \t\n#:@-]+|"[^"\n]*"|'[^'\n]*')/ 

	let lbr = del /\[/ "["
	let rbr = del /\]/ "]"
	let colon = del /:[ \t]*/ ": "
	let dash = del /-[ \t]*/ "- "
	(* let comma = del /,[ \t]*(\n[ \t]+)?/ ", " *)
	let comma = del /[ \t]*,[ \t]*/ ", "

	let eol_only = del /\n/ "\n"

	(* TODO Would be better to make items a child of a document *)
	let docmarker = /-{3}/

	let eol   = Util.eol
	let comment = Util.comment
	let empty   = Util.empty
	let indent = del /[ \t]+/ "\t"
	let ws = del /[ \t]*/ " "

	let value_list = Build.opt_list [label "item" . store kv] comma
	let setting = [key kw . colon . store kv] . eol
	let simple_setting_suffix = store kv . eol
	let setting_list_suffix =  [label "sequence" . lbr . ws . (value_list . ws)? . rbr ] . eol
	let indendented_setting_list_suffix =  eol_only . (indent . setting)+
    let indented_list_suffix =  [label "list" . eol_only . ([ label "value" . indent . dash  . store kv] . eol)+]

    (* Break out setting because of a current bug in augeas *)
	let nested_setting = [key kw . colon . (
											(* simple_setting_suffix | *)
											setting_list_suffix |
											indendented_setting_list_suffix |
											indented_list_suffix
											)
						]

	let document = [label "---" . store docmarker] . eol    

	let lns = (document | comment | empty | setting | nested_setting )*
    (* let lns = (setting)* *)

	let xfm = transform lns (incl "/etc/cobbler/settings") 

	(*
	test lns  get "" = ?
	test lns  get "Simple_Setting: Value \n" = ?
	test lns  get "Simple_Setting2: 'Value2@acme.com' \n" = ?
	test lns  get "Simple_Setting3: ''\n" = ?
	test lns  get "Simple_Setting4: \"\"\n" = ?
	test lns  get "Setting_List:[Value1, Value2, Value3]\n" = ?
	test lns  get "Empty_Setting_List: []\n" = ?
	test lns  get "# Commented_Out_Setting: 'some value'\n" = ?
	test lns  get "---\n" = ?
	test lns  get "Nested_Setting:\n Test: Value\n" = ?
	test lns  get "Nested_Setting:\n - Test \n" = ?
	let  cset = Sys.read_file "/etc/cobbler/settings"
	test lns  get cset = ?
    *)
(* Local Variables: *)
(* mode: caml *)
(* End: *)

My next steps will be to clean this up, and to submit it along with some tests.

11
Dec
09

RHQ Build 1.4.0.B01

My new project at work put out it’s latest open source release. You can learn about it in this here If folks are looking to contribute to a very successful open source Java management project I suggest coming over and taking a look.

27
Aug
09

Stupid Error Messages

On Fedora 11, If you get this error message:


gconf-sanity-check-2 exit status 256

When you log in. Check that your /tmp file is not write protected. If it is write protected, or the disk is full, you will get this error. Save yourself a few hours of installing/unintsalling and check the /tmp directory.

09
Jul
09

Speeding up git-svn for several users

Git-svn is a wonderful tool if you need to access an svn repo. Reading the docs, it discusses how slow the initial clone is and that you should do one clone, check it into git, and have others clone from you. I tried this, doing the following:


$ git svn clone svn://some/project
$ git push git+ssh://mygit.repo

All was good. I then attempted to clone this, and I saw the following:


$ git clone git+ssh://mygit.repo
$ git svn init svn://some/project
$ git svn rebase
Unable to determine upstream SVN information from working tree history

And worse then this, if I did a git-svn fetch it pulled down the entire repo again (4 hours). I am trying to find where in the code the issue is, but here is the workaroung. You need to add one file into the .git repo which points to the current commit’s hash.


# clone the git repo
$ git clone git+ssh://mygit.repo

# Attach it to the svn repo:
$ git svn init svn://some/project

# get the latest commit hash
$ cd mygit.repo
$ git log

# The latest hash will bet the first thing you see (commit [HASH])
# Copy it, and add it as a single line to the git-svn file
$ vi .git/refs/remotes/git-svn

# Now you can fetch the latest from subversion, and begin working
$ git svn fetch
$ git svn rebase 
07
Jul
09

QMF#4: Ruby accessing EJBs running in JBoss

This is the latest in a series of posts on using qmf consoles in various languages to connect to EJBs running in a JBoss 5 container. There hass been python, C#, and Java. Now, lets add ruby to the list. Steps for building and deploy the Java agent can be found in the Java article. I will assume you have a running agent, a running broker, the latest qpid code, and would like to use the rby console now.

The current ruby console uses some native ruby extensions, so you first need to build those. Make sure you have ruby and rake installed


cd qpid/qpid/ruby/
rake build
export RUBYLIB=[QPID_SOURCE_LOCATION]/qpid/ruby/lib:[QPID_SOURCE_LOCATION]/qpid/qpid/ruby/ext/sasl/ 

Assuming you have the latest version of the git example code cloned from github, you can now run the following:


cd qmfExample/rubyConsole
ruby qmfExample.rb

You will see the same method calls, and XML Schema generated as from the earlier languages. A very easy way to expose your java code to many different languages.

26
Jun
09

QMF # 3: Java to Java over QMF

Here is the next post in the series. Java to Java over QMF. Granted, this is a pretty dumb way to actually connect to an EJB.. since Java provides many ways to do it natively. But, it does show a different console technology accessing the same backend. As before, you can read up on QMF and then build these examples. I will republish the directions from the earlier post to limit the number of times you need to scroll down.

To get started, you will need the gcc tools, ant, and jboss5 installed. Next.. get the code:


# Get the latest QPID Code
svn co http://svn.apache.org/repos/asf/qpid/trunk
# Get my example Code:
git clone git://github.com/bkearney/qmfExample.git

Build the latest qpidd broker and java code


cd trunk/qpid/cpp
./bootstrap
./configure --prefix ~/qpidlocal
make install
cp ../java
ant

Once this is done, you should be able to launch the most current qpidd


export LD_LIBRARY_PATH=~/qpidlocal/lib
~/qpidlocal/sbin/qpidd

Now…. build the java agent which has the EJB we are going to expose


cd ~/qmfExample/javaAgent
# Edit the build.properties file to point to your local
# installation
ant install

Now that we have that… we will build the Java Console to talk to the agent. As with the C# console earlier, the Java example code has 2 versions. One is using the raw QMF Session interface, and is the most similar to the python code. This is located in the qmfExample/javaConsole/generic directory. The second has some classes which were generated off of the example schema. This code is located in qmfExample/javaConsole/generated. The same logic can be used to generate either one.


cd qmfExample/javaConsole/generic
# edit your build.properties and set the property qpid.home and jboss.home
ant build
ant run

VIOLA! You see the EJB being accessed, and the schema being created. This is the third technology to access the example… next week.. ruby.

19
Jun
09

Now.. C# to EJB over QMF

This is a follow up to the earlier post about accessing EJBs from python.. In this post, we will build the CSharp Console and use that to access the EJBs which are running on JBoss. This code was built and tested using Mono on Fedora 10. My hope is that someone can test out the console in a windows proper environment. CSharp to dotnet is pretty hard with all but the most vanilla WS technologies. This post shows how the Qpid Management Framework can bridge that gap.

First.. follow the directions from the earlier post to check out the latest qpid code from apache, and the latest qmf example code from github. I will assume you have the broker running, and that you have tested the python client to see that it is working.

Now, lets build the dotnet qpid code. You will need ant, mono, and nant installed.


cd qpid/qpid/dotnet/client-010
# Read the README.txt file if things go wrong
cd gentool
ant
cd ..
nant

If you are getting a nansty nunit error, do the following before running nant:


export MONO_PATH=/usr/lib/mono/nunit22/

Now, we will build the test code which will use the console to access the Java Server. The example code has 2 versions. One is using the raw QMF Session interface, and is the most similar to the python code. This is located in the qmfExample/cSharpConsole/generic directory. The second has some classes which were generated off of the example schema. This code is located in qmfExample/cSharpConsole/generic. The same logic can be used to generate either one.


cd qmfExample/cSharpConsole/generic
# edit your default.build and set the property qpid.dir
nant
# it is now built, lets run it
export MONO_PATH=$MONO_PATH:[QPID_DIR]/qpid/qpid/dotnet/client-010/bin/mono-2.0/debug/
mono ./bin/QmfExample.exe

And.. Bobs your uncle. Now we have 2 technologies (python and C#) which are historically not friendly to Java, accessing EJBs running on Jboss.

12
Jun
09

Accessing JBoss Session beans from python using QMF

My current project is looking at how to expose Enterprise Java Beans to other technologies. I am most concerned with C#, but any other languages would be cool. We looked at the WS-* standards (and CXF which is a great tool) but the different versions across the vendors provided difficult.

We then looked at QMF, which is an management framework written on top of the QPID messaging fabric. You can learn about QMF here. This post will walk you through an eaxmple of exposing an EJB in jboss over the QMF Bus. Gregory Mostizky is working on a deployer, so this should get easier.. but this is a good enough to criticize.. so I am posting it.

To get started, you will need the gcc tools, ant, and jboss5 installed. Next.. get the code:

# Get the latest QPID Code
svn co http://svn.apache.org/repos/asf/qpid/trunk
# Get my example Code:
git clone git://github.com/bkearney/qmfExample.git

Build the latest qpidd broker and java code

cd trunk/qpid/cpp
./bootstrap
./configure --prefix ~/qpidlocal
make install
cp ../java
ant

Once this is done, you should be able to launch the most current qpidd

export LD_LIBRARY_PATH=~/qpidlocal/lib
~/qpidlocal/sbin/qpidd

Now…. build the example code:

cd ~/qmfExample/javaAgent
# Edit the build.properties file to point to your local
# installation
ant install

You can now start up jboss, and run the example python script to access the bean

export PYTHONPATH=~/trunk/qpid/python
cd ~/qmfExample/pythonConsole
python ./qmfExample.py

Thats all there is. Python is now calling EJBs! Now… lets see how we did it. All the code below is in the qmfExample/javaAgent/src
directory. Lets first look at the Session Bean we created:

package qmf.example.ejb;

import java.util.ArrayList;
import java.util.List;
import javax.ejb.Stateless;
import org.apache.qpid.agent.annotations.QMFHide;
import org.apache.qpid.agent.annotations.QMFObject;
import qmf.example.BaseClass;
import qmf.example.DerivedClass;

@Stateless(name="ServiceBean")
@QMFObject(className="ExampleService", packageName="qmf.example.ejb")
public class ServiceClassBean implements ServiceClass
{

    public BaseClass getBase(String name, String description) {
        BaseClass bc = new BaseClass() ;
        bc.setName(name) ;
        bc.setDescription(description) ;
        return bc ;
    }

    public DerivedClass getDerived(String name, String description, int count) {
        DerivedClass dc = new DerivedClass() ;
        dc.setName(name) ;
        dc.setDescription(description) ;
        dc.setCount(count) ;
        return dc ;
    }

    public List findMany() {
        ArrayList list= new ArrayList() ;
        list.add(getBase("JarJar", "My Friend")) ;
        list.add(getDerived("Binks", "Not My Friend", 12)) ;
        ArrayList data = new ArrayList() ;
        data.add(11) ;
        data.add("Info") ;
        data.add(getBase("Wotto", "Also My Friend")) ;
        list.get(0).setStuff(data) ;
        return list ;
    }

    @QMFHide
    public void doHokeyPokey() {
        System.out.println("Turn yourself around") ;
    }
}

This is pretty normal except for 2 annotations. One, @QMFObject, gives
the name and package to expose. The second, @QMFHide, causes the method
to be ignored. The bean returns 2 classes, a base class and a derived
class. We have annotated the base class so that the marshalling code
knows about the derived class. This is a similar pattern to JAXB:

package qmf.example;

import java.util.ArrayList;

import org.apache.qpid.agent.annotations.QMFSeeAlso;

@QMFSeeAlso({DerivedClass.class})
public class BaseClass
{
.....

The final magic, is a beans.xml file which tells the JBoss microcontainer to start up the agent. Here is the code for that:

<deployment xmlns="urn:jboss:bean-deployer:2.0">    

	<bean name="QPIDConnection" class="org.apache.qpid.client.AMQConnection">
		<constructor>
			<parameter>amqp://guest:guest@/?brokerlist='tcp://localhost'</parameter>
		</constructor>
	</bean>

    <bean name="ServiceBean" class="org.apache.qpid.agent.ManagedEJB">
        <property name="name">ServiceBean</property>
        <property name="className">qmf.example.ejb.ServiceClassBean</property>
        <property name="jndiLocation">qmfExample/ServiceBean/local</property>
    </bean>	    

	<bean name="QMFAgent" class="org.apache.qpid.agent.Agent">
		<property name="label">agent</property>
		<property name="sessionTransacted">false</property>
		<property name="connection">
			<inject bean="QPIDConnection" />
		</property>
		<property name="managedObjects">
			<list elementClass="org.apache.qpid.agent.ManagedObject">
				<inject bean="ServiceBean" />
			</list>
		</property>
		<property name="registeredClasses">
			<list elementClass="java.lang.String">
			</list>
		</property>
	</bean>

</deployment>

As I said earlier, the deployer should make this easier. Specifically.. it will remove the need for the beans file. But.. this will work until the deployer is done.




bk on Identi.ca (via twitter)