hadoop-mapreduce-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From acmur...@apache.org
Subject svn commit: r1082677 [26/38] - in /hadoop/mapreduce/branches/MR-279: ./ assembly/ ivy/ mr-client/ mr-client/hadoop-mapreduce-client-app/ mr-client/hadoop-mapreduce-client-app/src/ mr-client/hadoop-mapreduce-client-app/src/main/ mr-client/hadoop-mapredu...
Date Thu, 17 Mar 2011 20:21:54 GMT
Added: hadoop/mapreduce/branches/MR-279/yarn/yarn-common/src/test/java/org/apache/hadoop/yarn/TestRPC.java
URL: http://svn.apache.org/viewvc/hadoop/mapreduce/branches/MR-279/yarn/yarn-common/src/test/java/org/apache/hadoop/yarn/TestRPC.java?rev=1082677&view=auto
==============================================================================
--- hadoop/mapreduce/branches/MR-279/yarn/yarn-common/src/test/java/org/apache/hadoop/yarn/TestRPC.java (added)
+++ hadoop/mapreduce/branches/MR-279/yarn/yarn-common/src/test/java/org/apache/hadoop/yarn/TestRPC.java Thu Mar 17 20:21:13 2011
@@ -0,0 +1,136 @@
+/**
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements.  See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership.  The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License.  You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+package org.apache.hadoop.yarn;
+
+import java.net.InetSocketAddress;
+import java.util.ArrayList;
+import java.util.HashMap;
+
+import junit.framework.Assert;
+
+import org.apache.avro.ipc.AvroRemoteException;
+import org.apache.avro.ipc.Server;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.net.NetUtils;
+import org.apache.hadoop.yarn.ipc.AvroYarnRPC;
+import org.apache.hadoop.yarn.ipc.HadoopYarnRPC;
+import org.apache.hadoop.yarn.ipc.RPCUtil;
+import org.apache.hadoop.yarn.ipc.YarnRPC;
+import org.apache.hadoop.yarn.ApplicationID;
+import org.apache.hadoop.yarn.ContainerID;
+import org.apache.hadoop.yarn.ContainerLaunchContext;
+import org.apache.hadoop.yarn.ContainerManager;
+import org.apache.hadoop.yarn.ContainerState;
+import org.apache.hadoop.yarn.ContainerStatus;
+import org.apache.hadoop.yarn.Resource;
+import org.apache.hadoop.yarn.YarnRemoteException;
+import org.junit.Test;
+
+public class TestRPC {
+
+  private static final String EXCEPTION_MSG = "test error";
+  private static final String EXCEPTION_CAUSE = "exception cause";
+  
+  @Test
+  public void testAvroRPC() throws Exception {
+    test(AvroYarnRPC.class.getName());
+  }
+
+  @Test
+  public void testHadoopNativeRPC() throws Exception {
+    test(HadoopYarnRPC.class.getName());
+  }
+
+  private void test(String rpcClass) throws Exception {
+    Configuration conf = new Configuration();
+    conf.set(YarnRPC.RPC_CLASSNAME, rpcClass);
+    YarnRPC rpc = YarnRPC.create(conf);
+    String bindAddr = "localhost:0";
+    InetSocketAddress addr = NetUtils.createSocketAddr(bindAddr);
+    Server server = rpc.getServer(ContainerManager.class, 
+            new DummyContainerManager(), addr, conf, null);
+    server.start();
+    ContainerManager proxy = (ContainerManager) 
+        rpc.getProxy(ContainerManager.class, 
+            NetUtils.createSocketAddr("localhost:" + server.getPort()), conf);
+    ContainerLaunchContext containerLaunchContext = new ContainerLaunchContext();
+    containerLaunchContext.user = "dummy-user";
+    containerLaunchContext.id = new ContainerID();
+    containerLaunchContext.id.appID = new ApplicationID();
+    containerLaunchContext.id.appID.id = 0;
+    containerLaunchContext.id.id = 100;  
+    containerLaunchContext.env = new HashMap<CharSequence, CharSequence>();
+    containerLaunchContext.resource = new Resource();
+    containerLaunchContext.command = new ArrayList<CharSequence>();
+    proxy.startContainer(containerLaunchContext);
+    ContainerStatus status = proxy.getContainerStatus(containerLaunchContext.id);
+    
+    //test remote exception
+    boolean exception = false;
+    try {
+      proxy.stopContainer(containerLaunchContext.id);
+    } catch (YarnRemoteException e) {
+      exception = true;
+      Assert.assertTrue(EXCEPTION_MSG.equals(e.message.toString()));
+      Assert.assertTrue(EXCEPTION_CAUSE.equals(e.cause.message.toString()));
+      System.out.println("Test Exception is " + RPCUtil.toString(e));
+    }
+    Assert.assertTrue(exception);
+    
+    server.close();
+    Assert.assertNotNull(status);
+    Assert.assertEquals(ContainerState.RUNNING, status.state.RUNNING);
+  }
+
+  public class DummyContainerManager implements ContainerManager {
+
+    private ContainerStatus status = null;
+
+    @Override
+    public Void cleanupContainer(ContainerID containerId) 
+        throws AvroRemoteException {
+      return null;
+    }
+
+    @Override
+    public ContainerStatus getContainerStatus(ContainerID containerId)
+        throws AvroRemoteException {
+      return status;
+    }
+
+    @Override
+    public Void startContainer(ContainerLaunchContext container)
+        throws AvroRemoteException {
+      status = new ContainerStatus();
+      status.state = ContainerState.RUNNING;
+      status.containerID = container.id;
+      status.exitStatus = 0;
+      return null;
+    }
+
+    @Override
+    public Void stopContainer(ContainerID containerId)
+        throws AvroRemoteException {
+      Exception e = new Exception(EXCEPTION_MSG, 
+          new Exception(EXCEPTION_CAUSE));
+      throw RPCUtil.getRemoteException(e);
+    }
+    
+  }
+}

Added: hadoop/mapreduce/branches/MR-279/yarn/yarn-common/src/test/java/org/apache/hadoop/yarn/webapp/TestParseRoute.java
URL: http://svn.apache.org/viewvc/hadoop/mapreduce/branches/MR-279/yarn/yarn-common/src/test/java/org/apache/hadoop/yarn/webapp/TestParseRoute.java?rev=1082677&view=auto
==============================================================================
--- hadoop/mapreduce/branches/MR-279/yarn/yarn-common/src/test/java/org/apache/hadoop/yarn/webapp/TestParseRoute.java (added)
+++ hadoop/mapreduce/branches/MR-279/yarn/yarn-common/src/test/java/org/apache/hadoop/yarn/webapp/TestParseRoute.java Thu Mar 17 20:21:13 2011
@@ -0,0 +1,83 @@
+/**
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements.  See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership.  The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License.  You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+package org.apache.hadoop.yarn.webapp;
+
+import java.util.Arrays;
+
+import org.apache.hadoop.yarn.webapp.WebApp;
+import org.apache.hadoop.yarn.webapp.WebAppException;
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+public class TestParseRoute {
+
+  @Test public void testNormalAction() {
+    assertEquals(Arrays.asList("/foo/action", "foo", "action", ":a1", ":a2"),
+                 WebApp.parseRoute("/foo/action/:a1/:a2"));
+  }
+
+  @Test public void testDefaultController() {
+    assertEquals(Arrays.asList("/", "default", "index"),
+                 WebApp.parseRoute("/"));
+  }
+
+  @Test public void testDefaultAction() {
+    assertEquals(Arrays.asList("/foo", "foo", "index"),
+                 WebApp.parseRoute("/foo"));
+    assertEquals(Arrays.asList("/foo", "foo", "index"),
+                 WebApp.parseRoute("/foo/"));
+  }
+
+  @Test public void testMissingAction() {
+    assertEquals(Arrays.asList("/foo", "foo", "index", ":a1"),
+                 WebApp.parseRoute("/foo/:a1"));
+  }
+
+  @Test public void testDefaultCapture() {
+    assertEquals(Arrays.asList("/", "default", "index", ":a"),
+                 WebApp.parseRoute("/:a"));
+  }
+
+  @Test public void testPartialCapture1() {
+    assertEquals(Arrays.asList("/foo/action/bar", "foo", "action", "bar", ":a"),
+                 WebApp.parseRoute("/foo/action/bar/:a"));
+  }
+
+  @Test public void testPartialCapture2() {
+    assertEquals(Arrays.asList("/foo/action", "foo", "action", ":a1", "bar",
+                               ":a2", ":a3"),
+                 WebApp.parseRoute("/foo/action/:a1/bar/:a2/:a3"));
+  }
+
+  @Test public void testLeadingPaddings() {
+    assertEquals(Arrays.asList("/foo/action", "foo", "action", ":a"),
+                 WebApp.parseRoute(" /foo/action/ :a"));
+  }
+
+  @Test public void testTrailingPaddings() {
+    assertEquals(Arrays.asList("/foo/action", "foo", "action", ":a"),
+                 WebApp.parseRoute("/foo/action//:a / "));
+    assertEquals(Arrays.asList("/foo/action", "foo", "action"),
+                 WebApp.parseRoute("/foo/action / "));
+  }
+
+  @Test(expected=WebAppException.class) public void testMissingLeadingSlash() {
+    WebApp.parseRoute("foo/bar");
+  }
+}

Added: hadoop/mapreduce/branches/MR-279/yarn/yarn-common/src/test/java/org/apache/hadoop/yarn/webapp/TestSubViews.java
URL: http://svn.apache.org/viewvc/hadoop/mapreduce/branches/MR-279/yarn/yarn-common/src/test/java/org/apache/hadoop/yarn/webapp/TestSubViews.java?rev=1082677&view=auto
==============================================================================
--- hadoop/mapreduce/branches/MR-279/yarn/yarn-common/src/test/java/org/apache/hadoop/yarn/webapp/TestSubViews.java (added)
+++ hadoop/mapreduce/branches/MR-279/yarn/yarn-common/src/test/java/org/apache/hadoop/yarn/webapp/TestSubViews.java Thu Mar 17 20:21:13 2011
@@ -0,0 +1,75 @@
+/**
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements.  See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership.  The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License.  You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+package org.apache.hadoop.yarn.webapp;
+
+import org.apache.hadoop.yarn.webapp.test.WebAppTests;
+import org.apache.hadoop.yarn.webapp.view.HtmlBlock;
+import org.apache.hadoop.yarn.webapp.view.HtmlPage;
+import java.io.PrintWriter;
+import javax.servlet.http.HttpServletResponse;
+import com.google.inject.Injector;
+
+import org.junit.Test;
+import static org.mockito.Mockito.*;
+
+public class TestSubViews {
+
+  static public class MainView extends HtmlPage {
+    @Override
+    public void render(Page.HTML<_> html) {
+      html.
+        body().
+          div().
+            _(Sub1.class)._().
+          div().
+            i("inline text").
+            _(Sub2.class)._()._()._();
+    }
+  }
+
+  static public class Sub1 extends HtmlBlock {
+    @Override
+    public void render(Block html) {
+      html.
+        div("#sub1").
+          _("sub1 text")._();
+    }
+  }
+
+  static public class Sub2 extends HtmlBlock {
+    @Override
+    public void render(Block html) {
+      html.
+        pre().
+          _("sub2 text")._();
+    }
+  }
+
+  @Test public void testSubView() throws Exception {
+    Injector injector = WebAppTests.createMockInjector(this);
+    injector.getInstance(MainView.class).render();
+
+    PrintWriter out =
+        injector.getInstance(HttpServletResponse.class).getWriter();
+    out.flush();
+    verify(out).print("sub1 text");
+    verify(out).print("sub2 text");
+    verify(out, times(15)).println(); // test inline transition across views
+  }
+}

Added: hadoop/mapreduce/branches/MR-279/yarn/yarn-common/src/test/java/org/apache/hadoop/yarn/webapp/TestWebApp.java
URL: http://svn.apache.org/viewvc/hadoop/mapreduce/branches/MR-279/yarn/yarn-common/src/test/java/org/apache/hadoop/yarn/webapp/TestWebApp.java?rev=1082677&view=auto
==============================================================================
--- hadoop/mapreduce/branches/MR-279/yarn/yarn-common/src/test/java/org/apache/hadoop/yarn/webapp/TestWebApp.java (added)
+++ hadoop/mapreduce/branches/MR-279/yarn/yarn-common/src/test/java/org/apache/hadoop/yarn/webapp/TestWebApp.java Thu Mar 17 20:21:13 2011
@@ -0,0 +1,231 @@
+/**
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements.  See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership.  The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License.  You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+package org.apache.hadoop.yarn.webapp;
+
+import org.apache.hadoop.yarn.MockApps;
+import org.apache.hadoop.yarn.webapp.Controller;
+import org.apache.hadoop.yarn.webapp.WebApp;
+import org.apache.hadoop.yarn.webapp.WebApps;
+import org.apache.hadoop.yarn.webapp.view.HtmlPage;
+import org.apache.hadoop.yarn.webapp.view.JQueryUI;
+import org.apache.hadoop.yarn.webapp.view.TextPage;
+
+import com.google.inject.Inject;
+
+import java.io.InputStream;
+import java.net.HttpURLConnection;
+import java.net.URL;
+
+import static org.apache.hadoop.yarn.util.StringHelper.*;
+import static org.apache.hadoop.yarn.webapp.view.JQueryUI.*;
+
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class TestWebApp {
+  static final Logger LOG = LoggerFactory.getLogger(TestWebApp.class);
+
+  static class FooController extends Controller {
+    final TestWebApp test;
+
+    @Inject FooController(TestWebApp test) {
+      this.test = test;
+    }
+
+    @Override public void index() {
+      set("key", test.echo("foo"));
+    }
+
+    public void bar() {
+      set("key", "bar");
+    }
+
+    public void names() {
+      for (int i = 0; i < 20; ++i) {
+        renderText(MockApps.newAppName() + "\n");
+      }
+    }
+
+    public void ex() {
+      boolean err = $("clear").isEmpty();
+      renderText(err ? "Should redirect to an error page." : "No error!");
+      if (err) {
+        throw new RuntimeException("exception test");
+      }
+    }
+
+    public void tables() {
+      render(TablesView.class);
+    }
+  }
+
+  static class FooView extends TextPage {
+    @Override public void render() {
+      puts($("key"), $("foo"));
+    }
+  }
+
+  static class DefaultController extends Controller {
+    @Override public void index() {
+      set("key", "default");
+      render(FooView.class);
+    }
+  }
+
+  static class TablesView extends HtmlPage {
+    @Override
+    public void render(Page.HTML<_> html) {
+      set(DATATABLES_ID, "t1 t2 t3 t4");
+      set(initID(DATATABLES, "t1"), tableInit().append("}").toString());
+      set(initID(DATATABLES, "t2"), join("{bJQueryUI:true, sDom:'t',",
+          "aoColumns:[null, {bSortable:false, bSearchable:false}]}"));
+      set(initID(DATATABLES, "t3"), "{bJQueryUI:true, sDom:'t'}");
+      set(initID(DATATABLES, "t4"), "{bJQueryUI:true, sDom:'t'}");
+      html.
+        title("Test DataTables").
+        link("/static/yarn.css").
+        _(JQueryUI.class).
+        style(".wrapper { padding: 1em }",
+              ".wrapper h2 { margin: 0.5em 0 }",
+              ".dataTables_wrapper { min-height: 1em }").
+        div(".wrapper").
+          h2("Default table init").
+          table("#t1").
+            thead().
+              tr().th("Column1").th("Column2")._()._().
+            tbody().
+              tr().td("c1r1").td("c2r1")._().
+              tr().td("c1r2").td("c2r2")._()._()._().
+          h2("Nested tables").
+          div(_INFO_WRAP).
+            table("#t2").
+              thead().
+                tr().th(_TH, "Column1").th(_TH, "Column2")._()._().
+              tbody().
+                tr().td("r1"). // th wouldn't work as of dt 1.7.5
+                  td().$class(C_TABLE).
+                    table("#t3").
+                      thead().
+                        tr().th("SubColumn1").th("SubColumn2")._()._().
+                      tbody().
+                        tr().td("subc1r1").td("subc2r1")._().
+                        tr().td("subc1r2").td("subc2r2")._()._()._()._()._().
+                tr().td("r2"). // ditto
+                  td().$class(C_TABLE).
+                    table("#t4").
+                      thead().
+                        tr().th("SubColumn1").th("SubColumn2")._()._().
+                      tbody().
+                        tr().td("subc1r1").td("subc2r1")._().
+                        tr().td("subc1r2").td("subc2r2")._().
+                        _()._()._()._()._()._()._()._()._();
+    }
+  }
+
+  String echo(String s) { return s; }
+
+  @Test public void testCreate() {
+    WebApp app = WebApps.$for(this).start();
+    app.stop();
+  }
+
+  @Test public void testDefaultRoutes() throws Exception {
+    WebApp app = WebApps.$for("test", this).start();
+    String baseUrl = baseUrl(app);
+    try {
+      assertEquals("foo", getContent(baseUrl +"test/foo").trim());
+      assertEquals("foo", getContent(baseUrl +"test/foo/index").trim());
+      assertEquals("bar", getContent(baseUrl +"test/foo/bar").trim());
+      assertEquals("default", getContent(baseUrl +"test").trim());
+      assertEquals("default", getContent(baseUrl +"test/").trim());
+      assertEquals("default", getContent(baseUrl).trim());
+    } finally {
+      app.stop();
+    }
+  }
+
+  @Test public void testCustomRoutes() throws Exception {
+    WebApp app = WebApps.$for("test", this).start(new WebApp() {
+      @Override public void setup() {
+        route("/:foo", FooController.class);
+        route("/bar/foo", FooController.class, "bar");
+        route("/foo/:foo", DefaultController.class);
+        route("/foo/bar/:foo", DefaultController.class, "index");
+      }
+    });
+    String baseUrl = baseUrl(app);
+    try {
+      assertEquals("foo", getContent(baseUrl).trim());
+      assertEquals("foo", getContent(baseUrl +"test").trim());
+      assertEquals("foo1", getContent(baseUrl +"test/1").trim());
+      assertEquals("bar", getContent(baseUrl +"test/bar/foo").trim());
+      assertEquals("default", getContent(baseUrl +"test/foo/bar").trim());
+      assertEquals("default1", getContent(baseUrl +"test/foo/1").trim());
+      assertEquals("default2", getContent(baseUrl +"test/foo/bar/2").trim());
+      assertEquals(404, getResponseCode(baseUrl +"test/goo"));
+    } finally {
+      app.stop();
+    }
+  }
+
+  static String baseUrl(WebApp app) {
+    return "http://localhost:"+ app.port() +"/";
+  }
+
+  static String getContent(String url) {
+    try {
+      StringBuilder out = new StringBuilder();
+      InputStream in = new URL(url).openConnection().getInputStream();
+      byte[] buffer = new byte[64 * 1024];
+      int len = in.read(buffer);
+      while (len > 0) {
+        out.append(new String(buffer, 0, len));
+        len = in.read(buffer);
+      }
+      return out.toString();
+    } catch (Exception e) {
+      throw new RuntimeException(e);
+    }
+  }
+
+  static int getResponseCode(String url) {
+    try {
+      HttpURLConnection c = (HttpURLConnection)new URL(url).openConnection();
+      return c.getResponseCode();
+    } catch (Exception e) {
+      throw new RuntimeException(e);
+    }
+  }
+
+  public static void main(String[] args) throws Exception {
+    // For manual controller/view testing.
+    WebApps.$for("test", new TestWebApp()).at(8888).inDevMode().start().
+        joinThread();
+//        start(new WebApp() {
+//          @Override public void setup() {
+//            route("/:foo", FooController.class);
+//            route("/foo/:foo", FooController.class);
+//            route("/bar", FooController.class);
+//          }
+//        }).join();
+  }
+}

Added: hadoop/mapreduce/branches/MR-279/yarn/yarn-common/src/test/java/org/apache/hadoop/yarn/webapp/hamlet/TestHamlet.java
URL: http://svn.apache.org/viewvc/hadoop/mapreduce/branches/MR-279/yarn/yarn-common/src/test/java/org/apache/hadoop/yarn/webapp/hamlet/TestHamlet.java?rev=1082677&view=auto
==============================================================================
--- hadoop/mapreduce/branches/MR-279/yarn/yarn-common/src/test/java/org/apache/hadoop/yarn/webapp/hamlet/TestHamlet.java (added)
+++ hadoop/mapreduce/branches/MR-279/yarn/yarn-common/src/test/java/org/apache/hadoop/yarn/webapp/hamlet/TestHamlet.java Thu Mar 17 20:21:13 2011
@@ -0,0 +1,166 @@
+/**
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements.  See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership.  The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License.  You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+package org.apache.hadoop.yarn.webapp.hamlet;
+
+import java.util.EnumSet;
+import java.io.PrintWriter;
+import org.junit.Test;
+import static org.junit.Assert.*;
+import static org.mockito.Mockito.*;
+
+import org.apache.hadoop.yarn.webapp.SubView;
+import org.apache.hadoop.yarn.webapp.hamlet.Hamlet;
+
+import static org.apache.hadoop.yarn.webapp.hamlet.HamletSpec.*;
+
+public class TestHamlet {
+
+  @Test public void testHamlet() {
+    Hamlet h = newHamlet().
+        title("test").
+        h1("heading 1").
+        p("#id.class").
+          b("hello").
+          em("world!")._().
+        div("#footer").
+          _("Brought to you by").
+          a("http://hostname/", "Somebody")._();
+
+    PrintWriter out = h.getWriter();
+    out.flush();
+    assertEquals(0, h.nestLevel);
+    verify(out).print("<title");
+    verify(out).print("test");
+    verify(out).print("</title>");
+    verify(out).print("<h1");
+    verify(out).print("heading 1");
+    verify(out).print("</h1>");
+    verify(out).print("<p");
+    verify(out).print(" id=\"id\"");
+    verify(out).print(" class=\"class\"");
+    verify(out).print("<b");
+    verify(out).print("hello");
+    verify(out).print("</b>");
+    verify(out).print("<em");
+    verify(out).print("world!");
+    verify(out).print("</em>");
+    verify(out).print("<div");
+    verify(out).print(" id=\"footer\"");
+    verify(out).print("Brought to you by");
+    verify(out).print("<a");
+    verify(out).print(" href=\"http://hostname/\"");
+    verify(out).print("Somebody");
+    verify(out).print("</a>");
+    verify(out).print("</div>");
+    verify(out, never()).print("</p>");
+  }
+
+  @Test public void testTable() {
+    Hamlet h = newHamlet().
+        title("test table").
+        link("style.css");
+
+    TABLE t = h.table("#id");
+
+    for (int i = 0; i < 3; ++i) {
+      t.tr().td("1").td("2")._();
+    }
+    t._();
+
+    PrintWriter out = h.getWriter();
+    out.flush();
+    assertEquals(0, h.nestLevel);
+    verify(out).print("<table");
+    verify(out).print("</table>");
+    verify(out, never()).print("</td>");
+    verify(out, never()).print("</tr>");
+  }
+
+  @Test public void testEnumAttrs() {
+    Hamlet h = newHamlet().
+        meta_http("Content-type", "text/html; charset=utf-8").
+        title("test enum attrs").
+        link().$rel("stylesheet").
+          $media(EnumSet.of(Media.screen, Media.print)).
+          $type("text/css").$href("style.css")._().
+        link().$rel(EnumSet.of(LinkType.index, LinkType.start)).
+          $href("index.html")._();
+
+    h.div("#content")._("content")._();
+
+    PrintWriter out = h.getWriter();
+    out.flush();
+    assertEquals(0, h.nestLevel);
+    verify(out).print(" media=\"screen, print\"");
+    verify(out).print(" rel=\"start index\"");
+  }
+
+  @Test public void testScriptStyle() {
+    Hamlet h = newHamlet().
+        script("a.js").script("b.js").
+        style("h1 { font-size: 1.2em }");
+
+    PrintWriter out = h.getWriter();
+    out.flush();
+    assertEquals(0, h.nestLevel);
+    verify(out, times(2)).print(" type=\"text/javascript\"");
+    verify(out).print(" type=\"text/css\"");
+  }
+
+  @Test public void testPreformatted() {
+    Hamlet h = newHamlet().
+        div().
+          i("inline before pre").
+          pre().
+            _("pre text1\npre text2").
+            i("inline in pre").
+            _("pre text after inline")._().
+          i("inline after pre")._();
+
+    PrintWriter out = h.getWriter();
+    out.flush();
+    assertEquals(5, h.indents);
+  }
+
+  static class TestView1 implements SubView {
+    @Override public void renderPartial() {}
+  }
+
+  static class TestView2 implements SubView {
+    @Override public void renderPartial() {}
+  }
+
+  @Test public void testSubViews() {
+    Hamlet h = newHamlet().
+        title("test sub-views").
+        div("#view1")._(TestView1.class)._().
+        div("#view2")._(TestView2.class)._();
+
+    PrintWriter out = h.getWriter();
+    out.flush();
+    assertEquals(0, h.nestLevel);
+    verify(out).print("["+ TestView1.class.getName() +"]");
+    verify(out).print("["+ TestView2.class.getName() +"]");
+  }
+
+  static Hamlet newHamlet() {
+    PrintWriter out = spy(new PrintWriter(System.out));
+    return new Hamlet(out, 0, false);
+  }
+}

Added: hadoop/mapreduce/branches/MR-279/yarn/yarn-common/src/test/java/org/apache/hadoop/yarn/webapp/hamlet/TestHamletImpl.java
URL: http://svn.apache.org/viewvc/hadoop/mapreduce/branches/MR-279/yarn/yarn-common/src/test/java/org/apache/hadoop/yarn/webapp/hamlet/TestHamletImpl.java?rev=1082677&view=auto
==============================================================================
--- hadoop/mapreduce/branches/MR-279/yarn/yarn-common/src/test/java/org/apache/hadoop/yarn/webapp/hamlet/TestHamletImpl.java (added)
+++ hadoop/mapreduce/branches/MR-279/yarn/yarn-common/src/test/java/org/apache/hadoop/yarn/webapp/hamlet/TestHamletImpl.java Thu Mar 17 20:21:13 2011
@@ -0,0 +1,108 @@
+/**
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements.  See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership.  The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License.  You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+package org.apache.hadoop.yarn.webapp.hamlet;
+
+import java.io.PrintWriter;
+import org.junit.Test;
+import static org.junit.Assert.*;
+import static org.mockito.Mockito.*;
+
+import org.apache.hadoop.yarn.webapp.hamlet.HamletImpl;
+import org.apache.hadoop.yarn.webapp.hamlet.HamletSpec.*;
+
+public class TestHamletImpl {
+  /**
+   * Test the generic implementation methods
+   * @see TestHamlet for Hamlet syntax
+   */
+  @Test public void testGeneric() {
+    PrintWriter out = spy(new PrintWriter(System.out));
+    HamletImpl hi = new HamletImpl(out, 0, false);
+    hi.
+      root("start")._attr("name", "value").
+        _("start text").
+        elem("sub")._attr("name", "value").
+          _("sub text")._().
+        elem("sub1")._noEndTag()._attr("boolean", null).
+          _("sub1text")._().
+        _("start text2").
+        elem("pre")._pre().
+          _("pre text").
+          elem("i")._inline()._("inline")._()._().
+        elem("i")._inline()._("inline after pre")._().
+        _("start text3").
+        elem("sub2").
+          _("sub2text")._().
+        elem("sub3")._noEndTag().
+          _("sub3text")._().
+        elem("sub4")._noEndTag().
+          elem("i")._inline()._("inline")._().
+          _("sub4text")._()._();
+
+    out.flush();
+    assertEquals(0, hi.nestLevel);
+    assertEquals(20, hi.indents);
+    verify(out).print("<start");
+    verify(out, times(2)).print(" name=\"value\"");
+    verify(out).print(" boolean");
+    verify(out).print("</start>");
+    verify(out, never()).print("</sub1>");
+    verify(out, never()).print("</sub3>");
+    verify(out, never()).print("</sub4>");
+  }
+
+  @Test public void testSetSelector() {
+    CoreAttrs e = mock(CoreAttrs.class);
+    HamletImpl.setSelector(e, "#id.class");
+
+    verify(e).$id("id");
+    verify(e).$class("class");
+
+    H1 t = mock(H1.class);
+    HamletImpl.setSelector(t, "#id.class")._("heading");
+
+    verify(t).$id("id");
+    verify(t).$class("class");
+    verify(t)._("heading");
+  }
+
+  @Test public void testSetLinkHref() {
+    LINK link = mock(LINK.class);
+    HamletImpl.setLinkHref(link, "uri");
+    HamletImpl.setLinkHref(link, "style.css");
+
+    verify(link).$href("uri");
+    verify(link).$rel("stylesheet");
+    verify(link).$href("style.css");
+
+    verifyNoMoreInteractions(link);
+  }
+
+  @Test public void testSetScriptSrc() {
+    SCRIPT script = mock(SCRIPT.class);
+    HamletImpl.setScriptSrc(script, "uri");
+    HamletImpl.setScriptSrc(script, "script.js");
+
+    verify(script).$src("uri");
+    verify(script).$type("text/javascript");
+    verify(script).$src("script.js");
+
+    verifyNoMoreInteractions(script);
+  }
+}

