Pages

Monday, August 29, 2011

RHQ (Jopr)


1. What is RHQ (Jopr).
2. Database Preparation
3. Rhq Server Installation & Configuration
4. Rhq Agent Installation & Configuration

1. What is RHQ (Jopr).


According to the RHQ documentation

This pluggable project provides administration, monitoring, alerting, operational control and configuration in an enterprise setting with fine-grained security and an advanced extension model.

By Using RHQ we can monitor, manage various resources including JBoss server, Web Server, File system and other resources in the Operating System.

The Rhq includes a Rhq Server where we can see the resources that are to be managed, a database which holds the resources that are imported into the Rhq Server.

In this article, we will see how we can configure a RHQ server , Configure Database for the Server, the agent installation and Configuration e.t.c.

2. Database Preparation

For holding the Managed resources, the RHQ server use a database at the back. Rhq server supports Oracle and PostgreSql Databases. For this demo purpose I will install PostgreSql.

Download the PostgreSql 8.8.8-1 for the Linux Distribution from Here.

Now we need to install the Postgresql with a different userID rather that root.create a new User With name Postgres.

adduser postgres
passwd postgres

Once you have created the postgres userID and defined a password to it.Login in to postgres and install the Postgresql database.

For installation just go the location where the Postgresql was downloaded and run the command like

./postgresql-8.4.8-1-linux.bin 

Once the command is executed, you can see the installation of database is started.

It will be installed to /opt location if you select the default location to install.

Now once the installation is done, we now configure the PostgreSql server that suits for the RHQ 
server.

Execute the initdb command for postgresql from bin location like,

./initdb -D opt/PostgreSQL/8.4/data

It executes and shows the following output

The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.

The database cluster will be initialized with locale en_US.UTF-8.
The default database encoding has accordingly been set to UTF8.
The default text search configuration will be set to "english".

creating directory opt/PostgreSQL/8.4/data ... ok
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers ... 32MB
creating configuration files ... ok
creating template1 database in opt/PostgreSQL/8.4/data/base/1 ... ok
initializing pg_authid ... ok
initializing dependencies ... ok
creating system views ... ok
loading system objects' descriptions ... ok
creating conversions ... ok
creating dictionaries ... ok
setting privileges on built-in objects ... ok
creating information schema ... ok
vacuuming database template1 ... ok
copying template1 to template0 ... ok
copying template1 to postgres ... ok
.
.
.
Success. You can now start the database server using:
    ./postgres -D opt/PostgreSQL/8.4/data
or
    ./pg_ctl -D opt/PostgreSQL/8.4/data -l logfile start


Once this is executed, start the Server using postgres command from bin like,

./postgres -D opt/PostgreSQL/8.4/data &

This shows the following output,

[postgres@vx111a bin]$ ./postgres -D opt/PostgreSQL/8.4/data &
[postgres@vx111a bin]$ LOG:  database system was shut down at 2011-08-29 04:43:35 EDT
LOG:  autovacuum launcher started
LOG:  database system is ready to accept connections

While starting the Server, it may throw some security exceptions, at that point execute the below command as root,

chcon -t textrel_shlib_t '/opt/PostgreSQL/8.4/lib/libedit.so'

By this the server is up and running. Now we will create a user and Database by which we can login to server.

From the same bin location, execute command to create user

./createuser -h 127.0.0.1 -p 5432 -U postgres -S -D -R rhqadmin

And execute command to create a Database

./createdb -h 127.0.0.1 -p 5432 -U postgres -O rhqadmin rhq

By this the Installation of Database is done.

3. Rhq Server Installation & Configuration

Since the Database Configuration is done, its time to configure the Rhq Server. Download the Rhq Server from Here.

I download jopr2.3.1 for this demo purpose. Once the download is done extract to a location. Now move to the bin in /jopr-server-2.3.1/bin and execute the command,

./rhq-server.sh console

This command will start the JBoss server and once the server is up and running, we can see the admin console using,


The link will be like this




















Click On the “Click Here To Continue Installation” .













In The next page, you will various connection properties and other configuration stuff. Click On the “Test Connection” to see if the Server was able to get a connection to the Postgresql Database. Once the Connection is fine, Click on the button “Install Server” at the bottom of the Page.




















The installation will take a few minutes. Once the installation is done, we will see a link at the both saying “Done, Click here to get Started” .Click that and it will take you to a login page.




















