Skip to content
This repository has been archived by the owner on Jun 7, 2021. It is now read-only.

Commit

Permalink
APEXCORE-488: Issues in SSL communication with StrAM
Browse files Browse the repository at this point in the history
 - Fixed Application Master trackingURL
 - StramAgent shall not assume always HTTP
  • Loading branch information
pradeepdalvi committed Jul 13, 2016
1 parent 1b1813f commit 22783a7
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@
import com.datatorrent.stram.security.StramDelegationTokenManager;
import com.datatorrent.stram.security.StramUserLogin;
import com.datatorrent.stram.security.StramWSFilterInitializer;
import com.datatorrent.stram.util.ConfigUtils;
import com.datatorrent.stram.util.SecurityUtils;
import com.datatorrent.stram.webapp.AppInfo;
import com.datatorrent.stram.webapp.StramWebApp;
Expand Down Expand Up @@ -614,7 +615,16 @@ protected void serviceStart() throws Exception
}
WebApp webApp = WebApps.$for("stram", StramAppContext.class, appContext, "ws").with(config).start(new StramWebApp(this.dnmgr));
LOG.info("Started web service at port: " + webApp.port());
this.appMasterTrackingUrl = NetUtils.getConnectAddress(webApp.getListenerAddress()).getHostName() + ":" + webApp.port();
String host = NetUtils.getConnectAddress(webApp.getListenerAddress()).getHostName() + ":" + webApp.port();

// For backward compatibility, not adding scheme in TrackingURL for non-HTTPS
// TODO: Remove the check in next major release and add scheme always
if (ConfigUtils.isSecure(config)) {
String scheme = ConfigUtils.getSchemePrefix(config);
this.appMasterTrackingUrl = scheme + host;
} else {
this.appMasterTrackingUrl = host;
}
LOG.info("Setting tracking URL to: " + appMasterTrackingUrl);
} catch (Exception e) {
LOG.error("Webapps failed to start. Ignoring for now:", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,14 @@ private UriBuilder getStramWebURIBuilder(WebServicesClient webServicesClient, St
if (info != null) {
//ws = wsClient.resource("http://" + info.appMasterTrackingUrl).path(WebServices.PATH).path(info.version).path("stram");
// the filter should convert to the right version
ub = UriBuilder.fromUri("http://" + info.appMasterTrackingUrl).path(WebServices.PATH).path(WebServices.VERSION).path("stram");
String url;
if (!info.appMasterTrackingUrl.startsWith("http://")
&& !info.appMasterTrackingUrl.startsWith("https://")) {
url = "http://" + info.appMasterTrackingUrl;
} else {
url = info.appMasterTrackingUrl;
}
ub = UriBuilder.fromUri(url).path(WebServices.PATH).path(WebServices.VERSION).path("stram");
WebServicesVersionConversion.Converter versionConverter = WebServicesVersionConversion.getConverter(info.version);
if (versionConverter != null) {
VersionConversionFilter versionConversionFilter = new VersionConversionFilter(versionConverter);
Expand Down
19 changes: 17 additions & 2 deletions engine/src/main/java/com/datatorrent/stram/util/ConfigUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,30 @@ public static String getRMUsername(Configuration conf)
return principal;
}

public static String getSchemePrefix(YarnConfiguration conf)
public static boolean isSecure(Configuration conf)
{
if (HttpConfig.Policy.HTTPS_ONLY == HttpConfig.Policy.fromString(
conf.get(YarnConfiguration.YARN_HTTP_POLICY_KEY, YarnConfiguration.YARN_HTTP_POLICY_DEFAULT))) {
return true;
}
return false;
}

public static String getSchemePrefix(Configuration conf)
{
if (HttpConfig.Policy.HTTPS_ONLY == HttpConfig.Policy.fromString(conf.get(YarnConfiguration.YARN_HTTP_POLICY_KEY, YarnConfiguration.YARN_HTTP_POLICY_DEFAULT))) {
if (isSecure(conf)) {
return "https://";
} else {
return "http://";
}
}

@Deprecated
public static String getSchemePrefix(YarnConfiguration conf)
{
return getSchemePrefix((Configuration)conf);
}

public static String getYarnLogDir()
{
if (yarnLogDir != null) {
Expand Down

0 comments on commit 22783a7

Please sign in to comment.