1 /** 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the 7 * "License"); you may not use this file except in compliance 8 * with the License. You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 19 package org.apache.hadoop.yarn.webapp.example; 20 21 import org.apache.hadoop.classification.InterfaceAudience; 22 import org.apache.hadoop.yarn.webapp.Controller; 23 import org.apache.hadoop.yarn.webapp.WebApps; 24 import org.apache.hadoop.yarn.webapp.view.HtmlPage; 25 26 /** 27 * The obligatory example. No xml/jsp/templates/config files! No 28 * proliferation of strange annotations either :) 29 * 30 * <p>3 in 1 example. Check results at 31 * <br>http://localhost:8888/hello and 32 * <br>http://localhost:8888/hello/html 33 * <br>http://localhost:8888/hello/json 34 */ 35 @InterfaceAudience.LimitedPrivate({"YARN", "MapReduce"}) 36 public class HelloWorld { 37 public static class Hello extends Controller { index()38 @Override public void index() { renderText("Hello world!"); } html()39 public void html() { setTitle("Hello world!"); } json()40 public void json() { renderJSON("Hello world!"); } 41 } 42 43 public static class HelloView extends HtmlPage { render(Page.HTML<_> html)44 @Override protected void render(Page.HTML<_> html) { 45 html. // produces valid html 4.01 strict 46 title($("title")). 47 p("#hello-for-css"). 48 _($("title"))._()._(); 49 } 50 } 51 main(String[] args)52 public static void main(String[] args) { 53 WebApps.$for(new HelloWorld()).at(8888).inDevMode().start().joinThread(); 54 } 55 } 56