APEX-147 added more error info when getting the web service and ignore only FileNotFoundException when trying to get permission info
Project: http://git-wip-us.apache.org/repos/asf/incubator-apex-core/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-apex-core/commit/381ee948 Tree: http://git-wip-us.apache.org/repos/asf/incubator-apex-core/tree/381ee948 Diff: http://git-wip-us.apache.org/repos/asf/incubator-apex-core/diff/381ee948 Branch: refs/heads/feature-module Commit: 381ee94854e264461e167357284c9ff5392fb871 Parents: 507fac3 Author: David Yan <[email protected]> Authored: Tue Sep 22 20:18:23 2015 -0700 Committer: David Yan <[email protected]> Committed: Fri Sep 25 09:29:25 2015 -0700 ---------------------------------------------------------------------- .../datatorrent/stram/client/StramAgent.java | 23 ++++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-apex-core/blob/381ee948/engine/src/main/java/com/datatorrent/stram/client/StramAgent.java ---------------------------------------------------------------------- diff --git a/engine/src/main/java/com/datatorrent/stram/client/StramAgent.java b/engine/src/main/java/com/datatorrent/stram/client/StramAgent.java index adb438a..2b5968c 100644 --- a/engine/src/main/java/com/datatorrent/stram/client/StramAgent.java +++ b/engine/src/main/java/com/datatorrent/stram/client/StramAgent.java @@ -15,6 +15,7 @@ */ package com.datatorrent.stram.client; +import java.io.FileNotFoundException; import java.io.IOException; import java.util.Map; @@ -26,6 +27,7 @@ import javax.ws.rs.core.UriBuilder; import com.sun.jersey.api.client.Client; import com.sun.jersey.api.client.ClientResponse; +import org.apache.hadoop.yarn.api.records.YarnApplicationState; import org.codehaus.jettison.json.JSONException; import org.codehaus.jettison.json.JSONObject; import org.slf4j.Logger; @@ -318,6 +320,7 @@ public class StramAgent extends FSAgent return info == null ? getAppsRoot() + "/" + appId : info.appPath; } + // Note that this method only works if the app is running. We might want to deprecate this method. public String getUser(String appid) { StramWebServicesInfo info = getWebServicesInfo(appid); @@ -331,7 +334,16 @@ public class StramAgent extends FSAgent try { yarnClient.init(conf); yarnClient.start(); + ApplicationReport ar = yarnClient.getApplicationReport(ConverterUtils.toApplicationId(appId)); + if (ar == null) { + LOG.warn("YARN does not have record for this application {}", appId); + return null; + } else if (ar.getYarnApplicationState() != YarnApplicationState.RUNNING) { + LOG.debug("Application {} is not running (state: {})", appId, ar.getYarnApplicationState()); + return null; + } + String trackingUrl = ar.getTrackingUrl(); if (!trackingUrl.startsWith("http://") && !trackingUrl.startsWith("https://")) { @@ -350,7 +362,7 @@ public class StramAgent extends FSAgent url += WebServices.PATH; } catch (Exception ex) { - //LOG.error("Caught exception when retrieving web services info", ex); + LOG.error("Caught exception when retrieving web services info", ex); return null; } finally { @@ -412,11 +424,8 @@ public class StramAgent extends FSAgent is = fileSystem.open(new Path(appPath, "permissions.json")); permissionsInfo = new JSONObject(IOUtils.toString(is)); } - catch (JSONException ex) { - LOG.error("Error reading from the permissions info. Ignoring", ex); - } - catch (IOException ex) { - // ignore + catch (FileNotFoundException ex) { + // ignore if file is not found } finally { IOUtils.closeQuietly(is); @@ -424,7 +433,7 @@ public class StramAgent extends FSAgent return new StramWebServicesInfo(appMasterUrl, version, appPath, user, secToken, permissionsInfo); } catch (Exception ex) { - LOG.debug("Caught exception when retrieving web service info for app " + appId, ex); + LOG.warn("Caught exception when retrieving web service info for app {}", appId, ex); return null; } }
