This is an automated email from the ASF dual-hosted git repository.
hemanthboyina pushed a commit to branch branch-3.3
in repository https://gitbox.apache.org/repos/asf/hadoop.git
The following commit(s) were added to refs/heads/branch-3.3 by this push:
new 5ededc0 YARN-10336. RM page should throw exception when command
injected in RM REST API to get applications. Contributed by Bilwa S T.
5ededc0 is described below
commit 5ededc0cba44888153f6424d8af8f705a6256540
Author: hemanthboyina <[email protected]>
AuthorDate: Thu Aug 13 23:44:42 2020 +0530
YARN-10336. RM page should throw exception when command injected in RM REST
API to get applications. Contributed by Bilwa S T.
(cherry picked from commit 86bbd38c8dc2aa4a7a5a7ac831c4c966c6eb231c)
---
.../hadoop/yarn/server/webapp/AppsBlock.java | 3 +-
.../hadoop/yarn/server/webapp/TestAppsBlock.java | 76 ++++++++++++++++++++++
2 files changed, 77 insertions(+), 2 deletions(-)
diff --git
a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/webapp/AppsBlock.java
b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/webapp/AppsBlock.java
index 6737e4d..40bd702 100644
---
a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/webapp/AppsBlock.java
+++
b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/webapp/AppsBlock.java
@@ -136,8 +136,7 @@ public class AppsBlock extends HtmlBlock {
try {
fetchData();
- }
- catch( Exception e) {
+ } catch (YarnException | IOException | InterruptedException e) {
String message = "Failed to read the applications.";
LOG.error(message, e);
html.p().__(message).__();
diff --git
a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/test/java/org/apache/hadoop/yarn/server/webapp/TestAppsBlock.java
b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/test/java/org/apache/hadoop/yarn/server/webapp/TestAppsBlock.java
new file mode 100644
index 0000000..6853558
--- /dev/null
+++
b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/test/java/org/apache/hadoop/yarn/server/webapp/TestAppsBlock.java
@@ -0,0 +1,76 @@
+/**
+ * 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.webapp;
+
+import java.io.OutputStream;
+import java.io.PrintWriter;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.commons.io.output.ByteArrayOutputStream;
+import org.apache.hadoop.yarn.webapp.SubView;
+import org.apache.hadoop.yarn.webapp.YarnWebParams;
+import org.apache.hadoop.yarn.webapp.view.BlockForTest;
+import org.apache.hadoop.yarn.webapp.view.HtmlBlock;
+import org.apache.hadoop.yarn.webapp.view.HtmlBlockForTest;
+import org.junit.Test;
+
+public class TestAppsBlock {
+
+ /**
+ * Test invalid application state.Exception should be thrown if application
+ * state is not valid.
+ */
+ @Test(expected = IllegalArgumentException.class)
+ public void testInvalidAppState() {
+ AppsBlock appBlock = new AppsBlock(null, null) {
+ // override this so that apps block can fetch app state.
+ @Override
+ public Map<String, String> moreParams() {
+ Map<String, String> map = new HashMap<>();
+ map.put(YarnWebParams.APP_STATE, "ACCEPTEDPING");
+ return map;
+ }
+
+ @Override
+ protected void renderData(Block html) {
+ }
+ };
+
+ // set up the test block to render AppsBlock
+ OutputStream outputStream = new ByteArrayOutputStream();
+ HtmlBlock.Block block = createBlockToCreateTo(outputStream);
+
+ // If application state is invalid it should throw exception
+ // instead of catching it.
+ appBlock.render(block);
+ }
+
+ private static HtmlBlock.Block createBlockToCreateTo(
+ OutputStream outputStream) {
+ PrintWriter printWriter = new PrintWriter(outputStream);
+ HtmlBlock html = new HtmlBlockForTest();
+ return new BlockForTest(html, printWriter, 10, false) {
+ @Override
+ protected void subView(Class<? extends SubView> cls) {
+ }
+ };
+ };
+
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]