Favorite View Example


The Favoriate View is a very simple view example. It demonstrates the very basics of how to write and expose a REST service which works with instance parameters and instance data.


All views are packaged as a view archive. The view archive contains the configuration file and various optional components of the view.


The view.xml file is the only required file for a view archive. The view.xml is the configuration that describes the view and view instances for Ambari. The view.xml for this example defines two required parameters for configuring a view instance: what.is.the.question and i.do.not.know. The view also defines a single resource that exposes a REST service at the /favorite end point.

    <description>Ask a question</description>
    <description>If you do not know</description>


The view can be built as a maven project.

cd ambari-views/examples/favorite-view
mvn clean package

The build will produce the view archive.


Place the view archive on the Ambari Server and restart to deploy.

cp favorite-view-1.0.0.jar /var/lib/ambari-server/resources/views/
ambari-server restart

Create View Instance

With the view deployed, create an instance of the view to be used by Ambari users.


[ {
  "ViewInstanceInfo" : {
    "label" : "Colors",
    "description" : "Choose your favorite color",
    "properties" : {
      "what.is.the.question" : "What is your favorite color?",
      "i.do.not.know" : "green"
} ]

Access the view service end point:


To get the favorite color:


To set the favorite color: