Last active
January 22, 2020 22:36
-
-
Save jeff303/8dab0e52dc227741b6605f576a317798 to your computer and use it in GitHub Desktop.
Miscellaneous Spark utilities
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.apache.hadoop.yarn.api.records.ApplicationReport; | |
import org.apache.hadoop.yarn.client.api.YarnClient; | |
import org.apache.hadoop.yarn.exceptions.YarnException; | |
import org.apache.hadoop.yarn.util.ConverterUtils; | |
import org.slf4j.Logger; | |
import org.slf4j.LoggerFactory; | |
public class SparkUtils { | |
private static final Logger LOG = LoggerFactory.getLogger(SparkUtils.class); | |
/** | |
* Given a Hadoop configuration and appId, use the YARN API (via the {@link YarnClient}) to get the application | |
* report, which includes the trackingUrl. | |
* | |
* @param hadoopConf the Hadoop {@link org.apache.hadoop.conf.Configuration} | |
* @param appId the YARN application ID | |
* @return the app trackingUrl | |
*/ | |
public static String getYarnApplicationTrackingUrl(org.apache.hadoop.conf.Configuration hadoopConf, String appId) { | |
final YarnClient yarnClient = YarnClient.createYarnClient(); | |
try { | |
yarnClient.init(hadoopConf); | |
yarnClient.start(); | |
final ApplicationReport report = yarnClient.getApplicationReport(ConverterUtils.toApplicationId(appId)); | |
return report.getTrackingUrl(); | |
} catch (YarnException | IOException e) { | |
LOG.warn("{} attempting to get report for YARN appId {}", e.getClass().getSimpleName(), appId, e); | |
return null; | |
} finally { | |
yarnClient.stop(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment