You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-issues@hadoop.apache.org by GitBox <gi...@apache.org> on 2022/06/04 02:10:02 UTC

[GitHub] [hadoop] goiri commented on a diff in pull request #4314: YARN-11153. Make proxy server support yarn federation.

goiri commented on code in PR #4314:
URL: https://github.com/apache/hadoop/pull/4314#discussion_r889435983


##########
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-web-proxy/src/test/java/org/apache/hadoop/yarn/server/webproxy/TestWebAppProxyServerFed.java:
##########
@@ -0,0 +1,29 @@
+/**
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.webproxy;
+
+import org.apache.hadoop.yarn.conf.YarnConfiguration;
+
+public class TestWebAppProxyServerFed extends TestWebAppProxyServer {
+
+  @Override
+  public void setUp() throws Exception {
+    super.setUp();
+    conf.setBoolean(YarnConfiguration.FEDERATION_ENABLED, true);

Review Comment:
   Do we want to extend some tests just for federation or TestWebAppProxyServer is now generic enough?



##########
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-web-proxy/src/test/java/org/apache/hadoop/yarn/server/webproxy/TestFedAppReportFetcher.java:
##########
@@ -0,0 +1,186 @@
+/**
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.webproxy;
+
+import java.io.IOException;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.yarn.api.ApplicationClientProtocol;
+import org.apache.hadoop.yarn.api.ApplicationHistoryProtocol;
+import org.apache.hadoop.yarn.api.protocolrecords.GetApplicationReportRequest;
+import org.apache.hadoop.yarn.api.protocolrecords.GetApplicationReportResponse;
+import org.apache.hadoop.yarn.api.records.ApplicationId;
+import org.apache.hadoop.yarn.conf.YarnConfiguration;
+import org.apache.hadoop.yarn.exceptions.ApplicationNotFoundException;
+import org.apache.hadoop.yarn.exceptions.YarnException;
+import org.apache.hadoop.yarn.server.federation.store.FederationStateStore;
+import org.apache.hadoop.yarn.server.federation.store.impl.MemoryFederationStateStore;
+import org.apache.hadoop.yarn.server.federation.store.records.AddApplicationHomeSubClusterRequest;
+import org.apache.hadoop.yarn.server.federation.store.records.ApplicationHomeSubCluster;
+import org.apache.hadoop.yarn.server.federation.store.records.SubClusterId;
+import org.apache.hadoop.yarn.server.federation.store.records.SubClusterInfo;
+import org.apache.hadoop.yarn.server.federation.store.records.SubClusterRegisterRequest;
+import org.apache.hadoop.yarn.server.federation.store.records.SubClusterState;
+import org.apache.hadoop.yarn.server.federation.utils.FederationStateStoreFacade;
+import org.apache.hadoop.yarn.util.StringHelper;
+import org.apache.hadoop.yarn.webapp.util.WebAppUtils;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Test;
+import org.mockito.Mockito;
+
+public class TestFedAppReportFetcher {
+
+  Configuration conf;
+  static ApplicationHistoryProtocol history;
+
+  private SubClusterId subClusterId1 = SubClusterId.newInstance("subCluster1");
+  private SubClusterId subClusterId2 = SubClusterId.newInstance("subCluster2");
+  private SubClusterInfo clusterInfo1 = SubClusterInfo
+      .newInstance(subClusterId1, "10.0.0.1:1000", "10.0.0.1:1000",
+          "10.0.0.1:1000", "10.0.0.1:1000", SubClusterState.SC_RUNNING, 0l, "");
+  private SubClusterInfo clusterInfo2 = SubClusterInfo
+      .newInstance(subClusterId2, "10.0.0.2:1000", "10.0.0.2:1000",
+          "10.0.0.2:1000", "10.0.0.2:1000", SubClusterState.SC_RUNNING, 0l, "");
+  private ApplicationClientProtocol appManager1;
+  private ApplicationClientProtocol appManager2;
+  private ApplicationId appId1 = ApplicationId.newInstance(0, 1);
+  private ApplicationId appId2 = ApplicationId.newInstance(0, 2);
+
+  private static FedAppReportFetcher fetcher;
+  private final String appNotFoundExceptionMsg = "APP NOT FOUND";
+
+  @After
+  public void cleanUp() {
+    history = null;
+    fetcher = null;
+  }
+
+  private void testHelper(boolean isAHSEnabled)
+      throws YarnException, IOException {
+    conf = new YarnConfiguration();
+    conf.setBoolean(YarnConfiguration.APPLICATION_HISTORY_ENABLED,
+        isAHSEnabled);
+
+    FederationStateStoreFacade fedFacade =
+        FederationStateStoreFacade.getInstance();
+    FederationStateStore fss = new MemoryFederationStateStore();
+    fss.init(conf);
+    fedFacade.reinitialize(fss, conf);
+
+    fss.registerSubCluster(SubClusterRegisterRequest.newInstance(clusterInfo1));
+    fss.registerSubCluster(SubClusterRegisterRequest.newInstance(clusterInfo2));
+    fss.addApplicationHomeSubCluster(AddApplicationHomeSubClusterRequest
+        .newInstance(ApplicationHomeSubCluster.newInstance(appId1,
+            subClusterId1)));
+    fss.addApplicationHomeSubCluster(AddApplicationHomeSubClusterRequest
+        .newInstance(ApplicationHomeSubCluster.newInstance(appId2,
+            subClusterId2)));
+
+    appManager1 = Mockito.mock(ApplicationClientProtocol.class);
+    Mockito.when(appManager1
+        .getApplicationReport(Mockito.any(GetApplicationReportRequest.class)))
+        .thenThrow(new ApplicationNotFoundException(appNotFoundExceptionMsg));
+
+    appManager2 = Mockito.mock(ApplicationClientProtocol.class);
+    Mockito.when(appManager2
+        .getApplicationReport(Mockito.any(GetApplicationReportRequest.class)))
+        .thenThrow(new ApplicationNotFoundException(appNotFoundExceptionMsg));
+
+    fetcher = new TestFedAppReportFetcher.FedAppReportFetcherForTest(conf);
+    fetcher.registerSubCluster(clusterInfo1, appManager1);
+    fetcher.registerSubCluster(clusterInfo2, appManager2);
+  }
+
+  @Test
+  public void testFetchReportAHSEnabled() throws YarnException, IOException {
+    testHelper(true);
+    fetcher.getApplicationReport(appId1);
+    fetcher.getApplicationReport(appId2);
+    Mockito.verify(history, Mockito.times(2))
+        .getApplicationReport(Mockito.any(GetApplicationReportRequest.class));
+    Mockito.verify(appManager1, Mockito.times(1))
+        .getApplicationReport(Mockito.any(GetApplicationReportRequest.class));
+    Mockito.verify(appManager2, Mockito.times(1))
+        .getApplicationReport(Mockito.any(GetApplicationReportRequest.class));
+  }
+
+  @Test
+  public void testFetchReportAHSDisabled() throws YarnException, IOException {
+    testHelper(false);
+    try {
+      fetcher.getApplicationReport(appId1);
+    } catch (ApplicationNotFoundException e) {
+      Assert.assertTrue(e.getMessage() == appNotFoundExceptionMsg);
+      /* RM will not know of the app and Application History Service is disabled
+       * So we will not try to get the report from AHS and RM will throw
+       * ApplicationNotFoundException
+       */
+    }
+    try {
+      fetcher.getApplicationReport(appId2);
+    } catch (ApplicationNotFoundException e) {
+      Assert.assertTrue(e.getMessage() == appNotFoundExceptionMsg);
+      /* RM will not know of the app and Application History Service is disabled
+       * So we will not try to get the report from AHS and RM will throw
+       * ApplicationNotFoundException
+       */
+    }
+    Mockito.verify(appManager1, Mockito.times(1))
+        .getApplicationReport(Mockito.any(GetApplicationReportRequest.class));
+    Mockito.verify(appManager2, Mockito.times(1))
+        .getApplicationReport(Mockito.any(GetApplicationReportRequest.class));
+    if (history != null) {

Review Comment:
   assertNotNull and have the message there



##########
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-web-proxy/src/test/java/org/apache/hadoop/yarn/server/webproxy/TestFedAppReportFetcher.java:
##########
@@ -0,0 +1,186 @@
+/**
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.webproxy;
+
+import java.io.IOException;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.yarn.api.ApplicationClientProtocol;
+import org.apache.hadoop.yarn.api.ApplicationHistoryProtocol;
+import org.apache.hadoop.yarn.api.protocolrecords.GetApplicationReportRequest;
+import org.apache.hadoop.yarn.api.protocolrecords.GetApplicationReportResponse;
+import org.apache.hadoop.yarn.api.records.ApplicationId;
+import org.apache.hadoop.yarn.conf.YarnConfiguration;
+import org.apache.hadoop.yarn.exceptions.ApplicationNotFoundException;
+import org.apache.hadoop.yarn.exceptions.YarnException;
+import org.apache.hadoop.yarn.server.federation.store.FederationStateStore;
+import org.apache.hadoop.yarn.server.federation.store.impl.MemoryFederationStateStore;
+import org.apache.hadoop.yarn.server.federation.store.records.AddApplicationHomeSubClusterRequest;
+import org.apache.hadoop.yarn.server.federation.store.records.ApplicationHomeSubCluster;
+import org.apache.hadoop.yarn.server.federation.store.records.SubClusterId;
+import org.apache.hadoop.yarn.server.federation.store.records.SubClusterInfo;
+import org.apache.hadoop.yarn.server.federation.store.records.SubClusterRegisterRequest;
+import org.apache.hadoop.yarn.server.federation.store.records.SubClusterState;
+import org.apache.hadoop.yarn.server.federation.utils.FederationStateStoreFacade;
+import org.apache.hadoop.yarn.util.StringHelper;
+import org.apache.hadoop.yarn.webapp.util.WebAppUtils;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Test;
+import org.mockito.Mockito;
+
+public class TestFedAppReportFetcher {
+
+  Configuration conf;
+  static ApplicationHistoryProtocol history;
+
+  private SubClusterId subClusterId1 = SubClusterId.newInstance("subCluster1");
+  private SubClusterId subClusterId2 = SubClusterId.newInstance("subCluster2");
+  private SubClusterInfo clusterInfo1 = SubClusterInfo
+      .newInstance(subClusterId1, "10.0.0.1:1000", "10.0.0.1:1000",
+          "10.0.0.1:1000", "10.0.0.1:1000", SubClusterState.SC_RUNNING, 0l, "");
+  private SubClusterInfo clusterInfo2 = SubClusterInfo
+      .newInstance(subClusterId2, "10.0.0.2:1000", "10.0.0.2:1000",
+          "10.0.0.2:1000", "10.0.0.2:1000", SubClusterState.SC_RUNNING, 0l, "");
+  private ApplicationClientProtocol appManager1;
+  private ApplicationClientProtocol appManager2;
+  private ApplicationId appId1 = ApplicationId.newInstance(0, 1);
+  private ApplicationId appId2 = ApplicationId.newInstance(0, 2);
+
+  private static FedAppReportFetcher fetcher;
+  private final String appNotFoundExceptionMsg = "APP NOT FOUND";
+
+  @After
+  public void cleanUp() {
+    history = null;
+    fetcher = null;
+  }
+
+  private void testHelper(boolean isAHSEnabled)
+      throws YarnException, IOException {
+    conf = new YarnConfiguration();
+    conf.setBoolean(YarnConfiguration.APPLICATION_HISTORY_ENABLED,
+        isAHSEnabled);
+
+    FederationStateStoreFacade fedFacade =
+        FederationStateStoreFacade.getInstance();
+    FederationStateStore fss = new MemoryFederationStateStore();
+    fss.init(conf);
+    fedFacade.reinitialize(fss, conf);
+
+    fss.registerSubCluster(SubClusterRegisterRequest.newInstance(clusterInfo1));
+    fss.registerSubCluster(SubClusterRegisterRequest.newInstance(clusterInfo2));
+    fss.addApplicationHomeSubCluster(AddApplicationHomeSubClusterRequest
+        .newInstance(ApplicationHomeSubCluster.newInstance(appId1,
+            subClusterId1)));
+    fss.addApplicationHomeSubCluster(AddApplicationHomeSubClusterRequest
+        .newInstance(ApplicationHomeSubCluster.newInstance(appId2,
+            subClusterId2)));
+
+    appManager1 = Mockito.mock(ApplicationClientProtocol.class);
+    Mockito.when(appManager1
+        .getApplicationReport(Mockito.any(GetApplicationReportRequest.class)))
+        .thenThrow(new ApplicationNotFoundException(appNotFoundExceptionMsg));
+
+    appManager2 = Mockito.mock(ApplicationClientProtocol.class);
+    Mockito.when(appManager2
+        .getApplicationReport(Mockito.any(GetApplicationReportRequest.class)))
+        .thenThrow(new ApplicationNotFoundException(appNotFoundExceptionMsg));
+
+    fetcher = new TestFedAppReportFetcher.FedAppReportFetcherForTest(conf);
+    fetcher.registerSubCluster(clusterInfo1, appManager1);
+    fetcher.registerSubCluster(clusterInfo2, appManager2);
+  }
+
+  @Test
+  public void testFetchReportAHSEnabled() throws YarnException, IOException {
+    testHelper(true);
+    fetcher.getApplicationReport(appId1);
+    fetcher.getApplicationReport(appId2);
+    Mockito.verify(history, Mockito.times(2))
+        .getApplicationReport(Mockito.any(GetApplicationReportRequest.class));
+    Mockito.verify(appManager1, Mockito.times(1))
+        .getApplicationReport(Mockito.any(GetApplicationReportRequest.class));
+    Mockito.verify(appManager2, Mockito.times(1))
+        .getApplicationReport(Mockito.any(GetApplicationReportRequest.class));
+  }
+
+  @Test
+  public void testFetchReportAHSDisabled() throws YarnException, IOException {
+    testHelper(false);
+    try {
+      fetcher.getApplicationReport(appId1);
+    } catch (ApplicationNotFoundException e) {
+      Assert.assertTrue(e.getMessage() == appNotFoundExceptionMsg);
+      /* RM will not know of the app and Application History Service is disabled
+       * So we will not try to get the report from AHS and RM will throw
+       * ApplicationNotFoundException
+       */
+    }
+    try {
+      fetcher.getApplicationReport(appId2);
+    } catch (ApplicationNotFoundException e) {
+      Assert.assertTrue(e.getMessage() == appNotFoundExceptionMsg);

Review Comment:
   == will give issues right? assertEquals()



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: common-issues-unsubscribe@hadoop.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: common-issues-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-issues-help@hadoop.apache.org