Enterprise Java

A Java EE 7 Application on OpenShift 3 With JBoss Tools

You can create and manage OpenShift applications in Eclipse with the latest version of the OpenShift Plugin for JBoss Tools. They are either pre-bundled with the latest

JBoss Developer Studio (9.0.0.GA) or you can install them into an existing Eclipse Mars. This post walks you through deploying the Java EE 7 Hands-On-Lab in OpenShift with the JBoss Developer Studio.

OpenShift 3 Tooling Overview

The OpenShift 3 tooling is included as a TechPreview. It will allow you to connect to OpenShift 3 servers using OAuth or Basic authentication, manage your OpenShit 3 Projects, deploy new applications in the Cloud, using pre-defined (or your own) templates, or even Docker images. You will be able to import existing applications in your workspace, monitor them via remote log streaming directly into your local console, or enable Port-Forwarding and access their data as if it was local.

Get Started

Install the OpenShift 3 all-in-one VM and start your local instance with vagrant. Login via the oc command-line tool with admin/admin and get your OAuth token:

oc login https://localhost:8334
oc whoami -t

And while we’re at the command line, let’s create a new OpenShift project for this example.

oc new-project javaeehol --display-name="Java EE 7 HOL w/ WildFly MySql"

1_create_os3_connection

Install and fire up your JBoss Developer Studio. If you want to get started with the JBoss Tools in an existing Eclipse distribution use this package from the Eclipse marketplace.

Create a new OpenShift Project. Select OpenShift 3 as server type, change the server to https://localhost:8443 and enter the token you gathered from the cli into the token field. When you click next, the credentials are verified and you need to accept a warning about an unsigned certificate when using the all-in-one vm.

Select the project from the first drop down list in the next dialogue. The dialogue also lists all available templates on your server.A complete list can befound on github. We want to use our own template in this case. The Java EE 7 Hands-On-Lab has been converted into a Kubernetes template by Ben Pares. So, we’re going to use this. Download it from Ben’s Github repository and save it locally.

Open it with a text editor and change the “apiVersion” value from v1beta3 to “v1”. And in line 47 is a host entry which says: “www.example.com”, change that to “jee-sample.openshiftdev.local”. And while you are in a text-editor make sure to add an entry to your hosts file which maps the loopback interface to the changed domain name.

127.0.0.1 jee-sample.openshiftdev.local

Now back to JBDS.

jbds-eap7-server
Select “Use a template from my local file system” and browse to the place you saved it.

After clicking next you see another dialogue which allows you to change the template parameter values for the various passwords. Leave everything as it is and click “next” again.

The following dialogue will let you add additional labels. Just click “Finish” now.

The final dialogue gives you an overview about the executed actions and generated passwords. Make sure to write them down in case you need them later.

You can also access the github web-hook secrets and URLs. After clicking “ok” a last wizard clones the application from github into a folder of your choice locally. It get’s opened in JBDS and you can browser through the various resources and explore the example a bit. While you’re doing that, OpenShift actually triggered a build of the sample application. When you point your browser to the web-console at http://localhost:8443/ and login with admin/admin and select the javaee project, you can see the mysql service running and a build job:

openshift-console

After a couple of minutes, this one finishes and you see the running frontend-service. Let’s briefly look into the build logs:

oc get builds #Shows the one successful build
oc build-logs  jee-sample-build-1  #Shows the log output for the build

Everything looks good. You can see, that the maven dependencies are downloaded and looking at the various image streams with:

oc get is

you can see, that there are two:

NAME         DOCKER REPO                                TAGS      UPDATED
jee-sample   172.30.236.154:5000/javaeehol/jee-sample
wildfly      openshift/wildfly-90-centos7               latest    57 seconds ago

OpenShift actually build a new docker image with the javaee-hol in it and deploys the result as a new pod. Time to see everything in action. Point your browser to http://jee-sample.openshiftdev.local:1080/movieplex7-1.0-SNAPSHOT/ and see the Movieplex application in action.

movieplex

Are you wondering about the weird port? 1080 is actually a specialty of the OpenShift all-in-one-VM. Because, we assume that you already have a service running on port 80 and because of that, the NAT mapping in VirtualBox assigns port 1080 to port 80 on the OpenShift master. Unfortunately this makes some things in the OpenShift Eclipse tooling a little unhandy. But, it’s a local installation and has this one drawback. Let’s explore the tooling features a little bit more

OpenShift Explorer View – The embedded Web Console.

The OpenShift Explorer View lets you connect to OpenShift 3 instances, create new applications, manage domains or projects, execute action such as Port-Forwarding and Tail Files (Log Streaming). Specific actions are available, depending on the version of the OpenShift instance you’re connected to. For OpenShift 2 connections, you can configure cartridges, for OpenShift 3, you can access Pods, Routes, Services and deploy Docker images. Just expand the tree and right click on the resource you’re interested in. For example, like in the following screenshot to access the frontend logs.

jdbs-pod-logs

You can find even more details about the Docker Tooling and other features in the detailed feature description.

Learn Even More

Learn more about OpenShift Origin and how to get started with the All-In-One-VMTake the Java EE 7 Hands-On-Lab and follow the individual steps to get a refresher in Java EE 7. Follow @OpenShift on Twitter and stay up to date with latest news. Feel free to reach out to me in the comments or via Twitter @myfear.

Markus Eisele

Markus is a Developer Advocate at Red Hat and focuses on JBoss Middleware. He is working with Java EE servers from different vendors since more than 14 years and talks about his favorite topics around Java EE on conferences all over the world. He has been a principle consultant and worked with different customers on all kinds of Java EE related applications and solutions. Beside that he has always been a prolific blogger, writer and tech editor for different Java EE related books. He is an active member of the German DOAG e.V. and it's representative on the iJUG e.V. As a Java Champion and former ACE Director he is well known in the community. Follow him on Twitter @myfear.
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Back to top button