Wednesday, March 03, 2010

Multiple usage of the maven exec plugin

So I was trying to use the maven exec plugin in my alert-operations sender pom in RHQ to automatically run a java class and generate some documentation.

I've added the maven exec plugin to the pom like this:


<build>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<!-- Generate tokens.xml file -->
<phase>install</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>java</executable>
...


As soon as I added this and tried to build after a mvn clean, the build failed without an obvious message why. Commenting out this plugin made the build succeed. Digging around showed that we have an other call to this plugin in the root pom. So there was some clash - but which?

I thought "perhaps I need to include the execution from the root pom in mine as well (via copy&paste). I did that and got an error message, that it is not possible to have two executions without an <id> in a pom. So it turned out that both executions had the same implicit id - even while being in different poms, so one was overwriting the other.

Now I have


<execution>
<id>generate-tokens-xml</id>
<!-- Generate tokens.xml file -->
<phase>install</phase>
<goals>


and everything is fine again.

Saturday, February 27, 2010

Glassfish v3 - what's the deal to have Weld and REST?

<UPDATE>

It turns out I did the right thing, but obviously needed a few more mvn clean install cycles (or in other words I have no obvious clue why this consistently failed at the start

</UPDATE>

---------------

So I've been trying to write an app that uses CDI (Weld) and JAX-RS.
As I want separate layers, I coded everything up to have a web.war, an ejb.jar and packaged everything together in an ear-file.

I've coded a bean like this:

@Stateless
@Path("/xx")
@Produces({MediaType.TEXT_PLAIN})
@Named
public class StatusManager {

public String foo() {
...
}
}


Now I can use it in a JSF like

 <h:commandButton value="Submit!" action="#{statusManager.foo}"/>

Works like a charm.

When I try to accces the REST endpoint I get a "resource not found". Ok,
so I add some stuff to web.xml:

    <servlet>
<servlet-name>ServletAdaptor</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>ServletAdaptor</servlet-name>
<url-pattern>/xxx/*</url-pattern>
</servlet-mapping>


Now accessing the JAX-RS endpoint works like a charm, but the above JSF action breaks and the container shows the following in the logs:

com.sun.jersey.api.container.ContainerException: The ResourceConfig instance does not contain any root resource classes.


Does anyone know what is going on and how to use both at a time?

Monday, February 22, 2010

RHQ / Jopr tab sweep

Lot has happened since the last tab sweep ...

Releases

RHQ 3.0.0.B03 has been released. You can find more information on the release notes page and the bits at the download page.

Videos

There are several new videos available:





Talks

I've been talking about RHQ at FOSDEM X - the talk was well received and its recording is finally online (see above).


Misc

Spacewalk 0.8 has been released.

Joe Marques gives a tip about automation in web development




Quote html for MarsEdit



I am using MarsEdit to post my blog entries, which is a nice editor (ok, it could sometimes have a more wysiwig mode, but in total I am happy with it).

One thing that I find often annoying or missing when writing posts is that there is no build in quotation mechanism for '<' in a <pre> block (many of my posts are rather technical and contain XML snippets).

Luckily MarsEdit has AppleScript support, so I wrote this little AppleScript script (actually I copied a good part from the supplied Add Paragraph Tags one):


tell application "MarsEdit"
try
set currentWindow to document 1
on error errorMessage
displayErrorMessage("Can’t add paragraph tags because no post windows are open. This script works on text in the frontmost post window.") of me
return
end try

set currentTextView to selected text in currentWindow
set numChars to number of (characters in currentTextView)
set newBodyText to ""

repeat with i from 1 to numChars

set currentChar to character i in currentTextView

if (currentChar is "<") then
set newBodyText to newBodyText & "&lt;"
else
set newBodyText to newBodyText & currentChar
end if
end repeat

set (selected text in document 1) to newBodyText
end tell


This allows to quote the current selection. Save the script to
~/Library/Application Support/MarsEdit/Scripts/Quote Html.scpt.
It will then be availably in the ApppleScript Menu:

Bildschirmfoto 2010-02-22 um 09.35.54.png


To use it, just select the text and then invoke this Quote Html menu item

Monday, February 08, 2010

Small FOSDEM 2010 round up (with pics and video)

So I've spent last weekend in Brussels, Belgium at FOSDEM, gave a talk, met with some colleagues and had a great time.



Ok, this was a bit tense :)

FOSDEM 2010 was the 10th incarnation of the Free and Open Source Developer's European Meeting. There have been thousands of geeks at the ULB (UNiveristé libre de Brussels) - exact numbers are not known as there has been no official registration. THere have been tweets about being around 2000 devices with IPv4 and close to 2000 devices with IPv& active - this already shows the size of the audience.
Despite this huge number of devices online, the network was great (FOSDEM had a 1GBit link to the internet) - wireless was available in nearly every room at good strength and performance On sunday morning they even encouraged people to use more bandwidth - many much more commercial conferences should talk to the FOSDEM NOC in order to learn how to do this.

I arrived in Brussels on Saturday morning having taken an early train from Stuttgart - after Cologne I met the first two other guys heading to FOSDEM too :)

Later on saturday I gave myself a talk about Systemsmanagement with RHQ. Slides are available here.

After my talk, my colleague Mark Procter gave a presentation about Drools. When my talk was over I felt very much relieved and was more able to attend other talks. I wanted to attend some Postgres related ones, but they were already crowded.

One of the/my highlights was the talk by Andy S. Tanenbaum about Minix 3 - he presented with a good sense of humor, so it was nice to listen. His talk actually made me want to do some low-level stuff hacking again (I used to work on NetBSD in the past). Later on I was sitting in the Free Java track and was thinking that I should perhaps also start hacking on the VM. Lukily for me I did not attend all talks. Otherwise I'd probably end up with programming Drupal in Assembler for one of those little embedded boards I that the OpenEmbedded guys had on display :-)

On Sunday Dave Fetter from Postgres showed on Sunday how to compute Mandelbrot sets and solve the Traveling Salesman Problem in SQL on Postgres - totally crazy! :)

After this I have been in the Free Java dev room and met some colleagues from Red Hat, working in that area - it is always nice to finally be able to put a face behind a name.

Below are a few impressions from Fosdem and Brussels - enjoy (I will fix the image orientation as soon as I know how ... ). More pictures are e.g. on Flickr, here and here.


Below movie is also available as .ogg version (79 MB).












































Thursday, February 04, 2010

RHQ / Jopr tab sweep



Releases

RHQ 3.0.0.b02 has been released

Web articles

We have set up a page that lists third party plugins and also usages of Jopr and RHQ - if you want to be listed here, contact us


Marek Goldmann has written a blog post, where he shows how CirrAS uses RHQ for management of servers in the cloud. This post especially talks about using the RHQ CLI to import and configure resources.

Mazz also refers to this in his latest blog entry. In another post he describes how to install the JD java decompiler, which also understands generics unlike the outdated (but often used) jad.

My (German) article "Polyglotte Bohnen" on JSR 223 usage at the example of JRuby got published at Heise Developer. JSR 223 is in usage in a few places within RHQ: CLI, script2 alert plugin and scriptlang alert sender plugin (and probably others).

Talks

I'm going to FOSDEM, the Free and Open Source Software Developers' European Meeting

I will talk about RHQ at FOSDEM. There will be other people from Red Hat, as well as many other interesting talks.

Wednesday, February 03, 2010

RESTEasy client : authentication

Was just playing with RESTEasy and needed to do authentication against the server.
Came up with this solution:


String userId = "myName";
String password = "verySecret";
 
Credentials credentials = new UsernamePasswordCredentials(userId, password);
HttpClient httpClient = new HttpClient();
httpClient.getState().setCredentials(AuthScope.ANY, credentials);
httpClient.getParams().setAuthenticationPreemptive(true);
 
ClientExecutor clientExecutor = new ApacheHttpClientExecutor(httpClient);
 
try {
URI uri = new URI("http://.....");
ClientRequestFactory fac = new ClientRequestFactory(clientExecutor,uri);
 
ClientRequest request = fac.createRequest("http://.....);

I don't know if there is a better way, as there are a lot of steps to do here. Just thought I should share as documentation is a little sparse here.

Tuesday, February 02, 2010

RHQ 3.0.0.b02 released - includes Jopr

We are proud to announce the release of RHQ 3.0.0.b02. Like the 1.4.0.B01 release, this is a developer preview and not intended for production. As with the previous release, this includes the Jopr bits, which now also live in the combined RHQ source repository.

You may wonder about the jump in the major release number. Well, first of all, the next release will be a big jump forward for the project, so a new major number is appropriate. And then, there is a very practical reason too: as I've already written earlier, the download not only contains the RHQ bits, but also the Jopr bits, which creates some confusion in the install / upgrade process, as the Jopr bits, which in the last Jopr-release were named xy-plugin-2.3.1, in 1.4.0.B01 they were suddenly xy-plugin-1.4.0.b01. The RHQ installer assumes that plugin versions are increasing and thus is considering the Jopr plugins in 1.4.0.B01 as older.
We could have hacked around this, but just increasing the major number solves this issue in a very natural way.

New Features:

  • Some French installer messages contributed by Victor Montaner

  • Alerting

    • Much improved UI for the new alert sender plugins

    • Alert definition UI partly moved from JSF to struts

    • Improved alert senders for microblog and snmp

    • It is now possible to define templates of alert notifications that contain a bundle of senders that can be reused to create notifications for alert definitions. See menu "Administration -> Settings -> Alert Notification Templates"

    • Alert migration: the datamodel for alerts has changed an needs migration. See the README for a how to

    • NOTE: alert senders for Subject, Roles and Operation are not in this release - they will come back soon


  • Raw configuration support: It is now possible to edit the raw text of configuration files and not only the structural view of them. This includes validation and rollback

  • Operations for server side plugins: it is now possible to define operations on server side plugins, that can be triggered through the alert plugin gui (Administration -> System Configuration -> Plugins -> Server Plugins)

  • Cosmetical changes in the left nav tree


Have a look at the full release notes for more details.

Download:

You can download this release from SourceForge at

https://sourceforge.net/projects/rhq/files/rhq/rhq-3.0.0.B02/. There is an agent download as well, but you don't need to download this, as the agent is contained in the server download already.

The source for the community release can be found in the 3.0.0.b02 branch in RHQ git.



Thursday, January 21, 2010

JBoss talks at FOSDEM 2010

FOSDEM, the Free and Open Source Software Developers' European Meeting

I will talk at FOSDEM 2010 in Brussels about RHQ and Jopr. (Sat, 3pm)

There are actually other JBoss-related talks too:

Of course, there are lots of other interesting talks at Fosdem (some would say: too many):

And much much more.

For iPhone users there is an application available that holds the whole schedule, can inform you what is running now and next and can hold your favorites

Monday, January 18, 2010

RHQ / Jopr tab sweep



Call for papers for JBoss World 2010 in Boston

ends on January 22th - be sure to submit a talk about Jopr or RHQ!



Other news:

Mazz has updated the Byteman plugin for RHQ see http://management-platform.blogspot.com/2010/01/byteman-plugin-revisited.html

Mobicents JAIN SLEE server 2.x does now also support management via Jopr / RHQ (via Amit Bhayani).

We've got some French translations for Installer messages in - those have been provided by Victor Montaner long time ago. If you want to help translating the messages into other languages, feel free to ping me or any other team member.

Speaking of participating: this wiki page contains a list of hints about contributing to RHQ.

RHQ Mastermind Greg Hinkle has written a longer blog post about autocompletion in the RHQ Command line interface (CLI).

I will talk at FOSDEM 2010 in Brussels about Jopr and RHQ. FOSDEM is one of the largest open source conferences in Europe (5000 attendees expected). Have a look at the JBoss developer room page for the exact schedule (as soon as it is published). And the best: admission is free!


FOSDEM, the Free and Open Source Software Developers' European Meeting

Sunday, January 10, 2010

Laufen mit Daisy (German)

Seit Freitag hat uns Tief Daisy fest im Griff und dementsprechend ist alles weiß. Hier im Süden ist es nicht so tragisch, wie beispielsweise in Brandenburg. Ich bin dann heute nachmittag doch noch aufgebrochen und eine Runde gelaufen. Es ist interessant wie viele Gehwege nicht geräumt sind, obwohl doch Räumpflicht besteht (nicht dass ich auf die Räumung bestehen würde). Laufen auf Schnee war ja ganz ok, aber im lockeren, mehrfach von Autos oder Fußgänger durchpflügten Schnee ist es ganz schön anstrengend. Deswegen war ich auf den 12km dann auch eher langsam unterwegs. Spaß gemacht hat es trotzdem :-)

Wednesday, December 30, 2009

Laufen 2009 / 2010 (German)

Das Jahr neigt sich dem Ende zu; Zeit für einen Jahresrückblick: ich habe beide gesteckten Laufziele gut geschafft:

- Stuttgart-Lauf ankommen. Ich habe das Ziel dann zweimal hochgesetzt. Erst auf unter 2:30h und dann auf unter 2:15h. Letztlich war es dann besser :-)

- Mehr als 750km laufen - das habe ich mit 792km auch gut hinbekommen - wenngleich ich im Dezember nochmals richtig Gas geben musste









Einheiten75
Distanz792,23 km
Distanz pro Einheit Ø10,56 km
Pace Ø5:55 min/km
Geschwindigkeit Ø10,14 km/h
Fitness46 (37-45)
Puls Ø / Max159/191
Kalorien62237

Bester Monat war der Dezember mit 135km

Läufe an "exotischen" Plätzen:



Ziele für 2010

- Stuttgart-Lauf schneller als 2009 (also unter 1:59:04) - wenn das Wetter mitspielt und ich nicht krank bin

- 900 Laufkilometer

Monday, December 21, 2009

RHQ / Jopr tab sweep

This post is to gather a few of the recent developments around RHQ and Jopr

Just in case you have missed it: RHQ 1.4.0.B01 is out - this build contains the Jopr plugins and thus is the successor of the Jopr-server builds that you have seen before.

Mailing lists:

We have opened two mailing lists for RHQ where we expect to bundle the email activities in the future:

  • rhq-users: for user questions around RHQ (including the Jopr plugins

  • rhq-devel: for developing with and on RHQ


Video:

Galder Zamarenno from Infinispan has created a video showing a three-node Infinispan cluster being monitored. It demonstrates graphical measurements, and non-graphical information of running Infinispan instances, addition or removal of monitored metrics and finally, execution of management operations on a Infinispan instance.

Mazz has created a demo on how to use the new server side plugins to periodically create reports on the server.

Alert senders:

Alert notifications can now be processed by plugins. This means that it is finally possible to easily write own notification schemes to forward alerts to various devices. Two posts show how to write such a sender (Part 1 & Part 2).

Agent plugins:

A new agent plugin allows to use script in Ruby and JavaScript to do monitoring. This allows to easily monitor resources via dynamic scripting languages without writing Java code.

Tuesday, December 15, 2009

How to write an alert sender plugin for RHQ/Jopr (Part 2)

Now that we have seen the "theoretical side" of writing an alert sender, lets just start and code one up.

First grab RHQ from GIT and then change into
modules/enterprise/server/plugins.


  • Run this little script:

    mkdir alert-url
    cd alert-url
    mkdir -p src/main/java/org/rhq/enterprise/server/plugins/alertUrl
    mkdir -p src/main/resources/META-INF

  • copy over the pom.xml from alert-email and change email to url in it:

    cp ../alert-email/pom.xml pom.xml,1
    sed -e 's/email/url/' < pom.xml,1 > pom.xml

  • Lets edit the plugin descriptor

    vi src/main/resources/META-INF/rhq-serverplugin.xml

    <alert-plugin
    name="alert-url"
    displayName="Alert:Url"
    xmlns="urn:xmlns:rhq-serverplugin.alert"
    xmlns:c="urn:xmlns:rhq-configuration"
    xmlns:serverplugin="urn:xmlns:rhq-serverplugin"
    package="org.rhq.enterprise.server.plugins.alertUrl"
    description="Alert sender plugin"
    version="1.0"
    >

    This is just the generic header. Now lets set the target host name on the server-wide preferences and

    <serverplugin:plugin-configuration>
    <c:simple-property name="hostName"
    default="localhost" />
    </serverplugin:plugin-configuration>

    Now the name of the sender and its alert sender class

    <short-name>Url</short-name>
     
    <!-- Class that does the actual sending -->
    <plugin-class>UrlSender</plugin-class>

    And now finally the Information that is specific to an alert definition. Lets just set the port here for demonstation purposes.

    <alert-configuration>
    <c:simple-property name="port" type="integer"/>
    </alert-configuration>
    </alert-plugin>

  • Now lets implement the Java sender class

    $ cd src/main/java/org/rhq/enterprise/server/plugins/alertUrl
    $ vi UrlSender.java

    package org.rhq.enterprise.server.plugins.alertUrl;
     
    import java.io.OutputStream;
    import java.net.HttpURLConnection;
    import java.net.URL;
     
    import org.apache.commons.logging.Log;
    import org.apache.commons.logging.LogFactory;
     
    import org.rhq.core.domain.alert.Alert;
    import org.rhq.enterprise.server.alert.AlertManagerLocal;
    import org.rhq.enterprise.server.plugin.pc.alert.AlertSender;
    import org.rhq.enterprise.server.plugin.pc.alert.ResultState;
    import org.rhq.enterprise.server.plugin.pc.alert.SenderResult;
    import org.rhq.enterprise.server.util.LookupUtil;
    import org.rhq.enterprise.server.xmlschema.generated.serverplugin.perspective.ResourceTaskElement;
     
    public class UrlSender extends AlertSender{
     
    @Override
    public SenderResult send(Alert alert) {

    So this was just the bolier plate code - now lets get the work done by first getting our data that the user entered in the UI

    String hostname = preferences.getSimpleValue("hostname","localhost");
    String portS = alertParameters.getSimpleValue("port","80");

    Then construct an URL and URL connection

    HttpURLConnection conn = null;
    try {
    URL url = new URL("http://" + hostname + ":" + portS);
    conn = (HttpURLConnection) url.openConnection();
    conn.setRequestMethod("POST");
    conn.setDoOutput(true);
    conn.setDoInput(true);
    OutputStream out = conn.getOutputStream();

    Then we get the message together - you see, you can even call into the EJB layer to get things done - and send it off.
         
    AlertManagerLocal alertManager = LookupUtil.getAlertManager();
    StringBuilder b = new StringBuilder("Alert: '");
    b.append(alert.getAlertDefinition().getResource().getName());
    b.append("' (");
    b.append(alert.getAlertDefinition().getResource().getId());
    b.append("): ");
    b.append(alertManager.prettyPrintAlertConditions(alert));
     
    out.write(b.toString().getBytes());
    out.flush();
    conn.connect();
    } catch (Exception e) {
    return new SenderResult(ResultState.FAILURE,"Sending failed " + e.getMessage());
    }
    finally {
    if (conn!=null)
    conn.disconnect();
    }
     
    return new SenderResult(ResultState.SUCCESS,"Sending to " + hostname + ":" + portS + " worked");
    }
    }

    After this was done, we return our operation result in a new SenderResult object - that's all.

    Now just change back to the root directory (the one with the pom.xml file) and fire "mvn install". This leaves you with a jar archive in target/ that you can then deploy into a (running) server:

    Deploying the plugin



    You can deploy the plugin in three ways, where the first one is probably the best, when developing such a plugin:

    • run mvn install above with option -Pdev - this will automatically deploy into the development containter
    • copy the plugin manually into the dropbox at $RHQ_SERVER/plugins (that directory is in parallel to bin/ and jbossas/ )
    • Deploy via GUI:


      • Go to the plugins page
        Bildschirmfoto 2009-12-15 um 21.00.37.png


        and select server plugins at the top tab
      • Scroll down to the upload box, select add, select the plugin in the open dialog and then when done, click on "upload".
      • Press "scan for updates" at the bottom of the plugin list above - it should now show up in the list of plugins


    Configuring it



    Click on "Alert:Url" in the list of plugins. This will bring you to the plugin details. And then on "Configure Alert:Url" (configuring could also happen from the Administration->System Configuration->Settings menu).

    You will see a list of plugins where the Alert:Url one is selected on the left and the current site wide preferences on the right:

    Bildschirmfoto 2009-12-15 um 21.41.18.png


    If you click on Edit, you can edit the host to some other value than the default.

    Using it in an alert definition




    Go to the usual screen for alert definitions of a resource - in the preliminary gui, there is a link To Alert sender plugins; click it.

    You will come to a screen with a drop down - select Url from it

    THIS UI IS CURRENTLY WORK IN PROGRESS

    Click on "Go" and then in the configuration enter the port number to use. Click on "submit it".

    Done

    Congratulations


    you have just written and deployed your first alert sender plugin for RHQ and Jopr




Monday, December 14, 2009

How to write an alert sender plugin for RHQ/Jopr (Part 1)

Now that RHQ 1.4.0-B01 is out, it is time to show you how you can easily write your own alert notification mechanism and plug it into RHQ (see also "RHQ and the future of alerts").

As an example we'll use a sender that will use a http-POST request to a remote host where the body of the request will contain the alert message (like the one you know from the existing email-sender).

But before we do this, I'll show you the bits involved, so that the source code is easier to understand.

In order to write the plugin you need two things at least:

  • plugin descriptor

  • a sender class


Sometimes you also want to implement a component class (more later).

So lets have a look at them in turn:

Plugin descriptor



The structure of the plugin descriptor, rhq-serverplugin.xml, looks like this:

rhq-serverplugin-alert.png


It follows the schema definition in rhq-serverplugin-alert.xsd.
Elements in it are the following.
  • alert-plugin: This is the parent element for the whole descriptor. It contains the following attributes, which are all taken from the general server plugin descriptor:

    • name: name of the plugin

    • displayName: name of the plugin as it shows up in the UI

    • package: the package of the plugin. Is used to determine the fully qualified class name if it contains no package. Within RHQ, there is a naming convention of Alert:medium for this

    • description: A description of the plugin as it shows up in the list of plugins

    • version: the version of the plugin.




The first few child elements come from the general server-plugin descriptor and apply to all server side plugins.

  • help: general information about the plugin, that also shows up in the list of plugins

  • plugin-component: class name of a class that gets loaded on plugin start and stays there as a "singleton" until unload. See below.

  • scheduled-jobs: this is a configuration that allows you to have your plugin code be run at regular intervals; it is probably less of interest for alert senders

  • plugin-configuration: properties listed here will end up in the system-wide preferences system UI and serve to do general configuration of the plugin (like e.g. the name of a remote host where alert notifications should be sent to)


The next batch of elements is specific to the alert-plugins:

  • short-name: the short name of the sender. This is used e.g. in UI drop downs to select the sender

  • plugin-class: the name of the class that implements the abstract AlertSender class to build the actual sender.

  • alert-configuration: specific properties on a per AlertDefinition basis. This can e.g. be the list of email addresses the alert notification should be sent to.

  • custom-ui: this element is not yet active and is supposed to help building a custom UI if the UI via alert-configuration is not powerful enough.



The sender class



All senders need to extend the class org.rhq.enterprise.server.plugin.pc.alert.AlertSender which looks a little like this:

public abstract class AlertSender {
 
/** Configuration from the global per plugin type preferences */
protected Configuration preferences;
 
/** Configuration from the per alert definition parameters */
protected Configuration alertParameters;
 
/** Global component holding persistent resources */
protected T pluginComponent;
 
/** Do the work */
public abstract SenderResult send(Alert alert) ;
}


