KNOX-1244 - YARNUIV2 fix HA support (Sunil Govind via Sandeep More)
authorSandeep More <more@apache.org>
Fri, 11 May 2018 19:02:54 +0000 (15:02 -0400)
committerSandeep More <more@apache.org>
Fri, 11 May 2018 19:02:54 +0000 (15:02 -0400)
gateway-service-definitions/src/main/resources/services/yarnuiv2/3.0.0/service.xml
gateway-service-rm/src/main/java/org/apache/knox/gateway/rm/dispatch/RMUI2HaDispatch.java [new file with mode: 0644]

index bdbb0e7..1fb1d21 100644 (file)
@@ -56,7 +56,6 @@
         <rewrite apply="YARNUIV2/yarnuiv2/inbound/ws" to="request.url"/>
         <rewrite apply="YARNUIV2/yarnuiv2/headers/outbound" to="response.headers"/>
         <rewrite apply="YARNUIV2/yarnuiv2/outbound/mainpage" to="response.body"/>
-        <dispatch contributor-name="http-client" />
     </route>
     <!-- Resources -->
     <route path="/yarnuiv2/styles/**">
@@ -92,5 +91,5 @@
     </route>
     
   </routes>
-  <dispatch classname="org.apache.knox.gateway.dispatch.PassAllHeadersDispatch"/>
+  <dispatch classname="org.apache.knox.gateway.dispatch.PassAllHeadersDispatch" ha-classname="org.apache.knox.gateway.rm.dispatch.RMUI2HaDispatch"/>
 </service>
diff --git a/gateway-service-rm/src/main/java/org/apache/knox/gateway/rm/dispatch/RMUI2HaDispatch.java b/gateway-service-rm/src/main/java/org/apache/knox/gateway/rm/dispatch/RMUI2HaDispatch.java
new file mode 100644 (file)
index 0000000..61e05b7
--- /dev/null
@@ -0,0 +1,58 @@
+/**
+ * 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.knox.gateway.rm.dispatch;
+
+import java.io.IOException;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.http.HttpResponse;
+import org.apache.http.client.methods.HttpUriRequest;
+import org.apache.knox.gateway.config.Configure;
+import org.apache.knox.gateway.ha.provider.HaProvider;
+import org.apache.knox.gateway.ha.provider.HaServiceConfig;
+
+public class RMUI2HaDispatch extends RMHaBaseDispatcher {
+
+  private static final String RESOURCE_ROLE = "YARNUIV2";
+  private HaProvider haProvider;
+
+  public RMUI2HaDispatch() throws ServletException {
+   super();
+  }
+
+  @Configure
+  public void setHaProvider(HaProvider haProvider) {
+    this.haProvider = haProvider;
+  }
+
+  @Override
+  public void init() {
+    super.init();
+    if (haProvider != null) {
+      super.setResourceRole(RESOURCE_ROLE);
+      HaServiceConfig serviceConfig = haProvider.getHaDescriptor().getServiceConfig(RESOURCE_ROLE);
+      super.setMaxFailoverAttempts(serviceConfig.getMaxFailoverAttempts());
+      super.setFailoverSleep(serviceConfig.getFailoverSleep());
+      super.setMaxRetryAttempts(serviceConfig.getMaxRetryAttempts());
+      super.setRetrySleep(serviceConfig.getRetrySleep());
+      super.setHaProvider(haProvider);
+    }
+  }
+}