accumulo-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] ctubbsii commented on a change in pull request #19: Fixes #16 - Refactored examples in client.md
Date Mon, 09 Apr 2018 21:23:38 GMT
ctubbsii commented on a change in pull request #19: Fixes #16 - Refactored examples in client.md
URL: https://github.com/apache/accumulo-examples/pull/19#discussion_r180233549
 
 

 ##########
 File path: src/main/java/org/apache/accumulo/examples/client/ReadWriteExample.java
 ##########
 @@ -17,135 +17,48 @@
 package org.apache.accumulo.examples.client;
 
 import java.util.Map.Entry;
-import java.util.SortedSet;
-import java.util.TreeSet;
 
 import org.apache.accumulo.core.client.BatchWriter;
-import org.apache.accumulo.core.client.BatchWriterConfig;
 import org.apache.accumulo.core.client.Connector;
-import org.apache.accumulo.core.client.Durability;
 import org.apache.accumulo.core.client.Scanner;
-import org.apache.accumulo.core.client.impl.DurabilityImpl;
+import org.apache.accumulo.core.client.TableExistsException;
 import org.apache.accumulo.core.data.Key;
 import org.apache.accumulo.core.data.Mutation;
 import org.apache.accumulo.core.data.Value;
 import org.apache.accumulo.core.security.Authorizations;
-import org.apache.accumulo.core.security.ColumnVisibility;
-import org.apache.accumulo.core.util.ByteArraySet;
-import org.apache.accumulo.examples.cli.ClientOnDefaultTable;
-import org.apache.accumulo.examples.cli.ScannerOpts;
-import org.apache.hadoop.io.Text;
-
-import com.beust.jcommander.IStringConverter;
-import com.beust.jcommander.Parameter;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class ReadWriteExample {
-  // defaults
-  private static final String DEFAULT_AUTHS = "LEVEL1,GROUP1";
-  private static final String DEFAULT_TABLE_NAME = "test";
-
-  private Connector conn;
 
-  static class DurabilityConverter implements IStringConverter<Durability> {
-    @Override
-    public Durability convert(String value) {
-      return DurabilityImpl.fromString(value);
-    }
-  }
-
-  static class Opts extends ClientOnDefaultTable {
-    @Parameter(names = {"--createtable"}, description = "create table before doing anything")
-    boolean createtable = false;
-    @Parameter(names = {"--deletetable"}, description = "delete table when finished")
-    boolean deletetable = false;
-    @Parameter(names = {"--create"}, description = "create entries before any deletes")
-    boolean createEntries = false;
-    @Parameter(names = {"--read"}, description = "read entries after any creates/deletes")
-    boolean readEntries = false;
-    @Parameter(names = {"--delete"}, description = "delete entries after any creates")
-    boolean deleteEntries = false;
-    @Parameter(names = {"--durability"}, description = "durability used for writes (none,
log, flush or sync)", converter = DurabilityConverter.class)
-    Durability durability = Durability.DEFAULT;
-
-    public Opts() {
-      super(DEFAULT_TABLE_NAME);
-      auths = new Authorizations(DEFAULT_AUTHS.split(","));
-    }
-  }
-
-  // hidden constructor
-  private ReadWriteExample() {}
-
-  private void execute(Opts opts, ScannerOpts scanOpts) throws Exception {
-    conn = opts.getConnector();
-
-    // add the authorizations to the user
-    Authorizations userAuthorizations = conn.securityOperations().getUserAuthorizations(opts.getPrincipal());
-    ByteArraySet auths = new ByteArraySet(userAuthorizations.getAuthorizations());
-    auths.addAll(opts.auths.getAuthorizations());
-    if (!auths.isEmpty())
-      conn.securityOperations().changeUserAuthorizations(opts.getPrincipal(), new Authorizations(auths));
-
-    // create table
-    if (opts.createtable) {
-      SortedSet<Text> partitionKeys = new TreeSet<>();
-      for (int i = Byte.MIN_VALUE; i < Byte.MAX_VALUE; i++)
-        partitionKeys.add(new Text(new byte[] {(byte) i}));
-      conn.tableOperations().create(opts.getTableName());
-      conn.tableOperations().addSplits(opts.getTableName(), partitionKeys);
-    }
+  private static final Logger log = LoggerFactory.getLogger(ReadWriteExample.class);
 
 Review comment:
   I wouldn't even bother having a logger for the client code. It may make more sense for
the example client code to just print to the console directly.

----------------------------------------------------------------
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

Mime
View raw message