YARN-4810. NM applicationpage cause internal error 500. Contributed by Bibin A Chundatt.

This commit is contained in:
Naganarasimha 2016-04-12 17:59:46 +05:30
parent 209303be3a
commit 437e9d6475
2 changed files with 101 additions and 3 deletions

View File

@ -34,6 +34,7 @@ import org.apache.hadoop.yarn.util.ConverterUtils;
import org.apache.hadoop.yarn.webapp.SubView;
import org.apache.hadoop.yarn.webapp.YarnWebParams;
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;
@ -75,10 +76,21 @@ public class ApplicationPage extends NMView implements YarnWebParams {
@Override
protected void render(Block html) {
ApplicationId applicationID =
ConverterUtils.toApplicationId(this.recordFactory,
$(APPLICATION_ID));
ApplicationId applicationID = null;
try {
applicationID = ConverterUtils.toApplicationId(this.recordFactory,
$(APPLICATION_ID));
} catch (IllegalArgumentException e) {
html.p()._("Invalid Application Id " + $(APPLICATION_ID))._();
return;
}
DIV<Hamlet> div = html.div("#content");
Application app = this.nmContext.getApplications().get(applicationID);
if (app == null) {
div.h1("Unknown application with id " + applicationID
+ ". Application might have been completed")._();
return;
}
AppInfo info = new AppInfo(app);
info("Application's information")
._("ApplicationId", info.getId())

View File

@ -0,0 +1,86 @@
/**
* 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.nodemanager.webapp;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.util.Arrays;
import java.util.Collection;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.yarn.server.nodemanager.Context;
import org.apache.hadoop.yarn.server.nodemanager.NodeManager;
import org.apache.hadoop.yarn.server.nodemanager.NodeManager.NMContext;
import org.apache.hadoop.yarn.server.nodemanager.recovery.NMNullStateStoreService;
import org.apache.hadoop.yarn.server.nodemanager.security.NMContainerTokenSecretManager;
import org.apache.hadoop.yarn.server.nodemanager.security.NMTokenSecretManagerInNM;
import org.apache.hadoop.yarn.server.nodemanager.webapp.ApplicationPage.ApplicationBlock;
import org.apache.hadoop.yarn.server.security.ApplicationACLsManager;
import org.apache.hadoop.yarn.webapp.YarnWebParams;
import org.apache.hadoop.yarn.webapp.test.WebAppTests;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import com.google.inject.Binder;
import com.google.inject.Injector;
import com.google.inject.Module;
@RunWith(Parameterized.class)
public class TestNMAppsPage {
String applicationid;
public TestNMAppsPage(String appid) {
this.applicationid = appid;
}
@Parameterized.Parameters
public static Collection<Object[]> getAppIds() {
return Arrays.asList(new Object[][] { { "appid" },
{ "application_123123213_0001" }, { "" } });
}
@Test
public void testNMAppsPage() {
Configuration conf = new Configuration();
final NMContext nmcontext = new NMContext(
new NMContainerTokenSecretManager(conf), new NMTokenSecretManagerInNM(),
null, new ApplicationACLsManager(conf), new NMNullStateStoreService());
Injector injector = WebAppTests.createMockInjector(NMContext.class,
nmcontext, new Module() {
@Override
public void configure(Binder binder) {
NodeManager nm = TestNMAppsPage.mocknm(nmcontext);
binder.bind(NodeManager.class).toInstance(nm);
binder.bind(Context.class).toInstance(nmcontext);
}
});
ApplicationBlock instance = injector.getInstance(ApplicationBlock.class);
instance.set(YarnWebParams.APPLICATION_ID, applicationid);
instance.render();
}
protected static NodeManager mocknm(NMContext nmcontext) {
NodeManager rm = mock(NodeManager.class);
when(rm.getNMContext()).thenReturn(nmcontext);
return rm;
}
}