You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@accumulo.apache.org by GitBox <gi...@apache.org> on 2018/12/07 15:07:22 UTC

[GitHub] mikewalch closed pull request #47: Reduced use of ClientInfo

mikewalch closed pull request #47: Reduced use of ClientInfo
URL: https://github.com/apache/accumulo-testing/pull/47
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/src/main/java/org/apache/accumulo/testing/TestEnv.java b/src/main/java/org/apache/accumulo/testing/TestEnv.java
index 19e4891..1df78c1 100644
--- a/src/main/java/org/apache/accumulo/testing/TestEnv.java
+++ b/src/main/java/org/apache/accumulo/testing/TestEnv.java
@@ -7,9 +7,6 @@
 
 import org.apache.accumulo.core.client.Accumulo;
 import org.apache.accumulo.core.client.AccumuloClient;
-import org.apache.accumulo.core.client.AccumuloException;
-import org.apache.accumulo.core.client.AccumuloSecurityException;
-import org.apache.accumulo.core.client.ClientInfo;
 import org.apache.accumulo.core.client.security.tokens.AuthenticationToken;
 import org.apache.accumulo.core.conf.ClientProperty;
 import org.apache.hadoop.conf.Configuration;
@@ -18,7 +15,7 @@
 
   protected final Properties testProps;
   private String clientPropsPath;
-  private ClientInfo info;
+  private final Properties clientProps;
   private AccumuloClient client = null;
   private Configuration hadoopConfig = null;
 
@@ -27,14 +24,20 @@ public TestEnv(String testPropsPath, String clientPropsPath) {
     requireNonNull(clientPropsPath);
     this.testProps = TestProps.loadFromFile(testPropsPath);
     this.clientPropsPath = clientPropsPath;
-    this.info = ClientInfo.from(TestProps.loadFromFile(clientPropsPath));
+    this.clientProps = Accumulo.newClientProperties().from(clientPropsPath).build();
+  }
+
+  private Properties copyProperties(Properties props) {
+    Properties result = new Properties();
+    props.forEach((key, value) -> result.setProperty((String) key, (String) value));
+    return result;
   }
 
   /**
    * @return a copy of the test properties
    */
   public Properties getTestProperties() {
-    return new Properties(testProps);
+    return copyProperties(testProps);
   }
 
   /**
@@ -48,8 +51,8 @@ public String getClientPropsPath() {
     return clientPropsPath;
   }
 
-  public ClientInfo getInfo() {
-    return info;
+  public Properties getClientProps() {
+    return copyProperties(clientProps);
   }
 
   /**
@@ -58,7 +61,7 @@ public ClientInfo getInfo() {
    * @return username
    */
   public String getAccumuloUserName() {
-    return info.getPrincipal();
+    return ClientProperty.AUTH_PRINCIPAL.getValue(clientProps);
   }
 
   /**
@@ -67,9 +70,9 @@ public String getAccumuloUserName() {
    * @return password
    */
   public String getAccumuloPassword() {
-    String authType = info.getProperties().getProperty(ClientProperty.AUTH_TYPE.getKey());
+    String authType = ClientProperty.AUTH_TYPE.getValue(clientProps);
     if (authType.equals("password")) {
-      return info.getProperties().getProperty(ClientProperty.AUTH_TOKEN.getKey());
+      return ClientProperty.AUTH_TOKEN.getValue(clientProps);
     }
     return null;
   }
