我试图使用AccumuloInputFormat
和newAPIHadoopRDD
从Apache Spark作业(用Java编写)访问Accumulo 1.6。为了做到这一点,我必须通过调用setZooKeeperInstance
方法告诉AccumuloInputFormat
ZooKeeper的位置。该方法采用指定各种相关属性的ClientConfiguration
对象。如何在YARN Spark作业中设置环境变量?
我正在通过调用静态loadDefault
方法创建我的ClientConfiguration
对象。这种方法应该在各个地方查找client.conf
文件以从中加载其默认值。它应该看的地方之一是$ACCUMULO_CONF_DIR/client.conf
。
因此,我试图设置ACCUMULO_CONF_DIR
环境变量,使它在Spark运行作业时可见(供参考,我试图在yarn-cluster
部署模式下运行)。我还没有找到成功的方法。
到目前为止,我已经试过:
- 在他们
spark-defaults.conf
无呼吁SparkConf
ACCUMULO_CONF_DIR
setExecutorEnv("ACCUMULO_CONF_DIR", "/etc/accumulo/conf")
在spark-env.sh
spark.executorEnv.ACCUMULO_CONF_DIR
工作过。在拨打setZooKeeperInstance
之前打印环境时,ACCUMULO_CONF_DIR
未出现。 如果它是相关的,我使用的是一切的CDH5版本。
这里是我想要做的一个例子(进口和异常处理冷落为了简洁):
public class MySparkJob
{
public static void main(String[] args)
{
SparkConf sparkConf = new SparkConf();
sparkConf.setAppName("MySparkJob");
sparkConf.setExecutorEnv("ACcUMULO_CONF_DIR", "/etc/accumulo/conf");
JavaSparkContext sc = new JavaSparkContext(sparkConf);
Job accumuloJob = Job.getInstance(sc.hadoopConfiguration());
// Foreach loop to print environment, shows no ACCUMULO_CONF_DIR
ClientConfiguration accumuloConfiguration = ClientConfiguration.loadDefault();
AccumuloInputFormat.setZooKeeperInstance(accumuloJob, accumuloConfiguration);
// Other calls to AccumuloInputFormat static functions to configure it properly.
JavaPairRDD<Key, Value> accumuloRDD =
sc.newAPIHadoopRDD(accumuloJob.getConfiguration(),
AccumuloInputFormat.class,
Key.class,
Value.class);
}
}