The method of interest is send(Alert) where you get the data for this specific alert passed in. You need to implement it.

The preferences or the alert definition specific properties are injected by the RHQ server, as well as the plugin component, so that you can just get your properties that you set up in the deployment descriptor via calls like this:

String hostname = preferences.getSimpleValue("hostName","localhost");

assuming that you have the following in the plugin descriptor:

....
<serverplugin:plugin-configuration>
<c:simple-property name="hostName" />
</serverplugin:plugin-configuration>
...


Component class (optional)



The component class is a class that implements the interface org.rhq.enterprise.server.plugin.pc.ServerPluginComponent. It can be used to e.g start up a connection to a remote host within the start() method and tear it down when stop() is called. You need to expect that start() and stop() can get calles multiple times during the life of a plugin.

The interface has two more methods: initialize() and shutdown() - those are called directly after loading and before unloading an alert sender. The idea here could e.g. to load an external library and unload it at plugin unload.

The component class is a "singleton" in the lifecycle of a server plugin and stays present while the plugin is loaded. It is optional for alert Plugins - if it is present, it will be injected into AlertSender.pluginComponent.

Plugin structure



The alert sender is created in the standard Maven-2 directory structure. Java sources go into src/main/java/, while the plugin descriptor goes into src/main/resources/META-INF/rhq-serverplugin.xml:

