accumulo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ctubb...@apache.org
Subject [43/50] [abbrv] git commit: ACCUMULO-1496 Use classloader to locate annotated launchable classes
Date Wed, 17 Jul 2013 02:33:45 GMT
ACCUMULO-1496 Use classloader to locate annotated launchable classes

git-svn-id: https://svn.apache.org/repos/asf/accumulo/branches/ACCUMULO-1496@1491605 13f79535-47bb-0310-9956-ffa450edef68


Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo
Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/dd0b97e5
Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/dd0b97e5
Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/dd0b97e5

Branch: refs/heads/ACCUMULO-1496
Commit: dd0b97e5c8a1c00e0e309694a3a6242afc0c8870
Parents: db39c35
Author: Christopher Tubbs <ctubbsii@apache.org>
Authored: Mon Jun 10 21:23:30 2013 +0000
Committer: Christopher Tubbs <ctubbsii@apache.org>
Committed: Tue Jul 16 15:01:47 2013 -0400

----------------------------------------------------------------------
 api/pom.xml                                     |  27 +++++
 .../api/annotations/AccumuloService.java        |  33 ++++++
 assemble/pom.xml                                |  12 +++
 assemble/src/main/assemblies/component.xml      |   2 +
 bin/accumulo                                    |   5 +-
 .../accumulo/core/file/rfile/PrintInfo.java     |   4 +-
 .../apache/accumulo/core/util/CreateToken.java  |   2 +
 .../apache/accumulo/core/util/shell/Shell.java  |   2 +
 .../minicluster/MiniAccumuloRunner.java         |   2 +
 pom.xml                                         |  16 +++
 .../java/org/apache/accumulo/proxy/Proxy.java   |   7 +-
 .../server/gc/SimpleGarbageCollector.java       |   2 +
 .../apache/accumulo/server/master/Master.java   |   2 +
 .../apache/accumulo/server/monitor/Monitor.java |   3 +
 .../server/tabletserver/TabletServer.java       |   2 +
 .../accumulo/server/trace/TraceServer.java      |   6 +-
 .../org/apache/accumulo/server/util/Admin.java  |   3 +
 .../apache/accumulo/server/util/Initialize.java |   2 +
 .../accumulo/server/util/ZooKeeperMain.java     |   3 +
 start/pom.xml                                   |  12 +++
 .../java/org/apache/accumulo/start/Main.java    | 106 +++++++++++--------
 .../classloader/vfs/AccumuloVFSClassLoader.java |  25 ++++-
 22 files changed, 226 insertions(+), 52 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/accumulo/blob/dd0b97e5/api/pom.xml
----------------------------------------------------------------------
diff --git a/api/pom.xml b/api/pom.xml
new file mode 100644
index 0000000..9fe5f60
--- /dev/null
+++ b/api/pom.xml
@@ -0,0 +1,27 @@
+<?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>
+  <parent>
+    <groupId>org.apache.accumulo</groupId>
+    <artifactId>accumulo-project</artifactId>
+    <version>1.6.0-SNAPSHOT</version>
+  </parent>
+  <artifactId>accumulo-api</artifactId>
+  <name>API</name>
+</project>

