job用法 Java_Java Job.addCacheFile方法代码示例

import org.apache.hadoop.mapreduce.Job; //导入方法依赖的package包/类

public void _testDistributedCache(String jobJarPath) throws Exception {

if (!(new File(MiniMRYarnCluster.APPJAR)).exists()) {

LOG.info("MRAppJar " + MiniMRYarnCluster.APPJAR

+ " not found. Not running test.");

return;

}

// Create a temporary file of length 1.

Path first = createTempFile("distributed.first", "x");

// Create two jars with a single file inside them.

Path second =

makeJar(new Path(TEST_ROOT_DIR, "distributed.second.jar"), 2);

Path third =

makeJar(new Path(TEST_ROOT_DIR, "distributed.third.jar"), 3);

Path fourth =

makeJar(new Path(TEST_ROOT_DIR, "distributed.fourth.jar"), 4);

Job job = Job.getInstance(mrCluster.getConfig());

// Set the job jar to a new "dummy" jar so we can check that its extracted

// properly

job.setJar(jobJarPath);

// Because the job jar is a "dummy" jar, we need to include the jar with

// DistributedCacheChecker or it won't be able to find it

Path distributedCacheCheckerJar = new Path(

JarFinder.getJar(DistributedCacheChecker.class));

job.addFileToClassPath(distributedCacheCheckerJar.makeQualified(

localFs.getUri(), distributedCacheCheckerJar.getParent()));

job.setMapperClass(DistributedCacheChecker.class);

job.setOutputFormatClass(NullOutputFormat.class);

FileInputFormat.setInputPaths(job, first);

// Creates the Job Configuration

job.addCacheFile(

new URI(first.toUri().toString() + "#distributed.first.symlink"));

job.addFileToClassPath(second);

// The AppMaster jar itself

job.addFileToClassPath(

APP_JAR.makeQualified(localFs.getUri(), APP_JAR.getParent()));

job.addArchiveToClassPath(third);

job.addCacheArchive(fourth.toUri());

job.setMaxMapAttempts(1); // speed up failures

job.submit();

String trackingUrl = job.getTrackingURL();

String jobId = job.getJobID().toString();

Assert.assertTrue(job.waitForCompletion(false));

Assert.assertTrue("Tracking URL was " + trackingUrl +

" but didn't Match Job ID " + jobId ,

trackingUrl.endsWith(jobId.substring(jobId.lastIndexOf("_")) + "/"));

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值