Bootstrapping DropWizard apps with AppDynamics on OpenShift by Red Hat

image_pdfimage_print

Getting started with DropWizard, OpenShift, and AppDynamics

In this blog post, I’ll show you how to deploy a Dropwizard-based application on OpenShift by Red Hat and monitor it with AppDynamics.

DropWizard is a high-performance Java framework for building RESTful web services. It is built by the smart folks at Yammer and is available as an open-source project on GitHub. The easiest way to get started with DropWizard is with the example application. The DropWizard example application was developed to, as its name implies, provide examples of some of the features present in DropWizard.

DropWizard

OpenShift can be used to deploy any kind of application with the DIY (do it yourself) cartridge. To get started, log in to OpenShift and create an application using the DIY cartridge.

With the official OpenShift quick start guide to AppDynamics getting started with AppDynamics on OpenShift couldn’t be easier.

1) Signup for an account on OpenShift by RedHat

2) Setup RedHat client tools on your local machine

$ gem install rhc
$ rhc setup

3) Create a Do It Yourself application on OpenShift

$ rhc app create appdynamicsdemo diy-0.1
 --from-code https://github.com/Appdynamics/dropwizard-sample-app.git

Getting started is as easy as creating an application from an existing git repository: https://github.com/Appdynamics/dropwizard-sample-app.git

DIY Cartridge


% rhc app create appdynamicsdemo diy-0.1 --from-code https://github.com/Appdynamics/dropwizard-sample-app.git

Application Options
——————-
Domain: appddemo
Cartridges: diy-0.1
Source Code: https://github.com/Appdynamics/dropwizard-sample-app.git
Gear Size: default
Scaling: no

Creating application ‘appdynamicsdemo’ … done
Waiting for your DNS name to be available … done

Cloning into ‘appdynamicsdemo’…
Your application ‘appdynamicsdemo’ is now available.

URL: http://appdynamicsdemo-appddemo.rhcloud.com/
SSH to: 52b8adc15973ca7e46000077@appdynamicsdemo-appddemo.rhcloud.com
Git remote: ssh://52b8adc15973ca7e46000077@appdynamicsdemo-appddemo.rhcloud.com/~/git/appdynamicsdemo.git/

Run ‘rhc show-app appdynamicsdemo’ for more details about your app.

With the OpenShift Do-It-Yourself container you can easily run any application by adding a few action hooks to your application. In order to make DropWizard work on OpenShift we need to create three action hooks for building, deploying, and starting the application. Action hooks are simply scripts that are run at different points during deployment. To get started simply create a .openshift/action_hooks directory:

mkdir -p .openshift/action_hooks

Here is the example for the above sample application:

When checking out the repository use Maven to download the project dependencies and package the project for production from source code:

.openshift/action_hooks/build

cd $OPENSHIFT_REPO_DIR

mvn -s $OPENSHIFT_REPO_DIR/.openshift/settings.xml -q package

When deploying the code you need to replace the IP address and port for the DIY container. The properties are made available as environment variables:

.openshift/action_hooks/deploy

cd $OPENSHIFT_REPO_DIR

sed -i 's/@OPENSHIFT_DIY_IP@/'"$OPENSHIFT_DIY_IP"'/g' example.yml
sed -i 's/@OPENSHIFT_DIY_PORT@/'"$OPENSHIFT_DIY_PORT"'/g' example.yml

Let’s recap some of the smart decisions we have made so far:

  • Leverage OpenShift platform as a service (PaaS) for managing the infrastructure
  • Use DropWizard as a solid foundation for our Java application
  • Monitor the application performance with AppDynamics Pro

With a solid Java foundation we are prepared to build our new application. Next, try adding another machine or dive into the DropWizard documentation.

Combining DropWizard, OpenShift, and AppDynamics

AppDynamics allows you to instrument any Java application with by simply adding the AppDynamics agent to the JVM. Sign up for a AppDynamics Pro self-service account. Log in using your account details in your email titled “Welcome to your AppDynamics Pro SaaS Trial” or the account details you have entered during On-Premise installation.

The last step to combine the power of OpenShift and DropWizard is to instrument the app with AppDynamics. Simply update your AppDynamics credentials in the Java agent’s AppServerAgent/conf/controller-info.xml configuration file.

Finally, to start the application we need to run any database migrations and add the AppDynamics Java agent to the startup commmand:

.openshift/action_hooks/deploy

cd $OPENSHIFT_REPO_DIR

java -jar target/dropwizard-example-0.7.0-SNAPSHOT.jar db migrate example.yml

java -javaagent:${OPENSHIFT_REPO_DIR}AppServerAgent/javaagent.jar
     -jar ${OPENSHIFT_REPO_DIR}target/dropwizard-example-0.7.0-SNAPSHOT.jar
     server example.yml > ${OPENSHIFT_DIY_LOG_DIR}/helloworld.log &

OpenShift App

Additional resources on running DropWizard on OpenShift:

Take five minutes to get complete visibility into the performance of your production applications with AppDynamics Pro today.

As always, please feel free to comment if you think I have missed something or if you have a request for content in an upcoming post.

  • Zack Belcher

    Great post – thanks for sharing.

  • anthavio

    Nope. I’m getting.
    [Thread-0] 01 Nov 2014 15:41:32,434 ERROR ConfigurationChannel – Fatal transport error: Permission denied
    [Thread-0] 01 Nov 2014 15:41:32,434 WARN ConfigurationChannel – Could not connect to the controller/invalid response from controller, cannot get initialization information, controller host [paidXY.saas.appdynamics.com], port[80], exception [Fatal transport error: Permission denied]
    [Thread-0] 01 Nov 2014 15:41:32,442 WARN AgentErrorProcessor – Agent error occurred, [name,transformId]=[com.singularity.CONFIG.ConfigurationChannel - java.net .BindException,2147483647]
    [Thread-0] 01 Nov 2014 15:41:32,443 WARN AgentErrorProcessor – 4 instance(s) remaining before error log is silenced
    [Thread-0] 01 Nov 2014 15:41:32,445 ERROR ConfigurationChannel – Exception: Permission denied
    java.net.BindException: Permission denied
    at java.net.PlainSocketImpl.socketBind(Native Method)
    at java.net.AbstractPlainSocketImpl.bind(AbstractPlainSocketImpl.java:382)
    at java.net.Socket.bind(Socket.java:644)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at org.apache.commons.httpclient.protocol.ReflectionSocketFactory.createSocket(ReflectionSocketFactory.java:139)

Copyright © 2014 AppDynamics. All rights Reserved.