Java Code Examples for org.apache.hadoop.yarn.webapp.WebApp

The following examples show how to use org.apache.hadoop.yarn.webapp.WebApp. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: hadoop   Source File: TestHsWebServicesAttempts.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void configureServlets() {

  appContext = new MockHistoryContext(0, 1, 2, 1);
  webApp = mock(HsWebApp.class);
  when(webApp.name()).thenReturn("hsmockwebapp");

  bind(JAXBContextResolver.class);
  bind(HsWebServices.class);
  bind(GenericExceptionHandler.class);
  bind(WebApp.class).toInstance(webApp);
  bind(AppContext.class).toInstance(appContext);
  bind(HistoryContext.class).toInstance(appContext);
  bind(Configuration.class).toInstance(conf);

  serve("/*").with(GuiceContainer.class);
}
 
Example 2
Source Project: hadoop   Source File: TestHsWebServicesAcls.java    License: Apache License 2.0 6 votes vote down vote up
@Before
public void setup() throws IOException {
  this.conf = new JobConf();
  this.conf.set(CommonConfigurationKeys.HADOOP_SECURITY_GROUP_MAPPING,
      NullGroupsProvider.class.getName());
  this.conf.setBoolean(MRConfig.MR_ACLS_ENABLED, true);
  Groups.getUserToGroupsMappingService(conf);
  this.ctx = buildHistoryContext(this.conf);
  WebApp webApp = mock(HsWebApp.class);
  when(webApp.name()).thenReturn("hsmockwebapp");
  this.hsWebServices= new HsWebServices(ctx, conf, webApp);
  this.hsWebServices.setResponse(mock(HttpServletResponse.class));

  Job job = ctx.getAllJobs().values().iterator().next();
  this.jobIdStr = job.getID().toString();
  Task task = job.getTasks().values().iterator().next();
  this.taskIdStr = task.getID().toString();
  this.taskAttemptIdStr =
      task.getAttempts().keySet().iterator().next().toString();
}
 
Example 3
Source Project: hadoop   Source File: TestHsWebServices.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void configureServlets() {

  appContext = new MockHistoryContext(0, 1, 1, 1);
  JobHistory jobHistoryService = new JobHistory();
  HistoryContext historyContext = (HistoryContext) jobHistoryService;
  webApp = new HsWebApp(historyContext);

  bind(JAXBContextResolver.class);
  bind(HsWebServices.class);
  bind(GenericExceptionHandler.class);
  bind(WebApp.class).toInstance(webApp);
  bind(AppContext.class).toInstance(appContext);
  bind(HistoryContext.class).toInstance(appContext);
  bind(Configuration.class).toInstance(conf);

  serve("/*").with(GuiceContainer.class);
}
 
Example 4
Source Project: hadoop   Source File: TestHsWebServicesJobs.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void configureServlets() {

  appContext = new MockHistoryContext(0, 1, 2, 1, false);
  webApp = mock(HsWebApp.class);
  when(webApp.name()).thenReturn("hsmockwebapp");

  bind(JAXBContextResolver.class);
  bind(HsWebServices.class);
  bind(GenericExceptionHandler.class);
  bind(WebApp.class).toInstance(webApp);
  bind(AppContext.class).toInstance(appContext);
  bind(HistoryContext.class).toInstance(appContext);
  bind(Configuration.class).toInstance(conf);

  serve("/*").with(GuiceContainer.class);
}
 
Example 5
Source Project: hadoop   Source File: TestHsWebServicesJobsQuery.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void configureServlets() {

  appContext = new MockHistoryContext(3, 2, 1);
  webApp = mock(HsWebApp.class);
  when(webApp.name()).thenReturn("hsmockwebapp");

  bind(JAXBContextResolver.class);
  bind(HsWebServices.class);
  bind(GenericExceptionHandler.class);
  bind(WebApp.class).toInstance(webApp);
  bind(AppContext.class).toInstance(appContext);
  bind(HistoryContext.class).toInstance(appContext);
  bind(Configuration.class).toInstance(conf);

  serve("/*").with(GuiceContainer.class);
}
 
