You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hdt.apache.org by ad...@apache.org on 2013/05/21 05:04:54 UTC
[2/2] git commit: [HDT-21] contributed by Mirko Kaempf
[HDT-21] contributed by Mirko Kaempf
Project: http://git-wip-us.apache.org/repos/asf/incubator-hdt/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-hdt/commit/2b7256ee
Tree: http://git-wip-us.apache.org/repos/asf/incubator-hdt/tree/2b7256ee
Diff: http://git-wip-us.apache.org/repos/asf/incubator-hdt/diff/2b7256ee
Branch: refs/heads/master
Commit: 2b7256ee2dbfb5d59d5ec1bad4684e14b562f27e
Parents: a36e229
Author: adamb <ad...@apache.org>
Authored: Mon May 20 22:04:38 2013 -0500
Committer: adamb <ad...@apache.org>
Committed: Mon May 20 22:04:38 2013 -0500
----------------------------------------------------------------------
org.apache.hdt.ui/plugin.xml | 10 +
.../apache/hdt/ui/wizards/NewDriverWizardPage.java | 44 ++--
.../org/apache/hdt/ui/wizards/NewMapperWizard.java | 14 +-
.../hdt/ui/wizards/NewPartitionerWizard.java | 199 +++++++++++++++
.../apache/hdt/ui/wizards/NewReducerWizard.java | 22 +-
5 files changed, 246 insertions(+), 43 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-hdt/blob/2b7256ee/org.apache.hdt.ui/plugin.xml
----------------------------------------------------------------------
diff --git a/org.apache.hdt.ui/plugin.xml b/org.apache.hdt.ui/plugin.xml
index 9e9bfa2..e04d5e6 100644
--- a/org.apache.hdt.ui/plugin.xml
+++ b/org.apache.hdt.ui/plugin.xml
@@ -68,6 +68,16 @@
id="org.apache.hdt.ui.NewDriverWizard"
name="MapReduce Driver"
project="false"/>
+ <wizard
+ category="org.apache.hdt.category"
+ class="org.apache.hdt.ui.wizards.NewPartitionerWizard"
+ finalPerspective="org.apache.hdt.ui.HadoopPerspective"
+ hasPages="true"
+ icon="resources/Elephant16x16.gif"
+ id="org.apache.hdt.ui.NewPartitionerWizard2"
+ name="Partitioner"
+ preferredPerspectives="org.apache.hadoop.eclipse.Perspective"
+ project="false"/>
<category
id="org.apache.hdt.category"
name="Hadoop"/>
http://git-wip-us.apache.org/repos/asf/incubator-hdt/blob/2b7256ee/org.apache.hdt.ui/src/org/apache/hdt/ui/wizards/NewDriverWizardPage.java
----------------------------------------------------------------------
diff --git a/org.apache.hdt.ui/src/org/apache/hdt/ui/wizards/NewDriverWizardPage.java b/org.apache.hdt.ui/src/org/apache/hdt/ui/wizards/NewDriverWizardPage.java
index 99d0f99..cf29661 100644
--- a/org.apache.hdt.ui/src/org/apache/hdt/ui/wizards/NewDriverWizardPage.java
+++ b/org.apache.hdt.ui/src/org/apache/hdt/ui/wizards/NewDriverWizardPage.java
@@ -70,7 +70,7 @@ public class NewDriverWizardPage extends NewTypeWizardPage {
this.showContainerSelector = showContainerSelector;
setTitle("MapReduce Driver");
- setDescription("Create a new MapReduce driver.");
+ setDescription("Create a new MapReduce driver");
setImageDescriptor(ImageLibrary.get("wizard.driver.new"));
}
@@ -95,10 +95,9 @@ public class NewDriverWizardPage extends NewTypeWizardPage {
imports.addImport("org.apache.hadoop.fs.Path");
imports.addImport("org.apache.hadoop.io.Text");
imports.addImport("org.apache.hadoop.io.IntWritable");
- imports.addImport("org.apache.hadoop.mapred.JobClient");
- imports.addImport("org.apache.hadoop.mapred.JobConf");
- imports.addImport("org.apache.hadoop.mapred.Reducer");
- imports.addImport("org.apache.hadoop.mapred.Mapper");
+ imports.addImport("org.apache.hadoop.mapreduce.Job");
+ imports.addImport("org.apache.hadoop.mapreduce.lib.input.FileInputFormat");
+ imports.addImport("org.apache.hadoop.mapreduce.lib.output.FileOutputFormat");
/**
* TODO(jz) - move most code out of the runnable
@@ -106,31 +105,32 @@ public class NewDriverWizardPage extends NewTypeWizardPage {
getContainer().getShell().getDisplay().syncExec(new Runnable() {
public void run() {
- String method = "public static void main(String[] args) {\n JobClient client = new JobClient();";
- method += "JobConf conf = new JobConf("
- + newType.getFullyQualifiedName() + ".class);\n\n";
-
- method += "// TODO: specify output types\nconf.setOutputKeyClass(Text.class);\nconf.setOutputValueClass(IntWritable.class);\n\n";
-
- method += "// TODO: specify input and output DIRECTORIES (not files)\nconf.setInputPath(new Path(\"src\"));\nconf.setOutputPath(new Path(\"out\"));\n\n";
+ String method = "public static void main(String[] args) throws IOException, InterruptedException, ClassNotFoundException {\n";
+ method += " Job job = new Job();\n\n";
+ method += " job.setJarByClass( ... );\n\n";
+ method += " job.setJobName( \"a nice name\" );\n\n";
+ method += " FileInputFormat.setInputPaths(job, new Path(args[0]));\n";
+ method += " FileOutputFormat.setOutputPath(job, new Path(args[1]));\n\n";
+
if (mapperText.getText().length() > 0) {
- method += "conf.setMapperClass(" + mapperText.getText()
+ method += " job.setMapperClass(" + mapperText.getText()
+ ".class);\n\n";
} else {
- method += "// TODO: specify a mapper\nconf.setMapperClass(org.apache.hadoop.mapred.lib.IdentityMapper.class);\n\n";
+ method += " // TODO: specify a mapper\njob.setMapperClass( ... );\n\n";
}
if (reducerText.getText().length() > 0) {
- method += "conf.setReducerClass(" + reducerText.getText()
+ method += " job.setReducerClass(" + reducerText.getText()
+ ".class);\n\n";
} else {
- method += "// TODO: specify a reducer\nconf.setReducerClass(org.apache.hadoop.mapred.lib.IdentityReducer.class);\n\n";
+ method += " // TODO: specify a reducer\njob.setReducerClass( ... );\n\n";
}
- method += "client.setConf(conf);\n";
- method += "try {\n\tJobClient.runJob(conf);\n} catch (Exception e) {\n"
- + "\te.printStackTrace();\n}\n";
- method += "}\n";
+ method += " job.setOutputKeyClass(Text.class);\n";
+ method += " job.setOutputValueClass(IntWritable.class);\n\n";
+
+ method += " boolean success = job.waitForCompletion(true);\n";
+ method += " System.exit(success ? 0 : 1);\n\t};";
try {
newType.createMethod(method, null, false, monitor);
@@ -198,12 +198,12 @@ public class NewDriverWizardPage extends NewTypeWizardPage {
private void createMapperControls(Composite composite) {
this.mapperText = createBrowseClassControl(composite, "Ma&pper:",
- "&Browse...", "org.apache.hadoop.mapred.Mapper", "Mapper Selection");
+ "&Browse...", "org.apache.hadoop.mapreduce.Mapper", "Mapper Selection");
}
private void createReducerControls(Composite composite) {
this.reducerText = createBrowseClassControl(composite, "&Reducer:",
- "Browse&...", "org.apache.hadoop.mapred.Reducer", "Reducer Selection");
+ "Browse&...", "org.apache.hadoop.mapreduce.Reducer", "Reducer Selection");
}
private Text createBrowseClassControl(final Composite composite,
http://git-wip-us.apache.org/repos/asf/incubator-hdt/blob/2b7256ee/org.apache.hdt.ui/src/org/apache/hdt/ui/wizards/NewMapperWizard.java
----------------------------------------------------------------------
diff --git a/org.apache.hdt.ui/src/org/apache/hdt/ui/wizards/NewMapperWizard.java b/org.apache.hdt.ui/src/org/apache/hdt/ui/wizards/NewMapperWizard.java
index 710c915..82443dc 100644
--- a/org.apache.hdt.ui/src/org/apache/hdt/ui/wizards/NewMapperWizard.java
+++ b/org.apache.hdt.ui/src/org/apache/hdt/ui/wizards/NewMapperWizard.java
@@ -104,13 +104,13 @@ public class NewMapperWizard extends NewElementWizard implements INewWizard,
IProgressMonitor monitor) throws CoreException {
super.createTypeMembers(newType, imports, monitor);
imports.addImport("java.io.IOException");
- imports.addImport("org.apache.hadoop.io.WritableComparable");
- imports.addImport("org.apache.hadoop.io.Writable");
- imports.addImport("org.apache.hadoop.mapred.OutputCollector");
- imports.addImport("org.apache.hadoop.mapred.Reporter");
+ imports.addImport("org.apache.hadoop.io.Text");
+ imports.addImport("org.apache.hadoop.io.IntWritable");
+ imports.addImport("org.apache.hadoop.io.LongWritable");
+ imports.addImport("org.apache.hadoop.mapreduce.Mapper");
newType
.createMethod(
- "public void map(WritableComparable key, Writable values, OutputCollector output, Reporter reporter) throws IOException \n{\n}\n",
+ "public void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException \n{\n}\n",
null, false, monitor);
}
@@ -133,9 +133,7 @@ public class NewMapperWizard extends NewElementWizard implements INewWizard,
setControl(composite);
- setSuperClass("org.apache.hadoop.mapred.MapReduceBase", true);
- setSuperInterfaces(Arrays
- .asList(new String[] { "org.apache.hadoop.mapred.Mapper" }), true);
+ setSuperClass("org.apache.hadoop.mapreduce.Mapper<LongWritable, Text, Text, IntWritable>", true);
setFocus();
validate();
http://git-wip-us.apache.org/repos/asf/incubator-hdt/blob/2b7256ee/org.apache.hdt.ui/src/org/apache/hdt/ui/wizards/NewPartitionerWizard.java
----------------------------------------------------------------------
diff --git a/org.apache.hdt.ui/src/org/apache/hdt/ui/wizards/NewPartitionerWizard.java b/org.apache.hdt.ui/src/org/apache/hdt/ui/wizards/NewPartitionerWizard.java
new file mode 100644
index 0000000..16c1d40
--- /dev/null
+++ b/org.apache.hdt.ui/src/org/apache/hdt/ui/wizards/NewPartitionerWizard.java
@@ -0,0 +1,199 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hdt.ui.wizards;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+
+import org.apache.hdt.ui.ImageLibrary;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.internal.ui.wizards.NewElementWizard;
+import org.eclipse.jdt.ui.wizards.NewTypeWizardPage;
+import org.eclipse.jface.operation.IRunnableWithProgress;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.ui.INewWizard;
+import org.eclipse.ui.IWorkbench;
+
+/**
+ * Wizard for creating a new Partitioner class (a class that runs the Map portion
+ * of a MapReduce job). The class is pre-filled with a template.
+ *
+ */
+
+public class NewPartitionerWizard extends NewElementWizard implements INewWizard,
+ IRunnableWithProgress {
+ private Page page;
+
+ public NewPartitionerWizard() {
+ setWindowTitle("New Partitioner");
+ }
+
+ public void run(IProgressMonitor monitor) {
+ try {
+ page.createType(monitor);
+ } catch (CoreException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (InterruptedException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+ @Override
+ public void init(IWorkbench workbench, IStructuredSelection selection) {
+ super.init(workbench, selection);
+
+ page = new Page();
+ addPage(page);
+ page.setSelection(selection);
+ }
+
+ public static class Page extends NewTypeWizardPage {
+ private Button isCreateMapMethod;
+
+ public Page() {
+ super(true, "Partitioner");
+
+ setTitle("Partitioner");
+ setDescription("Create a new Partitioner implementation.");
+ setImageDescriptor(ImageLibrary.get("wizard.partitioner.new"));
+ }
+
+ public void setSelection(IStructuredSelection selection) {
+ initContainerPage(getInitialJavaElement(selection));
+ initTypePage(getInitialJavaElement(selection));
+ }
+
+ @Override
+ public void createType(IProgressMonitor monitor) throws CoreException,
+ InterruptedException {
+ super.createType(monitor);
+ }
+
+ @Override
+ protected void createTypeMembers(IType newType, ImportsManager imports,
+ IProgressMonitor monitor) throws CoreException {
+ super.createTypeMembers(newType, imports, monitor);
+ imports.addImport("java.util.HashMap");
+ imports.addImport("org.apache.hadoop.io.Text");
+ imports.addImport("org.apache.hadoop.conf.Configurable");
+ imports.addImport("org.apache.hadoop.conf.Configuration");
+ imports.addImport("org.apache.hadoop.mapreduce.Partitioner");
+
+
+ newType
+ .createMethod(
+ " @Override\n" +
+ " public Configuration getConf() { \n" +
+ " // TODO Auto-generated method stub \n" +
+ " return null;\n" +
+ " }\n\n" +
+ " @Override\n" +
+ " public void setConf(Configuration conf) {\n" +
+ " // TODO Auto-generated method stub\n" +
+ " }\n\n" +
+ " @Override\n" +
+ " public int getPartition(Text key, Text value, int nr) { \n" +
+ " // TODO Auto-generated method stub \n" +
+ " return 0; \n" +
+ " }\n", null, false,
+ monitor);
+ }
+
+ public void createControl(Composite parent) {
+ // super.createControl(parent);
+
+ initializeDialogUnits(parent);
+ Composite composite = new Composite(parent, SWT.NONE);
+ GridLayout layout = new GridLayout();
+ layout.numColumns = 4;
+ composite.setLayout(layout);
+
+ createContainerControls(composite, 4);
+ createPackageControls(composite, 4);
+ createSeparator(composite, 4);
+ createTypeNameControls(composite, 4);
+ createSuperClassControls(composite, 4);
+ createSuperInterfacesControls(composite, 4);
+ // createSeparator(composite, 4);
+
+ setControl(composite);
+
+ setSuperClass("org.apache.hadoop.mapreduce.Partitioner<Text, Text>", true);
+ ArrayList al = new ArrayList();
+ al.add("org.apache.hadoop.conf.Configurable");
+ setSuperInterfaces(al, true);
+
+ setFocus();
+ validate();
+ }
+
+ @Override
+ protected void handleFieldChanged(String fieldName) {
+ super.handleFieldChanged(fieldName);
+
+ validate();
+ }
+
+ private void validate() {
+ updateStatus(new IStatus[] { fContainerStatus, fPackageStatus,
+ fTypeNameStatus, fSuperClassStatus, fSuperInterfacesStatus });
+ }
+ }
+
+ @Override
+ public boolean performFinish() {
+ if (super.performFinish()) {
+ if (getCreatedElement() != null) {
+ openResource((IFile) page.getModifiedResource());
+ selectAndReveal(page.getModifiedResource());
+ }
+
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ @Override
+ protected void finishPage(IProgressMonitor monitor)
+ throws InterruptedException, CoreException {
+ this.run(monitor);
+ }
+
+ @Override
+ public IJavaElement getCreatedElement() {
+ return page.getCreatedType().getPrimaryElement();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-hdt/blob/2b7256ee/org.apache.hdt.ui/src/org/apache/hdt/ui/wizards/NewReducerWizard.java
----------------------------------------------------------------------
diff --git a/org.apache.hdt.ui/src/org/apache/hdt/ui/wizards/NewReducerWizard.java b/org.apache.hdt.ui/src/org/apache/hdt/ui/wizards/NewReducerWizard.java
index 5ea7bab..225b8a9 100644
--- a/org.apache.hdt.ui/src/org/apache/hdt/ui/wizards/NewReducerWizard.java
+++ b/org.apache.hdt.ui/src/org/apache/hdt/ui/wizards/NewReducerWizard.java
@@ -101,18 +101,16 @@ public class NewReducerWizard extends NewElementWizard implements
IProgressMonitor monitor) throws CoreException {
super.createTypeMembers(newType, imports, monitor);
imports.addImport("java.io.IOException");
- imports.addImport("org.apache.hadoop.io.WritableComparable");
- imports.addImport("org.apache.hadoop.mapred.OutputCollector");
- imports.addImport("org.apache.hadoop.mapred.Reporter");
- imports.addImport("java.util.Iterator");
+ imports.addImport("org.apache.hadoop.mapreduce.Reducer");
+ imports.addImport("org.apache.hadoop.io.Text");
+ imports.addImport("org.apache.hadoop.io.IntWritable");
newType
.createMethod(
- "public void reduce(WritableComparable _key, Iterator values, OutputCollector output, Reporter reporter) throws IOException \n{\n"
- + "\t// replace KeyType with the real type of your key\n"
- + "\tKeyType key = (KeyType) _key;\n\n"
- + "\twhile (values.hasNext()) {\n"
+ "public void reduce(Text key, Iterable<IntWritable> values, Context context) throws IOException, InterruptedException \n{\n"
+
+ + "\twhile (values.iterator().hasNext()) {\n"
+ "\t\t// replace ValueType with the real type of your value\n"
- + "\t\tValueType value = (ValueType) values.next();\n\n"
+
+ "\t\t// process value\n" + "\t}\n" + "}\n", null, false,
monitor);
}
@@ -136,10 +134,8 @@ public class NewReducerWizard extends NewElementWizard implements
setControl(composite);
- setSuperClass("org.apache.hadoop.mapred.MapReduceBase", true);
- setSuperInterfaces(Arrays
- .asList(new String[] { "org.apache.hadoop.mapred.Reducer" }), true);
-
+ setSuperClass("org.apache.hadoop.mapreduce.Reducer<Text, IntWritable, Text, IntWritable>", true);
+
setFocus();
validate();
}