Browse Source

AMBARI-14058. "Application Tracking URL" in Tez View broken due to RM HA changes in Ambari views framework. (Dipayan Bhowmick via yusaku)

Yusaku Sako 10 năm trước cách đây
mục cha
commit
29264fabf0

+ 11 - 1
contrib/views/tez/src/main/java/org/apache/ambari/view/tez/rest/BaseProxyResource.java

@@ -19,6 +19,7 @@
 package org.apache.ambari.view.tez.rest;
 
 import com.google.inject.Inject;
+import org.apache.ambari.view.tez.exceptions.ProxyException;
 import org.apache.ambari.view.tez.utils.ProxyHelper;
 import org.json.simple.JSONObject;
 import org.json.simple.JSONValue;
@@ -27,7 +28,11 @@ import javax.ws.rs.GET;
 import javax.ws.rs.Path;
 import javax.ws.rs.PathParam;
 import javax.ws.rs.Produces;
-import javax.ws.rs.core.*;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriInfo;
 import java.util.HashMap;
 
 /**
@@ -50,6 +55,11 @@ public abstract class BaseProxyResource {
     String response = proxyHelper.getResponse(url, new HashMap<String, String>());
 
     JSONObject jsonObject = (JSONObject) JSONValue.parse(response);
+
+    if (jsonObject == null) {
+      throw new ProxyException("Failed to parse JSON from URL : " + url + ".Internal Error.",
+        Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response);
+    }
     return Response.ok(jsonObject).type(MediaType.APPLICATION_JSON).build();
   }
 

+ 52 - 0
contrib/views/tez/src/main/java/org/apache/ambari/view/tez/rest/BaseRedirectionResource.java

@@ -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
+ * <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.ambari.view.tez.rest;
+
+import org.apache.ambari.view.tez.exceptions.ProxyException;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriInfo;
+import java.net.URI;
+import java.net.URISyntaxException;
+
+/**
+ * Base class for resources which will redirect the call to the active URL by fetching the current active URL.
+ * Ex: To redirect a endpoint to active RM/ATS url.
+ */
+public abstract class BaseRedirectionResource {
+
+  @Path("/{endpoint:.+}")
+  @GET
+  public Response getData(@Context UriInfo uriInfo, @PathParam("endpoint") String endpoint) {
+    String url = getProxyUrl(endpoint, uriInfo.getQueryParameters());
+    try {
+      return Response.temporaryRedirect(new URI(url)).build();
+    } catch (URISyntaxException e) {
+      throw new ProxyException("Failed to set the redirection url to : " + url + ".Internal Error.",
+        Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), e.getMessage());
+    }
+  }
+
+  public abstract String getProxyUrl(String endpoint, MultivaluedMap<String, String> queryParams);
+}

+ 46 - 0
contrib/views/tez/src/main/java/org/apache/ambari/view/tez/rest/RMRedirectResource.java

@@ -0,0 +1,46 @@
+/**
+ * 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.ambari.view.tez.rest;
+
+import com.google.inject.Inject;
+import org.apache.ambari.view.tez.ViewController;
+import org.apache.ambari.view.tez.utils.ProxyHelper;
+
+import javax.ws.rs.core.MultivaluedMap;
+
+/**
+ * Proxy class to redirect call to Active RM server
+ */
+public class RMRedirectResource extends BaseRedirectionResource {
+
+  private ViewController viewController;
+  private ProxyHelper proxyHelper;
+
+  @Inject
+  public RMRedirectResource(ViewController viewController, ProxyHelper proxyHelper) {
+    this.viewController = viewController;
+    this.proxyHelper = proxyHelper;
+  }
+
+  @Override
+  public String getProxyUrl(String endpoint, MultivaluedMap<String, String> queryParams) {
+    String activeRMUrl = viewController.getActiveRMUrl();
+    return String.format("%s/%s%s", activeRMUrl, endpoint, proxyHelper.getQueryParamsString(queryParams));
+  }
+}

+ 3 - 0
contrib/views/tez/src/main/resources/ui/scripts/init-ambari-view.js

@@ -164,6 +164,9 @@ function setConfigs() {
       aminfo: '%@rmproxy/proxy/__app_id__/ws/v1/tez'.fmt(resourcesPrefix),
       aminfoV2: '%@rmproxy/proxy/__app_id__/ws/v2/tez'.fmt(resourcesPrefix),
       cluster: '%@rmproxy/ws/v1/cluster'.fmt(resourcesPrefix)
+    },
+    otherNamespace: {
+      cluster: '%@rmredirect/cluster'.fmt(resourcesPrefix)
     }
   });
 

+ 4 - 0
contrib/views/tez/src/main/resources/view.xml

@@ -41,6 +41,10 @@ limitations under the License. Kerberos, LDAP, Custom. Binary/Htt
     <name>status</name>
     <service-class>org.apache.ambari.view.tez.rest.ViewStatusResource</service-class>
   </resource>
+  <resource>
+    <name>rmredirect</name>
+    <service-class>org.apache.ambari.view.tez.rest.RMRedirectResource</service-class>
+  </resource>
   <resource>
     <name>rmproxy</name>
     <service-class>org.apache.ambari.view.tez.rest.RMProxyResource</service-class>