http://git-wip-us.apache.org/repos/asf/accumulo/blob/dd0b97e5/api/src/main/java/org/apache/accumulo/api/annotations/AccumuloService.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/accumulo/api/annotations/AccumuloService.java b/api/src/main/java/org/apache/accumulo/api/annotations/AccumuloService.java
new file mode 100644
index 0000000..31fbc67
--- /dev/null
+++ b/api/src/main/java/org/apache/accumulo/api/annotations/AccumuloService.java
@@ -0,0 +1,33 @@
+/*
+ * 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.api.annotations;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Annotation to describe a class that can be launched by Accumulo
+ * 
+ * @since 1.6.0
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.TYPE)
+public @interface AccumuloService {
+  String value();
+}

http://git-wip-us.apache.org/repos/asf/accumulo/blob/dd0b97e5/assemble/pom.xml
----------------------------------------------------------------------
diff --git a/assemble/pom.xml b/assemble/pom.xml
index db40b65..7584510 100644
--- a/assemble/pom.xml
+++ b/assemble/pom.xml
@@ -47,6 +47,14 @@
       <artifactId>jline</artifactId>
     </dependency>
     <dependency>
+      <groupId>net.sf.scannotation</groupId>
+      <artifactId>scannotation</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.accumulo</groupId>
+      <artifactId>accumulo-api</artifactId>
+    </dependency>
+    <dependency>
       <groupId>org.apache.accumulo</groupId>
       <artifactId>accumulo-core</artifactId>
     </dependency>
@@ -90,6 +98,10 @@
       <groupId>org.apache.thrift</groupId>
       <artifactId>libthrift</artifactId>
     </dependency>
+    <dependency>
+      <groupId>org.javassist</groupId>
+      <artifactId>javassist</artifactId>
+    </dependency>
   </dependencies>
   <profiles>
     <profile>

http://git-wip-us.apache.org/repos/asf/accumulo/blob/dd0b97e5/assemble/src/main/assemblies/component.xml
----------------------------------------------------------------------
diff --git a/assemble/src/main/assemblies/component.xml b/assemble/src/main/assemblies/component.xml
index 3655a22..c366c41 100644
--- a/assemble/src/main/assemblies/component.xml
+++ b/assemble/src/main/assemblies/component.xml
@@ -32,7 +32,9 @@
         <include>com.google.code.gson:gson</include>
         <include>com.google.guava:guava</include>
         <include>jline:jline</include>
+        <include>net.sf.scannotation:scannotation</include>
         <include>org.apache.thrift:libthrift</include>
+        <include>org.javassist:javassist</include>
       </includes>
       <excludes>
         <exclude>${groupId}:${artifactId}-docs</exclude>

http://git-wip-us.apache.org/repos/asf/accumulo/blob/dd0b97e5/bin/accumulo
----------------------------------------------------------------------
diff --git a/bin/accumulo b/bin/accumulo
index dcbdbae..a3b0a21 100755
--- a/bin/accumulo
+++ b/bin/accumulo
@@ -29,6 +29,9 @@ script=$( basename "$SOURCE" )
 . "$bin"/config.sh
 
 START_JAR=$ACCUMULO_HOME/lib/accumulo-start.jar
+API_JAR=$ACCUMULO_HOME/lib/accumulo-api.jar
+SCANNOTATION_JAR=$ACCUMULO_HOME/lib/scannotation.jar
+JAVASSIST_JAR=$ACCUMULO_HOME/lib/javassist.jar
 
 #
 # Resolve a program to its installation directory
@@ -81,7 +84,7 @@ esac
 
 XML_FILES=${ACCUMULO_HOME}/conf
 LOG4J_JAR=$(find $HADOOP_PREFIX/lib $HADOOP_PREFIX/share/hadoop/common/lib -name 'log4j*.jar'
-print 2>/dev/null | head -1)
-CLASSPATH=${XML_FILES}:${START_JAR}:${LOG4J_JAR}
+CLASSPATH=${XML_FILES}:${API_JAR}:${JAVASSIST_JAR}:${SCANNOTATION_JAR}:${START_JAR}:${LOG4J_JAR}
 
 if [ -z "$JAVA_HOME" -o ! -d "$JAVA_HOME" ]; then
    echo "JAVA_HOME is not set or is not a directory.  Please make sure it's set globally
or in conf/accumulo-env.sh"

http://git-wip-us.apache.org/repos/asf/accumulo/blob/dd0b97e5/core/src/main/java/org/apache/accumulo/core/file/rfile/PrintInfo.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/file/rfile/PrintInfo.java b/core/src/main/java/org/apache/accumulo/core/file/rfile/PrintInfo.java
index e591403..2f06474 100644
--- a/core/src/main/java/org/apache/accumulo/core/file/rfile/PrintInfo.java
+++ b/core/src/main/java/org/apache/accumulo/core/file/rfile/PrintInfo.java
@@ -19,6 +19,7 @@ package org.apache.accumulo.core.file.rfile;
 import java.util.ArrayList;
 import java.util.List;
 
+import org.apache.accumulo.api.annotations.AccumuloService;
 import org.apache.accumulo.core.cli.Help;
 import org.apache.accumulo.core.conf.AccumuloConfiguration;
 import org.apache.accumulo.core.data.ByteSequence;
@@ -34,6 +35,7 @@ import org.apache.hadoop.fs.Path;
 
 import com.beust.jcommander.Parameter;
 
+@AccumuloService("rfile-info")
 public class PrintInfo {
   
   static class Opts extends Help {
@@ -49,7 +51,7 @@ public class PrintInfo {
     Configuration conf = new Configuration();
     @SuppressWarnings("deprecation")
     FileSystem hadoopFs = FileUtil.getFileSystem(conf, AccumuloConfiguration.getSiteConfiguration());
-    FileSystem localFs  = FileSystem.getLocal(conf);
+    FileSystem localFs = FileSystem.getLocal(conf);
     Opts opts = new Opts();
     opts.parseArgs(PrintInfo.class.getName(), args);
     if (opts.files.isEmpty()) {

http://git-wip-us.apache.org/repos/asf/accumulo/blob/dd0b97e5/core/src/main/java/org/apache/accumulo/core/util/CreateToken.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/util/CreateToken.java b/core/src/main/java/org/apache/accumulo/core/util/CreateToken.java
index d8e6d94..5b25424 100644
--- a/core/src/main/java/org/apache/accumulo/core/util/CreateToken.java
+++ b/core/src/main/java/org/apache/accumulo/core/util/CreateToken.java
@@ -23,6 +23,7 @@ import java.io.PrintStream;
 
 import jline.console.ConsoleReader;
 
+import org.apache.accumulo.api.annotations.AccumuloService;
 import org.apache.accumulo.core.Constants;
 import org.apache.accumulo.core.cli.ClientOpts.Password;
 import org.apache.accumulo.core.cli.ClientOpts.PasswordConverter;
@@ -35,6 +36,7 @@ import org.apache.accumulo.core.security.CredentialHelper;
 
 import com.beust.jcommander.Parameter;
 
+@AccumuloService("create-token")
 public class CreateToken {
   
   private static ConsoleReader reader = null;

http://git-wip-us.apache.org/repos/asf/accumulo/blob/dd0b97e5/core/src/main/java/org/apache/accumulo/core/util/shell/Shell.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/util/shell/Shell.java b/core/src/main/java/org/apache/accumulo/core/util/shell/Shell.java
index ef3e519..129fff7 100644
--- a/core/src/main/java/org/apache/accumulo/core/util/shell/Shell.java
+++ b/core/src/main/java/org/apache/accumulo/core/util/shell/Shell.java
@@ -37,6 +37,7 @@ import java.util.UUID;
 import jline.console.ConsoleReader;
 import jline.console.history.FileHistory;
 
+import org.apache.accumulo.api.annotations.AccumuloService;
 import org.apache.accumulo.core.Constants;
 import org.apache.accumulo.core.client.AccumuloException;
 import org.apache.accumulo.core.client.AccumuloSecurityException;
@@ -158,6 +159,7 @@ import com.beust.jcommander.ParameterException;
 /**
  * A convenient console interface to perform basic accumulo functions Includes auto-complete,
help, and quoted strings with escape sequences
  */
