|Rise above the Cloud hype|
In this article will walk you through the simple steps it takes to setup not one, not two, not three, but up to five new machines in the Cloud with OpenShift. You will have your applications deployed for development, testing or to present them to the world at large in minutes. No more messing around.
We start with an overview of what OpenShift is, where it comes from and how you can get the client tooling setup on your workstation. You will then be taken on a tour of the client tooling as it applies to the entry level of OpenShift, called Express. In minutes you will be off and back to focusing on your application development, deploying to test it in OpenShift Express. When finished you will just discard your test machine and move on. When you have mastered this, it will be time to ramp up into the next level with OpenShift Flex. This opens up your options a bit so you can do more with complex applications and deployments that might need a bit more fire power. After this you will be fully capable of ascending into the OpenShift Cloud when you chose, where you need it and at a moments notice. This is how development is supposed to be, development without stack distractions.
|Dorking with the stack?|
There is a great amount of hype in the IT world right now about Cloud. There is no shortage of acronyms for the various areas that have been carved out, like IaaS, PaaS and SaaS. OpenShift is a Platform as a Service (PaaS) from Red Hat which provides you with a platform to run your applications. For you as a developer, you want to look at the environment where you put your applications as just a service that is being provided. You don't want to bother with how that service is constructed of a set of components, how they are configured or where they are running. You just want to make use of this service that they offer to deploy, develop, test and run your application. At this basic level, OpenShift provides a platform for your Java applications.
First let's take a quick look at where OpenShift comes from. It started at a company called Makara that was based in Redwood City, Calif., providing solutions to enable organizations to deploy, manage, monitor and scale their applications on both private or public clouds. Red Hat acquired Makara in November of 2010, and in the following year they have merged Red Hat technologies into a new project called OpenShift. They launched a first project that initially provides two levels of service, a shared hosting solution called Express and a dedicated hosting solution known as Flex. What makes this merging of technologies interesting for a Java developer is that Red Hat has included the next generation application platform based on JBoss AS 7 in OpenShift. This brings a lightning fast application platform for all your development needs.
Getting started in Express is well documented on the website as a quick start, which you can get to once you have signed up for a Red Hat Cloud (rhcloud) account. This quick start provides us with the four steps you need to get our application online and starts with the installation of the necessary client tools. This is outlined for Red Hat Enterprise Linux (RHEL), Fedora Linux, generic Linux distributions, Mac OS X and Windows. For RHEL and Fedora it is a simple package installation, for the rest it is a Ruby based gem installation which we will leave for the reader to apply to her system.
Once the client tooling is installed, there are several commands based on the form rhc-<command>. There is an online interface available but most developers prefer the control offered by the command line client tools so we will be making use of these. Here is an overview of what is available with a brief description of each:
- rhc-create-domain – used to bind a registered rhcloud user to a domain in rhcloud. You can have maximum of one domain per registered rhcloud user.
- rhc-create-app - used to create an application for a given rhcloud user, a given development environment (Java, Ruby, Python, Perl, PHP) and for a given rhcloud domain. You can create up to five applications for a given domain. This will generate the full URI for your rhcloud instance, setup your rhcloud instance based on the environment you chose and by default will create a local git project for your chosen development environment.
- rhc-snapshot – used to create a local backup of a given rhcloud instance.
- rhc-ctl-app – used to control a given rhcloud application. Here you can add a database, check the status of the instance, start, stop, etc.
- rhc-tail-files – used to connect to a rhcloud applications log files and dump them into your command shell.
- rhc-user-info – used to look at a given rhcloud user, the defined domains and created applications.
- rhc-chk – used to run a simple configuration check on your setup.
Create your domain
To get started with our demo application we need to do a few simple thing to get an Express instance setup for hosting our Java application, beginning with a domain.
# We need to create the domain for Express to start setting up # We need to create the domain for Express to start setting up # our URL with the client tooling using # rhc-create-domain -n domainname -l rhlogin # $ rhc-create-domain --help Usage: /usr/bin/rhc-create-domain Bind a registered rhcloud user to a domain in rhcloud. NOTE: to change ssh key, please alter your ~/.ssh/libra_id_rsa and ~/.ssh/libra_id_rsa.pub key, then re-run with --alter -n|--namespace namespace Namespace for your application(s) (alphanumeric - max 16 chars) (required) -l|--rhlogin rhlogin Red Hat login (RHN or OpenShift login with OpenShift Express access) (required) -p|--password password RHLogin password (optional, will prompt) -a|--alter Alter namespace (will change urls) and/or ssh key -d|--debug Print Debug info -h|--help Show Usage info # So we setup one for our Java application. Note that we already have # setup my ssh keys for OpenShift, if you have not yet done that, # then it will walk you through it. # $ rhc-create-domain -n inthe -l [rhcloud-user] -p [mypassword] OpenShift Express key found at /home/[homedir]/.ssh/libra_id_rsa. Reusing... Contacting https://openshift.redhat.com Creation successful You may now create an application. Please make note of your local config file in /home/[homedir]/.openshift/express.conf which has been created and populated for you.
Create your application
Next we want to create our application, which means we want to tell the OpenShift Express which stack we need. This is done with the rhc-create-app client tool.
# Let's take a look at the options available before we setup a Java # instance for our application. # $ rhc-create-app --help Contacting https://openshift.redhat.com to obtain list of cartridges... (please excuse the delay) Usage: /usr/bin/rhc-create-app Create an OpenShift Express app. -a|--app application Application name (alphanumeric - max 16 chars) (required) -t|--type type Type of app to create (perl-5.10, jbossas-7.0, wsgi-3.2, rack-1.1, php-5.3) (required) -l|--rhlogin rhlogin Red Hat login (RHN or OpenShift login with OpenShift Express access) (Default: xxxxxxxxx) -p|--password password RHLogin password (optional, will prompt) -r|--repo path Git Repo path (defaults to ./$app_name) -n|--nogit Only create remote space, don't pull it locally -d|--debug Print Debug info -h|--help Show Usage info # It seems we can choose between several but we want the jboss-as7.0 # stack (called a cartridge). Provide a user, password and location # for the git repo to be created called 'jbpmmigration', see the # documentation for the defaults. Let's watch the magic happen! # $ rhc-create-app -a jbpmmigration -t jbossas-7.0 -l [rhcloud-user] -p [mypassword] -r /home/[homedir]/git-projects/jbpmmigration Found a bug? Post to the forum and we'll get right on it. IRC: #openshift on freenode Forums: https://www.redhat.com/openshift/forums Attempting to create remote application space: jbpmmigration Contacting https://openshift.redhat.com API version: 1.1.1 Broker version: 1.1.1 RESULT: Successfully created application: jbpmmigration Checking ~/.ssh/config Contacting https://openshift.redhat.com Found rhcloud.com in ~/.ssh/config... No need to adjust Now your new domain name is being propagated worldwide (this might take a minute)... Pulling new repo down Warning: Permanently added 'jbpmmigration-inthe.rhcloud.com,18.104.22.168' (RSA) to the list of known hosts. Confirming application jbpmmigration is available Attempt # 1 Success! Your application is now published here: http://jbpmmigration-inthe.rhcloud.com/ The remote repository is located here: ssh://firstname.lastname@example.org/~/git/jbpmmigration.git/ To make changes to your application, commit to jbpmmigration/. Then run 'git push' to update your OpenShift Express space .
If we take a look at my given path to the repo we find a git-projects/jbpmmigration git repository. Note that if you decide to alter your domain name you will have to adjust the git repository config file to reflect where the remote repository is, see above the line with 'ssh:.....'. Also the page is already live at http://jbpmmigration-ishereon.rhcloud.com/. It is just a splash screen to get you started, so now we move on to deploying our existing jBPM Migration project.
First lets look at the provided README in our git project which gives some insight to the repository layout.
Repo layout =========== deployments/ - location for built wars (Details below) src/ - maven src structure pom.xml - maven build file .openshift/ - location for openshift specific files .openshift/config/ - location for configuration files such as standalone.xml (used to modify jboss config such as datasources) ../data - For persistent data (also in env var OPENSHIFT_DATA_DIR) .openshift/action_hooks/build - Script that gets run every push, just prior to starting your app
For this article we only will examine the deployments and src directories. You can just drop in your WAR files, remove the pom.xml file in the root of the project and they will be automatically deployed. If you want to deploy exploded WAR files then you just add a file called '.dodeploy' as outlined in the README file. For real project development we want to push our code through the normal src directory structure and this is also possible by working with the provided pom.xml file. The README file provided gives all the details needed to get your started.
Our demo application, jbpmmigration also comes with a README file that provides the instructions to add the project contents to our new git repository, so we will run these commands to pull the files into our local project.
# placing our application into our express git repo. # $ cd jbpmmigration $ git remote add upstream -m master git://github.com/eschabell/openshift-jbpmmigration.git $ git pull -s recursive -X theirs upstream master # now we need to push the content. # $ git push origin [jbpmmigration maven build log output removed] ... remote: [INFO] ------------------------------------------------------------------------ remote: [INFO] BUILD SUCCESS remote: [INFO] ------------------------------------------------------------------------ remote: [INFO] Total time: 3.114s remote: [INFO] Finished at: Mon Nov 14 10:26:57 EST 2011 remote: [INFO] Final Memory: 5M/141M remote: [INFO] ------------------------------------------------------------------------ remote: ~/git/jbpmmigration.git remote: Running .openshift/action_hooks/build remote: Running .openshift/action_hooks/deploy remote: Starting application... remote: Done remote: Running .openshift/action_hooks/post_deploy To ssh://email@example.com/~/git/jbpmmigration.git/ 410a1c9..7ea0003 master -> master
As you can see we have now pushed our content to the rhcloud instance we created, it deployed the content and started our instance. Now we should be able to find our application online at http://jbpmmigration-ishereon.rhcloud.com/jbpmmigration_upload-0.4/.
The final step would then be that you are finished working on this application and want to free it up for a new application. You can then make a backup with the rhc-snapshot client tool and then remove your instance with rhc-ctl-app client tool.
# Ready to get rid of our application now. # $ rhc-ctl-app -a jbpmmigration -l eschabell -c destroy Password: ******** Contacting https://openshift.redhat.com !!!! WARNING !!!! WARNING !!!! WARNING !!!! You are about to destroy the jbpmmigration application. This is NOT reversible, all remote data for this application will be removed. Do you want to destroy this application (y/n): y Contacting https://openshift.redhat.com API version: 1.1.1 Broker version: 1.1.1 RESULT: Successfully destroyed application: jbpmmigration
As you can see, it is really easy to get started with the five free instances you have to play with for your application development. You might notice that there are limitation, with no ability to use specific integrated monitoring tooling, auto-scaling features are missing and control of the configuration is limited. For those needing more access and features, take a look at the next step up with OpenShift Flex.
This completes our tour of the OpenShift Express project where we provided you with a glimpse of the possibilities that await you and your applications. It was a breeze to create your domain, define your applications needs and import your project into the provided git project. After pushing your changes to the new Express instance you are off and testing your application development in the cloud. This is real. This is easy. Now get out there and raise your code above the cloud hype.
- Project overview OpenShift, https://openshift.redhat.com/app/platform.
- JBoss AS7 in the Cloud, http://www.jboss.org/openshift.
- jBPM Migration project web application, https://github.com/eschabell/jbpmmigration_upload.
- OpenShift Express Quick Start, https://openshift.redhat.com/app/express#quickstart.
- OpenShift Flex Quick Start, https://openshift.redhat.com/app/flex#quickstart.
Final note: I was asked at the end of 2011 to put together and introduction article to OpenShift, the Red Hat Platform as a Service (PaaS) open source project. It was to be published in a Dutch language magazine at the beginning of 2012. I wanted to post the English language version here for the rest of the non-Dutch speaking population.