[HADOOP] Eclipse로 Hadoop 맵핑 / 축소 작업 개발, 테스트 및 디버깅
HADOOPEclipse로 Hadoop 맵핑 / 축소 작업 개발, 테스트 및 디버깅
Eclipse에서 Java Map Reduce 작업을 개발하기위한 나의 옵션에는 무엇이 있습니까? 최종 목표는 내 아마존 Hadoop 클러스터에서 개발 한지도 / 논리를 실행하는 것이지만, 먼저 로컬 시스템에서 로직을 테스트하고 더 큰 클러스터에 배치하기 전에 브레이크 포인트를 넣고 싶습니다.
나이가 들어 보이는 이클립스 용 Hadoop 플러그인이 있다는 것을 알았고 (잘못된 것이라면 나를 바로 잡는다.) Karmasphere라는 회사는 ecplise와 Hadoop을 위해 뭔가를 가지고 있었다. 그러나 여전히 사용 가능한지 확실하지 않다.
Eclipse를 사용하여 맵을 작성, 테스트 및 디버깅하는 방법은 무엇입니까?
해결법
-
==============================
1.Eclipse에서 Cassandra / Hadoop 응용 프로그램을 개발합니다.
Eclipse에서 Cassandra / Hadoop 응용 프로그램을 개발합니다.
보조 노트와 마찬가지로 Eclipse의 M2T JET 프로젝트를 기반으로하는 많은 코드 생성 도구를 만들었습니다. 위에서 언급 한 모든 것에 대한 인프라를 생성하고, 매퍼, 감속기 및 테스트 케이스에 대한 논리를 작성합니다. 나는 당신이 아마 약간의 재사용 가능한 클래스 세트를 생각해 낼 수 있다고 생각한다면, 당신이 확장 할 수있는 클래스는 꽤 똑같을 것이라고 생각합니다.
샘플 테스트 케이스 클래스는 다음과 같습니다.
/* * * This source code and information are provided "AS-IS" without * warranty of any kind, either expressed or implied, including * but not limited to the implied warranties of merchantability * and/or fitness for a particular purpose. * * This source code was generated using an evaluation copy * of the Cassandra/Hadoop Accelerator and may not be used for * production purposes. * */ package com.creditco.countwords.ReadDocs; // Begin imports import java.io.IOException; import java.util.ArrayList; import junit.framework.TestCase; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.io.IntWritable; import org.apache.hadoop.io.LongWritable; import org.apache.hadoop.io.Text; import org.apache.hadoop.mapreduce.Counter; import org.apache.hadoop.mapreduce.Counters; import org.apache.hadoop.mapreduce.InputSplit; import org.apache.hadoop.mapreduce.JobContext; import org.apache.hadoop.mapreduce.Mapper; import org.apache.hadoop.mapreduce.OutputCommitter; import org.apache.hadoop.mapreduce.RecordReader; import org.apache.hadoop.mapreduce.RecordWriter; import org.apache.hadoop.mapreduce.StatusReporter; import org.apache.hadoop.mapreduce.TaskAttemptContext; import org.apache.hadoop.mapreduce.TaskAttemptID; import org.junit.Test; // End imports public class ParseDocsMapperTest extends TestCase { @Test public void testCount() { TestRecordWriter recordWriter = new TestRecordWriter(); TestRecordReader recordReader = new TestRecordReader(); TestOutputCommitter outputCommitter = new TestOutputCommitter(); TestStatusReporter statusReporter = new TestStatusReporter(); TestInputSplit inputSplit = new TestInputSplit(); try { // Begin test logic // Get an instance of the mapper to be tested and a context instance ParseDocsMapper mapper = new ParseDocsMapper(); Mapper<LongWritable,Text,Text,IntWritable>.Context context = mapper.testContext(new Configuration(), new TaskAttemptID(),recordReader,recordWriter,outputCommitter,statusReporter,inputSplit); // Invoke the setup, map and cleanup methods mapper.setup(context); LongWritable key = new LongWritable(30); Text value = new Text("abc def ghi"); mapper.map(key, value, context); if (recordWriter.getKeys().length != 3) { fail("com.creditco.countwords:ParseDocsMapperTest.testCount() - Wrong number of records written "); } mapper.cleanup(context); // Validation: // // recordWriter.getKeys() returns the keys written to the context by the mapper // recordWriter.getValues() returns the values written to the context by the mapper // statusReporter returns the most recent status and any counters set by the mapper // // End test logic } catch (Exception e) { fail("com.creditco.countwords:ParseDocsMapperTest.testCount() - Exception thrown: "+e.getMessage()); } } final class TestRecordWriter extends RecordWriter<Text, IntWritable> { ArrayList<Text> keys = new ArrayList<Text>(); ArrayList<IntWritable> values = new ArrayList<IntWritable>(); public void close(TaskAttemptContext arg0) throws IOException, InterruptedException { } public void write(Text key, IntWritable value) throws IOException, InterruptedException { keys.add(key); values.add(value); } public Text[] getKeys() { Text result[] = new Text[keys.size()]; keys.toArray(result); return result; } public IntWritable[] getValues() { IntWritable[] result = new IntWritable[values.size()]; values.toArray(result); return result; } }; final class TestRecordReader extends RecordReader<LongWritable, Text> { public void close() throws IOException { } public LongWritable getCurrentKey() throws IOException, InterruptedException { throw new RuntimeException("Tried to call RecordReader:getCurrentKey()"); } public Text getCurrentValue() throws IOException, InterruptedException { throw new RuntimeException("Tried to call RecordReader:getCurrentValue()"); } public float getProgress() throws IOException, InterruptedException { throw new RuntimeException("Tried to call RecordReader:getProgress()"); } public void initialize(InputSplit arg0, TaskAttemptContext arg1) throws IOException, InterruptedException { } public boolean nextKeyValue() throws IOException, InterruptedException { return false; } }; final class TestStatusReporter extends StatusReporter { private Counters counters = new Counters(); private String status = null; public void setStatus(String arg0) { status = arg0; } public String getStatus() { return status; } public void progress() { } public Counter getCounter(String arg0, String arg1) { return counters.getGroup(arg0).findCounter(arg1); } public Counter getCounter(Enum<?> arg0) { return null; } }; final class TestInputSplit extends InputSplit { public String[] getLocations() throws IOException, InterruptedException { return null; } public long getLength() throws IOException, InterruptedException { return 0; } }; final class TestOutputCommitter extends OutputCommitter { public void setupTask(TaskAttemptContext arg0) throws IOException { } public void setupJob(JobContext arg0) throws IOException { } public boolean needsTaskCommit(TaskAttemptContext arg0) throws IOException { return false; } public void commitTask(TaskAttemptContext arg0) throws IOException { } public void cleanupJob(JobContext arg0) throws IOException { } public void abortTask(TaskAttemptContext arg0) throws IOException { } }; }
여기 샘플 maven pom이 있습니다. 참조 된 버전은 약간 오래되었지만, 그 버전이 어디에서나 maven 저장소에 보관되어 있다면이 프로젝트를 빌드 할 수 있습니다.
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.creditco</groupId> <artifactId>wordcount.example</artifactId> <version>0.0.1-SNAPSHOT</version> <build> <plugins> <plugin> <artifactId>maven-assembly-plugin</artifactId> <version>2.2</version> <configuration> <descriptorRefs> <descriptorRef>jar-with-dependencies</descriptorRef> </descriptorRefs> </configuration> </plugin> </plugins> </build> <dependencies> <dependency> <groupId>org.apache.hadoop</groupId> <artifactId>hadoop-core</artifactId> <version>0.20.2</version> <type>jar</type> <scope>compile</scope> </dependency> <dependency> <groupId>org.apache.cassandra</groupId> <artifactId>cassandra-all</artifactId> <version>1.0.6</version> <type>jar</type> <scope>compile</scope> </dependency> <dependency> <groupId>org.cassandraunit</groupId> <artifactId>cassandra-unit</artifactId> <version>1.0.1.1</version> <type>jar</type> <scope>compile</scope> <exclusions> <exclusion> <artifactId>hamcrest-all</artifactId> <groupId>org.hamcrest</groupId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.apache.pig</groupId> <artifactId>pig</artifactId> <version>0.9.1</version> <type>jar</type> <scope>compile</scope> </dependency> <dependency> <groupId>org.json</groupId> <artifactId>json</artifactId> <version>20090211</version> <type>jar</type> <scope>compile</scope> </dependency> </dependencies> </project>
-
==============================
2.아파치와 함께 제공되는 MiniMRCluster 클러스터를 사용합니다. 단위 테스트에서 미니 맵 Reduce 클러스터를 시작하는 데 사용합니다! HBase에는 HBaseTestingUtil도 있는데, HDFS와 MapReduce를 약 두 줄부터 시작하기 때문에 좋습니다.
아파치와 함께 제공되는 MiniMRCluster 클러스터를 사용합니다. 단위 테스트에서 미니 맵 Reduce 클러스터를 시작하는 데 사용합니다! HBase에는 HBaseTestingUtil도 있는데, HDFS와 MapReduce를 약 두 줄부터 시작하기 때문에 좋습니다.
-
==============================
3.@ 크리스 Gerken - 나는 자바 응용 프로그램으로 드라이버를 실행하여 이클립스에서 단어 개수 작업을 실행하려고하지만 매퍼에서 ClassNotFoundException을 얻을. Java 응용 프로그램으로 실행되는 hadoop 작업은 필요한 Mapper 및 Reduid를 jar 파일로 가져 오지 않습니다.
@ 크리스 Gerken - 나는 자바 응용 프로그램으로 드라이버를 실행하여 이클립스에서 단어 개수 작업을 실행하려고하지만 매퍼에서 ClassNotFoundException을 얻을. Java 응용 프로그램으로 실행되는 hadoop 작업은 필요한 Mapper 및 Reduid를 jar 파일로 가져 오지 않습니다.
from https://stackoverflow.com/questions/11007423/developing-testing-and-debugging-hadoop-map-reduce-jobs-with-eclipse by cc-by-sa and MIT license
'HADOOP' 카테고리의 다른 글
[HADOOP] hadoop fs -copyToLocal 명령을 사용하여 기존 파일을 덮어 쓰는 방법 (0) | 2019.07.07 |
---|---|
[HADOOP] 지도 축소 : ChainMapper 및 ChainReducer (0) | 2019.07.07 |
[HADOOP] hadoop을 사용한 이미지 처리 (0) | 2019.07.07 |
[HADOOP] Hadoop Streaming에서 "typedbytes"또는 "rawbytes"를 사용하는 방법은 무엇입니까? (0) | 2019.07.07 |
[HADOOP] HDFS에서 blockName의 파일을 찾는 방법 hadoop (0) | 2019.07.07 |