Red Hat release OpenShift PaaS as opensource, and ability to run your own PaaS with OpenShift Origin

Yesterday Red Hat announced at the Open Cloud Conference in Sunnyvale, CA, the release of OpenShift as open source, and the ability to take OpenShift and use it to run your own PaaS.

What does this mean? Firstly, you can take the source for OpenShift and view or modify it (under the Apache 2 license) as you please. Secondly, if you have a need to run your systems using a private cloud model locally or hosted using your own hosting provider, you can take OpenShift and deploy it where ever you need, and still take advantage of the ability to dynamically provision/deploy apps and services using the OpenShift toolset.

This is very similar to the approach VMWare have taken with Micro Cloud Foundry, which is also open source, and also available so you can run the PaaS yourself.

Troubleshooting your app on Red Hat’s OpenShift

My hosted server seems to not be responding or I’m getting a blank page instead of seeing my app:

  • Try tailing your server log and then hit your app to see if you’re getting errors:
rhc-tail-files -l your_account_id -a your_app_name
  • Give your account password and/or ssh passphrase when prompted

If you’re seeing exceptions from your app, this should give you a clue what’g going wrong.
If you’re seeing a a line in the log like this:

2012/04/03 13:08:59,601 INFO  [org.jboss.as.jpa] (MSC service thread 1-2) JBAS011403: Stopping Persistence Unit Service 'ROOT.war#persistenceUnit'
2012/04/03 13:09:00,152 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-1) JBAS015877: Stopped deployment ROOT.war in 20354ms

… then for some reason your app was stopped, and needs to be restarted manually. There are some ongoing issues in the OpenShift environment currently that Red Hat is investigating where apps are left in a stopped state (possibly related t your deployment taking too long and timing out).

Can I browse through my log files on the server?

ssh://long_string_here@your_app_name-your_domain_name.rhcloud.com/~/git/your_app_name.git/

… then the url to ssh to your server is this part:

long_string_here@your_app_name-your_domain_name.rhcloud.com

Ssh like this:

ssh long_string_here@your_app_name-your_domain_name.rhcloud.com

… enter your ssh passphrase when prompted. Your log files are in your_app_name/logs/ – the current log is server.log and there are copies of each log for each previous day. You can use common utils like vi/less/more/cat etc to view your files.

How do I check on the status of my app?

  • rhc-ctl-app -l your_acount_id -a your_app_name -c status

… this will show the status, either RUNNING, STOPPED, or if there is maintenance currently in progress you may see this message:

MESSAGES:
OpenShift is currently being upgraded, some services may be unavailable.

 

How do I manually restart or start my app?

  • rhc-ctl-app -l your_acount_id -a your_app_name -c restart | start

 

Installing and hosting a Joomla site on OpenShift

OpenShift have an example Joomla app ready to deploy on github, but it’s currently not working – once you’ve deployed it, it gives you a page with this error:

Infinite loop detected in JError

Given that it’s relatively simple to setup Joomla, I set up a new app on OpenShift, downloaded the latest install for Joomla, and then pushed it up to OpenShift. Using this approach you can walk through the admin screens to configure your site and point it to your hosted MySQL, and it’s just as easy as installing it locally.

Here’s the steps:

1. Create your PHP app on OpenShift:

rhc app create -a your_app_name -t php-5.3

2. Add the MySQL cartridge:

rhc app cartridge add -a your_app_name -c mysql-5.1

3. Download Joomla. Unzip the download into the php add inside your app dir that was created by ‘rhc app create’

4. Add, commit and push your changes to OpenShift:

git add .
git commit -m "Joomla initial commit"
git push

5. Now hit your URL for your hosted app, and then walk through the setup steps as normal. When prompted for your MySQL config, use the values given in step 2 above.

Configuring a Spring web app using JPA2 to use a JBoss datasource on OpenShift

By default, when creating a web app with Spring Roo, your JPA configuration is set up to use a Commons DBCP BasicDataSource. This works great for testing locally on Tomcat, but doesn’t work when deployed to the OpenShift environment, you’ll get errors like this as Hibernate tries to get connections and set up your schema based on your Entity mappings :

2012/03/08 18:17:03,423 ERROR [org.hibernate.tool.hbm2ddl.SchemaExport]
(MSC service thread 1-3) HHH000231: Schema export unsuccessful:
java.lang.UnsupportedOperationException: The application must supply JDBC connections

At the current time there isn’t a great deal of documentation on the Open Shift site that explains how to config your app to use a datasource, but this post on the community forum has some good clues (this one is Flex specific, but it mentions the standalone.xml JBoss config file).

When you add a database cartridge to your app in OpenShift, your JBoss in your environment is also configured with a DataSource using connection properties set up to access your MySQL (or other) db, and it’s ready to go.

To get your Spring Roo app configured to use the datasource requires a bit more effort. There’s various posts online about how to configure JPA2 to use a DataSource provided by a container, but getting all the right parts changed or removed in your existing config is a bit tricky. This post here lists all the steps needed, and most of the text below is taken from this post (thanks to the poster of this entry on the Spring forum as before I got to this stage I had already spent a few hours trying to piece this together) – here we go:

Edit src/main/resources/META-INF/spring/applicationContext.xml:

  • remove the BasicDataSource bean (the DataSource is now specified in persistence.xml)
  • remove the JpaTransactionManager bean
  • add <tx:jta-transaction-manager /> to look up JBoss’ JtaTransactionManager from JNDI instead. The default name of the bean using this tag is ‘transactionManager’
  • If you had previously used the <tx:annotation-driven> tag, make sure it’s transaction-manger attribute now uses ‘transactionManager’ (from the previous step):
<tx:annotation-driven mode="aspectj" transaction-manager="transactionManager"/>

 

  • remove the LocalContainerEntityManagerFactoryBean
  • add this bean:
<jee:jndi-lookup id="entityManagerFactory"
        jndi-name="your/app/MyEntityManagerFactory"
        expected-type="javax.persistence.EntityManagerFactory" />

Your EntityManagerFactory gets exposed by JBoss from the following changes to your persistence.xml files:

Edit src/main/resources/META-INF/persistence.xml:

  • change the persistence-unit’s “transaction-type” attribute from RESOURCE_LOCAL to JTA
  • add a child element to “persistence-unit” as follows:
<jta-data-source>java:/MyDSName</jta-data-source>

Add the following property to expose your EntityManagerFactory:

<property name="jboss.entity.manager.factory.jndi.name"
        value="your/app/MyEntityManagerFactory"/>