You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@accumulo.apache.org by ct...@apache.org on 2013/11/08 23:27:02 UTC
[1/4] ACCUMULO-1872 Remove compiler warnings
Updated Branches:
refs/heads/master c00ac6287 -> 4d690b1e0
http://git-wip-us.apache.org/repos/asf/accumulo/blob/7f403df2/minicluster/src/main/java/org/apache/accumulo/minicluster/MiniAccumuloConfig.java
----------------------------------------------------------------------
diff --git a/minicluster/src/main/java/org/apache/accumulo/minicluster/MiniAccumuloConfig.java b/minicluster/src/main/java/org/apache/accumulo/minicluster/MiniAccumuloConfig.java
index 81fbe29..94094ed 100644
--- a/minicluster/src/main/java/org/apache/accumulo/minicluster/MiniAccumuloConfig.java
+++ b/minicluster/src/main/java/org/apache/accumulo/minicluster/MiniAccumuloConfig.java
@@ -27,13 +27,13 @@ import java.util.Map;
*/
public class MiniAccumuloConfig {
-
+
private File dir = null;
private String rootPassword = null;
private Map<String,String> siteConfig = Collections.emptyMap();
private int numTservers = 2;
private boolean runGC = false;
-
+
/**
* @param dir
* An empty or nonexistant temp directoy that Accumulo and Zookeeper can store data in. Creating the directory is left to the user. Java 7, Guava,
@@ -41,64 +41,64 @@ public class MiniAccumuloConfig {
* @param rootPassword
* The initial password for the Accumulo root user
*/
-
+
public MiniAccumuloConfig(File dir, String rootPassword) {
this.dir = dir;
this.rootPassword = rootPassword;
}
-
+
public File getDir() {
return dir;
}
-
+
public String getRootPassword() {
return rootPassword;
}
-
+
public int getNumTservers() {
return numTservers;
}
-
+
/**
* Calling this method is optional. If not set, it defaults to two.
*
* @param numTservers
* the number of tablet servers that mini accumulo cluster should start
*/
-
+
public MiniAccumuloConfig setNumTservers(int numTservers) {
if (numTservers < 1)
throw new IllegalArgumentException("Must have at least one tablet server");
this.numTservers = numTservers;
return this;
}
-
+
public Map<String,String> getSiteConfig() {
return siteConfig;
}
-
+
/**
* Calling this method is optional. If not set, it defautls to an empty map.
*
* @param siteConfig
* key/values that you normally put in accumulo-site.xml can be put here
*/
-
+
public MiniAccumuloConfig setSiteConfig(Map<String,String> siteConfig) {
this.siteConfig = siteConfig;
return this;
}
-
+
/**
* Whether or not the Accumulo garbage collector proces will run
- * @return
*/
public boolean shouldRunGC() {
return runGC;
}
-
+
/**
* Sets if the Accumulo garbage collector process should run
+ *
* @param shouldRunGC
*/
public void runGC(boolean shouldRunGC) {
http://git-wip-us.apache.org/repos/asf/accumulo/blob/7f403df2/server/src/main/java/org/apache/accumulo/server/client/HdfsZooInstance.java
----------------------------------------------------------------------
diff --git a/server/src/main/java/org/apache/accumulo/server/client/HdfsZooInstance.java b/server/src/main/java/org/apache/accumulo/server/client/HdfsZooInstance.java
index 074f3be..ca7e42c 100644
--- a/server/src/main/java/org/apache/accumulo/server/client/HdfsZooInstance.java
+++ b/server/src/main/java/org/apache/accumulo/server/client/HdfsZooInstance.java
@@ -52,74 +52,74 @@ import org.apache.log4j.Logger;
*
*/
public class HdfsZooInstance implements Instance {
-
+
public static class AccumuloNotInitializedException extends RuntimeException {
private static final long serialVersionUID = 1L;
-
+
public AccumuloNotInitializedException(String string) {
super(string);
}
}
-
+
private HdfsZooInstance() {
AccumuloConfiguration acuConf = ServerConfiguration.getSiteConfiguration();
zooCache = new ZooCache(acuConf.get(Property.INSTANCE_ZK_HOST), (int) acuConf.getTimeInMillis(Property.INSTANCE_ZK_TIMEOUT));
}
-
+
private static HdfsZooInstance cachedHdfsZooInstance = null;
-
+
public static synchronized Instance getInstance() {
if (cachedHdfsZooInstance == null)
cachedHdfsZooInstance = new HdfsZooInstance();
return cachedHdfsZooInstance;
}
-
+
private static ZooCache zooCache;
private static String instanceId = null;
private static final Logger log = Logger.getLogger(HdfsZooInstance.class);
-
+
@Override
public String getRootTabletLocation() {
String zRootLocPath = ZooUtil.getRoot(this) + Constants.ZROOT_TABLET_LOCATION;
-
+
OpTimer opTimer = new OpTimer(log, Level.TRACE).start("Looking up root tablet location in zoocache.");
-
+
byte[] loc = zooCache.get(zRootLocPath);
-
+
opTimer.stop("Found root tablet at " + (loc == null ? null : new String(loc)) + " in %DURATION%");
-
+
if (loc == null) {
return null;
}
-
+
return new String(loc).split("\\|")[0];
}
-
+
@Override
public List<String> getMasterLocations() {
-
+
String masterLocPath = ZooUtil.getRoot(this) + Constants.ZMASTER_LOCK;
-
+
OpTimer opTimer = new OpTimer(log, Level.TRACE).start("Looking up master location in zoocache.");
-
+
byte[] loc = ZooLock.getLockData(zooCache, masterLocPath, null);
-
+
opTimer.stop("Found master at " + (loc == null ? null : new String(loc)) + " in %DURATION%");
-
+
if (loc == null) {
return Collections.emptyList();
}
-
+
return Collections.singletonList(new String(loc));
}
-
+
@Override
public String getInstanceID() {
if (instanceId == null)
_getInstanceID();
return instanceId;
}
-
+
private static synchronized void _getInstanceID() {
if (instanceId == null) {
@SuppressWarnings("deprecation")
@@ -127,64 +127,67 @@ public class HdfsZooInstance implements Instance {
instanceId = instanceIdFromFile;
}
}
-
+
@Override
public String getInstanceName() {
return ZooKeeperInstance.lookupInstanceName(zooCache, UUID.fromString(getInstanceID()));
}
-
+
@Override
public String getZooKeepers() {
return ServerConfiguration.getSiteConfiguration().get(Property.INSTANCE_ZK_HOST);
}
-
+
@Override
public int getZooKeepersSessionTimeOut() {
return (int) ServerConfiguration.getSiteConfiguration().getTimeInMillis(Property.INSTANCE_ZK_TIMEOUT);
}
-
+
@Override
// Not really deprecated, just not for client use
public Connector getConnector(String principal, AuthenticationToken token) throws AccumuloException, AccumuloSecurityException {
return getConnector(CredentialHelper.create(principal, token, getInstanceID()));
}
-
+
@SuppressWarnings("deprecation")
private Connector getConnector(TCredentials cred) throws AccumuloException, AccumuloSecurityException {
return new ConnectorImpl(this, cred);
}
-
+
+ @Deprecated
@Override
// Not really deprecated, just not for client use
public Connector getConnector(String user, byte[] pass) throws AccumuloException, AccumuloSecurityException {
return getConnector(user, new PasswordToken(pass));
}
-
+
+ @Deprecated
@Override
// Not really deprecated, just not for client use
public Connector getConnector(String user, ByteBuffer pass) throws AccumuloException, AccumuloSecurityException {
return getConnector(user, ByteBufferUtil.toBytes(pass));
}
-
+
+ @Deprecated
@Override
public Connector getConnector(String user, CharSequence pass) throws AccumuloException, AccumuloSecurityException {
return getConnector(user, TextUtil.getBytes(new Text(pass.toString())));
}
-
+
private AccumuloConfiguration conf = null;
-
+
@Override
public AccumuloConfiguration getConfiguration() {
if (conf == null)
conf = new ServerConfiguration(this).getConfiguration();
return conf;
}
-
+
@Override
public void setConfiguration(AccumuloConfiguration conf) {
this.conf = conf;
}
-
+
public static void main(String[] args) {
Instance instance = HdfsZooInstance.getInstance();
System.out.println("Instance Name: " + instance.getInstanceName());
@@ -192,7 +195,7 @@ public class HdfsZooInstance implements Instance {
System.out.println("ZooKeepers: " + instance.getZooKeepers());
System.out.println("Masters: " + StringUtil.join(instance.getMasterLocations(), ", "));
}
-
+
@Deprecated
@Override
public Connector getConnector(org.apache.accumulo.core.security.thrift.AuthInfo auth) throws AccumuloException, AccumuloSecurityException {
http://git-wip-us.apache.org/repos/asf/accumulo/blob/7f403df2/server/src/main/java/org/apache/accumulo/server/security/SecurityOperation.java
----------------------------------------------------------------------
diff --git a/server/src/main/java/org/apache/accumulo/server/security/SecurityOperation.java b/server/src/main/java/org/apache/accumulo/server/security/SecurityOperation.java
index e167516..2c5aa7d 100644
--- a/server/src/main/java/org/apache/accumulo/server/security/SecurityOperation.java
+++ b/server/src/main/java/org/apache/accumulo/server/security/SecurityOperation.java
@@ -48,21 +48,21 @@ import org.apache.log4j.Logger;
*/
public class SecurityOperation {
private static final Logger log = Logger.getLogger(SecurityOperationsImpl.class);
-
+
protected Authorizor authorizor;
protected Authenticator authenticator;
protected PermissionHandler permHandle;
private static String rootUserName = null;
private final ZooCache zooCache;
private final String ZKUserPath;
-
+
protected static SecurityOperation instance;
-
+
public static synchronized SecurityOperation getInstance() {
String instanceId = HdfsZooInstance.getInstance().getInstanceID();
return getInstance(instanceId, false);
}
-
+
public static synchronized SecurityOperation getInstance(String instanceId, boolean initialize) {
if (instance == null) {
instance = new SecurityOperation(getAuthorizor(instanceId, initialize), getAuthenticator(instanceId, initialize), getPermHandler(instanceId, initialize),
@@ -70,55 +70,56 @@ public class SecurityOperation {
}
return instance;
}
-
+
protected static Authorizor getAuthorizor(String instanceId, boolean initialize) {
Authorizor toRet = Master.createInstanceFromPropertyName(ServerConfiguration.getSiteConfiguration(), Property.INSTANCE_SECURITY_AUTHORIZOR,
Authorizor.class, ZKAuthorizor.getInstance());
toRet.initialize(instanceId, initialize);
return toRet;
}
-
+
protected static Authenticator getAuthenticator(String instanceId, boolean initialize) {
Authenticator toRet = Master.createInstanceFromPropertyName(ServerConfiguration.getSiteConfiguration(), Property.INSTANCE_SECURITY_AUTHENTICATOR,
Authenticator.class, ZKAuthenticator.getInstance());
toRet.initialize(instanceId, initialize);
return toRet;
}
-
+
protected static PermissionHandler getPermHandler(String instanceId, boolean initialize) {
PermissionHandler toRet = Master.createInstanceFromPropertyName(ServerConfiguration.getSiteConfiguration(), Property.INSTANCE_SECURITY_PERMISSION_HANDLER,
PermissionHandler.class, ZKPermHandler.getInstance());
toRet.initialize(instanceId, initialize);
return toRet;
}
-
+
/**
*
* @deprecated not for client use
*/
+ @Deprecated
public SecurityOperation(String instanceId) {
ZKUserPath = Constants.ZROOT + "/" + instanceId + "/users";
zooCache = new ZooCache();
}
-
+
public SecurityOperation(Authorizor author, Authenticator authent, PermissionHandler pm, String instanceId) {
this(instanceId);
authorizor = author;
authenticator = authent;
permHandle = pm;
-
+
if (!authorizor.validSecurityHandlers(authenticator, pm) || !authenticator.validSecurityHandlers(authorizor, pm)
|| !permHandle.validSecurityHandlers(authent, author))
throw new RuntimeException(authorizor + ", " + authenticator + ", and " + pm
+ " do not play nice with eachother. Please choose authentication and authorization mechanisms that are compatible with one another.");
}
-
+
public void initializeSecurity(TCredentials credentials, String rootPrincipal, byte[] token) throws AccumuloSecurityException, ThriftSecurityException {
authenticate(credentials);
-
+
if (!credentials.getPrincipal().equals(SecurityConstants.SYSTEM_PRINCIPAL))
throw new AccumuloSecurityException(credentials.getPrincipal(), SecurityErrorCode.PERMISSION_DENIED);
-
+
authenticator.initializeSecurity(credentials, rootPrincipal, token);
authorizor.initializeSecurity(credentials, rootPrincipal);
permHandle.initializeSecurity(credentials, rootPrincipal);
@@ -129,23 +130,23 @@ public class SecurityOperation {
throw new RuntimeException(e);
}
}
-
+
public synchronized String getRootUsername() {
if (rootUserName == null)
rootUserName = new String(zooCache.get(ZKUserPath));
return rootUserName;
}
-
+
private void authenticate(TCredentials credentials) throws ThriftSecurityException {
if (!credentials.getInstanceId().equals(HdfsZooInstance.getInstance().getInstanceID()))
throw new ThriftSecurityException(credentials.getPrincipal(), SecurityErrorCode.INVALID_INSTANCEID);
-
+
if (SecurityConstants.getSystemCredentials().equals(credentials))
return;
else if (credentials.getPrincipal().equals(SecurityConstants.SYSTEM_PRINCIPAL)) {
throw new ThriftSecurityException(credentials.getPrincipal(), SecurityErrorCode.BAD_CREDENTIALS);
}
-
+
try {
AuthenticationToken token = reassembleToken(credentials);
if (!authenticator.authenticateUser(credentials.getPrincipal(), token)) {
@@ -156,14 +157,14 @@ public class SecurityOperation {
throw e.asThriftException();
}
}
-
+
public boolean canAskAboutUser(TCredentials credentials, String user) throws ThriftSecurityException {
// Authentication done in canPerformSystemActions
if (!(canPerformSystemActions(credentials) || credentials.getPrincipal().equals(user)))
throw new ThriftSecurityException(credentials.getPrincipal(), SecurityErrorCode.PERMISSION_DENIED);
return true;
}
-
+
public boolean authenticateUser(TCredentials credentials, TCredentials toAuth) throws ThriftSecurityException {
canAskAboutUser(credentials, toAuth.getPrincipal());
// User is already authenticated from canAskAboutUser, this gets around issues with !SYSTEM user
@@ -176,7 +177,7 @@ public class SecurityOperation {
throw e.asThriftException();
}
}
-
+
/**
* @param toAuth
* @return
@@ -189,30 +190,30 @@ public class SecurityOperation {
}
throw new AccumuloSecurityException(toAuth.getPrincipal(), SecurityErrorCode.INVALID_TOKEN);
}
-
+
public Authorizations getUserAuthorizations(TCredentials credentials, String user) throws ThriftSecurityException {
authenticate(credentials);
-
+
targetUserExists(user);
-
+
if (!credentials.getPrincipal().equals(user) && !hasSystemPermission(credentials.getPrincipal(), SystemPermission.SYSTEM, false))
throw new ThriftSecurityException(credentials.getPrincipal(), SecurityErrorCode.PERMISSION_DENIED);
-
+
// system user doesn't need record-level authorizations for the tables it reads (for now)
if (user.equals(SecurityConstants.SYSTEM_PRINCIPAL))
return Constants.NO_AUTHS;
-
+
try {
return authorizor.getCachedUserAuthorizations(user);
} catch (AccumuloSecurityException e) {
throw e.asThriftException();
}
}
-
+
public Authorizations getUserAuthorizations(TCredentials credentials) throws ThriftSecurityException {
return getUserAuthorizations(credentials, credentials.getPrincipal());
}
-
+
/**
* Checks if a user has a system permission
*
@@ -221,9 +222,9 @@ public class SecurityOperation {
private boolean hasSystemPermission(String user, SystemPermission permission, boolean useCached) throws ThriftSecurityException {
if (user.equals(getRootUsername()) || user.equals(SecurityConstants.SYSTEM_PRINCIPAL))
return true;
-
+
targetUserExists(user);
-
+
try {
if (useCached)
return permHandle.hasCachedSystemPermission(user, permission);
@@ -232,7 +233,7 @@ public class SecurityOperation {
throw e.asThriftException();
}
}
-
+
/**
* Checks if a user has a table permission
*
@@ -241,12 +242,12 @@ public class SecurityOperation {
private boolean hasTablePermission(String user, String table, TablePermission permission, boolean useCached) throws ThriftSecurityException {
if (user.equals(SecurityConstants.SYSTEM_PRINCIPAL))
return true;
-
+
targetUserExists(user);
-
+
if (table.equals(Constants.METADATA_TABLE_ID) && permission.equals(TablePermission.READ))
return true;
-
+
try {
if (useCached)
return permHandle.hasCachedTablePermission(user, table, permission);
@@ -257,7 +258,7 @@ public class SecurityOperation {
throw new ThriftSecurityException(user, SecurityErrorCode.TABLE_DOESNT_EXIST);
}
}
-
+
// some people just aren't allowed to ask about other users; here are those who can ask
private boolean canAskAboutOtherUsers(TCredentials credentials, String user) throws ThriftSecurityException {
authenticate(credentials);
@@ -266,11 +267,11 @@ public class SecurityOperation {
|| hasSystemPermission(credentials.getPrincipal(), SystemPermission.ALTER_USER, false)
|| hasSystemPermission(credentials.getPrincipal(), SystemPermission.DROP_USER, false);
}
-
+
private void targetUserExists(String user) throws ThriftSecurityException {
if (user.equals(SecurityConstants.SYSTEM_PRINCIPAL) || user.equals(getRootUsername()))
return;
-
+
try {
if (!authenticator.userExists(user))
throw new ThriftSecurityException(user, SecurityErrorCode.USER_DOESNT_EXIST);
@@ -278,24 +279,24 @@ public class SecurityOperation {
throw e.asThriftException();
}
}
-
+
public boolean canScan(TCredentials credentials, String table) throws ThriftSecurityException {
authenticate(credentials);
return hasTablePermission(credentials.getPrincipal(), table, TablePermission.READ, true);
}
-
+
public boolean canWrite(TCredentials credentials, String table) throws ThriftSecurityException {
authenticate(credentials);
return hasTablePermission(credentials.getPrincipal(), table, TablePermission.WRITE, true);
}
-
+
public boolean canSplitTablet(TCredentials credentials, String table) throws ThriftSecurityException {
authenticate(credentials);
return hasSystemPermission(credentials.getPrincipal(), SystemPermission.ALTER_TABLE, false)
|| hasSystemPermission(credentials.getPrincipal(), SystemPermission.SYSTEM, false)
|| hasTablePermission(credentials.getPrincipal(), table, TablePermission.ALTER_TABLE, false);
}
-
+
/**
* This is the check to perform any system action. This includes tserver's loading of a tablet, shutting the system down, or altering system properties.
*/
@@ -303,161 +304,161 @@ public class SecurityOperation {
authenticate(credentials);
return hasSystemPermission(credentials.getPrincipal(), SystemPermission.SYSTEM, false);
}
-
+
public boolean canFlush(TCredentials c, String tableId) throws ThriftSecurityException {
authenticate(c);
return hasTablePermission(c.getPrincipal(), tableId, TablePermission.WRITE, false)
|| hasTablePermission(c.getPrincipal(), tableId, TablePermission.ALTER_TABLE, false);
}
-
+
public boolean canAlterTable(TCredentials c, String tableId) throws ThriftSecurityException {
authenticate(c);
return hasTablePermission(c.getPrincipal(), tableId, TablePermission.ALTER_TABLE, false)
|| hasSystemPermission(c.getPrincipal(), SystemPermission.ALTER_TABLE, false);
}
-
+
public boolean canCreateTable(TCredentials c) throws ThriftSecurityException {
authenticate(c);
return hasSystemPermission(c.getPrincipal(), SystemPermission.CREATE_TABLE, false);
}
-
+
public boolean canRenameTable(TCredentials c, String tableId) throws ThriftSecurityException {
authenticate(c);
return hasSystemPermission(c.getPrincipal(), SystemPermission.ALTER_TABLE, false)
|| hasTablePermission(c.getPrincipal(), tableId, TablePermission.ALTER_TABLE, false);
}
-
+
public boolean canCloneTable(TCredentials c, String tableId) throws ThriftSecurityException {
authenticate(c);
return hasSystemPermission(c.getPrincipal(), SystemPermission.CREATE_TABLE, false)
&& hasTablePermission(c.getPrincipal(), tableId, TablePermission.READ, false);
}
-
+
public boolean canDeleteTable(TCredentials c, String tableId) throws ThriftSecurityException {
authenticate(c);
return hasSystemPermission(c.getPrincipal(), SystemPermission.DROP_TABLE, false)
|| hasTablePermission(c.getPrincipal(), tableId, TablePermission.DROP_TABLE, false);
}
-
+
public boolean canOnlineOfflineTable(TCredentials c, String tableId) throws ThriftSecurityException {
authenticate(c);
return hasSystemPermission(c.getPrincipal(), SystemPermission.SYSTEM, false) || hasSystemPermission(c.getPrincipal(), SystemPermission.ALTER_TABLE, false)
|| hasTablePermission(c.getPrincipal(), tableId, TablePermission.ALTER_TABLE, false);
}
-
+
public boolean canMerge(TCredentials c, String tableId) throws ThriftSecurityException {
authenticate(c);
return hasSystemPermission(c.getPrincipal(), SystemPermission.SYSTEM, false) || hasSystemPermission(c.getPrincipal(), SystemPermission.ALTER_TABLE, false)
|| hasTablePermission(c.getPrincipal(), tableId, TablePermission.ALTER_TABLE, false);
}
-
+
public boolean canDeleteRange(TCredentials c, String tableId) throws ThriftSecurityException {
authenticate(c);
return hasSystemPermission(c.getPrincipal(), SystemPermission.SYSTEM, false) || hasTablePermission(c.getPrincipal(), tableId, TablePermission.WRITE, false);
}
-
+
public boolean canBulkImport(TCredentials c, String tableId) throws ThriftSecurityException {
authenticate(c);
return hasTablePermission(c.getPrincipal(), tableId, TablePermission.BULK_IMPORT, false);
}
-
+
public boolean canCompact(TCredentials c, String tableId) throws ThriftSecurityException {
authenticate(c);
return hasSystemPermission(c.getPrincipal(), SystemPermission.ALTER_TABLE, false)
|| hasTablePermission(c.getPrincipal(), tableId, TablePermission.ALTER_TABLE, false)
|| hasTablePermission(c.getPrincipal(), tableId, TablePermission.WRITE, false);
}
-
+
public boolean canChangeAuthorizations(TCredentials c, String user) throws ThriftSecurityException {
authenticate(c);
if (user.equals(SecurityConstants.SYSTEM_PRINCIPAL))
throw new ThriftSecurityException(c.getPrincipal(), SecurityErrorCode.PERMISSION_DENIED);
return hasSystemPermission(c.getPrincipal(), SystemPermission.ALTER_USER, false);
}
-
+
public boolean canChangePassword(TCredentials c, String user) throws ThriftSecurityException {
authenticate(c);
if (user.equals(SecurityConstants.SYSTEM_PRINCIPAL))
throw new ThriftSecurityException(c.getPrincipal(), SecurityErrorCode.PERMISSION_DENIED);
return c.getPrincipal().equals(user) || hasSystemPermission(c.getPrincipal(), SystemPermission.ALTER_USER, false);
}
-
+
public boolean canCreateUser(TCredentials c, String user) throws ThriftSecurityException {
authenticate(c);
-
+
// don't allow creating a user with the same name as system user
if (user.equals(SecurityConstants.SYSTEM_PRINCIPAL))
throw new ThriftSecurityException(c.getPrincipal(), SecurityErrorCode.PERMISSION_DENIED);
-
+
return hasSystemPermission(c.getPrincipal(), SystemPermission.CREATE_USER, false);
}
-
+
public boolean canDropUser(TCredentials c, String user) throws ThriftSecurityException {
authenticate(c);
-
+
// can't delete root or system users
if (user.equals(getRootUsername()) || user.equals(SecurityConstants.SYSTEM_PRINCIPAL))
throw new ThriftSecurityException(c.getPrincipal(), SecurityErrorCode.PERMISSION_DENIED);
-
+
return hasSystemPermission(c.getPrincipal(), SystemPermission.DROP_USER, false);
}
-
+
public boolean canGrantSystem(TCredentials c, String user, SystemPermission sysPerm) throws ThriftSecurityException {
authenticate(c);
-
+
// can't modify system user
if (user.equals(SecurityConstants.SYSTEM_PRINCIPAL))
throw new ThriftSecurityException(c.getPrincipal(), SecurityErrorCode.PERMISSION_DENIED);
-
+
// can't grant GRANT
if (sysPerm.equals(SystemPermission.GRANT))
throw new ThriftSecurityException(c.getPrincipal(), SecurityErrorCode.GRANT_INVALID);
-
+
return hasSystemPermission(c.getPrincipal(), SystemPermission.GRANT, false);
}
-
+
public boolean canGrantTable(TCredentials c, String user, String table) throws ThriftSecurityException {
authenticate(c);
-
+
// can't modify system user
if (user.equals(SecurityConstants.SYSTEM_PRINCIPAL))
throw new ThriftSecurityException(c.getPrincipal(), SecurityErrorCode.PERMISSION_DENIED);
-
+
return hasSystemPermission(c.getPrincipal(), SystemPermission.ALTER_TABLE, false)
|| hasTablePermission(c.getPrincipal(), table, TablePermission.GRANT, false);
}
-
+
public boolean canRevokeSystem(TCredentials c, String user, SystemPermission sysPerm) throws ThriftSecurityException {
authenticate(c);
-
+
// can't modify system or root user
if (user.equals(getRootUsername()) || user.equals(SecurityConstants.SYSTEM_PRINCIPAL))
throw new ThriftSecurityException(c.getPrincipal(), SecurityErrorCode.PERMISSION_DENIED);
-
+
// can't revoke GRANT
if (sysPerm.equals(SystemPermission.GRANT))
throw new ThriftSecurityException(c.getPrincipal(), SecurityErrorCode.GRANT_INVALID);
-
+
return hasSystemPermission(c.getPrincipal(), SystemPermission.GRANT, false);
}
-
+
public boolean canRevokeTable(TCredentials c, String user, String table) throws ThriftSecurityException {
authenticate(c);
-
+
// can't modify system user
if (user.equals(SecurityConstants.SYSTEM_PRINCIPAL))
throw new ThriftSecurityException(c.getPrincipal(), SecurityErrorCode.PERMISSION_DENIED);
-
+
return hasSystemPermission(c.getPrincipal(), SystemPermission.ALTER_TABLE, false)
|| hasTablePermission(c.getPrincipal(), table, TablePermission.GRANT, false);
}
-
+
public void changeAuthorizations(TCredentials credentials, String user, Authorizations authorizations) throws ThriftSecurityException {
if (!canChangeAuthorizations(credentials, user))
throw new ThriftSecurityException(credentials.getPrincipal(), SecurityErrorCode.PERMISSION_DENIED);
-
+
targetUserExists(user);
-
+
try {
authorizor.changeAuthorizations(user, authorizations);
log.info("Changed authorizations for user " + user + " at the request of user " + credentials.getPrincipal());
@@ -465,7 +466,7 @@ public class SecurityOperation {
throw ase.asThriftException();
}
}
-
+
public void changePassword(TCredentials credentials, TCredentials toChange) throws ThriftSecurityException {
if (!canChangePassword(credentials, toChange.getPrincipal()))
throw new ThriftSecurityException(credentials.getPrincipal(), SecurityErrorCode.PERMISSION_DENIED);
@@ -477,7 +478,7 @@ public class SecurityOperation {
throw e.asThriftException();
}
}
-
+
public void createUser(TCredentials credentials, TCredentials newUser, Authorizations authorizations) throws ThriftSecurityException {
if (!canCreateUser(credentials, newUser.getPrincipal()))
throw new ThriftSecurityException(credentials.getPrincipal(), SecurityErrorCode.PERMISSION_DENIED);
@@ -493,7 +494,7 @@ public class SecurityOperation {
throw ase.asThriftException();
}
}
-
+
public void dropUser(TCredentials credentials, String user) throws ThriftSecurityException {
if (!canDropUser(credentials, user))
throw new ThriftSecurityException(credentials.getPrincipal(), SecurityErrorCode.PERMISSION_DENIED);
@@ -506,13 +507,13 @@ public class SecurityOperation {
throw e.asThriftException();
}
}
-
+
public void grantSystemPermission(TCredentials credentials, String user, SystemPermission permissionById) throws ThriftSecurityException {
if (!canGrantSystem(credentials, user, permissionById))
throw new ThriftSecurityException(credentials.getPrincipal(), SecurityErrorCode.PERMISSION_DENIED);
-
+
targetUserExists(user);
-
+
try {
permHandle.grantSystemPermission(user, permissionById);
log.info("Granted system permission " + permissionById + " for user " + user + " at the request of user " + credentials.getPrincipal());
@@ -520,13 +521,13 @@ public class SecurityOperation {
throw e.asThriftException();
}
}
-
+
public void grantTablePermission(TCredentials c, String user, String tableId, TablePermission permission) throws ThriftSecurityException {
if (!canGrantTable(c, user, tableId))
throw new ThriftSecurityException(c.getPrincipal(), SecurityErrorCode.PERMISSION_DENIED);
-
+
targetUserExists(user);
-
+
try {
permHandle.grantTablePermission(user, tableId, permission);
log.info("Granted table permission " + permission + " for user " + user + " on the table " + tableId + " at the request of user " + c.getPrincipal());
@@ -536,51 +537,51 @@ public class SecurityOperation {
throw new ThriftSecurityException(c.getPrincipal(), SecurityErrorCode.TABLE_DOESNT_EXIST);
}
}
-
+
public void revokeSystemPermission(TCredentials credentials, String user, SystemPermission permission) throws ThriftSecurityException {
if (!canRevokeSystem(credentials, user, permission))
throw new ThriftSecurityException(credentials.getPrincipal(), SecurityErrorCode.PERMISSION_DENIED);
-
+
targetUserExists(user);
-
+
try {
permHandle.revokeSystemPermission(user, permission);
log.info("Revoked system permission " + permission + " for user " + user + " at the request of user " + credentials.getPrincipal());
-
+
} catch (AccumuloSecurityException e) {
throw e.asThriftException();
}
}
-
+
public void revokeTablePermission(TCredentials c, String user, String tableId, TablePermission permission) throws ThriftSecurityException {
if (!canRevokeTable(c, user, tableId))
throw new ThriftSecurityException(c.getPrincipal(), SecurityErrorCode.PERMISSION_DENIED);
-
+
targetUserExists(user);
-
+
try {
permHandle.revokeTablePermission(user, tableId, permission);
log.info("Revoked table permission " + permission + " for user " + user + " on the table " + tableId + " at the request of user " + c.getPrincipal());
-
+
} catch (AccumuloSecurityException e) {
throw e.asThriftException();
} catch (TableNotFoundException e) {
throw new ThriftSecurityException(c.getPrincipal(), SecurityErrorCode.TABLE_DOESNT_EXIST);
}
}
-
+
public boolean hasSystemPermission(TCredentials credentials, String user, SystemPermission permissionById) throws ThriftSecurityException {
if (!canAskAboutOtherUsers(credentials, user))
throw new ThriftSecurityException(credentials.getPrincipal(), SecurityErrorCode.PERMISSION_DENIED);
return hasSystemPermission(user, permissionById, false);
}
-
+
public boolean hasTablePermission(TCredentials credentials, String user, String tableId, TablePermission permissionById) throws ThriftSecurityException {
if (!canAskAboutOtherUsers(credentials, user))
throw new ThriftSecurityException(credentials.getPrincipal(), SecurityErrorCode.PERMISSION_DENIED);
return hasTablePermission(user, tableId, permissionById, false);
}
-
+
public Set<String> listUsers(TCredentials credentials) throws ThriftSecurityException {
authenticate(credentials);
try {
@@ -589,7 +590,7 @@ public class SecurityOperation {
throw e.asThriftException();
}
}
-
+
public void deleteTable(TCredentials credentials, String tableId) throws ThriftSecurityException {
if (!canDeleteTable(credentials, tableId))
throw new ThriftSecurityException(credentials.getPrincipal(), SecurityErrorCode.PERMISSION_DENIED);
@@ -602,12 +603,12 @@ public class SecurityOperation {
throw new ThriftSecurityException(credentials.getPrincipal(), SecurityErrorCode.TABLE_DOESNT_EXIST);
}
}
-
+
public boolean canExport(TCredentials credentials, String tableId) throws ThriftSecurityException {
authenticate(credentials);
return hasTablePermission(credentials.getPrincipal(), tableId, TablePermission.READ, false);
}
-
+
public boolean canImport(TCredentials credentials) throws ThriftSecurityException {
authenticate(credentials);
return hasSystemPermission(credentials.getPrincipal(), SystemPermission.CREATE_TABLE, false);
http://git-wip-us.apache.org/repos/asf/accumulo/blob/7f403df2/server/src/main/java/org/apache/accumulo/server/tabletserver/log/DfsLogger.java
----------------------------------------------------------------------
diff --git a/server/src/main/java/org/apache/accumulo/server/tabletserver/log/DfsLogger.java b/server/src/main/java/org/apache/accumulo/server/tabletserver/log/DfsLogger.java
index 9ab9f28..2235242 100644
--- a/server/src/main/java/org/apache/accumulo/server/tabletserver/log/DfsLogger.java
+++ b/server/src/main/java/org/apache/accumulo/server/tabletserver/log/DfsLogger.java
@@ -53,11 +53,11 @@ import org.apache.hadoop.fs.FSDataInputStream;
import org.apache.hadoop.fs.FSDataOutputStream;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
-//import org.apache.hadoop.fs.CreateFlag;
-//import org.apache.hadoop.fs.Syncable;
import org.apache.hadoop.fs.permission.FsPermission;
import org.apache.hadoop.util.Progressable;
import org.apache.log4j.Logger;
+//import org.apache.hadoop.fs.CreateFlag;
+//import org.apache.hadoop.fs.Syncable;
/**
* Wrap a connection to a logger.
@@ -66,50 +66,50 @@ import org.apache.log4j.Logger;
public class DfsLogger {
// Package private so that LogSorter can find this
static final String LOG_FILE_HEADER_V2 = "--- Log File Header (v2) ---";
-
+
private static Logger log = Logger.getLogger(DfsLogger.class);
-
+
public static class LogClosedException extends IOException {
private static final long serialVersionUID = 1L;
-
+
public LogClosedException() {
super("LogClosed");
}
}
-
+
public interface ServerResources {
AccumuloConfiguration getConfiguration();
-
+
FileSystem getFileSystem();
-
+
Set<TServerInstance> getCurrentTServers();
}
-
+
private final LinkedBlockingQueue<DfsLogger.LogWork> workQueue = new LinkedBlockingQueue<DfsLogger.LogWork>();
-
+
private final Object closeLock = new Object();
-
+
private static final DfsLogger.LogWork CLOSED_MARKER = new DfsLogger.LogWork(null, null);
-
+
private static final LogFileValue EMPTY = new LogFileValue();
-
+
private boolean closed = false;
-
+
private class LogSyncingTask implements Runnable {
-
+
@Override
public void run() {
ArrayList<DfsLogger.LogWork> work = new ArrayList<DfsLogger.LogWork>();
while (true) {
work.clear();
-
+
try {
work.add(workQueue.take());
} catch (InterruptedException ex) {
continue;
}
workQueue.drainTo(work);
-
+
synchronized (closeLock) {
if (!closed) {
try {
@@ -126,14 +126,14 @@ public class DfsLogger {
}
}
}
-
+
boolean sawClosedMarker = false;
for (DfsLogger.LogWork logWork : work)
if (logWork == CLOSED_MARKER)
sawClosedMarker = true;
else
logWork.latch.countDown();
-
+
if (sawClosedMarker) {
synchronized (closeLock) {
closeLock.notifyAll();
@@ -143,32 +143,32 @@ public class DfsLogger {
}
}
}
-
+
static class LogWork {
List<TabletMutations> mutations;
CountDownLatch latch;
volatile Exception exception;
-
+
public LogWork(List<TabletMutations> mutations, CountDownLatch latch) {
this.mutations = mutations;
this.latch = latch;
}
}
-
+
public static class LoggerOperation {
private final LogWork work;
-
+
public LoggerOperation(LogWork work) {
this.work = work;
}
-
+
public void await() throws IOException {
try {
work.latch.await();
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
-
+
if (work.exception != null) {
if (work.exception instanceof IOException)
throw (IOException) work.exception;
@@ -179,7 +179,7 @@ public class DfsLogger {
}
}
}
-
+
/*
* (non-Javadoc)
*
@@ -194,7 +194,7 @@ public class DfsLogger {
return getFileName().equals(((DfsLogger) obj).getFileName());
return false;
}
-
+
/*
* (non-Javadoc)
*
@@ -205,24 +205,24 @@ public class DfsLogger {
// filename is unique
return getFileName().hashCode();
}
-
+
private final ServerResources conf;
private FSDataOutputStream logFile;
private DataOutputStream encryptingLogFile = null;
private Method sync;
private Path logPath;
private String logger;
-
+
public DfsLogger(ServerResources conf) throws IOException {
this.conf = conf;
}
-
+
public DfsLogger(ServerResources conf, String logger, String filename) throws IOException {
this.conf = conf;
this.logger = logger;
this.logPath = new Path(Constants.getWalDirectory(conf.getConfiguration()), filename);
}
-
+
public static FSDataInputStream readHeader(FileSystem fs, Path path, Map<String,String> opts) throws IOException {
FSDataInputStream file = fs.open(path);
try {
@@ -246,19 +246,19 @@ public class DfsLogger {
return file;
}
}
-
+
public synchronized void open(String address) throws IOException {
String filename = UUID.randomUUID().toString();
logger = StringUtil.join(Arrays.asList(address.split(":")), "+");
-
+
log.debug("DfsLogger.open() begin");
-
+
logPath = new Path(Constants.getWalDirectory(conf.getConfiguration()) + "/" + logger + "/" + filename);
try {
FileSystem fs = conf.getFileSystem();
short replication = (short) conf.getConfiguration().getCount(Property.TSERV_WAL_REPLICATION);
if (replication == 0)
- replication = fs.getDefaultReplication();
+ replication = fs.getDefaultReplication(logPath);
long blockSize = conf.getConfiguration().getMemoryInBytes(Property.TSERV_WAL_BLOCKSIZE);
if (blockSize == 0)
blockSize = (long) (conf.getConfiguration().getMemoryInBytes(Property.TSERV_WALOG_MAX_SIZE) * 1.1);
@@ -269,38 +269,36 @@ public class DfsLogger {
logFile = create(fs, logPath, true, fs.getConf().getInt("io.file.buffer.size", 4096), replication, blockSize);
else
logFile = fs.create(logPath, true, fs.getConf().getInt("io.file.buffer.size", 4096), replication, blockSize);
-
+
try {
// sync: send data to datanodes
sync = logFile.getClass().getMethod("sync");
try {
// hsych: send data to datanodes and sync the data to disk
sync = logFile.getClass().getMethod("hsync");
- } catch (NoSuchMethodException ex) {
- }
+ } catch (NoSuchMethodException ex) {}
} catch (Exception e) {
throw new RuntimeException(e);
}
-
-
+
// Initialize the crypto operations.
@SuppressWarnings("deprecation")
org.apache.accumulo.core.security.crypto.CryptoModule cryptoModule = org.apache.accumulo.core.security.crypto.CryptoModuleFactory.getCryptoModule(conf
.getConfiguration().get(Property.CRYPTO_MODULE_CLASS));
-
+
// Initialize the log file with a header and the crypto params used to set up this log file.
logFile.write(LOG_FILE_HEADER_V2.getBytes());
Map<String,String> cryptoOpts = conf.getConfiguration().getAllPropertiesWithPrefix(Property.CRYPTO_PREFIX);
-
+
logFile.writeInt(cryptoOpts.size());
for (String key : cryptoOpts.keySet()) {
logFile.writeUTF(key);
logFile.writeUTF(cryptoOpts.get(key));
}
-
+
@SuppressWarnings("deprecation")
OutputStream encipheringOutputStream = cryptoModule.getEncryptingOutputStream(logFile, cryptoOpts);
-
+
// If the module just kicks back our original stream, then just use it, don't wrap it in
// another data OutputStream.
if (encipheringOutputStream == logFile) {
@@ -308,7 +306,7 @@ public class DfsLogger {
} else {
encryptingLogFile = new DataOutputStream(encipheringOutputStream);
}
-
+
LogFileKey key = new LogFileKey();
key.event = OPEN;
key.tserverSession = filename;
@@ -322,28 +320,28 @@ public class DfsLogger {
logFile = null;
throw ex;
}
-
+
Thread t = new Daemon(new LogSyncingTask());
t.setName("Accumulo WALog thread " + toString());
t.start();
}
-
+
private FSDataOutputStream create(FileSystem fs, Path logPath, boolean b, int buffersize, short replication, long blockSize) throws IOException {
try {
- // This...
- // EnumSet<CreateFlag> set = EnumSet.of(CreateFlag.SYNC_BLOCK, CreateFlag.CREATE);
- // return fs.create(logPath, FsPermission.getDefault(), set, buffersize, replication, blockSize, null);
+ // This...
+ // EnumSet<CreateFlag> set = EnumSet.of(CreateFlag.SYNC_BLOCK, CreateFlag.CREATE);
+ // return fs.create(logPath, FsPermission.getDefault(), set, buffersize, replication, blockSize, null);
// Becomes this:
Class<?> createFlags = Class.forName("org.apache.hadoop.fs.CreateFlag");
List<Enum<?>> flags = new ArrayList<Enum<?>>();
if (createFlags.isEnum()) {
for (Object constant : createFlags.getEnumConstants()) {
if (constant.toString().equals("SYNC_BLOCK")) {
- flags.add((Enum<?>)constant);
+ flags.add((Enum<?>) constant);
log.debug("Found synch enum " + constant);
}
if (constant.toString().equals("CREATE")) {
- flags.add((Enum<?>)constant);
+ flags.add((Enum<?>) constant);
log.debug("Found CREATE enum " + constant);
}
}
@@ -351,11 +349,11 @@ public class DfsLogger {
Object set = EnumSet.class.getMethod("of", java.lang.Enum.class, java.lang.Enum.class).invoke(null, flags.get(0), flags.get(1));
log.debug("CreateFlag set: " + set);
if (fs instanceof TraceFileSystem) {
- fs = ((TraceFileSystem)fs).getImplementation();
+ fs = ((TraceFileSystem) fs).getImplementation();
}
Method create = fs.getClass().getMethod("create", Path.class, FsPermission.class, EnumSet.class, Integer.TYPE, Short.TYPE, Long.TYPE, Progressable.class);
log.debug("creating " + logPath + " with SYNCH_BLOCK flag");
- return (FSDataOutputStream)create.invoke(fs, logPath, FsPermission.getDefault(), set, buffersize, replication, blockSize, null);
+ return (FSDataOutputStream) create.invoke(fs, logPath, FsPermission.getDefault(), set, buffersize, replication, blockSize, null);
} catch (ClassNotFoundException ex) {
// Expected in hadoop 1.0
return fs.create(logPath, b, buffersize, replication, blockSize);
@@ -374,17 +372,17 @@ public class DfsLogger {
public String toString() {
return getLogger() + "/" + getFileName();
}
-
+
public String getLogger() {
return logger;
}
-
+
public String getFileName() {
return logPath.getName();
}
-
+
public void close() throws IOException {
-
+
synchronized (closeLock) {
if (closed)
return;
@@ -402,7 +400,7 @@ public class DfsLogger {
log.info("Interrupted");
}
}
-
+
if (logFile != null)
try {
logFile.close();
@@ -411,7 +409,7 @@ public class DfsLogger {
throw new LogClosedException();
}
}
-
+
public synchronized void defineTablet(int seq, int tid, KeyExtent tablet) throws IOException {
// write this log to the METADATA table
final LogFileKey key = new LogFileKey();
@@ -427,7 +425,7 @@ public class DfsLogger {
throw ex;
}
}
-
+
/**
* @param key
* @param empty2
@@ -437,14 +435,14 @@ public class DfsLogger {
key.write(encryptingLogFile);
value.write(encryptingLogFile);
}
-
+
public LoggerOperation log(int seq, int tid, Mutation mutation) throws IOException {
return logManyTablets(Collections.singletonList(new TabletMutations(tid, seq, Collections.singletonList(mutation))));
}
-
+
public LoggerOperation logManyTablets(List<TabletMutations> mutations) throws IOException {
DfsLogger.LogWork work = new DfsLogger.LogWork(mutations, new CountDownLatch(1));
-
+
synchronized (DfsLogger.this) {
try {
for (TabletMutations tabletMutations : mutations) {
@@ -461,19 +459,19 @@ public class DfsLogger {
work.exception = e;
}
}
-
+
synchronized (closeLock) {
// use a different lock for close check so that adding to work queue does not need
// to wait on walog I/O operations
-
+
if (closed)
throw new LogClosedException();
workQueue.add(work);
}
-
+
return new LoggerOperation(work);
}
-
+
public synchronized void minorCompactionFinished(int seq, int tid, String fqfn) throws IOException {
LogFileKey key = new LogFileKey();
key.event = COMPACTION_FINISH;
@@ -486,7 +484,7 @@ public class DfsLogger {
throw ex;
}
}
-
+
public synchronized void minorCompactionStarted(int seq, int tid, String fqfn) throws IOException {
LogFileKey key = new LogFileKey();
key.event = COMPACTION_START;
@@ -500,5 +498,5 @@ public class DfsLogger {
throw ex;
}
}
-
+
}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/7f403df2/server/src/main/java/org/apache/accumulo/server/trace/TraceFileSystem.java
----------------------------------------------------------------------
diff --git a/server/src/main/java/org/apache/accumulo/server/trace/TraceFileSystem.java b/server/src/main/java/org/apache/accumulo/server/trace/TraceFileSystem.java
index 5a212cb..71cc562 100644
--- a/server/src/main/java/org/apache/accumulo/server/trace/TraceFileSystem.java
+++ b/server/src/main/java/org/apache/accumulo/server/trace/TraceFileSystem.java
@@ -38,7 +38,7 @@ import org.apache.hadoop.util.Progressable;
// If FileSystem was an interface, we could use a Proxy, but it's not, so we have to override everything manually
public class TraceFileSystem extends FileSystem {
-
+
@Override
public void setConf(Configuration conf) {
Span span = Trace.start("setConf");
@@ -51,7 +51,7 @@ public class TraceFileSystem extends FileSystem {
span.stop();
}
}
-
+
@Override
public Configuration getConf() {
Span span = Trace.start("getConf");
@@ -61,7 +61,7 @@ public class TraceFileSystem extends FileSystem {
span.stop();
}
}
-
+
@Override
public BlockLocation[] getFileBlockLocations(FileStatus file, long start, long len) throws IOException {
Span span = Trace.start("getFileBlockLocations");
@@ -71,7 +71,7 @@ public class TraceFileSystem extends FileSystem {
span.stop();
}
}
-
+
@Override
public FSDataInputStream open(Path f) throws IOException {
Span span = Trace.start("open");
@@ -83,7 +83,7 @@ public class TraceFileSystem extends FileSystem {
span.stop();
}
}
-
+
@Override
public FSDataOutputStream create(Path f) throws IOException {
Span span = Trace.start("create");
@@ -95,7 +95,7 @@ public class TraceFileSystem extends FileSystem {
span.stop();
}
}
-
+
@Override
public FSDataOutputStream create(Path f, boolean overwrite) throws IOException {
Span span = Trace.start("create");
@@ -107,20 +107,20 @@ public class TraceFileSystem extends FileSystem {
span.stop();
}
}
-
+
@Override
public FSDataOutputStream create(Path f, Progressable progress) throws IOException {
Span span = Trace.start("create");
if (Trace.isTracing())
span.data("path", f.toString());
try {
-
+
return impl.create(f, progress);
} finally {
span.stop();
}
}
-
+
@Override
public FSDataOutputStream create(Path f, short replication) throws IOException {
Span span = Trace.start("create");
@@ -132,7 +132,7 @@ public class TraceFileSystem extends FileSystem {
span.stop();
}
}
-
+
@Override
public FSDataOutputStream create(Path f, short replication, Progressable progress) throws IOException {
Span span = Trace.start("create");
@@ -144,7 +144,7 @@ public class TraceFileSystem extends FileSystem {
span.stop();
}
}
-
+
@Override
public FSDataOutputStream create(Path f, boolean overwrite, int bufferSize) throws IOException {
Span span = Trace.start("create");
@@ -156,7 +156,7 @@ public class TraceFileSystem extends FileSystem {
span.stop();
}
}
-
+
@Override
public FSDataOutputStream create(Path f, boolean overwrite, int bufferSize, Progressable progress) throws IOException {
Span span = Trace.start("create");
@@ -168,7 +168,7 @@ public class TraceFileSystem extends FileSystem {
span.stop();
}
}
-
+
@Override
public FSDataOutputStream create(Path f, boolean overwrite, int bufferSize, short replication, long blockSize) throws IOException {
Span span = Trace.start("create");
@@ -180,7 +180,7 @@ public class TraceFileSystem extends FileSystem {
span.stop();
}
}
-
+
@Override
public FSDataOutputStream create(Path f, boolean overwrite, int bufferSize, short replication, long blockSize, Progressable progress) throws IOException {
Span span = Trace.start("create");
@@ -192,7 +192,7 @@ public class TraceFileSystem extends FileSystem {
span.stop();
}
}
-
+
@Override
public boolean createNewFile(Path f) throws IOException {
Span span = Trace.start("createNewFile");
@@ -204,7 +204,7 @@ public class TraceFileSystem extends FileSystem {
span.stop();
}
}
-
+
@Override
public FSDataOutputStream append(Path f) throws IOException {
Span span = Trace.start("append");
@@ -216,7 +216,7 @@ public class TraceFileSystem extends FileSystem {
span.stop();
}
}
-
+
@Override
public FSDataOutputStream append(Path f, int bufferSize) throws IOException {
Span span = Trace.start("append");
@@ -228,7 +228,7 @@ public class TraceFileSystem extends FileSystem {
span.stop();
}
}
-
+
@Deprecated
@Override
public short getReplication(Path src) throws IOException {
@@ -241,7 +241,7 @@ public class TraceFileSystem extends FileSystem {
span.stop();
}
}
-
+
@Override
public boolean setReplication(Path src, short replication) throws IOException {
Span span = Trace.start("setReplication");
@@ -253,7 +253,7 @@ public class TraceFileSystem extends FileSystem {
span.stop();
}
}
-
+
@Override
public boolean exists(Path f) throws IOException {
Span span = Trace.start("exists");
@@ -265,7 +265,8 @@ public class TraceFileSystem extends FileSystem {
span.stop();
}
}
-
+
+ @Deprecated
@Override
public boolean isDirectory(Path f) throws IOException {
Span span = Trace.start("isDirectory");
@@ -277,7 +278,7 @@ public class TraceFileSystem extends FileSystem {
span.stop();
}
}
-
+
@Override
public boolean isFile(Path f) throws IOException {
Span span = Trace.start("isFile");
@@ -289,7 +290,7 @@ public class TraceFileSystem extends FileSystem {
span.stop();
}
}
-
+
@SuppressWarnings("deprecation")
@Override
public long getLength(Path f) throws IOException {
@@ -302,7 +303,7 @@ public class TraceFileSystem extends FileSystem {
span.stop();
}
}
-
+
@Override
public ContentSummary getContentSummary(Path f) throws IOException {
Span span = Trace.start("getContentSummary");
@@ -314,7 +315,7 @@ public class TraceFileSystem extends FileSystem {
span.stop();
}
}
-
+
@Override
public FileStatus[] listStatus(Path f, PathFilter filter) throws IOException {
Span span = Trace.start("listStatus");
@@ -326,7 +327,7 @@ public class TraceFileSystem extends FileSystem {
span.stop();
}
}
-
+
@Override
public FileStatus[] listStatus(Path[] files) throws IOException {
Span span = Trace.start("listStatus");
@@ -336,7 +337,7 @@ public class TraceFileSystem extends FileSystem {
span.stop();
}
}
-
+
@Override
public FileStatus[] listStatus(Path[] files, PathFilter filter) throws IOException {
Span span = Trace.start("listStatus");
@@ -346,7 +347,7 @@ public class TraceFileSystem extends FileSystem {
span.stop();
}
}
-
+
@Override
public FileStatus[] globStatus(Path pathPattern) throws IOException {
Span span = Trace.start("globStatus");
@@ -358,7 +359,7 @@ public class TraceFileSystem extends FileSystem {
span.stop();
}
}
-
+
@Override
public FileStatus[] globStatus(Path pathPattern, PathFilter filter) throws IOException {
Span span = Trace.start("globStatus");
@@ -370,7 +371,7 @@ public class TraceFileSystem extends FileSystem {
span.stop();
}
}
-
+
@Override
public Path getHomeDirectory() {
Span span = Trace.start("getHomeDirectory");
@@ -380,7 +381,7 @@ public class TraceFileSystem extends FileSystem {
span.stop();
}
}
-
+
@Override
public boolean mkdirs(Path f) throws IOException {
Span span = Trace.start("mkdirs");
@@ -392,7 +393,7 @@ public class TraceFileSystem extends FileSystem {
span.stop();
}
}
-
+
@Override
public void copyFromLocalFile(Path src, Path dst) throws IOException {
Span span = Trace.start("copyFromLocalFile");
@@ -406,7 +407,7 @@ public class TraceFileSystem extends FileSystem {
span.stop();
}
}
-
+
@Override
public void moveFromLocalFile(Path[] srcs, Path dst) throws IOException {
Span span = Trace.start("moveFromLocalFile");
@@ -419,7 +420,7 @@ public class TraceFileSystem extends FileSystem {
span.stop();
}
}
-
+
@Override
public void moveFromLocalFile(Path src, Path dst) throws IOException {
Span span = Trace.start("moveFromLocalFile");
@@ -433,7 +434,7 @@ public class TraceFileSystem extends FileSystem {
span.stop();
}
}
-
+
@Override
public void copyFromLocalFile(boolean delSrc, Path src, Path dst) throws IOException {
Span span = Trace.start("copyFromLocalFile");
@@ -447,7 +448,7 @@ public class TraceFileSystem extends FileSystem {
span.stop();
}
}
-
+
@Override
public void copyFromLocalFile(boolean delSrc, boolean overwrite, Path[] srcs, Path dst) throws IOException {
Span span = Trace.start("copyFromLocalFile");
@@ -460,7 +461,7 @@ public class TraceFileSystem extends FileSystem {
span.stop();
}
}
-
+
@Override
public void copyFromLocalFile(boolean delSrc, boolean overwrite, Path src, Path dst) throws IOException {
Span span = Trace.start("copyFromLocalFile");
@@ -474,7 +475,7 @@ public class TraceFileSystem extends FileSystem {
span.stop();
}
}
-
+
@Override
public void copyToLocalFile(Path src, Path dst) throws IOException {
Span span = Trace.start("copyFromLocalFile");
@@ -488,7 +489,7 @@ public class TraceFileSystem extends FileSystem {
span.stop();
}
}
-
+
@Override
public void moveToLocalFile(Path src, Path dst) throws IOException {
Span span = Trace.start("moveToLocalFile");
@@ -502,7 +503,7 @@ public class TraceFileSystem extends FileSystem {
span.stop();
}
}
-
+
@Override
public void copyToLocalFile(boolean delSrc, Path src, Path dst) throws IOException {
Span span = Trace.start("copyToLocalFile");
@@ -516,7 +517,7 @@ public class TraceFileSystem extends FileSystem {
span.stop();
}
}
-
+
@Override
public Path startLocalOutput(Path fsOutputFile, Path tmpLocalFile) throws IOException {
Span span = Trace.start("startLocalOutput");
@@ -530,7 +531,7 @@ public class TraceFileSystem extends FileSystem {
span.stop();
}
}
-
+
@Override
public void completeLocalOutput(Path fsOutputFile, Path tmpLocalFile) throws IOException {
Span span = Trace.start("completeLocalOutput");
@@ -544,7 +545,7 @@ public class TraceFileSystem extends FileSystem {
span.stop();
}
}
-
+
@Override
public void close() throws IOException {
Span span = Trace.start("close");
@@ -554,7 +555,7 @@ public class TraceFileSystem extends FileSystem {
span.stop();
}
}
-
+
@Override
public long getUsed() throws IOException {
Span span = Trace.start("getUsed");
@@ -564,7 +565,7 @@ public class TraceFileSystem extends FileSystem {
span.stop();
}
}
-
+
@SuppressWarnings("deprecation")
@Override
public long getBlockSize(Path f) throws IOException {
@@ -578,7 +579,8 @@ public class TraceFileSystem extends FileSystem {
span.stop();
}
}
-
+
+ @Deprecated
@Override
public long getDefaultBlockSize() {
Span span = Trace.start("getDefaultBlockSize");
@@ -588,7 +590,8 @@ public class TraceFileSystem extends FileSystem {
span.stop();
}
}
-
+
+ @Deprecated
@Override
public short getDefaultReplication() {
Span span = Trace.start("getDefaultReplication");
@@ -598,7 +601,7 @@ public class TraceFileSystem extends FileSystem {
span.stop();
}
}
-
+
@Override
public FileChecksum getFileChecksum(Path f) throws IOException {
Span span = Trace.start("getFileChecksum");
@@ -611,7 +614,7 @@ public class TraceFileSystem extends FileSystem {
span.stop();
}
}
-
+
@Override
public void setVerifyChecksum(boolean verifyChecksum) {
Span span = Trace.start("setVerifyChecksum");
@@ -621,7 +624,7 @@ public class TraceFileSystem extends FileSystem {
span.stop();
}
}
-
+
@Override
public void setPermission(Path p, FsPermission permission) throws IOException {
Span span = Trace.start("setPermission");
@@ -634,7 +637,7 @@ public class TraceFileSystem extends FileSystem {
span.stop();
}
}
-
+
@Override
public void setOwner(Path p, String username, String groupname) throws IOException {
Span span = Trace.start("setOwner");
@@ -643,14 +646,14 @@ public class TraceFileSystem extends FileSystem {
span.data("user", username);
span.data("group", groupname);
}
-
+
try {
impl.setOwner(p, username, groupname);
} finally {
span.stop();
}
}
-
+
@Override
public void setTimes(Path p, long mtime, long atime) throws IOException {
Span span = Trace.start("setTimes");
@@ -660,18 +663,18 @@ public class TraceFileSystem extends FileSystem {
span.stop();
}
}
-
+
final FileSystem impl;
-
+
TraceFileSystem(FileSystem impl) {
ArgumentChecker.notNull(impl);
this.impl = impl;
}
-
+
public FileSystem getImplementation() {
return impl;
}
-
+
@Override
public URI getUri() {
Span span = Trace.start("getUri");
@@ -681,7 +684,7 @@ public class TraceFileSystem extends FileSystem {
span.stop();
}
}
-
+
@Override
public FSDataInputStream open(Path f, int bufferSize) throws IOException {
Span span = Trace.start("open");
@@ -691,7 +694,7 @@ public class TraceFileSystem extends FileSystem {
span.stop();
}
}
-
+
@Override
public FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize, short replication, long blockSize, Progressable progress)
throws IOException {
@@ -702,7 +705,7 @@ public class TraceFileSystem extends FileSystem {
span.stop();
}
}
-
+
@Override
public void initialize(URI name, Configuration conf) throws IOException {
Span span = Trace.start("initialize");
@@ -712,7 +715,7 @@ public class TraceFileSystem extends FileSystem {
span.stop();
}
}
-
+
@Override
public FSDataOutputStream append(Path f, int bufferSize, Progressable progress) throws IOException {
Span span = Trace.start("append");
@@ -722,7 +725,7 @@ public class TraceFileSystem extends FileSystem {
span.stop();
}
}
-
+
@Override
public boolean rename(Path src, Path dst) throws IOException {
Span span = Trace.start("rename");
@@ -732,7 +735,7 @@ public class TraceFileSystem extends FileSystem {
span.stop();
}
}
-
+
@SuppressWarnings("deprecation")
@Override
public boolean delete(Path f) throws IOException {
@@ -743,7 +746,7 @@ public class TraceFileSystem extends FileSystem {
span.stop();
}
}
-
+
@Override
public boolean delete(Path f, boolean recursive) throws IOException {
Span span = Trace.start("delete");
@@ -753,7 +756,7 @@ public class TraceFileSystem extends FileSystem {
span.stop();
}
}
-
+
@Override
public FileStatus[] listStatus(Path f) throws IOException {
Span span = Trace.start("listStatus");
@@ -763,7 +766,7 @@ public class TraceFileSystem extends FileSystem {
span.stop();
}
}
-
+
@Override
public void setWorkingDirectory(Path new_dir) {
Span span = Trace.start("setWorkingDirectory");
@@ -773,7 +776,7 @@ public class TraceFileSystem extends FileSystem {
span.stop();
}
}
-
+
@Override
public Path getWorkingDirectory() {
Span span = Trace.start("getWorkingDirectory");
@@ -783,7 +786,7 @@ public class TraceFileSystem extends FileSystem {
span.stop();
}
}
-
+
@Override
public boolean mkdirs(Path f, FsPermission permission) throws IOException {
Span span = Trace.start("mkdirs");
@@ -793,7 +796,7 @@ public class TraceFileSystem extends FileSystem {
span.stop();
}
}
-
+
@Override
public FileStatus getFileStatus(Path f) throws IOException {
Span span = Trace.start("getFileStatus");
@@ -803,13 +806,13 @@ public class TraceFileSystem extends FileSystem {
span.stop();
}
}
-
+
public static FileSystem wrap(FileSystem fileSystem) {
return new TraceFileSystem(fileSystem);
}
-
+
public static FileSystem getAndWrap(Configuration conf) throws IOException {
return wrap(FileSystem.get(conf));
}
-
+
}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/7f403df2/test/src/test/java/org/apache/accumulo/test/randomwalk/FrameworkTest.java
----------------------------------------------------------------------
diff --git a/test/src/test/java/org/apache/accumulo/test/randomwalk/FrameworkTest.java b/test/src/test/java/org/apache/accumulo/test/randomwalk/FrameworkTest.java
index 7829ac5..d43347e 100644
--- a/test/src/test/java/org/apache/accumulo/test/randomwalk/FrameworkTest.java
+++ b/test/src/test/java/org/apache/accumulo/test/randomwalk/FrameworkTest.java
@@ -17,7 +17,6 @@
package org.apache.accumulo.test.randomwalk;
import java.io.File;
-import java.util.Properties;
import javax.xml.XMLConstants;
import javax.xml.parsers.DocumentBuilder;
@@ -31,12 +30,12 @@ import org.apache.accumulo.test.randomwalk.unit.CreateTable;
import org.junit.Assert;
public class FrameworkTest extends TestCase {
-
+
public void testXML() {
-
+
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder docbuilder;
-
+
SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema moduleSchema = null;
try {
@@ -44,9 +43,9 @@ public class FrameworkTest extends TestCase {
} catch (Exception e) {
Assert.fail("Caught exception: " + e);
}
-
+
dbf.setSchema(moduleSchema);
-
+
try {
File f = new File(this.getClass().getResource("/randomwalk/Basic.xml").toURI());
docbuilder = dbf.newDocumentBuilder();
@@ -55,14 +54,14 @@ public class FrameworkTest extends TestCase {
Assert.fail("Caught exception: " + e);
}
}
-
+
public void testRWTest() {
-
+
Test t1 = new CreateTable();
assertTrue(t1.toString().equals("org.apache.accumulo.test.randomwalk.unit.CreateTable"));
-
+
Test t2 = new CreateTable();
assertTrue(t1.equals(t2));
}
-
+
}
[3/4] git commit: Merge branch '1.5.1-SNAPSHOT' into 1.6.0-SNAPSHOT
Posted by ct...@apache.org.
Merge branch '1.5.1-SNAPSHOT' into 1.6.0-SNAPSHOT
Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo
Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/c68066db
Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/c68066db
Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/c68066db
Branch: refs/heads/master
Commit: c68066db46540e9b6d92c77e3a1edcae5349cdc6
Parents: fdc6c62 7f403df
Author: Christopher Tubbs <ct...@apache.org>
Authored: Fri Nov 8 17:25:55 2013 -0500
Committer: Christopher Tubbs <ct...@apache.org>
Committed: Fri Nov 8 17:25:55 2013 -0500
----------------------------------------------------------------------
----------------------------------------------------------------------
[2/4] git commit: ACCUMULO-1872 Remove compiler warnings
Posted by ct...@apache.org.
ACCUMULO-1872 Remove compiler warnings
Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo
Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/7f403df2
Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/7f403df2
Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/7f403df2
Branch: refs/heads/master
Commit: 7f403df24a29c57cc5d4758b4aa552c237b68fff
Parents: 422aaaa
Author: Christopher Tubbs <ct...@apache.org>
Authored: Fri Nov 8 17:17:50 2013 -0500
Committer: Christopher Tubbs <ct...@apache.org>
Committed: Fri Nov 8 17:17:50 2013 -0500
----------------------------------------------------------------------
.../core/client/AccumuloSecurityException.java | 20 +-
.../accumulo/core/client/IteratorSetting.java | 61 ++--
.../core/client/MutationsRejectedException.java | 15 +-
.../core/client/admin/TableOperationsImpl.java | 313 ++++++++++---------
.../mapreduce/lib/util/ConfiguratorBase.java | 38 +--
.../core/client/mock/MockTableOperations.java | 80 ++---
.../core/client/security/tokens/NullToken.java | 23 +-
.../accumulo/core/security/Authorizations.java | 82 +++--
.../client/admin/TableOperationsHelperTest.java | 90 +++---
.../examples/simple/client/TracingExample.java | 201 ++++++------
.../minicluster/MiniAccumuloConfig.java | 28 +-
.../accumulo/server/client/HdfsZooInstance.java | 71 +++--
.../server/security/SecurityOperation.java | 199 ++++++------
.../server/tabletserver/log/DfsLogger.java | 138 ++++----
.../accumulo/server/trace/TraceFileSystem.java | 147 ++++-----
.../accumulo/test/randomwalk/FrameworkTest.java | 19 +-
16 files changed, 763 insertions(+), 762 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/accumulo/blob/7f403df2/core/src/main/java/org/apache/accumulo/core/client/AccumuloSecurityException.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/client/AccumuloSecurityException.java b/core/src/main/java/org/apache/accumulo/core/client/AccumuloSecurityException.java
index 4c429e4..890db36 100644
--- a/core/src/main/java/org/apache/accumulo/core/client/AccumuloSecurityException.java
+++ b/core/src/main/java/org/apache/accumulo/core/client/AccumuloSecurityException.java
@@ -25,7 +25,7 @@ import org.apache.accumulo.core.client.impl.thrift.ThriftSecurityException;
*/
public class AccumuloSecurityException extends Exception {
private static final long serialVersionUID = 1L;
-
+
private static String getDefaultErrorMessage(final SecurityErrorCode errorcode) {
switch (errorcode) {
case BAD_CREDENTIALS:
@@ -61,17 +61,17 @@ public class AccumuloSecurityException extends Exception {
return "Unknown security exception";
}
}
-
+
private String user;
private SecurityErrorCode errorCode;
-
+
/**
* @return this exception as a thrift exception
*/
public ThriftSecurityException asThriftException() {
return new ThriftSecurityException(user, errorCode);
}
-
+
/**
* @param user
* the relevant user for the security violation
@@ -85,7 +85,7 @@ public class AccumuloSecurityException extends Exception {
this.user = user;
this.errorCode = errorcode == null ? SecurityErrorCode.DEFAULT_SECURITY_ERROR : errorcode;
}
-
+
/**
* @param user
* the relevant user for the security violation
@@ -97,18 +97,18 @@ public class AccumuloSecurityException extends Exception {
this.user = user;
this.errorCode = errorcode == null ? SecurityErrorCode.DEFAULT_SECURITY_ERROR : errorcode;
}
-
+
/**
* @return the relevant user for the security violation
*/
public String getUser() {
return user;
}
-
+
public void setUser(String s) {
this.user = s;
}
-
+
/**
* @return the specific reason for this exception
* @since 1.5.0
@@ -123,10 +123,12 @@ public class AccumuloSecurityException extends Exception {
*
* @deprecated since 1.5.0; Use {@link #getSecurityErrorCode()} instead.
*/
+ @Deprecated
public org.apache.accumulo.core.security.thrift.SecurityErrorCode getErrorCode() {
return org.apache.accumulo.core.security.thrift.SecurityErrorCode.valueOf(errorCode.name());
}
-
+
+ @Override
public String getMessage() {
return "Error " + errorCode + " for user " + user + " - " + super.getMessage();
}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/7f403df2/core/src/main/java/org/apache/accumulo/core/client/IteratorSetting.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/client/IteratorSetting.java b/core/src/main/java/org/apache/accumulo/core/client/IteratorSetting.java
index 70a7e45..85e996a 100644
--- a/core/src/main/java/org/apache/accumulo/core/client/IteratorSetting.java
+++ b/core/src/main/java/org/apache/accumulo/core/client/IteratorSetting.java
@@ -52,7 +52,7 @@ public class IteratorSetting implements Writable {
private String name;
private String iteratorClass;
private Map<String,String> properties;
-
+
/**
* Get layer at which this iterator applies. See {@link #setPriority(int)} for how the priority is used.
*
@@ -61,7 +61,7 @@ public class IteratorSetting implements Writable {
public int getPriority() {
return priority;
}
-
+
/**
* Set layer at which this iterator applies.
*
@@ -73,7 +73,7 @@ public class IteratorSetting implements Writable {
ArgumentChecker.strictlyPositive(priority);
this.priority = priority;
}
-
+
/**
* Get the iterator's name.
*
@@ -82,7 +82,7 @@ public class IteratorSetting implements Writable {
public String getName() {
return name;
}
-
+
/**
* Set the iterator's name. Must be a simple alphanumeric identifier.
*
@@ -92,7 +92,7 @@ public class IteratorSetting implements Writable {
ArgumentChecker.notNull(name);
this.name = name;
}
-
+
/**
* Get the name of the class that implements the iterator.
*
@@ -101,7 +101,7 @@ public class IteratorSetting implements Writable {
public String getIteratorClass() {
return iteratorClass;
}
-
+
/**
* Set the name of the class that implements the iterator. The class does not have to be present on the client, but it must be available to all tablet
* servers.
@@ -112,7 +112,7 @@ public class IteratorSetting implements Writable {
ArgumentChecker.notNull(iteratorClass);
this.iteratorClass = iteratorClass;
}
-
+
/**
* Constructs an iterator setting configured for the scan scope with no parameters. (Parameters can be added later.)
*
@@ -126,7 +126,7 @@ public class IteratorSetting implements Writable {
public IteratorSetting(int priority, String name, String iteratorClass) {
this(priority, name, iteratorClass, new HashMap<String,String>());
}
-
+
/**
* Constructs an iterator setting configured for the specified scopes with the specified parameters.
*
@@ -146,7 +146,7 @@ public class IteratorSetting implements Writable {
this.properties = new HashMap<String,String>();
addOptions(properties);
}
-
+
/**
* Constructs an iterator setting using the given class's SimpleName for the iterator name. The iterator setting will be configured for the scan scope with no
* parameters.
@@ -159,7 +159,7 @@ public class IteratorSetting implements Writable {
public IteratorSetting(int priority, Class<? extends SortedKeyValueIterator<Key,Value>> iteratorClass) {
this(priority, iteratorClass.getSimpleName(), iteratorClass.getName());
}
-
+
/**
*
* Constructs an iterator setting using the given class's SimpleName for the iterator name and configured for the specified scopes with the specified
@@ -175,7 +175,7 @@ public class IteratorSetting implements Writable {
public IteratorSetting(int priority, Class<? extends SortedKeyValueIterator<Key,Value>> iteratorClass, Map<String,String> properties) {
this(priority, iteratorClass.getSimpleName(), iteratorClass.getName(), properties);
}
-
+
/**
* Constructs an iterator setting configured for the scan scope with no parameters.
*
@@ -189,7 +189,7 @@ public class IteratorSetting implements Writable {
public IteratorSetting(int priority, String name, Class<? extends SortedKeyValueIterator<Key,Value>> iteratorClass) {
this(priority, name, iteratorClass.getName());
}
-
+
/**
* @since 1.5.0
*/
@@ -210,7 +210,7 @@ public class IteratorSetting implements Writable {
ArgumentChecker.notNull(option, value);
properties.put(option, value);
}
-
+
/**
* Remove an option from the iterator.
*
@@ -222,7 +222,7 @@ public class IteratorSetting implements Writable {
ArgumentChecker.notNull(option);
return properties.remove(option);
}
-
+
/**
* Add many options to the iterator.
*
@@ -235,7 +235,7 @@ public class IteratorSetting implements Writable {
addOption(keyValue.getKey(), keyValue.getValue());
}
}
-
+
/**
* Add many options to the iterator.
*
@@ -246,7 +246,7 @@ public class IteratorSetting implements Writable {
ArgumentChecker.notNull(properties);
addOptions(properties.entrySet());
}
-
+
/**
* Get the configuration parameters for this iterator.
*
@@ -255,14 +255,14 @@ public class IteratorSetting implements Writable {
public Map<String,String> getOptions() {
return Collections.unmodifiableMap(properties);
}
-
+
/**
* Remove all options from the iterator.
*/
public void clearOptions() {
properties.clear();
}
-
+
/**
* @see java.lang.Object#hashCode()
*/
@@ -276,10 +276,7 @@ public class IteratorSetting implements Writable {
result = prime * result + ((properties == null) ? 0 : properties.hashCode());
return result;
}
-
- /**
- * @see java.lang.Object#equals()
- */
+
@Override
public boolean equals(Object obj) {
if (this == obj)
@@ -325,38 +322,38 @@ public class IteratorSetting implements Writable {
sb.append(properties);
return sb.toString();
}
-
+
/**
* A convenience class for passing column family and column qualifiers to iterator configuration methods.
*/
public static class Column extends Pair<Text,Text> {
-
+
public Column(Text columnFamily, Text columnQualifier) {
super(columnFamily, columnQualifier);
}
-
+
public Column(Text columnFamily) {
super(columnFamily, null);
}
-
+
public Column(String columnFamily, String columnQualifier) {
super(new Text(columnFamily), new Text(columnQualifier));
}
-
+
public Column(String columnFamily) {
super(new Text(columnFamily), null);
}
-
+
public Text getColumnFamily() {
return getFirst();
}
-
+
public Text getColumnQualifier() {
return getSecond();
}
-
+
}
-
+
/**
* @since 1.5.0
*/
@@ -372,7 +369,7 @@ public class IteratorSetting implements Writable {
size--;
}
}
-
+
/**
* @since 1.5.0
*/
http://git-wip-us.apache.org/repos/asf/accumulo/blob/7f403df2/core/src/main/java/org/apache/accumulo/core/client/MutationsRejectedException.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/client/MutationsRejectedException.java b/core/src/main/java/org/apache/accumulo/core/client/MutationsRejectedException.java
index 25fc43c..03b914c 100644
--- a/core/src/main/java/org/apache/accumulo/core/client/MutationsRejectedException.java
+++ b/core/src/main/java/org/apache/accumulo/core/client/MutationsRejectedException.java
@@ -33,12 +33,12 @@ import org.apache.accumulo.core.data.KeyExtent;
*/
public class MutationsRejectedException extends AccumuloException {
private static final long serialVersionUID = 1L;
-
+
private List<ConstraintViolationSummary> cvsl;
private Map<KeyExtent,Set<SecurityErrorCode>> af;
private Collection<String> es;
private int unknownErrors;
-
+
/**
* @param cvsList
* list of constraint violations
@@ -58,22 +58,23 @@ public class MutationsRejectedException extends AccumuloException {
this.es = serverSideErrors;
this.unknownErrors = unknownErrors;
}
-
+
/**
* @return the internal list of constraint violations
*/
public List<ConstraintViolationSummary> getConstraintViolationSummaries() {
return cvsl;
}
-
+
/**
* @return the internal list of authorization failures
* @deprecated since 1.5, see {@link #getAuthorizationFailuresMap()}
*/
+ @Deprecated
public List<KeyExtent> getAuthorizationFailures() {
return new ArrayList<KeyExtent>(af.keySet());
}
-
+
/**
* @return the internal mapping of keyextent mappings to SecurityErrorCode
* @since 1.5.0
@@ -81,7 +82,7 @@ public class MutationsRejectedException extends AccumuloException {
public Map<KeyExtent,Set<SecurityErrorCode>> getAuthorizationFailuresMap() {
return af;
}
-
+
/**
*
* @return A list of servers that had internal errors when mutations were written
@@ -90,7 +91,7 @@ public class MutationsRejectedException extends AccumuloException {
public Collection<String> getErrorServers() {
return es;
}
-
+
/**
*
* @return a count of unknown exceptions that occurred during processing
http://git-wip-us.apache.org/repos/asf/accumulo/blob/7f403df2/core/src/main/java/org/apache/accumulo/core/client/admin/TableOperationsImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/client/admin/TableOperationsImpl.java b/core/src/main/java/org/apache/accumulo/core/client/admin/TableOperationsImpl.java
index 3aca348..cdb813a 100644
--- a/core/src/main/java/org/apache/accumulo/core/client/admin/TableOperationsImpl.java
+++ b/core/src/main/java/org/apache/accumulo/core/client/admin/TableOperationsImpl.java
@@ -112,11 +112,11 @@ import org.apache.thrift.transport.TTransportException;
public class TableOperationsImpl extends TableOperationsHelper {
private Instance instance;
private TCredentials credentials;
-
+
public static final String CLONE_EXCLUDE_PREFIX = "!";
private static final Logger log = Logger.getLogger(TableOperations.class);
-
+
/**
* @param instance
* the connection information for this instance
@@ -128,7 +128,7 @@ public class TableOperationsImpl extends TableOperationsHelper {
this.instance = instance;
this.credentials = credentials;
}
-
+
/**
* Retrieve a list of tables in Accumulo.
*
@@ -141,7 +141,7 @@ public class TableOperationsImpl extends TableOperationsHelper {
opTimer.stop("Fetched " + tableNames.size() + " table names in %DURATION%");
return tableNames;
}
-
+
/**
* A method to check if a table exists in Accumulo.
*
@@ -154,13 +154,13 @@ public class TableOperationsImpl extends TableOperationsHelper {
ArgumentChecker.notNull(tableName);
if (tableName.equals(Constants.METADATA_TABLE_NAME))
return true;
-
+
OpTimer opTimer = new OpTimer(log, Level.TRACE).start("Checking if table " + tableName + "exists...");
boolean exists = Tables.getNameToIdMap(instance).containsKey(tableName);
opTimer.stop("Checked existance of " + exists + " in %DURATION%");
return exists;
}
-
+
/**
* Create a table with no special configuration
*
@@ -177,7 +177,7 @@ public class TableOperationsImpl extends TableOperationsHelper {
public void create(String tableName) throws AccumuloException, AccumuloSecurityException, TableExistsException {
create(tableName, true, TimeType.MILLIS);
}
-
+
/**
* @param tableName
* the name of the table
@@ -188,7 +188,7 @@ public class TableOperationsImpl extends TableOperationsHelper {
public void create(String tableName, boolean limitVersion) throws AccumuloException, AccumuloSecurityException, TableExistsException {
create(tableName, limitVersion, TimeType.MILLIS);
}
-
+
/**
* @param tableName
* the name of the table
@@ -200,11 +200,11 @@ public class TableOperationsImpl extends TableOperationsHelper {
@Override
public void create(String tableName, boolean limitVersion, TimeType timeType) throws AccumuloException, AccumuloSecurityException, TableExistsException {
ArgumentChecker.notNull(tableName, timeType);
-
+
List<ByteBuffer> args = Arrays.asList(ByteBuffer.wrap(tableName.getBytes()), ByteBuffer.wrap(timeType.name().getBytes()));
-
+
Map<String,String> opts = IteratorUtil.generateInitialTableProperties(limitVersion);
-
+
try {
doTableOperation(TableOperation.CREATE, args, opts);
} catch (TableNotFoundException e1) {
@@ -212,7 +212,7 @@ public class TableOperationsImpl extends TableOperationsHelper {
throw new RuntimeException(e1);
}
}
-
+
private long beginTableOperation() throws ThriftSecurityException, TException {
while (true) {
MasterClientService.Iface client = null;
@@ -227,7 +227,7 @@ public class TableOperationsImpl extends TableOperationsHelper {
}
}
}
-
+
private void executeTableOperation(long opid, TableOperation op, List<ByteBuffer> args, Map<String,String> opts, boolean autoCleanUp)
throws ThriftSecurityException, TException, ThriftTableOperationException {
while (true) {
@@ -244,7 +244,7 @@ public class TableOperationsImpl extends TableOperationsHelper {
}
}
}
-
+
private String waitForTableOperation(long opid) throws ThriftSecurityException, TException, ThriftTableOperationException {
while (true) {
MasterClientService.Iface client = null;
@@ -259,7 +259,7 @@ public class TableOperationsImpl extends TableOperationsHelper {
}
}
}
-
+
private void finishTableOperation(long opid) throws ThriftSecurityException, TException {
while (true) {
MasterClientService.Iface client = null;
@@ -275,16 +275,16 @@ public class TableOperationsImpl extends TableOperationsHelper {
}
}
}
-
+
private String doTableOperation(TableOperation op, List<ByteBuffer> args, Map<String,String> opts) throws AccumuloSecurityException, TableExistsException,
TableNotFoundException, AccumuloException {
return doTableOperation(op, args, opts, true);
}
-
+
private String doTableOperation(TableOperation op, List<ByteBuffer> args, Map<String,String> opts, boolean wait) throws AccumuloSecurityException,
TableExistsException, TableNotFoundException, AccumuloException {
Long opid = null;
-
+
try {
opid = beginTableOperation();
executeTableOperation(opid, op, args, opts, !wait);
@@ -321,14 +321,14 @@ public class TableOperationsImpl extends TableOperationsHelper {
}
}
}
-
+
private static class SplitEnv {
private String tableName;
private String tableId;
private ExecutorService executor;
private CountDownLatch latch;
private AtomicReference<Exception> exception;
-
+
SplitEnv(String tableName, String tableId, ExecutorService executor, CountDownLatch latch, AtomicReference<Exception> exception) {
this.tableName = tableName;
this.tableId = tableId;
@@ -337,47 +337,47 @@ public class TableOperationsImpl extends TableOperationsHelper {
this.exception = exception;
}
}
-
+
private class SplitTask implements Runnable {
-
+
private List<Text> splits;
private SplitEnv env;
-
+
SplitTask(SplitEnv env, List<Text> splits) {
this.env = env;
this.splits = splits;
}
-
+
@Override
public void run() {
try {
if (env.exception.get() != null)
return;
-
+
if (splits.size() <= 2) {
addSplits(env.tableName, new TreeSet<Text>(splits), env.tableId);
for (int i = 0; i < splits.size(); i++)
env.latch.countDown();
return;
}
-
+
int mid = splits.size() / 2;
-
+
// split the middle split point to ensure that child task split different tablets and can therefore
// run in parallel
addSplits(env.tableName, new TreeSet<Text>(splits.subList(mid, mid + 1)), env.tableId);
env.latch.countDown();
-
+
env.executor.submit(new SplitTask(env, splits.subList(0, mid)));
env.executor.submit(new SplitTask(env, splits.subList(mid + 1, splits.size())));
-
+
} catch (Exception e) {
env.exception.compareAndSet(null, e);
}
}
-
+
}
-
+
/**
* @param tableName
* the name of the table
@@ -393,19 +393,19 @@ public class TableOperationsImpl extends TableOperationsHelper {
@Override
public void addSplits(String tableName, SortedSet<Text> partitionKeys) throws TableNotFoundException, AccumuloException, AccumuloSecurityException {
String tableId = Tables.getTableId(instance, tableName);
-
+
List<Text> splits = new ArrayList<Text>(partitionKeys);
// should be sorted because we copied from a sorted set, but that makes assumptions about
// how the copy was done so resort to be sure.
Collections.sort(splits);
-
+
CountDownLatch latch = new CountDownLatch(splits.size());
AtomicReference<Exception> exception = new AtomicReference<Exception>(null);
-
+
ExecutorService executor = Executors.newFixedThreadPool(16, new NamingThreadFactory("addSplits"));
try {
executor.submit(new SplitTask(new SplitEnv(tableName, tableId, executor, latch, exception), splits));
-
+
while (!latch.await(100, TimeUnit.MILLISECONDS)) {
if (exception.get() != null) {
executor.shutdownNow();
@@ -428,24 +428,24 @@ public class TableOperationsImpl extends TableOperationsHelper {
executor.shutdown();
}
}
-
+
private void addSplits(String tableName, SortedSet<Text> partitionKeys, String tableId) throws AccumuloException, AccumuloSecurityException,
TableNotFoundException, AccumuloServerException {
TabletLocator tabLocator = TabletLocator.getInstance(instance, new Text(tableId));
-
+
for (Text split : partitionKeys) {
boolean successful = false;
int attempt = 0;
-
+
while (!successful) {
-
+
if (attempt > 0)
UtilWaitThread.sleep(100);
-
+
attempt++;
-
+
TabletLocation tl = tabLocator.locateTablet(split, false, false, credentials);
-
+
if (tl == null) {
if (!Tables.exists(instance, tableId))
throw new TableNotFoundException(tableId, tableName, null);
@@ -453,25 +453,25 @@ public class TableOperationsImpl extends TableOperationsHelper {
throw new TableOfflineException(instance, tableId);
continue;
}
-
+
try {
TabletClientService.Client client = ThriftUtil.getTServerClient(tl.tablet_location, instance.getConfiguration());
try {
OpTimer opTimer = null;
if (log.isTraceEnabled())
opTimer = new OpTimer(log, Level.TRACE).start("Splitting tablet " + tl.tablet_extent + " on " + tl.tablet_location + " at " + split);
-
+
client.splitTablet(Tracer.traceInfo(), credentials, tl.tablet_extent.toThrift(), TextUtil.getByteBuffer(split));
-
+
// just split it, might as well invalidate it in the cache
tabLocator.invalidateCache(tl.tablet_extent);
-
+
if (opTimer != null)
opTimer.stop("Split tablet in %DURATION%");
} finally {
ThriftUtil.returnClient(client);
}
-
+
} catch (TApplicationException tae) {
throw new AccumuloServerException(tl.tablet_location, tae);
} catch (TTransportException e) {
@@ -489,15 +489,15 @@ public class TableOperationsImpl extends TableOperationsHelper {
tabLocator.invalidateCache(tl.tablet_location);
continue;
}
-
+
successful = true;
}
}
}
-
+
@Override
public void merge(String tableName, Text start, Text end) throws AccumuloException, AccumuloSecurityException, TableNotFoundException {
-
+
ArgumentChecker.notNull(tableName);
ByteBuffer EMPTY = ByteBuffer.allocate(0);
List<ByteBuffer> args = Arrays.asList(ByteBuffer.wrap(tableName.getBytes()), start == null ? EMPTY : TextUtil.getByteBuffer(start), end == null ? EMPTY
@@ -510,10 +510,10 @@ public class TableOperationsImpl extends TableOperationsHelper {
throw new RuntimeException(e);
}
}
-
+
@Override
public void deleteRows(String tableName, Text start, Text end) throws AccumuloException, AccumuloSecurityException, TableNotFoundException {
-
+
ArgumentChecker.notNull(tableName);
ByteBuffer EMPTY = ByteBuffer.allocate(0);
List<ByteBuffer> args = Arrays.asList(ByteBuffer.wrap(tableName.getBytes()), start == null ? EMPTY : TextUtil.getByteBuffer(start), end == null ? EMPTY
@@ -526,7 +526,7 @@ public class TableOperationsImpl extends TableOperationsHelper {
throw new RuntimeException(e);
}
}
-
+
/**
* @param tableName
* the name of the table
@@ -534,11 +534,11 @@ public class TableOperationsImpl extends TableOperationsHelper {
*/
@Override
public Collection<Text> listSplits(String tableName) throws TableNotFoundException, AccumuloSecurityException {
-
+
ArgumentChecker.notNull(tableName);
-
+
String tableId = Tables.getTableId(instance, tableName);
-
+
SortedSet<KeyExtent> tablets = new TreeSet<KeyExtent>();
Map<KeyExtent,String> locations = new TreeMap<KeyExtent,String>();
@@ -564,16 +564,17 @@ public class TableOperationsImpl extends TableOperationsHelper {
UtilWaitThread.sleep(3000);
}
}
-
+
ArrayList<Text> endRows = new ArrayList<Text>(tablets.size());
-
+
for (KeyExtent ke : tablets)
if (ke.getEndRow() != null)
endRows.add(ke.getEndRow());
-
+
return endRows;
}
-
+
+ @Deprecated
@Override
public Collection<Text> getSplits(String tableName) throws TableNotFoundException {
try {
@@ -594,15 +595,15 @@ public class TableOperationsImpl extends TableOperationsHelper {
@Override
public Collection<Text> listSplits(String tableName, int maxSplits) throws TableNotFoundException, AccumuloSecurityException {
Collection<Text> endRows = listSplits(tableName);
-
+
if (endRows.size() <= maxSplits)
return endRows;
-
+
double r = (maxSplits + 1) / (double) (endRows.size());
double pos = 0;
-
+
ArrayList<Text> subset = new ArrayList<Text>(maxSplits);
-
+
int j = 0;
for (int i = 0; i < endRows.size() && j < maxSplits; i++) {
pos += r;
@@ -612,10 +613,11 @@ public class TableOperationsImpl extends TableOperationsHelper {
pos -= 1;
}
}
-
+
return subset;
}
-
+
+ @Deprecated
@Override
public Collection<Text> getSplits(String tableName, int maxSplits) throws TableNotFoundException {
try {
@@ -640,39 +642,39 @@ public class TableOperationsImpl extends TableOperationsHelper {
@Override
public void delete(String tableName) throws AccumuloException, AccumuloSecurityException, TableNotFoundException {
ArgumentChecker.notNull(tableName);
-
+
List<ByteBuffer> args = Arrays.asList(ByteBuffer.wrap(tableName.getBytes()));
Map<String,String> opts = new HashMap<String,String>();
-
+
try {
doTableOperation(TableOperation.DELETE, args, opts);
} catch (TableExistsException e) {
// should not happen
throw new RuntimeException(e);
}
-
+
}
-
+
@Override
public void clone(String srcTableName, String newTableName, boolean flush, Map<String,String> propertiesToSet, Set<String> propertiesToExclude)
throws AccumuloSecurityException, TableNotFoundException, AccumuloException, TableExistsException {
-
+
ArgumentChecker.notNull(srcTableName, newTableName);
-
+
String srcTableId = Tables.getTableId(instance, srcTableName);
-
+
if (flush)
_flush(srcTableId, null, null, true);
-
+
if (propertiesToExclude == null)
propertiesToExclude = Collections.emptySet();
-
+
if (propertiesToSet == null)
propertiesToSet = Collections.emptyMap();
-
+
if (!Collections.disjoint(propertiesToExclude, propertiesToSet.keySet()))
throw new IllegalArgumentException("propertiesToSet and propertiesToExclude not disjoint");
-
+
List<ByteBuffer> args = Arrays.asList(ByteBuffer.wrap(srcTableId.getBytes()), ByteBuffer.wrap(newTableName.getBytes()));
Map<String,String> opts = new HashMap<String,String>();
for (Entry<String,String> entry : propertiesToSet.entrySet()) {
@@ -680,14 +682,14 @@ public class TableOperationsImpl extends TableOperationsHelper {
throw new IllegalArgumentException("Property can not start with " + CLONE_EXCLUDE_PREFIX);
opts.put(entry.getKey(), entry.getValue());
}
-
+
for (String prop : propertiesToExclude) {
opts.put(CLONE_EXCLUDE_PREFIX + prop, "");
}
-
+
doTableOperation(TableOperation.CLONE, args, opts);
}
-
+
/**
* Rename a table
*
@@ -707,12 +709,12 @@ public class TableOperationsImpl extends TableOperationsHelper {
@Override
public void rename(String oldTableName, String newTableName) throws AccumuloSecurityException, TableNotFoundException, AccumuloException,
TableExistsException {
-
+
List<ByteBuffer> args = Arrays.asList(ByteBuffer.wrap(oldTableName.getBytes()), ByteBuffer.wrap(newTableName.getBytes()));
Map<String,String> opts = new HashMap<String,String>();
doTableOperation(TableOperation.RENAME, args, opts);
}
-
+
/**
* @deprecated since 1.4 {@link #flush(String, Text, Text, boolean)}
*/
@@ -725,7 +727,7 @@ public class TableOperationsImpl extends TableOperationsHelper {
throw new AccumuloException(e.getMessage(), e);
}
}
-
+
/**
* Flush a table
*
@@ -740,31 +742,31 @@ public class TableOperationsImpl extends TableOperationsHelper {
@Override
public void flush(String tableName, Text start, Text end, boolean wait) throws AccumuloException, AccumuloSecurityException, TableNotFoundException {
ArgumentChecker.notNull(tableName);
-
+
String tableId = Tables.getTableId(instance, tableName);
_flush(tableId, start, end, wait);
}
-
+
@Override
public void compact(String tableName, Text start, Text end, boolean flush, boolean wait) throws AccumuloSecurityException, TableNotFoundException,
AccumuloException {
compact(tableName, start, end, new ArrayList<IteratorSetting>(), flush, wait);
}
-
+
@Override
public void compact(String tableName, Text start, Text end, List<IteratorSetting> iterators, boolean flush, boolean wait) throws AccumuloSecurityException,
TableNotFoundException, AccumuloException {
ArgumentChecker.notNull(tableName);
ByteBuffer EMPTY = ByteBuffer.allocate(0);
-
+
String tableId = Tables.getTableId(instance, tableName);
-
+
if (flush)
_flush(tableId, start, end, true);
-
+
List<ByteBuffer> args = Arrays.asList(ByteBuffer.wrap(tableId.getBytes()), start == null ? EMPTY : TextUtil.getByteBuffer(start), end == null ? EMPTY
: TextUtil.getByteBuffer(end), ByteBuffer.wrap(IteratorUtil.encodeIteratorSettings(iterators)));
-
+
Map<String,String> opts = new HashMap<String,String>();
try {
doTableOperation(TableOperation.COMPACT, args, opts, wait);
@@ -773,13 +775,13 @@ public class TableOperationsImpl extends TableOperationsHelper {
throw new RuntimeException(e);
}
}
-
+
@Override
public void cancelCompaction(String tableName) throws AccumuloSecurityException, TableNotFoundException, AccumuloException {
String tableId = Tables.getTableId(instance, tableName);
-
+
List<ByteBuffer> args = Arrays.asList(ByteBuffer.wrap(tableId.getBytes()));
-
+
Map<String,String> opts = new HashMap<String,String>();
try {
doTableOperation(TableOperation.COMPACT_CANCEL, args, opts, true);
@@ -787,17 +789,17 @@ public class TableOperationsImpl extends TableOperationsHelper {
// should not happen
throw new RuntimeException(e);
}
-
+
}
-
+
private void _flush(String tableId, Text start, Text end, boolean wait) throws AccumuloException, AccumuloSecurityException, TableNotFoundException {
-
+
try {
long flushID;
-
+
// used to pass the table name. but the tableid associated with a table name could change between calls.
// so pass the tableid to both calls
-
+
while (true) {
MasterClientService.Iface client = null;
try {
@@ -811,7 +813,7 @@ public class TableOperationsImpl extends TableOperationsHelper {
MasterClient.close(client);
}
}
-
+
while (true) {
MasterClientService.Iface client = null;
try {
@@ -844,7 +846,7 @@ public class TableOperationsImpl extends TableOperationsHelper {
throw new AccumuloException(e);
}
}
-
+
/**
* Sets a property on a table
*
@@ -869,7 +871,7 @@ public class TableOperationsImpl extends TableOperationsHelper {
}
});
}
-
+
/**
* Removes a property from a table
*
@@ -892,7 +894,7 @@ public class TableOperationsImpl extends TableOperationsHelper {
}
});
}
-
+
/**
* Gets properties of a table
*
@@ -925,9 +927,9 @@ public class TableOperationsImpl extends TableOperationsHelper {
} catch (Exception e) {
throw new AccumuloException(e);
}
-
+
}
-
+
/**
* Sets a tables locality groups. A tables locality groups can be changed at any time.
*
@@ -947,22 +949,22 @@ public class TableOperationsImpl extends TableOperationsHelper {
// ensure locality groups do not overlap
HashSet<Text> all = new HashSet<Text>();
for (Entry<String,Set<Text>> entry : groups.entrySet()) {
-
+
if (!Collections.disjoint(all, entry.getValue())) {
throw new IllegalArgumentException("Group " + entry.getKey() + " overlaps with another group");
}
-
+
all.addAll(entry.getValue());
}
-
+
for (Entry<String,Set<Text>> entry : groups.entrySet()) {
Set<Text> colFams = entry.getValue();
String value = LocalityGroupUtil.encodeColumnFamilies(colFams);
setProperty(tableName, Property.TABLE_LOCALITY_GROUP_PREFIX + entry.getKey(), value);
}
-
+
setProperty(tableName, Property.TABLE_LOCALITY_GROUPS.getKey(), StringUtil.join(groups.keySet(), ","));
-
+
// remove anything extraneous
String prefix = Property.TABLE_LOCALITY_GROUP_PREFIX.getKey();
for (Entry<String,String> entry : getProperties(tableName)) {
@@ -972,14 +974,14 @@ public class TableOperationsImpl extends TableOperationsHelper {
// one:
String[] parts = property.split("\\.");
String group = parts[parts.length - 1];
-
+
if (!groups.containsKey(group)) {
removeProperty(tableName, property);
}
}
}
}
-
+
/**
*
* Gets the locality groups currently set for a table.
@@ -996,22 +998,22 @@ public class TableOperationsImpl extends TableOperationsHelper {
public Map<String,Set<Text>> getLocalityGroups(String tableName) throws AccumuloException, TableNotFoundException {
AccumuloConfiguration conf = new ConfigurationCopy(this.getProperties(tableName));
Map<String,Set<ByteSequence>> groups = LocalityGroupUtil.getLocalityGroups(conf);
-
+
Map<String,Set<Text>> groups2 = new HashMap<String,Set<Text>>();
for (Entry<String,Set<ByteSequence>> entry : groups.entrySet()) {
-
+
HashSet<Text> colFams = new HashSet<Text>();
-
+
for (ByteSequence bs : entry.getValue()) {
colFams.add(new Text(bs.toArray()));
}
-
+
groups2.put(entry.getKey(), colFams);
}
-
+
return groups2;
}
-
+
/**
* @param tableName
* the name of the table
@@ -1035,7 +1037,7 @@ public class TableOperationsImpl extends TableOperationsHelper {
throw new IllegalArgumentException("maximum splits must be >= 1");
if (maxSplits == 1)
return Collections.singleton(range);
-
+
Map<String,Map<KeyExtent,List<Range>>> binnedRanges = new HashMap<String,Map<KeyExtent,List<Range>>>();
String tableId = Tables.getTableId(instance, tableName);
TabletLocator tl = TabletLocator.getInstance(instance, new Text(tableId));
@@ -1046,24 +1048,24 @@ public class TableOperationsImpl extends TableOperationsHelper {
throw new TableDeletedException(tableId);
if (Tables.getTableState(instance, tableId) == TableState.OFFLINE)
throw new TableOfflineException(instance, tableId);
-
+
log.warn("Unable to locate bins for specified range. Retrying.");
// sleep randomly between 100 and 200ms
UtilWaitThread.sleep(100 + (int) (Math.random() * 100));
binnedRanges.clear();
tl.invalidateCache();
}
-
+
// group key extents to get <= maxSplits
LinkedList<KeyExtent> unmergedExtents = new LinkedList<KeyExtent>();
List<KeyExtent> mergedExtents = new ArrayList<KeyExtent>();
-
+
for (Map<KeyExtent,List<Range>> map : binnedRanges.values())
unmergedExtents.addAll(map.keySet());
-
+
// the sort method is efficient for linked list
Collections.sort(unmergedExtents);
-
+
while (unmergedExtents.size() + mergedExtents.size() > maxSplits) {
if (unmergedExtents.size() >= 2) {
KeyExtent first = unmergedExtents.removeFirst();
@@ -1076,18 +1078,18 @@ public class TableOperationsImpl extends TableOperationsHelper {
unmergedExtents.addAll(mergedExtents);
mergedExtents.clear();
}
-
+
}
-
+
mergedExtents.addAll(unmergedExtents);
-
+
Set<Range> ranges = new HashSet<Range>();
for (KeyExtent k : mergedExtents)
ranges.add(k.toDataRange().clip(range));
-
+
return ranges;
}
-
+
@Override
public void importDirectory(String tableName, String dir, String failureDir, boolean setTime) throws IOException, AccumuloSecurityException,
TableNotFoundException, AccumuloException {
@@ -1109,7 +1111,7 @@ public class TableOperationsImpl extends TableOperationsHelper {
List<ByteBuffer> args = Arrays.asList(ByteBuffer.wrap(tableName.getBytes()), ByteBuffer.wrap(dirPath.toString().getBytes()),
ByteBuffer.wrap(failPath.toString().getBytes()), ByteBuffer.wrap((setTime + "").getBytes()));
Map<String,String> opts = new HashMap<String,String>();
-
+
try {
doTableOperation(TableOperation.BULK_IMPORT, args, opts);
} catch (TableExistsException e) {
@@ -1119,7 +1121,7 @@ public class TableOperationsImpl extends TableOperationsHelper {
// return new BulkImportHelper(instance, credentials, tableName).importDirectory(new Path(dir), new Path(failureDir), numThreads, numAssignThreads,
// disableGC);
}
-
+
/**
*
* @param tableName
@@ -1132,11 +1134,11 @@ public class TableOperationsImpl extends TableOperationsHelper {
*/
@Override
public void offline(String tableName) throws AccumuloSecurityException, AccumuloException, TableNotFoundException {
-
+
ArgumentChecker.notNull(tableName);
List<ByteBuffer> args = Arrays.asList(ByteBuffer.wrap(tableName.getBytes()));
Map<String,String> opts = new HashMap<String,String>();
-
+
try {
doTableOperation(TableOperation.OFFLINE, args, opts);
} catch (TableExistsException e) {
@@ -1144,7 +1146,7 @@ public class TableOperationsImpl extends TableOperationsHelper {
throw new RuntimeException(e);
}
}
-
+
/**
*
* @param tableName
@@ -1160,7 +1162,7 @@ public class TableOperationsImpl extends TableOperationsHelper {
ArgumentChecker.notNull(tableName);
List<ByteBuffer> args = Arrays.asList(ByteBuffer.wrap(tableName.getBytes()));
Map<String,String> opts = new HashMap<String,String>();
-
+
try {
doTableOperation(TableOperation.ONLINE, args, opts);
} catch (TableExistsException e) {
@@ -1168,7 +1170,7 @@ public class TableOperationsImpl extends TableOperationsHelper {
throw new RuntimeException(e);
}
}
-
+
/**
* Clears the tablet locator cache for a specified table
*
@@ -1183,7 +1185,7 @@ public class TableOperationsImpl extends TableOperationsHelper {
TabletLocator tabLocator = TabletLocator.getInstance(instance, new Text(Tables.getTableId(instance, tableName)));
tabLocator.invalidateCache();
}
-
+
/**
* Get a mapping of table name to internal table id.
*
@@ -1193,7 +1195,7 @@ public class TableOperationsImpl extends TableOperationsHelper {
public Map<String,String> tableIdMap() {
return Tables.getNameToIdMap(instance);
}
-
+
@Override
public Text getMaxRow(String tableName, Authorizations auths, Text startRow, boolean startInclusive, Text endRow, boolean endInclusive)
throws TableNotFoundException, AccumuloException, AccumuloSecurityException {
@@ -1201,10 +1203,10 @@ public class TableOperationsImpl extends TableOperationsHelper {
Scanner scanner = instance.getConnector(credentials.getPrincipal(), CredentialHelper.extractToken(credentials)).createScanner(tableName, auths);
return FindMax.findMax(scanner, startRow, startInclusive, endRow, endInclusive);
}
-
+
public static Map<String,String> getExportedProps(FileSystem fs, Path path) throws IOException {
HashMap<String,String> props = new HashMap<String,String>();
-
+
ZipInputStream zis = new ZipInputStream(fs.open(path));
try {
ZipEntry zipEntry;
@@ -1216,7 +1218,7 @@ public class TableOperationsImpl extends TableOperationsHelper {
String sa[] = line.split("=", 2);
props.put(sa[0], sa[1]);
}
-
+
break;
}
}
@@ -1225,48 +1227,48 @@ public class TableOperationsImpl extends TableOperationsHelper {
}
return props;
}
-
+
@Override
public void importTable(String tableName, String importDir) throws TableExistsException, AccumuloException, AccumuloSecurityException {
ArgumentChecker.notNull(tableName, importDir);
-
+
try {
FileSystem fs = FileUtil.getFileSystem(CachedConfiguration.getInstance(), instance.getConfiguration());
;
Map<String,String> props = getExportedProps(fs, new Path(importDir, Constants.EXPORT_FILE));
-
+
for (String propKey : props.keySet()) {
if (Property.isClassProperty(propKey) && !props.get(propKey).contains(Constants.CORE_PACKAGE_NAME)) {
Logger.getLogger(this.getClass()).info(
"Imported table sets '" + propKey + "' to '" + props.get(propKey) + "'. Ensure this class is on Accumulo classpath.");
}
}
-
+
} catch (IOException ioe) {
Logger.getLogger(this.getClass()).warn("Failed to check if imported table references external java classes : " + ioe.getMessage());
}
-
+
List<ByteBuffer> args = Arrays.asList(ByteBuffer.wrap(tableName.getBytes()), ByteBuffer.wrap(importDir.getBytes()));
-
+
Map<String,String> opts = Collections.emptyMap();
-
+
try {
doTableOperation(TableOperation.IMPORT, args, opts);
} catch (TableNotFoundException e1) {
// should not happen
throw new RuntimeException(e1);
}
-
+
}
-
+
@Override
public void exportTable(String tableName, String exportDir) throws TableNotFoundException, AccumuloException, AccumuloSecurityException {
ArgumentChecker.notNull(tableName, exportDir);
-
+
List<ByteBuffer> args = Arrays.asList(ByteBuffer.wrap(tableName.getBytes()), ByteBuffer.wrap(exportDir.getBytes()));
-
+
Map<String,String> opts = Collections.emptyMap();
-
+
try {
doTableOperation(TableOperation.EXPORT, args, opts);
} catch (TableExistsException e1) {
@@ -1274,12 +1276,11 @@ public class TableOperationsImpl extends TableOperationsHelper {
throw new RuntimeException(e1);
}
}
-
+
@Override
public boolean testClassLoad(final String tableName, final String className, final String asTypeName) throws TableNotFoundException, AccumuloException,
AccumuloSecurityException {
ArgumentChecker.notNull(tableName, className, asTypeName);
-
try {
return ServerClient.executeRaw(instance, new ClientExecReturn<Boolean,ClientService.Client>() {
@@ -1304,14 +1305,14 @@ public class TableOperationsImpl extends TableOperationsHelper {
throw new AccumuloException(e);
}
}
-
+
@Override
public void attachIterator(String tableName, IteratorSetting setting, EnumSet<IteratorScope> scopes) throws AccumuloSecurityException, AccumuloException,
TableNotFoundException {
testClassLoad(tableName, setting.getIteratorClass(), SortedKeyValueIterator.class.getName());
super.attachIterator(tableName, setting, scopes);
}
-
+
@Override
public int addConstraint(String tableName, String constraintClassName) throws AccumuloException, AccumuloSecurityException, TableNotFoundException {
testClassLoad(tableName, constraintClassName, Constraint.class.getName());
http://git-wip-us.apache.org/repos/asf/accumulo/blob/7f403df2/core/src/main/java/org/apache/accumulo/core/client/mapreduce/lib/util/ConfiguratorBase.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/client/mapreduce/lib/util/ConfiguratorBase.java b/core/src/main/java/org/apache/accumulo/core/client/mapreduce/lib/util/ConfiguratorBase.java
index dceabec..ab99f56 100644
--- a/core/src/main/java/org/apache/accumulo/core/client/mapreduce/lib/util/ConfiguratorBase.java
+++ b/core/src/main/java/org/apache/accumulo/core/client/mapreduce/lib/util/ConfiguratorBase.java
@@ -35,16 +35,16 @@ import org.apache.log4j.Logger;
* @since 1.5.0
*/
public class ConfiguratorBase {
-
+
/**
- * Configuration keys for {@link Instance#getConnector(String, byte[])}.
+ * Configuration keys for {@link Instance#getConnector(String, AuthenticationToken)}.
*
* @since 1.5.0
*/
public static enum ConnectorInfo {
IS_CONFIGURED, PRINCIPAL, TOKEN, TOKEN_CLASS
}
-
+
/**
* Configuration keys for {@link Instance}, {@link ZooKeeperInstance}, and {@link MockInstance}.
*
@@ -53,7 +53,7 @@ public class ConfiguratorBase {
protected static enum InstanceOpts {
TYPE, NAME, ZOO_KEEPERS;
}
-
+
/**
* Configuration keys for general configuration options.
*
@@ -62,7 +62,7 @@ public class ConfiguratorBase {
protected static enum GeneralOpts {
LOG_LEVEL
}
-
+
/**
* Provides a configuration key for a given feature enum, prefixed by the implementingClass
*
@@ -76,7 +76,7 @@ public class ConfiguratorBase {
protected static String enumToConfKey(Class<?> implementingClass, Enum<?> e) {
return implementingClass.getSimpleName() + "." + e.getDeclaringClass().getSimpleName() + "." + StringUtils.camelize(e.name().toLowerCase());
}
-
+
/**
* Sets the connector information needed to communicate with Accumulo in this job.
*
@@ -99,14 +99,14 @@ public class ConfiguratorBase {
throws AccumuloSecurityException {
if (isConnectorInfoSet(implementingClass, conf))
throw new IllegalStateException("Connector info for " + implementingClass.getSimpleName() + " can only be set once per job");
-
+
ArgumentChecker.notNull(principal, token);
conf.setBoolean(enumToConfKey(implementingClass, ConnectorInfo.IS_CONFIGURED), true);
conf.set(enumToConfKey(implementingClass, ConnectorInfo.PRINCIPAL), principal);
conf.set(enumToConfKey(implementingClass, ConnectorInfo.TOKEN_CLASS), token.getClass().getCanonicalName());
conf.set(enumToConfKey(implementingClass, ConnectorInfo.TOKEN), CredentialHelper.tokenAsBase64(token));
}
-
+
/**
* Determines if the connector info has already been set for this instance.
*
@@ -121,7 +121,7 @@ public class ConfiguratorBase {
public static Boolean isConnectorInfoSet(Class<?> implementingClass, Configuration conf) {
return conf.getBoolean(enumToConfKey(implementingClass, ConnectorInfo.IS_CONFIGURED), false);
}
-
+
/**
* Gets the user name from the configuration.
*
@@ -136,7 +136,7 @@ public class ConfiguratorBase {
public static String getPrincipal(Class<?> implementingClass, Configuration conf) {
return conf.get(enumToConfKey(implementingClass, ConnectorInfo.PRINCIPAL));
}
-
+
/**
* Gets the serialized token class from the configuration.
*
@@ -151,7 +151,7 @@ public class ConfiguratorBase {
public static String getTokenClass(Class<?> implementingClass, Configuration conf) {
return conf.get(enumToConfKey(implementingClass, ConnectorInfo.TOKEN_CLASS));
}
-
+
/**
* Gets the password from the configuration. WARNING: The password is stored in the Configuration and shared with all MapReduce tasks; It is BASE64 encoded to
* provide a charset safe conversion to a string, and is not intended to be secure.
@@ -167,7 +167,7 @@ public class ConfiguratorBase {
public static byte[] getToken(Class<?> implementingClass, Configuration conf) {
return Base64.decodeBase64(conf.get(enumToConfKey(implementingClass, ConnectorInfo.TOKEN), "").getBytes(Charset.forName("UTF-8")));
}
-
+
/**
* Configures a {@link ZooKeeperInstance} for this job.
*
@@ -186,12 +186,12 @@ public class ConfiguratorBase {
if (!conf.get(key, "").isEmpty())
throw new IllegalStateException("Instance info can only be set once per job; it has already been configured with " + conf.get(key));
conf.set(key, "ZooKeeperInstance");
-
+
ArgumentChecker.notNull(instanceName, zooKeepers);
conf.set(enumToConfKey(implementingClass, InstanceOpts.NAME), instanceName);
conf.set(enumToConfKey(implementingClass, InstanceOpts.ZOO_KEEPERS), zooKeepers);
}
-
+
/**
* Configures a {@link MockInstance} for this job.
*
@@ -208,11 +208,11 @@ public class ConfiguratorBase {
if (!conf.get(key, "").isEmpty())
throw new IllegalStateException("Instance info can only be set once per job; it has already been configured with " + conf.get(key));
conf.set(key, "MockInstance");
-
+
ArgumentChecker.notNull(instanceName);
conf.set(enumToConfKey(implementingClass, InstanceOpts.NAME), instanceName);
}
-
+
/**
* Initializes an Accumulo {@link Instance} based on the configuration.
*
@@ -237,7 +237,7 @@ public class ConfiguratorBase {
else
throw new IllegalStateException("Unrecognized instance type " + instanceType);
}
-
+
/**
* Sets the log level for this job.
*
@@ -254,7 +254,7 @@ public class ConfiguratorBase {
Logger.getLogger(implementingClass).setLevel(level);
conf.setInt(enumToConfKey(implementingClass, GeneralOpts.LOG_LEVEL), level.toInt());
}
-
+
/**
* Gets the log level from this configuration.
*
@@ -269,5 +269,5 @@ public class ConfiguratorBase {
public static Level getLogLevel(Class<?> implementingClass, Configuration conf) {
return Level.toLevel(conf.getInt(enumToConfKey(implementingClass, GeneralOpts.LOG_LEVEL), Level.INFO.toInt()));
}
-
+
}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/7f403df2/core/src/main/java/org/apache/accumulo/core/client/mock/MockTableOperations.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/client/mock/MockTableOperations.java b/core/src/main/java/org/apache/accumulo/core/client/mock/MockTableOperations.java
index ec11335..f088b1f 100644
--- a/core/src/main/java/org/apache/accumulo/core/client/mock/MockTableOperations.java
+++ b/core/src/main/java/org/apache/accumulo/core/client/mock/MockTableOperations.java
@@ -55,25 +55,25 @@ import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.Text;
public class MockTableOperations extends TableOperationsHelper {
-
+
final private MockAccumulo acu;
final private String username;
-
+
MockTableOperations(MockAccumulo acu, String username) {
this.acu = acu;
this.username = username;
}
-
+
@Override
public SortedSet<String> list() {
return new TreeSet<String>(acu.tables.keySet());
}
-
+
@Override
public boolean exists(String tableName) {
return acu.tables.containsKey(tableName);
}
-
+
@Override
public void create(String tableName) throws AccumuloException, AccumuloSecurityException, TableExistsException {
if (!tableName.matches(Constants.VALID_TABLE_NAME_REGEX)) {
@@ -81,12 +81,12 @@ public class MockTableOperations extends TableOperationsHelper {
}
create(tableName, true, TimeType.MILLIS);
}
-
+
@Override
public void create(String tableName, boolean versioningIter) throws AccumuloException, AccumuloSecurityException, TableExistsException {
create(tableName, versioningIter, TimeType.MILLIS);
}
-
+
@Override
public void create(String tableName, boolean versioningIter, TimeType timeType) throws AccumuloException, AccumuloSecurityException, TableExistsException {
if (!tableName.matches(Constants.VALID_TABLE_NAME_REGEX)) {
@@ -96,24 +96,26 @@ public class MockTableOperations extends TableOperationsHelper {
throw new TableExistsException(tableName, tableName, "");
acu.createTable(username, tableName, versioningIter, timeType);
}
-
+
@Override
public void addSplits(String tableName, SortedSet<Text> partitionKeys) throws TableNotFoundException, AccumuloException, AccumuloSecurityException {
if (!exists(tableName))
throw new TableNotFoundException(tableName, tableName, "");
acu.addSplits(tableName, partitionKeys);
}
-
+
+ @Deprecated
@Override
public Collection<Text> getSplits(String tableName) throws TableNotFoundException {
return listSplits(tableName);
}
-
+
+ @Deprecated
@Override
public Collection<Text> getSplits(String tableName, int maxSplits) throws TableNotFoundException {
return listSplits(tableName);
}
-
+
@Override
public Collection<Text> listSplits(String tableName) throws TableNotFoundException {
if (!exists(tableName))
@@ -125,14 +127,14 @@ public class MockTableOperations extends TableOperationsHelper {
public Collection<Text> listSplits(String tableName, int maxSplits) throws TableNotFoundException {
return listSplits(tableName);
}
-
+
@Override
public void delete(String tableName) throws AccumuloException, AccumuloSecurityException, TableNotFoundException {
if (!exists(tableName))
throw new TableNotFoundException(tableName, tableName, "");
acu.tables.remove(tableName);
}
-
+
@Override
public void rename(String oldTableName, String newTableName) throws AccumuloSecurityException, TableNotFoundException, AccumuloException,
TableExistsException {
@@ -143,42 +145,42 @@ public class MockTableOperations extends TableOperationsHelper {
MockTable t = acu.tables.remove(oldTableName);
acu.tables.put(newTableName, t);
}
-
+
@Deprecated
@Override
public void flush(String tableName) throws AccumuloException, AccumuloSecurityException {}
-
+
@Override
public void setProperty(String tableName, String property, String value) throws AccumuloException, AccumuloSecurityException {
acu.tables.get(tableName).settings.put(property, value);
}
-
+
@Override
public void removeProperty(String tableName, String property) throws AccumuloException, AccumuloSecurityException {
acu.tables.get(tableName).settings.remove(property);
}
-
+
@Override
public Iterable<Entry<String,String>> getProperties(String tableName) throws TableNotFoundException {
if (!exists(tableName))
throw new TableNotFoundException(tableName, tableName, "");
return acu.tables.get(tableName).settings.entrySet();
}
-
+
@Override
public void setLocalityGroups(String tableName, Map<String,Set<Text>> groups) throws AccumuloException, AccumuloSecurityException, TableNotFoundException {
if (!exists(tableName))
throw new TableNotFoundException(tableName, tableName, "");
acu.tables.get(tableName).setLocalityGroups(groups);
}
-
+
@Override
public Map<String,Set<Text>> getLocalityGroups(String tableName) throws AccumuloException, TableNotFoundException {
if (!exists(tableName))
throw new TableNotFoundException(tableName, tableName, "");
return acu.tables.get(tableName).getLocalityGroups();
}
-
+
@Override
public Set<Range> splitRangeByTablets(String tableName, Range range, int maxSplits) throws AccumuloException, AccumuloSecurityException,
TableNotFoundException {
@@ -186,7 +188,7 @@ public class MockTableOperations extends TableOperationsHelper {
throw new TableNotFoundException(tableName, tableName, "");
return Collections.singleton(range);
}
-
+
@Override
public void importDirectory(String tableName, String dir, String failureDir, boolean setTime) throws IOException, AccumuloException,
AccumuloSecurityException, TableNotFoundException {
@@ -197,7 +199,7 @@ public class MockTableOperations extends TableOperationsHelper {
}
Path importPath = new Path(dir);
Path failurePath = new Path(failureDir);
-
+
FileSystem fs = acu.getFileSystem();
/*
* check preconditions
@@ -272,25 +274,25 @@ public class MockTableOperations extends TableOperationsHelper {
fs.delete(importStatus.getPath(), true);
}
}
-
+
@Override
public void offline(String tableName) throws AccumuloSecurityException, AccumuloException, TableNotFoundException {
if (!exists(tableName))
throw new TableNotFoundException(tableName, tableName, "");
}
-
+
@Override
public void online(String tableName) throws AccumuloSecurityException, AccumuloException, TableNotFoundException {
if (!exists(tableName))
throw new TableNotFoundException(tableName, tableName, "");
}
-
+
@Override
public void clearLocatorCache(String tableName) throws TableNotFoundException {
if (!exists(tableName))
throw new TableNotFoundException(tableName, tableName, "");
}
-
+
@Override
public Map<String,String> tableIdMap() {
Map<String,String> result = new HashMap<String,String>();
@@ -299,14 +301,14 @@ public class MockTableOperations extends TableOperationsHelper {
}
return result;
}
-
+
@Override
public void merge(String tableName, Text start, Text end) throws AccumuloException, AccumuloSecurityException, TableNotFoundException {
if (!exists(tableName))
throw new TableNotFoundException(tableName, tableName, "");
acu.merge(tableName, start, end);
}
-
+
@Override
public void deleteRows(String tableName, Text start, Text end) throws AccumuloException, AccumuloSecurityException, TableNotFoundException {
if (!exists(tableName))
@@ -315,63 +317,63 @@ public class MockTableOperations extends TableOperationsHelper {
Set<Key> keep = new TreeSet<Key>(t.table.tailMap(new Key(start)).headMap(new Key(end)).keySet());
t.table.keySet().removeAll(keep);
}
-
+
@Override
public void compact(String tableName, Text start, Text end, boolean flush, boolean wait) throws AccumuloSecurityException, TableNotFoundException,
AccumuloException {
if (!exists(tableName))
throw new TableNotFoundException(tableName, tableName, "");
}
-
+
@Override
public void compact(String tableName, Text start, Text end, List<IteratorSetting> iterators, boolean flush, boolean wait) throws AccumuloSecurityException,
TableNotFoundException, AccumuloException {
if (!exists(tableName))
throw new TableNotFoundException(tableName, tableName, "");
}
-
+
@Override
public void cancelCompaction(String tableName) throws AccumuloSecurityException, TableNotFoundException, AccumuloException {
if (!exists(tableName))
throw new TableNotFoundException(tableName, tableName, "");
}
-
+
@Override
public void clone(String srcTableName, String newTableName, boolean flush, Map<String,String> propertiesToSet, Set<String> propertiesToExclude)
throws AccumuloException, AccumuloSecurityException, TableNotFoundException, TableExistsException {
throw new NotImplementedException();
}
-
+
@Override
public void flush(String tableName, Text start, Text end, boolean wait) throws AccumuloException, AccumuloSecurityException, TableNotFoundException {
if (!exists(tableName))
throw new TableNotFoundException(tableName, tableName, "");
}
-
+
@Override
public Text getMaxRow(String tableName, Authorizations auths, Text startRow, boolean startInclusive, Text endRow, boolean endInclusive)
throws TableNotFoundException, AccumuloException, AccumuloSecurityException {
MockTable table = acu.tables.get(tableName);
if (table == null)
throw new TableNotFoundException(tableName, tableName, "no such table");
-
+
return FindMax.findMax(new MockScanner(table, auths), startRow, startInclusive, endRow, endInclusive);
}
-
+
@Override
public void importTable(String tableName, String exportDir) throws TableExistsException, AccumuloException, AccumuloSecurityException {
throw new NotImplementedException();
}
-
+
@Override
public void exportTable(String tableName, String exportDir) throws TableNotFoundException, AccumuloException, AccumuloSecurityException {
throw new NotImplementedException();
}
-
+
@Override
public boolean testClassLoad(String tableName, String className, String asTypeName) throws AccumuloException, AccumuloSecurityException,
TableNotFoundException {
-
+
try {
AccumuloVFSClassLoader.loadClass(className, Class.forName(asTypeName));
} catch (ClassNotFoundException e) {
http://git-wip-us.apache.org/repos/asf/accumulo/blob/7f403df2/core/src/main/java/org/apache/accumulo/core/client/security/tokens/NullToken.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/client/security/tokens/NullToken.java b/core/src/main/java/org/apache/accumulo/core/client/security/tokens/NullToken.java
index c2e74c3..a69c51f 100644
--- a/core/src/main/java/org/apache/accumulo/core/client/security/tokens/NullToken.java
+++ b/core/src/main/java/org/apache/accumulo/core/client/security/tokens/NullToken.java
@@ -28,40 +28,47 @@ import javax.security.auth.DestroyFailedException;
* @since 1.5.0
*/
public class NullToken implements AuthenticationToken {
-
+
@Override
public void readFields(DataInput arg0) throws IOException {
return;
}
-
+
@Override
public void write(DataOutput arg0) throws IOException {
return;
}
-
+
@Override
public void destroy() throws DestroyFailedException {
return;
}
-
+
@Override
public boolean isDestroyed() {
return false;
}
-
+
+ @Override
public NullToken clone() {
return new NullToken();
}
-
+
+ @Override
public boolean equals(Object obj) {
return obj instanceof NullToken;
}
-
+
@Override
public void init(Properties properties) {}
-
+
@Override
public Set<TokenProperty> getProperties() {
return Collections.emptySet();
}
+
+ @Override
+ public int hashCode() {
+ return 0;
+ }
}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/7f403df2/core/src/main/java/org/apache/accumulo/core/security/Authorizations.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/security/Authorizations.java b/core/src/main/java/org/apache/accumulo/core/security/Authorizations.java
index 327cf23..b546a48 100644
--- a/core/src/main/java/org/apache/accumulo/core/security/Authorizations.java
+++ b/core/src/main/java/org/apache/accumulo/core/security/Authorizations.java
@@ -33,56 +33,56 @@ import org.apache.accumulo.core.util.ByteBufferUtil;
import org.apache.commons.codec.binary.Base64;
public class Authorizations implements Iterable<byte[]>, Serializable {
-
+
private static final long serialVersionUID = 1L;
-
+
private HashSet<ByteSequence> auths = new HashSet<ByteSequence>();
private List<byte[]> authsList = new ArrayList<byte[]>();
private List<byte[]> immutableList = Collections.unmodifiableList(authsList);
-
+
private static final boolean[] validAuthChars = new boolean[256];
-
+
public static final String HEADER = "!AUTH1:";
-
+
static {
for (int i = 0; i < 256; i++) {
validAuthChars[i] = false;
}
-
+
for (int i = 'a'; i <= 'z'; i++) {
validAuthChars[i] = true;
}
-
+
for (int i = 'A'; i <= 'Z'; i++) {
validAuthChars[i] = true;
}
-
+
for (int i = '0'; i <= '9'; i++) {
validAuthChars[i] = true;
}
-
+
validAuthChars['_'] = true;
validAuthChars['-'] = true;
validAuthChars[':'] = true;
validAuthChars['.'] = true;
validAuthChars['/'] = true;
}
-
+
static final boolean isValidAuthChar(byte b) {
return validAuthChars[0xff & b];
}
-
+
private void checkAuths() {
-
+
for (ByteSequence bs : auths) {
if (bs.length() == 0) {
throw new IllegalArgumentException("Empty authorization");
}
-
+
authsList.add(bs.toArray());
}
}
-
+
/**
* A convenience constructor that accepts a collection of string authorizations that have each already been encoded as UTF-8 bytes.
*
@@ -94,7 +94,7 @@ public class Authorizations implements Iterable<byte[]>, Serializable {
auths.add(new ArrayByteSequence(auth));
checkAuths();
}
-
+
/**
* A convenience constructor that accepts a collection of string authorizations that have each already been encoded as UTF-8 bytes.
*
@@ -107,7 +107,7 @@ public class Authorizations implements Iterable<byte[]>, Serializable {
}
checkAuths();
}
-
+
/**
* Constructs an authorizations object a serialized form. This is NOT a constructor for a set of authorizations of size one.
*
@@ -115,9 +115,9 @@ public class Authorizations implements Iterable<byte[]>, Serializable {
* a serialized authorizations string produced by {@link #getAuthorizationsArray()} or {@link #serialize()} (converted to UTF-8 bytes)
*/
public Authorizations(byte[] authorizations) {
-
+
ArgumentChecker.notNull(authorizations);
-
+
String authsString = new String(authorizations, Constants.UTF8);
if (authsString.startsWith(HEADER)) {
// it's the new format
@@ -136,14 +136,14 @@ public class Authorizations implements Iterable<byte[]>, Serializable {
setAuthorizations(authsString.split(","));
}
}
-
+
/**
* Constructs an empty set of authorizations.
*
* @see #Authorizations(String...)
*/
public Authorizations() {}
-
+
/**
* Constructs an authorizations object from a set of human-readable authorizations.
*
@@ -153,7 +153,7 @@ public class Authorizations implements Iterable<byte[]>, Serializable {
public Authorizations(String... authorizations) {
setAuthorizations(authorizations);
}
-
+
private void setAuthorizations(String... authorizations) {
ArgumentChecker.notNull(authorizations);
auths.clear();
@@ -161,10 +161,10 @@ public class Authorizations implements Iterable<byte[]>, Serializable {
str = str.trim();
auths.add(new ArrayByteSequence(str.getBytes(Constants.UTF8)));
}
-
+
checkAuths();
}
-
+
/**
* Retrieve a serialized form of the underlying set of authorizations.
*
@@ -173,7 +173,7 @@ public class Authorizations implements Iterable<byte[]>, Serializable {
public byte[] getAuthorizationsArray() {
return serialize().getBytes(Constants.UTF8);
}
-
+
/**
* Retrieve authorizations as a list of strings that have been encoded as UTF-8 bytes.
*
@@ -182,16 +182,14 @@ public class Authorizations implements Iterable<byte[]>, Serializable {
public List<byte[]> getAuthorizations() {
return immutableList;
}
-
+
/**
* Retrieve authorizations as a list of strings that have been encoded as UTF-8 bytes.
- *
- * @see #Authorizations(List)
*/
public List<ByteBuffer> getAuthorizationsBB() {
return ByteBufferUtil.toByteBuffers(immutableList);
}
-
+
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
@@ -201,46 +199,46 @@ public class Authorizations implements Iterable<byte[]>, Serializable {
sep = ",";
sb.append(new String(auth.toArray(), Constants.UTF8));
}
-
+
return sb.toString();
}
-
+
/**
* Checks for the existence of this UTF-8 encoded authorization.
*/
public boolean contains(byte[] auth) {
return auths.contains(new ArrayByteSequence(auth));
}
-
+
/**
* Checks for the existence of this UTF-8 encoded authorization.
*/
public boolean contains(ByteSequence auth) {
return auths.contains(auth);
}
-
+
/**
* Checks for the existence of this authorization.
*/
public boolean contains(String auth) {
return auths.contains(auth.getBytes(Constants.UTF8));
}
-
+
@Override
public boolean equals(Object o) {
if (o == null) {
return false;
}
-
+
if (o instanceof Authorizations) {
Authorizations ao = (Authorizations) o;
-
+
return auths.equals(ao.auths);
}
-
+
return false;
}
-
+
@Override
public int hashCode() {
int result = 0;
@@ -248,20 +246,20 @@ public class Authorizations implements Iterable<byte[]>, Serializable {
result += b.hashCode();
return result;
}
-
+
public int size() {
return auths.size();
}
-
+
public boolean isEmpty() {
return auths.isEmpty();
}
-
+
@Override
public Iterator<byte[]> iterator() {
return immutableList.iterator();
}
-
+
/**
* Returns a serialized form of these authorizations. Convert to UTF-8 bytes to deserialize with {@link #Authorizations(byte[])}
*/
@@ -273,7 +271,7 @@ public class Authorizations implements Iterable<byte[]>, Serializable {
sep = ",";
sb.append(new String(Base64.encodeBase64(auth.toArray()), Constants.UTF8));
}
-
+
return sb.toString();
}
}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/7f403df2/core/src/test/java/org/apache/accumulo/core/client/admin/TableOperationsHelperTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/accumulo/core/client/admin/TableOperationsHelperTest.java b/core/src/test/java/org/apache/accumulo/core/client/admin/TableOperationsHelperTest.java
index 990ee53..1248018 100644
--- a/core/src/test/java/org/apache/accumulo/core/client/admin/TableOperationsHelperTest.java
+++ b/core/src/test/java/org/apache/accumulo/core/client/admin/TableOperationsHelperTest.java
@@ -41,108 +41,110 @@ import org.junit.Assert;
import org.junit.Test;
public class TableOperationsHelperTest {
-
+
static class Tester extends TableOperationsHelper {
Map<String,Map<String,String>> settings = new HashMap<String,Map<String,String>>();
-
+
@Override
public SortedSet<String> list() {
return null;
}
-
+
@Override
public boolean exists(String tableName) {
return true;
}
-
+
@Override
public void create(String tableName) throws AccumuloException, AccumuloSecurityException, TableExistsException {}
-
+
@Override
public void create(String tableName, boolean limitVersion) throws AccumuloException, AccumuloSecurityException, TableExistsException {
create(tableName, limitVersion, TimeType.MILLIS);
}
-
+
@Override
public void create(String tableName, boolean versioningIter, TimeType timeType) throws AccumuloException, AccumuloSecurityException, TableExistsException {}
-
+
@Override
public void addSplits(String tableName, SortedSet<Text> partitionKeys) throws TableNotFoundException, AccumuloException, AccumuloSecurityException {}
-
+
+ @Deprecated
@Override
public Collection<Text> getSplits(String tableName) throws TableNotFoundException {
return null;
}
-
+
+ @Deprecated
@Override
public Collection<Text> getSplits(String tableName, int maxSplits) throws TableNotFoundException {
return null;
}
-
+
@Override
public Collection<Text> listSplits(String tableName) throws TableNotFoundException {
return null;
}
-
+
@Override
public Collection<Text> listSplits(String tableName, int maxSplits) throws TableNotFoundException {
return null;
}
-
+
@Override
public Text getMaxRow(String tableName, Authorizations auths, Text startRow, boolean startInclusive, Text endRow, boolean endInclusive)
throws TableNotFoundException, AccumuloException, AccumuloSecurityException {
return null;
}
-
+
@Override
public void merge(String tableName, Text start, Text end) throws AccumuloException, AccumuloSecurityException, TableNotFoundException {
-
+
}
-
+
@Override
public void deleteRows(String tableName, Text start, Text end) throws AccumuloException, AccumuloSecurityException, TableNotFoundException {}
-
+
@Override
public void compact(String tableName, Text start, Text end, boolean flush, boolean wait) throws AccumuloSecurityException, TableNotFoundException,
AccumuloException {}
-
+
@Override
public void compact(String tableName, Text start, Text end, List<IteratorSetting> iterators, boolean flush, boolean wait) throws AccumuloSecurityException,
TableNotFoundException, AccumuloException {}
-
+
@Override
public void delete(String tableName) throws AccumuloException, AccumuloSecurityException, TableNotFoundException {}
-
+
@Override
public void clone(String srcTableName, String newTableName, boolean flush, Map<String,String> propertiesToSet, Set<String> propertiesToExclude)
throws AccumuloException, AccumuloSecurityException, TableNotFoundException, TableExistsException {}
-
+
@Override
public void rename(String oldTableName, String newTableName) throws AccumuloSecurityException, TableNotFoundException, AccumuloException,
TableExistsException {}
-
+
@Deprecated
@Override
public void flush(String tableName) throws AccumuloException, AccumuloSecurityException {}
-
+
@Override
public void flush(String tableName, Text start, Text end, boolean wait) throws AccumuloException, AccumuloSecurityException, TableNotFoundException {}
-
+
@Override
public void setProperty(String tableName, String property, String value) throws AccumuloException, AccumuloSecurityException {
if (!settings.containsKey(tableName))
settings.put(tableName, new TreeMap<String,String>());
settings.get(tableName).put(property, value);
}
-
+
@Override
public void removeProperty(String tableName, String property) throws AccumuloException, AccumuloSecurityException {
if (!settings.containsKey(tableName))
return;
settings.get(tableName).remove(property);
}
-
+
@Override
public Iterable<Entry<String,String>> getProperties(String tableName) throws AccumuloException, TableNotFoundException {
Map<String,String> empty = Collections.emptyMap();
@@ -150,41 +152,41 @@ public class TableOperationsHelperTest {
return empty.entrySet();
return settings.get(tableName).entrySet();
}
-
+
@Override
public void setLocalityGroups(String tableName, Map<String,Set<Text>> groups) throws AccumuloException, AccumuloSecurityException, TableNotFoundException {}
-
+
@Override
public Map<String,Set<Text>> getLocalityGroups(String tableName) throws AccumuloException, TableNotFoundException {
return null;
}
-
+
@Override
public Set<Range> splitRangeByTablets(String tableName, Range range, int maxSplits) throws AccumuloException, AccumuloSecurityException,
TableNotFoundException {
return null;
}
-
+
@Override
public void importDirectory(String tableName, String dir, String failureDir, boolean setTime) throws TableNotFoundException, IOException,
AccumuloException, AccumuloSecurityException {}
-
+
@Override
public void offline(String tableName) throws AccumuloSecurityException, AccumuloException, TableNotFoundException {
-
+
}
-
+
@Override
public void online(String tableName) throws AccumuloSecurityException, AccumuloException, TableNotFoundException {}
-
+
@Override
public void clearLocatorCache(String tableName) throws TableNotFoundException {}
-
+
@Override
public Map<String,String> tableIdMap() {
return null;
}
-
+
void check(String tablename, String[] values) {
Map<String,String> expected = new TreeMap<String,String>();
for (String value : values) {
@@ -193,23 +195,23 @@ public class TableOperationsHelperTest {
}
Assert.assertEquals(expected, settings.get(tablename));
}
-
+
@Override
public void importTable(String tableName, String exportDir) throws TableExistsException, AccumuloException, AccumuloSecurityException {}
-
+
@Override
public void exportTable(String tableName, String exportDir) throws TableNotFoundException, AccumuloException, AccumuloSecurityException {}
-
+
@Override
public void cancelCompaction(String tableName) throws AccumuloSecurityException, TableNotFoundException, AccumuloException {}
-
+
@Override
public boolean testClassLoad(String tableName, String className, String asTypeName) throws AccumuloException, AccumuloSecurityException,
TableNotFoundException {
return false;
}
}
-
+
@Test
public void testAttachIterator() throws Exception {
Tester t = new Tester();
@@ -218,7 +220,7 @@ public class TableOperationsHelperTest {
t.check("table", new String[] {"table.iterator.scan.someName=10,foo.bar",});
t.removeIterator("table", "someName", EnumSet.of(IteratorScope.scan));
t.check("table", new String[] {});
-
+
IteratorSetting setting = new IteratorSetting(10, "someName", "foo.bar");
setting.addOptions(Collections.singletonMap("key", "value"));
t.attachIterator("table", setting, EnumSet.of(IteratorScope.majc));
@@ -226,7 +228,7 @@ public class TableOperationsHelperTest {
t.attachIterator("table", setting, EnumSet.of(IteratorScope.scan));
t.check("table", new String[] {"table.iterator.majc.someName=10,foo.bar", "table.iterator.majc.someName.opt.key=value",
"table.iterator.scan.someName=10,foo.bar",});
-
+
t.removeIterator("table", "someName", EnumSet.of(IteratorScope.scan));
setting = new IteratorSetting(20, "otherName", "some.classname");
setting.addOptions(Collections.singletonMap("key", "value"));
@@ -245,7 +247,7 @@ public class TableOperationsHelperTest {
t.removeIterator("table", "someName", EnumSet.allOf(IteratorScope.class));
t.check("table", new String[] {"table.iterator.majc.otherName=20,some.classname", "table.iterator.majc.otherName.opt.key=value",
"table.iterator.scan.otherName=20,some.classname",});
-
+
setting = t.getIteratorSetting("table", "otherName", IteratorScope.scan);
Assert.assertEquals(20, setting.getPriority());
Assert.assertEquals("some.classname", setting.getIteratorClass());
@@ -258,7 +260,7 @@ public class TableOperationsHelperTest {
t.attachIterator("table", setting, EnumSet.of(IteratorScope.minc));
t.check("table", new String[] {"table.iterator.majc.otherName=20,some.classname", "table.iterator.majc.otherName.opt.key=value",
"table.iterator.minc.otherName=20,some.classname", "table.iterator.minc.otherName.opt.key=value", "table.iterator.scan.otherName=20,some.classname",});
-
+
try {
t.attachIterator("table", setting);
Assert.fail();
http://git-wip-us.apache.org/repos/asf/accumulo/blob/7f403df2/examples/simple/src/main/java/org/apache/accumulo/examples/simple/client/TracingExample.java
----------------------------------------------------------------------
diff --git a/examples/simple/src/main/java/org/apache/accumulo/examples/simple/client/TracingExample.java b/examples/simple/src/main/java/org/apache/accumulo/examples/simple/client/TracingExample.java
index 46752c8..994ebf2 100644
--- a/examples/simple/src/main/java/org/apache/accumulo/examples/simple/client/TracingExample.java
+++ b/examples/simple/src/main/java/org/apache/accumulo/examples/simple/client/TracingExample.java
@@ -17,7 +17,6 @@
package org.apache.accumulo.examples.simple.client;
-import java.io.IOException;
import java.util.Map.Entry;
import org.apache.accumulo.core.cli.ClientOnDefaultTable;
@@ -42,113 +41,101 @@ import com.beust.jcommander.Parameter;
/**
* A simple example showing how to use the distributed tracing API in client code
- *
+ *
*/
public class TracingExample {
-
- private static final String DEFAULT_TABLE_NAME = "test";
-
- static class Opts extends ClientOnDefaultTable {
- @Parameter(names = {"-C", "--createtable"}, description = "create table before doing anything")
- boolean createtable = false;
- @Parameter(names = {"-D", "--deletetable"}, description = "delete table when finished")
- boolean deletetable = false;
- @Parameter(names = {"-c", "--create"}, description = "create entries before any deletes")
- boolean createEntries = false;
- @Parameter(names = {"-r", "--read"}, description = "read entries after any creates/deletes")
- boolean readEntries = false;
-
- public Opts() {
- super(DEFAULT_TABLE_NAME);
- auths = new Authorizations();
- }
- }
-
- public void enableTracing(Opts opts) throws Exception {
- DistributedTrace.enable(opts.getInstance(), new ZooReader(opts.getInstance().getZooKeepers(), 1000), "myHost", "myApp");
- }
-
- public void execute(Opts opts) throws TableNotFoundException, InterruptedException, AccumuloException, AccumuloSecurityException, TableExistsException {
-
- if (opts.createtable) {
- opts.getConnector().tableOperations().create(opts.getTableName());
- }
-
- if (opts.createEntries) {
- createEntries(opts);
- }
-
- if (opts.readEntries) {
- readEntries(opts);
- }
-
- if (opts.deletetable) {
- opts.getConnector().tableOperations().delete(opts.getTableName());
- }
- }
-
- private void createEntries(Opts opts) throws TableNotFoundException, AccumuloException, AccumuloSecurityException {
-
-
- BatchWriter batchWriter = opts.getConnector().createBatchWriter(opts.getTableName(), new BatchWriterConfig());
-
- Mutation m = new Mutation("row");
- m.put("cf", "cq", "value");
-
- // Trace the write operation. Note, unless you flush the BatchWriter, you will not capture
- // the write operation as it is occurs asynchronously. You can optionally create additional Spans
- // within a given Trace as seen below around the flush
- Trace.on("Client Write");
-
- batchWriter.addMutation(m);
- Span flushSpan = Trace.start("Client Flush");
- batchWriter.flush();
- flushSpan.stop();
-
- // Use Trace.offNoFlush() if you don't want the operation to block.
- Trace.off();
-
- batchWriter.close();
- }
-
- private void readEntries(Opts opts) throws TableNotFoundException, AccumuloException, AccumuloSecurityException {
-
- Scanner scanner = opts.getConnector().createScanner(opts.getTableName(), opts.auths);
-
- // Trace the read operation.
- Span readSpan = Trace.on("Client Read");
-
- int numberOfEntriesRead = 0;
- for (Entry<Key,Value> entry : scanner) {
- System.out.println(entry.getKey().toString() + " -> " + entry.getValue().toString());
- ++numberOfEntriesRead;
- }
- // You can add additional metadata (key, values) to Spans which will be able to be viewed in the Monitor
- readSpan.data("Number of Entries Read", String.valueOf(numberOfEntriesRead));
-
- Trace.off();
- }
-
-
- /**
- * @param args
- * @throws AccumuloSecurityException
- * @throws AccumuloException
- * @throws TableNotFoundException
- * @throws InterruptedException
- * @throws KeeperException
- * @throws IOException
- * @throws TableExistsException
- */
- public static void main(String[] args) throws Exception {
-
- TracingExample tracingExample = new TracingExample();
- Opts opts = new Opts();
- ScannerOpts scannerOpts = new ScannerOpts();
- opts.parseArgs(TracingExample.class.getName(), args, scannerOpts);
-
- tracingExample.enableTracing(opts);
- tracingExample.execute(opts);
- }
+
+ private static final String DEFAULT_TABLE_NAME = "test";
+
+ static class Opts extends ClientOnDefaultTable {
+ @Parameter(names = {"-C", "--createtable"}, description = "create table before doing anything")
+ boolean createtable = false;
+ @Parameter(names = {"-D", "--deletetable"}, description = "delete table when finished")
+ boolean deletetable = false;
+ @Parameter(names = {"-c", "--create"}, description = "create entries before any deletes")
+ boolean createEntries = false;
+ @Parameter(names = {"-r", "--read"}, description = "read entries after any creates/deletes")
+ boolean readEntries = false;
+
+ public Opts() {
+ super(DEFAULT_TABLE_NAME);
+ auths = new Authorizations();
+ }
+ }
+
+ public void enableTracing(Opts opts) throws Exception {
+ DistributedTrace.enable(opts.getInstance(), new ZooReader(opts.getInstance().getZooKeepers(), 1000), "myHost", "myApp");
+ }
+
+ public void execute(Opts opts) throws TableNotFoundException, InterruptedException, AccumuloException, AccumuloSecurityException, TableExistsException {
+
+ if (opts.createtable) {
+ opts.getConnector().tableOperations().create(opts.getTableName());
+ }
+
+ if (opts.createEntries) {
+ createEntries(opts);
+ }
+
+ if (opts.readEntries) {
+ readEntries(opts);
+ }
+
+ if (opts.deletetable) {
+ opts.getConnector().tableOperations().delete(opts.getTableName());
+ }
+ }
+
+ private void createEntries(Opts opts) throws TableNotFoundException, AccumuloException, AccumuloSecurityException {
+
+ BatchWriter batchWriter = opts.getConnector().createBatchWriter(opts.getTableName(), new BatchWriterConfig());
+
+ Mutation m = new Mutation("row");
+ m.put("cf", "cq", "value");
+
+ // Trace the write operation. Note, unless you flush the BatchWriter, you will not capture
+ // the write operation as it is occurs asynchronously. You can optionally create additional Spans
+ // within a given Trace as seen below around the flush
+ Trace.on("Client Write");
+
+ batchWriter.addMutation(m);
+ Span flushSpan = Trace.start("Client Flush");
+ batchWriter.flush();
+ flushSpan.stop();
+
+ // Use Trace.offNoFlush() if you don't want the operation to block.
+ Trace.off();
+
+ batchWriter.close();
+ }
+
+ private void readEntries(Opts opts) throws TableNotFoundException, AccumuloException, AccumuloSecurityException {
+
+ Scanner scanner = opts.getConnector().createScanner(opts.getTableName(), opts.auths);
+
+ // Trace the read operation.
+ Span readSpan = Trace.on("Client Read");
+
+ int numberOfEntriesRead = 0;
+ for (Entry<Key,Value> entry : scanner) {
+ System.out.println(entry.getKey().toString() + " -> " + entry.getValue().toString());
+ ++numberOfEntriesRead;
+ }
+ // You can add additional metadata (key, values) to Spans which will be able to be viewed in the Monitor
+ readSpan.data("Number of Entries Read", String.valueOf(numberOfEntriesRead));
+
+ Trace.off();
+ }
+
+ public static void main(String[] args) throws Exception {
+
+ TracingExample tracingExample = new TracingExample();
+ Opts opts = new Opts();
+ ScannerOpts scannerOpts = new ScannerOpts();
+ opts.parseArgs(TracingExample.class.getName(), args, scannerOpts);
+
+ tracingExample.enableTracing(opts);
+ tracingExample.execute(opts);
+ }
}
[4/4] git commit: Merge branch '1.6.0-SNAPSHOT'
Posted by ct...@apache.org.
Merge branch '1.6.0-SNAPSHOT'
Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo
Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/4d690b1e
Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/4d690b1e
Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/4d690b1e
Branch: refs/heads/master
Commit: 4d690b1e0beaec2aeaa1e1c22f8861a68fa8fe39
Parents: c00ac62 c68066d
Author: Christopher Tubbs <ct...@apache.org>
Authored: Fri Nov 8 17:26:08 2013 -0500
Committer: Christopher Tubbs <ct...@apache.org>
Committed: Fri Nov 8 17:26:08 2013 -0500
----------------------------------------------------------------------
----------------------------------------------------------------------