/** * Get the proxied path for an application. * * @param id the application id to use * @return the base path to that application through the proxy */ public static String getPath(ApplicationId id) { return getPath(id, false); }
private String getDefaultProxyTrackingUrl() { try { final String scheme = WebAppUtils.getHttpSchemePrefix(conf); String proxy = WebAppUtils.getProxyHostAndPort(conf); URI proxyUri = ProxyUriUtils.getUriFromAMUrl(scheme, proxy); URI result = ProxyUriUtils.getProxyUri(null, proxyUri, applicationId); return result.toASCIIString(); } catch (URISyntaxException e) { LOG.warn("Could not generate default proxy tracking URL for " + applicationId); return UNAVAILABLE; } }
/** * Get the proxied path for an application * @param id the id of the application * @param path the path of the application. * @param query the query parameters * @param approved true if the user has approved accessing this app. * @return the proxied path for this app. */ public static String getPathAndQuery(ApplicationId id, String path, String query, boolean approved) { StringBuilder newp = new StringBuilder(); newp.append(getPath(id, path)); boolean first = appendQuery(newp, query, true); if(approved) { appendQuery(newp, PROXY_APPROVAL_PARAM+"=true", first); } return newp.toString(); }
.getUriFromTrackingPlugins(id, this.trackingUriPlugins); if (toFetch != null) { ProxyUtils.sendRedirect(req, resp, toFetch.toString()); if (ProxyUriUtils.getSchemeFromUrl(original).isEmpty()) { trackingUri = ProxyUriUtils.getUriFromAMUrl( WebAppUtils.getHttpSchemePrefix(conf), original); } else { + "app master GUI of {} owned by {}", remoteUser, appId, runningUser); warnUserPage(resp, ProxyUriUtils.getPathAndQuery(id, rest, req.getQueryString(), true), runningUser, id); return;
StringHelper.pjoin(ahsAppPageUrlBase, id.toString())); } else if (ProxyUriUtils.getSchemeFromUrl(originalUri).isEmpty()) { trackingUri = ProxyUriUtils.getUriFromAMUrl(WebAppUtils.getHttpSchemePrefix(conf), originalUri); } else {
.getUriFromTrackingPlugins(id, this.trackingUriPlugins); if (toFetch != null) { ProxyUtils.sendRedirect(req, resp, toFetch.toString()); + "app master GUI of {} owned by {}", remoteUser, appId, runningUser); warnUserPage(resp, ProxyUriUtils.getPathAndQuery(id, rest, req.getQueryString(), true), runningUser, id);
@Test public void testGetProxyUriFromPluginsReturnsNullIfNoPlugins() throws URISyntaxException { ApplicationId id = BuilderUtils.newApplicationId(6384623l, 5); List<TrackingUriPlugin> list = Lists.newArrayListWithExpectedSize(0); assertNull(ProxyUriUtils.getUriFromTrackingPlugins(id, list)); }
@Test public void testGetProxyUri() throws Exception { URI originalUri = new URI("http://host.com/static/foo?bar=bar"); URI proxyUri = new URI("http://proxy.net:8080/"); ApplicationId id = BuilderUtils.newApplicationId(6384623l, 5); URI expected = new URI("http://proxy.net:8080/proxy/application_6384623_0005/static/foo?bar=bar"); URI result = ProxyUriUtils.getProxyUri(originalUri, proxyUri, id); assertEquals(expected, result); }
@Test public void testGetPathAndQuery() { assertEquals("/proxy/application_6384623_0005/static/app?foo=bar", ProxyUriUtils.getPathAndQuery(BuilderUtils.newApplicationId(6384623l, 5), "/static/app", "?foo=bar", false)); assertEquals("/proxy/application_6384623_0005/static/app?foo=bar&bad=good&proxyapproved=true", ProxyUriUtils.getPathAndQuery(BuilderUtils.newApplicationId(6384623l, 5), "/static/app", "foo=bar&bad=good", true)); }
/** * Get the proxied path for an application. * @param id the application id to use. * @return the base path to that application through the proxy. */ public static String getPath(ApplicationId id) { if(id == null) { throw new IllegalArgumentException("Application id cannot be null "); } return ujoin(PROXY_BASE, uriEncode(id)); }
/** * Create a URI form a no scheme Url, such as is returned by the AM. * @param noSchemeUrl the URL formate returned by an AM * @return a URI with an http scheme * @throws URISyntaxException if the url is not formatted correctly. */ public static URI getUriFromAMUrl(String scheme, String noSchemeUrl) throws URISyntaxException { if (getSchemeFromUrl(noSchemeUrl).isEmpty()) { /* * check is made to make sure if AM reports with scheme then it will be * used by default otherwise it will default to the one configured using * "yarn.http.policy". */ return new URI(scheme + noSchemeUrl); } else { return new URI(noSchemeUrl); } }
.getUriFromTrackingPlugins(id, this.trackingUriPlugins); if (toFetch != null) { ProxyUtils.sendRedirect(req, resp, toFetch.toString()); if (ProxyUriUtils.getSchemeFromUrl(original).isEmpty()) { trackingUri = ProxyUriUtils.getUriFromAMUrl( WebAppUtils.getHttpSchemePrefix(conf), original); } else { + "app master GUI of {} owned by {}", remoteUser, appId, runningUser); warnUserPage(resp, ProxyUriUtils.getPathAndQuery(id, rest, req.getQueryString(), true), runningUser, id); return;
@Test public void testGetProxyUriFromPluginsReturnsNullIfNoPlugins() throws URISyntaxException { ApplicationId id = BuilderUtils.newApplicationId(6384623l, 5); List<TrackingUriPlugin> list = Lists.newArrayListWithExpectedSize(0); assertNull(ProxyUriUtils.getUriFromTrackingPlugins(id, list)); }
@Test public void testGetProxyUri() throws Exception { URI originalUri = new URI("http://host.com/static/foo?bar=bar"); URI proxyUri = new URI("http://proxy.net:8080/"); ApplicationId id = BuilderUtils.newApplicationId(6384623l, 5); URI expected = new URI("http://proxy.net:8080/proxy/application_6384623_0005/static/foo?bar=bar"); URI result = ProxyUriUtils.getProxyUri(originalUri, proxyUri, id); assertEquals(expected, result); }
@Test public void testGetPathAndQuery() { assertEquals("/proxy/application_6384623_0005/static/app?foo=bar", ProxyUriUtils.getPathAndQuery(BuilderUtils.newApplicationId(6384623l, 5), "/static/app", "?foo=bar", false)); assertEquals("/proxy/application_6384623_0005/static/app?foo=bar&bad=good&proxyapproved=true", ProxyUriUtils.getPathAndQuery(BuilderUtils.newApplicationId(6384623l, 5), "/static/app", "foo=bar&bad=good", true)); }
/** * Get the proxied path for an application. * @param id the application id to use. * @return the base path to that application through the proxy. */ public static String getPath(ApplicationId id) { if(id == null) { throw new IllegalArgumentException("Application id cannot be null "); } return ujoin(PROXY_BASE, uriEncode(id)); }
/** * Create a URI form a no scheme Url, such as is returned by the AM. * @param noSchemeUrl the URL formate returned by an AM * @return a URI with an http scheme * @throws URISyntaxException if the url is not formatted correctly. */ public static URI getUriFromAMUrl(String scheme, String noSchemeUrl) throws URISyntaxException { if (getSchemeFromUrl(noSchemeUrl).isEmpty()) { /* * check is made to make sure if AM reports with scheme then it will be * used by default otherwise it will default to the one configured using * "yarn.http.policy". */ return new URI(scheme + noSchemeUrl); } else { return new URI(noSchemeUrl); } }
/** * Get the proxied path for an application. * * @param id the application id to use * @param path the rest of the path to the application * @return the base path to that application through the proxy */ public static String getPath(ApplicationId id, String path) { return getPath(id, path, false); }
.getUriFromTrackingPlugins(id, this.trackingUriPlugins); if (toFetch != null) { ProxyUtils.sendRedirect(req, resp, toFetch.toString()); if (ProxyUriUtils.getSchemeFromUrl(original).isEmpty()) { trackingUri = ProxyUriUtils.getUriFromAMUrl( WebAppUtils.getHttpSchemePrefix(conf), original); } else { + "app master GUI of {} owned by {}", remoteUser, appId, runningUser); warnUserPage(resp, ProxyUriUtils.getPathAndQuery(id, rest, req.getQueryString(), true), runningUser, id); return;
private String getDefaultProxyTrackingUrl() { try { final String scheme = WebAppUtils.getHttpSchemePrefix(conf); String proxy = WebAppUtils.getProxyHostAndPort(conf); URI proxyUri = ProxyUriUtils.getUriFromAMUrl(scheme, proxy); URI result = ProxyUriUtils.getProxyUri(null, proxyUri, applicationId); return result.toASCIIString(); } catch (URISyntaxException e) { LOG.warn("Could not generate default proxy tracking URL for " + applicationId); return UNAVAILABLE; } }