在Hadoop的mapreduce框架中运行“Selenium Webdriver”,在地图步骤中冻结
几天前,我决定让selenium webdriver(第三方软件包)在hadoop的mapreduce框架中运行。 我遇到了一个问题。 地图步骤冻结在new FirefoxDriver();
。 FirefoxDriver类位于名为selenium-server-standalone-2.38.0.jar
的第三方jar中。 如果有人有经验或兴趣,我需要你的帮助!
一些细节:
- 问题详情
- 为了在命令行中运行代码,我使用“Xvfb”来停止Firefox图形界面。 然后我在开始时说的问题出现了。 我查看了tasktraker的日志,并在
this.driver = new FirefoxDriver(ffprofile);
找到代码冻结this.driver = new FirefoxDriver(ffprofile);
虽然代码已冻结,但firefox已经设置完毕,我使用ps -A | grep firefox
检查ps -A | grep firefox
- 为了在命令行中运行代码,我使用“Xvfb”来停止Firefox图形界面。 然后我在开始时说的问题出现了。 我查看了tasktraker的日志,并在
- 环境:
ubuntu 10.04 32bit; Hadoop的1.2.0; Mozilla Firefox 17.0.5; selenium – 服务器 – 独立-2.38.0.jar; xvfb的;
- 提示
- (1)Hadoop以Pesudo分布式运行;
- (2)当我在Eclipse中运行代码时,每件事情都可以。火狐按计划弹出。(我最后会显示演示代码);
- (3)如果你运行到
org.openqa.selenium.WebDriverException: Unable to bind to locking port 7054 within 45000 ms
,请使用commadps -A | grep firefox
ps -A | grep firefox
检查是否设置了一些firefox,并使用killall firefox
。 - (4)让代码在命令行中运行。 也许你会遇到
Error no display specified
你可以使用Xvfb :99 -ac 2>/dev/null &
安装xvfb
并设置xvfb
Xvfb :99 -ac 2>/dev/null &
。 在安装之前,xvfb
将一行export DISPLAY=:99
附加到HADOOP_HOME/conf/hadoop-env.sh
的末尾
- 代码演示
公共类MapRunnerNewFirefox扩展了Configured implements Tool,MapRunnable { public static final Logger LOG = LoggerFactory.getLogger(MapRunnerNewFirefox.class); @覆盖 public void configure(JobConf conf){ } @覆盖 public void run(RecordReader recordReader, OutputCollector输出,Reporter记者)抛出IOException { LongWritable key = new LongWritable(-1); //不应该为null,否则recordReader将报告nullpointer err; 文本val =新文本(“开始文本”); //与上线相同; int i = 0; reporter.progress(); while(recordReader.next(key,val)){ 如果(LOG.isInfoEnabled()){ LOG.info(“key:”+ key.toString()+“val:”+ val.toString()); } String temp =“ao”; NewFirefox ff = new NewFirefox(“/ home / cc / firefox / firefox / firefox”); output.collect(new Text(“get - ”+ key.toString()),new Text(temp)); } } @覆盖 public int run(String [] args)抛出exception{ if(LOG.isInfoEnabled()){ LOG.info(“set maprunner conf”); } 路径urlDir = new Path(args [0]); 路径resultDir = new Path(args [1] + System.currentTimeMillis()); JobConf job = new JobConf(getConf()); job.setNumMapTasks(1); job.setJobName(“hello maprunners”); job.setInputFormat(TextInputFormat.class); FileInputFormat.addInputPath(job,urlDir); job.setMapRunnerClass(MapRunnerNewFirefox.class); FileOutputFormat.setOutputPath(job,resultDir); job.setOutputFormat(TextOutputFormat.class); job.setOutputKeyClass(Text.class); job.setOutputValueClass(Text.class); JobClient.runJob(工作); 返回0; } public static void main(String [] args)throws Exception { 配置conf = new Configuration(); int res = ToolRunner.run(conf,new MapRunnerNewFirefox(),args); System.exit(RES); } } 公共类NewFirefox { 私人WebDriver驱动程序; private static final Logger LOG = LoggerFactory.getLogger(NewFirefox.class); public NewFirefox(String firefoxPath){ 如果(LOG.isInfoEnabled()){ LOG.info(“firefox **** 0”); } System.setProperty(“webdriver.firefox.bin”,firefoxPath); 如果(LOG.isInfoEnabled()){ LOG.info(“firefox **** 1”); } ProfilesIni profile = new ProfilesIni(); FirefoxProfile ffprofile = profile.getProfile(“default”); 如果(LOG.isInfoEnabled()){ LOG.info(“firefox **** 2”); } this.driver = new FirefoxDriver(ffprofile); 如果(LOG.isInfoEnabled()){ LOG.info(“firefox **** 3”); } this.driver.quit(); 如果(LOG.isInfoEnabled()){ LOG.info(“firefox quit”); } } }