You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by yu...@apache.org on 2015/12/02 07:04:24 UTC
ambari git commit: AMBARI-14058. "Application Tracking URL" in Tez
View broken due to RM HA changes in Ambari views framework. (Dipayan Bhowmick
via yusaku)
Repository: ambari
Updated Branches:
refs/heads/trunk 21b37c20f -> 29264fabf
AMBARI-14058. "Application Tracking URL" in Tez View broken due to RM HA changes in Ambari views framework. (Dipayan Bhowmick via yusaku)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/29264fab
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/29264fab
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/29264fab
Branch: refs/heads/trunk
Commit: 29264fabf08ca8fea7be48d17a3670581125ad1a
Parents: 21b37c2
Author: Yusaku Sako <yu...@hortonworks.com>
Authored: Tue Dec 1 22:03:19 2015 -0800
Committer: Yusaku Sako <yu...@hortonworks.com>
Committed: Tue Dec 1 22:03:19 2015 -0800
----------------------------------------------------------------------
.../ambari/view/tez/rest/BaseProxyResource.java | 12 ++++-
.../view/tez/rest/BaseRedirectionResource.java | 52 ++++++++++++++++++++
.../view/tez/rest/RMRedirectResource.java | 46 +++++++++++++++++
.../resources/ui/scripts/init-ambari-view.js | 3 ++
contrib/views/tez/src/main/resources/view.xml | 4 ++
5 files changed, 116 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/29264fab/contrib/views/tez/src/main/java/org/apache/ambari/view/tez/rest/BaseProxyResource.java
----------------------------------------------------------------------
diff --git a/contrib/views/tez/src/main/java/org/apache/ambari/view/tez/rest/BaseProxyResource.java b/contrib/views/tez/src/main/java/org/apache/ambari/view/tez/rest/BaseProxyResource.java
index 3670a40..619f81e 100644
--- a/contrib/views/tez/src/main/java/org/apache/ambari/view/tez/rest/BaseProxyResource.java
+++ b/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();
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/29264fab/contrib/views/tez/src/main/java/org/apache/ambari/view/tez/rest/BaseRedirectionResource.java
----------------------------------------------------------------------
diff --git a/contrib/views/tez/src/main/java/org/apache/ambari/view/tez/rest/BaseRedirectionResource.java b/contrib/views/tez/src/main/java/org/apache/ambari/view/tez/rest/BaseRedirectionResource.java
new file mode 100644
index 0000000..97ee01d
--- /dev/null
+++ b/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);
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/29264fab/contrib/views/tez/src/main/java/org/apache/ambari/view/tez/rest/RMRedirectResource.java
----------------------------------------------------------------------
diff --git a/contrib/views/tez/src/main/java/org/apache/ambari/view/tez/rest/RMRedirectResource.java b/contrib/views/tez/src/main/java/org/apache/ambari/view/tez/rest/RMRedirectResource.java
new file mode 100644
index 0000000..e217884
--- /dev/null
+++ b/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));
+ }
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/29264fab/contrib/views/tez/src/main/resources/ui/scripts/init-ambari-view.js
----------------------------------------------------------------------
diff --git a/contrib/views/tez/src/main/resources/ui/scripts/init-ambari-view.js b/contrib/views/tez/src/main/resources/ui/scripts/init-ambari-view.js
index 5152fb9..b45fef0 100644
--- a/contrib/views/tez/src/main/resources/ui/scripts/init-ambari-view.js
+++ b/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)
}
});
http://git-wip-us.apache.org/repos/asf/ambari/blob/29264fab/contrib/views/tez/src/main/resources/view.xml
----------------------------------------------------------------------
diff --git a/contrib/views/tez/src/main/resources/view.xml b/contrib/views/tez/src/main/resources/view.xml
index 08f6f40..d1ad5ad 100644
--- a/contrib/views/tez/src/main/resources/view.xml
+++ b/contrib/views/tez/src/main/resources/view.xml
@@ -42,6 +42,10 @@ limitations under the License. Kerberos, LDAP, Custom. Binary/Htt
<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>
</resource>