Return-Path: X-Original-To: apmail-accumulo-commits-archive@www.apache.org Delivered-To: apmail-accumulo-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 9B8CA10116 for ; Fri, 12 Jul 2013 21:51:12 +0000 (UTC) Received: (qmail 80324 invoked by uid 500); 12 Jul 2013 21:51:12 -0000 Delivered-To: apmail-accumulo-commits-archive@accumulo.apache.org Received: (qmail 80303 invoked by uid 500); 12 Jul 2013 21:51:12 -0000 Mailing-List: contact commits-help@accumulo.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@accumulo.apache.org Delivered-To: mailing list commits@accumulo.apache.org Received: (qmail 80293 invoked by uid 99); 12 Jul 2013 21:51:12 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 12 Jul 2013 21:51:12 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 12 Jul 2013 21:51:05 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id D830D23888E2; Fri, 12 Jul 2013 21:50:42 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1502702 - in /accumulo/trunk: ./ maven-plugin/ maven-plugin/src/ maven-plugin/src/it/ maven-plugin/src/it/plugin-test/ maven-plugin/src/it/plugin-test/src/ maven-plugin/src/it/plugin-test/src/test/ maven-plugin/src/it/plugin-test/src/test/... Date: Fri, 12 Jul 2013 21:50:42 -0000 To: commits@accumulo.apache.org From: ctubbsii@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20130712215042.D830D23888E2@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: ctubbsii Date: Fri Jul 12 21:50:41 2013 New Revision: 1502702 URL: http://svn.apache.org/r1502702 Log: ACCUMULO-1030 First attempt at a working accumulo-maven-plugin Added: accumulo/trunk/maven-plugin/ (with props) accumulo/trunk/maven-plugin/pom.xml accumulo/trunk/maven-plugin/src/ accumulo/trunk/maven-plugin/src/it/ accumulo/trunk/maven-plugin/src/it/plugin-test/ accumulo/trunk/maven-plugin/src/it/plugin-test/pom.xml accumulo/trunk/maven-plugin/src/it/plugin-test/postbuild.groovy accumulo/trunk/maven-plugin/src/it/plugin-test/src/ accumulo/trunk/maven-plugin/src/it/plugin-test/src/test/ accumulo/trunk/maven-plugin/src/it/plugin-test/src/test/java/ accumulo/trunk/maven-plugin/src/it/plugin-test/src/test/java/org/ accumulo/trunk/maven-plugin/src/it/plugin-test/src/test/java/org/apache/ accumulo/trunk/maven-plugin/src/it/plugin-test/src/test/java/org/apache/accumulo/ accumulo/trunk/maven-plugin/src/it/plugin-test/src/test/java/org/apache/accumulo/plugin/ accumulo/trunk/maven-plugin/src/it/plugin-test/src/test/java/org/apache/accumulo/plugin/PluginIT.java accumulo/trunk/maven-plugin/src/it/settings.xml accumulo/trunk/maven-plugin/src/main/ accumulo/trunk/maven-plugin/src/main/java/ accumulo/trunk/maven-plugin/src/main/java/org/ accumulo/trunk/maven-plugin/src/main/java/org/accumulo/ accumulo/trunk/maven-plugin/src/main/java/org/accumulo/maven/ accumulo/trunk/maven-plugin/src/main/java/org/accumulo/maven/plugin/ accumulo/trunk/maven-plugin/src/main/java/org/accumulo/maven/plugin/AbstractAccumuloMojo.java accumulo/trunk/maven-plugin/src/main/java/org/accumulo/maven/plugin/StartMojo.java accumulo/trunk/maven-plugin/src/main/java/org/accumulo/maven/plugin/StopMojo.java accumulo/trunk/minicluster/src/main/java/org/apache/accumulo/minicluster/MiniAccumuloInstance.java Modified: accumulo/trunk/minicluster/src/main/java/org/apache/accumulo/minicluster/MiniAccumuloCluster.java accumulo/trunk/pom.xml Propchange: accumulo/trunk/maven-plugin/ ------------------------------------------------------------------------------ --- svn:ignore (added) +++ svn:ignore Fri Jul 12 21:50:41 2013 @@ -0,0 +1,3 @@ +.* +target +accumulo-maven-plugin.iml Added: accumulo/trunk/maven-plugin/pom.xml URL: http://svn.apache.org/viewvc/accumulo/trunk/maven-plugin/pom.xml?rev=1502702&view=auto ============================================================================== --- accumulo/trunk/maven-plugin/pom.xml (added) +++ accumulo/trunk/maven-plugin/pom.xml Fri Jul 12 21:50:41 2013 @@ -0,0 +1,163 @@ + + + + 4.0.0 + + org.apache.accumulo + accumulo-project + 1.6.0-SNAPSHOT + + accumulo-maven-plugin + maven-plugin + Accumulo Maven Plugin + + + commons-cli + commons-cli + + + commons-codec + commons-codec + + + commons-collections + commons-collections + + + commons-configuration + commons-configuration + + + commons-httpclient + commons-httpclient + + + commons-io + commons-io + + + commons-lang + commons-lang + + + commons-logging + commons-logging + + + log4j + log4j + + + org.apache.accumulo + accumulo-minicluster + + + org.apache.hadoop + hadoop-client + + + org.apache.maven + maven-plugin-api + + + org.apache.maven.plugin-tools + maven-plugin-annotations + + + org.apache.zookeeper + zookeeper + + + org.codehaus.plexus + plexus-utils + + + org.slf4j + slf4j-api + + + org.slf4j + slf4j-log4j12 + + + + + + org.apache.maven.plugins + maven-plugin-plugin + + true + + + + mojo-descriptor + + descriptor + + + + help-goal + + helpmojo + + + + + + + + + test-accumulo-maven-plugin + + + !skipITs + + + + + + org.apache.maven.plugins + maven-invoker-plugin + + true + ${project.build.directory}/it + + */pom.xml + + ${project.build.directory}/local-repo + src/it/settings.xml + + clean + post-integration-test + + + + + integration-test + + install + run + + + + + + + + + Added: accumulo/trunk/maven-plugin/src/it/plugin-test/pom.xml URL: http://svn.apache.org/viewvc/accumulo/trunk/maven-plugin/src/it/plugin-test/pom.xml?rev=1502702&view=auto ============================================================================== --- accumulo/trunk/maven-plugin/src/it/plugin-test/pom.xml (added) +++ accumulo/trunk/maven-plugin/src/it/plugin-test/pom.xml Fri Jul 12 21:50:41 2013 @@ -0,0 +1,117 @@ + + + + 4.0.0 + + + @project.groupId@ + accumulo-project + @project.version@ + + + @project.groupId@ + @project.artifactId@-test + @project.version@ + + A simple IT verifying the basic use case. + + + UTF-8 + + + + + commons-cli + commons-cli + + + commons-codec + commons-codec + + + commons-collections + commons-collections + + + commons-configuration + commons-configuration + + + commons-httpclient + commons-httpclient + + + commons-io + commons-io + + + commons-lang + commons-lang + + + commons-logging + commons-logging + + + log4j + log4j + + + org.apache.accumulo + accumulo-minicluster + + + org.apache.hadoop + hadoop-client + + + org.apache.zookeeper + zookeeper + + + org.slf4j + slf4j-api + + + org.slf4j + slf4j-log4j12 + + + + + + @project.groupId@ + @project.artifactId@ + @project.version@ + + plugin-it-instance + ITSecret + + + + run-plugin + + start + stop + + + + + + + Added: accumulo/trunk/maven-plugin/src/it/plugin-test/postbuild.groovy URL: http://svn.apache.org/viewvc/accumulo/trunk/maven-plugin/src/it/plugin-test/postbuild.groovy?rev=1502702&view=auto ============================================================================== --- accumulo/trunk/maven-plugin/src/it/plugin-test/postbuild.groovy (added) +++ accumulo/trunk/maven-plugin/src/it/plugin-test/postbuild.groovy Fri Jul 12 21:50:41 2013 @@ -0,0 +1,24 @@ +/* + * 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. + */ +File outputDirectory = new File(basedir, "target/accumulo-maven-plugin/plugin-it-instance"); +assert outputDirectory.isDirectory() + +File testCreateTable = new File(basedir, "target/accumulo-maven-plugin/plugin-it-instance/testCreateTablePassed"); +assert testCreateTable.isFile() + +File testWriteToTable = new File(basedir, "target/accumulo-maven-plugin/plugin-it-instance/testWriteToTablePassed"); +assert testWriteToTable.isFile() Added: accumulo/trunk/maven-plugin/src/it/plugin-test/src/test/java/org/apache/accumulo/plugin/PluginIT.java URL: http://svn.apache.org/viewvc/accumulo/trunk/maven-plugin/src/it/plugin-test/src/test/java/org/apache/accumulo/plugin/PluginIT.java?rev=1502702&view=auto ============================================================================== --- accumulo/trunk/maven-plugin/src/it/plugin-test/src/test/java/org/apache/accumulo/plugin/PluginIT.java (added) +++ accumulo/trunk/maven-plugin/src/it/plugin-test/src/test/java/org/apache/accumulo/plugin/PluginIT.java Fri Jul 12 21:50:41 2013 @@ -0,0 +1,98 @@ +/* + * 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.accumulo.plugin; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.io.File; +import java.io.IOException; +import java.util.Map.Entry; + +import org.apache.accumulo.core.client.AccumuloException; +import org.apache.accumulo.core.client.AccumuloSecurityException; +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.TableExistsException; +import org.apache.accumulo.core.client.TableNotFoundException; +import org.apache.accumulo.core.client.security.tokens.PasswordToken; +import org.apache.accumulo.core.data.Key; +import org.apache.accumulo.core.data.Mutation; +import org.apache.accumulo.core.data.Value; +import org.apache.accumulo.core.security.Authorizations; +import org.apache.accumulo.minicluster.MiniAccumuloInstance; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +public class PluginIT { + + private static Instance instance; + private static Connector connector; + + @BeforeClass + public static void setUp() throws Exception { + String instanceName = "plugin-it-instance"; + instance = new MiniAccumuloInstance(instanceName, new File("target/accumulo-maven-plugin/" + instanceName)); + connector = instance.getConnector("root", new PasswordToken("ITSecret")); + } + + @Test + public void testInstanceConnection() { + assertTrue(instance != null); + assertTrue(instance instanceof MiniAccumuloInstance); + assertTrue(connector != null); + assertTrue(connector instanceof Connector); + } + + @Test + public void testCreateTable() throws AccumuloException, AccumuloSecurityException, TableExistsException, IOException { + String tableName = "testCreateTable"; + connector.tableOperations().create(tableName); + assertTrue(connector.tableOperations().exists(tableName)); + assertTrue(new File("target/accumulo-maven-plugin/" + instance.getInstanceName() + "/testCreateTablePassed").createNewFile()); + } + + @Test + public void writeToTable() throws AccumuloException, AccumuloSecurityException, TableExistsException, TableNotFoundException, IOException { + String tableName = "writeToTable"; + connector.tableOperations().create(tableName); + BatchWriter bw = connector.createBatchWriter(tableName, new BatchWriterConfig()); + Mutation m = new Mutation("ROW"); + m.put("CF", "CQ", "V"); + bw.addMutation(m); + bw.close(); + Scanner scanner = connector.createScanner(tableName, Authorizations.EMPTY); + int count = 0; + for (Entry entry : scanner) { + count++; + assertEquals("ROW", entry.getKey().getRow().toString()); + assertEquals("CF", entry.getKey().getColumnFamily().toString()); + assertEquals("CQ", entry.getKey().getColumnQualifier().toString()); + assertEquals("V", entry.getValue().toString()); + } + assertEquals(1, count); + assertTrue(new File("target/accumulo-maven-plugin/" + instance.getInstanceName() + "/testWriteToTablePassed").createNewFile()); + } + + @AfterClass + public static void tearDown() throws Exception {} + +} Added: accumulo/trunk/maven-plugin/src/it/settings.xml URL: http://svn.apache.org/viewvc/accumulo/trunk/maven-plugin/src/it/settings.xml?rev=1502702&view=auto ============================================================================== --- accumulo/trunk/maven-plugin/src/it/settings.xml (added) +++ accumulo/trunk/maven-plugin/src/it/settings.xml Fri Jul 12 21:50:41 2013 @@ -0,0 +1,55 @@ + + + + + + + + it-repo + + true + + + + local.central + @localRepositoryUrl@ + + true + + + true + + + + + + local.central + @localRepositoryUrl@ + + true + + + true + + + + + + Added: accumulo/trunk/maven-plugin/src/main/java/org/accumulo/maven/plugin/AbstractAccumuloMojo.java URL: http://svn.apache.org/viewvc/accumulo/trunk/maven-plugin/src/main/java/org/accumulo/maven/plugin/AbstractAccumuloMojo.java?rev=1502702&view=auto ============================================================================== --- accumulo/trunk/maven-plugin/src/main/java/org/accumulo/maven/plugin/AbstractAccumuloMojo.java (added) +++ accumulo/trunk/maven-plugin/src/main/java/org/accumulo/maven/plugin/AbstractAccumuloMojo.java Fri Jul 12 21:50:41 2013 @@ -0,0 +1,42 @@ +/* + * 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.accumulo.maven.plugin; + +import java.io.File; +import java.net.MalformedURLException; +import java.util.List; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugins.annotations.Parameter; + +public abstract class AbstractAccumuloMojo extends AbstractMojo { + + @Parameter(defaultValue = "${plugin.artifacts}", readonly = true, required = true) + private List pluginArtifacts; + + void configureMiniClasspath() { + for (Artifact artifact : pluginArtifacts) { + try { + System.setProperty("java.class.path", System.getProperty("java.class.path", "") + File.pathSeparator + artifact.getFile().toURI().toURL()); + } catch (MalformedURLException e) { + e.printStackTrace(); + } + } + + } +} Added: accumulo/trunk/maven-plugin/src/main/java/org/accumulo/maven/plugin/StartMojo.java URL: http://svn.apache.org/viewvc/accumulo/trunk/maven-plugin/src/main/java/org/accumulo/maven/plugin/StartMojo.java?rev=1502702&view=auto ============================================================================== --- accumulo/trunk/maven-plugin/src/main/java/org/accumulo/maven/plugin/StartMojo.java (added) +++ accumulo/trunk/maven-plugin/src/main/java/org/accumulo/maven/plugin/StartMojo.java Fri Jul 12 21:50:41 2013 @@ -0,0 +1,67 @@ +/* + * 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.accumulo.maven.plugin; + +import java.io.File; +import java.util.Collections; +import java.util.HashSet; +import java.util.Set; + +import org.apache.accumulo.minicluster.MiniAccumuloCluster; +import org.apache.accumulo.minicluster.MiniAccumuloConfig; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugins.annotations.LifecyclePhase; +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.Parameter; +import org.apache.maven.plugins.annotations.ResolutionScope; + +/** + * Goal which starts an instance of {@link MiniAccumuloCluster}. + */ +@Mojo(name = "start", defaultPhase = LifecyclePhase.PRE_INTEGRATION_TEST, requiresDependencyResolution = ResolutionScope.TEST) +public class StartMojo extends AbstractAccumuloMojo { + + @Parameter(defaultValue = "${project.build.directory}", property = "outputDir", required = true) + private File outputDirectory; + + @Parameter(defaultValue = "testInstance", property = "instanceName", required = true) + private String instanceName; + + @Parameter(defaultValue = "secret", property = "rootPassword", required = true) + private String rootPassword = "secret"; + + static Set runningClusters = Collections.synchronizedSet(new HashSet()); + + @Override + public void execute() throws MojoExecutionException { + File subdir = new File(new File(outputDirectory, "accumulo-maven-plugin"), instanceName); + subdir.mkdirs(); + + try { + configureMiniClasspath(); + MiniAccumuloConfig cfg = new MiniAccumuloConfig(subdir, rootPassword); + cfg.setInstanceName(instanceName); + MiniAccumuloCluster mac = new MiniAccumuloCluster(cfg); + System.out.println("Starting MiniAccumuloCluster: " + mac.getInstanceName()); + mac.start(); + runningClusters.add(mac); + } catch (Exception e) { + throw new MojoExecutionException("Unable to start " + MiniAccumuloCluster.class.getSimpleName(), e); + } + + } +} Added: accumulo/trunk/maven-plugin/src/main/java/org/accumulo/maven/plugin/StopMojo.java URL: http://svn.apache.org/viewvc/accumulo/trunk/maven-plugin/src/main/java/org/accumulo/maven/plugin/StopMojo.java?rev=1502702&view=auto ============================================================================== --- accumulo/trunk/maven-plugin/src/main/java/org/accumulo/maven/plugin/StopMojo.java (added) +++ accumulo/trunk/maven-plugin/src/main/java/org/accumulo/maven/plugin/StopMojo.java Fri Jul 12 21:50:41 2013 @@ -0,0 +1,45 @@ +/* + * 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.accumulo.maven.plugin; + +import org.apache.accumulo.minicluster.MiniAccumuloCluster; +import org.apache.accumulo.minicluster.MiniAccumuloCluster.LogWriter; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugins.annotations.LifecyclePhase; +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.ResolutionScope; + +/** + * Goal which stops all instances of {@link MiniAccumuloCluster} started with the start mojo. + */ +@Mojo(name = "stop", defaultPhase = LifecyclePhase.POST_INTEGRATION_TEST, requiresDependencyResolution = ResolutionScope.TEST) +public class StopMojo extends AbstractAccumuloMojo { + + @Override + public void execute() throws MojoExecutionException { + for (MiniAccumuloCluster mac : StartMojo.runningClusters) { + System.out.println("Stopping MiniAccumuloCluster: " + mac.getInstanceName()); + try { + mac.stop(); + for (LogWriter log : mac.getLogWriters()) + log.flush(); + } catch (Exception e) { + throw new MojoExecutionException("Unable to start " + MiniAccumuloCluster.class.getSimpleName(), e); + } + } + } +} Modified: accumulo/trunk/minicluster/src/main/java/org/apache/accumulo/minicluster/MiniAccumuloCluster.java URL: http://svn.apache.org/viewvc/accumulo/trunk/minicluster/src/main/java/org/apache/accumulo/minicluster/MiniAccumuloCluster.java?rev=1502702&r1=1502701&r2=1502702&view=diff ============================================================================== --- accumulo/trunk/minicluster/src/main/java/org/apache/accumulo/minicluster/MiniAccumuloCluster.java (original) +++ accumulo/trunk/minicluster/src/main/java/org/apache/accumulo/minicluster/MiniAccumuloCluster.java Fri Jul 12 21:50:41 2013 @@ -58,7 +58,7 @@ import org.apache.zookeeper.server.ZooKe /** * A utility class that will create Zookeeper and Accumulo processes that write all of their data to a single local directory. This class makes it easy to test * code against a real Accumulo instance. Its much more accurate for testing than {@link org.apache.accumulo.core.client.mock.MockAccumulo}, but much slower. - * + * * @since 1.5.0 */ public class MiniAccumuloCluster { @@ -66,14 +66,11 @@ public class MiniAccumuloCluster { public static class LogWriter extends Daemon { private BufferedReader in; private BufferedWriter out; - - /** - * @throws IOException - */ + public LogWriter(InputStream stream, File logFile) throws IOException { this.in = new BufferedReader(new InputStreamReader(stream)); out = new BufferedWriter(new FileWriter(logFile)); - + SimpleTimer.getInstance().schedule(new Runnable() { @Override public void run() { @@ -85,75 +82,74 @@ public class MiniAccumuloCluster { } }, 1000, 1000); } - + public synchronized void flush() throws IOException { if (out != null) out.flush(); } - + @Override public void run() { String line; - + try { while ((line = in.readLine()) != null) { out.append(line); out.append("\n"); } - + synchronized (this) { out.close(); out = null; in.close(); } - + } catch (IOException e) {} } } - + private boolean initialized = false; private Process zooKeeperProcess = null; private Process masterProcess = null; private List tabletServerProcesses = new ArrayList(); - + private Set> debugPorts = new HashSet>(); - + private File zooCfgFile; - + public List getLogWriters() { return logWriters; } - - + private List logWriters = new ArrayList(); - + private MiniAccumuloConfig config; - + public Process exec(Class clazz, String... args) throws IOException { return exec(clazz, Collections.singletonList("-Xmx" + config.getDefaultMemory()), args); } - + private Process exec(Class clazz, List extraJvmOpts, String... args) throws IOException { String javaHome = System.getProperty("java.home"); String javaBin = javaHome + File.separator + "bin" + File.separator + "java"; String classpath = System.getProperty("java.class.path"); - + classpath = config.getConfDir().getAbsolutePath() + File.pathSeparator + classpath; - + String className = clazz.getCanonicalName(); - + ArrayList argList = new ArrayList(); argList.addAll(Arrays.asList(javaBin, "-Dproc=" + clazz.getSimpleName(), "-cp", classpath)); argList.add("-Djava.library.path=" + config.getLibDir()); argList.addAll(extraJvmOpts); argList.addAll(Arrays.asList("-XX:+UseConcMarkSweepGC", "-XX:CMSInitiatingOccupancyFraction=75", Main.class.getName(), className)); argList.addAll(Arrays.asList(args)); - + ProcessBuilder builder = new ProcessBuilder(argList); - + builder.environment().put("ACCUMULO_HOME", config.getDir().getAbsolutePath()); builder.environment().put("ACCUMULO_LOG_DIR", config.getLogDir().getAbsolutePath()); - + // if we're running under accumulo.start, we forward these env vars String env = System.getenv("HADOOP_PREFIX"); if (env != null) @@ -161,9 +157,9 @@ public class MiniAccumuloCluster { env = System.getenv("ZOOKEEPER_HOME"); if (env != null) builder.environment().put("ZOOKEEPER_HOME", env); - + Process process = builder.start(); - + LogWriter lw; lw = new LogWriter(process.getErrorStream(), new File(config.getLogDir(), clazz.getSimpleName() + "_" + process.hashCode() + ".err")); logWriters.add(lw); @@ -171,12 +167,12 @@ public class MiniAccumuloCluster { lw = new LogWriter(process.getInputStream(), new File(config.getLogDir(), clazz.getSimpleName() + "_" + process.hashCode() + ".out")); logWriters.add(lw); lw.start(); - + return process; } - + private Process exec(Class clazz, ServerType serverType, String... args) throws IOException { - + List jvmOpts = new ArrayList(); jvmOpts.add("-Xmx" + config.getMemory(serverType)); @@ -187,49 +183,47 @@ public class MiniAccumuloCluster { } return exec(clazz, jvmOpts, args); } - + /** - * + * * @param dir * An empty or nonexistant temp directoy that Accumulo and Zookeeper can store data in. Creating the directory is left to the user. Java 7, Guava, * and Junit provide methods for creating temporary directories. * @param rootPassword * Initial root password for instance. - * @throws IOException */ public MiniAccumuloCluster(File dir, String rootPassword) throws IOException { this(new MiniAccumuloConfig(dir, rootPassword)); } - + /** * @param config * initial configuration - * @throws IOException */ public MiniAccumuloCluster(MiniAccumuloConfig config) throws IOException { - + this.config = config.initialize(); - + config.getConfDir().mkdirs(); config.getAccumuloDir().mkdirs(); config.getZooKeeperDir().mkdirs(); config.getLogDir().mkdirs(); config.getWalogDir().mkdirs(); config.getLibDir().mkdirs(); - + File siteFile = new File(config.getConfDir(), "accumulo-site.xml"); - + FileWriter fileWriter = new FileWriter(siteFile); fileWriter.append("\n"); - + for (Entry entry : config.getSiteConfig().entrySet()) fileWriter.append("" + entry.getKey() + "" + entry.getValue() + "\n"); fileWriter.append("\n"); fileWriter.close(); - + zooCfgFile = new File(config.getConfDir(), "zoo.cfg"); fileWriter = new FileWriter(zooCfgFile); - + // zookeeper uses Properties to read its config, so use that to write in order to properly escape things like Windows paths Properties zooCfg = new Properties(); zooCfg.setProperty("tickTime", "1000"); @@ -239,9 +233,9 @@ public class MiniAccumuloCluster { zooCfg.setProperty("maxClientCnxns", "100"); zooCfg.setProperty("dataDir", config.getZooKeeperDir().getAbsolutePath()); zooCfg.store(fileWriter, null); - + fileWriter.close(); - + File nativeMap = new File(config.getLibDir().getAbsolutePath() + "/native/map"); nativeMap.mkdirs(); File testRoot = new File(new File(new File(System.getProperty("user.dir")).getParent() + "/server/src/main/c++/nativeMap").getAbsolutePath()); @@ -254,17 +248,15 @@ public class MiniAccumuloCluster { } } } - + /** * Starts Accumulo and Zookeeper processes. Can only be called once. - * - * @throws IOException - * @throws InterruptedException + * * @throws IllegalStateException * if already started */ public void start() throws IOException, InterruptedException { - + if (!initialized) { Runtime.getRuntime().addShutdownHook(new Thread() { @@ -280,22 +272,22 @@ public class MiniAccumuloCluster { } }); } - + if (zooKeeperProcess == null) { zooKeeperProcess = exec(Main.class, ServerType.ZOOKEEPER, ZooKeeperServerMain.class.getName(), zooCfgFile.getAbsolutePath()); // sleep a little bit to let zookeeper come up before calling init, seems to work better UtilWaitThread.sleep(250); } - + if (!initialized) { Process initProcess = exec(Initialize.class, "--instance-name", config.getInstanceName(), "--password", config.getRootPassword(), "--username", "root"); int ret = initProcess.waitFor(); if (ret != 0) { throw new RuntimeException("Initialize process returned " + ret); } - initialized = true; + initialized = true; } - + for (int i = tabletServerProcesses.size(); i < config.getNumTservers(); i++) { tabletServerProcesses.add(exec(TabletServer.class, ServerType.TABLET_SERVER)); } @@ -308,14 +300,13 @@ public class MiniAccumuloCluster { masterProcess = exec(Master.class, ServerType.MASTER); } } - + private List buildRemoteDebugParams(int port) { return Arrays.asList(new String[] {"-Xdebug", String.format("-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=%d", port)}); } - + /** * @return generated remote debug ports if in debug mode. - * * @since 1.6.0 */ public Set> getDebugPorts() { @@ -330,8 +321,8 @@ public class MiniAccumuloCluster { return result; } - public Map> getProcesses() { - Map> result = new HashMap>(); + public Map> getProcesses() { + Map> result = new HashMap>(); result.put(ServerType.MASTER, references(masterProcess)); result.put(ServerType.TABLET_SERVER, references(tabletServerProcesses.toArray(new Process[0]))); result.put(ServerType.ZOOKEEPER, references(zooKeeperProcess)); @@ -349,7 +340,7 @@ public class MiniAccumuloCluster { } break; case TABLET_SERVER: - for (Process tserver: tabletServerProcesses) { + for (Process tserver : tabletServerProcesses) { if (proc.equals(tserver)) { tabletServerProcesses.remove(tserver); found = true; @@ -368,27 +359,24 @@ public class MiniAccumuloCluster { if (!found) throw new ProcessNotFoundException(); } - + /** * @return Accumulo instance name */ public String getInstanceName() { return config.getInstanceName(); } - + /** * @return zookeeper connection string */ public String getZooKeepers() { return config.getZooKeepers(); } - + /** * Stops Accumulo and Zookeeper processes. If stop is not called, there is a shutdown hook that is setup to kill the processes. However its probably best to * call stop in a finally block as soon as possible. - * - * @throws IOException - * @throws InterruptedException */ public void stop() throws IOException, InterruptedException { if (zooKeeperProcess != null) @@ -400,29 +388,25 @@ public class MiniAccumuloCluster { tserver.destroy(); } } - + for (LogWriter lw : logWriters) lw.flush(); zooKeeperProcess = null; masterProcess = null; tabletServerProcesses.clear(); } - + /** * @since 1.6.0 */ public MiniAccumuloConfig getConfig() { return config; } - + /** * Utility method to get a connector to the MAC. + * * @since 1.6.0 - * @param user - * @param passwd - * @return Connector - * @throws AccumuloException - * @throws AccumuloSecurityException */ public Connector getConnector(String user, String passwd) throws AccumuloException, AccumuloSecurityException { Instance instance = new ZooKeeperInstance(this.getInstanceName(), this.getZooKeepers()); Added: accumulo/trunk/minicluster/src/main/java/org/apache/accumulo/minicluster/MiniAccumuloInstance.java URL: http://svn.apache.org/viewvc/accumulo/trunk/minicluster/src/main/java/org/apache/accumulo/minicluster/MiniAccumuloInstance.java?rev=1502702&view=auto ============================================================================== --- accumulo/trunk/minicluster/src/main/java/org/apache/accumulo/minicluster/MiniAccumuloInstance.java (added) +++ accumulo/trunk/minicluster/src/main/java/org/apache/accumulo/minicluster/MiniAccumuloInstance.java Fri Jul 12 21:50:41 2013 @@ -0,0 +1,51 @@ +/* + * 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.accumulo.minicluster; + +import java.io.File; +import java.net.MalformedURLException; + +import org.apache.accumulo.core.client.Instance; +import org.apache.accumulo.core.client.ZooKeeperInstance; +import org.apache.accumulo.core.conf.Property; +import org.apache.hadoop.conf.Configuration; + +/** + * + */ +public class MiniAccumuloInstance extends ZooKeeperInstance { + + /** + * Construct an {@link Instance} entry point to Accumulo using a {@link MiniAccumuloCluster} directory + */ + public MiniAccumuloInstance(String instanceName, File directory) { + super(instanceName, getZooKeepersFromDir(directory)); + } + + private static String getZooKeepersFromDir(File directory) { + if (!directory.isDirectory()) + throw new IllegalArgumentException("Not a directory " + directory.getPath()); + File configFile = new File(new File(directory, "conf"), "accumulo-site.xml"); + Configuration conf = new Configuration(false); + try { + conf.addResource(configFile.toURI().toURL()); + } catch (MalformedURLException e) { + throw new IllegalStateException("Missing file: " + configFile.getPath()); + } + return conf.get(Property.INSTANCE_ZK_HOST.getKey()); + } +} Modified: accumulo/trunk/pom.xml URL: http://svn.apache.org/viewvc/accumulo/trunk/pom.xml?rev=1502702&r1=1502701&r2=1502702&view=diff ============================================================================== --- accumulo/trunk/pom.xml (original) +++ accumulo/trunk/pom.xml Fri Jul 12 21:50:41 2013 @@ -83,6 +83,7 @@ test minicluster docs + maven-plugin scm:svn:http://svn.apache.org/repos/asf/accumulo/trunk @@ -297,6 +298,16 @@ ${hadoop.version} + org.apache.maven + maven-plugin-api + ${maven.min-version} + + + org.apache.maven.plugin-tools + maven-plugin-annotations + 3.2 + + org.apache.thrift libthrift 0.9.0 @@ -307,6 +318,11 @@ ${zookeeper.version} + org.codehaus.plexus + plexus-utils + 3.0.10 + + org.easymock easymock 3.1 @@ -571,6 +587,19 @@ + org.apache.maven.plugins + maven-invoker-plugin + [1.7,) + + install + + + + + + + + com.google.code.sortpom maven-sortpom-plugin [2.1.0,) @@ -630,18 +659,11 @@ run-integration-tests integration-test - - integration-test - - true - - - - verify-integration-tests - verify - verify + + true + @@ -839,6 +861,7 @@ seal-jars true + true true