Added: hadoop/mapreduce/branches/MR-279/yarn/yarn-common/src/test/java/org/apache/hadoop/yarn/webapp/hamlet/TestParseSelector.java
URL: http://svn.apache.org/viewvc/hadoop/mapreduce/branches/MR-279/yarn/yarn-common/src/test/java/org/apache/hadoop/yarn/webapp/hamlet/TestParseSelector.java?rev=1082677&view=auto
==============================================================================
--- hadoop/mapreduce/branches/MR-279/yarn/yarn-common/src/test/java/org/apache/hadoop/yarn/webapp/hamlet/TestParseSelector.java (added)
+++ hadoop/mapreduce/branches/MR-279/yarn/yarn-common/src/test/java/org/apache/hadoop/yarn/webapp/hamlet/TestParseSelector.java Thu Mar 17 20:21:13 2011
@@ -0,0 +1,57 @@
+/**
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements.  See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership.  The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License.  You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+package org.apache.hadoop.yarn.webapp.hamlet;
+
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+import org.apache.hadoop.yarn.webapp.WebAppException;
+
+import static org.apache.hadoop.yarn.webapp.hamlet.HamletImpl.*;
+
+public class TestParseSelector {
+
+  @Test public void testNormal() {
+    String[] res = parseSelector("#id.class");
+    assertEquals("id", res[S_ID]);
+    assertEquals("class", res[S_CLASS]);
+  }
+
+  @Test public void testMultiClass() {
+    String[] res = parseSelector("#id.class1.class2");
+    assertEquals("id", res[S_ID]);
+    assertEquals("class1 class2", res[S_CLASS]);
+  }
+
+  @Test public void testMissingId() {
+    String[] res = parseSelector(".class");
+    assertNull(res[S_ID]);
+    assertEquals("class", res[S_CLASS]);
+  }
+
+  @Test public void testMissingClass() {
+    String[] res = parseSelector("#id");
+    assertEquals("id", res[S_ID]);
+    assertNull(res[S_CLASS]);
+  }
+
+  @Test(expected=WebAppException.class) public void testMissingAll() {
+    parseSelector("");
+  }
+}

Added: hadoop/mapreduce/branches/MR-279/yarn/yarn-common/src/test/java/org/apache/hadoop/yarn/webapp/test/TestWebAppTests.java
URL: http://svn.apache.org/viewvc/hadoop/mapreduce/branches/MR-279/yarn/yarn-common/src/test/java/org/apache/hadoop/yarn/webapp/test/TestWebAppTests.java?rev=1082677&view=auto
==============================================================================
--- hadoop/mapreduce/branches/MR-279/yarn/yarn-common/src/test/java/org/apache/hadoop/yarn/webapp/test/TestWebAppTests.java (added)
+++ hadoop/mapreduce/branches/MR-279/yarn/yarn-common/src/test/java/org/apache/hadoop/yarn/webapp/test/TestWebAppTests.java Thu Mar 17 20:21:13 2011
@@ -0,0 +1,103 @@
+/**
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements.  See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership.  The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License.  You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+package org.apache.hadoop.yarn.webapp.test;
+
+import com.google.inject.AbstractModule;
+import com.google.inject.Injector;
+import com.google.inject.servlet.RequestScoped;
+import java.io.PrintWriter;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import org.junit.Test;
+import static org.junit.Assert.*;
+import static org.mockito.Mockito.*;
+
+import org.slf4j.LoggerFactory;
+import org.slf4j.Logger;
+
+public class TestWebAppTests {
+  static final Logger LOG = LoggerFactory.getLogger(TestWebAppTests.class);
+
+  @Test public void testInstances() throws Exception {
+    Injector injector = WebAppTests.createMockInjector(this);
+    HttpServletRequest req = injector.getInstance(HttpServletRequest.class);
+    HttpServletResponse res = injector.getInstance(HttpServletResponse.class);
+    String val = req.getParameter("foo");
+    PrintWriter out = res.getWriter();
+    out.println("Hello world!");
+    logInstances(req, res, out);
+
+    assertSame(req, injector.getInstance(HttpServletRequest.class));
+    assertSame(res, injector.getInstance(HttpServletResponse.class));
+    assertSame(this, injector.getInstance(TestWebAppTests.class));
+
+    verify(req).getParameter("foo");
+    verify(res).getWriter();
+    verify(out).println("Hello world!");
+  }
+
+  interface Foo {
+  }
+
+  static class Bar implements Foo {
+  }
+
+  static class FooBar extends Bar {
+  }
+
+  @Test public void testCreateInjector() throws Exception {
+    Bar bar = new Bar();
+    Injector injector = WebAppTests.createMockInjector(Foo.class, bar);
+    logInstances(injector.getInstance(HttpServletRequest.class),
+                 injector.getInstance(HttpServletResponse.class),
+                 injector.getInstance(HttpServletResponse.class).getWriter());
+    assertSame(bar, injector.getInstance(Foo.class));
+  }
+
+  @Test public void testCreateInjector2() {
+    final FooBar foobar = new FooBar();
+    Bar bar = new Bar();
+    Injector injector = WebAppTests.createMockInjector(Foo.class, bar,
+        new AbstractModule() {
+      @Override protected void configure() {
+        bind(Bar.class).toInstance(foobar);
+      }
+    });
+    assertNotSame(bar, injector.getInstance(Bar.class));
+    assertSame(foobar, injector.getInstance(Bar.class));
+  }
+
+  @RequestScoped
+  static class ScopeTest {
+  }
+
+  @Test public void testRequestScope() {
+    Injector injector = WebAppTests.createMockInjector(this);
+
+    assertSame(injector.getInstance(ScopeTest.class),
+               injector.getInstance(ScopeTest.class));
+  }
+
+  private void logInstances(HttpServletRequest req, HttpServletResponse res,
+                            PrintWriter out) {
+    LOG.info("request: {}", req);
+    LOG.info("response: {}", res);
+    LOG.info("writer: {}", out);
+  }
+}

Added: hadoop/mapreduce/branches/MR-279/yarn/yarn-common/src/test/java/org/apache/hadoop/yarn/webapp/test/WebAppTests.java
URL: http://svn.apache.org/viewvc/hadoop/mapreduce/branches/MR-279/yarn/yarn-common/src/test/java/org/apache/hadoop/yarn/webapp/test/WebAppTests.java?rev=1082677&view=auto
==============================================================================
--- hadoop/mapreduce/branches/MR-279/yarn/yarn-common/src/test/java/org/apache/hadoop/yarn/webapp/test/WebAppTests.java (added)
+++ hadoop/mapreduce/branches/MR-279/yarn/yarn-common/src/test/java/org/apache/hadoop/yarn/webapp/test/WebAppTests.java Thu Mar 17 20:21:13 2011
@@ -0,0 +1,162 @@
+/**
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements.  See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership.  The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License.  You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+package org.apache.hadoop.yarn.webapp.test;
+
+import org.apache.hadoop.yarn.webapp.Controller;
+import org.apache.hadoop.yarn.webapp.SubView;
+import org.apache.hadoop.yarn.webapp.View;
+import org.apache.hadoop.yarn.webapp.WebAppException;
+
+import java.lang.reflect.Method;
+import com.google.inject.Module;
+import com.google.inject.Scopes;
+import com.google.inject.servlet.RequestScoped;
+import com.google.inject.AbstractModule;
+import com.google.inject.Guice;
+import com.google.inject.Injector;
+import com.google.inject.Provides;
+
+import java.io.PrintWriter;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpServletRequest;
+
+
+import static org.mockito.Mockito.*;
+
+public class WebAppTests {
+
+  /**
+   * Create a mock injector for tests
+   * @param <T> type of class/interface
+   * @param api the interface class of the object to inject
+   * @param impl the implementation object to inject
+   * @param modules additional guice modules
+   * @return an injector
+   */
+  public static <T> Injector createMockInjector(final Class<T> api,
+                                                final T impl,
+                                                final Module... modules) {
+    return Guice.createInjector(new AbstractModule() {
+      final PrintWriter writer = spy(new PrintWriter(System.out));
+      final HttpServletRequest request = createRequest();
+      final HttpServletResponse response = createResponse();
+
+      @Override
+      protected void configure() {
+        if (api != null) {
+          bind(api).toInstance(impl);
+        }
+        bindScope(RequestScoped.class, Scopes.SINGLETON);
+        if (modules != null) {
+          for (Module module : modules) {
+            install(module);
+          }
+        }
+      }
+
+      @Provides HttpServletRequest request() {
+        return request;
+      }
+
+      @Provides HttpServletResponse response() {
+        return response;
+      }
+
+      @Provides PrintWriter writer() {
+        return writer;
+      }
+
+      HttpServletRequest createRequest() {
+        // the default suffices for now
+        return mock(HttpServletRequest.class);
+      }
+
+      HttpServletResponse createResponse() {
+        try {
+          HttpServletResponse res = mock(HttpServletResponse.class);
+          when(res.getWriter()).thenReturn(writer);
+          return res;
+        } catch (Exception e) {
+          throw new WebAppException(e);
+        }
+      }
+    });
+  }
+
+  // convenience
+  @SuppressWarnings("unchecked")
+  public static <T> Injector createMockInjector(T impl) {
+    return createMockInjector((Class<T>)impl.getClass(), impl);
+  }
+
+  public static void flushOutput(Injector injector) {
+    HttpServletResponse res = injector.getInstance(HttpServletResponse.class);
+    try {
+      res.getWriter().flush();
+    } catch (Exception e) {
+      throw new RuntimeException(e);
+    }
+  }
+
+  public static <T> Injector testController(Class<? extends Controller> ctrlr,
+      String methodName, Class<T> api, T impl, Module... modules) {
+    try {
+      Injector injector = createMockInjector(api, impl, modules);
+      Method method = ctrlr.getMethod(methodName, (Class<?>[])null);
+      method.invoke(injector.getInstance(ctrlr), (Object[])null);
+      return injector;
+    } catch (Exception e) {
+      throw new WebAppException(e);
+    }
+  }
+
+  @SuppressWarnings("unchecked")
+  public static <T> Injector testController(Class<? extends Controller> ctrlr,
+      String methodName) {
+    return testController(ctrlr, methodName, null, null);
+  }
+
+  public static <T> Injector testPage(Class<? extends View> page, Class<T> api,
+                                      T impl, Module... modules) {
+    Injector injector = createMockInjector(api, impl, modules);
+    injector.getInstance(page).render();
+    flushOutput(injector);
+    return injector;
+  }
+
+  // convenience
+  @SuppressWarnings("unchecked")
+  public static <T> Injector testPage(Class<? extends View> page) {
+    return testPage(page, null, null);
+  }
+
+  public static <T> Injector testBlock(Class<? extends SubView> block,
+      Class<T> api, T impl, Module... modules) {
+    Injector injector = createMockInjector(api, impl, modules);
+    injector.getInstance(block).renderPartial();
+    flushOutput(injector);
+    return injector;
+  }
+
+  // convenience
+  @SuppressWarnings("unchecked")
+  public static <T> Injector testBlock(Class<? extends SubView> block) {
+    return testBlock(block, null, null);
+  }
+}