Use the Credentials “rhqadmin” as both user name and password.

Once logged in, you can see the Server with not resources to manage.Now the Server installation is done.The next step would be do the Agent installation and configuration of the Agent.






















4. Rhq Agent Installation & Configuration

Once the server installation is done, its time to download the agent and configure it. The agent can be download using the link


Make sure you change any values if you configured differently. It will start to download a jar file (rhq-enterprise-agent-1.3.1.jar).Copy the jar file to a location (mostly besides where the rhq-server is downloaded).execute the command to install the agent like,



java -jar rhq-enterprise-agent-1.3.1.jar –install

Once the command is executed and the contents are extracted, go to the /rhq-agent/bin/ and execute the command,

/rhq-agent.sh –ln

It goes like this,

[root@vx111a bin]# ./rhq-agent.sh -ln
RHQ 1.3.1 [5183] (Wed Sep 16 14:17:12 EDT 2009)
Answer the following questions to setup this RHQ Agent instance.
- After each prompt, a default value will appear in square brackets.
  If you press the ENTER key without providing any value,
  the new preference value will be set to that default value.
- If you wish to rely on the system internal default value and
  not define any preference value, enter '!*'.
- If you wish to stop before finishing all the questions but still
  retain those preferences you already set, enter '!+'.
- If you wish to cancel before finishing all the questions and revert
  all preferences back to their original values, enter '!-'.
- If you need help for a particular preference, enter '!?'.

Agent Name [vx111a] : SampleAgent
Agent Hostname or IP Address [!*] :
Agent Port [16163] : 16162
RHQ Server Hostname or IP Address [127.0.0.1] :
RHQ Server Port [7080] :
The setup has been completed for the preferences at node [/rhq-agent/default].
> quit
Once the we configured the Agent,it now time to start the Agent.Execute the command from the same location,

 ./rhq-agent-wrapper.sh start

Now In the Rhq server console, click on the OverVvew -> DashBoard to see the new agents that we configured. Select the SampleAgent and click Import under that to make the resources imported. Now we can managed the resources that are imported.
















By this we complete the configuration of RHQ (Jopr) server and agent configuration.

More articles to Come. Happy Coding.











Read More

Sample MDB in JBoss 5


In this article we will see how we can create a sample Message Driven bean in EJBS3 using eclipse and deploy that in JBoss 5.The example simply takes some text from web application (index.jsp) and sends that to (WebClient.jsp) jsp page which has the code to access the EJBs and print the response from EJBs.

1. Create a Message Driven Bean

The First step in creating a sample EJB3 application is (in eclipse),
Select New -> EJB Project -> Enter The Project Name (ExampleMDB).
Select the Target Runtime as JBoss and EJB version as 3.0.Click next.
Click Next
Select the “Generate ejb-jar.xml”.Click Finish

Once the project is created, select the ejbModule -> Right click and create a Package (com.exmaple).Once the package is created, create a Message Driven Bean(ExampleMDBean) and add the code ,

package com.example;

import javax.ejb.ActivationConfigProperty;
import javax.ejb.MessageDriven;
import javax.ejb.MessageDrivenBean;
import javax.ejb.MessageDrivenContext;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.TextMessage;

