Apache Ambari: Hello World!

Ambari-logo-300x141

Hello World with Ambari Views

Previously, I gave a brief overview of what an Ambari View is and how it can be beneficial to you.Let’s dive in!

First, make sure you have IntelliJ installed on your computer with JDK 1.8 installed.

intellij.PNG

  1. Create a new Maven project!
    1. File>New>Project…>Choose your SDK location
    2. Enter your groupID (you can just make this up! org.hadoopsters.tutorials is fine) and artifactID (ambari-views)
    3. Pick a location to save this project, I like to keep all of my Ambari Views in one area: C:\Users\jbarney\IdeaProjects\ambai-views\<view-name>
    4. Click finish and you’ll have a new project!
  2. IntelliJ should open up to your project’s pom.xml, the dependency management file for Maven projects. You’ll want to make yours look like mine:
    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
    
        <groupId>org.hadoopsters.tutorials</groupId>
        <artifactId>hello-world</artifactId>
        <version>1.0-SNAPSHOT</version>
        <dependencies>
            <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <version>4.8.1</version>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>org.easymock</groupId>
                <artifactId>easymock</artifactId>
                <version>3.1</version>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>org.apache.ambari</groupId>
                <artifactId>ambari-views</artifactId>
                <version>[1.7.0.0,)</version>
            </dependency>
            <dependency>
                <groupId>com.sun.jersey</groupId>
                <artifactId>jersey-server</artifactId>
                <version>1.8</version>
            </dependency>
        </dependencies>
    
    </project>
  3. Now we add some files to our view!
    1. In the project’s structure, navigate to src>main>resources and create two files:
      1. index.html
        <html>
            <head>
                <title>Hello world!</title>
            </head>
            <body>
                <h1>Hello world!</h1>
            </body>
        </html>
      2. view.html
        <view>
            <name>HELLO_WORLD</name>
            <label>The Hello World View!</label>
            <version>1.0.0</version>
            <instance>
                <name>INSTANCE_1</name>
            </instance>
        </view>
    2. These two files are all you need to build your first Ambari View.
  4. Create your Ambari View’s jar file.
    1. Click File > Project Structure > Artifacts > + > Jar > From modules with dependencies > Ok
    2. Then click Apply and Ok at to confirm adding that artifact to your project
    3. Click Build > Build Artifacts > hello-world:jar > Build
    4. Should take a few seconds, if IntelliJ says it needs to import dependencies, allow it to.
  5. Now you should have a hell0-world.jar file sitting in hello-world>out>artifacts>hello_world_jar. We need to move that to our cluster. Use WinSCP or Filezilla or any other file transfer program to move it over.
  6. Log in as root where your Ambari Server is installed and copy the jar to /var/lib/ambari-server/resources/views/ambari-views
  7. Now restart Ambari
    ambari-server restart
  8. Navigate to http://your-ambari-server:8080/#/main/views/HELLO_WORLD/1.0.0/INSTANCE_1

All done! If everything worked, you should see HELLO WORLD in big bold <h1> letters!

For more information, go here: https://github.com/apache/ambari/tree/trunk/ambari-views/examples

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s