+@AccumuloService("shell")
 public class Shell extends ShellOptions {
   public static final Logger log = Logger.getLogger(Shell.class);
   private static final Logger audit = Logger.getLogger(Shell.class.getName() + ".audit");

http://git-wip-us.apache.org/repos/asf/accumulo/blob/dd0b97e5/minicluster/src/main/java/org/apache/accumulo/minicluster/MiniAccumuloRunner.java
----------------------------------------------------------------------
diff --git a/minicluster/src/main/java/org/apache/accumulo/minicluster/MiniAccumuloRunner.java
b/minicluster/src/main/java/org/apache/accumulo/minicluster/MiniAccumuloRunner.java
index 1402b53..d3b2f94 100644
--- a/minicluster/src/main/java/org/apache/accumulo/minicluster/MiniAccumuloRunner.java
+++ b/minicluster/src/main/java/org/apache/accumulo/minicluster/MiniAccumuloRunner.java
@@ -27,6 +27,7 @@ import java.util.Map;
 import java.util.Properties;
 import java.util.regex.Pattern;
 
+import org.apache.accumulo.api.annotations.AccumuloService;
 import org.apache.accumulo.core.cli.Help;
 import org.apache.accumulo.core.util.Pair;
 import org.apache.commons.io.FileUtils;
@@ -58,6 +59,7 @@ import com.google.common.io.Files;
  * 
  * @since 1.6.0
  */
+@AccumuloService("minicluster")
 public class MiniAccumuloRunner {
   public static class PropertiesConverter implements IStringConverter<Properties> {
     @Override

http://git-wip-us.apache.org/repos/asf/accumulo/blob/dd0b97e5/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 905e4e7..6d6539c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -72,6 +72,7 @@
     <maven>${maven.min-version}</maven>
   </prerequisites>
   <modules>
+    <module>api</module>
     <module>trace</module>
     <module>core</module>
     <module>fate</module>
@@ -206,6 +207,16 @@
         <version>1.2.16</version>
       </dependency>
       <dependency>
+        <groupId>net.sf.scannotation</groupId>
+        <artifactId>scannotation</artifactId>
+        <version>1.0.2</version>
+      </dependency>
+      <dependency>
+        <groupId>org.apache.accumulo</groupId>
+        <artifactId>accumulo-api</artifactId>
+        <version>${project.version}</version>
+      </dependency>
+      <dependency>
         <groupId>org.apache.accumulo</groupId>
         <artifactId>accumulo-core</artifactId>
         <version>${project.version}</version>
@@ -328,6 +339,11 @@
         <version>3.1</version>
       </dependency>
       <dependency>
+        <groupId>org.javassist</groupId>
+        <artifactId>javassist</artifactId>
+        <version>3.17.1-GA</version>
+      </dependency>
+      <dependency>
         <groupId>org.mortbay.jetty</groupId>
         <artifactId>jetty</artifactId>
         <version>6.1.26</version>

http://git-wip-us.apache.org/repos/asf/accumulo/blob/dd0b97e5/proxy/src/main/java/org/apache/accumulo/proxy/Proxy.java
----------------------------------------------------------------------
diff --git a/proxy/src/main/java/org/apache/accumulo/proxy/Proxy.java b/proxy/src/main/java/org/apache/accumulo/proxy/Proxy.java
index 72231f0..9552456 100644
--- a/proxy/src/main/java/org/apache/accumulo/proxy/Proxy.java
+++ b/proxy/src/main/java/org/apache/accumulo/proxy/Proxy.java
@@ -23,6 +23,7 @@ import java.io.InputStream;
 import java.lang.reflect.Constructor;
 import java.util.Properties;
 
+import org.apache.accumulo.api.annotations.AccumuloService;
 import org.apache.accumulo.core.cli.Help;
 import org.apache.accumulo.core.conf.AccumuloConfiguration;
 import org.apache.accumulo.minicluster.MiniAccumuloCluster;
@@ -40,6 +41,7 @@ import com.beust.jcommander.IStringConverter;
 import com.beust.jcommander.Parameter;
 import com.google.common.io.Files;
 
+@AccumuloService("proxy")
 public class Proxy {
   
   private static final Logger log = Logger.getLogger(Proxy.class);
@@ -100,6 +102,7 @@ public class Proxy {
       opts.prop.setProperty("instance", accumulo.getConfig().getInstanceName());
       opts.prop.setProperty("zookeepers", accumulo.getConfig().getZooKeepers());
       Runtime.getRuntime().addShutdownHook(new Thread() {
+        @Override
         public void start() {
           try {
             accumulo.stop();
@@ -128,7 +131,7 @@ public class Proxy {
     
     Class<?> proxyProcClass = Class.forName(api.getName() + "$Processor");
     Class<?> proxyIfaceClass = Class.forName(api.getName() + "$Iface");
-
+    
     @SuppressWarnings("unchecked")
     Constructor<? extends TProcessor> proxyProcConstructor = (Constructor<? extends
TProcessor>) proxyProcClass.getConstructor(proxyIfaceClass);
     
@@ -139,7 +142,7 @@ public class Proxy {
     final long maxFrameSize = AccumuloConfiguration.getMemoryInBytes(properties.getProperty("maxFrameSize",
"16M"));
     if (maxFrameSize > Integer.MAX_VALUE)
       throw new RuntimeException(maxFrameSize + " is larger than MAX_INT");
-    args.transportFactory(new TFramedTransport.Factory((int)maxFrameSize));
+    args.transportFactory(new TFramedTransport.Factory((int) maxFrameSize));
     args.protocolFactory(protoClass.newInstance());
     return new THsHaServer(args);
   }

http://git-wip-us.apache.org/repos/asf/accumulo/blob/dd0b97e5/server/src/main/java/org/apache/accumulo/server/gc/SimpleGarbageCollector.java
----------------------------------------------------------------------
diff --git a/server/src/main/java/org/apache/accumulo/server/gc/SimpleGarbageCollector.java
b/server/src/main/java/org/apache/accumulo/server/gc/SimpleGarbageCollector.java
index f18e5bc..864717f 100644
--- a/server/src/main/java/org/apache/accumulo/server/gc/SimpleGarbageCollector.java
+++ b/server/src/main/java/org/apache/accumulo/server/gc/SimpleGarbageCollector.java
@@ -36,6 +36,7 @@ import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 import java.util.concurrent.TimeUnit;
 
+import org.apache.accumulo.api.annotations.AccumuloService;
 import org.apache.accumulo.core.Constants;
 import org.apache.accumulo.core.cli.Help;
 import org.apache.accumulo.core.client.AccumuloException;
@@ -104,6 +105,7 @@ import org.apache.zookeeper.KeeperException;
 
 import com.beust.jcommander.Parameter;
 
+@AccumuloService("gc")
 public class SimpleGarbageCollector implements Iface {
   private static final Text EMPTY_TEXT = new Text();
   

http://git-wip-us.apache.org/repos/asf/accumulo/blob/dd0b97e5/server/src/main/java/org/apache/accumulo/server/master/Master.java
----------------------------------------------------------------------
diff --git a/server/src/main/java/org/apache/accumulo/server/master/Master.java b/server/src/main/java/org/apache/accumulo/server/master/Master.java
index b5ffd0a..fa8a7e5 100644
--- a/server/src/main/java/org/apache/accumulo/server/master/Master.java
+++ b/server/src/main/java/org/apache/accumulo/server/master/Master.java
@@ -34,6 +34,7 @@ import java.util.TreeMap;
 import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.concurrent.atomic.AtomicInteger;
 
+import org.apache.accumulo.api.annotations.AccumuloService;
 import org.apache.accumulo.core.Constants;
 import org.apache.accumulo.core.client.AccumuloException;
 import org.apache.accumulo.core.client.AccumuloSecurityException;
@@ -163,6 +164,7 @@ import org.apache.zookeeper.data.Stat;
  * 
  * The master will also coordinate log recoveries and reports general status.
  */
+@AccumuloService("master")
 public class Master implements LiveTServerSet.Listener, TableObserver, CurrentState {
   
   final static Logger log = Logger.getLogger(Master.class);

http://git-wip-us.apache.org/repos/asf/accumulo/blob/dd0b97e5/server/src/main/java/org/apache/accumulo/server/monitor/Monitor.java
----------------------------------------------------------------------
diff --git a/server/src/main/java/org/apache/accumulo/server/monitor/Monitor.java b/server/src/main/java/org/apache/accumulo/server/monitor/Monitor.java
index 56e473a..6069f64 100644
--- a/server/src/main/java/org/apache/accumulo/server/monitor/Monitor.java
+++ b/server/src/main/java/org/apache/accumulo/server/monitor/Monitor.java
@@ -27,6 +27,7 @@ import java.util.Map;
 import java.util.Map.Entry;
 import java.util.Set;
 
+import org.apache.accumulo.api.annotations.AccumuloService;
 import org.apache.accumulo.core.Constants;
 import org.apache.accumulo.core.client.Instance;
 import org.apache.accumulo.core.client.impl.MasterClient;
@@ -73,6 +74,7 @@ import org.apache.accumulo.server.problems.ProblemType;
 import org.apache.accumulo.server.security.SecurityConstants;
 import org.apache.accumulo.server.util.EmbeddedWebServer;
 import org.apache.accumulo.trace.instrument.Tracer;
+import org.apache.hadoop.fs.FileSystem;
 import org.apache.log4j.Logger;
 import org.apache.zookeeper.WatchedEvent;
 import org.apache.zookeeper.Watcher;
@@ -81,6 +83,7 @@ import org.apache.zookeeper.ZooKeeper;
 /**
  * Serve master statistics with an embedded web server.
  */
+@AccumuloService("monitor")
 public class Monitor {
   private static final Logger log = Logger.getLogger(Monitor.class);
   

http://git-wip-us.apache.org/repos/asf/accumulo/blob/dd0b97e5/server/src/main/java/org/apache/accumulo/server/tabletserver/TabletServer.java
----------------------------------------------------------------------
diff --git a/server/src/main/java/org/apache/accumulo/server/tabletserver/TabletServer.java
b/server/src/main/java/org/apache/accumulo/server/tabletserver/TabletServer.java
index 9d50f07..9ddf6bb 100644
--- a/server/src/main/java/org/apache/accumulo/server/tabletserver/TabletServer.java
+++ b/server/src/main/java/org/apache/accumulo/server/tabletserver/TabletServer.java
@@ -62,6 +62,7 @@ import java.util.concurrent.atomic.AtomicReference;
 import javax.management.ObjectName;
 import javax.management.StandardMBean;
 
+import org.apache.accumulo.api.annotations.AccumuloService;
 import org.apache.accumulo.core.Constants;
 import org.apache.accumulo.core.client.AccumuloException;
 import org.apache.accumulo.core.client.AccumuloSecurityException;
@@ -220,6 +221,7 @@ enum ScanRunState {
   QUEUED, RUNNING, FINISHED
 }
 
+@AccumuloService("tserver")
 public class TabletServer extends AbstractMetricsImpl implements org.apache.accumulo.server.tabletserver.metrics.TabletServerMBean
{
   private static final Logger log = Logger.getLogger(TabletServer.class);
   

http://git-wip-us.apache.org/repos/asf/accumulo/blob/dd0b97e5/server/src/main/java/org/apache/accumulo/server/trace/TraceServer.java
----------------------------------------------------------------------
diff --git a/server/src/main/java/org/apache/accumulo/server/trace/TraceServer.java b/server/src/main/java/org/apache/accumulo/server/trace/TraceServer.java
index 67a55fa..841166d 100644
--- a/server/src/main/java/org/apache/accumulo/server/trace/TraceServer.java
+++ b/server/src/main/java/org/apache/accumulo/server/trace/TraceServer.java
@@ -23,6 +23,7 @@ import java.util.Map;
 import java.util.Map.Entry;
 import java.util.concurrent.TimeUnit;
 
+import org.apache.accumulo.api.annotations.AccumuloService;
 import org.apache.accumulo.core.Constants;
 import org.apache.accumulo.core.client.BatchWriter;
 import org.apache.accumulo.core.client.BatchWriterConfig;
@@ -72,6 +73,7 @@ import org.apache.zookeeper.Watcher;
 import org.apache.zookeeper.Watcher.Event.EventType;
 import org.apache.zookeeper.Watcher.Event.KeeperState;
 
+@AccumuloService("tracer")
 public class TraceServer implements Watcher {
   
   final private static Logger log = Logger.getLogger(TraceServer.class);
@@ -172,12 +174,12 @@ public class TraceServer implements Watcher {
           Properties props = new Properties();
           AuthenticationToken token = AccumuloClassLoader.getClassLoader().loadClass(conf.get(Property.TRACE_TOKEN_TYPE)).asSubclass(AuthenticationToken.class)
               .newInstance();
-
+          
           int prefixLength = Property.TRACE_TOKEN_PROPERTY_PREFIX.getKey().length() + 1;
           for (Entry<String,String> entry : loginMap.entrySet()) {
             props.put(entry.getKey().substring(prefixLength), entry.getValue());
           }
-
+          
           token.init(props);
           
           at = token;

http://git-wip-us.apache.org/repos/asf/accumulo/blob/dd0b97e5/server/src/main/java/org/apache/accumulo/server/util/Admin.java
----------------------------------------------------------------------
diff --git a/server/src/main/java/org/apache/accumulo/server/util/Admin.java b/server/src/main/java/org/apache/accumulo/server/util/Admin.java
index 3bb801a..a415de7 100644
--- a/server/src/main/java/org/apache/accumulo/server/util/Admin.java
+++ b/server/src/main/java/org/apache/accumulo/server/util/Admin.java
@@ -22,6 +22,8 @@ import java.util.List;
 import java.util.Set;
 import java.util.concurrent.atomic.AtomicInteger;
 
+import org.apache.accumulo.api.annotations.AccumuloService;
+import org.apache.accumulo.core.Constants;
 import org.apache.accumulo.core.client.AccumuloException;
 import org.apache.accumulo.core.client.AccumuloSecurityException;
 import org.apache.accumulo.core.client.Connector;
@@ -44,6 +46,7 @@ import com.beust.jcommander.JCommander;
 import com.beust.jcommander.Parameter;
 import com.beust.jcommander.Parameters;
 
+@AccumuloService("admin")
 public class Admin {
   private static final Logger log = Logger.getLogger(Admin.class);
   

http://git-wip-us.apache.org/repos/asf/accumulo/blob/dd0b97e5/server/src/main/java/org/apache/accumulo/server/util/Initialize.java
----------------------------------------------------------------------
diff --git a/server/src/main/java/org/apache/accumulo/server/util/Initialize.java b/server/src/main/java/org/apache/accumulo/server/util/Initialize.java
index 7d4e6f2..af053aa 100644
--- a/server/src/main/java/org/apache/accumulo/server/util/Initialize.java
+++ b/server/src/main/java/org/apache/accumulo/server/util/Initialize.java
@@ -28,6 +28,7 @@ import java.util.UUID;
 
 import jline.console.ConsoleReader;
 
+import org.apache.accumulo.api.annotations.AccumuloService;
 import org.apache.accumulo.core.Constants;
 import org.apache.accumulo.core.cli.Help;
 import org.apache.accumulo.core.client.AccumuloSecurityException;
@@ -82,6 +83,7 @@ import com.beust.jcommander.Parameter;
  * This class is used to setup the directory structure and the root tablet to get an instance
started
  * 
  */
+@AccumuloService("init")
 public class Initialize {
   private static final Logger log = Logger.getLogger(Initialize.class);
   private static final String DEFAULT_ROOT_USER = "root";

http://git-wip-us.apache.org/repos/asf/accumulo/blob/dd0b97e5/server/src/main/java/org/apache/accumulo/server/util/ZooKeeperMain.java
----------------------------------------------------------------------
diff --git a/server/src/main/java/org/apache/accumulo/server/util/ZooKeeperMain.java b/server/src/main/java/org/apache/accumulo/server/util/ZooKeeperMain.java
index 37edb1a..dc01915 100644
--- a/server/src/main/java/org/apache/accumulo/server/util/ZooKeeperMain.java
+++ b/server/src/main/java/org/apache/accumulo/server/util/ZooKeeperMain.java
@@ -16,6 +16,8 @@
  */
 package org.apache.accumulo.server.util;
 
+import org.apache.accumulo.api.annotations.AccumuloService;
+import org.apache.accumulo.core.Constants;
 import org.apache.accumulo.core.cli.Help;
 import org.apache.accumulo.core.client.Instance;
 import org.apache.accumulo.core.util.CachedConfiguration;
@@ -26,6 +28,7 @@ import org.apache.hadoop.fs.Path;
 
 import com.beust.jcommander.Parameter;
 
+@AccumuloService("zookeeper")
 public class ZooKeeperMain {
   
   static class Opts extends Help {

http://git-wip-us.apache.org/repos/asf/accumulo/blob/dd0b97e5/start/pom.xml
----------------------------------------------------------------------
diff --git a/start/pom.xml b/start/pom.xml
index 3484aab..133413e 100644
--- a/start/pom.xml
+++ b/start/pom.xml
@@ -26,10 +26,22 @@
   <name>Start</name>
   <dependencies>
     <dependency>
+      <groupId>net.sf.scannotation</groupId>
+      <artifactId>scannotation</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.accumulo</groupId>
+      <artifactId>accumulo-api</artifactId>
+    </dependency>
+    <dependency>
       <groupId>org.apache.commons</groupId>
       <artifactId>commons-vfs2</artifactId>
     </dependency>
     <dependency>
+      <groupId>org.javassist</groupId>
+      <artifactId>javassist</artifactId>
+    </dependency>
+    <dependency>
       <groupId>commons-io</groupId>
       <artifactId>commons-io</artifactId>
       <scope>provided</scope>

http://git-wip-us.apache.org/repos/asf/accumulo/blob/dd0b97e5/start/src/main/java/org/apache/accumulo/start/Main.java
----------------------------------------------------------------------
diff --git a/start/src/main/java/org/apache/accumulo/start/Main.java b/start/src/main/java/org/apache/accumulo/start/Main.java
index 66a3e71..3821c3f 100644
--- a/start/src/main/java/org/apache/accumulo/start/Main.java
+++ b/start/src/main/java/org/apache/accumulo/start/Main.java
@@ -16,75 +16,65 @@
  */
 package org.apache.accumulo.start;
 
+import java.io.IOException;
 import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Set;
 
+import org.apache.accumulo.api.annotations.AccumuloService;
 import org.apache.accumulo.start.classloader.AccumuloClassLoader;
+import org.scannotation.AnnotationDB;
 
 public class Main {
   
+  private static AnnotationDB annotationDatabase;
+  
   public static void main(String[] args) throws Exception {
     Runnable r = null;
     
     try {
+      Thread.currentThread().setContextClassLoader(AccumuloClassLoader.getClassLoader());
+      Class<?> vfsClassLoader = AccumuloClassLoader.getClassLoader().loadClass("org.apache.accumulo.start.classloader.vfs.AccumuloVFSClassLoader");
+      ClassLoader cl = (ClassLoader) vfsClassLoader.getMethod("getClassLoader", new Class[]
{}).invoke(null, new Object[] {});
+      Thread.currentThread().setContextClassLoader(cl);
+      
+      URL[] urls = (URL[]) vfsClassLoader.getMethod("getURLs", new Class[] {}).invoke(null,
new Object[] {});
+      
       if (args.length == 0) {
-        printUsage();
+        printUsage(cl, urls);
         System.exit(1);
       }
       final String argsToPass[] = new String[args.length - 1];
       System.arraycopy(args, 1, argsToPass, 0, args.length - 1);
       
-      Thread.currentThread().setContextClassLoader(AccumuloClassLoader.getClassLoader());
-      
-      Class<?> vfsClassLoader = AccumuloClassLoader.getClassLoader().loadClass("org.apache.accumulo.start.classloader.vfs.AccumuloVFSClassLoader");
-      
-      ClassLoader cl = (ClassLoader) vfsClassLoader.getMethod("getClassLoader", new Class[]
{}).invoke(null, new Object[] {});
-      
       Class<?> runTMP = null;
       
-      Thread.currentThread().setContextClassLoader(cl);
-      
-      if (args[0].equals("master")) {
-        runTMP = cl.loadClass("org.apache.accumulo.server.master.Master");
-      } else if (args[0].equals("tserver")) {
-        runTMP = cl.loadClass("org.apache.accumulo.server.tabletserver.TabletServer");
-      } else if (args[0].equals("shell")) {
-        runTMP = cl.loadClass("org.apache.accumulo.core.util.shell.Shell");
-      } else if (args[0].equals("init")) {
-        runTMP = cl.loadClass("org.apache.accumulo.server.util.Initialize");
-      } else if (args[0].equals("admin")) {
-        runTMP = cl.loadClass("org.apache.accumulo.server.util.Admin");
-      } else if (args[0].equals("gc")) {
-        runTMP = cl.loadClass("org.apache.accumulo.server.gc.SimpleGarbageCollector");
-      } else if (args[0].equals("monitor")) {
-        runTMP = cl.loadClass("org.apache.accumulo.server.monitor.Monitor");
-      } else if (args[0].equals("tracer")) {
-        runTMP = cl.loadClass("org.apache.accumulo.server.trace.TraceServer");
-      } else if (args[0].equals("proxy")) {
-        runTMP = cl.loadClass("org.apache.accumulo.proxy.Proxy");
-      } else if (args[0].equals("minicluster")) {
-        runTMP = cl.loadClass("org.apache.accumulo.minicluster.MiniAccumuloRunner");
-      } else if (args[0].equals("classpath")) {
+      if (args[0].equals("classpath")) {
         vfsClassLoader.getMethod("printClassPath", new Class[] {}).invoke(vfsClassLoader,
new Object[] {});
         return;
       } else if (args[0].equals("version")) {
         runTMP = cl.loadClass("org.apache.accumulo.core.Constants");
         System.out.println(runTMP.getField("VERSION").get(null));
         return;
-      } else if (args[0].equals("rfile-info")) {
-        runTMP = cl.loadClass("org.apache.accumulo.core.file.rfile.PrintInfo");
-      } else if (args[0].equals("login-info")) {
-        runTMP = cl.loadClass("org.apache.accumulo.core.util.LoginProperties");
-      } else if (args[0].equals("zookeeper")) {
-        runTMP = cl.loadClass("org.apache.accumulo.server.util.ZooKeeperMain");
-      } else if (args[0].equals("create-token")) {
-        runTMP = cl.loadClass("org.apache.accumulo.core.util.CreateToken");
       } else {
-        try {
-          runTMP = cl.loadClass(args[0]);
-        } catch (ClassNotFoundException cnfe) {
-          System.out.println("Classname " + args[0] + " not found.  Please make sure you
use the wholly qualified package name.");
-          System.exit(1);
+        for (String className : loadAnnotationDB(urls, AccumuloService.class)) {
+          Class<?> runTMPCandidate = cl.loadClass(className);
+          if (args[0].equals(runTMPCandidate.getAnnotation(AccumuloService.class).value()))
{
+            runTMP = runTMPCandidate;
+            break;
+          }
+        }
+        
+        if (runTMP == null) {
+          try {
+            runTMP = cl.loadClass(args[0]);
+          } catch (ClassNotFoundException cnfe) {
+            System.out.println("Classname " + args[0] + " not found.  Please make sure you
use the wholly qualified package name.");
+            System.exit(1);
+          }
         }
       }
       Method main = null;
@@ -100,6 +90,7 @@ public class Main {
       final Object thisIsJustOneArgument = argsToPass;
       final Method finalMain = main;
       r = new Runnable() {
+        @Override
         public void run() {
           try {
             finalMain.invoke(null, thisIsJustOneArgument);
@@ -120,7 +111,32 @@ public class Main {
     }
   }
   
-  private static void printUsage() {
-    System.out.println("accumulo init | master | tserver | monitor | shell | admin | gc |
classpath | rfile-info | login-info | tracer | minicluster | proxy | zookeeper | create-token
| <accumulo class> args");
+  private static void printUsage(ClassLoader cl, URL[] urls) throws IOException, ClassNotFoundException
{
+    ArrayList<String> keywords = new ArrayList<String>(20);
+    for (String className : loadAnnotationDB(urls, AccumuloService.class)) {
+      Class<?> runTMPCandidate = cl.loadClass(className);
+      keywords.add(runTMPCandidate.getAnnotation(AccumuloService.class).value());
+    }
+    keywords.add("classpath");
+    keywords.add("version");
+    
+    String prefix = "";
+    String kwString = "";
+    for (String kw : keywords) {
+      kwString += prefix + kw;
+      prefix = " | ";
+    }
+    System.out.println("accumulo " + kwString + " | <accumulo class> args");
+  }
+  
+  protected synchronized static Set<String> loadAnnotationDB(URL[] urls, Class<?>
annotationClass) throws IOException {
+    if (annotationDatabase == null) {
+      AnnotationDB database = new AnnotationDB();
+      database.setScanClassAnnotations(true);
+      database.scanArchives(urls);
+      annotationDatabase = database;
+    }
+    Set<String> retVal = annotationDatabase.getAnnotationIndex().get(annotationClass.getName());
+    return retVal == null ? (retVal = Collections.emptySet()) : retVal;
   }
 }

http://git-wip-us.apache.org/repos/asf/accumulo/blob/dd0b97e5/start/src/main/java/org/apache/accumulo/start/classloader/vfs/AccumuloVFSClassLoader.java
----------------------------------------------------------------------
diff --git a/start/src/main/java/org/apache/accumulo/start/classloader/vfs/AccumuloVFSClassLoader.java
b/start/src/main/java/org/apache/accumulo/start/classloader/vfs/AccumuloVFSClassLoader.java
index eb653bc..0ff8843 100644
--- a/start/src/main/java/org/apache/accumulo/start/classloader/vfs/AccumuloVFSClassLoader.java
+++ b/start/src/main/java/org/apache/accumulo/start/classloader/vfs/AccumuloVFSClassLoader.java
@@ -61,6 +61,7 @@ public class AccumuloVFSClassLoader {
   
   public static class AccumuloVFSClassLoaderShutdownThread implements Runnable {
     
+    @Override
     public void run() {
       try {
         AccumuloVFSClassLoader.close();
@@ -99,7 +100,7 @@ public class AccumuloVFSClassLoader {
   
   public synchronized static <U> Class<? extends U> loadClass(String classname,
Class<U> extension) throws ClassNotFoundException {
     try {
-      return (Class<? extends U>) getClassLoader().loadClass(classname).asSubclass(extension);
+      return getClassLoader().loadClass(classname).asSubclass(extension);
     } catch (IOException e) {
       throw new ClassNotFoundException("IO Error loading class " + classname, e);
     }
@@ -282,6 +283,28 @@ public class AccumuloVFSClassLoader {
     });
   }
   
+  public static URL[] getURLs() {
+    ArrayList<URL> urls = new ArrayList<URL>(20);
+    try {
+      ClassLoader cl = getClassLoader();
+      while (cl != null && cl != ClassLoader.getSystemClassLoader()) {
+        if (cl instanceof URLClassLoader) {
+          URLClassLoader ucl = (URLClassLoader) cl;
+          for (URL u : ucl.getURLs())
+            urls.add(u);
+        } else if (cl instanceof VFSClassLoader) {
+          VFSClassLoader vcl = (VFSClassLoader) cl;
+          for (FileObject f : vcl.getFileObjects())
+            urls.add(f.getURL());
+        }
+        cl = cl.getParent();
+      }
+    } catch (Exception t) {
+      throw new RuntimeException(t);
+    }
+    return urls.toArray(new URL[urls.size()]);
+  }
+  
   public static void printClassPath(Printer out) {
     try {
       ClassLoader cl = getClassLoader();


Mime
View raw message