Index: hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/AHSWebServer.java =================================================================== --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/AHSWebServer.java (revision 1507882) +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/AHSWebServer.java (working copy) @@ -18,12 +18,40 @@ package org.apache.hadoop.yarn.server.applicationhistoryservice; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.apache.hadoop.service.AbstractService; +import org.apache.hadoop.yarn.exceptions.YarnRuntimeException; +import org.apache.hadoop.yarn.server.applicationhistoryservice.webapp.AHSWebApp; +import org.apache.hadoop.yarn.webapp.WebApps; public class AHSWebServer extends AbstractService { + private static final Log LOG = LogFactory.getLog(AHSWebServer.class); + private AHSWebApp webApp; - public AHSWebServer() { + public AHSWebServer(ApplicationHistoryContext applicationHistoryContext) { super(AHSWebServer.class.getName()); + webApp = new AHSWebApp(applicationHistoryContext); } -} + @Override + protected void serviceStart() throws Exception { + String bindAddress = getConfig().get( + "yarn.applicationhistoryserver.webapp.address", "0.0.0.0:19889"); + LOG.info("Instantiating AHSWebApp at " + bindAddress); + try { + WebApps.$for("applicationhistory").at(bindAddress).with(getConfig()) + .start(this.webApp); + } catch (Exception e) { + String msg = "AHSWebapps failed to start."; + LOG.error(msg, e); + throw new YarnRuntimeException(msg, e); + } + super.serviceStart(); + } + + @Override + protected void serviceStop() throws Exception { + super.serviceStop(); + } +} \ No newline at end of file Index: hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/ApplicationHistory.java =================================================================== --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/ApplicationHistory.java (revision 0) +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/ApplicationHistory.java (working copy) @@ -0,0 +1,54 @@ +package org.apache.hadoop.yarn.server.applicationhistoryservice; + +import java.util.ArrayList; +import java.util.Collection; + +import org.apache.hadoop.yarn.api.records.ApplicationAttemptId; +import org.apache.hadoop.yarn.api.records.ApplicationId; +import org.apache.hadoop.yarn.api.records.ContainerId; +import org.apache.hadoop.yarn.server.applicationhistoryservice.records.ApplicationAttemptHistoryData; +import org.apache.hadoop.yarn.server.applicationhistoryservice.records.ApplicationHistoryData; +import org.apache.hadoop.yarn.server.applicationhistoryservice.records.ContainerHistoryData; + +public class ApplicationHistory implements ApplicationHistoryContext { + + @Override + public Collection getAllApplications() { + return new ArrayList(); + } + + @Override + public ApplicationHistoryData getApplicationHistoryData( + ApplicationId applicationId) { + return null; + } + + @Override + public Collection getApplicationAttempts( + ApplicationId applicationId) { + return new ArrayList(); + } + + @Override + public ApplicationAttemptHistoryData getApplicationAttemptHistoryData( + ApplicationAttemptId applicationAttemptId) { + return null; + } + + @Override + public Collection getAllContainers( + ApplicationId applicationId) { + return new ArrayList(); + } + + @Override + public Collection getAllContainersForAppAttempt( + ApplicationAttemptId applicationAttemptId) { + return new ArrayList(); + } + + @Override + public ContainerHistoryData getContainerHistoryData(ContainerId containerId) { + return null; + } +} Index: hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/ApplicationHistoryContext.java =================================================================== --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/ApplicationHistoryContext.java (revision 0) +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/ApplicationHistoryContext.java (working copy) @@ -0,0 +1,30 @@ +package org.apache.hadoop.yarn.server.applicationhistoryservice; + +import java.util.Collection; + +import org.apache.hadoop.yarn.api.records.ApplicationAttemptId; +import org.apache.hadoop.yarn.api.records.ApplicationId; +import org.apache.hadoop.yarn.api.records.ContainerId; +import org.apache.hadoop.yarn.server.applicationhistoryservice.records.ApplicationAttemptHistoryData; +import org.apache.hadoop.yarn.server.applicationhistoryservice.records.ApplicationHistoryData; +import org.apache.hadoop.yarn.server.applicationhistoryservice.records.ContainerHistoryData; + +public interface ApplicationHistoryContext { + Collection getAllApplications(); + + ApplicationHistoryData getApplicationHistoryData(ApplicationId applicationId); + + Collection getApplicationAttempts( + ApplicationId applicationId); + + ApplicationAttemptHistoryData getApplicationAttemptHistoryData( + ApplicationAttemptId applicationAttemptId); + + Collection getAllContainers(ApplicationId applicationId); + + Collection getAllContainersForAppAttempt( + ApplicationAttemptId applicationAttemptId); + + ContainerHistoryData getContainerHistoryData(ContainerId containerId); + +} Index: hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/ApplicationHistoryServer.java =================================================================== --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/ApplicationHistoryServer.java (revision 1507882) +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/ApplicationHistoryServer.java (working copy) @@ -33,10 +33,11 @@ @Override protected void serviceInit(Configuration conf) throws Exception { - super.serviceInit(conf); AHSClientService ahsClientService = new AHSClientService(); addService(ahsClientService); - AHSWebServer webServer = new AHSWebServer(); + ApplicationHistory applicationHistory = new ApplicationHistory(); + AHSWebServer webServer = new AHSWebServer(applicationHistory); addService(webServer); + super.serviceInit(conf); } } Index: hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/webapp/AHSAboutPage.java =================================================================== --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/webapp/AHSAboutPage.java (revision 0) +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/webapp/AHSAboutPage.java (working copy) @@ -0,0 +1,40 @@ +/** + * 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.applicationhistoryservice.webapp; + +import static org.apache.hadoop.yarn.webapp.view.JQueryUI.ACCORDION; +import static org.apache.hadoop.yarn.webapp.view.JQueryUI.initID; + +import org.apache.hadoop.yarn.webapp.SubView; +import org.apache.hadoop.yarn.webapp.view.InfoBlock; + +public class AHSAboutPage extends AHSView { + + @Override + protected void preHead(Page.HTML<_> html) { + commonPreHead(html); + set(initID(ACCORDION, "nav"), "{autoHeight:false, active:0}"); + } + + @Override + protected Class content() { + info("History Server")._("BuildVersion", "" + " on " + "")._( + "History Server started on", ""); + return InfoBlock.class; + } +} \ No newline at end of file Index: hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/webapp/AHSAppAttemptsBlock.java =================================================================== --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/webapp/AHSAppAttemptsBlock.java (revision 0) +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/webapp/AHSAppAttemptsBlock.java (working copy) @@ -0,0 +1,91 @@ +/** + * 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.applicationhistoryservice.webapp; + +import static org.apache.hadoop.yarn.webapp.view.JQueryUI._EVEN; +import static org.apache.hadoop.yarn.webapp.view.JQueryUI._INFO_WRAP; +import static org.apache.hadoop.yarn.webapp.view.JQueryUI._ODD; +import static org.apache.hadoop.yarn.webapp.view.JQueryUI._TH; + +import java.util.Collection; + +import org.apache.hadoop.yarn.api.records.ApplicationId; +import org.apache.hadoop.yarn.server.applicationhistoryservice.ApplicationHistoryContext; +import org.apache.hadoop.yarn.server.applicationhistoryservice.records.ApplicationAttemptHistoryData; +import org.apache.hadoop.yarn.util.Apps; +import org.apache.hadoop.yarn.webapp.hamlet.Hamlet; +import org.apache.hadoop.yarn.webapp.hamlet.Hamlet.DIV; +import org.apache.hadoop.yarn.webapp.hamlet.Hamlet.TABLE; +import org.apache.hadoop.yarn.webapp.view.HtmlBlock; + +import com.google.inject.Inject; + +public class AHSAppAttemptsBlock extends HtmlBlock { + + private final ApplicationHistoryContext appHistoryContext; + + @Inject + public AHSAppAttemptsBlock(ApplicationHistoryContext appHistoryContext) { + this.appHistoryContext = appHistoryContext; + } + + @Override + protected void render(Block html) { + String appid = $("app.id"); + if (appid.isEmpty()) { + html. + p()._("Sorry, can't do anything without a App Id.")._(); + return; + } + ApplicationId applicationId = Apps.toAppID(appid); + + DIV div = html.div(_INFO_WRAP); + Collection applicationAttempts = + appHistoryContext.getApplicationAttempts(applicationId); + String amString = + applicationAttempts.size() >1 ? "ApplicationMasters" : "ApplicationMaster"; + + TABLE> table = div.table("#attempts"); + table. + tr(). + th(amString)._(). + tr(). + th(_TH, "Attempt Id"). + th(_TH, "Host"). + th(_TH, "RPC Port"). + th(_TH, "Tracking URL"). + th(_TH, "Diagnostics Info"). + th(_TH, "Final Application Status"). + th(_TH, "Master Container Id"). + _(); + + boolean odd = false; + for (ApplicationAttemptHistoryData attemptData : applicationAttempts) { + table.tr((odd = !odd) ? _ODD : _EVEN). + td(String.valueOf(attemptData.getApplicationAttemptId())). + td(attemptData.getHost()). + td(String.valueOf(attemptData.getRPCPort())). + td(attemptData.getTrackingURL()). + td(attemptData.getDiagnosticsInfo()). + td(String.valueOf(attemptData.getFinalApplicationStatus())). + td(String.valueOf(attemptData.getMasterContainerId())). _(); + } + table._(); + div._(); + } +} Index: hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/webapp/AHSAppAttemptsPage.java =================================================================== --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/webapp/AHSAppAttemptsPage.java (revision 0) +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/webapp/AHSAppAttemptsPage.java (working copy) @@ -0,0 +1,41 @@ +/** + * 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.applicationhistoryservice.webapp; + +import static org.apache.hadoop.yarn.util.StringHelper.join; +import static org.apache.hadoop.yarn.webapp.view.JQueryUI.ACCORDION; +import static org.apache.hadoop.yarn.webapp.view.JQueryUI.initID; + +import org.apache.hadoop.yarn.webapp.SubView; + +public class AHSAppAttemptsPage extends AHSView { + + @Override + protected void preHead(Page.HTML<_> html) { + String appId = $("app.id"); + set(TITLE, appId.isEmpty() ? "Bad request: missing application ID" : join( + "YARN Application ", $("app.id"))); + commonPreHead(html); + set(initID(ACCORDION, "nav"), "{autoHeight:false, active:1}"); + } + + @Override + protected Class content() { + return AHSAppAttemptsBlock.class; + } +} Index: hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/webapp/AHSAppContainersBlock.java =================================================================== --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/webapp/AHSAppContainersBlock.java (revision 0) +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/webapp/AHSAppContainersBlock.java (working copy) @@ -0,0 +1,100 @@ +/** + * 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.applicationhistoryservice.webapp; + +import java.util.Date; +import java.text.SimpleDateFormat; + +import org.apache.hadoop.yarn.api.records.ApplicationAttemptId; +import org.apache.hadoop.yarn.server.applicationhistoryservice.ApplicationHistoryContext; +import org.apache.hadoop.yarn.server.applicationhistoryservice.records.ContainerHistoryData; +import org.apache.hadoop.yarn.webapp.hamlet.Hamlet; +import org.apache.hadoop.yarn.webapp.hamlet.Hamlet.TABLE; +import org.apache.hadoop.yarn.webapp.hamlet.Hamlet.TBODY; +import org.apache.hadoop.yarn.webapp.hamlet.HamletSpec.InputType; +import org.apache.hadoop.yarn.webapp.view.HtmlBlock; + +import com.google.inject.Inject; + +public class AHSAppContainersBlock extends HtmlBlock { + + private final ApplicationHistoryContext appHistoryContext; + private final SimpleDateFormat dateFormat = new SimpleDateFormat( + "yyyy.MM.dd HH:mm:ss z"); + + @Inject + public AHSAppContainersBlock(ApplicationHistoryContext appHistoryContext) { + this.appHistoryContext = appHistoryContext; + } + + @Override + protected void render(Block html) { + TBODY> tbody = html. + h2("Containers"). + table("#appContainers"). + thead(). + tr(). + th(".id", "Container ID"). + th(".name", "Allocated Resource"). + th("Assigned Node"). + th("Priority"). + th("Start Time"). + th("Finish Time"). + th("Diagnostics Info"). + th(".state", "Final Container Status")._()._(). + tbody(); + + StringBuilder containersTableData = new StringBuilder("[\n"); + ApplicationAttemptId applicationAttemptId = null; + for (ContainerHistoryData containerHistoryData : appHistoryContext + .getAllContainersForAppAttempt(applicationAttemptId )) { + String containerId = String.valueOf(containerHistoryData.getContainerId()); + containersTableData.append("[\"") + .append("").append(containerId).append("\",\"") + .append(containerHistoryData.getAllocatedResource()).append("\",\"") + .append(String.valueOf(containerHistoryData.getAssignedNode())).append("\",\"") + .append(containerHistoryData.getPriority()).append("\",\"") + .append(dateFormat.format(new Date(containerHistoryData.getStartTime()))).append("\",\"") + .append(dateFormat.format(new Date(containerHistoryData.getFinishTime()))).append("\",\"") + .append(containerHistoryData.getDiagnosticsInfo()).append("\",\"") + .append(containerHistoryData.getFinalContainerStatus()).append("\"],\n"); + } + + // Remove the last comma and close off the array of arrays + if (containersTableData.charAt(containersTableData.length() - 2) == ',') { + containersTableData.delete(containersTableData.length() - 2, + containersTableData.length() - 1); + } + containersTableData.append("]"); + html.script().$type("text/javascript")._( + "var appContainers=" + containersTableData)._(); + tbody._(). + tfoot(). + tr(). + th().input("search_init").$type(InputType.text).$name("start_time").$value("Container ID")._()._(). + th().input("search_init").$type(InputType.text).$name("finish_time").$value("Allocated Resource")._()._(). + th().input("search_init").$type(InputType.text).$name("start_time").$value("Assigned Node")._()._(). + th().input("search_init").$type(InputType.text).$name("start_time").$value("Priority")._()._(). + th().input("search_init").$type(InputType.text).$name("start_time").$value("Start Time")._()._(). + th().input("search_init").$type(InputType.text).$name("start_time").$value("Finish Time")._()._(). + th().input("search_init").$type(InputType.text).$name("start_time").$value("Diagnostics")._()._(). + th().input("search_init").$type(InputType.text).$name("start_time").$value("Final Container Status")._()._(). + _()._()._(); + } + +} Index: hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/webapp/AHSAppContainersPage.java =================================================================== --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/webapp/AHSAppContainersPage.java (revision 0) +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/webapp/AHSAppContainersPage.java (working copy) @@ -0,0 +1,88 @@ +/** + * 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.applicationhistoryservice.webapp; + +import static org.apache.hadoop.yarn.util.StringHelper.join; +import static org.apache.hadoop.yarn.webapp.view.JQueryUI.ACCORDION; +import static org.apache.hadoop.yarn.webapp.view.JQueryUI.DATATABLES; +import static org.apache.hadoop.yarn.webapp.view.JQueryUI.DATATABLES_ID; +import static org.apache.hadoop.yarn.webapp.view.JQueryUI.initID; +import static org.apache.hadoop.yarn.webapp.view.JQueryUI.postInitID; +import static org.apache.hadoop.yarn.webapp.view.JQueryUI.tableInit; + +import org.apache.hadoop.yarn.webapp.SubView; + +public class AHSAppContainersPage extends AHSView { + + @Override + protected void preHead(Page.HTML<_> html) { + String appId = $("app.id"); + set(TITLE, appId.isEmpty() ? "Bad request: missing application ID" : join( + "YARN Application ", $("app.id"), " Containers")); + commonPreHead(html); + set(DATATABLES_ID, "appContainers"); + setTableStyles(html, "appContainers", ".queue {width:6em}", + ".ui {width:8em}"); + set(initID(DATATABLES, "appContainers"), appContainersTableInit()); + set(postInitID(DATATABLES, "appContainers"), appContainerssPostTableInit()); + setTitle("Application History"); + set(initID(ACCORDION, "nav"), "{autoHeight:false, active:1}"); + } + + private String appContainerssPostTableInit() { + return "var asInitVals = new Array();\n" + + "$('tfoot input').keyup( function () \n{"+ + " appsTableData.fnFilter( this.value, $('tfoot input').index(this) );\n"+ + "} );\n"+ + "$('tfoot input').each( function (i) {\n"+ + " asInitVals[i] = this.value;\n"+ + "} );\n"+ + "$('tfoot input').focus( function () {\n"+ + " if ( this.className == 'search_init' )\n"+ + " {\n"+ + " this.className = '';\n"+ + " this.value = '';\n"+ + " }\n"+ + "} );\n"+ + "$('tfoot input').blur( function (i) {\n"+ + " if ( this.value == '' )\n"+ + " {\n"+ + " this.className = 'search_init';\n"+ + " this.value = asInitVals[$('tfoot input').index(this)];\n"+ + " }\n"+ + "} );\n"; + } + + private String appContainersTableInit() { + return tableInit(). + append(", 'aaData': appContainers"). + append(", bDeferRender: true"). + append(", bProcessing: true"). + + // Sort by id upon page load + append(", aaSorting: [[0, 'desc']]"). + append(", aoColumnDefs:["). + append("]}"). + toString(); + } + + @Override + protected Class content() { + return AHSAppContainersBlock.class; + } +} Index: hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/webapp/AHSApplicationBlock.java =================================================================== --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/webapp/AHSApplicationBlock.java (revision 0) +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/webapp/AHSApplicationBlock.java (working copy) @@ -0,0 +1,116 @@ +/** + * 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.applicationhistoryservice.webapp; + +import static org.apache.hadoop.yarn.webapp.view.JQueryUI._EVEN; +import static org.apache.hadoop.yarn.webapp.view.JQueryUI._INFO_WRAP; +import static org.apache.hadoop.yarn.webapp.view.JQueryUI._ODD; +import static org.apache.hadoop.yarn.webapp.view.JQueryUI._TH; + +import java.util.Collection; +import java.util.Date; + +import org.apache.hadoop.util.StringUtils; +import org.apache.hadoop.yarn.api.records.ApplicationId; +import org.apache.hadoop.yarn.server.applicationhistoryservice.ApplicationHistoryContext; +import org.apache.hadoop.yarn.server.applicationhistoryservice.records.ApplicationAttemptHistoryData; +import org.apache.hadoop.yarn.server.applicationhistoryservice.records.ApplicationHistoryData; +import org.apache.hadoop.yarn.util.Apps; +import org.apache.hadoop.yarn.util.Times; +import org.apache.hadoop.yarn.webapp.hamlet.Hamlet; +import org.apache.hadoop.yarn.webapp.hamlet.Hamlet.DIV; +import org.apache.hadoop.yarn.webapp.hamlet.Hamlet.TABLE; +import org.apache.hadoop.yarn.webapp.view.HtmlBlock; +import org.apache.hadoop.yarn.webapp.view.InfoBlock; + +import com.google.inject.Inject; + +public class AHSApplicationBlock extends HtmlBlock { + + private final ApplicationHistoryContext appHistoryContext; + + @Inject + public AHSApplicationBlock(ApplicationHistoryContext appHistoryContext) { + this.appHistoryContext = appHistoryContext; + } + + @Override + protected void render(Block html) { + String appid = $("app.id"); + if (appid.isEmpty()) { + html. + p()._("Sorry, can't do anything without a App Id.")._(); + return; + } + ApplicationId applicationId = Apps.toAppID(appid); + ApplicationHistoryData applicationHistoryData = appHistoryContext + .getApplicationHistoryData(applicationId); + if (applicationHistoryData == null) { + html. + p()._("Sorry, ", applicationId, " not found.")._(); + return; + } + info("Application Overview"). + _("Application Name:", applicationHistoryData.getApplicationName()). + _("Type:", applicationHistoryData.getApplicationType()). + _("User Name:", applicationHistoryData.getApplicationName()). + _("Queue:", applicationHistoryData.getQueue()). + _("Submitted:", new Date(applicationHistoryData.getSubmitTime())). + _("Started:", new Date(applicationHistoryData.getStartTime())). + _("Finished:", new Date(applicationHistoryData.getFinishTime())). + _("Final Status:", applicationHistoryData.getFinalApplicationStatus()). + _("Diagnostics:", applicationHistoryData.getDiagnosticsInfo()). + _("Elapsed:", StringUtils.formatTime( + Times.elapsed(applicationHistoryData.getStartTime(), applicationHistoryData.getFinishTime(), false))); + + DIV div = html._(InfoBlock.class).div(_INFO_WRAP); + + Collection applicationAttempts = + appHistoryContext.getApplicationAttempts(applicationId); + String amString = + applicationAttempts.size() >1 ? "ApplicationMasters" : "ApplicationMaster"; + + TABLE> table = div.table("#attempts"); + table. + tr(). + th(amString)._(). + tr(). + th(_TH, "Attempt Id"). + th(_TH, "Host"). + th(_TH, "RPC Port"). + th(_TH, "Tracking URL"). + th(_TH, "Diagnostics Info"). + th(_TH, "Final Application Status"). + th(_TH, "Master Container Id"). + _(); + + boolean odd = false; + for (ApplicationAttemptHistoryData attemptData : applicationAttempts) { + table.tr((odd = !odd) ? _ODD : _EVEN). + td(String.valueOf(attemptData.getApplicationAttemptId())). + td(attemptData.getHost()). + td(String.valueOf(attemptData.getRPCPort())). + td(attemptData.getTrackingURL()). + td(attemptData.getDiagnosticsInfo()). + td(String.valueOf(attemptData.getFinalApplicationStatus())). + td(String.valueOf(attemptData.getMasterContainerId())). _(); + } + table._(); + div._(); + } +} Index: hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/webapp/AHSApplicationPage.java =================================================================== --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/webapp/AHSApplicationPage.java (revision 0) +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/webapp/AHSApplicationPage.java (working copy) @@ -0,0 +1,41 @@ +/** + * 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.applicationhistoryservice.webapp; + +import static org.apache.hadoop.yarn.util.StringHelper.join; +import static org.apache.hadoop.yarn.webapp.view.JQueryUI.ACCORDION; +import static org.apache.hadoop.yarn.webapp.view.JQueryUI.initID; + +import org.apache.hadoop.yarn.webapp.SubView; + +public class AHSApplicationPage extends AHSView { + + @Override + protected void preHead(Page.HTML<_> html) { + String appId = $("app.id"); + set(TITLE, appId.isEmpty() ? "Bad request: missing application ID" : join( + "YARN Application ", $("app.id"))); + commonPreHead(html); + set(initID(ACCORDION, "nav"), "{autoHeight:false, active:1}"); + } + + @Override + protected Class content() { + return AHSApplicationBlock.class; + } +} Index: hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/webapp/AHSJAXBContextResolver.java =================================================================== --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/webapp/AHSJAXBContextResolver.java (revision 0) +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/webapp/AHSJAXBContextResolver.java (working copy) @@ -0,0 +1,52 @@ +/** + * 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.applicationhistoryservice.webapp; + +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; + +import javax.ws.rs.ext.ContextResolver; +import javax.ws.rs.ext.Provider; +import javax.xml.bind.JAXBContext; + +import com.google.inject.Singleton; +import com.sun.jersey.api.json.JSONConfiguration; +import com.sun.jersey.api.json.JSONJAXBContext; + +@Singleton +@Provider +@SuppressWarnings("unchecked") +public class AHSJAXBContextResolver implements ContextResolver { + + private JAXBContext context; + private final Set types; + + private final Class[] cTypes = {}; + + public AHSJAXBContextResolver() throws Exception { + this.types = new HashSet(Arrays.asList(cTypes)); + this.context = new JSONJAXBContext(JSONConfiguration.natural() + .rootUnwrapping(false).build(), cTypes); + } + + @Override + public JAXBContext getContext(Class objectType) { + return (types.contains(objectType)) ? context : null; + } +} \ No newline at end of file Index: hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/webapp/AHSNavBlock.java =================================================================== --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/webapp/AHSNavBlock.java (revision 0) +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/webapp/AHSNavBlock.java (working copy) @@ -0,0 +1,50 @@ +/** + * 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.applicationhistoryservice.webapp; + +import org.apache.hadoop.yarn.webapp.hamlet.Hamlet; +import org.apache.hadoop.yarn.webapp.hamlet.Hamlet.DIV; +import org.apache.hadoop.yarn.webapp.view.HtmlBlock; + +public class AHSNavBlock extends HtmlBlock { + + @Override protected void render(Block html) { + DIV nav = html. + div("#nav"). + h3("Application History"). + ul(). + li().a(url("about"), "About")._(). + li().a("/applicationhistory", "Applications")._()._(); + String appId = $("app.id"); + if (appId != null && appId.isEmpty() == false) { + nav. + h3("Application"). + ul(). + li().a(url("application", appId), "Overview")._(). + li().a(url("appattempts", appId), "Attempts")._(). + li().a(url("appcontainers", appId), "Containers")._()._(); + } + nav. + h3("Tools"). + ul(). + li().a("/conf", "Configuration")._(). + li().a("/stacks", "Thread dump")._(). + li().a("/logs", "Logs")._(). + li().a("/metrics", "Metrics")._()._()._(); + } +} Index: hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/webapp/AHSView.java =================================================================== --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/webapp/AHSView.java (revision 0) +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/webapp/AHSView.java (working copy) @@ -0,0 +1,95 @@ +/** + * 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.applicationhistoryservice.webapp; + +import static org.apache.hadoop.yarn.webapp.view.JQueryUI.ACCORDION; +import static org.apache.hadoop.yarn.webapp.view.JQueryUI.ACCORDION_ID; +import static org.apache.hadoop.yarn.webapp.view.JQueryUI.DATATABLES; +import static org.apache.hadoop.yarn.webapp.view.JQueryUI.DATATABLES_ID; +import static org.apache.hadoop.yarn.webapp.view.JQueryUI.initID; +import static org.apache.hadoop.yarn.webapp.view.JQueryUI.postInitID; +import static org.apache.hadoop.yarn.webapp.view.JQueryUI.tableInit; + +import org.apache.hadoop.yarn.webapp.SubView; +import org.apache.hadoop.yarn.webapp.view.TwoColumnLayout; + +public class AHSView extends TwoColumnLayout { + + @Override + protected void preHead(Page.HTML<_> html) { + commonPreHead(html); + set(DATATABLES_ID, "appsTableData"); + setTableStyles(html, "appsTableData", ".queue {width:6em}", + ".ui {width:8em}"); + set(initID(DATATABLES, "appsTableData"), appsTableInit()); + set(postInitID(DATATABLES, "appsTableData"), appsPostTableInit()); + setTitle("Application History"); + } + + protected void commonPreHead(Page.HTML<_> html) { + set(ACCORDION_ID, "nav"); + set(initID(ACCORDION, "nav"), "{autoHeight:false, active:0}"); + } + + @Override + protected Class nav() { + return AHSNavBlock.class; + } + + @Override + protected Class content() { + return ApplicationHistoryView.class; + } + + private String appsPostTableInit() { + return "var asInitVals = new Array();\n" + + "$('tfoot input').keyup( function () \n{"+ + " appsTableData.fnFilter( this.value, $('tfoot input').index(this) );\n"+ + "} );\n"+ + "$('tfoot input').each( function (i) {\n"+ + " asInitVals[i] = this.value;\n"+ + "} );\n"+ + "$('tfoot input').focus( function () {\n"+ + " if ( this.className == 'search_init' )\n"+ + " {\n"+ + " this.className = '';\n"+ + " this.value = '';\n"+ + " }\n"+ + "} );\n"+ + "$('tfoot input').blur( function (i) {\n"+ + " if ( this.value == '' )\n"+ + " {\n"+ + " this.className = 'search_init';\n"+ + " this.value = asInitVals[$('tfoot input').index(this)];\n"+ + " }\n"+ + "} );\n"; + } + + private String appsTableInit() { + return tableInit(). + append(", 'aaData': appsTableData"). + append(", bDeferRender: true"). + append(", bProcessing: true"). + + // Sort by id upon page load + append(", aaSorting: [[0, 'desc']]"). + append(", aoColumnDefs:["). + append("]}"). + toString(); + } +} Index: hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/webapp/AHSWebApp.java =================================================================== --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/webapp/AHSWebApp.java (revision 0) +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/webapp/AHSWebApp.java (working copy) @@ -0,0 +1,53 @@ +/** + * 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.applicationhistoryservice.webapp; + +import static org.apache.hadoop.yarn.util.StringHelper.pajoin; + +import org.apache.hadoop.yarn.server.applicationhistoryservice.ApplicationHistoryContext; +import org.apache.hadoop.yarn.webapp.GenericExceptionHandler; +import org.apache.hadoop.yarn.webapp.WebApp; +import org.apache.hadoop.yarn.webapp.YarnWebParams; + +public class AHSWebApp extends WebApp implements YarnWebParams { + + private final ApplicationHistoryContext applicationHistoryContext; + + public AHSWebApp(ApplicationHistoryContext applicationHistoryContext) { + this.applicationHistoryContext = applicationHistoryContext; + } + + @Override + public void setup() { + bind(AHSWebServices.class); + bind(GenericExceptionHandler.class); + bind(AHSJAXBContextResolver.class); + bind(ApplicationHistoryContext.class).toInstance( + this.applicationHistoryContext); + route("/", ApplicationHistoryController.class, "applicationHistory"); + route("/about", ApplicationHistoryController.class, "about"); + route("/applicationhistory", ApplicationHistoryController.class, + "applicationHistory"); + route(pajoin("/application", "app.id"), ApplicationHistoryController.class, + "application"); + route(pajoin("/appattempts", "app.id"), ApplicationHistoryController.class, + "appAttempts"); + route(pajoin("/appcontainers", "app.id"), + ApplicationHistoryController.class, "appContainers"); + } +} Index: hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/webapp/AHSWebServices.java =================================================================== --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/webapp/AHSWebServices.java (revision 0) +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/webapp/AHSWebServices.java (working copy) @@ -0,0 +1,47 @@ +/** + * 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.applicationhistoryservice.webapp; + +import javax.servlet.http.HttpServletResponse; +import javax.ws.rs.Path; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.UriInfo; + +import org.apache.hadoop.yarn.server.applicationhistoryservice.ApplicationHistoryContext; +import org.apache.hadoop.yarn.webapp.WebApp; + +import com.google.inject.Inject; + +@Path("/ws/v1/applicationhistory") +@SuppressWarnings("unused") +public class AHSWebServices { + private WebApp webapp; + + @Context + private HttpServletResponse response; + @Context + UriInfo uriInfo; + + private ApplicationHistoryContext ctx; + + @Inject + public AHSWebServices(final ApplicationHistoryContext ctx, final WebApp webapp) { + this.ctx = ctx; + this.webapp = webapp; + } +} Index: hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/webapp/ApplicationHistoryController.java =================================================================== --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/webapp/ApplicationHistoryController.java (revision 0) +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/webapp/ApplicationHistoryController.java (working copy) @@ -0,0 +1,51 @@ +/** + * 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.applicationhistoryservice.webapp; + +import org.apache.hadoop.yarn.webapp.Controller; +import org.apache.hadoop.yarn.webapp.YarnWebParams; + +public class ApplicationHistoryController extends Controller implements + YarnWebParams { + + public void applicationHistory() { + render(ApplicationHistoryPage.class); + } + + public void about() { + render(AHSAboutPage.class); + } + + public void application() { + render(AHSApplicationPage.class); + } + + public void appAttempts() { + render(AHSAppAttemptsPage.class); + } + + public void appContainers() { + render(AHSAppContainersPage.class); + } + + @Override + public void index() { + } + + +} \ No newline at end of file Index: hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/webapp/ApplicationHistoryPage.java =================================================================== --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/webapp/ApplicationHistoryPage.java (revision 0) +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/webapp/ApplicationHistoryPage.java (working copy) @@ -0,0 +1,113 @@ +/** + * 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.applicationhistoryservice.webapp; + +import java.util.Date; +import java.text.SimpleDateFormat; + +import org.apache.commons.lang.StringEscapeUtils; +import org.apache.hadoop.yarn.server.applicationhistoryservice.ApplicationHistoryContext; +import org.apache.hadoop.yarn.server.applicationhistoryservice.records.ApplicationHistoryData; +import org.apache.hadoop.yarn.webapp.SubView; +import org.apache.hadoop.yarn.webapp.hamlet.Hamlet; +import org.apache.hadoop.yarn.webapp.hamlet.Hamlet.TABLE; +import org.apache.hadoop.yarn.webapp.hamlet.Hamlet.TBODY; +import org.apache.hadoop.yarn.webapp.hamlet.HamletSpec.InputType; +import org.apache.hadoop.yarn.webapp.view.HtmlBlock; + +import com.google.inject.Inject; + +public class ApplicationHistoryPage extends AHSView { + + @Override + protected Class content() { + return ApplicationHistoryView.class; + } +} + +class ApplicationHistoryView extends HtmlBlock { + final SimpleDateFormat dateFormat = new SimpleDateFormat( + "yyyy.MM.dd HH:mm:ss z"); + private final ApplicationHistoryContext applicationHistoryContext; + + @Inject + ApplicationHistoryView(ApplicationHistoryContext applicationHistoryContext) { + this.applicationHistoryContext = applicationHistoryContext; + } + + @Override + protected void render(Block html) { + TBODY> tbody = html. + h2("Completed Applications"). + table("#appsTableData"). + thead(). + tr(). + th(".id", "Application ID"). + th(".name", "Name"). + th("Application Type"). + th("User"). + th("Queue"). + th("Submit Time"). + th("Start Time"). + th("Finish Time"). + th("Diagnostics"). + th(".state", "Final Application Status")._()._(). + tbody(); + + StringBuilder appsTableData = new StringBuilder("[\n"); + for (ApplicationHistoryData appHistoryData : applicationHistoryContext + .getAllApplications()) { + String appId = String.valueOf(appHistoryData.getApplicationId()); + appsTableData.append("[\"") + .append("").append(appId).append("\",\"") + .append(StringEscapeUtils.escapeJavaScript(StringEscapeUtils.escapeHtml(appHistoryData.getApplicationName()))).append("\",\"") + .append(appHistoryData.getApplicationType()).append("\",\"") + .append(StringEscapeUtils.escapeJavaScript(StringEscapeUtils.escapeHtml(appHistoryData.getUser()))).append("\",\"") + .append(StringEscapeUtils.escapeJavaScript(StringEscapeUtils.escapeHtml(appHistoryData.getQueue()))).append("\",\"") + .append(dateFormat.format(new Date(appHistoryData.getSubmitTime()))).append("\",\"") + .append(dateFormat.format(new Date(appHistoryData.getStartTime()))).append("\",\"") + .append(dateFormat.format(new Date(appHistoryData.getFinishTime()))).append("\",\"") + .append(appHistoryData.getDiagnosticsInfo()).append("\",\"") + .append(appHistoryData.getFinalApplicationStatus()).append("\"],\n"); + } + + // Remove the last comma and close off the array of arrays + if (appsTableData.charAt(appsTableData.length() - 2) == ',') { + appsTableData.delete(appsTableData.length() - 2, + appsTableData.length() - 1); + } + appsTableData.append("]"); + html.script().$type("text/javascript")._( + "var appsTableData=" + appsTableData)._(); + tbody._(). + tfoot(). + tr(). + th().input("search_init").$type(InputType.text).$name("start_time").$value("Application ID")._()._(). + th().input("search_init").$type(InputType.text).$name("finish_time").$value("Name")._()._(). + th().input("search_init").$type(InputType.text).$name("start_time").$value("Application Type")._()._(). + th().input("search_init").$type(InputType.text).$name("start_time").$value("User")._()._(). + th().input("search_init").$type(InputType.text).$name("start_time").$value("Queue")._()._(). + th().input("search_init").$type(InputType.text).$name("start_time").$value("Submit Time")._()._(). + th().input("search_init").$type(InputType.text).$name("start_time").$value("Start Time")._()._(). + th().input("search_init").$type(InputType.text).$name("start_time").$value("Finish Time")._()._(). + th().input("search_init").$type(InputType.text).$name("start_time").$value("Diagnostics")._()._() + .th().input("search_init").$type(InputType.text).$name("start_time").$value("Final Application Status") + ._() + ._()._()._()._(); + } +}