Added: hadoop/mapreduce/branches/MR-279/yarn/yarn-common/src/test/java/org/apache/hadoop/yarn/webapp/view/TestCommonViews.java
URL: http://svn.apache.org/viewvc/hadoop/mapreduce/branches/MR-279/yarn/yarn-common/src/test/java/org/apache/hadoop/yarn/webapp/view/TestCommonViews.java?rev=1082677&view=auto
==============================================================================
--- hadoop/mapreduce/branches/MR-279/yarn/yarn-common/src/test/java/org/apache/hadoop/yarn/webapp/view/TestCommonViews.java (added)
+++ hadoop/mapreduce/branches/MR-279/yarn/yarn-common/src/test/java/org/apache/hadoop/yarn/webapp/view/TestCommonViews.java Thu Mar 17 20:21:13 2011
@@ -0,0 +1,56 @@
+/**
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements.  See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership.  The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License.  You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+package org.apache.hadoop.yarn.webapp.view;
+
+import com.google.inject.Injector;
+
+import org.apache.hadoop.yarn.webapp.ResponseInfo;
+import org.apache.hadoop.yarn.webapp.test.WebAppTests;
+import org.apache.hadoop.yarn.webapp.view.ErrorPage;
+import org.apache.hadoop.yarn.webapp.view.FooterBlock;
+import org.apache.hadoop.yarn.webapp.view.HeaderBlock;
+import org.apache.hadoop.yarn.webapp.view.JQueryUI;
+
+import org.junit.Test;
+import static org.mockito.Mockito.*;
+
+public class TestCommonViews {
+
+  @Test public void testErrorPage() {
+    Injector injector = WebAppTests.testPage(ErrorPage.class);
+
+  }
+
+  @Test public void testHeaderBlock() {
+    WebAppTests.testBlock(HeaderBlock.class);
+  }
+
+  @Test public void testFooterBlock() {
+    WebAppTests.testBlock(FooterBlock.class);
+  }
+
+  @Test public void testJQueryUI() {
+    WebAppTests.testBlock(JQueryUI.class);
+  }
+
+  @Test public void testInfoBlock() {
+    Injector injector = WebAppTests.createMockInjector(this);
+    ResponseInfo info = injector.getInstance(ResponseInfo.class);
+  }
+}

Added: hadoop/mapreduce/branches/MR-279/yarn/yarn-common/src/test/java/org/apache/hadoop/yarn/webapp/view/TestHtmlBlock.java
URL: http://svn.apache.org/viewvc/hadoop/mapreduce/branches/MR-279/yarn/yarn-common/src/test/java/org/apache/hadoop/yarn/webapp/view/TestHtmlBlock.java?rev=1082677&view=auto
==============================================================================
--- hadoop/mapreduce/branches/MR-279/yarn/yarn-common/src/test/java/org/apache/hadoop/yarn/webapp/view/TestHtmlBlock.java (added)
+++ hadoop/mapreduce/branches/MR-279/yarn/yarn-common/src/test/java/org/apache/hadoop/yarn/webapp/view/TestHtmlBlock.java Thu Mar 17 20:21:13 2011
@@ -0,0 +1,74 @@
+/**
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements.  See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership.  The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License.  You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+package org.apache.hadoop.yarn.webapp.view;
+
+import com.google.inject.Injector;
+
+import java.io.PrintWriter;
+
+import org.apache.hadoop.yarn.webapp.WebAppException;
+import org.apache.hadoop.yarn.webapp.test.WebAppTests;
+import org.apache.hadoop.yarn.webapp.view.HtmlBlock;
+import org.apache.hadoop.yarn.webapp.view.HtmlPage;
+
+import org.junit.Test;
+import static org.mockito.Mockito.*;
+
+public class TestHtmlBlock {
+  public static class TestBlock extends HtmlBlock {
+    @Override
+    public void render(Block html) {
+      html.
+        p("#testid")._("test note")._();
+    }
+  }
+
+  public static class ShortBlock extends HtmlBlock {
+    @Override
+    public void render(Block html) {
+      html.
+        p()._("should throw");
+    }
+  }
+
+  public static class ShortPage extends HtmlPage {
+    @Override
+    public void render(Page.HTML<_> html) {
+      html.
+        title("short test").
+        _(ShortBlock.class);
+    }
+  }
+
+  @Test public void testUsual() {
+    Injector injector = WebAppTests.testBlock(TestBlock.class);
+    PrintWriter out = injector.getInstance(PrintWriter.class);
+
+    verify(out).print(" id=\"testid\"");
+    verify(out).print("test note");
+  }
+
+  @Test(expected=WebAppException.class) public void testShortBlock() {
+    WebAppTests.testBlock(ShortBlock.class);
+  }
+
+  @Test(expected=WebAppException.class) public void testShortPage() {
+    WebAppTests.testPage(ShortPage.class);
+  }
+}

Added: hadoop/mapreduce/branches/MR-279/yarn/yarn-common/src/test/java/org/apache/hadoop/yarn/webapp/view/TestHtmlPage.java
URL: http://svn.apache.org/viewvc/hadoop/mapreduce/branches/MR-279/yarn/yarn-common/src/test/java/org/apache/hadoop/yarn/webapp/view/TestHtmlPage.java?rev=1082677&view=auto
==============================================================================
--- hadoop/mapreduce/branches/MR-279/yarn/yarn-common/src/test/java/org/apache/hadoop/yarn/webapp/view/TestHtmlPage.java (added)
+++ hadoop/mapreduce/branches/MR-279/yarn/yarn-common/src/test/java/org/apache/hadoop/yarn/webapp/view/TestHtmlPage.java Thu Mar 17 20:21:13 2011
@@ -0,0 +1,64 @@
+/**
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements.  See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership.  The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License.  You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+package org.apache.hadoop.yarn.webapp.view;
+
+import com.google.inject.Injector;
+
+import java.io.PrintWriter;
+
+import org.apache.hadoop.yarn.webapp.WebAppException;
+import org.apache.hadoop.yarn.webapp.test.WebAppTests;
+import org.apache.hadoop.yarn.webapp.view.HtmlPage;
+
+import org.junit.Test;
+import static org.mockito.Mockito.*;
+
+public class TestHtmlPage {
+  
+  public static class TestView extends HtmlPage {
+    @Override
+    public void render(Page.HTML<_> html) {
+      html.
+        title("test").
+        p("#testid")._("test note")._()._();
+    }
+  }
+
+  public static class ShortView extends HtmlPage {
+    @Override
+    public void render(Page.HTML<_> html) {
+      html.
+        title("short test").
+        p()._("should throw");
+    }
+  }
+
+  @Test public void testUsual() {
+    Injector injector = WebAppTests.testPage(TestView.class);
+    PrintWriter out = injector.getInstance(PrintWriter.class);
+
+    verify(out).print("test");
+    verify(out).print(" id=\"testid\"");
+    verify(out).print("test note");
+  }
+
+  @Test(expected=WebAppException.class) public void testShort() {
+    WebAppTests.testPage(ShortView.class);
+  }
+}

Added: hadoop/mapreduce/branches/MR-279/yarn/yarn-common/src/test/java/org/apache/hadoop/yarn/webapp/view/TestTwoColumnCssPage.java
URL: http://svn.apache.org/viewvc/hadoop/mapreduce/branches/MR-279/yarn/yarn-common/src/test/java/org/apache/hadoop/yarn/webapp/view/TestTwoColumnCssPage.java?rev=1082677&view=auto
==============================================================================
--- hadoop/mapreduce/branches/MR-279/yarn/yarn-common/src/test/java/org/apache/hadoop/yarn/webapp/view/TestTwoColumnCssPage.java (added)
+++ hadoop/mapreduce/branches/MR-279/yarn/yarn-common/src/test/java/org/apache/hadoop/yarn/webapp/view/TestTwoColumnCssPage.java Thu Mar 17 20:21:13 2011
@@ -0,0 +1,70 @@
+/**
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements.  See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership.  The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License.  You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+package org.apache.hadoop.yarn.webapp.view;
+
+import org.apache.hadoop.yarn.MockApps;
+import org.apache.hadoop.yarn.webapp.Controller;
+import org.apache.hadoop.yarn.webapp.WebApps;
+import org.apache.hadoop.yarn.webapp.test.WebAppTests;
+import org.apache.hadoop.yarn.webapp.view.HtmlPage;
+import org.apache.hadoop.yarn.webapp.view.TwoColumnCssLayout;
+import org.junit.Test;
+
+public class TestTwoColumnCssPage {
+
+  public static class TestController extends Controller {
+    @Override
+    public void index() {
+      set("title", "Testing a Two Column Layout");
+      set("ui.accordion.id", "nav");
+      set("ui.themeswitcher.id", "themeswitcher");
+      render(TwoColumnCssLayout.class);
+    }
+
+    public void names() {
+      StringBuilder sb = new StringBuilder();
+      for (int i = 0; i < 8; ++i) {
+        sb.append(MockApps.newAppName()).append(' ');
+      }
+      setTitle(sb.toString());
+    }
+
+    public void textnames() {
+      names();
+      renderText($("title"));
+    }
+  }
+
+  public static class TestView extends HtmlPage {
+    @Override
+    public void render(Page.HTML<_> html) {
+      html.
+        title($("title")).
+        h1($("title"))._();
+    }
+  }
+
+  @Test public void shouldNotThrow() {
+    WebAppTests.testPage(TwoColumnCssLayout.class);
+  }
+
+  public static void main(String[] args) {
+    WebApps.$for("test").at(8888).inDevMode().start().joinThread();
+  }
+}

Added: hadoop/mapreduce/branches/MR-279/yarn/yarn-common/src/test/java/org/apache/hadoop/yarn/webapp/view/TestTwoColumnLayout.java
URL: http://svn.apache.org/viewvc/hadoop/mapreduce/branches/MR-279/yarn/yarn-common/src/test/java/org/apache/hadoop/yarn/webapp/view/TestTwoColumnLayout.java?rev=1082677&view=auto
==============================================================================
--- hadoop/mapreduce/branches/MR-279/yarn/yarn-common/src/test/java/org/apache/hadoop/yarn/webapp/view/TestTwoColumnLayout.java (added)
+++ hadoop/mapreduce/branches/MR-279/yarn/yarn-common/src/test/java/org/apache/hadoop/yarn/webapp/view/TestTwoColumnLayout.java Thu Mar 17 20:21:13 2011
@@ -0,0 +1,45 @@
+/**
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements.  See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership.  The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License.  You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+package org.apache.hadoop.yarn.webapp.view;
+
+import org.apache.hadoop.yarn.webapp.Controller;
+import org.apache.hadoop.yarn.webapp.WebApps;
+import org.apache.hadoop.yarn.webapp.test.WebAppTests;
+import org.junit.Test;
+
+public class TestTwoColumnLayout {
+
+  public static class TestController extends Controller {
+    @Override
+    public void index() {
+      setTitle("Test the two column table layout");
+      set("ui.accordion.id", "nav");
+      set("ui.themeswitcher.id", "themeswitcher");
+      render(TwoColumnLayout.class);
+    }
+  }
+
+  @Test public void shouldNotThrow() {
+    WebAppTests.testPage(TwoColumnLayout.class);
+  }
+
+  public static void main(String[] args) {
+    WebApps.$for("test").at(8888).inDevMode().start().joinThread();
+  }
+}

Added: hadoop/mapreduce/branches/MR-279/yarn/yarn-server/pom.xml
URL: http://svn.apache.org/viewvc/hadoop/mapreduce/branches/MR-279/yarn/yarn-server/pom.xml?rev=1082677&view=auto
==============================================================================
--- hadoop/mapreduce/branches/MR-279/yarn/yarn-server/pom.xml (added)
+++ hadoop/mapreduce/branches/MR-279/yarn/yarn-server/pom.xml Thu Mar 17 20:21:13 2011
@@ -0,0 +1,38 @@
+<?xml version="1.0"?><project>
+  <parent>
+    <artifactId>yarn</artifactId>
+    <groupId>org.apache.hadoop</groupId>
+    <version>${yarn.version}</version>
+  </parent>
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>org.apache.hadoop</groupId>
+  <artifactId>yarn-server</artifactId>
+  <name>yarn-server</name>
+  <version>${yarn.version}</version>
+  <packaging>pom</packaging>
+  <url>http://maven.apache.org</url>
+
+  <dependencies>
+    <!-- begin MNG-4223 workaround -->
+    <dependency>
+      <groupId>org.apache.hadoop</groupId>
+      <artifactId>yarn-api</artifactId>
+      <version>${yarn.version}</version>
+    </dependency>
+    <!-- end MNG-4223 workaround -->
+    <dependency>
+      <groupId>org.apache.hadoop</groupId>
+      <artifactId>yarn-common</artifactId>
+      <version>${yarn.version}</version>
+      <type>test-jar</type>
+      <scope>test</scope>
+    </dependency>
+  </dependencies>
+
+  <modules>
+    <module>yarn-server-common</module>
+    <module>yarn-server-nodemanager</module>
+    <module>yarn-server-resourcemanager</module>
+    <module>yarn-server-tests</module>
+  </modules>
+</project>

Added: hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-common/pom.xml
URL: http://svn.apache.org/viewvc/hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-common/pom.xml?rev=1082677&view=auto
==============================================================================
--- hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-common/pom.xml (added)
+++ hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-common/pom.xml Thu Mar 17 20:21:13 2011
@@ -0,0 +1,55 @@
+<?xml version="1.0"?><project>
+  <parent>
+    <artifactId>yarn-server</artifactId>
+    <groupId>org.apache.hadoop</groupId>
+    <version>${yarn.version}</version>
+  </parent>
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>org.apache.hadoop</groupId>
+  <artifactId>yarn-server-common</artifactId>
+  <name>yarn-server-common</name>
+  <version>${yarn.version}</version>
+  <url>http://maven.apache.org</url>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.hadoop</groupId>
+      <artifactId>yarn-common</artifactId>
+      <version>${yarn.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.hadoop</groupId>
+      <artifactId>zookeeper</artifactId>
+      <version>3.3.1</version>
+      <scope>compile</scope>
+       <exclusions>
+        <exclusion>
+          <groupId>com.sun.jdmk</groupId>
+          <artifactId>jmxtools</artifactId>
+        </exclusion>
+        <exclusion>
+          <groupId>com.sun.jmx</groupId>
+          <artifactId>jmxri</artifactId>
+        </exclusion>
+      </exclusions>
+    </dependency>
+  </dependencies>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.avro</groupId>
+        <artifactId>avro-maven-plugin</artifactId>
+        <version>1.4.0-SNAPSHOT</version>
+        <executions>
+          <execution>
+            <phase>generate-sources</phase>
+            <goals>
+              <goal>compile</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+</project>

Added: hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-common/src/main/avro/ResourceTracker.genavro
URL: http://svn.apache.org/viewvc/hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-common/src/main/avro/ResourceTracker.genavro?rev=1082677&view=auto
==============================================================================
--- hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-common/src/main/avro/ResourceTracker.genavro (added)
+++ hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-common/src/main/avro/ResourceTracker.genavro Thu Mar 17 20:21:13 2011
@@ -0,0 +1,33 @@
+@namespace("org.apache.hadoop.yarn")
+protocol ResourceTracker {
+
+  import idl "yarn/yarn-api/src/main/avro/yarn-types.genavro";
+  
+  // ResourceTracker
+  record NodeID {
+    int id;
+  }
+ 
+  record NodeStatus {
+    NodeID nodeId;
+	int responseId;
+	long lastSeen;
+    map<array<org.apache.hadoop.yarn.Container>> containers;
+  }
+
+  record RegistrationResponse {
+    NodeID nodeID;
+    union {bytes, null} secretKey;
+  }
+
+  record HeartbeatResponse {
+    int responseId;
+    boolean reboot;
+    array<org.apache.hadoop.yarn.Container> containersToCleanup;
+    array<org.apache.hadoop.yarn.ApplicationID> appplicationsToCleanup;
+  }
+  
+  RegistrationResponse registerNodeManager(string node, org.apache.hadoop.yarn.Resource resource) throws YarnRemoteException;
+  HeartbeatResponse nodeHeartbeat(NodeStatus nodeStatus) throws YarnRemoteException;
+  
+}

Added: hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-common/src/main/java/org/apache/hadoop/yarn/lib/ZKClient.java
URL: http://svn.apache.org/viewvc/hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-common/src/main/java/org/apache/hadoop/yarn/lib/ZKClient.java?rev=1082677&view=auto
==============================================================================
--- hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-common/src/main/java/org/apache/hadoop/yarn/lib/ZKClient.java (added)
+++ hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-common/src/main/java/org/apache/hadoop/yarn/lib/ZKClient.java Thu Mar 17 20:21:13 2011
@@ -0,0 +1,133 @@
+/**
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements.  See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership.  The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License.  You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+package org.apache.hadoop.yarn.lib;
+
+import java.io.IOException;
+import java.util.List;
+
+import org.apache.zookeeper.CreateMode;
+import org.apache.zookeeper.KeeperException;
+import org.apache.zookeeper.WatchedEvent;
+import org.apache.zookeeper.Watcher;
+import org.apache.zookeeper.ZooDefs;
+import org.apache.zookeeper.ZooKeeper;
+import org.apache.zookeeper.data.Stat;
+
+/** ZK Registration Library
+ * currently does not use any authorization
+ */
+public class ZKClient {
+  private ZooKeeper zkClient;
+  
+  /**
+   * the zookeeper client library to 
+   * talk to zookeeper 
+   * @param string the host
+   * @throws throws IOException
+   */
+  public ZKClient(String string) throws IOException {
+    zkClient = new ZooKeeper(string, 30000, new ZKWatcher());
+  }
+  
+  /**
+   * register the service to a specific path
+   * @param path the path in zookeeper namespace to register to
+   * @param data the data that is part of this registration
+   * @throws IOException
+   * @throws InterruptedException
+   */
+  public void registerService(String path, String data) throws
+    IOException, InterruptedException {
+    try {
+      zkClient.create(path, data.getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, 
+          CreateMode.EPHEMERAL);
+    } catch(KeeperException ke) {
+      throw new IOException(ke);
+    }
+  }
+  
+  /**
+   * unregister the service. 
+   * @param path the path at which the service was registered
+   * @throws IOException
+   * @throws InterruptedException
+   */
+  public void unregisterService(String path) throws IOException,
+    InterruptedException {
+    try {
+      zkClient.delete(path, -1);
+    } catch(KeeperException ke) {
+      throw new IOException(ke);
+    }
+  }
+
+  /**
+   * list the services registered under a path
+   * @param path the path under which services are
+   * registered
+   * @return the list of names of services registered
+   * @throws IOException 
+   * @throws InterruptedException
+   */
+  public List<String> listServices(String path) throws IOException, 
+    InterruptedException {
+    List<String> children = null;
+    try {
+      children = zkClient.getChildren(path, false);
+    } catch(KeeperException ke) {
+      throw new IOException(ke);
+    }
+    return children;
+  }
+  
+  /**
+   * get data published by the service at the registration address
+   * @param path the path where the service is registered 
+   * @return  the data of the registered service
+   * @throws IOException
+   * @throws InterruptedException
+   */
+  public String getServiceData(String path) throws IOException,
+    InterruptedException {
+    String data;
+    try {
+      Stat stat = new Stat();
+      byte[] byteData = zkClient.getData(path, false, stat);
+      data = new String(byteData);
+    } catch(KeeperException ke) {
+      throw new IOException(ke);
+    }
+    return data;
+  }
+  
+  
+  /**
+   * a watcher class that handles what events from
+   * zookeeper.
+   *
+   */
+  private static class ZKWatcher implements Watcher {
+
+    @Override
+    public void process(WatchedEvent arg0) {
+      
+    }
+    
+  }
+}