@MessageDriven(name = "MessageMDBSample", activationConfig = {
        @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
        @ActivationConfigProperty(propertyName = "destination", propertyValue = "queue/MyQueue"),
        @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge")},
        messageListenerInterface = MessageListener.class)

public class ExampleMDBean implements MessageListener, MessageDrivenBean {

private static final long serialVersionUID = 1L;

    public ExampleMDBean() {
        // TODO Auto-generated constructor stub
    }

    public void ejbRemove() {
        // TODO Auto-generated method stub
    }

    public void setMessageDrivenContext(MessageDrivenContext arg0) {
     this.setMessageDrivenContext(arg0);
    }
    
    public void onMessage(Message mess) {
     TextMessage message=(TextMessage)mess;
     try {
System.out.println("Message Received"+message.getText());
}catch(Exception e) {
e.printStackTrace();
    }
        }
}


2. Create a Sample Web application to access the Stateless bean (ExampleMDBWeb).

For this, create a sample web application,in the WebContent,create 2 jsp pages which work in accessing the EJB’s.

WebClient.jsp

This page simply creates an InitialContext and will make a lookup for the Queue | Topic.

<%@ page import="javax.naming.*"%>
<%@ page import="javax.jms.*" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>

<%!

QueueConnection queueConnection=null;
QueueConnectionFactory queueFactory =null;
QueueSession queueSession =null;
Queue queue =null;
QueueSender queueSender =null;
TextMessage message =null;
public void jspInit() {
        try {
        
            InitialContext context = new InitialContext();
            queueFactory = (QueueConnectionFactory)context.lookup("/ConnectionFactory");
            queueConnection = queueFactory.createQueueConnection();
            queueSession = queueConnection.createQueueSession
                                         (false,javax.jms.Session.AUTO_ACKNOWLEDGE);
            queue = (Queue)context.lookup("/queue/MyQueue");
            queueSender = queueSession.createSender(queue);
            message = queueSession.createTextMessage();
            
            System.out.println("Configuration For Bean Done");

        } catch (Exception ex) {
            System.out.println("Error:"+ex.getMessage());
        }
    }

    public void jspDestroy() {      }
 %>
<%

try {
            String resultMessage = request.getParameter("message");
            message.setText(resultMessage);
            queueSender.send(message);
       %>
      
   <p>
      <b>The result is:</b> <% response.getWriter().println("Message Sent Successfully"); %>
     <p>
        
  <%
            }// end of try
                catch (Exception e) {
                             e.printStackTrace ();
    }
%>
        
</body>
</html>

Index.jsp

<form name="myForm" action="WebClient.jsp" method="post">
Enter Text Here<input type=text value="" name="message"/>
<input type=submit name="submit" value="Enter Test To Get Response"/>
</form>

This file contains nothing but a form which has a text field to send message to WebClient.jsp.

3. Create a EAR with both the Example EJB application (Example) and Web application (ExampleWeb).

Select New -> Java EE -> Enterprise Application project .Click next.
Enter the Name (ExampleMDBEAR ) and Click Next.In the Next screen select the Java EE modules (in this case both ExampleMDB and ExampleMDBWeb).Check the “Generate the application.xml” and click Finish.

Now once the ExampleMDBEAR is created, open the application.xml and modify the <context-root> to /example like
<context-root>/example<context-root>

4. Create a ear from the ExampleMDBEAR file and copy the file into all/deploy/ location. Start the Server.

If you check the logs, you can see similar INFO messages like,

2011-08-29 08:21:14,807 INFO  [org.jboss.ejb3.deployers.JBossASKernel] (HDScanner) Created KernelDeployment for: EampleMDB.jar
2011-08-29 08:21:14,807 INFO  [org.jboss.ejb3.deployers.JBossASKernel] (HDScanner) installing bean: jboss.j2ee:ear=ExampleMDBEar.ear,jar=EampleMDB.jar,name=MessageMDBSample,service=EJB3
2011-08-29 08:21:14,807 INFO  [org.jboss.ejb3.deployers.JBossASKernel] (HDScanner)   with dependencies:
2011-08-29 08:21:14,807 INFO  [org.jboss.ejb3.deployers.JBossASKernel] (HDScanner)   and demands:
2011-08-29 08:21:14,807 INFO  [org.jboss.ejb3.deployers.JBossASKernel] (HDScanner)  jboss.ejb:service=EJBTimerService
2011-08-29 08:21:14,807 INFO  [org.jboss.ejb3.deployers.JBossASKernel] (HDScanner)   and supplies:
2011-08-29 08:21:14,807 INFO  [org.jboss.ejb3.deployers.JBossASKernel] (HDScanner)  jndi:null
2011-08-29 08:21:14,822 INFO  [org.jboss.ejb3.deployers.JBossASKernel] (HDScanner)  Class:javax.jms.MessageListener
2011-08-29 08:21:14,822 INFO  [org.jboss.ejb3.deployers.JBossASKernel] (HDScanner) Added bean(jboss.j2ee:ear=ExampleMDBEar.ear,jar=EampleMDB.jar,name=MessageMDBSample,service=EJB3) to KernelDeployment of: EampleMDB.jar
2011-08-29 08:21:14,869 INFO  [org.jboss.ejb3.EJBContainer] (HDScanner) STARTED EJB: com.example.ExampleMDBean ejbName: MessageMDBSample
2011-08-29 08:21:15,086 INFO  [org.jboss.web.tomcat.service.deployers.TomcatDeployment] (HDScanner) deploy, ctxPath=/example

Check the Application using , http://localhost:Port Number>/example

More articles to come , Happy Coding.
Read More