As we have anticipated, when you create an application, you will have a local repository, which can be used for advanced cloud configuration. We have formerly discussed about the deployments folder. Besides this, there are some more interesting things in your Git repository. Looking under the .openshift folder, we see the following files:
[francesco@localhost .openshift]$ ls -al
drwxrwxr-x. francesco francesco 4096 10 sep 10.10 action_hooks
drwxrwxr-x. francesco francesco 4096 10 sep 10.42 config
drwxrwxr-x. francesco francesco 4096 10 sep 10.10 markers
The action_hooks contains a script named build which will be executed after git push and before the application is started.
The other folder named markers can be used to send some hints to the maven compiler. For example, the skip_maven_build marker file will instruct the maven compiler to skip the build process.
Most importantly, the config folder contains the following structure under it:
[francesco@localhost config]$ ls -al
drwxrwxr-x. francesco francesco 4096 sep 10.57 modules
-rw-rw-r–. francesco francesco 9495 sep 10.10 standalone.xml
Here, the standalone.xml file will be used as a configuration for your applications. You can actually use it to customize your application environment, though there are some limitations: for example, you cannot exceed the Java max heap at 128MB, and 83MB of PermGen.
Besides this, OpenShift Express users running the application are limited to about 100 processes, which translate to a max of 80 or so Java threads, so excessive thread creation can eat up available processes and begin to cause java.lang.OutOfMemoryErrors with a failure to create native thread cause.
In the next section, we will show how to modify the standard configuration by enabling the MySQL datasource contained in it.
Finally, the modules folder can be used to inject modules into your JBoss AS 7 environment, emulating the same folder, which we described in the local AS 7 distribution.
Well, every Enterprise application needs a storage for its data and OpenShift makes no exception to it. OpenShift Express provides up to 128MB of storage space for your application. You can also use your allocated storage space to store databases.
At the time of writing, the databases available on the Flex Platform are MySQL and PDOMySql (A PHP Database object). In order to embed the MySql database in your application, you have to pass the –e option to the rhc-ctl-app command, as shown next:
Okay, now you have a datasource registered under the java:jboss/datasources/MysqlDS JNDI namespace that is available for use by your applications.
The Flex framework is not surprisingly a more flexible instrument to deploy your application on the cloud. When using the Flex platform you have direct control over your PaaS environment, made up of a cluster of nodes.
The first difference with the Express platform is that OpenShift Flex provides a graphical user interface (GUI) that you can use to create, deploy, configure, manage, and monitor your cloud environment. Although OpenShift Flex is designed for commercial use, you can start your cloud environment with a free trial period.
At the time of writing, you need to link your OpenShift Flex account with an Amazon EC2 account. Navigate to the AWS home page at: HTTPS://CONSOLE.AWS.AMAZON.COM/EC2/HOME.
Enter your e-mail address and password and sign in. Next, you will be taken to the payment gateway, which requires entering credit card information. Don’t worry, you will not be billed during your trial period!
Once completed, the website displays a numerical security code; use your phone keypad to enter this code when prompted by the automated call from Amazon. Now, return to your Flex Console and enter your Amazon account. Click on Try it and Flex will link it to your OpenShift Flex account:
As a first step, you will define the name and the shape of your cluster of nodes:
Once you have defined the cluster name and the capabilities of your cloud of servers, you will be interviewed shortly with some basic questions about your plans with cloud and OpenShift. We will not detail this process and move to the application setup.
You are now ready to rock with the Flex platform. There are basically two ways to get started: you can either deploy a ready-made application, such as the Seam booking example.
See HTTP://DOCS.JBOSS.ORG/SEAM/LATEST/REFERENCE/EN-US/HTML/TUTORIAL.HTML), or you can deploy your own application.
Adding pre-built application is quite a straightforward task and it’s entirely driven by the Flex console. We will rather show how to deploy one of your applications. To make it more interesting, we will add it as a requirement to store some data in a no-SQL database like MongoDB .
Related Article: Deploying Applications on Jboss as 7
So, reach the Applications tab option in the upper area of the screen. You will see there are at the moment no running applications in your cluster. Click on the Add application button.
From there, choose an appropriate application name, such as NoSqlApp; flag the Create New option and select an application version. (this is to enable support for multiple versions in later releases of OpenShift Flex. Choose 1 in our case). Click on Submit.
Now, your application should be enlisted in the main application list. By clicking on the application name, you will be linked to the main application menu, which is composed of the following tabs:
Overview: This gathers generic information about the application components and, most important, it informs us the DNS name of the application, which we will use it to reach it from the browser.
Components: This window contains the components, which will be installed along the application, including application server components, JDK and additional frameworks like Infinispan cache or MongoDB database.
Files: These contain information about the application files. The application files can be added from here, or even from an SSH session.
Configure: It can be used to configure the specific components used by your application. For example, if you are using a MySQL database, you will configure in this tab the connection properties.
Deploy changes: This window is used to deploy your application files on the cluster.
Our first step will be selecting the resources used by our application, so move to theComponents menu. Here, select JBoss AS 7.0.0 (or higher) and a JDK 1.6. In the Other components frame, choose to add MongoDB component.
Fine, we will now deploy a simple application, which stores data in the no-SQL MongoDB and performs some basic searches.
Create a new Dynamic Web project, which contains the following Servlet in it:
As you can see, this Servlet basically connects to default test DB instance of MongoDB and, if not found, creates a collection of employee objects which include information about the employee’s name, surname. This information is linked with department and wage and stored using a JSON lightweight data-interchange format:
For the sake of brevity, we don’t include the welcome page, which is a basic HTML page, containing the name, surname, department, and wage input text fields, and submits to our Servlet the request.
Now package the web application into a file named mongoapp.war and move to the Files tab menu. From there, upload your web application as shown in the following screenshot:
We are almost done. Now, click on the Deploy changes tab and choose Save and Publish to publish your application. You application is now published and just need to be started from the main application menu.
In a couple of minutes, it will be up and running; we just need to know how to access our application. If you had a look at the Applications’ Overview tab, you might have noticed that it shows the cluster DNS address where the application can be reached:
In our example, point the browser to
and you will be redirected to the application’s landing page.
If everything works correctly, you will be able to store and display collection data stored in MongoDB. Nothing fancy, however it’s a good starting point for learning how to mix and match different available components.
Going beyond the basics of OpenShift Flex We have just mentioned some of the most interesting features of the OpenShift Flex platform. Although we cannot describe all the available options in one single chapter, we will mention two of the most interesting features, which are application scaling andmonitoring.
Application scaling can either be carried out manually by adding more servers to the cluster, as shown by the following screenshot:
Or you can enable the advanced auto-scale option, which is available in your Cluster subsection. Auto-scaling will automatically add or remove nodes to your cluster as required to meet the application demand of resources. This can be exceptionally useful to save expenditures in servers machines.
Monitoring is another key element of the Flex platform. Using the OpenShift Flex performance monitor tool, you can monitor the performance of each cloud container and its elements. You can view both current and historical performance data and charts for each element in your cloud environment.
The performance charts can be reached within your cloud environment at the Performance panel. The Performance screen displays five charts as defaults. You can, however, customize these charts to fit your cloud container view.
From the Performance panel, you can choose a timeframe by simply selecting a portion of the graph, which may identify, for example, a peak in the server activities:
The entire performance window is organized as a drag-and-drop portal where you can add or remove charts to your liking:
You can view more details about the performance with the performance transaction charts. For example, in the Transaction Times By Component chart, you can identify which transactions take the longest time to complete. Move over to various segments in the bar graphs to view the time taken by each software component for each transaction.
Free Demo for Corporate & Online Trainings.