Friday, September 28, 2012

ADF Essentials in the RedHat Cloud (Glassfish / OpenShift)

VERSIONS / PLATFORM

ADF 11.1.2.3
GlassFish 3.1.2.2
RedHat OpenShift Cloud

INTRODUCTION

In this post we (Ulrich @GerkmannBartels (http://maybe-interesting.blogspot.com),@multikoop, www.enpit.de) are going to show how to setup the runtime environment for running ADF Essentials Applications on Glassfish in RedHats OpenShift Cloud. For the moment we are not going to connect to any database. What we are actually going to show is
  • Setup Glassfish on OpenShift Cloud
  • Configure appropriate JVM settings
  • Install ADF Share Libraries into Glassfish Domain
  • Deploy ADF Essentials Application (currently with no database access)

SETUP GLASSFISH ON OPENSHIFT CLOUD

Step 1: Sign up for free OpenShift account (if needed)
Goto https://openshift.redhat.com and register for a free account if you do not have one yet.
All you need is a valid emailadress. You will get 1.5G Memory and 3G Storage

Step 2: Create new Cloud Application
Login through the web interface and create a new application, i.e. adf with the Do-It-Yourself Catridge. This is pretty easy. Just log into your Openshift account and choose create application. Choose the following catridge



After that, just follow the instructions and you are done. This is really easy. Believe me!

Step 3: Prepare your client for the cloud
Well, this actually depends on your OS. You can read a detailed instruction about it here: https://openshift.redhat.com/community/get-started

On a Mac: Open Terminal and enter:

enpitmac:~ak$ sudo gem install rhc
Password:
Successfully installed jruby-pageant-1.1.1
.......
enpitmac:~ak$ 


This will install the RedHat Client tools. Test the availability of rhc via

enpitmac:~ ak$ rhc -version
rhc 0.98.16
enpitmac:~ ak$ 


Setup OpenShift environment on your client

enpitmac:~ ak$ rhc setup

Starting Interactive Setup for OpenShift's command line interface
...
To connect to openshift.redhat.com enter your OpenShift login (email or Red
Hat login id): <your id>
Password: *******
enpitmac:~ak$ 


Next step: I would like to access the cloud by ssh. So to get this, we need to setup up an SSH equivalence, which actually the red hat client tools are doing for us. For me it was done, when I just send the first command with rhc, i.e.

enpitmac: ak$ rhc app
Password: *******

Starting Interactive Setup for OpenShift's command line interface

It looks like you have not configured or used OpenShift client tools on this computer. We'll help you configure the client tools with a few quick questions.
..
..

The OpenShift client tools have been configured on your computer.  You can run this setup wizard at any time by using the command 'rhc setup' We will now execute your original command (rhc app)
..
enpitmac:~ ak$ 

Well, the command 'rhc app' does not exists, but it helped to setup the ssh equivalence.

Step 4: Install Glassfish
OK, now the fun part starts. After we have setup OpenShift, lets get glassfish running . The easiest way is to log into your open shift cloud through ssh and download the glassfish right into your repository directory.

Goto https://openshift.redhat.com/app/console/applications choose your application and then expand 'WANT TO LOG I TO YOUR APPLICATION' Item. Here you will see the ssh command which allows you to login from your local machine.


Once logged in grab the latest GlassFish binaries into your repository directory:

unzip glassfish-3.1.2.2.zip
...
Since it is not allowed to start more than one http-listener on port 8080 on openshift cloud, we have to adjust the glassfish domain.xml configuration. (Read more about this here: https://openshift.redhat.com/community/blogs/running-java-apps-in-the-cloud-with-glassfish-and-a-paas )

In order to make life easier you can download the preconfigured domain.xml from our server.

In short: it contains the following (main) changes which are needed in order to be able to run Glassfish for ADF Essentials on Openshift.

/domain1/config/domain.xml
a) REPLACE ALL: localhost with OPENSHIFT_INTERNAL_IP
b) deactivate http-listener2 (Openshift only allows to run one listener, no admin console will be available)

CONFIGURE APPROPRIATE JVM SETTINGS FOR ADF ESSENTIALS

c) ADJUST MaxPermSize to:
<
jvm-options>-XX:MaxPermSize=512m</jvm-options> 
d) Configure simple MDS Cache:
<
jvm-options>-Doracle.mds.cache=simple

C.4.3 How to Configure the JVM Cache 
for detailed instructions of the Oracle ADF Admin Guide.)


Start / Stop Glassfish by start / stop hooks of your OpenShift application

Adjust start script hook
adf/.openshift/action_hooks/stop
#!/bin/bash
# The logic to start up your application should be put in this
# script. The application will work only if it binds to
# $OPENSHIFT_INTERNAL_IP:8080
cd $OPENSHIFT_REPO_DIR/diy/glassfish3/glassfish/domains/domain1/config/
mv domain.xml domain.xml_2
sed 's/'$( grep serverName domain.xml_2 | cut -d\" -f 2 )'/'$OPENSHIFT_INTERNAL_IP'/g' domain.xml_2 > domain.xml
../../../bin/asadmin start-domain &> $OPENSHIFT_LOG_DIR/server.log


Adjust stop script  hook
adf/.openshift/action_hooks/stop
kill `ps -ef | grep glassfish3 | grep -v grep | awk '{ print $2 }'` > /dev/null 2>&1
exit 0

TEST if your Glassfish is running by typing from your client terminal

enpitmac:~ ak$ rhc app start -a adf
...
Result:
SUCCESS

Check on Browser

INSTALL ADF SHARE LIBRARIES FOR GLASSFISH

Well, the basis is done. Now we need to get the ADF Share Libraries onto Glassfish
C.3 Configuring GlassFish with ADF Runtime Libraries 
for detailed instructions of the Oracle ADF Admin Guide.)

