Rise above the Cloud hype with OpenShift

Tutorial: Getting to grips with OpenShift - Part 2

            

Create your domain

To get started with our demo application we need to do a few simple things to get an OpenShift instance setup for hosting our Java application, beginning with a domain.

# We need to create the domain for OpenShift 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 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 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 which has been created and populated for you.

 

Create your application

Next we want to create our application, which means we want to tell OpenShift 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 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) (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,50.17.167.44' (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://1806d6b78bb844d49378874f222f4403@jbpmmigration-inthe.rhcloud.com/~/git/jbpmmigration.git/

 

To make changes to your application, commit to jbpmmigration/. Then run 'git push' to update your OpenShift 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 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 Openshift 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://1806d6b78bb844d49378874f222f4403@jbpmmigration-inthe.rhcloud.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-inthe.rhcloud.com/jbpmmigration_upload-0.2.

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 

Conclusion

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.

This completes our tour of the OpenShift 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 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.

----

Eric D. Schabell has been working within software development since 1998 for many different organizations such as IBM, Radboud University Nijmegen, SNS Bank and smaller software companies. He has been involved with Open Source projects such as Sourcemage Linux, eGroupWare, DocConversion, cmlFramework & still helping out in the JBoss jBPM project. Currently lead on jBPM Migration Project.

This article originally appeared in Java Tech Journal: PaaS Above The Cloud Hype. Check out that issue and others of the new JAX Magazine here

Pages

Eric Schabell
Eric Schabell

What do you think?

JAX Magazine - 2014 - 06 Exclucively for iPad users JAX Magazine on Android

Comments

Latest opinions