Using RedHat's OpenShift PaaS, you can run Java EE 6 applications on the cloud. JBoss offers support for Java EE 6 at this time. New GateIn 3.2.0 includes JBoss compatibility, which makes it a natural fit for the OpenShift platform as well. This blog explains how to set up an OpenShift account and deploy GateIn 3.2.0.
Before you can create an application, you need to create a domain. OpenShift Express uses non-strict domains (that is, there is no preceding period), and the domain name forms part of the application name. The syntax for the application name is applicationName–domainName.rhcloud.com.
Each username can only support a single domain, but you can create multiple applications within this domain. If you need multiple domains, you need to create multiple accounts using different usernames.
To create a new domain, run the rhc-create-domain command. For example, supposing you were to create the as7sample domain for the user email@example.com:
$ rhc-create-domain -n as7sample -l firstname.lastname@example.org -p password
In this command line, the –n option specifies the name of the domain that you want to create. The –l option is the e-mail address that you used to apply for your OpenShift Express account and –p as its password.
What if I need to develop my application from different hosts?
As explained before, communication between your computer and OpenShift Express happens over SSH using secure keys. So, in order to use your domain from different machines you need to copy SSH keys and the SSH configuration file from one machine to another so that you can use OpenShift Express on multiple computers. You should
also copy the express configuration file which is located at $HOME/.openshift/express.conf.
Having registered a domain, we will now use it to create an application. OpenShift is able to deliver a set of different server applications: you can mix and match Java, PHP, Perl, Python, and Ruby to your heart’s content. What really matters is that you deploy applications on a JBoss AS 7.0 platform using the Java EE 6 web profile.
Actually, the configuration of the JBossAS7 server used by the OpenShift Express JBoss cartridge is a simple modification of the JBoss 7.0.2. Final release (upgraded to 7.1.0 Alpha just before this book was going to be printed). The OpenShift Express release does contain some limitations concerning the amount of memory and the number of
processes which can be spawned by the application server.
From a conceptual point of view, an application can be seen as a container for one or more server-side components. The command used to create an application is rhccreate- app, which accepts multiple options. For a complete list of options run: $ rhc-create-app –help
Supposing we want to create an application named example using our credentials, we will issue:
Here, the –a option points to the application name, the -l flag stands for the user login name, -p is the password, -t is the application type (which, in our case, will be a JBoss 7.0 application), finally the -r option is used to point to a folder on your local filesystem where OpenShift will store all the data-related to your application. Part of
that data will be a local copy of the Git-versioning system. In the next section, we will return more in detail on the local repository.
When you issue the rhc-create-app, the SSL handshake will take place:
Creating remote application space: example
Successfully created application: example Adding rhcloud.com to ~/.ssh/config
Warning: Permanently added ‘exampleas7sample.
rhcloud.com,22.214.171.124′ (RSA) to the
list of known hosts.
Receiving objects: 100% (19/19), done. Confirming application example is available
Attempt # 1
Success! Your application is now published here:
Okay. Now, your domain contains an application namespace which can be verified by pointing to the URL where it has been published: https://exampleas7sample. rhcloud.com/.
In order to deploy artifacts in your application namespace, we need to use the Git local repository which has been created for us.
If you look beneath the application’s example folder, you will notice something familiar in it:
As you can imagine, the deployments folder performs the same task of the equivalent JBOSS_HOME/standalone/deployments directory. Applications placed in it will be candidate for uploading in the OpenShift repository.
So, now we need to create an application and deploy it there. As our first example, we will deploy a simple cloud service which renders a text file as a PDF—something that you might have searched for on the Internet at least once in your life!
This application consists just of a Servlet which translated the request into a PDF response, using the iText library (available at: https://itextpdf.com/download.php)
Next, we will package the application into a file named createpdf.war and we will bring it to the cloud. For this purpose, let’s copy the createpdf.war file into the deployments folder using the cp command: $ cp createpdf.war /home/francesco/example/deployments.
We need to add and commit our application to the Git repository using the git add and git commit command:
$ git add deployments/createpdf.war
$ git commit -m “First application on the cloud” deployments/ createpdf.war
[master 1637c21] Deploy createpdf application 1 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 deployments/createpdf.war
In practice, with the git add command, we tell Git to take a snapshot of the file createpdf.war. You can permanently store the contents of the index in the repository with git commit.
Your application has now been moved on the remote Git repository. The command git push will actual deploy the application on JBoss AS 7: git push
Finally, we are able to access our application using the OpenShift application name and domain, in addition to the web context: https://exampleas7sample. rhcloud.com/createpdf
Launching our application generates as result a PDF file: your first cloud application!
Having completed the first application in the next sections, we will now show you how to manage your Openshift Express applications and introduce some advanced features.
Watching what’s happening on the server
When you deploy or run your applications you might be interested to know what is happening on the server side. The most basic form of control on your application server is the console which produces some information, such as when an application is deployed or if it encountered any error.
Tailing for the application server logs is quite simple and you just need to use the rhctail- files for this. For instance, our example application can be watched using this shell:
Working in the cloud may be perceived a bit difficult, at first, because you don’t have your standard instruments to manage your applications. At the time of writing, the only available instrument to manage your applications is a command line, however a new web interface has been announced which will further simplify your application’s
In order to control your applications, you can use the rhc-ctl-app command, which accepts besides user credentials and info, the –c command, which allows basic application control.
The following is the list of available commands which can be used to manage your applications (you can get, at any time, the list of available options using the –help flag):
For example, supposing you want to delete your just created application example, you could use the following shell:
$ rhc-ctl-app -l email@example.com -p mypassword -a example -c
!!!! WARNING !!!! WARNING !!!! WARNING !!!!
You are about to destroy the example application. This is NOT reversible, all remote data for this application will be
Do you want to destroy this application (y/n): y
API version: 1.1.1
Broker version: 1.1.1
Successfully destroyed application: example
Stay updated with our newsletter, packed with Tutorials, Interview Questions, How-to's, Tips & Tricks, Latest Trends & Updates, and more ➤ Straight to your inbox!
|JBoss Training||Dec 02 to Dec 17||View Details|
|JBoss Training||Dec 05 to Dec 20||View Details|
|JBoss Training||Dec 09 to Dec 24||View Details|
|JBoss Training||Dec 12 to Dec 27||View Details|
Ravindra Savaram is a Technical Lead at Mindmajix.com. His passion lies in writing articles on the most popular IT platforms including Machine learning, DevOps, Data Science, Artificial Intelligence, RPA, Deep Learning, and so on. You can stay up to date on all these technologies by following him on LinkedIn and Twitter.
Copyright © 2013 - 2023 MindMajix Technologies