accumulo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ctubb...@apache.org
Subject [accumulo] branch master updated: ACCUMULO-1975 Consolidate class instantiation config helper methods (#351)
Date Thu, 11 Jan 2018 22:41:13 GMT
This is an automated email from the ASF dual-hosted git repository.

ctubbsii pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/accumulo.git


The following commit(s) were added to refs/heads/master by this push:
     new 13619d5  ACCUMULO-1975  Consolidate class instantiation config helper methods (#351)
13619d5 is described below

commit 13619d57968724d360ef632d8bc11a22a2ba5bac
Author: Jared <15164322+jkrdev@users.noreply.github.com>
AuthorDate: Thu Jan 11 17:41:11 2018 -0500

    ACCUMULO-1975  Consolidate class instantiation config helper methods (#351)
    
    Remove redundant AccumuloConfiguration.instantiateClassProperty() method in favor of
    Refactor Property.createInstanceFromPropertyName()
---
 .../accumulo/core/conf/AccumuloConfiguration.java  | 32 ----------------------
 .../server/security/SecurityOperation.java         | 11 +++++---
 .../java/org/apache/accumulo/master/Master.java    |  2 +-
 .../master/MasterClientServiceHandler.java         |  5 ++--
 .../accumulo/master/recovery/RecoveryManager.java  |  3 +-
 5 files changed, 13 insertions(+), 40 deletions(-)

diff --git a/core/src/main/java/org/apache/accumulo/core/conf/AccumuloConfiguration.java b/core/src/main/java/org/apache/accumulo/core/conf/AccumuloConfiguration.java
index 2c53407..832bebd 100644
--- a/core/src/main/java/org/apache/accumulo/core/conf/AccumuloConfiguration.java
+++ b/core/src/main/java/org/apache/accumulo/core/conf/AccumuloConfiguration.java
@@ -27,7 +27,6 @@ import java.util.function.Predicate;
 import org.apache.accumulo.core.Constants;
 import org.apache.accumulo.core.conf.PropertyType.PortRange;
 import org.apache.accumulo.core.util.Pair;
-import org.apache.accumulo.start.classloader.vfs.AccumuloVFSClassLoader;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -284,35 +283,4 @@ public abstract class AccumuloConfiguration implements Iterable<Entry<String,Str
    */
   public void invalidateCache() {}
 
-  /**
-   * Creates a new instance of a class specified in a configuration property.
-   *
-   * @param property
-   *          property specifying class name
-   * @param base
-   *          base class of type
-   * @param defaultInstance
-   *          instance to use if creation fails
-   * @return new class instance, or default instance if creation failed
-   * @see AccumuloVFSClassLoader
-   */
-  public <T> T instantiateClassProperty(Property property, Class<T> base, T defaultInstance)
{
-    String clazzName = get(property);
-    T instance = null;
-
-    try {
-      Class<? extends T> clazz = AccumuloVFSClassLoader.loadClass(clazzName, base);
-      instance = clazz.newInstance();
-      log.info("Loaded class : {}", clazzName);
-    } catch (Exception e) {
-      log.warn("Failed to load class ", e);
-    }
-
-    if (instance == null) {
-      log.info("Using {}", defaultInstance.getClass().getName());
-      instance = defaultInstance;
-    }
-    return instance;
-  }
-
 }
diff --git a/server/base/src/main/java/org/apache/accumulo/server/security/SecurityOperation.java
b/server/base/src/main/java/org/apache/accumulo/server/security/SecurityOperation.java
index 1918646..b859e3f 100644
--- a/server/base/src/main/java/org/apache/accumulo/server/security/SecurityOperation.java
+++ b/server/base/src/main/java/org/apache/accumulo/server/security/SecurityOperation.java
@@ -33,6 +33,7 @@ import org.apache.accumulo.core.client.impl.Table;
 import org.apache.accumulo.core.client.impl.thrift.SecurityErrorCode;
 import org.apache.accumulo.core.client.impl.thrift.ThriftSecurityException;
 import org.apache.accumulo.core.client.security.tokens.AuthenticationToken;
+import org.apache.accumulo.core.conf.AccumuloConfiguration;
 import org.apache.accumulo.core.conf.Property;
 import org.apache.accumulo.core.conf.SiteConfiguration;
 import org.apache.accumulo.core.data.thrift.IterInfo;
@@ -89,21 +90,23 @@ public class SecurityOperation {
   }
 
   protected static Authorizor getAuthorizor(String instanceId, boolean initialize) {
-    Authorizor toRet = SiteConfiguration.getInstance().instantiateClassProperty(Property.INSTANCE_SECURITY_AUTHORIZOR,
Authorizor.class,
-        ZKAuthorizor.getInstance());
+    AccumuloConfiguration conf = SiteConfiguration.getInstance();
+    Authorizor toRet = Property.createInstanceFromPropertyName(conf, Property.INSTANCE_SECURITY_AUTHORIZOR,
Authorizor.class, ZKAuthorizor.getInstance());
     toRet.initialize(instanceId, initialize);
     return toRet;
   }
 
   protected static Authenticator getAuthenticator(String instanceId, boolean initialize)
{
-    Authenticator toRet = SiteConfiguration.getInstance().instantiateClassProperty(Property.INSTANCE_SECURITY_AUTHENTICATOR,
Authenticator.class,
+    AccumuloConfiguration conf = SiteConfiguration.getInstance();
+    Authenticator toRet = Property.createInstanceFromPropertyName(conf, Property.INSTANCE_SECURITY_AUTHENTICATOR,
Authenticator.class,
         ZKAuthenticator.getInstance());
     toRet.initialize(instanceId, initialize);
     return toRet;
   }
 
   protected static PermissionHandler getPermHandler(String instanceId, boolean initialize)
{
-    PermissionHandler toRet = SiteConfiguration.getInstance().instantiateClassProperty(Property.INSTANCE_SECURITY_PERMISSION_HANDLER,
PermissionHandler.class,
+    AccumuloConfiguration conf = SiteConfiguration.getInstance();
+    PermissionHandler toRet = Property.createInstanceFromPropertyName(conf, Property.INSTANCE_SECURITY_PERMISSION_HANDLER,
PermissionHandler.class,
         ZKPermHandler.getInstance());
     toRet.initialize(instanceId, initialize);
     return toRet;
diff --git a/server/master/src/main/java/org/apache/accumulo/master/Master.java b/server/master/src/main/java/org/apache/accumulo/master/Master.java
index 4532129..441a265 100644
--- a/server/master/src/main/java/org/apache/accumulo/master/Master.java
+++ b/server/master/src/main/java/org/apache/accumulo/master/Master.java
@@ -610,7 +610,7 @@ public class Master extends AccumuloServerContext implements LiveTServerSet.List
     timeKeeper = new MasterTime(this);
     ThriftTransportPool.getInstance().setIdleTime(aconf.getTimeInMillis(Property.GENERAL_RPC_TIMEOUT));
     tserverSet = new LiveTServerSet(this, this);
-    this.tabletBalancer = aconf.instantiateClassProperty(Property.MASTER_TABLET_BALANCER,
TabletBalancer.class, new DefaultLoadBalancer());
+    this.tabletBalancer = Property.createInstanceFromPropertyName(aconf, Property.MASTER_TABLET_BALANCER,
TabletBalancer.class, new DefaultLoadBalancer());
     this.tabletBalancer.init(this);
 
     try {
diff --git a/server/master/src/main/java/org/apache/accumulo/master/MasterClientServiceHandler.java
b/server/master/src/main/java/org/apache/accumulo/master/MasterClientServiceHandler.java
index ee7542e..273784b 100644
--- a/server/master/src/main/java/org/apache/accumulo/master/MasterClientServiceHandler.java
+++ b/server/master/src/main/java/org/apache/accumulo/master/MasterClientServiceHandler.java
@@ -49,6 +49,7 @@ import org.apache.accumulo.core.client.impl.thrift.TableOperation;
 import org.apache.accumulo.core.client.impl.thrift.TableOperationExceptionType;
 import org.apache.accumulo.core.client.impl.thrift.ThriftSecurityException;
 import org.apache.accumulo.core.client.impl.thrift.ThriftTableOperationException;
+import org.apache.accumulo.core.conf.AccumuloConfiguration;
 import org.apache.accumulo.core.conf.Property;
 import org.apache.accumulo.core.data.Key;
 import org.apache.accumulo.core.data.Range;
@@ -467,8 +468,8 @@ public class MasterClientServiceHandler extends FateServiceHandler implements
Ma
 
   private void updatePlugins(String property) {
     if (property.equals(Property.MASTER_TABLET_BALANCER.getKey())) {
-      TabletBalancer balancer = master.getConfiguration().instantiateClassProperty(Property.MASTER_TABLET_BALANCER,
TabletBalancer.class,
-          new DefaultLoadBalancer());
+      AccumuloConfiguration conf = master.getConfiguration();
+      TabletBalancer balancer = Property.createInstanceFromPropertyName(conf, Property.MASTER_TABLET_BALANCER,
TabletBalancer.class, new DefaultLoadBalancer());
       balancer.init(master);
       master.tabletBalancer = balancer;
       log.info("tablet balancer changed to {}", master.tabletBalancer.getClass().getName());
diff --git a/server/master/src/main/java/org/apache/accumulo/master/recovery/RecoveryManager.java
b/server/master/src/main/java/org/apache/accumulo/master/recovery/RecoveryManager.java
index a6a97c9..d22d800 100644
--- a/server/master/src/main/java/org/apache/accumulo/master/recovery/RecoveryManager.java
+++ b/server/master/src/main/java/org/apache/accumulo/master/recovery/RecoveryManager.java
@@ -173,7 +173,8 @@ public class RecoveryManager {
         synchronized (this) {
           if (!closeTasksQueued.contains(sortId) && !sortsQueued.contains(sortId))
{
             AccumuloConfiguration aconf = master.getConfiguration();
-            LogCloser closer = aconf.instantiateClassProperty(Property.MASTER_WALOG_CLOSER_IMPLEMETATION,
LogCloser.class, new HadoopLogCloser());
+            LogCloser closer = Property.createInstanceFromPropertyName(aconf, Property.MASTER_WALOG_CLOSER_IMPLEMETATION,
LogCloser.class,
+                new HadoopLogCloser());
             Long delay = recoveryDelay.get(sortId);
             if (delay == null) {
               delay = aconf.getTimeInMillis(Property.MASTER_RECOVERY_DELAY);

-- 
To stop receiving notification emails like this one, please contact
['"commits@accumulo.apache.org" <commits@accumulo.apache.org>'].

Mime
View raw message