Copy adf-essentials.zip onto the $GF_DOMAIN_HOME/lib with scp und unzip (with -j , this is important) 
enpitmac:~ ak$ scp Downloads/adf-essentials.zip @adf-multikoop.rhcloud.com:/var/lib/stickshift//adf/repo/diy/glassfish3/glassfish/domains/domain1/lib
adf-essentials.zip                                                                          100%   21MB  25.6KB/s   13:48   
enpitmac:~ ak$ ssh @adf-multikoop.rhcloud.com
...
[adf-multikoop.rhcloud.com ~]\> cd adf/repo/diy/glassfish3/glassfish/domains/domain1/lib
[adf-multikoop.rhcloud.com lib]\> unzip -j adf-essentials.zip
Archive:  adf-essentials.zip
Label: JDEVADF_11.1.2.3.0_GENERIC_120914.0223.6276.1
  inflating: adf-controller-security.jar 
  inflating: adf-share-security.jar 
...
[adf-multikoop.rhcloud.com lib]\>

Now restart glassfish to grab the changes!
adf-multikoop.rhcloud.com ~]\> ./adf/repo/.openshift/action_hooks/stop
..
adf-multikoop.rhcloud.com ~]\> ./adf/repo/.openshift/action_hooks/start
..

Create a simple ADF 11.1.2.3 Application and copy it into the autodeploy folder
enpitmac:~ ak$ cd Workspace/enpit-base/development/enpit.sample/enpit.sample.gf.app1/deploy/

enpitmac:deploy ak$ scp enpit-sample-app1.ear <.....>@adf-multikoop.rhcloud.com:/var/lib/stickshift/<...>/adf/repo/diy/glassfish3/glassfish/domains/domain1/autodeploy
enpit-sample-app1.ear                                                                       100%   64MB  18.1KB/s   59:55   
enpitmac:deploy ak$ 

(BTW: I must say the size of the EAR for ONE single ADF UI View just sucks: more than 60MB.  IMHO not ready for the cloud!)

Anyway, after doing all that above the running application should be satisfying ;)

WHAT'S NEXT

  • Hopefully Oracle will unveil the Oracle Cloud for everyone who wants to run / try out ADF ;). Please ! http://cloud.oracle.com

REFERENCES


10 comments:

  1. Hi,how did you deploy an EAR on Glassfish?
    The only Type one comes across is Web Application.
    When i tried to select EAR package, i get this:
    Error occurred during deployment: no container associated with application of type : ear. Please see server.log for more details.

    ReplyDelete
  2. my problem is when i try to deploy war, i get error:
    Error occurred during deployment: Exception while loading the app : java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: java.lang.IllegalArgumentException: java.lang.ClassNotFoundException: oracle.adf.share.glassfish.listener.ADFGlassFishAppLifeCycleListener

    could you come up with an idea?

    ReplyDelete
  3. Hello Bond Buster,

    a) having the GF Administration console / server you have many options too deploy the EAR. Right from the web interface or through the asadmin cli tool.

    For the deployment on Openshift I used the autodeploy feature which means just copying the EAR to the $DOMAIN/autodeploy directory.

    b) The EAR of course should be created by the correct deployment profile from within jdeveloper or ojdeploy. Otherwise the deployment will not work.

    c) Do not try to deploy the WAR. It will not work since Oracle writes the following in the dev guide "For Oracle ADF applications, WAR files can be deployed only as part of an EAR file" ;) See http://docs.oracle.com/cd/E35521_01/web.111230/e16182/appendix_glassfish.htm#ADFFD23812 for more information on "ADF on GlassFish".

    Best regards,
    Andreas

    ReplyDelete
    Replies
    1. Hello Bond Buster,

      Were you using a web profile at that time?
      You need to use the full glassfish profile to deploy an ear file.

      Kind Regards,
      Herman Mensinga

      Delete
  4. Hi i folllow this tutorial and i have my glassfish running. Then i add the MySql cartridge and create a database...so my question is how i create a datasource in my glassfish that points to the mysql cartridge. Since we dont have the console i try to modify the domain.xml config file but i have no success. Any ideas??? Sorry for my english.

    ReplyDelete
    Replies
    1. No, since i cant did that i try another solutions like Amazon EC2 or DigitalOcean or Jelastic :) . Did you find a solution?

      Delete
  5. Hello Sebastian,

    I am sorry but in that case I did not go further so I have to research myself. I hope there is some help in the Glassfish Community.

    Regards,
    Andreas

    ReplyDelete
  6. Hi Koop,

    It may be a silly question to ask, but I really didn't get following point as you said :
    "
    Once logged in grab the latest GlassFish binaries into your repository directory:
    [adf-multikoop.rhcloud.com diy]\> wget http://download.java.net/glassfish/3.1.2.2/release/glassfish-3.1.2.2.zip
    "

    I am on windows 7 and my command prompt says "wget" is invalid command, I have installed git and RHC Client tools and they are working fine.
    So please help me to configure GF Server.

    Thanks.

    ReplyDelete
    Replies
    1. Hi, I have not tested it from Windows Machines. The "wget command" is meant to be executed on the openshift cloud machine.

      If you are on Windows your best choice is to use Putty to log on to your openshift machine. Then everything should work as expected.

      Regards
      Andreas

      Delete
  7. I used the domain.xml from here: wget http://dl.enpit.de/adf/openshift/domain.xml. I'm assuming I don't have to do the other steps you've outlined. But when I try to start GF it says there are no domains. What am I doing wrong? Thanks!

    ReplyDelete