@@ -101,7 +104,7 @@ public Configuration getHadoopConfiguration() {
    * Gets an authentication token based on the configured password.
    */
   public AuthenticationToken getToken() {
-    return info.getAuthenticationToken();
+    return ClientProperty.getAuthenticationToken(clientProps);
   }
 
   public String getHdfsRoot() {
@@ -115,16 +118,15 @@ public String getYarnResourceManager() {
   /**
    * Gets an Accumulo client. The same client is reused after the first call.
    */
-  public synchronized AccumuloClient getAccumuloClient() throws AccumuloException, AccumuloSecurityException {
+  public synchronized AccumuloClient getAccumuloClient() {
     if (client == null) {
-      client = Accumulo.newClient().from(info).build();
+      client = Accumulo.newClient().from(clientProps).build();
     }
     return client;
   }
 
-  public AccumuloClient createClient(String principal, AuthenticationToken token)
-      throws AccumuloSecurityException, AccumuloException {
-    return Accumulo.newClient().from(getInfo()).as(principal, token).build();
+  public AccumuloClient createClient(String principal, AuthenticationToken token) {
+    return Accumulo.newClient().from(clientProps).as(principal, token).build();
   }
 
   @Override
diff --git a/src/main/java/org/apache/accumulo/testing/continuous/ContinuousMoru.java b/src/main/java/org/apache/accumulo/testing/continuous/ContinuousMoru.java
index 6e19ed0..6497067 100644
--- a/src/main/java/org/apache/accumulo/testing/continuous/ContinuousMoru.java
+++ b/src/main/java/org/apache/accumulo/testing/continuous/ContinuousMoru.java
@@ -24,6 +24,7 @@
 import java.util.UUID;
 
 import org.apache.accumulo.core.client.AccumuloSecurityException;
+import org.apache.accumulo.core.client.ClientInfo;
 import org.apache.accumulo.core.client.mapreduce.AccumuloInputFormat;
 import org.apache.accumulo.core.client.mapreduce.AccumuloOutputFormat;
 import org.apache.accumulo.core.data.Key;
@@ -123,7 +124,7 @@ public int run(String[] args) throws IOException, InterruptedException, ClassNot
 
     job.setInputFormatClass(AccumuloInputFormat.class);
 
-    AccumuloInputFormat.setClientInfo(job, env.getInfo());
+    AccumuloInputFormat.setClientInfo(job, ClientInfo.from(env.getClientProps()));
     AccumuloInputFormat.setInputTableName(job, env.getAccumuloTableName());
 
     int maxMaps = Integer.parseInt(env.getTestProperty(TestProps.CI_VERIFY_MAX_MAPS));
@@ -140,7 +141,7 @@ public int run(String[] args) throws IOException, InterruptedException, ClassNot
     job.setMapperClass(CMapper.class);
     job.setNumReduceTasks(0);
     job.setOutputFormatClass(AccumuloOutputFormat.class);
-    AccumuloOutputFormat.setClientInfo(job, env.getInfo());
+    AccumuloOutputFormat.setClientInfo(job, ClientInfo.from(env.getClientProps()));
     AccumuloOutputFormat.setCreateTables(job, true);
     AccumuloOutputFormat.setDefaultTableName(job, env.getAccumuloTableName());
 
diff --git a/src/main/java/org/apache/accumulo/testing/continuous/ContinuousVerify.java b/src/main/java/org/apache/accumulo/testing/continuous/ContinuousVerify.java
index 59beb15..94d0fbd 100644
--- a/src/main/java/org/apache/accumulo/testing/continuous/ContinuousVerify.java
+++ b/src/main/java/org/apache/accumulo/testing/continuous/ContinuousVerify.java
@@ -26,6 +26,7 @@
 import java.util.Set;
 
 import org.apache.accumulo.core.client.AccumuloClient;
+import org.apache.accumulo.core.client.ClientInfo;
 import org.apache.accumulo.core.client.mapreduce.AccumuloInputFormat;
 import org.apache.accumulo.core.data.Key;
 import org.apache.accumulo.core.data.Range;
@@ -174,7 +175,7 @@ public int run(String[] args) throws Exception {
 
     AccumuloInputFormat.setRanges(job, ranges);
     AccumuloInputFormat.setAutoAdjustRanges(job, false);
-    AccumuloInputFormat.setClientInfo(job, env.getInfo());
+    AccumuloInputFormat.setClientInfo(job, ClientInfo.from(env.getClientProps()));
 
     job.setMapperClass(CMapper.class);
     job.setMapOutputKeyClass(LongWritable.class);
diff --git a/src/main/java/org/apache/accumulo/testing/ingest/TestIngest.java b/src/main/java/org/apache/accumulo/testing/ingest/TestIngest.java
index 5702b13..5f058ab 100644
--- a/src/main/java/org/apache/accumulo/testing/ingest/TestIngest.java
+++ b/src/main/java/org/apache/accumulo/testing/ingest/TestIngest.java
@@ -36,6 +36,7 @@
 import org.apache.accumulo.core.clientImpl.TabletServerBatchWriter;
 import org.apache.accumulo.core.client.security.SecurityErrorCode;
 import org.apache.accumulo.core.conf.DefaultConfiguration;
+import org.apache.accumulo.core.crypto.CryptoServiceFactory;
 import org.apache.accumulo.core.data.ConstraintViolationSummary;
 import org.apache.accumulo.core.data.Key;
 import org.apache.accumulo.core.data.Mutation;
@@ -218,7 +219,8 @@ public static void ingest(AccumuloClient client, FileSystem fs, Opts opts, Batch
 
     if (opts.outputFile != null) {
       Configuration conf = CachedConfiguration.getInstance();
-      writer = FileOperations.getInstance().newWriterBuilder().forFile(opts.outputFile + "." + RFile.EXTENSION, fs, conf)
+      writer = FileOperations.getInstance().newWriterBuilder()
+          .forFile(opts.outputFile + "." + RFile.EXTENSION, fs, conf, CryptoServiceFactory.newDefaultInstance())
           .withTableConfiguration(DefaultConfiguration.getInstance()).build();
       writer.startDefaultLocalityGroup();
     } else {
diff --git a/src/main/java/org/apache/accumulo/testing/randomwalk/concurrent/Replication.java b/src/main/java/org/apache/accumulo/testing/randomwalk/concurrent/Replication.java
index 8018df4..85f1fe6 100644
--- a/src/main/java/org/apache/accumulo/testing/randomwalk/concurrent/Replication.java
+++ b/src/main/java/org/apache/accumulo/testing/randomwalk/concurrent/Replication.java
@@ -42,6 +42,7 @@
 import org.apache.accumulo.core.client.Scanner;
 import org.apache.accumulo.core.client.admin.InstanceOperations;
 import org.apache.accumulo.core.client.admin.TableOperations;
+import org.apache.accumulo.core.conf.ClientProperty;
 import org.apache.accumulo.core.data.Key;
 import org.apache.accumulo.core.data.Mutation;
 import org.apache.accumulo.core.data.Value;
@@ -60,14 +61,14 @@
   @Override
   public void visit(State state, RandWalkEnv env, Properties props) throws Exception {
     final AccumuloClient c = env.getAccumuloClient();
-    final String instName = c.info().getInstanceName();
+    final String instName = ClientProperty.INSTANCE_NAME.getValue(c.properties());
+    final String zookeepers = ClientProperty.INSTANCE_ZOOKEEPERS.getValue(c.properties());
     final InstanceOperations iOps = c.instanceOperations();
     final TableOperations tOps = c.tableOperations();
 
     // Replicate to ourselves
     iOps.setProperty(REPLICATION_NAME.getKey(), instName);
-    iOps.setProperty(REPLICATION_PEERS.getKey() + instName, "org.apache.accumulo.tserver.replication.AccumuloReplicaSystem," + instName + ","
-        + c.info().getZooKeepers());
+    iOps.setProperty(REPLICATION_PEERS.getKey() + instName, "org.apache.accumulo.tserver.replication.AccumuloReplicaSystem," + instName + "," + zookeepers);
     iOps.setProperty(REPLICATION_PEER_USER.getKey() + instName, env.getAccumuloUserName());
     iOps.setProperty(REPLICATION_PEER_PASSWORD.getKey() + instName, env.getAccumuloPassword());
     // Tweak some replication parameters to make the replication go faster
diff --git a/src/main/java/org/apache/accumulo/testing/randomwalk/multitable/CopyTool.java b/src/main/java/org/apache/accumulo/testing/randomwalk/multitable/CopyTool.java
index 7831e60..747ec08 100644
--- a/src/main/java/org/apache/accumulo/testing/randomwalk/multitable/CopyTool.java
+++ b/src/main/java/org/apache/accumulo/testing/randomwalk/multitable/CopyTool.java
@@ -17,6 +17,7 @@
 package org.apache.accumulo.testing.randomwalk.multitable;
 
 import java.io.IOException;
+import java.util.Properties;
 
 import org.apache.accumulo.core.client.Accumulo;
 import org.apache.accumulo.core.client.ClientInfo;
@@ -56,7 +57,8 @@ public int run(String[] args) throws Exception {
       return 1;
     }
 
-    ClientInfo info = Accumulo.newClient().from(args[0]).info();
+    Properties props = Accumulo.newClientProperties().from(args[0]).build();
+    ClientInfo info = ClientInfo.from(props);
     job.setInputFormatClass(AccumuloInputFormat.class);
     AccumuloInputFormat.setClientInfo(job, info);
     AccumuloInputFormat.setInputTableName(job, args[1]);
diff --git a/src/main/java/org/apache/accumulo/testing/randomwalk/security/AlterTable.java b/src/main/java/org/apache/accumulo/testing/randomwalk/security/AlterTable.java
index ea30ee3..72ccbc5 100644
--- a/src/main/java/org/apache/accumulo/testing/randomwalk/security/AlterTable.java
+++ b/src/main/java/org/apache/accumulo/testing/randomwalk/security/AlterTable.java
@@ -36,8 +36,7 @@
   @Override
   public void visit(State state, RandWalkEnv env, Properties props) throws Exception {
     String systemUser = WalkingSecurity.get(state, env).getSysUserName();
-    try (AccumuloClient client = env.createClient(systemUser,
-        WalkingSecurity.get(state, env).getSysToken())) {
+    try (AccumuloClient client = env.createClient(systemUser, WalkingSecurity.get(state, env).getSysToken())) {
 
       String tableName = WalkingSecurity.get(state, env).getTableName();
 
diff --git a/src/main/java/org/apache/accumulo/testing/randomwalk/security/CreateTable.java b/src/main/java/org/apache/accumulo/testing/randomwalk/security/CreateTable.java
index 51db1eb..e9d53eb 100644
--- a/src/main/java/org/apache/accumulo/testing/randomwalk/security/CreateTable.java
+++ b/src/main/java/org/apache/accumulo/testing/randomwalk/security/CreateTable.java
@@ -33,8 +33,7 @@
 
   @Override
   public void visit(State state, RandWalkEnv env, Properties props) throws Exception {
-    try (AccumuloClient client = env.createClient(WalkingSecurity.get(state, env).getSysUserName(),
-        WalkingSecurity.get(state, env).getSysToken())) {
+    try (AccumuloClient client = env.createClient(WalkingSecurity.get(state, env).getSysUserName(), WalkingSecurity.get(state, env).getSysToken())) {
 
       String tableName = WalkingSecurity.get(state, env).getTableName();
 
diff --git a/src/main/java/org/apache/accumulo/testing/randomwalk/security/SecurityFixture.java b/src/main/java/org/apache/accumulo/testing/randomwalk/security/SecurityFixture.java
index a61eed9..cbc5464 100644
--- a/src/main/java/org/apache/accumulo/testing/randomwalk/security/SecurityFixture.java
+++ b/src/main/java/org/apache/accumulo/testing/randomwalk/security/SecurityFixture.java
@@ -35,7 +35,7 @@
   public void setUp(State state, RandWalkEnv env) throws Exception {
     String secTableName, systemUserName, tableUserName, secNamespaceName;
     // A best-effort sanity check to guard against not password-based auth
-    if (env.getInfo().getProperties().getProperty(ClientProperty.AUTH_TYPE.getKey()).equals("kerberos")) {
+    if (env.getClientProps().getProperty(ClientProperty.AUTH_TYPE.getKey()).equals("kerberos")) {
       throw new IllegalStateException("Security module currently cannot support Kerberos/SASL instances");
     }
 
diff --git a/src/main/java/org/apache/accumulo/testing/randomwalk/sequential/MapRedVerifyTool.java b/src/main/java/org/apache/accumulo/testing/randomwalk/sequential/MapRedVerifyTool.java
index b67c11b..2f98bc2 100644
--- a/src/main/java/org/apache/accumulo/testing/randomwalk/sequential/MapRedVerifyTool.java
+++ b/src/main/java/org/apache/accumulo/testing/randomwalk/sequential/MapRedVerifyTool.java
@@ -18,6 +18,7 @@
 
 import java.io.IOException;
 import java.util.Iterator;
+import java.util.Properties;
 
 import org.apache.accumulo.core.client.Accumulo;
 import org.apache.accumulo.core.client.ClientInfo;
@@ -87,11 +88,11 @@ public int run(String[] args) throws Exception {
       return 1;
     }
 
-    ClientInfo info = Accumulo.newClient().from(args[0]).info();
-    AccumuloInputFormat.setClientInfo(job, info);
+    Properties props = Accumulo.newClientProperties().from(args[0]).build();
+    AccumuloInputFormat.setClientInfo(job, ClientInfo.from(props));
     AccumuloInputFormat.setInputTableName(job, args[1]);
 
-    AccumuloOutputFormat.setClientInfo(job, info);
+    AccumuloOutputFormat.setClientInfo(job, ClientInfo.from(props));
     AccumuloOutputFormat.setDefaultTableName(job, args[2]);
 
     job.setInputFormatClass(AccumuloInputFormat.class);


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services