ACCUMULO-1166 Make a maven archetype out of Instamo to make it even easier for users to easily spin up Accumulo and start coding.

git-svn-id: https://svn.apache.org/repos/asf/accumulo/contrib/instamo-archetype/trunk@1454220 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/pom.xml b/pom.xml
new file mode 100644
index 0000000..82cc2f7
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>

+<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>org.apache.accumulo</groupId>

+  <artifactId>instamo-archetype</artifactId>

+  <version>1.5.0-SNAPSHOT</version>

+  <packaging>maven-archetype</packaging>

+

+  <name>instamo-archetype</name>

+

+  <build>

+    <extensions>

+      <extension>

+        <groupId>org.apache.maven.archetype</groupId>

+        <artifactId>archetype-packaging</artifactId>

+        <version>2.2</version>

+      </extension>

+    </extensions>

+

+    <pluginManagement>

+      <plugins>

+        <plugin>

+          <artifactId>maven-archetype-plugin</artifactId>

+          <version>2.2</version>

+        </plugin>

+      </plugins>

+    </pluginManagement>

+  </build>

+

+  <url>http://accumulo.apache.org</url>

+</project>

diff --git a/src/main/resources/META-INF/maven/archetype-metadata.xml b/src/main/resources/META-INF/maven/archetype-metadata.xml
new file mode 100644
index 0000000..47c9589
--- /dev/null
+++ b/src/main/resources/META-INF/maven/archetype-metadata.xml
@@ -0,0 +1,44 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<archetype-descriptor xsi:schemaLocation="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.0.0 http://maven.apache.org/xsd/archetype-descriptor-1.0.0.xsd" name="instamo"
+    xmlns="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.0.0"
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+  <fileSets>
+    <fileSet filtered="true" encoding="UTF-8">
+      <directory>src/main/java</directory>
+      <includes>
+        <include>**/*.java</include>
+      </includes>
+    </fileSet>
+    <fileSet filtered="true" encoding="UTF-8">
+      <directory>src/main/resources</directory>
+      <includes>
+        <include>**/*.properties</include>
+      </includes>
+    </fileSet>
+    <fileSet filtered="true" encoding="UTF-8">
+      <directory>src/test/java</directory>
+      <includes>
+        <include>**/*.java</include>
+      </includes>
+    </fileSet>
+    <fileSet encoding="UTF-8">
+      <directory>.settings</directory>
+      <includes>
+        <include>**/*.prefs</include>
+      </includes>
+    </fileSet>
+    <fileSet filtered="true" encoding="UTF-8">
+      <directory></directory>
+      <includes>
+        <include>.classpath</include>
+        <include>.project</include>
+      </includes>
+    </fileSet>
+    <fileSet filtered="true" encoding="UTF-8">
+      <directory></directory>
+      <includes>
+        <include>README.md</include>
+      </includes>
+    </fileSet>
+  </fileSets>
+</archetype-descriptor>
diff --git a/src/main/resources/archetype-resources/.classpath b/src/main/resources/archetype-resources/.classpath
new file mode 100644
index 0000000..71534d2
--- /dev/null
+++ b/src/main/resources/archetype-resources/.classpath
@@ -0,0 +1,12 @@
+#set( $symbol_pound = '#' )
+#set( $symbol_dollar = '$' )
+#set( $symbol_escape = '\' )
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry kind="src" output="target/classes" path="src/main/java"/>
+	<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"/>
+	<classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+	<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"/>
+	<classpathentry kind="output" path="target/classes"/>
+</classpath>
diff --git a/src/main/resources/archetype-resources/.project b/src/main/resources/archetype-resources/.project
new file mode 100644
index 0000000..ad0d171
--- /dev/null
+++ b/src/main/resources/archetype-resources/.project
@@ -0,0 +1,26 @@
+#set( $symbol_pound = '#' )
+#set( $symbol_dollar = '$' )
+#set( $symbol_escape = '\' )
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>${artifactId}-archetype</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.eclipse.jdt.core.javabuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>org.eclipse.m2e.core.maven2Builder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>org.eclipse.jdt.core.javanature</nature>
+		<nature>org.eclipse.m2e.core.maven2Nature</nature>
+	</natures>
+</projectDescription>
diff --git a/src/main/resources/archetype-resources/.settings/org.eclipse.jdt.core.prefs b/src/main/resources/archetype-resources/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..92f0cdb
--- /dev/null
+++ b/src/main/resources/archetype-resources/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,6 @@
+#Fri Mar 01 21:44:42 EST 2013
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
+org.eclipse.jdt.core.compiler.source=1.6
diff --git a/src/main/resources/archetype-resources/.settings/org.eclipse.m2e.core.prefs b/src/main/resources/archetype-resources/.settings/org.eclipse.m2e.core.prefs
new file mode 100644
index 0000000..e9d221d
--- /dev/null
+++ b/src/main/resources/archetype-resources/.settings/org.eclipse.m2e.core.prefs
@@ -0,0 +1,5 @@
+#Fri Mar 01 21:44:32 EST 2013
+activeProfiles=
+eclipse.preferences.version=1
+resolveWorkspaceProjects=true
+version=1
diff --git a/src/main/resources/archetype-resources/README.md b/src/main/resources/archetype-resources/README.md
new file mode 100644
index 0000000..cb289e9
--- /dev/null
+++ b/src/main/resources/archetype-resources/README.md
@@ -0,0 +1,27 @@
+Instamo
+=======
+
+Introduction
+-----------
+
+Instamo makes it easy to write some code and run it against a local, transient
+[Accumulo](http://accumulo.apache.org) instance in minutes.  No setup or
+installation is required.  This is possible if Java and Maven are already
+installed by following the steps below.
+
+```
+vim src/main/java/${package}/AccumuloApp.java
+mvn package
+```
+
+Map Reduce
+----------
+
+Its possible to run local map reduce jobs against the MiniAccumuloCluster
+instance.   There is an example of this in the src directory  The following
+command will run the map reduce example.
+
+```
+mvn exec:exec
+```
+
diff --git a/src/main/resources/archetype-resources/pom.xml b/src/main/resources/archetype-resources/pom.xml
new file mode 100644
index 0000000..49c6d8a
--- /dev/null
+++ b/src/main/resources/archetype-resources/pom.xml
@@ -0,0 +1,132 @@
+<?xml version="1.0" encoding="UTF-8"?>

+<!--
+  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.
+--><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/maven-v4_0_0.xsd">

+  <modelVersion>4.0.0</modelVersion>

+  <groupId>${groupId}</groupId>

+  <artifactId>${artifactId}</artifactId>

+  <packaging>jar</packaging>

+  <version>${version}</version>

+  <name>Instamo Example</name>

+  <url>http://accumulo.apache.org</url>

+  <properties>

+    <accumulo.version>1.5.0-SNAPSHOT</accumulo.version>

+    <hadoop-one.version>1.0.4</hadoop-one.version>

+    <hadoop-two.version>2.0.2-alpha</hadoop-two.version>

+    <maclass>${package}.MapReduceExample</maclass>

+  </properties>

+  <profiles>

+    <!-- profile for building against Hadoop 1.0.x
+    Activate by not specifying hadoop.profile -->

+    <profile>

+      <id>hadoop-1.0</id>

+      <activation>

+        <property>

+          <name>!hadoop.profile</name>

+        </property>

+      </activation>

+      <properties>

+        <hadoop.version>${hadoop-one.version}</hadoop.version>

+      </properties>

+      <dependencies>

+        <dependency>

+          <groupId>org.apache.hadoop</groupId>

+          <artifactId>hadoop-core</artifactId>

+          <version>${hadoop.version}</version>

+        </dependency>

+      </dependencies>

+    </profile>

+    <!-- profile for building against Hadoop 2.0.x
+    Activate using: mvn -Dhadoop.profile=2.0 -->

+    <profile>

+      <id>hadoop-2.0</id>

+      <activation>

+        <property>

+          <name>hadoop.profile</name>

+          <value>2.0</value>

+        </property>

+      </activation>

+      <properties>

+        <hadoop.version>${hadoop-two.version}</hadoop.version>

+      </properties>

+      <dependencies>

+        <dependency>

+          <groupId>org.apache.hadoop</groupId>

+          <artifactId>hadoop-client</artifactId>

+          <version>${hadoop.version}</version>

+        </dependency>

+      </dependencies>

+    </profile>

+  </profiles>

+  <dependencies>

+    <dependency>

+      <groupId>junit</groupId>

+      <artifactId>junit</artifactId>

+      <version>4.11</version>

+      <scope>test</scope>

+    </dependency>

+    <dependency>

+      <groupId>org.apache.accumulo</groupId>

+      <artifactId>accumulo-core</artifactId>

+      <version>${accumulo.version}</version>

+    </dependency>

+    <dependency>

+      <groupId>org.apache.accumulo</groupId>

+      <artifactId>accumulo-server</artifactId>

+      <version>${accumulo.version}</version>

+    </dependency>

+    <dependency>

+      <groupId>org.apache.zookeeper</groupId>

+      <artifactId>zookeeper</artifactId>

+      <version>3.3.4</version>

+    </dependency>

+    <dependency>

+      <groupId>commons-io</groupId>

+      <artifactId>commons-io</artifactId>

+      <version>2.4</version>

+    </dependency>

+    <dependency>

+    	<groupId>org.apache.accumulo</groupId>

+    	<artifactId>accumulo-test</artifactId>

+    	<version>${accumulo.version}</version>

+    </dependency>

+  </dependencies>

+  <build>

+    <plugins>

+      <plugin>

+        <artifactId>maven-compiler-plugin</artifactId>

+        <version>2.0.2</version>

+        <configuration>

+          <source>1.6</source>

+          <target>1.6</target>

+        </configuration>

+      </plugin>

+      <plugin>

+        <groupId>org.codehaus.mojo</groupId>

+        <artifactId>exec-maven-plugin</artifactId>

+        <version>1.2.1</version>

+        <configuration>

+          <executable>java</executable>

+          <arguments>

+            <argument>-classpath</argument>

+            <classpath />

+            <argument>${maclass}</argument>

+          </arguments>

+        </configuration>

+      </plugin>

+    </plugins>

+  </build>

+</project>

diff --git a/src/main/resources/archetype-resources/src/main/java/AccumuloApp.java b/src/main/resources/archetype-resources/src/main/java/AccumuloApp.java
new file mode 100644
index 0000000..d275672
--- /dev/null
+++ b/src/main/resources/archetype-resources/src/main/java/AccumuloApp.java
@@ -0,0 +1,60 @@
+#set( $symbol_pound = '#' )
+#set( $symbol_dollar = '$' )
+#set( $symbol_escape = '\' )
+/*
+ * 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 ${package};
+
+import java.util.Map.Entry;
+
+import org.apache.accumulo.core.Constants;
+import org.apache.accumulo.core.client.BatchWriter;
+import org.apache.accumulo.core.client.BatchWriterConfig;
+import org.apache.accumulo.core.client.Connector;
+import org.apache.accumulo.core.client.Instance;
+import org.apache.accumulo.core.client.Scanner;
+import org.apache.accumulo.core.client.ZooKeeperInstance;
+import org.apache.accumulo.core.data.Key;
+import org.apache.accumulo.core.data.Mutation;
+import org.apache.accumulo.core.data.Value;
+
+public class AccumuloApp {
+  
+  public static void run(String instanceName, String zookeepers, String rootPassword, String args[]) throws Exception {
+    // edit this method to play with Accumulo
+
+    Instance instance = new ZooKeeperInstance(instanceName, zookeepers);
+    
+    Connector conn = instance.getConnector("root", rootPassword);
+    
+    conn.tableOperations().create("foo");
+    
+    BatchWriter bw = conn.createBatchWriter("foo", new BatchWriterConfig());
+    Mutation m = new Mutation("r1");
+    m.put("cf1", "cq1", "v1");
+    m.put("cf1", "cq2", "v3");
+    bw.addMutation(m);
+    bw.close();
+    
+    Scanner scanner = conn.createScanner("foo", Constants.NO_AUTHS);
+    for (Entry<Key,Value> entry : scanner) {
+      System.out.println(entry.getKey() + " " + entry.getValue());
+    }
+    
+    conn.tableOperations().delete("foo");
+  }
+}
diff --git a/src/main/resources/archetype-resources/src/main/java/MapReduceExample.java b/src/main/resources/archetype-resources/src/main/java/MapReduceExample.java
new file mode 100644
index 0000000..53a0ba3
--- /dev/null
+++ b/src/main/resources/archetype-resources/src/main/java/MapReduceExample.java
@@ -0,0 +1,71 @@
+#set( $symbol_pound = '#' )
+#set( $symbol_dollar = '$' )
+#set( $symbol_escape = '\' )
+/*
+ * 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 ${package};
+
+import java.io.File;
+import java.util.UUID;
+
+import org.apache.accumulo.test.MiniAccumuloCluster;
+import org.apache.accumulo.test.continuous.ContinuousIngest;
+import org.apache.accumulo.test.continuous.ContinuousVerify;
+import org.apache.commons.io.FileUtils;
+
+/**
+ * An example of running local map reduce against MiniAccumuloCluster
+ */
+public class MapReduceExample {
+  
+  public static void run(String instanceName, String zookeepers, String rootPassword, String args[]) throws Exception {
+    
+    // run continuous ingest to create data. This is not a map reduce job
+    ContinuousIngest.main(new String[] {"-i", instanceName, "-z", zookeepers, "-u", "root", "-p", rootPassword, "--table", "ci", "--num", "5000000",
+        "--batchMemory", "1000000"});
+    
+    String outputDir = FileUtils.getTempDirectoryPath() + File.separator + "ci_verify" + UUID.randomUUID().toString();
+    
+    try {
+      // run verify map reduce job locally. This jobs looks for holes in the linked list create by continuous ingest
+      ContinuousVerify.main(new String[] {"-D", "mapred.job.tracker=local", "-D", "fs.default.name=file:///", "-i", instanceName, "-z", zookeepers, "-u",
+          "root", "-p", rootPassword, "--table", "ci", "--output", outputDir, "--maxMappers", "4", "--reducers", "1"});
+    } finally {
+      // delete output dir of mapreduce job
+      FileUtils.deleteQuietly(new File(outputDir));
+    }
+  }
+
+  public static void main(String[] args) throws Exception {
+    File tmpDir = new File(FileUtils.getTempDirectory(), "macc-" + UUID.randomUUID().toString());
+    
+    try {
+      MiniAccumuloCluster la = new MiniAccumuloCluster(tmpDir, "pass1234");
+      la.start();
+      
+      System.out.println("${symbol_escape}n   ---- Running Mapred Against Accumulo${symbol_escape}n");
+      
+      run(la.getInstanceName(), la.getZooKeepers(), "pass1234", args);
+      
+      System.out.println("${symbol_escape}n   ---- Ran Mapred Against Accumulo${symbol_escape}n");
+      
+      la.stop();
+    } finally {
+      FileUtils.deleteQuietly(tmpDir);
+    }
+  }
+}
diff --git a/src/main/resources/archetype-resources/src/main/resources/log4j.properties b/src/main/resources/archetype-resources/src/main/resources/log4j.properties
new file mode 100644
index 0000000..0f2e7be
--- /dev/null
+++ b/src/main/resources/archetype-resources/src/main/resources/log4j.properties
@@ -0,0 +1,12 @@
+#set( $symbol_pound = '#' )
+#set( $symbol_dollar = '$' )
+#set( $symbol_escape = '\' )
+log4j.rootLogger=INFO, CA
+log4j.appender.CA=org.apache.log4j.ConsoleAppender
+log4j.appender.CA.layout=org.apache.log4j.PatternLayout
+log4j.appender.CA.layout.ConversionPattern=[%t] %-5p %c %x - %m%n
+
+log4j.logger.org.apache.zookeeper=ERROR,CA
+log4j.logger.${groupId}.core.client.impl.ServerClient=ERROR
+log4j.logger.${groupId}.server.security.Auditor=off
+
diff --git a/src/main/resources/archetype-resources/src/test/java/ExampleAccumuloUnitTest.java b/src/main/resources/archetype-resources/src/test/java/ExampleAccumuloUnitTest.java
new file mode 100644
index 0000000..31102aa
--- /dev/null
+++ b/src/main/resources/archetype-resources/src/test/java/ExampleAccumuloUnitTest.java
@@ -0,0 +1,60 @@
+#set( $symbol_pound = '#' )
+#set( $symbol_dollar = '$' )
+#set( $symbol_escape = '\' )
+/*
+ * 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 ${package};
+
+import org.apache.accumulo.test.MiniAccumuloCluster;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+
+/**
+ * An example unit test that shows how to use MiniAccumuloCluster in a unit test
+ */
+
+public class ExampleAccumuloUnitTest {
+  
+  public static TemporaryFolder folder = new TemporaryFolder();
+  
+  private static MiniAccumuloCluster accumulo;
+
+  @BeforeClass
+  public static void setupMiniCluster() throws Exception {
+
+    folder.create();
+    
+    accumulo = new MiniAccumuloCluster(folder.getRoot(), "superSecret");
+    
+    accumulo.start();
+    
+  }
+
+  @Test(timeout = 30000)
+  public void test() throws Exception {
+    AccumuloApp.run(accumulo.getInstanceName(), accumulo.getZooKeepers(), "superSecret", new String[0]);
+  }
+  
+  @AfterClass
+  public static void tearDownMiniCluster() throws Exception {
+    accumulo.stop();
+    folder.delete();
+  }
+  
+}
diff --git a/src/test/resources/projects/basic/archetype.properties b/src/test/resources/projects/basic/archetype.properties
new file mode 100644
index 0000000..66d6142
--- /dev/null
+++ b/src/test/resources/projects/basic/archetype.properties
@@ -0,0 +1,5 @@
+#Thu Mar 07 21:20:20 EST 2013
+package=it.pkg
+version=0.1-SNAPSHOT
+groupId=archetype.it
+artifactId=basic
diff --git a/src/test/resources/projects/basic/goal.txt b/src/test/resources/projects/basic/goal.txt
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/test/resources/projects/basic/goal.txt