Added: hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/RMNMSecurityInfoClass.java
URL: http://svn.apache.org/viewvc/hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/RMNMSecurityInfoClass.java?rev=1082677&view=auto
==============================================================================
--- hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/RMNMSecurityInfoClass.java (added)
+++ hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/RMNMSecurityInfoClass.java Thu Mar 17 20:21:13 2011
@@ -0,0 +1,56 @@
+/**
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements.  See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership.  The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License.  You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+package org.apache.hadoop.yarn.server;
+
+import java.lang.annotation.Annotation;
+
+import org.apache.hadoop.security.KerberosInfo;
+import org.apache.hadoop.security.SecurityInfo;
+import org.apache.hadoop.security.token.TokenInfo;
+import org.apache.hadoop.yarn.conf.YarnConfiguration;
+
+public class RMNMSecurityInfoClass implements SecurityInfo {
+
+  @Override
+  public KerberosInfo getKerborosInfo(Class<?> protocol) {
+    return new KerberosInfo() {
+
+      @Override
+      public Class<? extends Annotation> annotationType() {
+        return null;
+      }
+
+      @Override
+      public String serverPrincipal() {
+        return YarnConfiguration.RM_SERVER_PRINCIPAL_KEY;
+      }
+
+      @Override
+      public String clientPrincipal() {
+        return YarnServerConfig.NM_SERVER_PRINCIPAL_KEY;
+      }
+    };
+  }
+
+  @Override
+  public TokenInfo getTokenInfo(Class<?> protocol) {
+    return null;
+  }
+
+}

Added: hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/YarnServerConfig.java
URL: http://svn.apache.org/viewvc/hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/YarnServerConfig.java?rev=1082677&view=auto
==============================================================================
--- hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/YarnServerConfig.java (added)
+++ hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/YarnServerConfig.java Thu Mar 17 20:21:13 2011
@@ -0,0 +1,30 @@
+/**
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements.  See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership.  The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License.  You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+package org.apache.hadoop.yarn.server;
+
+import org.apache.hadoop.yarn.conf.YarnConfiguration;
+
+public class YarnServerConfig {
+  public static final String NM_SERVER_PRINCIPAL_KEY =
+      "yarn.nodemanager.principal";
+  public static final String RESOURCETRACKER_ADDRESS =
+      YarnConfiguration.RM_PREFIX + "resourcetracker.address";
+  public static final String DEFAULT_RESOURCETRACKER_BIND_ADDRESS =
+      "0.0.0.0:8020";
+}
\ No newline at end of file

Added: hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/security/ContainerTokenSecretManager.java
URL: http://svn.apache.org/viewvc/hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/security/ContainerTokenSecretManager.java?rev=1082677&view=auto
==============================================================================
--- hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/security/ContainerTokenSecretManager.java (added)
+++ hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/security/ContainerTokenSecretManager.java Thu Mar 17 20:21:13 2011
@@ -0,0 +1,77 @@
+/**
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements.  See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership.  The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License.  You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+package org.apache.hadoop.yarn.server.security;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.crypto.SecretKey;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.hadoop.security.token.SecretManager;
+import org.apache.hadoop.yarn.security.ContainerTokenIdentifier;
+
+public class ContainerTokenSecretManager extends
+    SecretManager<ContainerTokenIdentifier> {
+
+  private static Log LOG = LogFactory
+      .getLog(ContainerTokenSecretManager.class);
+
+  private Map<String, SecretKey> secretkeys =
+      new HashMap<String, SecretKey>();
+
+  // Used by master for generation of secretyKey per host
+  public SecretKey createAndGetSecretKey(CharSequence hostName) {
+    String hostNameStr = hostName.toString();
+    if (!this.secretkeys.containsKey(hostNameStr)) {
+      LOG.info("Creating secretKey for NM " + hostNameStr);
+      this.secretkeys.put(hostNameStr,
+          createSecretKey("mySecretKey".getBytes()));
+    }
+    return this.secretkeys.get(hostNameStr);
+  }
+
+  // Used by slave for using secretKey sent by the master.
+  public void setSecretKey(CharSequence hostName, byte[] secretKeyBytes) {
+    this.secretkeys.put(hostName.toString(), createSecretKey(secretKeyBytes));
+  }
+
+  @Override
+  public byte[] createPassword(ContainerTokenIdentifier identifier) {
+    LOG.info("Creating password for " + identifier.getContainerID()
+        + " to be run on NM " + identifier.getNmHostName() + " ======= " + this.secretkeys.get(identifier.getNmHostName()));
+    return createPassword(identifier.getBytes(),
+        this.secretkeys.get(identifier.getNmHostName()));
+  }
+
+  @Override
+  public byte[] retrievePassword(ContainerTokenIdentifier identifier)
+      throws org.apache.hadoop.security.token.SecretManager.InvalidToken {
+    LOG.info("Retrieving password for " + identifier.getContainerID()
+        + " to be run on NM " + identifier.getNmHostName());
+    return createPassword(identifier.getBytes(),
+        this.secretkeys.get(identifier.getNmHostName()));
+  }
+
+  @Override
+  public ContainerTokenIdentifier createIdentifier() {
+    return new ContainerTokenIdentifier();
+  }
+}

Added: hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-common/src/main/resources/yarn-default.xml
URL: http://svn.apache.org/viewvc/hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-common/src/main/resources/yarn-default.xml?rev=1082677&view=auto
==============================================================================
--- hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-common/src/main/resources/yarn-default.xml (added)
+++ hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-common/src/main/resources/yarn-default.xml Thu Mar 17 20:21:13 2011
@@ -0,0 +1,107 @@
+<?xml version="1.0"?>
+<configuration>
+
+ <property>
+    <name>yarn.resourcemanager.principal</name>
+    <value>rm/sightbusy-lx@LOCALHOST</value>
+  </property>
+
+ <property>
+    <name>yarn.nodemanager.principal</name>
+    <value>nm/sightbusy-lx@LOCALHOST</value>
+  </property>
+
+
+<!-- All resourcemanager related configuration properties -->
+
+  <property>
+    <name>yarn.server.resourcemanager.address</name>
+    <value>0.0.0.0:8020</value>
+  </property>
+
+ <property>
+    <name>yarn.server.resourcemanager.resourcetracker.address</name>
+    <value>0.0.0.0:8025</value>
+  </property>
+
+ <property>
+    <name>yarn.server.resourcemanager.scheduler.address</name>
+    <value>0.0.0.0:8030</value>
+  </property>
+
+  <property>
+    <name>yarn.server.resourcemanager.keytab</name>
+    <value>/etc/krb5.keytab</value>
+  </property>
+
+<!-- All nodemanager related configuration properties -->
+
+  <property>
+    <name>yarn.server.nodemanager.local-dir</name>
+    <value>/tmp/nm-local-dir</value>
+  </property>
+
+  <property>
+    <name>yarn.apps.stagingDir</name>
+    <value>/tmp/hadoop-yarn/${user.name}/staging</value>
+   </property>
+
+
+  <property>
+    <name>yarn.server.nodemanager.keytab</name>
+    <value>/etc/krb5.keytab</value>
+  </property>
+
+  <property>
+    <name>yarn.server.nodemanager.container-executor.class</name>
+    <value>org.apache.hadoop.yarn.server.nodemanager.DefaultContainerExecutor</value>
+    <!--<value>org.apache.hadoop.yarn.server.nodemanager.LinuxContainerExecutor</value>-->
+  </property>
+
+  <property><name>NM_HOSTS</name><value>0.0.0.0:45454</value></property> 
+
+  <property>
+    <name>yarn.server.nodemanager.address</name>
+    <value>0.0.0.0:45454</value>
+  </property>
+
+<property><name>yarn.server.nodemanager.connect.rm</name><value>true</value></property> 
+
+<!-- All MRAppMaster related configuration properties -->
+
+  <property>
+    <name>yarn.server.mapreduce-appmanager.attempt-listener.bindAddress</name>
+    <value>0.0.0.0</value>
+  </property>
+
+  <property>
+    <name>yarn.server.mapreduce-appmanager.client-service.bindAddress</name>
+    <value>0.0.0.0</value>
+  </property>
+
+
+  <property>
+    <name>mapreduce.job.jar</name>
+    <value></value>
+    <!--<value>~/Workspace/eclipse-workspace/yarn/yarn-mapreduce/yarn-mapreduce-app/target/yarn-mapreduce-app-1.0-SNAPSHOT.jar</value>-->
+  </property>
+
+  <property>
+   <name>mapreduce.job.hdfs-servers</name>
+   <value>${fs.default.name}</value>
+ </property>
+
+  <property>
+  <name>nodemanager.auxiluary.services</name>
+  <value></value>
+  <!--
+  <value>mapreduce.shuffle</value>
+  -->
+  </property>
+
+  <property>
+  <name>nodemanager.aux.service.mapreduce.shuffle.class</name>
+  <value>org.apache.hadoop.mapred.ShuffleHandler</value>
+  </property>
+
+</configuration>

Added: hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-common/src/test/java/org/apache/hadoop/yarn/lib/TestZKClient.java
URL: http://svn.apache.org/viewvc/hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-common/src/test/java/org/apache/hadoop/yarn/lib/TestZKClient.java?rev=1082677&view=auto
==============================================================================
--- hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-common/src/test/java/org/apache/hadoop/yarn/lib/TestZKClient.java (added)
+++ hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-common/src/test/java/org/apache/hadoop/yarn/lib/TestZKClient.java Thu Mar 17 20:21:13 2011
@@ -0,0 +1,187 @@
+/**
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements.  See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership.  The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License.  You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+package org.apache.hadoop.yarn.lib;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.net.InetSocketAddress;
+import java.net.Socket;
+
+import junit.framework.Assert;
+
+import org.apache.hadoop.yarn.lib.ZKClient;
+import org.apache.zookeeper.server.NIOServerCnxn;
+import org.apache.zookeeper.server.ZKDatabase;
+import org.apache.zookeeper.server.ZooKeeperServer;
+import org.apache.zookeeper.server.persistence.FileTxnLog;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+public class TestZKClient  {
+
+  public static int CONNECTION_TIMEOUT = 30000;
+  static final File BASETEST =
+    new File(System.getProperty("build.test.dir", "target/zookeeper-build"));
+
+  protected String hostPort = "127.0.0.1:2000";
+  protected int maxCnxns = 0;
+  protected NIOServerCnxn.Factory factory = null;
+  protected File tmpDir = null;
+
+  public static String send4LetterWord(String host, int port, String cmd)
+  throws IOException
+  {
+    Socket sock = new Socket(host, port);
+    BufferedReader reader = null;
+    try {
+      OutputStream outstream = sock.getOutputStream();
+      outstream.write(cmd.getBytes());
+      outstream.flush();
+      // this replicates NC - close the output stream before reading
+      sock.shutdownOutput();
+
+      reader =
+        new BufferedReader(
+            new InputStreamReader(sock.getInputStream()));
+      StringBuilder sb = new StringBuilder();
+      String line;
+      while((line = reader.readLine()) != null) {
+        sb.append(line + "\n");
+      }
+      return sb.toString();
+    } finally {
+      sock.close();
+      if (reader != null) {
+        reader.close();
+      }
+    }
+  }
+
+  public static boolean waitForServerDown(String hp, long timeout) {
+    long start = System.currentTimeMillis();
+    while (true) {
+      try {
+        String host = hp.split(":")[0];
+        int port = Integer.parseInt(hp.split(":")[1]);
+        send4LetterWord(host, port, "stat");
+      } catch (IOException e) {
+        return true;
+      }
+
+      if (System.currentTimeMillis() > start + timeout) {
+        break;
+      }
+      try {
+        Thread.sleep(250);
+      } catch (InterruptedException e) {
+        // ignore
+      }
+    }
+    return false;
+  }
+
+
+  public static boolean waitForServerUp(String hp, long timeout) {
+    long start = System.currentTimeMillis();
+    while (true) {
+      try {
+        String host = hp.split(":")[0];
+        int port = Integer.parseInt(hp.split(":")[1]);
+        // if there are multiple hostports, just take the first one
+        String result = send4LetterWord(host, port, "stat");
+        if (result.startsWith("Zookeeper version:")) {
+          return true;
+        }
+      } catch (IOException e) {
+      }
+      if (System.currentTimeMillis() > start + timeout) {
+        break;
+      }
+      try {
+        Thread.sleep(250);
+      } catch (InterruptedException e) {
+        // ignore
+      }
+    }
+    return false;
+  }
+
+  public static File createTmpDir(File parentDir) throws IOException {
+    File tmpFile = File.createTempFile("test", ".junit", parentDir);
+    // don't delete tmpFile - this ensures we don't attempt to create
+    // a tmpDir with a duplicate name
+    File tmpDir = new File(tmpFile + ".dir");
+    Assert.assertFalse(tmpDir.exists()); 
+    Assert.assertTrue(tmpDir.mkdirs());
+    return tmpDir;
+  }
+
+  @Before
+  public void setUp() throws IOException, InterruptedException {
+    System.setProperty("zookeeper.preAllocSize", "100");
+    FileTxnLog.setPreallocSize(100 * 1024);
+    if (!BASETEST.exists()) {
+      BASETEST.mkdirs();
+    }
+    File dataDir = createTmpDir(BASETEST);
+    ZooKeeperServer zks = new ZooKeeperServer(dataDir, dataDir, 3000);
+    final int PORT = Integer.parseInt(hostPort.split(":")[1]);
+    if (factory == null) {
+      factory = new NIOServerCnxn.Factory(new InetSocketAddress(PORT),maxCnxns);
+    }
+    factory.startup(zks);
+    Assert.assertTrue("waiting for server up",
+        waitForServerUp("127.0.0.1:" + PORT,
+            CONNECTION_TIMEOUT));
+    
+  }
+  
+  @After
+  public void tearDown() throws IOException, InterruptedException {
+    if (factory != null) {
+      ZKDatabase zkDb = factory.getZooKeeperServer().getZKDatabase();
+      factory.shutdown();
+      try {
+        zkDb.close();
+      } catch (IOException ie) {
+      }
+      final int PORT = Integer.parseInt(hostPort.split(":")[1]);
+
+      Assert.assertTrue("waiting for server down",
+          waitForServerDown("127.0.0.1:" + PORT,
+              CONNECTION_TIMEOUT));
+    }
+
+  }
+  @Test
+  public void testzkClient() throws Exception {
+    test("/some/test");
+  }
+
+  private void test(String testClient) throws Exception { 
+    ZKClient client = new ZKClient(hostPort);
+    client.registerService("/nodemanager", "hostPort");
+    client.unregisterService("/nodemanager");
+  }
+
+}



Mime
View raw message