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 b609f55  Some ServerContext clean up (#1567)
b609f55 is described below

commit b609f55b63cd4ddfdc2f619b8d7b51a92ba48d10
Author: Mike Miller <mmil...@apache.org>
AuthorDate: Wed Mar 18 16:17:17 2020 -0400

    Some ServerContext clean up (#1567)
    
    * Drop ServerContext overloaded constructors
    * Create a static methods for special cases
---
 .../standalone/StandaloneAccumuloCluster.java      |  3 +-
 .../org/apache/accumulo/server/ServerContext.java  | 37 +++++-----
 .../apache/accumulo/server/cli/ServerUtilOpts.java |  5 +-
 .../apache/accumulo/server/init/Initialize.java    | 83 +++++++++++-----------
 .../accumulo/test/performance/NullTserver.java     |  2 +-
 5 files changed, 66 insertions(+), 64 deletions(-)

diff --git 
a/minicluster/src/main/java/org/apache/accumulo/cluster/standalone/StandaloneAccumuloCluster.java
 
b/minicluster/src/main/java/org/apache/accumulo/cluster/standalone/StandaloneAccumuloCluster.java
index 805ae29..4bf0efb 100644
--- 
a/minicluster/src/main/java/org/apache/accumulo/cluster/standalone/StandaloneAccumuloCluster.java
+++ 
b/minicluster/src/main/java/org/apache/accumulo/cluster/standalone/StandaloneAccumuloCluster.java
@@ -135,7 +135,8 @@ public class StandaloneAccumuloCluster implements 
AccumuloCluster {
   @Override
   public synchronized ServerContext getServerContext() {
     if (context == null) {
-      context = new ServerContext(siteConfig, getClientProperties());
+      context = ServerContext.override(siteConfig, info.getInstanceName(), 
info.getZooKeepers(),
+          info.getZooKeepersSessionTimeOut());
     }
     return context;
   }
diff --git 
a/server/base/src/main/java/org/apache/accumulo/server/ServerContext.java 
b/server/base/src/main/java/org/apache/accumulo/server/ServerContext.java
index 5844b00..d7c6150 100644
--- a/server/base/src/main/java/org/apache/accumulo/server/ServerContext.java
+++ b/server/base/src/main/java/org/apache/accumulo/server/ServerContext.java
@@ -21,10 +21,8 @@ package org.apache.accumulo.server;
 import static com.google.common.base.Preconditions.checkArgument;
 
 import java.io.IOException;
-import java.util.Properties;
 
 import org.apache.accumulo.core.clientImpl.ClientContext;
-import org.apache.accumulo.core.clientImpl.ClientInfo;
 import org.apache.accumulo.core.conf.AccumuloConfiguration;
 import org.apache.accumulo.core.conf.Property;
 import org.apache.accumulo.core.conf.SiteConfiguration;
@@ -63,30 +61,29 @@ public class ServerContext extends ClientContext {
     this(new ServerInfo(siteConfig));
   }
 
-  public ServerContext(SiteConfiguration siteConfig, String instanceName, 
String zooKeepers,
-      int zooKeepersSessionTimeOut) {
-    this(new ServerInfo(siteConfig, instanceName, zooKeepers, 
zooKeepersSessionTimeOut));
-  }
-
-  public ServerContext(SiteConfiguration siteConfig, String instanceName, 
String instanceID) {
-    this(new ServerInfo(siteConfig, instanceName, instanceID));
-  }
-
-  public ServerContext(SiteConfiguration siteConfig, Properties clientProps) {
-    this(siteConfig, ClientInfo.from(clientProps));
-  }
-
-  private ServerContext(SiteConfiguration siteConfig, ClientInfo info) {
-    this(new ServerInfo(siteConfig, info.getInstanceName(), 
info.getZooKeepers(),
-        info.getZooKeepersSessionTimeOut()));
-  }
-
   private ServerContext(ServerInfo info) {
     super(info, info.getSiteConfiguration());
     this.info = info;
     zooReaderWriter = new ZooReaderWriter(info.getSiteConfiguration());
   }
 
+  /**
+   * Used during initialization to set the instance name and ID.
+   */
+  public static ServerContext initialize(SiteConfiguration siteConfig, String 
instanceName,
+      String instanceID) {
+    return new ServerContext(new ServerInfo(siteConfig, instanceName, 
instanceID));
+  }
+
+  /**
+   * Override properties for testing
+   */
+  public static ServerContext override(SiteConfiguration siteConfig, String 
instanceName,
+      String zooKeepers, int zkSessionTimeOut) {
+    return new ServerContext(
+        new ServerInfo(siteConfig, instanceName, zooKeepers, 
zkSessionTimeOut));
+  }
+
   @Override
   public String getInstanceID() {
     return info.getInstanceID();
diff --git 
a/server/base/src/main/java/org/apache/accumulo/server/cli/ServerUtilOpts.java 
b/server/base/src/main/java/org/apache/accumulo/server/cli/ServerUtilOpts.java
index 85eadfa..7cca4e3 100644
--- 
a/server/base/src/main/java/org/apache/accumulo/server/cli/ServerUtilOpts.java
+++ 
b/server/base/src/main/java/org/apache/accumulo/server/cli/ServerUtilOpts.java
@@ -19,6 +19,7 @@
 package org.apache.accumulo.server.cli;
 
 import org.apache.accumulo.core.cli.ClientOpts;
+import org.apache.accumulo.core.clientImpl.ClientInfo;
 import org.apache.accumulo.core.conf.SiteConfiguration;
 import org.apache.accumulo.server.ServerContext;
 
@@ -31,7 +32,9 @@ public class ServerUtilOpts extends ClientOpts {
       if (getClientConfigFile() == null) {
         context = new ServerContext(SiteConfiguration.auto());
       } else {
-        context = new ServerContext(SiteConfiguration.auto(), 
getClientProps());
+        ClientInfo info = ClientInfo.from(getClientProps());
+        context = ServerContext.override(SiteConfiguration.auto(), 
info.getInstanceName(),
+            info.getZooKeepers(), info.getZooKeepersSessionTimeOut());
       }
     }
     return context;
diff --git 
a/server/base/src/main/java/org/apache/accumulo/server/init/Initialize.java 
b/server/base/src/main/java/org/apache/accumulo/server/init/Initialize.java
index 9623c24..09f7aec 100644
--- a/server/base/src/main/java/org/apache/accumulo/server/init/Initialize.java
+++ b/server/base/src/main/java/org/apache/accumulo/server/init/Initialize.java
@@ -363,52 +363,53 @@ public class Initialize implements KeywordExecutable {
     // the actual disk locations of the root table and tablets
     Set<String> configuredVolumes = 
VolumeConfiguration.getVolumeUris(siteConfig, hadoopConf);
     String instanceName = 
instanceNamePath.substring(getInstanceNamePrefix().length());
-    ServerContext serverContext = new ServerContext(siteConfig, instanceName, 
uuid.toString());
-    VolumeChooserEnvironment chooserEnv =
-        new VolumeChooserEnvironmentImpl(ChooserScope.INIT, RootTable.ID, 
null, serverContext);
-    String rootTabletDirName = RootTable.ROOT_TABLET_DIR_NAME;
-    String ext = 
FileOperations.getNewFileExtension(DefaultConfiguration.getInstance());
-    String rootTabletFileUri = new Path(fs.choose(chooserEnv, 
configuredVolumes) + Path.SEPARATOR
-        + ServerConstants.TABLE_DIR + Path.SEPARATOR + RootTable.ID + 
Path.SEPARATOR
-        + rootTabletDirName + Path.SEPARATOR + "00000_00000." + 
ext).toString();
 
-    try {
-      initZooKeeper(opts, uuid.toString(), instanceNamePath, 
rootTabletDirName, rootTabletFileUri);
-    } catch (Exception e) {
-      log.error("FATAL: Failed to initialize zookeeper", e);
-      return false;
-    }
+    try (ServerContext context =
+        ServerContext.initialize(siteConfig, instanceName, uuid.toString())) {
+      VolumeChooserEnvironment chooserEnv =
+          new VolumeChooserEnvironmentImpl(ChooserScope.INIT, RootTable.ID, 
null, context);
+      String rootTabletDirName = RootTable.ROOT_TABLET_DIR_NAME;
+      String ext = 
FileOperations.getNewFileExtension(DefaultConfiguration.getInstance());
+      String rootTabletFileUri = new Path(fs.choose(chooserEnv, 
configuredVolumes) + Path.SEPARATOR
+          + ServerConstants.TABLE_DIR + Path.SEPARATOR + RootTable.ID + 
Path.SEPARATOR
+          + rootTabletDirName + Path.SEPARATOR + "00000_00000." + 
ext).toString();
 
-    try {
-      initFileSystem(siteConfig, hadoopConf, fs, uuid,
-          new Path(fs.choose(chooserEnv, configuredVolumes) + Path.SEPARATOR
-              + ServerConstants.TABLE_DIR + Path.SEPARATOR + RootTable.ID + 
rootTabletDirName)
-                  .toString(),
-          rootTabletFileUri, serverContext);
-    } catch (Exception e) {
-      log.error("FATAL Failed to initialize filesystem", e);
-
-      if (siteConfig.get(Property.INSTANCE_VOLUMES).trim().equals("")) {
-
-        final String defaultFsUri = "file:///";
-        String fsDefaultName = hadoopConf.get("fs.default.name", defaultFsUri),
-            fsDefaultFS = hadoopConf.get("fs.defaultFS", defaultFsUri);
-
-        // Try to determine when we couldn't find an appropriate core-site.xml 
on the classpath
-        if (defaultFsUri.equals(fsDefaultName) && 
defaultFsUri.equals(fsDefaultFS)) {
-          log.error(
-              "FATAL: Default filesystem value ('fs.defaultFS' or"
-                  + " 'fs.default.name') of '{}' was found in the Hadoop 
configuration",
-              defaultFsUri);
-          log.error("FATAL: Please ensure that the Hadoop core-site.xml is on"
-              + " the classpath using 'general.classpaths' in 
accumulo.properties");
-        }
+      try {
+        initZooKeeper(opts, uuid.toString(), instanceNamePath, 
rootTabletDirName,
+            rootTabletFileUri);
+      } catch (Exception e) {
+        log.error("FATAL: Failed to initialize zookeeper", e);
+        return false;
       }
 
-      return false;
-    }
+      try {
+        initFileSystem(siteConfig, hadoopConf, fs, uuid,
+            new Path(fs.choose(chooserEnv, configuredVolumes) + Path.SEPARATOR
+                + ServerConstants.TABLE_DIR + Path.SEPARATOR + RootTable.ID + 
rootTabletDirName)
+                    .toString(),
+            rootTabletFileUri, context);
+      } catch (Exception e) {
+        log.error("FATAL Failed to initialize filesystem", e);
+
+        if (siteConfig.get(Property.INSTANCE_VOLUMES).trim().equals("")) {
+
+          final String defaultFsUri = "file:///";
+          String fsDefaultName = hadoopConf.get("fs.default.name", 
defaultFsUri),
+              fsDefaultFS = hadoopConf.get("fs.defaultFS", defaultFsUri);
+
+          // Try to determine when we couldn't find an appropriate 
core-site.xml on the classpath
+          if (defaultFsUri.equals(fsDefaultName) && 
defaultFsUri.equals(fsDefaultFS)) {
+            log.error(
+                "FATAL: Default filesystem value ('fs.defaultFS' or"
+                    + " 'fs.default.name') of '{}' was found in the Hadoop 
configuration",
+                defaultFsUri);
+            log.error("FATAL: Please ensure that the Hadoop core-site.xml is 
on"
+                + " the classpath using 'general.classpaths' in 
accumulo.properties");
+          }
+        }
 
-    try (ServerContext context = new ServerContext(siteConfig)) {
+        return false;
+      }
 
       // When we're using Kerberos authentication, we need valid credentials 
to perform
       // initialization. If the user provided some, use them.
diff --git 
a/test/src/main/java/org/apache/accumulo/test/performance/NullTserver.java 
b/test/src/main/java/org/apache/accumulo/test/performance/NullTserver.java
index 197864b..9ce7525 100644
--- a/test/src/main/java/org/apache/accumulo/test/performance/NullTserver.java
+++ b/test/src/main/java/org/apache/accumulo/test/performance/NullTserver.java
@@ -297,7 +297,7 @@ public class NullTserver {
     int zkTimeOut =
         (int) 
DefaultConfiguration.getInstance().getTimeInMillis(Property.INSTANCE_ZK_TIMEOUT);
     var siteConfig = SiteConfiguration.auto();
-    ServerContext context = new ServerContext(siteConfig, opts.iname, 
opts.keepers, zkTimeOut);
+    ServerContext context = ServerContext.override(siteConfig, opts.iname, 
opts.keepers, zkTimeOut);
     TransactionWatcher watcher = new TransactionWatcher(context);
     ThriftClientHandler tch = new ThriftClientHandler(context, watcher);
     Processor<Iface> processor = new Processor<>(tch);

Reply via email to