Friday, May 09, 2008

Writing a RHQ plugin Part 2

In the last post I showed the general architecture of RHQ and where plugins live. So we can now start writing one.

The scenario revisited



Our plugin should be able to connect to a http server, issue a HEAD request on the base url (e.g.
http://localhost/) and return the http return code as trait and the time it took as numeric data (see below).



To make things easier for the purpose of this series of postings, we will have the agent running on the machine the RHQ server lives on and we will just try to get data from the Servers http connector at port 7080 (the default port).

What do we need ?



In order to write our plugin we basically need three things

  • A plugin descriptor. This contains metadata about the plugin: which metrics should be collected, what operations does it support etc.

  • A discovery component. This part discovers the actual resource(s) and delivers them to the Inventory.

  • A plugin component. This component executes operations and gathers the measurement data etc.



So lets have a look into those three parts.

Plugin descriptor



The plugin descriptor is described by an XML Schema that you can find in svn. The basic structure is as follows:




(Click for pdf version), Graphic done with http://x2svg.sf.net/

The desciptor consists of a few sections. First you can express dependencies to other plugins. This is allows reuse of existing plugins and is useful when you e.g. want to write a plugin that itself needs the JMX plugin, so that it can do its work.

The next are a row of platform/server/service sections. Each of those can have the same (XML-)content as the platform that is shown as an example - they are all of the same (XML-) data type (as a platform/server/service) as each is a kind of resource type, as you already know from the first part.

Example:

<service name="CheckHttp">
<metric property="responseTime"
description="How long did it take to connect"
displayType="Summary"
displayName="Time to get the response"
units="ms"
/>
</service>


The name of a <service> and the other ResourceTypes (platform, server) must be unique for a plugin. So it is not allowed to have two services named "CheckHttp" within our example plugin, but you could write a Tomcat5 and a separate Tomcat6 plugin that both have a service with the name "connector".

For the start we are especially interested in one of the sub elements: metric for our example plugin, so I will describe this here in a little more detail. For all other tags refer to the XML Schema that has a lot of comments.

Metric



This is a simple element with a bunch of attributes and no child tags. You have already seen an example above.
Attributes of it are:

property: name of this metric. Can be obtained in the code via getName()
  • description: A human readable description of the metric

  • displayName: The name that gets displayed

  • dataType: Type of metric (numeric / trait /...)

  • units: The measurement units for numerical dataType

  • displayType: if set to "summary", the metric will show at the indicator charts and collected by default

  • defaultOn: Shall this metric collected by default

  • measurementType: what characteristics do the numerical values have (trends up, trends down, dynamic). The system will for trends* metrics, automatically create additional per minute metrics.



For the sample plugin we will use a metric with numerical dataType for the response time and a dataType of trait for the Status code. Traits are meant to be data values that only rarely change like OS version, IP Address of an ethernet interface or the hostname. RHQ is intelligent enough to only store changed traits to conserve space.

Discovery component



The discovery component will be called by the InventoryManager in the agent to discover resources. This can be done by a process table scan (e.g. for the Postgres plugin) or by any other means (if your plugin wants to look for JMX-based resources, then it can just query the MBeanServer. Well, actually there is a JMX-Plugin that can do that for you in clever ways).

The most important thing here is that the Discovery component must return the same unique key each time for the same resource.

The DiscoveryComponent needs to implement org.rhq.core.pluginapi.inventory.ResourceDiscoveryComponent and you need to implement discoverResources().
The usual code block that you will see in discoverResources() is:


Set<DiscoveredResourceDetails> result = new HashSet<DiscoveredResourceDetails>();
for ( ... ) {
...
DiscoveredResourceDetails detail = new DiscoveredResourceDetails(
context.getResourceType(),
uniqueResourceKey,
resourceName,
resourceVersion,
description,
configuration, // can be null if no confi
processInfo);
result.add(detail);
}
return result;


Basically the context passed in gives you a lot of information, that you can use to discover the resource and create a DiscoveredResourceDetails object per discovered resource. The list of result objects is then returned to the caller. Simple - eh?

Plugin component



The plugin component is the part of the plugin that does the work after the discovery has finished.
For each of the "basic functions" in the plugin descriptor, it needs to implement an appropriate Facet:












Descriptor elementFacet
<metric> MeasurementFacet
<operation> OperationFacet
.....


Each Facet has its own methods to implement. In the case of the MeasurementFacet this is e.g. getValues(MeasurementReport report, Set metrics). The report passed in is where you add your results. The metrics is a list of metrics for which data should be gathered. This can be all ouf your definied <metric>s at once or only a few of them - this depends on the schedules the user configured in the GUI.




Ok, that's it for now. In the next post we will do some coding and get our plugin to work.




Part 1
Part 3
Part 4
Part 5







Technorati Tags:
, ,


Thursday, May 08, 2008

Sample app of my ejb3 book updated (German)

I have just updated the sample app + installation guide of the sample app from my ejb3 book to use JBoss 4.2.2.GA. This makes the installation much simpler. I also removed a few issues from various places.

You can the updated description on the books web page.

Remember, even as there is the free PDF version of the book, it still can be ordered in print.

Wednesday, May 07, 2008

Writing a RHQ plugin Part 1

Red Hat and Hyperic released Project RHQ in the open in February. Meanwhile we released the first GA version of RHQ together with JBossON 2.0 at JavaOne 2008.

This post and the next few will try to show how to write your own plugins for RHQ.
As an example scenario the plugin will try to reach a http server, see if the base URL is available and return the status code + the time it took to reach it.

General architecture of RHQ



Before we go into detailed plugin writing, I first want to show the general architecture of RHQ and its plugin system.

RHQ follows a hub and spoke approach: A central server (or cluster) processes data coming in from agents. The data is stored in a database connected to the server. Users / admin can look at the data and trigger operations through a web-based GUI on the server



Agents do not have a fixed functionality, but can be extended through plugins which we will see below. Usually there is one agent running per machine with resources to manage. The RHQ server itself is able to run an agent embedded in the server. This is mostly for demo and test scenarios, but it is well able to monitor the server machine.

Server services



The server hosts a number of services like

  • It has a view on the complete Inventory

  • It processes incoming measurement data

  • It triggers alerts to be sent

  • It triggers operations on managed resources

  • It hosts the graphical user interface

  • It hosts the user management

  • ...



Some of those services are reflected in the agent like inventory syncing, gathering of measurement data or running operations on a managed resource, while alert processing or hosting of the GUI is purely on the server.

Agent architecture



The agent is sort of a container that hosts some common functionality like the communication interface with the server, logging, starting and stopping of plugins or reading configuration files. In addition to this, it hosts plugin containers, who host the actual plugins. When you write a plugin, you talk to the plugin container.



The agent is in addition to the plugin containers also hosting common service like the communication with the RHQ server, logging or the handling of the command line and interactive command prompt.


Central functionality: Inventory



The central functionality of RHQ is the inventory. Each resource that you want to manage or monitor must be present in that inventory. RHQ has mechanisms to autodetect and also manually add resources. We'll come back to that later when we are talking about implementing plugins.

Each org.rhq.core.domain.resource.Resource has a certain org.rhq.core.domain.resource.ResourceCategory:


  • Platform: This is basically a host where things run on

  • Server: Things like database server, JBossAS instance or the RHQ agent

  • Service: (Fine grained) Services offered by a server



The ResourceCategory is sort of hierarchic as you can see on the next image:



A platform hosts servers, a server can host other servers and services and a service can host other services. In theory it is also possible that a platform is hosting other platforms.
As an example: you have a Red Hat Linux platform, which hosts the RHQ Agent and JBossAS as a server. This AS it self is hosting a Tomcat server. Both JBossAS and Tomcat themselves are hosting services like JMS or Connectors.
So at the end this will result in a tree of resources with the Linux platform as its root.

In addition to the category each Resource also is of a certain org.rhq.core.domain.resource.ResourceType. For a platform this might e.g. "Max OS X", "Red Hat Linux", "Debian Linux" etc. Or the JBossAS and Tomcat from above are both of category Server, but have different ResourceType.

The RHQ wiki has an overview of the inventory db schema.



Ok, that's it for now. As a homework, check out the documentation at the RHQ wiki and the source code from the RHQ svn

Greg Hinkle also put a high level overview of the plugin system online.

Joseph Marques has written an article about things to consider before writing a plugin and will soon write a second part of it (actually it is already online).





Part 2
Part 3
Part 4
Part 5







Technorati Tags:
, ,


Tuesday, May 06, 2008

JBossON 2.0 and RHQ 1.0 released

After a lot of work JBossON 2.0 was released today together with RHQ 1.0 at JavaOne conference.

You can read the press release at:

Yahoo

Red Hat

This is a great release and it feels great that over a year of hard work finally fell into place. There are no real release notes for RHQ, but you can browse the release notes created by JIRA at jira.rhq-project.org.

I wrote already about a few of the new features and I am planning on writing soon about developing own plugins for RHQ and JBossON.

If you want to meet the team, join us on #rhq at irc.freenode.net.

Greg from the JBossON team will also be around at JavaOne - you can probably meet him at the JBoss booth.

My colleague Jason Dobies also has an article about the release.


Friday, May 02, 2008

JPA 2 first draft is out

The counterpart to the EJB 3.1 spec, the Java Persistence API 2.0 spec has just published a first public draft at JSR 317.
There have been so many changes to the spec since JPA 1.0 (JSR 220) that I don't want to mention them here.
Mike Keith has recently written an article that describes some of them.

Like in JPA 1.0, JBoss has contributed a lot to the stuff. Both Gavin King and Emmanuel Bernard were very active in this update.

But check them out by yourself at the JSR 317 spec page.

Monday, April 28, 2008

NetBeans 6.1. is here !

Last time I was asking where NetBeans 6.1 is, as its release got delayed.

I got a comment on my blog entry that it will be released today (4/28). And here it is!

Nice!

Stuttgart SIG-JBoss: upcoming meetings



After a long time without any meetings, SIG-JBoss as part of the Java User Group Stuttgart (JUGS e.V.) is coming to live again with the following two user group meetings:



  • Thu 5.6.2008 Bernd Rücker: Presentation of the jBPM Business Process Simulation Component

  • Thu 26.6.2008 Myself: presentation of RHQ



We will meet both times in the rooms of the Stuttgart Red Hat office at 7pm.
Guests are welcome as always.

Please register yourself so that we have an idea about the number of people that will participate.

Sunday, April 27, 2008

x2svg new release 1.2beta3

Project x2svg just released a new version.



Changes in release 1.2beta3 are:

  • Updated the libraries on the scripts to match the libraries introduced in 1.2-beta2 (SF bug#1944294).

  • Added the possibility to the XSD parser to just show references to substitutonGroups, but not the whole
    substituted group (SF fr#1769065).

  • Added the possibility to limit the depth of the parsed tree of the XSD Parser

  • It is now possible to get the parser specific help on the command line and to list modes and suffixes (SG
    bug#1950350)

  • Fix errors with options without argument and NPE without input file (SF bug#1951088).



You can download it from Sourceforge

Please provide feeback:

Saturday, April 26, 2008

JBossON 2 not just sexy - huh?

Rich Sharpless posted about JBossON 2 not only being sexy after he has seen a presentation on it.

Of course it is not only sexy when you look at the covers, but also when you unfold it. A few items to notice:

  • The plugin development is much easier than in the past

  • Groups are much more powerful - including new DynaGroups

  • The internal data model is much cleaner and easier to extend and understand

  • The application is written in EJB 3.0 with heavy usage of JPA 1 for the persistence (there is some pure hibernate and even JDBC code in it, but >90% is JPA).

  • Due to the latter (and other reasons) it is much faster.


And last but not least: most of it is (already) open source in the form of RHQ.

When you want to know for your self how JBossON 2 looks like, just check out RHQ.

And of course we are not only looking for marketing people, but also always for developers with clue :-)

Friday, April 25, 2008

So where is Netbeans 6.1 ?

When I was recently testing NetBeans, I also saw that 6.1 GA was supposed to be released on Apr 23th. Now it is two days later and still no sign of it (or why it is delayed). So I will postpone further testing in that area until 6.1 is out.

Small step for mankind, big Step for Marlene

My little daughter finally did her first steps on her own - that is just great. And she really is enjoying it. Orlando is also very happy.

As am I :-)

Monday, April 21, 2008

Testing NetBeans (coming from Eclipse)

Inspired by Adam Bien's praise on NetBeans and its Maven support, I was looking at NetBeans again.
NetBeans basically was my first Java IDE, but somehow I never got infected by it and switched to Eclipse relatively soon thereafter.

I downloaded NetBeans 6.0.1 for Mac OS X from the website and started ..

First a little test



So I first tried to import a simple Eclipse project like x2svg with the "Open Project..." and "from existing build file" option, but this wasn't really as I wanted it. Ok, back to the dialog and searching for "from Eclipse project" - nothing. A quick search in help showed that I first have to download and install the respective plugin. That was quick and this time the import worked well.

The next thing that I changed was the key bindings. I am so used to the Eclipse ones, that I don't want to learn new ones. This was equally simple. Just go to preferences and the key bindings section, then choose Eclipse from the drop down. Done (Note to Mac users: Save is on Ctrl-S in that binding, but can be easily changed).

One drawbacks for me is that run/debug options have not been transferred (I am currently trying to improve the XSD parser and have a longish command line).

One irritating thing is that it seemed like the SVN settings also have not been imported. But it turned out that as soon as I specified the location of the svn executable (actually SVN_HOME is the directory where it resides in), svn integration worked as supposed. Interestingly, as I have three source trees in the project, NetBeans is connecting three times to the svn server, while Eclipse uses one connection only on a svn up.

Another thing that is irritating (but which I find a good think after I know what is going on) is the fact that NetBeans is storing its information in a separate folder in the filesystem and uses this folder as default root directory when running an executable, which will make some tests fail. But the I am very happy, that it doesn't just write stuff in my existing project that I would need to remove later.

When I tried to open my two GUI files, I received a (well known) NPE both times - actually I was hoping to get some sort of visual Swing editor instead. The website that took my error report told me that this is probably already resolved and that I should download the latest NB 6.1 milestone (RC2 in my case).

Updating to 6.1 RC 2



The update was painless, and installed a new version next to the 6.0 one in /Applications/NetBeans. Having seen this, I did not expect the plugins that I installed earlier to be present - and I was right.

The NPE was gone too, but I still have no GUI editor - perhaps because NB is just not able to parse GUI elements that were not created using NB?

But from that little test I have to say that I like it much more than when I was looking at it the last time. Now lets go on to something heavier.

Testing with a mavenized project



In RHQ we are using maven a lot. So the next test is to see if the maven support is really as good as Adam is saying.

Checkout from http://svn.rhq-project.org/repos/rhq was painless and NetBeans was asking what project I want to open. I've chosen the root and it now showed me a structure of maven poms, that I could open as project afterwards. This again is very different from how Eclipse is handling things (I mean, RHQ is one project with a bunch of modules). But ok, that import was painless as well.
And then: a build from within NetBeans fails because of some wrong maven version. But this is not fatal for me, as I am used to build from the command line anyway.

Speed



In total NB doesn't feel slow, but with RHQ, auto completion is slower than in Eclipse, the "member view" is slower than the Outline view and the fan of my MacBook is much more active. I can imagine that this comes from the usage of the mavenized project. I will try to import this as Eclipse project as well to see if that changes things to the better.

My friend, the problem view



Eclipse has a problem view that just works. Period. IntelliJ 6 had its issues with it. And now I am finding basically the same in NB 6.1. Perhaps I am missing something obvious - dunno. I have already enabled the "track java dependencies" setting:



(I am not even sure if this setting is supposed to do what I want it to do).

In x2svg I have three source trees src, gui-src and test-src. When I now e.g. rename a method in src (by hand, not via re-factoring), only the errors in the src tree show in the project explorer and in the task list. Even when I have a file from gui-src open and the editor shows the error for that file, it doesn't appear in the task list nor the projects explorer.



When I switch back to the other file, the error will eventually show.

When I then fix the issue in src/ , the error will still show up for the file(s) in gui-src/.

Profiler



Just to mention that as a big plus for NetBeans: it comes with a built in profiler. I don't know how much I'll look at it or even use it, as we are using jProfiler in RHQ, but nevertheless this is a big plus.



Conclusion



NetBeans has gained a lot since I was last looking at it and the Maven integration is really so much better than in Eclipse, which saves me from the pain to always update the .classpath file when we pull in a different library version.

I will keep an eye on NB in the upcoming weeks to see if it could be an alternative to what I now have with Eclispe. But the issue with the problem view / task list, that I mentioned, really is close to a show stopper for me. Perhaps it will just be fixed in NB 6.1 GA.


Sunday, April 20, 2008

Java Forum Stuttgart 2008 - Schedule posted

The tracks for this years Java Forum Stuttgart has been
posted.

It again features 42 sessions in six parallel tracks.
From the JBoss side there are two interesting tracks:

  • Advanced JBoss Cache (F2)

  • Geschäftsprozesse & Regeln mit jBPM & Drools - ein unschlagbares Team (C3)


My submission for a talk about RHQ and JBossON was rejected as well as an outlook into EJB 3.1, but my third proposal made it into the program:
"Profiler der bessere Debugger?" (C6).

Go and check out the whole program - registration starts Mon 21.4.2008.
Hope to see you there!

Wednesday, April 16, 2008

Free PDF version of my German EJB 3 book available

I am very pleased to announce that dpunkt.verlag, my publisher for my EJB-3 and JBoss books, has made a free PDF version of my German EJB-3 book available for download.



Cover of my EJB 3 book



You can download it from the book site. Please take a few seconds to fill in the survey.

[ There were access issues on the server - please retry the download ]

The book is of course still available in printed form - e.g. at Amazon.de.

Many thanks go to the nice folks at dpunkt.