Example 6
Source Project: hadoop   Source File: TestHsWebServicesTasks.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void configureServlets() {

  appContext = new MockHistoryContext(0, 1, 2, 1);
  webApp = mock(HsWebApp.class);
  when(webApp.name()).thenReturn("hsmockwebapp");

  bind(JAXBContextResolver.class);
  bind(HsWebServices.class);
  bind(GenericExceptionHandler.class);
  bind(WebApp.class).toInstance(webApp);
  bind(AppContext.class).toInstance(appContext);
  bind(HistoryContext.class).toInstance(appContext);
  bind(Configuration.class).toInstance(conf);

  serve("/*").with(GuiceContainer.class);
}
 
Example 7
Source Project: big-c   Source File: TestHsWebServicesAttempts.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void configureServlets() {

  appContext = new MockHistoryContext(0, 1, 2, 1);
  webApp = mock(HsWebApp.class);
  when(webApp.name()).thenReturn("hsmockwebapp");

  bind(JAXBContextResolver.class);
  bind(HsWebServices.class);
  bind(GenericExceptionHandler.class);
  bind(WebApp.class).toInstance(webApp);
  bind(AppContext.class).toInstance(appContext);
  bind(HistoryContext.class).toInstance(appContext);
  bind(Configuration.class).toInstance(conf);

  serve("/*").with(GuiceContainer.class);
}
 
Example 8
Source Project: big-c   Source File: TestHsWebServicesAcls.java    License: Apache License 2.0 6 votes vote down vote up
@Before
public void setup() throws IOException {
  this.conf = new JobConf();
  this.conf.set(CommonConfigurationKeys.HADOOP_SECURITY_GROUP_MAPPING,
      NullGroupsProvider.class.getName());
  this.conf.setBoolean(MRConfig.MR_ACLS_ENABLED, true);
  Groups.getUserToGroupsMappingService(conf);
  this.ctx = buildHistoryContext(this.conf);
  WebApp webApp = mock(HsWebApp.class);
  when(webApp.name()).thenReturn("hsmockwebapp");
  this.hsWebServices= new HsWebServices(ctx, conf, webApp);
  this.hsWebServices.setResponse(mock(HttpServletResponse.class));

  Job job = ctx.getAllJobs().values().iterator().next();
  this.jobIdStr = job.getID().toString();
  Task task = job.getTasks().values().iterator().next();
  this.taskIdStr = task.getID().toString();
  this.taskAttemptIdStr =
      task.getAttempts().keySet().iterator().next().toString();
}
 
Example 9
Source Project: big-c   Source File: TestHsWebServices.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void configureServlets() {

  appContext = new MockHistoryContext(0, 1, 1, 1);
  JobHistory jobHistoryService = new JobHistory();
  HistoryContext historyContext = (HistoryContext) jobHistoryService;
  webApp = new HsWebApp(historyContext);

  bind(JAXBContextResolver.class);
  bind(HsWebServices.class);
  bind(GenericExceptionHandler.class);
  bind(WebApp.class).toInstance(webApp);
  bind(AppContext.class).toInstance(appContext);
  bind(HistoryContext.class).toInstance(appContext);
  bind(Configuration.class).toInstance(conf);

  serve("/*").with(GuiceContainer.class);
}
 
Example 10
Source Project: big-c   Source File: TestHsWebServicesJobs.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void configureServlets() {

  appContext = new MockHistoryContext(0, 1, 2, 1, false);
  webApp = mock(HsWebApp.class);
  when(webApp.name()).thenReturn("hsmockwebapp");

  bind(JAXBContextResolver.class);
  bind(HsWebServices.class);
  bind(GenericExceptionHandler.class);
  bind(WebApp.class).toInstance(webApp);
  bind(AppContext.class).toInstance(appContext);
  bind(HistoryContext.class).toInstance(appContext);
  bind(Configuration.class).toInstance(conf);

  serve("/*").with(GuiceContainer.class);
}
 
Example 11
Source Project: big-c   Source File: TestHsWebServicesJobsQuery.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void configureServlets() {

  appContext = new MockHistoryContext(3, 2, 1);
  webApp = mock(HsWebApp.class);
  when(webApp.name()).thenReturn("hsmockwebapp");

  bind(JAXBContextResolver.class);
  bind(HsWebServices.class);
  bind(GenericExceptionHandler.class);
  bind(WebApp.class).toInstance(webApp);
  bind(AppContext.class).toInstance(appContext);
  bind(HistoryContext.class).toInstance(appContext);
  bind(Configuration.class).toInstance(conf);

  serve("/*").with(GuiceContainer.class);
}
 
