accumulo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mwa...@apache.org
Subject [accumulo-testing] branch master updated: Reduced use of ClientInfo (#47)
Date Fri, 07 Dec 2018 15:07:24 GMT
This is an automated email from the ASF dual-hosted git repository.

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


The following commit(s) were added to refs/heads/master by this push:
     new d52c5bf  Reduced use of ClientInfo (#47)
d52c5bf is described below

commit d52c5bf11ece4a9493d74756156f8d5a42cc75d7
Author: Mike Walch <mwalch@apache.org>
AuthorDate: Fri Dec 7 10:07:20 2018 -0500

    Reduced use of ClientInfo (#47)
---
 .../java/org/apache/accumulo/testing/TestEnv.java  | 36 ++++++++++++----------
 .../testing/continuous/ContinuousMoru.java         |  5 +--
 .../testing/continuous/ContinuousVerify.java       |  3 +-
 .../apache/accumulo/testing/ingest/TestIngest.java |  4 ++-
 .../testing/randomwalk/concurrent/Replication.java |  7 +++--
 .../testing/randomwalk/multitable/CopyTool.java    |  4 ++-
 .../testing/randomwalk/security/AlterTable.java    |  3 +-
 .../testing/randomwalk/security/CreateTable.java   |  3 +-
 .../randomwalk/security/SecurityFixture.java       |  2 +-
 .../randomwalk/sequential/MapRedVerifyTool.java    |  7 +++--
 10 files changed, 41 insertions(+), 33 deletions(-)

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 java.util.Properties;
 
 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 @@ public class TestEnv implements AutoCloseable {
 
   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 class TestEnv implements AutoCloseable {
     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 class TestEnv implements AutoCloseable {
     return clientPropsPath;
   }
 
-  public ClientInfo getInfo() {
-    return info;
+  public Properties getClientProps() {
+    return copyProperties(clientProps);
   }
 
   /**
@@ -58,7 +61,7 @@ public class TestEnv implements AutoCloseable {
    * @return username
    */
   public String getAccumuloUserName() {
-    return info.getPrincipal();
+    return ClientProperty.AUTH_PRINCIPAL.getValue(clientProps);
   }
 
   /**
@@ -67,9 +70,9 @@ public class TestEnv implements AutoCloseable {
    * @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 class TestEnv implements AutoCloseable {
    * 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 class TestEnv implements AutoCloseable {
   /**
    * 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.Set;
 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 class ContinuousMoru extends Configured implements Tool {
 
     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 class ContinuousMoru extends Configured implements Tool {
     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.Random;
 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 class ContinuousVerify extends Configured implements Tool {
 
     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.client.TableNotFoundException;
 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 class TestIngest {
 
     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.BatchWriter;
 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 @@ public class Replication extends Test {
   @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 class CopyTool extends Configured implements Tool {
       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 @@ public class AlterTable extends Test {
   @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 @@ public class CreateTable extends Test {
 
   @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 class SecurityFixture extends Fixture {
   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 @@ package org.apache.accumulo.testing.randomwalk.sequential;
 
 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 class MapRedVerifyTool extends Configured implements Tool {
       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);


Mime
View raw message