File system structure for an alert sender plugin


Round up


Ok, that's it for now. You have seen what is involved in writing an alert sender plugin for RHQ and Jopr (versions 1.4.0.B01 and up).

As always give me and us feedback - e.g. via Irc at #rhq on freenode.


Continue with part 2...

Friday, December 11, 2009

RHQ 1.4.0.B01 released - includes Jopr

The RHQ project is pleased to announce the release the first developer build of the RHQ 1.4.0 platform. This developer release, 1.4.0-B01, provides an early looks at the new features which we are planning for the 1.4.0. This release contains many of the plugins which had been available as part of the Jopr project, along with the plugins that were included in previous RHQ releases.

Note: we do not advise to upgrade any existing Jopr or RHQ installs with this build!

Check out the
Release notes.

And
download the software.
The individual maven project artifacts have been published to the JBoss maven repository under org/rhq/ and org/jboss/on/.

Source code can be found in the git repository at fedorahosted.

If you have questions, join us on #rhq on irc.freenode.net or use the mailing lists:

Of course you can still use the existing mailing lists and forums.

Tuesday, December 08, 2009

New experimental (ruby) script plugin for RHQ / Jopr (updated)

I've just committed an experimental 'script2' plugin to the RHQ git repository, that allows to write monitoring scripts in the Ruby programming language.