Example 12
Source Project: big-c   Source File: TestHsWebServicesTasks.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void configureServlets() {

  appContext = new MockHistoryContext(0, 1, 2, 1);
  webApp = mock(HsWebApp.class);
  when(webApp.name()).thenReturn("hsmockwebapp");

  bind(JAXBContextResolver.class);
  bind(HsWebServices.class);
  bind(GenericExceptionHandler.class);
  bind(WebApp.class).toInstance(webApp);
  bind(AppContext.class).toInstance(appContext);
  bind(HistoryContext.class).toInstance(appContext);
  bind(Configuration.class).toInstance(conf);

  serve("/*").with(GuiceContainer.class);
}
 
Example 13
Source Project: XLearning   Source File: InfoPage.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected  Class<? extends SubView> header() {
  try {
    if (WebApps.Builder.class.getMethod("build", WebApp.class) != null) {
      return HeaderBlock.class;
    }
  } catch (NoSuchMethodException e) {
    LOG.debug("current hadoop version don't have the method build of Class " + WebApps.class.toString() + ". For More Detail: " + e);
    return org.apache.hadoop.yarn.webapp.view.HeaderBlock.class;
  }
  return null;
}
 
Example 14
Source Project: XLearning   Source File: HsJobPage.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected  Class<? extends SubView> header() {
  try {
    if (WebApps.Builder.class.getMethod("build", WebApp.class) != null) {
      return HeaderBlock.class;
    }
  } catch (NoSuchMethodException e) {
    LOG.debug("current hadoop version don't have the method build of Class " + WebApps.class.toString() + ". For More Detail: " + e);
    return org.apache.hadoop.yarn.webapp.view.HeaderBlock.class;
  }
  return null;
}
 
Example 15
Source Project: hadoop   Source File: NMWebServices.java    License: Apache License 2.0 5 votes vote down vote up
@Inject
public NMWebServices(final Context nm, final ResourceView view,
    final WebApp webapp) {
  this.nmContext = nm;
  this.rview = view;
  this.webapp = webapp;
}
 
Example 16
Source Project: hadoop   Source File: TestHsWebServicesJobs.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testJobCountersForKilledJob() throws Exception {
  WebResource r = resource();
  appContext = new MockHistoryContext(0, 1, 1, 1, true);
  injector = Guice.createInjector(new ServletModule() {
    @Override
    protected void configureServlets() {

      webApp = mock(HsWebApp.class);
      when(webApp.name()).thenReturn("hsmockwebapp");

      bind(JAXBContextResolver.class);
      bind(HsWebServices.class);
      bind(GenericExceptionHandler.class);
      bind(WebApp.class).toInstance(webApp);
      bind(AppContext.class).toInstance(appContext);
      bind(HistoryContext.class).toInstance(appContext);
      bind(Configuration.class).toInstance(conf);

      serve("/*").with(GuiceContainer.class);
    }
  });
  
  Map<JobId, Job> jobsMap = appContext.getAllJobs();
  for (JobId id : jobsMap.keySet()) {
    String jobId = MRApps.toString(id);

    ClientResponse response = r.path("ws").path("v1").path("history")
        .path("mapreduce").path("jobs").path(jobId).path("counters/")
        .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
    assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
    JSONObject json = response.getEntity(JSONObject.class);
    assertEquals("incorrect number of elements", 1, json.length());
    JSONObject info = json.getJSONObject("jobCounters");
    WebServicesTestUtils.checkStringMatch("id", MRApps.toString(id),
        info.getString("id"));
    assertTrue("Job shouldn't contain any counters", info.length() == 1);
  }
}
 
Example 17
Source Project: big-c   Source File: NMWebServices.java    License: Apache License 2.0 5 votes vote down vote up
@Inject
public NMWebServices(final Context nm, final ResourceView view,
    final WebApp webapp) {
  this.nmContext = nm;
  this.rview = view;
  this.webapp = webapp;
}
 
