Search in sources :

Example 1 with ExecutorInfo

use of org.apache.spark.scheduler.cluster.ExecutorInfo in project beam by apache.

the class SparkCommon method startEventLoggingListener.

/**
 * Starts an EventLoggingListener to save Beam Metrics on Spark's History Server if event logging
 * is enabled.
 *
 * @return The associated EventLoggingListener or null if it could not be started.
 */
@Nullable
public static EventLoggingListener startEventLoggingListener(final JavaSparkContext jsc, SparkPipelineOptions pipelineOptions, long startTime) {
    EventLoggingListener eventLoggingListener = null;
    try {
        if (jsc.getConf().getBoolean("spark.eventLog.enabled", false)) {
            eventLoggingListener = new EventLoggingListener(jsc.getConf().getAppId(), scala.Option.apply("1"), new URI(jsc.getConf().get("spark.eventLog.dir", null)), jsc.getConf(), jsc.hadoopConfiguration());
            eventLoggingListener.initializeLogIfNecessary(false, false);
            eventLoggingListener.start();
            scala.collection.immutable.Map<String, String> logUrlMap = new scala.collection.immutable.HashMap<>();
            Tuple2<String, String>[] sparkMasters = jsc.getConf().getAllWithPrefix("spark.master");
            Tuple2<String, String>[] sparkExecutors = jsc.getConf().getAllWithPrefix("spark.executor.id");
            for (Tuple2<String, String> sparkExecutor : sparkExecutors) {
                eventLoggingListener.onExecutorAdded(new SparkListenerExecutorAdded(startTime, sparkExecutor._2(), new ExecutorInfo(sparkMasters[0]._2(), 0, logUrlMap)));
            }
            return eventLoggingListener;
        }
    } catch (URISyntaxException e) {
        throw new RuntimeException("The URI syntax in the Spark config \"spark.eventLog.dir\" is not correct", e);
    }
    return eventLoggingListener;
}
Also used : URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) ExecutorInfo(org.apache.spark.scheduler.cluster.ExecutorInfo) Tuple2(scala.Tuple2) SparkListenerExecutorAdded(org.apache.spark.scheduler.SparkListenerExecutorAdded) EventLoggingListener(org.apache.spark.scheduler.EventLoggingListener) Nullable(org.checkerframework.checker.nullness.qual.Nullable)

Aggregations

URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 EventLoggingListener (org.apache.spark.scheduler.EventLoggingListener)1 SparkListenerExecutorAdded (org.apache.spark.scheduler.SparkListenerExecutorAdded)1 ExecutorInfo (org.apache.spark.scheduler.cluster.ExecutorInfo)1 Nullable (org.checkerframework.checker.nullness.qual.Nullable)1 Tuple2 (scala.Tuple2)1