This plugin is not yet enabled in the normal build because of issues (see below) - if you want to have a look at it, go to modules/plugins/script2 and issue mvn -Pdev install.

To use the script, go to the platform and manually add a script2 resource
For the connection properties you need to specify the scripting language to use and the name of the script, which needs to exist at $AGENT/data/script2/ in the agents file system.

Your script needs to provide 3 functions: avail, metric(name) and trait(name) - here is an example to show this. By default 4 metrics named 'metric1'..'metric4' are collected as well as one trait called 'trait1'.



def avail
return 1
end
 
def metric(name)
return 4
end
 
def trait(name)
return "Hello Ruby World: #{name}"
end




Unfortunately there is still one issue in the code that makes the scripting engine "forget" the script, so that after some time you'll see
exceptions like the following show up:

:1: undefined method `avail' for main:Object (NoMethodError)

If you have an idea what is going on, please tell me.


UPDATE
Thanks to Yoko Harada I was able to isolate the issue and fix it. Basically the issue is that the script was evaluated in one thread and later its methods got invoked in other threads which did not contain the evaluated script. So now I am just always re-evaluating the script before calling invokeFunction(). This is somewhat slower, but works.

It looks like if I would use the Red Bridge api directly (which is part of the JRuby 1.4 distro), there would be a better way, but the current implementation would allow for different scripting languages. Which brings me to:

Also if you want to help to get other languages implemented, contact me.

Friday, December 04, 2009

Facelets ui:include considered powerful

Just as a preface: I am very far from being a JSF or Facelets expert - more a novice.


So lately I have been looking at how to dynamically include Facelets or general xhtml snippets into my JSF/Facelets pages. One of the tags made for this is of course <ui:include>. In its src-attribute you give a path to a page to include like <ui:include src="/path/to/file.xhtml"/>. So far so cool.

Now I want to have the page to include to be dynamic - after a lot of googling I found that I can actually pass an EL expression like this <ui:include src="#{BackingBean.path}"/>. This did first not work at all, because I had a typo in the name of the backing bean - and I just got an error "there is an error" :-/ After the typo was fixed, I was able to get the path from the backing bean.

Now there are situations where my included page can or should not be shown.

First (naive) approach was (we are using RichFaces):

<rich:panel rendered="someCondition">
<ui:include src="#{BackingBean.path}"/>
</rich:panel>

But no matter the condition, BackingBean.path was evaluated and this could return something that does not point to the file, which screwed up the whole page with the above "there is an error" message.

So I ended up with creating an empty page, that I put into the webapp and my BackingBean.path now looks like this:


public String getPath() {
if (someCondition)
return stringExpression;
else
return "/path/to/empty.xhtml";
}


This works like a charm.

And I also found out that the src-attribute of ui:include actually is an URL, which means, that it is possible to get the included snippet from a remote web site or from within a Jar file like


public String getPath() {
URL pathUrl = getClassloader().getResource("nameOnClasspath");
return pathUrl.toString();
}


So yes, <ui:include> is a powerful feature of Facelets.

Thursday, November 26, 2009

RHQ and the future of alerts

So don't get me wrong, alerts will stay within RHQ - I am not questioning them.
In contrary - I am actually working on improving the alert subsystem. As a start I've written some design documents that can be found on the RHQ wiki:


Please go through them and give us feedback.

But before I continue - a little teaser:

Sms_alert.jpg


I've extended the Mobicents sender in my experimental branch (see 'Jopr talking') to also support sending via SMS now. So the image above shows an alert sent via that mechanism. Thanks to Jean Deruelle again for helping me on the Mobicents side.

But now back to future alert design...

We have identified the following four fields of change / improvement:

  • Allow for pluggable alert senders

  • Allow to acknowledge alerts by users

  • When a resource is in maintenance mode, do not send alerts about it

  • Escalate alert notifications if an alert is not reacted on


Of course some of those are meant for the future - e.g. there is no maintenance mode yet.

The first thing - which I am currently working on are pluggable alert senders. So if you want to e.g write a sender that posts alert notifications to an IRC channel, you can do so now. This is done in a pluggable fashion, which means that the code that does the work and also the UI is encoded in your plugin.

If you want to write such a plugin, you need to do two things:

Extend the abstract AlertSender class and write a plugin descriptor (here is the schema)

I've started an example on how to use this API.

Note that all of this is not yet finished and may change at any time - again I'd like to hear your feedback.

In the very first version only UI elements that follow a <configuration> will be supported. Later it will also be possible to supply a XHTHL snippet for UI fields, where you need to write your own backing beans to transfer the values into the alert subsystem.

Monday, November 23, 2009

Struts 1 and enums - heads up

I lost some good hours on the weekend trying to find out, why a field in my struts form bean was not filled with the correct value, while I could see in the HttpRequest, that the browser / page was indeed sending the correct data.

My form bean contained something like:

public class MyBean extends ValidatorForm {
 
private MyEnum anEnum;
private String someField;
 
public MyEnum getAnEmum() {...}
public void setAnEnum(MyEnum val) {...}
 
public String getSomeField() {...}
public void setSomeField(String val) {...}
}


Not only did my class compile well, I also did not get any errors when running the code - except that anEnum was always populated with the first value listed in MyEnum.

After I changed anEnum to String (and the getter/setter too) and did the conversion to Enum in the backend code, all was fine.

And yes, after I found the solution, I remembered, that we did have such an issue in the past already :-/