Example 18
Source Project: big-c   Source File: TestHsWebServicesJobs.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testJobCountersForKilledJob() throws Exception {
  WebResource r = resource();
  appContext = new MockHistoryContext(0, 1, 1, 1, true);
  injector = Guice.createInjector(new ServletModule() {
    @Override
    protected void configureServlets() {

      webApp = mock(HsWebApp.class);
      when(webApp.name()).thenReturn("hsmockwebapp");

      bind(JAXBContextResolver.class);
      bind(HsWebServices.class);
      bind(GenericExceptionHandler.class);
      bind(WebApp.class).toInstance(webApp);
      bind(AppContext.class).toInstance(appContext);
      bind(HistoryContext.class).toInstance(appContext);
      bind(Configuration.class).toInstance(conf);

      serve("/*").with(GuiceContainer.class);
    }
  });
  
  Map<JobId, Job> jobsMap = appContext.getAllJobs();
  for (JobId id : jobsMap.keySet()) {
    String jobId = MRApps.toString(id);

    ClientResponse response = r.path("ws").path("v1").path("history")
        .path("mapreduce").path("jobs").path(jobId).path("counters/")
        .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
    assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
    JSONObject json = response.getEntity(JSONObject.class);
    assertEquals("incorrect number of elements", 1, json.length());
    JSONObject info = json.getJSONObject("jobCounters");
    WebServicesTestUtils.checkStringMatch("id", MRApps.toString(id),
        info.getString("id"));
    assertTrue("Job shouldn't contain any counters", info.length() == 1);
  }
}
 
Example 19
Source Project: Bats   Source File: StreamingAppMasterService.java    License: Apache License 2.0 4 votes vote down vote up
@Override
protected void serviceStart() throws Exception
{
  super.serviceStart();
  if (UserGroupInformation.isSecurityEnabled()) {
    delegationTokenManager.startThreads();
  }

  // write the connect address for containers to DFS
  InetSocketAddress connectAddress = NetUtils.getConnectAddress(this.heartbeatListener.getAddress());
  URI connectUri = RecoverableRpcProxy.toConnectURI(connectAddress);
  FSRecoveryHandler recoveryHandler = new FSRecoveryHandler(dag.assertAppPath(), getConfig());
  recoveryHandler.writeConnectUri(connectUri.toString());

  // start web service
  try {
    org.mortbay.log.Log.setLog(null);
  } catch (Throwable throwable) {
    // SPOI-2687. As part of Pivotal Certification, we need to catch ClassNotFoundException as Pivotal was using
    // Jetty 7 where as other distros are using Jetty 6.
    // LOG.error("can't set the log to null: ", throwable);
  }

  try {
    Configuration config = SecurityUtils.configureWebAppSecurity(getConfig(), dag.getValue(Context.DAGContext.SSL_CONFIG));
    WebApp webApp = WebApps.$for("stram", StramAppContext.class, appContext, "ws").with(config).start(new StramWebApp(this.dnmgr));
    LOG.info("Started web service at port: " + webApp.port());
    // best effort to produce FQDN for the client to connect with
    // (when SSL is enabled, it may be required to match the certificate)
    connectAddress = NetUtils.getConnectAddress(webApp.getListenerAddress());
    String hostname = connectAddress.getAddress().getCanonicalHostName();
    if (hostname.equals(connectAddress.getAddress().getHostAddress())) {
      // lookup didn't yield a name
      hostname = connectAddress.getHostName();
    }
    appMasterTrackingUrl = hostname + ":" + webApp.port();
    if (ConfigUtils.isSSLEnabled(config)) {
      appMasterTrackingUrl = "https://" + appMasterTrackingUrl;
    }
    LOG.info("Setting tracking URL to: " + appMasterTrackingUrl);
  } catch (Exception e) {
    LOG.error("Webapps failed to start. Ignoring for now:", e);
  }
}
 
Example 20
Source Project: hadoop   Source File: TestParseRoute.java    License: Apache License 2.0 4 votes vote down vote up
@Test public void testNormalAction() {
  assertEquals(Arrays.asList("/foo/action", "foo", "action", ":a1", ":a2"),
               WebApp.parseRoute("/foo/action/:a1/:a2"));
}
 
Example 21
Source Project: hadoop   Source File: TestParseRoute.java    License: Apache License 2.0 4 votes vote down vote up
@Test public void testDefaultController() {
  assertEquals(Arrays.asList("/", "default", "index"),
               WebApp.parseRoute("/"));
}
 
Example 22
Source Project: hadoop   Source File: TestParseRoute.java    License: Apache License 2.0 4 votes vote down vote up
@Test public void testDefaultAction() {
  assertEquals(Arrays.asList("/foo", "foo", "index"),
               WebApp.parseRoute("/foo"));
  assertEquals(Arrays.asList("/foo", "foo", "index"),
               WebApp.parseRoute("/foo/"));
}
 
