Pages

Monday, April 7, 2014

Deploy a Custom Application into OpenShift

By now we have the funtest domain available in OpenShift. The next step is to create a sample custom application ,deploy that to the fundomain and access the application online.

Create a application "funtest" with Jboss 7. The application will deploy to the JBoss 7 Container

[root@vx111a funtest]# rhc app create -a funtest -t jbossas-7
Application Options
-------------------
Domain:     fundomain
Cartridges: jbossas-7
Gear Size:  default
Scaling:    no

Creating application 'funtest' ... done

Waiting for your DNS name to be available ... done

Initialized empty Git repository in /soa/openShift/funtest/funtest/.git/
Warning: Permanently added the RSA host key for IP address '50.16.11.24' to the list of known hosts.

Your application 'funtest' is now available.

  URL:        http://funtest-fundomain.rhcloud.com/
  SSH to:     537f2c545973caec750002b8@funtest-fundomain.rhcloud.com
  Git remote: ssh://537f2c545973caec750002b8@funtest-  fundomain.rhcloud.com/~/git/funtest.git/
  Cloned to:  /soa/openShift/funtest/funtest

Run 'rhc show-app funtest' for more details about your app.

So when we create the application using the above command , we can see a directory created at the current directory from where we ran the command.

The directory will be with the name of the application, funtest in this case. When you check the directory structure we can see a deployments directory , conf directory and pom.xml file.

Since this was a custom application, we dont need pom.xml file. remove the pom.xml file. For the demo purpose ,i have written a Sample web application by the name "sample-app.war"

Now copy the war file to the deployments directory. Once the copy is done we need to create a file called "applicationName.dodeploy" for telling the OpenShift to deploy the applicaiton.

touch Sample-app.war.dodeploy

The next thing to do is to copy the deployments to the OpenShift online account. For that we can use the rsync command provided by linux. run the below command

[root@vx111a funtest]# rsync -avz /soa/openShift/funtest/funtest/deployments/ 537f2c545973caec750002b8@funtest-fundomain.rhcloud.com:/var/lib/openshift/537f2c545973caec750002b8/app-deployments/2014-05-23_07-09-16.841/repo/deployments
sending incremental file list
./
.gitkeep
Sample-app.war
Sample-app.war.dodeploy

sent 1828 bytes  received 72 bytes  165.22 bytes/sec
total size is 2514  speedup is 1.32

There are few things that we need to , for copying the files we need to know the location where to copy the files. We get the below details when creating an application

URL:        http://funtest-fundomain.rhcloud.com/
SSH to:     537f2c545973caec750002b8@funtest-fundomain.rhcloud.com
Git remote: ssh://537f2c545973caec750002b8@funtest-  fundomain.rhcloud.com/~/git/funtest.git/
Cloned to:  /soa/openShift/funtest/funtest

for using the rsync command we need to use the Git Remote location given above.In the rsync command

/soa/openShift/funtest/funtest/deployments/ : the location in our local machine from where the war file is available

537f2c545973caec750002b8@funtest-fundomain.rhcloud.com : the OpenShift location where we need to copy the deployments

/var/lib/openshift/537f2c545973caec750002b8/app-deployments/2014-05-23_07-09-16.841/repo/deployments : the location on OpenShift where we need to deploy the applications

So for finding the location where we need to push the deployments ,we can get that by Connecting to the SSH location using , run the below command

ssh 537f2c545973caec750002b8@funtest-fundomain.rhcloud.com

Help menu: The following commands are available to help control your openshift
application and environment.

gear            control your application (start, stop, restart, etc)
                or deps with --cart      (gear start --cart mysql-5.1)
tail_all        tail all log files
export          list available environment variables
rm              remove files / directories
ls              list files / directories
ps              list running applications
kill            kill running applications
mysql           interactive MySQL shell
mongo           interactive MongoDB shell
psql            interactive PostgreSQL shell
quota           list disk usage

Deprecated:
ctl_app         control your application (start, stop, restart, etc)
ctl_all         control application and deps like mysql in one command
[dbtest-fundomain.rhcloud.com 537f4c0f50044652c1000265]\> mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.1.73 Source distribution

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

Now we will login to the remote OpenShift machine. We can see the directories available in the remote Machine.

Once the rsync command is completed ,we ca n go to this location and see that our deployments are copied.

/app-deployments/2014-05-23_07-09-16.841/repo/deployments

But some how even after deploying the application to this location , we cant access the application here. We need to copy the deployment war file to the /jboss/standalone/deployments/.

[funtest-fundomain.rhcloud.com deployments]\> ls
ROOT.war  ROOT.war.deployed  Sample-app.war  Sample-app.war.deployed

So the deployment is done, we can check the log files using

[funtest-fundomain.rhcloud.com 537f2c545973caec750002b8]\> tail_all
2014/05/23 07:09:49,435 INFO  [org.jboss.as.messaging] (MSC service thread 1-4) JBAS011601: Bound messaging object to jndi name java:/topic/test
2014/05/23 07:09:49,438 INFO  [org.jboss.as.messaging] (MSC service thread 1-4) JBAS011601: Bound messaging object to jndi name java:jboss/exported/jms/topic/test
2014/05/23 07:09:49,515 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-3) JBAS015876: Starting deployment of "ROOT.war"
2014/05/23 07:09:52,001 INFO  [org.jboss.web] (MSC service thread 1-1) JBAS018210: Registering web context:
2014/05/23 07:09:52,016 INFO  [org.jboss.as] (MSC service thread 1-3) JBAS015951: Admin console listening on http://127.10.221.1:9990
2014/05/23 07:09:52,016 INFO  [org.jboss.as] (MSC service thread 1-3) JBAS015874: JBoss AS 7.1.1.Final "Brontes" started in 18605ms - Started 211 of 330 services (116 services are passive or on-demand)
2014/05/23 07:09:52,125 INFO  [org.jboss.as.server] (DeploymentScanner-threads - 2) JBAS018559: Deployed "ROOT.war"
2014/05/23 07:32:24,313 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-1) JBAS015876: Starting deployment of "Sample-app.war"
2014/05/23 07:32:24,895 INFO  [org.jboss.web] (MSC service thread 1-4) JBAS018210: Registering web context: /Sample-app
2014/05/23 07:32:25,339 INFO  [org.jboss.as.server] (DeploymentScanner-threads - 1) JBAS018559: Deployed "Sample-app.war"

We can access the application using,
http://funtest-fundomain.rhcloud.com/Sample-app

Here are the Screen Shots,









More to come , Happy Learning

No comments:

Post a Comment