Example 23
Source Project: hadoop   Source File: TestParseRoute.java    License: Apache License 2.0 4 votes vote down vote up
@Test public void testMissingAction() {
  assertEquals(Arrays.asList("/foo", "foo", "index", ":a1"),
               WebApp.parseRoute("/foo/:a1"));
}
 
Example 24
Source Project: hadoop   Source File: TestParseRoute.java    License: Apache License 2.0 4 votes vote down vote up
@Test public void testDefaultCapture() {
  assertEquals(Arrays.asList("/", "default", "index", ":a"),
               WebApp.parseRoute("/:a"));
}
 
Example 25
Source Project: hadoop   Source File: TestParseRoute.java    License: Apache License 2.0 4 votes vote down vote up
@Test public void testPartialCapture1() {
  assertEquals(Arrays.asList("/foo/action/bar", "foo", "action", "bar", ":a"),
               WebApp.parseRoute("/foo/action/bar/:a"));
}
 
Example 26
Source Project: hadoop   Source File: TestParseRoute.java    License: Apache License 2.0 4 votes vote down vote up
@Test public void testPartialCapture2() {
  assertEquals(Arrays.asList("/foo/action", "foo", "action", ":a1", "bar",
                             ":a2", ":a3"),
               WebApp.parseRoute("/foo/action/:a1/bar/:a2/:a3"));
}
 
Example 27
Source Project: hadoop   Source File: TestParseRoute.java    License: Apache License 2.0 4 votes vote down vote up
@Test public void testLeadingPaddings() {
  assertEquals(Arrays.asList("/foo/action", "foo", "action", ":a"),
               WebApp.parseRoute(" /foo/action/ :a"));
}
 
Example 28
Source Project: hadoop   Source File: TestParseRoute.java    License: Apache License 2.0 4 votes vote down vote up
@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 / "));
}
 
Example 29
Source Project: hadoop   Source File: TestParseRoute.java    License: Apache License 2.0 4 votes vote down vote up
@Test(expected=WebAppException.class) public void testMissingLeadingSlash() {
  WebApp.parseRoute("foo/bar");
}
 
Example 30
Source Project: hadoop   Source File: TestNMWebServicesApps.java    License: Apache License 2.0 4 votes vote down vote up
@Override
protected void configureServlets() {
  conf.set(YarnConfiguration.NM_LOCAL_DIRS, testRootDir.getAbsolutePath());
  conf.set(YarnConfiguration.NM_LOG_DIRS, testLogDir.getAbsolutePath());
  LocalDirsHandlerService dirsHandler = new LocalDirsHandlerService();
  NodeHealthCheckerService healthChecker = new NodeHealthCheckerService(
      NodeManager.getNodeHealthScriptRunner(conf), dirsHandler);
  healthChecker.init(conf);
  dirsHandler = healthChecker.getDiskHandler();
  aclsManager = new ApplicationACLsManager(conf);
  nmContext = new NodeManager.NMContext(null, null, dirsHandler,
      aclsManager, null);
  NodeId nodeId = NodeId.newInstance("testhost.foo.com", 9999);
  ((NodeManager.NMContext)nmContext).setNodeId(nodeId);
  resourceView = new ResourceView() {
    @Override
    public long getVmemAllocatedForContainers() {
      // 15.5G in bytes
      return new Long("16642998272");
    }

    @Override
    public long getPmemAllocatedForContainers() {
      // 16G in bytes
      return new Long("17179869184");
    }

    @Override
    public long getVCoresAllocatedForContainers() {
      return new Long("4000");
    }

    @Override
    public long getGCoresAllocatedForContainers() {
      return new Long("4000");
    }

    @Override
    public boolean isVmemCheckEnabled() {
      return true;
    }

    @Override
    public boolean isPmemCheckEnabled() {
      return true;
    }
  };
  nmWebApp = new NMWebApp(resourceView, aclsManager, dirsHandler);
  bind(JAXBContextResolver.class);
  bind(NMWebServices.class);
  bind(GenericExceptionHandler.class);
  bind(Context.class).toInstance(nmContext);
  bind(WebApp.class).toInstance(nmWebApp);
  bind(ResourceView.class).toInstance(resourceView);
  bind(ApplicationACLsManager.class).toInstance(aclsManager);
  bind(LocalDirsHandlerService.class).toInstance(dirsHandler);

  serve("/*").with(GuiceContainer.class);
}